Changeset 357a302 in mainline


Ignore:
Timestamp:
2011-02-20T14:17:40Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b68b279
Parents:
3ae93a8
Message:

USB interfaces reorganization

The most important change is that getting USB address of a device
is an operation of generic USB interface, not USB-HC interface.
That is needed for proper functionality of a MID driver.

Also added sample implementation of USB interface operations as is
needed by most drivers (sample does not mean unfunctional or partially
implemented here).
They are stored in libusb/ddfiface.h

Updated UHCI, UHCI-RH, hub, VHC drivers to use these sample
implementations.

Updated libusb device recognition routines to route get_address requests
through USB interface.

Location:
uspace
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/iface.c

    r3ae93a8 r357a302  
    4242#include "uhci.h"
    4343
    44 static int get_address(device_t *dev, devman_handle_t handle,
    45     usb_address_t *address)
    46 {
    47         assert(dev);
    48         uhci_t *hc = dev_to_uhci(dev);
    49         assert(hc);
    50         *address = usb_address_keeping_find(&hc->address_manager, handle);
    51         if (*address <= 0)
    52           return *address;
    53         return EOK;
    54 }
    5544/*----------------------------------------------------------------------------*/
    5645static int reserve_default_address(device_t *dev, usb_speed_t speed)
     
    168157/*----------------------------------------------------------------------------*/
    169158usbhc_iface_t uhci_iface = {
    170         .tell_address = get_address,
    171 
    172159        .reserve_default_address = reserve_default_address,
    173160        .release_default_address = release_default_address,
  • uspace/drv/uhci-hcd/main.c

    r3ae93a8 r357a302  
    5555}
    5656
     57static int usb_iface_get_address(device_t *dev, devman_handle_t handle,
     58    usb_address_t *address)
     59{
     60        assert(dev);
     61        uhci_t *hc = dev_to_uhci(dev);
     62        assert(hc);
     63
     64        usb_address_t addr = usb_address_keeping_find(&hc->address_manager,
     65            handle);
     66        if (addr < 0) {
     67                return addr;
     68        }
     69
     70        if (address != NULL) {
     71                *address = addr;
     72        }
     73
     74        return EOK;
     75}
     76
    5777static usb_iface_t hc_usb_iface = {
    58         .get_hc_handle = usb_iface_get_hc_handle
     78        .get_hc_handle = usb_iface_get_hc_handle,
     79        .get_address = usb_iface_get_address
    5980};
    6081
  • uspace/drv/uhci-rhd/main.c

    r3ae93a8 r357a302  
    3434#include <driver.h>
    3535#include <usb_iface.h>
     36#include <usb/ddfiface.h>
    3637
    3738#include <errno.h>
     
    5657
    5758static usb_iface_t uhci_rh_usb_iface = {
    58         .get_hc_handle = usb_iface_get_hc_handle
     59        .get_hc_handle = usb_iface_get_hc_handle,
     60        .get_address = usb_iface_get_address_hub_impl
    5961};
    6062
  • uspace/drv/usbhub/usbhub.c

    r3ae93a8 r357a302  
    3939
    4040#include <usb_iface.h>
     41#include <usb/ddfiface.h>
    4142#include <usb/usbdrv.h>
    4243#include <usb/descriptor.h>
     
    5051#include "usb/usb.h"
    5152
    52 static int iface_get_hc_handle(device_t *device, devman_handle_t *handle)
    53 {
    54         return usb_hc_find(device->handle, handle);
    55 }
    56 
    57 static usb_iface_t hub_usb_iface = {
    58         .get_hc_handle = iface_get_hc_handle
    59 };
    60 
    6153static device_ops_t hub_device_ops = {
    62         .interfaces[USB_DEV_IFACE] = &hub_usb_iface
     54        .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
    6355};
    6456
  • uspace/drv/vhc/conn.h

    r3ae93a8 r357a302  
    3838#include <usb/usb.h>
    3939#include <usbhc_iface.h>
     40#include <usb_iface.h>
    4041#include "vhcd.h"
    4142#include "devices.h"
     
    4344void connection_handler_host(sysarg_t);
    4445
    45 usbhc_iface_t vhc_iface;
     46extern usbhc_iface_t vhc_iface;
     47extern usb_iface_t vhc_usb_iface;
    4648
    4749void address_init(void);
  • uspace/drv/vhc/connhost.c

    r3ae93a8 r357a302  
    3737#include <usb/usb.h>
    3838#include <usb/addrkeep.h>
     39#include <usb/ddfiface.h>
    3940
    4041#include "vhcd.h"
     
    313314static usb_address_keeping_t addresses;
    314315
     316static int tell_address(device_t *dev, devman_handle_t handle,
     317    usb_address_t *address)
     318{
     319        usb_address_t addr = usb_address_keeping_find(&addresses, handle);
     320        if (addr < 0) {
     321                return addr;
     322        }
     323
     324        *address = addr;
     325        return EOK;
     326}
    315327
    316328static int reserve_default_address(device_t *dev, usb_speed_t ignored)
     
    350362}
    351363
    352 static int tell_address(device_t *dev, devman_handle_t handle,
    353     usb_address_t *address)
    354 {
    355         usb_address_t addr = usb_address_keeping_find(&addresses, handle);
    356         if (addr < 0) {
    357                 return addr;
    358         }
    359 
    360         *address = addr;
    361         return EOK;
    362 }
    363 
    364364void address_init(void)
    365365{
     
    368368
    369369usbhc_iface_t vhc_iface = {
    370         .tell_address = tell_address,
    371 
    372370        .reserve_default_address = reserve_default_address,
    373371        .release_default_address = release_default_address,
     
    383381};
    384382
     383usb_iface_t vhc_usb_iface = {
     384        .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
     385        .get_address = tell_address
     386};
     387
     388
    385389/**
    386390 * @}
  • uspace/drv/vhc/hcd.c

    r3ae93a8 r357a302  
    4545
    4646#include <usb/usb.h>
     47#include <usb/ddfiface.h>
    4748#include <usb_iface.h>
    4849#include "vhcd.h"
     
    5253#include "conn.h"
    5354
    54 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
    55 {
    56         /* This shall be called only for VHC device. */
    57         assert(dev->parent == NULL);
    58 
    59         *handle = dev->handle;
    60         return EOK;
    61 }
    62 
    63 static usb_iface_t hc_usb_iface = {
    64         .get_hc_handle = usb_iface_get_hc_handle
    65 };
    66 
    6755static device_ops_t vhc_ops = {
    6856        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
    69         .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
     57        .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
    7058        .close = on_client_close,
    7159        .default_handler = default_connection_handler
  • uspace/lib/drv/generic/remote_usb.c

    r3ae93a8 r357a302  
    4141
    4242static void remote_usb_get_hc_handle(device_t *, void *, ipc_callid_t, ipc_call_t *);
     43static void remote_usb_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4344//static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4445
    4546/** Remote USB interface operations. */
    4647static remote_iface_func_ptr_t remote_usb_iface_ops [] = {
     48        remote_usb_get_address,
    4749        remote_usb_get_hc_handle
    4850};
     
    5557        .methods = remote_usb_iface_ops
    5658};
     59
     60
     61void remote_usb_get_address(device_t *device, void *iface,
     62    ipc_callid_t callid, ipc_call_t *call)
     63{
     64        usb_iface_t *usb_iface = (usb_iface_t *) iface;
     65
     66        if (usb_iface->get_address == NULL) {
     67                async_answer_0(callid, ENOTSUP);
     68                return;
     69        }
     70
     71        devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
     72
     73        usb_address_t address;
     74        int rc = usb_iface->get_address(device, handle, &address);
     75        if (rc != EOK) {
     76                async_answer_0(callid, rc);
     77        } else {
     78                async_answer_1(callid, EOK, address);
     79        }
     80}
    5781
    5882
  • uspace/lib/drv/generic/remote_usbhc.c

    r3ae93a8 r357a302  
    4343#define HACK_MAX_PACKET_SIZE_INTERRUPT_IN 4
    4444
    45 static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4645static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4746static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    5958/** Remote USB host controller interface operations. */
    6059static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = {
    61         remote_usbhc_get_address,
    62 
    6360        remote_usbhc_reserve_default_address,
    6461        remote_usbhc_release_default_address,
     
    124121
    125122        return trans;
    126 }
    127 
    128 void remote_usbhc_get_address(device_t *device, void *iface,
    129     ipc_callid_t callid, ipc_call_t *call)
    130 {
    131         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    132 
    133         if (!usb_iface->tell_address) {
    134                 async_answer_0(callid, ENOTSUP);
    135                 return;
    136         }
    137 
    138         devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
    139 
    140         usb_address_t address;
    141         int rc = usb_iface->tell_address(device, handle, &address);
    142         if (rc != EOK) {
    143                 async_answer_0(callid, rc);
    144         } else {
    145                 async_answer_1(callid, EOK, address);
    146         }
    147123}
    148124
  • uspace/lib/drv/include/usb_iface.h

    r3ae93a8 r357a302  
    4141#include <usb/usb.h>
    4242typedef 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        IPC_M_USB_GET_ADDRESS,
     53
    4354        /** Tell devman handle of device host controller.
    4455         * Parameters:
     
    5566/** USB device communication interface. */
    5667typedef struct {
     68        int (*get_address)(device_t *, devman_handle_t, usb_address_t *);
    5769        int (*get_hc_handle)(device_t *, devman_handle_t *);
    5870} usb_iface_t;
  • uspace/lib/drv/include/usbhc_iface.h

    r3ae93a8 r357a302  
    8585 */
    8686typedef enum {
    87         /** Tell USB address assigned to device.
    88          * Parameters:
    89          * - devman handle id
    90          * Answer:
    91          * - EINVAL - unknown handle or handle not managed by this driver
    92          * - ENOTSUP - operation not supported by HC (shall not happen)
    93          * - arbitrary error code if returned by remote implementation
    94          * - EOK - handle found, first parameter contains the USB address
    95          */
    96         IPC_M_USBHC_GET_ADDRESS,
    97 
    98 
    9987        /** Reserve usage of default address.
    10088         * This call informs the host controller that the caller will be
     
    206194/** USB host controller communication interface. */
    207195typedef struct {
    208         int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
    209 
    210196        int (*reserve_default_address)(device_t *, usb_speed_t);
    211197        int (*release_default_address)(device_t *);
  • uspace/lib/usb/Makefile

    r3ae93a8 r357a302  
    3535        src/addrkeep.c \
    3636        src/class.c \
     37        src/ddfiface.c \
    3738        src/debug.c \
    3839        src/dp.c \
  • uspace/lib/usb/src/hub.c

    r3ae93a8 r357a302  
    301301}
    302302
    303 
    304303/**
    305304 * @}
  • uspace/lib/usb/src/pipes.c

    r3ae93a8 r357a302  
    3636#include <usb/pipes.h>
    3737#include <usbhc_iface.h>
     38#include <usb_iface.h>
    3839#include <errno.h>
    3940#include <assert.h>
     
    4142/** Tell USB address assigned to given device.
    4243 *
    43  * @param phone Phone to my HC.
     44 * @param phone Phone to parent device.
    4445 * @param dev Device in question.
    4546 * @return USB address or error code.
     
    4849{
    4950        sysarg_t address;
    50         int rc = async_req_2_1(phone, DEV_IFACE_ID(USBHC_DEV_IFACE),
    51             IPC_M_USBHC_GET_ADDRESS,
     51        int rc = async_req_2_1(phone, DEV_IFACE_ID(USB_DEV_IFACE),
     52            IPC_M_USB_GET_ADDRESS,
    5253            dev->handle, &address);
    5354
     
    8081        }
    8182
    82         int hc_phone = devman_device_connect(hc_handle, 0);
    83         if (hc_phone < 0) {
    84                 return hc_phone;
    85         }
    86 
    87         my_address = get_my_address(hc_phone, device);
     83        int parent_phone = devman_parent_device_connect(device->handle,
     84            IPC_FLAG_BLOCKING);
     85        if (parent_phone < 0) {
     86                return parent_phone;
     87        }
     88
     89        my_address = get_my_address(parent_phone, device);
    8890        if (my_address < 0) {
    8991                rc = my_address;
     
    9597
    9698leave:
    97         async_hangup(hc_phone);
     99        async_hangup(parent_phone);
    98100        return rc;
    99101}
  • uspace/lib/usb/src/recognise.c

    r3ae93a8 r357a302  
    3434 */
    3535#include <sys/types.h>
    36 #include <usb_iface.h>
    3736#include <usb/usbdrv.h>
    3837#include <usb/pipes.h>
    3938#include <usb/recognise.h>
     39#include <usb/ddfiface.h>
    4040#include <usb/request.h>
    4141#include <usb/classes/classes.h>
     
    4646static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    4747
    48 /** Callback for getting host controller handle.
    49  *
    50  * @param dev Device in question.
    51  * @param[out] handle Devman handle of the host controller.
    52  * @return Error code.
    53  */
    54 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
    55 {
    56         assert(dev);
    57         assert(dev->parent != NULL);
    58 
    59         device_t *parent = dev->parent;
    60 
    61         if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
    62                 usb_iface_t *usb_iface
    63                     = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
    64                 assert(usb_iface != NULL);
    65                 if (usb_iface->get_hc_handle) {
    66                         int rc = usb_iface->get_hc_handle(parent, handle);
    67                         return rc;
    68                 }
    69         }
    70 
    71         return ENOTSUP;
    72 }
    73 
    74 static usb_iface_t usb_iface = {
    75         .get_hc_handle = usb_iface_get_hc_handle
    76 };
    77 
    7848device_ops_t child_ops = {
    79         .interfaces[USB_DEV_IFACE] = &usb_iface
     49        .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
    8050};
    8151
Note: See TracChangeset for help on using the changeset viewer.