Changeset 7aaed09 in mainline for uspace/lib/usb/src/ddfiface.c


Ignore:
Timestamp:
2011-12-18T14:02:30Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c868e2d
Parents:
3b71e84d (diff), 1761268 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/ddfiface.c

    r3b71e84d r7aaed09  
    3636#include <devman.h>
    3737#include <async.h>
     38#include <usb_iface.h>
    3839#include <usb/ddfiface.h>
    3940#include <usb/hc.h>
    4041#include <usb/debug.h>
     42#include <usb/dev/hub.h>
    4143#include <errno.h>
    4244#include <assert.h>
    4345
    4446/** DDF interface for USB device, implementation for typical hub. */
    45 usb_iface_t  usb_iface_hub_impl = {
    46         .get_hc_handle = usb_iface_get_hc_handle_hub_impl,
    47         .get_address = usb_iface_get_address_hub_impl
     47usb_iface_t usb_iface_hub_impl = {
     48        .get_hc_handle = usb_iface_get_hc_handle_device_impl,
     49        .get_my_address = usb_iface_get_my_address_forward_impl,
    4850};
    4951
    5052/** DDF interface for USB device, implementation for child of a typical hub. */
    51 usb_iface_t  usb_iface_hub_child_impl = {
    52         .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl,
    53         .get_address = usb_iface_get_address_hub_child_impl
     53usb_iface_t usb_iface_hub_child_impl = {
     54        .get_hc_handle = usb_iface_get_hc_handle_device_impl,
     55        .get_my_address = usb_iface_get_my_address_from_device_data,
    5456};
    5557
     
    6163 * @return Error code.
    6264 */
    63 int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *fun, devman_handle_t *handle)
     65int usb_iface_get_hc_handle_device_impl(ddf_fun_t *fun, devman_handle_t *handle)
    6466{
    6567        assert(fun);
    6668        return usb_hc_find(fun->handle, handle);
    67 }
    68 
    69 /** Get host controller handle, interface implementation for child of
    70  * a hub driver.
    71  *
    72  * @param[in] fun Device function the operation is running on.
    73  * @param[out] handle Storage for the host controller handle.
    74  * @return Error code.
    75  */
    76 int usb_iface_get_hc_handle_hub_child_impl(ddf_fun_t *fun,
    77     devman_handle_t *handle)
    78 {
    79         assert(fun != NULL);
    80        
    81         async_sess_t *parent_sess =
    82             devman_parent_device_connect(EXCHANGE_SERIALIZE, fun->handle,
    83             IPC_FLAG_BLOCKING);
    84         if (!parent_sess)
    85                 return ENOMEM;
    86        
    87         async_exch_t *exch = async_exchange_begin(parent_sess);
    88        
    89         sysarg_t hc_handle;
    90         int rc = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    91             IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &hc_handle);
    92        
    93         async_exchange_end(exch);
    94         async_hangup(parent_sess);
    95        
    96         if (rc != EOK)
    97                 return rc;
    98        
    99         *handle = hc_handle;
    100         return EOK;
    10169}
    10270
     
    12593 * @return Error code.
    12694 */
    127 int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
     95int usb_iface_get_my_address_forward_impl(ddf_fun_t *fun,
    12896    usb_address_t *address)
    12997{
    13098        assert(fun);
    131        
     99
    132100        async_sess_t *parent_sess =
    133101            devman_parent_device_connect(EXCHANGE_SERIALIZE, fun->handle,
     
    135103        if (!parent_sess)
    136104                return ENOMEM;
    137        
     105
    138106        async_exch_t *exch = async_exchange_begin(parent_sess);
    139        
    140         sysarg_t addr;
    141         int rc = async_req_2_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    142             IPC_M_USB_GET_ADDRESS, handle, &addr);
    143        
     107        if (!exch) {
     108                async_hangup(parent_sess);
     109                return ENOMEM;
     110        }
     111
     112        const int ret = usb_get_my_address(exch, address);
     113
    144114        async_exchange_end(exch);
    145115        async_hangup(parent_sess);
    146        
    147         if (rc != EOK)
    148                 return rc;
    149        
    150         if (address != NULL)
    151                 *address = (usb_address_t) addr;
    152        
    153         return EOK;
     116
     117        return ret;
    154118}
    155119
    156120/** Get USB device address, interface implementation for child of
    157121 * a hub driver.
     122 *
     123 * This implementation eccepts 0 as valid handle and replaces it with fun's
     124 * handle.
    158125 *
    159126 * @param[in] fun Device function the operation is running on.
     
    162129 * @return Error code.
    163130 */
    164 int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
    165     devman_handle_t handle, usb_address_t *address)
     131int usb_iface_get_my_address_from_device_data(ddf_fun_t *fun,
     132    usb_address_t *address)
    166133{
    167         if (handle == 0) {
    168                 handle = fun->handle;
    169         }
    170         return usb_iface_get_address_hub_impl(fun, handle, address);
     134        assert(fun);
     135        assert(fun->driver_data);
     136        usb_hub_attached_device_t *device = fun->driver_data;
     137        assert(device->fun == fun);
     138        if (address)
     139                *address = device->address;
     140        return EOK;
    171141}
    172142
Note: See TracChangeset for help on using the changeset viewer.