Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 56bdd9a4 in mainline


Ignore:
Timestamp:
2011-11-25T15:20:04Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
02fc5c4
Parents:
317a463
Message:

usb: Provide IPC wrappers instead of IPC call numbers.

Put IPC protocol in one file.
This is does not make much difference for usb_iface, but will be useful
for more complicated interfaces.

Location:
uspace/lib
Files:
5 edited

Legend:

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

    r317a463 r56bdd9a4  
    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 *);
     
    59121};
    60122
    61 
     123/*----------------------------------------------------------------------------*/
    62124void remote_usb_get_my_address(ddf_fun_t *fun, void *iface,
    63125    ipc_callid_t callid, ipc_call_t *call)
    64126{
    65         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     127        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    66128
    67129        if (usb_iface->get_my_address == NULL) {
     
    71133
    72134        usb_address_t address;
    73         int rc = usb_iface->get_my_address(fun, &address);
    74         if (rc != EOK) {
    75                 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);
    76138        } else {
    77139                async_answer_1(callid, EOK, address);
    78140        }
    79141}
    80 
     142/*----------------------------------------------------------------------------*/
    81143void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
    82144    ipc_callid_t callid, ipc_call_t *call)
    83145{
    84         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     146        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    85147
    86148        if (usb_iface->get_my_interface == NULL) {
     
    90152
    91153        int iface_no;
    92         int rc = usb_iface->get_my_interface(fun, &iface_no);
    93         if (rc != EOK) {
    94                 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);
    95157        } else {
    96158                async_answer_1(callid, EOK, iface_no);
    97159        }
    98160}
    99 
     161/*----------------------------------------------------------------------------*/
    100162void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface,
    101163    ipc_callid_t callid, ipc_call_t *call)
    102164{
    103         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     165        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    104166
    105167        if (usb_iface->get_hc_handle == NULL) {
     
    109171
    110172        devman_handle_t handle;
    111         int rc = usb_iface->get_hc_handle(fun, &handle);
    112         if (rc != EOK) {
    113                 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);
    114176        }
    115177
    116178        async_answer_1(callid, EOK, (sysarg_t) handle);
    117179}
    118 
    119 
    120 
    121180/**
    122181 * @}
  • uspace/lib/drv/include/usb_iface.h

    r317a463 r56bdd9a4  
    3939
    4040#include "ddf/driver.h"
     41#include <async.h>
    4142#include <usb/usb.h>
    42 typedef enum {
    43         /** Tell USB address assigned to device.
    44          * Parameters:
    45          * - devman handle id
    46          * Answer:
    47          * - EINVAL - unknown handle or handle not managed by this driver
    48          * - ENOTSUP - operation not supported (shall not happen)
    49          * - arbitrary error code if returned by remote implementation
    50          * - EOK - handle found, first parameter contains the USB address
    51          *
    52          * The handle must be the one used for binding USB address with
    53          * it (IPC_M_USBHC_BIND_ADDRESS), otherwise the host controller
    54          * (that this request would eventually reach) would not be able
    55          * to find it.
    56          * The problem is that this handle is actually assigned to the
    57          * function inside driver of the parent device (usually hub driver).
    58          * To bypass this problem, the initial caller specify handle as
    59          * zero and the first parent assigns the actual value.
    60          * See usb_iface_get_address_hub_child_impl() implementation
    61          * that could be assigned to device ops of a child device of in a
    62          * hub driver.
    63          * For example, the USB multi interface device driver (MID)
    64          * passes this initial zero without any modification because the
    65          * handle must be resolved by its parent.
    66          */
    67         IPC_M_USB_GET_MY_ADDRESS,
    6843
    69         /** Tell interface number given device can use.
    70          * Parameters
    71          * - devman handle id of the device
    72          * Answer:
    73          * - ENOTSUP - operation not supported (can also mean any interface)
    74          * - EOK - operation okay, first parameter contains interface number
    75          */
    76         IPC_M_USB_GET_MY_INTERFACE,
    77 
    78         /** Tell devman handle of device host controller.
    79          * Parameters:
    80          * - none
    81          * Answer:
    82          * - EOK - request processed without errors
    83          * - ENOTSUP - this indicates invalid USB driver
    84          * Parameters of the answer:
    85          * - devman handle of HC caller is physically connected to
    86          */
    87         IPC_M_USB_GET_HOST_CONTROLLER_HANDLE
    88 } usb_iface_funcs_t;
     44int usb_get_my_address(async_exch_t *, usb_address_t *);
     45int usb_get_my_interface(async_exch_t *, int *);
     46int usb_get_hc_handle(async_exch_t *, devman_handle_t *);
    8947
    9048/** USB device communication interface. */
     
    9553} usb_iface_t;
    9654
    97 
    9855#endif
    9956/**
  • uspace/lib/usb/src/ddfiface.c

    r317a463 r56bdd9a4  
    3636#include <devman.h>
    3737#include <async.h>
     38#include <usb_iface.h>
    3839#include <usb/ddfiface.h>
    3940#include <usb/hc.h>
     
    104105
    105106        async_exch_t *exch = async_exchange_begin(parent_sess);
     107        if (!exch) {
     108                async_hangup(parent_sess);
     109                return ENOMEM;
     110        }
    106111
    107         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);
     112        const int ret = usb_get_my_address(exch, address);
    110113
    111114        async_exchange_end(exch);
    112115        async_hangup(parent_sess);
    113116
    114         if (rc != EOK)
    115                 return rc;
    116 
    117         if (address != NULL)
    118                 *address = (usb_address_t) addr;
    119 
    120         return EOK;
     117        return ret;
    121118}
    122119
  • uspace/lib/usb/src/hc.c

    r317a463 r56bdd9a4  
    181181        if (!parent_sess)
    182182                return ENOMEM;
    183        
     183
    184184        async_exch_t *exch = async_exchange_begin(parent_sess);
    185        
    186         sysarg_t address;
    187         int rc = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    188             IPC_M_USB_GET_MY_ADDRESS, &address);
    189        
     185        if (!exch) {
     186                async_hangup(parent_sess);
     187                return ENOMEM;
     188        }
     189        usb_address_t address;
     190        const int ret = usb_get_my_address(exch, &address);
     191
    190192        async_exchange_end(exch);
    191193        async_hangup(parent_sess);
    192        
    193         if (rc != EOK)
    194                 return rc;
    195        
    196         return (usb_address_t) address;
     194
     195        if (ret != EOK)
     196                return ret;
     197
     198        return address;
    197199}
    198200
     
    231233        if (!parent_sess)
    232234                return ENOMEM;
    233        
     235
    234236        async_exch_t *exch = async_exchange_begin(parent_sess);
    235        
    236         devman_handle_t h;
    237         int rc = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    238             IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
    239        
     237        if (!exch) {
     238                async_hangup(parent_sess);
     239                return ENOMEM;
     240        }
     241        const int ret = usb_get_hc_handle(exch, hc_handle);
     242
    240243        async_exchange_end(exch);
    241244        async_hangup(parent_sess);
    242        
    243         if (rc != EOK)
    244                 return rc;
    245        
    246         if (hc_handle != NULL)
    247                 *hc_handle = h;
    248        
    249         return EOK;
     245
     246        return ret;
    250247}
    251248
  • uspace/lib/usbdev/src/pipes.c

    r317a463 r56bdd9a4  
    5454static usb_address_t get_my_address(async_sess_t *sess, const ddf_dev_t *dev)
    5555{
     56        assert(sess);
    5657        async_exch_t *exch = async_exchange_begin(sess);
    57        
    58         sysarg_t address;
    59         int rc = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    60             IPC_M_USB_GET_MY_ADDRESS, &address);
    61        
     58        if (!exch)
     59                return ENOMEM;
     60
     61        usb_address_t address;
     62        const int ret = usb_get_my_address(exch, &address);
     63
    6264        async_exchange_end(exch);
    63        
    64         if (rc != EOK)
    65                 return rc;
    66        
    67         return (usb_address_t) address;
     65
     66        return (ret == EOK) ? address : ret;
    6867}
    6968
     
    7170 *
    7271 * @param device Device in question.
    73  * @return Interface number (negative code means any).
     72 * @return Error code (ENOTSUP means any).
    7473 */
    7574int usb_device_get_assigned_interface(const ddf_dev_t *device)
     
    8079            IPC_FLAG_BLOCKING);
    8180        if (!parent_sess)
    82                 return -1;
    83        
     81                return ENOMEM;
     82
    8483        async_exch_t *exch = async_exchange_begin(parent_sess);
    85        
    86         sysarg_t iface_no;
    87         int rc = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    88             IPC_M_USB_GET_MY_INTERFACE, &iface_no);
    89        
    90         async_exchange_end(exch);
    91         async_hangup(parent_sess);
    92        
    93         if (rc != EOK)
    94                 return -1;
    95        
    96         return (int) iface_no;
     84        if (!exch) {
     85                async_hangup(parent_sess);
     86                return ENOMEM;
     87        }
     88
     89        int iface_no;
     90        const int ret = usb_get_my_interface(exch, &iface_no);
     91
     92        return ret == EOK ? iface_no : ret;
    9793}
    9894
Note: See TracChangeset for help on using the changeset viewer.