Changeset c952abc4 in mainline
- Timestamp:
- 2018-01-16T12:25:34Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7d1dd2b
- Parents:
- c4e84ed6
- git-author:
- Ondřej Hlavatý <aearsis@…> (2018-01-16 12:25:23)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2018-01-16 12:25:34)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/ddf_helpers.c
rc4e84ed6 rc952abc4 54 54 #include "ddf_helpers.h" 55 55 56 57 static int hcd_ddf_new_device(hc_device_t *hcd, ddf_dev_t *hc, device_t *hub_dev, unsigned port);58 static int hcd_ddf_remove_device(ddf_dev_t *device, device_t *hub, unsigned port);59 60 61 56 /** 62 57 * DDF usbhc_iface callback. Passes the endpoint descriptors, fills the pipe … … 173 168 assert(hub); 174 169 170 int err; 171 175 172 usb_log_debug("Hub %d reported a new USB device on port: %u", 176 173 hub->address, port); 177 return hcd_ddf_new_device(hcd, hc, hub, port); 174 175 device_t *dev = hcd_ddf_fun_create(hcd); 176 if (!dev) { 177 usb_log_error("Failed to create USB device function."); 178 return ENOMEM; 179 } 180 181 dev->hub = hub; 182 dev->port = port; 183 184 if ((err = bus_device_enumerate(dev))) { 185 usb_log_error("Failed to initialize USB dev memory structures."); 186 goto err_usb_dev; 187 } 188 189 /* If the driver didn't name the dev when enumerating, 190 * do it in some generic way. 191 */ 192 if (!ddf_fun_get_name(dev->fun)) { 193 bus_device_set_default_name(dev); 194 } 195 196 if ((err = ddf_fun_bind(dev->fun))) { 197 usb_log_error("Device(%d): Failed to register: %s.", dev->address, str_error(err)); 198 goto err_usb_dev; 199 } 200 201 return EOK; 202 203 err_usb_dev: 204 hcd_ddf_fun_destroy(dev); 205 return err; 178 206 } 179 207 … … 181 209 { 182 210 assert(fun); 183 ddf_dev_t *ddf_dev = ddf_fun_get_dev(fun); 184 device_t *dev = ddf_fun_data_get(fun); 185 assert(ddf_dev); 186 assert(dev); 211 device_t *hub = ddf_fun_data_get(fun); 212 assert(hub); 187 213 usb_log_debug("Hub `%s' reported removal of device on port %u", 188 214 ddf_fun_get_name(fun), port); 189 return hcd_ddf_remove_device(ddf_dev, dev, port); 215 216 device_t *victim = NULL; 217 218 fibril_mutex_lock(&hub->guard); 219 list_foreach(hub->devices, link, device_t, it) { 220 if (it->port == port) { 221 victim = it; 222 break; 223 } 224 } 225 fibril_mutex_unlock(&hub->guard); 226 227 if (!victim) { 228 usb_log_warning("Hub '%s' tried to remove non-existant" 229 " device.", ddf_fun_get_name(fun)); 230 return ENOENT; 231 } 232 233 assert(victim->fun); 234 assert(victim->port == port); 235 assert(victim->hub == hub); 236 237 bus_device_gone(victim); 238 return EOK; 190 239 } 191 240 … … 331 380 } 332 381 333 static int hcd_ddf_remove_device(ddf_dev_t *device, device_t *hub,334 unsigned port)335 {336 assert(device);337 338 device_t *victim = NULL;339 340 fibril_mutex_lock(&hub->guard);341 list_foreach(hub->devices, link, device_t, it) {342 if (it->port == port) {343 victim = it;344 break;345 }346 }347 fibril_mutex_unlock(&hub->guard);348 349 if (!victim)350 return ENOENT;351 352 assert(victim->fun);353 assert(victim->port == port);354 assert(victim->hub == hub);355 356 bus_device_gone(victim);357 return EOK;358 }359 360 382 device_t *hcd_ddf_fun_create(hc_device_t *hc) 361 383 { … … 431 453 } 432 454 433 static int hcd_ddf_new_device(hc_device_t *hcd, ddf_dev_t *hc, device_t *hub, unsigned port)434 {435 int err;436 assert(hcd);437 assert(hcd->bus);438 assert(hub);439 assert(hc);440 441 device_t *dev = hcd_ddf_fun_create(hcd);442 if (!dev) {443 usb_log_error("Failed to create USB device function.");444 return ENOMEM;445 }446 447 dev->hub = hub;448 dev->port = port;449 450 if ((err = bus_device_enumerate(dev))) {451 usb_log_error("Failed to initialize USB dev memory structures.");452 return err;453 }454 455 /* If the driver didn't name the dev when enumerating,456 * do it in some generic way.457 */458 if (!ddf_fun_get_name(dev->fun)) {459 bus_device_set_default_name(dev);460 }461 462 if ((err = ddf_fun_bind(dev->fun))) {463 usb_log_error("Device(%d): Failed to register: %s.", dev->address, str_error(err));464 goto err_usb_dev;465 }466 467 return EOK;468 469 err_usb_dev:470 hcd_ddf_fun_destroy(dev);471 return err;472 }473 474 455 /** Announce root hub to the DDF 475 456 *
Note:
See TracChangeset
for help on using the changeset viewer.