blob: 49027ce0a2e62bd7eda918751ecf150715ea83f0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren59d63f72012-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 Warren59d63f72012-09-01 16:27:56 +00007 */
8
9#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -070010#include <cpu_func.h>
Simon Glass691d7192020-05-10 11:40:02 -060011#include <init.h>
Matthias Bruggerdd47ca72019-11-19 16:01:04 +010012#include <dm/device.h>
13#include <fdt_support.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Stephen Warren59d63f72012-09-01 16:27:56 +000015
Marek Szyprowskid69ddf22020-05-25 13:39:55 +020016#define BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS 0x600000000UL
17#define BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE 0x800000UL
18
Matthias Brugger917a1e92019-11-19 16:01:05 +010019#ifdef CONFIG_ARM64
20#include <asm/armv8/mmu.h>
21
Marek Szyprowskid69ddf22020-05-25 13:39:55 +020022#define MEM_MAP_MAX_ENTRIES (4)
23
24static struct mm_region bcm283x_mem_map[MEM_MAP_MAX_ENTRIES] = {
Matthias Brugger917a1e92019-11-19 16:01:05 +010025 {
26 .virt = 0x00000000UL,
27 .phys = 0x00000000UL,
28 .size = 0x3f000000UL,
29 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
30 PTE_BLOCK_INNER_SHARE
31 }, {
32 .virt = 0x3f000000UL,
33 .phys = 0x3f000000UL,
34 .size = 0x01000000UL,
35 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
36 PTE_BLOCK_NON_SHARE |
37 PTE_BLOCK_PXN | PTE_BLOCK_UXN
38 }, {
39 /* List terminator */
40 0,
41 }
42};
43
Marek Szyprowskid69ddf22020-05-25 13:39:55 +020044static struct mm_region bcm2711_mem_map[MEM_MAP_MAX_ENTRIES] = {
Matthias Brugger917a1e92019-11-19 16:01:05 +010045 {
46 .virt = 0x00000000UL,
47 .phys = 0x00000000UL,
Marek Szyprowskic44b3f52020-05-25 13:39:54 +020048 .size = 0xfc000000UL,
Matthias Brugger917a1e92019-11-19 16:01:05 +010049 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
50 PTE_BLOCK_INNER_SHARE
51 }, {
Amit Singh Tomarfff5d542020-01-27 01:14:43 +000052 .virt = 0xfc000000UL,
53 .phys = 0xfc000000UL,
54 .size = 0x03800000UL,
Matthias Brugger917a1e92019-11-19 16:01:05 +010055 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
56 PTE_BLOCK_NON_SHARE |
57 PTE_BLOCK_PXN | PTE_BLOCK_UXN
58 }, {
Marek Szyprowskid69ddf22020-05-25 13:39:55 +020059 .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) |
63 PTE_BLOCK_NON_SHARE |
64 PTE_BLOCK_PXN | PTE_BLOCK_UXN
65 }, {
Matthias Brugger917a1e92019-11-19 16:01:05 +010066 /* List terminator */
67 0,
68 }
69};
70
71struct mm_region *mem_map = bcm283x_mem_map;
72
73/*
74 * I/O address space varies on different chip versions.
75 * We set the base address by inspecting the DTB.
76 */
77static const struct udevice_id board_ids[] = {
78 { .compatible = "brcm,bcm2837", .data = (ulong)&bcm283x_mem_map},
79 { .compatible = "brcm,bcm2838", .data = (ulong)&bcm2711_mem_map},
80 { .compatible = "brcm,bcm2711", .data = (ulong)&bcm2711_mem_map},
81 { },
82};
83
84static void _rpi_update_mem_map(struct mm_region *pd)
85{
86 int i;
87
Marek Szyprowskid69ddf22020-05-25 13:39:55 +020088 for (i = 0; i < MEM_MAP_MAX_ENTRIES; i++) {
Matthias Brugger917a1e92019-11-19 16:01:05 +010089 mem_map[i].virt = pd[i].virt;
90 mem_map[i].phys = pd[i].phys;
91 mem_map[i].size = pd[i].size;
92 mem_map[i].attrs = pd[i].attrs;
93 }
94}
95
96static void rpi_update_mem_map(void)
97{
98 int ret;
99 struct mm_region *mm;
100 const struct udevice_id *of_match = board_ids;
101
102 while (of_match->compatible) {
103 ret = fdt_node_check_compatible(gd->fdt_blob, 0,
104 of_match->compatible);
105 if (!ret) {
106 mm = (struct mm_region *)of_match->data;
107 _rpi_update_mem_map(mm);
108 break;
109 }
110
111 of_match++;
112 }
113}
114#else
115static void rpi_update_mem_map(void) {}
116#endif
117
Matthias Bruggerdd47ca72019-11-19 16:01:04 +0100118unsigned long rpi_bcm283x_base = 0x3f000000;
Matthias Brugger8e3361c2019-11-19 16:01:03 +0100119
Stephen Warren59d63f72012-09-01 16:27:56 +0000120int arch_cpu_init(void)
121{
122 icache_enable();
123
124 return 0;
125}
Alexander Grafccd9d512016-03-16 15:41:23 +0100126
Matthias Brugger8e3361c2019-11-19 16:01:03 +0100127int mach_cpu_init(void)
128{
Matthias Bruggerdd47ca72019-11-19 16:01:04 +0100129 int ret, soc_offset;
130 u64 io_base, size;
131
Matthias Brugger917a1e92019-11-19 16:01:05 +0100132 rpi_update_mem_map();
133
Matthias Bruggerdd47ca72019-11-19 16:01:04 +0100134 /* Get IO base from device tree */
135 soc_offset = fdt_path_offset(gd->fdt_blob, "/soc");
136 if (soc_offset < 0)
137 return soc_offset;
138
139 ret = fdt_read_range((void *)gd->fdt_blob, soc_offset, 0, NULL,
140 &io_base, &size);
141 if (ret)
142 return ret;
143
144 rpi_bcm283x_base = io_base;
Matthias Brugger8e3361c2019-11-19 16:01:03 +0100145
146 return 0;
147}
Matthias Bruggerdd47ca72019-11-19 16:01:04 +0100148
Alexander Grafccd9d512016-03-16 15:41:23 +0100149#ifdef CONFIG_ARMV7_LPAE
Marek Szyprowski814e1a42020-06-03 14:43:44 +0200150#ifdef CONFIG_TARGET_RPI_4_32B
151#define BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT 0xff800000UL
152#include <addr_map.h>
153#include <asm/system.h>
154
155void init_addr_map(void)
156{
157 mmu_set_region_dcache_behaviour_phys(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
158 BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
159 BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE,
160 DCACHE_OFF);
161
162 /* identity mapping for 0..BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
163 addrmap_set_entry(0, 0, BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT, 0);
164 /* XHCI MMIO on PCIe at BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT */
165 addrmap_set_entry(BCM2711_RPI4_PCIE_XHCI_MMIO_VIRT,
166 BCM2711_RPI4_PCIE_XHCI_MMIO_PHYS,
167 BCM2711_RPI4_PCIE_XHCI_MMIO_SIZE, 1);
168}
169#endif
170
Alexander Grafccd9d512016-03-16 15:41:23 +0100171void enable_caches(void)
172{
173 dcache_enable();
174}
175#endif