Changes in uspace/lib/usbhost/include/usb/host/hcd.h [ae3a941:b7fd2a0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/hcd.h
rae3a941 rb7fd2a0 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2018 Ondrej Hlavaty4 3 * All rights reserved. 5 4 * … … 38 37 #define LIBUSBHOST_HOST_HCD_H 39 38 40 #include <ddf/driver.h> 41 #include <usb/request.h> 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> 42 43 43 typedef struct hw_resource_list_parsed hw_res_list_parsed_t; 44 typedef struct bus bus_t; 45 typedef struct device device_t; 44 #include <assert.h> 45 #include <usbhc_iface.h> 46 #include <stddef.h> 47 #include <stdint.h> 46 48 47 /* Treat this header as read-only in driver code. 48 * It could be opaque, but why to complicate matters. 49 */ 50 typedef struct hc_device { 51 /* Bus instance */ 52 bus_t *bus; 49 typedef struct hcd hcd_t; 53 50 54 /* Managed DDF device */ 55 ddf_dev_t *ddf_dev; 51 typedef errno_t (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *); 52 typedef errno_t (*ep_add_hook_t)(hcd_t *, endpoint_t *); 53 typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *); 54 typedef void (*interrupt_hook_t)(hcd_t *, uint32_t); 55 typedef errno_t (*status_hook_t)(hcd_t *, uint32_t *); 56 56 57 /* Control function */ 58 ddf_fun_t *ctl_fun; 57 typedef struct { 58 /** Transfer scheduling, implement in device driver. */ 59 schedule_hook_t schedule; 60 /** Hook called upon registering new endpoint. */ 61 ep_add_hook_t ep_add_hook; 62 /** Hook called upon removing of an endpoint. */ 63 ep_remove_hook_t ep_remove_hook; 64 /** Hook to be called on device interrupt, passes ARG1 */ 65 interrupt_hook_t irq_hook; 66 /** Periodic polling hook */ 67 status_hook_t status_hook; 68 } hcd_ops_t; 59 69 60 /* Result of enabling HW IRQs */ 61 int irq_cap; 70 /** Generic host controller driver structure. */ 71 struct hcd { 72 /** Endpoint manager. */ 73 usb_bus_t bus; 62 74 63 75 /** Interrupt replacement fibril */ 64 76 fid_t polling_fibril; 65 77 66 /* This structure is meant to be extended by driver code. */ 67 } hc_device_t; 78 /** Driver implementation */ 79 hcd_ops_t ops; 80 /** Device specific driver data. */ 81 void * driver_data; 82 }; 68 83 69 typedef struct hc_driver { 70 const char *name; 84 extern void hcd_init(hcd_t *, usb_speed_t, size_t, bw_count_func_t); 71 85 72 /** Size of the device data to be allocated, and passed as the 73 * hc_device_t. */ 74 size_t hc_device_size; 75 76 /** Initialize device structures. */ 77 int (*hc_add)(hc_device_t *, const hw_res_list_parsed_t *); 78 79 /** Generate IRQ code to handle interrupts. */ 80 int (*irq_code_gen)(irq_code_t *, hc_device_t *, 81 const hw_res_list_parsed_t *, int *); 82 83 /** Claim device from BIOS. */ 84 int (*claim)(hc_device_t *); 85 86 /** Start the host controller. */ 87 int (*start)(hc_device_t *); 88 89 /** Setup the virtual roothub. */ 90 int (*setup_root_hub)(hc_device_t *); 91 92 /** Stop the host controller (after start has been called) */ 93 int (*stop)(hc_device_t *); 94 95 /** HC was asked to be removed (after hc_add has been called) */ 96 int (*hc_remove)(hc_device_t *); 97 98 /** HC is gone. */ 99 int (*hc_gone)(hc_device_t *); 100 } hc_driver_t; 101 102 /* Drivers should call this before leaving hc_add */ 103 static inline void hc_device_setup(hc_device_t *hcd, bus_t *bus) 86 static inline void hcd_set_implementation(hcd_t *hcd, void *data, 87 const hcd_ops_t *ops) 104 88 { 105 hcd->bus = bus; 89 assert(hcd); 90 if (ops) { 91 hcd->driver_data = data; 92 hcd->ops = *ops; 93 } else { 94 memset(&hcd->ops, 0, sizeof(hcd->ops)); 95 } 106 96 } 107 97 108 static inline hc_device_t *dev_to_hcd(ddf_dev_t *dev)98 static inline void * hcd_get_driver_data(hcd_t *hcd) 109 99 { 110 return ddf_dev_data_get(dev); 100 assert(hcd); 101 return hcd->driver_data; 111 102 } 112 103 113 extern errno_t hc_driver_main(const hc_driver_t *); 104 extern errno_t hcd_request_address(hcd_t *, usb_speed_t, usb_address_t *); 105 106 extern errno_t hcd_release_address(hcd_t *, usb_address_t); 107 108 extern errno_t hcd_reserve_default_address(hcd_t *, usb_speed_t); 109 110 static inline errno_t hcd_release_default_address(hcd_t *hcd) 111 { 112 return hcd_release_address(hcd, USB_ADDRESS_DEFAULT); 113 } 114 115 extern errno_t hcd_add_ep(hcd_t *, usb_target_t, usb_direction_t, 116 usb_transfer_type_t, size_t, unsigned int, size_t, usb_address_t, 117 unsigned int); 118 119 extern errno_t hcd_remove_ep(hcd_t *, usb_target_t, usb_direction_t); 120 121 extern errno_t hcd_send_batch(hcd_t *, usb_target_t, usb_direction_t, void *, 122 size_t, uint64_t, usbhc_iface_transfer_in_callback_t, 123 usbhc_iface_transfer_out_callback_t, void *, const char *); 124 125 extern errno_t hcd_send_batch_sync(hcd_t *, usb_target_t, usb_direction_t, 126 void *, size_t, uint64_t, const char *, size_t *); 114 127 115 128 #endif
Note:
See TracChangeset
for help on using the changeset viewer.