Changeset 79ae36dd in mainline for uspace/lib/usbdev/src/pipes.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (13 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.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/pipes.c

    r764d71e r79ae36dd  
    4848/** Tell USB address assigned to given device.
    4949 *
    50  * @param phone Phone to parent device.
     50 * @param sess Session to parent device.
    5151 * @param dev Device in question.
    5252 * @return USB address or error code.
    5353 */
    54 static usb_address_t get_my_address(int phone, ddf_dev_t *dev)
    55 {
    56         sysarg_t address;
    57 
     54static usb_address_t get_my_address(async_sess_t *sess, ddf_dev_t *dev)
     55{
     56        async_exch_t *exch = async_exchange_begin(sess);
     57       
    5858        /*
    5959         * We are sending special value as a handle - zero - to get
     
    6161         * when registering our device @p dev.
    6262         */
    63         int rc = async_req_2_1(phone, DEV_IFACE_ID(USB_DEV_IFACE),
    64             IPC_M_USB_GET_ADDRESS,
    65             0, &address);
    66 
    67         if (rc != EOK) {
     63        sysarg_t address;
     64        int rc = async_req_2_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     65            IPC_M_USB_GET_ADDRESS, 0, &address);
     66       
     67        async_exchange_end(exch);
     68       
     69        if (rc != EOK)
    6870                return rc;
    69         }
    70 
     71       
    7172        return (usb_address_t) address;
    7273}
     
    7980int usb_device_get_assigned_interface(ddf_dev_t *device)
    8081{
    81         int parent_phone = devman_parent_device_connect(device->handle,
     82        async_sess_t *parent_sess =
     83            devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle,
    8284            IPC_FLAG_BLOCKING);
    83         if (parent_phone < 0) {
     85        if (!parent_sess)
    8486                return -1;
    85         }
    86 
     87       
     88        async_exch_t *exch = async_exchange_begin(parent_sess);
     89       
    8790        sysarg_t iface_no;
    88         int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
    89             IPC_M_USB_GET_INTERFACE,
    90             device->handle, &iface_no);
    91 
    92         async_hangup(parent_phone);
    93 
    94         if (rc != EOK) {
     91        int rc = async_req_2_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     92            IPC_M_USB_GET_INTERFACE, device->handle, &iface_no);
     93       
     94        async_exchange_end(exch);
     95        async_hangup(parent_sess);
     96       
     97        if (rc != EOK)
    9598                return -1;
    96         }
    97 
     99       
    98100        return (int) iface_no;
    99101}
     
    110112        assert(connection);
    111113        assert(dev);
    112 
     114       
    113115        int rc;
    114116        devman_handle_t hc_handle;
    115117        usb_address_t my_address;
    116 
     118       
    117119        rc = usb_hc_find(dev->handle, &hc_handle);
    118         if (rc != EOK) {
     120        if (rc != EOK)
    119121                return rc;
    120         }
    121 
    122         int parent_phone = devman_parent_device_connect(dev->handle,
     122       
     123        async_sess_t *parent_sess =
     124            devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
    123125            IPC_FLAG_BLOCKING);
    124         if (parent_phone < 0) {
    125                 return parent_phone;
    126         }
    127 
     126        if (!parent_sess)
     127                return ENOMEM;
     128       
    128129        /*
    129130         * Asking for "my" address may require several attempts.
     
    137138         *  So, we need to wait for the HC to learn the binding.
    138139         */
     140       
    139141        do {
    140                 my_address = get_my_address(parent_phone, dev);
    141 
     142                my_address = get_my_address(parent_sess, dev);
     143               
    142144                if (my_address == ENOENT) {
    143145                        /* Be nice, let other fibrils run and try again. */
     
    148150                        goto leave;
    149151                }
    150 
     152       
    151153        } while (my_address < 0);
    152 
     154       
    153155        rc = usb_device_connection_initialize(connection,
    154156            hc_handle, my_address);
    155 
     157       
    156158leave:
    157         async_hangup(parent_phone);
     159        async_hangup(parent_sess);
    158160        return rc;
    159161}
Note: See TracChangeset for help on using the changeset viewer.