blob: 75ba3c33d56dad8d43da0131e54d30982ab0269a [file] [log] [blame]
Usama Arif9218a112020-08-12 16:12:53 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2020 Arm Limited
4 * Usama Arif <usama.arif@arm.com>
5 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <config.h>
Usama Arif9218a112020-08-12 16:12:53 +01008#include <dm.h>
9#include <dm/platform_data/serial_pl01x.h>
Leo Yan7b7d7e32024-10-25 18:18:21 +010010#include <cpu_func.h>
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010011#include <env.h>
Boyan Karatotev898f4b92024-10-25 18:18:15 +010012#include <linux/sizes.h>
13
Usama Arif9218a112020-08-12 16:12:53 +010014#include <asm/armv8/mmu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010016#include <asm/system.h>
Usama Arif9218a112020-08-12 16:12:53 +010017
Leo Yan7b7d7e32024-10-25 18:18:21 +010018/* +1 is end of list which needs to be empty */
19#define TC_MEM_MAP_MAX (1 + CONFIG_NR_DRAM_BANKS + 1)
20
21static struct mm_region total_compute_mem_map[TC_MEM_MAP_MAX] = {
Usama Arif9218a112020-08-12 16:12:53 +010022 {
23 .virt = 0x0UL,
24 .phys = 0x0UL,
25 .size = 0x80000000UL,
26 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
27 PTE_BLOCK_NON_SHARE |
28 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Usama Arif9218a112020-08-12 16:12:53 +010029 }
30};
31
32struct mm_region *mem_map = total_compute_mem_map;
33
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010034/*
35 * Push the variable into the .data section so that it
36 * does not get cleared later.
37 */
38unsigned long __section(".data") fw_dtb_pointer;
39
Simon Glass94086b22024-11-02 11:49:42 -060040int board_fdt_blob_setup(void **fdtp)
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010041{
Simon Glass94086b22024-11-02 11:49:42 -060042 if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
43 return -ENXIO;
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010044
Simon Glass94086b22024-11-02 11:49:42 -060045 *fdtp = (void *)fw_dtb_pointer;
46 return 0;
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010047}
48
Boyan Karatotev898f4b92024-10-25 18:18:15 +010049int misc_init_r(void)
50{
51 size_t base;
52
53 if (!env_get("fdt_addr_r"))
54 env_set_hex("fdt_addr_r", fw_dtb_pointer);
55
56 if (!env_get("kernel_addr_r")) {
57 /*
58 * The kernel has to be 2M aligned and the first 64K at the
59 * start of SDRAM is reserved for DTB.
60 */
61 base = gd->ram_base + SZ_2M;
62 assert(IS_ALIGNED(base, SZ_2M));
63
64 env_set_hex("kernel_addr_r", base);
65 }
66
67 return 0;
68}
69
Usama Arif9218a112020-08-12 16:12:53 +010070int board_init(void)
71{
72 return 0;
73}
74
75int dram_init(void)
76{
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010077 return fdtdec_setup_mem_size_base();
Usama Arif9218a112020-08-12 16:12:53 +010078}
79
80int dram_init_banksize(void)
81{
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010082 return fdtdec_setup_memory_banksize();
Usama Arif9218a112020-08-12 16:12:53 +010083}
84
Leo Yan7b7d7e32024-10-25 18:18:21 +010085void build_mem_map(void)
86{
87 int i;
88
89 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
90 /*
91 * The first node is for I/O device, start from node 1 for
92 * updating DRAM info.
93 */
94 mem_map[i + 1].virt = gd->bd->bi_dram[i].start;
95 mem_map[i + 1].phys = gd->bd->bi_dram[i].start;
96 mem_map[i + 1].size = gd->bd->bi_dram[i].size;
97 mem_map[i + 1].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
98 PTE_BLOCK_INNER_SHARE;
99 }
100}
101
102void enable_caches(void)
103{
104 build_mem_map();
105
106 icache_enable();
107 dcache_enable();
108}
109
110u64 get_page_table_size(void)
111{
112 return SZ_256K;
113}
114
Usama Arif9218a112020-08-12 16:12:53 +0100115/* Nothing to be done here as handled by PSCI interface */
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100116void reset_cpu(void)
Usama Arif9218a112020-08-12 16:12:53 +0100117{
118}