]> git.ipfire.org Git - thirdparty/pciutils.git/commitdiff
Introduced an explicit probe sequence
authorMartin Mares <mj@ucw.cz>
Sat, 17 Mar 2018 15:28:15 +0000 (16:28 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 17 Mar 2018 15:28:15 +0000 (16:28 +0100)
Previously, the probe order was determined by the order of back-ends.
However, new back-ends must be always added at the end of the list
to maintain ABI compatibility, so they were always probed last.

lib/init.c
lib/pci.h

index c7800e06927e1164dc03903fb557815828a273cd..abd4fd859be22f917caa949b84193d3999f8e060 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     The PCI Library -- Initialization and related things
  *
- *     Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 1997--2018 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -64,6 +64,22 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {
 #endif
 };
 
+// If PCI_ACCESS_AUTO is selected, we probe the access methods in this order
+static int probe_sequence[] = {
+  // System-specific methods
+  PCI_ACCESS_SYS_BUS_PCI,
+  PCI_ACCESS_PROC_BUS_PCI,
+  PCI_ACCESS_FBSD_DEVICE,
+  PCI_ACCESS_AIX_DEVICE,
+  PCI_ACCESS_NBSD_LIBPCI,
+  PCI_ACCESS_OBSD_DEVICE,
+  PCI_ACCESS_DARWIN,
+  // Low-level methods poking the hardware directly
+  PCI_ACCESS_I386_TYPE1,
+  PCI_ACCESS_I386_TYPE2,
+  -1,
+};
+
 void *
 pci_malloc(struct pci_access *a, int size)
 {
@@ -193,19 +209,21 @@ pci_init_v35(struct pci_access *a)
   else
     {
       unsigned int i;
-      for (i=0; i<PCI_ACCESS_MAX; i++)
-       if (pci_methods[i])
-         {
-           a->debug("Trying method %d...", i);
-           if (pci_methods[i]->detect(a))
-             {
-               a->debug("...OK\n");
-               a->methods = pci_methods[i];
-               a->method = i;
-               break;
-             }
-           a->debug("...No.\n");
-         }
+      for (i=0; probe_sequence[i] >= 0; i++)
+       {
+         struct pci_methods *m = pci_methods[probe_sequence[i]];
+         if (!m)
+           continue;
+         a->debug("Trying method %s...", m->name);
+         if (m->detect(a))
+           {
+             a->debug("...OK\n");
+             a->methods = m;
+             a->method = probe_sequence[i];
+             break;
+           }
+         a->debug("...No.\n");
+       }
       if (!a->methods)
        a->error("Cannot find any working access method.");
     }
index 81bdab372f4200494970714e60ddd8e1aa262420..0f96101da8aeeaec4ab9aaf659cf1b514c924f10 100644 (file)
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -29,7 +29,7 @@
 struct pci_methods;
 
 enum pci_access_type {
-  /* Known access methods, remember to update access.c as well */
+  /* Known access methods, remember to update init.c as well */
   PCI_ACCESS_AUTO,                     /* Autodetection */
   PCI_ACCESS_SYS_BUS_PCI,              /* Linux /sys/bus/pci */
   PCI_ACCESS_PROC_BUS_PCI,             /* Linux /proc/bus/pci */