blob: 3b3c6f7cde9a0422d8cfbc84702ab815cf0e0cde [file] [log] [blame]
Paul Barkerd5e2e692023-10-16 10:25:41 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Renesas RZ/G2L family memory map tables
4 *
5 * Copyright (C) 2017 Marek Vasut <marek.vasut@gmail.com>
6 * Copyright (C) 2023 Renesas Electronics Corp.
7 */
8
Paul Barkerd5e2e692023-10-16 10:25:41 +01009#include <asm/armv8/mmu.h>
10#include <asm/global_data.h>
Paul Barkerd5e2e692023-10-16 10:25:41 +010011#include <cpu_func.h>
12
13#define RZG2L_NR_REGIONS 16
14
15/*
16 * RZ/G2L supports up to 4 GiB RAM starting at 0x40000000, of
17 * which the first 128 MiB is reserved by TF-A.
18 */
19static struct mm_region rzg2l_mem_map[RZG2L_NR_REGIONS] = {
20 {
21 .virt = 0x0UL,
22 .phys = 0x0UL,
23 .size = 0x40000000UL,
24 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
25 PTE_BLOCK_NON_SHARE |
26 PTE_BLOCK_PXN | PTE_BLOCK_UXN
27 }, {
28 .virt = 0x40000000UL,
29 .phys = 0x40000000UL,
30 .size = 0x03F00000UL,
31 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
32 PTE_BLOCK_INNER_SHARE
33 }, {
34 .virt = 0x47E00000UL,
35 .phys = 0x47E00000UL,
36 .size = 0xF8200000UL,
37 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
38 PTE_BLOCK_INNER_SHARE
39 }, {
40 /* List terminator */
41 0,
42 }
43};
44
45struct mm_region *mem_map = rzg2l_mem_map;
46
47DECLARE_GLOBAL_DATA_PTR;
48
49#define debug_memmap(i, map) \
50 debug("memmap %d: virt 0x%llx -> phys 0x%llx, size=0x%llx, attrs=0x%llx\n", \
51 i, map[i].virt, map[i].phys, map[i].size, map[i].attrs)
52
53void enable_caches(void)
54{
55 unsigned int bank, i = 0;
56 u64 start, size;
57
58 /* Create map for register access */
59 rzg2l_mem_map[i].virt = 0x0ULL;
60 rzg2l_mem_map[i].phys = 0x0ULL;
61 rzg2l_mem_map[i].size = 0x40000000ULL;
62 rzg2l_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
63 PTE_BLOCK_NON_SHARE |
64 PTE_BLOCK_PXN | PTE_BLOCK_UXN;
65 debug_memmap(i, rzg2l_mem_map);
66 i++;
67
68 /* Generate entries for DRAM in 32bit address space */
69 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
70 start = gd->bd->bi_dram[bank].start;
71 size = gd->bd->bi_dram[bank].size;
72
73 /* Skip empty DRAM banks */
74 if (!size)
75 continue;
76
77 /* Mark memory reserved by ATF as cacheable too. */
78 if (start == 0x48000000) {
79 /* Unmark protection area (0x43F00000 to 0x47DFFFFF) */
80 rzg2l_mem_map[i].virt = 0x40000000ULL;
81 rzg2l_mem_map[i].phys = 0x40000000ULL;
82 rzg2l_mem_map[i].size = 0x03F00000ULL;
83 rzg2l_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
84 PTE_BLOCK_INNER_SHARE;
85 debug_memmap(i, rzg2l_mem_map);
86 i++;
87
88 start = 0x47E00000ULL;
89 size += 0x00200000ULL;
90 }
91
92 rzg2l_mem_map[i].virt = start;
93 rzg2l_mem_map[i].phys = start;
94 rzg2l_mem_map[i].size = size;
95 rzg2l_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
96 PTE_BLOCK_INNER_SHARE;
97 debug_memmap(i, rzg2l_mem_map);
98 i++;
99 }
100
101 /* Zero out the remaining regions. */
102 for (; i < RZG2L_NR_REGIONS; i++) {
103 rzg2l_mem_map[i].virt = 0;
104 rzg2l_mem_map[i].phys = 0;
105 rzg2l_mem_map[i].size = 0;
106 rzg2l_mem_map[i].attrs = 0;
107 debug_memmap(i, rzg2l_mem_map);
108 }
109
110 if (!icache_status())
111 icache_enable();
112
113 dcache_enable();
114}
115
116int dram_init(void)
117{
118 return fdtdec_setup_mem_size_base();
119}
120
121int dram_init_banksize(void)
122{
123 fdtdec_setup_memory_banksize();
124
125 return 0;
126}