summaryrefslogtreecommitdiff
path: root/sys/dev/pci
diff options
context:
space:
mode:
authorMarc Balmer <mbalmer@cvs.openbsd.org>2007-01-02 19:22:39 +0000
committerMarc Balmer <mbalmer@cvs.openbsd.org>2007-01-02 19:22:39 +0000
commit9bab9e143a76bc8940746c4151dfa18dc814571a (patch)
treee20a1a88b680d3b3acd2cddfbb93794f1fe2de19 /sys/dev/pci
parent7fb614193bec906617aa3e8b00b7240e52355204 (diff)
Provide a new function, pci_findproduct(), which is analog to pci_findvendor().
Use these two functions in pci_devinfo() to remove some duplicated code and make it easier to read. Remove two now unused variables. This shrinks the size of the resulting object code. Drivers (or other kernel code) can now get at the PCI vendor and/or product strings using pci_findvendor() and pci_findproduct(). ok claudio, deraadt, mglocker
Diffstat (limited to 'sys/dev/pci')
-rw-r--r--sys/dev/pci/pci_subr.c45
-rw-r--r--sys/dev/pci/pcivar.h3
2 files changed, 26 insertions, 22 deletions
diff --git a/sys/dev/pci/pci_subr.c b/sys/dev/pci/pci_subr.c
index ed4412d86ce..5fc0be8093a 100644
--- a/sys/dev/pci/pci_subr.c
+++ b/sys/dev/pci/pci_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pci_subr.c,v 1.19 2006/06/01 11:17:31 brad Exp $ */
+/* $OpenBSD: pci_subr.c,v 1.20 2007/01/02 19:22:38 mbalmer Exp $ */
/* $NetBSD: pci_subr.c,v 1.19 1996/10/13 01:38:29 christos Exp $ */
/*
@@ -312,6 +312,26 @@ pci_findvendor(pcireg_t id_reg)
#endif
}
+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);
+ const struct pci_known_product *pkp;
+
+ pkp = pci_known_products;
+ while (pkp->productname != NULL) { /* all have product name */
+ if (pkp->vendor == vendor && pkp->product == product)
+ break;
+ pkp++;
+ }
+ return (pkp->productname);
+#else
+ return NULL;
+#endif
+}
+
void
pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp,
size_t cp_max)
@@ -326,8 +346,6 @@ pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp,
const struct pci_class *classp, *subclassp;
size_t cp_len = 0;
#ifdef PCIVERBOSE
- const struct pci_known_vendor *pkv;
- const struct pci_known_product *pkp;
const char *unmatched = "unknown ";
#else
const char *unmatched = "";
@@ -342,24 +360,9 @@ pci_devinfo(pcireg_t id_reg, pcireg_t class_reg, int showclass, char *cp,
revision = PCI_REVISION(class_reg);
#ifdef PCIVERBOSE
- pkv = pci_known_vendors;
- while (pkv->vendorname != NULL) { /* all have vendor name */
- if (pkv->vendor == vendor) {
- vendor_namep = pkv->vendorname;
- break;
- }
- pkv++;
- }
- if (vendor_namep) {
- pkp = pci_known_products;
- while (pkp->productname != NULL) { /* all have product name */
- if (pkp->vendor == vendor && pkp->product == product) {
- product_namep = pkp->productname;
- break;
- }
- pkp++;
- }
- }
+ vendor_namep = pci_findvendor(id_reg);
+ if (vendor_namep != NULL)
+ product_namep = pci_findproduct(id_reg);
#endif /* PCIVERBOSE */
classp = pci_class;
diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h
index 99cafa18b2d..5ab2de32e4e 100644
--- a/sys/dev/pci/pcivar.h
+++ b/sys/dev/pci/pcivar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcivar.h,v 1.50 2006/12/14 17:36:12 kettenis Exp $ */
+/* $OpenBSD: pcivar.h,v 1.51 2007/01/02 19:22:38 mbalmer Exp $ */
/* $NetBSD: pcivar.h,v 1.23 1997/06/06 23:48:05 thorpej Exp $ */
/*
@@ -216,6 +216,7 @@ int pci_matchbyid(struct pci_attach_args *, const struct pci_matchid *, int);
* Helper functions for autoconfiguration.
*/
const char *pci_findvendor(pcireg_t);
+const char *pci_findproduct(pcireg_t);
int pci_find_device(struct pci_attach_args *pa,
int (*match)(struct pci_attach_args *));
int pci_probe_device(struct pci_softc *, pcitag_t tag,