Edward O'Callaghan submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Subrata Banik: Looks good to me, approved
pcidev: Move pci_get_dev() logic into canonical place

BUG=b:220950271
TEST=```sudo ./flashrom -p internal --flash-size
<snip>
Found Programmer flash chip "Opaque flash chip" (16384 kB, Programmer-specific) mapped at physical address 0x0000000000000000.
16777216
```

Change-Id: Id9ce055d5e5d347520ec5002b8c6548e60eaa0a7
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/59276
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Subrata Banik <subratabanik@google.com>
---
M board_enable.c
M pcidev.c
M programmer.h
3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/board_enable.c b/board_enable.c
index 94cfc9d..194357a 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -1094,15 +1094,7 @@
return -1;
}

-#if !defined(OLD_PCI_GET_DEV)
- dev = pci_get_dev(pacc, dev->domain, dev->bus, dev->dev, 1);
-#else
- /* pciutils/libpci before version 2.2 is too old to support
- * PCI domains. Such old machines usually don't have domains
- * besides domain 0, so this is not a problem.
- */
- dev = pci_get_dev(pacc, dev->bus, dev->dev, 1);
-#endif
+ dev = pcidev_getdevfn(dev, 1);
if (!dev) {
msg_perr("MCP SMBus controller could not be found\n");
return -1;
diff --git a/pcidev.c b/pcidev.c
index f323851..0f8c4e5 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -157,6 +157,19 @@
return NULL;
}

+struct pci_dev *pcidev_getdevfn(struct pci_dev *dev, const int func)
+{
+#if !defined(OLD_PCI_GET_DEV)
+ return pci_get_dev(pacc, dev->domain, dev->bus, dev->dev, func);
+#else
+ /* pciutils/libpci before version 2.2 is too old to support
+ * PCI domains. Such old machines usually don't have domains
+ * besides domain 0, so this is not a problem.
+ */
+ return pci_get_dev(pacc, dev->bus, dev->dev, func);
+#endif
+}
+
static int pcidev_shutdown(void *data)
{
if (pacc == NULL) {
diff --git a/programmer.h b/programmer.h
index 4024966..d0e86a4 100644
--- a/programmer.h
+++ b/programmer.h
@@ -126,6 +126,7 @@
uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
struct pci_dev *pcidev_scandev(struct pci_filter *filter, struct pci_dev *start);
+struct pci_dev *pcidev_getdevfn(struct pci_dev *dev, const int func);
/* rpci_write_* are reversible writes. The original PCI config space register
* contents will be restored on shutdown.
* To clone the pci_dev instances internally, the `pacc` global

To view, visit change 59276. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id9ce055d5e5d347520ec5002b8c6548e60eaa0a7
Gerrit-Change-Number: 59276
Gerrit-PatchSet: 6
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Peter Marheine <pmarheine@chromium.org>
Gerrit-Reviewer: Subrata Banik <subratabanik@google.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-CC: Thomas Heijligen <src@posteo.de>
Gerrit-MessageType: merged