Module Name:    src
Committed By:   pgoyette
Date:           Sat May 29 01:14:30 UTC 2010

Modified Files:
        src/distrib/sets/lists/modules: mi
        src/sys/dev/usb: files.usb usb.c usb_subr.c
        src/sys/modules: Makefile
Added Files:
        src/sys/dev/usb: usb_verbose.c usb_verbose.h
        src/sys/modules/usbverbose: Makefile

Log Message:
Extract USBVERBOSE into a kernel module.  The module can be builtin
by defining 'options USBVERBOSE' in the kernel config file (no change
from current behavior), or it can be loaded at boot time on those
architectures that support the boot loader's "load" command.

The module is built for all architectures, whether or not USB support
exists.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/distrib/sets/lists/modules/mi
cvs rdiff -u -r1.97 -r1.98 src/sys/dev/usb/files.usb
cvs rdiff -u -r1.120 -r1.121 src/sys/dev/usb/usb.c
cvs rdiff -u -r1.168 -r1.169 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r0 -r1.1 src/sys/dev/usb/usb_verbose.c \
    src/sys/dev/usb/usb_verbose.h
cvs rdiff -u -r1.42 -r1.43 src/sys/modules/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/modules/usbverbose/Makefile

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

Modified files:

Index: src/distrib/sets/lists/modules/mi
diff -u src/distrib/sets/lists/modules/mi:1.14 src/distrib/sets/lists/modules/mi:1.15
--- src/distrib/sets/lists/modules/mi:1.14	Mon May 24 20:29:41 2010
+++ src/distrib/sets/lists/modules/mi	Sat May 29 01:14:30 2010
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.14 2010/05/24 20:29:41 pgoyette Exp $
+# $NetBSD: mi,v 1.15 2010/05/29 01:14:30 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -124,6 +124,8 @@
 ./@MODULEDIR@/umap/umap.kmod			base-kernel-modules	kmod
 ./@MODULEDIR@/union				base-kernel-modules	kmod
 ./@MODULEDIR@/union/union.kmod			base-kernel-modules	kmod
+./@MODULEDIR@/usbverbose			base-kernel-modules	kmod
+./@MODULEDIR@/usbverbose/usbverbose.kmod	base-kernel-modules	kmod
 ./@MODULEDIR@/vnd 				base-kernel-modules	kmod
 ./@MODULEDIR@/vnd/vnd.kmod		        base-kernel-modules	kmod
 ./@MODULEDIR@/zfs				base-kernel-modules     kmod,zfs

Index: src/sys/dev/usb/files.usb
diff -u src/sys/dev/usb/files.usb:1.97 src/sys/dev/usb/files.usb:1.98
--- src/sys/dev/usb/files.usb:1.97	Thu Mar 11 10:38:37 2010
+++ src/sys/dev/usb/files.usb	Sat May 29 01:14:29 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: files.usb,v 1.97 2010/03/11 10:38:37 enami Exp $
+#	$NetBSD: files.usb,v 1.98 2010/05/29 01:14:29 pgoyette Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -22,6 +22,7 @@
 file	dev/usb/usb_mem.c		usb
 file	dev/usb/usb_subr.c		usb
 file	dev/usb/usb_quirks.c		usb
+file	dev/usb/usb_verbose.c		usb & usbverbose
 
 # Hub driver
 device	uhub: usbdevif, usbifif

Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.120 src/sys/dev/usb/usb.c:1.121
--- src/sys/dev/usb/usb.c:1.120	Sat Dec 19 11:41:56 2009
+++ src/sys/dev/usb/usb.c	Sat May 29 01:14:29 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.120 2009/12/19 11:41:56 pooka Exp $	*/
+/*	$NetBSD: usb.c,v 1.121 2010/05/29 01:14:29 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.120 2009/12/19 11:41:56 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.121 2010/05/29 01:14:29 pgoyette Exp $");
 
 #include "opt_compat_netbsd.h"
 
@@ -55,10 +55,12 @@
 #include <sys/vnode.h>
 #include <sys/signalvar.h>
 #include <sys/intr.h>
+#include <sys/module.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdi_util.h>
+#include <dev/usb/usb_verbose.h>
 
 #define USB_DEV_MINOR 255
 
@@ -187,6 +189,9 @@
 	}
 	aprint_normal("\n");
 
+	/* Try to load the usbverbose module */
+	usb_verbose_ctl(true);
+
 	config_interrupts(self, usb_doattach);
 }
 
@@ -981,6 +986,9 @@
 	ue->u.ue_ctrlr.ue_bus = device_unit(self);
 	usb_add_event(USB_EVENT_CTRLR_DETACH, ue);
 
+	/* Try to unload the usbverbose module */
+	usb_verbose_ctl(false);
+
 	return (0);
 }
 

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.168 src/sys/dev/usb/usb_subr.c:1.169
--- src/sys/dev/usb/usb_subr.c:1.168	Sun Apr 25 09:14:38 2010
+++ src/sys/dev/usb/usb_subr.c	Sat May 29 01:14:29 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.168 2010/04/25 09:14:38 matthias Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.169 2010/05/29 01:14:29 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.168 2010/04/25 09:14:38 matthias Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.169 2010/05/29 01:14:29 pgoyette Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_usbverbose.h"
@@ -46,6 +46,7 @@
 #include <sys/proc.h>
 
 #include <sys/bus.h>
+#include <sys/module.h>
 
 #include <dev/usb/usb.h>
 
@@ -54,6 +55,7 @@
 #include <dev/usb/usbdivar.h>
 #include <dev/usb/usbdevs.h>
 #include <dev/usb/usb_quirks.h>
+#include <dev/usb/usb_verbose.h>
 
 #include "locators.h"
 
@@ -81,26 +83,6 @@
 
 Static u_int32_t usb_cookie_no = 0;
 
-#ifdef USBVERBOSE
-typedef u_int16_t usb_vendor_id_t;
-typedef u_int16_t usb_product_id_t;
-
-/*
- * Descriptions of of known vendors and devices ("products").
- */
-struct usb_vendor {
-	usb_vendor_id_t		vendor;
-	const char		*vendorname;
-};
-struct usb_product {
-	usb_vendor_id_t		vendor;
-	usb_product_id_t	product;
-	const char		*productname;
-};
-
-#include <dev/usb/usbdevs_data.h>
-#endif /* USBVERBOSE */
-
 Static const char * const usbd_error_strs[] = {
 	"NORMAL_COMPLETION",
 	"IN_PROGRESS",
@@ -124,6 +106,35 @@
 	"XXX",
 };
 
+void (*get_usb_vendor)(char *, usb_vendor_id_t) = (void *)get_usb_none;
+void (*get_usb_product)(char *, usb_vendor_id_t, usb_product_id_t) =
+	(void *)get_usb_none;
+
+void get_usb_none(void)
+{
+	/* Nothing happens */
+}
+
+/*
+ * Load/unload the usbverbose module
+ */
+void usb_verbose_ctl(bool load)
+{
+	static int loaded = 0;
+ 
+	if (load) {
+		if (loaded++ == 0)
+			if (module_load("usbverbose", MODCTL_LOAD_FORCE,
+					NULL, MODULE_CLASS_MISC) != 0)
+				loaded = 0;
+		return; 
+	}
+	if (loaded == 0)
+		return; 
+	if (--loaded == 0)
+		module_unload("pciverbose");
+}
+
 const char *
 usbd_errstr(usbd_status err)
 {
@@ -192,9 +203,6 @@
 		int useencoded)
 {
 	usb_device_descriptor_t *udd = &dev->ddesc;
-#ifdef USBVERBOSE
-	int n;
-#endif
 
 	v[0] = p[0] = '\0';
 	if (dev == NULL)
@@ -208,22 +216,12 @@
 		    USBD_NORMAL_COMPLETION)
 			usbd_trim_spaces(p);
 	}
-	/* There is no need for strlcpy & snprintf below. */
-#ifdef USBVERBOSE
 	if (v[0] == '\0')
-		for (n = 0; n < usb_nvendors; n++)
-			if (usb_vendors[n].vendor == UGETW(udd->idVendor)) {
-				strcpy(v, usb_vendors[n].vendorname);
-				break;
-			}
+		get_usb_vendor(v, UGETW(udd->idVendor));
 	if (p[0] == '\0')
-		for (n = 0; n < usb_nproducts; n++)
-			if (usb_products[n].vendor == UGETW(udd->idVendor) &&
-			    usb_products[n].product == UGETW(udd->idProduct)) {
-				strcpy(p, usb_products[n].productname);
-				break;
-			}
-#endif
+		get_usb_product(p, UGETW(udd->idVendor), UGETW(udd->idProduct));
+
+	/* There is no need for snprintf below. */
 	if (v[0] == '\0')
 		sprintf(v, "vendor 0x%04x", UGETW(udd->idVendor));
 	if (p[0] == '\0')

Index: src/sys/modules/Makefile
diff -u src/sys/modules/Makefile:1.42 src/sys/modules/Makefile:1.43
--- src/sys/modules/Makefile:1.42	Mon May 24 20:29:41 2010
+++ src/sys/modules/Makefile	Sat May 29 01:14:30 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.42 2010/05/24 20:29:41 pgoyette Exp $
+#	$NetBSD: Makefile,v 1.43 2010/05/29 01:14:30 pgoyette Exp $
 
 .include <bsd.own.mk>
 
@@ -55,6 +55,7 @@
 SUBDIR+=	udf
 SUBDIR+=	umap
 SUBDIR+=	union
+SUBDIR+=	usbverbose
 SUBDIR+=	vnd
 SUBDIR+=	tprof
 .if (defined(NOTYET))

Added files:

Index: src/sys/dev/usb/usb_verbose.c
diff -u /dev/null src/sys/dev/usb/usb_verbose.c:1.1
--- /dev/null	Sat May 29 01:14:31 2010
+++ src/sys/dev/usb/usb_verbose.c	Sat May 29 01:14:29 2010
@@ -0,0 +1,104 @@
+/*	$NetBSD: usb_verbose.c,v 1.1 2010/05/29 01:14:29 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 (lenn...@augustsson.net) 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_verbose.c,v 1.1 2010/05/29 01:14:29 pgoyette Exp $");
+
+#include <sys/param.h>
+#include <sys/module.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdevs.h>
+#include <dev/usb/usb_verbose.h>
+
+/*
+ * Descriptions of known vendors and devices ("products").
+ */
+struct usb_vendor {
+	usb_vendor_id_t		vendor;
+	const char		*vendorname;
+};
+struct usb_product {
+	usb_vendor_id_t		vendor;
+	usb_product_id_t	product;
+	const char		*productname;
+};
+
+#include <dev/usb/usbdevs_data.h>
+
+void get_usb_vendor_real(char *, usb_vendor_id_t);
+void get_usb_product_real(char *, usb_vendor_id_t, usb_product_id_t);
+
+MODULE(MODULE_CLASS_MISC, usbverbose, NULL);
+  
+static int
+usbverbose_modcmd(modcmd_t cmd, void *arg)
+{
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		get_usb_vendor = get_usb_vendor_real;
+		get_usb_product = get_usb_product_real;
+		return 0;
+	case MODULE_CMD_FINI:
+		get_usb_vendor = (void *)get_usb_none;
+		get_usb_product = (void *)get_usb_none;
+		return 0;
+	default:
+		return ENOTTY;  
+	}
+}
+
+void get_usb_vendor_real(char *v, usb_vendor_id_t v_id)
+{
+	int n;
+
+	/* There is no need for strlcpy below. */
+	for (n = 0; n < usb_nvendors; n++)
+		if (usb_vendors[n].vendor == v_id) {
+			strcpy(v, usb_vendors[n].vendorname);
+			break;
+		}
+}
+
+void get_usb_product_real(char *p, usb_vendor_id_t v_id, usb_product_id_t p_id)
+{
+	int n;
+
+	/* There is no need for strlcpy below. */
+	for (n = 0; n < usb_nproducts; n++)
+		if (usb_products[n].vendor == v_id &&
+		    usb_products[n].product == p_id) {
+			strcpy(p, usb_products[n].productname);
+			break;
+		}
+}
Index: src/sys/dev/usb/usb_verbose.h
diff -u /dev/null src/sys/dev/usb/usb_verbose.h:1.1
--- /dev/null	Sat May 29 01:14:31 2010
+++ src/sys/dev/usb/usb_verbose.h	Sat May 29 01:14:29 2010
@@ -0,0 +1,44 @@
+/*      $NetBSD: usb_verbose.h,v 1.1 2010/05/29 01:14:29 pgoyette 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 (lenn...@augustsson.net) 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.
+ */
+
+#ifndef _DEV_USB_USBVERBOSE_H_
+#define _DEV_USB_USBVERBOSE_H_
+
+typedef u_int16_t usb_vendor_id_t;
+typedef u_int16_t usb_product_id_t;
+
+void get_usb_none(void);
+void usb_verbose_ctl(bool);
+extern void (*get_usb_vendor)(char *, usb_vendor_id_t);
+extern void (*get_usb_product)(char *, usb_vendor_id_t, usb_product_id_t);
+
+#endif /* _DEV_USB_USBVERBOSE_H_ */

Index: src/sys/modules/usbverbose/Makefile
diff -u /dev/null src/sys/modules/usbverbose/Makefile:1.1
--- /dev/null	Sat May 29 01:14:31 2010
+++ src/sys/modules/usbverbose/Makefile	Sat May 29 01:14:30 2010
@@ -0,0 +1,10 @@
+#	$NetBSD: Makefile,v 1.1 2010/05/29 01:14:30 pgoyette Exp $
+
+.include "../Makefile.inc"
+
+KMOD=	usbverbose
+
+.PATH:	${S}/dev/usb
+SRCS=	usb_verbose.c
+
+.include <bsd.kmodule.mk>

Reply via email to