Changeset eda7a4e0 in mainline
- Timestamp:
- 2011-10-13T11:43:23Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a14d6a7
- Parents:
- fb422312
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/usbhub.c
rfb422312 reda7a4e0 69 69 static int usb_set_first_configuration(usb_device_t *usb_device); 70 70 static usb_hub_dev_t * usb_hub_dev_create(usb_device_t *usb_dev); 71 static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_ info);72 static void usb_hub_over_current(const usb_hub_dev_t *hub_ info,71 static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_dev); 72 static void usb_hub_over_current(const usb_hub_dev_t *hub_dev, 73 73 usb_hub_status_t status); 74 static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_ info);74 static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_dev); 75 75 static void usb_hub_polling_terminated_callback(usb_device_t *device, 76 76 bool was_error, void *data); … … 124 124 assert(usb_dev); 125 125 /* Create driver soft-state structure */ 126 usb_hub_dev_t *hub_ info= usb_hub_dev_create(usb_dev);127 if (hub_ info== NULL) {126 usb_hub_dev_t *hub_dev = usb_hub_dev_create(usb_dev); 127 if (hub_dev == NULL) { 128 128 usb_log_error("Failed to create hun driver structure.\n"); 129 129 return ENOMEM; … … 133 133 usb_log_debug("Initializing USB wire abstraction.\n"); 134 134 int opResult = usb_hc_connection_initialize_from_device( 135 &hub_ info->connection, hub_info->usb_device->ddf_dev);135 &hub_dev->connection, hub_dev->usb_device->ddf_dev); 136 136 if (opResult != EOK) { 137 137 usb_log_error("Could not initialize connection to device: %s\n", 138 138 str_error(opResult)); 139 free(hub_ info);139 free(hub_dev); 140 140 return opResult; 141 141 } … … 146 146 usb_log_error("Could not set hub configuration: %s\n", 147 147 str_error(opResult)); 148 free(hub_ info);148 free(hub_dev); 149 149 return opResult; 150 150 } 151 151 152 152 /* Get port count and create attached_devices. */ 153 opResult = usb_hub_process_hub_specific_info(hub_ info);153 opResult = usb_hub_process_hub_specific_info(hub_dev); 154 154 if (opResult != EOK) { 155 155 usb_log_error("Could process hub specific info, %s\n", 156 156 str_error(opResult)); 157 free(hub_ info);157 free(hub_dev); 158 158 return opResult; 159 159 } 160 160 161 161 usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n"); 162 hub_ info->hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,162 hub_dev->hub_fun = ddf_fun_create(hub_dev->usb_device->ddf_dev, 163 163 fun_exposed, HUB_FNC_NAME); 164 if (hub_ info->hub_fun == NULL) {164 if (hub_dev->hub_fun == NULL) { 165 165 usb_log_error("Failed to create hub function.\n"); 166 free(hub_ info);166 free(hub_dev); 167 167 return ENOMEM; 168 168 } 169 169 170 opResult = ddf_fun_bind(hub_ info->hub_fun);170 opResult = ddf_fun_bind(hub_dev->hub_fun); 171 171 if (opResult != EOK) { 172 172 usb_log_error("Failed to bind hub function: %s.\n", 173 173 str_error(opResult)); 174 free(hub_ info);175 ddf_fun_destroy(hub_ info->hub_fun);174 free(hub_dev); 175 ddf_fun_destroy(hub_dev->hub_fun); 176 176 return opResult; 177 177 } 178 178 179 opResult = usb_device_auto_poll(hub_ info->usb_device, 0,180 hub_port_changes_callback, ((hub_ info->port_count + 1) / 8) + 1,181 usb_hub_polling_terminated_callback, hub_ info);179 opResult = usb_device_auto_poll(hub_dev->usb_device, 0, 180 hub_port_changes_callback, ((hub_dev->port_count + 1) / 8) + 1, 181 usb_hub_polling_terminated_callback, hub_dev); 182 182 if (opResult != EOK) { 183 183 /* Function is already bound */ 184 ddf_fun_unbind(hub_ info->hub_fun);185 ddf_fun_destroy(hub_ info->hub_fun);186 free(hub_ info);184 ddf_fun_unbind(hub_dev->hub_fun); 185 ddf_fun_destroy(hub_dev->hub_fun); 186 free(hub_dev); 187 187 usb_log_error("Failed to create polling fibril: %s.\n", 188 188 str_error(opResult)); 189 189 return opResult; 190 190 } 191 hub_ info->running = true;191 hub_dev->running = true; 192 192 usb_log_info("Controlling hub '%s' (%zu ports).\n", 193 hub_ info->usb_device->ddf_dev->name, hub_info->port_count);193 hub_dev->usb_device->ddf_dev->name, hub_dev->port_count); 194 194 195 195 return EOK; … … 243 243 { 244 244 assert(usb_dev); 245 usb_hub_dev_t * info= malloc(sizeof(usb_hub_dev_t));246 if (! info)245 usb_hub_dev_t *hub_dev = malloc(sizeof(usb_hub_dev_t)); 246 if (!hub_dev) 247 247 return NULL; 248 248 249 info->usb_device = usb_dev;250 251 info->ports = NULL;252 info->port_count = -1;253 info->pending_ops_count = 0;254 info->running = false;255 fibril_mutex_initialize(& info->pending_ops_mutex);256 fibril_condvar_initialize(& info->pending_ops_cv);257 usb_dev->driver_data = info;258 259 return info;260 } 261 /*----------------------------------------------------------------------------*/ 262 /** 263 * Load hub-specific information into hub_ infostructure and process if needed249 hub_dev->usb_device = usb_dev; 250 251 hub_dev->ports = NULL; 252 hub_dev->port_count = -1; 253 hub_dev->pending_ops_count = 0; 254 hub_dev->running = false; 255 fibril_mutex_initialize(&hub_dev->pending_ops_mutex); 256 fibril_condvar_initialize(&hub_dev->pending_ops_cv); 257 usb_dev->driver_data = hub_dev; 258 259 return hub_dev; 260 } 261 /*----------------------------------------------------------------------------*/ 262 /** 263 * Load hub-specific information into hub_dev structure and process if needed 264 264 * 265 265 * Read port count and initialize structures holding per port information. … … 267 267 * This function is hub-specific and should be run only after the hub is 268 268 * configured using usb_set_first_configuration function. 269 * @param hub_ infohub representation269 * @param hub_dev hub representation 270 270 * @return error code 271 271 */ 272 static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_ info)273 { 274 assert(hub_ info);272 static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_dev) 273 { 274 assert(hub_dev); 275 275 276 276 /* Get hub descriptor. */ 277 277 usb_log_debug("Retrieving descriptor\n"); 278 usb_pipe_t *control_pipe = &hub_ info->usb_device->ctrl_pipe;278 usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe; 279 279 280 280 usb_hub_descriptor_header_t descriptor; … … 291 291 292 292 usb_log_debug("Setting port count to %d.\n", descriptor.port_count); 293 hub_ info->port_count = descriptor.port_count;293 hub_dev->port_count = descriptor.port_count; 294 294 295 295 // TODO: +1 hack is no longer necessary 296 hub_ info->ports =297 calloc(hub_ info->port_count + 1, sizeof(usb_hub_port_t));298 if (!hub_ info->ports) {296 hub_dev->ports = 297 calloc(hub_dev->port_count + 1, sizeof(usb_hub_port_t)); 298 if (!hub_dev->ports) { 299 299 return ENOMEM; 300 300 } 301 301 302 for (size_t port = 1; port < hub_ info->port_count + 1; ++port) {303 usb_hub_port_init(&hub_ info->ports[port], port, control_pipe);302 for (size_t port = 1; port < hub_dev->port_count + 1; ++port) { 303 usb_hub_port_init(&hub_dev->ports[port], port, control_pipe); 304 304 } 305 305 … … 311 311 & HUB_CHAR_POWER_PER_PORT_FLAG; 312 312 313 for (size_t port = 1; port <= hub_ info->port_count; ++port) {313 for (size_t port = 1; port <= hub_dev->port_count; ++port) { 314 314 usb_log_debug("Powering port %zu.\n", port); 315 315 opResult = usb_hub_port_set_feature( 316 &hub_ info->ports[port], USB_HUB_FEATURE_PORT_POWER);316 &hub_dev->ports[port], USB_HUB_FEATURE_PORT_POWER); 317 317 if (opResult != EOK) { 318 318 usb_log_error("Cannot power on port %zu: %s.\n", … … 384 384 * 385 385 * This means either to power off the hub or power it on. 386 * @param hub_ infohub instance386 * @param hub_dev hub instance 387 387 * @param status hub status bitmask 388 388 * @return error code 389 389 */ 390 static void usb_hub_over_current(const usb_hub_dev_t *hub_ info,390 static void usb_hub_over_current(const usb_hub_dev_t *hub_dev, 391 391 usb_hub_status_t status) 392 392 { … … 399 399 * ports on. */ 400 400 size_t port; 401 for (port = 1; port <= hub_ info->port_count; ++port) {401 for (port = 1; port <= hub_dev->port_count; ++port) { 402 402 const int opResult = usb_hub_port_set_feature( 403 &hub_ info->ports[port], USB_HUB_FEATURE_PORT_POWER);403 &hub_dev->ports[port], USB_HUB_FEATURE_PORT_POWER); 404 404 if (opResult != EOK) { 405 405 usb_log_warning( … … 411 411 } 412 412 const int opResult = usb_request_clear_feature( 413 &hub_ info->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,413 &hub_dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS, 414 414 USB_REQUEST_RECIPIENT_DEVICE, 415 415 USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0); … … 425 425 * 426 426 * The change can be either in the over-current condition or local-power change. 427 * @param hub_ infohub instance428 */ 429 static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_ info)430 { 431 assert(hub_ info);432 assert(hub_ info->usb_device);427 * @param hub_dev hub instance 428 */ 429 static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_dev) 430 { 431 assert(hub_dev); 432 assert(hub_dev->usb_device); 433 433 usb_log_debug("Global interrupt on a hub\n"); 434 usb_pipe_t *control_pipe = &hub_ info->usb_device->ctrl_pipe;434 usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe; 435 435 436 436 usb_hub_status_t status; … … 453 453 /* Handle status changes */ 454 454 if (status & USB_HUB_STATUS_C_OVER_CURRENT) { 455 usb_hub_over_current(hub_ info, status);455 usb_hub_over_current(hub_dev, status); 456 456 } 457 457 … … 485 485 * callback called from hub polling fibril when the fibril terminates 486 486 * 487 * Should perform a cleanup - deletes hub_info.487 * Does not perform cleanup, just marks the hub as not running. 488 488 * @param device usb device afected 489 489 * @param was_error indicates that the fibril is stoped due to an error
Note:
See TracChangeset
for help on using the changeset viewer.