diff options
Diffstat (limited to 'drivers/usb/core/usb.c')
-rw-r--r-- | drivers/usb/core/usb.c | 544 |
1 files changed, 64 insertions, 480 deletions
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index e80ef9467825..13d1d367f7f1 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -32,7 +32,6 @@ | |||
32 | #include <linux/spinlock.h> | 32 | #include <linux/spinlock.h> |
33 | #include <linux/errno.h> | 33 | #include <linux/errno.h> |
34 | #include <linux/smp_lock.h> | 34 | #include <linux/smp_lock.h> |
35 | #include <linux/rwsem.h> | ||
36 | #include <linux/usb.h> | 35 | #include <linux/usb.h> |
37 | 36 | ||
38 | #include <asm/io.h> | 37 | #include <asm/io.h> |
@@ -47,165 +46,7 @@ | |||
47 | const char *usbcore_name = "usbcore"; | 46 | const char *usbcore_name = "usbcore"; |
48 | 47 | ||
49 | static int nousb; /* Disable USB when built into kernel image */ | 48 | static int nousb; /* Disable USB when built into kernel image */ |
50 | /* Not honored on modular build */ | ||
51 | 49 | ||
52 | static DECLARE_RWSEM(usb_all_devices_rwsem); | ||
53 | |||
54 | |||
55 | static int generic_probe (struct device *dev) | ||
56 | { | ||
57 | return 0; | ||
58 | } | ||
59 | static int generic_remove (struct device *dev) | ||
60 | { | ||
61 | struct usb_device *udev = to_usb_device(dev); | ||
62 | |||
63 | /* if this is only an unbind, not a physical disconnect, then | ||
64 | * unconfigure the device */ | ||
65 | if (udev->state == USB_STATE_CONFIGURED) | ||
66 | usb_set_configuration(udev, 0); | ||
67 | |||
68 | /* in case the call failed or the device was suspended */ | ||
69 | if (udev->state >= USB_STATE_CONFIGURED) | ||
70 | usb_disable_device(udev, 0); | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static struct device_driver usb_generic_driver = { | ||
75 | .owner = THIS_MODULE, | ||
76 | .name = "usb", | ||
77 | .bus = &usb_bus_type, | ||
78 | .probe = generic_probe, | ||
79 | .remove = generic_remove, | ||
80 | }; | ||
81 | |||
82 | static int usb_generic_driver_data; | ||
83 | |||
84 | /* called from driver core with usb_bus_type.subsys writelock */ | ||
85 | static int usb_probe_interface(struct device *dev) | ||
86 | { | ||
87 | struct usb_interface * intf = to_usb_interface(dev); | ||
88 | struct usb_driver * driver = to_usb_driver(dev->driver); | ||
89 | const struct usb_device_id *id; | ||
90 | int error = -ENODEV; | ||
91 | |||
92 | dev_dbg(dev, "%s\n", __FUNCTION__); | ||
93 | |||
94 | if (!driver->probe) | ||
95 | return error; | ||
96 | /* FIXME we'd much prefer to just resume it ... */ | ||
97 | if (interface_to_usbdev(intf)->state == USB_STATE_SUSPENDED) | ||
98 | return -EHOSTUNREACH; | ||
99 | |||
100 | id = usb_match_id (intf, driver->id_table); | ||
101 | if (id) { | ||
102 | dev_dbg (dev, "%s - got id\n", __FUNCTION__); | ||
103 | |||
104 | /* Interface "power state" doesn't correspond to any hardware | ||
105 | * state whatsoever. We use it to record when it's bound to | ||
106 | * a driver that may start I/0: it's not frozen/quiesced. | ||
107 | */ | ||
108 | mark_active(intf); | ||
109 | intf->condition = USB_INTERFACE_BINDING; | ||
110 | error = driver->probe (intf, id); | ||
111 | if (error) { | ||
112 | mark_quiesced(intf); | ||
113 | intf->condition = USB_INTERFACE_UNBOUND; | ||
114 | } else | ||
115 | intf->condition = USB_INTERFACE_BOUND; | ||
116 | } | ||
117 | |||
118 | return error; | ||
119 | } | ||
120 | |||
121 | /* called from driver core with usb_bus_type.subsys writelock */ | ||
122 | static int usb_unbind_interface(struct device *dev) | ||
123 | { | ||
124 | struct usb_interface *intf = to_usb_interface(dev); | ||
125 | struct usb_driver *driver = to_usb_driver(intf->dev.driver); | ||
126 | |||
127 | intf->condition = USB_INTERFACE_UNBINDING; | ||
128 | |||
129 | /* release all urbs for this interface */ | ||
130 | usb_disable_interface(interface_to_usbdev(intf), intf); | ||
131 | |||
132 | if (driver && driver->disconnect) | ||
133 | driver->disconnect(intf); | ||
134 | |||
135 | /* reset other interface state */ | ||
136 | usb_set_interface(interface_to_usbdev(intf), | ||
137 | intf->altsetting[0].desc.bInterfaceNumber, | ||
138 | 0); | ||
139 | usb_set_intfdata(intf, NULL); | ||
140 | intf->condition = USB_INTERFACE_UNBOUND; | ||
141 | mark_quiesced(intf); | ||
142 | |||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * usb_register - register a USB driver | ||
148 | * @new_driver: USB operations for the driver | ||
149 | * | ||
150 | * Registers a USB driver with the USB core. The list of unattached | ||
151 | * interfaces will be rescanned whenever a new driver is added, allowing | ||
152 | * the new driver to attach to any recognized devices. | ||
153 | * Returns a negative error code on failure and 0 on success. | ||
154 | * | ||
155 | * NOTE: if you want your driver to use the USB major number, you must call | ||
156 | * usb_register_dev() to enable that functionality. This function no longer | ||
157 | * takes care of that. | ||
158 | */ | ||
159 | int usb_register(struct usb_driver *new_driver) | ||
160 | { | ||
161 | int retval = 0; | ||
162 | |||
163 | if (nousb) | ||
164 | return -ENODEV; | ||
165 | |||
166 | new_driver->driver.name = (char *)new_driver->name; | ||
167 | new_driver->driver.bus = &usb_bus_type; | ||
168 | new_driver->driver.probe = usb_probe_interface; | ||
169 | new_driver->driver.remove = usb_unbind_interface; | ||
170 | new_driver->driver.owner = new_driver->owner; | ||
171 | |||
172 | usb_lock_all_devices(); | ||
173 | retval = driver_register(&new_driver->driver); | ||
174 | usb_unlock_all_devices(); | ||
175 | |||
176 | if (!retval) { | ||
177 | pr_info("%s: registered new driver %s\n", | ||
178 | usbcore_name, new_driver->name); | ||
179 | usbfs_update_special(); | ||
180 | } else { | ||
181 | printk(KERN_ERR "%s: error %d registering driver %s\n", | ||
182 | usbcore_name, retval, new_driver->name); | ||
183 | } | ||
184 | |||
185 | return retval; | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * usb_deregister - unregister a USB driver | ||
190 | * @driver: USB operations of the driver to unregister | ||
191 | * Context: must be able to sleep | ||
192 | * | ||
193 | * Unlinks the specified driver from the internal USB driver list. | ||
194 | * | ||
195 | * NOTE: If you called usb_register_dev(), you still need to call | ||
196 | * usb_deregister_dev() to clean up your driver's allocated minor numbers, | ||
197 | * this * call will no longer do it for you. | ||
198 | */ | ||
199 | void usb_deregister(struct usb_driver *driver) | ||
200 | { | ||
201 | pr_info("%s: deregistering driver %s\n", usbcore_name, driver->name); | ||
202 | |||
203 | usb_lock_all_devices(); | ||
204 | driver_unregister (&driver->driver); | ||
205 | usb_unlock_all_devices(); | ||
206 | |||
207 | usbfs_update_special(); | ||
208 | } | ||
209 | 50 | ||
210 | /** | 51 | /** |
211 | * usb_ifnum_to_if - get the interface object with a given interface number | 52 | * usb_ifnum_to_if - get the interface object with a given interface number |
@@ -352,151 +193,23 @@ void usb_driver_release_interface(struct usb_driver *driver, | |||
352 | mark_quiesced(iface); | 193 | mark_quiesced(iface); |
353 | } | 194 | } |
354 | 195 | ||
355 | /** | 196 | struct find_interface_arg { |
356 | * usb_match_id - find first usb_device_id matching device or interface | 197 | int minor; |
357 | * @interface: the interface of interest | 198 | struct usb_interface *interface; |
358 | * @id: array of usb_device_id structures, terminated by zero entry | 199 | }; |
359 | * | ||
360 | * usb_match_id searches an array of usb_device_id's and returns | ||
361 | * the first one matching the device or interface, or null. | ||
362 | * This is used when binding (or rebinding) a driver to an interface. | ||
363 | * Most USB device drivers will use this indirectly, through the usb core, | ||
364 | * but some layered driver frameworks use it directly. | ||
365 | * These device tables are exported with MODULE_DEVICE_TABLE, through | ||
366 | * modutils and "modules.usbmap", to support the driver loading | ||
367 | * functionality of USB hotplugging. | ||
368 | * | ||
369 | * What Matches: | ||
370 | * | ||
371 | * The "match_flags" element in a usb_device_id controls which | ||
372 | * members are used. If the corresponding bit is set, the | ||
373 | * value in the device_id must match its corresponding member | ||
374 | * in the device or interface descriptor, or else the device_id | ||
375 | * does not match. | ||
376 | * | ||
377 | * "driver_info" is normally used only by device drivers, | ||
378 | * but you can create a wildcard "matches anything" usb_device_id | ||
379 | * as a driver's "modules.usbmap" entry if you provide an id with | ||
380 | * only a nonzero "driver_info" field. If you do this, the USB device | ||
381 | * driver's probe() routine should use additional intelligence to | ||
382 | * decide whether to bind to the specified interface. | ||
383 | * | ||
384 | * What Makes Good usb_device_id Tables: | ||
385 | * | ||
386 | * The match algorithm is very simple, so that intelligence in | ||
387 | * driver selection must come from smart driver id records. | ||
388 | * Unless you have good reasons to use another selection policy, | ||
389 | * provide match elements only in related groups, and order match | ||
390 | * specifiers from specific to general. Use the macros provided | ||
391 | * for that purpose if you can. | ||
392 | * | ||
393 | * The most specific match specifiers use device descriptor | ||
394 | * data. These are commonly used with product-specific matches; | ||
395 | * the USB_DEVICE macro lets you provide vendor and product IDs, | ||
396 | * and you can also match against ranges of product revisions. | ||
397 | * These are widely used for devices with application or vendor | ||
398 | * specific bDeviceClass values. | ||
399 | * | ||
400 | * Matches based on device class/subclass/protocol specifications | ||
401 | * are slightly more general; use the USB_DEVICE_INFO macro, or | ||
402 | * its siblings. These are used with single-function devices | ||
403 | * where bDeviceClass doesn't specify that each interface has | ||
404 | * its own class. | ||
405 | * | ||
406 | * Matches based on interface class/subclass/protocol are the | ||
407 | * most general; they let drivers bind to any interface on a | ||
408 | * multiple-function device. Use the USB_INTERFACE_INFO | ||
409 | * macro, or its siblings, to match class-per-interface style | ||
410 | * devices (as recorded in bDeviceClass). | ||
411 | * | ||
412 | * Within those groups, remember that not all combinations are | ||
413 | * meaningful. For example, don't give a product version range | ||
414 | * without vendor and product IDs; or specify a protocol without | ||
415 | * its associated class and subclass. | ||
416 | */ | ||
417 | const struct usb_device_id * | ||
418 | usb_match_id(struct usb_interface *interface, const struct usb_device_id *id) | ||
419 | { | ||
420 | struct usb_host_interface *intf; | ||
421 | struct usb_device *dev; | ||
422 | |||
423 | /* proc_connectinfo in devio.c may call us with id == NULL. */ | ||
424 | if (id == NULL) | ||
425 | return NULL; | ||
426 | |||
427 | intf = interface->cur_altsetting; | ||
428 | dev = interface_to_usbdev(interface); | ||
429 | |||
430 | /* It is important to check that id->driver_info is nonzero, | ||
431 | since an entry that is all zeroes except for a nonzero | ||
432 | id->driver_info is the way to create an entry that | ||
433 | indicates that the driver want to examine every | ||
434 | device and interface. */ | ||
435 | for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass || | ||
436 | id->driver_info; id++) { | ||
437 | |||
438 | if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && | ||
439 | id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) | ||
440 | continue; | ||
441 | |||
442 | if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) && | ||
443 | id->idProduct != le16_to_cpu(dev->descriptor.idProduct)) | ||
444 | continue; | ||
445 | |||
446 | /* No need to test id->bcdDevice_lo != 0, since 0 is never | ||
447 | greater than any unsigned number. */ | ||
448 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) && | ||
449 | (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice))) | ||
450 | continue; | ||
451 | |||
452 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) && | ||
453 | (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice))) | ||
454 | continue; | ||
455 | |||
456 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) && | ||
457 | (id->bDeviceClass != dev->descriptor.bDeviceClass)) | ||
458 | continue; | ||
459 | |||
460 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && | ||
461 | (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass)) | ||
462 | continue; | ||
463 | |||
464 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && | ||
465 | (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) | ||
466 | continue; | ||
467 | |||
468 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) && | ||
469 | (id->bInterfaceClass != intf->desc.bInterfaceClass)) | ||
470 | continue; | ||
471 | |||
472 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) && | ||
473 | (id->bInterfaceSubClass != intf->desc.bInterfaceSubClass)) | ||
474 | continue; | ||
475 | |||
476 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) && | ||
477 | (id->bInterfaceProtocol != intf->desc.bInterfaceProtocol)) | ||
478 | continue; | ||
479 | |||
480 | return id; | ||
481 | } | ||
482 | |||
483 | return NULL; | ||
484 | } | ||
485 | |||
486 | 200 | ||
487 | static int __find_interface(struct device * dev, void * data) | 201 | static int __find_interface(struct device * dev, void * data) |
488 | { | 202 | { |
489 | struct usb_interface ** ret = (struct usb_interface **)data; | 203 | struct find_interface_arg *arg = data; |
490 | struct usb_interface * intf = *ret; | 204 | struct usb_interface *intf; |
491 | int *minor = (int *)data; | ||
492 | 205 | ||
493 | /* can't look at usb devices, only interfaces */ | 206 | /* can't look at usb devices, only interfaces */ |
494 | if (dev->driver == &usb_generic_driver) | 207 | if (dev->driver == &usb_generic_driver) |
495 | return 0; | 208 | return 0; |
496 | 209 | ||
497 | intf = to_usb_interface(dev); | 210 | intf = to_usb_interface(dev); |
498 | if (intf->minor != -1 && intf->minor == *minor) { | 211 | if (intf->minor != -1 && intf->minor == arg->minor) { |
499 | *ret = intf; | 212 | arg->interface = intf; |
500 | return 1; | 213 | return 1; |
501 | } | 214 | } |
502 | return 0; | 215 | return 0; |
@@ -513,42 +226,18 @@ static int __find_interface(struct device * dev, void * data) | |||
513 | */ | 226 | */ |
514 | struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) | 227 | struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) |
515 | { | 228 | { |
516 | struct usb_interface *intf = (struct usb_interface *)(long)minor; | 229 | struct find_interface_arg argb; |
517 | int ret; | ||
518 | |||
519 | ret = driver_for_each_device(&drv->driver, NULL, &intf, __find_interface); | ||
520 | |||
521 | return ret ? intf : NULL; | ||
522 | } | ||
523 | |||
524 | static int usb_device_match (struct device *dev, struct device_driver *drv) | ||
525 | { | ||
526 | struct usb_interface *intf; | ||
527 | struct usb_driver *usb_drv; | ||
528 | const struct usb_device_id *id; | ||
529 | |||
530 | /* check for generic driver, which we don't match any device with */ | ||
531 | if (drv == &usb_generic_driver) | ||
532 | return 0; | ||
533 | |||
534 | intf = to_usb_interface(dev); | ||
535 | usb_drv = to_usb_driver(drv); | ||
536 | |||
537 | id = usb_match_id (intf, usb_drv->id_table); | ||
538 | if (id) | ||
539 | return 1; | ||
540 | 230 | ||
541 | return 0; | 231 | argb.minor = minor; |
232 | argb.interface = NULL; | ||
233 | driver_for_each_device(&drv->driver, NULL, &argb, __find_interface); | ||
234 | return argb.interface; | ||
542 | } | 235 | } |
543 | 236 | ||
544 | |||
545 | #ifdef CONFIG_HOTPLUG | 237 | #ifdef CONFIG_HOTPLUG |
546 | 238 | ||
547 | /* | 239 | /* |
548 | * USB hotplugging invokes what /proc/sys/kernel/hotplug says | 240 | * This sends an uevent to userspace, typically helping to load driver |
549 | * (normally /sbin/hotplug) when USB devices get added or removed. | ||
550 | * | ||
551 | * This invokes a user mode policy agent, typically helping to load driver | ||
552 | * or other modules, configure the device, and more. Drivers can provide | 241 | * or other modules, configure the device, and more. Drivers can provide |
553 | * a MODULE_DEVICE_TABLE to help with module loading subtasks. | 242 | * a MODULE_DEVICE_TABLE to help with module loading subtasks. |
554 | * | 243 | * |
@@ -557,8 +246,8 @@ static int usb_device_match (struct device *dev, struct device_driver *drv) | |||
557 | * delays in event delivery. Use sysfs (and DEVPATH) to make sure the | 246 | * delays in event delivery. Use sysfs (and DEVPATH) to make sure the |
558 | * device (and this configuration!) are still present. | 247 | * device (and this configuration!) are still present. |
559 | */ | 248 | */ |
560 | static int usb_hotplug (struct device *dev, char **envp, int num_envp, | 249 | static int usb_uevent(struct device *dev, char **envp, int num_envp, |
561 | char *buffer, int buffer_size) | 250 | char *buffer, int buffer_size) |
562 | { | 251 | { |
563 | struct usb_interface *intf; | 252 | struct usb_interface *intf; |
564 | struct usb_device *usb_dev; | 253 | struct usb_device *usb_dev; |
@@ -570,7 +259,7 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp, | |||
570 | return -ENODEV; | 259 | return -ENODEV; |
571 | 260 | ||
572 | /* driver is often null here; dev_dbg() would oops */ | 261 | /* driver is often null here; dev_dbg() would oops */ |
573 | pr_debug ("usb %s: hotplug\n", dev->bus_id); | 262 | pr_debug ("usb %s: uevent\n", dev->bus_id); |
574 | 263 | ||
575 | /* Must check driver_data here, as on remove driver is always NULL */ | 264 | /* Must check driver_data here, as on remove driver is always NULL */ |
576 | if ((dev->driver == &usb_generic_driver) || | 265 | if ((dev->driver == &usb_generic_driver) || |
@@ -597,51 +286,51 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp, | |||
597 | * | 286 | * |
598 | * FIXME reduce hardwired intelligence here | 287 | * FIXME reduce hardwired intelligence here |
599 | */ | 288 | */ |
600 | if (add_hotplug_env_var(envp, num_envp, &i, | 289 | if (add_uevent_var(envp, num_envp, &i, |
601 | buffer, buffer_size, &length, | 290 | buffer, buffer_size, &length, |
602 | "DEVICE=/proc/bus/usb/%03d/%03d", | 291 | "DEVICE=/proc/bus/usb/%03d/%03d", |
603 | usb_dev->bus->busnum, usb_dev->devnum)) | 292 | usb_dev->bus->busnum, usb_dev->devnum)) |
604 | return -ENOMEM; | 293 | return -ENOMEM; |
605 | #endif | 294 | #endif |
606 | 295 | ||
607 | /* per-device configurations are common */ | 296 | /* per-device configurations are common */ |
608 | if (add_hotplug_env_var(envp, num_envp, &i, | 297 | if (add_uevent_var(envp, num_envp, &i, |
609 | buffer, buffer_size, &length, | 298 | buffer, buffer_size, &length, |
610 | "PRODUCT=%x/%x/%x", | 299 | "PRODUCT=%x/%x/%x", |
611 | le16_to_cpu(usb_dev->descriptor.idVendor), | 300 | le16_to_cpu(usb_dev->descriptor.idVendor), |
612 | le16_to_cpu(usb_dev->descriptor.idProduct), | 301 | le16_to_cpu(usb_dev->descriptor.idProduct), |
613 | le16_to_cpu(usb_dev->descriptor.bcdDevice))) | 302 | le16_to_cpu(usb_dev->descriptor.bcdDevice))) |
614 | return -ENOMEM; | 303 | return -ENOMEM; |
615 | 304 | ||
616 | /* class-based driver binding models */ | 305 | /* class-based driver binding models */ |
617 | if (add_hotplug_env_var(envp, num_envp, &i, | 306 | if (add_uevent_var(envp, num_envp, &i, |
618 | buffer, buffer_size, &length, | 307 | buffer, buffer_size, &length, |
619 | "TYPE=%d/%d/%d", | 308 | "TYPE=%d/%d/%d", |
620 | usb_dev->descriptor.bDeviceClass, | 309 | usb_dev->descriptor.bDeviceClass, |
621 | usb_dev->descriptor.bDeviceSubClass, | 310 | usb_dev->descriptor.bDeviceSubClass, |
622 | usb_dev->descriptor.bDeviceProtocol)) | 311 | usb_dev->descriptor.bDeviceProtocol)) |
623 | return -ENOMEM; | 312 | return -ENOMEM; |
624 | 313 | ||
625 | if (add_hotplug_env_var(envp, num_envp, &i, | 314 | if (add_uevent_var(envp, num_envp, &i, |
626 | buffer, buffer_size, &length, | 315 | buffer, buffer_size, &length, |
627 | "INTERFACE=%d/%d/%d", | 316 | "INTERFACE=%d/%d/%d", |
628 | alt->desc.bInterfaceClass, | 317 | alt->desc.bInterfaceClass, |
629 | alt->desc.bInterfaceSubClass, | 318 | alt->desc.bInterfaceSubClass, |
630 | alt->desc.bInterfaceProtocol)) | 319 | alt->desc.bInterfaceProtocol)) |
631 | return -ENOMEM; | 320 | return -ENOMEM; |
632 | 321 | ||
633 | if (add_hotplug_env_var(envp, num_envp, &i, | 322 | if (add_uevent_var(envp, num_envp, &i, |
634 | buffer, buffer_size, &length, | 323 | buffer, buffer_size, &length, |
635 | "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", | 324 | "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", |
636 | le16_to_cpu(usb_dev->descriptor.idVendor), | 325 | le16_to_cpu(usb_dev->descriptor.idVendor), |
637 | le16_to_cpu(usb_dev->descriptor.idProduct), | 326 | le16_to_cpu(usb_dev->descriptor.idProduct), |
638 | le16_to_cpu(usb_dev->descriptor.bcdDevice), | 327 | le16_to_cpu(usb_dev->descriptor.bcdDevice), |
639 | usb_dev->descriptor.bDeviceClass, | 328 | usb_dev->descriptor.bDeviceClass, |
640 | usb_dev->descriptor.bDeviceSubClass, | 329 | usb_dev->descriptor.bDeviceSubClass, |
641 | usb_dev->descriptor.bDeviceProtocol, | 330 | usb_dev->descriptor.bDeviceProtocol, |
642 | alt->desc.bInterfaceClass, | 331 | alt->desc.bInterfaceClass, |
643 | alt->desc.bInterfaceSubClass, | 332 | alt->desc.bInterfaceSubClass, |
644 | alt->desc.bInterfaceProtocol)) | 333 | alt->desc.bInterfaceProtocol)) |
645 | return -ENOMEM; | 334 | return -ENOMEM; |
646 | 335 | ||
647 | envp[i] = NULL; | 336 | envp[i] = NULL; |
@@ -651,7 +340,7 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp, | |||
651 | 340 | ||
652 | #else | 341 | #else |
653 | 342 | ||
654 | static int usb_hotplug (struct device *dev, char **envp, | 343 | static int usb_uevent(struct device *dev, char **envp, |
655 | int num_envp, char *buffer, int buffer_size) | 344 | int num_envp, char *buffer, int buffer_size) |
656 | { | 345 | { |
657 | return -ENODEV; | 346 | return -ENODEV; |
@@ -750,12 +439,11 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) | |||
750 | /* hub driver sets up TT records */ | 439 | /* hub driver sets up TT records */ |
751 | } | 440 | } |
752 | 441 | ||
442 | dev->portnum = port1; | ||
753 | dev->bus = bus; | 443 | dev->bus = bus; |
754 | dev->parent = parent; | 444 | dev->parent = parent; |
755 | INIT_LIST_HEAD(&dev->filelist); | 445 | INIT_LIST_HEAD(&dev->filelist); |
756 | 446 | ||
757 | init_MUTEX(&dev->serialize); | ||
758 | |||
759 | return dev; | 447 | return dev; |
760 | } | 448 | } |
761 | 449 | ||
@@ -828,76 +516,21 @@ void usb_put_intf(struct usb_interface *intf) | |||
828 | 516 | ||
829 | /* USB device locking | 517 | /* USB device locking |
830 | * | 518 | * |
831 | * Although locking USB devices should be straightforward, it is | 519 | * USB devices and interfaces are locked using the semaphore in their |
832 | * complicated by the way the driver-model core works. When a new USB | 520 | * embedded struct device. The hub driver guarantees that whenever a |
833 | * driver is registered or unregistered, the core will automatically | 521 | * device is connected or disconnected, drivers are called with the |
834 | * probe or disconnect all matching interfaces on all USB devices while | 522 | * USB device locked as well as their particular interface. |
835 | * holding the USB subsystem writelock. There's no good way for us to | ||
836 | * tell which devices will be used or to lock them beforehand; our only | ||
837 | * option is to effectively lock all the USB devices. | ||
838 | * | ||
839 | * We do that by using a private rw-semaphore, usb_all_devices_rwsem. | ||
840 | * When locking an individual device you must first acquire the rwsem's | ||
841 | * readlock. When a driver is registered or unregistered the writelock | ||
842 | * must be held. These actions are encapsulated in the subroutines | ||
843 | * below, so all a driver needs to do is call usb_lock_device() and | ||
844 | * usb_unlock_device(). | ||
845 | * | 523 | * |
846 | * Complications arise when several devices are to be locked at the same | 524 | * Complications arise when several devices are to be locked at the same |
847 | * time. Only hub-aware drivers that are part of usbcore ever have to | 525 | * time. Only hub-aware drivers that are part of usbcore ever have to |
848 | * do this; nobody else needs to worry about it. The problem is that | 526 | * do this; nobody else needs to worry about it. The rule for locking |
849 | * usb_lock_device() must not be called to lock a second device since it | 527 | * is simple: |
850 | * would acquire the rwsem's readlock reentrantly, leading to deadlock if | ||
851 | * another thread was waiting for the writelock. The solution is simple: | ||
852 | * | ||
853 | * When locking more than one device, call usb_lock_device() | ||
854 | * to lock the first one. Lock the others by calling | ||
855 | * down(&udev->serialize) directly. | ||
856 | * | ||
857 | * When unlocking multiple devices, use up(&udev->serialize) | ||
858 | * to unlock all but the last one. Unlock the last one by | ||
859 | * calling usb_unlock_device(). | ||
860 | * | 528 | * |
861 | * When locking both a device and its parent, always lock the | 529 | * When locking both a device and its parent, always lock the |
862 | * the parent first. | 530 | * the parent first. |
863 | */ | 531 | */ |
864 | 532 | ||
865 | /** | 533 | /** |
866 | * usb_lock_device - acquire the lock for a usb device structure | ||
867 | * @udev: device that's being locked | ||
868 | * | ||
869 | * Use this routine when you don't hold any other device locks; | ||
870 | * to acquire nested inner locks call down(&udev->serialize) directly. | ||
871 | * This is necessary for proper interaction with usb_lock_all_devices(). | ||
872 | */ | ||
873 | void usb_lock_device(struct usb_device *udev) | ||
874 | { | ||
875 | down_read(&usb_all_devices_rwsem); | ||
876 | down(&udev->serialize); | ||
877 | } | ||
878 | |||
879 | /** | ||
880 | * usb_trylock_device - attempt to acquire the lock for a usb device structure | ||
881 | * @udev: device that's being locked | ||
882 | * | ||
883 | * Don't use this routine if you already hold a device lock; | ||
884 | * use down_trylock(&udev->serialize) instead. | ||
885 | * This is necessary for proper interaction with usb_lock_all_devices(). | ||
886 | * | ||
887 | * Returns 1 if successful, 0 if contention. | ||
888 | */ | ||
889 | int usb_trylock_device(struct usb_device *udev) | ||
890 | { | ||
891 | if (!down_read_trylock(&usb_all_devices_rwsem)) | ||
892 | return 0; | ||
893 | if (down_trylock(&udev->serialize)) { | ||
894 | up_read(&usb_all_devices_rwsem); | ||
895 | return 0; | ||
896 | } | ||
897 | return 1; | ||
898 | } | ||
899 | |||
900 | /** | ||
901 | * usb_lock_device_for_reset - cautiously acquire the lock for a | 534 | * usb_lock_device_for_reset - cautiously acquire the lock for a |
902 | * usb device structure | 535 | * usb device structure |
903 | * @udev: device that's being locked | 536 | * @udev: device that's being locked |
@@ -935,7 +568,7 @@ int usb_lock_device_for_reset(struct usb_device *udev, | |||
935 | } | 568 | } |
936 | } | 569 | } |
937 | 570 | ||
938 | while (!usb_trylock_device(udev)) { | 571 | while (usb_trylock_device(udev) != 0) { |
939 | 572 | ||
940 | /* If we can't acquire the lock after waiting one second, | 573 | /* If we can't acquire the lock after waiting one second, |
941 | * we're probably deadlocked */ | 574 | * we're probably deadlocked */ |
@@ -953,39 +586,6 @@ int usb_lock_device_for_reset(struct usb_device *udev, | |||
953 | return 1; | 586 | return 1; |
954 | } | 587 | } |
955 | 588 | ||
956 | /** | ||
957 | * usb_unlock_device - release the lock for a usb device structure | ||
958 | * @udev: device that's being unlocked | ||
959 | * | ||
960 | * Use this routine when releasing the only device lock you hold; | ||
961 | * to release inner nested locks call up(&udev->serialize) directly. | ||
962 | * This is necessary for proper interaction with usb_lock_all_devices(). | ||
963 | */ | ||
964 | void usb_unlock_device(struct usb_device *udev) | ||
965 | { | ||
966 | up(&udev->serialize); | ||
967 | up_read(&usb_all_devices_rwsem); | ||
968 | } | ||
969 | |||
970 | /** | ||
971 | * usb_lock_all_devices - acquire the lock for all usb device structures | ||
972 | * | ||
973 | * This is necessary when registering a new driver or probing a bus, | ||
974 | * since the driver-model core may try to use any usb_device. | ||
975 | */ | ||
976 | void usb_lock_all_devices(void) | ||
977 | { | ||
978 | down_write(&usb_all_devices_rwsem); | ||
979 | } | ||
980 | |||
981 | /** | ||
982 | * usb_unlock_all_devices - release the lock for all usb device structures | ||
983 | */ | ||
984 | void usb_unlock_all_devices(void) | ||
985 | { | ||
986 | up_write(&usb_all_devices_rwsem); | ||
987 | } | ||
988 | |||
989 | 589 | ||
990 | static struct usb_device *match_device(struct usb_device *dev, | 590 | static struct usb_device *match_device(struct usb_device *dev, |
991 | u16 vendor_id, u16 product_id) | 591 | u16 vendor_id, u16 product_id) |
@@ -1008,10 +608,10 @@ static struct usb_device *match_device(struct usb_device *dev, | |||
1008 | /* look through all of the children of this device */ | 608 | /* look through all of the children of this device */ |
1009 | for (child = 0; child < dev->maxchild; ++child) { | 609 | for (child = 0; child < dev->maxchild; ++child) { |
1010 | if (dev->children[child]) { | 610 | if (dev->children[child]) { |
1011 | down(&dev->children[child]->serialize); | 611 | usb_lock_device(dev->children[child]); |
1012 | ret_dev = match_device(dev->children[child], | 612 | ret_dev = match_device(dev->children[child], |
1013 | vendor_id, product_id); | 613 | vendor_id, product_id); |
1014 | up(&dev->children[child]->serialize); | 614 | usb_unlock_device(dev->children[child]); |
1015 | if (ret_dev) | 615 | if (ret_dev) |
1016 | goto exit; | 616 | goto exit; |
1017 | } | 617 | } |
@@ -1491,23 +1091,13 @@ static int usb_generic_resume(struct device *dev) | |||
1491 | struct bus_type usb_bus_type = { | 1091 | struct bus_type usb_bus_type = { |
1492 | .name = "usb", | 1092 | .name = "usb", |
1493 | .match = usb_device_match, | 1093 | .match = usb_device_match, |
1494 | .hotplug = usb_hotplug, | 1094 | .uevent = usb_uevent, |
1495 | .suspend = usb_generic_suspend, | 1095 | .suspend = usb_generic_suspend, |
1496 | .resume = usb_generic_resume, | 1096 | .resume = usb_generic_resume, |
1497 | }; | 1097 | }; |
1498 | 1098 | ||
1499 | #ifndef MODULE | ||
1500 | |||
1501 | static int __init usb_setup_disable(char *str) | ||
1502 | { | ||
1503 | nousb = 1; | ||
1504 | return 1; | ||
1505 | } | ||
1506 | |||
1507 | /* format to disable USB on kernel command line is: nousb */ | 1099 | /* format to disable USB on kernel command line is: nousb */ |
1508 | __setup("nousb", usb_setup_disable); | 1100 | __module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444); |
1509 | |||
1510 | #endif | ||
1511 | 1101 | ||
1512 | /* | 1102 | /* |
1513 | * for external read access to <nousb> | 1103 | * for external read access to <nousb> |
@@ -1598,8 +1188,6 @@ module_exit(usb_exit); | |||
1598 | * driver modules to use. | 1188 | * driver modules to use. |
1599 | */ | 1189 | */ |
1600 | 1190 | ||
1601 | EXPORT_SYMBOL(usb_register); | ||
1602 | EXPORT_SYMBOL(usb_deregister); | ||
1603 | EXPORT_SYMBOL(usb_disabled); | 1191 | EXPORT_SYMBOL(usb_disabled); |
1604 | 1192 | ||
1605 | EXPORT_SYMBOL_GPL(usb_get_intf); | 1193 | EXPORT_SYMBOL_GPL(usb_get_intf); |
@@ -1610,14 +1198,10 @@ EXPORT_SYMBOL(usb_put_dev); | |||
1610 | EXPORT_SYMBOL(usb_get_dev); | 1198 | EXPORT_SYMBOL(usb_get_dev); |
1611 | EXPORT_SYMBOL(usb_hub_tt_clear_buffer); | 1199 | EXPORT_SYMBOL(usb_hub_tt_clear_buffer); |
1612 | 1200 | ||
1613 | EXPORT_SYMBOL(usb_lock_device); | ||
1614 | EXPORT_SYMBOL(usb_trylock_device); | ||
1615 | EXPORT_SYMBOL(usb_lock_device_for_reset); | 1201 | EXPORT_SYMBOL(usb_lock_device_for_reset); |
1616 | EXPORT_SYMBOL(usb_unlock_device); | ||
1617 | 1202 | ||
1618 | EXPORT_SYMBOL(usb_driver_claim_interface); | 1203 | EXPORT_SYMBOL(usb_driver_claim_interface); |
1619 | EXPORT_SYMBOL(usb_driver_release_interface); | 1204 | EXPORT_SYMBOL(usb_driver_release_interface); |
1620 | EXPORT_SYMBOL(usb_match_id); | ||
1621 | EXPORT_SYMBOL(usb_find_interface); | 1205 | EXPORT_SYMBOL(usb_find_interface); |
1622 | EXPORT_SYMBOL(usb_ifnum_to_if); | 1206 | EXPORT_SYMBOL(usb_ifnum_to_if); |
1623 | EXPORT_SYMBOL(usb_altnum_to_altsetting); | 1207 | EXPORT_SYMBOL(usb_altnum_to_altsetting); |