Edward O'Callaghan has uploaded this change for review.
pcidev.c: Simplify by consolidating common logic
BUG=none
TEST=builds
Change-Id: I0048fc6ab816d230ff48c84bc17122431753d55d
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M pcidev.c
M programmer.h
2 files changed, 11 insertions(+), 30 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/81/59281/1
diff --git a/pcidev.c b/pcidev.c
index 721243a..629304a 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -155,26 +155,26 @@
return (uintptr_t)addr;
}
-struct pci_dev *pcidev_scandev(struct pci_filter *filter)
+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))
+ if (pci_filter_match(&filter, temp))
return temp;
return NULL;
}
struct pci_dev *pcidev_find_vendorclass(uint16_t vendor, uint16_t devclass)
{
- struct pci_dev *temp;
- struct pci_filter filter;
- uint16_t tmp2;
-
- pci_filter_init(NULL, &filter);
- filter.vendor = vendor;
-
- temp = pcidev_scandev(&filter);
+ struct pci_dev *temp = pci_dev_find(vendor, 0);
if (temp) {
+ uint16_t tmp2;
/* Read PCI class */
tmp2 = pci_read_word(temp, PCI_CLASS_DEVICE);
if (tmp2 == devclass)
@@ -187,14 +187,7 @@
struct pci_dev *pcidev_card_find(uint16_t vendor, uint16_t device,
uint16_t card_vendor, uint16_t card_device)
{
- struct pci_dev *temp;
- struct pci_filter filter;
-
- pci_filter_init(NULL, &filter);
- filter.vendor = vendor;
- filter.device = device;
-
- temp = pcidev_scandev(&filter);
+ struct pci_dev *temp = pci_dev_find(vendor, device);
if (temp) {
if ((card_vendor == pci_read_word(temp, PCI_SUBSYSTEM_VENDOR_ID))
&& (card_device == pci_read_word(temp, PCI_SUBSYSTEM_ID)))
@@ -204,17 +197,6 @@
return NULL;
}
-struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device)
-{
- struct pci_filter filter;
-
- pci_filter_init(NULL, &filter);
- filter.vendor = vendor;
- filter.device = device;
-
- return pcidev_scandev(&filter);
-}
-
struct pci_dev *pcidev_getdev(struct pci_dev *dev)
{
#if !defined(OLD_PCI_GET_DEV)
diff --git a/programmer.h b/programmer.h
index 3b08f61..b9cd3de 100644
--- a/programmer.h
+++ b/programmer.h
@@ -124,7 +124,6 @@
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);
struct pci_dev *pcidev_find_vendorclass(uint16_t vendor, uint16_t devclass);
struct pci_dev *pcidev_getdev(struct pci_dev *dev);
struct pci_dev *pcidev_card_find(uint16_t vendor, uint16_t device,
To view, visit change 59281. To unsubscribe, or for help writing mail filters, visit settings.