Changeset 76ef94e in mainline
- Timestamp:
- 2011-05-07T15:51:20Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3ae5ca8
- Parents:
- d2bff2f (diff), b23e9cc (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:
-
- 4 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
rd2bff2f r76ef94e 49 49 ./uspace/app/killall/killall 50 50 ./uspace/app/klog/klog 51 ./uspace/app/lsusb/lsusb 51 52 ./uspace/app/mkfat/mkfat 52 53 ./uspace/app/netstart/netstart -
boot/Makefile.common
rd2bff2f r76ef94e 128 128 $(USPACE_PATH)/app/killall/killall \ 129 129 $(USPACE_PATH)/app/mkfat/mkfat \ 130 $(USPACE_PATH)/app/lsusb/lsusb \ 130 131 $(USPACE_PATH)/app/sbi/sbi \ 131 132 $(USPACE_PATH)/app/redir/redir \ -
uspace/Makefile
rd2bff2f r76ef94e 41 41 app/killall \ 42 42 app/klog \ 43 app/lsusb \ 43 44 app/mkfat \ 44 45 app/redir \ -
uspace/app/usbinfo/dev.c
rd2bff2f r76ef94e 40 40 #include "usbinfo.h" 41 41 42 usbinfo_device_t *prepare_device( devman_handle_t hc_handle,43 usb_address_t dev_addr)42 usbinfo_device_t *prepare_device(const char *name, 43 devman_handle_t hc_handle, usb_address_t dev_addr) 44 44 { 45 45 usbinfo_device_t *dev = malloc(sizeof(usbinfo_device_t)); … … 55 55 if (rc != EOK) { 56 56 fprintf(stderr, 57 NAME ": failed to create connection to the device: %s.\n",58 str_error(rc));57 NAME ": failed to create connection to device %s: %s.\n", 58 name, str_error(rc)); 59 59 goto leave; 60 60 } … … 64 64 if (rc != EOK) { 65 65 fprintf(stderr, 66 NAME ": failed to create default control pipe : %s.\n",67 str_error(rc));66 NAME ": failed to create default control pipe to %s: %s.\n", 67 name, str_error(rc)); 68 68 goto leave; 69 69 } … … 71 71 rc = usb_pipe_probe_default_control(&dev->ctrl_pipe); 72 72 if (rc != EOK) { 73 fprintf(stderr, 74 NAME ": probing default control pipe failed: %s.\n", 75 str_error(rc)); 73 if (rc == ENOENT) { 74 fprintf(stderr, NAME ": " \ 75 "device %s not present or malfunctioning.\n", 76 name); 77 } else { 78 fprintf(stderr, NAME ": " \ 79 "probing default control pipe of %s failed: %s.\n", 80 name, str_error(rc)); 81 } 76 82 goto leave; 77 83 } … … 84 90 if (rc != EOK) { 85 91 fprintf(stderr, 86 NAME ": failed to retrieve device descriptor : %s.\n",87 str_error(rc));92 NAME ": failed to retrieve device descriptor of %s: %s.\n", 93 name, str_error(rc)); 88 94 goto leave; 89 95 } … … 93 99 &dev->full_configuration_descriptor_size); 94 100 if (rc != EOK) { 95 fprintf(stderr, 96 NAME ": failed to retrieve configuration descriptor: %s.\n",97 str_error(rc));101 fprintf(stderr, NAME ": " \ 102 "failed to retrieve configuration descriptor of %s: %s.\n", 103 name, str_error(rc)); 98 104 goto leave; 99 105 } -
uspace/app/usbinfo/main.c
rd2bff2f r76ef94e 45 45 #include <usb/usbdevice.h> 46 46 #include <usb/pipes.h> 47 #include <usb/host.h> 47 48 #include "usbinfo.h" 49 50 static bool try_parse_class_and_address(const char *path, 51 devman_handle_t *out_hc_handle, usb_address_t *out_device_address) 52 { 53 size_t class_index; 54 size_t address; 55 int rc; 56 char *ptr; 57 58 rc = str_size_t(path, &ptr, 10, false, &class_index); 59 if (rc != EOK) { 60 return false; 61 } 62 if ((*ptr == ':') || (*ptr == '.')) { 63 ptr++; 64 } else { 65 return false; 66 } 67 rc = str_size_t(ptr, NULL, 10, true, &address); 68 if (rc != EOK) { 69 return false; 70 } 71 rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle); 72 if (rc != EOK) { 73 return false; 74 } 75 if (out_device_address != NULL) { 76 *out_device_address = (usb_address_t) address; 77 } 78 return true; 79 } 48 80 49 81 static bool resolve_hc_handle_and_dev_addr(const char *devpath, … … 60 92 if (str_cmp(devpath, "virt") == 0) { 61 93 devpath = "/virt/usbhc/usb00_a1/usb00_a2"; 94 } 95 96 if (try_parse_class_and_address(devpath, 97 out_hc_handle, out_device_address)) { 98 return true; 62 99 } 63 100 … … 271 308 } 272 309 273 usbinfo_device_t *dev = prepare_device(hc_handle, dev_addr); 310 usbinfo_device_t *dev = prepare_device(devpath, 311 hc_handle, dev_addr); 274 312 if (dev == NULL) { 275 313 continue; -
uspace/app/usbinfo/usbinfo.h
rd2bff2f r76ef94e 71 71 } 72 72 73 usbinfo_device_t *prepare_device( devman_handle_t, usb_address_t);73 usbinfo_device_t *prepare_device(const char *, devman_handle_t, usb_address_t); 74 74 void destroy_device(usbinfo_device_t *); 75 75 -
uspace/doc/doxygroups.h
rd2bff2f r76ef94e 220 220 221 221 /** 222 * @defgroup lsusb HelenOS version of lsusb command 223 * @ingroup usb 224 * @brief Application for listing USB host controllers. 225 * @details 226 * List all found host controllers. 227 */ 228 229 /** 222 230 * @defgroup drvusbmid USB multi interface device driver 223 231 * @ingroup usb -
uspace/drv/ehci-hcd/main.c
rd2bff2f r76ef94e 97 97 } 98 98 hc_fun->ops = &hc_ops; 99 99 100 ret = ddf_fun_bind(hc_fun); 100 101 101 CHECK_RET_RETURN(ret, 102 102 "Failed to bind EHCI function: %s.\n", 103 str_error(ret)); 104 ret = ddf_fun_add_to_class(hc_fun, USB_HC_DDF_CLASS_NAME); 105 CHECK_RET_RETURN(ret, 106 "Failed to add EHCI to HC class: %s.\n", 103 107 str_error(ret)); 104 108 -
uspace/drv/ohci/ohci.c
rd2bff2f r76ef94e 230 230 ret, str_error(ret)); 231 231 232 ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME); 233 CHECK_RET_FINI_RETURN(ret, 234 "Failed to add OHCI to HC class: %s.\n", str_error(ret)); 235 232 236 device->driver_data = instance; 233 237 -
uspace/drv/ohci/root_hub.c
rd2bff2f r76ef94e 45 45 46 46 /** 47 * 47 * standart device descriptor for ohci root hub 48 48 */ 49 49 static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = { … … 69 69 */ 70 70 static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = { 71 /// \TODO some values are default or guessed72 71 .attributes = 1 << 7, 73 72 .configuration_number = 1, … … 87 86 .endpoint_count = 1, 88 87 .interface_class = USB_CLASS_HUB, 89 /// \TODO is this correct?90 88 .interface_number = 1, 91 89 .interface_protocol = 0, … … 107 105 }; 108 106 107 /** 108 * bitmask of hub features that are valid to be cleared 109 */ 109 110 static const uint32_t hub_clear_feature_valid_mask = 110 111 (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) | 111 112 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 112 113 114 /** 115 * bitmask of hub features that are cleared by writing 1 (and not 0) 116 */ 113 117 static const uint32_t hub_clear_feature_by_writing_one_mask = 114 1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER; 115 118 1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER; 119 120 /** 121 * bitmask of hub features that are valid to be set 122 */ 116 123 static const uint32_t hub_set_feature_valid_mask = 117 124 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) | 118 125 (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER); 119 126 120 127 /** 128 * bitmask of hub features that are set by writing 1 and cleared by writing 0 129 */ 121 130 static const uint32_t hub_set_feature_direct_mask = 122 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 123 131 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 132 133 /** 134 * bitmask of port features that are valid to be set 135 */ 124 136 static const uint32_t port_set_feature_valid_mask = 125 137 (1 << USB_HUB_FEATURE_PORT_ENABLE) | 126 138 (1 << USB_HUB_FEATURE_PORT_SUSPEND) | 127 139 (1 << USB_HUB_FEATURE_PORT_RESET) | 128 140 (1 << USB_HUB_FEATURE_PORT_POWER); 129 141 142 /** 143 * bitmask of port features that can be cleared 144 */ 130 145 static const uint32_t port_clear_feature_valid_mask = 131 146 (1 << USB_HUB_FEATURE_PORT_CONNECTION) | 132 147 (1 << USB_HUB_FEATURE_PORT_SUSPEND) | 133 148 (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) | … … 141 156 //USB_HUB_FEATURE_PORT_LOW_SPEED 142 157 158 /** 159 * bitmask with port status changes 160 */ 143 161 static const uint32_t port_status_change_mask = 144 (1<< USB_HUB_FEATURE_C_PORT_CONNECTION) |145 (1 << USB_HUB_FEATURE_C_PORT_ENABLE) |146 (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |147 (1 << USB_HUB_FEATURE_C_PORT_RESET) |148 (1 << USB_HUB_FEATURE_C_PORT_SUSPEND);162 (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) | 163 (1 << USB_HUB_FEATURE_C_PORT_ENABLE) | 164 (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) | 165 (1 << USB_HUB_FEATURE_C_PORT_RESET) | 166 (1 << USB_HUB_FEATURE_C_PORT_SUSPEND); 149 167 150 168 … … 154 172 155 173 static int process_get_port_status_request(rh_t *instance, uint16_t port, 156 174 usb_transfer_batch_t * request); 157 175 158 176 static int process_get_hub_status_request(rh_t *instance, 159 177 usb_transfer_batch_t * request); 160 178 161 179 static int process_get_status_request(rh_t *instance, 162 180 usb_transfer_batch_t * request); 163 181 164 182 static void create_interrupt_mask_in_instance(rh_t *instance); 165 183 166 184 static int process_get_descriptor_request(rh_t *instance, 167 185 usb_transfer_batch_t *request); 168 186 169 187 static int process_get_configuration_request(rh_t *instance, 170 188 usb_transfer_batch_t *request); 171 189 172 190 static int process_hub_feature_set_request(rh_t *instance, uint16_t feature); 173 191 174 192 static int process_hub_feature_clear_request(rh_t *instance, 175 193 uint16_t feature); 176 194 177 195 static int process_port_feature_set_request(rh_t *instance, 178 196 uint16_t feature, uint16_t port); 179 197 180 198 static int process_port_feature_clear_request(rh_t *instance, 181 199 uint16_t feature, uint16_t port); 182 200 183 201 static int process_address_set_request(rh_t *instance, 184 202 uint16_t address); 185 203 186 204 static int process_request_with_output(rh_t *instance, 187 205 usb_transfer_batch_t *request); 188 206 189 207 static int process_request_with_input(rh_t *instance, 190 208 usb_transfer_batch_t *request); 191 209 192 210 static int process_request_without_data(rh_t *instance, 193 211 usb_transfer_batch_t *request); 194 212 195 213 static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request); … … 198 216 199 217 static bool is_zeros(void * buffer, size_t size); 200 201 202 218 203 219 /** Root hub initialization … … 210 226 (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK; 211 227 int opResult = rh_init_descriptors(instance); 212 if (opResult != EOK){228 if (opResult != EOK) { 213 229 return opResult; 214 230 } … … 216 232 instance->registers->rh_desc_a |= RHDA_NPS_FLAG; 217 233 instance->unfinished_interrupt_transfer = NULL; 218 instance->interrupt_mask_size = (instance->port_count + 8) /8;234 instance->interrupt_mask_size = (instance->port_count + 8) / 8; 219 235 instance->interrupt_buffer = malloc(instance->interrupt_mask_size); 220 if (!instance->interrupt_buffer)236 if (!instance->interrupt_buffer) 221 237 return ENOMEM; 222 223 224 usb_log_info("OHCI root hub with %d ports.\n", instance->port_count); 238 239 usb_log_info("OHCI root hub with %d ports initialized.\n", 240 instance->port_count); 241 225 242 return EOK; 226 243 } … … 245 262 usb_log_info("Root hub got INTERRUPT packet\n"); 246 263 create_interrupt_mask_in_instance(instance); 247 if (is_zeros(instance->interrupt_buffer,248 instance->interrupt_mask_size)) {264 if (is_zeros(instance->interrupt_buffer, 265 instance->interrupt_mask_size)) { 249 266 usb_log_debug("no changes..\n"); 250 267 instance->unfinished_interrupt_transfer = request; 251 268 //will be finished later 252 } else{269 } else { 253 270 usb_log_debug("processing changes..\n"); 254 271 process_interrupt_mask_in_instance(instance, request); … … 256 273 opResult = EOK; 257 274 } else { 275 258 276 opResult = EINVAL; 259 277 usb_transfer_batch_finish_error(request, opResult); … … 271 289 */ 272 290 void rh_interrupt(rh_t *instance) { 273 if (!instance->unfinished_interrupt_transfer){291 if (!instance->unfinished_interrupt_transfer) { 274 292 return; 275 293 } … … 292 310 static int create_serialized_hub_descriptor(rh_t *instance) { 293 311 size_t size = 7 + 294 ((instance->port_count + 7 )/ 8) * 2;295 size_t var_size = (instance->port_count + 7 )/ 8;312 ((instance->port_count + 7) / 8) * 2; 313 size_t var_size = (instance->port_count + 7) / 8; 296 314 uint8_t * result = (uint8_t*) malloc(size); 297 if (!result) return ENOMEM;315 if (!result) return ENOMEM; 298 316 299 317 bzero(result, size); … … 305 323 uint32_t hub_desc_reg = instance->registers->rh_desc_a; 306 324 result[3] = 307 308 309 310 311 325 ((hub_desc_reg >> 8) % 2) + 326 (((hub_desc_reg >> 9) % 2) << 1) + 327 (((hub_desc_reg >> 10) % 2) << 2) + 328 (((hub_desc_reg >> 11) % 2) << 3) + 329 (((hub_desc_reg >> 12) % 2) << 4); 312 330 result[4] = 0; 313 331 result[5] = /*descriptor->pwr_on_2_good_time*/ 50; 314 332 result[6] = 50; 315 333 316 int port;334 size_t port; 317 335 for (port = 1; port <= instance->port_count; ++port) { 318 336 uint8_t is_non_removable = 319 337 instance->registers->rh_desc_b >> port % 2; 320 338 result[7 + port / 8] += 321 339 is_non_removable << (port % 8); 322 340 } 323 341 size_t i; … … 327 345 instance->hub_descriptor = result; 328 346 instance->descriptor_size = size; 347 329 348 return EOK; 330 349 } … … 340 359 static int rh_init_descriptors(rh_t *instance) { 341 360 memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor, 342 343 361 sizeof (ohci_rh_device_descriptor) 362 ); 344 363 usb_standard_configuration_descriptor_t descriptor; 345 364 memcpy(&descriptor, &ohci_rh_conf_descriptor, 346 365 sizeof (ohci_rh_conf_descriptor)); 347 366 348 367 int opResult = create_serialized_hub_descriptor(instance); 349 if (opResult != EOK){368 if (opResult != EOK) { 350 369 return opResult; 351 370 } 352 371 descriptor.total_length = 353 354 355 356 372 sizeof (usb_standard_configuration_descriptor_t) + 373 sizeof (usb_standard_endpoint_descriptor_t) + 374 sizeof (usb_standard_interface_descriptor_t) + 375 instance->descriptor_size; 357 376 358 377 uint8_t * full_config_descriptor = 359 360 if (!full_config_descriptor){378 (uint8_t*) malloc(descriptor.total_length); 379 if (!full_config_descriptor) { 361 380 return ENOMEM; 362 381 } 363 382 memcpy(full_config_descriptor, &descriptor, sizeof (descriptor)); 364 383 memcpy(full_config_descriptor + sizeof (descriptor), 365 384 &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor)); 366 385 memcpy(full_config_descriptor + sizeof (descriptor) + 367 368 386 sizeof (ohci_rh_iface_descriptor), 387 &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor)); 369 388 memcpy(full_config_descriptor + sizeof (descriptor) + 370 371 372 373 389 sizeof (ohci_rh_iface_descriptor) + 390 sizeof (ohci_rh_ep_descriptor), 391 instance->hub_descriptor, instance->descriptor_size); 392 374 393 instance->descriptors.configuration = full_config_descriptor; 375 394 instance->descriptors.configuration_size = descriptor.total_length; 395 376 396 return EOK; 377 397 } … … 389 409 */ 390 410 static int process_get_port_status_request(rh_t *instance, uint16_t port, 391 411 usb_transfer_batch_t * request) { 392 412 if (port < 1 || port > instance->port_count) 393 413 return EINVAL; … … 398 418 int i; 399 419 for (i = 0; i < instance->port_count; ++i) { 420 400 421 usb_log_debug("port status %d,x%x\n", 401 402 422 instance->registers->rh_port_status[i], 423 instance->registers->rh_port_status[i]); 403 424 } 404 425 #endif … … 417 438 */ 418 439 static int process_get_hub_status_request(rh_t *instance, 419 440 usb_transfer_batch_t * request) { 420 441 uint32_t * uint32_buffer = (uint32_t*) request->data_buffer; 421 442 request->transfered_size = 4; … … 423 444 uint32_t mask = 1 | (1 << 1) | (1 << 16) | (1 << 17); 424 445 uint32_buffer[0] = mask & instance->registers->rh_status; 446 425 447 return EOK; 426 448 } … … 437 459 */ 438 460 static int process_get_status_request(rh_t *instance, 439 461 usb_transfer_batch_t * request) { 440 462 size_t buffer_size = request->buffer_size; 441 463 usb_device_request_setup_packet_t * request_packet = 442 443 464 (usb_device_request_setup_packet_t*) 465 request->setup_buffer; 444 466 445 467 usb_hub_bm_request_type_t request_type = request_packet->request_type; … … 453 475 if (request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS) 454 476 return process_get_port_status_request(instance, 455 request_packet->index, 456 request); 477 request_packet->index, 478 request); 479 457 480 return ENOTSUP; 458 481 } … … 472 495 uint8_t * bitmap = (uint8_t*) (instance->interrupt_buffer); 473 496 uint32_t mask = (1 << (USB_HUB_FEATURE_C_HUB_LOCAL_POWER + 16)) 474 497 | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16)); 475 498 bzero(bitmap, instance->interrupt_mask_size); 476 499 if (instance->registers->rh_status & mask) { 477 500 bitmap[0] = 1; 478 501 } 479 int port;502 size_t port; 480 503 mask = port_status_change_mask; 481 504 for (port = 1; port <= instance->port_count; ++port) { 482 505 if (mask & instance->registers->rh_port_status[port - 1]) { 506 483 507 bitmap[(port) / 8] += 1 << (port % 8); 484 508 } … … 497 521 */ 498 522 static int process_get_descriptor_request(rh_t *instance, 499 523 usb_transfer_batch_t *request) { 500 524 usb_device_request_setup_packet_t * setup_request = 501 525 (usb_device_request_setup_packet_t*) request->setup_buffer; 502 526 size_t size; 503 527 const void * result_descriptor = NULL; … … 543 567 { 544 568 usb_log_debug("USB_DESCTYPE_EINVAL %d \n", 545 569 setup_request->value); 546 570 usb_log_debug("\ttype %d\n\trequest %d\n\tvalue " 547 548 549 550 551 552 553 571 "%d\n\tindex %d\n\tlen %d\n ", 572 setup_request->request_type, 573 setup_request->request, 574 setup_request_value, 575 setup_request->index, 576 setup_request->length 577 ); 554 578 return EINVAL; 555 579 } … … 560 584 request->transfered_size = size; 561 585 memcpy(request->data_buffer, result_descriptor, size); 586 562 587 return EOK; 563 588 } … … 573 598 */ 574 599 static int process_get_configuration_request(rh_t *instance, 575 600 usb_transfer_batch_t *request) { 576 601 //set and get configuration requests do not have any meaning, only dummy 577 602 //values are returned … … 580 605 request->data_buffer[0] = 1; 581 606 request->transfered_size = 1; 607 582 608 return EOK; 583 609 } … … 592 618 */ 593 619 static int process_hub_feature_set_request(rh_t *instance, 594 620 uint16_t feature) { 595 621 if (!((1 << feature) & hub_set_feature_valid_mask)) 596 622 return EINVAL; 597 if (feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)623 if (feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER) 598 624 feature = USB_HUB_FEATURE_C_HUB_LOCAL_POWER << 16; 599 625 instance->registers->rh_status = 600 (instance->registers->rh_status | (1 << feature)) 601 & (~hub_clear_feature_by_writing_one_mask); 626 (instance->registers->rh_status | (1 << feature)) 627 & (~hub_clear_feature_by_writing_one_mask); 628 602 629 return EOK; 603 630 } … … 612 639 */ 613 640 static int process_hub_feature_clear_request(rh_t *instance, 614 641 uint16_t feature) { 615 642 if (!((1 << feature) & hub_clear_feature_valid_mask)) 616 643 return EINVAL; … … 618 645 if ((1 << feature) & hub_set_feature_direct_mask) { 619 646 instance->registers->rh_status = 620 621 647 (instance->registers->rh_status & (~(1 << feature))) 648 & (~hub_clear_feature_by_writing_one_mask); 622 649 } else {//the feature is cleared by writing '1' 650 623 651 instance->registers->rh_status = 624 625 626 652 (instance->registers->rh_status 653 & (~hub_clear_feature_by_writing_one_mask)) 654 | (1 << feature); 627 655 } 628 656 return EOK; … … 640 668 */ 641 669 static int process_port_feature_set_request(rh_t *instance, 642 670 uint16_t feature, uint16_t port) { 643 671 if (!((1 << feature) & port_set_feature_valid_mask)) 644 672 return EINVAL; … … 646 674 return EINVAL; 647 675 instance->registers->rh_port_status[port - 1] = 648 649 676 (instance->registers->rh_port_status[port - 1] | (1 << feature)) 677 & (~port_clear_feature_valid_mask); 650 678 /// \TODO any error? 679 651 680 return EOK; 652 681 } … … 663 692 */ 664 693 static int process_port_feature_clear_request(rh_t *instance, 665 694 uint16_t feature, uint16_t port) { 666 695 if (!((1 << feature) & port_clear_feature_valid_mask)) 667 696 return EINVAL; … … 673 702 feature = USB_HUB_FEATURE_PORT_OVER_CURRENT; 674 703 instance->registers->rh_port_status[port - 1] = 675 676 677 704 (instance->registers->rh_port_status[port - 1] 705 & (~port_clear_feature_valid_mask)) 706 | (1 << feature); 678 707 /// \TODO any error? 708 679 709 return EOK; 680 710 } … … 689 719 */ 690 720 static int process_address_set_request(rh_t *instance, 691 721 uint16_t address) { 692 722 instance->address = address; 723 693 724 return EOK; 694 725 } … … 705 736 */ 706 737 static int process_request_with_output(rh_t *instance, 707 738 usb_transfer_batch_t *request) { 708 739 usb_device_request_setup_packet_t * setup_request = 709 740 (usb_device_request_setup_packet_t*) request->setup_buffer; 710 741 if (setup_request->request == USB_DEVREQ_GET_STATUS) { 711 742 usb_log_debug("USB_DEVREQ_GET_STATUS\n"); … … 718 749 if (setup_request->request == USB_DEVREQ_GET_CONFIGURATION) { 719 750 usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n"); 751 720 752 return process_get_configuration_request(instance, request); 721 753 } … … 734 766 */ 735 767 static int process_request_with_input(rh_t *instance, 736 768 usb_transfer_batch_t *request) { 737 769 usb_device_request_setup_packet_t * setup_request = 738 770 (usb_device_request_setup_packet_t*) request->setup_buffer; 739 771 request->transfered_size = 0; 740 772 if (setup_request->request == USB_DEVREQ_SET_DESCRIPTOR) { … … 744 776 //set and get configuration requests do not have any meaning, 745 777 //only dummy values are returned 778 746 779 return EOK; 747 780 } … … 760 793 */ 761 794 static int process_request_without_data(rh_t *instance, 762 795 usb_transfer_batch_t *request) { 763 796 usb_device_request_setup_packet_t * setup_request = 764 797 (usb_device_request_setup_packet_t*) request->setup_buffer; 765 798 request->transfered_size = 0; 766 799 if (setup_request->request == USB_DEVREQ_CLEAR_FEATURE) { … … 768 801 usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n"); 769 802 return process_hub_feature_clear_request(instance, 770 803 setup_request->value); 771 804 } 772 805 if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) { 773 806 usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n"); 774 807 return process_port_feature_clear_request(instance, 775 776 808 setup_request->value, 809 setup_request->index); 777 810 } 778 811 usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n", 779 812 setup_request->request_type); 780 813 return EINVAL; 781 814 } … … 784 817 usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n"); 785 818 return process_hub_feature_set_request(instance, 786 819 setup_request->value); 787 820 } 788 821 if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) { 789 822 usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n"); 790 823 return process_port_feature_set_request(instance, 791 792 824 setup_request->value, 825 setup_request->index); 793 826 } 794 827 usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n", 795 828 setup_request->request_type); 796 829 return EINVAL; 797 830 } … … 799 832 usb_log_debug("USB_DEVREQ_SET_ADDRESS\n"); 800 833 return process_address_set_request(instance, 801 834 setup_request->value); 802 835 } 803 836 usb_log_debug("USB_DEVREQ_SET_ENOTSUP %d\n", 804 setup_request->request_type); 837 setup_request->request_type); 838 805 839 return ENOTSUP; 806 840 } … … 836 870 } 837 871 usb_log_info("CTRL packet: %s.\n", 838 839 872 usb_debug_str_buffer( 873 (const uint8_t *) request->setup_buffer, 8, 8)); 840 874 usb_device_request_setup_packet_t * setup_request = 841 842 875 (usb_device_request_setup_packet_t*) 876 request->setup_buffer; 843 877 switch (setup_request->request) { 844 878 case USB_DEVREQ_GET_STATUS: … … 847 881 usb_log_debug("processing request with output\n"); 848 882 opResult = process_request_with_output( 849 883 instance, request); 850 884 break; 851 885 case USB_DEVREQ_CLEAR_FEATURE: … … 853 887 case USB_DEVREQ_SET_ADDRESS: 854 888 usb_log_debug("processing request without " 855 889 "additional data\n"); 856 890 opResult = process_request_without_data( 857 891 instance, request); 858 892 break; 859 893 case USB_DEVREQ_SET_DESCRIPTOR: 860 894 case USB_DEVREQ_SET_CONFIGURATION: 861 895 usb_log_debug("processing request with " 862 896 "input\n"); 863 897 opResult = process_request_with_input( 864 instance, request); 898 instance, request); 899 865 900 break; 866 901 default: 867 902 usb_log_warning("received unsuported request: " 868 869 870 903 "%d\n", 904 setup_request->request 905 ); 871 906 opResult = ENOTSUP; 872 907 } … … 888 923 * @return 889 924 */ 890 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request) {925 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request) { 891 926 memcpy(request->data_buffer, instance->interrupt_buffer, 892 927 instance->interrupt_mask_size); … … 894 929 instance->unfinished_interrupt_transfer = NULL; 895 930 usb_transfer_batch_finish_error(request, EOK); 931 896 932 return EOK; 897 933 } … … 907 943 * @return 908 944 */ 909 static bool is_zeros(void * buffer, size_t size) {910 if (!buffer) return true;911 if (!size) return true;945 static bool is_zeros(void * buffer, size_t size) { 946 if (!buffer) return true; 947 if (!size) return true; 912 948 size_t i; 913 for (i=0;i<size;++i){914 if (((char*)buffer)[i])949 for (i = 0; i < size; ++i) { 950 if (((char*) buffer)[i]) 915 951 return false; 916 952 } -
uspace/drv/ohci/root_hub.h
rd2bff2f r76ef94e 51 51 usb_address_t address; 52 52 /** hub port count */ 53 int port_count;53 size_t port_count; 54 54 /** hubs descriptors */ 55 55 usb_device_descriptors_t descriptors; -
uspace/drv/uhci-hcd/uhci.c
rd2bff2f r76ef94e 264 264 ret, str_error(ret)); 265 265 266 ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME); 267 CHECK_RET_DEST_FUN_RETURN(ret, 268 "Failed to add UHCI to HC class: %s.\n", str_error(ret)); 269 266 270 ret = rh_init(&instance->rh, instance->rh_fun, 267 271 (uintptr_t)instance->hc.registers + 0x10, 4); -
uspace/drv/usbhub/ports.c
rd2bff2f r76ef94e 53 53 size_t port; 54 54 usb_speed_t speed; 55 }; 56 57 /** 58 * count of port status changes that are not explicitly handled by 59 * any function here and must be cleared by hand 60 */ 61 static const unsigned int non_handled_changes_count = 2; 62 63 /** 64 * port status changes that are not explicitly handled by 65 * any function here and must be cleared by hand 66 */ 67 static const int non_handled_changes[] = { 68 USB_HUB_FEATURE_C_PORT_ENABLE, 69 USB_HUB_FEATURE_C_PORT_SUSPEND 55 70 }; 56 71 … … 131 146 &status, USB_HUB_FEATURE_C_PORT_CONNECTION,false); 132 147 usb_port_status_set_bit( 133 &status, USB_HUB_FEATURE_PORT_RESET,false);134 usb_port_status_set_bit(135 148 &status, USB_HUB_FEATURE_C_PORT_RESET,false); 136 149 usb_port_status_set_bit( 137 150 &status, USB_HUB_FEATURE_C_PORT_OVER_CURRENT,false); 138 /// \TODO what about port power change? 139 if (status >> 16) { 140 usb_log_info("there was unsupported change on port %d: %X\n", 141 port, status); 142 151 152 //clearing not yet handled changes 153 unsigned int feature_idx; 154 for(feature_idx = 0;feature_idx<non_handled_changes_count; 155 ++feature_idx){ 156 unsigned int bit_idx = non_handled_changes[feature_idx]; 157 if(status & (1<<bit_idx)){ 158 usb_log_info( 159 "there was not yet handled change on port %d: %d" 160 ";clearing it\n", 161 port, bit_idx); 162 int opResult = usb_hub_clear_port_feature( 163 hub->control_pipe, 164 port, bit_idx); 165 if (opResult != EOK) { 166 usb_log_warning( 167 "could not clear port flag %d: %d\n", 168 bit_idx, opResult 169 ); 170 } 171 usb_port_status_set_bit( 172 &status, bit_idx,false); 173 } 174 } 175 if(status>>16){ 176 usb_log_info("there is still some unhandled change %X\n", 177 status); 143 178 } 144 179 } … … 222 257 "Port %zu reset complete but port not enabled.\n", 223 258 (size_t) port); 259 } 260 /* Clear the port reset change. */ 261 int rc = usb_hub_clear_port_feature(hub->control_pipe, 262 port, USB_HUB_FEATURE_C_PORT_RESET); 263 if (rc != EOK) { 264 usb_log_error("Failed to clear port %d reset feature: %s.\n", 265 port, str_error(rc)); 224 266 } 225 267 } … … 319 361 fibril_mutex_unlock(&my_port->reset_mutex); 320 362 321 /* Clear the port reset change. */322 rc = usb_hub_clear_port_feature(hub->control_pipe,323 port_no, USB_HUB_FEATURE_C_PORT_RESET);324 if (rc != EOK) {325 usb_log_error("Failed to clear port %d reset feature: %s.\n",326 port_no, str_error(rc));327 return rc;328 }329 330 363 if (my_port->reset_okay) { 331 364 return EOK; -
uspace/drv/vhc/main.c
rd2bff2f r76ef94e 104 104 } 105 105 106 ddf_fun_add_to_class(hc, "usbhc"); 106 rc = ddf_fun_add_to_class(hc, USB_HC_DDF_CLASS_NAME); 107 if (rc != EOK) { 108 usb_log_fatal("Failed to add function to HC class: %s.\n", 109 str_error(rc)); 110 free(data); 111 return rc; 112 } 107 113 108 114 virtual_hub_device_init(hc); -
uspace/lib/c/generic/devman.c
rd2bff2f r76ef94e 374 374 } 375 375 376 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size) 377 { 378 int phone = devman_get_phone(DEVMAN_CLIENT, 0); 379 380 if (phone < 0) 381 return phone; 382 383 async_serialize_start(); 384 385 ipc_call_t answer; 386 aid_t req = async_send_1(phone, DEVMAN_DEVICE_GET_DEVICE_PATH, 387 handle, &answer); 388 389 ipc_call_t data_request_call; 390 aid_t data_request = async_data_read(phone, path, path_size, 391 &data_request_call); 392 if (data_request == 0) { 393 async_wait_for(req, NULL); 394 async_serialize_end(); 395 return ENOMEM; 396 } 397 398 sysarg_t data_request_rc; 399 sysarg_t opening_request_rc; 400 async_wait_for(data_request, &data_request_rc); 401 async_wait_for(req, &opening_request_rc); 402 403 async_serialize_end(); 404 405 if (data_request_rc != EOK) { 406 /* Prefer the return code of the opening request. */ 407 if (opening_request_rc != EOK) { 408 return (int) opening_request_rc; 409 } else { 410 return (int) data_request_rc; 411 } 412 } 413 if (opening_request_rc != EOK) { 414 return (int) opening_request_rc; 415 } 416 417 path[path_size - 1] = 0; 418 419 if (IPC_GET_ARG2(data_request_call) >= path_size) { 420 return ELIMIT; 421 } 422 423 return EOK; 424 } 425 376 426 377 427 /** @} -
uspace/lib/c/include/devman.h
rd2bff2f r76ef94e 55 55 extern int devman_device_get_handle_by_class(const char *, const char *, 56 56 devman_handle_t *, unsigned int); 57 extern int devman_get_device_path(devman_handle_t, char *, size_t); 57 58 58 59 extern int devman_add_device_to_class(devman_handle_t, const char *); -
uspace/lib/c/include/ipc/devman.h
rd2bff2f r76ef94e 149 149 typedef enum { 150 150 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD, 151 DEVMAN_DEVICE_GET_HANDLE_BY_CLASS 151 DEVMAN_DEVICE_GET_HANDLE_BY_CLASS, 152 DEVMAN_DEVICE_GET_DEVICE_PATH 152 153 } client_to_devman_t; 153 154 -
uspace/lib/drv/generic/remote_usbhc.c
rd2bff2f r76ef94e 302 302 async_transaction_t *trans = async_transaction_create(callid); 303 303 if (trans == NULL) { 304 async_answer_0(data_callid, ENOMEM); 304 305 async_answer_0(callid, ENOMEM); 305 306 return; … … 314 315 315 316 if (rc != EOK) { 317 async_answer_0(data_callid, rc); 316 318 async_answer_0(callid, rc); 317 319 async_transaction_destroy(trans); … … 460 462 async_transaction_t *trans = async_transaction_create(callid); 461 463 if (trans == NULL) { 464 async_answer_0(data_callid, ENOMEM); 462 465 async_answer_0(callid, ENOMEM); 463 466 free(setup_packet); … … 469 472 trans->buffer = malloc(data_len); 470 473 if (trans->buffer == NULL) { 474 async_answer_0(data_callid, ENOMEM); 471 475 async_answer_0(callid, ENOMEM); 472 476 async_transaction_destroy(trans); … … 480 484 481 485 if (rc != EOK) { 486 async_answer_0(data_callid, rc); 482 487 async_answer_0(callid, rc); 483 488 async_transaction_destroy(trans); -
uspace/lib/usb/Makefile
rd2bff2f r76ef94e 46 46 src/hidparser.c \ 47 47 src/hiddescriptor.c \ 48 src/host.c \ 48 49 src/hub.c \ 49 50 src/pipepriv.c \ -
uspace/lib/usb/include/usb/usb.h
rd2bff2f r76ef94e 172 172 } usb_packet_id; 173 173 174 /** Class name for USB host controllers. */ 175 #define USB_HC_DDF_CLASS_NAME "usbhc" 176 174 177 #endif 175 178 /** -
uspace/srv/devman/main.c
rd2bff2f r76ef94e 515 515 } 516 516 517 /** Find device path by its handle. */ 518 static void devman_get_device_path_by_handle(ipc_callid_t iid, 519 ipc_call_t *icall) 520 { 521 devman_handle_t handle = IPC_GET_ARG1(*icall); 522 523 fun_node_t *fun = find_fun_node(&device_tree, handle); 524 if (fun == NULL) { 525 async_answer_0(iid, ENOMEM); 526 return; 527 } 528 529 ipc_callid_t data_callid; 530 size_t data_len; 531 if (!async_data_read_receive(&data_callid, &data_len)) { 532 async_answer_0(iid, EINVAL); 533 return; 534 } 535 536 void *buffer = malloc(data_len); 537 if (buffer == NULL) { 538 async_answer_0(data_callid, ENOMEM); 539 async_answer_0(iid, ENOMEM); 540 return; 541 } 542 543 size_t sent_length = str_size(fun->pathname); 544 if (sent_length > data_len) { 545 sent_length = data_len; 546 } 547 548 async_data_read_finalize(data_callid, fun->pathname, sent_length); 549 async_answer_0(iid, EOK); 550 551 free(buffer); 552 } 553 517 554 518 555 /** Function for handling connections from a client to the device manager. */ … … 536 573 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS: 537 574 devman_function_get_handle_by_class(callid, &call); 575 break; 576 case DEVMAN_DEVICE_GET_DEVICE_PATH: 577 devman_get_device_path_by_handle(callid, &call); 538 578 break; 539 579 default:
Note:
See TracChangeset
for help on using the changeset viewer.