Skip to contentSkip to conversation

pci: Enable dm_pci_map_bar() for 64-bit BARs

PATCH Superseded Moritz Fischer 2 participants 2 messages Nov 24, 2023 PCI

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: Enable dm_pci_map_bar() for 64-bit BARs

Allow dm_pci_map_bar() usage on systems with CONFIG_PCI_SYS_64BIT.

---
 drivers/pci/pci-uclass.c | 11 +++++++++++
 include/pci.h            |  4 ++--
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/pci/pci-uclass.c +11 -0
index e0d01f6a85..82308c7477 100644
@@ -1611,6 +1611,17 @@ void *dm_pci_map_bar(struct udevice *dev, int bar, size_t offset, size_t len,
 	dm_pci_read_config32(udev, bar, &bar_response);
 	pci_bus_addr = (pci_addr_t)(bar_response & ~0xf);
 
+	/*
+	 * This assumes that dm_pciauto_setup_device() will allocate
+	 * a 64-bit address if CONFIG_SYS_PCI_64BIT is enabled and
+	 * the device advertises that it supports it.
+	 */
+	if (IS_ENABLED(CONFIG_SYS_PCI_64BIT) &&
+	    (bar_response & PCI_BASE_ADDRESS_MEM_TYPE_64)) {
+		dm_pci_read_config32(udev, bar + 4, &bar_response);
+		pci_bus_addr |= (pci_addr_t)bar_response << 32;
+	}
+
 	if (~((pci_addr_t)0) - pci_bus_addr < offset)
 		return NULL;
 
include/pci.h +2 -2
index 2f5eb30b83..0d1ac7b015 100644
@@ -1350,8 +1350,8 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, size_t len,
  *
  * Looks up a base address register and finds the physical memory address
  * that corresponds to it.
- * Can be used for 32b BARs 0-5 on type 0 functions and for 32b BARs 0-1 on
- * type 1 functions.
+ * Can be used for 32b/64b BARs 0-5 on type 0 functions and for 32b BARs 0-1
+ * on type 1 functions.
  * Can also be used on type 0 functions that support Enhanced Allocation for
  * 32b/64b BARs.  Note that duplicate BEI entries are not supported.
  *
Signature · 1 line
2.43.0.rc1.413.gea7ed67945-goog
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 1 line · Moritz Fischer

Allow dm_pci_map_bar() usage on systems with CONFIG_PCI_SYS_64BIT.

<snip>

drivers/pci/pci-uclass.c void *dm_pci_map_bar(struct udevice *dev, int bar, size_t offset, size_t len, · line 1618

Quoted 6 lines
drivers/pci/pci-uclass.c +5 -0
+	/*
+	 * This assumes that dm_pciauto_setup_device() will allocate
+	 * a 64-bit address if CONFIG_SYS_PCI_64BIT is enabled and
+	 * the device advertises that it supports it.
+	 */

This patch is also useful if the previous bootstage, e.g. coreboot, allocated a 64-bit address. In fact I recently did something very similar (downstream), so

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-22  Fax: +49-8142-66989-80   Email: [email protected]
=====================================================================
Quoted 27 lines
drivers/pci/pci-uclass.c +6 -0
+	if (IS_ENABLED(CONFIG_SYS_PCI_64BIT) &&
+	    (bar_response & PCI_BASE_ADDRESS_MEM_TYPE_64)) {
+		dm_pci_read_config32(udev, bar + 4, &bar_response);
+		pci_bus_addr |= (pci_addr_t)bar_response << 32;
+	}
+
 	if (~((pci_addr_t)0) - pci_bus_addr < offset)
 		return NULL;
include/pci.h +2 -2
index 2f5eb30b83..0d1ac7b015 100644
@@ -1350,8 +1350,8 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, size_t len,
  *
  * Looks up a base address register and finds the physical memory address
  * that corresponds to it.
- * Can be used for 32b BARs 0-5 on type 0 functions and for 32b BARs 0-1 on
- * type 1 functions.
+ * Can be used for 32b/64b BARs 0-5 on type 0 functions and for 32b BARs 0-1
+ * on type 1 functions.
  * Can also be used on type 0 functions that support Enhanced Allocation for
  * 32b/64b BARs.  Note that duplicate BEI entries are not supported.
  *
Signature · 1 line
2.43.0.rc1.413.gea7ed67945-goog