Changes in uspace/lib/usbhost/include/usb/host/hcd.h [56fd7cf:58563585] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/hcd.h
r56fd7cf r58563585 37 37 #define LIBUSBHOST_HOST_HCD_H 38 38 39 #include <usb/host/endpoint.h> 40 #include <usb/host/usb_bus.h> 41 #include <usb/host/usb_transfer_batch.h> 42 #include <usb/usb.h> 43 39 44 #include <assert.h> 40 45 #include <usbhc_iface.h> 41 42 #include <usb/host/usb_device_manager.h> 43 #include <usb/host/usb_endpoint_manager.h> 44 #include <usb/host/usb_transfer_batch.h> 46 #include <sys/types.h> 45 47 46 48 typedef struct hcd hcd_t; 47 49 50 typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *); 51 typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *); 52 typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *); 53 typedef void (*interrupt_hook_t)(hcd_t *, uint32_t); 54 typedef int (*status_hook_t)(hcd_t *, uint32_t *); 55 56 typedef struct { 57 /** Transfer scheduling, implement in device driver. */ 58 schedule_hook_t schedule; 59 /** Hook called upon registering new endpoint. */ 60 ep_add_hook_t ep_add_hook; 61 /** Hook called upon removing of an endpoint. */ 62 ep_remove_hook_t ep_remove_hook; 63 /** Hook to be called on device interrupt, passes ARG1 */ 64 interrupt_hook_t irq_hook; 65 /** Periodic polling hook */ 66 status_hook_t status_hook; 67 } hcd_ops_t; 68 48 69 /** Generic host controller driver structure. */ 49 70 struct hcd { 50 /** Device manager storing handles and addresses. */51 usb_device_manager_t dev_manager;52 71 /** Endpoint manager. */ 53 usb_ endpoint_manager_t ep_manager;72 usb_bus_t bus; 54 73 74 /** Interrupt replacement fibril */ 75 fid_t polling_fibril; 76 77 /** Driver implementation */ 78 hcd_ops_t ops; 55 79 /** Device specific driver data. */ 56 void *private_data; 57 /** Transfer scheduling, implement in device driver. */ 58 int (*schedule)(hcd_t *, usb_transfer_batch_t *); 59 /** Hook called upon registering new endpoint. */ 60 int (*ep_add_hook)(hcd_t *, endpoint_t *); 61 /** Hook called upon removing of an endpoint. */ 62 void (*ep_remove_hook)(hcd_t *, endpoint_t *); 80 void * driver_data; 63 81 }; 64 82 65 /** Initialize hcd_t structure. 66 * Initializes device and endpoint managers. Sets data and hook pointer to NULL. 67 * @param hcd hcd_t structure to initialize, non-null. 68 * @param bandwidth Available bandwidth, passed to endpoint manager. 69 * @param bw_count Bandwidth compute function, passed to endpoint manager. 70 */ 71 static inline void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth, 72 size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t)) 83 extern void hcd_init(hcd_t *, usb_speed_t, size_t, bw_count_func_t); 84 85 static inline void hcd_set_implementation(hcd_t *hcd, void *data, 86 const hcd_ops_t *ops) 73 87 { 74 88 assert(hcd); 75 usb_device_manager_init(&hcd->dev_manager, max_speed);76 usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);77 hcd->private_data = NULL;78 hcd->schedule = NULL;79 hcd->ep_add_hook = NULL;80 hcd->ep_remove_hook = NULL;89 if (ops) { 90 hcd->driver_data = data; 91 hcd->ops = *ops; 92 } else { 93 memset(&hcd->ops, 0, sizeof(hcd->ops)); 94 } 81 95 } 82 96 83 /** Check registered endpoints and reset toggle bit if necessary. 84 * @param hcd hcd_t structure, non-null. 85 * @param target Control communication target. 86 * @param setup_data Setup packet of the control communication. 87 */ 88 static inline void reset_ep_if_need(hcd_t *hcd, usb_target_t target, 89 const char setup_data[8]) 97 static inline void * hcd_get_driver_data(hcd_t *hcd) 90 98 { 91 99 assert(hcd); 92 usb_endpoint_manager_reset_eps_if_need( 93 &hcd->ep_manager, target, (const uint8_t *)setup_data); 100 return hcd->driver_data; 94 101 } 95 102 96 /** Data retrieve wrapper. 97 * @param fun ddf function, non-null. 98 * @return pointer cast to hcd_t*. 99 */ 100 static inline hcd_t *fun_to_hcd(ddf_fun_t *fun) 103 extern usb_address_t hcd_request_address(hcd_t *, usb_speed_t); 104 105 extern int hcd_release_address(hcd_t *, usb_address_t); 106 107 extern int hcd_reserve_default_address(hcd_t *, usb_speed_t); 108 109 static inline int hcd_release_default_address(hcd_t *hcd) 101 110 { 102 return ddf_fun_data_get(fun);111 return hcd_release_address(hcd, USB_ADDRESS_DEFAULT); 103 112 } 104 113 105 extern usbhc_iface_t hcd_iface; 114 extern int hcd_add_ep(hcd_t *, usb_target_t, usb_direction_t, 115 usb_transfer_type_t, size_t, unsigned int, size_t, usb_address_t, 116 unsigned int); 117 118 extern int hcd_remove_ep(hcd_t *, usb_target_t, usb_direction_t); 119 120 extern int hcd_send_batch(hcd_t *, usb_target_t, usb_direction_t, void *, 121 size_t, uint64_t, usbhc_iface_transfer_in_callback_t, 122 usbhc_iface_transfer_out_callback_t, void *, const char *); 123 124 extern ssize_t hcd_send_batch_sync(hcd_t *, usb_target_t, usb_direction_t, 125 void *, size_t, uint64_t, const char *); 106 126 107 127 #endif
Note:
See TracChangeset
for help on using the changeset viewer.