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


Ignore:
Timestamp:
2011-12-03T11:10:06Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
30413b31
Parents:
07fd4cd1 (diff), 1f5c9c96 (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 with mainline

File:
1 edited

Legend:

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

    r07fd4cd1 rb8b1e631  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
     3 * Copyright (c) 2011 Jan Vesely
    34 * All rights reserved.
    45 *
     
    3940#include "ddf/driver.h"
    4041
     42typedef enum {
     43        IPC_M_USB_GET_MY_ADDRESS,
     44        IPC_M_USB_GET_MY_INTERFACE,
     45        IPC_M_USB_GET_HOST_CONTROLLER_HANDLE,
     46} usb_iface_funcs_t;
     47
     48/** Tell USB address assigned to device.
     49 * @param exch Vaid IPC exchange
     50 * @param address Pointer to address storage place.
     51 * @return Error code.
     52 *
     53 * Exch param is an open communication to device implementing usb_iface.
     54 */
     55int usb_get_my_address(async_exch_t *exch, usb_address_t *address)
     56{
     57        if (!exch)
     58                return EINVAL;
     59        sysarg_t addr;
     60        const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     61            IPC_M_USB_GET_MY_ADDRESS, &addr);
     62
     63        if (ret == EOK && address != NULL)
     64                *address = (usb_address_t) addr;
     65        return ret;
     66}
     67/*----------------------------------------------------------------------------*/
     68/** Tell interface number given device can use.
     69 * @param[in] exch IPC communication exchange
     70 * @param[in] handle Id of the device
     71 * @param[out] usb_iface Assigned USB interface
     72 * @return Error code.
     73 */
     74int usb_get_my_interface(async_exch_t *exch, int *usb_iface)
     75{
     76        if (!exch)
     77                return EINVAL;
     78        sysarg_t iface_no;
     79        const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     80            IPC_M_USB_GET_MY_INTERFACE, &iface_no);
     81        if (ret == EOK && usb_iface)
     82                *usb_iface = (int)iface_no;
     83        return ret;
     84}
     85/*----------------------------------------------------------------------------*/
     86/** Tell devman handle of device host controller.
     87 * @param[in] exch IPC communication exchange
     88 * @param[out] hc_handle devman handle of the HC used by the target device.
     89 * @return Error code.
     90 */
     91int usb_get_hc_handle(async_exch_t *exch, devman_handle_t *hc_handle)
     92{
     93        if (!exch)
     94                return EINVAL;
     95        devman_handle_t h;
     96        const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     97            IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
     98        if (ret == EOK && hc_handle)
     99                *hc_handle = (devman_handle_t)h;
     100        return ret;
     101}
     102
    41103
    42104static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    43 static void remote_usb_get_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     105static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    44106static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    45 //static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *);
    46107
    47108/** Remote USB interface operations. */
    48109static remote_iface_func_ptr_t remote_usb_iface_ops [] = {
    49110        [IPC_M_USB_GET_MY_ADDRESS] = remote_usb_get_my_address,
    50         [IPC_M_USB_GET_INTERFACE] = remote_usb_get_interface,
     111        [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
    51112        [IPC_M_USB_GET_HOST_CONTROLLER_HANDLE] = remote_usb_get_hc_handle,
    52113};
     
    60121};
    61122
    62 
     123/*----------------------------------------------------------------------------*/
    63124void remote_usb_get_my_address(ddf_fun_t *fun, void *iface,
    64125    ipc_callid_t callid, ipc_call_t *call)
    65126{
    66         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     127        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    67128
    68129        if (usb_iface->get_my_address == NULL) {
     
    72133
    73134        usb_address_t address;
    74         int rc = usb_iface->get_my_address(fun, &address);
    75         if (rc != EOK) {
    76                 async_answer_0(callid, rc);
     135        const int ret = usb_iface->get_my_address(fun, &address);
     136        if (ret != EOK) {
     137                async_answer_0(callid, ret);
    77138        } else {
    78139                async_answer_1(callid, EOK, address);
    79140        }
    80141}
    81 
    82 void remote_usb_get_interface(ddf_fun_t *fun, void *iface,
     142/*----------------------------------------------------------------------------*/
     143void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
    83144    ipc_callid_t callid, ipc_call_t *call)
    84145{
    85         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     146        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    86147
    87         if (usb_iface->get_interface == NULL) {
     148        if (usb_iface->get_my_interface == NULL) {
    88149                async_answer_0(callid, ENOTSUP);
    89150                return;
    90151        }
    91152
    92         devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
    93 
    94153        int iface_no;
    95         int rc = usb_iface->get_interface(fun, handle, &iface_no);
    96         if (rc != EOK) {
    97                 async_answer_0(callid, rc);
     154        const int ret = usb_iface->get_my_interface(fun, &iface_no);
     155        if (ret != EOK) {
     156                async_answer_0(callid, ret);
    98157        } else {
    99158                async_answer_1(callid, EOK, iface_no);
    100159        }
    101160}
    102 
     161/*----------------------------------------------------------------------------*/
    103162void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface,
    104163    ipc_callid_t callid, ipc_call_t *call)
    105164{
    106         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     165        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    107166
    108167        if (usb_iface->get_hc_handle == NULL) {
     
    112171
    113172        devman_handle_t handle;
    114         int rc = usb_iface->get_hc_handle(fun, &handle);
    115         if (rc != EOK) {
    116                 async_answer_0(callid, rc);
     173        const int ret = usb_iface->get_hc_handle(fun, &handle);
     174        if (ret != EOK) {
     175                async_answer_0(callid, ret);
    117176        }
    118177
    119178        async_answer_1(callid, EOK, (sysarg_t) handle);
    120179}
    121 
    122 
    123 
    124180/**
    125181 * @}
Note: See TracChangeset for help on using the changeset viewer.