Module Name: src
Committed By: christos
Date: Sun Sep 21 14:30:22 UTC 2014
Modified Files:
src/sys/dev/pci: Makefile.pcidevs azalia.c cs4280.c ehci_pci.c
ohci_pci.c pci_subr.c pci_verbose.c pci_verbose.h uhci_pci.c
xhci_pci.c
src/sys/dev/pci/hdaudio: Makefile.hdaudiodevs hdafg.c hdaudio.c
hdaudio_verbose.c hdaudio_verbose.h
src/sys/dev/usb: Makefile.usbdevs usb_subr.c usb_verbose.c
usb_verbose.h
Added Files:
src/sys/dev: dev_verbose.c dev_verbose.h devlist2h.awk
Removed Files:
src/sys/dev/pci: devlist2h.awk
src/sys/dev/pci/hdaudio: devlist2h.awk
src/sys/dev/usb: devlist2h.awk
Log Message:
Merge the 3 copies of devlist2h.awk that deal with 16 bit key and value
pairs to the compressed one that matt wrote.
To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/dev_verbose.c src/sys/dev/dev_verbose.h \
src/sys/dev/devlist2h.awk
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/pci/Makefile.pcidevs
cvs rdiff -u -r1.81 -r1.82 src/sys/dev/pci/azalia.c
cvs rdiff -u -r1.66 -r1.67 src/sys/dev/pci/cs4280.c
cvs rdiff -u -r1.13 -r0 src/sys/dev/pci/devlist2h.awk
cvs rdiff -u -r1.58 -r1.59 src/sys/dev/pci/ehci_pci.c
cvs rdiff -u -r1.52 -r1.53 src/sys/dev/pci/ohci_pci.c
cvs rdiff -u -r1.125 -r1.126 src/sys/dev/pci/pci_subr.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/pci/pci_verbose.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/pci/pci_verbose.h \
src/sys/dev/pci/xhci_pci.c
cvs rdiff -u -r1.57 -r1.58 src/sys/dev/pci/uhci_pci.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/pci/hdaudio/Makefile.hdaudiodevs \
src/sys/dev/pci/hdaudio/hdaudio_verbose.c \
src/sys/dev/pci/hdaudio/hdaudio_verbose.h
cvs rdiff -u -r1.1 -r0 src/sys/dev/pci/hdaudio/devlist2h.awk
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/pci/hdaudio/hdafg.c \
src/sys/dev/pci/hdaudio/hdaudio.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/usb/Makefile.usbdevs \
src/sys/dev/usb/usb_verbose.c
cvs rdiff -u -r1.14 -r0 src/sys/dev/usb/devlist2h.awk
cvs rdiff -u -r1.197 -r1.198 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/usb/usb_verbose.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/dev/pci/Makefile.pcidevs
diff -u src/sys/dev/pci/Makefile.pcidevs:1.5 src/sys/dev/pci/Makefile.pcidevs:1.6
--- src/sys/dev/pci/Makefile.pcidevs:1.5 Sun Oct 19 18:05:23 2008
+++ src/sys/dev/pci/Makefile.pcidevs Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.pcidevs,v 1.5 2008/10/19 22:05:23 apb Exp $
+# $NetBSD: Makefile.pcidevs,v 1.6 2014/09/21 14:30:22 christos Exp $
#
# As per [email protected], the proper procedure is
#
@@ -9,6 +9,6 @@
.include <bsd.own.mk>
-pcidevs.h pcidevs_data.h: pcidevs devlist2h.awk
+pcidevs.h pcidevs_data.h: ${.CURDIR}/../devlist2h.awk pcidevs
/bin/rm -f pcidevs.h pcidevs_data.h
- ${TOOL_AWK} -f devlist2h.awk pcidevs
+ ${TOOL_AWK} -f ${.ALLSRC}
Index: src/sys/dev/pci/azalia.c
diff -u src/sys/dev/pci/azalia.c:1.81 src/sys/dev/pci/azalia.c:1.82
--- src/sys/dev/pci/azalia.c:1.81 Sat Mar 29 15:28:24 2014
+++ src/sys/dev/pci/azalia.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: azalia.c,v 1.81 2014/03/29 19:28:24 christos Exp $ */
+/* $NetBSD: azalia.c,v 1.82 2014/09/21 14:30:22 christos Exp $ */
/*-
* Copyright (c) 2005, 2008 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: azalia.c,v 1.81 2014/03/29 19:28:24 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: azalia.c,v 1.82 2014/09/21 14:30:22 christos Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -303,8 +303,8 @@ azalia_pci_attach(device_t parent, devic
pcireg_t v;
pci_intr_handle_t ih;
const char *intrrupt_str;
- const char *name;
- const char *vendor;
+ char vendor[PCI_VENDORSTR_LEN];
+ char product[PCI_PRODUCTSTR_LEN];
char intrbuf[PCI_INTRSTR_LEN];
sc->dev = self;
@@ -353,16 +353,11 @@ azalia_pci_attach(device_t parent, devic
aprint_error_dev(self, "couldn't establish power handler\n");
sc->pciid = pa->pa_id;
- vendor = pci_findvendor(pa->pa_id);
- name = pci_findproduct(pa->pa_id);
- if (vendor != NULL && name != NULL) {
- aprint_normal_dev(self, "host: %s %s (rev. %d)",
- vendor, name, PCI_REVISION(pa->pa_class));
- } else {
- aprint_normal_dev(self, "host: 0x%4.4x/0x%4.4x (rev. %d)",
- PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id),
- PCI_REVISION(pa->pa_class));
- }
+ pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(pa->pa_id));
+ pci_findproduct(product, sizeof(product), PCI_VENDOR(pa->pa_id),
+ PCI_PRODUCT(pa->pa_id));
+ aprint_normal_dev(self, "host: %s %s (rev. %d)",
+ vendor, product, PCI_REVISION(pa->pa_class));
if (azalia_attach(sc)) {
aprint_error_dev(self, "initialization failure\n");
Index: src/sys/dev/pci/cs4280.c
diff -u src/sys/dev/pci/cs4280.c:1.66 src/sys/dev/pci/cs4280.c:1.67
--- src/sys/dev/pci/cs4280.c:1.66 Sat Mar 29 15:28:24 2014
+++ src/sys/dev/pci/cs4280.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: cs4280.c,v 1.66 2014/03/29 19:28:24 christos Exp $ */
+/* $NetBSD: cs4280.c,v 1.67 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 1999, 2000 Tatoku Ogaito. All rights reserved.
@@ -52,7 +52,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1.66 2014/03/29 19:28:24 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1.67 2014/09/21 14:30:22 christos Exp $");
#include "midi.h"
@@ -245,6 +245,8 @@ cs4280_attach(device_t parent, device_t
pcireg_t reg;
uint32_t mem;
int error;
+ chae vendor[PCI_VENDORSTR_LEN];
+ chae product[PCI_PRODUCTSTR_LEN];
char intrbuf[PCI_INTRSTR_LEN];
sc = device_private(self);
@@ -256,19 +258,10 @@ cs4280_attach(device_t parent, device_t
cs_card = cs4280_identify_card(pa);
if (cs_card != NULL) {
- vendor = pci_findvendor(cs_card->id);
- product = pci_findproduct(cs_card->id);
- if (vendor == NULL)
- aprint_normal_dev(sc->sc_dev,
- "vendor 0x%04x product 0x%04x\n",
- PCI_VENDOR(cs_card->id),
- PCI_PRODUCT(cs_card->id));
- else if (product == NULL)
- aprint_normal_dev(sc->sc_dev, "%s product 0x%04x\n",
- vendor, PCI_PRODUCT(cs_card->id));
- else
- aprint_normal_dev(sc->sc_dev, "%s %s\n",
- vendor, product);
+ pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(cs_card->id));
+ pci_findproduct(product, sizeof(product),
+ PCI_VENDOR(cs_card->id), PCI_PRODUCT(cs_card->id));
+ aprint_normal_dev(sc->sc_dev, "%s %s\n", vendor, product);
sc->sc_flags = cs_card->flags;
} else {
sc->sc_flags = CS428X_FLAG_NONE;
Index: src/sys/dev/pci/ehci_pci.c
diff -u src/sys/dev/pci/ehci_pci.c:1.58 src/sys/dev/pci/ehci_pci.c:1.59
--- src/sys/dev/pci/ehci_pci.c:1.58 Sat Mar 29 15:28:24 2014
+++ src/sys/dev/pci/ehci_pci.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ehci_pci.c,v 1.58 2014/03/29 19:28:24 christos Exp $ */
+/* $NetBSD: ehci_pci.c,v 1.59 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci_pci.c,v 1.58 2014/03/29 19:28:24 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci_pci.c,v 1.59 2014/09/21 14:30:22 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -119,7 +119,6 @@ ehci_pci_attach(device_t parent, device_
char const *intrstr;
pci_intr_handle_t ih;
pcireg_t csr;
- const char *vendor;
usbd_status r;
int ncomp;
struct usb_pci *up;
@@ -204,14 +203,9 @@ ehci_pci_attach(device_t parent, device_
}
/* Figure out vendor for root hub descriptor. */
- vendor = pci_findvendor(pa->pa_id);
sc->sc.sc_id_vendor = PCI_VENDOR(pa->pa_id);
- if (vendor)
- strlcpy(sc->sc.sc_vendor, vendor, sizeof(sc->sc.sc_vendor));
- else
- snprintf(sc->sc.sc_vendor, sizeof(sc->sc.sc_vendor),
- "vendor 0x%04x", PCI_VENDOR(pa->pa_id));
-
+ pci_findvendor(sc->sc.sc_vendor,
+ sizeof(sc->sc.sc_vendor), sc->sc.sc_id_vendor);
/* Enable workaround for dropped interrupts as required */
switch (sc->sc.sc_id_vendor) {
case PCI_VENDOR_ATI:
Index: src/sys/dev/pci/ohci_pci.c
diff -u src/sys/dev/pci/ohci_pci.c:1.52 src/sys/dev/pci/ohci_pci.c:1.53
--- src/sys/dev/pci/ohci_pci.c:1.52 Sat Mar 29 15:28:25 2014
+++ src/sys/dev/pci/ohci_pci.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ohci_pci.c,v 1.52 2014/03/29 19:28:25 christos Exp $ */
+/* $NetBSD: ohci_pci.c,v 1.53 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci_pci.c,v 1.52 2014/03/29 19:28:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci_pci.c,v 1.53 2014/09/21 14:30:22 christos Exp $");
#include "ehci.h"
@@ -90,7 +90,6 @@ ohci_pci_attach(device_t parent, device_
pci_intr_handle_t ih;
pcireg_t csr;
usbd_status r;
- const char *vendor;
char intrbuf[PCI_INTRSTR_LEN];
sc->sc.sc_dev = self;
@@ -154,14 +153,9 @@ ohci_pci_attach(device_t parent, device_
aprint_normal_dev(self, "interrupting at %s\n", intrstr);
/* Figure out vendor for root hub descriptor. */
- vendor = pci_findvendor(pa->pa_id);
sc->sc.sc_id_vendor = PCI_VENDOR(pa->pa_id);
- if (vendor)
- strlcpy(sc->sc.sc_vendor, vendor, sizeof(sc->sc.sc_vendor));
- else
- snprintf(sc->sc.sc_vendor, sizeof(sc->sc.sc_vendor),
- "vendor 0x%04x", PCI_VENDOR(pa->pa_id));
-
+ pci_findvendor(sc->sc.sc_vendor, sizeof(sc->sc.sc_vendor),
+ sc->sc.sc_id_vendor);
r = ohci_init(&sc->sc);
if (r != USBD_NORMAL_COMPLETION) {
aprint_error_dev(self, "init failed, error=%d\n", r);
Index: src/sys/dev/pci/pci_subr.c
diff -u src/sys/dev/pci/pci_subr.c:1.125 src/sys/dev/pci/pci_subr.c:1.126
--- src/sys/dev/pci/pci_subr.c:1.125 Fri Sep 5 01:29:16 2014
+++ src/sys/dev/pci/pci_subr.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_subr.c,v 1.125 2014/09/05 05:29:16 matt Exp $ */
+/* $NetBSD: pci_subr.c,v 1.126 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 1997 Zubin D. Dittia. All rights reserved.
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.125 2014/09/05 05:29:16 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.126 2014/09/21 14:30:22 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_pci.h"
@@ -62,6 +62,10 @@ __KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v
#include <dev/pci/pcireg.h>
#ifdef _KERNEL
#include <dev/pci/pcivar.h>
+#else
+#include <dev/pci/pci_verbose.h>
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pcidevs_data.h>
#endif
/*
@@ -538,92 +542,30 @@ static const struct pci_class pci_class[
NULL, },
};
-void pci_load_verbose(void);
-
-#if defined(_KERNEL)
-/*
- * In kernel, these routines are provided and linked via the
- * pciverbose module.
- */
-const char *pci_findvendor_stub(pcireg_t);
-const char *pci_findproduct_stub(pcireg_t);
-
-const char *(*pci_findvendor)(pcireg_t) = pci_findvendor_stub;
-const char *(*pci_findproduct)(pcireg_t) = pci_findproduct_stub;
-const char *pci_unmatched = "";
-#else
-/*
- * For userland we just set the vectors here.
- */
-const char *(*pci_findvendor)(pcireg_t id_reg) = pci_findvendor_real;
-const char *(*pci_findproduct)(pcireg_t id_reg) = pci_findproduct_real;
-const char *pci_unmatched = "unmatched ";
-#endif
-
-int pciverbose_loaded = 0;
-
-#if defined(_KERNEL)
-/*
- * Routine to load the pciverbose kernel module as needed
- */
-void
-pci_load_verbose(void)
-{
-
- if (pciverbose_loaded == 0)
- module_autoload("pciverbose", MODULE_CLASS_MISC);
-}
-
-const char *
-pci_findvendor_stub(pcireg_t id_reg)
-{
-
- pci_load_verbose();
- if (pciverbose_loaded)
- return pci_findvendor(id_reg);
- else
- return NULL;
-}
-
-const char *
-pci_findproduct_stub(pcireg_t id_reg)
-{
-
- pci_load_verbose();
- if (pciverbose_loaded)
- return pci_findproduct(id_reg);
- else
- return NULL;
-}
-#endif
+DEV_VERBOSE_DEFINE(pci);
void
pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp,
size_t l)
{
- pci_vendor_id_t vendor;
- pci_product_id_t product;
pci_class_t pciclass;
pci_subclass_t subclass;
pci_interface_t interface;
pci_revision_t revision;
- const char *unmatched = pci_unmatched;
- const char *vendor_namep, *product_namep;
+ char vendor[PCI_VENDORSTR_LEN], product[PCI_PRODUCTSTR_LEN];
const struct pci_class *classp, *subclassp, *interfacep;
char *ep;
ep = cp + l;
- vendor = PCI_VENDOR(id_reg);
- product = PCI_PRODUCT(id_reg);
-
pciclass = PCI_CLASS(class_reg);
subclass = PCI_SUBCLASS(class_reg);
interface = PCI_INTERFACE(class_reg);
revision = PCI_REVISION(class_reg);
- vendor_namep = pci_findvendor(id_reg);
- product_namep = pci_findproduct(id_reg);
+ pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(id_reg));
+ pci_findproduct(product, sizeof(product), PCI_VENDOR(id_reg),
+ PCI_PRODUCT(id_reg));
classp = pci_class;
while (classp->name != NULL) {
@@ -647,15 +589,7 @@ pci_devinfo(pcireg_t id_reg, pcireg_t cl
interfacep++;
}
- if (vendor_namep == NULL)
- cp += snprintf(cp, ep - cp, "%svendor 0x%04x product 0x%04x",
- unmatched, vendor, product);
- else if (product_namep != NULL)
- cp += snprintf(cp, ep - cp, "%s %s", vendor_namep,
- product_namep);
- else
- cp += snprintf(cp, ep - cp, "%s product 0x%04x",
- vendor_namep, product);
+ cp += snprintf(cp, ep - cp, "%s %s", vendor, product);
if (showclass) {
cp += snprintf(cp, ep - cp, " (");
if (classp->name == NULL)
@@ -735,17 +669,20 @@ pci_conf_print_common(
{
const char *name;
const struct pci_class *classp, *subclassp;
+ char vendor[PCI_VENDORSTR_LEN];
+ char product[PCI_PRODUCTSTR_LEN];
pcireg_t rval;
unsigned int num;
rval = regs[o2i(PCI_ID_REG)];
- name = pci_findvendor(rval);
+ name = pci_findvendor(vendor, sizeof(vendor), PCI_VENDOR(rval));
if (name)
printf(" Vendor Name: %s (0x%04x)\n", name,
PCI_VENDOR(rval));
else
printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval));
- name = pci_findproduct(rval);
+ name = pci_findproduct(product, sizeof(product), PCI_VENDOR(rval),
+ PCI_PRODUCT(rval));
if (name)
printf(" Device Name: %s (0x%04x)\n", name,
PCI_PRODUCT(rval));
Index: src/sys/dev/pci/pci_verbose.c
diff -u src/sys/dev/pci/pci_verbose.c:1.8 src/sys/dev/pci/pci_verbose.c:1.9
--- src/sys/dev/pci/pci_verbose.c:1.8 Mon Aug 29 10:47:08 2011
+++ src/sys/dev/pci/pci_verbose.c Sun Sep 21 10:30:22 2014
@@ -1,10 +1,8 @@
-/* $NetBSD: pci_verbose.c,v 1.8 2011/08/29 14:47:08 jmcneill Exp $ */
+/* $NetBSD: pci_verbose.c,v 1.9 2014/09/21 14:30:22 christos Exp $ */
/*
- * Copyright (c) 1997 Zubin D. Dittia. All rights reserved.
- * Copyright (c) 1995, 1996, 1998, 2000
- * Christopher G. Demetriou. All rights reserved.
- * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -14,22 +12,18 @@
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Charles M. Hannum.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ * 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.
*/
/*
@@ -40,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_verbose.c,v 1.8 2011/08/29 14:47:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_verbose.c,v 1.9 2014/09/21 14:30:22 christos Exp $");
#include <sys/param.h>
@@ -48,111 +42,12 @@ __KERNEL_RCSID(0, "$NetBSD: pci_verbose.
#include <sys/module.h>
#else
#include <pci.h>
+#include <string.h>
#endif
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
-#ifdef _KERNEL
#include <dev/pci/pci_verbose.h>
-#endif
-
-/*
- * Descriptions of of known vendors and devices ("products").
- */
-
#include <dev/pci/pcidevs_data.h>
-#ifndef _KERNEL
-#include <string.h>
-#endif
-
-#ifdef _KERNEL
-static int pciverbose_modcmd(modcmd_t, void *);
-
-MODULE(MODULE_CLASS_MISC, pciverbose, "pci");
-
-static int
-pciverbose_modcmd(modcmd_t cmd, void *arg)
-{
- static const char *(*saved_findvendor)(pcireg_t);
- static const char *(*saved_findproduct)(pcireg_t);
- static const char *saved_unmatched;
-
- switch (cmd) {
- case MODULE_CMD_INIT:
- saved_findvendor = pci_findvendor;
- saved_findproduct = pci_findproduct;
- saved_unmatched = pci_unmatched;
- pci_findvendor = pci_findvendor_real;
- pci_findproduct = pci_findproduct_real;
- pci_unmatched = "unmatched ";
- pciverbose_loaded = 1;
- return 0;
- case MODULE_CMD_FINI:
- pci_findvendor = saved_findvendor;
- pci_findproduct = saved_findproduct;
- pci_unmatched = saved_unmatched;
- pciverbose_loaded = 0;
- return 0;
- default:
- return ENOTTY;
- }
-}
-#endif /* KERNEL */
-
-static const char *
-pci_untokenstring(const uint16_t *token, char *buf, size_t len)
-{
- char *cp = buf;
-
- buf[0] = '\0';
- for (; *token != 0; token++) {
- cp = buf + strlcat(buf, pci_words + *token, len - 2);
- cp[0] = ' ';
- cp[1] = '\0';
- }
- *cp = '\0';
- return cp != buf ? buf : NULL;
-}
-
-const char *
-pci_findvendor_real(pcireg_t id_reg)
-{
- static char buf[256];
- pci_vendor_id_t vendor = PCI_VENDOR(id_reg);
- size_t n;
-
- for (n = 0; n < __arraycount(pci_vendors); n++) {
- if (pci_vendors[n] == vendor)
- return pci_untokenstring(&pci_vendors[n+1], buf,
- sizeof(buf));
-
- /* Skip Tokens */
- n++;
- while (pci_vendors[n] != 0 && n < __arraycount(pci_vendors))
- n++;
- }
- return (NULL);
-}
-
-const char *
-pci_findproduct_real(pcireg_t id_reg)
-{
- static char buf[256];
- pci_vendor_id_t vendor = PCI_VENDOR(id_reg);
- pci_product_id_t product = PCI_PRODUCT(id_reg);
- size_t n;
-
- for (n = 0; n < __arraycount(pci_products); n++) {
- if (pci_products[n] == vendor && pci_products[n+1] == product)
- return pci_untokenstring(&pci_products[n+2], buf,
- sizeof(buf));
-
- /* Skip Tokens */
- n += 2;
- while (pci_products[n] != 0 && n < __arraycount(pci_products))
- n++;
- }
- return (NULL);
-}
-
+DEV_VERBOSE_MODULE_DEFINE(pci, "pci")
Index: src/sys/dev/pci/pci_verbose.h
diff -u src/sys/dev/pci/pci_verbose.h:1.3 src/sys/dev/pci/pci_verbose.h:1.4
--- src/sys/dev/pci/pci_verbose.h:1.3 Sun Jun 6 14:58:24 2010
+++ src/sys/dev/pci/pci_verbose.h Sun Sep 21 10:30:22 2014
@@ -1,8 +1,8 @@
-/* $NetBSD: pci_verbose.h,v 1.3 2010/06/06 18:58:24 pgoyette Exp $ */
+/* $NetBSD: pci_verbose.h,v 1.4 2014/09/21 14:30:22 christos Exp $ */
/*
- * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
- * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -12,39 +12,32 @@
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Charles M. Hannum.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ * 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_PCI_PCIVERBOSE_H_
#define _DEV_PCI_PCIVERBOSE_H_
-/*
- * Misc.
- */
-typedef u_int32_t pcireg_t; /* configuration space register XXX */
+#include <dev/dev_verbose.h>
-const char *pci_findvendor_real(pcireg_t);
-const char *pci_findproduct_real(pcireg_t);
+#ifdef _KERNEL
+typedef uint32_t pcireg_t; /* configuration space register XXX */
+#endif
-extern int pciverbose_loaded;
+#define PCI_VENDORSTR_LEN 64
+#define PCI_PRODUCTSTR_LEN 64
-extern const char *(*pci_findvendor)(pcireg_t);
-extern const char *(*pci_findproduct)(pcireg_t);
-extern const char *pci_unmatched;
+DEV_VERBOSE_DECLARE(pci);
#endif /* _DEV_PCI_PCIVERBOSE_H_ */
Index: src/sys/dev/pci/xhci_pci.c
diff -u src/sys/dev/pci/xhci_pci.c:1.3 src/sys/dev/pci/xhci_pci.c:1.4
--- src/sys/dev/pci/xhci_pci.c:1.3 Sat Mar 29 15:28:25 2014
+++ src/sys/dev/pci/xhci_pci.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci_pci.c,v 1.3 2014/03/29 19:28:25 christos Exp $ */
+/* $NetBSD: xhci_pci.c,v 1.4 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.3 2014/03/29 19:28:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.4 2014/09/21 14:30:22 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -156,13 +156,9 @@ xhci_pci_attach(device_t parent, device_
#if 0
/* Figure out vendor for root hub descriptor. */
- vendor = pci_findvendor(pa->pa_id);
sc->sc_id_vendor = PCI_VENDOR(pa->pa_id);
- if (vendor)
- strlcpy(sc->sc_vendor, vendor, sizeof(sc->sc_vendor));
- else
- snprintf(sc->sc_vendor, sizeof(sc->sc_vendor),
- "vendor 0x%04x", PCI_VENDOR(pa->pa_id));
+ pci_findvendor(sc->sc_vendor, sizeof(sc->sc_vendor),
+ sc->sc_id_vendor);
#endif
err = xhci_init(sc);
Index: src/sys/dev/pci/uhci_pci.c
diff -u src/sys/dev/pci/uhci_pci.c:1.57 src/sys/dev/pci/uhci_pci.c:1.58
--- src/sys/dev/pci/uhci_pci.c:1.57 Sat Mar 29 15:28:25 2014
+++ src/sys/dev/pci/uhci_pci.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: uhci_pci.c,v 1.57 2014/03/29 19:28:25 christos Exp $ */
+/* $NetBSD: uhci_pci.c,v 1.58 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci_pci.c,v 1.57 2014/03/29 19:28:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci_pci.c,v 1.58 2014/09/21 14:30:22 christos Exp $");
#include "ehci.h"
@@ -93,7 +93,6 @@ uhci_pci_attach(device_t parent, device_
char const *intrstr;
pci_intr_handle_t ih;
pcireg_t csr;
- const char *vendor;
usbd_status r;
int s;
char intrbuf[PCI_INTRSTR_LEN];
@@ -171,14 +170,9 @@ uhci_pci_attach(device_t parent, device_
}
/* Figure out vendor for root hub descriptor. */
- vendor = pci_findvendor(pa->pa_id);
sc->sc.sc_id_vendor = PCI_VENDOR(pa->pa_id);
- if (vendor)
- strlcpy(sc->sc.sc_vendor, vendor, sizeof(sc->sc.sc_vendor));
- else
- snprintf(sc->sc.sc_vendor, sizeof(sc->sc.sc_vendor),
- "vendor 0x%04x", PCI_VENDOR(pa->pa_id));
-
+ pci_findvendor(sc->sc.sc_vendor, sizeof(sc->sc.sc_vendor),
+ sc->sc.sc_id_vendor);
r = uhci_init(&sc->sc);
if (r != USBD_NORMAL_COMPLETION) {
aprint_error_dev(self, "init failed, error=%d\n", r);
Index: src/sys/dev/pci/hdaudio/Makefile.hdaudiodevs
diff -u src/sys/dev/pci/hdaudio/Makefile.hdaudiodevs:1.1 src/sys/dev/pci/hdaudio/Makefile.hdaudiodevs:1.2
--- src/sys/dev/pci/hdaudio/Makefile.hdaudiodevs:1.1 Fri Sep 19 13:23:35 2014
+++ src/sys/dev/pci/hdaudio/Makefile.hdaudiodevs Sun Sep 21 10:30:22 2014
@@ -1,18 +1,14 @@
-# $NetBSD: Makefile.hdaudiodevs,v 1.1 2014/09/19 17:23:35 christos Exp $
-
-# The header files depend on the correct version of hdaudiodevs.
+# $NetBSD: Makefile.hdaudiodevs,v 1.2 2014/09/21 14:30:22 christos Exp $
+#
+# As per [email protected], the proper procedure is
#
-# Thus, the procedure is:
-# 1) change hdaudiodevs
-# 2) commit hdaudiodevs
-# 3) _then_ generate header files
-# 4) commit them
+# 1.) Change "src/sys/dev/hdaudio/hdaudiodevs".
+# 2.) Commit "src/sys/dev/hdaudio/hdaudiodevs".
+# 3.) Execute "make -f Makefile.hdaudiodevs" in "src/sys/dev/pci/hdaudio".
+# 4.) Commit "src/sys/dev/hdaudio/hdaudiodevs.h" and "src/sys/dev/pci/hdaudio/hdaudiodevs_data.h".
.include <bsd.own.mk>
-UNAME= uname
-RM= rm
-
-hdaudiodevs.h hdaudiodevs_data.h: hdaudiodevs devlist2h.awk
- ${RM} -f hdaudiodevs.h hdaudiodevs_data.h
- ${TOOL_AWK} -v os=`${UNAME} -s` -f devlist2h.awk hdaudiodevs
+hdaudiodevs.h hdaudiodevs_data.h: ${.CURDIR}/../../devlist2h.awk hdaudiodevs
+ /bin/rm -f hdaudiodevs.h hdaudiodevs_data.h
+ ${TOOL_AWK} -f ${.ALLSRC}
Index: src/sys/dev/pci/hdaudio/hdaudio_verbose.c
diff -u src/sys/dev/pci/hdaudio/hdaudio_verbose.c:1.1 src/sys/dev/pci/hdaudio/hdaudio_verbose.c:1.2
--- src/sys/dev/pci/hdaudio/hdaudio_verbose.c:1.1 Fri Sep 19 13:23:35 2014
+++ src/sys/dev/pci/hdaudio/hdaudio_verbose.c Sun Sep 21 10:30:22 2014
@@ -1,13 +1,9 @@
-/* $NetBSD: hdaudio_verbose.c,v 1.1 2014/09/19 17:23:35 christos Exp $ */
+/* $NetBSD: hdaudio_verbose.c,v 1.2 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 2014 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:
@@ -31,83 +27,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hdaudio_verbose.c,v 1.1 2014/09/19 17:23:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdaudio_verbose.c,v 1.2 2014/09/21 14:30:22 christos Exp $");
#include <sys/param.h>
#include <sys/module.h>
#include <dev/pci/hdaudio/hdaudio_verbose.h>
-
-/*
- * Descriptions of known vendors and devices ("products").
- */
-struct hdaudio_vendor {
- hdaudio_vendor_id_t vendor;
- const char *vendorname;
-};
-struct hdaudio_product {
- hdaudio_vendor_id_t vendor;
- hdaudio_product_id_t product;
- const char *productname;
-};
-
#include <dev/pci/hdaudio/hdaudiodevs.h>
#include <dev/pci/hdaudio/hdaudiodevs_data.h>
-void get_hdaudio_vendor_real(char *, size_t, hdaudio_vendor_id_t);
-void get_hdaudio_product_real(char *, size_t, hdaudio_vendor_id_t, hdaudio_product_id_t);
-
-MODULE(MODULE_CLASS_MISC, hdaudioverbose, NULL);
-
-static int
-hdaudioverbose_modcmd(modcmd_t cmd, void *arg)
-{
- static void (*saved_hdaudio_vendor)(char *, size_t, hdaudio_vendor_id_t);
- static void (*saved_hdaudio_product)(char *, size_t, hdaudio_vendor_id_t,
- hdaudio_product_id_t);
-
- switch (cmd) {
- case MODULE_CMD_INIT:
- saved_hdaudio_vendor = get_hdaudio_vendor;
- saved_hdaudio_product = get_hdaudio_product;
- get_hdaudio_vendor = get_hdaudio_vendor_real;
- get_hdaudio_product = get_hdaudio_product_real;
- hdaudio_verbose_loaded = 1;
- return 0;
- case MODULE_CMD_FINI:
- get_hdaudio_vendor = saved_hdaudio_vendor;
- get_hdaudio_product = saved_hdaudio_product;
- hdaudio_verbose_loaded = 0;
- return 0;
- default:
- return ENOTTY;
- }
-}
-
-void get_hdaudio_vendor_real(char *v, size_t vl, hdaudio_vendor_id_t v_id)
-{
- int n;
-
- /* There is no need for strlcpy below. */
- for (n = 0; n < hdaudio_nvendors; n++)
- if (hdaudio_vendors[n].vendor == v_id) {
- strlcpy(v, hdaudio_vendors[n].vendorname, vl);
- return;
- }
- snprintf(v, vl, "vendor 0x%.x", v_id);
-}
-
-void get_hdaudio_product_real(char *p, size_t pl, hdaudio_vendor_id_t v_id,
- hdaudio_product_id_t p_id)
-{
- int n;
-
- /* There is no need for strlcpy below. */
- for (n = 0; n < hdaudio_nproducts; n++)
- if (hdaudio_products[n].vendor == v_id &&
- hdaudio_products[n].product == p_id) {
- strlcpy(p, hdaudio_products[n].productname, pl);
- return;
- }
- snprintf(p, pl, "product 0x%.x", v_id);
-}
+DEV_VERBOSE_MODULE_DEFINE(hdaudio, NULL)
Index: src/sys/dev/pci/hdaudio/hdaudio_verbose.h
diff -u src/sys/dev/pci/hdaudio/hdaudio_verbose.h:1.1 src/sys/dev/pci/hdaudio/hdaudio_verbose.h:1.2
--- src/sys/dev/pci/hdaudio/hdaudio_verbose.h:1.1 Fri Sep 19 13:23:35 2014
+++ src/sys/dev/pci/hdaudio/hdaudio_verbose.h Sun Sep 21 10:30:22 2014
@@ -1,13 +1,9 @@
-/* $NetBSD: hdaudio_verbose.h,v 1.1 2014/09/19 17:23:35 christos Exp $ */
+/* $NetBSD: hdaudio_verbose.h,v 1.2 2014/09/21 14:30:22 christos Exp $ */
/*
- * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 2014 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:
@@ -33,13 +29,8 @@
#ifndef _DEV_PCI_HDAUDIO_HDAUDIO_VERBOSE_H_
#define _DEV_PCI_HDAUDIO_HDAUDIO_VERBOSE_H_
-typedef u_int16_t hdaudio_vendor_id_t;
-typedef u_int16_t hdaudio_product_id_t;
-
-extern void (*get_hdaudio_vendor)(char *, size_t, hdaudio_vendor_id_t);
-extern void (*get_hdaudio_product)(char *, size_t, hdaudio_vendor_id_t,
- hdaudio_product_id_t);
+#include <dev/dev_verbose.h>
-extern int hdaudio_verbose_loaded;
+DEV_VERBOSE_DECLARE(hdaudio);
#endif /* _DEV_PCI_HDAUDIO_HDAUDIO_VERBOSE_H_ */
Index: src/sys/dev/pci/hdaudio/hdafg.c
diff -u src/sys/dev/pci/hdaudio/hdafg.c:1.23 src/sys/dev/pci/hdaudio/hdafg.c:1.24
--- src/sys/dev/pci/hdaudio/hdafg.c:1.23 Sun Sep 21 06:41:22 2014
+++ src/sys/dev/pci/hdaudio/hdafg.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: hdafg.c,v 1.23 2014/09/21 10:41:22 nat Exp $ */
+/* $NetBSD: hdafg.c,v 1.24 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 2009 Precedence Technologies Ltd <[email protected]>
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hdafg.c,v 1.23 2014/09/21 10:41:22 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdafg.c,v 1.24 2014/09/21 14:30:22 christos Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -3614,8 +3614,8 @@ hdafg_attach(device_t parent, device_t s
prop_dictionary_get_uint16(args, "vendor-id", &sc->sc_vendor);
prop_dictionary_get_uint16(args, "product-id", &sc->sc_product);
- get_hdaudio_vendor(vendor, sizeof(vendor), sc->sc_vendor);
- get_hdaudio_product(product, sizeof(product), sc->sc_vendor,
+ hdaudio_findvendor(vendor, sizeof(vendor), sc->sc_vendor);
+ hdaudio_findproduct(product, sizeof(product), sc->sc_vendor,
sc->sc_product);
hda_print1(sc, ": %s %s%s\n", vendor, product,
sc->sc_config ? " (custom configuration)" : "");
@@ -3969,9 +3969,9 @@ hdafg_getdev(void *opaque, struct audio_
struct hdaudio_audiodev *ad = opaque;
struct hdafg_softc *sc = ad->ad_sc;
- get_hdaudio_vendor(audiodev->name, sizeof(audiodev->name),
+ hdaudio_findvendor(audiodev->name, sizeof(audiodev->name),
sc->sc_vendor);
- get_hdaudio_product(audiodev->version, sizeof(audiodev->version),
+ hdaudio_findproduct(audiodev->version, sizeof(audiodev->version),
sc->sc_vendor, sc->sc_product);
snprintf(audiodev->config, sizeof(audiodev->config) - 1,
"%02Xh", sc->sc_nid);
Index: src/sys/dev/pci/hdaudio/hdaudio.c
diff -u src/sys/dev/pci/hdaudio/hdaudio.c:1.23 src/sys/dev/pci/hdaudio/hdaudio.c:1.24
--- src/sys/dev/pci/hdaudio/hdaudio.c:1.23 Fri Sep 19 13:23:35 2014
+++ src/sys/dev/pci/hdaudio/hdaudio.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: hdaudio.c,v 1.23 2014/09/19 17:23:35 christos Exp $ */
+/* $NetBSD: hdaudio.c,v 1.24 2014/09/21 14:30:22 christos Exp $ */
/*
* Copyright (c) 2009 Precedence Technologies Ltd <[email protected]>
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.23 2014/09/19 17:23:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.24 2014/09/21 14:30:22 christos Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -1631,43 +1631,4 @@ hdaudio_modcmd(modcmd_t cmd, void *opaqu
}
}
-void hdaudio_load_verbose(void);
-
-void get_hdaudio_vendor_stub(char *, size_t, hdaudio_vendor_id_t);
-void get_hdaudio_product_stub(char *, size_t, hdaudio_vendor_id_t,
- hdaudio_product_id_t);
-
-void (*get_hdaudio_vendor)(char *, size_t, hdaudio_vendor_id_t) =
- get_hdaudio_vendor_stub;
-void (*get_hdaudio_product)(char *, size_t, hdaudio_vendor_id_t,
- hdaudio_product_id_t) = get_hdaudio_product_stub;
-
-int hdaudio_verbose_loaded = 0;
-
-/*
- * Load the hdaudioverbose module
- */
-void hdaudio_load_verbose(void)
-{
- if (hdaudio_verbose_loaded == 0)
- module_autoload("hdaudioverbose", MODULE_CLASS_MISC);
-}
-
-void get_hdaudio_vendor_stub(char *v, size_t l, hdaudio_vendor_id_t v_id)
-{
- hdaudio_load_verbose();
- if (hdaudio_verbose_loaded)
- get_hdaudio_vendor(v, l, v_id);
- else
- snprintf(v, l, "vendor 0x%.4x", v_id);
-}
-
-void get_hdaudio_product_stub(char *p, size_t l, hdaudio_vendor_id_t v_id,
- hdaudio_product_id_t p_id)
-{
- hdaudio_load_verbose();
- if (hdaudio_verbose_loaded)
- get_hdaudio_product(p, l, v_id, p_id);
- else
- snprintf(p, l, "product 0x%.4x", p_id);
-}
+DEV_VERBOSE_DEFINE(hdaudio);
Index: src/sys/dev/usb/Makefile.usbdevs
diff -u src/sys/dev/usb/Makefile.usbdevs:1.6 src/sys/dev/usb/Makefile.usbdevs:1.7
--- src/sys/dev/usb/Makefile.usbdevs:1.6 Mon Oct 12 18:28:47 2009
+++ src/sys/dev/usb/Makefile.usbdevs Sun Sep 21 10:30:22 2014
@@ -1,18 +1,14 @@
-# $NetBSD: Makefile.usbdevs,v 1.6 2009/10/12 22:28:47 wiz Exp $
-
-# The header files depend on the correct version of usbdevs.
+# $NetBSD: Makefile.usbdevs,v 1.7 2014/09/21 14:30:22 christos Exp $
+#
+# As per [email protected], the proper procedure is
#
-# Thus, the procedure is:
-# 1) change usbdevs
-# 2) commit usbdevs
-# 3) _then_ generate header files
-# 4) commit them
+# 1.) Change "src/sys/dev/usb/usbdevs".
+# 2.) Commit "src/sys/dev/usb/usbdevs".
+# 3.) Execute "make -f Makefile.usbdevs" in "src/sys/dev/usb".
+# 4.) Commit "src/sys/dev/usb/usbdevs.h" and "src/sys/dev/usb/usbdevs_data.h".
.include <bsd.own.mk>
-UNAME= uname
-RM= rm
-
-usbdevs.h usbdevs_data.h: usbdevs devlist2h.awk
- ${RM} -f usbdevs.h usbdevs_data.h
- ${TOOL_AWK} -v os=`${UNAME} -s` -f devlist2h.awk usbdevs
+usbdevs.h usbdevs_data.h: ${.CURDIR}/../devlist2h.awk usbdevs
+ /bin/rm -f usbdevs.h usbdevs_data.h
+ ${TOOL_AWK} -f ${.ALLSRC}
Index: src/sys/dev/usb/usb_verbose.c
diff -u src/sys/dev/usb/usb_verbose.c:1.6 src/sys/dev/usb/usb_verbose.c:1.7
--- src/sys/dev/usb/usb_verbose.c:1.6 Thu Dec 22 19:51:48 2011
+++ src/sys/dev/usb/usb_verbose.c Sun Sep 21 10:30:22 2014
@@ -1,14 +1,9 @@
-/* $NetBSD: usb_verbose.c,v 1.6 2011/12/23 00:51:48 jakllsch Exp $ */
-/* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */
+/* $NetBSD: usb_verbose.c,v 1.7 2014/09/21 14:30:22 christos Exp $ */
/*
- * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 2014 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:
@@ -32,82 +27,14 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_verbose.c,v 1.6 2011/12/23 00:51:48 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_verbose.c,v 1.7 2014/09/21 14:30:22 christos 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>
+#include <dev/usb/usb_verbose.h>
-void get_usb_vendor_real(char *, size_t, usb_vendor_id_t);
-void get_usb_product_real(char *, size_t, usb_vendor_id_t, usb_product_id_t);
-
-MODULE(MODULE_CLASS_MISC, usbverbose, NULL);
-
-static int
-usbverbose_modcmd(modcmd_t cmd, void *arg)
-{
- static void (*saved_usb_vendor)(char *, size_t, usb_vendor_id_t);
- static void (*saved_usb_product)(char *, size_t, usb_vendor_id_t,
- usb_product_id_t);
-
- switch (cmd) {
- case MODULE_CMD_INIT:
- saved_usb_vendor = get_usb_vendor;
- saved_usb_product = get_usb_product;
- get_usb_vendor = get_usb_vendor_real;
- get_usb_product = get_usb_product_real;
- usb_verbose_loaded = 1;
- return 0;
- case MODULE_CMD_FINI:
- get_usb_vendor = saved_usb_vendor;
- get_usb_product = saved_usb_product;
- usb_verbose_loaded = 0;
- return 0;
- default:
- return ENOTTY;
- }
-}
-
-void get_usb_vendor_real(char *v, size_t vl, 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) {
- strlcpy(v, usb_vendors[n].vendorname, vl);
- break;
- }
-}
-
-void get_usb_product_real(char *p, size_t pl, 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) {
- strlcpy(p, usb_products[n].productname, pl);
- break;
- }
-}
+DEV_VERBOSE_MODULE_DEFINE(usb, NULL)
Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.197 src/sys/dev/usb/usb_subr.c:1.198
--- src/sys/dev/usb/usb_subr.c:1.197 Fri Sep 12 12:40:38 2014
+++ src/sys/dev/usb/usb_subr.c Sun Sep 21 10:30:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: usb_subr.c,v 1.197 2014/09/12 16:40:38 skrll Exp $ */
+/* $NetBSD: usb_subr.c,v 1.198 2014/09/21 14:30:22 christos 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.197 2014/09/12 16:40:38 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.198 2014/09/21 14:30:22 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -109,40 +109,7 @@ Static const char * const usbd_error_str
"XXX",
};
-void usb_load_verbose(void);
-
-void get_usb_vendor_stub(char *, size_t, usb_vendor_id_t);
-void get_usb_product_stub(char *, size_t, usb_vendor_id_t, usb_product_id_t);
-
-void (*get_usb_vendor)(char *, size_t, usb_vendor_id_t) = get_usb_vendor_stub;
-void (*get_usb_product)(char *, size_t, usb_vendor_id_t, usb_product_id_t) =
- get_usb_product_stub;
-
-int usb_verbose_loaded = 0;
-
-/*
- * Load the usbverbose module
- */
-void usb_load_verbose(void)
-{
- if (usb_verbose_loaded == 0)
- module_autoload("usbverbose", MODULE_CLASS_MISC);
-}
-
-void get_usb_vendor_stub(char *v, size_t l, usb_vendor_id_t v_id)
-{
- usb_load_verbose();
- if (usb_verbose_loaded)
- get_usb_vendor(v, l, v_id);
-}
-
-void get_usb_product_stub(char *p, size_t l, usb_vendor_id_t v_id,
- usb_product_id_t p_id)
-{
- usb_load_verbose();
- if (usb_verbose_loaded)
- get_usb_product(p, l, v_id, p_id);
-}
+DEV_VERBOSE_DEFINE(usb);
const char *
usbd_errstr(usbd_status err)
@@ -226,15 +193,10 @@ usbd_devinfo_vp(usbd_device_handle dev,
usbd_trim_spaces(p);
}
if (v[0] == '\0')
- get_usb_vendor(v, vl, UGETW(udd->idVendor));
+ usb_findvendor(v, vl, UGETW(udd->idVendor));
if (p[0] == '\0')
- get_usb_product(p, pl, UGETW(udd->idVendor),
+ usb_findproduct(p, pl, UGETW(udd->idVendor),
UGETW(udd->idProduct));
-
- if (v[0] == '\0')
- snprintf(v, vl, "vendor 0x%04x", UGETW(udd->idVendor));
- if (p[0] == '\0')
- snprintf(p, pl, "product 0x%04x", UGETW(udd->idProduct));
}
int
Index: src/sys/dev/usb/usb_verbose.h
diff -u src/sys/dev/usb/usb_verbose.h:1.3 src/sys/dev/usb/usb_verbose.h:1.4
--- src/sys/dev/usb/usb_verbose.h:1.3 Sat Aug 7 17:09:48 2010
+++ src/sys/dev/usb/usb_verbose.h Sun Sep 21 10:30:22 2014
@@ -1,13 +1,9 @@
-/* $NetBSD: usb_verbose.h,v 1.3 2010/08/07 21:09:48 christos Exp $ */
+/* $NetBSD: usb_verbose.h,v 1.4 2014/09/21 14:30:22 christos Exp $ */
/*
- * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 2014 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:
@@ -33,13 +29,8 @@
#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;
-
-extern void (*get_usb_vendor)(char *, size_t, usb_vendor_id_t);
-extern void (*get_usb_product)(char *, size_t, usb_vendor_id_t,
- usb_product_id_t);
+#include <dev/dev_verbose.h>
-extern int usb_verbose_loaded;
+DEV_VERBOSE_DECLARE(usb);
#endif /* _DEV_USB_USBVERBOSE_H_ */
Added files:
Index: src/sys/dev/dev_verbose.c
diff -u /dev/null src/sys/dev/dev_verbose.c:1.1
--- /dev/null Sun Sep 21 10:30:22 2014
+++ src/sys/dev/dev_verbose.c Sun Sep 21 10:30:22 2014
@@ -0,0 +1,94 @@
+/* $NetBSD: dev_verbose.c,v 1.1 2014/09/21 14:30:22 christos Exp $ */
+
+/*
+ * 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 AUTHOR ``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 AUTHOR 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: dev_verbose.c,v 1.1 2014/09/21 14:30:22 christos Exp $");
+
+#include <sys/param.h>
+
+#ifdef _KERNEL
+#include <sys/systm.h>
+#else
+#include <stdio.h>
+#include <string.h>
+#endif
+
+#include <dev/dev_verbose.h>
+
+static const char *
+dev_untokenstring(const char *words, const uint16_t *token, char *buf,
+ size_t len)
+{
+ char *cp = buf;
+
+ buf[0] = '\0';
+ for (; *token != 0; token++) {
+ cp = buf + strlcat(buf, words + *token, len - 2);
+ cp[0] = ' ';
+ cp[1] = '\0';
+ }
+ *cp = '\0';
+ return cp != buf ? buf : NULL;
+}
+
+const char *
+dev_findvendor(char *buf, size_t len, const char *words, size_t nwords,
+ const uint16_t *vendors, size_t nvendors, uint16_t vendor)
+{
+ size_t n;
+
+ for (n = 0; n < nvendors; n++) {
+ if (vendors[n] == vendor)
+ return dev_untokenstring(words, &vendors[n + 1],
+ buf, len);
+
+ /* Skip Tokens */
+ n++;
+ while (vendors[n] != 0 && n < nvendors)
+ n++;
+ }
+ snprintf(buf, len, "vendor %4.4x", vendor);
+ return NULL;
+}
+
+const char *
+dev_findproduct(char *buf, size_t len, const char *words, size_t nwords,
+ const uint16_t *products, size_t nproducts, uint16_t vendor,
+ uint16_t product)
+{
+ size_t n;
+
+ for (n = 0; n < nproducts; n++) {
+ if (products[n] == vendor && products[n + 1] == product)
+ return dev_untokenstring(words, &products[n + 2],
+ buf, len);
+
+ /* Skip Tokens */
+ n += 2;
+ while (products[n] != 0 && n < nproducts)
+ n++;
+ }
+ snprintf(buf, len, "product %4.4x", product);
+ return NULL;
+}
Index: src/sys/dev/dev_verbose.h
diff -u /dev/null src/sys/dev/dev_verbose.h:1.1
--- /dev/null Sun Sep 21 10:30:22 2014
+++ src/sys/dev/dev_verbose.h Sun Sep 21 10:30:22 2014
@@ -0,0 +1,145 @@
+/* $NetBSD: dev_verbose.h,v 1.1 2014/09/21 14:30:22 christos Exp $ */
+
+/*
+ * 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 AUTHOR ``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 AUTHOR 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_DEV_VERBOSE_H_
+#define _DEV_DEV_VERBOSE_H_
+
+const char *dev_findvendor(char *, size_t, const char *, size_t,
+ const uint16_t *, size_t, uint16_t);
+const char *dev_findproduct(char *, size_t, const char *, size_t,
+ const uint16_t *, size_t, uint16_t, uint16_t);
+
+#define DEV_VERBOSE_COMMON_DEFINE(tag) \
+static const char * \
+tag ## _findvendor_real(char *buf, size_t len, uint16_t vendor) \
+{ \
+ return dev_findvendor(buf, len, tag ## _words, \
+ __arraycount(tag ## _words), tag ## _vendors, \
+ __arraycount(tag ## _vendors), vendor); \
+} \
+ \
+static const char * \
+tag ## _findproduct_real(char *buf, size_t len, uint16_t vendor, \
+ uint16_t product) \
+{ \
+ return dev_findproduct(buf, len, tag ## _words, \
+ __arraycount(tag ## _words), tag ## _products, \
+ __arraycount(tag ## _products), vendor, product); \
+} \
+
+#ifdef _KERNEL
+
+#define DEV_VERBOSE_MODULE_DEFINE(tag, deps) \
+DEV_VERBOSE_COMMON_DEFINE(tag) \
+extern int tag ## verbose_loaded; \
+ \
+static int \
+tag ## verbose_modcmd(modcmd_t cmd, void *arg) \
+{ \
+ static const char *(*saved_findvendor)(char *, size_t, \
+ uint16_t); \
+ static const char *(*saved_findproduct)(char *, size_t, \
+ uint16_t, uint16_t); \
+ \
+ switch (cmd) { \
+ case MODULE_CMD_INIT: \
+ saved_findvendor = tag ## _findvendor; \
+ saved_findproduct = tag ## _findproduct; \
+ tag ## _findvendor = tag ## _findvendor_real; \
+ tag ## _findproduct = tag ## _findproduct_real; \
+ tag ## verbose_loaded = 1; \
+ return 0; \
+ case MODULE_CMD_FINI: \
+ tag ## _findvendor = saved_findvendor; \
+ tag ## _findproduct = saved_findproduct; \
+ tag ## verbose_loaded = 0; \
+ return 0; \
+ default: \
+ return ENOTTY; \
+ } \
+} \
+MODULE(MODULE_CLASS_MISC, tag ## verbose, deps)
+
+#endif /* KERNEL */
+
+#define DEV_VERBOSE_DECLARE(tag) \
+extern const char * (*tag ## _findvendor)(char *, size_t, uint16_t); \
+extern const char * (*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t)
+
+#if defined(_KERNEL)
+#define DEV_VERBOSE_DEFINE(tag) \
+int tag ## verbose_loaded = 0; \
+ \
+static void \
+tag ## _load_verbose(void) \
+{ \
+ \
+ if (tag ## verbose_loaded == 0) \
+ module_autoload(# tag "verbose", MODULE_CLASS_MISC); \
+} \
+ \
+static const char * \
+tag ## _findvendor_stub(char *buf, size_t len, uint16_t vendor) \
+{ \
+ \
+ tag ## _load_verbose(); \
+ if (tag ## verbose_loaded) \
+ return tag ## _findvendor(buf, len, vendor); \
+ else { \
+ snprintf(buf, len, "vendor %4.4x", vendor); \
+ return NULL; \
+ } \
+} \
+ \
+static const char * \
+tag ## _findproduct_stub(char *buf, size_t len, uint16_t vendor, \
+ uint16_t product) \
+{ \
+ \
+ tag ## _load_verbose(); \
+ if (tag ## verbose_loaded) \
+ return tag ## _findproduct(buf, len, vendor, product); \
+ else { \
+ snprintf(buf, len, "product %4.4x", product); \
+ return NULL; \
+ } \
+} \
+ \
+const char *(*tag ## _findvendor)(char *, size_t, uint16_t) = \
+ tag ## _findvendor_stub; \
+const char *(*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t) =\
+ tag ## _findproduct_stub; \
+
+#else
+
+#define DEV_VERBOSE_DEFINE(tag) \
+DEV_VERBOSE_COMMON_DEFINE(tag) \
+const char *(*tag ## _findvendor)(char *, size_t, uint16_t) = \
+ tag ## _findvendor_real; \
+const char *(*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t) =\
+ tag ## _findproduct_real; \
+
+#endif /* _KERNEL */
+
+#endif /* _DEV_DEV_VERBOSE_H_ */
Index: src/sys/dev/devlist2h.awk
diff -u /dev/null src/sys/dev/devlist2h.awk:1.1
--- /dev/null Sun Sep 21 10:30:22 2014
+++ src/sys/dev/devlist2h.awk Sun Sep 21 10:30:22 2014
@@ -0,0 +1,245 @@
+#! /usr/bin/awk -f
+# $NetBSD: devlist2h.awk,v 1.1 2014/09/21 14:30:22 christos Exp $
+#
+# Copyright (c) 1995, 1996 Christopher G. Demetriou
+# All rights reserved.
+#
+# 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.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by Christopher G. Demetriou.
+# 4. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+#
+NR == 1 {
+ nproducts = nvendors = blanklines = 0
+ nchars = 1
+ dfile= FILENAME "_data.h"
+ hfile= FILENAME ".h"
+ prefix = FILENAME
+ gsub("devs", "", prefix)
+ PREFIX = toupper(prefix)
+ VERSION = $0
+ gsub("\\$", "", VERSION)
+ gsub(/ $/, "", VERSION)
+
+ printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
+ printf("/*\n") > dfile
+ printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
+ > dfile
+ printf(" *\n") > dfile
+ printf(" * generated from:\n") > dfile
+ printf(" *\t%s\n", VERSION) > dfile
+ printf(" */\n") > dfile
+
+ printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
+ printf("/*\n") > hfile
+ printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
+ > hfile
+ printf(" *\n") > hfile
+ printf(" * generated from:\n") > hfile
+ printf(" *\t%s\n", VERSION) > hfile
+ printf(" */\n") > hfile
+
+ next
+}
+NF > 0 && $1 == "vendor" {
+ nvendors++
+
+ vendorindex[$2] = nvendors; # record index for this name, for later.
+ vendors[nvendors, 1] = $2; # name
+ vendors[nvendors, 2] = $3; # id
+ printf("#define\t%s_VENDOR_%s\t%s", PREFIX, vendors[nvendors, 1],
+ vendors[nvendors, 2]) > hfile
+
+ i = 3; f = 4;
+
+ # comments
+ ocomment = oparen = 0
+ if (f <= NF) {
+ printf("\t\t/* ") > hfile
+ ocomment = 1;
+ }
+ while (f <= NF) {
+ if ($f == "#") {
+ printf("(") > hfile
+ oparen = 1
+ f++
+ continue
+ }
+ if (oparen) {
+ printf("%s", $f) > hfile
+ if (f < NF)
+ printf(" ") > hfile
+ f++
+ continue
+ }
+ vendors[nvendors, i] = $f
+ if (words[$f, 1] == 0) {
+ l = length($f);
+ parts = split($f, junk, "\\");
+ l = l - (parts - 1);
+ nwords++;
+ words[$f, 1] = nwords;
+ words[$f, 2] = l;
+ wordlist[nwords, 1] = $f;
+ wordlist[nwords, 3] = nchars;
+ nchars = nchars + l + 1;
+ }
+ wordlist[words[$f, 1], 2]++;
+ vendors[nvendors, i] = words[$f, 1];
+ printf("%s", $f) > hfile
+ if (f < NF)
+ printf(" ") > hfile
+ i++; f++;
+ }
+ if (oparen)
+ printf(")") > hfile
+ if (ocomment)
+ printf(" */") > hfile
+ printf("\n") > hfile
+
+ next
+}
+NF > 0 && $1 == "product" {
+ nproducts++
+
+ products[nproducts, 1] = $2; # vendor name
+ products[nproducts, 2] = $3; # product id
+ products[nproducts, 3] = $4; # id
+ printf("#define\t%s_PRODUCT_%s_%s\t%s", PREFIX, products[nproducts, 1],
+ products[nproducts, 2], products[nproducts, 3]) > hfile
+
+ i=4; f = 5;
+
+ # comments
+ ocomment = oparen = 0
+ if (f <= NF) {
+ printf("\t\t/* ") > hfile
+ ocomment = 1;
+ }
+ while (f <= NF) {
+ if ($f == "#") {
+ printf("(") > hfile
+ oparen = 1
+ f++
+ continue
+ }
+ if (oparen) {
+ printf("%s", $f) > hfile
+ if (f < NF)
+ printf(" ") > hfile
+ f++
+ continue
+ }
+ if (words[$f, 1] == 0) {
+ l = length($f);
+ parts = split($f, junk, "\\");
+ l = l - (parts - 1);
+ nwords++;
+ words[$f, 2] = l;
+ words[$f, 1] = nwords;
+ wordlist[nwords, 1] = $f;
+ wordlist[nwords, 3] = nchars;
+ nchars = nchars + l + 1;
+ }
+ wordlist[words[$f, 1], 2]++;
+ products[nproducts, i] = words[$f, 1];
+ printf("%s", $f) > hfile
+ if (f < NF)
+ printf(" ") > hfile
+ i++; f++;
+ }
+ if (oparen)
+ printf(")") > hfile
+ if (ocomment)
+ printf(" */") > hfile
+ printf("\n") > hfile
+
+ next
+}
+{
+ if ($0 == "")
+ blanklines++
+ print $0 > hfile
+ if (blanklines < 2)
+ print $0 > dfile
+}
+END {
+ # print out the match tables
+
+ printf("\n") > dfile
+
+ printf("static const uint16_t %s_vendors[] = {\n", prefix) > dfile
+ for (i = 1; i <= nvendors; i++) {
+ printf("\t %s_VENDOR_%s", PREFIX, vendors[i, 1]) \
+ > dfile
+
+ j = 3;
+ while ((i, j) in vendors) {
+ printf(", %d",
+ wordlist[vendors[i, j], 3]) > dfile
+# printf(", %d /* %s */",
+# wordlist[vendors[i, j], 3],
+# wordlist[vendors[i, j], 1]) > dfile
+ j++
+ }
+ printf(", 0,\n", sep) > dfile
+ }
+ printf("};\n") > dfile
+
+ printf("\n") > dfile
+
+ printf("static const uint16_t %s_products[] = {\n", prefix) > dfile
+ for (i = 1; i <= nproducts; i++) {
+ printf("\t %s_VENDOR_%s, %s_PRODUCT_%s_%s, \n",
+ PREFIX, products[i, 1], PREFIX, products[i, 1],
+ products[i, 2]) > dfile
+
+ printf("\t ") > dfile
+ j = 4
+ sep = ""
+ while ((i, j) in products) {
+ printf("%s%d", sep,
+ wordlist[products[i, j], 3]) > dfile
+# printf("%s%d /* %s */", sep,
+# wordlist[products[i, j], 3],
+# wordlist[products[i, j], 1]) > dfile
+ sep = ", "
+ j++
+ }
+ printf("%s0,\n", sep) > dfile
+ }
+ printf("};\n") > dfile
+
+ printf("static const char %s_words[] = { \".\" \n", prefix) > dfile
+ for (i = 1; i <= nwords; i++) {
+ printf("\t \"%s\\0\" /* %d refs @ %d */\n",
+ wordlist[i, 1], wordlist[i, 2], wordlist[i, 3]) > dfile
+ }
+ printf("};\n") > dfile
+ printf("const int %s_nwords = %d;\n", prefix, nwords) > dfile
+
+ printf("\n") > dfile
+
+ close(dfile)
+ close(hfile)
+}