Ignore:
File:
1 edited

Legend:

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

    rbc1c6fb r357a302  
    3434 */
    3535#include <ipc/devman.h>
    36 #include <devman.h>
    37 #include <async.h>
    3836#include <usb/ddfiface.h>
    39 #include <usb/debug.h>
    4037#include <errno.h>
    41 #include <assert.h>
    4238
    4339/** DDF interface for USB device, implementation for typical hub. */
     
    5652/** Get host controller handle, interface implementation for hub driver.
    5753 *
    58  * @param[in] fun Device function the operation is running on.
     54 * @param[in] device Device the operation is running on.
    5955 * @param[out] handle Storage for the host controller handle.
    6056 * @return Error code.
    6157 */
    62 int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *fun, devman_handle_t *handle)
     58int usb_iface_get_hc_handle_hub_impl(device_t *device, devman_handle_t *handle)
    6359{
    64         assert(fun);
    65         return usb_hc_find(fun->handle, handle);
     60        assert(device);
     61        return usb_hc_find(device->handle, handle);
    6662}
    6763
     
    6965 * a hub driver.
    7066 *
    71  * @param[in] fun Device function the operation is running on.
     67 * @param[in] device Device the operation is running on.
    7268 * @param[out] handle Storage for the host controller handle.
    7369 * @return Error code.
    7470 */
    75 int usb_iface_get_hc_handle_hub_child_impl(ddf_fun_t *fun,
     71int usb_iface_get_hc_handle_hub_child_impl(device_t *device,
    7672    devman_handle_t *handle)
    7773{
    78         assert(fun != NULL);
     74        assert(device);
     75        device_t *parent = device->parent;
    7976
    80         int parent_phone = devman_parent_device_connect(fun->handle,
    81             IPC_FLAG_BLOCKING);
    82         if (parent_phone < 0) {
    83                 return parent_phone;
     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                }
    8488        }
    8589
    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;
     90        return rc;
    9991}
    10092
    10193/** Get host controller handle, interface implementation for HC driver.
    10294 *
    103  * @param[in] fun Device function the operation is running on.
     95 * @param[in] device Device the operation is running on.
    10496 * @param[out] handle Storage for the host controller handle.
    10597 * @return Always EOK.
    10698 */
    107 int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *fun, devman_handle_t *handle)
     99int usb_iface_get_hc_handle_hc_impl(device_t *device, devman_handle_t *handle)
    108100{
    109         assert(fun);
     101        assert(device);
    110102
    111103        if (handle != NULL) {
    112                 *handle = fun->handle;
     104                *handle = device->handle;
    113105        }
    114106
     
    118110/** Get USB device address, interface implementation for hub driver.
    119111 *
    120  * @param[in] fun Device function the operation is running on.
     112 * @param[in] device Device the operation is running on.
    121113 * @param[in] handle Devman handle of USB device we want address of.
    122114 * @param[out] address Storage for USB address of device with handle @p handle.
    123115 * @return Error code.
    124116 */
    125 int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
     117int usb_iface_get_address_hub_impl(device_t *device, devman_handle_t handle,
    126118    usb_address_t *address)
    127119{
    128         assert(fun);
    129         int parent_phone = devman_parent_device_connect(fun->handle,
     120        assert(device);
     121        int parent_phone = devman_parent_device_connect(device->handle,
    130122            IPC_FLAG_BLOCKING);
    131123        if (parent_phone < 0) {
     
    153145 * a hub driver.
    154146 *
    155  * @param[in] fun Device function the operation is running on.
     147 * @param[in] device Device the operation is running on.
    156148 * @param[in] handle Devman handle of USB device we want address of.
    157149 * @param[out] address Storage for USB address of device with handle @p handle.
    158150 * @return Error code.
    159151 */
    160 int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
     152int usb_iface_get_address_hub_child_impl(device_t *device,
    161153    devman_handle_t handle, usb_address_t *address)
    162154{
    163         if (handle == 0) {
    164                 handle = fun->handle;
     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                }
    165169        }
    166         return usb_iface_get_address_hub_impl(fun, handle, address);
     170
     171        return rc;
    167172}
    168173
Note: See TracChangeset for help on using the changeset viewer.