Changes in / [da7c0a9:063ead6f] in mainline
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
rda7c0a9 r063ead6f 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); 263 256 opResult = usb_drv_reserve_default_address(hc); 264 257 if (opResult != EOK) { 265 258 dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used"); … … 268 261 //reset port 269 262 usb_hub_set_reset_port_request(&request, port); 270 opResult = usb_ endpoint_pipe_control_write(271 &hub->endpoints.control,272 &request, sizeof(usb_device_request_setup_packet_t),263 opResult = usb_drv_sync_control_write( 264 hc, target, 265 &request, 273 266 NULL, 0 274 267 ); 275 268 if (opResult != EOK) { 276 269 dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port"); 277 //usb_hub_release_default_address(hc); 278 usb_hc_release_default_address(&hub->connection); 270 usb_hub_release_default_address(hc); 279 271 } 280 272 } … … 287 279 */ 288 280 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 289 uint16_t port) {281 int hc, uint16_t port, usb_target_t target) { 290 282 291 283 int opResult; 292 284 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device"); 293 opResult = usb_hub_clear_port_feature( &hub->endpoints.control,285 opResult = usb_hub_clear_port_feature(hc, target.address, 294 286 port, USB_HUB_FEATURE_C_PORT_RESET); 295 296 287 if (opResult != EOK) { 297 288 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature"); 298 usb_hc_release_default_address(&hub->connection); 299 return; 300 } 301 //create connection to device 302 usb_endpoint_pipe_t new_device_pipe; 303 usb_device_connection_t new_device_connection; 304 usb_device_connection_initialize_on_default_address( 305 &new_device_connection, 306 &hub->connection 307 ); 308 usb_endpoint_pipe_initialize_default_control( 309 &new_device_pipe, 310 &new_device_connection); 311 /// \TODO get highspeed info 312 313 314 315 316 317 /* Request address from host controller. */ 318 usb_address_t new_device_address = usb_hc_request_address( 319 &hub->connection, 320 USB_SPEED_LOW/// \TODO fullspeed?? 321 ); 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); 322 295 if (new_device_address < 0) { 323 296 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address"); 324 297 opResult = new_device_address; 325 usb_h c_release_default_address(&hub->connection);298 usb_hub_release_default_address(hc); 326 299 return; 327 300 } 328 301 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address); 329 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 330 // new_device_address); 331 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); 332 304 333 305 if (opResult != EOK) { 334 306 dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device"); 335 usb_hc_release_default_address(&hub->connection); 336 return; 337 } 338 339 340 //opResult = usb_hub_release_default_address(hc); 341 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); 342 313 if(opResult!=EOK){ 343 314 return; 344 315 } 345 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 346 325 devman_handle_t child_handle; 347 //?? 348 opResult = usb_device_register_child_in_devman(new_device_address, 349 hub->connection.hc_handle, hub->device, &child_handle); 350 326 opResult = usb_device_register_child_in_devman(new_device_address, 327 hc_handle, hub->device, &child_handle); 351 328 if (opResult != EOK) { 352 329 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); 353 330 return; 354 331 } 355 hub->attached_devs[port]. handle = child_handle;332 hub->attached_devs[port].devman_handle = child_handle; 356 333 hub->attached_devs[port].address = new_device_address; 357 334 358 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 359 opResult = usb_hc_register_device( 360 &hub->connection, 361 &hub->attached_devs[port]); 335 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 362 336 if (opResult != EOK) { 363 337 dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd"); … … 376 350 */ 377 351 static void usb_hub_removed_device( 378 usb_hub_info_t * hub, uint16_t port) {352 usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) { 379 353 //usb_device_request_setup_packet_t request; 380 354 int opResult; … … 383 357 * devide manager 384 358 */ 385 359 360 hub->attached_devs[port].devman_handle=0; 386 361 //close address 387 362 if(hub->attached_devs[port].address!=0){ 388 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 389 opResult = usb_hc_unregister_device( 390 &hub->connection, hub->attached_devs[port].address); 363 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 391 364 if(opResult != EOK) { 392 365 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \ … … 394 367 } 395 368 hub->attached_devs[port].address = 0; 396 hub->attached_devs[port].handle = 0;397 369 }else{ 398 370 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address"); 399 371 //device was disconnected before it`s port was reset - return default address 400 //usb_drv_release_default_address(hc); 401 usb_hc_release_default_address(&hub->connection); 372 usb_drv_release_default_address(hc); 402 373 } 403 374 } … … 409 380 * @param target 410 381 */ 411 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 412 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) { 413 384 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 414 385 //determine type of change 415 usb_endpoint_pipe_t *pipe = &hub->endpoints.control;416 int opResult = usb_endpoint_pipe_start_session(pipe);417 418 if(opResult != EOK){419 dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);420 }421 422 /*423 386 usb_target_t target; 424 387 target.address=address; 425 388 target.endpoint=0; 426 */427 428 389 usb_port_status_t status; 429 390 size_t rcvd_size; 430 391 usb_device_request_setup_packet_t request; 431 //int opResult;392 int opResult; 432 393 usb_hub_set_port_status_request(&request, port); 433 394 //endpoint 0 434 395 435 opResult = usb_ endpoint_pipe_control_read(436 pipe,437 &request, sizeof(usb_device_request_setup_packet_t),396 opResult = usb_drv_sync_control_read( 397 hc, target, 398 &request, 438 399 &status, 4, &rcvd_size 439 400 ); … … 448 409 //something connected/disconnected 449 410 if (usb_port_connect_change(&status)) { 450 opResult = usb_hub_clear_port_feature( pipe,411 opResult = usb_hub_clear_port_feature(hc, target.address, 451 412 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 452 413 // TODO: check opResult 453 414 if (usb_port_dev_connected(&status)) { 454 415 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 455 usb_hub_init_add_device(h ub, port);416 usb_hub_init_add_device(hc, port, target); 456 417 } else { 457 usb_hub_removed_device(hub, port);418 usb_hub_removed_device(hub, hc, port, target); 458 419 } 459 420 } … … 462 423 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 463 424 if (usb_port_enabled(&status)) { 464 usb_hub_finalize_add_device(hub, port);425 usb_hub_finalize_add_device(hub, hc, port, target); 465 426 } else { 466 427 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 478 439 /// \TODO handle other changes 479 440 /// \TODO debug log for various situations 480 usb_endpoint_pipe_end_session(pipe);481 482 441 483 442 } … … 497 456 fibril_mutex_unlock(&usb_hub_list_lock); 498 457 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 499 int opResult;500 501 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);502 if(opResult != EOK){503 continue;504 }505 458 /* 506 459 * Check status change pipe of this hub. 507 460 */ 508 /* 461 509 462 usb_target_t target; 510 463 target.address = hub_info->address; … … 512 465 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 513 466 target.address); 514 */ 467 515 468 size_t port_count = hub_info->port_count; 516 469 517 470 /* 518 471 * Connect to respective HC. 519 * 472 */ 520 473 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 521 474 if (hc < 0) { 522 475 continue; 523 } */476 } 524 477 525 478 /// FIXME: count properly … … 528 481 void *change_bitmap = malloc(byte_length); 529 482 size_t actual_size; 530 //usb_handle_t handle;483 usb_handle_t handle; 531 484 532 485 /* 533 486 * Send the request. 534 487 */ 535 opResult = usb_endpoint_pipe_read( 536 &hub_info->endpoints.status_change, 537 change_bitmap, byte_length, &actual_size 538 ); 539 540 //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); 541 493 542 494 if (opResult != EOK) { … … 551 503 if (interrupt) { 552 504 usb_hub_process_interrupt( 553 hub_info, port);505 hub_info, hc, port, hub_info->address); 554 506 } 555 507 } 556 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);557 508 free(change_bitmap); 558 559 560 //async_hangup(hc); 509 510 async_hangup(hc); 561 511 fibril_mutex_lock(&usb_hub_list_lock); 562 512 } -
uspace/drv/usbhub/usbhub.h
rda7c0a9 r063ead6f 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
rda7c0a9 r063ead6f 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
rda7c0a9 r063ead6f 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
rda7c0a9 r063ead6f 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.