Home | History | Annotate | Line # | Download | only in usb
usb.c revision 1.12.4.1
      1  1.12.4.1   thorpej /*	$NetBSD: usb.c,v 1.12.4.1 1999/07/01 23:40:23 thorpej Exp $	*/
      2       1.1  augustss 
      3       1.1  augustss /*
      4       1.1  augustss  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1  augustss  * All rights reserved.
      6       1.1  augustss  *
      7       1.5  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8       1.5  augustss  * by Lennart Augustsson (augustss (at) carlstedt.se) at
      9       1.5  augustss  * Carlstedt Research & Technology.
     10       1.1  augustss  *
     11       1.1  augustss  * Redistribution and use in source and binary forms, with or without
     12       1.1  augustss  * modification, are permitted provided that the following conditions
     13       1.1  augustss  * are met:
     14       1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     15       1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     16       1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     18       1.1  augustss  *    documentation and/or other materials provided with the distribution.
     19       1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     20       1.1  augustss  *    must display the following acknowledgement:
     21       1.1  augustss  *        This product includes software developed by the NetBSD
     22       1.1  augustss  *        Foundation, Inc. and its contributors.
     23       1.1  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24       1.1  augustss  *    contributors may be used to endorse or promote products derived
     25       1.1  augustss  *    from this software without specific prior written permission.
     26       1.1  augustss  *
     27       1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28       1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29       1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30       1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31       1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32       1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33       1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34       1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35       1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36       1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37       1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     38       1.1  augustss  */
     39       1.1  augustss 
     40       1.1  augustss /*
     41       1.8  augustss  * USB specifications and other documentation can be found at
     42       1.8  augustss  * http://www.usb.org/developers/data/ and
     43       1.8  augustss  * http://www.usb.org/developers/index.html .
     44       1.1  augustss  */
     45       1.1  augustss 
     46       1.1  augustss #include <sys/param.h>
     47       1.1  augustss #include <sys/systm.h>
     48       1.1  augustss #include <sys/kernel.h>
     49       1.1  augustss #include <sys/malloc.h>
     50       1.7  augustss #if defined(__NetBSD__)
     51       1.1  augustss #include <sys/device.h>
     52  1.12.4.1   thorpej #include <sys/kthread.h>
     53       1.7  augustss #elif defined(__FreeBSD__)
     54       1.7  augustss #include <sys/module.h>
     55       1.7  augustss #include <sys/bus.h>
     56       1.7  augustss #include <sys/ioccom.h>
     57       1.7  augustss #include <sys/uio.h>
     58       1.7  augustss #include <sys/conf.h>
     59       1.7  augustss #endif
     60       1.1  augustss #include <sys/poll.h>
     61       1.1  augustss #include <sys/proc.h>
     62       1.1  augustss #include <sys/select.h>
     63       1.1  augustss 
     64       1.1  augustss #include <dev/usb/usb.h>
     65  1.12.4.1   thorpej #include <dev/usb/usbdi.h>
     66  1.12.4.1   thorpej #include <dev/usb/usbdi_util.h>
     67       1.1  augustss 
     68       1.7  augustss #if defined(__FreeBSD__)
     69       1.7  augustss MALLOC_DEFINE(M_USB, "USB", "USB");
     70       1.7  augustss MALLOC_DEFINE(M_USBDEV, "USBdev", "USB device");
     71  1.12.4.1   thorpej MALLOC_DEFINE(M_USBHC, "USBHC", "USB host controller");
     72       1.7  augustss 
     73       1.7  augustss #include "usb_if.h"
     74       1.7  augustss #endif /* defined(__FreeBSD__) */
     75       1.7  augustss 
     76       1.1  augustss #include <dev/usb/usbdivar.h>
     77       1.1  augustss #include <dev/usb/usb_quirks.h>
     78       1.1  augustss 
     79       1.1  augustss #ifdef USB_DEBUG
     80       1.1  augustss #define DPRINTF(x)	if (usbdebug) printf x
     81       1.1  augustss #define DPRINTFN(n,x)	if (usbdebug>(n)) printf x
     82       1.1  augustss int	usbdebug = 0;
     83       1.1  augustss int	uhcidebug;
     84       1.1  augustss int	ohcidebug;
     85       1.1  augustss #else
     86       1.1  augustss #define DPRINTF(x)
     87       1.1  augustss #define DPRINTFN(n,x)
     88       1.1  augustss #endif
     89       1.1  augustss 
     90       1.1  augustss #define USBUNIT(dev) (minor(dev))
     91       1.1  augustss 
     92       1.1  augustss struct usb_softc {
     93       1.7  augustss 	bdevice sc_dev;			/* base device */
     94       1.1  augustss 	usbd_bus_handle sc_bus;		/* USB controller */
     95       1.1  augustss 	struct usbd_port sc_port;	/* dummy port for root hub */
     96       1.1  augustss 	char sc_running;
     97       1.1  augustss 	char sc_exploring;
     98       1.1  augustss 	struct selinfo sc_consel;	/* waiting for connect change */
     99  1.12.4.1   thorpej 	int shutdown;
    100  1.12.4.1   thorpej 	struct proc *event_thread;
    101       1.1  augustss };
    102       1.1  augustss 
    103       1.7  augustss #if defined(__NetBSD__)
    104       1.1  augustss int usbopen __P((dev_t, int, int, struct proc *));
    105       1.1  augustss int usbclose __P((dev_t, int, int, struct proc *));
    106       1.1  augustss int usbioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
    107       1.1  augustss int usbpoll __P((dev_t, int, struct proc *));
    108       1.1  augustss 
    109       1.7  augustss #elif defined(__FreeBSD__)
    110       1.7  augustss d_open_t  usbopen;
    111       1.7  augustss d_close_t usbclose;
    112       1.7  augustss d_ioctl_t usbioctl;
    113       1.7  augustss int usbpoll __P((dev_t, int, struct proc *));
    114       1.7  augustss 
    115       1.7  augustss struct cdevsw usb_cdevsw = {
    116       1.7  augustss 	usbopen,     usbclose,    noread,         nowrite,
    117       1.7  augustss 	usbioctl,    nullstop,    nullreset,      nodevtotty,
    118       1.7  augustss 	usbpoll,     nommap,      nostrat,
    119       1.7  augustss 	"usb",        NULL,   -1
    120       1.7  augustss };
    121       1.7  augustss #endif
    122       1.7  augustss 
    123       1.1  augustss usbd_status usb_discover __P((struct usb_softc *));
    124  1.12.4.1   thorpej void	usb_create_event_thread __P((void *));
    125  1.12.4.1   thorpej void	usb_event_thread __P((void *));
    126       1.1  augustss 
    127      1.11  augustss USB_DECLARE_DRIVER_INIT(usb, DEVMETHOD(bus_print_child, usbd_print_child));
    128       1.1  augustss 
    129       1.7  augustss USB_MATCH(usb)
    130       1.1  augustss {
    131       1.1  augustss 	DPRINTF(("usbd_match\n"));
    132       1.7  augustss 	return (UMATCH_GENERIC);
    133       1.1  augustss }
    134       1.1  augustss 
    135       1.7  augustss USB_ATTACH(usb)
    136       1.1  augustss {
    137       1.7  augustss #if defined(__NetBSD__)
    138       1.1  augustss 	struct usb_softc *sc = (struct usb_softc *)self;
    139       1.7  augustss #elif defined(__FreeBSD__)
    140      1.11  augustss 	struct usb_softc *sc = device_get_softc(self);
    141      1.11  augustss 	void *aux = device_get_ivars(self);
    142       1.7  augustss #endif
    143       1.1  augustss 	usbd_device_handle dev;
    144       1.1  augustss 	usbd_status r;
    145       1.1  augustss 
    146       1.7  augustss #if defined(__NetBSD__)
    147       1.4  augustss 	printf("\n");
    148       1.7  augustss #elif defined(__FreeBSD__)
    149      1.11  augustss 	sc->sc_dev = self;
    150       1.7  augustss #endif
    151       1.4  augustss 
    152       1.1  augustss 	DPRINTF(("usbd_attach\n"));
    153       1.4  augustss 	usbd_init();
    154       1.1  augustss 	sc->sc_bus = aux;
    155       1.1  augustss 	sc->sc_bus->usbctl = sc;
    156       1.1  augustss 	sc->sc_running = 1;
    157       1.3  augustss 	sc->sc_bus->use_polling = 1;
    158       1.1  augustss 	sc->sc_port.power = USB_MAX_POWER;
    159  1.12.4.1   thorpej 	r = usbd_new_device(&sc->sc_dev, sc->sc_bus, 0,0,0, &sc->sc_port);
    160       1.7  augustss 
    161       1.1  augustss 	if (r == USBD_NORMAL_COMPLETION) {
    162       1.1  augustss 		dev = sc->sc_port.device;
    163       1.1  augustss 		if (!dev->hub) {
    164       1.1  augustss 			sc->sc_running = 0;
    165       1.7  augustss 			printf("%s: root device is not a hub\n",
    166       1.7  augustss 			       USBDEVNAME(sc->sc_dev));
    167       1.7  augustss 			USB_ATTACH_ERROR_RETURN;
    168       1.1  augustss 		}
    169       1.1  augustss 		sc->sc_bus->root_hub = dev;
    170       1.7  augustss 		dev->hub->explore(sc->sc_bus->root_hub);
    171       1.1  augustss 	} else {
    172       1.1  augustss 		printf("%s: root hub problem, error=%d\n",
    173       1.7  augustss 		       USBDEVNAME(sc->sc_dev), r);
    174       1.1  augustss 		sc->sc_running = 0;
    175       1.1  augustss 	}
    176       1.3  augustss 	sc->sc_bus->use_polling = 0;
    177       1.7  augustss 
    178  1.12.4.1   thorpej 	kthread_create_deferred(usb_create_event_thread, sc);
    179  1.12.4.1   thorpej 
    180       1.7  augustss 	USB_ATTACH_SUCCESS_RETURN;
    181       1.1  augustss }
    182       1.1  augustss 
    183  1.12.4.1   thorpej void
    184  1.12.4.1   thorpej usb_create_event_thread(arg)
    185  1.12.4.1   thorpej 	void *arg;
    186  1.12.4.1   thorpej {
    187  1.12.4.1   thorpej 	struct usb_softc *sc = arg;
    188  1.12.4.1   thorpej 
    189  1.12.4.1   thorpej 	if (kthread_create(usb_event_thread, sc, &sc->event_thread,
    190  1.12.4.1   thorpej 			   "%s", sc->sc_dev.dv_xname)) {
    191  1.12.4.1   thorpej 		printf("%s: unable to create event thread for\n",
    192  1.12.4.1   thorpej 		       sc->sc_dev.dv_xname);
    193  1.12.4.1   thorpej 		panic("usb_create_event_thread");
    194  1.12.4.1   thorpej 	}
    195  1.12.4.1   thorpej }
    196  1.12.4.1   thorpej 
    197  1.12.4.1   thorpej void
    198  1.12.4.1   thorpej usb_event_thread(arg)
    199  1.12.4.1   thorpej 	void *arg;
    200  1.12.4.1   thorpej {
    201  1.12.4.1   thorpej 	struct usb_softc *sc = arg;
    202  1.12.4.1   thorpej 
    203  1.12.4.1   thorpej 	while (!sc->shutdown) {
    204  1.12.4.1   thorpej 		(void)tsleep(&sc->sc_bus->needs_explore,
    205  1.12.4.1   thorpej 			     PWAIT, "usbevt", hz*30);
    206  1.12.4.1   thorpej 		DPRINTFN(2,("usb_event_thread: woke up\n"));
    207  1.12.4.1   thorpej 		usb_discover(sc);
    208  1.12.4.1   thorpej 	}
    209  1.12.4.1   thorpej 	sc->event_thread = 0;
    210  1.12.4.1   thorpej 
    211  1.12.4.1   thorpej 	/* In case parent is waiting for us to exit. */
    212  1.12.4.1   thorpej 	wakeup(sc);
    213  1.12.4.1   thorpej 
    214  1.12.4.1   thorpej 	kthread_exit(0);
    215  1.12.4.1   thorpej }
    216  1.12.4.1   thorpej 
    217       1.7  augustss #if defined(__NetBSD__)
    218       1.1  augustss int
    219       1.1  augustss usbctlprint(aux, pnp)
    220       1.1  augustss 	void *aux;
    221       1.1  augustss 	const char *pnp;
    222       1.1  augustss {
    223       1.1  augustss 	/* only "usb"es can attach to host controllers */
    224       1.1  augustss 	if (pnp)
    225       1.1  augustss 		printf("usb at %s", pnp);
    226       1.1  augustss 
    227       1.1  augustss 	return (UNCONF);
    228       1.1  augustss }
    229       1.7  augustss #endif
    230       1.7  augustss 
    231       1.1  augustss int
    232       1.1  augustss usbopen(dev, flag, mode, p)
    233       1.1  augustss 	dev_t dev;
    234       1.1  augustss 	int flag, mode;
    235       1.1  augustss 	struct proc *p;
    236       1.1  augustss {
    237       1.7  augustss 	USB_GET_SC_OPEN(usb, USBUNIT(dev), sc);
    238       1.1  augustss 
    239       1.1  augustss 	if (sc == 0 || !sc->sc_running)
    240       1.1  augustss 		return (ENXIO);
    241       1.1  augustss 
    242       1.1  augustss 	return (0);
    243       1.1  augustss }
    244       1.1  augustss 
    245       1.1  augustss int
    246       1.1  augustss usbclose(dev, flag, mode, p)
    247       1.1  augustss 	dev_t dev;
    248       1.1  augustss 	int flag, mode;
    249       1.1  augustss 	struct proc *p;
    250       1.1  augustss {
    251       1.1  augustss 	return (0);
    252       1.1  augustss }
    253       1.1  augustss 
    254       1.1  augustss int
    255       1.1  augustss usbioctl(dev, cmd, data, flag, p)
    256       1.1  augustss 	dev_t dev;
    257       1.1  augustss 	u_long cmd;
    258       1.1  augustss 	caddr_t data;
    259       1.1  augustss 	int flag;
    260       1.1  augustss 	struct proc *p;
    261       1.1  augustss {
    262       1.7  augustss 	USB_GET_SC(usb, USBUNIT(dev), sc);
    263       1.1  augustss 
    264       1.1  augustss 	if (sc == 0 || !sc->sc_running)
    265       1.1  augustss 		return (ENXIO);
    266       1.1  augustss 	switch (cmd) {
    267       1.1  augustss #ifdef USB_DEBUG
    268       1.1  augustss 	case USB_SETDEBUG:
    269       1.1  augustss 		usbdebug = uhcidebug = ohcidebug = *(int *)data;
    270       1.1  augustss 		break;
    271       1.1  augustss #endif
    272  1.12.4.1   thorpej #if 0
    273       1.1  augustss 	case USB_DISCOVER:
    274       1.1  augustss 		usb_discover(sc);
    275       1.1  augustss 		break;
    276  1.12.4.1   thorpej #endif
    277       1.1  augustss 	case USB_REQUEST:
    278       1.1  augustss 	{
    279       1.1  augustss 		struct usb_ctl_request *ur = (void *)data;
    280       1.1  augustss 		int len = UGETW(ur->request.wLength);
    281       1.1  augustss 		struct iovec iov;
    282       1.1  augustss 		struct uio uio;
    283       1.1  augustss 		void *ptr = 0;
    284       1.1  augustss 		int addr = ur->addr;
    285       1.1  augustss 		usbd_status r;
    286       1.1  augustss 		int error = 0;
    287       1.1  augustss 
    288       1.9  augustss 		DPRINTF(("usbioctl: USB_REQUEST addr=%d len=%d\n", addr, len));
    289       1.1  augustss 		if (len < 0 || len > 32768)
    290       1.9  augustss 			return (EINVAL);
    291       1.1  augustss 		if (addr < 0 || addr >= USB_MAX_DEVICES ||
    292       1.1  augustss 		    sc->sc_bus->devices[addr] == 0)
    293       1.9  augustss 			return (EINVAL);
    294       1.1  augustss 		if (len != 0) {
    295       1.1  augustss 			iov.iov_base = (caddr_t)ur->data;
    296       1.1  augustss 			iov.iov_len = len;
    297       1.1  augustss 			uio.uio_iov = &iov;
    298       1.1  augustss 			uio.uio_iovcnt = 1;
    299       1.1  augustss 			uio.uio_resid = len;
    300       1.1  augustss 			uio.uio_offset = 0;
    301       1.1  augustss 			uio.uio_segflg = UIO_USERSPACE;
    302       1.1  augustss 			uio.uio_rw =
    303       1.1  augustss 				ur->request.bmRequestType & UT_READ ?
    304       1.1  augustss 				UIO_READ : UIO_WRITE;
    305       1.1  augustss 			uio.uio_procp = p;
    306       1.1  augustss 			ptr = malloc(len, M_TEMP, M_WAITOK);
    307       1.1  augustss 			if (uio.uio_rw == UIO_WRITE) {
    308       1.1  augustss 				error = uiomove(ptr, len, &uio);
    309       1.1  augustss 				if (error)
    310       1.1  augustss 					goto ret;
    311       1.1  augustss 			}
    312       1.1  augustss 		}
    313       1.9  augustss 		r = usbd_do_request_flags(sc->sc_bus->devices[addr],
    314      1.10  augustss 					  &ur->request, ptr,
    315      1.10  augustss 					  ur->flags, &ur->actlen);
    316       1.1  augustss 		if (r) {
    317       1.1  augustss 			error = EIO;
    318       1.1  augustss 			goto ret;
    319       1.1  augustss 		}
    320       1.1  augustss 		if (len != 0) {
    321       1.1  augustss 			if (uio.uio_rw == UIO_READ) {
    322       1.1  augustss 				error = uiomove(ptr, len, &uio);
    323       1.1  augustss 				if (error)
    324       1.1  augustss 					goto ret;
    325       1.1  augustss 			}
    326       1.1  augustss 		}
    327       1.1  augustss 	ret:
    328       1.1  augustss 		if (ptr)
    329       1.1  augustss 			free(ptr, M_TEMP);
    330       1.1  augustss 		return (error);
    331       1.1  augustss 	}
    332       1.1  augustss 
    333       1.1  augustss 	case USB_DEVICEINFO:
    334       1.1  augustss 	{
    335       1.1  augustss 		struct usb_device_info *di = (void *)data;
    336       1.1  augustss 		int addr = di->addr;
    337       1.1  augustss 		usbd_device_handle dev;
    338       1.1  augustss 
    339       1.1  augustss 		if (addr < 1 || addr >= USB_MAX_DEVICES)
    340       1.1  augustss 			return (EINVAL);
    341       1.1  augustss 		dev = sc->sc_bus->devices[addr];
    342       1.1  augustss 		if (dev == 0)
    343       1.1  augustss 			return (ENXIO);
    344       1.6  augustss 		usbd_fill_deviceinfo(dev, di);
    345       1.1  augustss 		break;
    346       1.1  augustss 	}
    347       1.2  augustss 
    348       1.2  augustss 	case USB_DEVICESTATS:
    349       1.2  augustss 		*(struct usb_device_stats *)data = sc->sc_bus->stats;
    350       1.2  augustss 		break;
    351       1.1  augustss 
    352       1.1  augustss 	default:
    353       1.1  augustss 		return (ENXIO);
    354       1.1  augustss 	}
    355       1.1  augustss 	return (0);
    356       1.1  augustss }
    357       1.1  augustss 
    358       1.1  augustss int
    359       1.1  augustss usbpoll(dev, events, p)
    360       1.1  augustss 	dev_t dev;
    361       1.1  augustss 	int events;
    362       1.1  augustss 	struct proc *p;
    363       1.1  augustss {
    364       1.1  augustss 	int revents, s;
    365       1.7  augustss 	USB_GET_SC(usb, USBUNIT(dev), sc);
    366       1.1  augustss 
    367       1.1  augustss 	DPRINTFN(2, ("usbpoll: sc=%p events=0x%x\n", sc, events));
    368       1.1  augustss 	s = splusb();
    369       1.1  augustss 	revents = 0;
    370       1.1  augustss 	if (events & (POLLOUT | POLLWRNORM))
    371       1.1  augustss 		if (sc->sc_bus->needs_explore)
    372       1.1  augustss 			revents |= events & (POLLOUT | POLLWRNORM);
    373       1.1  augustss 	DPRINTFN(2, ("usbpoll: revents=0x%x\n", revents));
    374       1.1  augustss 	if (revents == 0) {
    375       1.1  augustss 		if (events & (POLLOUT | POLLWRNORM)) {
    376       1.1  augustss 			DPRINTFN(2, ("usbpoll: selrecord\n"));
    377       1.1  augustss 			selrecord(p, &sc->sc_consel);
    378       1.1  augustss 		}
    379       1.1  augustss 	}
    380       1.1  augustss 	splx(s);
    381       1.1  augustss 	return (revents);
    382       1.1  augustss }
    383       1.1  augustss 
    384      1.11  augustss #if 0
    385       1.1  augustss int
    386       1.1  augustss usb_bus_count()
    387       1.1  augustss {
    388       1.1  augustss 	int i, n;
    389       1.1  augustss 
    390       1.1  augustss 	for (i = n = 0; i < usb_cd.cd_ndevs; i++)
    391       1.1  augustss 		if (usb_cd.cd_devs[i])
    392       1.1  augustss 			n++;
    393       1.1  augustss 	return (n);
    394       1.1  augustss }
    395      1.11  augustss #endif
    396       1.1  augustss 
    397      1.12  augustss #if 0
    398       1.1  augustss usbd_status
    399       1.1  augustss usb_get_bus_handle(n, h)
    400       1.1  augustss 	int n;
    401       1.1  augustss 	usbd_bus_handle *h;
    402       1.1  augustss {
    403       1.1  augustss 	int i;
    404       1.1  augustss 
    405       1.1  augustss 	for (i = 0; i < usb_cd.cd_ndevs; i++)
    406       1.1  augustss 		if (usb_cd.cd_devs[i] && n-- == 0) {
    407       1.1  augustss 			*h = usb_cd.cd_devs[i];
    408       1.1  augustss 			return (USBD_NORMAL_COMPLETION);
    409       1.1  augustss 		}
    410       1.1  augustss 	return (USBD_INVAL);
    411       1.1  augustss }
    412      1.12  augustss #endif
    413       1.1  augustss 
    414       1.1  augustss usbd_status
    415       1.1  augustss usb_discover(sc)
    416       1.1  augustss 	struct usb_softc *sc;
    417       1.1  augustss {
    418       1.1  augustss 	int s;
    419       1.1  augustss 
    420       1.1  augustss 	/* Explore device tree from the root */
    421       1.1  augustss 	/* We need mutual exclusion while traversing the device tree. */
    422  1.12.4.1   thorpej 	do {
    423  1.12.4.1   thorpej 		s = splusb();
    424  1.12.4.1   thorpej 		while (sc->sc_exploring)
    425  1.12.4.1   thorpej 			tsleep(&sc->sc_exploring, PRIBIO, "usbdis", 0);
    426  1.12.4.1   thorpej 		sc->sc_exploring = 1;
    427  1.12.4.1   thorpej 		sc->sc_bus->needs_explore = 0;
    428  1.12.4.1   thorpej 		splx(s);
    429  1.12.4.1   thorpej 
    430  1.12.4.1   thorpej 		sc->sc_bus->root_hub->hub->explore(sc->sc_bus->root_hub);
    431  1.12.4.1   thorpej 
    432  1.12.4.1   thorpej 		s = splusb();
    433  1.12.4.1   thorpej 		sc->sc_exploring = 0;
    434  1.12.4.1   thorpej 		wakeup(&sc->sc_exploring);
    435  1.12.4.1   thorpej 		splx(s);
    436  1.12.4.1   thorpej 	} while (sc->sc_bus->needs_explore);
    437  1.12.4.1   thorpej 	return (USBD_NORMAL_COMPLETION);
    438       1.1  augustss }
    439       1.1  augustss 
    440       1.1  augustss void
    441       1.1  augustss usb_needs_explore(bus)
    442       1.1  augustss 	usbd_bus_handle bus;
    443       1.1  augustss {
    444       1.1  augustss 	bus->needs_explore = 1;
    445       1.1  augustss 	selwakeup(&bus->usbctl->sc_consel);
    446  1.12.4.1   thorpej 	wakeup(&bus->needs_explore);
    447       1.1  augustss }
    448       1.7  augustss 
    449       1.7  augustss int
    450  1.12.4.1   thorpej usb_activate(self, act)
    451  1.12.4.1   thorpej 	struct device *self;
    452  1.12.4.1   thorpej 	enum devact act;
    453       1.7  augustss {
    454  1.12.4.1   thorpej 	panic("usb_activate\n");
    455  1.12.4.1   thorpej 	return (0);
    456  1.12.4.1   thorpej }
    457       1.7  augustss 
    458  1.12.4.1   thorpej int
    459  1.12.4.1   thorpej usb_detach(self, flags)
    460  1.12.4.1   thorpej 	struct device  *self;
    461  1.12.4.1   thorpej 	int flags;
    462  1.12.4.1   thorpej {
    463  1.12.4.1   thorpej 	panic("usb_detach\n");
    464       1.7  augustss 	return (0);
    465       1.7  augustss }
    466       1.7  augustss 
    467  1.12.4.1   thorpej #if defined(__FreeBSD__)
    468       1.7  augustss DRIVER_MODULE(usb, root, usb_driver, usb_devclass, 0, 0);
    469       1.7  augustss #endif
    470