Module Name:    src
Committed By:   pgoyette
Date:           Thu Mar 29 11:20:03 UTC 2018

Modified Files:
        src/sys/compat/common [pgoyette-compat]: compat_30_mod.c compat_mod.c
            compat_mod.h files.common
        src/sys/dev/usb [pgoyette-compat]: ugen.c uhid.c usb.c usb_subr.c
            usbdi.h
        src/sys/kern [pgoyette-compat]: compat_stub.c
        src/sys/sys [pgoyette-compat]: compat_stub.h
Added Files:
        src/sys/compat/common [pgoyette-compat]: usb_30_subr.c

Log Message:
Split out the usb compat_30 code and add it to the module


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/compat/common/compat_30_mod.c
cvs rdiff -u -r1.24.14.22 -r1.24.14.23 src/sys/compat/common/compat_mod.c
cvs rdiff -u -r1.1.42.11 -r1.1.42.12 src/sys/compat/common/compat_mod.h
cvs rdiff -u -r1.1.2.21 -r1.1.2.22 src/sys/compat/common/files.common
cvs rdiff -u -r0 -r1.1.2.1 src/sys/compat/common/usb_30_subr.c
cvs rdiff -u -r1.139 -r1.139.2.1 src/sys/dev/usb/ugen.c
cvs rdiff -u -r1.101 -r1.101.2.1 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.168 -r1.168.2.1 src/sys/dev/usb/usb.c
cvs rdiff -u -r1.223 -r1.223.2.1 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.92 -r1.92.14.1 src/sys/dev/usb/usbdi.h
cvs rdiff -u -r1.1.2.10 -r1.1.2.11 src/sys/kern/compat_stub.c
cvs rdiff -u -r1.1.2.10 -r1.1.2.11 src/sys/sys/compat_stub.h

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

Modified files:

Index: src/sys/compat/common/compat_30_mod.c
diff -u src/sys/compat/common/compat_30_mod.c:1.1.2.2 src/sys/compat/common/compat_30_mod.c:1.1.2.3
--- src/sys/compat/common/compat_30_mod.c:1.1.2.2	Wed Mar 28 07:51:09 2018
+++ src/sys/compat/common/compat_30_mod.c	Thu Mar 29 11:20:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_30_mod.c,v 1.1.2.2 2018/03/28 07:51:09 pgoyette Exp $	*/
+/*	$NetBSD: compat_30_mod.c,v 1.1.2.3 2018/03/29 11:20:02 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_30_mod.c,v 1.1.2.2 2018/03/28 07:51:09 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_30_mod.c,v 1.1.2.3 2018/03/29 11:20:02 pgoyette Exp $");
 
 #include <sys/systm.h>
 #include <sys/module.h>
@@ -64,6 +64,7 @@ compat_30_init(void)
 	}
 	bio_30_init();
 	vnd_30_init();
+	usb_30_init();
 
 	return error;
 }
@@ -73,23 +74,26 @@ compat_30_fini(void)
 {
 	int error = 0;
 
+	usb_30_fini();
 	vnd_30_fini();
 	bio_30_fini();
 
 	error = kern_time_30_fini();
-	if (error != 0) {
-		bio_30_init();
-		vnd_30_init();
-		return error;
-	}
+	if (error != 0)
+		goto err1;
 
 	error = vfs_syscalls_30_fini();
-	if (error != 0) {
-		bio_30_init();
-		vnd_30_init();
-		kern_time_30_init();
-		return error;
-	}
+	if (error != 0)
+		goto err2;
+
+	return 0;
+
+ err2:
+	kern_time_30_init();
+ err1:
+	bio_30_init();
+	vnd_30_init();
+	usb_30_init();
 
 	return error;
 }

Index: src/sys/compat/common/compat_mod.c
diff -u src/sys/compat/common/compat_mod.c:1.24.14.22 src/sys/compat/common/compat_mod.c:1.24.14.23
--- src/sys/compat/common/compat_mod.c:1.24.14.22	Wed Mar 28 04:18:24 2018
+++ src/sys/compat/common/compat_mod.c	Thu Mar 29 11:20:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_mod.c,v 1.24.14.22 2018/03/28 04:18:24 pgoyette Exp $	*/
+/*	$NetBSD: compat_mod.c,v 1.24.14.23 2018/03/29 11:20:02 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_mod.c,v 1.24.14.22 2018/03/28 04:18:24 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_mod.c,v 1.24.14.23 2018/03/29 11:20:02 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -77,7 +77,8 @@ static struct sysctllog *compat_clog = N
 #endif
 
 static const char * const compat_includes[] = {
-	"compat_80", "compat_70", "compat_60", "compat_50", 
+	"compat_80", "compat_70", "compat_60", "compat_50", "compat_40",
+	"compat_30",
 	NULL
 };
 

Index: src/sys/compat/common/compat_mod.h
diff -u src/sys/compat/common/compat_mod.h:1.1.42.11 src/sys/compat/common/compat_mod.h:1.1.42.12
--- src/sys/compat/common/compat_mod.h:1.1.42.11	Wed Mar 28 07:51:09 2018
+++ src/sys/compat/common/compat_mod.h	Thu Mar 29 11:20:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_mod.h,v 1.1.42.11 2018/03/28 07:51:09 pgoyette Exp $	*/
+/*	$NetBSD: compat_mod.h,v 1.1.42.12 2018/03/29 11:20:02 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -101,6 +101,8 @@ void bio_30_init(void);
 void bio_30_fini(void);
 void vnd_30_init(void);
 void vnd_30_fini(void);
+void usb_30_init(void);
+void usb_30_fini(void);
 #endif
 
 #endif /* !_COMPAT_MOD_H_ */

Index: src/sys/compat/common/files.common
diff -u src/sys/compat/common/files.common:1.1.2.21 src/sys/compat/common/files.common:1.1.2.22
--- src/sys/compat/common/files.common:1.1.2.21	Wed Mar 28 07:51:09 2018
+++ src/sys/compat/common/files.common	Thu Mar 29 11:20:02 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.common,v 1.1.2.21 2018/03/28 07:51:09 pgoyette Exp $
+#	$NetBSD: files.common,v 1.1.2.22 2018/03/29 11:20:02 pgoyette Exp $
 
 #
 # Generic files, used by all compat options.
@@ -53,6 +53,7 @@ file	compat/common/vfs_syscalls_30.c		co
 file	compat/common/uipc_syscalls_30.c	compat_30
 file	compat/common/bio_30.c			compat_30
 file	compat/common/vnd_30.c			compat_30
+file	compat/common/usb_30_subr.c		compat_30
 
 # Compatibility code for NetBSD 4.0
 file	compat/common/compat_40_mod.c		compat_40

Index: src/sys/dev/usb/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.139 src/sys/dev/usb/ugen.c:1.139.2.1
--- src/sys/dev/usb/ugen.c:1.139	Mon Mar  5 09:35:01 2018
+++ src/sys/dev/usb/ugen.c	Thu Mar 29 11:20:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.139 2018/03/05 09:35:01 ws Exp $	*/
+/*	$NetBSD: ugen.c,v 1.139.2.1 2018/03/29 11:20:02 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.139 2018/03/05 09:35:01 ws Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.139.2.1 2018/03/29 11:20:02 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.1
 #include <sys/proc.h>
 #include <sys/vnode.h>
 #include <sys/poll.h>
+#include <sys/compat_stub.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -1835,13 +1836,11 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 		usbd_fill_deviceinfo(sc->sc_udev,
 				     (struct usb_device_info *)addr, 0);
 		break;
-#ifdef COMPAT_30
 	case USB_GET_DEVICEINFO_OLD:
-		usbd_fill_deviceinfo_old(sc->sc_udev,
-					 (struct usb_device_info_old *)addr, 0);
-
-		break;
-#endif
+		if ((*usbd30_fill_deviceinfo_old)(sc->sc_udev,
+			     (struct usb_device_info_old *)addr, 0) == 0)
+			return 0;
+		return EINVAL;
 	default:
 		return EINVAL;
 	}

Index: src/sys/dev/usb/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.101 src/sys/dev/usb/uhid.c:1.101.2.1
--- src/sys/dev/usb/uhid.c:1.101	Sun Dec 10 17:03:07 2017
+++ src/sys/dev/usb/uhid.c	Thu Mar 29 11:20:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.101 2017/12/10 17:03:07 bouyer Exp $	*/
+/*	$NetBSD: uhid.c,v 1.101.2.1 2018/03/29 11:20:03 pgoyette 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.101 2017/12/10 17:03:07 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.101.2.1 2018/03/29 11:20:03 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.1
 #include <sys/vnode.h>
 #include <sys/poll.h>
 #include <sys/intr.h>
+#include <sys/compat_stub.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbhid.h>
@@ -652,13 +653,13 @@ uhid_do_ioctl(struct uhid_softc *sc, u_l
 		usbd_fill_deviceinfo(sc->sc_hdev.sc_parent->sc_udev,
 				     (struct usb_device_info *)addr, 0);
 		break;
-#ifdef COMPAT_30
 	case USB_GET_DEVICEINFO_OLD:
-		usbd_fill_deviceinfo_old(sc->sc_hdev.sc_parent->sc_udev,
-					 (struct usb_device_info_old *)addr, 0);
-
+		err = (*usbd30_fill_deviceinfo_old)(
+			    sc->sc_hdev.sc_parent->sc_udev,
+			    (struct usb_device_info_old *)addr, 0);
+		if (err == 0)
+			return 0;
 		break;
-#endif
 	case USB_GET_STRING_DESC:
 	    {
 		struct usb_string_desc *si = (struct usb_string_desc *)addr;

Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.168 src/sys/dev/usb/usb.c:1.168.2.1
--- src/sys/dev/usb/usb.c:1.168	Sat Oct 28 00:37:12 2017
+++ src/sys/dev/usb/usb.c	Thu Mar 29 11:20:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.168 2017/10/28 00:37:12 pgoyette Exp $	*/
+/*	$NetBSD: usb.c,v 1.168.2.1 2018/03/29 11:20:03 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.168 2017/10/28 00:37:12 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.168.2.1 2018/03/29 11:20:03 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -64,6 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.16
 #include <sys/once.h>
 #include <sys/atomic.h>
 #include <sys/sysctl.h>
+#include <sys/compat_stub.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -198,10 +199,6 @@ Static int usb_get_next_event(struct usb
 Static void usb_async_intr(void *);
 Static void usb_soft_intr(void *);
 
-#ifdef COMPAT_30
-Static void usb_copy_old_devinfo(struct usb_device_info_old *, const struct usb_device_info *);
-#endif
-
 Static const char *usbrev_str[] = USBREV_STR;
 
 static int usb_match(device_t, cfdata_t, void *);
@@ -568,22 +565,18 @@ int
 usbread(dev_t dev, struct uio *uio, int flag)
 {
 	struct usb_event *ue;
-#ifdef COMPAT_30
 	struct usb_event_old *ueo = NULL;	/* XXXGCC */
 	int useold = 0;
-#endif
 	int error, n;
 
 	if (minor(dev) != USB_DEV_MINOR)
 		return ENXIO;
 
 	switch (uio->uio_resid) {
-#ifdef COMPAT_30
 	case sizeof(struct usb_event_old):
 		ueo = kmem_zalloc(sizeof(struct usb_event_old), KM_SLEEP);
 		useold = 1;
 		/* FALLTHRU */
-#endif
 	case sizeof(struct usb_event):
 		ue = usb_alloc_event();
 		break;
@@ -607,43 +600,19 @@ usbread(dev_t dev, struct uio *uio, int 
 	}
 	mutex_exit(&usb_event_lock);
 	if (!error) {
-#ifdef COMPAT_30
 		if (useold) { /* copy fields to old struct */
-			ueo->ue_type = ue->ue_type;
-			memcpy(&ueo->ue_time, &ue->ue_time,
-			      sizeof(struct timespec));
-			switch (ue->ue_type) {
-				case USB_EVENT_DEVICE_ATTACH:
-				case USB_EVENT_DEVICE_DETACH:
-					usb_copy_old_devinfo(&ueo->u.ue_device, &ue->u.ue_device);
-					break;
-
-				case USB_EVENT_CTRLR_ATTACH:
-				case USB_EVENT_CTRLR_DETACH:
-					ueo->u.ue_ctrlr.ue_bus=ue->u.ue_ctrlr.ue_bus;
-					break;
-
-				case USB_EVENT_DRIVER_ATTACH:
-				case USB_EVENT_DRIVER_DETACH:
-					ueo->u.ue_driver.ue_cookie=ue->u.ue_driver.ue_cookie;
-					memcpy(ueo->u.ue_driver.ue_devname,
-					       ue->u.ue_driver.ue_devname,
-					       sizeof(ue->u.ue_driver.ue_devname));
-					break;
-				default:
-					;
-			}
+			error = (*usb30_copy_to_old)(ue, ueo, uio);
+			if (error == ENOSYS)
+				error = EINVAL;
 
-			error = uiomove((void *)ueo, sizeof(*ueo), uio);
+			if (!error)
+				error = uiomove((void *)ueo, sizeof(*ueo), uio);
 		} else
-#endif
 			error = uiomove((void *)ue, sizeof(*ue), uio);
 	}
 	usb_free_event(ue);
-#ifdef COMPAT_30
-	if (useold)
+	if (ueo)
 		kmem_free(ueo, sizeof(struct usb_event_old));
-#endif
 
 	return error;
 }
@@ -797,7 +766,6 @@ usbioctl(dev_t devt, u_long cmd, void *d
 		break;
 	}
 
-#ifdef COMPAT_30
 	case USB_DEVICEINFO_OLD:
 	{
 		struct usbd_device *dev;
@@ -813,10 +781,12 @@ usbioctl(dev_t devt, u_long cmd, void *d
 			error = ENXIO;
 			goto fail;
 		}
-		usbd_fill_deviceinfo_old(dev, di, 1);
-		break;
+		error = (*usbd30_fill_deviceinfo_old)(dev, di, 1);
+		if (error == ENOSYS)
+			error = EINVAL;
+		if (error)
+			goto fail;
 	}
-#endif
 
 	case USB_DEVICESTATS:
 		*(struct usb_device_stats *)data = sc->sc_bus->ub_stats;
@@ -1156,62 +1126,3 @@ usb_detach(device_t self, int flags)
 
 	return 0;
 }
-
-#ifdef COMPAT_30
-Static void
-usb_copy_old_devinfo(struct usb_device_info_old *uo,
-		     const struct usb_device_info *ue)
-{
-	const unsigned char *p;
-	unsigned char *q;
-	int i, n;
-
-	uo->udi_bus = ue->udi_bus;
-	uo->udi_addr = ue->udi_addr;
-	uo->udi_cookie = ue->udi_cookie;
-	for (i = 0, p = (const unsigned char *)ue->udi_product,
-	     q = (unsigned char *)uo->udi_product;
-	     *p && i < USB_MAX_STRING_LEN - 1; p++) {
-		if (*p < 0x80)
-			q[i++] = *p;
-		else {
-			q[i++] = '?';
-			if ((*p & 0xe0) == 0xe0)
-				p++;
-			p++;
-		}
-	}
-	q[i] = 0;
-
-	for (i = 0, p = ue->udi_vendor, q = uo->udi_vendor;
-	     *p && i < USB_MAX_STRING_LEN - 1; p++) {
-		if (* p < 0x80)
-			q[i++] = *p;
-		else {
-			q[i++] = '?';
-			p++;
-			if ((*p & 0xe0) == 0xe0)
-				p++;
-		}
-	}
-	q[i] = 0;
-
-	memcpy(uo->udi_release, ue->udi_release, sizeof(uo->udi_release));
-
-	uo->udi_productNo = ue->udi_productNo;
-	uo->udi_vendorNo = ue->udi_vendorNo;
-	uo->udi_releaseNo = ue->udi_releaseNo;
-	uo->udi_class = ue->udi_class;
-	uo->udi_subclass = ue->udi_subclass;
-	uo->udi_protocol = ue->udi_protocol;
-	uo->udi_config = ue->udi_config;
-	uo->udi_speed = ue->udi_speed;
-	uo->udi_power = ue->udi_power;
-	uo->udi_nports = ue->udi_nports;
-
-	for (n=0; n<USB_MAX_DEVNAMES; n++)
-		memcpy(uo->udi_devnames[n],
-		       ue->udi_devnames[n], USB_MAX_DEVNAMELEN);
-	memcpy(uo->udi_ports, ue->udi_ports, sizeof(uo->udi_ports));
-}
-#endif

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.223 src/sys/dev/usb/usb_subr.c:1.223.2.1
--- src/sys/dev/usb/usb_subr.c:1.223	Tue Dec 26 18:44:52 2017
+++ src/sys/dev/usb/usb_subr.c	Thu Mar 29 11:20:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.223 2017/12/26 18:44:52 khorben Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.223.2.1 2018/03/29 11:20:03 pgoyette Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.223 2017/12/26 18:44:52 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.223.2.1 2018/03/29 11:20:03 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -68,8 +68,6 @@ __KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v
 
 Static usbd_status usbd_set_config(struct usbd_device *, int);
 Static void usbd_devinfo(struct usbd_device *, int, char *, size_t);
-Static void usbd_devinfo_vp(struct usbd_device *, char *, size_t, char *, size_t,
-    int, int);
 Static int usbd_getnewaddr(struct usbd_bus *);
 Static int usbd_print(void *, const char *);
 Static int usbd_ifprint(void *, const char *);
@@ -194,7 +192,7 @@ usbd_get_device_strings(struct usbd_devi
 }
 
 
-Static void
+void
 usbd_devinfo_vp(struct usbd_device *dev, char *v, size_t vl, char *p,
     size_t pl, int usedev, int useencoded)
 {
@@ -1581,76 +1579,6 @@ usbd_fill_deviceinfo(struct usbd_device 
 	di->udi_nports = nports;
 }
 
-#ifdef COMPAT_30
-void
-usbd_fill_deviceinfo_old(struct usbd_device *dev, struct usb_device_info_old *di,
-                         int usedev)
-{
-	struct usbd_port *p;
-	int i, j, err;
-
-	di->udi_bus = device_unit(dev->ud_bus->ub_usbctl);
-	di->udi_addr = dev->ud_addr;
-	di->udi_cookie = dev->ud_cookie;
-	usbd_devinfo_vp(dev, di->udi_vendor, sizeof(di->udi_vendor),
-	    di->udi_product, sizeof(di->udi_product), usedev, 0);
-	usbd_printBCD(di->udi_release, sizeof(di->udi_release),
-	    UGETW(dev->ud_ddesc.bcdDevice));
-	di->udi_vendorNo = UGETW(dev->ud_ddesc.idVendor);
-	di->udi_productNo = UGETW(dev->ud_ddesc.idProduct);
-	di->udi_releaseNo = UGETW(dev->ud_ddesc.bcdDevice);
-	di->udi_class = dev->ud_ddesc.bDeviceClass;
-	di->udi_subclass = dev->ud_ddesc.bDeviceSubClass;
-	di->udi_protocol = dev->ud_ddesc.bDeviceProtocol;
-	di->udi_config = dev->ud_config;
-	di->udi_power = dev->ud_selfpowered ? 0 : dev->ud_power;
-	di->udi_speed = dev->ud_speed;
-
-	if (dev->ud_subdevlen > 0) {
-		for (i = 0, j = 0; i < dev->ud_subdevlen &&
-			     j < USB_MAX_DEVNAMES; i++) {
-			if (!dev->ud_subdevs[i])
-				continue;
-			strncpy(di->udi_devnames[j],
-			    device_xname(dev->ud_subdevs[i]), USB_MAX_DEVNAMELEN);
-			di->udi_devnames[j][USB_MAX_DEVNAMELEN-1] = '\0';
-			j++;
-		}
-	} else {
-		j = 0;
-	}
-	for (/* j is set */; j < USB_MAX_DEVNAMES; j++)
-		di->udi_devnames[j][0] = 0;		 /* empty */
-
-	if (!dev->ud_hub) {
-		di->udi_nports = 0;
-		return;
-	}
-
-	const int nports = dev->ud_hub->uh_hubdesc.bNbrPorts;
-	for (i = 0; i < __arraycount(di->udi_ports) && i < nports;
-	     i++) {
-		p = &dev->ud_hub->uh_ports[i];
-		if (p->up_dev)
-			err = p->up_dev->ud_addr;
-		else {
-			const int s = UGETW(p->up_status.wPortStatus);
-			if (s & UPS_PORT_ENABLED)
-				err = USB_PORT_ENABLED;
-			else if (s & UPS_SUSPEND)
-				err = USB_PORT_SUSPENDED;
-			else if (s & UPS_PORT_POWER)
-				err = USB_PORT_POWERED;
-			else
-				err = USB_PORT_DISABLED;
-		}
-		di->udi_ports[i] = err;
-	}
-	di->udi_nports = nports;
-}
-#endif
-
-
 void
 usb_free_device(struct usbd_device *dev)
 {

Index: src/sys/dev/usb/usbdi.h
diff -u src/sys/dev/usb/usbdi.h:1.92 src/sys/dev/usb/usbdi.h:1.92.14.1
--- src/sys/dev/usb/usbdi.h:1.92	Sun Aug 14 14:42:22 2016
+++ src/sys/dev/usb/usbdi.h	Thu Mar 29 11:20:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.h,v 1.92 2016/08/14 14:42:22 skrll Exp $	*/
+/*	$NetBSD: usbdi.h,v 1.92.14.1 2018/03/29 11:20:03 pgoyette Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $	*/
 
 /*
@@ -156,10 +156,6 @@ usbd_status usbd_get_interface(struct us
 int usbd_get_no_alts(usb_config_descriptor_t *, int);
 
 void usbd_fill_deviceinfo(struct usbd_device *, struct usb_device_info *, int);
-#ifdef COMPAT_30
-void usbd_fill_deviceinfo_old(struct usbd_device *, struct usb_device_info_old *,
-    int);
-#endif
 int usbd_get_interface_altindex(struct usbd_interface *);
 
 usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *,
@@ -231,6 +227,12 @@ const struct usb_devno *usb_match_device
 	usb_match_device((const struct usb_devno *)(tbl), sizeof(tbl) / sizeof((tbl)[0]), sizeof((tbl)[0]), (vendor), (product))
 #define	USB_PRODUCT_ANY		0xffff
 
+/* compat callbacks */
+void usbd_devinfo_vp(struct usbd_device *, char *, size_t, char *, size_t,
+    int, int);
+int usbd_printBCD(char *, size_t, int);
+
+
 /* NetBSD attachment information */
 
 /* Attach data */

Index: src/sys/kern/compat_stub.c
diff -u src/sys/kern/compat_stub.c:1.1.2.10 src/sys/kern/compat_stub.c:1.1.2.11
--- src/sys/kern/compat_stub.c:1.1.2.10	Wed Mar 28 07:51:09 2018
+++ src/sys/kern/compat_stub.c	Thu Mar 29 11:20:03 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.c,v 1.1.2.10 2018/03/28 07:51:09 pgoyette Exp $	*/
+/* $NetBSD: compat_stub.c,v 1.1.2.11 2018/03/29 11:20:03 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -33,6 +33,7 @@
 
 #ifdef _KERNEL_OPT
 #include "opt_ntp.h"
+#include "usb.h"
 #endif
 
 #include <sys/systm.h>
@@ -110,6 +111,26 @@ int (*compat_bio_30)(void *, u_long, voi
 /*
  * vnd ioctl compatability
  */
-int (*compat_vndioctl_30)(u_long cmd, struct lwp *l, void *data, int unit,
-    struct vattr *vattr_p, int (*get)(struct lwp *, void *, int,
-    struct vattr *)) = (void *)enosys;
+int (*compat_vndioctl_30)(u_long, struct lwp *, void *, int, struct vattr *,
+    int (*get)(struct lwp *, void *, int, struct vattr *)) = (void *)enosys;
+
+/*
+ * usb device_info compatability
+ */
+int (*usbd30_fill_deviceinfo_old)(struct usbd_device *,
+    struct usb_device_info_old *, int) = (void *)enosys;
+
+int (*usb30_copy_to_old)(struct usb_event *, struct usb_event_old *,
+    struct uio *) = (void *)enosys;
+
+#if NUSB > 0
+void (*vec_usbd_devinfo_vp)(struct usbd_device *, char *, size_t, char *,
+    size_t, int, int) = usbd_devinfo_vp;
+int (*vec_usbd_printBCD)(char *cp, size_t l, int bcd) = usbd_printBCD;
+
+#else
+void (*vec_usbd_devinfo_vp)(struct usbd_device *, char *, size_t, char *,
+    size_t, int, int) = NULL;
+int (*vec_usbd_printBCD)(char *cp, size_t l, int bcd) = NULL;
+#endif
+

Index: src/sys/sys/compat_stub.h
diff -u src/sys/sys/compat_stub.h:1.1.2.10 src/sys/sys/compat_stub.h:1.1.2.11
--- src/sys/sys/compat_stub.h:1.1.2.10	Wed Mar 28 07:51:09 2018
+++ src/sys/sys/compat_stub.h	Thu Mar 29 11:20:03 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.h,v 1.1.2.10 2018/03/28 07:51:09 pgoyette Exp $	*/
+/* $NetBSD: compat_stub.h,v 1.1.2.11 2018/03/29 11:20:03 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -124,4 +124,29 @@ struct vattr;
 extern int (*compat_vndioctl_30)(u_long, struct lwp *, void *, int,
     struct vattr *, int (*)(struct lwp *, void *, int, struct vattr *));
 
+/*
+ * usb devinfo compatability
+ */
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+
+struct usbd_device;
+struct usb_device_info;
+struct usb_device_info_old;
+struct usb_event;
+struct usb_event_old;
+struct uio;
+
+extern int (*usbd30_fill_deviceinfo_old)(struct usbd_device *,
+    struct usb_device_info_old *, int);
+
+extern int (*usb30_copy_to_old)(struct usb_event *ue, struct usb_event_old *ueo,
+    struct uio *uio);
+
+extern void (*vec_usbd_devinfo_vp)(struct usbd_device *, char *, size_t, char *,
+    size_t, int, int);
+
+extern int (*vec_usbd_printBCD)(char *cp, size_t l, int bcd);
+
 #endif	/* _SYS_COMPAT_STUB_H */

Added files:

Index: src/sys/compat/common/usb_30_subr.c
diff -u /dev/null src/sys/compat/common/usb_30_subr.c:1.1.2.1
--- /dev/null	Thu Mar 29 11:20:03 2018
+++ src/sys/compat/common/usb_30_subr.c	Thu Mar 29 11:20:02 2018
@@ -0,0 +1,243 @@
+/*	$NetBSD: usb_30_subr.c,v 1.1.2.1 2018/03/29 11:20:02 pgoyette Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
+
+/*
+ * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Lennart Augustsson ([email protected]) at
+ * Carlstedt Research & Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: usb_30_subr.c,v 1.1.2.1 2018/03/29 11:20:02 pgoyette Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_compat_netbsd.h"
+#include "opt_usb.h"
+#include "opt_usbverbose.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/device.h>
+#include <sys/select.h>
+#include <sys/proc.h>
+
+#include <sys/bus.h>
+#include <sys/module.h>
+#include <sys/compat_stub.h>
+
+#include <compat/common/compat_mod.h>
+
+#include <dev/usb/usb.h>
+
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/usbdivar.h>
+#include <dev/usb/usbdevs.h>
+#include <dev/usb/usb_quirks.h>
+#include <dev/usb/usb_verbose.h>
+#include <dev/usb/usbhist.h>
+
+Static void usb_copy_old_devinfo(struct usb_device_info_old *,
+    const struct usb_device_info *);
+
+Static void
+usb_copy_old_devinfo(struct usb_device_info_old *uo,
+		     const struct usb_device_info *ue)
+{
+	const unsigned char *p;
+	unsigned char *q;
+	int i, n;
+
+	uo->udi_bus = ue->udi_bus;
+	uo->udi_addr = ue->udi_addr;
+	uo->udi_cookie = ue->udi_cookie;
+	for (i = 0, p = (const unsigned char *)ue->udi_product,
+	     q = (unsigned char *)uo->udi_product;
+	     *p && i < USB_MAX_STRING_LEN - 1; p++) {
+		if (*p < 0x80)
+			q[i++] = *p;
+		else {
+			q[i++] = '?';
+			if ((*p & 0xe0) == 0xe0)
+				p++;
+			p++;
+		}
+	}
+	q[i] = 0;
+
+	for (i = 0, p = ue->udi_vendor, q = uo->udi_vendor;
+	     *p && i < USB_MAX_STRING_LEN - 1; p++) {
+		if (* p < 0x80)
+			q[i++] = *p;
+		else {
+			q[i++] = '?';
+			p++;
+			if ((*p & 0xe0) == 0xe0)
+				p++;
+		}
+	}
+	q[i] = 0;
+
+	memcpy(uo->udi_release, ue->udi_release, sizeof(uo->udi_release));
+
+	uo->udi_productNo = ue->udi_productNo;
+	uo->udi_vendorNo = ue->udi_vendorNo;
+	uo->udi_releaseNo = ue->udi_releaseNo;
+	uo->udi_class = ue->udi_class;
+	uo->udi_subclass = ue->udi_subclass;
+	uo->udi_protocol = ue->udi_protocol;
+	uo->udi_config = ue->udi_config;
+	uo->udi_speed = ue->udi_speed;
+	uo->udi_power = ue->udi_power;
+	uo->udi_nports = ue->udi_nports;
+
+	for (n=0; n<USB_MAX_DEVNAMES; n++)
+		memcpy(uo->udi_devnames[n],
+		       ue->udi_devnames[n], USB_MAX_DEVNAMELEN);
+	memcpy(uo->udi_ports, ue->udi_ports, sizeof(uo->udi_ports));
+}
+
+static int
+usbd_fill_deviceinfo_old(struct usbd_device *dev,
+    struct usb_device_info_old *di, int usedev)
+{
+	struct usbd_port *p;
+	int i, j, err;
+
+	di->udi_bus = device_unit(dev->ud_bus->ub_usbctl);
+	di->udi_addr = dev->ud_addr;
+	di->udi_cookie = dev->ud_cookie;
+	(*vec_usbd_devinfo_vp)(dev, di->udi_vendor, sizeof(di->udi_vendor),
+	    di->udi_product, sizeof(di->udi_product), usedev, 0);
+	(*vec_usbd_printBCD)(di->udi_release, sizeof(di->udi_release),
+	    UGETW(dev->ud_ddesc.bcdDevice));
+	di->udi_vendorNo = UGETW(dev->ud_ddesc.idVendor);
+	di->udi_productNo = UGETW(dev->ud_ddesc.idProduct);
+	di->udi_releaseNo = UGETW(dev->ud_ddesc.bcdDevice);
+	di->udi_class = dev->ud_ddesc.bDeviceClass;
+	di->udi_subclass = dev->ud_ddesc.bDeviceSubClass;
+	di->udi_protocol = dev->ud_ddesc.bDeviceProtocol;
+	di->udi_config = dev->ud_config;
+	di->udi_power = dev->ud_selfpowered ? 0 : dev->ud_power;
+	di->udi_speed = dev->ud_speed;
+
+	if (dev->ud_subdevlen > 0) {
+		for (i = 0, j = 0; i < dev->ud_subdevlen &&
+			     j < USB_MAX_DEVNAMES; i++) {
+			if (!dev->ud_subdevs[i])
+				continue;
+			strncpy(di->udi_devnames[j],
+			    device_xname(dev->ud_subdevs[i]), USB_MAX_DEVNAMELEN);
+			di->udi_devnames[j][USB_MAX_DEVNAMELEN-1] = '\0';
+			j++;
+		}
+	} else {
+		j = 0;
+	}
+	for (/* j is set */; j < USB_MAX_DEVNAMES; j++)
+		di->udi_devnames[j][0] = 0;		 /* empty */
+
+	if (!dev->ud_hub) {
+		di->udi_nports = 0;
+		return 0;
+	}
+
+	const int nports = dev->ud_hub->uh_hubdesc.bNbrPorts;
+	for (i = 0; i < __arraycount(di->udi_ports) && i < nports;
+	     i++) {
+		p = &dev->ud_hub->uh_ports[i];
+		if (p->up_dev)
+			err = p->up_dev->ud_addr;
+		else {
+			const int s = UGETW(p->up_status.wPortStatus);
+			if (s & UPS_PORT_ENABLED)
+				err = USB_PORT_ENABLED;
+			else if (s & UPS_SUSPEND)
+				err = USB_PORT_SUSPENDED;
+			else if (s & UPS_PORT_POWER)
+				err = USB_PORT_POWERED;
+			else
+				err = USB_PORT_DISABLED;
+		}
+		di->udi_ports[i] = err;
+	}
+	di->udi_nports = nports;
+
+	return 0;
+}
+
+static int
+usb_copy_to_old30(struct usb_event *ue, struct usb_event_old *ueo,
+    struct uio *uio)
+{
+
+	ueo->ue_type = ue->ue_type;
+	memcpy(&ueo->ue_time, &ue->ue_time, sizeof(struct timespec));
+	switch (ue->ue_type) {
+		case USB_EVENT_DEVICE_ATTACH:
+		case USB_EVENT_DEVICE_DETACH:
+			usb_copy_old_devinfo(&ueo->u.ue_device,
+			    &ue->u.ue_device);
+			break;
+
+		case USB_EVENT_CTRLR_ATTACH:
+		case USB_EVENT_CTRLR_DETACH:
+			ueo->u.ue_ctrlr.ue_bus=ue->u.ue_ctrlr.ue_bus;
+			break;
+
+		case USB_EVENT_DRIVER_ATTACH:
+		case USB_EVENT_DRIVER_DETACH:
+			ueo->u.ue_driver.ue_cookie=ue->u.ue_driver.ue_cookie;
+			memcpy(ueo->u.ue_driver.ue_devname,
+			    ue->u.ue_driver.ue_devname,
+			    sizeof(ue->u.ue_driver.ue_devname));
+			break;
+		default:
+			;
+	}
+
+	return 0;
+}
+
+void
+usb_30_init(void)
+{
+
+	usbd30_fill_deviceinfo_old = usbd_fill_deviceinfo_old;
+	usb30_copy_to_old = usb_copy_to_old30;
+}
+
+void
+usb_30_fini(void)
+{
+
+	usbd30_fill_deviceinfo_old = (void *)enosys;
+	usb30_copy_to_old = (void *)enosys;
+}

Reply via email to