Source-Changes-HG archive

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

[src/trunk]: src/sys/arch pci_device_foreach(), pci_device_foreach_min(), pci...



details:   https://anonhg.NetBSD.org/src/rev/05d5d8c10edd
branches:  trunk
changeset: 582203:05d5d8c10edd
user:      sekiya <sekiya%NetBSD.org@localhost>
date:      Mon Jun 20 11:04:15 2005 +0000

description:
pci_device_foreach(), pci_device_foreach_min(), pci_bridge_foreach(), and
pci_bridge_hook don't actually have any dependancies on PCIBIOS-specific code,
and they can be used to fixup PCI bus numbering in the absence of the BIOS.

To that end, decouple them from PCIBIOS.

diffstat:

 sys/arch/i386/pci/pcibios.c        |  96 +------------------------------------
 sys/arch/i386/pci/pcibios.h        |  13 +----
 sys/arch/x86/include/pci_machdep.h |  14 ++++-
 sys/arch/x86/pci/pci_machdep.c     |  99 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 113 insertions(+), 109 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r f88799b726ff -r 05d5d8c10edd sys/arch/i386/pci/pcibios.c
--- a/sys/arch/i386/pci/pcibios.c       Mon Jun 20 10:41:29 2005 +0000
+++ b/sys/arch/i386/pci/pcibios.c       Mon Jun 20 11:04:15 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcibios.c,v 1.22 2005/02/03 21:35:44 perry Exp $       */
+/*     $NetBSD: pcibios.c,v 1.23 2005/06/20 11:04:15 sekiya Exp $      */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcibios.c,v 1.22 2005/02/03 21:35:44 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcibios.c,v 1.23 2005/06/20 11:04:15 sekiya Exp $");
 
 #include "opt_pcibios.h"
 
@@ -144,12 +144,6 @@
 #define        PCI_IRQ_TABLE_START     0xf0000
 #define        PCI_IRQ_TABLE_END       0xfffff
 
-static void pci_bridge_hook(pci_chipset_tag_t, pcitag_t, void *);
-struct pci_bridge_hook_arg {
-       void (*func)(pci_chipset_tag_t, pcitag_t, void *);
-       void *arg;
-};
-
 void
 pcibios_init(void)
 {
@@ -560,92 +554,6 @@
 }
 #endif
 
-void 
-pci_device_foreach(pci_chipset_tag_t pc, int maxbus,
-    void (*func)(pci_chipset_tag_t, pcitag_t, void *), void *context)
-{
-       pci_device_foreach_min(pc, 0, maxbus, func, context);
-}
-
-void
-pci_device_foreach_min(pci_chipset_tag_t pc, int minbus, int maxbus,
-    void (*func)(pci_chipset_tag_t, pcitag_t, void *), void *context)
-{
-       const struct pci_quirkdata *qd;
-       int bus, device, function, maxdevs, nfuncs;
-       pcireg_t id, bhlcr;
-       pcitag_t tag;
-
-       for (bus = minbus; bus <= maxbus; bus++) {
-               maxdevs = pci_bus_maxdevs(pc, bus);
-               for (device = 0; device < maxdevs; device++) {
-                       tag = pci_make_tag(pc, bus, device, 0);
-                       id = pci_conf_read(pc, tag, PCI_ID_REG);
-
-                       /* Invalid vendor ID value? */
-                       if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
-                               continue;
-                       /* XXX Not invalid, but we've done this ~forever. */
-                       if (PCI_VENDOR(id) == 0)
-                               continue;
-
-                       qd = pci_lookup_quirkdata(PCI_VENDOR(id),
-                           PCI_PRODUCT(id));
-
-                       bhlcr = pci_conf_read(pc, tag, PCI_BHLC_REG);
-                       if (PCI_HDRTYPE_MULTIFN(bhlcr) ||
-                           (qd != NULL &&
-                            (qd->quirks & PCI_QUIRK_MULTIFUNCTION) != 0))
-                               nfuncs = 8;
-                       else
-                               nfuncs = 1;
-
-                       for (function = 0; function < nfuncs; function++) {
-                               tag = pci_make_tag(pc, bus, device, function);
-                               id = pci_conf_read(pc, tag, PCI_ID_REG);
-
-                               /* Invalid vendor ID value? */
-                               if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
-                                       continue;
-                               /*
-                                * XXX Not invalid, but we've done this
-                                * ~forever.
-                                */
-                               if (PCI_VENDOR(id) == 0)
-                                       continue;
-                               (*func)(pc, tag, context);
-                       }
-               }
-       }
-}
-
-void
-pci_bridge_foreach(pci_chipset_tag_t pc, int minbus, int maxbus,
-    void (*func)(pci_chipset_tag_t, pcitag_t, void *), void *ctx)
-{
-       struct pci_bridge_hook_arg bridge_hook;
-
-       bridge_hook.func = func;
-       bridge_hook.arg = ctx;
-       
-       pci_device_foreach_min(pc, minbus, maxbus, pci_bridge_hook,
-           &bridge_hook);
-}
-
-void
-pci_bridge_hook(pci_chipset_tag_t pc, pcitag_t tag, void *ctx)
-{
-       struct pci_bridge_hook_arg *bridge_hook = (void *)ctx;
-       pcireg_t reg;
-
-       reg = pci_conf_read(pc, tag, PCI_CLASS_REG);
-       if (PCI_CLASS(reg) == PCI_CLASS_BRIDGE &&
-           (PCI_SUBCLASS(reg) == PCI_SUBCLASS_BRIDGE_PCI ||
-               PCI_SUBCLASS(reg) == PCI_SUBCLASS_BRIDGE_CARDBUS)) {
-               (*bridge_hook->func)(pc, tag, bridge_hook->arg);
-       }
-}
-
 #ifdef PCIBIOS_SHARP_MM20_FIXUP
 /*
  * This is a gross hack to get the interrupt from the EHCI controller
diff -r f88799b726ff -r 05d5d8c10edd sys/arch/i386/pci/pcibios.h
--- a/sys/arch/i386/pci/pcibios.h       Mon Jun 20 10:41:29 2005 +0000
+++ b/sys/arch/i386/pci/pcibios.h       Mon Jun 20 11:04:15 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcibios.h,v 1.7 2004/04/11 06:00:26 kochi Exp $        */
+/*     $NetBSD: pcibios.h,v 1.8 2005/06/20 11:04:15 sekiya Exp $       */
 
 /*
  * Copyright (c) 1999, by UCHIYAMA Yasushi
@@ -89,17 +89,6 @@
 extern int pcibios_pir_table_nentries;
 extern int pcibios_max_bus;
 
-void pci_device_foreach(pci_chipset_tag_t, int,
-                       void (*)(pci_chipset_tag_t, pcitag_t, void*),
-                       void *);
-
-void pci_device_foreach_min(pci_chipset_tag_t, int, int,
-                           void (*)(pci_chipset_tag_t, pcitag_t, void*),
-                           void *);
-
-void pci_bridge_foreach(pci_chipset_tag_t, int, int,
-    void (*) (pci_chipset_tag_t, pcitag_t, void *), void *);
-
 #ifdef PCIBIOSVERBOSE
 extern int pcibiosverbose;
 
diff -r f88799b726ff -r 05d5d8c10edd sys/arch/x86/include/pci_machdep.h
--- a/sys/arch/x86/include/pci_machdep.h        Mon Jun 20 10:41:29 2005 +0000
+++ b/sys/arch/x86/include/pci_machdep.h        Mon Jun 20 11:04:15 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep.h,v 1.5 2005/04/16 07:45:59 yamt Exp $     */
+/*     $NetBSD: pci_machdep.h,v 1.6 2005/06/20 11:04:15 sekiya Exp $   */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -119,4 +119,16 @@
  */
 #define        X86_PCI_INTERRUPT_LINE_NO_CONNECTION    0xff
 
+void pci_device_foreach(pci_chipset_tag_t, int,
+                       void (*)(pci_chipset_tag_t, pcitag_t, void*),
+                       void *);
+        
+void pci_device_foreach_min(pci_chipset_tag_t, int, int,
+                           void (*)(pci_chipset_tag_t, pcitag_t, void*),
+                           void *);
+        
+void pci_bridge_foreach(pci_chipset_tag_t, int, int,
+       void (*) (pci_chipset_tag_t, pcitag_t, void *), void *);
+
+
 #endif /* _X86_PCI_MACHDEP_H_ */
diff -r f88799b726ff -r 05d5d8c10edd sys/arch/x86/pci/pci_machdep.c
--- a/sys/arch/x86/pci/pci_machdep.c    Mon Jun 20 10:41:29 2005 +0000
+++ b/sys/arch/x86/pci/pci_machdep.c    Mon Jun 20 11:04:15 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep.c,v 1.10 2005/04/16 07:53:35 yamt Exp $    */
+/*     $NetBSD: pci_machdep.c,v 1.11 2005/06/20 11:04:15 sekiya Exp $  */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.10 2005/04/16 07:53:35 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.11 2005/06/20 11:04:15 sekiya Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -127,6 +127,13 @@
 
 int pci_mode = -1;
 
+static void pci_bridge_hook(pci_chipset_tag_t, pcitag_t, void *);
+struct pci_bridge_hook_arg {
+       void (*func)(pci_chipset_tag_t, pcitag_t, void *); 
+       void *arg; 
+}; 
+
+
 struct simplelock pci_conf_slock = SIMPLELOCK_INITIALIZER;
 
 #define        PCI_CONF_LOCK(s)                                                \
@@ -723,3 +730,91 @@
            PCI_FLAGS_MWI_OKAY);
        return (rval);
 }
+
+void
+pci_device_foreach(pci_chipset_tag_t pc, int maxbus,
+       void (*func)(pci_chipset_tag_t, pcitag_t, void *), void *context)
+{
+       pci_device_foreach_min(pc, 0, maxbus, func, context);
+}
+
+void
+pci_device_foreach_min(pci_chipset_tag_t pc, int minbus, int maxbus,
+       void (*func)(pci_chipset_tag_t, pcitag_t, void *), void *context)
+{
+       const struct pci_quirkdata *qd;
+       int bus, device, function, maxdevs, nfuncs;
+       pcireg_t id, bhlcr;
+       pcitag_t tag;
+
+       for (bus = minbus; bus <= maxbus; bus++) {
+               maxdevs = pci_bus_maxdevs(pc, bus);
+               for (device = 0; device < maxdevs; device++) {
+                       tag = pci_make_tag(pc, bus, device, 0);
+                       id = pci_conf_read(pc, tag, PCI_ID_REG);
+
+                       /* Invalid vendor ID value? */
+                       if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
+                               continue;
+                       /* XXX Not invalid, but we've done this ~forever. */
+                       if (PCI_VENDOR(id) == 0)
+                               continue;
+
+                       qd = pci_lookup_quirkdata(PCI_VENDOR(id),
+                               PCI_PRODUCT(id));
+
+                       bhlcr = pci_conf_read(pc, tag, PCI_BHLC_REG);
+                       if (PCI_HDRTYPE_MULTIFN(bhlcr) ||
+                            (qd != NULL &&
+                            (qd->quirks & PCI_QUIRK_MULTIFUNCTION) != 0))
+                               nfuncs = 8;
+                       else
+                               nfuncs = 1;
+
+                       for (function = 0; function < nfuncs; function++) {
+                               tag = pci_make_tag(pc, bus, device, function);
+                               id = pci_conf_read(pc, tag, PCI_ID_REG);
+
+                               /* Invalid vendor ID value? */
+                               if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
+                                       continue;
+                               /*
+                                * XXX Not invalid, but we've done this
+                                * ~forever.
+                                */
+                               if (PCI_VENDOR(id) == 0)
+                                       continue;
+                               (*func)(pc, tag, context);
+                       }
+               }
+       }
+}
+
+void
+pci_bridge_foreach(pci_chipset_tag_t pc, int minbus, int maxbus,
+       void (*func)(pci_chipset_tag_t, pcitag_t, void *), void *ctx)
+{
+       struct pci_bridge_hook_arg bridge_hook;
+
+       bridge_hook.func = func;
+       bridge_hook.arg = ctx;  
+
+       pci_device_foreach_min(pc, minbus, maxbus, pci_bridge_hook,
+               &bridge_hook);      
+}
+
+static void
+pci_bridge_hook(pci_chipset_tag_t pc, pcitag_t tag, void *ctx)
+{
+       struct pci_bridge_hook_arg *bridge_hook = (void *)ctx;
+       pcireg_t reg;
+
+       reg = pci_conf_read(pc, tag, PCI_CLASS_REG);
+       if (PCI_CLASS(reg) == PCI_CLASS_BRIDGE &&
+            (PCI_SUBCLASS(reg) == PCI_SUBCLASS_BRIDGE_PCI ||
+               PCI_SUBCLASS(reg) == PCI_SUBCLASS_BRIDGE_CARDBUS)) {
+               (*bridge_hook->func)(pc, tag, bridge_hook->arg);
+       }
+}
+



Home | Main Index | Thread Index | Old Index