Module Name:    src
Committed By:   riastradh
Date:           Mon Mar 28 12:43:12 UTC 2022

Modified Files:
        src/sys/arch/macppc/dev: pbms.c
        src/sys/dev/usb: uatp.c uhid.c ukbd.c ums.c uthum.c

Log Message:
uhidev(9): Get the device and interface through attach args.

This way uhidev drivers don't need access to uhidev_softc itself for
it.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/macppc/dev/pbms.c
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/usb/uatp.c
cvs rdiff -u -r1.121 -r1.122 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.157 -r1.158 src/sys/dev/usb/ukbd.c
cvs rdiff -u -r1.101 -r1.102 src/sys/dev/usb/ums.c
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/usb/uthum.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/macppc/dev/pbms.c
diff -u src/sys/arch/macppc/dev/pbms.c:1.19 src/sys/arch/macppc/dev/pbms.c:1.20
--- src/sys/arch/macppc/dev/pbms.c:1.19	Sat Aug  7 16:18:57 2021
+++ src/sys/arch/macppc/dev/pbms.c	Mon Mar 28 12:43:12 2022
@@ -1,4 +1,4 @@
-/* $Id: pbms.c,v 1.19 2021/08/07 16:18:57 thorpej Exp $ */
+/* $Id: pbms.c,v 1.20 2022/03/28 12:43:12 riastradh Exp $ */
 
 /*
  * Copyright (c) 2005, Johan Wallén
@@ -307,7 +307,8 @@ pbms_match(device_t parent, cfdata_t mat
 	 * we expect. 
 	 */
 	if (uha->uiaa->uiaa_proto == UIPROTO_MOUSE &&
-	    (udd = usbd_get_device_descriptor(uha->parent->sc_udev)) != NULL) {
+	    ((udd = usbd_get_device_descriptor(uha->uiaa->uiaa_device))
+		!= NULL)) {
 		vendor = UGETW(udd->idVendor);
 		product = UGETW(udd->idProduct);
 		for (i = 0; i < PBMS_NUM_DEVICES; i++) {
@@ -329,6 +330,7 @@ pbms_attach(device_t parent, device_t se
 	struct uhidev_attach_arg *uha = aux;
 	struct pbms_dev *pd;
 	struct pbms_softc *sc = device_private(self);
+	struct usbd_device *udev;
 	usb_device_descriptor_t *udd;
 	int i;
 	uint16_t vendor, product;
@@ -341,7 +343,8 @@ pbms_attach(device_t parent, device_t se
 	sc->sc_datalen = PBMS_DATA_LEN;
 
 	/* Fill in device-specific parameters. */
-	if ((udd = usbd_get_device_descriptor(uha->parent->sc_udev)) != NULL) {
+	udev = uha->uiaa->uiaa_udevice;
+	if ((udd = usbd_get_device_descriptor(udev)) != NULL) {
 		product = UGETW(udd->idProduct);
 		vendor = UGETW(udd->idVendor);
 		for (i = 0; i < PBMS_NUM_DEVICES; i++) {

Index: src/sys/dev/usb/uatp.c
diff -u src/sys/dev/usb/uatp.c:1.27 src/sys/dev/usb/uatp.c:1.28
--- src/sys/dev/usb/uatp.c:1.27	Sat Aug  7 16:19:17 2021
+++ src/sys/dev/usb/uatp.c	Mon Mar 28 12:43:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uatp.c,v 1.27 2021/08/07 16:19:17 thorpej Exp $	*/
+/*	$NetBSD: uatp.c,v 1.28 2022/03/28 12:43:12 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.27 2021/08/07 16:19:17 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uatp.c,v 1.28 2022/03/28 12:43:12 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -486,7 +486,8 @@ static const struct uatp_knobs default_k
 };
 
 struct uatp_softc {
-	struct uhidev sc_hdev;		/* USB parent.  */
+	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;
 	struct uatp_knobs sc_knobs;
@@ -936,6 +937,8 @@ uatp_attach(device_t parent, device_t se
 	sc->sc_hdev.sc_parent = uha->parent;
 	sc->sc_hdev.sc_report_id = uha->reportid;
 
+	sc->sc_udev = uha->uiaa->uiaa_device;
+
 	/* Identify ourselves to dmesg.  */
 	uatp_descriptor = find_uatp_descriptor(uha);
 	KASSERT(uatp_descriptor != NULL);
@@ -1296,7 +1299,7 @@ uatp_ioctl(void *v, unsigned long cmd, v
 static void
 geyser34_enable_raw_mode(struct uatp_softc *sc)
 {
-	struct usbd_device *udev = sc->sc_hdev.sc_parent->sc_udev;
+	struct usbd_device *udev = sc->sc_udev;
 	usb_device_request_t req;
 	usbd_status status;
 	uint8_t report[GEYSER34_MODE_PACKET_SIZE];
@@ -1368,8 +1371,8 @@ geyser34_finalize(struct uatp_softc *sc)
 {
 
 	DPRINTF(sc, UATP_DEBUG_MISC, ("finalizing\n"));
-	usb_rem_task_wait(sc->sc_hdev.sc_parent->sc_udev, &sc->sc_reset_task,
-	    USB_TASKQ_DRIVER, NULL);
+	usb_rem_task_wait(sc->sc_udev, &sc->sc_reset_task, USB_TASKQ_DRIVER,
+	    NULL);
 
 	return 0;
 }
@@ -1379,8 +1382,7 @@ geyser34_deferred_reset(struct uatp_soft
 {
 
 	DPRINTF(sc, UATP_DEBUG_RESET, ("deferring reset\n"));
-	usb_add_task(sc->sc_hdev.sc_parent->sc_udev, &sc->sc_reset_task,
-	    USB_TASKQ_DRIVER);
+	usb_add_task(sc->sc_udev, &sc->sc_reset_task, USB_TASKQ_DRIVER);
 }
 
 static void

Index: src/sys/dev/usb/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.121 src/sys/dev/usb/uhid.c:1.122
--- src/sys/dev/usb/uhid.c:1.121	Mon Mar 28 12:42:54 2022
+++ src/sys/dev/usb/uhid.c	Mon Mar 28 12:43:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.121 2022/03/28 12:42:54 riastradh Exp $	*/
+/*	$NetBSD: uhid.c,v 1.122 2022/03/28 12:43:12 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.121 2022/03/28 12:42:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.122 2022/03/28 12:43:12 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -86,6 +86,7 @@ int	uhiddebug = 0;
 
 struct uhid_softc {
 	struct uhidev sc_hdev;
+	struct usbd_device *sc_udev;
 
 	kmutex_t sc_lock;
 	kcondvar_t sc_cv;
@@ -181,6 +182,8 @@ uhid_attach(device_t parent, device_t se
 	sc->sc_hdev.sc_parent = uha->parent;
 	sc->sc_hdev.sc_report_id = uha->reportid;
 
+	sc->sc_udev = uha->uiaa->uiaa_device;
+
 	uhidev_get_report_desc(uha->parent, &desc, &size);
 	repid = uha->reportid;
 	sc->sc_isize = hid_report_size(desc, size, hid_input,   repid);
@@ -655,16 +658,16 @@ uhidioctl(dev_t dev, u_long cmd, void *a
 
 	case USB_GET_DEVICE_DESC:
 		*(usb_device_descriptor_t *)addr =
-			*usbd_get_device_descriptor(sc->sc_hdev.sc_parent->sc_udev);
+			*usbd_get_device_descriptor(sc->sc_udev);
 		break;
 
 	case USB_GET_DEVICEINFO:
-		usbd_fill_deviceinfo(sc->sc_hdev.sc_parent->sc_udev,
+		usbd_fill_deviceinfo(sc->sc_udev,
 				     (struct usb_device_info *)addr, 0);
 		break;
 	case USB_GET_DEVICEINFO_OLD:
 		MODULE_HOOK_CALL(usb_subr_fill_30_hook,
-                    (sc->sc_hdev.sc_parent->sc_udev,
+                    (sc->sc_udev,
 		      (struct usb_device_info_old *)addr, 0,
                       usbd_devinfo_vp, usbd_printBCD),
                     enosys(), err);
@@ -674,7 +677,7 @@ uhidioctl(dev_t dev, u_long cmd, void *a
 	case USB_GET_STRING_DESC:
 	    {
 		struct usb_string_desc *si = (struct usb_string_desc *)addr;
-		err = usbd_get_string_desc(sc->sc_hdev.sc_parent->sc_udev,
+		err = usbd_get_string_desc(sc->sc_udev,
 			si->usd_string_index,
 			si->usd_language_id, &si->usd_desc, &size);
 		if (err)

Index: src/sys/dev/usb/ukbd.c
diff -u src/sys/dev/usb/ukbd.c:1.157 src/sys/dev/usb/ukbd.c:1.158
--- src/sys/dev/usb/ukbd.c:1.157	Sat Jan  8 17:34:14 2022
+++ src/sys/dev/usb/ukbd.c	Mon Mar 28 12:43:12 2022
@@ -1,4 +1,4 @@
-/*      $NetBSD: ukbd.c,v 1.157 2022/01/08 17:34:14 riastradh Exp $        */
+/*      $NetBSD: ukbd.c,v 1.158 2022/03/28 12:43:12 riastradh Exp $        */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.157 2022/01/08 17:34:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.158 2022/03/28 12:43:12 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -236,6 +236,8 @@ Static const uint8_t ukbd_trtab[256] = {
 
 struct ukbd_softc {
 	struct uhidev sc_hdev;
+	struct usbd_device *sc_udev;
+	struct usbd_interface *sc_iface;
 
 	struct ukbd_data sc_ndata;
 	struct ukbd_data sc_odata;
@@ -410,6 +412,8 @@ ukbd_attach(device_t parent, device_t se
 	sc->sc_hdev.sc_intr = ukbd_intr;
 	sc->sc_hdev.sc_parent = uha->parent;
 	sc->sc_hdev.sc_report_id = uha->reportid;
+	sc->sc_udev = uha->uiaa->uiaa_device;
+	sc->sc_iface = uha->uiaa->uiaa_iface;
 	sc->sc_flags = 0;
 
 	aprint_naive("\n");
@@ -427,7 +431,7 @@ ukbd_attach(device_t parent, device_t se
 	}
 
 	/* Quirks */
-	qflags = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
+	qflags = usbd_get_quirks(sc->sc_udev)->uq_flags;
 	if (qflags & UQ_SPUR_BUT_UP)
 		sc->sc_flags |= FLAG_DEBOUNCE;
 	if (qflags & UQ_APPLE_ISO)
@@ -579,7 +583,7 @@ ukbd_detach(device_t self, int flags)
 
 	callout_halt(&sc->sc_delay, NULL);
 	callout_halt(&sc->sc_ledreset, NULL);
-	usb_rem_task_wait(sc->sc_hdev.sc_parent->sc_udev, &sc->sc_ledtask,
+	usb_rem_task_wait(sc->sc_udev, &sc->sc_ledtask,
 	    USB_TASKQ_DRIVER, NULL);
 
 	/* The console keyboard does not get a disable call, so check pipe. */
@@ -885,7 +889,7 @@ void
 ukbd_set_leds(void *v, int leds)
 {
 	struct ukbd_softc *sc = v;
-	struct usbd_device *udev = sc->sc_hdev.sc_parent->sc_udev;
+	struct usbd_device *udev = sc->sc_udev;
 
 	DPRINTF(("%s: sc=%p leds=%d, sc_leds=%d\n", __func__,
 		 sc, leds, sc->sc_leds));
@@ -995,7 +999,7 @@ ukbd_cngetc(void *v, u_int *type, int *d
 	DPRINTFN(0,("%s: enter\n", __func__));
 	sc->sc_flags |= FLAG_POLLING;
 	if (sc->sc_npollchar <= 0)
-		usbd_dopoll(sc->sc_hdev.sc_parent->sc_iface);
+		usbd_dopoll(sc->sc_iface);
 	sc->sc_flags &= ~FLAG_POLLING;
 	if (sc->sc_npollchar > 0) {
 		c = sc->sc_pollchars[0];
@@ -1021,7 +1025,8 @@ ukbd_cnpollc(void *v, int on)
 
 	DPRINTFN(2,("%s: sc=%p on=%d\n", __func__, v, on));
 
-	usbd_interface2device_handle(sc->sc_hdev.sc_parent->sc_iface, &dev);
+	/* XXX Can this just use sc->sc_udev, or am I mistaken?  */
+	usbd_interface2device_handle(sc->sc_iface, &dev);
 	if (on) {
 		sc->sc_spl = splusb();
 		pollenter++;

Index: src/sys/dev/usb/ums.c
diff -u src/sys/dev/usb/ums.c:1.101 src/sys/dev/usb/ums.c:1.102
--- src/sys/dev/usb/ums.c:1.101	Fri Oct  1 21:14:06 2021
+++ src/sys/dev/usb/ums.c	Mon Mar 28 12:43:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ums.c,v 1.101 2021/10/01 21:14:06 macallan Exp $	*/
+/*	$NetBSD: ums.c,v 1.102 2022/03/28 12:43:12 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2017 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.101 2021/10/01 21:14:06 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.102 2022/03/28 12:43:12 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -76,6 +76,7 @@ int	umsdebug = 0;
 
 struct ums_softc {
 	struct uhidev sc_hdev;
+	struct usbd_device *sc_udev;
 	struct hidms sc_ms;
 
 	bool	sc_alwayson;
@@ -149,8 +150,9 @@ ums_attach(device_t parent, device_t sel
 	sc->sc_hdev.sc_intr = ums_intr;
 	sc->sc_hdev.sc_parent = uha->parent;
 	sc->sc_hdev.sc_report_id = uha->reportid;
+	sc->sc_udev = uha->uiaa->uiaa_device;
 
-	quirks = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
+	quirks = usbd_get_quirks(sc->sc_udev)->uq_flags;
 	if (quirks & UQ_MS_REVZ)
 		sc->sc_ms.flags |= HIDMS_REVZ;
 	if (quirks & UQ_SPUR_BUT_UP)

Index: src/sys/dev/usb/uthum.c
diff -u src/sys/dev/usb/uthum.c:1.21 src/sys/dev/usb/uthum.c:1.22
--- src/sys/dev/usb/uthum.c:1.21	Sun Jun 13 09:28:23 2021
+++ src/sys/dev/usb/uthum.c	Mon Mar 28 12:43:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uthum.c,v 1.21 2021/06/13 09:28:23 mlelstv Exp $   */
+/*	$NetBSD: uthum.c,v 1.22 2022/03/28 12:43:12 riastradh Exp $   */
 /*	$OpenBSD: uthum.c,v 1.6 2010/01/03 18:43:02 deraadt Exp $   */
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uthum.c,v 1.21 2021/06/13 09:28:23 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uthum.c,v 1.22 2022/03/28 12:43:12 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -130,7 +130,7 @@ uthum_attach(device_t parent, device_t s
 {
 	struct uthum_softc *sc = device_private(self);
 	struct uhidev_attach_arg *uha = aux;
-	struct usbd_device *dev = uha->parent->sc_udev;
+	struct usbd_device *dev = uha->uiaa->uiaa_device;
 	int size, repid;
 	void *desc;
 

Reply via email to