xref: /openbmc/u-boot/arch/arm/mach-meson/board-common.c (revision 33e3378091391c90a110d93f4c89044b4461fb99)
1*33e33780SJerome Brunet // SPDX-License-Identifier: GPL-2.0+
2*33e33780SJerome Brunet /*
3*33e33780SJerome Brunet  * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
4*33e33780SJerome Brunet  */
5*33e33780SJerome Brunet 
6*33e33780SJerome Brunet #include <common.h>
7*33e33780SJerome Brunet #include <linux/libfdt.h>
8*33e33780SJerome Brunet #include <linux/err.h>
9*33e33780SJerome Brunet #include <asm/arch/mem.h>
10*33e33780SJerome Brunet #include <asm/arch/sm.h>
11*33e33780SJerome Brunet #include <asm/armv8/mmu.h>
12*33e33780SJerome Brunet #include <asm/unaligned.h>
13*33e33780SJerome Brunet #include <efi_loader.h>
14*33e33780SJerome Brunet 
15*33e33780SJerome Brunet DECLARE_GLOBAL_DATA_PTR;
16*33e33780SJerome Brunet 
17*33e33780SJerome Brunet int dram_init(void)
18*33e33780SJerome Brunet {
19*33e33780SJerome Brunet 	const fdt64_t *val;
20*33e33780SJerome Brunet 	int offset;
21*33e33780SJerome Brunet 	int len;
22*33e33780SJerome Brunet 
23*33e33780SJerome Brunet 	offset = fdt_path_offset(gd->fdt_blob, "/memory");
24*33e33780SJerome Brunet 	if (offset < 0)
25*33e33780SJerome Brunet 		return -EINVAL;
26*33e33780SJerome Brunet 
27*33e33780SJerome Brunet 	val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
28*33e33780SJerome Brunet 	if (len < sizeof(*val) * 2)
29*33e33780SJerome Brunet 		return -EINVAL;
30*33e33780SJerome Brunet 
31*33e33780SJerome Brunet 	/* Use unaligned access since cache is still disabled */
32*33e33780SJerome Brunet 	gd->ram_size = get_unaligned_be64(&val[1]);
33*33e33780SJerome Brunet 
34*33e33780SJerome Brunet 	return 0;
35*33e33780SJerome Brunet }
36*33e33780SJerome Brunet 
37*33e33780SJerome Brunet void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
38*33e33780SJerome Brunet {
39*33e33780SJerome Brunet 	int ret;
40*33e33780SJerome Brunet 
41*33e33780SJerome Brunet 	ret = fdt_add_mem_rsv(fdt, start, size);
42*33e33780SJerome Brunet 	if (ret)
43*33e33780SJerome Brunet 		printf("Could not reserve zone @ 0x%llx\n", start);
44*33e33780SJerome Brunet 
45*33e33780SJerome Brunet 	if (IS_ENABLED(CONFIG_EFI_LOADER)) {
46*33e33780SJerome Brunet 		efi_add_memory_map(start,
47*33e33780SJerome Brunet 				   ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
48*33e33780SJerome Brunet 				   EFI_RESERVED_MEMORY_TYPE, false);
49*33e33780SJerome Brunet 	}
50*33e33780SJerome Brunet }
51*33e33780SJerome Brunet 
52*33e33780SJerome Brunet void reset_cpu(ulong addr)
53*33e33780SJerome Brunet {
54*33e33780SJerome Brunet 	psci_system_reset();
55*33e33780SJerome Brunet }
56