diff options
author | Josef Karthauser <joe@FreeBSD.org> | 2002-01-28 01:03:19 +0000 |
---|---|---|
committer | Josef Karthauser <joe@FreeBSD.org> | 2002-01-28 01:03:19 +0000 |
commit | a07e9d4af3f47a6d2a75a7aa903add70886b863c (patch) | |
tree | c7820152b3d171d7820a328b8adc34c87a71de86 /sys/dev/usb | |
parent | a31999ca51d72a54f719da540a4d13c5ca72cdd2 (diff) | |
download | src-a07e9d4af3f47a6d2a75a7aa903add70886b863c.tar.gz src-a07e9d4af3f47a6d2a75a7aa903add70886b863c.zip |
Merge from NetBSD.
uhub.c: revision 1.37
usb.4: revision 1.30
usb.c: revision 1.38
usb.h: revision 1.40
usb_port.h: revision 1.21
usb_subr.c: revision 1.65
usbdi.h: revision 1.40
Split the attach/detach events up into device, driver and controller
attach and detach events.
The commit message from NetBSD was:
date: 2000/02/02 07:34:00; author: augustss; state: Exp;
Change the USB event mechanism to include more information
about devices and drivers. Partly from FreeBSD.
Also rework usbd to take these new event types into account.
Notes
Notes:
svn path=/head/; revision=89892
Diffstat (limited to 'sys/dev/usb')
-rw-r--r-- | sys/dev/usb/uhub.c | 5 | ||||
-rw-r--r-- | sys/dev/usb/usb.c | 57 | ||||
-rw-r--r-- | sys/dev/usb/usb.h | 1 | ||||
-rw-r--r-- | sys/dev/usb/usb_port.h | 3 | ||||
-rw-r--r-- | sys/dev/usb/usb_subr.c | 7 | ||||
-rw-r--r-- | sys/dev/usb/usbdi.h | 3 |
6 files changed, 55 insertions, 21 deletions
diff --git a/sys/dev/usb/uhub.c b/sys/dev/usb/uhub.c index 0533249aab8d..05a19729e8e2 100644 --- a/sys/dev/usb/uhub.c +++ b/sys/dev/usb/uhub.c @@ -263,6 +263,8 @@ USB_ATTACH(uhub) /* 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)); + /* * To have the best chance of success we do things in the exact same * order as Windoze98. This should not be necessary, but some @@ -525,7 +527,8 @@ USB_DETACH(uhub) if (rup->device) 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 --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index 545d35c97ec3..0798248809df 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -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$ */ /* @@ -163,6 +163,7 @@ Static int usb_nevents = 0; Static struct selinfo usb_selevent; 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 *); Static int usb_get_next_event(struct usb_event *); @@ -201,6 +202,7 @@ USB_ATTACH(usb) usbd_device_handle dev; usbd_status err; int usbrev; + struct usb_event ue; sc->sc_dev = self; @@ -226,6 +228,9 @@ USB_ATTACH(usb) 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) { @@ -631,18 +636,45 @@ usb_get_next_event(struct usb_event *ue) } void -usbd_add_event(int type, usbd_device_handle dev) +usbd_add_dev_event(int type, usbd_device_handle udev) +{ + struct usb_event ue; + + usbd_fill_deviceinfo(udev, &ue.u.ue_device, USB_EVENT_IS_ATTACH(type)); + usb_add_event(type, &ue); +} + +void +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), + sizeof ue.u.ue_driver.ue_devname); + usb_add_event(type, &ue); +} + +void +usb_add_event(int type, struct usb_event *uep) { struct usb_event_q *ueq, *ueq_next; struct usb_event ue; struct timeval thetime; int s; + ueq = malloc(sizeof *ueq, M_USBDEV, M_WAITOK); + ueq->ue = *uep; + ueq->ue.ue_type = type; + microtime(&thetime); + TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time); + s = splusb(); - if (type == USB_EVENT_CTRLR_DETACH) { + if (USB_EVENT_IS_DETACH(type)) { for (ueq = TAILQ_FIRST(&usb_events); ueq; ueq = ueq_next) { ueq_next = TAILQ_NEXT(ueq, next); - if (ueq->ue.u.ue_driver.ue_cookie.cookie == dev->cookie.cookie) { + if (ueq->ue.u.ue_driver.ue_cookie.cookie == + uep->u.ue_device.cookie.cookie) { TAILQ_REMOVE(&usb_events, ueq, next); free(ueq, M_USBDEV); usb_nevents--; @@ -655,18 +687,6 @@ usbd_add_event(int type, usbd_device_handle dev) DPRINTF(("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.u.ue_driver.ue_cookie = dev->cookie; - usbd_fill_deviceinfo(dev, &ueq->ue.u.ue_device, 0); - microtime(&thetime); - TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time); TAILQ_INSERT_TAIL(&usb_events, ueq, next); usb_nevents++; wakeup(&usb_events); @@ -713,6 +733,7 @@ int usb_detach(device_ptr_t self, int flags) { struct usb_softc *sc = (struct usb_softc *)self; + struct usb_event ue; DPRINTF(("usb_detach: start\n")); @@ -732,6 +753,10 @@ usb_detach(device_ptr_t self, int flags) } 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 --git a/sys/dev/usb/usb.h b/sys/dev/usb/usb.h index 21c733f33831..8d5a3da94d1e 100644 --- a/sys/dev/usb/usb.h +++ b/sys/dev/usb/usb.h @@ -627,6 +627,7 @@ struct usb_event { #define USB_EVENT_DRIVER_ATTACH 5 #define USB_EVENT_DRIVER_DETACH 6 #define USB_EVENT_IS_ATTACH(n) ((n) == USB_EVENT_CTRLR_ATTACH || (n) == USB_EVENT_DEVICE_ATTACH || (n) == USB_EVENT_DRIVER_ATTACH) +#define USB_EVENT_IS_DETACH(n) ((n) == USB_EVENT_CTRLR_DETACH || (n) == USB_EVENT_DEVICE_DETACH || (n) == USB_EVENT_DRIVER_DETACH) struct timespec ue_time; union { struct { diff --git a/sys/dev/usb/usb_port.h b/sys/dev/usb/usb_port.h index 3f7842250bc9..e2ac72f97e0e 100644 --- a/sys/dev/usb/usb_port.h +++ b/sys/dev/usb/usb_port.h @@ -70,6 +70,7 @@ typedef struct device *device_ptr_t; #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 USBDEVUNIT(bdev) ((bdev).dv_unit) @@ -191,6 +192,7 @@ typedef struct device device_ptr_t; #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 USBDEVUNIT(bdev) ((bdev).dv_unit) @@ -290,6 +292,7 @@ __CONCAT(dname,_detach)(self, flags) \ #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 USBDEVUNIT(bdev) device_get_unit(bdev) diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index f17e5155cf03..2565c44a8e59 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -1031,9 +1031,9 @@ usbd_new_device(device_ptr_t parent, usbd_bus_handle bus, int depth, usbd_remove_device(dev, up); return (err); } - - usbd_add_event(USB_EVENT_CTRLR_ATTACH, dev); + usbd_add_dev_event(USB_EVENT_DEVICE_ATTACH, dev); + return (USBD_NORMAL_COMPLETION); } @@ -1158,6 +1158,7 @@ usbd_fill_deviceinfo(usbd_device_handle dev, struct usb_device_info *di, di->bus = USBDEVUNIT(dev->bus->bdev); di->addr = dev->address; + di->cookie = dev->cookie; usbd_devinfo_vp(dev, di->vendor, di->product, usedev); usbd_printBCD(di->release, UGETW(dev->ddesc.bcdDevice)); di->vendorNo = UGETW(dev->ddesc.idVendor); @@ -1281,7 +1282,7 @@ usb_disconnect_port(struct usbd_port *up, device_ptr_t parent) } } - /*usbd_add_event(USB_EVENT_DETACH, dev);*/ + /*usbd_add_dev_event(USB_EVENT_DEVICE_DETACH, dev);*/ dev->bus->devices[dev->address] = NULL; up->device = NULL; usb_free_device(dev); diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h index bb5bfbf7fbe3..7a184e7b87e7 100644 --- a/sys/dev/usb/usbdi.h +++ b/sys/dev/usb/usbdi.h @@ -176,7 +176,8 @@ void usbd_set_polling(usbd_interface_handle iface, int on); const char *usbd_errstr(usbd_status err); -void usbd_add_event(int, usbd_device_handle); +void usbd_add_dev_event (int, usbd_device_handle); +void usbd_add_drv_event (int, usbd_device_handle, device_ptr_t); void usbd_devinfo(usbd_device_handle, int, char *); const struct usbd_quirks *usbd_get_quirks(usbd_device_handle); |