From: Pali Rohár Date: Thu, 18 May 2023 19:40:44 +0000 (+0200) Subject: libpci: ecam: Cache ACPI MCFG table between detect() and init() phase X-Git-Tag: v3.11.0~13 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=e4517524ca872caa5e89d7df50cd91aac476b7be;p=pciutils.git libpci: ecam: Cache ACPI MCFG table between detect() and init() phase This will speed up listing devices by lspci as it is not needed to scan BIOS memory two times. --- diff --git a/lib/ecam.c b/lib/ecam.c index 7c68816..f088c0c 100644 --- a/lib/ecam.c +++ b/lib/ecam.c @@ -898,10 +898,6 @@ ecam_detect(struct pci_access *a) a->backend_data = NULL; return 0; } - pci_mfree(eacc->mcfg); - physmem_close(eacc->physmem); - pci_mfree(eacc); - a->backend_data = NULL; } if (use_addrs) @@ -925,7 +921,7 @@ ecam_init(struct pci_access *a) #endif const char *addrs = pci_get_param(a, "ecam.addrs"); struct physmem *physmem = NULL; - struct ecam_access *eacc = NULL; + struct ecam_access *eacc = a->backend_data; long pagesize = 0; int use_bsd = 0; int use_x86bios = 0; @@ -936,20 +932,23 @@ ecam_init(struct pci_access *a) if (!validate_addrs(addrs)) a->error("Option ecam.addrs has invalid address format \"%s\".", addrs); - physmem = physmem_open(a, a->writeable); - if (!physmem) - a->error("Cannot open physcal memory: %s.", strerror(errno)); + if (!eacc) + { + physmem = physmem_open(a, a->writeable); + if (!physmem) + a->error("Cannot open physcal memory: %s.", strerror(errno)); - pagesize = physmem_get_pagesize(physmem); - if (pagesize <= 0) - a->error("Cannot get page size: %s.", strerror(errno)); + pagesize = physmem_get_pagesize(physmem); + if (pagesize <= 0) + a->error("Cannot get page size: %s.", strerror(errno)); - eacc = pci_malloc(a, sizeof(*eacc)); - eacc->mcfg = NULL; - eacc->cache = NULL; - eacc->physmem = physmem; - eacc->pagesize = pagesize; - a->backend_data = eacc; + eacc = pci_malloc(a, sizeof(*eacc)); + eacc->mcfg = NULL; + eacc->cache = NULL; + eacc->physmem = physmem; + eacc->pagesize = pagesize; + a->backend_data = eacc; + } if (!*addrs) { @@ -961,7 +960,8 @@ ecam_init(struct pci_access *a) if (strcmp(x86bios, "0") != 0) use_x86bios = 1; #endif - eacc->mcfg = find_mcfg(a, acpimcfg, efisystab, use_bsd, use_x86bios); + if (!eacc->mcfg) + eacc->mcfg = find_mcfg(a, acpimcfg, efisystab, use_bsd, use_x86bios); if (!eacc->mcfg) a->error("Option ecam.addrs was not specified and ACPI MCFG table cannot be found."); }