]> mj.ucw.cz Git - pciutils.git/commitdiff
libpci: ecam: Fix detect sequence when addresses are not specified
authorPali Rohár <pali@kernel.org>
Mon, 8 May 2023 19:25:36 +0000 (21:25 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 18 Feb 2024 15:18:43 +0000 (16:18 +0100)
Search for ACPI MCFG table in detect sequence, so on failure we can move to
the next pci access method.

lib/ecam.c

index cb479c6b8fc833aa954287e0955b08fdcc7a0ac9..7c688169548f0742dbca607025b6a969a60dc29c 100644 (file)
@@ -790,6 +790,7 @@ ecam_detect(struct pci_access *a)
   const char *x86bios = pci_get_param(a, "ecam.x86bios");
 #endif
   const char *addrs = pci_get_param(a, "ecam.addrs");
+  struct ecam_access *eacc;
   glob_t mcfg_glob;
   int ret;
 
@@ -865,6 +866,44 @@ ecam_detect(struct pci_access *a)
       return 0;
     }
 
+  if (!use_addrs)
+    {
+      eacc = pci_malloc(a, sizeof(*eacc));
+
+      eacc->physmem = physmem_open(a, a->writeable);
+      if (!eacc->physmem)
+        {
+          a->debug("cannot open physcal memory: %s.", strerror(errno));
+          pci_mfree(eacc);
+          return 0;
+        }
+
+      eacc->pagesize = physmem_get_pagesize(eacc->physmem);
+      if (eacc->pagesize <= 0)
+        {
+          a->debug("Cannot get page size: %s.", strerror(errno));
+          physmem_close(eacc->physmem);
+          pci_mfree(eacc);
+          return 0;
+        }
+
+      eacc->mcfg = NULL;
+      eacc->cache = NULL;
+      a->backend_data = eacc;
+      eacc->mcfg = find_mcfg(a, acpimcfg, efisystab, use_bsd, use_x86bios);
+      if (!eacc->mcfg)
+        {
+          physmem_close(eacc->physmem);
+          pci_mfree(eacc);
+          a->backend_data = NULL;
+          return 0;
+        }
+      pci_mfree(eacc->mcfg);
+      physmem_close(eacc->physmem);
+      pci_mfree(eacc);
+      a->backend_data = NULL;
+    }
+
   if (use_addrs)
     a->debug("using with ecam addresses %s", addrs);
   else