Changeset 20a3465 in mainline for uspace/lib/usbhost/include/usb


Ignore:
Timestamp:
2011-10-30T19:50:54Z (14 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3ce78580, 48902fa
Parents:
4c3ad56 (diff), 45bf63c (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 mainline changes

Location:
uspace/lib/usbhost/include/usb/host
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    r4c3ad56 r20a3465  
    3636#define LIBUSBHOST_HOST_ENDPOINT_H
    3737
    38 #include <assert.h>
    3938#include <bool.h>
    4039#include <adt/list.h>
    4140#include <fibril_synch.h>
    42 
    4341#include <usb/usb.h>
    4442
     43/** Host controller side endpoint structure. */
    4544typedef struct endpoint {
     45        /** Part of linked list. */
     46        link_t link;
     47        /** USB address. */
    4648        usb_address_t address;
     49        /** USB endpoint number. */
    4750        usb_endpoint_t endpoint;
     51        /** Communication direction. */
    4852        usb_direction_t direction;
     53        /** USB transfer type. */
    4954        usb_transfer_type_t transfer_type;
     55        /** Communication speed. */
    5056        usb_speed_t speed;
     57        /** Maximum size of data packets. */
    5158        size_t max_packet_size;
     59        /** Necessary bandwidth. */
     60        size_t bandwidth;
     61        /** Value of the toggle bit. */
    5262        unsigned toggle:1;
     63        /** True if there is a batch using this scheduled for this endpoint. */
     64        volatile bool active;
     65        /** Protects resources and active status changes. */
    5366        fibril_mutex_t guard;
     67        /** Signals change of active status. */
    5468        fibril_condvar_t avail;
    55         volatile bool active;
    56         void (*destroy_hook)(struct endpoint *);
     69        /** Optional device specific data. */
    5770        struct {
     71                /** Device specific data. */
    5872                void *data;
     73                /** Callback to get the value of toggle bit. */
    5974                int (*toggle_get)(void *);
     75                /** Callback to set the value of toggle bit. */
    6076                void (*toggle_set)(void *, int);
    6177        } hc_data;
    6278} endpoint_t;
    6379
    64 endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint,
     80endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
    6581    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
    66     size_t max_packet_size);
    67 
     82    size_t max_packet_size, size_t bw);
    6883void endpoint_destroy(endpoint_t *instance);
    6984
    7085void endpoint_set_hc_data(endpoint_t *instance,
    71     void *data, void (*destroy_hook)(endpoint_t *),
    72     int (*toggle_get)(void *), void (*toggle_set)(void *, int));
    73 
     86    void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int));
    7487void endpoint_clear_hc_data(endpoint_t *instance);
    7588
    7689void endpoint_use(endpoint_t *instance);
    77 
    7890void endpoint_release(endpoint_t *instance);
    7991
    8092int endpoint_toggle_get(endpoint_t *instance);
    81 
    8293void endpoint_toggle_set(endpoint_t *instance, int toggle);
    8394
    84 void endpoint_toggle_reset_filtered(endpoint_t *instance, usb_target_t target);
     95/** list_get_instance wrapper.
     96 * @param item Pointer to link member.
     97 * @return Pointer to enpoint_t structure.
     98 */
     99static inline endpoint_t * endpoint_get_instance(link_t *item)
     100{
     101        return list_get_instance(item, endpoint_t, link);
     102}
    85103#endif
    86104/**
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r4c3ad56 r20a3465  
    3737
    3838#include <assert.h>
     39#include <usbhc_iface.h>
     40
    3941#include <usb/host/usb_device_manager.h>
    4042#include <usb/host/usb_endpoint_manager.h>
    4143#include <usb/host/usb_transfer_batch.h>
    42 #include <usbhc_iface.h>
    4344
    4445typedef struct hcd hcd_t;
    4546
     47/** Generic host controller driver structure. */
    4648struct hcd {
     49        /** Device manager storing handles and addresses. */
    4750        usb_device_manager_t dev_manager;
     51        /** Endpoint manager. */
    4852        usb_endpoint_manager_t ep_manager;
     53
     54        /** Device specific driver data. */
    4955        void *private_data;
    50 
     56        /** Transfer scheduling, implement in device driver. */
    5157        int (*schedule)(hcd_t *, usb_transfer_batch_t *);
     58        /** Hook called upon registering new endpoint. */
    5259        int (*ep_add_hook)(hcd_t *, endpoint_t *);
     60        /** Hook called upon removing of an endpoint. */
     61        void (*ep_remove_hook)(hcd_t *, endpoint_t *);
    5362};
    5463/*----------------------------------------------------------------------------*/
    55 static inline int hcd_init(hcd_t *hcd, size_t bandwidth,
     64/** Initialize hcd_t structure.
     65 * Initializes device and endpoint managers. Sets data nd hook pointer to NULL.
     66 * @param hcd hcd_t structure to initialize, non-null.
     67 * @param bandwidth Available bandwidth, passed to endpoint manager.
     68 * @param bw_count Bandwidth compute function, passed to endpoint manager.
     69 */
     70static inline void hcd_init(hcd_t *hcd, size_t bandwidth,
    5671    size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t))
    5772{
    5873        assert(hcd);
    5974        usb_device_manager_init(&hcd->dev_manager);
    60         return usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);
     75        usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);
     76        hcd->private_data = NULL;
     77        hcd->schedule = NULL;
     78        hcd->ep_add_hook = NULL;
     79        hcd->ep_remove_hook = NULL;
    6180}
    6281/*----------------------------------------------------------------------------*/
    63 static inline void hcd_destroy(hcd_t *hcd)
    64 {
    65         usb_endpoint_manager_destroy(&hcd->ep_manager);
    66 }
    67 /*----------------------------------------------------------------------------*/
    68 static inline void reset_ep_if_need(
    69     hcd_t *hcd, usb_target_t target, const char* setup_data)
     82/** Check registered endpoints and reset toggle bit if necessary.
     83 * @param hcd hcd_t structure, non-null.
     84 * @param target Control communication target.
     85 * @param setup_data Setup packet of the control communication.
     86 */
     87static inline void reset_ep_if_need(hcd_t *hcd, usb_target_t target,
     88    const char setup_data[8])
    7089{
    7190        assert(hcd);
    72         usb_endpoint_manager_reset_if_need(
     91        usb_endpoint_manager_reset_eps_if_need(
    7392            &hcd->ep_manager, target, (const uint8_t *)setup_data);
    7493}
    7594/*----------------------------------------------------------------------------*/
    76 static inline hcd_t * fun_to_hcd(ddf_fun_t *fun)
     95/** Data retrieve wrapper.
     96 * @param fun ddf function, non-null.
     97 * @return pointer cast to hcd_t*.
     98 */
     99static inline hcd_t * fun_to_hcd(const ddf_fun_t *fun)
    77100{
    78101        assert(fun);
  • uspace/lib/usbhost/include/usb/host/usb_device_manager.h

    r4c3ad56 r20a3465  
    4949#define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1)
    5050
    51 /** Information about attached USB device. */
    52 struct usb_device_info {
    53         usb_speed_t speed;
    54         bool occupied;
    55         devman_handle_t handle;
    56 };
    57 
    5851/** Host controller device manager.
    59  * You shall not access members directly but only using functions below.
     52 * You shall not access members directly.
    6053 */
    6154typedef struct {
    62         struct usb_device_info devices[USB_ADDRESS_COUNT];
     55        /** Information about attached USB devices. */
     56        struct {
     57                usb_speed_t speed;      /**< Device speed */
     58                bool occupied;          /**< The address is in use. */
     59                devman_handle_t handle; /**< Devman handle of the device. */
     60        } devices[USB_ADDRESS_COUNT];
    6361        fibril_mutex_t guard;
     62        /** The last reserved address */
    6463        usb_address_t last_address;
    6564} usb_device_manager_t;
     
    7069    usb_device_manager_t *instance, usb_speed_t speed);
    7170
    72 void usb_device_manager_bind(usb_device_manager_t *instance,
     71int usb_device_manager_bind(usb_device_manager_t *instance,
    7372    usb_address_t address, devman_handle_t handle);
    7473
    75 void usb_device_manager_release(usb_device_manager_t *instance,
     74int usb_device_manager_release(usb_device_manager_t *instance,
    7675    usb_address_t address);
    7776
    78 usb_address_t usb_device_manager_find(usb_device_manager_t *instance,
     77usb_address_t usb_device_manager_find_address(usb_device_manager_t *instance,
    7978    devman_handle_t handle);
    8079
    81 bool usb_device_manager_find_by_address(usb_device_manager_t *instance,
    82     usb_address_t address, devman_handle_t *handle);
    83 
    84 usb_speed_t usb_device_manager_get_speed(usb_device_manager_t *instance,
    85     usb_address_t address);
     80int usb_device_manager_get_info_by_address(usb_device_manager_t *instance,
     81    usb_address_t address, devman_handle_t *handle, usb_speed_t *speed);
    8682#endif
    8783/**
  • uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h

    r4c3ad56 r20a3465  
    4040#define LIBUSBHOST_HOST_USB_ENDPOINT_MANAGER_H
    4141
    42 #include <stdlib.h>
    43 #include <adt/hash_table.h>
     42#include <adt/list.h>
    4443#include <fibril_synch.h>
    4544#include <usb/usb.h>
     45
    4646#include <usb/host/endpoint.h>
    4747
    48 #define BANDWIDTH_TOTAL_USB11 12000000
     48/** Bytes per second in FULL SPEED */
     49#define BANDWIDTH_TOTAL_USB11 (12000000 / 8)
     50/** 90% of total bandwidth is available for periodic transfers */
    4951#define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9)
     52/** 16 addresses per list */
     53#define ENDPOINT_LIST_COUNT 8
    5054
     55/** Endpoint management structure */
    5156typedef struct usb_endpoint_manager {
    52         hash_table_t ep_table;
     57        /** Store endpoint_t instances */
     58        list_t endpoint_lists[ENDPOINT_LIST_COUNT];
     59        /** Prevents races accessing lists */
    5360        fibril_mutex_t guard;
     61        /** Size of the bandwidth pool */
    5462        size_t free_bw;
     63        /** Use this function to count bw required by EP */
    5564        size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t);
    5665} usb_endpoint_manager_t;
     
    6372    size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t));
    6473
    65 void usb_endpoint_manager_destroy(usb_endpoint_manager_t *instance);
     74void usb_endpoint_manager_reset_eps_if_need(usb_endpoint_manager_t *instance,
     75    usb_target_t target, const uint8_t data[8]);
    6676
    67 int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance,
    68     endpoint_t *ep, size_t data_size);
    69 
    70 int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance,
     77int usb_endpoint_manager_register_ep(
     78    usb_endpoint_manager_t *instance, endpoint_t *ep, size_t data_size);
     79int usb_endpoint_manager_unregister_ep(
     80    usb_endpoint_manager_t *instance, endpoint_t *ep);
     81endpoint_t * usb_endpoint_manager_find_ep(usb_endpoint_manager_t *instance,
    7182    usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
    7283
    73 endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,
    74     usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,
    75     size_t *bw);
    76 
    77 void usb_endpoint_manager_reset_if_need(
    78     usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data);
    79 
    80 /** Wrapper combining allocation and insertion */
    81 static inline int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
     84int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
    8285    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
    8386    usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,
    84     size_t data_size)
    85 {
    86         endpoint_t *ep = endpoint_get(
    87             address, endpoint, direction, type, speed, max_packet_size);
    88         if (!ep)
    89                 return ENOMEM;
     87    size_t data_size, int (*callback)(endpoint_t *, void *), void *arg);
    9088
    91         const int ret =
    92             usb_endpoint_manager_register_ep(instance, ep, data_size);
    93         if (ret != EOK) {
    94                 endpoint_destroy(ep);
    95         }
    96         return ret;
    97 }
     89int usb_endpoint_manager_remove_ep(usb_endpoint_manager_t *instance,
     90    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
     91    void (*callback)(endpoint_t *, void *), void *arg);
    9892#endif
    9993/**
    10094 * @}
    10195 */
    102 
  • uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h

    r4c3ad56 r20a3465  
    4343#define USB_SETUP_PACKET_SIZE 8
    4444
    45 typedef struct usb_transfer_batch usb_transfer_batch_t;
    4645/** Structure stores additional data needed for communication with EP */
    47 struct usb_transfer_batch {
     46typedef struct usb_transfer_batch {
    4847        /** Endpoint used for communication */
    4948        endpoint_t *ep;
     
    7776        /** Callback to properly remove driver data during destruction */
    7877        void (*private_data_dtor)(void *p_data);
    79 };
     78} usb_transfer_batch_t;
    8079
    8180/** Printf formatting string for dumping usb_transfer_batch_t. */
     
    9392
    9493
    95 usb_transfer_batch_t * usb_transfer_batch_get(
     94usb_transfer_batch_t * usb_transfer_batch_create(
    9695    endpoint_t *ep,
    9796    char *buffer,
     
    105104    void (*private_data_dtor)(void *p_data)
    106105);
     106void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance);
    107107
    108 void usb_transfer_batch_finish(usb_transfer_batch_t *instance,
     108void usb_transfer_batch_finish(const usb_transfer_batch_t *instance,
    109109    const void* data, size_t size);
    110 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
    111 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
    112 void usb_transfer_batch_dispose(usb_transfer_batch_t *instance);
    113 
    114 /** Helper function, calls callback and correctly destroys batch structure.
    115  *
    116  * @param[in] instance Batch structure to use.
    117  */
    118 static inline void usb_transfer_batch_call_in_and_dispose(
    119     usb_transfer_batch_t *instance)
    120 {
    121         assert(instance);
    122         usb_transfer_batch_call_in(instance);
    123         usb_transfer_batch_dispose(instance);
    124 }
    125110/*----------------------------------------------------------------------------*/
    126 /** Helper function calls callback and correctly destroys batch structure.
    127  *
    128  * @param[in] instance Batch structure to use.
    129  */
    130 static inline void usb_transfer_batch_call_out_and_dispose(
    131     usb_transfer_batch_t *instance)
    132 {
    133         assert(instance);
    134         usb_transfer_batch_call_out(instance);
    135         usb_transfer_batch_dispose(instance);
    136 }
    137 /*----------------------------------------------------------------------------*/
    138 /** Helper function, sets error value and finishes transfer.
     111/** Override error value and finishes transfer.
    139112 *
    140113 * @param[in] instance Batch structure to use.
     
    151124}
    152125/*----------------------------------------------------------------------------*/
    153 /** Helper function, determines batch direction absed on the present callbacks
    154  * @param[in] instance Batch structure to use.
     126/** Determine batch direction based on the callbacks present
     127 * @param[in] instance Batch structure to use, non-null.
    155128 * @return USB_DIRECTION_IN, or USB_DIRECTION_OUT.
    156129 */
Note: See TracChangeset for help on using the changeset viewer.