Changeset 070f11e in mainline
- Timestamp:
- 2011-02-20T21:55:21Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d37b235
- Parents:
- 41e645c (diff), 6bb83c7 (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
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r41e645c r070f11e 44 44 #include <usb/recognise.h> 45 45 #include <usb/devreq.h> 46 #include <usb/request.h> 46 47 #include <usb/classes/hub.h> 47 48 … … 50 51 #include "port_status.h" 51 52 #include "usb/usb.h" 53 #include "usb/pipes.h" 52 54 53 55 static device_ops_t hub_device_ops = { … … 61 63 //********************************************* 62 64 63 usb_hub_info_t * usb_create_hub_info(device_t * device , int hc) {65 usb_hub_info_t * usb_create_hub_info(device_t * device) { 64 66 usb_hub_info_t* result = usb_new(usb_hub_info_t); 67 usb_device_connection_initialize_from_device(&result->device_connection, 68 device); 69 usb_hc_connection_initialize_from_device(&result->connection, 70 device); 71 usb_endpoint_pipe_initialize_default_control(&result->endpoints.control, 72 &result->device_connection); 73 74 65 75 //result->device = device; 66 76 result->port_count = -1; … … 68 78 result->device = device; 69 79 70 71 dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc); 72 if (hc < 0) { 73 return result; 74 } 75 //get some hub info 76 usb_address_t addr = usb_drv_get_my_address(hc, device); 77 dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr); 78 /*if(addr<0){ 79 //return result; 80 81 }*/ 82 83 result->address = addr; 84 80 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); 81 85 82 // get hub descriptor 86 83 … … 91 88 int opResult; 92 89 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 93 94 opResult = usb_ drv_req_get_descriptor(hc, addr,90 usb_endpoint_pipe_start_session(&result->endpoints.control); 91 opResult = usb_request_get_descriptor(&result->endpoints.control, 95 92 USB_REQUEST_TYPE_CLASS, 96 93 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 97 94 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 95 usb_endpoint_pipe_end_session(&result->endpoints.control); 96 97 /* Initialize the interrupt endpoint. 98 usb_endpoint_pipe_initalize( 99 &hub_data->endpoints->status_change, 100 &endpiont_descriptor, &hub_data->connection); 101 102 */ /// \TODO add this call 98 103 99 104 if (opResult != EOK) { … … 111 116 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count); 112 117 result->port_count = descriptor->ports_count; 113 result->attached_devs = (usb_h ub_attached_device_t*)114 malloc((result->port_count+1) * sizeof(usb_h ub_attached_device_t));118 result->attached_devs = (usb_hc_attached_device_t*) 119 malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t)); 115 120 int i; 116 121 for(i=0;i<result->port_count+1;++i){ 117 result->attached_devs[i]. devman_handle=0;122 result->attached_devs[i].handle=0; 118 123 result->attached_devs[i].address=0; 119 124 } … … 140 145 dev->ops = &hub_device_ops; 141 146 142 //create the hub structure 143 //get hc connection 144 int hc = usb_drv_hc_connect_auto(dev, 0); 145 if (hc < 0) { 146 return hc; 147 } 148 149 usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc); 147 148 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 149 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 150 150 151 int port; 151 152 int opResult; 152 usb_target_t target;153 target.address = hub_info->address;154 target.endpoint = 0;153 //usb_target_t target; 154 //target.address = hub_info->usb_device->address; 155 //target.endpoint = 0; 155 156 156 157 //get configuration descriptor … … 158 159 // and all should be checked 159 160 usb_standard_device_descriptor_t std_descriptor; 160 opResult = usb_ drv_req_get_device_descriptor(hc, target.address,161 opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control, 161 162 &std_descriptor); 162 163 if(opResult!=EOK){ … … 171 172 /// \TODO check other configurations 172 173 usb_standard_configuration_descriptor_t config_descriptor; 173 opResult = usb_ drv_req_get_bare_configuration_descriptor(hc,174 target.address, 0,174 opResult = usb_request_get_bare_configuration_descriptor( 175 &hub_info->endpoints.control, 0, 175 176 &config_descriptor); 176 177 if(opResult!=EOK){ … … 179 180 } 180 181 //set configuration 181 opResult = usb_ drv_req_set_configuration(hc, target.address,182 opResult = usb_request_set_configuration(&hub_info->endpoints.control, 182 183 config_descriptor.configuration_number); 183 184 … … 189 190 for (port = 1; port < hub_info->port_count+1; ++port) { 190 191 usb_hub_set_power_port_request(&request, port); 191 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 192 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 193 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 192 194 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 193 195 if (opResult != EOK) { … … 197 199 //ports powered, hub seems to be enabled 198 200 199 async_hangup(hc); 201 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 202 //async_hangup(hc); 200 203 201 204 //add the hub to list … … 211 214 212 215 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 216 //address is lost... 213 217 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 214 hub_info->address,218 //hub_info->endpoints.control., 215 219 hub_info->port_count); 216 220 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number); … … 249 253 * @param target 250 254 */ 251 static void usb_hub_init_add_device( int hc, uint16_t port, usb_target_t target) {255 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) { 252 256 usb_device_request_setup_packet_t request; 253 257 int opResult; 254 258 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 259 assert(hub->endpoints.control.hc_phone); 255 260 //get default address 256 opResult = usb_drv_reserve_default_address(hc); 261 //opResult = usb_drv_reserve_default_address(hc); 262 opResult = usb_hc_reserve_default_address(&hub->connection, false); 257 263 if (opResult != EOK) { 258 264 dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used"); … … 261 267 //reset port 262 268 usb_hub_set_reset_port_request(&request, port); 263 opResult = usb_ drv_sync_control_write(264 hc, target,265 &request, 269 opResult = usb_endpoint_pipe_control_write( 270 &hub->endpoints.control, 271 &request,sizeof(usb_device_request_setup_packet_t), 266 272 NULL, 0 267 273 ); 268 274 if (opResult != EOK) { 269 275 dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port"); 270 usb_hub_release_default_address(hc); 276 //usb_hub_release_default_address(hc); 277 usb_hc_release_default_address(&hub->connection); 271 278 } 272 279 } … … 279 286 */ 280 287 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 281 int hc, uint16_t port, usb_target_t target) {288 uint16_t port) { 282 289 283 290 int opResult; 284 291 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device"); 285 opResult = usb_hub_clear_port_feature( hc, target.address,292 opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 286 293 port, USB_HUB_FEATURE_C_PORT_RESET); 294 287 295 if (opResult != EOK) { 288 296 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature"); 289 usb_hub_release_default_address(hc); 290 return; 291 } 292 293 /* Request address at from host controller. */ 294 usb_address_t new_device_address = usb_drv_request_address(hc); 297 usb_hc_release_default_address(&hub->connection); 298 return; 299 } 300 //create connection to device 301 usb_endpoint_pipe_t new_device_pipe; 302 usb_device_connection_t new_device_connection; 303 usb_device_connection_initialize_on_default_address( 304 &new_device_connection, 305 &hub->connection 306 ); 307 usb_endpoint_pipe_initialize_default_control( 308 &new_device_pipe, 309 &new_device_connection); 310 /// \TODO get highspeed info 311 312 313 314 315 316 /* Request address from host controller. */ 317 usb_address_t new_device_address = usb_hc_request_address( 318 &hub->connection, 319 false/// \TODO fullspeed?? 320 ); 295 321 if (new_device_address < 0) { 296 322 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address"); 297 323 opResult = new_device_address; 298 usb_h ub_release_default_address(hc);324 usb_hc_release_default_address(&hub->connection); 299 325 return; 300 326 } 301 327 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address); 302 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 303 new_device_address); 328 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 329 // new_device_address); 330 opResult = usb_request_set_address(&new_device_pipe,new_device_address); 304 331 305 332 if (opResult != EOK) { 306 333 dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device"); 307 usb_hub_release_default_address(hc); 308 return; 309 } 310 311 312 opResult = usb_hub_release_default_address(hc); 334 usb_hc_release_default_address(&hub->connection); 335 return; 336 } 337 338 339 //opResult = usb_hub_release_default_address(hc); 340 opResult = usb_hc_release_default_address(&hub->connection); 313 341 if(opResult!=EOK){ 314 342 return; 315 343 } 316 344 317 devman_handle_t hc_handle;318 opResult = usb_drv_find_hc(hub->device, &hc_handle);319 if (opResult != EOK) {320 usb_log_error("Failed to get handle of host controller: %s.\n",321 str_error(opResult));322 return;323 }324 325 345 devman_handle_t child_handle; 326 opResult = usb_device_register_child_in_devman(new_device_address, 327 hc_handle, hub->device, &child_handle); 346 //?? 347 opResult = usb_device_register_child_in_devman(new_device_address, 348 hub->connection.hc_handle, hub->device, &child_handle); 349 328 350 if (opResult != EOK) { 329 351 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); 330 352 return; 331 353 } 332 hub->attached_devs[port]. devman_handle = child_handle;354 hub->attached_devs[port].handle = child_handle; 333 355 hub->attached_devs[port].address = new_device_address; 334 356 335 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 357 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 358 opResult = usb_hc_register_device( 359 &hub->connection, 360 &hub->attached_devs[port]); 336 361 if (opResult != EOK) { 337 362 dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd"); … … 350 375 */ 351 376 static void usb_hub_removed_device( 352 usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {377 usb_hub_info_t * hub,uint16_t port) { 353 378 //usb_device_request_setup_packet_t request; 354 379 int opResult; … … 357 382 * devide manager 358 383 */ 359 360 hub->attached_devs[port].devman_handle=0; 384 361 385 //close address 362 386 if(hub->attached_devs[port].address!=0){ 363 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 387 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 388 opResult = usb_hc_unregister_device( 389 &hub->connection, hub->attached_devs[port].address); 364 390 if(opResult != EOK) { 365 391 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \ … … 367 393 } 368 394 hub->attached_devs[port].address = 0; 395 hub->attached_devs[port].handle = 0; 369 396 }else{ 370 397 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address"); 371 398 //device was disconnected before it`s port was reset - return default address 372 usb_drv_release_default_address(hc); 399 //usb_drv_release_default_address(hc); 400 usb_hc_release_default_address(&hub->connection); 373 401 } 374 402 } … … 380 408 * @param target 381 409 */ 382 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,383 uint16_t port , usb_address_t address) {410 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 411 uint16_t port) { 384 412 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 385 413 //determine type of change 414 usb_endpoint_pipe_t *pipe = &hub->endpoints.control; 415 int opResult = usb_endpoint_pipe_start_session(pipe); 416 417 if(opResult != EOK){ 418 dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult); 419 } 420 421 /* 386 422 usb_target_t target; 387 423 target.address=address; 388 424 target.endpoint=0; 425 */ 426 389 427 usb_port_status_t status; 390 428 size_t rcvd_size; 391 429 usb_device_request_setup_packet_t request; 392 int opResult;430 //int opResult; 393 431 usb_hub_set_port_status_request(&request, port); 394 432 //endpoint 0 395 433 396 opResult = usb_ drv_sync_control_read(397 hc, target,398 &request, 434 opResult = usb_endpoint_pipe_control_read( 435 pipe, 436 &request, sizeof(usb_device_request_setup_packet_t), 399 437 &status, 4, &rcvd_size 400 438 ); … … 409 447 //something connected/disconnected 410 448 if (usb_port_connect_change(&status)) { 411 opResult = usb_hub_clear_port_feature( hc, target.address,449 opResult = usb_hub_clear_port_feature(pipe, 412 450 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 413 451 // TODO: check opResult 414 452 if (usb_port_dev_connected(&status)) { 415 453 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 416 usb_hub_init_add_device(h c, port, target);454 usb_hub_init_add_device(hub, port); 417 455 } else { 418 usb_hub_removed_device(hub, hc, port, target);456 usb_hub_removed_device(hub, port); 419 457 } 420 458 } … … 423 461 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 424 462 if (usb_port_enabled(&status)) { 425 usb_hub_finalize_add_device(hub, hc, port, target);463 usb_hub_finalize_add_device(hub, port); 426 464 } else { 427 465 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 439 477 /// \TODO handle other changes 440 478 /// \TODO debug log for various situations 479 usb_endpoint_pipe_end_session(pipe); 480 441 481 442 482 } … … 456 496 fibril_mutex_unlock(&usb_hub_list_lock); 457 497 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 498 int opResult; 499 500 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change); 501 if(opResult != EOK){ 502 continue; 503 } 458 504 /* 459 505 * Check status change pipe of this hub. 460 506 */ 461 507 /* 462 508 usb_target_t target; 463 509 target.address = hub_info->address; … … 465 511 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 466 512 target.address); 467 513 */ 468 514 size_t port_count = hub_info->port_count; 469 515 470 516 /* 471 517 * Connect to respective HC. 472 * /518 * 473 519 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 474 520 if (hc < 0) { 475 521 continue; 476 } 522 }*/ 477 523 478 524 /// FIXME: count properly … … 481 527 void *change_bitmap = malloc(byte_length); 482 528 size_t actual_size; 483 usb_handle_t handle;529 //usb_handle_t handle; 484 530 485 531 /* 486 532 * Send the request. 487 533 */ 488 int opResult = usb_drv_async_interrupt_in(hc, target, 489 change_bitmap, byte_length, &actual_size, 490 &handle); 491 492 usb_drv_async_wait_for(handle); 534 opResult = usb_endpoint_pipe_read( 535 &hub_info->endpoints.status_change, 536 change_bitmap, byte_length, &actual_size 537 ); 538 539 //usb_drv_async_wait_for(handle); 493 540 494 541 if (opResult != EOK) { … … 503 550 if (interrupt) { 504 551 usb_hub_process_interrupt( 505 hub_info, hc, port, hub_info->address);552 hub_info, port); 506 553 } 507 554 } 555 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 508 556 free(change_bitmap); 509 510 async_hangup(hc); 557 558 559 //async_hangup(hc); 511 560 fibril_mutex_lock(&usb_hub_list_lock); 512 561 } -
uspace/drv/usbhub/usbhub.h
r41e645c r070f11e 42 42 #define NAME "usbhub" 43 43 44 /** basic information about device attached to hub */ 45 typedef struct{ 46 usb_address_t address; 47 devman_handle_t devman_handle; 48 }usb_hub_attached_device_t; 44 //#include "usb/hcdhubd.h" 45 #include <usb/usbdrv.h> 46 #include <usb/hub.h> 47 48 #include <usb/pipes.h> 49 50 /* Hub endpoints. */ 51 typedef struct { 52 usb_endpoint_pipe_t control; 53 usb_endpoint_pipe_t status_change; 54 } usb_hub_endpoints_t; 55 56 49 57 50 58 /** Information about attached hub. */ … … 52 60 /** Number of ports. */ 53 61 int port_count; 54 /** attached device handles */55 usb_h ub_attached_device_t * attached_devs;56 /** USB address of the hub. */57 usb_address_t address;62 /** attached device handles, for each port one */ 63 usb_hc_attached_device_t * attached_devs; 64 /** General usb device info. */ 65 //usb_hcd_attached_device_info_t * usb_device; 58 66 /** General device info*/ 59 67 device_t * device; 68 /** connection to hcd */ 69 //usb_device_connection_t connection; 70 usb_hc_connection_t connection; 71 /** */ 72 usb_device_connection_t device_connection; 73 /** hub endpoints */ 74 usb_hub_endpoints_t endpoints; 60 75 } usb_hub_info_t; 61 76 -
uspace/drv/usbhub/usbhub_private.h
r41e645c r070f11e 45 45 #include <fibril_synch.h> 46 46 47 #include <usb/classes/hub.h> 47 48 #include <usb/usb.h> 48 49 #include <usb/usbdrv.h> 49 #include <usb/classes/hub.h> 50 #include <usb/devreq.h>50 51 //#include <usb/devreq.h> 51 52 #include <usb/debug.h> 52 53 … … 77 78 * @return 78 79 */ 79 usb_hub_info_t * usb_create_hub_info(device_t * device , int hc);80 usb_hub_info_t * usb_create_hub_info(device_t * device); 80 81 81 82 /** List of hubs maanged by this driver */ … … 98 99 * @return error code 99 100 */ 101 /* 100 102 int usb_drv_sync_control_read( 101 int phone, usb_target_t target,103 usb_endpoint_pipe_t *pipe, 102 104 usb_device_request_setup_packet_t * request, 103 105 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size 104 ); 106 );*/ 105 107 106 108 /** … … 115 117 * @return error code 116 118 */ 117 int usb_drv_sync_control_write(118 int phone, usb_target_t target,119 /*int usb_drv_sync_control_write( 120 usb_endpoint_pipe_t *pipe, 119 121 usb_device_request_setup_packet_t * request, 120 122 void * sent_buffer, size_t sent_size 121 ); 123 );*/ 122 124 123 125 /** … … 147 149 * @return Operation result 148 150 */ 149 static inline int usb_hub_clear_port_feature( int hc, usb_address_t address,151 static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe, 150 152 int port_index, 151 153 usb_hub_class_feature_t feature) { 152 usb_target_t target = { 153 .address = address, 154 .endpoint = 0 155 }; 154 156 155 usb_device_request_setup_packet_t clear_request = { 157 156 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE, … … 161 160 }; 162 161 clear_request.value = feature; 163 return usb_ drv_psync_control_write(hc, target, &clear_request,162 return usb_endpoint_pipe_control_write(pipe, &clear_request, 164 163 sizeof(clear_request), NULL, 0); 165 164 } -
uspace/drv/usbhub/utils.c
r41e645c r070f11e 114 114 115 115 //control transactions 116 116 /* 117 117 int usb_drv_sync_control_read( 118 118 int phone, usb_target_t target, … … 199 199 } 200 200 201 201 */ 202 202 203 203 -
uspace/lib/usb/include/usb/classes/hub.h
r41e645c r070f11e 1 1 /* 2 * Copyright (c) 2010 Vojtech Horky2 * Copyright (c) 2010 Matus Dekanek 3 3 * All rights reserved. 4 4 * … … 33 33 * @brief USB hub related structures. 34 34 */ 35 #ifndef LIBUSB_ HUB_H_36 #define LIBUSB_ HUB_H_35 #ifndef LIBUSB_CLASS_HUB_H_ 36 #define LIBUSB_CLASS_HUB_H_ 37 37 38 38 #include <sys/types.h>
Note:
See TracChangeset
for help on using the changeset viewer.