blob: 6fb41a99b26288fc8d67b0e32d2be9bf98efb7a1 [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>
Matthias Bruggerdd47ca72019-11-19 16:01:04 +010010#include <dm/device.h>
11#include <fdt_support.h>
Stephen Warren59d63f72012-09-01 16:27:56 +000012
Matthias Brugger917a1e92019-11-19 16:01:05 +010013#ifdef CONFIG_ARM64
14#include <asm/armv8/mmu.h>
15
16static struct mm_region bcm283x_mem_map[] = {
17 {
18 .virt = 0x00000000UL,
19 .phys = 0x00000000UL,
20 .size = 0x3f000000UL,
21 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
22 PTE_BLOCK_INNER_SHARE
23 }, {
24 .virt = 0x3f000000UL,
25 .phys = 0x3f000000UL,
26 .size = 0x01000000UL,
27 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
28 PTE_BLOCK_NON_SHARE |
29 PTE_BLOCK_PXN | PTE_BLOCK_UXN
30 }, {
31 /* List terminator */
32 0,
33 }
34};
35
36static struct mm_region bcm2711_mem_map[] = {
37 {
38 .virt = 0x00000000UL,
39 .phys = 0x00000000UL,
40 .size = 0xfe000000UL,
41 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
42 PTE_BLOCK_INNER_SHARE
43 }, {
44 .virt = 0xfe000000UL,
45 .phys = 0xfe000000UL,
46 .size = 0x01800000UL,
47 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
48 PTE_BLOCK_NON_SHARE |
49 PTE_BLOCK_PXN | PTE_BLOCK_UXN
50 }, {
51 /* List terminator */
52 0,
53 }
54};
55
56struct mm_region *mem_map = bcm283x_mem_map;
57
58/*
59 * I/O address space varies on different chip versions.
60 * We set the base address by inspecting the DTB.
61 */
62static const struct udevice_id board_ids[] = {
63 { .compatible = "brcm,bcm2837", .data = (ulong)&bcm283x_mem_map},
64 { .compatible = "brcm,bcm2838", .data = (ulong)&bcm2711_mem_map},
65 { .compatible = "brcm,bcm2711", .data = (ulong)&bcm2711_mem_map},
66 { },
67};
68
69static void _rpi_update_mem_map(struct mm_region *pd)
70{
71 int i;
72
73 for (i = 0; i < 2; i++) {
74 mem_map[i].virt = pd[i].virt;
75 mem_map[i].phys = pd[i].phys;
76 mem_map[i].size = pd[i].size;
77 mem_map[i].attrs = pd[i].attrs;
78 }
79}
80
81static void rpi_update_mem_map(void)
82{
83 int ret;
84 struct mm_region *mm;
85 const struct udevice_id *of_match = board_ids;
86
87 while (of_match->compatible) {
88 ret = fdt_node_check_compatible(gd->fdt_blob, 0,
89 of_match->compatible);
90 if (!ret) {
91 mm = (struct mm_region *)of_match->data;
92 _rpi_update_mem_map(mm);
93 break;
94 }
95
96 of_match++;
97 }
98}
99#else
100static void rpi_update_mem_map(void) {}
101#endif
102
Matthias Bruggerdd47ca72019-11-19 16:01:04 +0100103unsigned long rpi_bcm283x_base = 0x3f000000;
Matthias Brugger8e3361c2019-11-19 16:01:03 +0100104
Stephen Warren59d63f72012-09-01 16:27:56 +0000105int arch_cpu_init(void)
106{
107 icache_enable();
108
109 return 0;
110}
Alexander Grafccd9d512016-03-16 15:41:23 +0100111
Matthias Brugger8e3361c2019-11-19 16:01:03 +0100112int mach_cpu_init(void)
113{
Matthias Bruggerdd47ca72019-11-19 16:01:04 +0100114 int ret, soc_offset;
115 u64 io_base, size;
116
Matthias Brugger917a1e92019-11-19 16:01:05 +0100117 rpi_update_mem_map();
118
Matthias Bruggerdd47ca72019-11-19 16:01:04 +0100119 /* Get IO base from device tree */
120 soc_offset = fdt_path_offset(gd->fdt_blob, "/soc");
121 if (soc_offset < 0)
122 return soc_offset;
123
124 ret = fdt_read_range((void *)gd->fdt_blob, soc_offset, 0, NULL,
125 &io_base, &size);
126 if (ret)
127 return ret;
128
129 rpi_bcm283x_base = io_base;
Matthias Brugger8e3361c2019-11-19 16:01:03 +0100130
131 return 0;
132}
Matthias Bruggerdd47ca72019-11-19 16:01:04 +0100133
Alexander Grafccd9d512016-03-16 15:41:23 +0100134#ifdef CONFIG_ARMV7_LPAE
135void enable_caches(void)
136{
137 dcache_enable();
138}
139#endif