vserver 1.9.3
[linux-2.6.git] / drivers / usb / core / usb.c
1 /*
2  * drivers/usb/usb.c
3  *
4  * (C) Copyright Linus Torvalds 1999
5  * (C) Copyright Johannes Erdfelt 1999-2001
6  * (C) Copyright Andreas Gal 1999
7  * (C) Copyright Gregory P. Smith 1999
8  * (C) Copyright Deti Fliegl 1999 (new USB architecture)
9  * (C) Copyright Randy Dunlap 2000
10  * (C) Copyright David Brownell 2000-2004
11  * (C) Copyright Yggdrasil Computing, Inc. 2000
12  *     (usb_device_id matching changes by Adam J. Richter)
13  * (C) Copyright Greg Kroah-Hartman 2002-2003
14  *
15  * NOTE! This is not actually a driver at all, rather this is
16  * just a collection of helper routines that implement the
17  * generic USB things that the real drivers can use..
18  *
19  * Think of this as a "USB library" rather than anything else.
20  * It should be considered a slave, with no callbacks. Callbacks
21  * are evil.
22  */
23
24 #include <linux/config.h>
25
26 #ifdef CONFIG_USB_DEBUG
27         #define DEBUG
28 #else
29         #undef DEBUG
30 #endif
31
32 #include <linux/module.h>
33 #include <linux/string.h>
34 #include <linux/bitops.h>
35 #include <linux/slab.h>
36 #include <linux/interrupt.h>  /* for in_interrupt() */
37 #include <linux/kmod.h>
38 #include <linux/init.h>
39 #include <linux/spinlock.h>
40 #include <linux/errno.h>
41 #include <linux/smp_lock.h>
42 #include <linux/usb.h>
43
44 #include <asm/io.h>
45 #include <asm/scatterlist.h>
46 #include <linux/mm.h>
47 #include <linux/dma-mapping.h>
48
49 #include "hcd.h"
50 #include "usb.h"
51
52 extern int  usb_hub_init(void);
53 extern void usb_hub_cleanup(void);
54 extern int usb_major_init(void);
55 extern void usb_major_cleanup(void);
56 extern int usb_host_init(void);
57 extern void usb_host_cleanup(void);
58
59
60 const char *usbcore_name = "usbcore";
61
62 int nousb;              /* Disable USB when built into kernel image */
63                         /* Not honored on modular build */
64
65
66 static int generic_probe (struct device *dev)
67 {
68         return 0;
69 }
70 static int generic_remove (struct device *dev)
71 {
72         return 0;
73 }
74
75 static struct device_driver usb_generic_driver = {
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 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         if (interface_to_usbdev(intf)->state == USB_STATE_SUSPENDED)
97                 return -EHOSTUNREACH;
98
99         id = usb_match_id (intf, driver->id_table);
100         if (id) {
101                 dev_dbg (dev, "%s - got id\n", __FUNCTION__);
102                 error = driver->probe (intf, id);
103         }
104
105         return error;
106 }
107
108 /* called from driver core with usb_bus_type.subsys writelock */
109 int usb_unbind_interface(struct device *dev)
110 {
111         struct usb_interface *intf = to_usb_interface(dev);
112         struct usb_driver *driver = to_usb_driver(intf->dev.driver);
113
114         /* release all urbs for this interface */
115         usb_disable_interface(interface_to_usbdev(intf), intf);
116
117         if (driver && driver->disconnect)
118                 driver->disconnect(intf);
119
120         /* reset other interface state */
121         usb_set_interface(interface_to_usbdev(intf),
122                         intf->altsetting[0].desc.bInterfaceNumber,
123                         0);
124         usb_set_intfdata(intf, NULL);
125
126         return 0;
127 }
128
129 /**
130  * usb_register - register a USB driver
131  * @new_driver: USB operations for the driver
132  *
133  * Registers a USB driver with the USB core.  The list of unattached
134  * interfaces will be rescanned whenever a new driver is added, allowing
135  * the new driver to attach to any recognized devices.
136  * Returns a negative error code on failure and 0 on success.
137  * 
138  * NOTE: if you want your driver to use the USB major number, you must call
139  * usb_register_dev() to enable that functionality.  This function no longer
140  * takes care of that.
141  */
142 int usb_register(struct usb_driver *new_driver)
143 {
144         int retval = 0;
145
146         if (nousb)
147                 return -ENODEV;
148
149         new_driver->driver.name = (char *)new_driver->name;
150         new_driver->driver.bus = &usb_bus_type;
151         new_driver->driver.probe = usb_probe_interface;
152         new_driver->driver.remove = usb_unbind_interface;
153
154         retval = driver_register(&new_driver->driver);
155
156         if (!retval) {
157                 pr_info("%s: registered new driver %s\n",
158                         usbcore_name, new_driver->name);
159                 usbfs_update_special();
160         } else {
161                 printk(KERN_ERR "%s: error %d registering driver %s\n",
162                         usbcore_name, retval, new_driver->name);
163         }
164
165         return retval;
166 }
167
168 /**
169  * usb_deregister - unregister a USB driver
170  * @driver: USB operations of the driver to unregister
171  * Context: must be able to sleep
172  *
173  * Unlinks the specified driver from the internal USB driver list.
174  * 
175  * NOTE: If you called usb_register_dev(), you still need to call
176  * usb_deregister_dev() to clean up your driver's allocated minor numbers,
177  * this * call will no longer do it for you.
178  */
179 void usb_deregister(struct usb_driver *driver)
180 {
181         pr_info("%s: deregistering driver %s\n", usbcore_name, driver->name);
182
183         driver_unregister (&driver->driver);
184
185         usbfs_update_special();
186 }
187
188 /**
189  * usb_ifnum_to_if - get the interface object with a given interface number
190  * @dev: the device whose current configuration is considered
191  * @ifnum: the desired interface
192  *
193  * This walks the device descriptor for the currently active configuration
194  * and returns a pointer to the interface with that particular interface
195  * number, or null.
196  *
197  * Note that configuration descriptors are not required to assign interface
198  * numbers sequentially, so that it would be incorrect to assume that
199  * the first interface in that descriptor corresponds to interface zero.
200  * This routine helps device drivers avoid such mistakes.
201  * However, you should make sure that you do the right thing with any
202  * alternate settings available for this interfaces.
203  *
204  * Don't call this function unless you are bound to one of the interfaces
205  * on this device or you own the dev->serialize semaphore!
206  */
207 struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
208 {
209         struct usb_host_config *config = dev->actconfig;
210         int i;
211
212         if (!config)
213                 return NULL;
214         for (i = 0; i < config->desc.bNumInterfaces; i++)
215                 if (config->interface[i]->altsetting[0]
216                                 .desc.bInterfaceNumber == ifnum)
217                         return config->interface[i];
218
219         return NULL;
220 }
221
222 /**
223  * usb_altnum_to_altsetting - get the altsetting structure with a given
224  *      alternate setting number.
225  * @intf: the interface containing the altsetting in question
226  * @altnum: the desired alternate setting number
227  *
228  * This searches the altsetting array of the specified interface for
229  * an entry with the correct bAlternateSetting value and returns a pointer
230  * to that entry, or null.
231  *
232  * Note that altsettings need not be stored sequentially by number, so
233  * it would be incorrect to assume that the first altsetting entry in
234  * the array corresponds to altsetting zero.  This routine helps device
235  * drivers avoid such mistakes.
236  *
237  * Don't call this function unless you are bound to the intf interface
238  * or you own the device's ->serialize semaphore!
239  */
240 struct usb_host_interface *usb_altnum_to_altsetting(struct usb_interface *intf,
241                 unsigned int altnum)
242 {
243         int i;
244
245         for (i = 0; i < intf->num_altsetting; i++) {
246                 if (intf->altsetting[i].desc.bAlternateSetting == altnum)
247                         return &intf->altsetting[i];
248         }
249         return NULL;
250 }
251
252 /**
253  * usb_epnum_to_ep_desc - get the endpoint object with a given endpoint number
254  * @dev: the device whose current configuration+altsettings is considered
255  * @epnum: the desired endpoint, masked with USB_DIR_IN as appropriate.
256  *
257  * This walks the device descriptor for the currently active configuration,
258  * and returns a pointer to the endpoint with that particular endpoint
259  * number, or null.
260  *
261  * Note that interface descriptors are not required to list endpoint
262  * numbers in any standardized order, so that it would be wrong to
263  * assume that ep2in precedes either ep5in, ep2out, or even ep1out.
264  * This routine helps device drivers avoid such mistakes.
265  */
266 struct usb_endpoint_descriptor *
267 usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum)
268 {
269         struct usb_host_config *config = dev->actconfig;
270         int i, k;
271
272         if (!config)
273                 return NULL;
274         for (i = 0; i < config->desc.bNumInterfaces; i++) {
275                 struct usb_interface            *intf;
276                 struct usb_host_interface       *alt;
277
278                 /* only endpoints in current altsetting are active */
279                 intf = config->interface[i];
280                 alt = intf->cur_altsetting;
281
282                 for (k = 0; k < alt->desc.bNumEndpoints; k++)
283                         if (epnum == alt->endpoint[k].desc.bEndpointAddress)
284                                 return &alt->endpoint[k].desc;
285         }
286
287         return NULL;
288 }
289
290 /**
291  * usb_driver_claim_interface - bind a driver to an interface
292  * @driver: the driver to be bound
293  * @iface: the interface to which it will be bound; must be in the
294  *      usb device's active configuration
295  * @priv: driver data associated with that interface
296  *
297  * This is used by usb device drivers that need to claim more than one
298  * interface on a device when probing (audio and acm are current examples).
299  * No device driver should directly modify internal usb_interface or
300  * usb_device structure members.
301  *
302  * Few drivers should need to use this routine, since the most natural
303  * way to bind to an interface is to return the private data from
304  * the driver's probe() method.
305  *
306  * Callers must own the driver model's usb bus writelock.  So driver
307  * probe() entries don't need extra locking, but other call contexts
308  * may need to explicitly claim that lock.
309  */
310 int usb_driver_claim_interface(struct usb_driver *driver, struct usb_interface *iface, void* priv)
311 {
312         struct device *dev = &iface->dev;
313
314         if (dev->driver)
315                 return -EBUSY;
316
317         dev->driver = &driver->driver;
318         usb_set_intfdata(iface, priv);
319
320         /* if interface was already added, bind now; else let
321          * the future device_add() bind it, bypassing probe()
322          */
323         if (!list_empty (&dev->bus_list))
324                 device_bind_driver(dev);
325
326         return 0;
327 }
328
329 /**
330  * usb_driver_release_interface - unbind a driver from an interface
331  * @driver: the driver to be unbound
332  * @iface: the interface from which it will be unbound
333  *
334  * This can be used by drivers to release an interface without waiting
335  * for their disconnect() methods to be called.  In typical cases this
336  * also causes the driver disconnect() method to be called.
337  *
338  * This call is synchronous, and may not be used in an interrupt context.
339  * Callers must own the usb_device serialize semaphore and the driver model's
340  * usb bus writelock.  So driver disconnect() entries don't need extra locking,
341  * but other call contexts may need to explicitly claim those locks.
342  */
343 void usb_driver_release_interface(struct usb_driver *driver,
344                                         struct usb_interface *iface)
345 {
346         struct device *dev = &iface->dev;
347
348         /* this should never happen, don't release something that's not ours */
349         if (!dev->driver || dev->driver != &driver->driver)
350                 return;
351
352         /* don't disconnect from disconnect(), or before dev_add() */
353         if (!list_empty (&dev->driver_list) && !list_empty (&dev->bus_list))
354                 device_release_driver(dev);
355
356         dev->driver = NULL;
357         usb_set_intfdata(iface, NULL);
358 }
359
360 /**
361  * usb_match_id - find first usb_device_id matching device or interface
362  * @interface: the interface of interest
363  * @id: array of usb_device_id structures, terminated by zero entry
364  *
365  * usb_match_id searches an array of usb_device_id's and returns
366  * the first one matching the device or interface, or null.
367  * This is used when binding (or rebinding) a driver to an interface.
368  * Most USB device drivers will use this indirectly, through the usb core,
369  * but some layered driver frameworks use it directly.
370  * These device tables are exported with MODULE_DEVICE_TABLE, through
371  * modutils and "modules.usbmap", to support the driver loading
372  * functionality of USB hotplugging.
373  *
374  * What Matches:
375  *
376  * The "match_flags" element in a usb_device_id controls which
377  * members are used.  If the corresponding bit is set, the
378  * value in the device_id must match its corresponding member
379  * in the device or interface descriptor, or else the device_id
380  * does not match.
381  *
382  * "driver_info" is normally used only by device drivers,
383  * but you can create a wildcard "matches anything" usb_device_id
384  * as a driver's "modules.usbmap" entry if you provide an id with
385  * only a nonzero "driver_info" field.  If you do this, the USB device
386  * driver's probe() routine should use additional intelligence to
387  * decide whether to bind to the specified interface.
388  * 
389  * What Makes Good usb_device_id Tables:
390  *
391  * The match algorithm is very simple, so that intelligence in
392  * driver selection must come from smart driver id records.
393  * Unless you have good reasons to use another selection policy,
394  * provide match elements only in related groups, and order match
395  * specifiers from specific to general.  Use the macros provided
396  * for that purpose if you can.
397  *
398  * The most specific match specifiers use device descriptor
399  * data.  These are commonly used with product-specific matches;
400  * the USB_DEVICE macro lets you provide vendor and product IDs,
401  * and you can also match against ranges of product revisions.
402  * These are widely used for devices with application or vendor
403  * specific bDeviceClass values.
404  *
405  * Matches based on device class/subclass/protocol specifications
406  * are slightly more general; use the USB_DEVICE_INFO macro, or
407  * its siblings.  These are used with single-function devices
408  * where bDeviceClass doesn't specify that each interface has
409  * its own class. 
410  *
411  * Matches based on interface class/subclass/protocol are the
412  * most general; they let drivers bind to any interface on a
413  * multiple-function device.  Use the USB_INTERFACE_INFO
414  * macro, or its siblings, to match class-per-interface style 
415  * devices (as recorded in bDeviceClass).
416  *  
417  * Within those groups, remember that not all combinations are
418  * meaningful.  For example, don't give a product version range
419  * without vendor and product IDs; or specify a protocol without
420  * its associated class and subclass.
421  */   
422 const struct usb_device_id *
423 usb_match_id(struct usb_interface *interface, const struct usb_device_id *id)
424 {
425         struct usb_host_interface *intf;
426         struct usb_device *dev;
427
428         /* proc_connectinfo in devio.c may call us with id == NULL. */
429         if (id == NULL)
430                 return NULL;
431
432         intf = interface->cur_altsetting;
433         dev = interface_to_usbdev(interface);
434
435         /* It is important to check that id->driver_info is nonzero,
436            since an entry that is all zeroes except for a nonzero
437            id->driver_info is the way to create an entry that
438            indicates that the driver want to examine every
439            device and interface. */
440         for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass ||
441                id->driver_info; id++) {
442
443                 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
444                     id->idVendor != dev->descriptor.idVendor)
445                         continue;
446
447                 if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
448                     id->idProduct != dev->descriptor.idProduct)
449                         continue;
450
451                 /* No need to test id->bcdDevice_lo != 0, since 0 is never
452                    greater than any unsigned number. */
453                 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
454                     (id->bcdDevice_lo > dev->descriptor.bcdDevice))
455                         continue;
456
457                 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
458                     (id->bcdDevice_hi < dev->descriptor.bcdDevice))
459                         continue;
460
461                 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
462                     (id->bDeviceClass != dev->descriptor.bDeviceClass))
463                         continue;
464
465                 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
466                     (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass))
467                         continue;
468
469                 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
470                     (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
471                         continue;
472
473                 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) &&
474                     (id->bInterfaceClass != intf->desc.bInterfaceClass))
475                         continue;
476
477                 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) &&
478                     (id->bInterfaceSubClass != intf->desc.bInterfaceSubClass))
479                         continue;
480
481                 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) &&
482                     (id->bInterfaceProtocol != intf->desc.bInterfaceProtocol))
483                         continue;
484
485                 return id;
486         }
487
488         return NULL;
489 }
490
491 /**
492  * usb_find_interface - find usb_interface pointer for driver and device
493  * @drv: the driver whose current configuration is considered
494  * @minor: the minor number of the desired device
495  *
496  * This walks the driver device list and returns a pointer to the interface 
497  * with the matching minor.  Note, this only works for devices that share the
498  * USB major number.
499  */
500 struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
501 {
502         struct list_head *entry;
503         struct device *dev;
504         struct usb_interface *intf;
505
506         list_for_each(entry, &drv->driver.devices) {
507                 dev = container_of(entry, struct device, driver_list);
508
509                 /* can't look at usb devices, only interfaces */
510                 if (dev->driver == &usb_generic_driver)
511                         continue;
512
513                 intf = to_usb_interface(dev);
514                 if (intf->minor == -1)
515                         continue;
516                 if (intf->minor == minor)
517                         return intf;
518         }
519
520         /* no device found that matches */
521         return 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
536         usb_drv = to_usb_driver(drv);
537         id = usb_drv->id_table;
538         
539         id = usb_match_id (intf, usb_drv->id_table);
540         if (id)
541                 return 1;
542
543         return 0;
544 }
545
546
547 #ifdef  CONFIG_HOTPLUG
548
549 /*
550  * USB hotplugging invokes what /proc/sys/kernel/hotplug says
551  * (normally /sbin/hotplug) when USB devices get added or removed.
552  *
553  * This invokes a user mode policy agent, typically helping to load driver
554  * or other modules, configure the device, and more.  Drivers can provide
555  * a MODULE_DEVICE_TABLE to help with module loading subtasks.
556  *
557  * We're called either from khubd (the typical case) or from root hub
558  * (init, kapmd, modprobe, rmmod, etc), but the agents need to handle
559  * delays in event delivery.  Use sysfs (and DEVPATH) to make sure the
560  * device (and this configuration!) are still present.
561  */
562 static int usb_hotplug (struct device *dev, char **envp, int num_envp,
563                         char *buffer, int buffer_size)
564 {
565         struct usb_interface *intf;
566         struct usb_device *usb_dev;
567         char *scratch;
568         int i = 0;
569         int length = 0;
570
571         if (!dev)
572                 return -ENODEV;
573
574         /* driver is often null here; dev_dbg() would oops */
575         pr_debug ("usb %s: hotplug\n", dev->bus_id);
576
577         /* Must check driver_data here, as on remove driver is always NULL */
578         if ((dev->driver == &usb_generic_driver) || 
579             (dev->driver_data == &usb_generic_driver_data))
580                 return 0;
581
582         intf = to_usb_interface(dev);
583         usb_dev = interface_to_usbdev (intf);
584         
585         if (usb_dev->devnum < 0) {
586                 pr_debug ("usb %s: already deleted?\n", dev->bus_id);
587                 return -ENODEV;
588         }
589         if (!usb_dev->bus) {
590                 pr_debug ("usb %s: bus removed?\n", dev->bus_id);
591                 return -ENODEV;
592         }
593
594         scratch = buffer;
595
596 #ifdef  CONFIG_USB_DEVICEFS
597         /* If this is available, userspace programs can directly read
598          * all the device descriptors we don't tell them about.  Or
599          * even act as usermode drivers.
600          *
601          * FIXME reduce hardwired intelligence here
602          */
603         envp [i++] = scratch;
604         length += snprintf (scratch, buffer_size - length,
605                             "DEVICE=/proc/bus/usb/%03d/%03d",
606                             usb_dev->bus->busnum, usb_dev->devnum);
607         if ((buffer_size - length <= 0) || (i >= num_envp))
608                 return -ENOMEM;
609         ++length;
610         scratch += length;
611 #endif
612
613         /* per-device configurations are common */
614         envp [i++] = scratch;
615         length += snprintf (scratch, buffer_size - length, "PRODUCT=%x/%x/%x",
616                             usb_dev->descriptor.idVendor,
617                             usb_dev->descriptor.idProduct,
618                             usb_dev->descriptor.bcdDevice);
619         if ((buffer_size - length <= 0) || (i >= num_envp))
620                 return -ENOMEM;
621         ++length;
622         scratch += length;
623
624         /* class-based driver binding models */
625         envp [i++] = scratch;
626         length += snprintf (scratch, buffer_size - length, "TYPE=%d/%d/%d",
627                             usb_dev->descriptor.bDeviceClass,
628                             usb_dev->descriptor.bDeviceSubClass,
629                             usb_dev->descriptor.bDeviceProtocol);
630         if ((buffer_size - length <= 0) || (i >= num_envp))
631                 return -ENOMEM;
632         ++length;
633         scratch += length;
634
635         if (usb_dev->descriptor.bDeviceClass == 0) {
636                 struct usb_host_interface *alt = intf->cur_altsetting;
637
638                 /* 2.4 only exposed interface zero.  in 2.5, hotplug
639                  * agents are called for all interfaces, and can use
640                  * $DEVPATH/bInterfaceNumber if necessary.
641                  */
642                 envp [i++] = scratch;
643                 length += snprintf (scratch, buffer_size - length,
644                             "INTERFACE=%d/%d/%d",
645                             alt->desc.bInterfaceClass,
646                             alt->desc.bInterfaceSubClass,
647                             alt->desc.bInterfaceProtocol);
648                 if ((buffer_size - length <= 0) || (i >= num_envp))
649                         return -ENOMEM;
650                 ++length;
651                 scratch += length;
652
653         }
654         envp[i++] = NULL;
655
656         return 0;
657 }
658
659 #else
660
661 static int usb_hotplug (struct device *dev, char **envp,
662                         int num_envp, char *buffer, int buffer_size)
663 {
664         return -ENODEV;
665 }
666
667 #endif  /* CONFIG_HOTPLUG */
668
669 /**
670  * usb_release_dev - free a usb device structure when all users of it are finished.
671  * @dev: device that's been disconnected
672  *
673  * Will be called only by the device core when all users of this usb device are
674  * done.
675  */
676 static void usb_release_dev(struct device *dev)
677 {
678         struct usb_device *udev;
679
680         udev = to_usb_device(dev);
681
682         if (udev->bus && udev->bus->op && udev->bus->op->deallocate)
683                 udev->bus->op->deallocate(udev);
684         usb_destroy_configuration(udev);
685         usb_bus_put(udev->bus);
686         kfree (udev);
687 }
688
689 /**
690  * usb_alloc_dev - usb device constructor (usbcore-internal)
691  * @parent: hub to which device is connected; null to allocate a root hub
692  * @bus: bus used to access the device
693  * @port: zero based index of port; ignored for root hubs
694  * Context: !in_interrupt ()
695  *
696  * Only hub drivers (including virtual root hub drivers for host
697  * controllers) should ever call this.
698  *
699  * This call may not be used in a non-sleeping context.
700  */
701 struct usb_device *
702 usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port)
703 {
704         struct usb_device *dev;
705
706         dev = kmalloc(sizeof(*dev), GFP_KERNEL);
707         if (!dev)
708                 return NULL;
709
710         memset(dev, 0, sizeof(*dev));
711
712         bus = usb_bus_get(bus);
713         if (!bus) {
714                 kfree(dev);
715                 return NULL;
716         }
717
718         device_initialize(&dev->dev);
719         dev->dev.bus = &usb_bus_type;
720         dev->dev.dma_mask = bus->controller->dma_mask;
721         dev->dev.driver_data = &usb_generic_driver_data;
722         dev->dev.driver = &usb_generic_driver;
723         dev->dev.release = usb_release_dev;
724         dev->state = USB_STATE_ATTACHED;
725
726         /* Save readable and stable topology id, distinguishing devices
727          * by location for diagnostics, tools, driver model, etc.  The
728          * string is a path along hub ports, from the root.  Each device's
729          * dev->devpath will be stable until USB is re-cabled, and hubs
730          * are often labeled with these port numbers.  The bus_id isn't
731          * as stable:  bus->busnum changes easily from modprobe order,
732          * cardbus or pci hotplugging, and so on.
733          */
734         if (unlikely (!parent)) {
735                 dev->devpath [0] = '0';
736
737                 dev->dev.parent = bus->controller;
738                 sprintf (&dev->dev.bus_id[0], "usb%d", bus->busnum);
739         } else {
740                 /* match any labeling on the hubs; it's one-based */
741                 if (parent->devpath [0] == '0')
742                         snprintf (dev->devpath, sizeof dev->devpath,
743                                 "%d", port + 1);
744                 else
745                         snprintf (dev->devpath, sizeof dev->devpath,
746                                 "%s.%d", parent->devpath, port + 1);
747
748                 dev->dev.parent = &parent->dev;
749                 sprintf (&dev->dev.bus_id[0], "%d-%s",
750                         bus->busnum, dev->devpath);
751
752                 /* hub driver sets up TT records */
753         }
754
755         dev->bus = bus;
756         dev->parent = parent;
757         INIT_LIST_HEAD(&dev->filelist);
758
759         init_MUTEX(&dev->serialize);
760
761         if (dev->bus->op->allocate)
762                 dev->bus->op->allocate(dev);
763
764         return dev;
765 }
766
767 /**
768  * usb_get_dev - increments the reference count of the usb device structure
769  * @dev: the device being referenced
770  *
771  * Each live reference to a device should be refcounted.
772  *
773  * Drivers for USB interfaces should normally record such references in
774  * their probe() methods, when they bind to an interface, and release
775  * them by calling usb_put_dev(), in their disconnect() methods.
776  *
777  * A pointer to the device with the incremented reference counter is returned.
778  */
779 struct usb_device *usb_get_dev(struct usb_device *dev)
780 {
781         if (dev)
782                 get_device(&dev->dev);
783         return dev;
784 }
785
786 /**
787  * usb_put_dev - release a use of the usb device structure
788  * @dev: device that's been disconnected
789  *
790  * Must be called when a user of a device is finished with it.  When the last
791  * user of the device calls this function, the memory of the device is freed.
792  */
793 void usb_put_dev(struct usb_device *dev)
794 {
795         if (dev)
796                 put_device(&dev->dev);
797 }
798
799 /**
800  * usb_get_intf - increments the reference count of the usb interface structure
801  * @intf: the interface being referenced
802  *
803  * Each live reference to a interface must be refcounted.
804  *
805  * Drivers for USB interfaces should normally record such references in
806  * their probe() methods, when they bind to an interface, and release
807  * them by calling usb_put_intf(), in their disconnect() methods.
808  *
809  * A pointer to the interface with the incremented reference counter is
810  * returned.
811  */
812 struct usb_interface *usb_get_intf(struct usb_interface *intf)
813 {
814         if (intf)
815                 get_device(&intf->dev);
816         return intf;
817 }
818
819 /**
820  * usb_put_intf - release a use of the usb interface structure
821  * @intf: interface that's been decremented
822  *
823  * Must be called when a user of an interface is finished with it.  When the
824  * last user of the interface calls this function, the memory of the interface
825  * is freed.
826  */
827 void usb_put_intf(struct usb_interface *intf)
828 {
829         if (intf)
830                 put_device(&intf->dev);
831 }
832
833 static struct usb_device *match_device(struct usb_device *dev,
834                                        u16 vendor_id, u16 product_id)
835 {
836         struct usb_device *ret_dev = NULL;
837         int child;
838
839         dev_dbg(&dev->dev, "check for vendor %04x, product %04x ...\n",
840             dev->descriptor.idVendor,
841             dev->descriptor.idProduct);
842
843         /* see if this device matches */
844         if ((dev->descriptor.idVendor == vendor_id) &&
845             (dev->descriptor.idProduct == product_id)) {
846                 dev_dbg (&dev->dev, "matched this device!\n");
847                 ret_dev = usb_get_dev(dev);
848                 goto exit;
849         }
850
851         /* look through all of the children of this device */
852         for (child = 0; child < dev->maxchild; ++child) {
853                 if (dev->children[child]) {
854                         ret_dev = match_device(dev->children[child],
855                                                vendor_id, product_id);
856                         if (ret_dev)
857                                 goto exit;
858                 }
859         }
860 exit:
861         return ret_dev;
862 }
863
864 /**
865  * usb_find_device - find a specific usb device in the system
866  * @vendor_id: the vendor id of the device to find
867  * @product_id: the product id of the device to find
868  *
869  * Returns a pointer to a struct usb_device if such a specified usb
870  * device is present in the system currently.  The usage count of the
871  * device will be incremented if a device is found.  Make sure to call
872  * usb_put_dev() when the caller is finished with the device.
873  *
874  * If a device with the specified vendor and product id is not found,
875  * NULL is returned.
876  */
877 struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
878 {
879         struct list_head *buslist;
880         struct usb_bus *bus;
881         struct usb_device *dev = NULL;
882         
883         down(&usb_bus_list_lock);
884         for (buslist = usb_bus_list.next;
885              buslist != &usb_bus_list; 
886              buslist = buslist->next) {
887                 bus = container_of(buslist, struct usb_bus, bus_list);
888                 if (!bus->root_hub)
889                         continue;
890                 dev = match_device(bus->root_hub, vendor_id, product_id);
891                 if (dev)
892                         goto exit;
893         }
894 exit:
895         up(&usb_bus_list_lock);
896         return dev;
897 }
898
899 /**
900  * usb_get_current_frame_number - return current bus frame number
901  * @dev: the device whose bus is being queried
902  *
903  * Returns the current frame number for the USB host controller
904  * used with the given USB device.  This can be used when scheduling
905  * isochronous requests.
906  *
907  * Note that different kinds of host controller have different
908  * "scheduling horizons".  While one type might support scheduling only
909  * 32 frames into the future, others could support scheduling up to
910  * 1024 frames into the future.
911  */
912 int usb_get_current_frame_number(struct usb_device *dev)
913 {
914         return dev->bus->op->get_frame_number (dev);
915 }
916
917 /*-------------------------------------------------------------------*/
918 /*
919  * __usb_get_extra_descriptor() finds a descriptor of specific type in the
920  * extra field of the interface and endpoint descriptor structs.
921  */
922
923 int __usb_get_extra_descriptor(char *buffer, unsigned size,
924         unsigned char type, void **ptr)
925 {
926         struct usb_descriptor_header *header;
927
928         while (size >= sizeof(struct usb_descriptor_header)) {
929                 header = (struct usb_descriptor_header *)buffer;
930
931                 if (header->bLength < 2) {
932                         printk(KERN_ERR
933                                 "%s: bogus descriptor, type %d length %d\n",
934                                 usbcore_name,
935                                 header->bDescriptorType, 
936                                 header->bLength);
937                         return -1;
938                 }
939
940                 if (header->bDescriptorType == type) {
941                         *ptr = header;
942                         return 0;
943                 }
944
945                 buffer += header->bLength;
946                 size -= header->bLength;
947         }
948         return -1;
949 }
950
951 /**
952  * usb_buffer_alloc - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP
953  * @dev: device the buffer will be used with
954  * @size: requested buffer size
955  * @mem_flags: affect whether allocation may block
956  * @dma: used to return DMA address of buffer
957  *
958  * Return value is either null (indicating no buffer could be allocated), or
959  * the cpu-space pointer to a buffer that may be used to perform DMA to the
960  * specified device.  Such cpu-space buffers are returned along with the DMA
961  * address (through the pointer provided).
962  *
963  * These buffers are used with URB_NO_xxx_DMA_MAP set in urb->transfer_flags
964  * to avoid behaviors like using "DMA bounce buffers", or tying down I/O
965  * mapping hardware for long idle periods.  The implementation varies between
966  * platforms, depending on details of how DMA will work to this device.
967  * Using these buffers also helps prevent cacheline sharing problems on
968  * architectures where CPU caches are not DMA-coherent.
969  *
970  * When the buffer is no longer used, free it with usb_buffer_free().
971  */
972 void *usb_buffer_alloc (
973         struct usb_device *dev,
974         size_t size,
975         int mem_flags,
976         dma_addr_t *dma
977 )
978 {
979         if (!dev || !dev->bus || !dev->bus->op || !dev->bus->op->buffer_alloc)
980                 return NULL;
981         return dev->bus->op->buffer_alloc (dev->bus, size, mem_flags, dma);
982 }
983
984 /**
985  * usb_buffer_free - free memory allocated with usb_buffer_alloc()
986  * @dev: device the buffer was used with
987  * @size: requested buffer size
988  * @addr: CPU address of buffer
989  * @dma: DMA address of buffer
990  *
991  * This reclaims an I/O buffer, letting it be reused.  The memory must have
992  * been allocated using usb_buffer_alloc(), and the parameters must match
993  * those provided in that allocation request. 
994  */
995 void usb_buffer_free (
996         struct usb_device *dev,
997         size_t size,
998         void *addr,
999         dma_addr_t dma
1000 )
1001 {
1002         if (!dev || !dev->bus || !dev->bus->op || !dev->bus->op->buffer_free)
1003                 return;
1004         dev->bus->op->buffer_free (dev->bus, size, addr, dma);
1005 }
1006
1007 /**
1008  * usb_buffer_map - create DMA mapping(s) for an urb
1009  * @urb: urb whose transfer_buffer/setup_packet will be mapped
1010  *
1011  * Return value is either null (indicating no buffer could be mapped), or
1012  * the parameter.  URB_NO_TRANSFER_DMA_MAP and URB_NO_SETUP_DMA_MAP are
1013  * added to urb->transfer_flags if the operation succeeds.  If the device
1014  * is connected to this system through a non-DMA controller, this operation
1015  * always succeeds.
1016  *
1017  * This call would normally be used for an urb which is reused, perhaps
1018  * as the target of a large periodic transfer, with usb_buffer_dmasync()
1019  * calls to synchronize memory and dma state.
1020  *
1021  * Reverse the effect of this call with usb_buffer_unmap().
1022  */
1023 struct urb *usb_buffer_map (struct urb *urb)
1024 {
1025         struct usb_bus          *bus;
1026         struct device           *controller;
1027
1028         if (!urb
1029                         || !urb->dev
1030                         || !(bus = urb->dev->bus)
1031                         || !(controller = bus->controller))
1032                 return NULL;
1033
1034         if (controller->dma_mask) {
1035                 urb->transfer_dma = dma_map_single (controller,
1036                         urb->transfer_buffer, urb->transfer_buffer_length,
1037                         usb_pipein (urb->pipe)
1038                                 ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
1039                 if (usb_pipecontrol (urb->pipe))
1040                         urb->setup_dma = dma_map_single (controller,
1041                                         urb->setup_packet,
1042                                         sizeof (struct usb_ctrlrequest),
1043                                         DMA_TO_DEVICE);
1044         // FIXME generic api broken like pci, can't report errors
1045         // if (urb->transfer_dma == DMA_ADDR_INVALID) return 0;
1046         } else
1047                 urb->transfer_dma = ~0;
1048         urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP
1049                                 | URB_NO_SETUP_DMA_MAP);
1050         return urb;
1051 }
1052
1053 /* XXX DISABLED, no users currently.  If you wish to re-enable this
1054  * XXX please determine whether the sync is to transfer ownership of
1055  * XXX the buffer from device to cpu or vice verse, and thusly use the
1056  * XXX appropriate _for_{cpu,device}() method.  -DaveM
1057  */
1058 #if 0
1059
1060 /**
1061  * usb_buffer_dmasync - synchronize DMA and CPU view of buffer(s)
1062  * @urb: urb whose transfer_buffer/setup_packet will be synchronized
1063  */
1064 void usb_buffer_dmasync (struct urb *urb)
1065 {
1066         struct usb_bus          *bus;
1067         struct device           *controller;
1068
1069         if (!urb
1070                         || !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
1071                         || !urb->dev
1072                         || !(bus = urb->dev->bus)
1073                         || !(controller = bus->controller))
1074                 return;
1075
1076         if (controller->dma_mask) {
1077                 dma_sync_single (controller,
1078                         urb->transfer_dma, urb->transfer_buffer_length,
1079                         usb_pipein (urb->pipe)
1080                                 ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
1081                 if (usb_pipecontrol (urb->pipe))
1082                         dma_sync_single (controller,
1083                                         urb->setup_dma,
1084                                         sizeof (struct usb_ctrlrequest),
1085                                         DMA_TO_DEVICE);
1086         }
1087 }
1088 #endif
1089
1090 /**
1091  * usb_buffer_unmap - free DMA mapping(s) for an urb
1092  * @urb: urb whose transfer_buffer will be unmapped
1093  *
1094  * Reverses the effect of usb_buffer_map().
1095  */
1096 void usb_buffer_unmap (struct urb *urb)
1097 {
1098         struct usb_bus          *bus;
1099         struct device           *controller;
1100
1101         if (!urb
1102                         || !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
1103                         || !urb->dev
1104                         || !(bus = urb->dev->bus)
1105                         || !(controller = bus->controller))
1106                 return;
1107
1108         if (controller->dma_mask) {
1109                 dma_unmap_single (controller,
1110                         urb->transfer_dma, urb->transfer_buffer_length,
1111                         usb_pipein (urb->pipe)
1112                                 ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
1113                 if (usb_pipecontrol (urb->pipe))
1114                         dma_unmap_single (controller,
1115                                         urb->setup_dma,
1116                                         sizeof (struct usb_ctrlrequest),
1117                                         DMA_TO_DEVICE);
1118         }
1119         urb->transfer_flags &= ~(URB_NO_TRANSFER_DMA_MAP
1120                                 | URB_NO_SETUP_DMA_MAP);
1121 }
1122
1123 /**
1124  * usb_buffer_map_sg - create scatterlist DMA mapping(s) for an endpoint
1125  * @dev: device to which the scatterlist will be mapped
1126  * @pipe: endpoint defining the mapping direction
1127  * @sg: the scatterlist to map
1128  * @nents: the number of entries in the scatterlist
1129  *
1130  * Return value is either < 0 (indicating no buffers could be mapped), or
1131  * the number of DMA mapping array entries in the scatterlist.
1132  *
1133  * The caller is responsible for placing the resulting DMA addresses from
1134  * the scatterlist into URB transfer buffer pointers, and for setting the
1135  * URB_NO_TRANSFER_DMA_MAP transfer flag in each of those URBs.
1136  *
1137  * Top I/O rates come from queuing URBs, instead of waiting for each one
1138  * to complete before starting the next I/O.   This is particularly easy
1139  * to do with scatterlists.  Just allocate and submit one URB for each DMA
1140  * mapping entry returned, stopping on the first error or when all succeed.
1141  * Better yet, use the usb_sg_*() calls, which do that (and more) for you.
1142  *
1143  * This call would normally be used when translating scatterlist requests,
1144  * rather than usb_buffer_map(), since on some hardware (with IOMMUs) it
1145  * may be able to coalesce mappings for improved I/O efficiency.
1146  *
1147  * Reverse the effect of this call with usb_buffer_unmap_sg().
1148  */
1149 int usb_buffer_map_sg (struct usb_device *dev, unsigned pipe,
1150                 struct scatterlist *sg, int nents)
1151 {
1152         struct usb_bus          *bus;
1153         struct device           *controller;
1154
1155         if (!dev
1156                         || usb_pipecontrol (pipe)
1157                         || !(bus = dev->bus)
1158                         || !(controller = bus->controller)
1159                         || !controller->dma_mask)
1160                 return -1;
1161
1162         // FIXME generic api broken like pci, can't report errors
1163         return dma_map_sg (controller, sg, nents,
1164                         usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
1165 }
1166
1167 /* XXX DISABLED, no users currently.  If you wish to re-enable this
1168  * XXX please determine whether the sync is to transfer ownership of
1169  * XXX the buffer from device to cpu or vice verse, and thusly use the
1170  * XXX appropriate _for_{cpu,device}() method.  -DaveM
1171  */
1172 #if 0
1173
1174 /**
1175  * usb_buffer_dmasync_sg - synchronize DMA and CPU view of scatterlist buffer(s)
1176  * @dev: device to which the scatterlist will be mapped
1177  * @pipe: endpoint defining the mapping direction
1178  * @sg: the scatterlist to synchronize
1179  * @n_hw_ents: the positive return value from usb_buffer_map_sg
1180  *
1181  * Use this when you are re-using a scatterlist's data buffers for
1182  * another USB request.
1183  */
1184 void usb_buffer_dmasync_sg (struct usb_device *dev, unsigned pipe,
1185                 struct scatterlist *sg, int n_hw_ents)
1186 {
1187         struct usb_bus          *bus;
1188         struct device           *controller;
1189
1190         if (!dev
1191                         || !(bus = dev->bus)
1192                         || !(controller = bus->controller)
1193                         || !controller->dma_mask)
1194                 return;
1195
1196         dma_sync_sg (controller, sg, n_hw_ents,
1197                         usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
1198 }
1199 #endif
1200
1201 /**
1202  * usb_buffer_unmap_sg - free DMA mapping(s) for a scatterlist
1203  * @dev: device to which the scatterlist will be mapped
1204  * @pipe: endpoint defining the mapping direction
1205  * @sg: the scatterlist to unmap
1206  * @n_hw_ents: the positive return value from usb_buffer_map_sg
1207  *
1208  * Reverses the effect of usb_buffer_map_sg().
1209  */
1210 void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe,
1211                 struct scatterlist *sg, int n_hw_ents)
1212 {
1213         struct usb_bus          *bus;
1214         struct device           *controller;
1215
1216         if (!dev
1217                         || !(bus = dev->bus)
1218                         || !(controller = bus->controller)
1219                         || !controller->dma_mask)
1220                 return;
1221
1222         dma_unmap_sg (controller, sg, n_hw_ents,
1223                         usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
1224 }
1225
1226 static int usb_generic_suspend(struct device *dev, u32 state)
1227 {
1228         struct usb_interface *intf;
1229         struct usb_driver *driver;
1230
1231         if (dev->driver == &usb_generic_driver)
1232                 return usb_suspend_device (to_usb_device(dev), state);
1233
1234         if ((dev->driver == NULL) ||
1235             (dev->driver_data == &usb_generic_driver_data))
1236                 return 0;
1237
1238         intf = to_usb_interface(dev);
1239         driver = to_usb_driver(dev->driver);
1240
1241         if (driver->suspend)
1242                 return driver->suspend(intf, state);
1243         return 0;
1244 }
1245
1246 static int usb_generic_resume(struct device *dev)
1247 {
1248         struct usb_interface *intf;
1249         struct usb_driver *driver;
1250
1251         /* devices resume through their hub */
1252         if (dev->driver == &usb_generic_driver)
1253                 return usb_resume_device (to_usb_device(dev));
1254
1255         if ((dev->driver == NULL) ||
1256             (dev->driver_data == &usb_generic_driver_data))
1257                 return 0;
1258
1259         intf = to_usb_interface(dev);
1260         driver = to_usb_driver(dev->driver);
1261
1262         if (driver->resume)
1263                 return driver->resume(intf);
1264         return 0;
1265 }
1266
1267 struct bus_type usb_bus_type = {
1268         .name =         "usb",
1269         .match =        usb_device_match,
1270         .hotplug =      usb_hotplug,
1271         .suspend =      usb_generic_suspend,
1272         .resume =       usb_generic_resume,
1273 };
1274
1275 #ifndef MODULE
1276
1277 static int __init usb_setup_disable(char *str)
1278 {
1279         nousb = 1;
1280         return 1;
1281 }
1282
1283 /* format to disable USB on kernel command line is: nousb */
1284 __setup("nousb", usb_setup_disable);
1285
1286 #endif
1287
1288 /*
1289  * for external read access to <nousb>
1290  */
1291 int usb_disabled(void)
1292 {
1293         return nousb;
1294 }
1295
1296 /*
1297  * Init
1298  */
1299 static int __init usb_init(void)
1300 {
1301         int retval;
1302         if (nousb) {
1303                 pr_info ("%s: USB support disabled\n", usbcore_name);
1304                 return 0;
1305         }
1306
1307         retval = bus_register(&usb_bus_type);
1308         if (retval) 
1309                 goto out;
1310         retval = usb_host_init();
1311         if (retval)
1312                 goto host_init_failed;
1313         retval = usb_major_init();
1314         if (retval)
1315                 goto major_init_failed;
1316         retval = usbfs_init();
1317         if (retval)
1318                 goto fs_init_failed;
1319         retval = usb_hub_init();
1320         if (retval)
1321                 goto hub_init_failed;
1322
1323         retval = driver_register(&usb_generic_driver);
1324         if (!retval)
1325                 goto out;
1326
1327         usb_hub_cleanup();
1328 hub_init_failed:
1329         usbfs_cleanup();
1330 fs_init_failed:
1331         usb_major_cleanup();    
1332 major_init_failed:
1333         usb_host_cleanup();
1334 host_init_failed:
1335         bus_unregister(&usb_bus_type);
1336 out:
1337         return retval;
1338 }
1339
1340 /*
1341  * Cleanup
1342  */
1343 static void __exit usb_exit(void)
1344 {
1345         /* This will matter if shutdown/reboot does exitcalls. */
1346         if (nousb)
1347                 return;
1348
1349         driver_unregister(&usb_generic_driver);
1350         usb_major_cleanup();
1351         usbfs_cleanup();
1352         usb_hub_cleanup();
1353         usb_host_cleanup();
1354         bus_unregister(&usb_bus_type);
1355 }
1356
1357 subsys_initcall(usb_init);
1358 module_exit(usb_exit);
1359
1360 /*
1361  * USB may be built into the kernel or be built as modules.
1362  * These symbols are exported for device (or host controller)
1363  * driver modules to use.
1364  */
1365 EXPORT_SYMBOL(usb_epnum_to_ep_desc);
1366
1367 EXPORT_SYMBOL(usb_register);
1368 EXPORT_SYMBOL(usb_deregister);
1369 EXPORT_SYMBOL(usb_disabled);
1370
1371 EXPORT_SYMBOL(usb_alloc_dev);
1372 EXPORT_SYMBOL(usb_put_dev);
1373 EXPORT_SYMBOL(usb_get_dev);
1374 EXPORT_SYMBOL(usb_hub_tt_clear_buffer);
1375
1376 EXPORT_SYMBOL(usb_driver_claim_interface);
1377 EXPORT_SYMBOL(usb_driver_release_interface);
1378 EXPORT_SYMBOL(usb_match_id);
1379 EXPORT_SYMBOL(usb_find_interface);
1380 EXPORT_SYMBOL(usb_ifnum_to_if);
1381 EXPORT_SYMBOL(usb_altnum_to_altsetting);
1382
1383 EXPORT_SYMBOL(usb_reset_device);
1384 EXPORT_SYMBOL(usb_disconnect);
1385
1386 EXPORT_SYMBOL(__usb_get_extra_descriptor);
1387
1388 EXPORT_SYMBOL(usb_find_device);
1389 EXPORT_SYMBOL(usb_get_current_frame_number);
1390
1391 EXPORT_SYMBOL (usb_buffer_alloc);
1392 EXPORT_SYMBOL (usb_buffer_free);
1393
1394 EXPORT_SYMBOL (usb_buffer_map);
1395 #if 0
1396 EXPORT_SYMBOL (usb_buffer_dmasync);
1397 #endif
1398 EXPORT_SYMBOL (usb_buffer_unmap);
1399
1400 EXPORT_SYMBOL (usb_buffer_map_sg);
1401 #if 0
1402 EXPORT_SYMBOL (usb_buffer_dmasync_sg);
1403 #endif
1404 EXPORT_SYMBOL (usb_buffer_unmap_sg);
1405
1406 MODULE_LICENSE("GPL");