Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com> |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 4 | * (C) Copyright 2018 Neil Armstrong <narmstrong@baylibre.com> |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <net.h> |
Neil Armstrong | 2fbfcbb | 2018-07-27 14:10:00 +0200 | [diff] [blame] | 10 | #include <asm/arch/boot.h> |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 11 | #include <asm/arch/eth.h> |
Neil Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 12 | #include <asm/arch/gx.h> |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 13 | #include <asm/arch/mem.h> |
Maxime Jourdan | 1be090a | 2018-12-11 12:52:04 +0100 | [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 | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 16 | #include <asm/io.h> |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 17 | #include <asm/armv8/mmu.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 18 | #include <linux/printk.h> |
Neil Armstrong | 8b24569 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 19 | #include <linux/sizes.h> |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Neil Armstrong | 2fbfcbb | 2018-07-27 14:10:00 +0200 | [diff] [blame] | 23 | int meson_get_boot_device(void) |
| 24 | { |
| 25 | return readl(GX_AO_SEC_GP_CFG0) & GX_AO_BOOT_DEVICE; |
| 26 | } |
| 27 | |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 28 | /* Configure the reserved memory zones exported by the secure registers |
| 29 | * into EFI and DTB reserved memory entries. |
| 30 | */ |
| 31 | void meson_init_reserved_memory(void *fdt) |
Neil Armstrong | 8b24569 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 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 | */ |
Neil Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 43 | reg = readl(GX_AO_SEC_GP_CFG3); |
Neil Armstrong | 8b24569 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 44 | |
Neil Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 45 | 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 Armstrong | 8b24569 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 48 | |
Neil Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 49 | bl31_start = readl(GX_AO_SEC_GP_CFG5); |
| 50 | bl32_start = readl(GX_AO_SEC_GP_CFG4); |
Neil Armstrong | 8b24569 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 51 | |
| 52 | /* |
Neil Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 53 | * Early Meson GX Firmware revisions did not provide the reserved |
Neil Armstrong | 8b24569 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 54 | * memory zones in the registers, keep fixed memory zone handling. |
| 55 | */ |
Neil Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 56 | if (IS_ENABLED(CONFIG_MESON_GX) && |
Neil Armstrong | 8b24569 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 57 | !reg && !bl31_start && !bl32_start) { |
| 58 | bl31_start = 0x10000000; |
| 59 | bl31_size = 0x200000; |
| 60 | } |
| 61 | |
| 62 | /* Add first 16MiB reserved zone */ |
Neil Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 63 | meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE); |
Neil Armstrong | 8b24569 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 64 | |
| 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 Jourdan | 1be090a | 2018-12-11 12:52:04 +0100 | [diff] [blame] | 72 | |
| 73 | #if defined(CONFIG_VIDEO_MESON) |
| 74 | meson_vpu_rsv_fb(fdt); |
| 75 | #endif |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 78 | phys_size_t get_effective_memsize(void) |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 79 | { |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 80 | /* 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 Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Neil Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 85 | static struct mm_region gx_mem_map[] = { |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 86 | { |
York Sun | c7104e5 | 2016-06-24 16:46:22 -0700 | [diff] [blame] | 87 | .virt = 0x0UL, |
| 88 | .phys = 0x0UL, |
Loic Devulder | c067c58 | 2018-09-25 16:30:35 +0200 | [diff] [blame] | 89 | .size = 0xc0000000UL, |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 90 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 91 | PTE_BLOCK_INNER_SHARE |
| 92 | }, { |
Loic Devulder | c067c58 | 2018-09-25 16:30:35 +0200 | [diff] [blame] | 93 | .virt = 0xc0000000UL, |
| 94 | .phys = 0xc0000000UL, |
| 95 | .size = 0x30000000UL, |
Beniamino Galvani | d1037e4 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 96 | .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 Armstrong | 6e89d92 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 105 | struct mm_region *mem_map = gx_mem_map; |