Ignore:
File:
1 edited

Legend:

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

    r27ed734c r79ae36dd  
    3939#include <usb/hc.h>
    4040#include <usb/debug.h>
    41 #include <usb/dev/hub.h>
    4241#include <errno.h>
    4342#include <assert.h>
    4443
    4544/** DDF interface for USB device, implementation for typical hub. */
    46 usb_iface_t usb_iface_hub_impl = {
    47         .get_hc_handle = usb_iface_get_hc_handle_device_impl,
    48         .get_my_address = usb_iface_get_my_address_forward_impl,
     45usb_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
    4948};
    5049
    5150/** DDF interface for USB device, implementation for child of a typical hub. */
    52 usb_iface_t usb_iface_hub_child_impl = {
    53         .get_hc_handle = usb_iface_get_hc_handle_device_impl,
    54         .get_my_address = usb_iface_get_my_address_from_device_data,
     51usb_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
    5554};
    5655
     
    6261 * @return Error code.
    6362 */
    64 int usb_iface_get_hc_handle_device_impl(ddf_fun_t *fun, devman_handle_t *handle)
     63int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *fun, devman_handle_t *handle)
    6564{
    6665        assert(fun);
    6766        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 */
     76int 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;
    68101}
    69102
     
    92125 * @return Error code.
    93126 */
    94 int usb_iface_get_my_address_forward_impl(ddf_fun_t *fun,
     127int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
    95128    usb_address_t *address)
    96129{
    97130        assert(fun);
    98 
     131       
    99132        async_sess_t *parent_sess =
    100133            devman_parent_device_connect(EXCHANGE_SERIALIZE, fun->handle,
     
    102135        if (!parent_sess)
    103136                return ENOMEM;
    104 
     137       
    105138        async_exch_t *exch = async_exchange_begin(parent_sess);
    106 
     139       
    107140        sysarg_t addr;
    108         int rc = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    109             IPC_M_USB_GET_MY_ADDRESS, &addr);
    110 
     141        int rc = async_req_2_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     142            IPC_M_USB_GET_ADDRESS, handle, &addr);
     143       
    111144        async_exchange_end(exch);
    112145        async_hangup(parent_sess);
    113 
     146       
    114147        if (rc != EOK)
    115148                return rc;
    116 
     149       
    117150        if (address != NULL)
    118151                *address = (usb_address_t) addr;
    119 
     152       
    120153        return EOK;
    121154}
     
    124157 * a hub driver.
    125158 *
    126  * This implementation eccepts 0 as valid handle and replaces it with fun's
    127  * handle.
    128  *
    129159 * @param[in] fun Device function the operation is running on.
    130160 * @param[in] handle Devman handle of USB device we want address of.
     
    132162 * @return Error code.
    133163 */
    134 int usb_iface_get_my_address_from_device_data(ddf_fun_t *fun,
    135     usb_address_t *address)
     164int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
     165    devman_handle_t handle, usb_address_t *address)
    136166{
    137         assert(fun);
    138         assert(fun->driver_data);
    139         usb_hub_attached_device_t *device = fun->driver_data;
    140         assert(device->fun == fun);
    141         if (address)
    142                 *address = device->address;
    143         return EOK;
     167        if (handle == 0) {
     168                handle = fun->handle;
     169        }
     170        return usb_iface_get_address_hub_impl(fun, handle, address);
    144171}
    145172
Note: See TracChangeset for help on using the changeset viewer.