1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2020 Broadcom.
8 #include <fdt_support.h>
10 #include <asm/gic-v3.h>
11 #include <asm/system.h>
12 #include <asm/armv8/mmu.h>
13 #include <asm/arch-bcmns3/bl33_info.h>
14 #include <dt-bindings/memory/bcm-ns3-mc.h>
16 /* Default reset-level = 3 and strap-val = 0 */
19 #define BANK_OFFSET(bank) ((u64)BCM_NS3_DDR_INFO_BASE + 8 + ((bank) * 16))
22 * ns3_dram_bank - DDR bank details
24 * @start: DDR bank start address
25 * @len: DDR bank length
27 struct ns3_dram_bank {
28 u64 start[BCM_NS3_MAX_NR_BANKS];
29 u64 len[BCM_NS3_MAX_NR_BANKS];
33 * ns3_dram_hdr - DDR header info
35 * @sig: DDR info signature
36 * @bank: DDR bank details
40 struct ns3_dram_bank bank;
43 static struct mm_region ns3_mem_map[] = {
48 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
50 PTE_BLOCK_PXN | PTE_BLOCK_UXN
52 .virt = BCM_NS3_MEM_START,
53 .phys = BCM_NS3_MEM_START,
54 .size = BCM_NS3_MEM_LEN,
55 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
58 .virt = BCM_NS3_BANK_1_MEM_START,
59 .phys = BCM_NS3_BANK_1_MEM_START,
60 .size = BCM_NS3_BANK_1_MEM_LEN,
61 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
69 struct mm_region *mem_map = ns3_mem_map;
71 DECLARE_GLOBAL_DATA_PTR;
74 * Force the bl33_info to the data-section, as .bss will not be valid
75 * when save_boot_params is invoked.
77 struct bl33_info *bl33_info __section(".data");
80 * Run modulo 256 checksum calculation and return the calculated checksum
82 static u8 checksum_calc(u8 *p, unsigned int len)
87 for (i = 0; i < len; i++)
94 * This function parses the memory layout information from a reserved area in
95 * DDR, and then fix up the FDT before passing it to Linux.
97 * In the case of error, do nothing and the default memory layout in DT will
100 static int mem_info_parse_fixup(void *fdt)
102 struct ns3_dram_hdr hdr;
103 u32 *p32, i, nr_banks;
106 /* validate signature */
107 p32 = (u32 *)BCM_NS3_DDR_INFO_BASE;
109 if (hdr.sig != BCM_NS3_DDR_INFO_SIG) {
110 printf("DDR info signature 0x%x invalid\n", hdr.sig);
114 /* run checksum test to validate data */
115 if (checksum_calc((u8 *)p32, BCM_NS3_DDR_INFO_LEN) != 0) {
116 printf("Checksum on DDR info failed\n");
120 /* parse information for each bank */
122 for (i = 0; i < BCM_NS3_MAX_NR_BANKS; i++) {
123 /* skip banks with a length of zero */
124 p64 = (u64 *)BANK_OFFSET(i);
128 hdr.bank.start[i] = *p64;
129 hdr.bank.len[i] = *(p64 + 1);
131 printf("mem[%u] 0x%llx - 0x%llx\n", i, hdr.bank.start[i],
132 hdr.bank.start[i] + hdr.bank.len[i] - 1);
137 printf("No DDR banks detected\n");
141 return fdt_fixup_memory_banks(fdt, hdr.bank.start, hdr.bank.len,
147 /* Setup memory using "memory" node from DTB */
148 if (fdtdec_setup_mem_size_base() != 0)
150 fdtdec_setup_memory_banksize();
152 if (bl33_info->version != BL33_INFO_VERSION)
153 printf("*** warning: ATF BL31 and U-Boot not in sync! ***\n");
158 int board_late_init(void)
166 * Mark ram base as the last 16MB of 2GB DDR, which is 0xFF00_0000.
167 * So that relocation happens with in the last 16MB memory.
169 gd->ram_base = (phys_size_t)(BCM_NS3_MEM_END - SZ_16M);
170 gd->ram_size = (unsigned long)SZ_16M;
175 int dram_init_banksize(void)
177 gd->bd->bi_dram[0].start = (BCM_NS3_MEM_END - SZ_16M);
178 gd->bd->bi_dram[0].size = SZ_16M;
183 /* Limit RAM used by U-Boot to the DDR first bank End region */
184 ulong board_get_usable_ram_top(ulong total_size)
186 return BCM_NS3_MEM_END;
189 void reset_cpu(ulong level)
191 u32 reset_level, strap_val;
193 /* Default reset type is L3 reset */
196 * Encoding: U-Boot reset command expects decimal argument,
197 * Boot strap val: Bits[3:0]
198 * reset level: Bits[7:4]
200 strap_val = L3_RESET % 10;
201 level = L3_RESET / 10;
202 reset_level = level % 10;
203 psci_system_reset2(reset_level, strap_val);
205 /* U-Boot cmd "reset" with any arg will trigger L1 reset */
210 #ifdef CONFIG_OF_BOARD_SETUP
211 int ft_board_setup(void *fdt, struct bd_info *bd)
213 gic_lpi_tables_init();
215 return mem_info_parse_fixup(fdt);
217 #endif /* CONFIG_OF_BOARD_SETUP */