diff options
Diffstat (limited to 'sys/dev/usb/uhid.c')
-rw-r--r-- | sys/dev/usb/uhid.c | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/sys/dev/usb/uhid.c b/sys/dev/usb/uhid.c index 719341c..a38fbf4 100644 --- a/sys/dev/usb/uhid.c +++ b/sys/dev/usb/uhid.c @@ -1,4 +1,4 @@ -/* $NetBSD: uhid.c,v 1.24 1999/09/05 19:32:18 augustss Exp $ */ +/* $NetBSD: uhid.c,v 1.26 1999/10/13 08:10:56 augustss Exp $ */ /* $FreeBSD$ */ /* @@ -146,11 +146,13 @@ static struct cdevsw uhid_cdevsw = { }; #endif -void uhid_intr __P((usbd_request_handle, usbd_private_handle, usbd_status)); +static void uhid_intr __P((usbd_xfer_handle, usbd_private_handle, + usbd_status)); -int uhid_do_read __P((struct uhid_softc *, struct uio *uio, int)); -int uhid_do_write __P((struct uhid_softc *, struct uio *uio, int)); -int uhid_do_ioctl __P((struct uhid_softc *, u_long, caddr_t, int, struct proc *)); +static int uhid_do_read __P((struct uhid_softc *, struct uio *uio, int)); +static int uhid_do_write __P((struct uhid_softc *, struct uio *uio, int)); +static int uhid_do_ioctl __P((struct uhid_softc *, u_long, caddr_t, int, + struct proc *)); USB_DECLARE_DRIVER(uhid); @@ -159,10 +161,10 @@ USB_MATCH(uhid) USB_MATCH_START(uhid, uaa); usb_interface_descriptor_t *id; - if (!uaa->iface) + if (uaa->iface == NULL) return (UMATCH_NONE); id = usbd_get_interface_descriptor(uaa->iface); - if (!id || id->bInterfaceClass != UCLASS_HID) + if (id == NULL || id->bInterfaceClass != UCLASS_HID) return (UMATCH_NONE); return (UMATCH_IFACECLASS_GENERIC); } @@ -175,7 +177,7 @@ USB_ATTACH(uhid) usb_endpoint_descriptor_t *ed; int size; void *desc; - usbd_status r; + usbd_status err; char devinfo[1024]; sc->sc_iface = iface; @@ -186,7 +188,7 @@ USB_ATTACH(uhid) devinfo, id->bInterfaceClass, id->bInterfaceSubClass); ed = usbd_interface2endpoint_descriptor(iface, 0); - if (!ed) { + if (ed == NULL) { printf("%s: could not read endpoint descriptor\n", USBDEVNAME(sc->sc_dev)); sc->sc_dying = 1; @@ -212,11 +214,11 @@ USB_ATTACH(uhid) sc->sc_ep_addr = ed->bEndpointAddress; desc = 0; - r = usbd_alloc_report_desc(uaa->iface, &desc, &size, M_USBDEV); - if (r != USBD_NORMAL_COMPLETION) { + err = usbd_alloc_report_desc(uaa->iface, &desc, &size, M_USBDEV); + if (err) { printf("%s: no report descriptor\n", USBDEVNAME(sc->sc_dev)); sc->sc_dying = 1; - if (desc) + if (desc != NULL) free(desc, M_USBDEV); USB_ATTACH_ERROR_RETURN; } @@ -272,12 +274,12 @@ USB_DETACH(uhid) int maj, mn; DPRINTF(("uhid_detach: sc=%p flags=%d\n", sc, flags)); -#elif defined(__FreeBSD__) +#else DPRINTF(("uhid_detach: sc=%p\n", sc)); #endif sc->sc_dying = 1; - if (sc->sc_intrpipe) + if (sc->sc_intrpipe != NULL) usbd_abort_pipe(sc->sc_intrpipe); if (sc->sc_state & UHID_OPEN) { @@ -310,8 +312,8 @@ USB_DETACH(uhid) } void -uhid_intr(reqh, addr, status) - usbd_request_handle reqh; +uhid_intr(xfer, addr, status) + usbd_xfer_handle xfer; usbd_private_handle addr; usbd_status status; { @@ -347,7 +349,9 @@ uhidopen(dev, flag, mode, p) int mode; struct proc *p; { - usbd_status r; + struct uhid_softc *sc; + usbd_status err; + USB_GET_SC_OPEN(uhid, UHIDUNIT(dev), sc); DPRINTF(("uhidopen: sc=%p\n", sc)); @@ -359,26 +363,21 @@ uhidopen(dev, flag, mode, p) return (EBUSY); sc->sc_state |= UHID_OPEN; -#if defined(__NetBSD__) || defined(__OpenBSD__) if (clalloc(&sc->sc_q, UHID_BSIZE, 0) == -1) { sc->sc_state &= ~UHID_OPEN; return (ENOMEM); } -#elif defined(__FreeBSD__) - clist_alloc_cblocks(&sc->sc_q, UHID_BSIZE, 0); -#endif sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK); sc->sc_obuf = malloc(sc->sc_osize, M_USBDEV, M_WAITOK); /* Set up interrupt pipe. */ - r = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr, - USBD_SHORT_XFER_OK, - &sc->sc_intrpipe, sc, sc->sc_ibuf, - sc->sc_isize, uhid_intr); - if (r != USBD_NORMAL_COMPLETION) { + err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr, + USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc, sc->sc_ibuf, + sc->sc_isize, uhid_intr); + if (err) { DPRINTF(("uhidopen: usbd_open_pipe_intr failed, " - "error=%d\n",r)); + "error=%d\n",err)); free(sc->sc_ibuf, M_USBDEV); free(sc->sc_obuf, M_USBDEV); sc->sc_state &= ~UHID_OPEN; @@ -397,6 +396,8 @@ uhidclose(dev, flag, mode, p) int mode; struct proc *p; { + struct uhid_softc *sc; + USB_GET_SC(uhid, UHIDUNIT(dev), sc); DPRINTF(("uhidclose: sc=%p\n", sc)); @@ -406,11 +407,7 @@ uhidclose(dev, flag, mode, p) usbd_close_pipe(sc->sc_intrpipe); sc->sc_intrpipe = 0; -#if defined(__NetBSD__) || defined(__OpenBSD__) clfree(&sc->sc_q); -#elif defined(__FreeBSD__) - clist_free_cblocks(&sc->sc_q); -#endif free(sc->sc_ibuf, M_USBDEV); free(sc->sc_obuf, M_USBDEV); @@ -430,15 +427,15 @@ uhid_do_read(sc, uio, flag) int error = 0; size_t length; u_char buffer[UHID_CHUNK]; - usbd_status r; + usbd_status err; DPRINTFN(1, ("uhidread\n")); if (sc->sc_state & UHID_IMMED) { DPRINTFN(1, ("uhidread immed\n")); - r = usbd_get_report(sc->sc_iface, UHID_INPUT_REPORT, - sc->sc_iid, buffer, sc->sc_isize); - if (r != USBD_NORMAL_COMPLETION) + err = usbd_get_report(sc->sc_iface, UHID_INPUT_REPORT, + sc->sc_iid, buffer, sc->sc_isize); + if (err) return (EIO); return (uiomove(buffer, sc->sc_isize, uio)); } @@ -491,9 +488,11 @@ uhidread(dev, uio, flag) struct uio *uio; int flag; { - USB_GET_SC(uhid, UHIDUNIT(dev), sc); + struct uhid_softc *sc; int error; + USB_GET_SC(uhid, UHIDUNIT(dev), sc); + sc->sc_refcnt++; error = uhid_do_read(sc, uio, flag); if (--sc->sc_refcnt < 0) @@ -509,7 +508,7 @@ uhid_do_write(sc, uio, flag) { int error; int size; - usbd_status r; + usbd_status err; DPRINTFN(1, ("uhidwrite\n")); @@ -523,15 +522,13 @@ uhid_do_write(sc, uio, flag) error = uiomove(sc->sc_obuf, size, uio); if (!error) { if (sc->sc_oid) - r = usbd_set_report(sc->sc_iface, UHID_OUTPUT_REPORT, - sc->sc_obuf[0], - sc->sc_obuf+1, size-1); + err = usbd_set_report(sc->sc_iface, UHID_OUTPUT_REPORT, + sc->sc_obuf[0], sc->sc_obuf+1, size-1); else - r = usbd_set_report(sc->sc_iface, UHID_OUTPUT_REPORT, - 0, sc->sc_obuf, size); - if (r != USBD_NORMAL_COMPLETION) { + err = usbd_set_report(sc->sc_iface, UHID_OUTPUT_REPORT, + 0, sc->sc_obuf, size); + if (err) error = EIO; - } } return (error); @@ -543,9 +540,11 @@ uhidwrite(dev, uio, flag) struct uio *uio; int flag; { - USB_GET_SC(uhid, UHIDUNIT(dev), sc); + struct uhid_softc *sc; int error; + USB_GET_SC(uhid, UHIDUNIT(dev), sc); + sc->sc_refcnt++; error = uhid_do_write(sc, uio, flag); if (--sc->sc_refcnt < 0) @@ -564,7 +563,7 @@ uhid_do_ioctl(sc, cmd, addr, flag, p) struct usb_ctl_report_desc *rd; struct usb_ctl_report *re; int size, id; - usbd_status r; + usbd_status err; DPRINTFN(2, ("uhidioctl: cmd=%lx\n", cmd)); @@ -585,11 +584,10 @@ uhid_do_ioctl(sc, cmd, addr, flag, p) case USB_SET_IMMED: if (*(int *)addr) { - /* XXX should read into ibuf, but does it matter */ - r = usbd_get_report(sc->sc_iface, UHID_INPUT_REPORT, - sc->sc_iid, sc->sc_ibuf, - sc->sc_isize); - if (r != USBD_NORMAL_COMPLETION) + /* XXX should read into ibuf, but does it matter? */ + err = usbd_get_report(sc->sc_iface, UHID_INPUT_REPORT, + sc->sc_iid, sc->sc_ibuf, sc->sc_isize); + if (err) return (EOPNOTSUPP); sc->sc_state |= UHID_IMMED; @@ -615,9 +613,9 @@ uhid_do_ioctl(sc, cmd, addr, flag, p) default: return (EINVAL); } - r = usbd_get_report(sc->sc_iface, re->report, id, - re->data, size); - if (r != USBD_NORMAL_COMPLETION) + err = usbd_get_report(sc->sc_iface, re->report, id, re->data, + size); + if (err) return (EIO); break; @@ -635,9 +633,11 @@ uhidioctl(dev, cmd, addr, flag, p) int flag; struct proc *p; { - USB_GET_SC(uhid, UHIDUNIT(dev), sc); + struct uhid_softc *sc; int error; + USB_GET_SC(uhid, UHIDUNIT(dev), sc); + sc->sc_refcnt++; error = uhid_do_ioctl(sc, cmd, addr, flag, p); if (--sc->sc_refcnt < 0) @@ -651,8 +651,10 @@ uhidpoll(dev, events, p) 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) |