blob: 578cb9bfd3f8382022aabc408bd26cc5bfcb38eb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut23e239a2017-11-25 23:24:01 +01002/*
3 * Renesas RCar Gen3 memory map tables
4 *
5 * Copyright (C) 2017 Marek Vasut <marek.vasut@gmail.com>
Marek Vasut23e239a2017-11-25 23:24:01 +01006 */
7
8#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Marek Vasut23e239a2017-11-25 23:24:01 +010010#include <asm/armv8/mmu.h>
11
Marek Vasut970fd8c2018-10-31 15:06:50 +010012#define GEN3_NR_REGIONS 16
13
14static struct mm_region gen3_mem_map[GEN3_NR_REGIONS] = {
Marek Vasut23e239a2017-11-25 23:24:01 +010015 {
16 .virt = 0x0UL,
17 .phys = 0x0UL,
Marek Vasuta5abacc2018-02-15 13:19:33 +010018 .size = 0x40000000UL,
Marek Vasut23e239a2017-11-25 23:24:01 +010019 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
20 PTE_BLOCK_NON_SHARE |
21 PTE_BLOCK_PXN | PTE_BLOCK_UXN
22 }, {
Marek Vasuta5abacc2018-02-15 13:19:33 +010023 .virt = 0x40000000UL,
24 .phys = 0x40000000UL,
Hiroyuki Yokoyama5cc53952018-11-22 11:50:44 +090025 .size = 0x03F00000UL,
26 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
27 PTE_BLOCK_INNER_SHARE
28 }, {
29 .virt = 0x47E00000UL,
30 .phys = 0x47E00000UL,
31 .size = 0x78200000UL,
Marek Vasut04cd2e22017-10-08 20:52:52 +020032 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
33 PTE_BLOCK_INNER_SHARE
34 }, {
Marek Vasuta5abacc2018-02-15 13:19:33 +010035 .virt = 0xc0000000UL,
36 .phys = 0xc0000000UL,
37 .size = 0x40000000UL,
Marek Vasut04cd2e22017-10-08 20:52:52 +020038 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
39 PTE_BLOCK_NON_SHARE |
40 PTE_BLOCK_PXN | PTE_BLOCK_UXN
41 }, {
Marek Vasut48bbd492018-10-02 21:42:49 +020042 .virt = 0x100000000UL,
43 .phys = 0x100000000UL,
44 .size = 0xf00000000UL,
45 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
46 PTE_BLOCK_INNER_SHARE
47 }, {
Marek Vasut04cd2e22017-10-08 20:52:52 +020048 /* List terminator */
49 0,
50 }
51};
52
Marek Vasuta5abacc2018-02-15 13:19:33 +010053struct mm_region *mem_map = gen3_mem_map;
Marek Vasut970fd8c2018-10-31 15:06:50 +010054
55DECLARE_GLOBAL_DATA_PTR;
56
57void enable_caches(void)
58{
59 u64 start, size;
60 int bank, i = 0;
61
62 /* Create map for RPC access */
63 gen3_mem_map[i].virt = 0x0ULL;
64 gen3_mem_map[i].phys = 0x0ULL;
65 gen3_mem_map[i].size = 0x40000000ULL;
66 gen3_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
67 PTE_BLOCK_NON_SHARE |
68 PTE_BLOCK_PXN | PTE_BLOCK_UXN;
69 i++;
70
71 /* Generate entires for DRAM in 32bit address space */
72 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
73 start = gd->bd->bi_dram[bank].start;
74 size = gd->bd->bi_dram[bank].size;
75
76 /* Skip empty DRAM banks */
77 if (!size)
78 continue;
79
80 /* Skip DRAM above 4 GiB */
81 if (start >> 32ULL)
82 continue;
83
84 /* Mark memory reserved by ATF as cacheable too. */
85 if (start == 0x48000000) {
Takeshi Kihara5cecd1c2018-12-04 12:51:01 +090086 /* Unmark protection area (0x43F00000 to 0x47DFFFFF) */
87 gen3_mem_map[i].virt = 0x40000000ULL;
88 gen3_mem_map[i].phys = 0x40000000ULL;
89 gen3_mem_map[i].size = 0x03F00000ULL;
90 gen3_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
91 PTE_BLOCK_INNER_SHARE;
92 i++;
93
94 start = 0x47E00000ULL;
95 size += 0x00200000ULL;
Marek Vasut970fd8c2018-10-31 15:06:50 +010096 }
97
98 gen3_mem_map[i].virt = start;
99 gen3_mem_map[i].phys = start;
100 gen3_mem_map[i].size = size;
101 gen3_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
102 PTE_BLOCK_INNER_SHARE;
103 i++;
104 }
105
106 /* Create map for register access */
107 gen3_mem_map[i].virt = 0xc0000000ULL;
108 gen3_mem_map[i].phys = 0xc0000000ULL;
109 gen3_mem_map[i].size = 0x40000000ULL;
110 gen3_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
111 PTE_BLOCK_NON_SHARE |
112 PTE_BLOCK_PXN | PTE_BLOCK_UXN;
113 i++;
114
115 /* Generate entires for DRAM in 64bit address space */
116 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
117 start = gd->bd->bi_dram[bank].start;
118 size = gd->bd->bi_dram[bank].size;
119
120 /* Skip empty DRAM banks */
121 if (!size)
122 continue;
123
124 /* Skip DRAM below 4 GiB */
125 if (!(start >> 32ULL))
126 continue;
127
128 gen3_mem_map[i].virt = start;
129 gen3_mem_map[i].phys = start;
130 gen3_mem_map[i].size = size;
131 gen3_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
132 PTE_BLOCK_INNER_SHARE;
133 i++;
134 }
135
136 /* Zero out the remaining regions. */
137 for (; i < GEN3_NR_REGIONS; i++) {
138 gen3_mem_map[i].virt = 0;
139 gen3_mem_map[i].phys = 0;
140 gen3_mem_map[i].size = 0;
141 gen3_mem_map[i].attrs = 0;
142 }
143
Takeshi Kiharacb048902018-12-04 11:53:24 +0900144 if (!icache_status())
145 icache_enable();
146
Marek Vasut970fd8c2018-10-31 15:06:50 +0100147 dcache_enable();
148}