diff options
| author | mycroft <mycroft@NetBSD.org> | 2004-08-02 18:43:38 +0000 |
|---|---|---|
| committer | mycroft <mycroft@NetBSD.org> | 2004-08-02 18:43:38 +0000 |
| commit | 31a80e2d68e1aded54fd4df2d64616fec11e6633 (patch) | |
| tree | 07ecabf0042915b380872902c96c3128f20a1b81 /sys/dev | |
| parent | 08adc832cfa7df88c86695a57b1b02c89de83a35 (diff) | |
For the PCIVERBOSE case, separate vendors and products into separate tables.
Eliminating redundant pointers in the tables saves nearly 20K (20% of the table
size). In the process, add a pci_findproduct() and make that and
pci_findvendor() return a "const char *".
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/pci/devlist2h.awk | 53 | ||||
| -rw-r--r-- | sys/dev/pci/ehci_pci.c | 8 | ||||
| -rw-r--r-- | sys/dev/pci/ohci_pci.c | 8 | ||||
| -rw-r--r-- | sys/dev/pci/pci_subr.c | 94 | ||||
| -rw-r--r-- | sys/dev/pci/pcivar.h | 5 | ||||
| -rw-r--r-- | sys/dev/pci/uhci_pci.c | 8 |
6 files changed, 75 insertions, 101 deletions
diff --git a/sys/dev/pci/devlist2h.awk b/sys/dev/pci/devlist2h.awk index 03955e3862f..8676560c80a 100644 --- a/sys/dev/pci/devlist2h.awk +++ b/sys/dev/pci/devlist2h.awk @@ -1,5 +1,5 @@ #! /usr/bin/awk -f -# $NetBSD: devlist2h.awk,v 1.8 2003/12/15 07:32:21 jmc Exp $ +# $NetBSD: devlist2h.awk,v 1.9 2004/08/02 18:43:38 mycroft Exp $ # # Copyright (c) 1995, 1996 Christopher G. Demetriou # All rights reserved. @@ -160,64 +160,53 @@ END { printf("\n") > dfile - printf("const struct pci_knowndev pci_knowndevs[] = {\n") > dfile - for (i = 1; i <= nproducts; i++) { + printf("const struct pci_vendor pci_vendors[] = {\n") > dfile + for (i = 1; i <= nvendors; i++) { printf("\t{\n") > dfile - printf("\t PCI_VENDOR_%s, PCI_PRODUCT_%s_%s,\n", - products[i, 1], products[i, 1], products[i, 2]) \ + printf("\t PCI_VENDOR_%s,\n", vendors[i, 1]) \ > dfile - printf("\t ") > dfile - printf("0") > dfile - printf(",\n") > dfile - vendi = vendorindex[products[i, 1]]; printf("\t \"") > dfile j = 3; needspace = 0; - while ((vendi, j) in vendors) { - if (needspace) - printf(" ") > dfile - printf("%s", vendors[vendi, j]) > dfile - needspace = 1 - j++ - } - printf("\",\n") > dfile - - printf("\t \"") > dfile - j = 4; - needspace = 0; - while ((i, j) in products) { + while ((i, j) in vendors) { if (needspace) printf(" ") > dfile - printf("%s", products[i, j]) > dfile + printf("%s", vendors[i, j]) > dfile needspace = 1 j++ } printf("\",\n") > dfile printf("\t},\n") > dfile } - for (i = 1; i <= nvendors; i++) { + printf("};\n") > dfile + printf("const int pci_nvendors = %d;\n", nvendors) > dfile + + printf("\n") > dfile + + printf("const struct pci_product pci_products[] = {\n") > dfile + for (i = 1; i <= nproducts; i++) { printf("\t{\n") > dfile - printf("\t PCI_VENDOR_%s, 0,\n", vendors[i, 1]) \ - > dfile - printf("\t PCI_KNOWNDEV_NOPROD,\n") \ + printf("\t PCI_VENDOR_%s, PCI_PRODUCT_%s_%s,\n", + products[i, 1], products[i, 1], products[i, 2]) \ > dfile + printf("\t \"") > dfile - j = 3; + j = 4; needspace = 0; - while ((i, j) in vendors) { + while ((i, j) in products) { if (needspace) printf(" ") > dfile - printf("%s", vendors[i, j]) > dfile + printf("%s", products[i, j]) > dfile needspace = 1 j++ } printf("\",\n") > dfile - printf("\t NULL,\n") > dfile printf("\t},\n") > dfile } - printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile printf("};\n") > dfile + printf("const int pci_nproducts = %d;\n", nproducts) >dfile + close(dfile) close(hfile) } diff --git a/sys/dev/pci/ehci_pci.c b/sys/dev/pci/ehci_pci.c index 8242332db63..b080eeaaeda 100644 --- a/sys/dev/pci/ehci_pci.c +++ b/sys/dev/pci/ehci_pci.c @@ -1,4 +1,4 @@ -/* $NetBSD: ehci_pci.c,v 1.15 2004/04/23 21:13:06 itojun Exp $ */ +/* $NetBSD: ehci_pci.c,v 1.16 2004/08/02 18:43:38 mycroft Exp $ */ /* * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ehci_pci.c,v 1.15 2004/04/23 21:13:06 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ehci_pci.c,v 1.16 2004/08/02 18:43:38 mycroft Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -103,8 +103,8 @@ ehci_pci_attach(struct device *parent, struct device *self, void *aux) char const *intrstr; pci_intr_handle_t ih; pcireg_t csr; - char *vendor; - char *devname = sc->sc.sc_bus.bdev.dv_xname; + const char *vendor; + const char *devname = sc->sc.sc_bus.bdev.dv_xname; char devinfo[256]; usbd_status r; int ncomp; diff --git a/sys/dev/pci/ohci_pci.c b/sys/dev/pci/ohci_pci.c index 3b4a40a27bd..d2fccb26f9b 100644 --- a/sys/dev/pci/ohci_pci.c +++ b/sys/dev/pci/ohci_pci.c @@ -1,4 +1,4 @@ -/* $NetBSD: ohci_pci.c,v 1.25 2004/04/23 21:13:06 itojun Exp $ */ +/* $NetBSD: ohci_pci.c,v 1.26 2004/08/02 18:43:38 mycroft Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ohci_pci.c,v 1.25 2004/04/23 21:13:06 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ohci_pci.c,v 1.26 2004/08/02 18:43:38 mycroft Exp $"); #include "ehci.h" @@ -103,8 +103,8 @@ ohci_pci_attach(struct device *parent, struct device *self, void *aux) pcireg_t csr; char devinfo[256]; usbd_status r; - char *vendor; - char *devname = sc->sc.sc_bus.bdev.dv_xname; + const char *vendor; + const char *devname = sc->sc.sc_bus.bdev.dv_xname; pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo)); printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class)); diff --git a/sys/dev/pci/pci_subr.c b/sys/dev/pci/pci_subr.c index a85e58b546c..f3d79c72faf 100644 --- a/sys/dev/pci/pci_subr.c +++ b/sys/dev/pci/pci_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: pci_subr.c,v 1.58 2004/04/23 21:13:07 itojun Exp $ */ +/* $NetBSD: pci_subr.c,v 1.59 2004/08/02 18:43:38 mycroft 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.58 2004/04/23 21:13:07 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.59 2004/08/02 18:43:38 mycroft Exp $"); #ifdef _KERNEL_OPT #include "opt_pci.h" @@ -295,34 +295,47 @@ const struct pci_class pci_class[] = { /* * Descriptions of of known vendors and devices ("products"). */ -struct pci_knowndev { +struct pci_vendor { + pci_vendor_id_t vendor; + const char *vendorname; +}; +struct pci_product { pci_vendor_id_t vendor; pci_product_id_t product; - int flags; - char *vendorname, *productname; + const char *productname; }; -#define PCI_KNOWNDEV_NOPROD 0x01 /* match on vendor only */ #include <dev/pci/pcidevs_data.h> #endif /* PCIVERBOSE */ -char * +const char * pci_findvendor(pcireg_t id_reg) { #ifdef PCIVERBOSE pci_vendor_id_t vendor = PCI_VENDOR(id_reg); - const struct pci_knowndev *kdp; + int n; - kdp = pci_knowndevs; - while (kdp->vendorname != NULL) { /* all have vendor name */ - if (kdp->vendor == vendor) - break; - kdp++; - } - return (kdp->vendorname); -#else + for (n = 0; n < pci_nvendors; n++) + if (pci_vendors[n].vendor == vendor) + return (pci_vendors[n].vendorname); +#endif return (NULL); +} + +const char * +pci_findproduct(pcireg_t id_reg) +{ +#ifdef PCIVERBOSE + pci_vendor_id_t vendor = PCI_VENDOR(id_reg); + pci_product_id_t product = PCI_PRODUCT(id_reg); + int n; + + for (n = 0; n < pci_nproducts; n++) + if (pci_products[n].vendor == vendor && + pci_products[n].product == product) + return (pci_products[n].productname); #endif + return (NULL); } void @@ -335,10 +348,9 @@ pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp, pci_subclass_t subclass; pci_interface_t interface; pci_revision_t revision; - char *vendor_namep, *product_namep; + const char *vendor_namep, *product_namep; const struct pci_class *classp, *subclassp; #ifdef PCIVERBOSE - const struct pci_knowndev *kdp; const char *unmatched = "unknown "; #else const char *unmatched = ""; @@ -355,24 +367,8 @@ pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp, interface = PCI_INTERFACE(class_reg); revision = PCI_REVISION(class_reg); -#ifdef PCIVERBOSE - kdp = pci_knowndevs; - while (kdp->vendorname != NULL) { /* all have vendor name */ - if (kdp->vendor == vendor && (kdp->product == product || - (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0)) - break; - kdp++; - } - if (kdp->vendorname == NULL) - vendor_namep = product_namep = NULL; - else { - vendor_namep = kdp->vendorname; - product_namep = (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0 ? - kdp->productname : NULL; - } -#else /* PCIVERBOSE */ - vendor_namep = product_namep = NULL; -#endif /* PCIVERBOSE */ + vendor_namep = pci_findvendor(id_reg); + product_namep = pci_findproduct(id_reg); classp = pci_class; while (classp->name != NULL) { @@ -443,35 +439,23 @@ pci_conf_print_common( #endif const pcireg_t *regs) { -#ifdef PCIVERBOSE - const struct pci_knowndev *kdp; -#endif + const char *name; const struct pci_class *classp, *subclassp; pcireg_t rval; rval = regs[o2i(PCI_ID_REG)]; -#ifndef PCIVERBOSE - printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval)); - printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval)); -#else - for (kdp = pci_knowndevs; kdp->vendorname != NULL; kdp++) { - if (kdp->vendor == PCI_VENDOR(rval) && - (kdp->product == PCI_PRODUCT(rval) || - (kdp->flags & PCI_KNOWNDEV_NOPROD) != 0)) { - break; - } - } - if (kdp->vendorname != NULL) - printf(" Vendor Name: %s (0x%04x)\n", kdp->vendorname, + name = pci_findvendor(rval); + if (name) + printf(" Vendor Name: %s (0x%04x)\n", name, PCI_VENDOR(rval)); else printf(" Vendor ID: 0x%04x\n", PCI_VENDOR(rval)); - if (kdp->productname != NULL && (kdp->flags & PCI_KNOWNDEV_NOPROD) == 0) - printf(" Device Name: %s (0x%04x)\n", kdp->productname, + name = pci_findproduct(rval); + if (name) + printf(" Device Name: %s (0x%04x)\n", name, PCI_PRODUCT(rval)); else printf(" Device ID: 0x%04x\n", PCI_PRODUCT(rval)); -#endif /* PCIVERBOSE */ rval = regs[o2i(PCI_COMMAND_STATUS_REG)]; diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index 71db9056fc5..2beae79b097 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: pcivar.h,v 1.62 2004/07/29 16:51:01 drochner Exp $ */ +/* $NetBSD: pcivar.h,v 1.63 2004/08/02 18:43:38 mycroft Exp $ */ /* * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. @@ -237,7 +237,8 @@ int pci_vpd_write __P((pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *)); /* * Misc. */ -char *pci_findvendor __P((pcireg_t)); +const char *pci_findvendor __P((pcireg_t)); +const char *pci_findproduct __P((pcireg_t)); int pci_find_device(struct pci_attach_args *pa, int (*match)(struct pci_attach_args *)); int pci_dma64_available(struct pci_attach_args *); diff --git a/sys/dev/pci/uhci_pci.c b/sys/dev/pci/uhci_pci.c index e7c038ea189..bd1a193f8c6 100644 --- a/sys/dev/pci/uhci_pci.c +++ b/sys/dev/pci/uhci_pci.c @@ -1,4 +1,4 @@ -/* $NetBSD: uhci_pci.c,v 1.26 2004/04/23 21:13:07 itojun Exp $ */ +/* $NetBSD: uhci_pci.c,v 1.27 2004/08/02 18:43:38 mycroft Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uhci_pci.c,v 1.26 2004/04/23 21:13:07 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uhci_pci.c,v 1.27 2004/08/02 18:43:38 mycroft Exp $"); #include "ehci.h" @@ -102,8 +102,8 @@ uhci_pci_attach(struct device *parent, struct device *self, void *aux) char const *intrstr; pci_intr_handle_t ih; pcireg_t csr; - char *vendor; - char *devname = sc->sc.sc_bus.bdev.dv_xname; + const char *vendor; + const char *devname = sc->sc.sc_bus.bdev.dv_xname; char devinfo[256]; usbd_status r; |
