Changeset 32fb6bce in mainline for uspace/lib/usbhost/include
- Timestamp:
- 2017-12-18T22:50:21Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f70d1c
- Parents:
- 1ea0bbf
- git-author:
- Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
- Location:
- uspace/lib/usbhost/include/usb/host
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/bus.h
r1ea0bbf r32fb6bce 43 43 #define LIBUSBHOST_HOST_BUS_H 44 44 45 #include <usb/usb.h>46 #include <usb/request.h>47 #include <usb/host/hcd.h>48 49 45 #include <assert.h> 50 46 #include <fibril_synch.h> 51 47 #include <stdbool.h> 48 #include <usb/host/hcd.h> 49 #include <usb/request.h> 50 #include <usb/usb.h> 51 #include <usbhc_iface.h> 52 52 53 53 typedef struct hcd hcd_t; … … 94 94 95 95 /* Global operations on the bus */ 96 void (*interrupt)(bus_t *, uint32_t); 97 int (*status)(bus_t *, uint32_t *); 96 98 int (*reserve_default_address)(bus_t *, usb_speed_t); 97 99 int (*release_default_address)(bus_t *); … … 116 118 117 119 /* Operations on batch */ 118 void (*batch_destroy)(usb_transfer_batch_t *); /**< Optional */ 120 void (*batch_destroy)(usb_transfer_batch_t *); /**< Optional */ 121 int (*batch_schedule)(usb_transfer_batch_t *); 119 122 }; 120 123 … … 129 132 fibril_mutex_t guard; 130 133 131 /* TODO: get rid of this one. */ 132 hcd_t *hcd; 133 134 /* Size of the device_t extended structure */ 134 135 size_t device_size; 135 136 … … 140 141 } bus_t; 141 142 142 void bus_init(bus_t *, hcd_t *,size_t);143 void bus_init(bus_t *, size_t); 143 144 int bus_device_init(device_t *, bus_t *); 144 145 … … 150 151 int bus_device_online(device_t *); 151 152 int bus_device_offline(device_t *); 153 154 int bus_device_send_batch(device_t *, usb_target_t, 155 usb_direction_t direction, char *, size_t, uint64_t, 156 usbhc_iface_transfer_callback_t, void *, const char *); 157 158 ssize_t bus_device_send_batch_sync(device_t *, usb_target_t, 159 usb_direction_t direction, char *, size_t, uint64_t, 160 const char *); 152 161 153 162 int bus_endpoint_add(device_t *, const usb_endpoint_desc_t *, endpoint_t **); -
uspace/lib/usbhost/include/usb/host/ddf_helpers.h
r1ea0bbf r32fb6bce 39 39 #include <ddf/driver.h> 40 40 #include <ddf/interrupt.h> 41 #include <device/hw_res_parsed.h>42 41 #include <usb/usb.h> 43 42 44 43 #include <usb/host/hcd.h> 45 44 46 typedef int (*driver_init_t)(hcd_t *, const hw_res_list_parsed_t *, ddf_dev_t *); 47 typedef int (*irq_code_gen_t)(irq_code_t *, hcd_t *, const hw_res_list_parsed_t *); 48 typedef int (*claim_t)(hcd_t *, ddf_dev_t *); 49 typedef int (*driver_start_t)(hcd_t *, bool irq); 50 typedef int (*setup_root_hub_t)(hcd_t *, ddf_dev_t *); 45 int hcd_ddf_setup_hc(ddf_dev_t *, size_t); 46 void hcd_ddf_clean_hc(hc_device_t *); 51 47 52 typedef void (*driver_stop_t)(hcd_t *); 53 typedef void (*driver_fini_t)(hcd_t *); 48 int hcd_setup_virtual_root_hub(hc_device_t *); 54 49 55 /** 56 * All callbacks are optional. 57 */ 58 typedef struct { 59 hcd_ops_t ops; 60 const char *name; 50 device_t *hcd_ddf_fun_create(hc_device_t *); 51 void hcd_ddf_fun_destroy(device_t *); 61 52 62 interrupt_handler_t *irq_handler; /**< Handler of IRQ. Do have generic implementation. */ 53 int hcd_device_explore(device_t *); 63 54 64 /* Initialization sequence: */ 65 driver_init_t init; /**< Initialize internal structures, memory */ 66 claim_t claim; /**< Claim device from BIOS */ 67 irq_code_gen_t irq_code_gen; /**< Generate IRQ handling code */ 68 driver_start_t start; /**< Start the HC */ 69 setup_root_hub_t setup_root_hub; /**< Setup the root hub */ 55 int hcd_ddf_enable_interrupt(hc_device_t *hcd, int); 56 int hcd_ddf_get_registers(hc_device_t *hcd, hw_res_list_parsed_t *hw_res); 70 57 71 /* Destruction sequence: */ 72 driver_stop_t stop; /**< Stop the HC (counterpart of start) */ 73 driver_fini_t fini; /**< Destroy internal structures (counterpart of init) */ 74 } ddf_hc_driver_t; 75 76 int hcd_ddf_add_hc(ddf_dev_t *device, const ddf_hc_driver_t *driver); 77 78 int hcd_ddf_setup_hc(ddf_dev_t *device); 79 void hcd_ddf_clean_hc(ddf_dev_t *device); 80 81 int hcd_setup_virtual_root_hub(hcd_t *, ddf_dev_t *); 82 83 device_t *hcd_ddf_device_create(ddf_dev_t *, bus_t *); 84 void hcd_ddf_device_destroy(device_t *); 85 int hcd_ddf_device_explore(device_t *); 86 int hcd_ddf_device_online(ddf_fun_t *); 87 int hcd_ddf_device_offline(ddf_fun_t *); 88 89 hcd_t *dev_to_hcd(ddf_dev_t *dev); 90 91 int hcd_ddf_enable_interrupt(ddf_dev_t *device, int); 92 int hcd_ddf_get_registers(ddf_dev_t *device, hw_res_list_parsed_t *hw_res); 93 int hcd_ddf_setup_interrupts(ddf_dev_t *device, 94 const hw_res_list_parsed_t *hw_res, 95 interrupt_handler_t handler, 96 irq_code_gen_t gen_irq_code); 97 void ddf_hcd_gen_irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev); 58 void hcd_ddf_gen_irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev); 98 59 99 60 #endif -
uspace/lib/usbhost/include/usb/host/endpoint.h
r1ea0bbf r32fb6bce 109 109 ssize_t endpoint_count_bw(endpoint_t *, size_t); 110 110 111 int endpoint_send_batch(endpoint_t *, usb_target_t, usb_direction_t, 112 char *, size_t, uint64_t, usbhc_iface_transfer_callback_t, void *, 113 const char *); 114 111 115 static inline bus_t *endpoint_get_bus(endpoint_t *ep) 112 116 { -
uspace/lib/usbhost/include/usb/host/hcd.h
r1ea0bbf r32fb6bce 37 37 #define LIBUSBHOST_HOST_HCD_H 38 38 39 #include <assert.h> 40 #include <mem.h> 41 #include <stddef.h> 42 #include <stdint.h> 43 #include <usb/usb.h> 44 #include <usbhc_iface.h> 39 #include <ddf/driver.h> 40 #include <usb/request.h> 45 41 46 typedef struct h cd hcd_t;42 typedef struct hw_resource_list_parsed hw_res_list_parsed_t; 47 43 typedef struct bus bus_t; 48 44 typedef struct device device_t; 49 typedef struct usb_transfer_batch usb_transfer_batch_t;50 45 51 typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *); 52 typedef void (*interrupt_hook_t)(hcd_t *, uint32_t); 53 typedef int (*status_hook_t)(hcd_t *, uint32_t *); 46 /* Treat this header as read-only in driver code. 47 * It could be opaque, but why to complicate matters. 48 */ 49 typedef struct hc_device { 50 /* Bus instance */ 51 bus_t *bus; 54 52 55 typedef struct { 56 /** Transfer scheduling, implement in device driver. */ 57 schedule_hook_t schedule; 58 /** Hook to be called on device interrupt, passes ARG1 */ 59 interrupt_hook_t irq_hook; 60 /** Periodic polling hook */ 61 status_hook_t status_hook; 62 } hcd_ops_t; 53 /* Managed DDF device */ 54 ddf_dev_t *ddf_dev; 63 55 64 /** Generic host controller driver structure. */ 65 struct hcd { 66 /** Endpoint manager. */ 67 bus_t *bus; 56 /* Control function */ 57 ddf_fun_t *ctl_fun; 58 59 /* Result of enabling HW IRQs */ 60 int irq_cap; 68 61 69 62 /** Interrupt replacement fibril */ 70 63 fid_t polling_fibril; 71 64 72 /* * Driver implementation*/73 hcd_ops_t ops;65 /* This structure is meant to be extended by driver code. */ 66 } hc_device_t; 74 67 75 /** Device specific driver data. */ 76 void * driver_data; 77 }; 68 typedef struct hc_driver { 69 const char *name; 78 70 79 extern void hcd_init(hcd_t *); 71 /** Size of the device data to be allocated, and passed as the 72 * hc_device_t. */ 73 size_t hc_device_size; 80 74 81 static inline void hcd_set_implementation(hcd_t *hcd, void *data, 82 const hcd_ops_t *ops, bus_t *bus) 83 { 84 assert(hcd); 85 if (ops) { 86 hcd->driver_data = data; 87 hcd->ops = *ops; 88 hcd->bus = bus; 89 } else { 90 memset(&hcd->ops, 0, sizeof(hcd->ops)); 91 } 75 /** Initialize device structures. */ 76 int (*hc_add)(hc_device_t *, const hw_res_list_parsed_t *); 77 78 /** Generate IRQ code to handle interrupts. */ 79 int (*irq_code_gen)(irq_code_t *, hc_device_t *, const hw_res_list_parsed_t *); 80 81 /** Claim device from BIOS. */ 82 int (*claim)(hc_device_t *); 83 84 /** Start the host controller. */ 85 int (*start)(hc_device_t *); 86 87 /** Setup the virtual roothub. */ 88 int (*setup_root_hub)(hc_device_t *); 89 90 /** Stop the host controller (after start has been called) */ 91 int (*stop)(hc_device_t *); 92 93 /** HC was asked to be removed (after hc_add has been called) */ 94 int (*hc_remove)(hc_device_t *); 95 96 /** HC is gone. */ 97 int (*hc_gone)(hc_device_t *); 98 } hc_driver_t; 99 100 /* Drivers should call this before leaving hc_add */ 101 static inline void hc_device_setup(hc_device_t *hcd, bus_t *bus) { 102 hcd->bus = bus; 92 103 } 93 104 94 static inline void * hcd_get_driver_data(hcd_t *hcd)105 static inline hc_device_t *dev_to_hcd(ddf_dev_t *dev) 95 106 { 96 assert(hcd); 97 return hcd->driver_data; 107 return ddf_dev_data_get(dev); 98 108 } 99 109 100 extern int hcd_get_ep0_max_packet_size(uint16_t *, hcd_t *, device_t *); 110 int hc_driver_main(const hc_driver_t *); 111 112 /* TODO: These are a kind of utility functions, they should probably go 113 * somewhere else. 114 */ 115 extern int hcd_get_ep0_max_packet_size(uint16_t *, bus_t *, device_t *); 101 116 extern void hcd_setup_device_tt(device_t *); 102 103 extern int hcd_send_batch(hcd_t *, device_t *, usb_target_t,104 usb_direction_t direction, char *, size_t, uint64_t,105 usbhc_iface_transfer_callback_t, void *, const char *);106 107 extern ssize_t hcd_send_batch_sync(hcd_t *, device_t *, usb_target_t,108 usb_direction_t direction, char *, size_t, uint64_t,109 const char *);110 117 111 118 /** How many toggles need to be reset */ … … 116 123 } toggle_reset_mode_t; 117 124 125 extern toggle_reset_mode_t hcd_get_request_toggle_reset_mode( 126 const usb_device_request_setup_packet_t *request); 127 118 128 #endif 119 129 -
uspace/lib/usbhost/include/usb/host/usb2_bus.h
r1ea0bbf r32fb6bce 66 66 extern const bus_ops_t usb2_bus_ops; 67 67 68 extern int usb2_bus_init(usb2_bus_t *, hcd_t *,size_t);68 extern int usb2_bus_init(usb2_bus_t *, size_t); 69 69 70 70 #endif
Note:
See TracChangeset
for help on using the changeset viewer.