Changes in / [41e645c:423e8c81] in mainline
- Files:
-
- 9 deleted
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r41e645c r423e8c81 88 88 ./uspace/drv/usbhub/usbhub 89 89 ./uspace/drv/usbhid/usbhid 90 ./uspace/drv/usbmid/usbmid91 90 ./uspace/drv/vhc/vhc 92 91 ./uspace/srv/bd/ata_bd/ata_bd -
boot/arch/amd64/Makefile.inc
r41e645c r423e8c81 47 47 usbhub \ 48 48 usbhid \ 49 usbmid \50 49 vhc 51 50 -
uspace/Makefile
r41e645c r423e8c81 121 121 drv/usbhid \ 122 122 drv/usbhub \ 123 drv/usbmid \124 123 drv/vhc 125 124 endif … … 137 136 drv/usbhid \ 138 137 drv/usbhub \ 139 drv/usbmid \140 138 drv/vhc 141 139 endif -
uspace/doc/doxygroups.h
r41e645c r423e8c81 220 220 221 221 /** 222 * @defgroup drvusbmid USB multi interface device driver223 * @ingroup usb224 * @brief USB multi interface device driver225 * @details226 * This driver serves as a mini hub (or bus) driver for devices227 * that have the class defined at interface level (those devices228 * usually have several interfaces).229 *230 * The term multi interface device driver (MID) was borrowed231 * Solaris operating system.232 */233 234 /**235 222 * @defgroup drvusbhub USB hub driver 236 223 * @ingroup usb -
uspace/drv/uhci-hcd/iface.c
r41e645c r423e8c81 42 42 #include "uhci.h" 43 43 44 static int get_address(device_t *dev, devman_handle_t handle, 45 usb_address_t *address) 46 { 47 assert(dev); 48 uhci_t *hc = dev_to_uhci(dev); 49 assert(hc); 50 *address = usb_address_keeping_find(&hc->address_manager, handle); 51 if (*address <= 0) 52 return *address; 53 return EOK; 54 } 44 55 /*----------------------------------------------------------------------------*/ 45 56 static int reserve_default_address(device_t *dev, usb_speed_t speed) … … 157 168 /*----------------------------------------------------------------------------*/ 158 169 usbhc_iface_t uhci_iface = { 170 .tell_address = get_address, 171 159 172 .reserve_default_address = reserve_default_address, 160 173 .release_default_address = release_default_address, -
uspace/drv/uhci-hcd/main.c
r41e645c r423e8c81 34 34 #include <driver.h> 35 35 #include <usb_iface.h> 36 #include <usb/ddfiface.h>37 36 #include <device/hw_res.h> 38 37 … … 49 48 50 49 static int uhci_add_device(device_t *device); 50 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle); 51 /*----------------------------------------------------------------------------*/ 52 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle) 53 { 54 /* This shall be called only for the UHCI itself. */ 55 assert(dev->parent == NULL); 51 56 52 static int usb_iface_get_address(device_t *dev, devman_handle_t handle, 53 usb_address_t *address) 54 { 55 assert(dev); 56 uhci_t *hc = dev_to_uhci(dev); 57 assert(hc); 58 59 usb_address_t addr = usb_address_keeping_find(&hc->address_manager, 60 handle); 61 if (addr < 0) { 62 return addr; 63 } 64 65 if (address != NULL) { 66 *address = addr; 67 } 68 57 *handle = dev->handle; 69 58 return EOK; 70 59 } 71 72 60 /*----------------------------------------------------------------------------*/ 73 61 static usb_iface_t hc_usb_iface = { 74 .get_hc_handle = usb_iface_get_hc_handle_hc_impl, 75 .get_address = usb_iface_get_address 62 .get_hc_handle = usb_iface_get_hc_handle 76 63 }; 77 64 /*----------------------------------------------------------------------------*/ -
uspace/drv/uhci-rhd/main.c
r41e645c r423e8c81 34 34 #include <driver.h> 35 35 #include <usb_iface.h> 36 #include <usb/ddfiface.h>37 36 38 37 #include <errno.h> … … 57 56 58 57 static usb_iface_t uhci_rh_usb_iface = { 59 .get_hc_handle = usb_iface_get_hc_handle, 60 .get_address = usb_iface_get_address_hub_impl 58 .get_hc_handle = usb_iface_get_hc_handle 61 59 }; 62 60 -
uspace/drv/usbhid/main.c
r41e645c r423e8c81 265 265 for (i = 0; i < count; ++i) { 266 266 printf("%d ", key_codes[i]); 267 }268 printf("\n");269 270 for (i = 0; i < count; ++i) {271 267 // TODO: Key press / release 272 268 273 269 // TODO: NOT WORKING 274 270 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 275 276 if (key == 0) {277 continue;278 }279 271 kbd_push_ev(KEY_PRESS, key); 280 272 } … … 356 348 { 357 349 .pipe = &kbd_dev->poll_pipe, 358 .description = &poll_endpoint_description, 359 .interface_no = 360 usb_device_get_assigned_interface(kbd_dev->device) 350 .description = &poll_endpoint_description 361 351 } 362 352 }; -
uspace/drv/usbhub/usbhub.c
r41e645c r423e8c81 39 39 40 40 #include <usb_iface.h> 41 #include <usb/ddfiface.h>42 41 #include <usb/usbdrv.h> 43 42 #include <usb/descriptor.h> … … 51 50 #include "usb/usb.h" 52 51 52 static int iface_get_hc_handle(device_t *device, devman_handle_t *handle) 53 { 54 return usb_hc_find(device->handle, handle); 55 } 56 57 static usb_iface_t hub_usb_iface = { 58 .get_hc_handle = iface_get_hc_handle 59 }; 60 53 61 static device_ops_t hub_device_ops = { 54 .interfaces[USB_DEV_IFACE] = & usb_iface_hub_impl62 .interfaces[USB_DEV_IFACE] = &hub_usb_iface 55 63 }; 56 64 -
uspace/drv/vhc/conn.h
r41e645c r423e8c81 38 38 #include <usb/usb.h> 39 39 #include <usbhc_iface.h> 40 #include <usb_iface.h>41 40 #include "vhcd.h" 42 41 #include "devices.h" … … 44 43 void connection_handler_host(sysarg_t); 45 44 46 extern usbhc_iface_t vhc_iface; 47 extern usb_iface_t vhc_usb_iface; 45 usbhc_iface_t vhc_iface; 48 46 49 47 void address_init(void); -
uspace/drv/vhc/connhost.c
r41e645c r423e8c81 37 37 #include <usb/usb.h> 38 38 #include <usb/addrkeep.h> 39 #include <usb/ddfiface.h>40 39 41 40 #include "vhcd.h" … … 314 313 static usb_address_keeping_t addresses; 315 314 315 316 static int reserve_default_address(device_t *dev, usb_speed_t ignored) 317 { 318 usb_address_keeping_reserve_default(&addresses); 319 return EOK; 320 } 321 322 static int release_default_address(device_t *dev) 323 { 324 usb_address_keeping_release_default(&addresses); 325 return EOK; 326 } 327 328 static int request_address(device_t *dev, usb_speed_t ignored, 329 usb_address_t *address) 330 { 331 usb_address_t addr = usb_address_keeping_request(&addresses); 332 if (addr < 0) { 333 return (int)addr; 334 } 335 336 *address = addr; 337 return EOK; 338 } 339 340 static int release_address(device_t *dev, usb_address_t address) 341 { 342 return usb_address_keeping_release(&addresses, address); 343 } 344 345 static int bind_address(device_t *dev, usb_address_t address, 346 devman_handle_t handle) 347 { 348 usb_address_keeping_devman_bind(&addresses, address, handle); 349 return EOK; 350 } 351 316 352 static int tell_address(device_t *dev, devman_handle_t handle, 317 353 usb_address_t *address) … … 326 362 } 327 363 328 static int reserve_default_address(device_t *dev, usb_speed_t ignored)329 {330 usb_address_keeping_reserve_default(&addresses);331 return EOK;332 }333 334 static int release_default_address(device_t *dev)335 {336 usb_address_keeping_release_default(&addresses);337 return EOK;338 }339 340 static int request_address(device_t *dev, usb_speed_t ignored,341 usb_address_t *address)342 {343 usb_address_t addr = usb_address_keeping_request(&addresses);344 if (addr < 0) {345 return (int)addr;346 }347 348 *address = addr;349 return EOK;350 }351 352 static int release_address(device_t *dev, usb_address_t address)353 {354 return usb_address_keeping_release(&addresses, address);355 }356 357 static int bind_address(device_t *dev, usb_address_t address,358 devman_handle_t handle)359 {360 usb_address_keeping_devman_bind(&addresses, address, handle);361 return EOK;362 }363 364 364 void address_init(void) 365 365 { … … 368 368 369 369 usbhc_iface_t vhc_iface = { 370 .tell_address = tell_address, 371 370 372 .reserve_default_address = reserve_default_address, 371 373 .release_default_address = release_default_address, … … 381 383 }; 382 384 383 usb_iface_t vhc_usb_iface = {384 .get_hc_handle = usb_iface_get_hc_handle_hc_impl,385 .get_address = tell_address386 };387 388 389 385 /** 390 386 * @} -
uspace/drv/vhc/hcd.c
r41e645c r423e8c81 45 45 46 46 #include <usb/usb.h> 47 #include <usb/ddfiface.h>48 47 #include <usb_iface.h> 49 48 #include "vhcd.h" … … 53 52 #include "conn.h" 54 53 54 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle) 55 { 56 /* This shall be called only for VHC device. */ 57 assert(dev->parent == NULL); 58 59 *handle = dev->handle; 60 return EOK; 61 } 62 63 static usb_iface_t hc_usb_iface = { 64 .get_hc_handle = usb_iface_get_hc_handle 65 }; 66 55 67 static device_ops_t vhc_ops = { 56 68 .interfaces[USBHC_DEV_IFACE] = &vhc_iface, 57 .interfaces[USB_DEV_IFACE] = & vhc_usb_iface,69 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 58 70 .close = on_client_close, 59 71 .default_handler = default_connection_handler -
uspace/lib/drv/generic/remote_usb.c
r41e645c r423e8c81 40 40 41 41 42 static void remote_usb_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);43 static void remote_usb_get_interface(device_t *, void *, ipc_callid_t, ipc_call_t *);44 42 static void remote_usb_get_hc_handle(device_t *, void *, ipc_callid_t, ipc_call_t *); 45 43 //static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 47 45 /** Remote USB interface operations. */ 48 46 static remote_iface_func_ptr_t remote_usb_iface_ops [] = { 49 remote_usb_get_address,50 remote_usb_get_interface,51 47 remote_usb_get_hc_handle 52 48 }; … … 60 56 }; 61 57 62 63 void remote_usb_get_address(device_t *device, void *iface,64 ipc_callid_t callid, ipc_call_t *call)65 {66 usb_iface_t *usb_iface = (usb_iface_t *) iface;67 68 if (usb_iface->get_address == NULL) {69 async_answer_0(callid, ENOTSUP);70 return;71 }72 73 devman_handle_t handle = DEV_IPC_GET_ARG1(*call);74 75 usb_address_t address;76 int rc = usb_iface->get_address(device, handle, &address);77 if (rc != EOK) {78 async_answer_0(callid, rc);79 } else {80 async_answer_1(callid, EOK, address);81 }82 }83 84 void remote_usb_get_interface(device_t *device, void *iface,85 ipc_callid_t callid, ipc_call_t *call)86 {87 usb_iface_t *usb_iface = (usb_iface_t *) iface;88 89 if (usb_iface->get_interface == NULL) {90 async_answer_0(callid, ENOTSUP);91 return;92 }93 94 devman_handle_t handle = DEV_IPC_GET_ARG1(*call);95 96 int iface_no;97 int rc = usb_iface->get_interface(device, handle, &iface_no);98 if (rc != EOK) {99 async_answer_0(callid, rc);100 } else {101 async_answer_1(callid, EOK, iface_no);102 }103 }104 58 105 59 void remote_usb_get_hc_handle(device_t *device, void *iface, -
uspace/lib/drv/generic/remote_usbhc.c
r41e645c r423e8c81 43 43 #define HACK_MAX_PACKET_SIZE_INTERRUPT_IN 4 44 44 45 static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 45 46 static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *); 46 47 static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *); 47 static void remote_usbhc_bulk_out(device_t *, void *, ipc_callid_t, ipc_call_t *);48 static void remote_usbhc_bulk_in(device_t *, void *, ipc_callid_t, ipc_call_t *);49 48 static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *); 50 49 static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 58 57 /** Remote USB host controller interface operations. */ 59 58 static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = { 59 remote_usbhc_get_address, 60 60 61 remote_usbhc_reserve_default_address, 61 62 remote_usbhc_release_default_address, … … 67 68 remote_usbhc_interrupt_out, 68 69 remote_usbhc_interrupt_in, 69 70 remote_usbhc_bulk_out,71 remote_usbhc_bulk_in,72 70 73 71 remote_usbhc_control_write, … … 123 121 } 124 122 123 void remote_usbhc_get_address(device_t *device, void *iface, 124 ipc_callid_t callid, ipc_call_t *call) 125 { 126 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 127 128 if (!usb_iface->tell_address) { 129 async_answer_0(callid, ENOTSUP); 130 return; 131 } 132 133 devman_handle_t handle = DEV_IPC_GET_ARG1(*call); 134 135 usb_address_t address; 136 int rc = usb_iface->tell_address(device, handle, &address); 137 if (rc != EOK) { 138 async_answer_0(callid, rc); 139 } else { 140 async_answer_1(callid, EOK, address); 141 } 142 } 143 125 144 void remote_usbhc_reserve_default_address(device_t *device, void *iface, 126 145 ipc_callid_t callid, ipc_call_t *call) … … 370 389 return remote_usbhc_in_transfer(device, callid, call, 371 390 usb_iface->interrupt_in); 372 }373 374 void remote_usbhc_bulk_out(device_t *device, void *iface,375 ipc_callid_t callid, ipc_call_t *call)376 {377 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;378 assert(usb_iface != NULL);379 380 return remote_usbhc_out_transfer(device, callid, call,381 usb_iface->bulk_out);382 }383 384 void remote_usbhc_bulk_in(device_t *device, void *iface,385 ipc_callid_t callid, ipc_call_t *call)386 {387 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;388 assert(usb_iface != NULL);389 390 return remote_usbhc_in_transfer(device, callid, call,391 usb_iface->bulk_in);392 391 } 393 392 -
uspace/lib/drv/include/usb_iface.h
r41e645c r423e8c81 41 41 #include <usb/usb.h> 42 42 typedef enum { 43 /** Tell USB address assigned to device.44 * Parameters:45 * - devman handle id46 * Answer:47 * - EINVAL - unknown handle or handle not managed by this driver48 * - ENOTSUP - operation not supported (shall not happen)49 * - arbitrary error code if returned by remote implementation50 * - EOK - handle found, first parameter contains the USB address51 */52 IPC_M_USB_GET_ADDRESS,53 54 /** Tell interface number given device can use.55 * Parameters56 * - devman handle id of the device57 * Answer:58 * - ENOTSUP - operation not supported (can also mean any interface)59 * - EOK - operation okay, first parameter contains interface number60 */61 IPC_M_USB_GET_INTERFACE,62 63 43 /** Tell devman handle of device host controller. 64 44 * Parameters: … … 75 55 /** USB device communication interface. */ 76 56 typedef struct { 77 int (*get_address)(device_t *, devman_handle_t, usb_address_t *);78 int (*get_interface)(device_t *, devman_handle_t, int *);79 57 int (*get_hc_handle)(device_t *, devman_handle_t *); 80 58 } usb_iface_t; -
uspace/lib/drv/include/usbhc_iface.h
r41e645c r423e8c81 85 85 */ 86 86 typedef enum { 87 /** Tell USB address assigned to device. 88 * Parameters: 89 * - devman handle id 90 * Answer: 91 * - EINVAL - unknown handle or handle not managed by this driver 92 * - ENOTSUP - operation not supported by HC (shall not happen) 93 * - arbitrary error code if returned by remote implementation 94 * - EOK - handle found, first parameter contains the USB address 95 */ 96 IPC_M_USBHC_GET_ADDRESS, 97 98 87 99 /** Reserve usage of default address. 88 100 * This call informs the host controller that the caller will be … … 141 153 IPC_M_USBHC_INTERRUPT_IN, 142 154 143 /** Send bulk data to device.144 * See explanation at usb_iface_funcs_t (OUT transaction).145 */146 IPC_M_USBHC_BULK_OUT,147 148 /** Get bulk data from device.149 * See explanation at usb_iface_funcs_t (IN transaction).150 */151 IPC_M_USBHC_BULK_IN,152 153 155 /** Issue control WRITE transfer. 154 156 * See explanation at usb_iface_funcs_t (OUT transaction) for … … 194 196 /** USB host controller communication interface. */ 195 197 typedef struct { 198 int (*tell_address)(device_t *, devman_handle_t, usb_address_t *); 199 196 200 int (*reserve_default_address)(device_t *, usb_speed_t); 197 201 int (*release_default_address)(device_t *); … … 203 207 usbhc_iface_transfer_in_t interrupt_in; 204 208 205 usbhc_iface_transfer_out_t bulk_out;206 usbhc_iface_transfer_in_t bulk_in;207 208 209 int (*control_write)(device_t *, usb_target_t, 209 210 size_t, -
uspace/lib/usb/Makefile
r41e645c r423e8c81 35 35 src/addrkeep.c \ 36 36 src/class.c \ 37 src/ddfiface.c \38 37 src/debug.c \ 39 38 src/dp.c \ -
uspace/lib/usb/include/usb/dp.h
r41e645c r423e8c81 45 45 } usb_dp_descriptor_nesting_t; 46 46 47 extern usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[];48 49 47 typedef struct { 50 48 usb_dp_descriptor_nesting_t *nesting; -
uspace/lib/usb/include/usb/pipes.h
r41e645c r423e8c81 107 107 /** Endpoint description. */ 108 108 const usb_endpoint_description_t *description; 109 /** Interface number the endpoint must belong to (-1 for any). */110 const int interface_no;111 109 /** Found descriptor fitting the description. */ 112 110 usb_standard_endpoint_descriptor_t *descriptor; … … 123 121 int usb_device_connection_initialize(usb_device_connection_t *, 124 122 devman_handle_t, usb_address_t); 125 126 int usb_device_get_assigned_interface(device_t *);127 123 128 124 int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *, -
uspace/lib/usb/include/usb/recognise.h
r41e645c r423e8c81 41 41 #include <ipc/devman.h> 42 42 43 int usb_device_create_match_ids_from_interface(44 const usb_standard_device_descriptor_t *,45 const usb_standard_interface_descriptor_t *, match_id_list_t *);46 47 43 int usb_device_create_match_ids(usb_endpoint_pipe_t *, match_id_list_t *); 48 44 -
uspace/lib/usb/include/usb/usbdrv.h
r41e645c r423e8c81 103 103 int usb_drv_create_match_ids_from_device_descriptor(match_id_list_t *, 104 104 const usb_standard_device_descriptor_t *); 105 int usb_drv_create_match_ids_from_configuration_descriptor(match_id_list_t *, 106 const void *, size_t); 107 105 108 106 109 #endif -
uspace/lib/usb/src/dp.c
r41e645c r423e8c81 40 40 #include <bool.h> 41 41 #include <usb/dp.h> 42 #include <usb/descriptor.h>43 44 #define NESTING(parentname, childname) \45 { \46 .child = USB_DESCTYPE_##childname, \47 .parent = USB_DESCTYPE_##parentname, \48 }49 #define LAST_NESTING { -1, -1 }50 51 /** Nesting of standard USB descriptors. */52 usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[] = {53 NESTING(CONFIGURATION, INTERFACE),54 NESTING(INTERFACE, ENDPOINT),55 NESTING(INTERFACE, HUB),56 NESTING(INTERFACE, HID),57 NESTING(HID, HID_REPORT),58 LAST_NESTING59 };60 61 #undef NESTING62 #undef LAST_NESTING63 42 64 43 /** Tells whether pointer points inside descriptor data. -
uspace/lib/usb/src/hub.c
r41e645c r423e8c81 301 301 } 302 302 303 303 304 /** 304 305 * @} -
uspace/lib/usb/src/pipes.c
r41e645c r423e8c81 36 36 #include <usb/pipes.h> 37 37 #include <usbhc_iface.h> 38 #include <usb_iface.h>39 38 #include <errno.h> 40 39 #include <assert.h> … … 42 41 /** Tell USB address assigned to given device. 43 42 * 44 * @param phone Phone to parent device.43 * @param phone Phone to my HC. 45 44 * @param dev Device in question. 46 45 * @return USB address or error code. … … 49 48 { 50 49 sysarg_t address; 51 int rc = async_req_2_1(phone, DEV_IFACE_ID(USB _DEV_IFACE),52 IPC_M_USB _GET_ADDRESS,50 int rc = async_req_2_1(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 51 IPC_M_USBHC_GET_ADDRESS, 53 52 dev->handle, &address); 54 53 … … 58 57 59 58 return (usb_address_t) address; 60 }61 62 /** Tell USB interface assigned to given device.63 *64 * @param device Device in question.65 * @return Interface number (negative code means any).66 */67 int usb_device_get_assigned_interface(device_t *device)68 {69 int parent_phone = devman_parent_device_connect(device->handle,70 IPC_FLAG_BLOCKING);71 if (parent_phone < 0) {72 return -1;73 }74 75 sysarg_t iface_no;76 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),77 IPC_M_USB_GET_INTERFACE,78 device->handle, &iface_no);79 80 async_hangup(parent_phone);81 82 if (rc != EOK) {83 return -1;84 }85 86 return (int) iface_no;87 59 } 88 60 … … 108 80 } 109 81 110 int parent_phone = devman_parent_device_connect(device->handle, 111 IPC_FLAG_BLOCKING); 112 if (parent_phone < 0) { 113 return parent_phone; 114 } 115 116 my_address = get_my_address(parent_phone, device); 82 int hc_phone = devman_device_connect(hc_handle, 0); 83 if (hc_phone < 0) { 84 return hc_phone; 85 } 86 87 my_address = get_my_address(hc_phone, device); 117 88 if (my_address < 0) { 118 89 rc = my_address; … … 124 95 125 96 leave: 126 async_hangup( parent_phone);97 async_hangup(hc_phone); 127 98 return rc; 128 99 } -
uspace/lib/usb/src/pipesinit.c
r41e645c r423e8c81 109 109 * @param mapping_count Number of endpoint mappings in @p mapping. 110 110 * @param found_endpoint Description of found endpoint. 111 * @param interface_number Number of currently processed interface.112 111 * @return Endpoint mapping corresponding to @p found_endpoint. 113 112 * @retval NULL No corresponding endpoint found. … … 115 114 static usb_endpoint_mapping_t *find_endpoint_mapping( 116 115 usb_endpoint_mapping_t *mapping, size_t mapping_count, 117 usb_endpoint_description_t *found_endpoint, 118 int interface_number) 116 usb_endpoint_description_t *found_endpoint) 119 117 { 120 118 while (mapping_count > 0) { 121 bool interface_number_fits = (mapping->interface_no < 0) 122 || (mapping->interface_no == interface_number); 123 124 bool endpoint_descriptions_fits = endpoint_fits_description( 125 mapping->description, found_endpoint); 126 127 if (interface_number_fits && endpoint_descriptions_fits) { 119 if (endpoint_fits_description(mapping->description, 120 found_endpoint)) { 128 121 return mapping; 129 122 } … … 176 169 */ 177 170 usb_endpoint_mapping_t *ep_mapping = find_endpoint_mapping(mapping, 178 mapping_count, &description , interface->interface_number);171 mapping_count, &description); 179 172 if (ep_mapping == NULL) { 180 173 return ENOENT; -
uspace/lib/usb/src/pipesio.c
r41e645c r423e8c81 71 71 ipc_method = IPC_M_USBHC_INTERRUPT_IN; 72 72 break; 73 case USB_TRANSFER_BULK:74 ipc_method = IPC_M_USBHC_BULK_IN;75 break;76 73 default: 77 74 return ENOTSUP; … … 197 194 case USB_TRANSFER_INTERRUPT: 198 195 ipc_method = IPC_M_USBHC_INTERRUPT_OUT; 199 break;200 case USB_TRANSFER_BULK:201 ipc_method = IPC_M_USBHC_BULK_OUT;202 196 break; 203 197 default: -
uspace/lib/usb/src/recognise.c
r41e645c r423e8c81 34 34 */ 35 35 #include <sys/types.h> 36 #include <usb_iface.h> 36 37 #include <usb/usbdrv.h> 37 38 #include <usb/pipes.h> 38 39 #include <usb/recognise.h> 39 #include <usb/ddfiface.h>40 40 #include <usb/request.h> 41 41 #include <usb/classes/classes.h> … … 46 46 static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex); 47 47 48 /** Callback for getting host controller handle. 49 * 50 * @param dev Device in question. 51 * @param[out] handle Devman handle of the host controller. 52 * @return Error code. 53 */ 54 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle) 55 { 56 assert(dev); 57 assert(dev->parent != NULL); 58 59 device_t *parent = dev->parent; 60 61 if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) { 62 usb_iface_t *usb_iface 63 = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE]; 64 assert(usb_iface != NULL); 65 if (usb_iface->get_hc_handle) { 66 int rc = usb_iface->get_hc_handle(parent, handle); 67 return rc; 68 } 69 } 70 71 return ENOTSUP; 72 } 73 74 static usb_iface_t usb_iface = { 75 .get_hc_handle = usb_iface_get_hc_handle 76 }; 77 48 78 device_ops_t child_ops = { 49 .interfaces[USB_DEV_IFACE] = &usb_iface _hub_child_impl79 .interfaces[USB_DEV_IFACE] = &usb_iface 50 80 }; 51 81 … … 112 142 } 113 143 114 #define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \115 do { \116 int __rc = usb_add_match_id((match_ids), (score), \117 format, ##__VA_ARGS__); \118 if (__rc != EOK) { \119 return __rc; \120 } \121 } while (0)122 123 /** Create device match ids based on its interface.124 *125 * @param[in] descriptor Interface descriptor.126 * @param[out] matches Initialized list of match ids.127 * @return Error code (the two mentioned are not the only ones).128 * @retval EINVAL Invalid input parameters (expects non NULL pointers).129 * @retval ENOENT Interface does not specify class.130 */131 int usb_device_create_match_ids_from_interface(132 const usb_standard_device_descriptor_t *desc_device,133 const usb_standard_interface_descriptor_t *desc_interface,134 match_id_list_t *matches)135 {136 if (desc_interface == NULL) {137 return EINVAL;138 }139 if (matches == NULL) {140 return EINVAL;141 }142 143 if (desc_interface->interface_class == USB_CLASS_USE_INTERFACE) {144 return ENOENT;145 }146 147 const char *classname = usb_str_class(desc_interface->interface_class);148 assert(classname != NULL);149 150 #define IFACE_PROTOCOL_FMT "interface&class=%s&subclass=0x%02x&protocol=0x%02x"151 #define IFACE_PROTOCOL_ARGS classname, desc_interface->interface_subclass, \152 desc_interface->interface_protocol153 154 #define IFACE_SUBCLASS_FMT "interface&class=%s&subclass=0x%02x"155 #define IFACE_SUBCLASS_ARGS classname, desc_interface->interface_subclass156 157 #define IFACE_CLASS_FMT "interface&class=%s"158 #define IFACE_CLASS_ARGS classname159 160 #define VENDOR_RELEASE_FMT "vendor=0x%04x&product=0x%04x&release=" BCD_FMT161 #define VENDOR_RELEASE_ARGS desc_device->vendor_id, desc_device->product_id, \162 BCD_ARGS(desc_device->device_version)163 164 #define VENDOR_PRODUCT_FMT "vendor=0x%04x&product=0x%04x"165 #define VENDOR_PRODUCT_ARGS desc_device->vendor_id, desc_device->product_id166 167 #define VENDOR_ONLY_FMT "vendor=0x%04x"168 #define VENDOR_ONLY_ARGS desc_device->vendor_id169 170 /*171 * If the vendor is specified, create match ids with vendor with172 * higher score.173 * Then the same ones without the vendor part.174 */175 if ((desc_device != NULL) && (desc_device->vendor_id != 0)) {176 /* First, interface matches with device release number. */177 ADD_MATCHID_OR_RETURN(matches, 250,178 "usb&" VENDOR_RELEASE_FMT "&" IFACE_PROTOCOL_FMT,179 VENDOR_RELEASE_ARGS, IFACE_PROTOCOL_ARGS);180 ADD_MATCHID_OR_RETURN(matches, 240,181 "usb&" VENDOR_RELEASE_FMT "&" IFACE_SUBCLASS_FMT,182 VENDOR_RELEASE_ARGS, IFACE_SUBCLASS_ARGS);183 ADD_MATCHID_OR_RETURN(matches, 230,184 "usb&" VENDOR_RELEASE_FMT "&" IFACE_CLASS_FMT,185 VENDOR_RELEASE_ARGS, IFACE_CLASS_ARGS);186 187 /* Next, interface matches without release number. */188 ADD_MATCHID_OR_RETURN(matches, 220,189 "usb&" VENDOR_PRODUCT_FMT "&" IFACE_PROTOCOL_FMT,190 VENDOR_PRODUCT_ARGS, IFACE_PROTOCOL_ARGS);191 ADD_MATCHID_OR_RETURN(matches, 210,192 "usb&" VENDOR_PRODUCT_FMT "&" IFACE_SUBCLASS_FMT,193 VENDOR_PRODUCT_ARGS, IFACE_SUBCLASS_ARGS);194 ADD_MATCHID_OR_RETURN(matches, 200,195 "usb&" VENDOR_PRODUCT_FMT "&" IFACE_CLASS_FMT,196 VENDOR_PRODUCT_ARGS, IFACE_CLASS_ARGS);197 198 /* Finally, interface matches with only vendor. */199 ADD_MATCHID_OR_RETURN(matches, 190,200 "usb&" VENDOR_ONLY_FMT "&" IFACE_PROTOCOL_FMT,201 VENDOR_ONLY_ARGS, IFACE_PROTOCOL_ARGS);202 ADD_MATCHID_OR_RETURN(matches, 180,203 "usb&" VENDOR_ONLY_FMT "&" IFACE_SUBCLASS_FMT,204 VENDOR_ONLY_ARGS, IFACE_SUBCLASS_ARGS);205 ADD_MATCHID_OR_RETURN(matches, 170,206 "usb&" VENDOR_ONLY_FMT "&" IFACE_CLASS_FMT,207 VENDOR_ONLY_ARGS, IFACE_CLASS_ARGS);208 }209 210 /* Now, the same but without any vendor specification. */211 ADD_MATCHID_OR_RETURN(matches, 160,212 "usb&" IFACE_PROTOCOL_FMT,213 IFACE_PROTOCOL_ARGS);214 ADD_MATCHID_OR_RETURN(matches, 150,215 "usb&" IFACE_SUBCLASS_FMT,216 IFACE_SUBCLASS_ARGS);217 ADD_MATCHID_OR_RETURN(matches, 140,218 "usb&" IFACE_CLASS_FMT,219 IFACE_CLASS_ARGS);220 221 #undef IFACE_PROTOCOL_FMT222 #undef IFACE_PROTOCOL_ARGS223 #undef IFACE_SUBCLASS_FMT224 #undef IFACE_SUBCLASS_ARGS225 #undef IFACE_CLASS_FMT226 #undef IFACE_CLASS_ARGS227 #undef VENDOR_RELEASE_FMT228 #undef VENDOR_RELEASE_ARGS229 #undef VENDOR_PRODUCT_FMT230 #undef VENDOR_PRODUCT_ARGS231 #undef VENDOR_ONLY_FMT232 #undef VENDOR_ONLY_ARGS233 234 return EOK;235 }236 237 144 /** Create DDF match ids from USB device descriptor. 238 145 * … … 245 152 const usb_standard_device_descriptor_t *device_descriptor) 246 153 { 154 int rc; 155 247 156 /* 248 157 * Unless the vendor id is 0, the pair idVendor-idProduct … … 251 160 if (device_descriptor->vendor_id != 0) { 252 161 /* First, with release number. */ 253 ADD_MATCHID_OR_RETURN(matches, 100,162 rc = usb_add_match_id(matches, 100, 254 163 "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT, 255 164 (int) device_descriptor->vendor_id, 256 165 (int) device_descriptor->product_id, 257 166 BCD_ARGS(device_descriptor->device_version)); 167 if (rc != EOK) { 168 return rc; 169 } 258 170 259 171 /* Next, without release number. */ 260 ADD_MATCHID_OR_RETURN(matches, 90,172 rc = usb_add_match_id(matches, 90, 261 173 "usb&vendor=0x%04x&product=0x%04x", 262 174 (int) device_descriptor->vendor_id, 263 175 (int) device_descriptor->product_id); 176 if (rc != EOK) { 177 return rc; 178 } 264 179 } 265 180 266 181 /* 267 182 * If the device class points to interface we skip adding 268 * class directly but we add a multi interface device.183 * class directly. 269 184 */ 270 185 if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) { 271 ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",186 rc = usb_add_match_id(matches, 50, "usb&class=%s", 272 187 usb_str_class(device_descriptor->device_class)); 273 } else { 274 ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid"); 188 if (rc != EOK) { 189 return rc; 190 } 275 191 } 276 192 … … 278 194 } 279 195 196 /** Create DDF match ids from USB configuration descriptor. 197 * The configuration descriptor is expected to be in the complete form, 198 * i.e. including interface, endpoint etc. descriptors. 199 * 200 * @param matches List of match ids to extend. 201 * @param config_descriptor Configuration descriptor returned by given device. 202 * @param total_size Size of the @p config_descriptor. 203 * @return Error code. 204 */ 205 int usb_drv_create_match_ids_from_configuration_descriptor( 206 match_id_list_t *matches, 207 const void *config_descriptor, size_t total_size) 208 { 209 /* 210 * Iterate through config descriptor to find the interface 211 * descriptors. 212 */ 213 size_t position = sizeof(usb_standard_configuration_descriptor_t); 214 while (position + 1 < total_size) { 215 uint8_t *current_descriptor 216 = ((uint8_t *) config_descriptor) + position; 217 uint8_t cur_descr_len = current_descriptor[0]; 218 uint8_t cur_descr_type = current_descriptor[1]; 219 220 if (cur_descr_len == 0) { 221 return ENOENT; 222 } 223 224 position += cur_descr_len; 225 226 if (cur_descr_type != USB_DESCTYPE_INTERFACE) { 227 continue; 228 } 229 230 /* 231 * Finally, we found an interface descriptor. 232 */ 233 usb_standard_interface_descriptor_t *interface 234 = (usb_standard_interface_descriptor_t *) 235 current_descriptor; 236 237 int rc = usb_add_match_id(matches, 50, 238 "usb&interface&class=%s", 239 usb_str_class(interface->interface_class)); 240 if (rc != EOK) { 241 return rc; 242 } 243 } 244 245 return EOK; 246 } 247 248 /** Add match ids based on configuration descriptor. 249 * 250 * @param pipe Control pipe to the device. 251 * @param matches Match ids list to add matches to. 252 * @param config_count Number of configurations the device has. 253 * @return Error code. 254 */ 255 static int usb_add_config_descriptor_match_ids(usb_endpoint_pipe_t *pipe, 256 match_id_list_t *matches, int config_count) 257 { 258 int final_rc = EOK; 259 260 int config_index; 261 for (config_index = 0; config_index < config_count; config_index++) { 262 int rc; 263 usb_standard_configuration_descriptor_t config_descriptor; 264 rc = usb_request_get_bare_configuration_descriptor(pipe, 265 config_index, &config_descriptor); 266 if (rc != EOK) { 267 final_rc = rc; 268 continue; 269 } 270 271 size_t full_config_descriptor_size; 272 void *full_config_descriptor 273 = malloc(config_descriptor.total_length); 274 rc = usb_request_get_full_configuration_descriptor(pipe, 275 config_index, 276 full_config_descriptor, config_descriptor.total_length, 277 &full_config_descriptor_size); 278 if (rc != EOK) { 279 final_rc = rc; 280 continue; 281 } 282 if (full_config_descriptor_size 283 != config_descriptor.total_length) { 284 final_rc = ERANGE; 285 continue; 286 } 287 288 rc = usb_drv_create_match_ids_from_configuration_descriptor( 289 matches, 290 full_config_descriptor, full_config_descriptor_size); 291 if (rc != EOK) { 292 final_rc = rc; 293 continue; 294 } 295 296 } 297 298 return final_rc; 299 } 280 300 281 301 /** Create match ids describing attached device. … … 310 330 311 331 /* 332 * Go through all configurations and add matches 333 * based on interface class. 334 */ 335 rc = usb_add_config_descriptor_match_ids(ctrl_pipe, matches, 336 device_descriptor.configuration_count); 337 if (rc != EOK) { 338 return rc; 339 } 340 341 /* 312 342 * As a fallback, provide the simplest match id possible. 313 343 */ 314 ADD_MATCHID_OR_RETURN(matches, 1, "usb&fallback"); 344 rc = usb_add_match_id(matches, 1, "usb&fallback"); 345 if (rc != EOK) { 346 return rc; 347 } 315 348 316 349 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.