blob: dc4abe1e107469c8cdd3917fcecbcbb774632449 [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
Simon Glass8e16b1e2019-12-28 10:45:05 -07007#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Jerome Brunet993709a2019-02-08 16:23:20 +010010#include <asm/arch/boot.h>
11#include <asm/arch/eth.h>
12#include <asm/arch/g12a.h>
13#include <asm/arch/mem.h>
Neil Armstrongff0d4782019-08-30 14:09:26 +020014#include <asm/arch/meson-vpu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Jerome Brunet993709a2019-02-08 16:23:20 +010016#include <asm/io.h>
17#include <asm/armv8/mmu.h>
18#include <linux/sizes.h>
Jerome Brunet993709a2019-02-08 16:23:20 +010019
20DECLARE_GLOBAL_DATA_PTR;
21
22int meson_get_boot_device(void)
23{
24 return readl(G12A_AO_SEC_GP_CFG0) & G12A_AO_BOOT_DEVICE;
25}
26
27/* Configure the reserved memory zones exported by the secure registers
28 * into EFI and DTB reserved memory entries.
29 */
30void meson_init_reserved_memory(void *fdt)
31{
32 u64 bl31_size, bl31_start;
33 u64 bl32_size, bl32_start;
34 u32 reg;
35
36 /*
37 * Get ARM Trusted Firmware reserved memory zones in :
38 * - AO_SEC_GP_CFG3: bl32 & bl31 size in KiB, can be 0
39 * - AO_SEC_GP_CFG5: bl31 physical start address, can be NULL
40 * - AO_SEC_GP_CFG4: bl32 physical start address, can be NULL
41 */
42 reg = readl(G12A_AO_SEC_GP_CFG3);
43
44 bl31_size = ((reg & G12A_AO_BL31_RSVMEM_SIZE_MASK)
45 >> G12A_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K;
46 bl32_size = (reg & G12A_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K;
47
48 bl31_start = readl(G12A_AO_SEC_GP_CFG5);
49 bl32_start = readl(G12A_AO_SEC_GP_CFG4);
50
51 /* Add BL31 reserved zone */
52 if (bl31_start && bl31_size)
53 meson_board_add_reserved_memory(fdt, bl31_start, bl31_size);
54
55 /* Add BL32 reserved zone */
56 if (bl32_start && bl32_size)
57 meson_board_add_reserved_memory(fdt, bl32_start, bl32_size);
Neil Armstrongff0d4782019-08-30 14:09:26 +020058
59#if defined(CONFIG_VIDEO_MESON)
60 meson_vpu_rsv_fb(fdt);
61#endif
Jerome Brunet993709a2019-02-08 16:23:20 +010062}
63
64phys_size_t get_effective_memsize(void)
65{
66 /* Size is reported in MiB, convert it in bytes */
Neil Armstrong8faccdc2019-07-22 11:32:50 +020067 return min(((readl(G12A_AO_SEC_GP_CFG0) & G12A_AO_MEM_SIZE_MASK)
68 >> G12A_AO_MEM_SIZE_SHIFT) * SZ_1M, 0xf5000000);
Jerome Brunet993709a2019-02-08 16:23:20 +010069}
70
71static struct mm_region g12a_mem_map[] = {
72 {
73 .virt = 0x0UL,
74 .phys = 0x0UL,
Neil Armstrong8faccdc2019-07-22 11:32:50 +020075 .size = 0xf5000000UL,
Jerome Brunet993709a2019-02-08 16:23:20 +010076 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
77 PTE_BLOCK_INNER_SHARE
78 }, {
Neil Armstrong8faccdc2019-07-22 11:32:50 +020079 .virt = 0xf5000000UL,
80 .phys = 0xf5000000UL,
81 .size = 0x0b000000UL,
Jerome Brunet993709a2019-02-08 16:23:20 +010082 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
83 PTE_BLOCK_NON_SHARE |
84 PTE_BLOCK_PXN | PTE_BLOCK_UXN
85 }, {
86 /* List terminator */
87 0,
88 }
89};
90
91struct mm_region *mem_map = g12a_mem_map;