blob: 1b459707bc63a4f2ca5821121e020b11aaafbbe9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warrendad11a92012-09-01 16:27:56 +00002/*
3 * (C) Copyright 2012 Stephen Warren
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
Stephen Warrendad11a92012-09-01 16:27:56 +00007 */
8
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Matthias Brugger51683d12019-11-19 16:01:04 +010011#include <dm/device.h>
12#include <fdt_support.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Stephen Warrendad11a92012-09-01 16:27:56 +000014
Marek Szyprowskid79c6882020-05-25 13:39:55 +020015#define BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS 0x600000000UL
Marek Szyprowskic15922b2021-06-17 11:22:03 +020016#define BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE 0x400000UL
Marek Szyprowskid79c6882020-05-25 13:39:55 +020017
Matthias Brugger82e74702019-11-19 16:01:05 +010018#ifdef CONFIG_ARM64
19#include <asm/armv8/mmu.h>
20
Marek Szyprowskid79c6882020-05-25 13:39:55 +020021#define MEM_MAP_MAX_ENTRIES (4)
22
23static struct mm_region bcm283x_mem_map[MEM_MAP_MAX_ENTRIES] = {
Matthias Brugger82e74702019-11-19 16:01:05 +010024 {
25 .virt = 0x00000000UL,
26 .phys = 0x00000000UL,
27 .size = 0x3f000000UL,
28 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
29 PTE_BLOCK_INNER_SHARE
30 }, {
31 .virt = 0x3f000000UL,
32 .phys = 0x3f000000UL,
33 .size = 0x01000000UL,
34 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
35 PTE_BLOCK_NON_SHARE |
36 PTE_BLOCK_PXN | PTE_BLOCK_UXN
37 }, {
38 /* List terminator */
39 0,
40 }
41};
42
Marek Szyprowskid79c6882020-05-25 13:39:55 +020043static struct mm_region bcm2711_mem_map[MEM_MAP_MAX_ENTRIES] = {
Matthias Brugger82e74702019-11-19 16:01:05 +010044 {
45 .virt = 0x00000000UL,
46 .phys = 0x00000000UL,
Marek Szyprowskia6e042e2020-05-25 13:39:54 +020047 .size = 0xfc000000UL,
Matthias Brugger82e74702019-11-19 16:01:05 +010048 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
49 PTE_BLOCK_INNER_SHARE
50 }, {
Amit Singh Tomara94f80e2020-01-27 01:14:43 +000051 .virt = 0xfc000000UL,
52 .phys = 0xfc000000UL,
53 .size = 0x03800000UL,
Matthias Brugger82e74702019-11-19 16:01:05 +010054 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
55 PTE_BLOCK_NON_SHARE |
56 PTE_BLOCK_PXN | PTE_BLOCK_UXN
57 }, {
Marek Szyprowskid79c6882020-05-25 13:39:55 +020058 .virt = BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
59 .phys = BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
60 .size = BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
61 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
62 PTE_BLOCK_NON_SHARE |
63 PTE_BLOCK_PXN | PTE_BLOCK_UXN
64 }, {
Matthias Brugger82e74702019-11-19 16:01:05 +010065 /* List terminator */
66 0,
67 }
68};
69
Dmitry Malkind93248e2024-01-23 10:07:53 +020070static struct mm_region bcm2712_mem_map[MEM_MAP_MAX_ENTRIES] = {
71 {
72 /* First 1GB of DRAM */
73 .virt = 0x00000000UL,
74 .phys = 0x00000000UL,
75 .size = 0x40000000UL,
76 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
77 PTE_BLOCK_INNER_SHARE
78 }, {
79 /* Beginning of AXI bus where uSD controller lives */
80 .virt = 0x1000000000UL,
81 .phys = 0x1000000000UL,
82 .size = 0x0002000000UL,
83 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
84 PTE_BLOCK_NON_SHARE |
85 PTE_BLOCK_PXN | PTE_BLOCK_UXN
86 }, {
87 /* SoC bus */
88 .virt = 0x107c000000UL,
89 .phys = 0x107c000000UL,
90 .size = 0x0004000000UL,
91 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
92 PTE_BLOCK_NON_SHARE |
93 PTE_BLOCK_PXN | PTE_BLOCK_UXN
94 }, {
95 /* List terminator */
96 0,
97 }
98};
99
Matthias Brugger82e74702019-11-19 16:01:05 +0100100struct mm_region *mem_map = bcm283x_mem_map;
101
102/*
103 * I/O address space varies on different chip versions.
104 * We set the base address by inspecting the DTB.
105 */
106static const struct udevice_id board_ids[] = {
107 { .compatible = "brcm,bcm2837", .data = (ulong)&bcm283x_mem_map},
108 { .compatible = "brcm,bcm2838", .data = (ulong)&bcm2711_mem_map},
109 { .compatible = "brcm,bcm2711", .data = (ulong)&bcm2711_mem_map},
Dmitry Malkind93248e2024-01-23 10:07:53 +0200110 { .compatible = "brcm,bcm2712", .data = (ulong)&bcm2712_mem_map},
Matthias Brugger82e74702019-11-19 16:01:05 +0100111 { },
112};
113
114static void _rpi_update_mem_map(struct mm_region *pd)
115{
116 int i;
117
Marek Szyprowskid79c6882020-05-25 13:39:55 +0200118 for (i = 0; i < MEM_MAP_MAX_ENTRIES; i++) {
Matthias Brugger82e74702019-11-19 16:01:05 +0100119 mem_map[i].virt = pd[i].virt;
120 mem_map[i].phys = pd[i].phys;
121 mem_map[i].size = pd[i].size;
122 mem_map[i].attrs = pd[i].attrs;
123 }
124}
125
126static void rpi_update_mem_map(void)
127{
128 int ret;
129 struct mm_region *mm;
130 const struct udevice_id *of_match = board_ids;
131
132 while (of_match->compatible) {
133 ret = fdt_node_check_compatible(gd->fdt_blob, 0,
134 of_match->compatible);
135 if (!ret) {
136 mm = (struct mm_region *)of_match->data;
137 _rpi_update_mem_map(mm);
138 break;
139 }
140
141 of_match++;
142 }
143}
144#else
145static void rpi_update_mem_map(void) {}
146#endif
147
Dmitry Malkinb8c537c2024-01-23 10:07:54 +0200148/* Default bcm283x devices addresses */
149unsigned long rpi_mbox_base = 0x3f00b880;
150unsigned long rpi_sdhci_base = 0x3f300000;
151unsigned long rpi_wdog_base = 0x3f100000;
152unsigned long rpi_timer_base = 0x3f003000;
Matthias Brugger2c68dee2019-11-19 16:01:03 +0100153
Stephen Warrendad11a92012-09-01 16:27:56 +0000154int arch_cpu_init(void)
155{
156 icache_enable();
157
158 return 0;
159}
Alexander Graf169892f2016-03-16 15:41:23 +0100160
Matthias Brugger2c68dee2019-11-19 16:01:03 +0100161int mach_cpu_init(void)
162{
Dmitry Malkinb8c537c2024-01-23 10:07:54 +0200163 int ret, soc, offset;
Matthias Brugger51683d12019-11-19 16:01:04 +0100164 u64 io_base, size;
165
Matthias Brugger82e74702019-11-19 16:01:05 +0100166 rpi_update_mem_map();
167
Matthias Brugger51683d12019-11-19 16:01:04 +0100168 /* Get IO base from device tree */
Dmitry Malkinb8c537c2024-01-23 10:07:54 +0200169 soc = fdt_path_offset(gd->fdt_blob, "/soc");
170 if (soc < 0)
171 return soc;
Matthias Brugger51683d12019-11-19 16:01:04 +0100172
Dmitry Malkinb8c537c2024-01-23 10:07:54 +0200173 ret = fdt_read_range((void *)gd->fdt_blob, soc, 0, NULL,
174 &io_base, &size);
Matthias Brugger51683d12019-11-19 16:01:04 +0100175 if (ret)
176 return ret;
177
Dmitry Malkinb8c537c2024-01-23 10:07:54 +0200178 rpi_mbox_base = io_base + 0x00b880;
179 rpi_sdhci_base = io_base + 0x300000;
180 rpi_wdog_base = io_base + 0x100000;
181 rpi_timer_base = io_base + 0x003000;
182
183 offset = fdt_node_offset_by_compatible(gd->fdt_blob, soc,
184 "brcm,bcm2835-mbox");
185 if (offset > soc)
186 rpi_mbox_base = fdt_get_base_address(gd->fdt_blob, offset);
187
188 offset = fdt_node_offset_by_compatible(gd->fdt_blob, soc,
189 "brcm,bcm2835-sdhci");
190 if (offset > soc)
191 rpi_sdhci_base = fdt_get_base_address(gd->fdt_blob, offset);
192
193 offset = fdt_node_offset_by_compatible(gd->fdt_blob, soc,
194 "brcm,bcm2835-system-timer");
195 if (offset > soc)
196 rpi_timer_base = fdt_get_base_address(gd->fdt_blob, offset);
197
198 offset = fdt_node_offset_by_compatible(gd->fdt_blob, soc,
199 "brcm,bcm2712-pm");
200 if (offset > soc)
201 rpi_wdog_base = fdt_get_base_address(gd->fdt_blob, offset);
Matthias Brugger2c68dee2019-11-19 16:01:03 +0100202
203 return 0;
204}
Matthias Brugger51683d12019-11-19 16:01:04 +0100205
Naveen Kumar Chaudharyfa0ff562023-08-03 19:09:35 +0530206#if defined(CONFIG_DISPLAY_CPUINFO)
207int print_cpuinfo(void)
208{
209 printf("CPU: BCM283x\n");
210 return 0;
211}
212#endif
213
Alexander Graf169892f2016-03-16 15:41:23 +0100214#ifdef CONFIG_ARMV7_LPAE
Marek Szyprowskiab9d99a2020-06-03 14:43:44 +0200215#ifdef CONFIG_TARGET_RPI_4_32B
Marek Szyprowskic15922b2021-06-17 11:22:03 +0200216#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT 0xffc00000UL
Marek Szyprowskiab9d99a2020-06-03 14:43:44 +0200217#include <addr_map.h>
218#include <asm/system.h>
219
Ovidiu Panait9ef3c8a2022-01-01 19:13:28 +0200220int init_addr_map(void)
Marek Szyprowskiab9d99a2020-06-03 14:43:44 +0200221{
222 mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
223 BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
224 BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
225 DCACHE_OFF);
226
227 /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
228 addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
229 /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
230 addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
231 BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
232 BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
Ovidiu Panait9ef3c8a2022-01-01 19:13:28 +0200233
234 return 0;
Marek Szyprowskiab9d99a2020-06-03 14:43:44 +0200235}
236#endif
237
Alexander Graf169892f2016-03-16 15:41:23 +0100238void enable_caches(void)
239{
240 dcache_enable();
241}
242#endif