Ignore:
File:
1 edited

Legend:

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

    r357a302 rbc1c6fb  
    3434 */
    3535#include <ipc/devman.h>
     36#include <devman.h>
     37#include <async.h>
    3638#include <usb/ddfiface.h>
     39#include <usb/debug.h>
    3740#include <errno.h>
     41#include <assert.h>
    3842
    3943/** DDF interface for USB device, implementation for typical hub. */
     
    5256/** Get host controller handle, interface implementation for hub driver.
    5357 *
    54  * @param[in] device Device the operation is running on.
     58 * @param[in] fun Device function the operation is running on.
    5559 * @param[out] handle Storage for the host controller handle.
    5660 * @return Error code.
    5761 */
    58 int usb_iface_get_hc_handle_hub_impl(device_t *device, devman_handle_t *handle)
     62int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *fun, devman_handle_t *handle)
    5963{
    60         assert(device);
    61         return usb_hc_find(device->handle, handle);
     64        assert(fun);
     65        return usb_hc_find(fun->handle, handle);
    6266}
    6367
     
    6569 * a hub driver.
    6670 *
    67  * @param[in] device Device the operation is running on.
     71 * @param[in] fun Device function the operation is running on.
    6872 * @param[out] handle Storage for the host controller handle.
    6973 * @return Error code.
    7074 */
    71 int usb_iface_get_hc_handle_hub_child_impl(device_t *device,
     75int usb_iface_get_hc_handle_hub_child_impl(ddf_fun_t *fun,
    7276    devman_handle_t *handle)
    7377{
    74         assert(device);
    75         device_t *parent = device->parent;
     78        assert(fun != NULL);
    7679
    77         /* Default error, device does not support this operation. */
    78         int rc = ENOTSUP;
    79 
    80         if (parent && parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
    81                 usb_iface_t *usb_iface
    82                     = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
    83                 assert(usb_iface != NULL);
    84 
    85                 if (usb_iface->get_hc_handle) {
    86                         rc = usb_iface->get_hc_handle(parent, handle);
    87                 }
     80        int parent_phone = devman_parent_device_connect(fun->handle,
     81            IPC_FLAG_BLOCKING);
     82        if (parent_phone < 0) {
     83                return parent_phone;
    8884        }
    8985
    90         return rc;
     86        sysarg_t hc_handle;
     87        int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
     88            IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &hc_handle);
     89
     90        async_hangup(parent_phone);
     91
     92        if (rc != EOK) {
     93                return rc;
     94        }
     95
     96        *handle = hc_handle;
     97
     98        return EOK;
    9199}
    92100
    93101/** Get host controller handle, interface implementation for HC driver.
    94102 *
    95  * @param[in] device Device the operation is running on.
     103 * @param[in] fun Device function the operation is running on.
    96104 * @param[out] handle Storage for the host controller handle.
    97105 * @return Always EOK.
    98106 */
    99 int usb_iface_get_hc_handle_hc_impl(device_t *device, devman_handle_t *handle)
     107int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *fun, devman_handle_t *handle)
    100108{
    101         assert(device);
     109        assert(fun);
    102110
    103111        if (handle != NULL) {
    104                 *handle = device->handle;
     112                *handle = fun->handle;
    105113        }
    106114
     
    110118/** Get USB device address, interface implementation for hub driver.
    111119 *
    112  * @param[in] device Device the operation is running on.
     120 * @param[in] fun Device function the operation is running on.
    113121 * @param[in] handle Devman handle of USB device we want address of.
    114122 * @param[out] address Storage for USB address of device with handle @p handle.
    115123 * @return Error code.
    116124 */
    117 int usb_iface_get_address_hub_impl(device_t *device, devman_handle_t handle,
     125int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
    118126    usb_address_t *address)
    119127{
    120         assert(device);
    121         int parent_phone = devman_parent_device_connect(device->handle,
     128        assert(fun);
     129        int parent_phone = devman_parent_device_connect(fun->handle,
    122130            IPC_FLAG_BLOCKING);
    123131        if (parent_phone < 0) {
     
    145153 * a hub driver.
    146154 *
    147  * @param[in] device Device the operation is running on.
     155 * @param[in] fun Device function the operation is running on.
    148156 * @param[in] handle Devman handle of USB device we want address of.
    149157 * @param[out] address Storage for USB address of device with handle @p handle.
    150158 * @return Error code.
    151159 */
    152 int usb_iface_get_address_hub_child_impl(device_t *device,
     160int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
    153161    devman_handle_t handle, usb_address_t *address)
    154162{
    155         assert(device);
    156         device_t *parent = device->parent;
    157 
    158         /* Default error, device does not support this operation. */
    159         int rc = ENOTSUP;
    160 
    161         if (parent && parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
    162                 usb_iface_t *usb_iface
    163                     = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
    164                 assert(usb_iface != NULL);
    165 
    166                 if (usb_iface->get_address) {
    167                         rc = usb_iface->get_address(parent, handle, address);
    168                 }
     163        if (handle == 0) {
     164                handle = fun->handle;
    169165        }
    170 
    171         return rc;
     166        return usb_iface_get_address_hub_impl(fun, handle, address);
    172167}
    173168
Note: See TracChangeset for help on using the changeset viewer.