133e33780SJerome Brunet // SPDX-License-Identifier: GPL-2.0+
233e33780SJerome Brunet /*
333e33780SJerome Brunet * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
433e33780SJerome Brunet */
533e33780SJerome Brunet
633e33780SJerome Brunet #include <common.h>
7*d96a782dSNeil Armstrong #include <asm/arch/boot.h>
833e33780SJerome Brunet #include <linux/libfdt.h>
933e33780SJerome Brunet #include <linux/err.h>
1033e33780SJerome Brunet #include <asm/arch/mem.h>
1133e33780SJerome Brunet #include <asm/arch/sm.h>
1233e33780SJerome Brunet #include <asm/armv8/mmu.h>
1333e33780SJerome Brunet #include <asm/unaligned.h>
1433e33780SJerome Brunet #include <efi_loader.h>
1533e33780SJerome Brunet
1633e33780SJerome Brunet DECLARE_GLOBAL_DATA_PTR;
1733e33780SJerome Brunet
board_init(void)18b890acc7SJerome Brunet __weak int board_init(void)
19b890acc7SJerome Brunet {
20b890acc7SJerome Brunet return 0;
21b890acc7SJerome Brunet }
22b890acc7SJerome Brunet
dram_init(void)2333e33780SJerome Brunet int dram_init(void)
2433e33780SJerome Brunet {
2533e33780SJerome Brunet const fdt64_t *val;
2633e33780SJerome Brunet int offset;
2733e33780SJerome Brunet int len;
2833e33780SJerome Brunet
2933e33780SJerome Brunet offset = fdt_path_offset(gd->fdt_blob, "/memory");
3033e33780SJerome Brunet if (offset < 0)
3133e33780SJerome Brunet return -EINVAL;
3233e33780SJerome Brunet
3333e33780SJerome Brunet val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
3433e33780SJerome Brunet if (len < sizeof(*val) * 2)
3533e33780SJerome Brunet return -EINVAL;
3633e33780SJerome Brunet
3733e33780SJerome Brunet /* Use unaligned access since cache is still disabled */
3833e33780SJerome Brunet gd->ram_size = get_unaligned_be64(&val[1]);
3933e33780SJerome Brunet
4033e33780SJerome Brunet return 0;
4133e33780SJerome Brunet }
4233e33780SJerome Brunet
meson_ft_board_setup(void * blob,bd_t * bd)43b890acc7SJerome Brunet __weak int meson_ft_board_setup(void *blob, bd_t *bd)
44b890acc7SJerome Brunet {
45b890acc7SJerome Brunet return 0;
46b890acc7SJerome Brunet }
47b890acc7SJerome Brunet
ft_board_setup(void * blob,bd_t * bd)48b890acc7SJerome Brunet int ft_board_setup(void *blob, bd_t *bd)
49b890acc7SJerome Brunet {
50b890acc7SJerome Brunet meson_init_reserved_memory(blob);
51b890acc7SJerome Brunet
52b890acc7SJerome Brunet return meson_ft_board_setup(blob, bd);
53b890acc7SJerome Brunet }
54b890acc7SJerome Brunet
meson_board_add_reserved_memory(void * fdt,u64 start,u64 size)5533e33780SJerome Brunet void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
5633e33780SJerome Brunet {
5733e33780SJerome Brunet int ret;
5833e33780SJerome Brunet
5933e33780SJerome Brunet ret = fdt_add_mem_rsv(fdt, start, size);
6033e33780SJerome Brunet if (ret)
6133e33780SJerome Brunet printf("Could not reserve zone @ 0x%llx\n", start);
6233e33780SJerome Brunet
6333e33780SJerome Brunet if (IS_ENABLED(CONFIG_EFI_LOADER)) {
6433e33780SJerome Brunet efi_add_memory_map(start,
6533e33780SJerome Brunet ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
6633e33780SJerome Brunet EFI_RESERVED_MEMORY_TYPE, false);
6733e33780SJerome Brunet }
6833e33780SJerome Brunet }
6933e33780SJerome Brunet
meson_set_boot_source(void)70*d96a782dSNeil Armstrong static void meson_set_boot_source(void)
71*d96a782dSNeil Armstrong {
72*d96a782dSNeil Armstrong const char *source;
73*d96a782dSNeil Armstrong
74*d96a782dSNeil Armstrong switch (meson_get_boot_device()) {
75*d96a782dSNeil Armstrong case BOOT_DEVICE_EMMC:
76*d96a782dSNeil Armstrong source = "emmc";
77*d96a782dSNeil Armstrong break;
78*d96a782dSNeil Armstrong
79*d96a782dSNeil Armstrong case BOOT_DEVICE_NAND:
80*d96a782dSNeil Armstrong source = "nand";
81*d96a782dSNeil Armstrong break;
82*d96a782dSNeil Armstrong
83*d96a782dSNeil Armstrong case BOOT_DEVICE_SPI:
84*d96a782dSNeil Armstrong source = "spi";
85*d96a782dSNeil Armstrong break;
86*d96a782dSNeil Armstrong
87*d96a782dSNeil Armstrong case BOOT_DEVICE_SD:
88*d96a782dSNeil Armstrong source = "sd";
89*d96a782dSNeil Armstrong break;
90*d96a782dSNeil Armstrong
91*d96a782dSNeil Armstrong case BOOT_DEVICE_USB:
92*d96a782dSNeil Armstrong source = "usb";
93*d96a782dSNeil Armstrong break;
94*d96a782dSNeil Armstrong
95*d96a782dSNeil Armstrong default:
96*d96a782dSNeil Armstrong source = "unknown";
97*d96a782dSNeil Armstrong }
98*d96a782dSNeil Armstrong
99*d96a782dSNeil Armstrong env_set("boot_source", source);
100*d96a782dSNeil Armstrong }
101*d96a782dSNeil Armstrong
meson_board_late_init(void)102*d96a782dSNeil Armstrong __weak int meson_board_late_init(void)
103*d96a782dSNeil Armstrong {
104*d96a782dSNeil Armstrong return 0;
105*d96a782dSNeil Armstrong }
106*d96a782dSNeil Armstrong
board_late_init(void)107*d96a782dSNeil Armstrong int board_late_init(void)
108*d96a782dSNeil Armstrong {
109*d96a782dSNeil Armstrong meson_set_boot_source();
110*d96a782dSNeil Armstrong
111*d96a782dSNeil Armstrong return meson_board_late_init();
112*d96a782dSNeil Armstrong }
113*d96a782dSNeil Armstrong
reset_cpu(ulong addr)11433e33780SJerome Brunet void reset_cpu(ulong addr)
11533e33780SJerome Brunet {
11633e33780SJerome Brunet psci_system_reset();
11733e33780SJerome Brunet }
118