Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Change the USB event mechanism to include more i...



details:   https://anonhg.NetBSD.org/src/rev/dd474127d1bb
branches:  trunk
changeset: 481568:dd474127d1bb
user:      augustss <augustss%NetBSD.org@localhost>
date:      Wed Feb 02 07:33:59 2000 +0000

description:
Change the USB event mechanism to include more information about devices
and drivers.  Partly from FreeBSD.

diffstat:

 sys/dev/usb/uhub.c     |   6 ++++-
 sys/dev/usb/usb.c      |  60 +++++++++++++++++++++++++++++++++++++------------
 sys/dev/usb/usb.h      |  33 ++++++++++++++++++++++-----
 sys/dev/usb/usb_port.h |   5 +++-
 sys/dev/usb/usb_subr.c |  32 +++++++++++++++++++++-----
 sys/dev/usb/usbdi.h    |   6 +++-
 6 files changed, 111 insertions(+), 31 deletions(-)

diffs (truncated from 351 to 300 lines):

diff -r 164bbaf8cbdf -r dd474127d1bb sys/dev/usb/uhub.c
--- a/sys/dev/usb/uhub.c        Wed Feb 02 07:23:28 2000 +0000
+++ b/sys/dev/usb/uhub.c        Wed Feb 02 07:33:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhub.c,v 1.36 2000/01/19 00:23:58 augustss Exp $       */
+/*     $NetBSD: uhub.c,v 1.37 2000/02/02 07:33:59 augustss Exp $       */
 /*     $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $       */
 
 /*
@@ -247,6 +247,8 @@
        /* Wait with power off for a while. */
        usbd_delay_ms(dev, USB_POWER_DOWN_TIME);
 
+       usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, USBDEV(sc->sc_dev));
+
        for (p = 0; p < nports; p++) {
                struct usbd_port *up = &hub->ports[p];
                up->device = 0;
@@ -523,6 +525,8 @@
                        usb_disconnect_port(rup, self);
        }
        
+       usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, dev, USBDEV(sc->sc_dev));
+
        free(dev->hub, M_USBDEV);
        dev->hub = NULL;
 
diff -r 164bbaf8cbdf -r dd474127d1bb sys/dev/usb/usb.c
--- a/sys/dev/usb/usb.c Wed Feb 02 07:23:28 2000 +0000
+++ b/sys/dev/usb/usb.c Wed Feb 02 07:33:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.c,v 1.37 2000/01/24 18:35:51 thorpej Exp $ */
+/*     $NetBSD: usb.c,v 1.38 2000/02/02 07:33:59 augustss Exp $        */
 /*     $FreeBSD: src/sys/dev/usb/usb.c,v 1.20 1999/11/17 22:33:46 n_hibma Exp $        */
 
 /*
@@ -161,6 +161,7 @@
 static struct selinfo usb_selevent;
 static struct proc *usb_async_proc;  /* process who wants USB SIGIO */
 static int usb_dev_open = 0;
+static void usb_add_event __P((int, struct usb_event *));
 
 static int usb_get_next_event __P((struct usb_event *));
 
@@ -190,6 +191,7 @@
        usbd_device_handle dev;
        usbd_status err;
        int usbrev;
+       struct usb_event ue;
        
 #if defined(__FreeBSD__)
        printf("%s", USBDEVNAME(sc->sc_dev));
@@ -215,6 +217,9 @@
        if (cold)
                sc->sc_bus->use_polling++;
 
+       ue.u.ue_ctrlr.ue_bus = USBDEVUNIT(sc->sc_dev);
+       usb_add_event(USB_EVENT_CTRLR_ATTACH, &ue);
+
        err = usbd_new_device(USBDEV(sc->sc_dev), sc->sc_bus, 0, 0, 0,
                  &sc->sc_port);
        if (!err) {
@@ -636,33 +641,53 @@
 }
 
 void
-usbd_add_event(type, dev)
+usbd_add_dev_event(type, udev)
+       int type;
+       usbd_device_handle udev;
+{
+       struct usb_event ue;
+
+       usbd_fill_deviceinfo(udev, &ue.u.ue_device);
+       usb_add_event(type, &ue);
+}
+
+void
+usbd_add_drv_event(type, udev, dev)
        int type;
-       usbd_device_handle dev;
+       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), 
+           sizeof ue.u.ue_driver.ue_devname);
+       usb_add_event(type, &ue);
+}
+
+static void
+usb_add_event(type, uep)
+       int type;
+       struct usb_event *uep;
 {
        struct usb_event_q *ueq;
        struct usb_event ue;
        struct timeval thetime;
        int s;
 
+       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);
+
        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);
        }
-       /* Don't want to wait here inside splusb() */
-       ueq = malloc(sizeof *ueq, M_USBDEV, M_NOWAIT);
-       if (ueq == NULL) {
-               printf("usb: no memory, event dropped\n");
-               splx(s);
-               return;
-       }
-       ueq->ue.ue_type = type;
-       ueq->ue.ue_cookie = dev->cookie;
-       usbd_fill_deviceinfo(dev, &ueq->ue.ue_device);
-       microtime(&thetime);
-       TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time);
        SIMPLEQ_INSERT_TAIL(&usb_events, ueq, next);
        wakeup(&usb_events);
        selwakeup(&usb_selevent);
@@ -703,6 +728,7 @@
        int flags;
 {
        struct usb_softc *sc = (struct usb_softc *)self;
+       struct usb_event ue;
 
        DPRINTF(("usb_detach: start\n"));
 
@@ -722,6 +748,10 @@
        }
 
        usbd_finish();
+
+       ue.u.ue_ctrlr.ue_bus = USBDEVUNIT(sc->sc_dev);
+       usb_add_event(USB_EVENT_CTRLR_DETACH, &ue);
+
        return (0);
 }
 #elif defined(__FreeBSD__)
diff -r 164bbaf8cbdf -r dd474127d1bb sys/dev/usb/usb.h
--- a/sys/dev/usb/usb.h Wed Feb 02 07:23:28 2000 +0000
+++ b/sys/dev/usb/usb.h Wed Feb 02 07:33:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.h,v 1.39 1999/11/18 23:32:30 augustss Exp $        */
+/*     $NetBSD: usb.h,v 1.40 2000/02/02 07:33:59 augustss Exp $        */
 /*     $FreeBSD: src/sys/dev/usb/usb.h,v 1.14 1999/11/17 22:33:46 n_hibma Exp $        */
 
 /*
@@ -476,18 +476,28 @@
        u_char  data[1024];     /* filled data size will vary */
 };
 
+typedef struct { u_int32_t cookie; } usb_event_cookie_t;
+
+#define USB_MAX_DEVNAMES 4
+#define USB_MAX_DEVNAMELEN 16
 struct usb_device_info {
+       u_int8_t        bus;
        u_int8_t        addr;   /* device address */
+       usb_event_cookie_t cookie;
        char            product[USB_MAX_STRING_LEN];
        char            vendor[USB_MAX_STRING_LEN];
        char            release[8];
        u_int16_t       productNo;
        u_int16_t       vendorNo;
+       u_int16_t       releaseNo;
        u_int8_t        class;
+       u_int8_t        subclass;
+       u_int8_t        protocol;
        u_int8_t        config;
        u_int8_t        lowspeed;
        int             power;  /* power consumption in mA, 0 if selfpowered */
        int             nports;
+       char            devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
        u_int8_t        ports[16];/* hub only: addresses of devices on ports */
 #define USB_PORT_ENABLED 0xff
 #define USB_PORT_SUSPENDED 0xfe
@@ -504,15 +514,26 @@
        u_long  requests[4];    /* indexed by transfer type UE_* */
 };
 
-typedef struct { u_int32_t cookie; } usb_event_cookie_t;
 /* Events that can be read from /dev/usb */
 struct usb_event {
        int                     ue_type;
-#define USB_EVENT_ATTACH 1
-#define USB_EVENT_DETACH 2
-       struct usb_device_info  ue_device;
+#define USB_EVENT_CTRLR_ATTACH 1
+#define USB_EVENT_CTRLR_DETACH 2
+#define USB_EVENT_DEVICE_ATTACH 3
+#define USB_EVENT_DEVICE_DETACH 4
+#define USB_EVENT_DRIVER_ATTACH 5
+#define USB_EVENT_DRIVER_DETACH 6
        struct timespec         ue_time;
-       usb_event_cookie_t      ue_cookie;
+       union {
+               struct {
+                       int                     ue_bus;
+               } ue_ctrlr;
+               struct usb_device_info          ue_device;
+               struct {
+                       usb_event_cookie_t      ue_cookie;
+                       char                    ue_devname[16];
+               } ue_driver;                    
+       } u;
 };
 
 /* USB controller */
diff -r 164bbaf8cbdf -r dd474127d1bb sys/dev/usb/usb_port.h
--- a/sys/dev/usb/usb_port.h    Wed Feb 02 07:23:28 2000 +0000
+++ b/sys/dev/usb/usb_port.h    Wed Feb 02 07:33:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_port.h,v 1.20 2000/01/16 15:36:28 augustss Exp $   */
+/*     $NetBSD: usb_port.h,v 1.21 2000/02/02 07:34:00 augustss Exp $   */
 /*     $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.21 1999/11/17 22:33:47 n_hibma Exp $   */
 
 /*
@@ -69,6 +69,7 @@
 #define USBBASEDEVICE struct device
 #define USBDEV(bdev) (&(bdev))
 #define USBDEVNAME(bdev) ((bdev).dv_xname)
+#define USBDEVUNIT(bdev) ((bdev).dv_unit)
 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
 #define USBGETSOFTC(d) ((void *)(d))
 
@@ -197,6 +198,7 @@
 #define USBBASEDEVICE struct device
 #define USBDEV(bdev) (&(bdev))
 #define USBDEVNAME(bdev) ((bdev).dv_xname)
+#define USBDEVUNIT(bdev) ((bdev).dv_unit)
 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
 #define USBGETSOFTC(d) ((void *)(d))
 
@@ -292,6 +294,7 @@
 #define USBBASEDEVICE device_t
 #define USBDEV(bdev) (bdev)
 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
+#define USBDEVUNIT(bdev) device_get_unit(bdev)
 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
 
diff -r 164bbaf8cbdf -r dd474127d1bb sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c    Wed Feb 02 07:23:28 2000 +0000
+++ b/sys/dev/usb/usb_subr.c    Wed Feb 02 07:33:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_subr.c,v 1.64 2000/02/01 17:46:17 augustss Exp $   */
+/*     $NetBSD: usb_subr.c,v 1.65 2000/02/02 07:34:00 augustss Exp $   */
 /*     $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $   */
 
 /*
@@ -1032,14 +1032,15 @@
 
        DPRINTF(("usbd_new_device: new dev (addr %d), dev=%p, parent=%p\n", 
                 addr, dev, parent));
+  
+       usbd_add_dev_event(USB_EVENT_DEVICE_ATTACH, dev);
 
        err = usbd_probe_and_attach(parent, dev, port, addr);
        if (err) {
                usbd_remove_device(dev, up);
                return (err);
        }
-  
-       usbd_add_event(USB_EVENT_ATTACH, dev);
+
        return (USBD_NORMAL_COMPLETION);
 }
 
@@ -1164,15 +1165,34 @@
        struct usbd_port *p;
        int i, err, s;
 
-       di->config = dev->config;
+       di->bus = USBDEVUNIT(dev->bus->bdev);
+       di->addr = dev->address;
+       di->cookie = dev->cookie;
        usbd_devinfo_vp(dev, di->vendor, di->product);
        usbd_printBCD(di->release, UGETW(dev->ddesc.bcdDevice));
        di->vendorNo = UGETW(dev->ddesc.idVendor);
        di->productNo = UGETW(dev->ddesc.idProduct);
+       di->releaseNo = UGETW(dev->ddesc.bcdDevice);
        di->class = dev->ddesc.bDeviceClass;
+       di->subclass = dev->ddesc.bDeviceSubClass;
+       di->protocol = dev->ddesc.bDeviceProtocol;
+       di->config = dev->config;
        di->power = dev->self_powered ? 0 : dev->power;
        di->lowspeed = dev->lowspeed;
-       di->addr = dev->address;
+



Home | Main Index | Thread Index | Old Index