Jerome Brunet | 993709a | 2019-02-08 16:23:20 +0100 | [diff] [blame] | 1 | // 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 Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 7 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <net.h> |
Jerome Brunet | 993709a | 2019-02-08 16:23:20 +0100 | [diff] [blame] | 10 | #include <asm/arch/boot.h> |
| 11 | #include <asm/arch/eth.h> |
| 12 | #include <asm/arch/g12a.h> |
| 13 | #include <asm/arch/mem.h> |
Neil Armstrong | ff0d478 | 2019-08-30 14:09:26 +0200 | [diff] [blame] | 14 | #include <asm/arch/meson-vpu.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Jerome Brunet | 993709a | 2019-02-08 16:23:20 +0100 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <asm/armv8/mmu.h> |
| 18 | #include <linux/sizes.h> |
Jerome Brunet | 993709a | 2019-02-08 16:23:20 +0100 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | int 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 | */ |
| 30 | void 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 Armstrong | ff0d478 | 2019-08-30 14:09:26 +0200 | [diff] [blame] | 58 | |
| 59 | #if defined(CONFIG_VIDEO_MESON) |
| 60 | meson_vpu_rsv_fb(fdt); |
| 61 | #endif |
Jerome Brunet | 993709a | 2019-02-08 16:23:20 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | phys_size_t get_effective_memsize(void) |
| 65 | { |
| 66 | /* Size is reported in MiB, convert it in bytes */ |
Neil Armstrong | 8faccdc | 2019-07-22 11:32:50 +0200 | [diff] [blame] | 67 | return min(((readl(G12A_AO_SEC_GP_CFG0) & G12A_AO_MEM_SIZE_MASK) |
| 68 | >> G12A_AO_MEM_SIZE_SHIFT) * SZ_1M, 0xf5000000); |
Jerome Brunet | 993709a | 2019-02-08 16:23:20 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static struct mm_region g12a_mem_map[] = { |
| 72 | { |
| 73 | .virt = 0x0UL, |
| 74 | .phys = 0x0UL, |
Neil Armstrong | 8faccdc | 2019-07-22 11:32:50 +0200 | [diff] [blame] | 75 | .size = 0xf5000000UL, |
Jerome Brunet | 993709a | 2019-02-08 16:23:20 +0100 | [diff] [blame] | 76 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 77 | PTE_BLOCK_INNER_SHARE |
| 78 | }, { |
Neil Armstrong | 8faccdc | 2019-07-22 11:32:50 +0200 | [diff] [blame] | 79 | .virt = 0xf5000000UL, |
| 80 | .phys = 0xf5000000UL, |
| 81 | .size = 0x0b000000UL, |
Jerome Brunet | 993709a | 2019-02-08 16:23:20 +0100 | [diff] [blame] | 82 | .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 | |
| 91 | struct mm_region *mem_map = g12a_mem_map; |