Source-Changes-HG archive

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

[src/trunk]: src Extract USBVERBOSE into a kernel module. The module can be ...



details:   https://anonhg.NetBSD.org/src/rev/995899938ad6
branches:  trunk
changeset: 755232:995899938ad6
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat May 29 01:14:29 2010 +0000

description:
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.

diffstat:

 distrib/sets/lists/modules/mi   |    4 +-
 sys/dev/usb/files.usb           |    3 +-
 sys/dev/usb/usb.c               |   12 +++-
 sys/dev/usb/usb_subr.c          |   76 ++++++++++++++---------------
 sys/dev/usb/usb_verbose.c       |  104 ++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/usb_verbose.h       |   44 ++++++++++++++++
 sys/modules/Makefile            |    3 +-
 sys/modules/usbverbose/Makefile |   10 +++
 8 files changed, 212 insertions(+), 44 deletions(-)

diffs (truncated from 407 to 300 lines):

diff -r 20e3d23b255f -r 995899938ad6 distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Fri May 28 23:41:14 2010 +0000
+++ b/distrib/sets/lists/modules/mi     Sat May 29 01:14:29 2010 +0000
@@ -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
diff -r 20e3d23b255f -r 995899938ad6 sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Fri May 28 23:41:14 2010 +0000
+++ b/sys/dev/usb/files.usb     Sat May 29 01:14:29 2010 +0000
@@ -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
diff -r 20e3d23b255f -r 995899938ad6 sys/dev/usb/usb.c
--- a/sys/dev/usb/usb.c Fri May 28 23:41:14 2010 +0000
+++ b/sys/dev/usb/usb.c Sat May 29 01:14:29 2010 +0000
@@ -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);
 }
 
diff -r 20e3d23b255f -r 995899938ad6 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c    Fri May 28 23:41:14 2010 +0000
+++ b/sys/dev/usb/usb_subr.c    Sat May 29 01:14:29 2010 +0000
@@ -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')
diff -r 20e3d23b255f -r 995899938ad6 sys/dev/usb/usb_verbose.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/usb_verbose.c Sat May 29 01:14:29 2010 +0000
@@ -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 (lennart%augustsson.net@localhost) 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:



Home | Main Index | Thread Index | Old Index