Changeset 79ae36dd in mainline for uspace/drv/vhc


Ignore:
Timestamp:
2011-06-08T19:01:55Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
Location:
uspace/drv/vhc
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/vhc/conndev.c

    r764d71e r79ae36dd  
    3838#include <ddf/driver.h>
    3939#include <usbvirt/ipc.h>
     40#include <async.h>
    4041#include "conn.h"
    4142
     
    4445static fibril_local char plugged_device_name[PLUGGED_DEVICE_NAME_MAXLEN + 1] = "<unknown>";
    4546
     47#if 0
    4648/** Receive device name.
    4749 *
    4850 * @warning Errors are silently ignored.
    4951 *
    50  * @param phone Phone to the virtual device.
     52 * @param sess Session to the virtual device.
     53 *
    5154 */
    52 static void receive_device_name(int phone)
     55static void receive_device_name(async_sess_t *sess)
    5356{
    54         aid_t opening_request = async_send_0(phone, IPC_M_USBVIRT_GET_NAME, NULL);
     57        async_exch_t *exch = async_exchange_begin(sess);
     58       
     59        aid_t opening_request = async_send_0(exch, IPC_M_USBVIRT_GET_NAME, NULL);
    5560        if (opening_request == 0) {
     61                async_exchange_end(exch);
    5662                return;
    5763        }
    58 
    59 
     64       
    6065        ipc_call_t data_request_call;
    61         aid_t data_request = async_data_read(phone,
    62              plugged_device_name, PLUGGED_DEVICE_NAME_MAXLEN,
    63              &data_request_call);
    64 
     66        aid_t data_request = async_data_read(exch, plugged_device_name,
     67             PLUGGED_DEVICE_NAME_MAXLEN, &data_request_call);
     68       
     69        async_exchange_end(exch);
     70       
    6571        if (data_request == 0) {
    6672                async_wait_for(opening_request, NULL);
    6773                return;
    6874        }
    69 
     75       
    7076        sysarg_t data_request_rc;
    7177        sysarg_t opening_request_rc;
    7278        async_wait_for(data_request, &data_request_rc);
    7379        async_wait_for(opening_request, &opening_request_rc);
    74 
    75         if ((data_request_rc != EOK) || (opening_request_rc != EOK)) {
     80       
     81        if ((data_request_rc != EOK) || (opening_request_rc != EOK))
    7682                return;
    77         }
    78 
     83       
    7984        size_t len = IPC_GET_ARG2(data_request_call);
    8085        plugged_device_name[len] = 0;
    8186}
     87#endif
    8288
    8389/** Default handler for IPC methods not handled by DDF.
     
    9096    ipc_callid_t icallid, ipc_call_t *icall)
    9197{
     98// FIXME:
     99// This code needs to be refactored since the async
     100// framework does not support automatic callback connections
     101// yet.
     102
     103#if 0
    92104        vhc_data_t *vhc = fun->dev->driver_data;
    93105        sysarg_t method = IPC_GET_IMETHOD(*icall);
     
    112124                return;
    113125        }
     126#endif
    114127
    115128        async_answer_0(icallid, EINVAL);
  • uspace/drv/vhc/devconn.c

    r764d71e r79ae36dd  
     1/*
     2 * Copyright (c) 2011 Vojtech Horky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#include <errno.h>
    230#include "vhcd.h"
     
    1139        }
    1240        dev->address = 0;
    13         dev->dev_phone = -1;
     41        dev->dev_sess = NULL;
    1442        dev->dev_local = NULL;
    1543        dev->plugged = true;
     
    2250
    2351static int vhc_virtdev_plug_generic(vhc_data_t *vhc,
    24     int phone, usbvirt_device_t *virtdev,
     52    async_sess_t *sess, usbvirt_device_t *virtdev,
    2553    uintptr_t *handle, bool connect)
    2654{
     
    3058        }
    3159
    32         dev->dev_phone = phone;
     60        dev->dev_sess = sess;
    3361        dev->dev_local = virtdev;
    3462
     
    5684}
    5785
    58 int vhc_virtdev_plug(vhc_data_t *vhc, int phone, uintptr_t *handle)
     86int vhc_virtdev_plug(vhc_data_t *vhc, async_sess_t *sess, uintptr_t *handle)
    5987{
    60         return vhc_virtdev_plug_generic(vhc, phone, NULL, handle, true);
     88        return vhc_virtdev_plug_generic(vhc, sess, NULL, handle, true);
    6189}
    6290
    6391int vhc_virtdev_plug_local(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle)
    6492{
    65         return vhc_virtdev_plug_generic(vhc, -1, dev, handle, true);
     93        return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, true);
    6694}
    6795
    6896int vhc_virtdev_plug_hub(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle)
    6997{
    70         return vhc_virtdev_plug_generic(vhc, -1, dev, handle, false);
     98        return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, false);
    7199}
    72100
  • uspace/drv/vhc/hub.c

    r764d71e r79ae36dd  
    3333 * @brief Virtual USB hub.
    3434 */
     35
    3536#include <usb/classes/classes.h>
    3637#include <usbvirt/device.h>
    3738#include <errno.h>
     39#include <async.h>
    3840#include <str_error.h>
    3941#include <stdlib.h>
     
    4446
    4547#include "hub.h"
    46 //#include "hub/virthub.h"
    4748#include "vhcd.h"
    4849#include "conn.h"
     
    9798         * Wait until parent device is properly initialized.
    9899         */
    99         int phone;
     100        async_sess_t *sess;
    100101        do {
    101                 phone = devman_device_connect(hc_dev->handle, 0);
    102         } while (phone < 0);
    103         async_hangup(phone);
     102                sess = devman_device_connect(EXCHANGE_SERIALIZE, hc_dev->handle, 0);
     103        } while (!sess);
     104        async_hangup(sess);
    104105
    105106        int rc;
     
    129130        return 0;
    130131}
    131        
    132132
    133133/**
  • uspace/drv/vhc/hub.h

    r764d71e r79ae36dd  
    3333 * @brief Virtual USB hub.
    3434 */
     35
    3536#ifndef VHCD_HUB_H_
    3637#define VHCD_HUB_H_
  • uspace/drv/vhc/main.c

    r764d71e r79ae36dd  
    2929/** @addtogroup drvusbvhc
    3030 * @{
    31  */ 
     31 */
    3232/** @file
    3333 * Virtual host controller.
  • uspace/drv/vhc/transfer.c

    r764d71e r79ae36dd  
     1/*
     2 * Copyright (c) 2011 Vojtech Horky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
    129#include <errno.h>
    230#include <str_error.h>
     
    123151
    124152static int process_transfer_remote(vhc_transfer_t *transfer,
    125     int phone, size_t *actual_data_size)
     153    async_sess_t *sess, size_t *actual_data_size)
    126154{
    127155        int rc;
     
    129157        if (transfer->transfer_type == USB_TRANSFER_CONTROL) {
    130158                if (transfer->direction == USB_DIRECTION_IN) {
    131                         rc = usbvirt_ipc_send_control_read(phone,
    132                             transfer->setup_buffer, transfer->setup_buffer_size,
    133                             transfer->data_buffer, transfer->data_buffer_size,
    134                             actual_data_size);
    135                 } else {
    136                         assert(transfer->direction == USB_DIRECTION_OUT);
    137                         rc = usbvirt_ipc_send_control_write(phone,
    138                             transfer->setup_buffer, transfer->setup_buffer_size,
    139                             transfer->data_buffer, transfer->data_buffer_size);
    140                 }
    141         } else {
    142                 if (transfer->direction == USB_DIRECTION_IN) {
    143                         rc = usbvirt_ipc_send_data_in(phone, transfer->endpoint,
     159                        rc = usbvirt_ipc_send_control_read(sess,
     160                            transfer->setup_buffer, transfer->setup_buffer_size,
     161                            transfer->data_buffer, transfer->data_buffer_size,
     162                            actual_data_size);
     163                } else {
     164                        assert(transfer->direction == USB_DIRECTION_OUT);
     165                        rc = usbvirt_ipc_send_control_write(sess,
     166                            transfer->setup_buffer, transfer->setup_buffer_size,
     167                            transfer->data_buffer, transfer->data_buffer_size);
     168                }
     169        } else {
     170                if (transfer->direction == USB_DIRECTION_IN) {
     171                        rc = usbvirt_ipc_send_data_in(sess, transfer->endpoint,
    144172                            transfer->transfer_type,
    145173                            transfer->data_buffer, transfer->data_buffer_size,
     
    147175                } else {
    148176                        assert(transfer->direction == USB_DIRECTION_OUT);
    149                         rc = usbvirt_ipc_send_data_out(phone, transfer->endpoint,
     177                        rc = usbvirt_ipc_send_data_out(sess, transfer->endpoint,
    150178                            transfer->transfer_type,
    151179                            transfer->data_buffer, transfer->data_buffer_size);
     
    206234                int rc = EOK;
    207235                size_t data_transfer_size = 0;
    208                 if (dev->dev_phone > 0) {
    209                         rc = process_transfer_remote(transfer, dev->dev_phone,
     236                if (dev->dev_sess) {
     237                        rc = process_transfer_remote(transfer, dev->dev_sess,
    210238                            &data_transfer_size);
    211239                } else if (dev->dev_local != NULL) {
  • uspace/drv/vhc/vhcd.h

    r764d71e r79ae36dd  
    4141#include <usb/host/device_keeper.h>
    4242#include <usbhc_iface.h>
     43#include <async.h>
    4344
    4445#define NAME "vhc"
     
    4647typedef struct {
    4748        link_t link;
    48         int dev_phone;
     49        async_sess_t *dev_sess;
    4950        usbvirt_device_t *dev_local;
    5051        bool plugged;
     
    8283vhc_transfer_t *vhc_transfer_create(usb_address_t, usb_endpoint_t,
    8384    usb_direction_t, usb_transfer_type_t, ddf_fun_t *, void *);
    84 int vhc_virtdev_plug(vhc_data_t *, int, uintptr_t *);
     85int vhc_virtdev_plug(vhc_data_t *, async_sess_t *, uintptr_t *);
    8586int vhc_virtdev_plug_local(vhc_data_t *, usbvirt_device_t *, uintptr_t *);
    8687int vhc_virtdev_plug_hub(vhc_data_t *, usbvirt_device_t *, uintptr_t *);
Note: See TracChangeset for help on using the changeset viewer.