Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb uhidev(9): Make uhidev state opaque.



details:   https://anonhg.NetBSD.org/src/rev/ddeca4aec129
branches:  trunk
changeset: 364544:ddeca4aec129
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Mar 28 12:44:17 2022 +0000

description:
uhidev(9): Make uhidev state opaque.

This makes the API simpler and clearer and gives us more latitude to
fix bugs in the state management without breaking the ABI.

XXX kernel ABI change to signature of uhidev_get_report_desc and
uhidev_open, and to struct uhidev_attach_arg, requires bump for
uhidev driver modules

diffstat:

 sys/dev/usb/uatp.c   |   35 ++++++-------
 sys/dev/usb/ucycom.c |   38 +++++++-------
 sys/dev/usb/uhid.c   |   57 +++++++++++-----------
 sys/dev/usb/uhidev.c |  129 ++++++++++++++++++++++++++------------------------
 sys/dev/usb/uhidev.h |   26 +--------
 sys/dev/usb/ukbd.c   |   52 ++++++++++----------
 sys/dev/usb/ums.c    |   27 ++++-----
 sys/dev/usb/uthum.c  |   36 +++++---------
 sys/dev/usb/uts.c    |   41 +++++++--------
 9 files changed, 207 insertions(+), 234 deletions(-)

diffs (truncated from 1289 to 300 lines):

diff -r 6efa5b4fc1af -r ddeca4aec129 sys/dev/usb/uatp.c
--- a/sys/dev/usb/uatp.c        Mon Mar 28 12:44:06 2022 +0000
+++ b/sys/dev/usb/uatp.c        Mon Mar 28 12:44:17 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uatp.c,v 1.28 2022/03/28 12:43:12 riastradh Exp $      */
+/*     $NetBSD: uatp.c,v 1.29 2022/03/28 12:44:17 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2011-2014 The NetBSD Foundation, Inc.
@@ -146,7 +146,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uatp.c,v 1.28 2022/03/28 12:43:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uatp.c,v 1.29 2022/03/28 12:44:17 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -301,7 +301,7 @@
 static int geyser34_finalize(struct uatp_softc *);
 static void geyser34_deferred_reset(struct uatp_softc *);
 static void geyser34_reset_task(void *);
-static void uatp_intr(struct uhidev *, void *, unsigned int);
+static void uatp_intr(void *, void *, unsigned int);
 static bool base_sample_softc_flag(const struct uatp_softc *, const uint8_t *);
 static bool base_sample_input_flag(const struct uatp_softc *, const uint8_t *);
 static void read_sample_1(uint8_t *, uint8_t *, const uint8_t *);
@@ -486,7 +486,8 @@
 };
 
 struct uatp_softc {
-       struct uhidev sc_hdev;          /* uhidev(9) parent.  */
+       device_t sc_dev;
+       struct uhidev *sc_hdev;         /* uhidev(9) parent.  */
        struct usbd_device *sc_udev;    /* USB device.  */
        device_t sc_wsmousedev;         /* Attached wsmouse device.  */
        const struct uatp_parameters *sc_parameters;
@@ -691,7 +692,7 @@
 static device_t
 uatp_dev(const struct uatp_softc *sc)
 {
-       return sc->sc_hdev.sc_dev;
+       return sc->sc_dev;
 }
 
 static uint8_t *
@@ -931,12 +932,8 @@
        int report_size, input_size;
        struct wsmousedev_attach_args a;
 
-       /* Set up uhidev state.  (Why doesn't uhidev do most of this?)  */
-       sc->sc_hdev.sc_dev = self;
-       sc->sc_hdev.sc_intr = uatp_intr;
-       sc->sc_hdev.sc_parent = uha->parent;
-       sc->sc_hdev.sc_report_id = uha->reportid;
-
+       sc->sc_dev = self;
+       sc->sc_hdev = uha->parent;
        sc->sc_udev = uha->uiaa->uiaa_device;
 
        /* Identify ourselves to dmesg.  */
@@ -948,7 +945,7 @@
            "vendor 0x%04x, product 0x%04x, report id %d\n",
            (unsigned int)uha->uiaa->uiaa_vendor,
            (unsigned int)uha->uiaa->uiaa_product,
-           (int)uha->reportid);
+           uha->reportid);
 
        uhidev_get_report_desc(uha->parent, &report_descriptor, &report_size);
        input_size = hid_report_size(report_descriptor, report_size, hid_input,
@@ -1251,8 +1248,8 @@
        tap_enable(sc);
        uatp_clear_position(sc);
 
-       DPRINTF(sc, UATP_DEBUG_MISC, ("uhidev_open(%p)\n", &sc->sc_hdev));
-       return uhidev_open(&sc->sc_hdev);
+       DPRINTF(sc, UATP_DEBUG_MISC, ("uhidev_open(%p)\n", sc->sc_hdev));
+       return uhidev_open(sc->sc_hdev, &uatp_intr, sc);
 }
 
 static void
@@ -1270,8 +1267,8 @@
        tap_disable(sc);
        sc->sc_status &=~ UATP_ENABLED;
 
-       DPRINTF(sc, UATP_DEBUG_MISC, ("uhidev_close(%p)\n", &sc->sc_hdev));
-       uhidev_close(&sc->sc_hdev);
+       DPRINTF(sc, UATP_DEBUG_MISC, ("uhidev_close(%p)\n", sc->sc_hdev));
+       uhidev_close(sc->sc_hdev);
 }
 
 static int
@@ -1399,15 +1396,15 @@
 /* Interrupt handler */
 
 static void
-uatp_intr(struct uhidev *addr, void *ibuf, unsigned int len)
+uatp_intr(void *cookie, void *ibuf, unsigned int len)
 {
-       struct uatp_softc *sc = (struct uatp_softc *)addr;
+       struct uatp_softc *sc = cookie;
        uint8_t *input;
        int dx, dy, dz, dw;
        uint32_t buttons;
 
        DPRINTF(sc, UATP_DEBUG_INTR, ("softc %p, ibuf %p, len %u\n",
-           addr, ibuf, len));
+           sc, ibuf, len));
 
        /*
         * Some devices break packets up into chunks, so we accumulate
diff -r 6efa5b4fc1af -r ddeca4aec129 sys/dev/usb/ucycom.c
--- a/sys/dev/usb/ucycom.c      Mon Mar 28 12:44:06 2022 +0000
+++ b/sys/dev/usb/ucycom.c      Mon Mar 28 12:44:17 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ucycom.c,v 1.54 2022/03/28 12:43:30 riastradh Exp $    */
+/*     $NetBSD: ucycom.c,v 1.55 2022/03/28 12:44:17 riastradh Exp $    */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.54 2022/03/28 12:43:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.55 2022/03/28 12:44:17 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -117,7 +117,8 @@
 #define UCYCOM_ORESET  0x08
 
 struct ucycom_softc {
-       struct uhidev           sc_hdev;
+       device_t                sc_dev;
+       struct uhidev           *sc_hdev;
        struct usbd_device      *sc_udev;
 
        struct usb_task         sc_task;
@@ -176,7 +177,7 @@
 Static void ucycomstart(struct tty *);
 Static void ucycomstarttask(void *);
 Static void ucycomwritecb(struct usbd_xfer *, void *, usbd_status);
-Static void ucycom_intr(struct uhidev *, void *, u_int);
+Static void ucycom_intr(void *, void *, u_int);
 Static int ucycom_configure(struct ucycom_softc *, uint32_t, uint8_t);
 Static void tiocm_to_ucycom(struct ucycom_softc *, u_long, int);
 Static int ucycom_to_tiocm(struct ucycom_softc *);
@@ -222,10 +223,8 @@
        int size, repid;
        void *desc;
 
-       sc->sc_hdev.sc_dev = self;
-       sc->sc_hdev.sc_intr = ucycom_intr;
-       sc->sc_hdev.sc_parent = uha->parent;
-       sc->sc_hdev.sc_report_id = uha->reportid;
+       sc->sc_dev = self;
+       sc->sc_hdev = uha->parent;
        sc->sc_udev = uha->uiaa->uiaa_device;
        sc->sc_init_state = UCYCOM_INIT_NONE;
 
@@ -280,7 +279,7 @@
                mutex_spin_exit(&tty_lock);
        }
        /* Wait for processes to go away. */
-       usb_detach_waitold(sc->sc_hdev.sc_dev);
+       usb_detach_waitold(sc->sc_dev);
        splx(s);
 
        /* locate the major number */
@@ -358,7 +357,7 @@
                return EIO;
        if (sc->sc_init_state != UCYCOM_INIT_INITED)
                return ENXIO;
-       if (!device_is_active(sc->sc_hdev.sc_dev))
+       if (!device_is_active(sc->sc_dev))
                return ENXIO;
 
        tp = sc->sc_tty;
@@ -375,7 +374,7 @@
 
                tp->t_dev = dev;
 
-               err = uhidev_open(&sc->sc_hdev);
+               err = uhidev_open(sc->sc_hdev, &ucycom_intr, sc);
                if (err) {
                        /* Any cleanup? */
                        splx(s);
@@ -617,7 +616,7 @@
        usbd_status err;
 
        /* What can we do on error? */
-       err = uhidev_write_async(&sc->sc_hdev, sc->sc_obuf, sc->sc_olen, 0,
+       err = uhidev_write_async(sc->sc_hdev, sc->sc_obuf, sc->sc_olen, 0,
            USBD_NO_TIMEOUT, ucycomwritecb, sc);
 
 #ifdef UCYCOM_DEBUG
@@ -942,7 +941,7 @@
        report[2] = (baud >> 16) & 0xff;
        report[3] = (baud >> 24) & 0xff;
        report[4] = cfg;
-       err = uhidev_set_report(&sc->sc_hdev, UHID_FEATURE_REPORT,
+       err = uhidev_set_report(sc->sc_hdev, UHID_FEATURE_REPORT,
            report, sc->sc_flen);
        if (err != 0) {
                DPRINTF(("%s\n", usbd_errstr(err)));
@@ -959,9 +958,9 @@
 }
 
 Static void
-ucycom_intr(struct uhidev *addr, void *ibuf, u_int len)
+ucycom_intr(void *cookie, void *ibuf, u_int len)
 {
-       struct ucycom_softc *sc = (struct ucycom_softc *)addr;
+       struct ucycom_softc *sc = cookie;
        struct tty *tp = sc->sc_tty;
        int (*rint)(int , struct tty *) = tp->t_linesw->l_rint;
        uint8_t *cp = ibuf;
@@ -1005,8 +1004,7 @@
                DPRINTFN(7,("ucycom_intr: char=0x%02x\n", *cp));
                if ((*rint)(*cp++, tp) == -1) {
                        /* XXX what should we do? */
-                       aprint_error_dev(sc->sc_hdev.sc_dev,
-                           "lost a character\n");
+                       aprint_error_dev(sc->sc_dev, "lost a character\n");
                        break;
                }
        }
@@ -1124,7 +1122,7 @@
        memset(sc->sc_obuf, 0, sc->sc_olen);
        sc->sc_obuf[0] = sc->sc_mcr;
 
-       err = uhidev_write(&sc->sc_hdev, sc->sc_obuf, sc->sc_olen);
+       err = uhidev_write(sc->sc_hdev, sc->sc_obuf, sc->sc_olen);
        if (err) {
                DPRINTF(("ucycom_set_status: err=%d\n", err));
        }
@@ -1137,7 +1135,7 @@
        int err, cfg, baud;
        uint8_t report[5];
 
-       err = uhidev_get_report(&sc->sc_hdev, UHID_FEATURE_REPORT,
+       err = uhidev_get_report(sc->sc_hdev, UHID_FEATURE_REPORT,
            report, sc->sc_flen);
        if (err) {
                DPRINTF(("%s: failed\n", __func__));
@@ -1163,7 +1161,7 @@
 
        obuf = sc->sc_obuf;
        sc->sc_obuf = NULL;
-       uhidev_close(&sc->sc_hdev);
+       uhidev_close(sc->sc_hdev);
 
        if (obuf != NULL)
                kmem_free(obuf, sc->sc_olen);
diff -r 6efa5b4fc1af -r ddeca4aec129 sys/dev/usb/uhid.c
--- a/sys/dev/usb/uhid.c        Mon Mar 28 12:44:06 2022 +0000
+++ b/sys/dev/usb/uhid.c        Mon Mar 28 12:44:17 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhid.c,v 1.122 2022/03/28 12:43:12 riastradh Exp $     */
+/*     $NetBSD: uhid.c,v 1.123 2022/03/28 12:44:17 riastradh Exp $     */
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.122 2022/03/28 12:43:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.123 2022/03/28 12:44:17 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -85,8 +85,10 @@
 #endif
 
 struct uhid_softc {
-       struct uhidev sc_hdev;
+       device_t sc_dev;
+       struct uhidev *sc_hdev;
        struct usbd_device *sc_udev;
+       uint8_t sc_report_id;
 
        kmutex_t sc_lock;
        kcondvar_t sc_cv;
@@ -144,7 +146,7 @@
        .d_flag = D_OTHER
 };
 
-static void uhid_intr(struct uhidev *, void *, u_int);
+static void uhid_intr(void *, void *, u_int);
 
 static int     uhid_match(device_t, cfdata_t, void *);
 static void    uhid_attach(device_t, device_t, void *);
@@ -176,13 +178,12 @@
        int size, repid;
        void *desc;
 
-       sc->sc_hdev.sc_dev = self;
+       sc->sc_dev = self;



Home | Main Index | Thread Index | Old Index