kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / bus / usb / usb.c
1 /*      $NetBSD: usb.c,v 1.33 1999/11/22 21:57:09 augustss Exp $        */
2 /*      $FreeBSD: src/sys/dev/usb/usb.c,v 1.26.2.9 2002/11/13 15:15:22 joe Exp $        */
3 /*      $DragonFly: src/sys/bus/usb/usb.c,v 1.8 2003/08/07 21:16:47 dillon Exp $        */
4
5 /*
6  * Copyright (c) 1998 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Lennart Augustsson (lennart@augustsson.net) at
11  * Carlstedt Research & Technology.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  *    must display the following acknowledgement:
23  *        This product includes software developed by the NetBSD
24  *        Foundation, Inc. and its contributors.
25  * 4. Neither the name of The NetBSD Foundation nor the names of its
26  *    contributors may be used to endorse or promote products derived
27  *    from this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  */
41
42 /*
43  * USB specifications and other documentation can be found at
44  * http://www.usb.org/developers/data/ and
45  * http://www.usb.org/developers/index.html .
46  */
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #if defined(__NetBSD__) || defined(__OpenBSD__)
53 #include <sys/device.h>
54 #include <sys/kthread.h>
55 #include <sys/proc.h>
56 #elif defined(__FreeBSD__)
57 #include <sys/module.h>
58 #include <sys/bus.h>
59 #include <sys/filio.h>
60 #include <sys/uio.h>
61 #endif
62 #include <sys/conf.h>
63 #include <sys/poll.h>
64 #include <sys/select.h>
65 #include <sys/vnode.h>
66 #include <sys/signalvar.h>
67 #include <sys/sysctl.h>
68
69 #include "usb.h"
70 #include "usbdi.h"
71 #include "usbdi_util.h"
72
73 #define USBUNIT(d)      (minor(d))      /* usb_discover device nodes, kthread */
74 #define USB_DEV_MINOR   255             /* event queue device */
75
76 #if defined(__FreeBSD__)
77 MALLOC_DEFINE(M_USB, "USB", "USB");
78 MALLOC_DEFINE(M_USBDEV, "USBdev", "USB device");
79 MALLOC_DEFINE(M_USBHC, "USBHC", "USB host controller");
80
81 #include "usb_if.h"
82 #endif /* defined(__FreeBSD__) */
83
84 #include <machine/bus.h>
85
86 #include "usbdivar.h"
87 #include "usb_quirks.h"
88
89 /* Define this unconditionally in case a kernel module is loaded that
90  * has been compiled with debugging options.
91  */
92 SYSCTL_NODE(_hw, OID_AUTO, usb, CTLFLAG_RW, 0, "USB debugging");
93
94 #ifdef USB_DEBUG
95 #define DPRINTF(x)      if (usbdebug) logprintf x
96 #define DPRINTFN(n,x)   if (usbdebug>(n)) logprintf x
97 int     usbdebug = 0;
98 SYSCTL_INT(_hw_usb, OID_AUTO, debug, CTLFLAG_RW,
99            &usbdebug, 0, "usb debug level");
100 #ifdef USB_DEBUG
101 extern int uhcidebug;
102 #endif
103 #ifdef USB_DEBUG
104 extern int ohcidebug;
105 #endif
106 /* 
107  * 0  - do usual exploration
108  * 1  - do not use timeout exploration
109  * >1 - do no exploration
110  */
111 int     usb_noexplore = 0;
112 #else
113 #define DPRINTF(x)
114 #define DPRINTFN(n,x)
115 #endif
116
117 struct usb_softc {
118         USBBASEDEVICE   sc_dev;         /* base device */
119         usbd_bus_handle sc_bus;         /* USB controller */
120         struct usbd_port sc_port;       /* dummy port for root hub */
121
122 #if defined(__FreeBSD__)
123         /* This part should be deleted when kthreads is available */
124         struct selinfo  sc_consel;      /* waiting for connect change */
125 #else
126         struct proc    *sc_event_thread;
127 #endif
128
129         char            sc_dying;
130 };
131
132 #if defined(__NetBSD__) || defined(__OpenBSD__)
133 cdev_decl(usb);
134 #elif defined(__FreeBSD__)
135 d_open_t  usbopen; 
136 d_close_t usbclose;
137 d_read_t usbread;
138 d_ioctl_t usbioctl;
139 int usbpoll(dev_t, int, usb_proc_ptr);
140
141 struct cdevsw usb_cdevsw = {
142         /* name */      "usb",
143         /* maj */       USB_CDEV_MAJOR,
144         /* flags */     0,
145         /* port */      NULL,
146         /* autoq */     0,
147
148         /* open */      usbopen,
149         /* close */     usbclose,
150         /* read */      usbread,
151         /* write */     nowrite,
152         /* ioctl */     usbioctl,
153         /* poll */      usbpoll,
154         /* mmap */      nommap,
155         /* strategy */  nostrategy,
156         /* dump */      nodump,
157         /* psize */     nopsize
158 };
159 #endif
160
161 Static usbd_status usb_discover(struct usb_softc *);
162 #if defined(__NetBSD__) || defined(__OpenBSD__)
163 Static void     usb_create_event_thread(void *);
164 Static void     usb_event_thread(void *);
165 #endif
166
167 #define USB_MAX_EVENTS 50
168 struct usb_event_q {
169         struct usb_event ue;
170         SIMPLEQ_ENTRY(usb_event_q) next;
171 };
172 Static SIMPLEQ_HEAD(, usb_event_q) usb_events =
173         SIMPLEQ_HEAD_INITIALIZER(usb_events);
174 Static int usb_nevents = 0;
175 Static struct selinfo usb_selevent;
176 Static struct thread *usb_async_proc;  /* process who wants USB SIGIO */
177 Static int usb_dev_open = 0;
178
179 Static int usb_get_next_event(struct usb_event *);
180
181 #if defined(__NetBSD__) || defined(__OpenBSD__)
182 /* Flag to see if we are in the cold boot process. */
183 extern int cold;
184 #endif
185
186 Static const char *usbrev_str[] = USBREV_STR;
187
188 USB_DECLARE_DRIVER_INIT(usb,
189                         DEVMETHOD(device_suspend, bus_generic_suspend),
190                         DEVMETHOD(device_resume, bus_generic_resume),
191                         DEVMETHOD(device_shutdown, bus_generic_shutdown)
192                         );
193
194 USB_MATCH(usb)
195 {
196         DPRINTF(("usbd_match\n"));
197         return (UMATCH_GENERIC);
198 }
199
200 USB_ATTACH(usb)
201 {
202 #if defined(__NetBSD__) || defined(__OpenBSD__)
203         struct usb_softc *sc = (struct usb_softc *)self;
204 #elif defined(__FreeBSD__)
205         struct usb_softc *sc = device_get_softc(self);
206         void *aux = device_get_ivars(self);
207         static int global_init_done = 0;
208 #endif
209         usbd_device_handle dev;
210         usbd_status err;
211         int usbrev;
212
213         sc->sc_dev = self;
214
215         DPRINTF(("usbd_attach\n"));
216
217         usbd_init();
218         sc->sc_bus = aux;
219         sc->sc_bus->usbctl = sc;
220         sc->sc_port.power = USB_MAX_POWER;
221
222 #if defined(__FreeBSD__)
223         printf("%s", USBDEVNAME(sc->sc_dev));
224 #endif
225         usbrev = sc->sc_bus->usbrev;
226         printf(": USB revision %s", usbrev_str[usbrev]);
227         if (usbrev != USBREV_1_0 && usbrev != USBREV_1_1) {
228                 printf(", not supported\n");
229                 USB_ATTACH_ERROR_RETURN;
230         }
231         printf("\n");
232
233         err = usbd_new_device(USBDEV(sc->sc_dev), sc->sc_bus, 0, 0, 0,
234                   &sc->sc_port);
235         if (!err) {
236                 dev = sc->sc_port.device;
237                 if (dev->hub == NULL) {
238                         sc->sc_dying = 1;
239                         printf("%s: root device is not a hub\n", 
240                                USBDEVNAME(sc->sc_dev));
241                         USB_ATTACH_ERROR_RETURN;
242                 }
243                 sc->sc_bus->root_hub = dev;
244 #if 1
245                 /* 
246                  * Turning this code off will delay attachment of USB devices
247                  * until the USB event thread is running, which means that
248                  * the keyboard will not work until after cold boot.
249                  */
250                 if (cold) {
251                         sc->sc_bus->use_polling++;
252                         dev->hub->explore(sc->sc_bus->root_hub);
253                         sc->sc_bus->use_polling--;
254                 }
255 #endif
256         } else {
257                 printf("%s: root hub problem, error=%d\n", 
258                        USBDEVNAME(sc->sc_dev), err); 
259                 sc->sc_dying = 1;
260         }
261
262         kthread_create(usb_create_event_thread, sc);
263
264 #if defined(__FreeBSD__)
265         /* The per controller devices (used for usb_discover) */
266         make_dev(&usb_cdevsw, device_get_unit(self), UID_ROOT, GID_OPERATOR,
267                 0644, "usb%d", device_get_unit(self));
268         if (!global_init_done) {
269                 /* The device spitting out events */
270                 make_dev(&usb_cdevsw, USB_DEV_MINOR, UID_ROOT, GID_OPERATOR,
271                         0644, "usb");
272                 global_init_done = 1;
273         }
274 #endif
275
276         USB_ATTACH_SUCCESS_RETURN;
277 }
278
279 #if defined(__NetBSD__) || defined(__OpenBSD__)
280 void
281 usb_create_event_thread(void *arg)
282 {
283         struct usb_softc *sc = arg;
284
285         if (kthread_create1(usb_event_thread, sc, &sc->sc_event_thread,
286                            "%s", sc->sc_dev.dv_xname)) {
287                 printf("%s: unable to create event thread for\n",
288                        sc->sc_dev.dv_xname);
289                 panic("usb_create_event_thread");
290         }
291 }
292
293 void
294 usb_event_thread(void *arg)
295 {
296         struct usb_softc *sc = arg;
297
298         DPRINTF(("usb_event_thread: start\n"));
299
300         while (!sc->sc_dying) {
301 #ifdef USB_DEBUG
302                 if (usb_noexplore < 2)
303 #endif
304                 usb_discover(sc);
305                 (void)tsleep(&sc->sc_bus->needs_explore, 0, "usbevt",
306 #ifdef USB_DEBUG
307                              usb_noexplore ? 0 :
308 #endif
309                              hz*60
310                        );
311                 DPRINTFN(2,("usb_event_thread: woke up\n"));
312         }
313         sc->sc_event_thread = 0;
314
315         /* In case parent is waiting for us to exit. */
316         wakeup(sc);
317
318         DPRINTF(("usb_event_thread: exit\n"));
319         kthread_exit();
320 }
321
322 int
323 usbctlprint(void *aux, const char *pnp)
324 {
325         /* only "usb"es can attach to host controllers */
326         if (pnp)
327                 printf("usb at %s", pnp);
328
329         return (UNCONF);
330 }
331 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
332
333 int
334 usbopen(dev_t dev, int flag, int mode, usb_proc_ptr p)
335 {
336         int unit = USBUNIT(dev);
337         struct usb_softc *sc;
338
339         if (unit == USB_DEV_MINOR) {
340                 if (usb_dev_open)
341                         return (EBUSY);
342                 usb_dev_open = 1;
343                 usb_async_proc = NULL;
344                 return (0);
345         } else {
346                 USB_GET_SC_OPEN(usb, unit, sc);
347
348                 if (sc->sc_dying)
349                         return (EIO);
350
351                 return (0);
352         }
353 }
354
355 int
356 usbread(dev_t dev, struct uio *uio, int flag)
357 {
358         struct usb_event ue;
359         int unit = USBUNIT(dev);
360         int s, error, n;
361
362         if (unit != USB_DEV_MINOR)
363                 return (ENODEV);
364
365         if (uio->uio_resid != sizeof(struct usb_event))
366                 return (EINVAL);
367
368         error = 0;
369         s = splusb();
370         for (;;) {
371                 n = usb_get_next_event(&ue);
372                 if (n != 0)
373                         break;
374                 if (flag & IO_NDELAY) {
375                         error = EWOULDBLOCK;
376                         break;
377                 }
378                 error = tsleep(&usb_events, PCATCH, "usbrea", 0);
379                 if (error)
380                         break;
381         }
382         splx(s);
383         if (!error)
384                 error = uiomove((void *)&ue, uio->uio_resid, uio);
385
386         return (error);
387 }
388
389 int
390 usbclose(dev_t dev, int flag, int mode, usb_proc_ptr p)
391 {
392         int unit = USBUNIT(dev);
393
394         if (unit == USB_DEV_MINOR) {
395                 usb_async_proc = NULL;
396                 usb_dev_open = 0;
397         }
398
399         return (0);
400 }
401
402 int
403 usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
404 {
405         struct usb_softc *sc;
406         int unit = USBUNIT(devt);
407
408         if (unit == USB_DEV_MINOR) {
409                 switch (cmd) {
410                 case FIONBIO:
411                         /* All handled in the upper FS layer. */
412                         return (0);
413                         
414                 case FIOASYNC:
415                         if (*(int *)data)
416                                 usb_async_proc = p;
417                         else
418                                 usb_async_proc = NULL;
419                         return (0);
420
421                 default:
422                         return (EINVAL);
423                 }
424         }
425
426         USB_GET_SC(usb, unit, sc);
427
428         if (sc->sc_dying)
429                 return (EIO);
430
431         switch (cmd) {
432 #if defined(__FreeBSD__) 
433         /* This part should be deleted when kthreads is available */
434         case USB_DISCOVER:
435                 usb_discover(sc);
436                 break;
437 #endif
438 #ifdef USB_DEBUG
439         case USB_SETDEBUG:
440                 usbdebug  = ((*(int *)data) & 0x000000ff);
441                 uhcidebug = ((*(int *)data) & 0x0000ff00) >> 8;
442                 ohcidebug = ((*(int *)data) & 0x00ff0000) >> 16;
443                 break;
444 #endif
445         case USB_REQUEST:
446         {
447                 struct usb_ctl_request *ur = (void *)data;
448                 int len = UGETW(ur->ucr_request.wLength);
449                 struct iovec iov;
450                 struct uio uio;
451                 void *ptr = 0;
452                 int addr = ur->ucr_addr;
453                 usbd_status err;
454                 int error = 0;
455
456                 DPRINTF(("usbioctl: USB_REQUEST addr=%d len=%d\n", addr, len));
457                 if (len < 0 || len > 32768)
458                         return (EINVAL);
459                 if (addr < 0 || addr >= USB_MAX_DEVICES || 
460                     sc->sc_bus->devices[addr] == 0)
461                         return (EINVAL);
462                 if (len != 0) {
463                         iov.iov_base = (caddr_t)ur->ucr_data;
464                         iov.iov_len = len;
465                         uio.uio_iov = &iov;
466                         uio.uio_iovcnt = 1;
467                         uio.uio_resid = len;
468                         uio.uio_offset = 0;
469                         uio.uio_segflg = UIO_USERSPACE;
470                         uio.uio_rw =
471                                 ur->ucr_request.bmRequestType & UT_READ ? 
472                                 UIO_READ : UIO_WRITE;
473                         uio.uio_td = p;
474                         ptr = malloc(len, M_TEMP, M_WAITOK);
475                         if (uio.uio_rw == UIO_WRITE) {
476                                 error = uiomove(ptr, len, &uio);
477                                 if (error)
478                                         goto ret;
479                         }
480                 }
481                 err = usbd_do_request_flags(sc->sc_bus->devices[addr],
482                           &ur->ucr_request, ptr, ur->ucr_flags, &ur->ucr_actlen);
483                 if (err) {
484                         error = EIO;
485                         goto ret;
486                 }
487                 if (len != 0) {
488                         if (uio.uio_rw == UIO_READ) {
489                                 error = uiomove(ptr, len, &uio);
490                                 if (error)
491                                         goto ret;
492                         }
493                 }
494         ret:
495                 if (ptr)
496                         free(ptr, M_TEMP);
497                 return (error);
498         }
499
500         case USB_DEVICEINFO:
501         {
502                 struct usb_device_info *di = (void *)data;
503                 int addr = di->udi_addr;
504                 usbd_device_handle dev;
505
506                 if (addr < 1 || addr >= USB_MAX_DEVICES)
507                         return (EINVAL);
508                 dev = sc->sc_bus->devices[addr];
509                 if (dev == 0)
510                         return (ENXIO);
511                 usbd_fill_deviceinfo(dev, di);
512                 break;
513         }
514
515         case USB_DEVICESTATS:
516                 *(struct usb_device_stats *)data = sc->sc_bus->stats;
517                 break;
518
519         default:
520                 return (EINVAL);
521         }
522         return (0);
523 }
524
525 int
526 usbpoll(dev_t dev, int events, usb_proc_ptr p)
527 {
528         int revents, mask, s;
529         int unit = USBUNIT(dev);
530
531         if (unit == USB_DEV_MINOR) {
532                 revents = 0;
533                 mask = POLLIN | POLLRDNORM;
534
535                 s = splusb();
536                 if ((events & mask) && usb_nevents > 0)
537                         revents |= events & mask;
538                 if (revents == 0 && (events & mask)) {
539                         DPRINTFN(2,("usb: sleeping on %p\n", &usb_selevent));
540                         selrecord(p, &usb_selevent);
541                 }
542                 splx(s);
543
544                 return (revents);
545         } else {
546 #if defined(__FreeBSD__)
547                 /* This part should be deleted when kthreads is available */
548                 struct usb_softc *sc;
549
550                 USB_GET_SC(usb, unit, sc);
551
552                 revents = 0;
553                 mask = POLLOUT | POLLRDNORM;
554
555                 s = splusb();
556                 if ((events & mask) && sc->sc_bus->needs_explore)
557                         revents |= events & mask;
558                 if (revents == 0 && (events & mask))
559                         selrecord(p, &sc->sc_consel);
560                 splx(s);
561
562                 return (revents);
563 #else
564                 return (ENXIO);
565 #endif
566         }
567 }
568
569 /* Explore device tree from the root. */
570 usbd_status
571 usb_discover(struct usb_softc *sc)
572 {
573 #if defined(__FreeBSD__)
574         /* The splxxx parts should be deleted when kthreads is available */
575         int s;
576 #endif
577
578         /* 
579          * We need mutual exclusion while traversing the device tree,
580          * but this is guaranteed since this function is only called
581          * from the event thread for the controller.
582          */
583 #if defined(__FreeBSD__)
584         s = splusb();
585 #endif
586         while (sc->sc_bus->needs_explore && !sc->sc_dying) {
587                 sc->sc_bus->needs_explore = 0;
588 #if defined(__FreeBSD__)
589                 splx(s);
590 #endif
591                 sc->sc_bus->root_hub->hub->explore(sc->sc_bus->root_hub);
592 #if defined(__FreeBSD__)
593                 s = splusb();
594 #endif
595         }
596 #if defined(__FreeBSD__)
597         splx(s);
598 #endif
599
600         return (USBD_NORMAL_COMPLETION);
601 }
602
603 void
604 usb_needs_explore(usbd_bus_handle bus)
605 {
606         bus->needs_explore = 1;
607 #if defined(__FreeBSD__)
608         /* This part should be deleted when kthreads is available */
609         selwakeup(&bus->usbctl->sc_consel);
610 #endif
611         wakeup(&bus->needs_explore);
612 }
613
614 /* Called at splusb() */
615 int
616 usb_get_next_event(struct usb_event *ue)
617 {
618         struct usb_event_q *ueq;
619
620         if (usb_nevents <= 0)
621                 return (0);
622         ueq = SIMPLEQ_FIRST(&usb_events);
623         *ue = ueq->ue;
624         SIMPLEQ_REMOVE_HEAD(&usb_events, ueq, next);
625         free(ueq, M_USBDEV);
626         usb_nevents--;
627         return (1);
628 }
629
630 void
631 usbd_add_event(int type, usbd_device_handle dev)
632 {
633         struct usb_event_q *ueq;
634         struct usb_event ue;
635         struct timeval thetime;
636         int s;
637
638         s = splusb();
639         if (++usb_nevents >= USB_MAX_EVENTS) {
640                 /* Too many queued events, drop an old one. */
641                 DPRINTF(("usb: event dropped\n"));
642                 (void)usb_get_next_event(&ue);
643         }
644         /* Don't want to wait here inside splusb() */
645         ueq = malloc(sizeof *ueq, M_USBDEV, M_NOWAIT);
646         if (ueq == NULL) {
647                 printf("usb: no memory, event dropped\n");
648                 splx(s);
649                 return;
650         }
651         ueq->ue.ue_type = type;
652         ueq->ue.u.ue_driver.ue_cookie = dev->cookie;
653         usbd_fill_deviceinfo(dev, &ueq->ue.u.ue_device);
654         microtime(&thetime);
655         TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time);
656         SIMPLEQ_INSERT_TAIL(&usb_events, ueq, next);
657         wakeup(&usb_events);
658         selwakeup(&usb_selevent);
659         if (usb_async_proc != NULL && usb_async_proc->td_proc)
660                 psignal(usb_async_proc->td_proc, SIGIO);
661         splx(s);
662 }
663
664 #if defined(__NetBSD__) || defined(__OpenBSD__)
665 int
666 usb_activate(device_ptr_t self, devact act)
667 {
668         struct usb_softc *sc = (struct usb_softc *)self;
669         usbd_device_handle dev = sc->sc_port.device;
670         int i, rv = 0;
671
672         switch (act) {
673         case DVACT_ACTIVATE:
674                 return (EOPNOTSUPP);
675                 break;
676
677         case DVACT_DEACTIVATE:
678                 sc->sc_dying = 1;
679                 if (dev && dev->cdesc && dev->subdevs) {
680                         for (i = 0; dev->subdevs[i]; i++)
681                                 rv |= config_deactivate(dev->subdevs[i]);
682                 }
683                 break;
684         }
685         return (rv);
686 }
687
688 int
689 usb_detach(device_ptr_t self, int flags)
690 {
691         struct usb_softc *sc = (struct usb_softc *)self;
692
693         DPRINTF(("usb_detach: start\n"));
694
695         sc->sc_dying = 1;
696
697         /* Make all devices disconnect. */
698         if (sc->sc_port.device)
699                 usb_disconnect_port(&sc->sc_port, self);
700
701         /* Kill off event thread. */
702         if (sc->sc_event_thread) {
703                 wakeup(&sc->sc_bus->needs_explore);
704                 if (tsleep(sc, 0, "usbdet", hz * 60))
705                         printf("%s: event thread didn't die\n",
706                                USBDEVNAME(sc->sc_dev));
707                 DPRINTF(("usb_detach: event thread dead\n"));
708         }
709
710         usbd_finish();
711         return (0);
712 }
713 #elif defined(__FreeBSD__)
714 int
715 usb_detach(device_t self)
716 {
717         DPRINTF(("%s: unload, prevented\n", USBDEVNAME(self)));
718
719         return (EINVAL);
720 }
721 #endif
722
723
724 #if defined(__FreeBSD__)
725 DRIVER_MODULE(usb, ohci, usb_driver, usb_devclass, 0, 0);
726 DRIVER_MODULE(usb, uhci, usb_driver, usb_devclass, 0, 0);
727 #endif