Changes in / [ace12560:41e645c] in mainline
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
race12560 r41e645c 44 44 #include <usb/recognise.h> 45 45 #include <usb/devreq.h> 46 #include <usb/request.h>47 46 #include <usb/classes/hub.h> 48 47 … … 51 50 #include "port_status.h" 52 51 #include "usb/usb.h" 53 #include "usb/pipes.h"54 52 55 53 static device_ops_t hub_device_ops = { … … 63 61 //********************************************* 64 62 65 usb_hub_info_t * usb_create_hub_info(device_t * device ) {63 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) { 66 64 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 75 65 //result->device = device; 76 66 result->port_count = -1; … … 78 68 result->device = device; 79 69 80 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); 81 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 82 85 // get hub descriptor 83 86 … … 88 91 int opResult; 89 92 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 90 usb_endpoint_pipe_start_session(&result->endpoints.control);91 opResult = usb_ request_get_descriptor(&result->endpoints.control,93 94 opResult = usb_drv_req_get_descriptor(hc, addr, 92 95 USB_REQUEST_TYPE_CLASS, 93 96 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 94 97 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 call103 98 104 99 if (opResult != EOK) { … … 116 111 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count); 117 112 result->port_count = descriptor->ports_count; 118 result->attached_devs = (usb_h c_attached_device_t*)119 malloc((result->port_count+1) * sizeof(usb_h c_attached_device_t));113 result->attached_devs = (usb_hub_attached_device_t*) 114 malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t)); 120 115 int i; 121 116 for(i=0;i<result->port_count+1;++i){ 122 result->attached_devs[i]. handle=0;117 result->attached_devs[i].devman_handle=0; 123 118 result->attached_devs[i].address=0; 124 119 } … … 145 140 dev->ops = &hub_device_ops; 146 141 147 148 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 149 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 150 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); 151 150 int port; 152 151 int opResult; 153 //usb_target_t target;154 //target.address = hub_info->usb_device->address;155 //target.endpoint = 0;152 usb_target_t target; 153 target.address = hub_info->address; 154 target.endpoint = 0; 156 155 157 156 //get configuration descriptor … … 159 158 // and all should be checked 160 159 usb_standard_device_descriptor_t std_descriptor; 161 opResult = usb_ request_get_device_descriptor(&hub_info->endpoints.control,160 opResult = usb_drv_req_get_device_descriptor(hc, target.address, 162 161 &std_descriptor); 163 162 if(opResult!=EOK){ … … 172 171 /// \TODO check other configurations 173 172 usb_standard_configuration_descriptor_t config_descriptor; 174 opResult = usb_ request_get_bare_configuration_descriptor(175 &hub_info->endpoints.control, 0,173 opResult = usb_drv_req_get_bare_configuration_descriptor(hc, 174 target.address, 0, 176 175 &config_descriptor); 177 176 if(opResult!=EOK){ … … 180 179 } 181 180 //set configuration 182 opResult = usb_ request_set_configuration(&hub_info->endpoints.control,181 opResult = usb_drv_req_set_configuration(hc, target.address, 183 182 config_descriptor.configuration_number); 184 183 … … 190 189 for (port = 1; port < hub_info->port_count+1; ++port) { 191 190 usb_hub_set_power_port_request(&request, port); 192 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 193 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 191 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 194 192 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 195 193 if (opResult != EOK) { … … 199 197 //ports powered, hub seems to be enabled 200 198 201 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 202 //async_hangup(hc); 199 async_hangup(hc); 203 200 204 201 //add the hub to list … … 214 211 215 212 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 216 //address is lost...217 213 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 218 //hub_info->endpoints.control.,214 hub_info->address, 219 215 hub_info->port_count); 220 216 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number); … … 253 249 * @param target 254 250 */ 255 static void usb_hub_init_add_device( usb_hub_info_t * hub, uint16_t port) {251 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) { 256 252 usb_device_request_setup_packet_t request; 257 253 int opResult; 258 254 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 259 assert(hub->endpoints.control.hc_phone);260 255 //get default address 261 //opResult = usb_drv_reserve_default_address(hc); 262 opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW); 256 opResult = usb_drv_reserve_default_address(hc); 263 257 if (opResult != EOK) { 264 258 dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used"); … … 267 261 //reset port 268 262 usb_hub_set_reset_port_request(&request, port); 269 opResult = usb_ endpoint_pipe_control_write(270 &hub->endpoints.control,271 &request, sizeof(usb_device_request_setup_packet_t),263 opResult = usb_drv_sync_control_write( 264 hc, target, 265 &request, 272 266 NULL, 0 273 267 ); 274 268 if (opResult != EOK) { 275 269 dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port"); 276 //usb_hub_release_default_address(hc); 277 usb_hc_release_default_address(&hub->connection); 270 usb_hub_release_default_address(hc); 278 271 } 279 272 } … … 286 279 */ 287 280 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 288 uint16_t port) {281 int hc, uint16_t port, usb_target_t target) { 289 282 290 283 int opResult; 291 284 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device"); 292 opResult = usb_hub_clear_port_feature( &hub->endpoints.control,285 opResult = usb_hub_clear_port_feature(hc, target.address, 293 286 port, USB_HUB_FEATURE_C_PORT_RESET); 294 295 287 if (opResult != EOK) { 296 288 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature"); 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 USB_SPEED_LOW/// \TODO fullspeed?? 320 ); 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); 321 295 if (new_device_address < 0) { 322 296 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address"); 323 297 opResult = new_device_address; 324 usb_h c_release_default_address(&hub->connection);298 usb_hub_release_default_address(hc); 325 299 return; 326 300 } 327 301 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",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); 302 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 303 new_device_address); 331 304 332 305 if (opResult != EOK) { 333 306 dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device"); 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); 307 usb_hub_release_default_address(hc); 308 return; 309 } 310 311 312 opResult = usb_hub_release_default_address(hc); 341 313 if(opResult!=EOK){ 342 314 return; 343 315 } 344 316 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 345 325 devman_handle_t child_handle; 346 //?? 347 opResult = usb_device_register_child_in_devman(new_device_address, 348 hub->connection.hc_handle, hub->device, &child_handle); 349 326 opResult = usb_device_register_child_in_devman(new_device_address, 327 hc_handle, hub->device, &child_handle); 350 328 if (opResult != EOK) { 351 329 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); 352 330 return; 353 331 } 354 hub->attached_devs[port]. handle = child_handle;332 hub->attached_devs[port].devman_handle = child_handle; 355 333 hub->attached_devs[port].address = new_device_address; 356 334 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]); 335 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 361 336 if (opResult != EOK) { 362 337 dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd"); … … 375 350 */ 376 351 static void usb_hub_removed_device( 377 usb_hub_info_t * hub, uint16_t port) {352 usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) { 378 353 //usb_device_request_setup_packet_t request; 379 354 int opResult; … … 382 357 * devide manager 383 358 */ 384 359 360 hub->attached_devs[port].devman_handle=0; 385 361 //close address 386 362 if(hub->attached_devs[port].address!=0){ 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); 363 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 390 364 if(opResult != EOK) { 391 365 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \ … … 393 367 } 394 368 hub->attached_devs[port].address = 0; 395 hub->attached_devs[port].handle = 0;396 369 }else{ 397 370 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address"); 398 371 //device was disconnected before it`s port was reset - return default address 399 //usb_drv_release_default_address(hc); 400 usb_hc_release_default_address(&hub->connection); 372 usb_drv_release_default_address(hc); 401 373 } 402 374 } … … 408 380 * @param target 409 381 */ 410 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 411 uint16_t port ) {382 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, 383 uint16_t port, usb_address_t address) { 412 384 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 413 385 //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 /*422 386 usb_target_t target; 423 387 target.address=address; 424 388 target.endpoint=0; 425 */426 427 389 usb_port_status_t status; 428 390 size_t rcvd_size; 429 391 usb_device_request_setup_packet_t request; 430 //int opResult;392 int opResult; 431 393 usb_hub_set_port_status_request(&request, port); 432 394 //endpoint 0 433 395 434 opResult = usb_ endpoint_pipe_control_read(435 pipe,436 &request, sizeof(usb_device_request_setup_packet_t),396 opResult = usb_drv_sync_control_read( 397 hc, target, 398 &request, 437 399 &status, 4, &rcvd_size 438 400 ); … … 447 409 //something connected/disconnected 448 410 if (usb_port_connect_change(&status)) { 449 opResult = usb_hub_clear_port_feature( pipe,411 opResult = usb_hub_clear_port_feature(hc, target.address, 450 412 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 451 413 // TODO: check opResult 452 414 if (usb_port_dev_connected(&status)) { 453 415 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 454 usb_hub_init_add_device(h ub, port);416 usb_hub_init_add_device(hc, port, target); 455 417 } else { 456 usb_hub_removed_device(hub, port);418 usb_hub_removed_device(hub, hc, port, target); 457 419 } 458 420 } … … 461 423 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 462 424 if (usb_port_enabled(&status)) { 463 usb_hub_finalize_add_device(hub, port);425 usb_hub_finalize_add_device(hub, hc, port, target); 464 426 } else { 465 427 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 477 439 /// \TODO handle other changes 478 440 /// \TODO debug log for various situations 479 usb_endpoint_pipe_end_session(pipe);480 481 441 482 442 } … … 496 456 fibril_mutex_unlock(&usb_hub_list_lock); 497 457 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 }504 458 /* 505 459 * Check status change pipe of this hub. 506 460 */ 507 /* 461 508 462 usb_target_t target; 509 463 target.address = hub_info->address; … … 511 465 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 512 466 target.address); 513 */ 467 514 468 size_t port_count = hub_info->port_count; 515 469 516 470 /* 517 471 * Connect to respective HC. 518 * 472 */ 519 473 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 520 474 if (hc < 0) { 521 475 continue; 522 } */476 } 523 477 524 478 /// FIXME: count properly … … 527 481 void *change_bitmap = malloc(byte_length); 528 482 size_t actual_size; 529 //usb_handle_t handle;483 usb_handle_t handle; 530 484 531 485 /* 532 486 * Send the request. 533 487 */ 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); 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); 540 493 541 494 if (opResult != EOK) { … … 550 503 if (interrupt) { 551 504 usb_hub_process_interrupt( 552 hub_info, port);505 hub_info, hc, port, hub_info->address); 553 506 } 554 507 } 555 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);556 508 free(change_bitmap); 557 558 559 //async_hangup(hc); 509 510 async_hangup(hc); 560 511 fibril_mutex_lock(&usb_hub_list_lock); 561 512 } -
uspace/drv/usbhub/usbhub.h
race12560 r41e645c 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
race12560 r41e645c 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
race12560 r41e645c 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
race12560 r41e645c 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.