Changes in / [62066b4:423e8c81] in mainline
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r62066b4 r423e8c81 43 43 #include <usb/recognise.h> 44 44 #include <usb/devreq.h> 45 #include <usb/request.h>46 45 #include <usb/classes/hub.h> 47 46 … … 50 49 #include "port_status.h" 51 50 #include "usb/usb.h" 52 #include "usb/pipes.h"53 51 54 52 static int iface_get_hc_handle(device_t *device, devman_handle_t *handle) … … 71 69 //********************************************* 72 70 73 usb_hub_info_t * usb_create_hub_info(device_t * device ) {71 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) { 74 72 usb_hub_info_t* result = usb_new(usb_hub_info_t); 75 usb_device_connection_initialize_from_device(&result->device_connection,76 device);77 usb_hc_connection_initialize_from_device(&result->connection,78 device);79 usb_endpoint_pipe_initialize_default_control(&result->endpoints.control,80 &result->device_connection);81 82 83 73 //result->device = device; 84 74 result->port_count = -1; … … 86 76 result->device = device; 87 77 88 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); 89 78 79 dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc); 80 if (hc < 0) { 81 return result; 82 } 83 //get some hub info 84 usb_address_t addr = usb_drv_get_my_address(hc, device); 85 dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr); 86 /*if(addr<0){ 87 //return result; 88 89 }*/ 90 91 result->address = addr; 92 90 93 // get hub descriptor 91 94 … … 96 99 int opResult; 97 100 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 98 usb_endpoint_pipe_start_session(&result->endpoints.control);99 opResult = usb_ request_get_descriptor(&result->endpoints.control,101 102 opResult = usb_drv_req_get_descriptor(hc, addr, 100 103 USB_REQUEST_TYPE_CLASS, 101 104 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 102 105 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 103 usb_endpoint_pipe_end_session(&result->endpoints.control);104 105 /* Initialize the interrupt endpoint.106 usb_endpoint_pipe_initalize(107 &hub_data->endpoints->status_change,108 &endpiont_descriptor, &hub_data->connection);109 110 */ /// \TODO add this call111 106 112 107 if (opResult != EOK) { … … 124 119 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count); 125 120 result->port_count = descriptor->ports_count; 126 result->attached_devs = (usb_h c_attached_device_t*)127 malloc((result->port_count+1) * sizeof(usb_h c_attached_device_t));121 result->attached_devs = (usb_hub_attached_device_t*) 122 malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t)); 128 123 int i; 129 124 for(i=0;i<result->port_count+1;++i){ 130 result->attached_devs[i]. handle=0;125 result->attached_devs[i].devman_handle=0; 131 126 result->attached_devs[i].address=0; 132 127 } … … 153 148 dev->ops = &hub_device_ops; 154 149 155 156 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 157 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 158 150 //create the hub structure 151 //get hc connection 152 int hc = usb_drv_hc_connect_auto(dev, 0); 153 if (hc < 0) { 154 return hc; 155 } 156 157 usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc); 159 158 int port; 160 159 int opResult; 161 //usb_target_t target;162 //target.address = hub_info->usb_device->address;163 //target.endpoint = 0;160 usb_target_t target; 161 target.address = hub_info->address; 162 target.endpoint = 0; 164 163 165 164 //get configuration descriptor … … 167 166 // and all should be checked 168 167 usb_standard_device_descriptor_t std_descriptor; 169 opResult = usb_ request_get_device_descriptor(&hub_info->endpoints.control,168 opResult = usb_drv_req_get_device_descriptor(hc, target.address, 170 169 &std_descriptor); 171 170 if(opResult!=EOK){ … … 180 179 /// \TODO check other configurations 181 180 usb_standard_configuration_descriptor_t config_descriptor; 182 opResult = usb_ request_get_bare_configuration_descriptor(183 &hub_info->endpoints.control, 0,181 opResult = usb_drv_req_get_bare_configuration_descriptor(hc, 182 target.address, 0, 184 183 &config_descriptor); 185 184 if(opResult!=EOK){ … … 188 187 } 189 188 //set configuration 190 opResult = usb_ request_set_configuration(&hub_info->endpoints.control,189 opResult = usb_drv_req_set_configuration(hc, target.address, 191 190 config_descriptor.configuration_number); 192 191 … … 198 197 for (port = 1; port < hub_info->port_count+1; ++port) { 199 198 usb_hub_set_power_port_request(&request, port); 200 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 201 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 199 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 202 200 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 203 201 if (opResult != EOK) { … … 207 205 //ports powered, hub seems to be enabled 208 206 209 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 210 //async_hangup(hc); 207 async_hangup(hc); 211 208 212 209 //add the hub to list … … 222 219 223 220 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 224 //address is lost...225 221 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 226 //hub_info->endpoints.control.,222 hub_info->address, 227 223 hub_info->port_count); 228 224 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number); … … 261 257 * @param target 262 258 */ 263 static void usb_hub_init_add_device( usb_hub_info_t * hub, uint16_t port) {259 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) { 264 260 usb_device_request_setup_packet_t request; 265 261 int opResult; 266 262 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 267 assert(hub->endpoints.control.hc_phone);268 263 //get default address 269 //opResult = usb_drv_reserve_default_address(hc); 270 opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW); 264 opResult = usb_drv_reserve_default_address(hc); 271 265 if (opResult != EOK) { 272 266 dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used"); … … 275 269 //reset port 276 270 usb_hub_set_reset_port_request(&request, port); 277 opResult = usb_ endpoint_pipe_control_write(278 &hub->endpoints.control,279 &request, sizeof(usb_device_request_setup_packet_t),271 opResult = usb_drv_sync_control_write( 272 hc, target, 273 &request, 280 274 NULL, 0 281 275 ); 282 276 if (opResult != EOK) { 283 277 dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port"); 284 //usb_hub_release_default_address(hc); 285 usb_hc_release_default_address(&hub->connection); 278 usb_hub_release_default_address(hc); 286 279 } 287 280 } … … 294 287 */ 295 288 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 296 uint16_t port) {289 int hc, uint16_t port, usb_target_t target) { 297 290 298 291 int opResult; 299 292 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device"); 300 opResult = usb_hub_clear_port_feature( &hub->endpoints.control,293 opResult = usb_hub_clear_port_feature(hc, target.address, 301 294 port, USB_HUB_FEATURE_C_PORT_RESET); 302 303 295 if (opResult != EOK) { 304 296 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature"); 305 usb_hc_release_default_address(&hub->connection); 306 return; 307 } 308 //create connection to device 309 usb_endpoint_pipe_t new_device_pipe; 310 usb_device_connection_t new_device_connection; 311 usb_device_connection_initialize_on_default_address( 312 &new_device_connection, 313 &hub->connection 314 ); 315 usb_endpoint_pipe_initialize_default_control( 316 &new_device_pipe, 317 &new_device_connection); 318 /// \TODO get highspeed info 319 320 321 322 323 324 /* Request address from host controller. */ 325 usb_address_t new_device_address = usb_hc_request_address( 326 &hub->connection, 327 USB_SPEED_LOW/// \TODO fullspeed?? 328 ); 297 usb_hub_release_default_address(hc); 298 return; 299 } 300 301 /* Request address at from host controller. */ 302 usb_address_t new_device_address = usb_drv_request_address(hc); 329 303 if (new_device_address < 0) { 330 304 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address"); 331 305 opResult = new_device_address; 332 usb_h c_release_default_address(&hub->connection);306 usb_hub_release_default_address(hc); 333 307 return; 334 308 } 335 309 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address); 336 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 337 // new_device_address); 338 opResult = usb_request_set_address(&new_device_pipe,new_device_address); 310 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 311 new_device_address); 339 312 340 313 if (opResult != EOK) { 341 314 dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device"); 342 usb_hc_release_default_address(&hub->connection); 343 return; 344 } 345 346 347 //opResult = usb_hub_release_default_address(hc); 348 opResult = usb_hc_release_default_address(&hub->connection); 315 usb_hub_release_default_address(hc); 316 return; 317 } 318 319 320 opResult = usb_hub_release_default_address(hc); 349 321 if(opResult!=EOK){ 350 322 return; 351 323 } 352 324 325 devman_handle_t hc_handle; 326 opResult = usb_drv_find_hc(hub->device, &hc_handle); 327 if (opResult != EOK) { 328 usb_log_error("Failed to get handle of host controller: %s.\n", 329 str_error(opResult)); 330 return; 331 } 332 353 333 devman_handle_t child_handle; 354 //?? 355 opResult = usb_device_register_child_in_devman(new_device_address, 356 hub->connection.hc_handle, hub->device, &child_handle); 357 334 opResult = usb_device_register_child_in_devman(new_device_address, 335 hc_handle, hub->device, &child_handle); 358 336 if (opResult != EOK) { 359 337 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); 360 338 return; 361 339 } 362 hub->attached_devs[port]. handle = child_handle;340 hub->attached_devs[port].devman_handle = child_handle; 363 341 hub->attached_devs[port].address = new_device_address; 364 342 365 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 366 opResult = usb_hc_register_device( 367 &hub->connection, 368 &hub->attached_devs[port]); 343 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 369 344 if (opResult != EOK) { 370 345 dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd"); … … 383 358 */ 384 359 static void usb_hub_removed_device( 385 usb_hub_info_t * hub, uint16_t port) {360 usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) { 386 361 //usb_device_request_setup_packet_t request; 387 362 int opResult; … … 390 365 * devide manager 391 366 */ 392 367 368 hub->attached_devs[port].devman_handle=0; 393 369 //close address 394 370 if(hub->attached_devs[port].address!=0){ 395 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 396 opResult = usb_hc_unregister_device( 397 &hub->connection, hub->attached_devs[port].address); 371 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 398 372 if(opResult != EOK) { 399 373 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \ … … 401 375 } 402 376 hub->attached_devs[port].address = 0; 403 hub->attached_devs[port].handle = 0;404 377 }else{ 405 378 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address"); 406 379 //device was disconnected before it`s port was reset - return default address 407 //usb_drv_release_default_address(hc); 408 usb_hc_release_default_address(&hub->connection); 380 usb_drv_release_default_address(hc); 409 381 } 410 382 } … … 416 388 * @param target 417 389 */ 418 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 419 uint16_t port ) {390 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, 391 uint16_t port, usb_address_t address) { 420 392 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 421 393 //determine type of change 422 usb_endpoint_pipe_t *pipe = &hub->endpoints.control;423 int opResult = usb_endpoint_pipe_start_session(pipe);424 425 if(opResult != EOK){426 dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);427 }428 429 /*430 394 usb_target_t target; 431 395 target.address=address; 432 396 target.endpoint=0; 433 */434 435 397 usb_port_status_t status; 436 398 size_t rcvd_size; 437 399 usb_device_request_setup_packet_t request; 438 //int opResult;400 int opResult; 439 401 usb_hub_set_port_status_request(&request, port); 440 402 //endpoint 0 441 403 442 opResult = usb_ endpoint_pipe_control_read(443 pipe,444 &request, sizeof(usb_device_request_setup_packet_t),404 opResult = usb_drv_sync_control_read( 405 hc, target, 406 &request, 445 407 &status, 4, &rcvd_size 446 408 ); … … 455 417 //something connected/disconnected 456 418 if (usb_port_connect_change(&status)) { 457 opResult = usb_hub_clear_port_feature( pipe,419 opResult = usb_hub_clear_port_feature(hc, target.address, 458 420 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 459 421 // TODO: check opResult 460 422 if (usb_port_dev_connected(&status)) { 461 423 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 462 usb_hub_init_add_device(h ub, port);424 usb_hub_init_add_device(hc, port, target); 463 425 } else { 464 usb_hub_removed_device(hub, port);426 usb_hub_removed_device(hub, hc, port, target); 465 427 } 466 428 } … … 469 431 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 470 432 if (usb_port_enabled(&status)) { 471 usb_hub_finalize_add_device(hub, port);433 usb_hub_finalize_add_device(hub, hc, port, target); 472 434 } else { 473 435 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 485 447 /// \TODO handle other changes 486 448 /// \TODO debug log for various situations 487 usb_endpoint_pipe_end_session(pipe);488 489 449 490 450 } … … 504 464 fibril_mutex_unlock(&usb_hub_list_lock); 505 465 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 506 int opResult;507 508 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);509 if(opResult != EOK){510 continue;511 }512 466 /* 513 467 * Check status change pipe of this hub. 514 468 */ 515 /* 469 516 470 usb_target_t target; 517 471 target.address = hub_info->address; … … 519 473 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 520 474 target.address); 521 */ 475 522 476 size_t port_count = hub_info->port_count; 523 477 524 478 /* 525 479 * Connect to respective HC. 526 * 480 */ 527 481 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 528 482 if (hc < 0) { 529 483 continue; 530 } */484 } 531 485 532 486 /// FIXME: count properly … … 535 489 void *change_bitmap = malloc(byte_length); 536 490 size_t actual_size; 537 //usb_handle_t handle;491 usb_handle_t handle; 538 492 539 493 /* 540 494 * Send the request. 541 495 */ 542 opResult = usb_endpoint_pipe_read( 543 &hub_info->endpoints.status_change, 544 change_bitmap, byte_length, &actual_size 545 ); 546 547 //usb_drv_async_wait_for(handle); 496 int opResult = usb_drv_async_interrupt_in(hc, target, 497 change_bitmap, byte_length, &actual_size, 498 &handle); 499 500 usb_drv_async_wait_for(handle); 548 501 549 502 if (opResult != EOK) { … … 558 511 if (interrupt) { 559 512 usb_hub_process_interrupt( 560 hub_info, port);513 hub_info, hc, port, hub_info->address); 561 514 } 562 515 } 563 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);564 516 free(change_bitmap); 565 566 567 //async_hangup(hc); 517 518 async_hangup(hc); 568 519 fibril_mutex_lock(&usb_hub_list_lock); 569 520 } -
uspace/drv/usbhub/usbhub.h
r62066b4 r423e8c81 42 42 #define NAME "usbhub" 43 43 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 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; 57 49 58 50 /** Information about attached hub. */ … … 60 52 /** Number of ports. */ 61 53 int port_count; 62 /** attached device handles , for each port one*/63 usb_h c_attached_device_t * attached_devs;64 /** General usb device info. */65 //usb_hcd_attached_device_info_t * usb_device;54 /** attached device handles */ 55 usb_hub_attached_device_t * attached_devs; 56 /** USB address of the hub. */ 57 usb_address_t address; 66 58 /** General device info*/ 67 59 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;75 60 } usb_hub_info_t; 76 61 -
uspace/drv/usbhub/usbhub_private.h
r62066b4 r423e8c81 45 45 #include <fibril_synch.h> 46 46 47 #include <usb/classes/hub.h>48 47 #include <usb/usb.h> 49 48 #include <usb/usbdrv.h> 50 51 //#include <usb/devreq.h>49 #include <usb/classes/hub.h> 50 #include <usb/devreq.h> 52 51 #include <usb/debug.h> 53 52 … … 78 77 * @return 79 78 */ 80 usb_hub_info_t * usb_create_hub_info(device_t * device );79 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc); 81 80 82 81 /** List of hubs maanged by this driver */ … … 99 98 * @return error code 100 99 */ 101 /*102 100 int usb_drv_sync_control_read( 103 usb_endpoint_pipe_t *pipe,101 int phone, usb_target_t target, 104 102 usb_device_request_setup_packet_t * request, 105 103 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size 106 ); */104 ); 107 105 108 106 /** … … 117 115 * @return error code 118 116 */ 119 /*int usb_drv_sync_control_write(120 usb_endpoint_pipe_t *pipe,117 int usb_drv_sync_control_write( 118 int phone, usb_target_t target, 121 119 usb_device_request_setup_packet_t * request, 122 120 void * sent_buffer, size_t sent_size 123 ); */121 ); 124 122 125 123 /** … … 149 147 * @return Operation result 150 148 */ 151 static inline int usb_hub_clear_port_feature( usb_endpoint_pipe_t *pipe,149 static inline int usb_hub_clear_port_feature(int hc, usb_address_t address, 152 150 int port_index, 153 151 usb_hub_class_feature_t feature) { 154 152 usb_target_t target = { 153 .address = address, 154 .endpoint = 0 155 }; 155 156 usb_device_request_setup_packet_t clear_request = { 156 157 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE, … … 160 161 }; 161 162 clear_request.value = feature; 162 return usb_ endpoint_pipe_control_write(pipe, &clear_request,163 return usb_drv_psync_control_write(hc, target, &clear_request, 163 164 sizeof(clear_request), NULL, 0); 164 165 } -
uspace/drv/usbhub/utils.c
r62066b4 r423e8c81 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
r62066b4 r423e8c81 1 1 /* 2 * Copyright (c) 2010 Matus Dekanek2 * Copyright (c) 2010 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 33 33 * @brief USB hub related structures. 34 34 */ 35 #ifndef LIBUSB_ CLASS_HUB_H_36 #define LIBUSB_ CLASS_HUB_H_35 #ifndef LIBUSB_HUB_H_ 36 #define LIBUSB_HUB_H_ 37 37 38 38 #include <sys/types.h>
Note:
See TracChangeset
for help on using the changeset viewer.