Changeset e938fa6 in mainline for uspace/lib/drv/generic/remote_usb.c


Ignore:
Timestamp:
2013-01-07T16:26:05Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
56bd6f11
Parents:
b995183
Message:

libdrv: Add hub required bus functions to usb iface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/remote_usb.c

    rb995183 re938fa6  
    3535
    3636#include <async.h>
     37#include <macros.h>
    3738#include <errno.h>
     39#include <devman.h>
    3840
    3941#include "usb_iface.h"
    4042#include "ddf/driver.h"
     43
     44usb_dev_session_t *usb_dev_connect(ddf_dev_t *parent)
     45{
     46        // TODO All usb requests are atomic so this is safe,
     47        // it will need to change once USING EXCHNAGE PARALLEL is safe with
     48        // devman_parent_device_connect
     49        return devman_parent_device_connect(EXCHANGE_ATOMIC,
     50            ddf_dev_get_handle(parent), IPC_FLAG_BLOCKING);
     51}
     52
     53void usb_dev_session_close(usb_dev_session_t *sess)
     54{
     55        if (sess)
     56                async_hangup(sess);
     57}
    4158
    4259typedef enum {
     
    4461        IPC_M_USB_GET_MY_INTERFACE,
    4562        IPC_M_USB_GET_HOST_CONTROLLER_HANDLE,
     63        IPC_M_USB_RESERVE_DEFAULT_ADDRESS,
     64        IPC_M_USB_RELEASE_DEFAULT_ADDRESS,
     65        IPC_M_USB_DEVICE_ENUMERATE,
     66        IPC_M_USB_DEVICE_REMOVE,
    4667} usb_iface_funcs_t;
    4768
     
    101122}
    102123
     124/** Reserve default USB address.
     125 * @param[in] exch IPC communication exchange
     126 * @param[in] speed Communication speed of the newly attached device
     127 * @return Error code.
     128 */
     129int usb_reserve_default_address(async_exch_t *exch, usb_speed_t speed)
     130{
     131        if (!exch)
     132                return EBADMEM;
     133        return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     134            IPC_M_USB_RESERVE_DEFAULT_ADDRESS, speed);
     135}
     136
     137/** Release default USB address.
     138 * @param[in] exch IPC communication exchange
     139 * @return Error code.
     140 */
     141int usb_release_default_address(async_exch_t *exch)
     142{
     143        if (!exch)
     144                return EBADMEM;
     145        return async_req_1_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     146            IPC_M_USB_RELEASE_DEFAULT_ADDRESS);
     147}
     148
     149/** Trigger USB device enumeration
     150 * @param[in] exch IPC communication exchange
     151 * @param[out] handle Identifier of the newly added device (if successful)
     152 * @return Error code.
     153 */
     154int usb_device_enumerate(async_exch_t *exch, usb_device_handle_t *handle)
     155{
     156        if (!exch || !handle)
     157                return EBADMEM;
     158        sysarg_t h;
     159        const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     160            IPC_M_USB_DEVICE_ENUMERATE, &h);
     161        if (ret == EOK)
     162                *handle = (usb_device_handle_t)h;
     163        return ret;
     164}
     165
     166/** Trigger USB device enumeration
     167 * @param[in] exch IPC communication exchange
     168 * @param[in] handle Identifier of the device
     169 * @return Error code.
     170 */
     171int usb_device_remove(async_exch_t *exch, usb_device_handle_t handle)
     172{
     173        if (!exch)
     174                return EBADMEM;
     175        return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     176            IPC_M_USB_DEVICE_REMOVE, handle);
     177}
    103178
    104179static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    105180static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    106181static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     182
     183static void remote_usb_reserve_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     184static void remote_usb_release_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     185static void remote_usb_device_enumerate(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     186static void remote_usb_device_remove(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    107187
    108188/** Remote USB interface operations. */
     
    111191        [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
    112192        [IPC_M_USB_GET_HOST_CONTROLLER_HANDLE] = remote_usb_get_hc_handle,
     193        [IPC_M_USB_RESERVE_DEFAULT_ADDRESS] = remote_usb_reserve_default_address,
     194        [IPC_M_USB_RELEASE_DEFAULT_ADDRESS] = remote_usb_release_default_address,
     195        [IPC_M_USB_DEVICE_ENUMERATE] = remote_usb_device_enumerate,
     196        [IPC_M_USB_DEVICE_REMOVE] = remote_usb_device_remove,
    113197};
    114198
     
    116200 */
    117201remote_iface_t remote_usb_iface = {
    118         .method_count = sizeof(remote_usb_iface_ops) /
    119             sizeof(remote_usb_iface_ops[0]),
    120         .methods = remote_usb_iface_ops
     202        .method_count = ARRAY_SIZE(remote_usb_iface_ops),
     203        .methods = remote_usb_iface_ops,
    121204};
    122205
     
    178261        async_answer_1(callid, EOK, (sysarg_t) handle);
    179262}
     263
     264void remote_usb_reserve_default_address(ddf_fun_t *fun, void *iface,
     265    ipc_callid_t callid, ipc_call_t *call)
     266{
     267        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
     268
     269        if (usb_iface->reserve_default_address == NULL) {
     270                async_answer_0(callid, ENOTSUP);
     271                return;
     272        }
     273
     274        usb_speed_t speed = DEV_IPC_GET_ARG1(*call);
     275        const int ret = usb_iface->reserve_default_address(fun, speed);
     276        async_answer_0(callid, ret);
     277}
     278
     279void remote_usb_release_default_address(ddf_fun_t *fun, void *iface,
     280    ipc_callid_t callid, ipc_call_t *call)
     281{
     282        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
     283
     284        if (usb_iface->release_default_address == NULL) {
     285                async_answer_0(callid, ENOTSUP);
     286                return;
     287        }
     288
     289        const int ret = usb_iface->release_default_address(fun);
     290        async_answer_0(callid, ret);
     291}
     292
     293static void remote_usb_device_enumerate(ddf_fun_t *fun, void *iface,
     294    ipc_callid_t callid, ipc_call_t *call)
     295{
     296        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
     297
     298        if (usb_iface->device_enumerate == NULL) {
     299                async_answer_0(callid, ENOTSUP);
     300                return;
     301        }
     302
     303        usb_device_handle_t handle = 0;
     304        const int ret = usb_iface->device_enumerate(fun, &handle);
     305        if (ret != EOK) {
     306                async_answer_0(callid, ret);
     307        }
     308
     309        async_answer_1(callid, EOK, (sysarg_t) handle);
     310}
     311
     312static void remote_usb_device_remove(ddf_fun_t *fun, void *iface,
     313    ipc_callid_t callid, ipc_call_t *call)
     314{
     315        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
     316
     317        if (usb_iface->device_remove == NULL) {
     318                async_answer_0(callid, ENOTSUP);
     319                return;
     320        }
     321
     322        usb_device_handle_t handle = DEV_IPC_GET_ARG1(*call);
     323        const int ret = usb_iface->device_remove(fun, handle);
     324        async_answer_0(callid, ret);
     325}
    180326/**
    181327 * @}
Note: See TracChangeset for help on using the changeset viewer.