Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 2 | /* |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 3 | * Copyright 2017-2021 NXP |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 4 | * Copyright 2014-2015 Freescale Semiconductor, Inc. |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 8 | #include <clock_legacy.h> |
Simon Glass | 33d1e70 | 2019-11-14 12:57:32 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | db22961 | 2019-08-01 09:46:42 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 12 | #include <hang.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 14 | #include <net.h> |
Simon Glass | f5c208d | 2019-11-14 12:57:20 -0700 | [diff] [blame] | 15 | #include <vsprintf.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 16 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 18 | #include <asm/io.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 19 | #include <asm/ptrace.h> |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 20 | #include <linux/arm-smccc.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 21 | #include <linux/errno.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 22 | #include <asm/system.h> |
Joe Hershberger | 8f454d9 | 2018-07-16 15:33:51 -0500 | [diff] [blame] | 23 | #include <fm_eth.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 24 | #include <asm/armv8/mmu.h> |
| 25 | #include <asm/io.h> |
| 26 | #include <asm/arch/fsl_serdes.h> |
| 27 | #include <asm/arch/soc.h> |
| 28 | #include <asm/arch/cpu.h> |
| 29 | #include <asm/arch/speed.h> |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 30 | #include <fsl_immap.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 31 | #include <asm/arch/mp.h> |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 32 | #include <efi_loader.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 33 | #include <fsl-mc/fsl_mc.h> |
| 34 | #ifdef CONFIG_FSL_ESDHC |
| 35 | #include <fsl_esdhc.h> |
| 36 | #endif |
Hou Zhiqiang | 21c4d55 | 2016-06-28 20:18:15 +0800 | [diff] [blame] | 37 | #include <asm/armv8/sec_firmware.h> |
Shengzhou Liu | 15875a5 | 2016-11-21 11:36:48 +0800 | [diff] [blame] | 38 | #ifdef CONFIG_SYS_FSL_DDR |
Tom Rini | 5618460 | 2022-02-25 11:19:53 -0500 | [diff] [blame] | 39 | #include <fsl_ddr_sdram.h> |
Shengzhou Liu | 15875a5 | 2016-11-21 11:36:48 +0800 | [diff] [blame] | 40 | #include <fsl_ddr.h> |
| 41 | #endif |
Simon Glass | 243182c | 2017-05-17 08:23:06 -0600 | [diff] [blame] | 42 | #include <asm/arch/clock.h> |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 43 | #include <hwconfig.h> |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 44 | #include <fsl_qbman.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 45 | |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 46 | #ifdef CONFIG_TFABOOT |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 47 | #include <env_internal.h> |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 49 | #include <fsl_validate.h> |
| 50 | #endif |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 51 | #endif |
Simon Glass | caefa32 | 2019-11-14 12:57:31 -0700 | [diff] [blame] | 52 | #include <linux/mii.h> |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 53 | #include <dm.h> |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 54 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 55 | DECLARE_GLOBAL_DATA_PTR; |
| 56 | |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 57 | static struct cpu_type cpu_type_list[] = { |
| 58 | CPU_TYPE_ENTRY(LS2080A, LS2080A, 8), |
| 59 | CPU_TYPE_ENTRY(LS2085A, LS2085A, 8), |
| 60 | CPU_TYPE_ENTRY(LS2045A, LS2045A, 4), |
| 61 | CPU_TYPE_ENTRY(LS2088A, LS2088A, 8), |
| 62 | CPU_TYPE_ENTRY(LS2084A, LS2084A, 8), |
| 63 | CPU_TYPE_ENTRY(LS2048A, LS2048A, 4), |
| 64 | CPU_TYPE_ENTRY(LS2044A, LS2044A, 4), |
| 65 | CPU_TYPE_ENTRY(LS2081A, LS2081A, 8), |
| 66 | CPU_TYPE_ENTRY(LS2041A, LS2041A, 4), |
| 67 | CPU_TYPE_ENTRY(LS1043A, LS1043A, 4), |
Hou Zhiqiang | b9aedf9 | 2018-12-20 06:31:17 +0000 | [diff] [blame] | 68 | CPU_TYPE_ENTRY(LS1043A, LS1043A_P23, 4), |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 69 | CPU_TYPE_ENTRY(LS1023A, LS1023A, 2), |
Hou Zhiqiang | b9aedf9 | 2018-12-20 06:31:17 +0000 | [diff] [blame] | 70 | CPU_TYPE_ENTRY(LS1023A, LS1023A_P23, 2), |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 71 | CPU_TYPE_ENTRY(LS1046A, LS1046A, 4), |
| 72 | CPU_TYPE_ENTRY(LS1026A, LS1026A, 2), |
| 73 | CPU_TYPE_ENTRY(LS2040A, LS2040A, 4), |
| 74 | CPU_TYPE_ENTRY(LS1012A, LS1012A, 1), |
Yuantian Tang | f463d75 | 2019-09-18 16:50:52 +0800 | [diff] [blame] | 75 | CPU_TYPE_ENTRY(LS1017A, LS1017A, 1), |
| 76 | CPU_TYPE_ENTRY(LS1018A, LS1018A, 1), |
| 77 | CPU_TYPE_ENTRY(LS1027A, LS1027A, 2), |
Yuantian Tang | 4aefa16 | 2019-04-10 16:43:33 +0800 | [diff] [blame] | 78 | CPU_TYPE_ENTRY(LS1028A, LS1028A, 2), |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 79 | CPU_TYPE_ENTRY(LS1088A, LS1088A, 8), |
| 80 | CPU_TYPE_ENTRY(LS1084A, LS1084A, 8), |
| 81 | CPU_TYPE_ENTRY(LS1048A, LS1048A, 4), |
| 82 | CPU_TYPE_ENTRY(LS1044A, LS1044A, 4), |
Priyanka Jain | ef76b2e | 2018-10-29 09:17:09 +0000 | [diff] [blame] | 83 | CPU_TYPE_ENTRY(LX2160A, LX2160A, 16), |
| 84 | CPU_TYPE_ENTRY(LX2120A, LX2120A, 12), |
| 85 | CPU_TYPE_ENTRY(LX2080A, LX2080A, 8), |
Meenakshi Aggarwal | ccb5d5d | 2020-10-29 19:16:16 +0530 | [diff] [blame] | 86 | CPU_TYPE_ENTRY(LX2162A, LX2162A, 16), |
| 87 | CPU_TYPE_ENTRY(LX2122A, LX2122A, 12), |
| 88 | CPU_TYPE_ENTRY(LX2082A, LX2082A, 8), |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | #define EARLY_PGTABLE_SIZE 0x5000 |
| 92 | static struct mm_region early_map[] = { |
| 93 | #ifdef CONFIG_FSL_LSCH3 |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 94 | { CFG_SYS_FSL_CCSR_BASE, CFG_SYS_FSL_CCSR_BASE, |
| 95 | CFG_SYS_FSL_CCSR_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 96 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 97 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 98 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 99 | { CFG_SYS_FSL_OCRAM_BASE, CFG_SYS_FSL_OCRAM_BASE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 100 | SYS_FSL_OCRAM_SPACE_SIZE, |
| 101 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE |
| 102 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 103 | { CFG_SYS_FSL_QSPI_BASE1, CFG_SYS_FSL_QSPI_BASE1, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 104 | CFG_SYS_FSL_QSPI_SIZE1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 105 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE}, |
| 106 | #ifdef CONFIG_FSL_IFC |
| 107 | /* For IFC Region #1, only the first 4MB is cache-enabled */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 108 | { CFG_SYS_FSL_IFC_BASE1, CFG_SYS_FSL_IFC_BASE1, |
| 109 | CFG_SYS_FSL_IFC_SIZE1_1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 110 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE |
| 111 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 112 | { CFG_SYS_FSL_IFC_BASE1 + CFG_SYS_FSL_IFC_SIZE1_1, |
| 113 | CFG_SYS_FSL_IFC_BASE1 + CFG_SYS_FSL_IFC_SIZE1_1, |
| 114 | CFG_SYS_FSL_IFC_SIZE1 - CFG_SYS_FSL_IFC_SIZE1_1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 115 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE |
| 116 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 117 | { CFG_SYS_FLASH_BASE, CFG_SYS_FSL_IFC_BASE1, |
| 118 | CFG_SYS_FSL_IFC_SIZE1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 119 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE |
| 120 | }, |
| 121 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 122 | { CFG_SYS_FSL_DRAM_BASE1, CFG_SYS_FSL_DRAM_BASE1, |
| 123 | CFG_SYS_FSL_DRAM_SIZE1, |
Rajesh Bhagat | 5efbecf | 2018-11-05 18:01:37 +0000 | [diff] [blame] | 124 | #if defined(CONFIG_TFABOOT) || \ |
| 125 | (defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)) |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 126 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 127 | #else /* Start with nGnRnE and PXN and UXN to prevent speculative access */ |
| 128 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN | |
| 129 | #endif |
| 130 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 131 | }, |
| 132 | #ifdef CONFIG_FSL_IFC |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 133 | /* Map IFC region #2 up to CFG_SYS_FLASH_BASE for NAND boot */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 134 | { CFG_SYS_FSL_IFC_BASE2, CFG_SYS_FSL_IFC_BASE2, |
| 135 | CFG_SYS_FLASH_BASE - CFG_SYS_FSL_IFC_BASE2, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 136 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE |
| 137 | }, |
| 138 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 139 | { CFG_SYS_FSL_DCSR_BASE, CFG_SYS_FSL_DCSR_BASE, |
| 140 | CFG_SYS_FSL_DCSR_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 141 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 142 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 143 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 144 | { CFG_SYS_FSL_DRAM_BASE2, CFG_SYS_FSL_DRAM_BASE2, |
| 145 | CFG_SYS_FSL_DRAM_SIZE2, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 146 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN | |
| 147 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 148 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 149 | #ifdef CFG_SYS_FSL_DRAM_BASE3 |
| 150 | { CFG_SYS_FSL_DRAM_BASE3, CFG_SYS_FSL_DRAM_BASE3, |
| 151 | CFG_SYS_FSL_DRAM_SIZE3, |
Priyanka Jain | 88c2566 | 2018-10-29 09:11:29 +0000 | [diff] [blame] | 152 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN | |
| 153 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 154 | }, |
| 155 | #endif |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 156 | #elif defined(CONFIG_FSL_LSCH2) |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 157 | { CFG_SYS_FSL_CCSR_BASE, CFG_SYS_FSL_CCSR_BASE, |
| 158 | CFG_SYS_FSL_CCSR_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 159 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 160 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 161 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 162 | { CFG_SYS_FSL_OCRAM_BASE, CFG_SYS_FSL_OCRAM_BASE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 163 | SYS_FSL_OCRAM_SPACE_SIZE, |
| 164 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE |
| 165 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 166 | { CFG_SYS_FSL_DCSR_BASE, CFG_SYS_FSL_DCSR_BASE, |
| 167 | CFG_SYS_FSL_DCSR_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 168 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 169 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 170 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 171 | { CFG_SYS_FSL_QSPI_BASE, CFG_SYS_FSL_QSPI_BASE, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 172 | CFG_SYS_FSL_QSPI_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 173 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE |
| 174 | }, |
| 175 | #ifdef CONFIG_FSL_IFC |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 176 | { CFG_SYS_FSL_IFC_BASE, CFG_SYS_FSL_IFC_BASE, |
| 177 | CFG_SYS_FSL_IFC_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 178 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE |
| 179 | }, |
| 180 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 181 | { CFG_SYS_FSL_DRAM_BASE1, CFG_SYS_FSL_DRAM_BASE1, |
| 182 | CFG_SYS_FSL_DRAM_SIZE1, |
Rajesh Bhagat | 5efbecf | 2018-11-05 18:01:37 +0000 | [diff] [blame] | 183 | #if defined(CONFIG_TFABOOT) || \ |
| 184 | (defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)) |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 185 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 186 | #else /* Start with nGnRnE and PXN and UXN to prevent speculative access */ |
| 187 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN | |
| 188 | #endif |
| 189 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 190 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 191 | { CFG_SYS_FSL_DRAM_BASE2, CFG_SYS_FSL_DRAM_BASE2, |
| 192 | CFG_SYS_FSL_DRAM_SIZE2, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 193 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN | |
| 194 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 195 | }, |
| 196 | #endif |
| 197 | {}, /* list terminator */ |
| 198 | }; |
| 199 | |
| 200 | static struct mm_region final_map[] = { |
| 201 | #ifdef CONFIG_FSL_LSCH3 |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 202 | { CFG_SYS_FSL_CCSR_BASE, CFG_SYS_FSL_CCSR_BASE, |
| 203 | CFG_SYS_FSL_CCSR_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 204 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 205 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 206 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 207 | { CFG_SYS_FSL_OCRAM_BASE, CFG_SYS_FSL_OCRAM_BASE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 208 | SYS_FSL_OCRAM_SPACE_SIZE, |
| 209 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE |
| 210 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 211 | { CFG_SYS_FSL_DRAM_BASE1, CFG_SYS_FSL_DRAM_BASE1, |
| 212 | CFG_SYS_FSL_DRAM_SIZE1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 213 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 214 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 215 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 216 | { CFG_SYS_FSL_QSPI_BASE1, CFG_SYS_FSL_QSPI_BASE1, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 217 | CFG_SYS_FSL_QSPI_SIZE1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 218 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 219 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 220 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 221 | { CFG_SYS_FSL_QSPI_BASE2, CFG_SYS_FSL_QSPI_BASE2, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 222 | CFG_SYS_FSL_QSPI_SIZE2, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 223 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 224 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 225 | }, |
| 226 | #ifdef CONFIG_FSL_IFC |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 227 | { CFG_SYS_FSL_IFC_BASE2, CFG_SYS_FSL_IFC_BASE2, |
| 228 | CFG_SYS_FSL_IFC_SIZE2, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 229 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 230 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 231 | }, |
| 232 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 233 | { CFG_SYS_FSL_DCSR_BASE, CFG_SYS_FSL_DCSR_BASE, |
| 234 | CFG_SYS_FSL_DCSR_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 235 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 236 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 237 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 238 | { CFG_SYS_FSL_MC_BASE, CFG_SYS_FSL_MC_BASE, |
| 239 | CFG_SYS_FSL_MC_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 240 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 241 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 242 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 243 | { CFG_SYS_FSL_NI_BASE, CFG_SYS_FSL_NI_BASE, |
| 244 | CFG_SYS_FSL_NI_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 245 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 246 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 247 | }, |
| 248 | /* For QBMAN portal, only the first 64MB is cache-enabled */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 249 | { CFG_SYS_FSL_QBMAN_BASE, CFG_SYS_FSL_QBMAN_BASE, |
| 250 | CFG_SYS_FSL_QBMAN_SIZE_1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 251 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 252 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN | PTE_BLOCK_NS |
| 253 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 254 | { CFG_SYS_FSL_QBMAN_BASE + CFG_SYS_FSL_QBMAN_SIZE_1, |
| 255 | CFG_SYS_FSL_QBMAN_BASE + CFG_SYS_FSL_QBMAN_SIZE_1, |
| 256 | CFG_SYS_FSL_QBMAN_SIZE - CFG_SYS_FSL_QBMAN_SIZE_1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 257 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 258 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 259 | }, |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 260 | { CFG_SYS_PCIE1_PHYS_ADDR, CFG_SYS_PCIE1_PHYS_ADDR, |
| 261 | CFG_SYS_PCIE1_PHYS_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 262 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 263 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 264 | }, |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 265 | { CFG_SYS_PCIE2_PHYS_ADDR, CFG_SYS_PCIE2_PHYS_ADDR, |
| 266 | CFG_SYS_PCIE2_PHYS_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 267 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 268 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 269 | }, |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 270 | #ifdef CFG_SYS_PCIE3_PHYS_ADDR |
| 271 | { CFG_SYS_PCIE3_PHYS_ADDR, CFG_SYS_PCIE3_PHYS_ADDR, |
| 272 | CFG_SYS_PCIE3_PHYS_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 273 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 274 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 275 | }, |
Yuantian Tang | 4aefa16 | 2019-04-10 16:43:33 +0800 | [diff] [blame] | 276 | #endif |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 277 | #ifdef CFG_SYS_PCIE4_PHYS_ADDR |
| 278 | { CFG_SYS_PCIE4_PHYS_ADDR, CFG_SYS_PCIE4_PHYS_ADDR, |
| 279 | CFG_SYS_PCIE4_PHYS_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 280 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 281 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 282 | }, |
| 283 | #endif |
Hou Zhiqiang | d08f970 | 2019-04-08 10:15:41 +0000 | [diff] [blame] | 284 | #ifdef SYS_PCIE5_PHYS_ADDR |
| 285 | { SYS_PCIE5_PHYS_ADDR, SYS_PCIE5_PHYS_ADDR, |
| 286 | SYS_PCIE5_PHYS_SIZE, |
| 287 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 288 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 289 | }, |
| 290 | #endif |
| 291 | #ifdef SYS_PCIE6_PHYS_ADDR |
| 292 | { SYS_PCIE6_PHYS_ADDR, SYS_PCIE6_PHYS_ADDR, |
| 293 | SYS_PCIE6_PHYS_SIZE, |
| 294 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 295 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 296 | }, |
| 297 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 298 | { CFG_SYS_FSL_WRIOP1_BASE, CFG_SYS_FSL_WRIOP1_BASE, |
| 299 | CFG_SYS_FSL_WRIOP1_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 300 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 301 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 302 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 303 | { CFG_SYS_FSL_AIOP1_BASE, CFG_SYS_FSL_AIOP1_BASE, |
| 304 | CFG_SYS_FSL_AIOP1_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 305 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 306 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 307 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 308 | { CFG_SYS_FSL_PEBUF_BASE, CFG_SYS_FSL_PEBUF_BASE, |
| 309 | CFG_SYS_FSL_PEBUF_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 310 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 311 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 312 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 313 | { CFG_SYS_FSL_DRAM_BASE2, CFG_SYS_FSL_DRAM_BASE2, |
| 314 | CFG_SYS_FSL_DRAM_SIZE2, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 315 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 316 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 317 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 318 | #ifdef CFG_SYS_FSL_DRAM_BASE3 |
| 319 | { CFG_SYS_FSL_DRAM_BASE3, CFG_SYS_FSL_DRAM_BASE3, |
| 320 | CFG_SYS_FSL_DRAM_SIZE3, |
Priyanka Jain | 88c2566 | 2018-10-29 09:11:29 +0000 | [diff] [blame] | 321 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 322 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 323 | }, |
| 324 | #endif |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 325 | #elif defined(CONFIG_FSL_LSCH2) |
| 326 | { CONFIG_SYS_FSL_BOOTROM_BASE, CONFIG_SYS_FSL_BOOTROM_BASE, |
| 327 | CONFIG_SYS_FSL_BOOTROM_SIZE, |
| 328 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 329 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 330 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 331 | { CFG_SYS_FSL_CCSR_BASE, CFG_SYS_FSL_CCSR_BASE, |
| 332 | CFG_SYS_FSL_CCSR_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 333 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 334 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 335 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 336 | { CFG_SYS_FSL_OCRAM_BASE, CFG_SYS_FSL_OCRAM_BASE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 337 | SYS_FSL_OCRAM_SPACE_SIZE, |
| 338 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE |
| 339 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 340 | { CFG_SYS_FSL_DCSR_BASE, CFG_SYS_FSL_DCSR_BASE, |
| 341 | CFG_SYS_FSL_DCSR_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 342 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 343 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 344 | }, |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 345 | { CFG_SYS_FSL_QSPI_BASE, CFG_SYS_FSL_QSPI_BASE, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 346 | CFG_SYS_FSL_QSPI_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 347 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 348 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 349 | }, |
| 350 | #ifdef CONFIG_FSL_IFC |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 351 | { CFG_SYS_FSL_IFC_BASE, CFG_SYS_FSL_IFC_BASE, |
| 352 | CFG_SYS_FSL_IFC_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 353 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE |
| 354 | }, |
| 355 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 356 | { CFG_SYS_FSL_DRAM_BASE1, CFG_SYS_FSL_DRAM_BASE1, |
| 357 | CFG_SYS_FSL_DRAM_SIZE1, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 358 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 359 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 360 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 361 | { CFG_SYS_FSL_QBMAN_BASE, CFG_SYS_FSL_QBMAN_BASE, |
| 362 | CFG_SYS_FSL_QBMAN_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 363 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 364 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 365 | }, |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 366 | { CFG_SYS_FSL_DRAM_BASE2, CFG_SYS_FSL_DRAM_BASE2, |
| 367 | CFG_SYS_FSL_DRAM_SIZE2, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 368 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 369 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 370 | }, |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 371 | { CFG_SYS_PCIE1_PHYS_ADDR, CFG_SYS_PCIE1_PHYS_ADDR, |
| 372 | CFG_SYS_PCIE1_PHYS_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 373 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 374 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 375 | }, |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 376 | { CFG_SYS_PCIE2_PHYS_ADDR, CFG_SYS_PCIE2_PHYS_ADDR, |
| 377 | CFG_SYS_PCIE2_PHYS_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 378 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 379 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 380 | }, |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 381 | #ifdef CFG_SYS_PCIE3_PHYS_ADDR |
| 382 | { CFG_SYS_PCIE3_PHYS_ADDR, CFG_SYS_PCIE3_PHYS_ADDR, |
| 383 | CFG_SYS_PCIE3_PHYS_SIZE, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 384 | PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 385 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 386 | }, |
Yuantian Tang | 4aefa16 | 2019-04-10 16:43:33 +0800 | [diff] [blame] | 387 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 388 | { CFG_SYS_FSL_DRAM_BASE3, CFG_SYS_FSL_DRAM_BASE3, |
| 389 | CFG_SYS_FSL_DRAM_SIZE3, |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 390 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 391 | PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS |
| 392 | }, |
| 393 | #endif |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 394 | #ifdef CFG_SYS_MEM_RESERVE_SECURE |
York Sun | ef4cef9 | 2018-11-05 18:01:06 +0000 | [diff] [blame] | 395 | {}, /* space holder for secure mem */ |
| 396 | #endif |
| 397 | {}, |
| 398 | }; |
| 399 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 400 | struct mm_region *mem_map = early_map; |
Alexander Graf | ce0a64e | 2016-03-04 01:09:54 +0100 | [diff] [blame] | 401 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 402 | void cpu_name(char *name) |
| 403 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 404 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 405 | unsigned int i, svr, ver; |
| 406 | |
| 407 | svr = gur_in32(&gur->svr); |
| 408 | ver = SVR_SOC_VER(svr); |
| 409 | |
| 410 | for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++) |
| 411 | if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) { |
| 412 | strcpy(name, cpu_type_list[i].name); |
Meenakshi Aggarwal | ccb5d5d | 2020-10-29 19:16:16 +0530 | [diff] [blame] | 413 | #if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A) |
Priyanka Jain | ef76b2e | 2018-10-29 09:17:09 +0000 | [diff] [blame] | 414 | if (IS_C_PROCESSOR(svr)) |
| 415 | strcat(name, "C"); |
| 416 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 417 | |
| 418 | if (IS_E_PROCESSOR(svr)) |
| 419 | strcat(name, "E"); |
Wenbin Song | 863a33a | 2016-09-13 16:13:54 +0800 | [diff] [blame] | 420 | |
| 421 | sprintf(name + strlen(name), " Rev%d.%d", |
| 422 | SVR_MAJ(svr), SVR_MIN(svr)); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 423 | break; |
| 424 | } |
| 425 | |
| 426 | if (i == ARRAY_SIZE(cpu_type_list)) |
| 427 | strcpy(name, "unknown"); |
| 428 | } |
| 429 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 430 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 431 | /* |
| 432 | * To start MMU before DDR is available, we create MMU table in SRAM. |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 433 | * The base address of SRAM is CFG_SYS_FSL_OCRAM_BASE. We use three |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 434 | * levels of translation tables here to cover 40-bit address space. |
| 435 | * We use 4KB granule size, with 40 bits physical address, T0SZ=24 |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 436 | * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose. |
| 437 | * Note, the debug print in cache_v8.c is not usable for debugging |
| 438 | * these early MMU tables because UART is not yet available. |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 439 | */ |
| 440 | static inline void early_mmu_setup(void) |
| 441 | { |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 442 | unsigned int el = current_el(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 443 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 444 | /* global data is already setup, no allocation yet */ |
Pankit Garg | c4d39eb | 2018-11-05 18:01:28 +0000 | [diff] [blame] | 445 | if (el == 3) |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 446 | gd->arch.tlb_addr = CFG_SYS_FSL_OCRAM_BASE; |
Pankit Garg | c4d39eb | 2018-11-05 18:01:28 +0000 | [diff] [blame] | 447 | else |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 448 | gd->arch.tlb_addr = CFG_SYS_DDR_SDRAM_BASE; |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 449 | gd->arch.tlb_fillptr = gd->arch.tlb_addr; |
| 450 | gd->arch.tlb_size = EARLY_PGTABLE_SIZE; |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 451 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 452 | /* Create early page tables */ |
| 453 | setup_pgtables(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 454 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 455 | /* point TTBR to the new table */ |
| 456 | set_ttbr_tcr_mair(el, gd->arch.tlb_addr, |
Andre Przywara | 630a794 | 2022-06-14 00:11:10 +0100 | [diff] [blame] | 457 | get_tcr(NULL, NULL) & |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 458 | ~(TCR_ORGN_MASK | TCR_IRGN_MASK), |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 459 | MEMORY_ATTRIBUTES); |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 460 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 461 | set_sctlr(get_sctlr() | CR_M); |
| 462 | } |
| 463 | |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 464 | static void fix_pcie_mmu_map(void) |
| 465 | { |
York Sun | 4ce6fbf | 2017-03-27 11:41:01 -0700 | [diff] [blame] | 466 | #ifdef CONFIG_ARCH_LS2080A |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 467 | unsigned int i; |
| 468 | u32 svr, ver; |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 469 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 470 | |
| 471 | svr = gur_in32(&gur->svr); |
| 472 | ver = SVR_SOC_VER(svr); |
| 473 | |
| 474 | /* Fix PCIE base and size for LS2088A */ |
| 475 | if ((ver == SVR_LS2088A) || (ver == SVR_LS2084A) || |
Priyanka Jain | 2b36178 | 2017-04-27 15:08:06 +0530 | [diff] [blame] | 476 | (ver == SVR_LS2048A) || (ver == SVR_LS2044A) || |
| 477 | (ver == SVR_LS2081A) || (ver == SVR_LS2041A)) { |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 478 | for (i = 0; i < ARRAY_SIZE(final_map); i++) { |
| 479 | switch (final_map[i].phys) { |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 480 | case CFG_SYS_PCIE1_PHYS_ADDR: |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 481 | final_map[i].phys = 0x2000000000ULL; |
| 482 | final_map[i].virt = 0x2000000000ULL; |
| 483 | final_map[i].size = 0x800000000ULL; |
| 484 | break; |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 485 | case CFG_SYS_PCIE2_PHYS_ADDR: |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 486 | final_map[i].phys = 0x2800000000ULL; |
| 487 | final_map[i].virt = 0x2800000000ULL; |
| 488 | final_map[i].size = 0x800000000ULL; |
| 489 | break; |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 490 | #ifdef CFG_SYS_PCIE3_PHYS_ADDR |
| 491 | case CFG_SYS_PCIE3_PHYS_ADDR: |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 492 | final_map[i].phys = 0x3000000000ULL; |
| 493 | final_map[i].virt = 0x3000000000ULL; |
| 494 | final_map[i].size = 0x800000000ULL; |
| 495 | break; |
Yuantian Tang | 4aefa16 | 2019-04-10 16:43:33 +0800 | [diff] [blame] | 496 | #endif |
Tom Rini | 56af659 | 2022-11-16 13:10:33 -0500 | [diff] [blame] | 497 | #ifdef CFG_SYS_PCIE4_PHYS_ADDR |
| 498 | case CFG_SYS_PCIE4_PHYS_ADDR: |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 499 | final_map[i].phys = 0x3800000000ULL; |
| 500 | final_map[i].virt = 0x3800000000ULL; |
| 501 | final_map[i].size = 0x800000000ULL; |
| 502 | break; |
Hou Zhiqiang | d5d1ce3 | 2019-04-08 10:15:32 +0000 | [diff] [blame] | 503 | #endif |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 504 | default: |
| 505 | break; |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | #endif |
| 510 | } |
| 511 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 512 | /* |
| 513 | * The final tables look similar to early tables, but different in detail. |
| 514 | * These tables are in DRAM. Sub tables are added to enable cache for |
| 515 | * QBMan and OCRAM. |
| 516 | * |
York Sun | 1ef95cc | 2016-06-24 16:46:18 -0700 | [diff] [blame] | 517 | * Put the MMU table in secure memory if gd->arch.secure_ram is valid. |
| 518 | * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0. |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 519 | */ |
| 520 | static inline void final_mmu_setup(void) |
| 521 | { |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 522 | u64 tlb_addr_save = gd->arch.tlb_addr; |
York Sun | 0804d56 | 2015-12-04 11:57:08 -0800 | [diff] [blame] | 523 | unsigned int el = current_el(); |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 524 | int index; |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 525 | |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 526 | /* fix the final_map before filling in the block entries */ |
| 527 | fix_pcie_mmu_map(); |
| 528 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 529 | mem_map = final_map; |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 530 | |
York Sun | 75488ed | 2017-03-06 09:02:30 -0800 | [diff] [blame] | 531 | /* Update mapping for DDR to actual size */ |
| 532 | for (index = 0; index < ARRAY_SIZE(final_map) - 2; index++) { |
| 533 | /* |
| 534 | * Find the entry for DDR mapping and update the address and |
| 535 | * size. Zero-sized mapping will be skipped when creating MMU |
| 536 | * table. |
| 537 | */ |
| 538 | switch (final_map[index].virt) { |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 539 | case CFG_SYS_FSL_DRAM_BASE1: |
York Sun | 75488ed | 2017-03-06 09:02:30 -0800 | [diff] [blame] | 540 | final_map[index].virt = gd->bd->bi_dram[0].start; |
| 541 | final_map[index].phys = gd->bd->bi_dram[0].start; |
| 542 | final_map[index].size = gd->bd->bi_dram[0].size; |
| 543 | break; |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 544 | #ifdef CFG_SYS_FSL_DRAM_BASE2 |
| 545 | case CFG_SYS_FSL_DRAM_BASE2: |
York Sun | 75488ed | 2017-03-06 09:02:30 -0800 | [diff] [blame] | 546 | #if (CONFIG_NR_DRAM_BANKS >= 2) |
| 547 | final_map[index].virt = gd->bd->bi_dram[1].start; |
| 548 | final_map[index].phys = gd->bd->bi_dram[1].start; |
| 549 | final_map[index].size = gd->bd->bi_dram[1].size; |
| 550 | #else |
| 551 | final_map[index].size = 0; |
| 552 | #endif |
| 553 | break; |
| 554 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 555 | #ifdef CFG_SYS_FSL_DRAM_BASE3 |
| 556 | case CFG_SYS_FSL_DRAM_BASE3: |
York Sun | 75488ed | 2017-03-06 09:02:30 -0800 | [diff] [blame] | 557 | #if (CONFIG_NR_DRAM_BANKS >= 3) |
| 558 | final_map[index].virt = gd->bd->bi_dram[2].start; |
| 559 | final_map[index].phys = gd->bd->bi_dram[2].start; |
| 560 | final_map[index].size = gd->bd->bi_dram[2].size; |
| 561 | #else |
| 562 | final_map[index].size = 0; |
| 563 | #endif |
| 564 | break; |
| 565 | #endif |
| 566 | default: |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 571 | #ifdef CFG_SYS_MEM_RESERVE_SECURE |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 572 | if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) { |
| 573 | if (el == 3) { |
| 574 | /* |
| 575 | * Only use gd->arch.secure_ram if the address is |
| 576 | * recalculated. Align to 4KB for MMU table. |
| 577 | */ |
| 578 | /* put page tables in secure ram */ |
| 579 | index = ARRAY_SIZE(final_map) - 2; |
| 580 | gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff; |
| 581 | final_map[index].virt = gd->arch.secure_ram & ~0x3; |
| 582 | final_map[index].phys = final_map[index].virt; |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 583 | final_map[index].size = CFG_SYS_MEM_RESERVE_SECURE; |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 584 | final_map[index].attrs = PTE_BLOCK_OUTER_SHARE; |
York Sun | 1ef95cc | 2016-06-24 16:46:18 -0700 | [diff] [blame] | 585 | gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED; |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 586 | tlb_addr_save = gd->arch.tlb_addr; |
York Sun | 0804d56 | 2015-12-04 11:57:08 -0800 | [diff] [blame] | 587 | } else { |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 588 | /* Use allocated (board_f.c) memory for TLB */ |
| 589 | tlb_addr_save = gd->arch.tlb_allocated; |
| 590 | gd->arch.tlb_addr = tlb_addr_save; |
York Sun | 0804d56 | 2015-12-04 11:57:08 -0800 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 594 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 595 | /* Reset the fill ptr */ |
| 596 | gd->arch.tlb_fillptr = tlb_addr_save; |
| 597 | |
| 598 | /* Create normal system page tables */ |
| 599 | setup_pgtables(); |
| 600 | |
| 601 | /* Create emergency page tables */ |
| 602 | gd->arch.tlb_addr = gd->arch.tlb_fillptr; |
| 603 | gd->arch.tlb_emerg = gd->arch.tlb_addr; |
| 604 | setup_pgtables(); |
| 605 | gd->arch.tlb_addr = tlb_addr_save; |
| 606 | |
York Sun | cf64ced | 2017-03-06 09:02:31 -0800 | [diff] [blame] | 607 | /* Disable cache and MMU */ |
| 608 | dcache_disable(); /* TLBs are invalidated */ |
| 609 | invalidate_icache_all(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 610 | |
| 611 | /* point TTBR to the new table */ |
Andre Przywara | 630a794 | 2022-06-14 00:11:10 +0100 | [diff] [blame] | 612 | set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(NULL, NULL), |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 613 | MEMORY_ATTRIBUTES); |
York Sun | cf64ced | 2017-03-06 09:02:31 -0800 | [diff] [blame] | 614 | |
York Sun | eb6eac1 | 2016-07-22 10:52:23 -0700 | [diff] [blame] | 615 | set_sctlr(get_sctlr() | CR_M); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 616 | } |
| 617 | |
Alexander Graf | bc78b92 | 2016-03-21 20:26:12 +0100 | [diff] [blame] | 618 | u64 get_page_table_size(void) |
| 619 | { |
| 620 | return 0x10000; |
| 621 | } |
| 622 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 623 | int arch_cpu_init(void) |
| 624 | { |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 625 | /* |
| 626 | * This function is called before U-Boot relocates itself to speed up |
| 627 | * on system running. It is not necessary to run if performance is not |
| 628 | * critical. Skip if MMU is already enabled by SPL or other means. |
| 629 | */ |
| 630 | if (get_sctlr() & CR_M) |
| 631 | return 0; |
| 632 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 633 | icache_enable(); |
| 634 | __asm_invalidate_dcache_all(); |
| 635 | __asm_invalidate_tlb_all(); |
| 636 | early_mmu_setup(); |
| 637 | set_sctlr(get_sctlr() | CR_C); |
| 638 | return 0; |
| 639 | } |
| 640 | |
Hou Zhiqiang | a7befa5 | 2016-06-28 20:18:12 +0800 | [diff] [blame] | 641 | void mmu_setup(void) |
| 642 | { |
| 643 | final_mmu_setup(); |
| 644 | } |
| 645 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 646 | /* |
Hou Zhiqiang | a7befa5 | 2016-06-28 20:18:12 +0800 | [diff] [blame] | 647 | * This function is called from common/board_r.c. |
| 648 | * It recreates MMU table in main memory. |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 649 | */ |
| 650 | void enable_caches(void) |
| 651 | { |
Hou Zhiqiang | a7befa5 | 2016-06-28 20:18:12 +0800 | [diff] [blame] | 652 | mmu_setup(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 653 | __asm_invalidate_tlb_all(); |
Hou Zhiqiang | a7befa5 | 2016-06-28 20:18:12 +0800 | [diff] [blame] | 654 | icache_enable(); |
| 655 | dcache_enable(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 656 | } |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 657 | #endif /* !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 658 | |
| 659 | #ifdef CONFIG_TFABOOT |
| 660 | enum boot_src __get_boot_src(u32 porsr1) |
| 661 | { |
| 662 | enum boot_src src = BOOT_SOURCE_RESERVED; |
| 663 | u32 rcw_src = (porsr1 & RCW_SRC_MASK) >> RCW_SRC_BIT; |
Priyanka Jain | 88c2566 | 2018-10-29 09:11:29 +0000 | [diff] [blame] | 664 | #if !defined(CONFIG_NXP_LSCH3_2) |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 665 | u32 val; |
| 666 | #endif |
| 667 | debug("%s: rcw_src 0x%x\n", __func__, rcw_src); |
| 668 | |
| 669 | #if defined(CONFIG_FSL_LSCH3) |
Priyanka Jain | 88c2566 | 2018-10-29 09:11:29 +0000 | [diff] [blame] | 670 | #if defined(CONFIG_NXP_LSCH3_2) |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 671 | switch (rcw_src) { |
| 672 | case RCW_SRC_SDHC1_VAL: |
| 673 | src = BOOT_SOURCE_SD_MMC; |
| 674 | break; |
| 675 | case RCW_SRC_SDHC2_VAL: |
| 676 | src = BOOT_SOURCE_SD_MMC2; |
| 677 | break; |
| 678 | case RCW_SRC_I2C1_VAL: |
| 679 | src = BOOT_SOURCE_I2C1_EXTENDED; |
| 680 | break; |
| 681 | case RCW_SRC_FLEXSPI_NAND2K_VAL: |
| 682 | src = BOOT_SOURCE_XSPI_NAND; |
| 683 | break; |
| 684 | case RCW_SRC_FLEXSPI_NAND4K_VAL: |
| 685 | src = BOOT_SOURCE_XSPI_NAND; |
| 686 | break; |
| 687 | case RCW_SRC_RESERVED_1_VAL: |
| 688 | src = BOOT_SOURCE_RESERVED; |
| 689 | break; |
| 690 | case RCW_SRC_FLEXSPI_NOR_24B: |
| 691 | src = BOOT_SOURCE_XSPI_NOR; |
| 692 | break; |
| 693 | default: |
| 694 | src = BOOT_SOURCE_RESERVED; |
| 695 | } |
| 696 | #else |
| 697 | val = rcw_src & RCW_SRC_TYPE_MASK; |
| 698 | if (val == RCW_SRC_NOR_VAL) { |
| 699 | val = rcw_src & NOR_TYPE_MASK; |
| 700 | |
| 701 | switch (val) { |
| 702 | case NOR_16B_VAL: |
| 703 | case NOR_32B_VAL: |
| 704 | src = BOOT_SOURCE_IFC_NOR; |
| 705 | break; |
| 706 | default: |
| 707 | src = BOOT_SOURCE_RESERVED; |
| 708 | } |
| 709 | } else { |
| 710 | /* RCW SRC Serial Flash */ |
| 711 | val = rcw_src & RCW_SRC_SERIAL_MASK; |
| 712 | switch (val) { |
| 713 | case RCW_SRC_QSPI_VAL: |
| 714 | /* RCW SRC Serial NOR (QSPI) */ |
| 715 | src = BOOT_SOURCE_QSPI_NOR; |
| 716 | break; |
| 717 | case RCW_SRC_SD_CARD_VAL: |
| 718 | /* RCW SRC SD Card */ |
| 719 | src = BOOT_SOURCE_SD_MMC; |
| 720 | break; |
| 721 | case RCW_SRC_EMMC_VAL: |
| 722 | /* RCW SRC EMMC */ |
Rajesh Bhagat | 5b73c90 | 2018-12-27 04:37:49 +0000 | [diff] [blame] | 723 | src = BOOT_SOURCE_SD_MMC; |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 724 | break; |
| 725 | case RCW_SRC_I2C1_VAL: |
| 726 | /* RCW SRC I2C1 Extended */ |
| 727 | src = BOOT_SOURCE_I2C1_EXTENDED; |
| 728 | break; |
| 729 | default: |
| 730 | src = BOOT_SOURCE_RESERVED; |
| 731 | } |
| 732 | } |
| 733 | #endif |
| 734 | #elif defined(CONFIG_FSL_LSCH2) |
| 735 | /* RCW SRC NAND */ |
| 736 | val = rcw_src & RCW_SRC_NAND_MASK; |
| 737 | if (val == RCW_SRC_NAND_VAL) { |
| 738 | val = rcw_src & NAND_RESERVED_MASK; |
| 739 | if (val != NAND_RESERVED_1 && val != NAND_RESERVED_2) |
| 740 | src = BOOT_SOURCE_IFC_NAND; |
| 741 | |
| 742 | } else { |
| 743 | /* RCW SRC NOR */ |
| 744 | val = rcw_src & RCW_SRC_NOR_MASK; |
| 745 | if (val == NOR_8B_VAL || val == NOR_16B_VAL) { |
| 746 | src = BOOT_SOURCE_IFC_NOR; |
| 747 | } else { |
| 748 | switch (rcw_src) { |
| 749 | case QSPI_VAL1: |
| 750 | case QSPI_VAL2: |
| 751 | src = BOOT_SOURCE_QSPI_NOR; |
| 752 | break; |
| 753 | case SD_VAL: |
| 754 | src = BOOT_SOURCE_SD_MMC; |
| 755 | break; |
| 756 | default: |
| 757 | src = BOOT_SOURCE_RESERVED; |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | #endif |
York Sun | 8f3f4ef | 2018-11-05 18:02:09 +0000 | [diff] [blame] | 762 | |
Simon Glass | 20b7cd6 | 2023-02-05 15:40:55 -0700 | [diff] [blame] | 763 | if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_A010539) && !rcw_src) |
York Sun | 8f3f4ef | 2018-11-05 18:02:09 +0000 | [diff] [blame] | 764 | src = BOOT_SOURCE_QSPI_NOR; |
| 765 | |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 766 | debug("%s: src 0x%x\n", __func__, src); |
| 767 | return src; |
| 768 | } |
| 769 | |
| 770 | enum boot_src get_boot_src(void) |
| 771 | { |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 772 | struct arm_smccc_res res; |
York Sun | 8f3f4ef | 2018-11-05 18:02:09 +0000 | [diff] [blame] | 773 | u32 porsr1 = 0; |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 774 | |
| 775 | #if defined(CONFIG_FSL_LSCH3) |
| 776 | u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE; |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 777 | #elif defined(CONFIG_FSL_LSCH2) |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 778 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
York Sun | 8f3f4ef | 2018-11-05 18:02:09 +0000 | [diff] [blame] | 779 | #endif |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 780 | |
York Sun | 8f3f4ef | 2018-11-05 18:02:09 +0000 | [diff] [blame] | 781 | if (current_el() == 2) { |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 782 | arm_smccc_smc(SIP_SVC_RCW, 0, 0, 0, 0, 0, 0, 0, &res); |
| 783 | if (!res.a0) |
| 784 | porsr1 = res.a1; |
York Sun | 8f3f4ef | 2018-11-05 18:02:09 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | if (current_el() == 3 || !porsr1) { |
| 788 | #ifdef CONFIG_FSL_LSCH3 |
| 789 | porsr1 = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4); |
| 790 | #elif defined(CONFIG_FSL_LSCH2) |
| 791 | porsr1 = in_be32(&gur->porsr1); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 792 | #endif |
York Sun | 8f3f4ef | 2018-11-05 18:02:09 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 795 | debug("%s: porsr1 0x%x\n", __func__, porsr1); |
| 796 | |
| 797 | return __get_boot_src(porsr1); |
| 798 | } |
| 799 | |
| 800 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 801 | int mmc_get_env_dev(void) |
| 802 | { |
| 803 | enum boot_src src = get_boot_src(); |
| 804 | int dev = CONFIG_SYS_MMC_ENV_DEV; |
| 805 | |
| 806 | switch (src) { |
| 807 | case BOOT_SOURCE_SD_MMC: |
| 808 | dev = 0; |
| 809 | break; |
| 810 | case BOOT_SOURCE_SD_MMC2: |
| 811 | dev = 1; |
| 812 | break; |
| 813 | default: |
| 814 | break; |
| 815 | } |
| 816 | |
| 817 | return dev; |
| 818 | } |
| 819 | #endif |
| 820 | |
Marek Vasut | 1137712 | 2022-04-06 02:21:33 +0200 | [diff] [blame] | 821 | enum env_location arch_env_get_location(enum env_operation op, int prio) |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 822 | { |
| 823 | enum boot_src src = get_boot_src(); |
| 824 | enum env_location env_loc = ENVL_NOWHERE; |
| 825 | |
| 826 | if (prio) |
| 827 | return ENVL_UNKNOWN; |
| 828 | |
Udit Agarwal | 5e9720c | 2019-04-23 06:06:04 +0000 | [diff] [blame] | 829 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 830 | return env_loc; |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 831 | #endif |
| 832 | |
Rajesh Bhagat | 583da8b | 2018-11-05 18:01:42 +0000 | [diff] [blame] | 833 | switch (src) { |
| 834 | case BOOT_SOURCE_IFC_NOR: |
| 835 | env_loc = ENVL_FLASH; |
| 836 | break; |
| 837 | case BOOT_SOURCE_QSPI_NOR: |
| 838 | /* FALLTHROUGH */ |
| 839 | case BOOT_SOURCE_XSPI_NOR: |
| 840 | env_loc = ENVL_SPI_FLASH; |
| 841 | break; |
| 842 | case BOOT_SOURCE_IFC_NAND: |
| 843 | /* FALLTHROUGH */ |
| 844 | case BOOT_SOURCE_QSPI_NAND: |
| 845 | /* FALLTHROUGH */ |
| 846 | case BOOT_SOURCE_XSPI_NAND: |
| 847 | env_loc = ENVL_NAND; |
| 848 | break; |
| 849 | case BOOT_SOURCE_SD_MMC: |
| 850 | /* FALLTHROUGH */ |
| 851 | case BOOT_SOURCE_SD_MMC2: |
| 852 | env_loc = ENVL_MMC; |
| 853 | break; |
| 854 | case BOOT_SOURCE_I2C1_EXTENDED: |
| 855 | /* FALLTHROUGH */ |
| 856 | default: |
| 857 | break; |
| 858 | } |
| 859 | |
| 860 | return env_loc; |
| 861 | } |
| 862 | #endif /* CONFIG_TFABOOT */ |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 863 | |
Priyanka Jain | 9a27670 | 2016-11-17 12:29:56 +0530 | [diff] [blame] | 864 | u32 initiator_type(u32 cluster, int init_id) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 865 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 866 | struct ccsr_gur *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 867 | u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK; |
| 868 | u32 type = 0; |
| 869 | |
| 870 | type = gur_in32(&gur->tp_ityp[idx]); |
| 871 | if (type & TP_ITYP_AV) |
| 872 | return type; |
| 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
York Sun | ed7fbe3 | 2016-09-13 12:40:30 -0700 | [diff] [blame] | 877 | u32 cpu_pos_mask(void) |
| 878 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 879 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
York Sun | ed7fbe3 | 2016-09-13 12:40:30 -0700 | [diff] [blame] | 880 | int i = 0; |
| 881 | u32 cluster, type, mask = 0; |
| 882 | |
| 883 | do { |
| 884 | int j; |
| 885 | |
| 886 | cluster = gur_in32(&gur->tp_cluster[i].lower); |
| 887 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 888 | type = initiator_type(cluster, j); |
| 889 | if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)) |
| 890 | mask |= 1 << (i * TP_INIT_PER_CLUSTER + j); |
| 891 | } |
| 892 | i++; |
| 893 | } while ((cluster & TP_CLUSTER_EOC) == 0x0); |
| 894 | |
| 895 | return mask; |
| 896 | } |
| 897 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 898 | u32 cpu_mask(void) |
| 899 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 900 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 901 | int i = 0, count = 0; |
| 902 | u32 cluster, type, mask = 0; |
| 903 | |
| 904 | do { |
| 905 | int j; |
| 906 | |
| 907 | cluster = gur_in32(&gur->tp_cluster[i].lower); |
| 908 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 909 | type = initiator_type(cluster, j); |
| 910 | if (type) { |
| 911 | if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM) |
| 912 | mask |= 1 << count; |
| 913 | count++; |
| 914 | } |
| 915 | } |
| 916 | i++; |
| 917 | } while ((cluster & TP_CLUSTER_EOC) == 0x0); |
| 918 | |
| 919 | return mask; |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * Return the number of cores on this SOC. |
| 924 | */ |
| 925 | int cpu_numcores(void) |
| 926 | { |
| 927 | return hweight32(cpu_mask()); |
| 928 | } |
| 929 | |
| 930 | int fsl_qoriq_core_to_cluster(unsigned int core) |
| 931 | { |
| 932 | struct ccsr_gur __iomem *gur = |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 933 | (void __iomem *)(CFG_SYS_FSL_GUTS_ADDR); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 934 | int i = 0, count = 0; |
| 935 | u32 cluster; |
| 936 | |
| 937 | do { |
| 938 | int j; |
| 939 | |
| 940 | cluster = gur_in32(&gur->tp_cluster[i].lower); |
| 941 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 942 | if (initiator_type(cluster, j)) { |
| 943 | if (count == core) |
| 944 | return i; |
| 945 | count++; |
| 946 | } |
| 947 | } |
| 948 | i++; |
| 949 | } while ((cluster & TP_CLUSTER_EOC) == 0x0); |
| 950 | |
| 951 | return -1; /* cannot identify the cluster */ |
| 952 | } |
| 953 | |
| 954 | u32 fsl_qoriq_core_to_type(unsigned int core) |
| 955 | { |
| 956 | struct ccsr_gur __iomem *gur = |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 957 | (void __iomem *)(CFG_SYS_FSL_GUTS_ADDR); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 958 | int i = 0, count = 0; |
| 959 | u32 cluster, type; |
| 960 | |
| 961 | do { |
| 962 | int j; |
| 963 | |
| 964 | cluster = gur_in32(&gur->tp_cluster[i].lower); |
| 965 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 966 | type = initiator_type(cluster, j); |
| 967 | if (type) { |
| 968 | if (count == core) |
| 969 | return type; |
| 970 | count++; |
| 971 | } |
| 972 | } |
| 973 | i++; |
| 974 | } while ((cluster & TP_CLUSTER_EOC) == 0x0); |
| 975 | |
| 976 | return -1; /* cannot identify the cluster */ |
| 977 | } |
| 978 | |
Priyanka Jain | 96b001f | 2016-11-17 12:29:51 +0530 | [diff] [blame] | 979 | #ifndef CONFIG_FSL_LSCH3 |
Sriram Dash | 9282d26 | 2016-06-13 09:58:32 +0530 | [diff] [blame] | 980 | uint get_svr(void) |
| 981 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 982 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Sriram Dash | 9282d26 | 2016-06-13 09:58:32 +0530 | [diff] [blame] | 983 | |
| 984 | return gur_in32(&gur->svr); |
| 985 | } |
Priyanka Jain | 96b001f | 2016-11-17 12:29:51 +0530 | [diff] [blame] | 986 | #endif |
Sriram Dash | 9282d26 | 2016-06-13 09:58:32 +0530 | [diff] [blame] | 987 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 988 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 989 | int print_cpuinfo(void) |
| 990 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 991 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 992 | struct sys_info sysinfo; |
| 993 | char buf[32]; |
| 994 | unsigned int i, core; |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 995 | u32 type, rcw, svr = gur_in32(&gur->svr); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 996 | |
| 997 | puts("SoC: "); |
| 998 | |
| 999 | cpu_name(buf); |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 1000 | printf(" %s (0x%x)\n", buf, svr); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1001 | memset((u8 *)buf, 0x00, ARRAY_SIZE(buf)); |
| 1002 | get_sys_info(&sysinfo); |
| 1003 | puts("Clock Configuration:"); |
| 1004 | for_each_cpu(i, core, cpu_numcores(), cpu_mask()) { |
| 1005 | if (!(i % 3)) |
| 1006 | puts("\n "); |
| 1007 | type = TP_ITYP_VER(fsl_qoriq_core_to_type(core)); |
| 1008 | printf("CPU%d(%s):%-4s MHz ", core, |
| 1009 | type == TY_ITYP_VER_A7 ? "A7 " : |
| 1010 | (type == TY_ITYP_VER_A53 ? "A53" : |
Alison Wang | 7980839 | 2016-07-05 16:01:52 +0800 | [diff] [blame] | 1011 | (type == TY_ITYP_VER_A57 ? "A57" : |
| 1012 | (type == TY_ITYP_VER_A72 ? "A72" : " "))), |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1013 | strmhz(buf, sysinfo.freq_processor[core])); |
| 1014 | } |
Hou Zhiqiang | 3f91cda | 2017-01-10 16:44:15 +0800 | [diff] [blame] | 1015 | /* Display platform clock as Bus frequency. */ |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1016 | printf("\n Bus: %-4s MHz ", |
Hou Zhiqiang | 3f91cda | 2017-01-10 16:44:15 +0800 | [diff] [blame] | 1017 | strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV)); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1018 | printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus)); |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 1019 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 1020 | printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0])); |
| 1021 | #endif |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 1022 | #ifdef CONFIG_SYS_FSL_HAS_DP_DDR |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 1023 | if (soc_has_dp_ddr()) { |
| 1024 | printf(" DP-DDR: %-4s MT/s", |
| 1025 | strmhz(buf, sysinfo.freq_ddrbus2)); |
| 1026 | } |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1027 | #endif |
| 1028 | puts("\n"); |
| 1029 | |
| 1030 | /* |
| 1031 | * Display the RCW, so that no one gets confused as to what RCW |
| 1032 | * we're actually using for this boot. |
| 1033 | */ |
| 1034 | puts("Reset Configuration Word (RCW):"); |
| 1035 | for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) { |
| 1036 | rcw = gur_in32(&gur->rcwsr[i]); |
| 1037 | if ((i % 4) == 0) |
| 1038 | printf("\n %08x:", i * 4); |
| 1039 | printf(" %08x", rcw); |
| 1040 | } |
| 1041 | puts("\n"); |
| 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | #endif |
| 1046 | |
| 1047 | #ifdef CONFIG_FSL_ESDHC |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1048 | int cpu_mmc_init(struct bd_info *bis) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1049 | { |
| 1050 | return fsl_esdhc_mmc_init(bis); |
| 1051 | } |
| 1052 | #endif |
| 1053 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1054 | int cpu_eth_init(struct bd_info *bis) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1055 | { |
| 1056 | int error = 0; |
| 1057 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 1058 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1059 | error = fsl_mc_ldpaa_init(bis); |
| 1060 | #endif |
| 1061 | return error; |
| 1062 | } |
| 1063 | |
Jiafei Pan | ded62e5 | 2021-04-21 12:12:49 +0800 | [diff] [blame] | 1064 | int check_psci(void) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1065 | { |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 1066 | unsigned int psci_ver; |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 1067 | |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 1068 | psci_ver = sec_firmware_support_psci_version(); |
| 1069 | if (psci_ver == PSCI_INVALID_VER) |
| 1070 | return 1; |
| 1071 | |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 1075 | static void config_core_prefetch(void) |
| 1076 | { |
| 1077 | char *buf = NULL; |
| 1078 | char buffer[HWCONFIG_BUFFER_SIZE]; |
| 1079 | const char *prefetch_arg = NULL; |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1080 | struct arm_smccc_res res; |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 1081 | size_t arglen; |
| 1082 | unsigned int mask; |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 1083 | |
| 1084 | if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0) |
| 1085 | buf = buffer; |
Pankaj Bansal | 6c77277 | 2019-10-31 05:41:09 +0000 | [diff] [blame] | 1086 | else |
| 1087 | return; |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 1088 | |
| 1089 | prefetch_arg = hwconfig_subarg_f("core_prefetch", "disable", |
| 1090 | &arglen, buf); |
| 1091 | |
| 1092 | if (prefetch_arg) { |
| 1093 | mask = simple_strtoul(prefetch_arg, NULL, 0) & 0xff; |
| 1094 | if (mask & 0x1) { |
| 1095 | printf("Core0 prefetch can't be disabled\n"); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | #define SIP_PREFETCH_DISABLE_64 0xC200FF13 |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1100 | arm_smccc_smc(SIP_PREFETCH_DISABLE_64, mask, 0, 0, 0, 0, 0, 0, |
| 1101 | &res); |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 1102 | |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1103 | if (res.a0) |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 1104 | printf("Prefetch disable config failed for mask "); |
| 1105 | else |
| 1106 | printf("Prefetch disable config passed for mask "); |
| 1107 | printf("0x%x\n", mask); |
| 1108 | } |
| 1109 | } |
| 1110 | |
Alex Marginean | 762a268 | 2019-11-27 17:19:32 +0200 | [diff] [blame] | 1111 | #ifdef CONFIG_PCIE_ECAM_GENERIC |
| 1112 | __weak void set_ecam_icids(void) |
| 1113 | { |
| 1114 | } |
| 1115 | #endif |
| 1116 | |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 1117 | int arch_early_init_r(void) |
| 1118 | { |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 1119 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009635 |
Priyanka Jain | 823e042 | 2017-02-14 10:34:31 +0530 | [diff] [blame] | 1120 | u32 svr_dev_id; |
| 1121 | /* |
| 1122 | * erratum A009635 is valid only for LS2080A SoC and |
| 1123 | * its personalitiesi |
| 1124 | */ |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 1125 | svr_dev_id = get_svr(); |
| 1126 | if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A))) |
Priyanka Jain | 823e042 | 2017-02-14 10:34:31 +0530 | [diff] [blame] | 1127 | erratum_a009635(); |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 1128 | #endif |
Shengzhou Liu | 15875a5 | 2016-11-21 11:36:48 +0800 | [diff] [blame] | 1129 | #if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR) |
| 1130 | erratum_a009942_check_cpo(); |
| 1131 | #endif |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 1132 | if (check_psci()) { |
| 1133 | debug("PSCI: PSCI does not exist.\n"); |
| 1134 | |
| 1135 | /* if PSCI does not exist, boot secondary cores here */ |
| 1136 | if (fsl_layerscape_wake_seconday_cores()) |
Hou Zhiqiang | 21c4d55 | 2016-06-28 20:18:15 +0800 | [diff] [blame] | 1137 | printf("Did not wake secondary cores\n"); |
| 1138 | } |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1139 | |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 1140 | config_core_prefetch(); |
| 1141 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1142 | #ifdef CONFIG_SYS_HAS_SERDES |
| 1143 | fsl_serdes_init(); |
| 1144 | #endif |
Pankaj Bansal | cc84062 | 2018-10-29 11:28:26 +0000 | [diff] [blame] | 1145 | #ifdef CONFIG_SYS_FSL_HAS_RGMII |
| 1146 | /* some dpmacs in armv8a based freescale layerscape SOCs can be |
Vladimir Oltean | 6a6e402 | 2021-09-18 15:32:34 +0300 | [diff] [blame] | 1147 | * configured via both serdes(sgmii, 10gbase-r, xlaui etc) bits and via |
Pankaj Bansal | cc84062 | 2018-10-29 11:28:26 +0000 | [diff] [blame] | 1148 | * EC*_PMUX(rgmii) bits in RCW. |
| 1149 | * e.g. dpmac 17 and 18 in LX2160A can be configured as SGMII from |
| 1150 | * serdes bits and as RGMII via EC1_PMUX/EC2_PMUX bits |
Razvan Ionut Cirjan | 912f2d8 | 2020-10-23 16:20:38 +0530 | [diff] [blame] | 1151 | * Now if a dpmac is enabled as RGMII through ECx_PMUX then it takes |
| 1152 | * precedence over SerDes protocol. i.e. in LX2160A if we select serdes |
| 1153 | * protocol that configures dpmac17 as SGMII and set the EC1_PMUX as |
| 1154 | * RGMII, then the dpmac is RGMII and not SGMII. |
Pankaj Bansal | cc84062 | 2018-10-29 11:28:26 +0000 | [diff] [blame] | 1155 | * |
Razvan Ionut Cirjan | 912f2d8 | 2020-10-23 16:20:38 +0530 | [diff] [blame] | 1156 | * Therefore, even thought fsl_rgmii_init is after fsl_serdes_init |
| 1157 | * function of SOC, the dpmac will be enabled as RGMII even if it was |
| 1158 | * also enabled before as SGMII. If ECx_PMUX is not configured for |
| 1159 | * RGMII, DPMAC will remain configured as SGMII from fsl_serdes_init(). |
Pankaj Bansal | cc84062 | 2018-10-29 11:28:26 +0000 | [diff] [blame] | 1160 | */ |
| 1161 | fsl_rgmii_init(); |
| 1162 | #endif |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 1163 | #ifdef CONFIG_FMAN_ENET |
Madalin Bucur | b76b0a6 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 1164 | #ifndef CONFIG_DM_ETH |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 1165 | fman_enet_init(); |
| 1166 | #endif |
Madalin Bucur | b76b0a6 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 1167 | #endif |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 1168 | #ifdef CONFIG_SYS_DPAA_QBMAN |
| 1169 | setup_qbman_portals(); |
| 1170 | #endif |
Alex Marginean | 762a268 | 2019-11-27 17:19:32 +0200 | [diff] [blame] | 1171 | #ifdef CONFIG_PCIE_ECAM_GENERIC |
| 1172 | set_ecam_icids(); |
| 1173 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | int timer_init(void) |
| 1178 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 1179 | u32 __iomem *cntcr = (u32 *)CFG_SYS_FSL_TIMER_ADDR; |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1180 | #ifdef CONFIG_FSL_LSCH3 |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 1181 | u32 __iomem *cltbenr = (u32 *)CFG_SYS_FSL_PMU_CLTBENR; |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1182 | #endif |
Thomas Schaefer | cbec2b8 | 2019-08-08 16:00:30 +0800 | [diff] [blame] | 1183 | #if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \ |
| 1184 | defined(CONFIG_ARCH_LS1028A) |
Yunhui Cui | 3dfb82a | 2016-06-08 10:31:42 +0800 | [diff] [blame] | 1185 | u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET; |
Priyanka Jain | 3d31ec7 | 2016-11-17 12:29:52 +0530 | [diff] [blame] | 1186 | u32 svr_dev_id; |
Yunhui Cui | 3dfb82a | 2016-06-08 10:31:42 +0800 | [diff] [blame] | 1187 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1188 | #ifdef COUNTER_FREQUENCY_REAL |
| 1189 | unsigned long cntfrq = COUNTER_FREQUENCY_REAL; |
| 1190 | |
| 1191 | /* Update with accurate clock frequency */ |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 1192 | if (current_el() == 3) |
| 1193 | asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory"); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1194 | #endif |
| 1195 | |
| 1196 | #ifdef CONFIG_FSL_LSCH3 |
| 1197 | /* Enable timebase for all clusters. |
| 1198 | * It is safe to do so even some clusters are not enabled. |
| 1199 | */ |
| 1200 | out_le32(cltbenr, 0xf); |
| 1201 | #endif |
| 1202 | |
Thomas Schaefer | cbec2b8 | 2019-08-08 16:00:30 +0800 | [diff] [blame] | 1203 | #if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \ |
| 1204 | defined(CONFIG_ARCH_LS1028A) |
Yunhui Cui | 3dfb82a | 2016-06-08 10:31:42 +0800 | [diff] [blame] | 1205 | /* |
| 1206 | * In certain Layerscape SoCs, the clock for each core's |
| 1207 | * has an enable bit in the PMU Physical Core Time Base Enable |
| 1208 | * Register (PCTBENR), which allows the watchdog to operate. |
| 1209 | */ |
| 1210 | setbits_le32(pctbenr, 0xff); |
Priyanka Jain | 3d31ec7 | 2016-11-17 12:29:52 +0530 | [diff] [blame] | 1211 | /* |
| 1212 | * For LS2080A SoC and its personalities, timer controller |
| 1213 | * offset is different |
| 1214 | */ |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 1215 | svr_dev_id = get_svr(); |
| 1216 | if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A))) |
Priyanka Jain | 3d31ec7 | 2016-11-17 12:29:52 +0530 | [diff] [blame] | 1217 | cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR; |
| 1218 | |
Yunhui Cui | 3dfb82a | 2016-06-08 10:31:42 +0800 | [diff] [blame] | 1219 | #endif |
| 1220 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1221 | /* Enable clock for timer |
| 1222 | * This is a global setting. |
| 1223 | */ |
| 1224 | out_le32(cntcr, 0x1); |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
Sean Anderson | dd79e0c | 2022-09-26 12:47:37 -0400 | [diff] [blame] | 1229 | #if !CONFIG_IS_ENABLED(SYSRESET) |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 1230 | __efi_runtime_data u32 __iomem *rstcr = (u32 *)CFG_SYS_FSL_RST_ADDR; |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 1231 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 1232 | void __efi_runtime reset_cpu(void) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1233 | { |
Meenakshi Aggarwal | ccb5d5d | 2020-10-29 19:16:16 +0530 | [diff] [blame] | 1234 | #if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A) |
Meenakshi Aggarwal | 95a805b | 2020-09-09 14:06:05 +0530 | [diff] [blame] | 1235 | /* clear the RST_REQ_MSK and SW_RST_REQ */ |
| 1236 | out_le32(rstcr, 0x0); |
| 1237 | |
| 1238 | /* initiate the sw reset request */ |
| 1239 | out_le32(rstcr, 0x1); |
Priyanka Jain | ef76b2e | 2018-10-29 09:17:09 +0000 | [diff] [blame] | 1240 | #else |
Meenakshi Aggarwal | 95a805b | 2020-09-09 14:06:05 +0530 | [diff] [blame] | 1241 | u32 val; |
| 1242 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1243 | /* Raise RESET_REQ_B */ |
| 1244 | val = scfg_in32(rstcr); |
| 1245 | val |= 0x02; |
| 1246 | scfg_out32(rstcr, val); |
Priyanka Jain | ef76b2e | 2018-10-29 09:17:09 +0000 | [diff] [blame] | 1247 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1248 | } |
Sean Anderson | dd79e0c | 2022-09-26 12:47:37 -0400 | [diff] [blame] | 1249 | #endif |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 1250 | |
Mathew McBride | 8f13773 | 2019-10-18 14:27:54 +1100 | [diff] [blame] | 1251 | #if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_PSCI_RESET) |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 1252 | |
| 1253 | void __efi_runtime EFIAPI efi_reset_system( |
| 1254 | enum efi_reset_type reset_type, |
| 1255 | efi_status_t reset_status, |
| 1256 | unsigned long data_size, void *reset_data) |
| 1257 | { |
| 1258 | switch (reset_type) { |
| 1259 | case EFI_RESET_COLD: |
| 1260 | case EFI_RESET_WARM: |
Heinrich Schuchardt | 450d4c8 | 2018-02-06 22:00:22 +0100 | [diff] [blame] | 1261 | case EFI_RESET_PLATFORM_SPECIFIC: |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 1262 | reset_cpu(); |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 1263 | break; |
| 1264 | case EFI_RESET_SHUTDOWN: |
| 1265 | /* Nothing we can do */ |
| 1266 | break; |
| 1267 | } |
| 1268 | |
| 1269 | while (1) { } |
| 1270 | } |
| 1271 | |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 1272 | efi_status_t efi_reset_system_init(void) |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 1273 | { |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 1274 | return efi_add_runtime_mmio(&rstcr, sizeof(*rstcr)); |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | #endif |
| 1278 | |
York Sun | 2db5408 | 2017-09-07 10:12:32 -0700 | [diff] [blame] | 1279 | /* |
| 1280 | * Calculate reserved memory with given memory bank |
| 1281 | * Return aligned memory size on success |
| 1282 | * Return (ram_size + needed size) for failure |
| 1283 | */ |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 1284 | phys_size_t board_reserve_ram_top(phys_size_t ram_size) |
| 1285 | { |
| 1286 | phys_size_t ram_top = ram_size; |
| 1287 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 1288 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
York Sun | 2db5408 | 2017-09-07 10:12:32 -0700 | [diff] [blame] | 1289 | ram_top = mc_get_dram_block_size(); |
| 1290 | if (ram_top > ram_size) |
| 1291 | return ram_size + ram_top; |
| 1292 | |
| 1293 | ram_top = ram_size - ram_top; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1294 | /* The start address of MC reserved memory needs to be aligned. */ |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 1295 | ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1); |
| 1296 | #endif |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1297 | |
| 1298 | return ram_size - ram_top; |
| 1299 | } |
| 1300 | |
| 1301 | phys_size_t get_effective_memsize(void) |
| 1302 | { |
| 1303 | phys_size_t ea_size, rem = 0; |
| 1304 | |
| 1305 | /* |
| 1306 | * For ARMv8 SoCs, DDR memory is split into two or three regions. The |
Sumit Garg | ed0deea | 2017-10-04 03:20:49 +0530 | [diff] [blame] | 1307 | * first region is 2GB space at 0x8000_0000. Secure memory needs to |
| 1308 | * allocated from first region. If the memory extends to the second |
| 1309 | * region (or the third region if applicable), Management Complex (MC) |
| 1310 | * memory should be put into the highest region, i.e. the end of DDR |
Tom Rini | bc9d46b | 2022-12-04 10:04:50 -0500 | [diff] [blame] | 1311 | * memory. CFG_MAX_MEM_MAPPED is set to the size of first region so |
Sumit Garg | ed0deea | 2017-10-04 03:20:49 +0530 | [diff] [blame] | 1312 | * U-Boot doesn't relocate itself into higher address. Should DDR be |
| 1313 | * configured to skip the first region, this function needs to be |
| 1314 | * adjusted. |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1315 | */ |
Tom Rini | bc9d46b | 2022-12-04 10:04:50 -0500 | [diff] [blame] | 1316 | if (gd->ram_size > CFG_MAX_MEM_MAPPED) { |
| 1317 | ea_size = CFG_MAX_MEM_MAPPED; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1318 | rem = gd->ram_size - ea_size; |
| 1319 | } else { |
| 1320 | ea_size = gd->ram_size; |
| 1321 | } |
| 1322 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1323 | #ifdef CFG_SYS_MEM_RESERVE_SECURE |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1324 | /* Check if we have enough space for secure memory */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1325 | if (ea_size > CFG_SYS_MEM_RESERVE_SECURE) |
| 1326 | ea_size -= CFG_SYS_MEM_RESERVE_SECURE; |
Sumit Garg | ed0deea | 2017-10-04 03:20:49 +0530 | [diff] [blame] | 1327 | else |
| 1328 | printf("Error: No enough space for secure memory.\n"); |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1329 | #endif |
| 1330 | /* Check if we have enough memory for MC */ |
| 1331 | if (rem < board_reserve_ram_top(rem)) { |
| 1332 | /* Not enough memory in high region to reserve */ |
York Sun | 2db5408 | 2017-09-07 10:12:32 -0700 | [diff] [blame] | 1333 | if (ea_size > board_reserve_ram_top(ea_size)) |
| 1334 | ea_size -= board_reserve_ram_top(ea_size); |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1335 | else |
| 1336 | printf("Error: No enough space for reserved memory.\n"); |
| 1337 | } |
| 1338 | |
| 1339 | return ea_size; |
| 1340 | } |
| 1341 | |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1342 | #ifdef CONFIG_TFABOOT |
| 1343 | phys_size_t tfa_get_dram_size(void) |
| 1344 | { |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1345 | struct arm_smccc_res res; |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1346 | |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1347 | arm_smccc_smc(SMC_DRAM_BANK_INFO, -1, 0, 0, 0, 0, 0, 0, &res); |
| 1348 | if (res.a0) |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1349 | return 0; |
| 1350 | |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1351 | return res.a1; |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | static int tfa_dram_init_banksize(void) |
| 1355 | { |
| 1356 | int i = 0, ret = 0; |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1357 | phys_size_t dram_size = tfa_get_dram_size(); |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1358 | struct arm_smccc_res res; |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1359 | |
| 1360 | debug("dram_size %llx\n", dram_size); |
| 1361 | |
| 1362 | if (!dram_size) |
| 1363 | return -EINVAL; |
| 1364 | |
| 1365 | do { |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1366 | arm_smccc_smc(SMC_DRAM_BANK_INFO, i, 0, 0, 0, 0, 0, 0, &res); |
| 1367 | if (res.a0) { |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1368 | ret = -EINVAL; |
| 1369 | break; |
| 1370 | } |
| 1371 | |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 1372 | debug("bank[%d]: start %lx, size %lx\n", i, res.a1, res.a2); |
| 1373 | gd->bd->bi_dram[i].start = res.a1; |
| 1374 | gd->bd->bi_dram[i].size = res.a2; |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1375 | |
| 1376 | dram_size -= gd->bd->bi_dram[i].size; |
| 1377 | |
| 1378 | i++; |
| 1379 | } while (dram_size); |
| 1380 | |
| 1381 | if (i > 0) |
| 1382 | ret = 0; |
| 1383 | |
Hou Zhiqiang | 80de373 | 2020-04-28 10:19:28 +0800 | [diff] [blame] | 1384 | #if defined(CONFIG_RESV_RAM) && !defined(CONFIG_SPL_BUILD) |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1385 | /* Assign memory for MC */ |
| 1386 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 1387 | if (gd->bd->bi_dram[2].size >= |
| 1388 | board_reserve_ram_top(gd->bd->bi_dram[2].size)) { |
| 1389 | gd->arch.resv_ram = gd->bd->bi_dram[2].start + |
| 1390 | gd->bd->bi_dram[2].size - |
| 1391 | board_reserve_ram_top(gd->bd->bi_dram[2].size); |
| 1392 | } else |
| 1393 | #endif |
| 1394 | { |
| 1395 | if (gd->bd->bi_dram[1].size >= |
| 1396 | board_reserve_ram_top(gd->bd->bi_dram[1].size)) { |
| 1397 | gd->arch.resv_ram = gd->bd->bi_dram[1].start + |
| 1398 | gd->bd->bi_dram[1].size - |
| 1399 | board_reserve_ram_top(gd->bd->bi_dram[1].size); |
| 1400 | } else if (gd->bd->bi_dram[0].size > |
| 1401 | board_reserve_ram_top(gd->bd->bi_dram[0].size)) { |
| 1402 | gd->arch.resv_ram = gd->bd->bi_dram[0].start + |
| 1403 | gd->bd->bi_dram[0].size - |
| 1404 | board_reserve_ram_top(gd->bd->bi_dram[0].size); |
| 1405 | } |
| 1406 | } |
Hou Zhiqiang | 80de373 | 2020-04-28 10:19:28 +0800 | [diff] [blame] | 1407 | #endif /* CONFIG_RESV_RAM */ |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1408 | |
| 1409 | return ret; |
| 1410 | } |
| 1411 | #endif |
| 1412 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 1413 | int dram_init_banksize(void) |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1414 | { |
| 1415 | #ifdef CONFIG_SYS_DP_DDR_BASE_PHY |
| 1416 | phys_size_t dp_ddr_size; |
| 1417 | #endif |
| 1418 | |
Rajesh Bhagat | 1dde2d2 | 2018-11-05 18:01:58 +0000 | [diff] [blame] | 1419 | #ifdef CONFIG_TFABOOT |
| 1420 | if (!tfa_dram_init_banksize()) |
| 1421 | return 0; |
| 1422 | #endif |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1423 | /* |
| 1424 | * gd->ram_size has the total size of DDR memory, less reserved secure |
| 1425 | * memory. The DDR extends from low region to high region(s) presuming |
| 1426 | * no hole is created with DDR configuration. gd->arch.secure_ram tracks |
| 1427 | * the location of secure memory. gd->arch.resv_ram tracks the location |
York Sun | c9e3e04 | 2017-09-28 08:42:12 -0700 | [diff] [blame] | 1428 | * of reserved memory for Management Complex (MC). Because gd->ram_size |
| 1429 | * is reduced by this function if secure memory is reserved, checking |
| 1430 | * gd->arch.secure_ram should be done to avoid running it repeatedly. |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1431 | */ |
York Sun | c9e3e04 | 2017-09-28 08:42:12 -0700 | [diff] [blame] | 1432 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1433 | #ifdef CFG_SYS_MEM_RESERVE_SECURE |
York Sun | c9e3e04 | 2017-09-28 08:42:12 -0700 | [diff] [blame] | 1434 | if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) { |
| 1435 | debug("No need to run again, skip %s\n", __func__); |
| 1436 | |
| 1437 | return 0; |
| 1438 | } |
| 1439 | #endif |
| 1440 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 1441 | gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE; |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1442 | if (gd->ram_size > CFG_SYS_DDR_BLOCK1_SIZE) { |
| 1443 | gd->bd->bi_dram[0].size = CFG_SYS_DDR_BLOCK1_SIZE; |
| 1444 | gd->bd->bi_dram[1].start = CFG_SYS_DDR_BLOCK2_BASE; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1445 | gd->bd->bi_dram[1].size = gd->ram_size - |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1446 | CFG_SYS_DDR_BLOCK1_SIZE; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1447 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 1448 | if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) { |
| 1449 | gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE; |
| 1450 | gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size - |
| 1451 | CONFIG_SYS_DDR_BLOCK2_SIZE; |
| 1452 | gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE; |
| 1453 | } |
| 1454 | #endif |
| 1455 | } else { |
| 1456 | gd->bd->bi_dram[0].size = gd->ram_size; |
| 1457 | } |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1458 | #ifdef CFG_SYS_MEM_RESERVE_SECURE |
Sumit Garg | ed0deea | 2017-10-04 03:20:49 +0530 | [diff] [blame] | 1459 | if (gd->bd->bi_dram[0].size > |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1460 | CFG_SYS_MEM_RESERVE_SECURE) { |
Sumit Garg | ed0deea | 2017-10-04 03:20:49 +0530 | [diff] [blame] | 1461 | gd->bd->bi_dram[0].size -= |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1462 | CFG_SYS_MEM_RESERVE_SECURE; |
Sumit Garg | ed0deea | 2017-10-04 03:20:49 +0530 | [diff] [blame] | 1463 | gd->arch.secure_ram = gd->bd->bi_dram[0].start + |
| 1464 | gd->bd->bi_dram[0].size; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1465 | gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED; |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1466 | gd->ram_size -= CFG_SYS_MEM_RESERVE_SECURE; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1467 | } |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1468 | #endif /* CFG_SYS_MEM_RESERVE_SECURE */ |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1469 | |
Hou Zhiqiang | 80de373 | 2020-04-28 10:19:28 +0800 | [diff] [blame] | 1470 | #if defined(CONFIG_RESV_RAM) && !defined(CONFIG_SPL_BUILD) |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1471 | /* Assign memory for MC */ |
| 1472 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 1473 | if (gd->bd->bi_dram[2].size >= |
| 1474 | board_reserve_ram_top(gd->bd->bi_dram[2].size)) { |
| 1475 | gd->arch.resv_ram = gd->bd->bi_dram[2].start + |
| 1476 | gd->bd->bi_dram[2].size - |
| 1477 | board_reserve_ram_top(gd->bd->bi_dram[2].size); |
| 1478 | } else |
| 1479 | #endif |
| 1480 | { |
| 1481 | if (gd->bd->bi_dram[1].size >= |
| 1482 | board_reserve_ram_top(gd->bd->bi_dram[1].size)) { |
| 1483 | gd->arch.resv_ram = gd->bd->bi_dram[1].start + |
| 1484 | gd->bd->bi_dram[1].size - |
| 1485 | board_reserve_ram_top(gd->bd->bi_dram[1].size); |
| 1486 | } else if (gd->bd->bi_dram[0].size > |
| 1487 | board_reserve_ram_top(gd->bd->bi_dram[0].size)) { |
| 1488 | gd->arch.resv_ram = gd->bd->bi_dram[0].start + |
| 1489 | gd->bd->bi_dram[0].size - |
| 1490 | board_reserve_ram_top(gd->bd->bi_dram[0].size); |
| 1491 | } |
| 1492 | } |
Hou Zhiqiang | 80de373 | 2020-04-28 10:19:28 +0800 | [diff] [blame] | 1493 | #endif /* CONFIG_RESV_RAM */ |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1494 | |
| 1495 | #ifdef CONFIG_SYS_DP_DDR_BASE_PHY |
| 1496 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 1497 | #error "This SoC shouldn't have DP DDR" |
| 1498 | #endif |
| 1499 | if (soc_has_dp_ddr()) { |
| 1500 | /* initialize DP-DDR here */ |
| 1501 | puts("DP-DDR: "); |
| 1502 | /* |
| 1503 | * DDR controller use 0 as the base address for binding. |
| 1504 | * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access. |
| 1505 | */ |
| 1506 | dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY, |
| 1507 | CONFIG_DP_DDR_CTRL, |
| 1508 | CONFIG_DP_DDR_NUM_CTRLS, |
| 1509 | CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR, |
| 1510 | NULL, NULL, NULL); |
| 1511 | if (dp_ddr_size) { |
| 1512 | gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE; |
| 1513 | gd->bd->bi_dram[2].size = dp_ddr_size; |
| 1514 | } else { |
| 1515 | puts("Not detected"); |
| 1516 | } |
| 1517 | } |
| 1518 | #endif |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 1519 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1520 | #ifdef CFG_SYS_MEM_RESERVE_SECURE |
York Sun | c9e3e04 | 2017-09-28 08:42:12 -0700 | [diff] [blame] | 1521 | debug("%s is called. gd->ram_size is reduced to %lu\n", |
| 1522 | __func__, (ulong)gd->ram_size); |
| 1523 | #endif |
| 1524 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 1525 | return 0; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1526 | } |
| 1527 | |
Stephen Warren | d0de806 | 2018-08-30 15:43:43 -0600 | [diff] [blame] | 1528 | #if CONFIG_IS_ENABLED(EFI_LOADER) |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1529 | void efi_add_known_memory(void) |
| 1530 | { |
| 1531 | int i; |
Michael Walle | 282d386 | 2020-05-17 12:29:19 +0200 | [diff] [blame] | 1532 | phys_addr_t ram_start; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1533 | phys_size_t ram_size; |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 1534 | |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1535 | /* Add RAM */ |
| 1536 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 1537 | #ifdef CONFIG_SYS_DP_DDR_BASE_PHY |
| 1538 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 1539 | #error "This SoC shouldn't have DP DDR" |
| 1540 | #endif |
| 1541 | if (i == 2) |
| 1542 | continue; /* skip DP-DDR */ |
| 1543 | #endif |
| 1544 | ram_start = gd->bd->bi_dram[i].start; |
| 1545 | ram_size = gd->bd->bi_dram[i].size; |
| 1546 | #ifdef CONFIG_RESV_RAM |
| 1547 | if (gd->arch.resv_ram >= ram_start && |
| 1548 | gd->arch.resv_ram < ram_start + ram_size) |
| 1549 | ram_size = gd->arch.resv_ram - ram_start; |
| 1550 | #endif |
Michael Walle | 282d386 | 2020-05-17 12:29:19 +0200 | [diff] [blame] | 1551 | efi_add_memory_map(ram_start, ram_size, |
| 1552 | EFI_CONVENTIONAL_MEMORY); |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1553 | } |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 1554 | } |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 1555 | #endif |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1556 | |
| 1557 | /* |
| 1558 | * Before DDR size is known, early MMU table have DDR mapped as device memory |
| 1559 | * to avoid speculative access. To relocate U-Boot to DDR, "normal memory" |
| 1560 | * needs to be set for these mappings. |
| 1561 | * If a special case configures DDR with holes in the mapping, the holes need |
| 1562 | * to be marked as invalid. This is not implemented in this function. |
| 1563 | */ |
| 1564 | void update_early_mmu_table(void) |
| 1565 | { |
| 1566 | if (!gd->arch.tlb_addr) |
| 1567 | return; |
| 1568 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 1569 | if (gd->ram_size <= CFG_SYS_FSL_DRAM_SIZE1) { |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1570 | mmu_change_region_attr( |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 1571 | CFG_SYS_SDRAM_BASE, |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1572 | gd->ram_size, |
| 1573 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 1574 | PTE_BLOCK_OUTER_SHARE | |
| 1575 | PTE_BLOCK_NS | |
| 1576 | PTE_TYPE_VALID); |
| 1577 | } else { |
| 1578 | mmu_change_region_attr( |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 1579 | CFG_SYS_SDRAM_BASE, |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1580 | CFG_SYS_DDR_BLOCK1_SIZE, |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1581 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 1582 | PTE_BLOCK_OUTER_SHARE | |
| 1583 | PTE_BLOCK_NS | |
| 1584 | PTE_TYPE_VALID); |
| 1585 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 1586 | #ifndef CONFIG_SYS_DDR_BLOCK2_SIZE |
| 1587 | #error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE" |
| 1588 | #endif |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1589 | if (gd->ram_size - CFG_SYS_DDR_BLOCK1_SIZE > |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1590 | CONFIG_SYS_DDR_BLOCK2_SIZE) { |
| 1591 | mmu_change_region_attr( |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1592 | CFG_SYS_DDR_BLOCK2_BASE, |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1593 | CONFIG_SYS_DDR_BLOCK2_SIZE, |
| 1594 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 1595 | PTE_BLOCK_OUTER_SHARE | |
| 1596 | PTE_BLOCK_NS | |
| 1597 | PTE_TYPE_VALID); |
| 1598 | mmu_change_region_attr( |
| 1599 | CONFIG_SYS_DDR_BLOCK3_BASE, |
| 1600 | gd->ram_size - |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1601 | CFG_SYS_DDR_BLOCK1_SIZE - |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1602 | CONFIG_SYS_DDR_BLOCK2_SIZE, |
| 1603 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 1604 | PTE_BLOCK_OUTER_SHARE | |
| 1605 | PTE_BLOCK_NS | |
| 1606 | PTE_TYPE_VALID); |
| 1607 | } else |
| 1608 | #endif |
| 1609 | { |
| 1610 | mmu_change_region_attr( |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1611 | CFG_SYS_DDR_BLOCK2_BASE, |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1612 | gd->ram_size - |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1613 | CFG_SYS_DDR_BLOCK1_SIZE, |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1614 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 1615 | PTE_BLOCK_OUTER_SHARE | |
| 1616 | PTE_BLOCK_NS | |
| 1617 | PTE_TYPE_VALID); |
| 1618 | } |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | __weak int dram_init(void) |
| 1623 | { |
Tom Rini | 5618460 | 2022-02-25 11:19:53 -0500 | [diff] [blame] | 1624 | #ifdef CONFIG_SYS_FSL_DDR |
Simon Glass | 0e0ac20 | 2017-04-06 12:47:04 -0600 | [diff] [blame] | 1625 | fsl_initdram(); |
Rajesh Bhagat | 5efbecf | 2018-11-05 18:01:37 +0000 | [diff] [blame] | 1626 | #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \ |
| 1627 | defined(CONFIG_SPL_BUILD) |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1628 | /* This will break-before-make MMU for DDR */ |
| 1629 | update_early_mmu_table(); |
| 1630 | #endif |
Tom Rini | 5618460 | 2022-02-25 11:19:53 -0500 | [diff] [blame] | 1631 | #endif |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 1632 | |
| 1633 | return 0; |
| 1634 | } |
Alex Marginean | 47568ce | 2020-01-11 01:05:40 +0200 | [diff] [blame] | 1635 | |
| 1636 | #ifdef CONFIG_ARCH_MISC_INIT |
| 1637 | __weak int serdes_misc_init(void) |
| 1638 | { |
| 1639 | return 0; |
| 1640 | } |
| 1641 | |
| 1642 | int arch_misc_init(void) |
| 1643 | { |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 1644 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 1645 | struct udevice *dev; |
| 1646 | int ret; |
| 1647 | |
| 1648 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 1649 | if (ret) |
Ye Li | ec34689 | 2022-05-11 13:56:20 +0530 | [diff] [blame] | 1650 | printf("Failed to initialize caam_jr: %d\n", ret); |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 1651 | } |
Alex Marginean | 47568ce | 2020-01-11 01:05:40 +0200 | [diff] [blame] | 1652 | serdes_misc_init(); |
| 1653 | |
| 1654 | return 0; |
| 1655 | } |
| 1656 | #endif |