Changeset cb0ab9e in mainline
- Timestamp:
- 2011-05-07T14:40:46Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6985b4e
- Parents:
- df0bbe1 (diff), 7205209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/drv
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/hc.c
rdf0bbe1 rcb0ab9e 49 49 static int interrupt_emulator(hc_t *instance); 50 50 static void hc_gain_control(hc_t *instance); 51 static void hc_init_hw(hc_t *instance);52 51 static int hc_init_transfer_lists(hc_t *instance); 53 52 static int hc_init_memory(hc_t *instance); … … 92 91 usb_log_error("Failed add root hub match-id.\n"); 93 92 } 93 ret = ddf_fun_bind(hub_fun); 94 94 return ret; 95 95 } … … 111 111 ret, str_error(ret)); 112 112 113 list_initialize(&instance->pending_batches); 113 114 usb_device_keeper_init(&instance->manager); 114 115 ret = usb_endpoint_manager_init(&instance->ep_manager, … … 117 118 str_error(ret)); 118 119 119 hc_gain_control(instance);120 120 ret = hc_init_memory(instance); 121 121 CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures: %s.\n", 122 122 str_error(ret)); 123 hc_init_hw(instance); 123 #undef CHECK_RET_RETURN 124 125 126 // hc_init_hw(instance); 127 hc_gain_control(instance); 124 128 fibril_mutex_initialize(&instance->guard); 125 129 … … 132 136 } 133 137 134 list_initialize(&instance->pending_batches);135 #undef CHECK_RET_RETURN136 138 return EOK; 137 139 } … … 287 289 { 288 290 assert(instance); 289 usb_log_debug("OHCI interrupt: %x.\n", status);291 usb_log_debug("OHCI(%p) interrupt: %x.\n", instance, status); 290 292 if ((status & ~I_SF) == 0) /* ignore sof status */ 291 293 return; … … 339 341 (uint32_t*)((char*)instance->registers + 0x100); 340 342 usb_log_debug("OHCI legacy register %p: %x.\n", 341 ohci_emulation_reg, *ohci_emulation_reg); 342 *ohci_emulation_reg &= ~0x1; 343 ohci_emulation_reg, *ohci_emulation_reg); 344 /* Do not change A20 state */ 345 *ohci_emulation_reg &= 0x100; 346 usb_log_debug("OHCI legacy register %p: %x.\n", 347 ohci_emulation_reg, *ohci_emulation_reg); 343 348 344 349 /* Interrupt routing enabled => smm driver is active */ … … 350 355 } 351 356 usb_log_info("SMM driver: Ownership taken.\n"); 357 instance->registers->control &= (C_HCFS_RESET << C_HCFS_SHIFT); 358 async_usleep(50000); 352 359 return; 353 360 } … … 375 382 } 376 383 /*----------------------------------------------------------------------------*/ 377 void hc_ init_hw(hc_t *instance)384 void hc_start_hw(hc_t *instance) 378 385 { 379 386 /* OHCI guide page 42 */ … … 474 481 { 475 482 assert(instance); 483 484 bzero(&instance->rh, sizeof(instance->rh)); 476 485 /* Init queues */ 477 486 hc_init_transfer_lists(instance); -
uspace/drv/ohci/hc.h
rdf0bbe1 rcb0ab9e 80 80 uintptr_t regs, size_t reg_size, bool interrupts); 81 81 82 void hc_start_hw(hc_t *instance); 83 82 84 /** Safely dispose host controller internal structures 83 85 * -
uspace/drv/ohci/main.c
rdf0bbe1 rcb0ab9e 75 75 return ret; 76 76 } 77 device->driver_data = ohci; 77 // device->driver_data = ohci; 78 hc_register_hub(&ohci->hc, ohci->rh_fun); 78 79 79 80 usb_log_info("Controlling new OHCI device `%s'.\n", device->name); … … 93 94 { 94 95 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 95 sleep(5);96 96 return ddf_driver_main(&ohci_driver); 97 97 } -
uspace/drv/ohci/ohci.c
rdf0bbe1 rcb0ab9e 54 54 { 55 55 assert(dev); 56 assert(dev->driver_data); 56 57 hc_t *hc = &((ohci_t*)dev->driver_data)->hc; 57 58 uint16_t status = IPC_GET_ARG1(*call); … … 152 153 usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n", 153 154 (void *) mem_reg_base, mem_reg_size, irq); 154 155 ret = pci_disable_legacy(device);156 CHECK_RET_DEST_FUN_RETURN(ret,157 "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));158 155 159 156 bool interrupts = false; … … 216 213 "Failed(%d) to create root hub function.\n", ret); 217 214 218 hc_register_hub(&instance->hc, instance->rh_fun);219 215 220 216 instance->rh_fun->ops = &rh_ops; 221 217 instance->rh_fun->driver_data = NULL; 222 ret = ddf_fun_bind(instance->rh_fun);223 CHECK_RET_FINI_RETURN(ret,224 "Failed(%d) to register OHCI root hub.\n", ret); 225 218 219 device->driver_data = instance; 220 221 hc_start_hw(&instance->hc); 226 222 return EOK; 227 223 #undef CHECK_RET_FINI_RETURN -
uspace/drv/ohci/pci.c
rdf0bbe1 rcb0ab9e 136 136 return enabled ? EOK : EIO; 137 137 } 138 /*----------------------------------------------------------------------------*/139 /** Implements BIOS handoff routine as decribed in OHCI spec140 *141 * @param[in] device Device asking for interrupts142 * @return Error code.143 */144 int pci_disable_legacy(ddf_dev_t *device)145 {146 /* TODO: implement */147 return EOK;148 }149 /*----------------------------------------------------------------------------*/150 138 /** 151 139 * @} -
uspace/drv/ohci/root_hub.c
rdf0bbe1 rcb0ab9e 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
rdf0bbe1 rcb0ab9e 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/usbhub/ports.c
rdf0bbe1 rcb0ab9e 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;
Note:
See TracChangeset
for help on using the changeset viewer.