Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb Add an event mechanism so that a userland proces...



details:   https://anonhg.NetBSD.org/src/rev/86233d331568
branches:  trunk
changeset: 477144:86233d331568
user:      augustss <augustss%NetBSD.org@localhost>
date:      Tue Oct 12 11:54:56 1999 +0000

description:
Add an event mechanism so that a userland process can watch devices come
and go.

diffstat:

 sys/dev/usb/ugen.c     |   18 ++-
 sys/dev/usb/uhid.c     |   20 +++-
 sys/dev/usb/ukbd.c     |    4 +-
 sys/dev/usb/ulpt.c     |   12 ++-
 sys/dev/usb/usb.c      |  204 +++++++++++++++++++++++++++++++++++++++---------
 sys/dev/usb/usb.h      |   15 +++-
 sys/dev/usb/usb_port.h |   14 +--
 sys/dev/usb/usb_subr.c |    7 +-
 sys/dev/usb/usbdi.c    |   33 ++++++-
 sys/dev/usb/usbdi.h    |    4 +-
 sys/dev/usb/usbdivar.h |    4 +-
 11 files changed, 260 insertions(+), 75 deletions(-)

diffs (truncated from 792 to 300 lines):

diff -r 5395f041b71d -r 86233d331568 sys/dev/usb/ugen.c
--- a/sys/dev/usb/ugen.c        Tue Oct 12 11:27:52 1999 +0000
+++ b/sys/dev/usb/ugen.c        Tue Oct 12 11:54:56 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ugen.c,v 1.23 1999/09/09 12:26:44 augustss Exp $       */
+/*     $NetBSD: ugen.c,v 1.24 1999/10/12 11:54:56 augustss Exp $       */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -251,6 +251,7 @@
        int mode;
        struct proc *p;
 {
+       struct ugen_softc *sc;
        int unit = UGENUNIT(dev);
        int endpt = UGENENDPOINT(dev);
        usb_endpoint_descriptor_t *edesc;
@@ -346,11 +347,12 @@
        int mode;
        struct proc *p;
 {
-       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        int endpt = UGENENDPOINT(dev);
+       struct ugen_softc *sc;
        struct ugen_endpoint *sce;
        int dir;
 
+       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        DPRINTFN(5, ("ugenclose: flag=%d, mode=%d, unit=%d, endpt=%d\n",
                     flag, mode, UGENUNIT(dev), endpt));
 
@@ -502,10 +504,11 @@
        struct uio *uio;
        int flag;
 {
-       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        int endpt = UGENENDPOINT(dev);
+       struct ugen_softc *sc;
        int error;
 
+       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        sc->sc_refcnt++;
        error = ugen_do_read(sc, endpt, uio, flag);
        if (--sc->sc_refcnt < 0)
@@ -576,10 +579,11 @@
        struct uio *uio;
        int flag;
 {
-       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        int endpt = UGENENDPOINT(dev);
+       struct ugen_softc *sc;
        int error;
 
+       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        sc->sc_refcnt++;
        error = ugen_do_write(sc, endpt, uio, flag);
        if (--sc->sc_refcnt < 0)
@@ -1072,10 +1076,11 @@
        int flag;
        struct proc *p;
 {
-       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        int endpt = UGENENDPOINT(dev);
+       struct ugen_softc *sc;
        int error;
 
+       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        sc->sc_refcnt++;
        error = ugen_do_ioctl(sc, endpt, cmd, addr, flag, p);
        if (--sc->sc_refcnt < 0)
@@ -1089,11 +1094,12 @@
        int events;
        struct proc *p;
 {
-       USB_GET_SC(ugen, UGENUNIT(dev), sc);
+       struct ugen_softc *sc;
        struct ugen_endpoint *sce;
        int revents = 0;
        int s;
 
+       USB_GET_SC(ugen, UGENUNIT(dev), sc);
        if (sc->sc_dying)
                return (EIO);
 
diff -r 5395f041b71d -r 86233d331568 sys/dev/usb/uhid.c
--- a/sys/dev/usb/uhid.c        Tue Oct 12 11:27:52 1999 +0000
+++ b/sys/dev/usb/uhid.c        Tue Oct 12 11:54:56 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhid.c,v 1.24 1999/09/05 19:32:18 augustss Exp $       */
+/*     $NetBSD: uhid.c,v 1.25 1999/10/12 11:54:56 augustss Exp $       */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -334,7 +334,9 @@
        int mode;
        struct proc *p;
 {
+       struct uhid_softc *sc;
        usbd_status r;
+
        USB_GET_SC_OPEN(uhid, UHIDUNIT(dev), sc);
 
        DPRINTF(("uhidopen: sc=%p\n", sc));
@@ -384,6 +386,8 @@
        int mode;
        struct proc *p;
 {
+       struct uhid_softc *sc;
+
        USB_GET_SC(uhid, UHIDUNIT(dev), sc);
 
        DPRINTF(("uhidclose: sc=%p\n", sc));
@@ -478,8 +482,10 @@
        struct uio *uio;
        int flag;
 {
+       struct uhid_softc *sc;
+       int error;
+
        USB_GET_SC(uhid, UHIDUNIT(dev), sc);
-       int error;
 
        sc->sc_refcnt++;
        error = uhid_do_read(sc, uio, flag);
@@ -530,8 +536,10 @@
        struct uio *uio;
        int flag;
 {
+       struct uhid_softc *sc;
+       int error;
+
        USB_GET_SC(uhid, UHIDUNIT(dev), sc);
-       int error;
 
        sc->sc_refcnt++;
        error = uhid_do_write(sc, uio, flag);
@@ -622,8 +630,10 @@
        int flag;
        struct proc *p;
 {
+       struct uhid_softc *sc;
+       int error;
+
        USB_GET_SC(uhid, UHIDUNIT(dev), sc);
-       int error;
 
        sc->sc_refcnt++;
        error = uhid_do_ioctl(sc, cmd, addr, flag, p);
@@ -638,8 +648,10 @@
        int events;
        struct proc *p;
 {
+       struct uhid_softc *sc;
        int revents = 0;
        int s;
+
        USB_GET_SC(uhid, UHIDUNIT(dev), sc);
 
        if (sc->sc_dying)
diff -r 5395f041b71d -r 86233d331568 sys/dev/usb/ukbd.c
--- a/sys/dev/usb/ukbd.c        Tue Oct 12 11:27:52 1999 +0000
+++ b/sys/dev/usb/ukbd.c        Tue Oct 12 11:54:56 1999 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: ukbd.c,v 1.44 1999/09/12 08:21:49 augustss Exp $        */
+/*      $NetBSD: ukbd.c,v 1.45 1999/10/12 11:54:56 augustss Exp $        */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -430,7 +430,7 @@
                 */
                panic("ukbd_detach: console keyboard");
        }
-       /* No need to do reference counting of ums, wskbd has all the goo. */
+       /* No need to do reference counting of ukbd, wskbd has all the goo. */
        if (sc->sc_wskbddev)
                rv = config_detach(sc->sc_wskbddev, flags);
        return (rv);
diff -r 5395f041b71d -r 86233d331568 sys/dev/usb/ulpt.c
--- a/sys/dev/usb/ulpt.c        Tue Oct 12 11:27:52 1999 +0000
+++ b/sys/dev/usb/ulpt.c        Tue Oct 12 11:54:56 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ulpt.c,v 1.25 1999/09/15 21:11:27 augustss Exp $       */
+/*     $NetBSD: ulpt.c,v 1.26 1999/10/12 11:54:56 augustss Exp $       */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -330,11 +330,13 @@
        struct proc *p;
 {
        u_char flags = ULPTFLAGS(dev);
+       struct ulpt_softc *sc;
        usbd_status r;
        int spin, error;
+
        USB_GET_SC_OPEN(ulpt, ULPTUNIT(dev), sc);
 
-       if (!sc || !sc->sc_iface || sc->sc_dying)
+       if (!sc->sc_iface || sc->sc_dying)
                return (ENXIO);
 
        if (sc->sc_state)
@@ -401,6 +403,8 @@
        int mode;
        struct proc *p;
 {
+       struct ulpt_softc *sc;
+
        USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
 
        if (sc->sc_state != ULPT_OPEN)
@@ -462,8 +466,10 @@
        struct uio *uio;
        int flags;
 {
+       struct ulpt_softc *sc;
+       int error;
+
        USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
-       int error;
 
        if (sc->sc_dying)
                return (EIO);
diff -r 5395f041b71d -r 86233d331568 sys/dev/usb/usb.c
--- a/sys/dev/usb/usb.c Tue Oct 12 11:27:52 1999 +0000
+++ b/sys/dev/usb/usb.c Tue Oct 12 11:54:56 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.c,v 1.25 1999/09/18 11:25:51 augustss Exp $        */
+/*     $NetBSD: usb.c,v 1.26 1999/10/12 11:54:56 augustss Exp $        */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -55,17 +55,20 @@
 #include <sys/bus.h>
 #include <sys/ioccom.h>
 #include <sys/uio.h>
-#include <sys/conf.h>
 #endif
 #include <sys/conf.h>
 #include <sys/poll.h>
 #include <sys/proc.h>
 #include <sys/select.h>
+#include <sys/vnode.h>
+#include <sys/signalvar.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdi_util.h>
 
+#define USB_DEV_MINOR 255
+
 #if defined(__FreeBSD__)
 MALLOC_DEFINE(M_USB, "USB", "USB");
 MALLOC_DEFINE(M_USBDEV, "USBdev", "USB device");
@@ -91,10 +94,6 @@
 #define DPRINTFN(n,x)
 #endif
 
-int usb_nbus = 0;
-
-#define USBUNIT(dev) (minor(dev))
-
 struct usb_softc {
        USBBASEDEVICE   sc_dev;         /* base device */
        usbd_bus_handle sc_bus;         /* USB controller */
@@ -126,6 +125,19 @@
 void   usb_create_event_thread __P((void *));
 void   usb_event_thread __P((void *));
 
+#define USB_MAX_EVENTS 50
+struct usb_event_q {
+       struct usb_event ue;
+       SIMPLEQ_ENTRY(usb_event_q) next;
+};
+SIMPLEQ_HEAD(, usb_event_q) usb_events = SIMPLEQ_HEAD_INITIALIZER(usb_events);
+int usb_nevents = 0;
+struct selinfo usb_selevent;
+struct proc *usb_async_proc;  /* process who wants USB SIGIO */
+int usb_dev_open = 0;
+
+int usb_get_next_event __P((struct usb_event *));
+
 /* Flag to see if we are in the cold boot process. */
 extern int cold;
 
@@ -191,7 +203,6 @@
 
        kthread_create(usb_create_event_thread, sc);
 
-       usb_nbus++;
        USB_ATTACH_SUCCESS_RETURN;
 }
 
@@ -252,10 +263,19 @@
        int flag, mode;
        struct proc *p;
 {
-       USB_GET_SC_OPEN(usb, USBUNIT(dev), sc);
+       int unit = minor(dev);
+       struct usb_softc *sc;
 



Home | Main Index | Thread Index | Old Index