Edward O'Callaghan has uploaded this change for review.

View Change

pcidev: Avoid internal relying on pacc global

Make progress towards the goal of removing pacc from global
state as noted in the FIXME of programmer.h

BUG=none
TEST=builds

Change-Id: Id83bfd41f785f907e52a65a6689e8c7016fc1b77
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M internal.c
M pcidev.c
M programmer.h
3 files changed, 25 insertions(+), 21 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/75/59275/1
diff --git a/internal.c b/internal.c
index 43bed9e..95ad5a4 100644
--- a/internal.c
+++ b/internal.c
@@ -38,31 +38,26 @@
pci_filter_init(NULL, &filter);
filter.vendor = vendor;

- for (temp = pacc->devices; temp; temp = temp->next)
- if (pci_filter_match(&filter, temp)) {
- /* Read PCI class */
- tmp2 = pci_read_word(temp, 0x0a);
- if (tmp2 == devclass)
- return temp;
- }
+ temp = pcidev_scandev(&filter);
+ if (temp) {
+ /* Read PCI class */
+ tmp2 = pci_read_word(temp, 0x0a);
+ if (tmp2 == devclass)
+ return temp;
+ }

return NULL;
}

struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device)
{
- struct pci_dev *temp;
struct pci_filter filter;

pci_filter_init(NULL, &filter);
filter.vendor = vendor;
filter.device = device;

- for (temp = pacc->devices; temp; temp = temp->next)
- if (pci_filter_match(&filter, temp))
- return temp;
-
- return NULL;
+ return pcidev_scandev(&filter);
}

struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
@@ -75,14 +70,12 @@
filter.vendor = vendor;
filter.device = device;

- for (temp = pacc->devices; temp; temp = temp->next)
- if (pci_filter_match(&filter, temp)) {
- if ((card_vendor ==
- pci_read_word(temp, PCI_SUBSYSTEM_VENDOR_ID))
- && (card_device ==
- pci_read_word(temp, PCI_SUBSYSTEM_ID)))
- return temp;
- }
+ temp = pcidev_scandev(&filter);
+ if (temp) {
+ if ((card_vendor == pci_read_word(temp, PCI_SUBSYSTEM_VENDOR_ID))
+ && (card_device == pci_read_word(temp, PCI_SUBSYSTEM_ID)))
+ return temp;
+ }

return NULL;
}
diff --git a/pcidev.c b/pcidev.c
index 9ffe05c..32c6d30 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -148,6 +148,15 @@
return (uintptr_t)addr;
}

+struct pci_dev *pcidev_scandev(struct pci_filter *filter)
+{
+ struct pci_dev *temp;
+ for (temp = pacc->devices; temp; temp = temp->next)
+ if (pci_filter_match(filter, temp))
+ return temp;
+ return NULL;
+}
+
static int pcidev_shutdown(void *data)
{
if (pacc == NULL) {
diff --git a/programmer.h b/programmer.h
index ec9503c..d6de7bc 100644
--- a/programmer.h
+++ b/programmer.h
@@ -116,6 +116,7 @@

#if NEED_PCI == 1
struct pci_dev;
+struct pci_filter;

/* pcidev.c */
// FIXME: This needs to be local, not global(?)
@@ -123,6 +124,7 @@
int pci_init_common(void);
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);
/* 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 59275. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id83bfd41f785f907e52a65a6689e8c7016fc1b77
Gerrit-Change-Number: 59275
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange