blob: c3fbdfffeae83687d627e4410e5c434332c6b136 [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
7#include <common.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -07008#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Neil Armstrong2fbfcbb2018-07-27 14:10:00 +020010#include <asm/arch/boot.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020011#include <asm/arch/eth.h>
Neil Armstrong6e89d922018-04-11 17:13:45 +020012#include <asm/arch/gx.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020013#include <asm/arch/mem.h>
Maxime Jourdan1be090a2018-12-11 12:52:04 +010014#include <asm/arch/meson-vpu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020016#include <asm/io.h>
Beniamino Galvanid1037e42016-05-08 08:30:16 +020017#include <asm/armv8/mmu.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060018#include <linux/printk.h>
Neil Armstrong8b245692017-11-27 10:35:46 +010019#include <linux/sizes.h>
Beniamino Galvanid1037e42016-05-08 08:30:16 +020020
21DECLARE_GLOBAL_DATA_PTR;
22
Neil Armstrong2fbfcbb2018-07-27 14:10:00 +020023int meson_get_boot_device(void)
24{
25 return readl(GX_AO_SEC_GP_CFG0) & GX_AO_BOOT_DEVICE;
26}
27
Jerome Brunetf897c4b2018-10-05 17:00:37 +020028/* 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)
Neil Armstrong8b245692017-11-27 10:35:46 +010032{
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 */
Neil Armstrong6e89d922018-04-11 17:13:45 +020043 reg = readl(GX_AO_SEC_GP_CFG3);
Neil Armstrong8b245692017-11-27 10:35:46 +010044
Neil Armstrong6e89d922018-04-11 17:13:45 +020045 bl31_size = ((reg & GX_AO_BL31_RSVMEM_SIZE_MASK)
46 >> GX_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K;
47 bl32_size = (reg & GX_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K;
Neil Armstrong8b245692017-11-27 10:35:46 +010048
Neil Armstrong6e89d922018-04-11 17:13:45 +020049 bl31_start = readl(GX_AO_SEC_GP_CFG5);
50 bl32_start = readl(GX_AO_SEC_GP_CFG4);
Neil Armstrong8b245692017-11-27 10:35:46 +010051
52 /*
Neil Armstrong6e89d922018-04-11 17:13:45 +020053 * Early Meson GX Firmware revisions did not provide the reserved
Neil Armstrong8b245692017-11-27 10:35:46 +010054 * memory zones in the registers, keep fixed memory zone handling.
55 */
Neil Armstrong6e89d922018-04-11 17:13:45 +020056 if (IS_ENABLED(CONFIG_MESON_GX) &&
Neil Armstrong8b245692017-11-27 10:35:46 +010057 !reg && !bl31_start && !bl32_start) {
58 bl31_start = 0x10000000;
59 bl31_size = 0x200000;
60 }
61
62 /* Add first 16MiB reserved zone */
Neil Armstrong6e89d922018-04-11 17:13:45 +020063 meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE);
Neil Armstrong8b245692017-11-27 10:35:46 +010064
65 /* Add BL31 reserved zone */
66 if (bl31_start && bl31_size)
67 meson_board_add_reserved_memory(fdt, bl31_start, bl31_size);
68
69 /* Add BL32 reserved zone */
70 if (bl32_start && bl32_size)
71 meson_board_add_reserved_memory(fdt, bl32_start, bl32_size);
Maxime Jourdan1be090a2018-12-11 12:52:04 +010072
73#if defined(CONFIG_VIDEO_MESON)
74 meson_vpu_rsv_fb(fdt);
75#endif
Beniamino Galvanid1037e42016-05-08 08:30:16 +020076}
77
Jerome Brunetf897c4b2018-10-05 17:00:37 +020078phys_size_t get_effective_memsize(void)
Beniamino Galvanid1037e42016-05-08 08:30:16 +020079{
Jerome Brunetf897c4b2018-10-05 17:00:37 +020080 /* Size is reported in MiB, convert it in bytes */
81 return ((readl(GX_AO_SEC_GP_CFG0) & GX_AO_MEM_SIZE_MASK)
82 >> GX_AO_MEM_SIZE_SHIFT) * SZ_1M;
Beniamino Galvanid1037e42016-05-08 08:30:16 +020083}
84
Neil Armstrong6e89d922018-04-11 17:13:45 +020085static struct mm_region gx_mem_map[] = {
Beniamino Galvanid1037e42016-05-08 08:30:16 +020086 {
York Sunc7104e52016-06-24 16:46:22 -070087 .virt = 0x0UL,
88 .phys = 0x0UL,
Loic Devulderc067c582018-09-25 16:30:35 +020089 .size = 0xc0000000UL,
Beniamino Galvanid1037e42016-05-08 08:30:16 +020090 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
91 PTE_BLOCK_INNER_SHARE
92 }, {
Loic Devulderc067c582018-09-25 16:30:35 +020093 .virt = 0xc0000000UL,
94 .phys = 0xc0000000UL,
95 .size = 0x30000000UL,
Beniamino Galvanid1037e42016-05-08 08:30:16 +020096 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
97 PTE_BLOCK_NON_SHARE |
98 PTE_BLOCK_PXN | PTE_BLOCK_UXN
99 }, {
100 /* List terminator */
101 0,
102 }
103};
104
Neil Armstrong6e89d922018-04-11 17:13:45 +0200105struct mm_region *mem_map = gx_mem_map;