blob: 9966d6c8336bd850129a0d0809d5d674cfbba151 [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
9#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070010#include <cpu_func.h>
Matthias Brugger51683d12019-11-19 16:01:04 +010011#include <dm/device.h>
12#include <fdt_support.h>
Stephen Warrendad11a92012-09-01 16:27:56 +000013
Matthias Brugger82e74702019-11-19 16:01:05 +010014#ifdef CONFIG_ARM64
15#include <asm/armv8/mmu.h>
16
17static struct mm_region bcm283x_mem_map[] = {
18 {
19 .virt = 0x00000000UL,
20 .phys = 0x00000000UL,
21 .size = 0x3f000000UL,
22 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
23 PTE_BLOCK_INNER_SHARE
24 }, {
25 .virt = 0x3f000000UL,
26 .phys = 0x3f000000UL,
27 .size = 0x01000000UL,
28 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
29 PTE_BLOCK_NON_SHARE |
30 PTE_BLOCK_PXN | PTE_BLOCK_UXN
31 }, {
32 /* List terminator */
33 0,
34 }
35};
36
37static struct mm_region bcm2711_mem_map[] = {
38 {
39 .virt = 0x00000000UL,
40 .phys = 0x00000000UL,
41 .size = 0xfe000000UL,
42 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
43 PTE_BLOCK_INNER_SHARE
44 }, {
Amit Singh Tomara94f80e2020-01-27 01:14:43 +000045 .virt = 0xfc000000UL,
46 .phys = 0xfc000000UL,
47 .size = 0x03800000UL,
Matthias Brugger82e74702019-11-19 16:01:05 +010048 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
49 PTE_BLOCK_NON_SHARE |
50 PTE_BLOCK_PXN | PTE_BLOCK_UXN
51 }, {
52 /* List terminator */
53 0,
54 }
55};
56
57struct mm_region *mem_map = bcm283x_mem_map;
58
59/*
60 * I/O address space varies on different chip versions.
61 * We set the base address by inspecting the DTB.
62 */
63static const struct udevice_id board_ids[] = {
64 { .compatible = "brcm,bcm2837", .data = (ulong)&bcm283x_mem_map},
65 { .compatible = "brcm,bcm2838", .data = (ulong)&bcm2711_mem_map},
66 { .compatible = "brcm,bcm2711", .data = (ulong)&bcm2711_mem_map},
67 { },
68};
69
70static void _rpi_update_mem_map(struct mm_region *pd)
71{
72 int i;
73
74 for (i = 0; i < 2; i++) {
75 mem_map[i].virt = pd[i].virt;
76 mem_map[i].phys = pd[i].phys;
77 mem_map[i].size = pd[i].size;
78 mem_map[i].attrs = pd[i].attrs;
79 }
80}
81
82static void rpi_update_mem_map(void)
83{
84 int ret;
85 struct mm_region *mm;
86 const struct udevice_id *of_match = board_ids;
87
88 while (of_match->compatible) {
89 ret = fdt_node_check_compatible(gd->fdt_blob, 0,
90 of_match->compatible);
91 if (!ret) {
92 mm = (struct mm_region *)of_match->data;
93 _rpi_update_mem_map(mm);
94 break;
95 }
96
97 of_match++;
98 }
99}
100#else
101static void rpi_update_mem_map(void) {}
102#endif
103
Matthias Brugger51683d12019-11-19 16:01:04 +0100104unsigned long rpi_bcm283x_base = 0x3f000000;
Matthias Brugger2c68dee2019-11-19 16:01:03 +0100105
Stephen Warrendad11a92012-09-01 16:27:56 +0000106int arch_cpu_init(void)
107{
108 icache_enable();
109
110 return 0;
111}
Alexander Graf169892f2016-03-16 15:41:23 +0100112
Matthias Brugger2c68dee2019-11-19 16:01:03 +0100113int mach_cpu_init(void)
114{
Matthias Brugger51683d12019-11-19 16:01:04 +0100115 int ret, soc_offset;
116 u64 io_base, size;
117
Matthias Brugger82e74702019-11-19 16:01:05 +0100118 rpi_update_mem_map();
119
Matthias Brugger51683d12019-11-19 16:01:04 +0100120 /* Get IO base from device tree */
121 soc_offset = fdt_path_offset(gd->fdt_blob, "/soc");
122 if (soc_offset < 0)
123 return soc_offset;
124
125 ret = fdt_read_range((void *)gd->fdt_blob, soc_offset, 0, NULL,
126 &io_base, &size);
127 if (ret)
128 return ret;
129
130 rpi_bcm283x_base = io_base;
Matthias Brugger2c68dee2019-11-19 16:01:03 +0100131
132 return 0;
133}
Matthias Brugger51683d12019-11-19 16:01:04 +0100134
Alexander Graf169892f2016-03-16 15:41:23 +0100135#ifdef CONFIG_ARMV7_LPAE
136void enable_caches(void)
137{
138 dcache_enable();
139}
140#endif