Changeset b4b534ac in mainline for uspace/lib/usbhost/include
- Timestamp:
- 2016-07-22T08:24:47Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f76d2c2
- Parents:
- 5b18137 (diff), 8351f9a4 (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. - Location:
- uspace/lib/usbhost/include/usb/host
- Files:
-
- 1 deleted
- 3 edited
- 3 moved
-
ddf_helpers.h (moved) (moved from uspace/drv/bus/usb/ohci/res.h ) (2 diffs)
-
endpoint.h (modified) (3 diffs)
-
hcd.h (modified) (1 diff)
-
usb_bus.h (moved) (moved from uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h ) (3 diffs)
-
usb_device_manager.h (deleted)
-
usb_transfer_batch.h (modified) (4 diffs)
-
utils/malloc32.h (moved) (moved from uspace/drv/bus/usb/ohci/utils/malloc32.h ) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/ddf_helpers.h
r5b18137 rb4b534ac 1 1 /* 2 * Copyright (c) 201 1 Vojtech Horky2 * Copyright (c) 2012 Jan Vesely 3 3 * All rights reserved. 4 4 * … … 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusbohci 28 29 /** @addtogroup libusbhost 29 30 * @{ 30 31 */ 31 32 /** @file 32 * PCI related functions needed by OHCI driver.33 * 33 34 */ 34 #ifndef DRV_OHCI_RES_H 35 #define DRV_OHCI_RES_H 35 36 #ifndef LIBUSBHOST_HOST_DDF_HELPERS_H 37 #define LIBUSBHOST_HOST_DDF_HELPERS_H 38 39 #include <usb/host/hcd.h> 40 #include <usb/host/usb_bus.h> 41 #include <usb/usb.h> 36 42 37 43 #include <ddf/driver.h> 44 #include <ddf/interrupt.h> 38 45 #include <device/hw_res_parsed.h> 39 46 40 int get_my_registers(ddf_dev_t *, addr_range_t *, int *); 41 int enable_interrupts(ddf_dev_t *); 47 typedef int (*driver_init_t)(hcd_t *, const hw_res_list_parsed_t *, bool); 48 typedef void (*driver_fini_t)(hcd_t *); 49 typedef int (*claim_t)(ddf_dev_t *); 50 typedef int (*irq_code_gen_t)(irq_code_t *, const hw_res_list_parsed_t *); 51 52 typedef struct { 53 hcd_ops_t ops; 54 claim_t claim; 55 usb_speed_t hc_speed; 56 driver_init_t init; 57 driver_fini_t fini; 58 interrupt_handler_t *irq_handler; 59 irq_code_gen_t irq_code_gen; 60 const char *name; 61 } ddf_hc_driver_t; 62 63 int hcd_ddf_add_hc(ddf_dev_t *device, const ddf_hc_driver_t *driver); 64 65 int hcd_ddf_setup_hc(ddf_dev_t *device, usb_speed_t max_speed, 66 size_t bw, bw_count_func_t bw_count); 67 void hcd_ddf_clean_hc(ddf_dev_t *device); 68 int hcd_ddf_setup_root_hub(ddf_dev_t *device); 69 70 hcd_t *dev_to_hcd(ddf_dev_t *dev); 71 72 int hcd_ddf_enable_interrupts(ddf_dev_t *device); 73 int hcd_ddf_get_registers(ddf_dev_t *device, hw_res_list_parsed_t *hw_res); 74 int hcd_ddf_setup_interrupts(ddf_dev_t *device, 75 const hw_res_list_parsed_t *hw_res, 76 interrupt_handler_t handler, 77 int (*gen_irq_code)(irq_code_t *, const hw_res_list_parsed_t *)); 78 void ddf_hcd_gen_irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev); 42 79 43 80 #endif 81 44 82 /** 45 83 * @} 46 84 */ 47 -
uspace/lib/usbhost/include/usb/host/endpoint.h
r5b18137 rb4b534ac 57 57 /** Maximum size of data packets. */ 58 58 size_t max_packet_size; 59 /** Additional opportunities per uframe */ 60 unsigned packets; 59 61 /** Necessary bandwidth. */ 60 62 size_t bandwidth; … … 67 69 /** Signals change of active status. */ 68 70 fibril_condvar_t avail; 71 /** High speed TT data */ 72 struct { 73 usb_address_t address; 74 unsigned port; 75 } tt; 69 76 /** Optional device specific data. */ 70 77 struct { … … 80 87 endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint, 81 88 usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed, 82 size_t max_packet_size, size_t bw); 89 size_t max_packet_size, unsigned packets, size_t bw, 90 usb_address_t tt_address, unsigned tt_port); 83 91 void endpoint_destroy(endpoint_t *instance); 84 92 -
uspace/lib/usbhost/include/usb/host/hcd.h
r5b18137 rb4b534ac 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 void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth, 84 bw_count_func_t bw_count); 85 86 static inline void hcd_set_implementation(hcd_t *hcd, void *data, 87 const hcd_ops_t *ops) 73 88 { 74 89 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;90 if (ops) { 91 hcd->driver_data = data; 92 hcd->ops = *ops; 93 } else { 94 memset(&hcd->ops, 0, sizeof(hcd->ops)); 95 } 81 96 } 82 97 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]) 98 static inline void * hcd_get_driver_data(hcd_t *hcd) 90 99 { 91 100 assert(hcd); 92 usb_endpoint_manager_reset_eps_if_need( 93 &hcd->ep_manager, target, (const uint8_t *)setup_data); 101 return hcd->driver_data; 94 102 } 95 103 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) 104 usb_address_t hcd_request_address(hcd_t *hcd, usb_speed_t speed); 105 106 int hcd_release_address(hcd_t *hcd, usb_address_t address); 107 108 int hcd_reserve_default_address(hcd_t *hcd, usb_speed_t speed); 109 110 static inline int hcd_release_default_address(hcd_t *hcd) 101 111 { 102 return ddf_fun_data_get(fun);112 return hcd_release_address(hcd, USB_ADDRESS_DEFAULT); 103 113 } 104 114 105 extern usbhc_iface_t hcd_iface; 115 int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir, 116 usb_transfer_type_t type, size_t max_packet_size, unsigned packets, 117 size_t size, usb_address_t tt_address, unsigned tt_port); 118 119 int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir); 120 121 int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction, 122 void *data, size_t size, uint64_t setup_data, 123 usbhc_iface_transfer_in_callback_t in, 124 usbhc_iface_transfer_out_callback_t out, void *arg, const char* name); 125 126 ssize_t hcd_send_batch_sync(hcd_t *hcd, usb_target_t target, 127 usb_direction_t dir, void *data, size_t size, uint64_t setup_data, 128 const char* name); 106 129 107 130 #endif 108 109 131 /** 110 132 * @} -
uspace/lib/usbhost/include/usb/host/usb_bus.h
r5b18137 rb4b534ac 40 40 #define LIBUSBHOST_HOST_USB_ENDPOINT_MANAGER_H 41 41 42 #include <usb/host/endpoint.h> 43 #include <usb/usb.h> 44 42 45 #include <adt/list.h> 43 46 #include <fibril_synch.h> 44 #include < usb/usb.h>47 #include <stdbool.h> 45 48 46 #include <usb/host/endpoint.h>47 49 48 50 /** Bytes per second in FULL SPEED */ … … 50 52 /** 90% of total bandwidth is available for periodic transfers */ 51 53 #define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9) 52 /** 16 addresses per list */ 53 #define ENDPOINT_LIST_COUNT 8 54 55 //TODO: Implement 56 #define BANDWIDTH_AVAILABLE_USB20 1 57 58 typedef size_t (*bw_count_func_t)(usb_speed_t, usb_transfer_type_t, size_t, size_t); 59 typedef void (*ep_remove_callback_t)(endpoint_t *, void *); 60 typedef int (*ep_add_callback_t)(endpoint_t *, void *); 54 61 55 62 /** Endpoint management structure */ 56 typedef struct usb_endpoint_manager { 57 /** Store endpoint_t instances */ 58 list_t endpoint_lists[ENDPOINT_LIST_COUNT]; 63 typedef struct usb_bus { 64 struct { 65 usb_speed_t speed; /**< Device speed */ 66 bool occupied; /**< The address is in use. */ 67 list_t endpoint_list; /**< Store endpoint_t instances */ 68 } devices[USB_ADDRESS_COUNT]; 59 69 /** Prevents races accessing lists */ 60 70 fibril_mutex_t guard; … … 62 72 size_t free_bw; 63 73 /** Use this function to count bw required by EP */ 64 size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t); 65 } usb_endpoint_manager_t; 74 bw_count_func_t bw_count; 75 /** Maximum speed allowed. */ 76 usb_speed_t max_speed; 77 /** The last reserved address */ 78 usb_address_t last_address; 79 } usb_bus_t; 80 66 81 67 82 size_t bandwidth_count_usb11(usb_speed_t speed, usb_transfer_type_t type, 68 83 size_t size, size_t max_packet_size); 84 size_t bandwidth_count_usb20(usb_speed_t speed, usb_transfer_type_t type, 85 size_t size, size_t max_packet_size); 69 86 70 int usb_endpoint_manager_init(usb_endpoint_manager_t *instance, 71 size_t available_bandwidth, 72 size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t)); 87 int usb_bus_init(usb_bus_t *instance, 88 size_t available_bandwidth, bw_count_func_t bw_count, usb_speed_t max_speed); 73 89 74 void usb_endpoint_manager_reset_eps_if_need(usb_endpoint_manager_t *instance, 75 usb_target_t target, const uint8_t data[8]); 90 int usb_bus_register_ep(usb_bus_t *instance, endpoint_t *ep, size_t data_size); 76 91 77 int usb_endpoint_manager_register_ep( 78 usb_endpoint_manager_t *instance, endpoint_t *ep, size_t data_size); 79 int usb_endpoint_manager_unregister_ep( 80 usb_endpoint_manager_t *instance, endpoint_t *ep); 81 endpoint_t * usb_endpoint_manager_find_ep(usb_endpoint_manager_t *instance, 92 int usb_bus_unregister_ep(usb_bus_t *instance, endpoint_t *ep); 93 94 endpoint_t * usb_bus_find_ep(usb_bus_t *instance, 82 95 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction); 83 96 84 int usb_ endpoint_manager_add_ep(usb_endpoint_manager_t *instance,97 int usb_bus_add_ep(usb_bus_t *instance, 85 98 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 86 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size, 87 size_t data_size, int (*callback)(endpoint_t *, void *), void *arg); 99 usb_transfer_type_t type, size_t max_packet_size, unsigned packets, 100 size_t data_size, ep_add_callback_t callback, void *arg, 101 usb_address_t tt_address, unsigned tt_port); 88 102 89 int usb_ endpoint_manager_remove_ep(usb_endpoint_manager_t *instance,103 int usb_bus_remove_ep(usb_bus_t *instance, 90 104 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 91 void (*callback)(endpoint_t *, void *), void *arg);105 ep_remove_callback_t callback, void *arg); 92 106 93 void usb_endpoint_manager_remove_address(usb_endpoint_manager_t *instance, 94 usb_address_t address, void (*callback)(endpoint_t *, void *), void *arg); 107 int usb_bus_reset_toggle(usb_bus_t *instance, usb_target_t target, bool all); 108 109 int usb_bus_remove_address(usb_bus_t *instance, 110 usb_address_t address, ep_remove_callback_t callback, void *arg); 111 112 int usb_bus_request_address(usb_bus_t *instance, 113 usb_address_t *address, bool strict, usb_speed_t speed); 114 115 int usb_bus_get_speed(usb_bus_t *instance, 116 usb_address_t address, usb_speed_t *speed); 95 117 #endif 96 118 /** -
uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h
r5b18137 rb4b534ac 37 37 #define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H 38 38 39 #include <adt/list.h> 39 #include <usb/host/endpoint.h> 40 #include <usb/usb.h> 40 41 42 #include <assert.h> 43 #include <stdbool.h> 44 #include <sys/types.h> 41 45 #include <usbhc_iface.h> 42 #include <usb/usb.h>43 #include <usb/host/endpoint.h>44 46 45 47 #define USB_SETUP_PACKET_SIZE 8 … … 67 69 */ 68 70 size_t setup_size; 69 /** Host controller function, passed to callback function */70 ddf_fun_t *fun;71 71 72 72 /** Actually used portion of the buffer … … 80 80 */ 81 81 int error; 82 83 /** Driver specific data */84 void *private_data;85 /** Callback to properly remove driver data during destruction */86 void (*private_data_dtor)(void *p_data);87 82 } usb_transfer_batch_t; 88 83 … … 108 103 usbhc_iface_transfer_in_callback_t func_in, 109 104 usbhc_iface_transfer_out_callback_t func_out, 110 void *arg, 111 ddf_fun_t *fun, 112 void *private_data, 113 void (*private_data_dtor)(void *p_data) 105 void *arg 114 106 ); 115 107 void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance); -
uspace/lib/usbhost/include/usb/host/utils/malloc32.h
r5b18137 rb4b534ac 1 1 /* 2 * Copyright (c) 201 0Jan Vesely2 * Copyright (c) 2013 Jan Vesely 3 3 * All rights reserved. 4 4 * … … 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusb ohci28 /** @addtogroup drvusbehci 29 29 * @{ 30 30 */ 31 31 /** @file 32 * @brief OHCI driver32 * @brief EHCI driver 33 33 */ 34 #ifndef DRV_ OHCI_UTILS_MALLOC32_H35 #define DRV_ OHCI_UTILS_MALLOC32_H34 #ifndef DRV_EHCI_UTILS_MALLOC32_H 35 #define DRV_EHCI_UTILS_MALLOC32_H 36 36 37 #include <a ssert.h>38 #include < malloc.h>39 #include < unistd.h>37 #include <align.h> 38 #include <as.h> 39 #include <ddi.h> 40 40 #include <errno.h> 41 #include < mem.h>42 #include < as.h>41 #include <stdlib.h> 42 #include <sys/types.h> 43 43 44 44 /* Generic TDs and EDs require 16byte alignment, … … 46 46 * buffers do not have to be aligned. 47 47 */ 48 #define OHCI_ALIGN 32 48 #define EHCI_ALIGN 32 49 50 #define EHCI_REQUIRED_PAGE_SIZE 4096 49 51 50 52 /** Get physical address translation … … 70 72 */ 71 73 static inline void * malloc32(size_t size) 72 { return memalign(OHCI_ALIGN, size); } 74 { 75 uintptr_t phys; 76 void *address = AS_AREA_ANY; 77 size_t real_size = ALIGN_UP(size, PAGE_SIZE); 78 79 const int ret = dmamem_map_anonymous(real_size, 80 DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys, 81 &address); 82 83 if (ret == EOK) { 84 /* Poison, accessing it should be enough to make sure 85 * the location is mapped, but poison works better */ 86 memset(address, 0x5, real_size); 87 return address; 88 } 89 return NULL; 90 } 73 91 74 92 /** Physical mallocator simulator … … 77 95 */ 78 96 static inline void free32(void *addr) 79 { free(addr); } 97 { 98 dmamem_unmap_anonymous(addr); 99 } 100 101 /** Create 4KB page mapping 102 * 103 * @return Address of the mapped page, NULL on failure. 104 */ 105 static inline void *get_page() 106 { 107 return malloc32(PAGE_SIZE); 108 } 109 110 static inline void return_page(void *page) 111 { 112 free32(page); 113 } 114 115 80 116 #endif 81 117 /**
Note:
See TracChangeset
for help on using the changeset viewer.
