]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm64: mvebu: a37xx: add device-tree fixer for PCIe regions
authorMarek Behún <marek.behun@nic.cz>
Wed, 8 Apr 2020 17:25:21 +0000 (19:25 +0200)
committerStefan Roese <sr@denx.de>
Tue, 14 Apr 2020 11:16:42 +0000 (13:16 +0200)
In case when ARM Trusted Firmware changes the default address of PCIe
regions (which can be done for devices with 4 GB RAM to maximize the
amount of RAM the device can use) we add code that looks at how ATF
changed the PCIe windows in the CPU Address Decoder and changes given
device-tree blob accordingly.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
arch/arm/mach-mvebu/armada3700/cpu.c
arch/arm/mach-mvebu/include/mach/cpu.h

index 959a909d8afacaef54eb58f8cfe50a2e442cd515..17d2d43babb60f615b6f865c295c69ae46876c82 100644 (file)
@@ -50,6 +50,8 @@
 #define A3700_PTE_BLOCK_DEVICE \
        (PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE)
 
+#define PCIE_PATH                      "/soc/pcie@d0070000"
+
 DECLARE_GLOBAL_DATA_PTR;
 
 static struct mm_region mvebu_mem_map[MAX_MEM_MAP_REGIONS] = {
@@ -259,6 +261,56 @@ int a3700_dram_init_banksize(void)
        return 0;
 }
 
+static u32 find_pcie_window_base(void)
+{
+       int win;
+
+       for (win = 0; win < MVEBU_CPU_DEC_WINS; ++win) {
+               u32 base, tgt;
+
+               /* skip disabled windows */
+               if (get_cpu_dec_win(win, &tgt, &base, NULL))
+                       continue;
+
+               if (tgt == MVEBU_CPU_DEC_WIN_CTRL_TGT_PCIE)
+                       return base;
+       }
+
+       return -1;
+}
+
+int a3700_fdt_fix_pcie_regions(void *blob)
+{
+       u32 new_ranges[14], base;
+       const u32 *ranges;
+       int node, len;
+
+       node = fdt_path_offset(blob, PCIE_PATH);
+       if (node < 0)
+               return node;
+
+       ranges = fdt_getprop(blob, node, "ranges", &len);
+       if (!ranges)
+               return -ENOENT;
+
+       if (len != sizeof(new_ranges))
+               return -EINVAL;
+
+       memcpy(new_ranges, ranges, len);
+
+       base = find_pcie_window_base();
+       if (base == -1)
+               return -ENOENT;
+
+       new_ranges[2] = cpu_to_fdt32(base);
+       new_ranges[4] = new_ranges[2];
+
+       new_ranges[9] = cpu_to_fdt32(base + 0x1000000);
+       new_ranges[11] = new_ranges[9];
+
+       return fdt_setprop_inplace(blob, node, "ranges", new_ranges, len);
+}
+
 void reset_cpu(ulong ignored)
 {
        /*
index 3bb541b6ca1fd358f04021060a3bb4606e8c6752..c3f8ad850651285aa5276063825821863702c896 100644 (file)
@@ -180,6 +180,9 @@ int a8k_dram_init_banksize(void);
 int a3700_dram_init(void);
 int a3700_dram_init_banksize(void);
 
+/* A3700 PCIe regions fixer for device tree */
+int a3700_fdt_fix_pcie_regions(void *blob);
+
 /*
  * get_ref_clk
  *