blob: 0370ed57e205073f431175eea9911e0d31861dab [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Beniamino Galvanid1037e42016-05-08 08:30:16 +02002/*
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
Jerome Brunetf897c4b2018-10-05 17:00:37 +02004 * (C) Copyright 2018 Neil Armstrong <narmstrong@baylibre.com>
Beniamino Galvanid1037e42016-05-08 08:30:16 +02005 */
6
Simon Glass8e16b1e2019-12-28 10:45:05 -07007#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06008#include <net.h>
Neil Armstrong2fbfcbb2018-07-27 14:10:00 +02009#include <asm/arch/boot.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020010#include <asm/arch/eth.h>
Neil Armstrong6e89d922018-04-11 17:13:45 +020011#include <asm/arch/gx.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020012#include <asm/arch/mem.h>
Maxime Jourdan1be090a2018-12-11 12:52:04 +010013#include <asm/arch/meson-vpu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020015#include <asm/io.h>
Beniamino Galvanid1037e42016-05-08 08:30:16 +020016#include <asm/armv8/mmu.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060017#include <linux/printk.h>
Neil Armstrong8b245692017-11-27 10:35:46 +010018#include <linux/sizes.h>
Beniamino Galvanid1037e42016-05-08 08:30:16 +020019
20DECLARE_GLOBAL_DATA_PTR;
21
Neil Armstrong2fbfcbb2018-07-27 14:10:00 +020022int meson_get_boot_device(void)
23{
24 return readl(GX_AO_SEC_GP_CFG0) & GX_AO_BOOT_DEVICE;
25}
26
Jerome Brunetf897c4b2018-10-05 17:00:37 +020027/* 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)
Neil Armstrong8b245692017-11-27 10:35:46 +010031{
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 */
Neil Armstrong6e89d922018-04-11 17:13:45 +020042 reg = readl(GX_AO_SEC_GP_CFG3);
Neil Armstrong8b245692017-11-27 10:35:46 +010043
Neil Armstrong6e89d922018-04-11 17:13:45 +020044 bl31_size = ((reg & GX_AO_BL31_RSVMEM_SIZE_MASK)
45 >> GX_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K;
46 bl32_size = (reg & GX_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K;
Neil Armstrong8b245692017-11-27 10:35:46 +010047
Neil Armstrong6e89d922018-04-11 17:13:45 +020048 bl31_start = readl(GX_AO_SEC_GP_CFG5);
49 bl32_start = readl(GX_AO_SEC_GP_CFG4);
Neil Armstrong8b245692017-11-27 10:35:46 +010050
51 /*
Neil Armstrong6e89d922018-04-11 17:13:45 +020052 * Early Meson GX Firmware revisions did not provide the reserved
Neil Armstrong8b245692017-11-27 10:35:46 +010053 * memory zones in the registers, keep fixed memory zone handling.
54 */
Neil Armstrong6e89d922018-04-11 17:13:45 +020055 if (IS_ENABLED(CONFIG_MESON_GX) &&
Neil Armstrong8b245692017-11-27 10:35:46 +010056 !reg && !bl31_start && !bl32_start) {
57 bl31_start = 0x10000000;
58 bl31_size = 0x200000;
59 }
60
61 /* Add first 16MiB reserved zone */
Neil Armstrong6e89d922018-04-11 17:13:45 +020062 meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE);
Neil Armstrong8b245692017-11-27 10:35:46 +010063
64 /* Add BL31 reserved zone */
65 if (bl31_start && bl31_size)
66 meson_board_add_reserved_memory(fdt, bl31_start, bl31_size);
67
68 /* Add BL32 reserved zone */
69 if (bl32_start && bl32_size)
70 meson_board_add_reserved_memory(fdt, bl32_start, bl32_size);
Maxime Jourdan1be090a2018-12-11 12:52:04 +010071
72#if defined(CONFIG_VIDEO_MESON)
73 meson_vpu_rsv_fb(fdt);
74#endif
Beniamino Galvanid1037e42016-05-08 08:30:16 +020075}
76
Jerome Brunetf897c4b2018-10-05 17:00:37 +020077phys_size_t get_effective_memsize(void)
Beniamino Galvanid1037e42016-05-08 08:30:16 +020078{
Jerome Brunetf897c4b2018-10-05 17:00:37 +020079 /* Size is reported in MiB, convert it in bytes */
80 return ((readl(GX_AO_SEC_GP_CFG0) & GX_AO_MEM_SIZE_MASK)
81 >> GX_AO_MEM_SIZE_SHIFT) * SZ_1M;
Beniamino Galvanid1037e42016-05-08 08:30:16 +020082}
83
Neil Armstrong6e89d922018-04-11 17:13:45 +020084static struct mm_region gx_mem_map[] = {
Beniamino Galvanid1037e42016-05-08 08:30:16 +020085 {
York Sunc7104e52016-06-24 16:46:22 -070086 .virt = 0x0UL,
87 .phys = 0x0UL,
Loic Devulderc067c582018-09-25 16:30:35 +020088 .size = 0xc0000000UL,
Beniamino Galvanid1037e42016-05-08 08:30:16 +020089 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
90 PTE_BLOCK_INNER_SHARE
91 }, {
Loic Devulderc067c582018-09-25 16:30:35 +020092 .virt = 0xc0000000UL,
93 .phys = 0xc0000000UL,
94 .size = 0x30000000UL,
Beniamino Galvanid1037e42016-05-08 08:30:16 +020095 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
96 PTE_BLOCK_NON_SHARE |
97 PTE_BLOCK_PXN | PTE_BLOCK_UXN
98 }, {
99 /* List terminator */
100 0,
101 }
102};
103
Neil Armstrong6e89d922018-04-11 17:13:45 +0200104struct mm_region *mem_map = gx_mem_map;