Changes in / [a146aa33:cd4ae1e] in mainline
- Location:
- uspace/drv
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
ra146aa33 rcd4ae1e 149 149 150 150 151 static int create_serialized_hub_descriptor(rh_t *instance); 152 153 static int rh_init_descriptors(rh_t *instance); 151 static void usb_create_serialized_hub_descriptor(rh_t *instance, 152 uint8_t ** out_result, 153 size_t * out_size); 154 155 static void rh_init_descriptors(rh_t *instance); 154 156 155 157 static int process_get_port_status_request(rh_t *instance, uint16_t port, … … 162 164 usb_transfer_batch_t * request); 163 165 164 static void create_interrupt_mask_in_instance(rh_t *instance); 166 static void create_interrupt_mask(rh_t *instance, void ** buffer, 167 size_t * buffer_size); 165 168 166 169 static int process_get_descriptor_request(rh_t *instance, … … 195 198 static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request); 196 199 197 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request); 200 static int process_interrupt(rh_t *instance, usb_transfer_batch_t * request, 201 void * change_buffer, size_t buffe_size); 198 202 199 203 static bool is_zeros(void * buffer, size_t size); … … 209 213 instance->port_count = 210 214 (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK; 211 int opResult = rh_init_descriptors(instance); 212 if(opResult != EOK){ 213 return opResult; 214 } 215 rh_init_descriptors(instance); 215 216 // set port power mode to no-power-switching 216 217 instance->registers->rh_desc_a |= RHDA_NPS_FLAG; 217 218 instance->unfinished_interrupt_transfer = NULL; 218 instance->interrupt_mask_size = (instance->port_count + 8)/8; 219 instance->interrupt_buffer = malloc(instance->interrupt_mask_size); 220 if(!instance->interrupt_buffer) 221 return ENOMEM; 222 223 219 instance->interrupt_buffer = malloc((instance->port_count + 8)/8); 224 220 usb_log_info("OHCI root hub with %d ports.\n", instance->port_count); 225 221 return EOK; … … 244 240 } else if (request->ep->transfer_type == USB_TRANSFER_INTERRUPT) { 245 241 usb_log_info("Root hub got INTERRUPT packet\n"); 246 create_interrupt_mask_in_instance(instance); 247 if(is_zeros(instance->interrupt_buffer, 248 instance->interrupt_mask_size)){ 249 usb_log_debug("no changes..\n"); 250 instance->unfinished_interrupt_transfer = request; 242 void * buffer; 243 size_t buffer_size; 244 create_interrupt_mask(instance, &buffer, 245 &buffer_size); 246 if(is_zeros(buffer,buffer_size)){ 247 usb_log_debug("no changes.."); 248 instance->unfinished_interrupt_transfer= 249 request; 251 250 //will be finished later 252 251 }else{ 253 usb_log_debug("processing changes..\n"); 254 process_interrupt_mask_in_instance(instance, request); 255 } 252 usb_log_debug("processing changes.."); 253 process_interrupt(instance, request, 254 buffer, buffer_size); 255 } 256 free(buffer); 256 257 opResult = EOK; 257 258 } else { … … 264 265 /*----------------------------------------------------------------------------*/ 265 266 266 /** 267 * process interrupt on a hub 268 * 269 * If there is no pending interrupt transfer, nothing happens. 270 * @param instance 271 */ 267 272 268 void rh_interrupt(rh_t *instance) { 269 //usb_log_info("Whoa whoa wait, I`m not supposed to receive any " 270 // "interrupts, am I?\n"); 273 271 if(!instance->unfinished_interrupt_transfer){ 274 272 return; 275 273 } 276 usb_log_debug("finalizing interrupt transfer\n"); 277 create_interrupt_mask_in_instance(instance); 278 process_interrupt_mask_in_instance(instance, 279 instance->unfinished_interrupt_transfer); 274 size_t size; 275 void * buffer; 276 create_interrupt_mask(instance, &buffer, 277 &size); 278 process_interrupt(instance,instance->unfinished_interrupt_transfer, 279 buffer,size); 280 free(buffer); 280 281 } 281 282 /*----------------------------------------------------------------------------*/ … … 288 289 * 289 290 * @param instance root hub instance 290 * @return error code 291 */ 292 static int create_serialized_hub_descriptor(rh_t *instance) { 293 size_t size = 7 + 294 ((instance->port_count +7 )/ 8) * 2; 295 size_t var_size = (instance->port_count +7 )/ 8; 291 * @param@out out_result pointer to resultant serialized descriptor 292 * @param@out out_size size of serialized descriptor 293 */ 294 static void usb_create_serialized_hub_descriptor(rh_t *instance, 295 uint8_t ** out_result, 296 size_t * out_size) { 297 //base size 298 size_t size = 7; 299 //variable size according to port count 300 size_t var_size = instance->port_count / 8 + 301 ((instance->port_count % 8 > 0) ? 1 : 0); 302 size += 2 * var_size; 296 303 uint8_t * result = (uint8_t*) malloc(size); 297 if(!result) return ENOMEM;298 299 304 bzero(result, size); 300 305 //size … … 325 330 result[7 + var_size + i] = 255; 326 331 } 327 instance->hub_descriptor = result; 328 instance->descriptor_size = size; 329 return EOK; 332 (*out_result) = result; 333 (*out_size) = size; 330 334 } 331 335 /*----------------------------------------------------------------------------*/ … … 336 340 * be initialized only once per hub. 337 341 * @instance root hub instance 338 * @return error code 339 */ 340 static int rh_init_descriptors(rh_t *instance) { 342 */ 343 static void rh_init_descriptors(rh_t *instance) { 341 344 memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor, 342 345 sizeof (ohci_rh_device_descriptor) … … 345 348 memcpy(&descriptor, &ohci_rh_conf_descriptor, 346 349 sizeof (ohci_rh_conf_descriptor)); 347 348 int opResult = create_serialized_hub_descriptor(instance);349 if(opResult != EOK){350 return opResult;351 } 350 uint8_t * hub_descriptor; 351 size_t hub_desc_size; 352 usb_create_serialized_hub_descriptor(instance, &hub_descriptor, 353 &hub_desc_size); 354 352 355 descriptor.total_length = 353 356 sizeof (usb_standard_configuration_descriptor_t) + 354 357 sizeof (usb_standard_endpoint_descriptor_t) + 355 358 sizeof (usb_standard_interface_descriptor_t) + 356 instance->descriptor_size;359 hub_desc_size; 357 360 358 361 uint8_t * full_config_descriptor = 359 362 (uint8_t*) malloc(descriptor.total_length); 360 if(!full_config_descriptor){361 return ENOMEM;362 }363 363 memcpy(full_config_descriptor, &descriptor, sizeof (descriptor)); 364 364 memcpy(full_config_descriptor + sizeof (descriptor), … … 370 370 sizeof (ohci_rh_iface_descriptor) + 371 371 sizeof (ohci_rh_ep_descriptor), 372 instance->hub_descriptor, instance->descriptor_size);373 372 hub_descriptor, hub_desc_size); 373 374 374 instance->descriptors.configuration = full_config_descriptor; 375 375 instance->descriptors.configuration_size = descriptor.total_length; 376 return EOK;377 376 } 378 377 /*----------------------------------------------------------------------------*/ … … 465 464 * bit i indicates change on i`th port (i>0). For more info see 466 465 * Hub and Port status bitmap specification in USB specification 467 * (chapter 11.13.4). 468 * Uses instance`s interrupt buffer to store the interrupt information. 469 * @param instance root hub instance 470 */ 471 static void create_interrupt_mask_in_instance(rh_t * instance) { 472 uint8_t * bitmap = (uint8_t*) (instance->interrupt_buffer); 466 * (chapter 11.13.4) 467 * @param instance root hub instance 468 * @param@out buffer pointer to created interrupt mas 469 * @param@out buffer_size size of created interrupt mask 470 */ 471 static void create_interrupt_mask(rh_t *instance, void ** buffer, 472 size_t * buffer_size) { 473 int bit_count = instance->port_count + 1; 474 (*buffer_size) = (bit_count+7 / 8); 475 476 (*buffer) = instance->interrupt_buffer;//malloc(*buffer_size); 477 uint8_t * bitmap = (uint8_t*) (*buffer); 473 478 uint32_t mask = (1 << (USB_HUB_FEATURE_C_HUB_LOCAL_POWER + 16)) 474 479 | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16)); 475 bzero(bitmap, instance->interrupt_mask_size);480 bzero(bitmap, (*buffer_size)); 476 481 if (instance->registers->rh_status & mask) { 477 482 bitmap[0] = 1; … … 504 509 const uint16_t setup_request_value = setup_request->value_high; 505 510 //(setup_request->value_low << 8); 511 bool del = false; 506 512 switch (setup_request_value) { 507 513 case USB_DESCTYPE_HUB: 508 514 { 509 usb_log_debug("USB_DESCTYPE_HUB\n"); 510 result_descriptor = instance->hub_descriptor; 511 size = instance->descriptor_size; 515 uint8_t * descriptor; 516 usb_create_serialized_hub_descriptor( 517 instance, &descriptor, &size); 518 result_descriptor = descriptor; 519 if (result_descriptor) del = true; 512 520 break; 513 521 } … … 560 568 request->transfered_size = size; 561 569 memcpy(request->data_buffer, result_descriptor, size); 570 if (del) 571 free(result_descriptor); 562 572 return EOK; 563 573 } … … 885 895 * @param instance hub instance 886 896 * @param request batch request to be processed 897 * @param change_buffer chages on hub 898 * @param buffer_size size of change buffer 887 899 * 888 900 * @return 889 901 */ 890 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request){ 891 memcpy(request->data_buffer, instance->interrupt_buffer, 892 instance->interrupt_mask_size); 893 request->transfered_size = instance->interrupt_mask_size; 902 static int process_interrupt(rh_t *instance, usb_transfer_batch_t * request, 903 void * change_buffer, size_t buffe_size){ 904 create_interrupt_mask(instance, &change_buffer, 905 &(request->transfered_size)); 906 memcpy(request->data_buffer, change_buffer,request->transfered_size); 894 907 instance->unfinished_interrupt_transfer = NULL; 895 908 usb_transfer_batch_finish_error(request, EOK); -
uspace/drv/ohci/root_hub.h
ra146aa33 rcd4ae1e 59 59 * 60 60 * This is allocated when initializing instance, so that memory 61 * allocation is not needed when processing request. Buffer is used for 62 * interrupt bitmask. 61 * allocation is not needed when processing request. 63 62 */ 64 63 uint8_t * interrupt_buffer; 65 /** size of interrupt buffer */66 size_t interrupt_mask_size;67 /** instance`s descriptor*/68 uint8_t * hub_descriptor;69 /** size of hub descriptor */70 size_t descriptor_size;71 72 73 64 } rh_t; 74 65 -
uspace/drv/usbhub/main.c
ra146aa33 rcd4ae1e 55 55 }; 56 56 57 /** 58 * usb hub driver operations 59 * 60 * The most important one is add_device, which is set to usb_hub_add_device. 61 */ 57 62 58 static usb_driver_ops_t usb_hub_driver_ops = { 63 59 .add_device = usb_hub_add_device 64 60 }; 65 61 66 /**67 * hub endpoints, excluding control endpoint68 */69 62 static usb_endpoint_description_t *usb_hub_endpoints[] = { 70 63 &hub_status_change_endpoint_description, … … 72 65 }; 73 66 74 /**75 * static usb hub driver information76 */77 67 static usb_driver_t usb_hub_driver = { 78 68 .name = NAME, -
uspace/drv/usbhub/ports.c
ra146aa33 rcd4ae1e 167 167 168 168 //close address 169 //if (hub->attached_devs[port].address != 0) { 169 170 if(hub->ports[port].attached_device.address >= 0){ 170 171 /*uncomment this code to use it when DDF allows device removal … … 181 182 */ 182 183 } else { 184 // TODO: is this really reason to print a warning? 183 185 usb_log_warning("Device removed before being registered.\n"); 184 186 -
uspace/drv/usbhub/usbhub.c
ra146aa33 rcd4ae1e 73 73 74 74 75 /// \TODO malloc checking 76 75 77 //********************************************* 76 78 // … … 246 248 hub_info->ports = malloc( 247 249 sizeof (usb_hub_port_t) * (hub_info->port_count + 1)); 248 if(!hub_info->ports){249 return ENOMEM;250 }251 250 size_t port; 252 251 for (port = 0; port < hub_info->port_count + 1; ++port) { … … 256 255 usb_log_debug("is_power_switched\n"); 257 256 257 for (port = 1; port <= hub_info->port_count; ++port) { 258 usb_log_debug("Powering port %zu.\n",port); 259 opResult = usb_hub_set_port_feature(hub_info->control_pipe, 260 port, USB_HUB_FEATURE_PORT_POWER); 261 if (opResult != EOK) { 262 usb_log_error("cannot power on port %zu: %s.\n", 263 port, str_error(opResult)); 264 } 265 } 258 266 if(!has_individual_port_powering){ 259 267 usb_log_debug("!has_individual_port_powering\n"); … … 265 273 } 266 274 } 267 268 for (port = 1; port <= hub_info->port_count; ++port) {269 usb_log_debug("Powering port %zu.\n",port);270 opResult = usb_hub_set_port_feature(hub_info->control_pipe,271 port, USB_HUB_FEATURE_PORT_POWER);272 if (opResult != EOK) {273 usb_log_error("cannot power on port %zu: %s.\n",274 port, str_error(opResult));275 }276 }277 278 275 }else{ 279 usb_log_debug("!is_power_switched , not going to be powered\n");276 usb_log_debug("!is_power_switched\n"); 280 277 } 281 278 usb_log_debug2("freeing data\n");
Note:
See TracChangeset
for help on using the changeset viewer.