blob: 8c41301674e3eafb67f69f161f80b610c29e7f20 [file] [log] [blame]
Jerome Brunetf897c4b2018-10-05 17:00:37 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
4 */
5
6#include <common.h>
Neil Armstrong2fbfcbb2018-07-27 14:10:00 +02007#include <asm/arch/boot.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +02008#include <linux/libfdt.h>
9#include <linux/err.h>
10#include <asm/arch/mem.h>
11#include <asm/arch/sm.h>
12#include <asm/armv8/mmu.h>
13#include <asm/unaligned.h>
14#include <efi_loader.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Jerome Brunet5c6fa8e2018-10-24 14:57:54 +020018__weak int board_init(void)
19{
20 return 0;
21}
22
Jerome Brunetf897c4b2018-10-05 17:00:37 +020023int dram_init(void)
24{
25 const fdt64_t *val;
26 int offset;
27 int len;
28
29 offset = fdt_path_offset(gd->fdt_blob, "/memory");
30 if (offset < 0)
31 return -EINVAL;
32
33 val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
34 if (len < sizeof(*val) * 2)
35 return -EINVAL;
36
37 /* Use unaligned access since cache is still disabled */
38 gd->ram_size = get_unaligned_be64(&val[1]);
39
40 return 0;
41}
42
Jerome Brunet5c6fa8e2018-10-24 14:57:54 +020043__weak int meson_ft_board_setup(void *blob, bd_t *bd)
44{
45 return 0;
46}
47
48int ft_board_setup(void *blob, bd_t *bd)
49{
50 meson_init_reserved_memory(blob);
51
52 return meson_ft_board_setup(blob, bd);
53}
54
Jerome Brunetf897c4b2018-10-05 17:00:37 +020055void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
56{
57 int ret;
58
59 ret = fdt_add_mem_rsv(fdt, start, size);
60 if (ret)
61 printf("Could not reserve zone @ 0x%llx\n", start);
62
63 if (IS_ENABLED(CONFIG_EFI_LOADER)) {
64 efi_add_memory_map(start,
65 ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
66 EFI_RESERVED_MEMORY_TYPE, false);
67 }
68}
69
Neil Armstrong2fbfcbb2018-07-27 14:10:00 +020070static void meson_set_boot_source(void)
71{
72 const char *source;
73
74 switch (meson_get_boot_device()) {
75 case BOOT_DEVICE_EMMC:
76 source = "emmc";
77 break;
78
79 case BOOT_DEVICE_NAND:
80 source = "nand";
81 break;
82
83 case BOOT_DEVICE_SPI:
84 source = "spi";
85 break;
86
87 case BOOT_DEVICE_SD:
88 source = "sd";
89 break;
90
91 case BOOT_DEVICE_USB:
92 source = "usb";
93 break;
94
95 default:
96 source = "unknown";
97 }
98
99 env_set("boot_source", source);
100}
101
102__weak int meson_board_late_init(void)
103{
104 return 0;
105}
106
107int board_late_init(void)
108{
109 meson_set_boot_source();
110
111 return meson_board_late_init();
112}
113
Jerome Brunetf897c4b2018-10-05 17:00:37 +0200114void reset_cpu(ulong addr)
115{
116 psci_system_reset();
117}