Martijn Berger has uploaded this change for review.

View Change

pcidev: On arm64 we are not getting a valid BAR0 address

It seems that there is some code to work around a possible bug in
old versions of libpci. This trusts libpci if it is new enough

Change-Id: I8bd32c6344b0831a949c3853abeb84905420922a
Signed-off-by: Martijn Berger <martijn.berger@gmail.com>
---
M pcidev.c
M programmer.h
2 files changed, 30 insertions(+), 2 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/65/39965/1
diff --git a/pcidev.c b/pcidev.c
index 54c1fd3..973acde 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -30,20 +30,47 @@
TYPE_UNKNOWN
};

+int pci_bar_nuber_from_offset(int offset)
+{
+ switch (offset) {
+ case PCI_BASE_ADDRESS_0:
+ return 0;
+ case PCI_BASE_ADDRESS_1:
+ return 1;
+ case PCI_BASE_ADDRESS_2:
+ return 2;
+ case PCI_BASE_ADDRESS_3:
+ return 3;
+ case PCI_BASE_ADDRESS_4:
+ return 4;
+ case PCI_BASE_ADDRESS_5:
+ return 5;
+ default:
+ return -1;
+ }
+ return -1;
+}
+
uintptr_t pcidev_readbar(struct pci_dev *dev, int bar)
{
uint64_t addr;
uint32_t upperaddr;
uint8_t headertype;
uint16_t supported_cycles;
+ int bar_number;
enum pci_bartype bartype = TYPE_UNKNOWN;


headertype = pci_read_byte(dev, PCI_HEADER_TYPE) & 0x7f;
msg_pspew("PCI header type 0x%02x\n", headertype);
+ bar_number = pci_bar_nuber_from_offset(bar);

- /* Don't use dev->base_addr[x] (as value for 'bar'), won't work on older libpci. */
- addr = pci_read_long(dev, bar);
+ if (PCI_LIB_VERSION >= 0x030500 && bar_number > -1) {
+ addr = dev->base_addr[bar_number];
+ } else {
+ /* Don't use dev->base_addr[x] (as value for 'bar'), won't work on older libpci. */
+ addr = pci_read_long(dev, bar);
+ }

/* Sanity checks. */
switch (headertype) {
diff --git a/programmer.h b/programmer.h
index 9a41be1..5d4c1d7 100644
--- a/programmer.h
+++ b/programmer.h
@@ -190,6 +190,7 @@
// FIXME: This needs to be local, not global(?)
extern struct pci_access *pacc;
int pci_init_common(void);
+int pci_bar_nuber_from_offset(int offset);
uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
/* rpci_write_* are reversible writes. The original PCI config space register

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I8bd32c6344b0831a949c3853abeb84905420922a
Gerrit-Change-Number: 39965
Gerrit-PatchSet: 1
Gerrit-Owner: Martijn Berger
Gerrit-MessageType: newchange