diff options
| author | matt <matt@NetBSD.org> | 2008-11-17 23:33:41 +0000 |
|---|---|---|
| committer | matt <matt@NetBSD.org> | 2008-11-17 23:33:41 +0000 |
| commit | eadd097264d343f7fff1c5caf78314bca1a89b3e (patch) | |
| tree | ffacad22cecda85b406335a54a8cb71e7f585168 /sys/dev | |
| parent | a5be52d405632098ec6152202de107e5bee5d5b3 (diff) | |
Store pcidevs in a more compact manner. Instead of many string with duplicate
words, store each word individual in a long string and then store offsets
in the string to that word. This reduces the space needed by half.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/pci/devlist2h.awk | 89 | ||||
| -rw-r--r-- | sys/dev/pci/pci_subr.c | 66 |
2 files changed, 106 insertions, 49 deletions
diff --git a/sys/dev/pci/devlist2h.awk b/sys/dev/pci/devlist2h.awk index e549eb8fb21..903b93ec5f9 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.12 2005/12/11 12:22:49 christos Exp $ +# $NetBSD: devlist2h.awk,v 1.13 2008/11/17 23:33:42 matt Exp $ # # Copyright (c) 1995, 1996 Christopher G. Demetriou # All rights reserved. @@ -31,6 +31,7 @@ # BEGIN { nproducts = nvendors = blanklines = 0 + nchars = 1 dfile="pcidevs_data.h" hfile="pcidevs.h" } @@ -91,7 +92,20 @@ NF > 0 && $1 == "vendor" { continue } vendors[nvendors, i] = $f - printf("%s", vendors[nvendors, i]) > hfile + 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++; @@ -135,8 +149,20 @@ NF > 0 && $1 == "product" { f++ continue } - products[nproducts, i] = $f - printf("%s", products[nproducts, i]) > hfile + 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++; @@ -161,52 +187,57 @@ END { printf("\n") > dfile - printf("static const struct pci_vendor pci_vendors[] = {\n") > dfile + printf("static const uint16_t pci_vendors[] = {\n") > dfile for (i = 1; i <= nvendors; i++) { - printf("\t{\n") > dfile - printf("\t PCI_VENDOR_%s,\n", vendors[i, 1]) \ + printf("\t PCI_VENDOR_%s", vendors[i, 1]) \ > dfile - printf("\t \"") > dfile j = 3; - needspace = 0; while ((i, j) in vendors) { - if (needspace) - printf(" ") > dfile - printf("%s", vendors[i, j]) > dfile - needspace = 1 + printf(", %d", + wordlist[vendors[i, j], 3]) > dfile +# printf(", %d /* %s */", +# wordlist[vendors[i, j], 3], +# wordlist[vendors[i, j], 1]) > dfile j++ } - printf("\",\n") > dfile - printf("\t},\n") > dfile + printf(", 0,\n", sep) > dfile } printf("};\n") > dfile - printf("const int pci_nvendors = %d;\n", nvendors) > dfile printf("\n") > dfile - printf("static const struct pci_product pci_products[] = {\n") > dfile + printf("static const uint16_t pci_products[] = {\n") > dfile for (i = 1; i <= nproducts; i++) { - printf("\t{\n") > dfile - printf("\t PCI_VENDOR_%s, PCI_PRODUCT_%s_%s,\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 = 4; - needspace = 0; + printf("\t ") > dfile + j = 4 + sep = "" while ((i, j) in products) { - if (needspace) - printf(" ") > dfile - printf("%s", products[i, j]) > dfile - needspace = 1 + 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("\",\n") > dfile - printf("\t},\n") > dfile + printf("%s0,\n", sep) > dfile } printf("};\n") > dfile - printf("const int pci_nproducts = %d;\n", nproducts) >dfile + + printf("static const char pci_words[] = { \".\" \n") > 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 pci_nwords = %d;\n", nwords) > dfile + + printf("\n") > dfile close(dfile) close(hfile) diff --git a/sys/dev/pci/pci_subr.c b/sys/dev/pci/pci_subr.c index 2a97d0b462e..94da4606928 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.75 2008/04/29 17:27:38 jmcneill Exp $ */ +/* $NetBSD: pci_subr.c,v 1.76 2008/11/17 23:33:41 matt 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.75 2008/04/29 17:27:38 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.76 2008/11/17 23:33:41 matt Exp $"); #ifdef _KERNEL_OPT #include "opt_pci.h" @@ -299,29 +299,48 @@ static const struct pci_class pci_class[] = { /* * Descriptions of of known vendors and devices ("products"). */ -struct pci_vendor { - pci_vendor_id_t vendor; - const char *vendorname; -}; -struct pci_product { - pci_vendor_id_t vendor; - pci_product_id_t product; - const char *productname; -}; #include <dev/pci/pcidevs_data.h> #endif /* PCIVERBOSE */ +#ifdef PCIVERBOSE +#ifndef _KERNEL +#include <string.h> +#endif +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; +} +#endif /* PCIVERBOSE */ + const char * pci_findvendor(pcireg_t id_reg) { #ifdef PCIVERBOSE + static char buf[256]; pci_vendor_id_t vendor = PCI_VENDOR(id_reg); - int n; + 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)); - for (n = 0; n < pci_nvendors; n++) - if (pci_vendors[n].vendor == vendor) - return (pci_vendors[n].vendorname); + /* Skip Tokens */ + n++; + while (pci_vendors[n] != 0 && n < __arraycount(pci_vendors)) + n++; + } #endif return (NULL); } @@ -330,14 +349,21 @@ const char * pci_findproduct(pcireg_t id_reg) { #ifdef PCIVERBOSE + static char buf[256]; pci_vendor_id_t vendor = PCI_VENDOR(id_reg); pci_product_id_t product = PCI_PRODUCT(id_reg); - int n; + 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)); - for (n = 0; n < pci_nproducts; n++) - if (pci_products[n].vendor == vendor && - pci_products[n].product == product) - return (pci_products[n].productname); + /* Skip Tokens */ + n += 2; + while (pci_products[n] != 0 && n < __arraycount(pci_products)) + n++; + } #endif return (NULL); } |
