Skip to contentSkip to conversation

ARM: arbitrary virtual-physical mappings for RPi4 XHCI support

RFC PATCH Superseded Marek Szyprowski 2 participants 11 messages May 18, 2020 – May 25, 2020 1 message not in the archive

Subsystems (5)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20200518131814eucas1p18b2f895c127708ac6b55b033fb7a43d2@eucas1p1.samsung.com

#1 lore raw

v3 cover ARM: arbitrary virtual-physical mappings for RPi4 XHCI support

Hi All,

This patchset add support for creating a mapping for the arbitrary physical address at the given virtual address. This is needed to enable support for XHCI USB controller on PCIe bridge on Raspberry Pi 4 board, on which the USB controller's MMIO area 0x600000000 has to be remapped somewhere to fit in 4GiB virtual address space when running in ARM 32bit mode.

This patchset is a continuation of the Raspberry Pi 4 XHCI/PCIe patchset:
https://patchwork.ozlabs.org/project/uboot/list/?series=176453
and the following discussion:
https://lists.denx.de/pipermail/u-boot/2020-May/411086.html

Best regards
Marek Szyprowski
Samsung R&D Institute Poland

Changelog:

v3:
- fixed broken RPi3 and lack of the identity mapping for map_physmem (for example for the itest command was broken)
- added a patch fixing a new build warning

v2: https://lists.denx.de/pipermail/u-boot/2020-May/411765.html
- fixed ARM64 build

v1: https://lists.denx.de/pipermail/u-boot/2020-May/411765.html
- initial RFC

Patch summary:

Marek Szyprowski (2):
arm: provide a function for boards init code to modify MMU
virtual-physical map
rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM

    32bit)

Seung-Woo Kim (1):
mmc: bcm283x: fix int to pointer cast

 arch/arm/include/asm/mmu.h                |  8 ++++++++
 arch/arm/include/asm/system.h             | 11 +++++++++++
 arch/arm/lib/cache-cp15.c                 | 24 ++++++++++++++++++------
 arch/arm/mach-bcm283x/Kconfig             |  1 +
 arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
 arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
 drivers/mmc/bcm2835_sdhci.c               |  2 +-
 include/configs/rpi.h                     |  7 +++++++
 8 files changed, 74 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm/include/asm/mmu.h
Signature · 1 line
1.9.1
#2 lore raw

RFC PATCH v3 1/3 arm: provide a function for boards init code to modify MMU virtual-physical map

Provide a function for setting arbitrary virtual-physical MMU mapping for the given region.

---
 arch/arm/include/asm/mmu.h    |  8 ++++++++
 arch/arm/include/asm/system.h | 11 +++++++++++
 arch/arm/lib/cache-cp15.c     | 24 ++++++++++++++++++------
 3 files changed, 37 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm/include/asm/mmu.h
arch/arm/include/asm/mmu.h new file +8 -0
new file mode 100644
index 0000000..fe3d793
@@ -0,0 +1,8 @@
+#ifndef __ASM_ARM_MMU_H
+#define __ASM_ARM_MMU_H
+
+#ifdef CONFIG_ADDR_MAP
+extern void init_addr_map(void);
+#endif
+
+#endif
arch/arm/include/asm/system.h +11 -0
index 81ccead..5b9f31c 100644
@@ -573,6 +573,17 @@ s32 psci_features(u32 function_id, u32 psci_fid);
 void save_boot_params_ret(void);
 
 /**
+ * Change the virt/phys mapping and cache settings for a region.
+ *
+ * \param virt		virtual start address of memory region to change
+ * \param phys		physical address for the memory region to set
+ * \param size		size of memory region to change
+ * \param option	dcache option to select
+ */
+void mmu_set_region_dcache_behaviour_phys(phys_addr_t virt, phys_addr_t phys,
+					size_t size, enum dcache_option option);
+
+/**
  * Change the cache settings for a region.
  *
  * \param start		start address of memory region to change
arch/arm/lib/cache-cp15.c +18 -6
index f8d2096..84ddad3 100644
@@ -24,7 +24,8 @@ __weak void arm_init_domains(void)
 {
 }
 
-void set_section_dcache(int section, enum dcache_option option)
+static void set_section_phys(int section, phys_addr_t phys,
+			     enum dcache_option option)
 {
 #ifdef CONFIG_ARMV7_LPAE
 	u64 *page_table = (u64 *)gd->arch.tlb_addr;
@@ -36,7 +37,7 @@ void set_section_dcache(int section, enum dcache_option option)
 #endif
 
 	/* Add the page offset */
-	value |= ((u32)section << MMU_SECTION_SHIFT);
+	value |= phys;
 
 	/* Add caching bits */
 	value |= option;
@@ -45,13 +46,18 @@ void set_section_dcache(int section, enum dcache_option option)
 	page_table[section] = value;
 }
 
+void set_section_dcache(int section, enum dcache_option option)
+{
+	set_section_phys(section, (u32)section << MMU_SECTION_SHIFT, option);
+}
+
 __weak void mmu_page_table_flush(unsigned long start, unsigned long stop)
 {
 	debug("%s: Warning: not implemented\n", __func__);
 }
 
-void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
-				     enum dcache_option option)
+void mmu_set_region_dcache_behaviour_phys(phys_addr_t start, phys_addr_t phys,
+					size_t size, enum dcache_option option)
 {
 #ifdef CONFIG_ARMV7_LPAE
 	u64 *page_table = (u64 *)gd->arch.tlb_addr;
@@ -70,8 +76,8 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
 	debug("%s: start=%pa, size=%zu, option=0x%x\n", __func__, &start, size,
 	      option);
 #endif
-	for (upto = start; upto < end; upto++)
-		set_section_dcache(upto, option);
+	for (upto = start; upto < end; upto++, phys += MMU_SECTION_SIZE)
+		set_section_phys(upto, phys, option);
 
 	/*
 	 * Make sure range is cache line aligned
@@ -86,6 +92,12 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
 	mmu_page_table_flush(startpt, stoppt);
 }
 
+void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
+				     enum dcache_option option)
+{
+	mmu_set_region_dcache_behaviour_phys(start, start, size, option);
+}
+
 __weak void dram_bank_mmu_setup(int bank)
 {
 	bd_t *bd = gd->bd;
Signature · 1 line
1.9.1
#3 lore raw

RFC PATCH v3 2/3 mmc: bcm283x: fix int to pointer cast

In reply to Marek Szyprowski

From: Seung-Woo Kim <[email protected]>

On build with 32 bit, there is a warning for int-to-pointer-cast. Fix the int to pointer cast by using uintptr_t.

---
 drivers/mmc/bcm2835_sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/bcm2835_sdhci.c +1 -1
index 39c93db..c31f099 100644
@@ -209,7 +209,7 @@ static int bcm2835_sdhci_probe(struct udevice *dev)
 	priv->last_write = 0;
 
 	host->name = dev->name;
-	host->ioaddr = (void *)base;
+	host->ioaddr = (void *)(uintptr_t)base;
 	host->quirks = SDHCI_QUIRK_BROKEN_VOLTAGE | SDHCI_QUIRK_BROKEN_R1B |
 		SDHCI_QUIRK_WAIT_SEND_CMD | SDHCI_QUIRK_NO_HISPD_BIT;
 	host->max_clk = emmc_freq;
Signature · 1 line
1.9.1
#4 lore raw

RFC PATCH v3 3/3 rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM 32bit)

In reply to Marek Szyprowski

Create a non-cacheable mapping for the 0x600000000 physical memory region, where MMIO registers for the PCIe XHCI controller are instantiated by the PCIe bridge. Due to 32bit limit in the CPU virtual address space in ARM 32bit mode, this region is mapped at 0xff800000 CPU virtual address.

---
 arch/arm/mach-bcm283x/Kconfig             |  1 +
 arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
 arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
 include/configs/rpi.h                     |  7 +++++++
 4 files changed, 36 insertions(+)
arch/arm/mach-bcm283x/Kconfig +1 -0
index 00419bf..bcb7f1d 100644
@@ -36,6 +36,7 @@ config BCM2711_32B
 	select BCM2711
 	select ARMV7_LPAE
 	select CPU_V7A
+	select PHYS_64BIT
 
 config BCM2711_64B
 	bool "Broadcom BCM2711 SoC 64-bit support"
arch/arm/mach-bcm283x/include/mach/base.h +8 -0
index c4ae398..4ccaf69 100644
@@ -8,4 +8,12 @@
 
 extern unsigned long rpi_bcm283x_base;
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#include <addr_map.h>
+#define phys_to_virt addrmap_phys_to_virt
+#define virt_to_phys addrmap_virt_to_phys
+#endif
+#endif
+
 #endif
arch/arm/mach-bcm283x/init.c +20 -0
index 9f5bca3..008b312 100644
@@ -145,6 +145,26 @@ int mach_cpu_init(void)
 }
 
 #ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT	0xff800000UL
+#include <addr_map.h>
+
+void init_addr_map(void)
+{
+	mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+					     BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+					     BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
+					     DCACHE_OFF);
+
+	/* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+	addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
+	/* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+	addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+			  BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+			  BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
+}
+#endif
+
 void enable_caches(void)
 {
 	dcache_enable();
include/configs/rpi.h +7 -0
index b53a4b6..296e8ee 100644
@@ -63,6 +63,13 @@
 #define CONFIG_SYS_BOOTM_LEN		SZ_64M
 #endif
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define CONFIG_ADDR_MAP 1
+#define CONFIG_SYS_NUM_ADDR_MAP 2
+#endif
+#endif
+
 /* Devices */
 /* GPIO */
 #define CONFIG_BCM2835_GPIO
Signature · 1 line
1.9.1
#5 lore raw

RFC PATCH v3 3/3 rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM 32bit)

Hi Marek,

Quoted 79 lines · Marek Szyprowski

Create a non-cacheable mapping for the 0x600000000 physical memory region, where MMIO registers for the PCIe XHCI controller are instantiated by the PCIe bridge. Due to 32bit limit in the CPU virtual address space in ARM 32bit mode, this region is mapped at 0xff800000 CPU virtual address.

---
 arch/arm/mach-bcm283x/Kconfig             |  1 +
 arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
 arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
 include/configs/rpi.h                     |  7 +++++++
 4 files changed, 36 insertions(+)
arch/arm/mach-bcm283x/Kconfig +1 -0
index 00419bf..bcb7f1d 100644
@@ -36,6 +36,7 @@ config BCM2711_32B
        select BCM2711
        select ARMV7_LPAE
        select CPU_V7A
+       select PHYS_64BIT
 
 config BCM2711_64B
        bool "Broadcom BCM2711 SoC 64-bit support"
arch/arm/mach-bcm283x/include/mach/base.h +8 -0
index c4ae398..4ccaf69 100644
@@ -8,4 +8,12 @@
 
 extern unsigned long rpi_bcm283x_base;
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#include <addr_map.h>
+#define phys_to_virt addrmap_phys_to_virt
+#define virt_to_phys addrmap_virt_to_phys
+#endif
+#endif
+
 #endif
arch/arm/mach-bcm283x/init.c +20 -0
index 9f5bca3..008b312 100644
@@ -145,6 +145,26 @@ int mach_cpu_init(void)
 }
 
 #ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT       0xff800000UL
+#include <addr_map.h>
+
+void init_addr_map(void)
+{
+       mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
+                                            DCACHE_OFF);
+
+       /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
+       /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
+}
+#endif
+
 void enable_caches(void)
 {
        dcache_enable();
include/configs/rpi.h +0 -0
index b53a4b6..296e8ee 100644

include/configs/rpi.h line 71

Quoted 9 lines
include/configs/rpi.h +6 -0
@@ -63,6 +63,13 @@
 #define CONFIG_SYS_BOOTM_LEN           SZ_64M
 #endif
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define CONFIG_ADDR_MAP 1
+#define CONFIG_SYS_NUM_ADDR_MAP 2
+#endif
+#endif

We should be removing things from the config files. Can you move this to devicetree or Kconfig?

Quoted 7 lines
include/configs/rpi.h +1 -1
+
 /* Devices */
 /* GPIO */
 #define CONFIG_BCM2835_GPIO
--

1.9.1

Regards,
Simon

#6 lore raw

RFC PATCH v3 3/3 rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM 32bit)

Hi Simon,

Quoted 82 lines · Simon Glass
Quoted 81 lines · Marek Szyprowski

Create a non-cacheable mapping for the 0x600000000 physical memory region, where MMIO registers for the PCIe XHCI controller are instantiated by the PCIe bridge. Due to 32bit limit in the CPU virtual address space in ARM 32bit mode, this region is mapped at 0xff800000 CPU virtual address.

---
  arch/arm/mach-bcm283x/Kconfig             |  1 +
  arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
  arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
  include/configs/rpi.h                     |  7 +++++++
  4 files changed, 36 insertions(+)
arch/arm/mach-bcm283x/Kconfig +1 -0
index 00419bf..bcb7f1d 100644
@@ -36,6 +36,7 @@ config BCM2711_32B
         select BCM2711
         select ARMV7_LPAE
         select CPU_V7A
+       select PHYS_64BIT
 
  config BCM2711_64B
         bool "Broadcom BCM2711 SoC 64-bit support"
arch/arm/mach-bcm283x/include/mach/base.h +8 -0
index c4ae398..4ccaf69 100644
@@ -8,4 +8,12 @@
 
  extern unsigned long rpi_bcm283x_base;
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#include <addr_map.h>
+#define phys_to_virt addrmap_phys_to_virt
+#define virt_to_phys addrmap_virt_to_phys
+#endif
+#endif
+
  #endif
arch/arm/mach-bcm283x/init.c +20 -0
index 9f5bca3..008b312 100644
@@ -145,6 +145,26 @@ int mach_cpu_init(void)
  }
 
  #ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT       0xff800000UL
+#include <addr_map.h>
+
+void init_addr_map(void)
+{
+       mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
+                                            DCACHE_OFF);
+
+       /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
+       /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
+}
+#endif
+
  void enable_caches(void)
  {
         dcache_enable();
include/configs/rpi.h +0 -0
index b53a4b6..296e8ee 100644
@@ -63,6 +63,13 @@
  #define CONFIG_SYS_BOOTM_LEN           SZ_64M
  #endif
 
Quoted 8 lines

include/configs/rpi.h line 71

Quoted 6 lines
include/configs/rpi.h +6 -0
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define CONFIG_ADDR_MAP 1
+#define CONFIG_SYS_NUM_ADDR_MAP 2
+#endif
+#endif

We should be removing things from the config files. Can you move this to devicetree or Kconfig?

I can move them to Kconfig, no problem. However I would like to get some comments if the approach I presented in this patchset is fine.

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#7 lore raw

RFC PATCH v3 3/3 rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM 32bit)

Hi Marek,

Quoted 95 lines · Marek Szyprowski

Hi Simon,

Quoted 82 lines · Simon Glass
Quoted 81 lines · Marek Szyprowski

Create a non-cacheable mapping for the 0x600000000 physical memory region, where MMIO registers for the PCIe XHCI controller are instantiated by the PCIe bridge. Due to 32bit limit in the CPU virtual address space in ARM 32bit mode, this region is mapped at 0xff800000 CPU virtual address.

---
  arch/arm/mach-bcm283x/Kconfig             |  1 +
  arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
  arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
  include/configs/rpi.h                     |  7 +++++++
  4 files changed, 36 insertions(+)
arch/arm/mach-bcm283x/Kconfig +1 -0
index 00419bf..bcb7f1d 100644
@@ -36,6 +36,7 @@ config BCM2711_32B
         select BCM2711
         select ARMV7_LPAE
         select CPU_V7A
+       select PHYS_64BIT
 
  config BCM2711_64B
         bool "Broadcom BCM2711 SoC 64-bit support"
arch/arm/mach-bcm283x/include/mach/base.h +8 -0
index c4ae398..4ccaf69 100644
@@ -8,4 +8,12 @@
 
  extern unsigned long rpi_bcm283x_base;
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#include <addr_map.h>
+#define phys_to_virt addrmap_phys_to_virt
+#define virt_to_phys addrmap_virt_to_phys
+#endif
+#endif
+
  #endif
arch/arm/mach-bcm283x/init.c +20 -0
index 9f5bca3..008b312 100644
@@ -145,6 +145,26 @@ int mach_cpu_init(void)
  }
 
  #ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT       0xff800000UL
+#include <addr_map.h>
+
+void init_addr_map(void)
+{
+       mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
+                                            DCACHE_OFF);
+
+       /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
+       /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
+}
+#endif
+
  void enable_caches(void)
  {
         dcache_enable();
include/configs/rpi.h +0 -0
index b53a4b6..296e8ee 100644
@@ -63,6 +63,13 @@
  #define CONFIG_SYS_BOOTM_LEN           SZ_64M
  #endif
 
Quoted 8 lines

include/configs/rpi.h line 71

Quoted 6 lines
include/configs/rpi.h +6 -0
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define CONFIG_ADDR_MAP 1
+#define CONFIG_SYS_NUM_ADDR_MAP 2
+#endif
+#endif

We should be removing things from the config files. Can you move this to devicetree or Kconfig?

Quoted 2 lines

I can move them to Kconfig, no problem. However I would like to get some comments if the approach I presented in this patchset is fine.

Yes, no problem.

I suspect we may need to expand the DMA drivers, perhaps, or some other way to map memory on a per-device basis using driver model.

Regards,
SImon

#8 lore raw

RFC PATCH v3 3/3 rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM 32bit)

Hi Simon,

Quoted 92 lines · Simon Glass
Quoted 91 lines · Marek Szyprowski
Quoted 90 lines · Simon Glass
Quoted 78 lines · Marek Szyprowski

Create a non-cacheable mapping for the 0x600000000 physical memory region, where MMIO registers for the PCIe XHCI controller are instantiated by the PCIe bridge. Due to 32bit limit in the CPU virtual address space in ARM 32bit mode, this region is mapped at 0xff800000 CPU virtual address.

---
   arch/arm/mach-bcm283x/Kconfig             |  1 +
   arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
   arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
   include/configs/rpi.h                     |  7 +++++++
   4 files changed, 36 insertions(+)
arch/arm/mach-bcm283x/Kconfig +1 -0
index 00419bf..bcb7f1d 100644
@@ -36,6 +36,7 @@ config BCM2711_32B
          select BCM2711
          select ARMV7_LPAE
          select CPU_V7A
+       select PHYS_64BIT
 
   config BCM2711_64B
          bool "Broadcom BCM2711 SoC 64-bit support"
arch/arm/mach-bcm283x/include/mach/base.h +8 -0
index c4ae398..4ccaf69 100644
@@ -8,4 +8,12 @@
 
   extern unsigned long rpi_bcm283x_base;
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#include <addr_map.h>
+#define phys_to_virt addrmap_phys_to_virt
+#define virt_to_phys addrmap_virt_to_phys
+#endif
+#endif
+
   #endif
arch/arm/mach-bcm283x/init.c +20 -0
index 9f5bca3..008b312 100644
@@ -145,6 +145,26 @@ int mach_cpu_init(void)
   }
 
   #ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT       0xff800000UL
+#include <addr_map.h>
+
+void init_addr_map(void)
+{
+       mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
+                                            DCACHE_OFF);
+
+       /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
+       /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
+}
+#endif
+
   void enable_caches(void)
   {
          dcache_enable();
include/configs/rpi.h +0 -0
index b53a4b6..296e8ee 100644

include/configs/rpi.h line 71

Quoted 9 lines
include/configs/rpi.h +6 -0
@@ -63,6 +63,13 @@
   #define CONFIG_SYS_BOOTM_LEN           SZ_64M
   #endif
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define CONFIG_ADDR_MAP 1
+#define CONFIG_SYS_NUM_ADDR_MAP 2
+#endif
+#endif

We should be removing things from the config files. Can you move this to devicetree or Kconfig?

Quoted 6 lines
Quoted 2 lines

I can move them to Kconfig, no problem. However I would like to get some comments if the approach I presented in this patchset is fine.

Yes, no problem.

I suspect we may need to expand the DMA drivers, perhaps, or some other way to map memory on a per-device basis using driver model.

I'm not sure that we really need such a complex solution. Usually the board (or even SoC), if ever, needs one or two such non-identity mappings, which can be easily created by the respective init code. The PowerPC case mentioned here looks a bit different, because it simply copies the mappings already configured in the CPU registers by the earlier firmware. Anyway, I don't think that we would ever need to manage physical/virtual mapping dynamically in the u-boot. All that cover current (and most future?) cases would be a simple function to map an arbitrary physical address at the predefined virtual one.

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#9 lore raw

RFC PATCH v3 3/3 rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM 32bit)

Hi Marek,

Quoted 103 lines · Marek Szyprowski

Hi Simon,

Quoted 92 lines · Simon Glass
Quoted 91 lines · Marek Szyprowski
Quoted 90 lines · Simon Glass
Quoted 78 lines · Marek Szyprowski

Create a non-cacheable mapping for the 0x600000000 physical memory region, where MMIO registers for the PCIe XHCI controller are instantiated by the PCIe bridge. Due to 32bit limit in the CPU virtual address space in ARM 32bit mode, this region is mapped at 0xff800000 CPU virtual address.

---
   arch/arm/mach-bcm283x/Kconfig             |  1 +
   arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
   arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
   include/configs/rpi.h                     |  7 +++++++
   4 files changed, 36 insertions(+)
arch/arm/mach-bcm283x/Kconfig +1 -0
index 00419bf..bcb7f1d 100644
@@ -36,6 +36,7 @@ config BCM2711_32B
          select BCM2711
          select ARMV7_LPAE
          select CPU_V7A
+       select PHYS_64BIT
 
   config BCM2711_64B
          bool "Broadcom BCM2711 SoC 64-bit support"
arch/arm/mach-bcm283x/include/mach/base.h +8 -0
index c4ae398..4ccaf69 100644
@@ -8,4 +8,12 @@
 
   extern unsigned long rpi_bcm283x_base;
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#include <addr_map.h>
+#define phys_to_virt addrmap_phys_to_virt
+#define virt_to_phys addrmap_virt_to_phys
+#endif
+#endif
+
   #endif
arch/arm/mach-bcm283x/init.c +20 -0
index 9f5bca3..008b312 100644
@@ -145,6 +145,26 @@ int mach_cpu_init(void)
   }
 
   #ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT       0xff800000UL
+#include <addr_map.h>
+
+void init_addr_map(void)
+{
+       mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
+                                            DCACHE_OFF);
+
+       /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
+       /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
+}
+#endif
+
   void enable_caches(void)
   {
          dcache_enable();
include/configs/rpi.h +0 -0
index b53a4b6..296e8ee 100644

include/configs/rpi.h line 71

Quoted 9 lines
include/configs/rpi.h +6 -0
@@ -63,6 +63,13 @@
   #define CONFIG_SYS_BOOTM_LEN           SZ_64M
   #endif
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define CONFIG_ADDR_MAP 1
+#define CONFIG_SYS_NUM_ADDR_MAP 2
+#endif
+#endif

We should be removing things from the config files. Can you move this to devicetree or Kconfig?

Quoted 6 lines
Quoted 2 lines

I can move them to Kconfig, no problem. However I would like to get some comments if the approach I presented in this patchset is fine.

Yes, no problem.

I suspect we may need to expand the DMA drivers, perhaps, or some other way to map memory on a per-device basis using driver model.

Quoted 9 lines

I'm not sure that we really need such a complex solution. Usually the board (or even SoC), if ever, needs one or two such non-identity mappings, which can be easily created by the respective init code. The PowerPC case mentioned here looks a bit different, because it simply copies the mappings already configured in the CPU registers by the earlier firmware. Anyway, I don't think that we would ever need to manage physical/virtual mapping dynamically in the u-boot. All that cover current (and most future?) cases would be a simple function to map an arbitrary physical address at the predefined virtual one.

OK, well see how you go. When I see CONFIG options that specify values I often think there should be a driver and device-tree node. We can see how things go in the future as to whether we need a driver.

Regards,
Simon

#10 lore raw

RFC PATCH v3 3/3 rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM 32bit)

Hi Simon,

Quoted 109 lines · Simon Glass
Quoted 99 lines · Marek Szyprowski
Quoted 92 lines · Simon Glass
Quoted 91 lines · Marek Szyprowski
Quoted 90 lines · Simon Glass
Quoted 78 lines · Marek Szyprowski

Create a non-cacheable mapping for the 0x600000000 physical memory region, where MMIO registers for the PCIe XHCI controller are instantiated by the PCIe bridge. Due to 32bit limit in the CPU virtual address space in ARM 32bit mode, this region is mapped at 0xff800000 CPU virtual address.

---
    arch/arm/mach-bcm283x/Kconfig             |  1 +
    arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
    arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
    include/configs/rpi.h                     |  7 +++++++
    4 files changed, 36 insertions(+)
arch/arm/mach-bcm283x/Kconfig +1 -0
index 00419bf..bcb7f1d 100644
@@ -36,6 +36,7 @@ config BCM2711_32B
           select BCM2711
           select ARMV7_LPAE
           select CPU_V7A
+       select PHYS_64BIT
 
    config BCM2711_64B
           bool "Broadcom BCM2711 SoC 64-bit support"
arch/arm/mach-bcm283x/include/mach/base.h +8 -0
index c4ae398..4ccaf69 100644
@@ -8,4 +8,12 @@
 
    extern unsigned long rpi_bcm283x_base;
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#include <addr_map.h>
+#define phys_to_virt addrmap_phys_to_virt
+#define virt_to_phys addrmap_virt_to_phys
+#endif
+#endif
+
    #endif
arch/arm/mach-bcm283x/init.c +20 -0
index 9f5bca3..008b312 100644
@@ -145,6 +145,26 @@ int mach_cpu_init(void)
    }
 
    #ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT       0xff800000UL
+#include <addr_map.h>
+
+void init_addr_map(void)
+{
+       mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
+                                            DCACHE_OFF);
+
+       /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
+       /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
+}
+#endif
+
    void enable_caches(void)
    {
           dcache_enable();
include/configs/rpi.h +0 -0
index b53a4b6..296e8ee 100644

include/configs/rpi.h line 71

Quoted 9 lines
include/configs/rpi.h +6 -0
@@ -63,6 +63,13 @@
    #define CONFIG_SYS_BOOTM_LEN           SZ_64M
    #endif
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define CONFIG_ADDR_MAP 1
+#define CONFIG_SYS_NUM_ADDR_MAP 2
+#endif
+#endif

We should be removing things from the config files. Can you move this to devicetree or Kconfig?

Quoted 6 lines
Quoted 2 lines

I can move them to Kconfig, no problem. However I would like to get some comments if the approach I presented in this patchset is fine.

Yes, no problem.

I suspect we may need to expand the DMA drivers, perhaps, or some other way to map memory on a per-device basis using driver model.

Quoted 9 lines

I'm not sure that we really need such a complex solution. Usually the board (or even SoC), if ever, needs one or two such non-identity mappings, which can be easily created by the respective init code. The PowerPC case mentioned here looks a bit different, because it simply copies the mappings already configured in the CPU registers by the earlier firmware. Anyway, I don't think that we would ever need to manage physical/virtual mapping dynamically in the u-boot. All that cover current (and most future?) cases would be a simple function to map an arbitrary physical address at the predefined virtual one.

Quoted 3 lines

OK, well see how you go. When I see CONFIG options that specify values I often think there should be a driver and device-tree node. We can see how things go in the future as to whether we need a driver.

In this case (CONFIG_ADDR_MAP) the values provided by the board's config.h (CONFIG_SYS_NUM_ADDR_MAP) only allows the code to use a simple static array instead of allocating things dynamically. It has no relation to the drivers nor device-tree.

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#11 lore raw

RFC PATCH v3 3/3 rpi4: add a mapping for the PCIe XHCI controller MMIO registers (ARM 32bit)

Hi Marek,

Quoted 113 lines · Marek Szyprowski

Hi Simon,

Quoted 109 lines · Simon Glass
Quoted 108 lines · Marek Szyprowski
Quoted 92 lines · Simon Glass
Quoted 91 lines · Marek Szyprowski
Quoted 90 lines · Simon Glass
Quoted 78 lines · Marek Szyprowski

Create a non-cacheable mapping for the 0x600000000 physical memory region, where MMIO registers for the PCIe XHCI controller are instantiated by the PCIe bridge. Due to 32bit limit in the CPU virtual address space in ARM 32bit mode, this region is mapped at 0xff800000 CPU virtual address.

---
    arch/arm/mach-bcm283x/Kconfig             |  1 +
    arch/arm/mach-bcm283x/include/mach/base.h |  8 ++++++++
    arch/arm/mach-bcm283x/init.c              | 20 ++++++++++++++++++++
    include/configs/rpi.h                     |  7 +++++++
    4 files changed, 36 insertions(+)
arch/arm/mach-bcm283x/Kconfig +1 -0
index 00419bf..bcb7f1d 100644
@@ -36,6 +36,7 @@ config BCM2711_32B
           select BCM2711
           select ARMV7_LPAE
           select CPU_V7A
+       select PHYS_64BIT
 
    config BCM2711_64B
           bool "Broadcom BCM2711 SoC 64-bit support"
arch/arm/mach-bcm283x/include/mach/base.h +8 -0
index c4ae398..4ccaf69 100644
@@ -8,4 +8,12 @@
 
    extern unsigned long rpi_bcm283x_base;
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#include <addr_map.h>
+#define phys_to_virt addrmap_phys_to_virt
+#define virt_to_phys addrmap_virt_to_phys
+#endif
+#endif
+
    #endif
arch/arm/mach-bcm283x/init.c +20 -0
index 9f5bca3..008b312 100644
@@ -145,6 +145,26 @@ int mach_cpu_init(void)
    }
 
    #ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT       0xff800000UL
+#include <addr_map.h>
+
+void init_addr_map(void)
+{
+       mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                                            BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
+                                            DCACHE_OFF);
+
+       /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
+       /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
+       addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
+                         BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
+}
+#endif
+
    void enable_caches(void)
    {
           dcache_enable();
include/configs/rpi.h +0 -0
index b53a4b6..296e8ee 100644

include/configs/rpi.h line 71

Quoted 9 lines
include/configs/rpi.h +6 -0
@@ -63,6 +63,13 @@
    #define CONFIG_SYS_BOOTM_LEN           SZ_64M
    #endif
 
+#ifdef CONFIG_ARMV7_LPAE
+#ifdef CONFIG_TARGET_RPI_4_32B
+#define CONFIG_ADDR_MAP 1
+#define CONFIG_SYS_NUM_ADDR_MAP 2
+#endif
+#endif

We should be removing things from the config files. Can you move this to devicetree or Kconfig?

Quoted 6 lines
Quoted 2 lines

I can move them to Kconfig, no problem. However I would like to get some comments if the approach I presented in this patchset is fine.

Yes, no problem.

I suspect we may need to expand the DMA drivers, perhaps, or some other way to map memory on a per-device basis using driver model.

I'm not sure that we really need such a complex solution. Usually the board (or even SoC), if ever, needs one or two such non-identity mappings, which can be easily created by the respective init code. The PowerPC case mentioned here looks a bit different, because it simply copies the mappings already configured in the CPU registers by the earlier firmware. Anyway, I don't think that we would ever need to manage physical/virtual mapping dynamically in the u-boot. All that cover current (and most future?) cases would be a simple function to map an arbitrary physical address at the predefined virtual one.

Quoted 7 lines
Quoted 3 lines

OK, well see how you go. When I see CONFIG options that specify values I often think there should be a driver and device-tree node. We can see how things go in the future as to whether we need a driver.

In this case (CONFIG_ADDR_MAP) the values provided by the board's config.h (CONFIG_SYS_NUM_ADDR_MAP) only allows the code to use a simple static array instead of allocating things dynamically. It has no relation to the drivers nor device-tree.

We are working to remove the board config.h files and move everything to Kconfig.

If there really is no need for a driver here, then we could perhaps use a weak function for the interface? (Tom, note :-)

Regards,
Simon