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