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> 733e33780SJerome Brunet #include <linux/libfdt.h> 833e33780SJerome Brunet #include <linux/err.h> 933e33780SJerome Brunet #include <asm/arch/mem.h> 1033e33780SJerome Brunet #include <asm/arch/sm.h> 1133e33780SJerome Brunet #include <asm/armv8/mmu.h> 1233e33780SJerome Brunet #include <asm/unaligned.h> 1333e33780SJerome Brunet #include <efi_loader.h> 1433e33780SJerome Brunet 1533e33780SJerome Brunet DECLARE_GLOBAL_DATA_PTR; 1633e33780SJerome Brunet 17*b890acc7SJerome Brunet __weak int board_init(void) 18*b890acc7SJerome Brunet { 19*b890acc7SJerome Brunet return 0; 20*b890acc7SJerome Brunet } 21*b890acc7SJerome Brunet 2233e33780SJerome Brunet int dram_init(void) 2333e33780SJerome Brunet { 2433e33780SJerome Brunet const fdt64_t *val; 2533e33780SJerome Brunet int offset; 2633e33780SJerome Brunet int len; 2733e33780SJerome Brunet 2833e33780SJerome Brunet offset = fdt_path_offset(gd->fdt_blob, "/memory"); 2933e33780SJerome Brunet if (offset < 0) 3033e33780SJerome Brunet return -EINVAL; 3133e33780SJerome Brunet 3233e33780SJerome Brunet val = fdt_getprop(gd->fdt_blob, offset, "reg", &len); 3333e33780SJerome Brunet if (len < sizeof(*val) * 2) 3433e33780SJerome Brunet return -EINVAL; 3533e33780SJerome Brunet 3633e33780SJerome Brunet /* Use unaligned access since cache is still disabled */ 3733e33780SJerome Brunet gd->ram_size = get_unaligned_be64(&val[1]); 3833e33780SJerome Brunet 3933e33780SJerome Brunet return 0; 4033e33780SJerome Brunet } 4133e33780SJerome Brunet 42*b890acc7SJerome Brunet __weak int meson_ft_board_setup(void *blob, bd_t *bd) 43*b890acc7SJerome Brunet { 44*b890acc7SJerome Brunet return 0; 45*b890acc7SJerome Brunet } 46*b890acc7SJerome Brunet 47*b890acc7SJerome Brunet int ft_board_setup(void *blob, bd_t *bd) 48*b890acc7SJerome Brunet { 49*b890acc7SJerome Brunet meson_init_reserved_memory(blob); 50*b890acc7SJerome Brunet 51*b890acc7SJerome Brunet return meson_ft_board_setup(blob, bd); 52*b890acc7SJerome Brunet } 53*b890acc7SJerome Brunet 5433e33780SJerome Brunet void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size) 5533e33780SJerome Brunet { 5633e33780SJerome Brunet int ret; 5733e33780SJerome Brunet 5833e33780SJerome Brunet ret = fdt_add_mem_rsv(fdt, start, size); 5933e33780SJerome Brunet if (ret) 6033e33780SJerome Brunet printf("Could not reserve zone @ 0x%llx\n", start); 6133e33780SJerome Brunet 6233e33780SJerome Brunet if (IS_ENABLED(CONFIG_EFI_LOADER)) { 6333e33780SJerome Brunet efi_add_memory_map(start, 6433e33780SJerome Brunet ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT, 6533e33780SJerome Brunet EFI_RESERVED_MEMORY_TYPE, false); 6633e33780SJerome Brunet } 6733e33780SJerome Brunet } 6833e33780SJerome Brunet 6933e33780SJerome Brunet void reset_cpu(ulong addr) 7033e33780SJerome Brunet { 7133e33780SJerome Brunet psci_system_reset(); 7233e33780SJerome Brunet } 73