blob: d5a830fb1db8de9c67db41f7013ccc9515f70f4c [file] [log] [blame]
Jerome Brunet993709a2019-02-08 16:23:20 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
4 * (C) Copyright 2018 Neil Armstrong <narmstrong@baylibre.com>
5 */
6
Tom Riniabb9a042024-05-18 20:20:43 -06007#include <common.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -07008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <net.h>
Jerome Brunet993709a2019-02-08 16:23:20 +010011#include <asm/arch/boot.h>
12#include <asm/arch/eth.h>
13#include <asm/arch/g12a.h>
14#include <asm/arch/mem.h>
Neil Armstrongff0d4782019-08-30 14:09:26 +020015#include <asm/arch/meson-vpu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Jerome Brunet993709a2019-02-08 16:23:20 +010017#include <asm/io.h>
18#include <asm/armv8/mmu.h>
19#include <linux/sizes.h>
Jerome Brunet993709a2019-02-08 16:23:20 +010020
21DECLARE_GLOBAL_DATA_PTR;
22
23int meson_get_boot_device(void)
24{
25 return readl(G12A_AO_SEC_GP_CFG0) & G12A_AO_BOOT_DEVICE;
26}
27
28/* Configure the reserved memory zones exported by the secure registers
29 * into EFI and DTB reserved memory entries.
30 */
31void meson_init_reserved_memory(void *fdt)
32{
33 u64 bl31_size, bl31_start;
34 u64 bl32_size, bl32_start;
35 u32 reg;
36
37 /*
38 * Get ARM Trusted Firmware reserved memory zones in :
39 * - AO_SEC_GP_CFG3: bl32 & bl31 size in KiB, can be 0
40 * - AO_SEC_GP_CFG5: bl31 physical start address, can be NULL
41 * - AO_SEC_GP_CFG4: bl32 physical start address, can be NULL
42 */
43 reg = readl(G12A_AO_SEC_GP_CFG3);
44
45 bl31_size = ((reg & G12A_AO_BL31_RSVMEM_SIZE_MASK)
46 >> G12A_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K;
47 bl32_size = (reg & G12A_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K;
48
49 bl31_start = readl(G12A_AO_SEC_GP_CFG5);
50 bl32_start = readl(G12A_AO_SEC_GP_CFG4);
51
52 /* Add BL31 reserved zone */
53 if (bl31_start && bl31_size)
54 meson_board_add_reserved_memory(fdt, bl31_start, bl31_size);
55
56 /* Add BL32 reserved zone */
57 if (bl32_start && bl32_size)
58 meson_board_add_reserved_memory(fdt, bl32_start, bl32_size);
Neil Armstrongff0d4782019-08-30 14:09:26 +020059
60#if defined(CONFIG_VIDEO_MESON)
61 meson_vpu_rsv_fb(fdt);
62#endif
Jerome Brunet993709a2019-02-08 16:23:20 +010063}
64
65phys_size_t get_effective_memsize(void)
66{
67 /* Size is reported in MiB, convert it in bytes */
Neil Armstrong8faccdc2019-07-22 11:32:50 +020068 return min(((readl(G12A_AO_SEC_GP_CFG0) & G12A_AO_MEM_SIZE_MASK)
69 >> G12A_AO_MEM_SIZE_SHIFT) * SZ_1M, 0xf5000000);
Jerome Brunet993709a2019-02-08 16:23:20 +010070}
71
72static struct mm_region g12a_mem_map[] = {
73 {
74 .virt = 0x0UL,
75 .phys = 0x0UL,
Neil Armstrong8faccdc2019-07-22 11:32:50 +020076 .size = 0xf5000000UL,
Jerome Brunet993709a2019-02-08 16:23:20 +010077 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
78 PTE_BLOCK_INNER_SHARE
79 }, {
Neil Armstrong8faccdc2019-07-22 11:32:50 +020080 .virt = 0xf5000000UL,
81 .phys = 0xf5000000UL,
82 .size = 0x0b000000UL,
Jerome Brunet993709a2019-02-08 16:23:20 +010083 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
84 PTE_BLOCK_NON_SHARE |
85 PTE_BLOCK_PXN | PTE_BLOCK_UXN
86 }, {
87 /* List terminator */
88 0,
89 }
90};
91
92struct mm_region *mem_map = g12a_mem_map;