2003-01-01 03:10:15 +03:00
|
|
|
/* $NetBSD: usb.c,v 1.77 2003/01/01 00:10:26 thorpej Exp $ */
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
/*
|
2002-01-02 23:55:58 +03:00
|
|
|
* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
|
1998-07-12 23:51:55 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-11-26 01:32:04 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-04-27 19:26:44 +04:00
|
|
|
* by Lennart Augustsson (lennart@augustsson.net) at
|
1998-11-26 01:32:04 +03:00
|
|
|
* Carlstedt Research & Technology.
|
1998-07-12 23:51:55 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1998-12-28 05:20:28 +03:00
|
|
|
* USB specifications and other documentation can be found at
|
|
|
|
* http://www.usb.org/developers/data/ and
|
|
|
|
* http://www.usb.org/developers/index.html .
|
1998-07-12 23:51:55 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 09:24:53 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-01-01 03:10:15 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.77 2003/01/01 00:10:26 thorpej Exp $");
|
2002-12-30 05:44:32 +03:00
|
|
|
|
|
|
|
#include "ohci.h"
|
|
|
|
#include "uhci.h"
|
2001-11-13 09:24:53 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/device.h>
|
1999-06-30 10:44:22 +04:00
|
|
|
#include <sys/kthread.h>
|
1999-11-19 02:32:25 +03:00
|
|
|
#include <sys/proc.h>
|
1999-09-15 14:25:30 +04:00
|
|
|
#include <sys/conf.h>
|
2002-04-23 10:34:11 +04:00
|
|
|
#include <sys/fcntl.h>
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/select.h>
|
1999-10-12 15:54:56 +04:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/signalvar.h>
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
1999-06-30 10:44:22 +04:00
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-10-12 15:54:56 +04:00
|
|
|
#define USB_DEV_MINOR 255
|
|
|
|
|
1999-09-13 23:18:17 +04:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <dev/usb/usbdivar.h>
|
|
|
|
#include <dev/usb/usb_quirks.h>
|
|
|
|
|
|
|
|
#ifdef USB_DEBUG
|
1999-08-14 18:49:31 +04:00
|
|
|
#define DPRINTF(x) if (usbdebug) logprintf x
|
|
|
|
#define DPRINTFN(n,x) if (usbdebug>(n)) logprintf x
|
1998-07-12 23:51:55 +04:00
|
|
|
int usbdebug = 0;
|
2002-12-30 05:44:32 +03:00
|
|
|
#if defined(UHCI_DEBUG) && NUHCI > 0
|
|
|
|
extern int uhcidebug;
|
1999-11-19 02:32:25 +03:00
|
|
|
#endif
|
2002-12-30 05:44:32 +03:00
|
|
|
#if defined(OHCI_DEBUG) && NOHCI > 0
|
|
|
|
extern int ohcidebug;
|
1999-11-19 02:32:25 +03:00
|
|
|
#endif
|
2002-02-03 21:15:20 +03:00
|
|
|
/*
|
1999-11-26 04:41:03 +03:00
|
|
|
* 0 - do usual exploration
|
|
|
|
* 1 - do not use timeout exploration
|
|
|
|
* >1 - do no exploration
|
|
|
|
*/
|
1999-09-14 01:33:25 +04:00
|
|
|
int usb_noexplore = 0;
|
1998-07-12 23:51:55 +04:00
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct usb_softc {
|
1999-09-15 14:25:30 +04:00
|
|
|
USBBASEDEVICE sc_dev; /* base device */
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_bus_handle sc_bus; /* USB controller */
|
|
|
|
struct usbd_port sc_port; /* dummy port for root hub */
|
1999-09-18 15:25:50 +04:00
|
|
|
|
2002-01-03 01:44:44 +03:00
|
|
|
struct proc *sc_event_thread;
|
1999-09-18 15:25:50 +04:00
|
|
|
|
|
|
|
char sc_dying;
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
2001-11-21 02:53:26 +03:00
|
|
|
TAILQ_HEAD(, usb_task) usb_all_tasks;
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(usbopen);
|
|
|
|
dev_type_close(usbclose);
|
|
|
|
dev_type_read(usbread);
|
|
|
|
dev_type_ioctl(usbioctl);
|
|
|
|
dev_type_poll(usbpoll);
|
2002-10-23 13:10:23 +04:00
|
|
|
dev_type_kqfilter(usbkqfilter);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
const struct cdevsw usb_cdevsw = {
|
|
|
|
usbopen, usbclose, usbread, nowrite, usbioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, usbpoll, nommap, usbkqfilter,
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2001-01-21 22:00:06 +03:00
|
|
|
Static void usb_discover(void *);
|
2000-06-01 18:28:57 +04:00
|
|
|
Static void usb_create_event_thread(void *);
|
|
|
|
Static void usb_event_thread(void *);
|
2001-11-21 02:53:26 +03:00
|
|
|
Static void usb_task_thread(void *);
|
2002-01-03 01:44:44 +03:00
|
|
|
Static struct proc *usb_task_thread_proc = NULL;
|
1998-12-26 15:53:00 +03:00
|
|
|
|
2000-03-16 03:46:38 +03:00
|
|
|
#define USB_MAX_EVENTS 100
|
1999-10-12 15:54:56 +04:00
|
|
|
struct usb_event_q {
|
|
|
|
struct usb_event ue;
|
|
|
|
SIMPLEQ_ENTRY(usb_event_q) next;
|
|
|
|
};
|
2002-02-03 21:15:20 +03:00
|
|
|
Static SIMPLEQ_HEAD(, usb_event_q) usb_events =
|
1999-11-12 03:34:57 +03:00
|
|
|
SIMPLEQ_HEAD_INITIALIZER(usb_events);
|
2000-03-27 16:33:53 +04:00
|
|
|
Static int usb_nevents = 0;
|
|
|
|
Static struct selinfo usb_selevent;
|
2001-12-31 15:15:21 +03:00
|
|
|
Static usb_proc_ptr usb_async_proc; /* process that wants USB SIGIO */
|
2000-03-27 16:33:53 +04:00
|
|
|
Static int usb_dev_open = 0;
|
2000-06-01 18:28:57 +04:00
|
|
|
Static void usb_add_event(int, struct usb_event *);
|
1999-10-12 15:54:56 +04:00
|
|
|
|
2000-06-01 18:28:57 +04:00
|
|
|
Static int usb_get_next_event(struct usb_event *);
|
1999-10-12 15:54:56 +04:00
|
|
|
|
2000-03-27 16:33:53 +04:00
|
|
|
Static const char *usbrev_str[] = USBREV_STR;
|
1999-11-20 03:57:08 +03:00
|
|
|
|
1999-10-13 12:10:55 +04:00
|
|
|
USB_DECLARE_DRIVER(usb);
|
1998-12-26 15:53:00 +03:00
|
|
|
|
|
|
|
USB_MATCH(usb)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
|
|
|
DPRINTF(("usbd_match\n"));
|
1998-12-26 15:53:00 +03:00
|
|
|
return (UMATCH_GENERIC);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH(usb)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
|
|
|
struct usb_softc *sc = (struct usb_softc *)self;
|
|
|
|
usbd_device_handle dev;
|
1999-11-12 03:34:57 +03:00
|
|
|
usbd_status err;
|
1999-11-20 03:57:08 +03:00
|
|
|
int usbrev;
|
2001-11-20 16:48:03 +03:00
|
|
|
int speed;
|
2000-02-02 10:33:59 +03:00
|
|
|
struct usb_event ue;
|
2002-02-03 21:15:20 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
DPRINTF(("usbd_attach\n"));
|
1999-11-20 03:57:08 +03:00
|
|
|
|
1998-09-22 00:47:25 +04:00
|
|
|
usbd_init();
|
1998-07-12 23:51:55 +04:00
|
|
|
sc->sc_bus = aux;
|
|
|
|
sc->sc_bus->usbctl = sc;
|
|
|
|
sc->sc_port.power = USB_MAX_POWER;
|
1999-11-20 03:57:08 +03:00
|
|
|
|
|
|
|
usbrev = sc->sc_bus->usbrev;
|
1999-11-20 04:15:25 +03:00
|
|
|
printf(": USB revision %s", usbrev_str[usbrev]);
|
2001-11-20 16:48:03 +03:00
|
|
|
switch (usbrev) {
|
|
|
|
case USBREV_1_0:
|
|
|
|
case USBREV_1_1:
|
|
|
|
speed = USB_SPEED_FULL;
|
|
|
|
break;
|
|
|
|
case USBREV_2_0:
|
|
|
|
speed = USB_SPEED_HIGH;
|
|
|
|
break;
|
|
|
|
default:
|
1999-11-20 03:57:08 +03:00
|
|
|
printf(", not supported\n");
|
2001-11-20 16:48:03 +03:00
|
|
|
sc->sc_dying = 1;
|
1999-11-20 03:57:08 +03:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1999-11-20 04:15:25 +03:00
|
|
|
}
|
|
|
|
printf("\n");
|
1999-11-20 03:57:08 +03:00
|
|
|
|
1999-12-20 05:12:23 +03:00
|
|
|
/* Make sure not to use tsleep() if we are cold booting. */
|
|
|
|
if (cold)
|
|
|
|
sc->sc_bus->use_polling++;
|
|
|
|
|
2000-02-02 10:33:59 +03:00
|
|
|
ue.u.ue_ctrlr.ue_bus = USBDEVUNIT(sc->sc_dev);
|
|
|
|
usb_add_event(USB_EVENT_CTRLR_ATTACH, &ue);
|
|
|
|
|
2001-01-21 05:39:52 +03:00
|
|
|
#ifdef USB_USE_SOFTINTR
|
|
|
|
#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
|
|
|
|
/* XXX we should have our own level */
|
2002-02-03 21:15:20 +03:00
|
|
|
sc->sc_bus->soft = softintr_establish(IPL_SOFTNET,
|
2001-01-21 05:39:52 +03:00
|
|
|
sc->sc_bus->methods->soft_intr, sc->sc_bus);
|
|
|
|
if (sc->sc_bus->soft == NULL) {
|
|
|
|
printf("%s: can't register softintr\n", USBDEVNAME(sc->sc_dev));
|
|
|
|
sc->sc_dying = 1;
|
2001-11-20 16:48:03 +03:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
2001-01-21 05:39:52 +03:00
|
|
|
}
|
|
|
|
#else
|
2002-05-10 01:54:32 +04:00
|
|
|
usb_callout_init(sc->sc_bus->softi);
|
2001-01-21 05:39:52 +03:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2001-11-20 16:48:03 +03:00
|
|
|
err = usbd_new_device(USBDEV(sc->sc_dev), sc->sc_bus, 0, speed, 0,
|
1999-11-12 03:34:57 +03:00
|
|
|
&sc->sc_port);
|
|
|
|
if (!err) {
|
1998-07-12 23:51:55 +04:00
|
|
|
dev = sc->sc_port.device;
|
1999-11-12 03:34:57 +03:00
|
|
|
if (dev->hub == NULL) {
|
1999-09-15 14:25:30 +04:00
|
|
|
sc->sc_dying = 1;
|
2002-02-03 21:15:20 +03:00
|
|
|
printf("%s: root device is not a hub\n",
|
1998-12-26 15:53:00 +03:00
|
|
|
USBDEVNAME(sc->sc_dev));
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
sc->sc_bus->root_hub = dev;
|
1999-09-16 01:10:11 +04:00
|
|
|
#if 1
|
2002-02-03 21:15:20 +03:00
|
|
|
/*
|
1999-09-16 01:10:11 +04:00
|
|
|
* Turning this code off will delay attachment of USB devices
|
|
|
|
* until the USB event thread is running, which means that
|
|
|
|
* the keyboard will not work until after cold boot.
|
|
|
|
*/
|
1999-12-23 02:54:09 +03:00
|
|
|
if (cold && (sc->sc_dev.dv_cfdata->cf_flags & 1))
|
1999-09-16 01:10:11 +04:00
|
|
|
dev->hub->explore(sc->sc_bus->root_hub);
|
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
} else {
|
2002-02-03 21:15:20 +03:00
|
|
|
printf("%s: root hub problem, error=%d\n",
|
|
|
|
USBDEVNAME(sc->sc_dev), err);
|
1999-09-15 14:25:30 +04:00
|
|
|
sc->sc_dying = 1;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
1999-12-20 05:12:23 +03:00
|
|
|
if (cold)
|
|
|
|
sc->sc_bus->use_polling--;
|
1998-12-26 15:53:00 +03:00
|
|
|
|
2000-01-24 21:35:51 +03:00
|
|
|
config_pending_incr();
|
2000-03-29 22:24:52 +04:00
|
|
|
usb_kthread_create(usb_create_event_thread, sc);
|
1999-10-13 12:10:55 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_SUCCESS_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1999-10-13 12:10:55 +04:00
|
|
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
1999-06-30 10:44:22 +04:00
|
|
|
void
|
2000-06-01 18:28:57 +04:00
|
|
|
usb_create_event_thread(void *arg)
|
1999-06-30 10:44:22 +04:00
|
|
|
{
|
|
|
|
struct usb_softc *sc = arg;
|
2001-11-21 02:53:26 +03:00
|
|
|
static int created = 0;
|
1999-06-30 10:44:22 +04:00
|
|
|
|
2000-03-29 22:24:52 +04:00
|
|
|
if (usb_kthread_create1(usb_event_thread, sc, &sc->sc_event_thread,
|
1999-06-30 10:44:22 +04:00
|
|
|
"%s", sc->sc_dev.dv_xname)) {
|
|
|
|
printf("%s: unable to create event thread for\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
panic("usb_create_event_thread");
|
|
|
|
}
|
2001-11-21 02:53:26 +03:00
|
|
|
if (!created) {
|
|
|
|
created = 1;
|
|
|
|
TAILQ_INIT(&usb_all_tasks);
|
|
|
|
if (usb_kthread_create1(usb_task_thread, NULL,
|
|
|
|
&usb_task_thread_proc, "usbtask")) {
|
|
|
|
printf("unable to create task thread\n");
|
|
|
|
panic("usb_create_event_thread task");
|
|
|
|
}
|
|
|
|
}
|
1999-06-30 10:44:22 +04:00
|
|
|
}
|
|
|
|
|
2001-01-21 22:00:29 +03:00
|
|
|
/*
|
2002-01-02 23:55:58 +03:00
|
|
|
* Add a task to be performed by the task thread. This function can be
|
2001-01-21 22:00:29 +03:00
|
|
|
* called from any context and the task will be executed in a process
|
|
|
|
* context ASAP.
|
|
|
|
*/
|
2001-01-21 22:00:06 +03:00
|
|
|
void
|
|
|
|
usb_add_task(usbd_device_handle dev, struct usb_task *task)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
if (!task->onqueue) {
|
2001-11-21 02:53:26 +03:00
|
|
|
DPRINTFN(2,("usb_add_task: task=%p\n", task));
|
|
|
|
TAILQ_INSERT_TAIL(&usb_all_tasks, task, next);
|
2001-01-21 22:00:06 +03:00
|
|
|
task->onqueue = 1;
|
2002-01-02 23:55:58 +03:00
|
|
|
} else {
|
2001-11-21 02:53:26 +03:00
|
|
|
DPRINTFN(3,("usb_add_task: task=%p on q\n", task));
|
2002-01-02 23:55:58 +03:00
|
|
|
}
|
2001-11-21 02:53:26 +03:00
|
|
|
wakeup(&usb_all_tasks);
|
2001-01-21 22:00:06 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
2001-01-23 20:04:30 +03:00
|
|
|
void
|
|
|
|
usb_rem_task(usbd_device_handle dev, struct usb_task *task)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
if (task->onqueue) {
|
2001-11-21 02:53:26 +03:00
|
|
|
TAILQ_REMOVE(&usb_all_tasks, task, next);
|
2001-01-23 20:04:30 +03:00
|
|
|
task->onqueue = 0;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
void
|
2000-06-01 18:28:57 +04:00
|
|
|
usb_event_thread(void *arg)
|
1999-06-30 10:44:22 +04:00
|
|
|
{
|
|
|
|
struct usb_softc *sc = arg;
|
|
|
|
|
1999-10-13 00:02:47 +04:00
|
|
|
DPRINTF(("usb_event_thread: start\n"));
|
|
|
|
|
2001-12-31 15:15:21 +03:00
|
|
|
/*
|
|
|
|
* In case this controller is a companion controller to an
|
|
|
|
* EHCI controller we need to wait until the EHCI controller
|
|
|
|
* has grabbed the port.
|
2002-01-03 01:44:44 +03:00
|
|
|
* XXX It would be nicer to do this with a tsleep(), but I don't
|
|
|
|
* know how to synchronize the creation of the threads so it
|
|
|
|
* will work.
|
2001-12-31 15:15:21 +03:00
|
|
|
*/
|
2001-12-31 18:55:51 +03:00
|
|
|
usb_delay_ms(sc->sc_bus, 500);
|
2001-12-31 15:15:21 +03:00
|
|
|
|
2000-03-15 02:13:12 +03:00
|
|
|
/* Make sure first discover does something. */
|
|
|
|
sc->sc_bus->needs_explore = 1;
|
2001-01-21 22:00:06 +03:00
|
|
|
usb_discover(sc);
|
|
|
|
config_pending_decr();
|
2000-03-15 02:13:12 +03:00
|
|
|
|
1999-09-15 14:25:30 +04:00
|
|
|
while (!sc->sc_dying) {
|
2001-11-21 02:53:26 +03:00
|
|
|
#ifdef USB_DEBUG
|
|
|
|
if (usb_noexplore < 2)
|
|
|
|
#endif
|
|
|
|
usb_discover(sc);
|
|
|
|
#ifdef USB_DEBUG
|
|
|
|
(void)tsleep(&sc->sc_bus->needs_explore, PWAIT, "usbevt",
|
|
|
|
usb_noexplore ? 0 : hz * 60);
|
|
|
|
#else
|
|
|
|
(void)tsleep(&sc->sc_bus->needs_explore, PWAIT, "usbevt",
|
|
|
|
hz * 60);
|
|
|
|
#endif
|
|
|
|
DPRINTFN(2,("usb_event_thread: woke up\n"));
|
1999-06-30 10:44:22 +04:00
|
|
|
}
|
2001-01-21 19:55:11 +03:00
|
|
|
sc->sc_event_thread = NULL;
|
1999-06-30 10:44:22 +04:00
|
|
|
|
|
|
|
/* In case parent is waiting for us to exit. */
|
|
|
|
wakeup(sc);
|
|
|
|
|
1999-10-13 00:02:47 +04:00
|
|
|
DPRINTF(("usb_event_thread: exit\n"));
|
1999-06-30 10:44:22 +04:00
|
|
|
kthread_exit(0);
|
|
|
|
}
|
|
|
|
|
2001-11-21 02:53:26 +03:00
|
|
|
void
|
|
|
|
usb_task_thread(void *arg)
|
|
|
|
{
|
|
|
|
struct usb_task *task;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
DPRINTF(("usb_task_thread: start\n"));
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
for (;;) {
|
|
|
|
task = TAILQ_FIRST(&usb_all_tasks);
|
|
|
|
if (task == NULL) {
|
2001-11-26 23:16:55 +03:00
|
|
|
tsleep(&usb_all_tasks, PWAIT, "usbtsk", 0);
|
2001-11-21 02:53:26 +03:00
|
|
|
task = TAILQ_FIRST(&usb_all_tasks);
|
|
|
|
}
|
|
|
|
DPRINTFN(2,("usb_task_thread: woke up task=%p\n", task));
|
|
|
|
if (task != NULL) {
|
|
|
|
TAILQ_REMOVE(&usb_all_tasks, task, next);
|
|
|
|
task->onqueue = 0;
|
|
|
|
splx(s);
|
|
|
|
task->fun(task->arg);
|
|
|
|
s = splusb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
usbctlprint(void *aux, const char *pnp)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
|
|
|
/* only "usb"es can attach to host controllers */
|
|
|
|
if (pnp)
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("usb at %s", pnp);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
return (UNCONF);
|
|
|
|
}
|
1999-10-13 12:10:55 +04:00
|
|
|
#endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
|
1998-12-26 15:53:00 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
int
|
2001-12-31 15:15:21 +03:00
|
|
|
usbopen(dev_t dev, int flag, int mode, usb_proc_ptr p)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
1999-10-12 15:54:56 +04:00
|
|
|
int unit = minor(dev);
|
|
|
|
struct usb_softc *sc;
|
|
|
|
|
|
|
|
if (unit == USB_DEV_MINOR) {
|
|
|
|
if (usb_dev_open)
|
|
|
|
return (EBUSY);
|
|
|
|
usb_dev_open = 1;
|
|
|
|
usb_async_proc = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
USB_GET_SC_OPEN(usb, unit, sc);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-09-15 14:25:30 +04:00
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-10-12 15:54:56 +04:00
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
usbread(dev_t dev, struct uio *uio, int flag)
|
1999-10-12 15:54:56 +04:00
|
|
|
{
|
|
|
|
struct usb_event ue;
|
|
|
|
int s, error, n;
|
|
|
|
|
|
|
|
if (minor(dev) != USB_DEV_MINOR)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (uio->uio_resid != sizeof(struct usb_event))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
s = splusb();
|
|
|
|
for (;;) {
|
|
|
|
n = usb_get_next_event(&ue);
|
|
|
|
if (n != 0)
|
|
|
|
break;
|
|
|
|
if (flag & IO_NDELAY) {
|
|
|
|
error = EWOULDBLOCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = tsleep(&usb_events, PZERO | PCATCH, "usbrea", 0);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
if (!error)
|
1999-11-19 02:32:25 +03:00
|
|
|
error = uiomove((void *)&ue, uio->uio_resid, uio);
|
1999-10-12 15:54:56 +04:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
int
|
2001-12-31 15:15:21 +03:00
|
|
|
usbclose(dev_t dev, int flag, int mode, usb_proc_ptr p)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
1999-10-12 15:54:56 +04:00
|
|
|
int unit = minor(dev);
|
|
|
|
|
|
|
|
if (unit == USB_DEV_MINOR) {
|
|
|
|
usb_async_proc = 0;
|
|
|
|
usb_dev_open = 0;
|
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-12-31 15:15:21 +03:00
|
|
|
usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
1999-10-12 15:54:56 +04:00
|
|
|
struct usb_softc *sc;
|
1999-10-13 12:10:55 +04:00
|
|
|
int unit = minor(devt);
|
1999-10-12 15:54:56 +04:00
|
|
|
|
|
|
|
if (unit == USB_DEV_MINOR) {
|
|
|
|
switch (cmd) {
|
|
|
|
case FIONBIO:
|
|
|
|
/* All handled in the upper FS layer. */
|
|
|
|
return (0);
|
2002-02-03 21:15:20 +03:00
|
|
|
|
1999-10-12 15:54:56 +04:00
|
|
|
case FIOASYNC:
|
|
|
|
if (*(int *)data)
|
|
|
|
usb_async_proc = p;
|
|
|
|
else
|
|
|
|
usb_async_proc = 0;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
USB_GET_SC(usb, unit, sc);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-09-15 14:25:30 +04:00
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
switch (cmd) {
|
|
|
|
#ifdef USB_DEBUG
|
|
|
|
case USB_SETDEBUG:
|
2002-04-23 10:34:11 +04:00
|
|
|
if (!(flag & FWRITE))
|
|
|
|
return (EBADF);
|
1999-11-19 02:32:25 +03:00
|
|
|
usbdebug = ((*(int *)data) & 0x000000ff);
|
2002-12-30 05:44:32 +03:00
|
|
|
#if defined(UHCI_DEBUG) && NUHCI > 0
|
1999-11-19 02:32:25 +03:00
|
|
|
uhcidebug = ((*(int *)data) & 0x0000ff00) >> 8;
|
|
|
|
#endif
|
2002-12-30 05:44:32 +03:00
|
|
|
#if defined(OHCI_DEBUG) && NOHCI > 0
|
1999-11-19 02:32:25 +03:00
|
|
|
ohcidebug = ((*(int *)data) & 0x00ff0000) >> 16;
|
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
break;
|
2001-11-13 10:55:30 +03:00
|
|
|
#endif /* USB_DEBUG */
|
1998-07-12 23:51:55 +04:00
|
|
|
case USB_REQUEST:
|
|
|
|
{
|
|
|
|
struct usb_ctl_request *ur = (void *)data;
|
2002-02-20 23:30:12 +03:00
|
|
|
int len = UGETW(ur->ucr_request.wLength);
|
1998-07-12 23:51:55 +04:00
|
|
|
struct iovec iov;
|
|
|
|
struct uio uio;
|
|
|
|
void *ptr = 0;
|
2002-02-20 23:30:12 +03:00
|
|
|
int addr = ur->ucr_addr;
|
1999-11-12 03:34:57 +03:00
|
|
|
usbd_status err;
|
1998-07-12 23:51:55 +04:00
|
|
|
int error = 0;
|
|
|
|
|
2002-04-23 10:34:11 +04:00
|
|
|
if (!(flag & FWRITE))
|
|
|
|
return (EBADF);
|
|
|
|
|
1998-12-29 06:13:10 +03:00
|
|
|
DPRINTF(("usbioctl: USB_REQUEST addr=%d len=%d\n", addr, len));
|
1998-07-12 23:51:55 +04:00
|
|
|
if (len < 0 || len > 32768)
|
1998-12-29 06:13:10 +03:00
|
|
|
return (EINVAL);
|
2002-02-03 21:15:20 +03:00
|
|
|
if (addr < 0 || addr >= USB_MAX_DEVICES ||
|
1998-07-12 23:51:55 +04:00
|
|
|
sc->sc_bus->devices[addr] == 0)
|
1998-12-29 06:13:10 +03:00
|
|
|
return (EINVAL);
|
1998-07-12 23:51:55 +04:00
|
|
|
if (len != 0) {
|
2002-02-20 23:30:12 +03:00
|
|
|
iov.iov_base = (caddr_t)ur->ucr_data;
|
1998-07-12 23:51:55 +04:00
|
|
|
iov.iov_len = len;
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_resid = len;
|
|
|
|
uio.uio_offset = 0;
|
|
|
|
uio.uio_segflg = UIO_USERSPACE;
|
|
|
|
uio.uio_rw =
|
2002-02-20 23:30:12 +03:00
|
|
|
ur->ucr_request.bmRequestType & UT_READ ?
|
1998-07-12 23:51:55 +04:00
|
|
|
UIO_READ : UIO_WRITE;
|
|
|
|
uio.uio_procp = p;
|
|
|
|
ptr = malloc(len, M_TEMP, M_WAITOK);
|
|
|
|
if (uio.uio_rw == UIO_WRITE) {
|
|
|
|
error = uiomove(ptr, len, &uio);
|
|
|
|
if (error)
|
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
}
|
1999-11-12 03:34:57 +03:00
|
|
|
err = usbd_do_request_flags(sc->sc_bus->devices[addr],
|
2002-02-20 23:30:12 +03:00
|
|
|
&ur->ucr_request, ptr, ur->ucr_flags, &ur->ucr_actlen,
|
2002-02-11 18:11:49 +03:00
|
|
|
USBD_DEFAULT_TIMEOUT);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (err) {
|
1998-07-12 23:51:55 +04:00
|
|
|
error = EIO;
|
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
if (len != 0) {
|
|
|
|
if (uio.uio_rw == UIO_READ) {
|
|
|
|
error = uiomove(ptr, len, &uio);
|
|
|
|
if (error)
|
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret:
|
|
|
|
if (ptr)
|
|
|
|
free(ptr, M_TEMP);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
case USB_DEVICEINFO:
|
|
|
|
{
|
|
|
|
struct usb_device_info *di = (void *)data;
|
2002-02-20 23:30:12 +03:00
|
|
|
int addr = di->udi_addr;
|
1999-11-19 02:32:25 +03:00
|
|
|
usbd_device_handle dev;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
if (addr < 1 || addr >= USB_MAX_DEVICES)
|
|
|
|
return (EINVAL);
|
1999-11-19 02:32:25 +03:00
|
|
|
dev = sc->sc_bus->devices[addr];
|
|
|
|
if (dev == NULL)
|
1998-07-12 23:51:55 +04:00
|
|
|
return (ENXIO);
|
2000-12-13 07:05:14 +03:00
|
|
|
usbd_fill_deviceinfo(dev, di, 1);
|
1998-07-12 23:51:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-07-25 19:22:11 +04:00
|
|
|
case USB_DEVICESTATS:
|
|
|
|
*(struct usb_device_stats *)data = sc->sc_bus->stats;
|
|
|
|
break;
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
default:
|
1999-10-12 15:54:56 +04:00
|
|
|
return (EINVAL);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-12-31 15:15:21 +03:00
|
|
|
usbpoll(dev_t dev, int events, usb_proc_ptr p)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
1999-10-12 15:54:56 +04:00
|
|
|
int revents, mask, s;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-11-19 02:32:25 +03:00
|
|
|
if (minor(dev) == USB_DEV_MINOR) {
|
|
|
|
revents = 0;
|
|
|
|
mask = POLLIN | POLLRDNORM;
|
2002-02-03 21:15:20 +03:00
|
|
|
|
1999-11-19 02:32:25 +03:00
|
|
|
s = splusb();
|
|
|
|
if (events & mask && usb_nevents > 0)
|
|
|
|
revents |= events & mask;
|
|
|
|
if (revents == 0 && events & mask)
|
|
|
|
selrecord(p, &usb_selevent);
|
|
|
|
splx(s);
|
2002-02-03 21:15:20 +03:00
|
|
|
|
1999-11-19 02:32:25 +03:00
|
|
|
return (revents);
|
|
|
|
} else {
|
|
|
|
return (ENXIO);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-23 13:10:23 +04:00
|
|
|
static void
|
|
|
|
filt_usbrdetach(struct knote *kn)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splusb();
|
2002-11-26 21:49:40 +03:00
|
|
|
SLIST_REMOVE(&usb_selevent.sel_klist, kn, knote, kn_selnext);
|
2002-10-23 13:10:23 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
filt_usbread(struct knote *kn, long hint)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (usb_nevents == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
kn->kn_data = sizeof(struct usb_event);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct filterops usbread_filtops =
|
|
|
|
{ 1, NULL, filt_usbrdetach, filt_usbread };
|
|
|
|
|
|
|
|
int
|
|
|
|
usbkqfilter(dev_t dev, struct knote *kn)
|
|
|
|
{
|
|
|
|
struct klist *klist;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
switch (kn->kn_filter) {
|
|
|
|
case EVFILT_READ:
|
|
|
|
if (minor(dev) != USB_DEV_MINOR)
|
|
|
|
return (1);
|
2002-11-26 21:49:40 +03:00
|
|
|
klist = &usb_selevent.sel_klist;
|
2002-10-23 13:10:23 +04:00
|
|
|
kn->kn_fop = &usbread_filtops;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
kn->kn_hook = NULL;
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-09-18 15:25:50 +04:00
|
|
|
/* Explore device tree from the root. */
|
2001-01-21 22:00:06 +03:00
|
|
|
Static void
|
|
|
|
usb_discover(void *v)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2001-01-21 22:00:06 +03:00
|
|
|
struct usb_softc *sc = v;
|
|
|
|
|
|
|
|
DPRINTFN(2,("usb_discover\n"));
|
|
|
|
#ifdef USB_DEBUG
|
|
|
|
if (usb_noexplore > 1)
|
|
|
|
return;
|
|
|
|
#endif
|
2002-02-03 21:15:20 +03:00
|
|
|
/*
|
1999-09-18 15:25:50 +04:00
|
|
|
* We need mutual exclusion while traversing the device tree,
|
|
|
|
* but this is guaranteed since this function is only called
|
|
|
|
* from the event thread for the controller.
|
|
|
|
*/
|
1999-11-19 02:32:25 +03:00
|
|
|
while (sc->sc_bus->needs_explore && !sc->sc_dying) {
|
1999-06-30 10:44:22 +04:00
|
|
|
sc->sc_bus->needs_explore = 0;
|
|
|
|
sc->sc_bus->root_hub->hub->explore(sc->sc_bus->root_hub);
|
1999-11-19 02:32:25 +03:00
|
|
|
}
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-01-21 22:00:06 +03:00
|
|
|
usb_needs_explore(usbd_device_handle dev)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2001-01-21 22:00:06 +03:00
|
|
|
DPRINTFN(2,("usb_needs_explore\n"));
|
|
|
|
dev->bus->needs_explore = 1;
|
2001-11-21 02:53:26 +03:00
|
|
|
wakeup(&dev->bus->needs_explore);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
1998-12-26 15:53:00 +03:00
|
|
|
|
1999-10-12 15:54:56 +04:00
|
|
|
/* Called at splusb() */
|
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
usb_get_next_event(struct usb_event *ue)
|
1999-10-12 15:54:56 +04:00
|
|
|
{
|
|
|
|
struct usb_event_q *ueq;
|
|
|
|
|
|
|
|
if (usb_nevents <= 0)
|
|
|
|
return (0);
|
|
|
|
ueq = SIMPLEQ_FIRST(&usb_events);
|
2002-01-04 01:20:45 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (ueq == NULL) {
|
|
|
|
printf("usb: usb_nevents got out of sync! %d\n", usb_nevents);
|
|
|
|
usb_nevents = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
1999-10-12 15:54:56 +04:00
|
|
|
*ue = ueq->ue;
|
2002-06-02 03:50:52 +04:00
|
|
|
SIMPLEQ_REMOVE_HEAD(&usb_events, next);
|
1999-10-12 15:54:56 +04:00
|
|
|
free(ueq, M_USBDEV);
|
|
|
|
usb_nevents--;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-01 18:28:57 +04:00
|
|
|
usbd_add_dev_event(int type, usbd_device_handle udev)
|
2000-02-02 10:33:59 +03:00
|
|
|
{
|
|
|
|
struct usb_event ue;
|
|
|
|
|
2000-12-13 07:05:14 +03:00
|
|
|
usbd_fill_deviceinfo(udev, &ue.u.ue_device, USB_EVENT_IS_ATTACH(type));
|
2000-02-02 10:33:59 +03:00
|
|
|
usb_add_event(type, &ue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-01 18:28:57 +04:00
|
|
|
usbd_add_drv_event(int type, usbd_device_handle udev, device_ptr_t dev)
|
2000-02-02 10:33:59 +03:00
|
|
|
{
|
|
|
|
struct usb_event ue;
|
|
|
|
|
|
|
|
ue.u.ue_driver.ue_cookie = udev->cookie;
|
2002-02-03 21:15:20 +03:00
|
|
|
strncpy(ue.u.ue_driver.ue_devname, USBDEVPTRNAME(dev),
|
2000-02-02 10:33:59 +03:00
|
|
|
sizeof ue.u.ue_driver.ue_devname);
|
|
|
|
usb_add_event(type, &ue);
|
|
|
|
}
|
|
|
|
|
2000-03-27 16:33:53 +04:00
|
|
|
Static void
|
2000-06-01 18:28:57 +04:00
|
|
|
usb_add_event(int type, struct usb_event *uep)
|
1999-10-12 15:54:56 +04:00
|
|
|
{
|
|
|
|
struct usb_event_q *ueq;
|
|
|
|
struct usb_event ue;
|
|
|
|
struct timeval thetime;
|
|
|
|
int s;
|
|
|
|
|
2000-02-02 10:33:59 +03:00
|
|
|
microtime(&thetime);
|
|
|
|
/* Don't want to wait here inside splusb() */
|
|
|
|
ueq = malloc(sizeof *ueq, M_USBDEV, M_WAITOK);
|
|
|
|
ueq->ue = *uep;
|
|
|
|
ueq->ue.ue_type = type;
|
|
|
|
TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time);
|
|
|
|
|
1999-10-12 15:54:56 +04:00
|
|
|
s = splusb();
|
|
|
|
if (++usb_nevents >= USB_MAX_EVENTS) {
|
|
|
|
/* Too many queued events, drop an old one. */
|
|
|
|
DPRINTFN(-1,("usb: event dropped\n"));
|
|
|
|
(void)usb_get_next_event(&ue);
|
|
|
|
}
|
|
|
|
SIMPLEQ_INSERT_TAIL(&usb_events, ueq, next);
|
|
|
|
wakeup(&usb_events);
|
2002-10-23 13:10:23 +04:00
|
|
|
selnotify(&usb_selevent, 0);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (usb_async_proc != NULL)
|
1999-10-12 15:54:56 +04:00
|
|
|
psignal(usb_async_proc, SIGIO);
|
|
|
|
splx(s);
|
|
|
|
}
|
2001-12-31 15:15:21 +03:00
|
|
|
|
2000-02-22 14:30:54 +03:00
|
|
|
void
|
2001-01-21 05:39:52 +03:00
|
|
|
usb_schedsoftintr(usbd_bus_handle bus)
|
2000-02-22 14:30:54 +03:00
|
|
|
{
|
2001-11-09 17:59:11 +03:00
|
|
|
DPRINTFN(10,("usb_schedsoftintr: polling=%d\n", bus->use_polling));
|
2001-01-21 05:39:52 +03:00
|
|
|
#ifdef USB_USE_SOFTINTR
|
|
|
|
if (bus->use_polling) {
|
|
|
|
bus->methods->soft_intr(bus);
|
|
|
|
} else {
|
|
|
|
#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
|
|
|
|
softintr_schedule(bus->soft);
|
|
|
|
#else
|
|
|
|
if (!callout_pending(&bus->softi))
|
|
|
|
callout_reset(&bus->softi, 0, bus->methods->soft_intr,
|
|
|
|
bus);
|
|
|
|
#endif /* __HAVE_GENERIC_SOFT_INTERRUPTS */
|
|
|
|
}
|
|
|
|
#else
|
2000-02-22 14:30:54 +03:00
|
|
|
bus->methods->soft_intr(bus);
|
2001-11-13 10:55:30 +03:00
|
|
|
#endif /* USB_USE_SOFTINTR */
|
2000-02-22 14:30:54 +03:00
|
|
|
}
|
1999-10-12 15:54:56 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
usb_activate(device_ptr_t self, enum devact act)
|
1998-12-26 15:53:00 +03:00
|
|
|
{
|
1999-09-15 14:25:30 +04:00
|
|
|
struct usb_softc *sc = (struct usb_softc *)self;
|
1999-09-18 15:25:50 +04:00
|
|
|
usbd_device_handle dev = sc->sc_port.device;
|
|
|
|
int i, rv = 0;
|
1999-09-15 14:25:30 +04:00
|
|
|
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
sc->sc_dying = 1;
|
2002-01-02 23:55:58 +03:00
|
|
|
if (dev != NULL && dev->cdesc != NULL && dev->subdevs != NULL) {
|
1999-09-18 15:25:50 +04:00
|
|
|
for (i = 0; dev->subdevs[i]; i++)
|
|
|
|
rv |= config_deactivate(dev->subdevs[i]);
|
|
|
|
}
|
1999-09-15 14:25:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (rv);
|
1999-06-30 10:44:22 +04:00
|
|
|
}
|
1998-12-26 15:53:00 +03:00
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
usb_detach(device_ptr_t self, int flags)
|
1999-06-30 10:44:22 +04:00
|
|
|
{
|
1999-09-15 14:25:30 +04:00
|
|
|
struct usb_softc *sc = (struct usb_softc *)self;
|
2000-02-02 10:33:59 +03:00
|
|
|
struct usb_event ue;
|
1999-09-15 14:25:30 +04:00
|
|
|
|
1999-10-13 00:02:47 +04:00
|
|
|
DPRINTF(("usb_detach: start\n"));
|
|
|
|
|
1999-09-15 14:25:30 +04:00
|
|
|
sc->sc_dying = 1;
|
|
|
|
|
|
|
|
/* Make all devices disconnect. */
|
2002-01-02 23:55:58 +03:00
|
|
|
if (sc->sc_port.device != NULL)
|
1999-10-13 00:02:47 +04:00
|
|
|
usb_disconnect_port(&sc->sc_port, self);
|
1999-09-15 14:25:30 +04:00
|
|
|
|
|
|
|
/* Kill off event thread. */
|
2002-01-02 23:55:58 +03:00
|
|
|
if (sc->sc_event_thread != NULL) {
|
2001-11-21 02:53:26 +03:00
|
|
|
wakeup(&sc->sc_bus->needs_explore);
|
1999-09-15 14:25:30 +04:00
|
|
|
if (tsleep(sc, PWAIT, "usbdet", hz * 60))
|
|
|
|
printf("%s: event thread didn't die\n",
|
|
|
|
USBDEVNAME(sc->sc_dev));
|
1999-10-13 00:02:47 +04:00
|
|
|
DPRINTF(("usb_detach: event thread dead\n"));
|
1999-09-15 14:25:30 +04:00
|
|
|
}
|
|
|
|
|
1999-10-12 15:54:56 +04:00
|
|
|
usbd_finish();
|
2000-02-02 10:33:59 +03:00
|
|
|
|
2001-01-21 05:39:52 +03:00
|
|
|
#ifdef USB_USE_SOFTINTR
|
|
|
|
#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
|
|
|
|
if (sc->sc_bus->soft != NULL) {
|
|
|
|
softintr_disestablish(sc->sc_bus->soft);
|
|
|
|
sc->sc_bus->soft = NULL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
callout_stop(&sc->sc_bus->softi);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2000-02-02 10:33:59 +03:00
|
|
|
ue.u.ue_ctrlr.ue_bus = USBDEVUNIT(sc->sc_dev);
|
|
|
|
usb_add_event(USB_EVENT_CTRLR_DETACH, &ue);
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
return (0);
|
|
|
|
}
|