Changeset 8961c22 in mainline
- Timestamp:
- 2011-04-09T08:35:58Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1e1b1a9
- Parents:
- 3e490eb (diff), 61727bf (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. - Files:
-
- 17 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/amd64/Makefile.inc
r3e490eb r8961c22 50 50 usbhub \ 51 51 usbkbd \ 52 usbhid \ 52 53 usbmid \ 53 54 usbmouse \ -
uspace/Makefile
r3e490eb r8961c22 123 123 drv/usbflbk \ 124 124 drv/usbkbd \ 125 drv/usbhid \ 125 126 drv/usbhub \ 126 127 drv/usbmid \ … … 143 144 drv/usbflbk \ 144 145 drv/usbkbd \ 146 drv/usbhid \ 145 147 drv/usbhub \ 146 148 drv/usbmid \ -
uspace/drv/ohci/root_hub.c
r3e490eb r8961c22 249 249 opResult = EINVAL; 250 250 } 251 usb_transfer_batch_finish (request, opResult);251 usb_transfer_batch_finish_error(request, opResult); 252 252 return EOK; 253 253 } … … 863 863 } 864 864 865 866 867 868 865 /** 869 866 * @} -
uspace/drv/uhci-hcd/batch.c
r3e490eb r8961c22 80 80 * transaction and callback. 81 81 */ 82 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 83 usb_transfer_type_t transfer_type, size_t max_packet_size, 84 usb_speed_t speed, char *buffer, size_t buffer_size, 85 char* setup_buffer, size_t setup_size, 82 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep, 83 char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size, 86 84 usbhc_iface_transfer_in_callback_t func_in, 87 usbhc_iface_transfer_out_callback_t func_out, void *arg , endpoint_t *ep88 ) 89 { 85 usbhc_iface_transfer_out_callback_t func_out, void *arg) 86 { 87 assert(ep); 90 88 assert(func_in == NULL || func_out == NULL); 91 89 assert(func_in != NULL || func_out != NULL); … … 103 101 CHECK_NULL_DISPOSE_RETURN(instance, 104 102 "Failed to allocate batch instance.\n"); 103 usb_target_t target = 104 { .address = ep->address, .endpoint = ep->endpoint }; 105 105 usb_transfer_batch_init(instance, target, 106 transfer_type, speed,max_packet_size,106 ep->transfer_type, ep->speed, ep->max_packet_size, 107 107 buffer, NULL, buffer_size, NULL, setup_size, func_in, 108 108 func_out, arg, fun, ep, NULL); … … 115 115 instance->private_data = data; 116 116 117 data->transfers = (buffer_size + max_packet_size - 1) / max_packet_size; 118 if (transfer_type == USB_TRANSFER_CONTROL) { 117 data->transfers = 118 (buffer_size + ep->max_packet_size - 1) / ep->max_packet_size; 119 if (ep->transfer_type == USB_TRANSFER_CONTROL) { 119 120 data->transfers += 2; 120 121 } … … 178 179 instance, i, data->tds[i].status); 179 180 td_print_status(&data->tds[i]); 180 if (instance->ep != NULL) 181 endpoint_toggle_set(instance->ep, 182 td_toggle(&data->tds[i])); 181 assert(instance->ep != NULL); 182 183 endpoint_toggle_set(instance->ep, 184 td_toggle(&data->tds[i])); 183 185 if (i > 0) 184 186 goto substract_ret; -
uspace/drv/uhci-hcd/batch.h
r3e490eb r8961c22 44 44 45 45 usb_transfer_batch_t * batch_get( 46 ddf_fun_t *fun, 47 usb_target_t target, 48 usb_transfer_type_t transfer_type, 49 size_t max_packet_size, 50 usb_speed_t speed, 51 char *buffer, 52 size_t size, 53 char *setup_buffer, 54 size_t setup_size, 46 ddf_fun_t *fun, endpoint_t *ep, char *buffer, size_t size, 47 char *setup_buffer, size_t setup_size, 55 48 usbhc_iface_transfer_in_callback_t func_in, 56 49 usbhc_iface_transfer_out_callback_t func_out, 57 void *arg, 58 endpoint_t *ep 59 ); 50 void *arg); 60 51 61 52 void batch_dispose(usb_transfer_batch_t *instance); -
uspace/drv/uhci-hcd/hc.c
r3e490eb r8961c22 332 332 instance->transfers[batch->speed][batch->transfer_type]; 333 333 assert(list); 334 if (batch->transfer_type == USB_TRANSFER_CONTROL) {335 usb_device_keeper_use_control(336 &instance->manager, batch->target);337 }338 334 transfer_list_add_batch(list, batch); 339 335 … … 373 369 usb_transfer_batch_t *batch = 374 370 list_get_instance(item, usb_transfer_batch_t, link); 375 switch (batch->transfer_type) 376 { 377 case USB_TRANSFER_CONTROL: 378 usb_device_keeper_release_control( 379 &instance->manager, batch->target); 380 break; 381 case USB_TRANSFER_INTERRUPT: 382 case USB_TRANSFER_ISOCHRONOUS: { 383 /* 384 int ret = bandwidth_free(&instance->bandwidth, 385 batch->target.address, 386 batch->target.endpoint, 387 batch->direction); 388 if (ret != EOK) 389 usb_log_warning("Failed(%d) to free " 390 "reserved bw: %s.\n", ret, 391 str_error(ret)); 392 */ 393 } 394 default: 395 break; 396 } 397 batch->next_step(batch); 371 usb_transfer_batch_finish(batch); 398 372 } 399 373 } -
uspace/drv/uhci-hcd/iface.c
r3e490eb r8961c22 40 40 #include "iface.h" 41 41 #include "hc.h" 42 43 static inline int setup_batch( 44 ddf_fun_t *fun, usb_target_t target, usb_direction_t direction, 45 void *data, size_t size, void * setup_data, size_t setup_size, 46 usbhc_iface_transfer_in_callback_t in, 47 usbhc_iface_transfer_out_callback_t out, void *arg, const char* name, 48 hc_t **hc, usb_transfer_batch_t **batch) 49 { 50 assert(hc); 51 assert(batch); 52 assert(fun); 53 *hc = fun_to_hc(fun); 54 assert(*hc); 55 56 size_t res_bw; 57 endpoint_t *ep = usb_endpoint_manager_get_ep(&(*hc)->ep_manager, 58 target.address, target.endpoint, direction, &res_bw); 59 if (ep == NULL) { 60 usb_log_error("Endpoint(%d:%d) not registered for %s.\n", 61 target.address, target.endpoint, name); 62 return ENOENT; 63 } 64 65 const size_t bw = bandwidth_count_usb11( 66 ep->speed, ep->transfer_type, size, ep->max_packet_size); 67 if (res_bw < bw) { 68 usb_log_error("Endpoint(%d:%d) %s needs %zu bw " 69 "but only %zu is reserved.\n", 70 name, target.address, target.endpoint, bw, res_bw); 71 return ENOSPC; 72 } 73 usb_log_debug("%s %d:%d %zu(%zu).\n", 74 name, target.address, target.endpoint, size, ep->max_packet_size); 75 76 assert(ep->speed == 77 usb_device_keeper_get_speed(&(*hc)->manager, target.address)); 78 // assert(ep->max_packet_size == max_packet_size); 79 // assert(ep->transfer_type == USB_TRANSFER_CONTROL); 80 81 *batch = 82 batch_get(fun, ep, data, size, setup_data, setup_size, 83 in, out, arg); 84 if (!batch) 85 return ENOMEM; 86 return EOK; 87 } 88 42 89 43 90 /** Reserve default address interface function … … 215 262 size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg) 216 263 { 217 assert(fun); 218 hc_t *hc = fun_to_hc(fun); 219 assert(hc); 220 221 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n", 222 target.address, target.endpoint, size, max_packet_size); 223 224 size_t res_bw; 225 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 226 target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw); 227 if (ep == NULL) { 228 usb_log_error("Endpoint(%d:%d) not registered for INT OUT.\n", 229 target.address, target.endpoint); 230 return ENOENT; 231 } 232 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 233 size, ep->max_packet_size); 234 if (res_bw < bw) 235 { 236 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw " 237 "but only %zu is reserved.\n", 238 target.address, target.endpoint, bw, res_bw); 239 return ENOENT; 240 } 241 assert(ep->speed == 242 usb_device_keeper_get_speed(&hc->manager, target.address)); 243 assert(ep->max_packet_size == max_packet_size); 244 assert(ep->transfer_type == USB_TRANSFER_INTERRUPT); 245 246 usb_transfer_batch_t *batch = 247 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 248 ep->speed, data, size, NULL, 0, NULL, callback, arg, ep); 249 if (!batch) 250 return ENOMEM; 264 usb_transfer_batch_t *batch = NULL; 265 hc_t *hc = NULL; 266 int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size, 267 NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch); 268 if (ret != EOK) 269 return ret; 251 270 batch_interrupt_out(batch); 252 const intret = hc_schedule(hc, batch);271 ret = hc_schedule(hc, batch); 253 272 if (ret != EOK) { 254 273 batch_dispose(batch); … … 272 291 size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg) 273 292 { 274 assert(fun); 275 hc_t *hc = fun_to_hc(fun); 276 assert(hc); 277 278 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n", 279 target.address, target.endpoint, size, max_packet_size); 280 281 size_t res_bw; 282 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 283 target.address, target.endpoint, USB_DIRECTION_IN, &res_bw); 284 if (ep == NULL) { 285 usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n", 286 target.address, target.endpoint); 287 return ENOENT; 288 } 289 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 290 size, ep->max_packet_size); 291 if (res_bw < bw) 292 { 293 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw " 294 "but only %zu bw is reserved.\n", 295 target.address, target.endpoint, bw, res_bw); 296 return ENOENT; 297 } 298 299 assert(ep->speed == 300 usb_device_keeper_get_speed(&hc->manager, target.address)); 301 assert(ep->max_packet_size == max_packet_size); 302 assert(ep->transfer_type == USB_TRANSFER_INTERRUPT); 303 304 usb_transfer_batch_t *batch = 305 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 306 ep->speed, data, size, NULL, 0, callback, NULL, arg, ep); 307 if (!batch) 308 return ENOMEM; 293 usb_transfer_batch_t *batch = NULL; 294 hc_t *hc = NULL; 295 int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size, 296 NULL, 0, callback, NULL, arg, "Interrupt IN", &hc, &batch); 297 if (ret != EOK) 298 return ret; 309 299 batch_interrupt_in(batch); 310 const intret = hc_schedule(hc, batch);300 ret = hc_schedule(hc, batch); 311 301 if (ret != EOK) { 312 302 batch_dispose(batch); … … 330 320 size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg) 331 321 { 332 assert(fun); 333 hc_t *hc = fun_to_hc(fun); 334 assert(hc); 335 336 usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n", 337 target.address, target.endpoint, size, max_packet_size); 338 339 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 340 target.address, target.endpoint, USB_DIRECTION_OUT, NULL); 341 if (ep == NULL) { 342 usb_log_error("Endpoint(%d:%d) not registered for BULK OUT.\n", 343 target.address, target.endpoint); 344 return ENOENT; 345 } 346 assert(ep->speed == 347 usb_device_keeper_get_speed(&hc->manager, target.address)); 348 assert(ep->max_packet_size == max_packet_size); 349 assert(ep->transfer_type == USB_TRANSFER_BULK); 350 351 usb_transfer_batch_t *batch = 352 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 353 ep->speed, data, size, NULL, 0, NULL, callback, arg, ep); 354 if (!batch) 355 return ENOMEM; 322 usb_transfer_batch_t *batch = NULL; 323 hc_t *hc = NULL; 324 int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size, 325 NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch); 326 if (ret != EOK) 327 return ret; 356 328 batch_bulk_out(batch); 357 const intret = hc_schedule(hc, batch);329 ret = hc_schedule(hc, batch); 358 330 if (ret != EOK) { 359 331 batch_dispose(batch); … … 377 349 size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg) 378 350 { 379 assert(fun); 380 hc_t *hc = fun_to_hc(fun); 381 assert(hc); 382 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n", 383 target.address, target.endpoint, size, max_packet_size); 384 385 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 386 target.address, target.endpoint, USB_DIRECTION_IN, NULL); 387 if (ep == NULL) { 388 usb_log_error("Endpoint(%d:%d) not registered for BULK IN.\n", 389 target.address, target.endpoint); 390 return ENOENT; 391 } 392 assert(ep->speed == 393 usb_device_keeper_get_speed(&hc->manager, target.address)); 394 assert(ep->max_packet_size == max_packet_size); 395 assert(ep->transfer_type == USB_TRANSFER_BULK); 396 397 usb_transfer_batch_t *batch = 398 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 399 ep->speed, data, size, NULL, 0, callback, NULL, arg, ep); 400 if (!batch) 401 return ENOMEM; 351 usb_transfer_batch_t *batch = NULL; 352 hc_t *hc = NULL; 353 int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size, 354 NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch); 355 if (ret != EOK) 356 return ret; 402 357 batch_bulk_in(batch); 403 const intret = hc_schedule(hc, batch);358 ret = hc_schedule(hc, batch); 404 359 if (ret != EOK) { 405 360 batch_dispose(batch); … … 426 381 usbhc_iface_transfer_out_callback_t callback, void *arg) 427 382 { 428 assert(fun); 429 hc_t *hc = fun_to_hc(fun); 430 assert(hc); 431 usb_speed_t speed = 432 usb_device_keeper_get_speed(&hc->manager, target.address); 433 usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n", 434 speed, target.address, target.endpoint, size, max_packet_size); 435 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 436 target.address, target.endpoint, USB_DIRECTION_BOTH, NULL); 437 if (ep == NULL) { 438 usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n", 439 target.address, target.endpoint); 440 } 441 442 if (setup_size != 8) 443 return EINVAL; 444 445 usb_transfer_batch_t *batch = 446 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed, 447 data, size, setup_data, setup_size, NULL, callback, arg, ep); 448 if (!batch) 449 return ENOMEM; 383 usb_transfer_batch_t *batch = NULL; 384 hc_t *hc = NULL; 385 int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size, 386 setup_data, setup_size, NULL, callback, arg, "Control WRITE", 387 &hc, &batch); 388 if (ret != EOK) 389 return ret; 450 390 usb_device_keeper_reset_if_need(&hc->manager, target, setup_data); 451 391 batch_control_write(batch); 452 const intret = hc_schedule(hc, batch);392 ret = hc_schedule(hc, batch); 453 393 if (ret != EOK) { 454 394 batch_dispose(batch); … … 475 415 usbhc_iface_transfer_in_callback_t callback, void *arg) 476 416 { 477 assert(fun); 478 hc_t *hc = fun_to_hc(fun); 479 assert(hc); 480 usb_speed_t speed = 481 usb_device_keeper_get_speed(&hc->manager, target.address); 482 483 usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n", 484 speed, target.address, target.endpoint, size, max_packet_size); 485 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 486 target.address, target.endpoint, USB_DIRECTION_BOTH, NULL); 487 if (ep == NULL) { 488 usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n", 489 target.address, target.endpoint); 490 } 491 usb_transfer_batch_t *batch = 492 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed, 493 data, size, setup_data, setup_size, callback, NULL, arg, ep); 494 if (!batch) 495 return ENOMEM; 417 usb_transfer_batch_t *batch = NULL; 418 hc_t *hc = NULL; 419 int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size, 420 setup_data, setup_size, callback, NULL, arg, "Control READ", 421 &hc, &batch); 422 if (ret != EOK) 423 return ret; 496 424 batch_control_read(batch); 497 const intret = hc_schedule(hc, batch);425 ret = hc_schedule(hc, batch); 498 426 if (ret != EOK) { 499 427 batch_dispose(batch); -
uspace/drv/uhci-hcd/transfer_list.c
r3e490eb r8961c22 132 132 } 133 133 /*----------------------------------------------------------------------------*/ 134 /** Check list for finished batches. 135 * 136 * @param[in] instance List to use. 137 * @return Error code 138 * 139 * Creates a local list of finished batches and calls next_step on each and 140 * every one. This is safer because next_step may theoretically access 141 * this transfer list leading to the deadlock if its done inline. 134 /** Create list for finished batches. 135 * 136 * @param[in] instance List to use. 137 * @param[in] done list to fill 142 138 */ 143 139 void transfer_list_remove_finished(transfer_list_t *instance, link_t *done) … … 161 157 } 162 158 fibril_mutex_unlock(&instance->guard); 163 164 159 } 165 160 /*----------------------------------------------------------------------------*/ … … 176 171 list_get_instance(current, usb_transfer_batch_t, link); 177 172 transfer_list_remove_batch(instance, batch); 178 usb_transfer_batch_finish (batch, EIO);173 usb_transfer_batch_finish_error(batch, EIO); 179 174 } 180 175 fibril_mutex_unlock(&instance->guard); -
uspace/drv/uhci-rhd/root_hub.h
r3e490eb r8961c22 40 40 41 41 #define UHCI_ROOT_HUB_PORT_COUNT 2 42 #define ROOT_HUB_WAIT_USEC 5000000 /* 5seconds */42 #define ROOT_HUB_WAIT_USEC 250000 /* 250 miliseconds */ 43 43 44 44 typedef struct root_hub { -
uspace/drv/usbkbd/kbddev.c
r3e490eb r8961c22 265 265 static void usb_kbd_set_led(usb_kbd_t *kbd_dev) 266 266 { 267 if (kbd_dev->output_size == 0) { 268 return; 269 } 270 267 271 unsigned i = 0; 268 272 … … 288 292 289 293 int rc = usb_hid_report_output_translate(kbd_dev->parser, 290 kbd_dev->led_path, USB_HID_PATH_COMPARE_END, kbd_dev->output_buffer, 294 kbd_dev->led_path, 295 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 296 kbd_dev->output_buffer, 291 297 kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size); 292 298 … … 539 545 * according to HID Usage Tables. 540 546 * @param count Number of key codes in report (size of the report). 541 * @param modifiers Bitmap of modifiers (Ctrl, Alt, Shift, GUI).547 * @param report_id 542 548 * @param arg User-specified argument. Expects pointer to the keyboard device 543 549 * structure representing the keyboard. … … 546 552 */ 547 553 static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 548 uint8_t modifiers, void *arg)554 uint8_t report_id, void *arg) 549 555 { 550 556 if (arg == NULL) { … … 557 563 assert(kbd_dev != NULL); 558 564 559 usb_log_debug("Got keys from parser : %s\n",560 usb_debug_str_buffer(key_codes, count, 0));565 usb_log_debug("Got keys from parser (report id: %u): %s\n", 566 report_id, usb_debug_str_buffer(key_codes, count, 0)); 561 567 562 568 if (count != kbd_dev->key_count) { … … 608 614 usb_hid_report_path_t *path = usb_hid_report_path(); 609 615 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 616 usb_hid_report_path_set_report_id(path, 0); 610 617 611 618 int rc = usb_hid_parse_report(kbd_dev->parser, buffer, 612 actual_size, path, USB_HID_PATH_COMPARE_STRICT, callbacks, kbd_dev); 619 actual_size, path, 620 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 621 callbacks, kbd_dev); 613 622 614 623 usb_hid_report_path_free (path); … … 758 767 usb_hid_report_path_t *path = usb_hid_report_path(); 759 768 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 769 770 usb_hid_report_path_set_report_id(path, 0); 771 760 772 kbd_dev->key_count = usb_hid_report_input_length( 761 kbd_dev->parser, path, USB_HID_PATH_COMPARE_STRICT); 773 kbd_dev->parser, path, 774 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); 762 775 usb_hid_report_path_free (path); 763 776 … … 777 790 kbd_dev->output_buffer = usb_hid_report_output(kbd_dev->parser, 778 791 &kbd_dev->output_size); 779 if (kbd_dev->output_buffer == NULL ) {792 if (kbd_dev->output_buffer == NULL && kbd_dev->output_size != 0) { 780 793 usb_log_warning("Error creating output report buffer.\n"); 781 794 free(kbd_dev->keys); … … 790 803 791 804 kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser, 792 kbd_dev->led_path, USB_HID_PATH_COMPARE_END); 805 kbd_dev->led_path, 806 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); 793 807 794 808 usb_log_debug("Output report size (in items): %zu\n", -
uspace/drv/usbkbd/main.c
r3e490eb r8961c22 33 33 /** 34 34 * @file 35 * Main routines of USB HID driver.35 * Main routines of USB KBD driver. 36 36 */ 37 37 … … 75 75 * @sa usb_kbd_fibril(), usb_kbd_repeat_fibril() 76 76 */ 77 static int usb hid_try_add_device(usb_device_t *dev)77 static int usb_kbd_try_add_device(usb_device_t *dev) 78 78 { 79 79 /* Create the function exposed under /dev/devices. */ … … 105 105 usb_kbd_free(&kbd_dev); 106 106 return rc; 107 } 107 } 108 108 109 109 usb_log_debug("USB/HID KBD device structure initialized.\n"); … … 195 195 * @retval EREFUSED if the device is not supported. 196 196 */ 197 static int usb hid_add_device(usb_device_t *dev)197 static int usb_kbd_add_device(usb_device_t *dev) 198 198 { 199 usb_log_debug("usb hid_add_device()\n");199 usb_log_debug("usb_kbd_add_device()\n"); 200 200 201 201 if (dev->interface_no < 0) { 202 202 usb_log_warning("Device is not a supported keyboard.\n"); 203 usb_log_error("Failed to add HID device: endpoint not found."204 " \n");203 usb_log_error("Failed to add USB KBD device: endpoint not " 204 "found.\n"); 205 205 return ENOTSUP; 206 206 } 207 207 208 int rc = usb hid_try_add_device(dev);208 int rc = usb_kbd_try_add_device(dev); 209 209 210 210 if (rc != EOK) { 211 211 usb_log_warning("Device is not a supported keyboard.\n"); 212 usb_log_error("Failed to add HID device: %s.\n",212 usb_log_error("Failed to add KBD device: %s.\n", 213 213 str_error(rc)); 214 214 return rc; … … 224 224 /* Currently, the framework supports only device adding. Once the framework 225 225 * supports unplug, more callbacks will be added. */ 226 static usb_driver_ops_t usb hid_driver_ops = {227 .add_device = usb hid_add_device,226 static usb_driver_ops_t usb_kbd_driver_ops = { 227 .add_device = usb_kbd_add_device, 228 228 }; 229 229 230 230 231 231 /* The driver itself. */ 232 static usb_driver_t usb hid_driver = {232 static usb_driver_t usb_kbd_driver = { 233 233 .name = NAME, 234 .ops = &usb hid_driver_ops,234 .ops = &usb_kbd_driver_ops, 235 235 .endpoints = usb_kbd_endpoints 236 236 }; … … 238 238 /*----------------------------------------------------------------------------*/ 239 239 240 //static driver_ops_t kbd_driver_ops = {241 // .add_device = usbhid_add_device,242 //};243 244 ///*----------------------------------------------------------------------------*/245 246 //static driver_t kbd_driver = {247 // .name = NAME,248 // .driver_ops = &kbd_driver_ops249 //};250 251 /*----------------------------------------------------------------------------*/252 253 240 int main(int argc, char *argv[]) 254 241 { 255 printf(NAME ": HelenOS USB HID driver.\n");242 printf(NAME ": HelenOS USB KBD driver.\n"); 256 243 257 244 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 258 245 259 return usb_driver_main(&usb hid_driver);246 return usb_driver_main(&usb_kbd_driver); 260 247 } 261 248 -
uspace/drv/usbkbd/usbkbd.ma
r3e490eb r8961c22 1 100 usb&interface&class=HID&subclass=0x01&protocol=0x01 2 10 usb&interface&class=HID 1 10 usb&interface&class=HID&subclass=0x01&protocol=0x01 -
uspace/lib/usb/include/usb/classes/hidparser.h
r3e490eb r8961c22 88 88 /** */ 89 89 int depth; 90 uint8_t report_id; 90 91 91 92 /** */ 92 93 link_t link; 94 93 95 } usb_hid_report_path_t; 94 96 … … 155 157 /** */ 156 158 link_t feature; 159 160 int use_report_id; 161 162 /** */ 163 link_t stack; 157 164 } usb_hid_report_parser_t; 158 165 … … 166 173 * @param arg Custom argument. 167 174 */ 168 void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t modifiers, void *arg);175 void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg); 169 176 } usb_hid_report_in_callbacks_t; 170 177 … … 269 276 270 277 /** */ 278 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, uint8_t report_id); 279 280 /** */ 271 281 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage); 272 282 -
uspace/lib/usb/include/usb/host/batch.h
r3e490eb r8961c22 92 92 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance); 93 93 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance); 94 void usb_transfer_batch_finish(usb_transfer_batch_t *instance, int error); 94 void usb_transfer_batch_finish(usb_transfer_batch_t *instance); 95 96 static inline void usb_transfer_batch_finish_error( 97 usb_transfer_batch_t *instance, int error) 98 { 99 assert(instance); 100 instance->error = error; 101 usb_transfer_batch_finish(instance); 102 } 95 103 96 104 #endif -
uspace/lib/usb/include/usb/host/device_keeper.h
r3e490eb r8961c22 96 96 usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance, 97 97 usb_address_t address); 98 99 void usb_device_keeper_use_control(usb_device_keeper_t *instance,100 usb_target_t target);101 102 void usb_device_keeper_release_control(usb_device_keeper_t *instance,103 usb_target_t target);104 105 98 #endif 106 99 /** -
uspace/lib/usb/include/usb/host/endpoint.h
r3e490eb r8961c22 39 39 #include <bool.h> 40 40 #include <adt/list.h> 41 #include <fibril_synch.h> 42 41 43 #include <usb/usb.h> 42 44 … … 48 50 usb_speed_t speed; 49 51 size_t max_packet_size; 50 bool active;51 52 unsigned toggle:1; 53 fibril_mutex_t guard; 54 fibril_condvar_t avail; 55 volatile bool active; 52 56 link_t same_device_eps; 53 57 } endpoint_t; … … 58 62 59 63 void endpoint_destroy(endpoint_t *instance); 64 65 void endpoint_use(endpoint_t *instance); 66 67 void endpoint_release(endpoint_t *instance); 60 68 61 69 int endpoint_toggle_get(endpoint_t *instance); -
uspace/lib/usb/src/devpoll.c
r3e490eb r8961c22 66 66 usb_pipe_t *pipe 67 67 = polling_data->dev->pipes[polling_data->pipe_index].pipe; 68 69 usb_log_debug("Pipe interface number: %d, protocol: %d, subclass: %d, max packet size: %d\n", 70 polling_data->dev->pipes[polling_data->pipe_index].interface_no, 71 polling_data->dev->pipes[polling_data->pipe_index].description->interface_protocol, 72 polling_data->dev->pipes[polling_data->pipe_index].description->interface_subclass, 73 pipe->max_packet_size); 68 74 69 75 size_t failed_attempts = 0; … … 83 89 /* Quit the session regardless of errors. */ 84 90 usb_pipe_end_session(pipe); 91 92 // if (rc == ESTALL) { 93 // usb_log_debug("Seding clear feature...\n"); 94 // usb_request_clear_feature(pipe, USB_REQUEST_TYPE_STANDARD, 95 // USB_REQUEST_RECIPIENT_ENDPOINT, 0, pipe->endpoint_no); 96 // continue; 97 // } 85 98 86 99 if (rc != EOK) { -
uspace/lib/usb/src/hidparser.c
r3e490eb r8961c22 64 64 int usb_hid_report_reset_local_items(); 65 65 void usb_hid_free_report_list(link_t *head); 66 66 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item); 67 67 /* 68 68 * Data translation private functions … … 106 106 list_initialize(&(parser->feature)); 107 107 108 list_initialize(&(parser->stack)); 109 110 parser->use_report_id = 0; 108 111 return EOK; 109 112 } … … 186 189 tmp_usage_path = NULL; 187 190 191 usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id); 192 if(report_item->id != 0){ 193 parser->use_report_id = 1; 194 } 188 195 189 196 switch(tag) { … … 215 222 if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) { 216 223 return ENOMEM; 217 } 224 } 218 225 memcpy(new_report_item,report_item, sizeof(usb_hid_report_item_t)); 226 link_initialize(&(new_report_item->link)); 227 219 228 /* reset local items */ 220 229 new_report_item->usage_minimum = 0; 221 230 new_report_item->usage_maximum = 0; 231 new_report_item->designator_index = 0; 232 new_report_item->designator_minimum = 0; 233 new_report_item->designator_maximum = 0; 234 new_report_item->string_index = 0; 235 new_report_item->string_minimum = 0; 236 new_report_item->string_maximum = 0; 237 238 /* reset usage from current usage path */ 239 usb_hid_report_usage_path_t *path = list_get_instance(&usage_path->link, usb_hid_report_usage_path_t, link); 240 path->usage = 0; 222 241 223 link_initialize(&(new_report_item->link));224 242 report_item = new_report_item; 225 243 … … 227 245 case USB_HID_REPORT_TAG_PUSH: 228 246 // push current state to stack 229 // not yet implemented 247 new_report_item = usb_hid_report_item_clone(report_item); 248 list_prepend (&parser->stack, &new_report_item->link); 249 230 250 break; 231 251 case USB_HID_REPORT_TAG_POP: 232 252 // restore current state from stack 233 // not yet implemented 253 if(list_empty (&parser->stack)) { 254 return EINVAL; 255 } 256 257 report_item = list_get_instance(&parser->stack, usb_hid_report_item_t, link); 258 list_remove (parser->stack.next); 259 234 260 break; 235 261 … … 647 673 } 648 674 675 parser->use_report_id = 0; 676 649 677 usb_hid_free_report_list(&parser->input); 650 678 usb_hid_free_report_list(&parser->output); … … 676 704 size_t i=0; 677 705 size_t j=0; 706 uint8_t report_id = 0; 678 707 679 708 if(parser == NULL) { … … 686 715 if(!(keys = malloc(sizeof(uint8_t) * key_count))){ 687 716 return ENOMEM; 717 } 718 719 if(parser->use_report_id != 0) { 720 report_id = data[0]; 721 usb_hid_report_path_set_report_id(path, report_id); 688 722 } 689 723 … … 693 727 694 728 item = list_get_instance(list_item, usb_hid_report_item_t, link); 729 695 730 if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) && 696 731 (usb_hid_report_compare_usage_path(item->usage_path, path, flags) == EOK)) { … … 715 750 } 716 751 717 callbacks->keyboard(keys, key_count, 0, arg);752 callbacks->keyboard(keys, key_count, report_id, arg); 718 753 719 754 free(keys); … … 739 774 int32_t mask; 740 775 const uint8_t *foo; 741 776 742 777 // now only common numbers llowed 743 778 if(item->size > 32) { … … 758 793 (usb_pow(10,(item->unit_exponent)))); 759 794 } 795 760 796 offset = item->offset + (j * item->size); 797 if(item->id != 0) { 798 offset += 8; 799 usb_log_debug("MOVED OFFSET BY 1Byte, REPORT_ID(%d)\n", item->id); 800 } 761 801 762 802 // FIXME … … 942 982 943 983 int only_page; 984 985 if(report_path->report_id != path->report_id) { 986 return 1; 987 } 944 988 945 989 if(path->depth == 0){ … … 1038 1082 else { 1039 1083 path->depth = 0; 1084 path->report_id = 0; 1040 1085 list_initialize(&path->link); 1041 1086 return path; … … 1155 1200 return 0; 1156 1201 } 1157 1202 1158 1203 item = parser->output.next; 1159 1204 while(&parser->output != item) { … … 1195 1240 int length; 1196 1241 int32_t tmp_value; 1242 size_t offset_prefix = 0; 1197 1243 1198 1244 if(parser == NULL) { 1199 1245 return EINVAL; 1246 } 1247 1248 if(parser->use_report_id != 0) { 1249 buffer[0] = path->report_id; 1250 offset_prefix = 8; 1200 1251 } 1201 1252 … … 1218 1269 // // variable item 1219 1270 value = usb_hid_translate_data_reverse(report_item, data[idx++]); 1220 offset = report_item->offset + (i * report_item->size) ;1271 offset = report_item->offset + (i * report_item->size) + offset_prefix; 1221 1272 length = report_item->size; 1222 1273 } … … 1224 1275 //bitmap 1225 1276 value += usb_hid_translate_data_reverse(report_item, data[idx++]); 1226 offset = report_item->offset ;1277 offset = report_item->offset + offset_prefix; 1227 1278 length = report_item->size * report_item->count; 1228 1279 } … … 1323 1374 1324 1375 1376 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id) 1377 { 1378 if(path == NULL){ 1379 return EINVAL; 1380 } 1381 1382 path->report_id = report_id; 1383 return EOK; 1384 } 1385 1386 1387 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item) 1388 { 1389 usb_hid_report_item_t *new_report_item; 1390 1391 if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) { 1392 return NULL; 1393 } 1394 memcpy(new_report_item,item, sizeof(usb_hid_report_item_t)); 1395 link_initialize(&(new_report_item->link)); 1396 1397 return new_report_item; 1398 } 1399 1325 1400 /** 1326 1401 * @} -
uspace/lib/usb/src/hidreport.c
r3e490eb r8961c22 80 80 d = usb_dp_get_sibling_descriptor(&parser, &parser_data, 81 81 dev->descriptors.configuration, d); 82 ++i; 82 83 } 83 84 -
uspace/lib/usb/src/host/batch.c
r3e490eb r8961c22 79 79 instance->error = EOK; 80 80 instance->ep = ep; 81 endpoint_use(instance->ep); 81 82 } 82 83 /*----------------------------------------------------------------------------*/ … … 86 87 * 87 88 */ 88 void usb_transfer_batch_finish(usb_transfer_batch_t *instance , int error)89 void usb_transfer_batch_finish(usb_transfer_batch_t *instance) 89 90 { 90 91 assert(instance); 91 instance->error = error; 92 assert(instance->ep); 93 endpoint_release(instance->ep); 92 94 instance->next_step(instance); 93 95 } -
uspace/lib/usb/src/host/device_keeper.c
r3e490eb r8961c22 264 264 return instance->devices[address].speed; 265 265 } 266 /*----------------------------------------------------------------------------*/267 void usb_device_keeper_use_control(268 usb_device_keeper_t *instance, usb_target_t target)269 {270 assert(instance);271 const uint16_t ep = 1 << target.endpoint;272 fibril_mutex_lock(&instance->guard);273 while (instance->devices[target.address].control_used & ep) {274 fibril_condvar_wait(&instance->change, &instance->guard);275 }276 instance->devices[target.address].control_used |= ep;277 fibril_mutex_unlock(&instance->guard);278 }279 /*----------------------------------------------------------------------------*/280 void usb_device_keeper_release_control(281 usb_device_keeper_t *instance, usb_target_t target)282 {283 assert(instance);284 const uint16_t ep = 1 << target.endpoint;285 fibril_mutex_lock(&instance->guard);286 assert((instance->devices[target.address].control_used & ep) != 0);287 instance->devices[target.address].control_used &= ~ep;288 fibril_mutex_unlock(&instance->guard);289 fibril_condvar_signal(&instance->change);290 }291 266 /** 292 267 * @} -
uspace/lib/usb/src/host/endpoint.c
r3e490eb r8961c22 34 34 */ 35 35 36 #include <assert.h> 36 37 #include <errno.h> 37 38 #include <usb/host/endpoint.h> … … 49 50 instance->max_packet_size = max_packet_size; 50 51 instance->toggle = 0; 52 instance->active = false; 53 fibril_mutex_initialize(&instance->guard); 54 fibril_condvar_initialize(&instance->avail); 51 55 link_initialize(&instance->same_device_eps); 52 56 return EOK; … … 56 60 { 57 61 assert(instance); 62 assert(!instance->active); 58 63 list_remove(&instance->same_device_eps); 59 64 free(instance); 65 } 66 /*----------------------------------------------------------------------------*/ 67 void endpoint_use(endpoint_t *instance) 68 { 69 assert(instance); 70 fibril_mutex_lock(&instance->guard); 71 while (instance->active) 72 fibril_condvar_wait(&instance->avail, &instance->guard); 73 instance->active = true; 74 fibril_mutex_unlock(&instance->guard); 75 } 76 /*----------------------------------------------------------------------------*/ 77 void endpoint_release(endpoint_t *instance) 78 { 79 assert(instance); 80 fibril_mutex_lock(&instance->guard); 81 instance->active = false; 82 fibril_mutex_unlock(&instance->guard); 83 fibril_condvar_signal(&instance->avail); 60 84 } 61 85 /*----------------------------------------------------------------------------*/ -
uspace/lib/usb/src/hub.c
r3e490eb r8961c22 178 178 * error codes than those listed as return codes by this function itself). 179 179 * 180 * The @p connection representing connection with host controller does not 181 * need to be started. 182 * This function duplicates the connection to allow simultaneous calls of 183 * this function (i.e. from different fibrils). 184 * 180 185 * @param[in] parent Parent device (i.e. the hub device). 181 * @param[in] connection Opened connection to host controller.186 * @param[in] connection Connection to host controller. 182 187 * @param[in] dev_speed New device speed. 183 188 * @param[in] enable_port Function for enabling signaling through the port the … … 206 211 ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun) 207 212 { 208 CHECK_CONNECTION(connection); 213 assert(connection != NULL); 214 // FIXME: this is awful, we are accessing directly the structure. 215 usb_hc_connection_t hc_conn = { 216 .hc_handle = connection->hc_handle, 217 .hc_phone = -1 218 }; 219 220 int rc; 221 222 rc = usb_hc_connection_open(&hc_conn); 223 if (rc != EOK) { 224 return rc; 225 } 226 209 227 210 228 /* 211 229 * Request new address. 212 230 */ 213 usb_address_t dev_addr = usb_hc_request_address( connection, dev_speed);231 usb_address_t dev_addr = usb_hc_request_address(&hc_conn, dev_speed); 214 232 if (dev_addr < 0) { 233 usb_hc_connection_close(&hc_conn); 215 234 return EADDRNOTAVAIL; 216 235 } 217 236 218 int rc;219 237 220 238 /* 221 239 * Reserve the default address. 222 240 */ 223 rc = usb_hc_reserve_default_address( connection, dev_speed);241 rc = usb_hc_reserve_default_address(&hc_conn, dev_speed); 224 242 if (rc != EOK) { 225 243 rc = EBUSY; … … 241 259 usb_device_connection_t dev_conn; 242 260 rc = usb_device_connection_initialize_on_default_address(&dev_conn, 243 connection);261 &hc_conn); 244 262 if (rc != EOK) { 245 263 rc = ENOTCONN; … … 258 276 * endpoint. 259 277 */ 260 rc = usb_pipe_register(&ctrl_pipe, 0, connection);278 rc = usb_pipe_register(&ctrl_pipe, 0, &hc_conn); 261 279 if (rc != EOK) { 262 280 rc = EREFUSED; … … 286 304 * Register the control endpoint for the new device. 287 305 */ 288 rc = usb_pipe_register(&ctrl_pipe, 0, connection);306 rc = usb_pipe_register(&ctrl_pipe, 0, &hc_conn); 289 307 if (rc != EOK) { 290 308 rc = EREFUSED; … … 295 313 * Release the original endpoint. 296 314 */ 297 unregister_control_endpoint_on_default_address( connection);315 unregister_control_endpoint_on_default_address(&hc_conn); 298 316 299 317 /* 300 318 * Once the address is changed, we can return the default address. 301 319 */ 302 usb_hc_release_default_address( connection);320 usb_hc_release_default_address(&hc_conn); 303 321 304 322 … … 325 343 .handle = child_handle 326 344 }; 327 rc = usb_hc_register_device( connection, &new_device);345 rc = usb_hc_register_device(&hc_conn, &new_device); 328 346 if (rc != EOK) { 329 347 rc = EDESTADDRREQ; … … 354 372 355 373 leave_unregister_endpoint: 356 usb_pipe_unregister(&ctrl_pipe, connection);374 usb_pipe_unregister(&ctrl_pipe, &hc_conn); 357 375 358 376 leave_release_default_address: 359 usb_hc_release_default_address( connection);377 usb_hc_release_default_address(&hc_conn); 360 378 361 379 leave_release_free_address: 362 usb_hc_unregister_device(connection, dev_addr); 380 usb_hc_unregister_device(&hc_conn, dev_addr); 381 382 usb_hc_connection_close(&hc_conn); 363 383 364 384 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.