1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2012 Stephen Warren
5 * See file CREDITS for list of people who contributed to this
12 #include <dm/device.h>
13 #include <fdt_support.h>
14 #include <asm/global_data.h>
16 #define BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS 0x600000000UL
17 #define BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE 0x400000UL
20 #include <asm/armv8/mmu.h>
22 #define MEM_MAP_MAX_ENTRIES (4)
24 static struct mm_region bcm283x_mem_map[MEM_MAP_MAX_ENTRIES] = {
29 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
35 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
37 PTE_BLOCK_PXN | PTE_BLOCK_UXN
44 static struct mm_region bcm2711_mem_map[MEM_MAP_MAX_ENTRIES] = {
49 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
55 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
57 PTE_BLOCK_PXN | PTE_BLOCK_UXN
59 .virt = BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
60 .phys = BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
61 .size = BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
62 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
64 PTE_BLOCK_PXN | PTE_BLOCK_UXN
71 static struct mm_region bcm2712_mem_map[MEM_MAP_MAX_ENTRIES] = {
73 /* First 1GB of DRAM */
77 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
80 /* Beginning of AXI bus where uSD controller lives */
81 .virt = 0x1000000000UL,
82 .phys = 0x1000000000UL,
83 .size = 0x0002000000UL,
84 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
86 PTE_BLOCK_PXN | PTE_BLOCK_UXN
89 .virt = 0x107c000000UL,
90 .phys = 0x107c000000UL,
91 .size = 0x0004000000UL,
92 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
94 PTE_BLOCK_PXN | PTE_BLOCK_UXN
101 struct mm_region *mem_map = bcm283x_mem_map;
104 * I/O address space varies on different chip versions.
105 * We set the base address by inspecting the DTB.
107 static const struct udevice_id board_ids[] = {
108 { .compatible = "brcm,bcm2837", .data = (ulong)&bcm283x_mem_map},
109 { .compatible = "brcm,bcm2838", .data = (ulong)&bcm2711_mem_map},
110 { .compatible = "brcm,bcm2711", .data = (ulong)&bcm2711_mem_map},
111 { .compatible = "brcm,bcm2712", .data = (ulong)&bcm2712_mem_map},
115 static void _rpi_update_mem_map(struct mm_region *pd)
119 for (i = 0; i < MEM_MAP_MAX_ENTRIES; i++) {
120 mem_map[i].virt = pd[i].virt;
121 mem_map[i].phys = pd[i].phys;
122 mem_map[i].size = pd[i].size;
123 mem_map[i].attrs = pd[i].attrs;
127 static void rpi_update_mem_map(void)
130 struct mm_region *mm;
131 const struct udevice_id *of_match = board_ids;
133 while (of_match->compatible) {
134 ret = fdt_node_check_compatible(gd->fdt_blob, 0,
135 of_match->compatible);
137 mm = (struct mm_region *)of_match->data;
138 _rpi_update_mem_map(mm);
146 static void rpi_update_mem_map(void) {}
149 /* Default bcm283x devices addresses */
150 unsigned long rpi_mbox_base = 0x3f00b880;
151 unsigned long rpi_sdhci_base = 0x3f300000;
152 unsigned long rpi_wdog_base = 0x3f100000;
153 unsigned long rpi_timer_base = 0x3f003000;
155 int arch_cpu_init(void)
162 int mach_cpu_init(void)
164 int ret, soc, offset;
167 rpi_update_mem_map();
169 /* Get IO base from device tree */
170 soc = fdt_path_offset(gd->fdt_blob, "/soc");
174 ret = fdt_read_range((void *)gd->fdt_blob, soc, 0, NULL,
179 rpi_mbox_base = io_base + 0x00b880;
180 rpi_sdhci_base = io_base + 0x300000;
181 rpi_wdog_base = io_base + 0x100000;
182 rpi_timer_base = io_base + 0x003000;
184 offset = fdt_node_offset_by_compatible(gd->fdt_blob, soc,
185 "brcm,bcm2835-mbox");
187 rpi_mbox_base = fdt_get_base_address(gd->fdt_blob, offset);
189 offset = fdt_node_offset_by_compatible(gd->fdt_blob, soc,
190 "brcm,bcm2835-sdhci");
192 rpi_sdhci_base = fdt_get_base_address(gd->fdt_blob, offset);
194 offset = fdt_node_offset_by_compatible(gd->fdt_blob, soc,
195 "brcm,bcm2835-system-timer");
197 rpi_timer_base = fdt_get_base_address(gd->fdt_blob, offset);
199 offset = fdt_node_offset_by_compatible(gd->fdt_blob, soc,
202 rpi_wdog_base = fdt_get_base_address(gd->fdt_blob, offset);
207 #ifdef CONFIG_ARMV7_LPAE
208 #ifdef CONFIG_TARGET_RPI_4_32B
209 #define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT 0xffc00000UL
210 #include <addr_map.h>
211 #include <asm/system.h>
213 int init_addr_map(void)
215 mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
216 BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
217 BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
220 /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
221 addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
222 /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
223 addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
224 BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
225 BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
231 void enable_caches(void)