From: Martin Mares Date: Sat, 17 Mar 2018 15:28:15 +0000 (+0100) Subject: Introduced an explicit probe sequence X-Git-Tag: v3.6.0~21 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fpciutils.git;a=commitdiff_plain;h=59cfe93d27db4603f5149351b9eb5d90a14f55a9 Introduced an explicit probe sequence 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. --- diff --git a/lib/init.c b/lib/init.c index c7800e0..abd4fd8 100644 --- a/lib/init.c +++ b/lib/init.c @@ -1,7 +1,7 @@ /* * The PCI Library -- Initialization and related things * - * Copyright (c) 1997--2008 Martin Mares + * Copyright (c) 1997--2018 Martin Mares * * 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; idebug("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."); } diff --git a/lib/pci.h b/lib/pci.h index 81bdab3..0f96101 100644 --- 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 */