diff options
author | Nathan Binkert <nate@cvs.openbsd.org> | 2002-05-07 18:29:20 +0000 |
---|---|---|
committer | Nathan Binkert <nate@cvs.openbsd.org> | 2002-05-07 18:29:20 +0000 |
commit | e3500453ce2b94b39af2ef626169742ebc17530c (patch) | |
tree | d3c1ce90d9ae11b43948c86e7276f9595b6ee08d /sys/dev/usb/usb.c | |
parent | 98e3a0a3b6a5b0271467c9f199a555d22161f072 (diff) |
Meant to commit only ulpt and committed everything. Most things weren't ready
Diffstat (limited to 'sys/dev/usb/usb.c')
-rw-r--r-- | sys/dev/usb/usb.c | 236 |
1 files changed, 66 insertions, 170 deletions
diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index 3cc61c6bb74..cd8e4d0aa93 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -1,8 +1,9 @@ -/* $OpenBSD: usb.c,v 1.18 2002/05/07 18:08:04 nate Exp $ */ -/* $NetBSD: usb.c,v 1.69 2002/04/23 06:34:11 augustss Exp $ */ +/* $OpenBSD: usb.c,v 1.19 2002/05/07 18:29:18 nate Exp $ */ +/* $NetBSD: usb.c,v 1.53 2001/01/23 17:04:30 augustss Exp $ */ +/* $FreeBSD: src/sys/dev/usb/usb.c,v 1.20 1999/11/17 22:33:46 n_hibma Exp $ */ /* - * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc. + * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -52,7 +53,6 @@ #include <sys/kthread.h> #include <sys/proc.h> #include <sys/conf.h> -#include <sys/fcntl.h> #include <sys/poll.h> #include <sys/select.h> #include <sys/vnode.h> @@ -79,7 +79,7 @@ int uhcidebug; #ifdef OHCI_DEBUG int ohcidebug; #endif -/* +/* * 0 - do usual exploration * 1 - do not use timeout exploration * >1 - do no exploration @@ -95,31 +95,30 @@ struct usb_softc { usbd_bus_handle sc_bus; /* USB controller */ struct usbd_port sc_port; /* dummy port for root hub */ - usb_proc_ptr sc_event_thread; + TAILQ_HEAD(, usb_task) sc_tasks; + struct proc *sc_event_thread; + + struct usb_task sc_exp_task; char sc_dying; }; -TAILQ_HEAD(, usb_task) usb_all_tasks; - cdev_decl(usb); Static void usb_discover(void *); Static void usb_create_event_thread(void *); Static void usb_event_thread(void *); -Static void usb_task_thread(void *); -Static usb_proc_ptr usb_task_thread_proc = NULL; #define USB_MAX_EVENTS 100 struct usb_event_q { struct usb_event ue; SIMPLEQ_ENTRY(usb_event_q) next; }; -Static SIMPLEQ_HEAD(, usb_event_q) usb_events = +Static SIMPLEQ_HEAD(, usb_event_q) usb_events = SIMPLEQ_HEAD_INITIALIZER(usb_events); Static int usb_nevents = 0; Static struct selinfo usb_selevent; -Static usb_proc_ptr usb_async_proc; /* process that wants USB SIGIO */ +Static struct proc *usb_async_proc; /* process that wants USB SIGIO */ Static int usb_dev_open = 0; Static void usb_add_event(int, struct usb_event *); @@ -141,29 +140,22 @@ USB_ATTACH(usb) usbd_device_handle dev; usbd_status err; int usbrev; - int speed; struct usb_event ue; - + DPRINTF(("usbd_attach\n")); usbd_init(); sc->sc_bus = aux; sc->sc_bus->usbctl = sc; sc->sc_port.power = USB_MAX_POWER; + TAILQ_INIT(&sc->sc_tasks); + + usb_init_task(&sc->sc_exp_task, usb_discover, sc); usbrev = sc->sc_bus->usbrev; printf(": USB revision %s", usbrev_str[usbrev]); - 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: + if (usbrev != USBREV_1_0 && usbrev != USBREV_1_1) { printf(", not supported\n"); - sc->sc_dying = 1; USB_ATTACH_ERROR_RETURN; } printf("\n"); @@ -175,34 +167,19 @@ USB_ATTACH(usb) ue.u.ue_ctrlr.ue_bus = USBDEVUNIT(sc->sc_dev); usb_add_event(USB_EVENT_CTRLR_ATTACH, &ue); -#ifdef USB_USE_SOFTINTR -#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS - /* XXX we should have our own level */ - sc->sc_bus->soft = softintr_establish(IPL_SOFTNET, - 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; - USB_ATTACH_ERROR_RETURN; - } -#else - usb_callout_init(&sc->sc_bus->softi); -#endif -#endif - - err = usbd_new_device(USBDEV(sc->sc_dev), sc->sc_bus, 0, speed, 0, + err = usbd_new_device(USBDEV(sc->sc_dev), sc->sc_bus, 0, 0, 0, &sc->sc_port); if (!err) { dev = sc->sc_port.device; if (dev->hub == NULL) { sc->sc_dying = 1; - printf("%s: root device is not a hub\n", + printf("%s: root device is not a hub\n", USBDEVNAME(sc->sc_dev)); USB_ATTACH_ERROR_RETURN; } sc->sc_bus->root_hub = dev; #if 1 - /* + /* * 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. @@ -211,8 +188,8 @@ USB_ATTACH(usb) dev->hub->explore(sc->sc_bus->root_hub); #endif } else { - printf("%s: root hub problem, error=%d\n", - USBDEVNAME(sc->sc_dev), err); + printf("%s: root hub problem, error=%d\n", + USBDEVNAME(sc->sc_dev), err); sc->sc_dying = 1; } if (cold) @@ -229,7 +206,6 @@ void usb_create_event_thread(void *arg) { struct usb_softc *sc = arg; - static int created = 0; if (usb_kthread_create1(usb_event_thread, sc, &sc->sc_event_thread, "%s", sc->sc_dev.dv_xname)) { @@ -237,47 +213,39 @@ usb_create_event_thread(void *arg) sc->sc_dev.dv_xname); panic("usb_create_event_thread"); } - 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"); - } - } } /* - * Add a task to be performed by the task thread. This function can be + * Add a task to be performed by the event thread. This function can be * called from any context and the task will be executed in a process * context ASAP. */ void usb_add_task(usbd_device_handle dev, struct usb_task *task) { + struct usb_softc *sc = dev->bus->usbctl; int s; s = splusb(); if (!task->onqueue) { - DPRINTFN(2,("usb_add_task: task=%p\n", task)); - TAILQ_INSERT_TAIL(&usb_all_tasks, task, next); + DPRINTFN(2,("usb_add_task: sc=%p task=%p\n", sc, task)); + TAILQ_INSERT_TAIL(&sc->sc_tasks, task, next); task->onqueue = 1; - } else { - DPRINTFN(3,("usb_add_task: task=%p on q\n", task)); - } - wakeup(&usb_all_tasks); + } else + DPRINTFN(3,("usb_add_task: sc=%p task=%p on q\n", sc, task)); + wakeup(&sc->sc_tasks); splx(s); } void usb_rem_task(usbd_device_handle dev, struct usb_task *task) { + struct usb_softc *sc = dev->bus->usbctl; int s; s = splusb(); if (task->onqueue) { - TAILQ_REMOVE(&usb_all_tasks, task, next); + TAILQ_REMOVE(&sc->sc_tasks, task, next); task->onqueue = 0; } splx(s); @@ -287,37 +255,31 @@ void usb_event_thread(void *arg) { struct usb_softc *sc = arg; + struct usb_task *task; + int s; DPRINTF(("usb_event_thread: start\n")); - /* - * In case this controller is a companion controller to an - * EHCI controller we need to wait until the EHCI controller - * has grabbed the port. - * 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. - */ - usb_delay_ms(sc->sc_bus, 500); - /* Make sure first discover does something. */ sc->sc_bus->needs_explore = 1; usb_discover(sc); config_pending_decr(); while (!sc->sc_dying) { -#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")); + s = splusb(); + task = TAILQ_FIRST(&sc->sc_tasks); + if (task == NULL) { + tsleep(&sc->sc_tasks, PWAIT, "usbevt", 0); + task = TAILQ_FIRST(&sc->sc_tasks); + } + DPRINTFN(2,("usb_event_thread: woke up task=%p\n", task)); + if (task != NULL && !sc->sc_dying) { + TAILQ_REMOVE(&sc->sc_tasks, task, next); + task->onqueue = 0; + splx(s); + task->fun(task->arg); + } else + splx(s); } sc->sc_event_thread = NULL; @@ -328,32 +290,6 @@ usb_event_thread(void *arg) kthread_exit(0); } -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) { - tsleep(&usb_all_tasks, PWAIT, "usbtsk", 0); - 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(); - } - } -} - int usbctlprint(void *aux, const char *pnp) { @@ -366,7 +302,7 @@ usbctlprint(void *aux, const char *pnp) #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */ int -usbopen(dev_t dev, int flag, int mode, usb_proc_ptr p) +usbopen(dev_t dev, int flag, int mode, struct proc *p) { int unit = minor(dev); struct usb_softc *sc; @@ -421,7 +357,7 @@ usbread(dev_t dev, struct uio *uio, int flag) } int -usbclose(dev_t dev, int flag, int mode, usb_proc_ptr p) +usbclose(dev_t dev, int flag, int mode, struct proc *p) { int unit = minor(dev); @@ -434,7 +370,7 @@ usbclose(dev_t dev, int flag, int mode, usb_proc_ptr p) } int -usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p) +usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p) { struct usb_softc *sc; int unit = minor(devt); @@ -444,7 +380,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p) case FIONBIO: /* All handled in the upper FS layer. */ return (0); - + case FIOASYNC: if (*(int *)data) usb_async_proc = p; @@ -465,8 +401,6 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p) switch (cmd) { #ifdef USB_DEBUG case USB_SETDEBUG: - if (!(flag & FWRITE)) - return (EBADF); usbdebug = ((*(int *)data) & 0x000000ff); #ifdef UHCI_DEBUG uhcidebug = ((*(int *)data) & 0x0000ff00) >> 8; @@ -475,7 +409,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p) ohcidebug = ((*(int *)data) & 0x00ff0000) >> 16; #endif break; -#endif /* USB_DEBUG */ +#endif case USB_REQUEST: { struct usb_ctl_request *ur = (void *)data; @@ -487,13 +421,10 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p) usbd_status err; int error = 0; - if (!(flag & FWRITE)) - return (EBADF); - DPRINTF(("usbioctl: USB_REQUEST addr=%d len=%d\n", addr, len)); if (len < 0 || len > 32768) return (EINVAL); - if (addr < 0 || addr >= USB_MAX_DEVICES || + if (addr < 0 || addr >= USB_MAX_DEVICES || sc->sc_bus->devices[addr] == 0) return (EINVAL); if (len != 0) { @@ -505,7 +436,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p) uio.uio_offset = 0; uio.uio_segflg = UIO_USERSPACE; uio.uio_rw = - ur->ucr_request.bmRequestType & UT_READ ? + ur->ucr_request.bmRequestType & UT_READ ? UIO_READ : UIO_WRITE; uio.uio_procp = p; ptr = malloc(len, M_TEMP, M_WAITOK); @@ -516,8 +447,8 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p) } } err = usbd_do_request_flags(sc->sc_bus->devices[addr], - &ur->ucr_request, ptr, ur->ucr_flags, &ur->ucr_actlen, - USBD_DEFAULT_TIMEOUT); + &ur->ucr_request, ptr, ur->ucr_flags, + &ur->ucr_actlen); if (err) { error = EIO; goto ret; @@ -561,21 +492,21 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p) } int -usbpoll(dev_t dev, int events, usb_proc_ptr p) +usbpoll(dev_t dev, int events, struct proc *p) { int revents, mask, s; if (minor(dev) == USB_DEV_MINOR) { revents = 0; mask = POLLIN | POLLRDNORM; - + s = splusb(); if (events & mask && usb_nevents > 0) revents |= events & mask; if (revents == 0 && events & mask) selrecord(p, &usb_selevent); splx(s); - + return (revents); } else { return (ENXIO); @@ -593,7 +524,7 @@ usb_discover(void *v) if (usb_noexplore > 1) return; #endif - /* + /* * 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. @@ -609,7 +540,7 @@ usb_needs_explore(usbd_device_handle dev) { DPRINTFN(2,("usb_needs_explore\n")); dev->bus->needs_explore = 1; - wakeup(&dev->bus->needs_explore); + usb_add_task(dev, &dev->bus->usbctl->sc_exp_task); } /* Called at splusb() */ @@ -621,13 +552,6 @@ usb_get_next_event(struct usb_event *ue) if (usb_nevents <= 0) return (0); ueq = SIMPLEQ_FIRST(&usb_events); -#ifdef DIAGNOSTIC - if (ueq == NULL) { - printf("usb: usb_nevents got out of sync! %d\n", usb_nevents); - usb_nevents = 0; - return (0); - } -#endif *ue = ueq->ue; SIMPLEQ_REMOVE_HEAD(&usb_events, ueq, next); free(ueq, M_USBDEV); @@ -650,7 +574,7 @@ usbd_add_drv_event(int type, usbd_device_handle udev, device_ptr_t dev) struct usb_event ue; ue.u.ue_driver.ue_cookie = udev->cookie; - strncpy(ue.u.ue_driver.ue_devname, USBDEVPTRNAME(dev), + strncpy(ue.u.ue_driver.ue_devname, USBDEVPTRNAME(dev), sizeof ue.u.ue_driver.ue_devname); usb_add_event(type, &ue); } @@ -683,26 +607,10 @@ usb_add_event(int type, struct usb_event *uep) psignal(usb_async_proc, SIGIO); splx(s); } - void -usb_schedsoftintr(usbd_bus_handle bus) +usb_schedsoftintr(struct usbd_bus *bus) { - DPRINTFN(10,("usb_schedsoftintr: polling=%d\n", bus->use_polling)); -#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 (!usb_callout_pending(bus->softi)) - usb_callout(bus->softi, 0, bus->methods->soft_intr, - bus); -#endif /* __HAVE_GENERIC_SOFT_INTERRUPTS */ - } -#else bus->methods->soft_intr(bus); -#endif /* USB_USE_SOFTINTR */ } int @@ -719,8 +627,7 @@ usb_activate(device_ptr_t self, enum devact act) case DVACT_DEACTIVATE: sc->sc_dying = 1; - if (dev != NULL && dev->cdesc != NULL && - dev->subdevs != NULL) { + if (dev && dev->cdesc && dev->subdevs) { for (i = 0; dev->subdevs[i]; i++) rv |= config_deactivate(dev->subdevs[i]); } @@ -740,12 +647,12 @@ usb_detach(device_ptr_t self, int flags) sc->sc_dying = 1; /* Make all devices disconnect. */ - if (sc->sc_port.device != NULL) + if (sc->sc_port.device) usb_disconnect_port(&sc->sc_port, self); /* Kill off event thread. */ - if (sc->sc_event_thread != NULL) { - wakeup(&sc->sc_bus->needs_explore); + if (sc->sc_event_thread) { + wakeup(&sc->sc_tasks); if (tsleep(sc, PWAIT, "usbdet", hz * 60)) printf("%s: event thread didn't die\n", USBDEVNAME(sc->sc_dev)); @@ -754,17 +661,6 @@ usb_detach(device_ptr_t self, int flags) usbd_finish(); -#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 - usb_uncallout(sc->sc_bus->softi, bus->methods->soft_intr, bus); -#endif -#endif - ue.u.ue_ctrlr.ue_bus = USBDEVUNIT(sc->sc_dev); usb_add_event(USB_EVENT_CTRLR_DETACH, &ue); |