blob: 1336d2eb163287e1293f2b374b93b57f9e36362c [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
40void *board_fdt_blob_setup(int *err)
41{
42 *err = 0;
43 if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) {
44 *err = -ENXIO;
45 return NULL;
46 }
47
48 return (void *)fw_dtb_pointer;
49}
50
Boyan Karatotev898f4b92024-10-25 18:18:15 +010051int misc_init_r(void)
52{
53 size_t base;
54
55 if (!env_get("fdt_addr_r"))
56 env_set_hex("fdt_addr_r", fw_dtb_pointer);
57
58 if (!env_get("kernel_addr_r")) {
59 /*
60 * The kernel has to be 2M aligned and the first 64K at the
61 * start of SDRAM is reserved for DTB.
62 */
63 base = gd->ram_base + SZ_2M;
64 assert(IS_ALIGNED(base, SZ_2M));
65
66 env_set_hex("kernel_addr_r", base);
67 }
68
69 return 0;
70}
71
Usama Arif9218a112020-08-12 16:12:53 +010072int board_init(void)
73{
74 return 0;
75}
76
77int dram_init(void)
78{
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010079 return fdtdec_setup_mem_size_base();
Usama Arif9218a112020-08-12 16:12:53 +010080}
81
82int dram_init_banksize(void)
83{
Boyan Karatotevf5e18c02024-10-25 18:18:14 +010084 return fdtdec_setup_memory_banksize();
Usama Arif9218a112020-08-12 16:12:53 +010085}
86
Leo Yan7b7d7e32024-10-25 18:18:21 +010087void build_mem_map(void)
88{
89 int i;
90
91 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
92 /*
93 * The first node is for I/O device, start from node 1 for
94 * updating DRAM info.
95 */
96 mem_map[i + 1].virt = gd->bd->bi_dram[i].start;
97 mem_map[i + 1].phys = gd->bd->bi_dram[i].start;
98 mem_map[i + 1].size = gd->bd->bi_dram[i].size;
99 mem_map[i + 1].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
100 PTE_BLOCK_INNER_SHARE;
101 }
102}
103
104void enable_caches(void)
105{
106 build_mem_map();
107
108 icache_enable();
109 dcache_enable();
110}
111
112u64 get_page_table_size(void)
113{
114 return SZ_256K;
115}
116
Usama Arif9218a112020-08-12 16:12:53 +0100117/* Nothing to be done here as handled by PSCI interface */
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100118void reset_cpu(void)
Usama Arif9218a112020-08-12 16:12:53 +0100119{
120}