Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 1 | /* |
Priyanka Jain | 2b36178 | 2017-04-27 15:08:06 +0530 | [diff] [blame] | 2 | * Copyright 2017 NXP |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 3 | * Copyright 2014-2015 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 0e0ac20 | 2017-04-06 12:47:04 -0600 | [diff] [blame] | 9 | #include <fsl_ddr_sdram.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 10 | #include <asm/io.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 11 | #include <linux/errno.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 12 | #include <asm/system.h> |
| 13 | #include <asm/armv8/mmu.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/fsl_serdes.h> |
| 16 | #include <asm/arch/soc.h> |
| 17 | #include <asm/arch/cpu.h> |
| 18 | #include <asm/arch/speed.h> |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 19 | #include <fsl_immap.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 20 | #include <asm/arch/mp.h> |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 21 | #include <efi_loader.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 22 | #include <fm_eth.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 23 | #include <fsl-mc/fsl_mc.h> |
| 24 | #ifdef CONFIG_FSL_ESDHC |
| 25 | #include <fsl_esdhc.h> |
| 26 | #endif |
Hou Zhiqiang | 21c4d55 | 2016-06-28 20:18:15 +0800 | [diff] [blame] | 27 | #include <asm/armv8/sec_firmware.h> |
Shengzhou Liu | 15875a5 | 2016-11-21 11:36:48 +0800 | [diff] [blame] | 28 | #ifdef CONFIG_SYS_FSL_DDR |
| 29 | #include <fsl_ddr.h> |
| 30 | #endif |
Simon Glass | 243182c | 2017-05-17 08:23:06 -0600 | [diff] [blame] | 31 | #include <asm/arch/clock.h> |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 32 | #include <hwconfig.h> |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 33 | #include <fsl_qbman.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 37 | struct mm_region *mem_map = early_map; |
Alexander Graf | ce0a64e | 2016-03-04 01:09:54 +0100 | [diff] [blame] | 38 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 39 | void cpu_name(char *name) |
| 40 | { |
| 41 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 42 | unsigned int i, svr, ver; |
| 43 | |
| 44 | svr = gur_in32(&gur->svr); |
| 45 | ver = SVR_SOC_VER(svr); |
| 46 | |
| 47 | for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++) |
| 48 | if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) { |
| 49 | strcpy(name, cpu_type_list[i].name); |
| 50 | |
| 51 | if (IS_E_PROCESSOR(svr)) |
| 52 | strcat(name, "E"); |
Wenbin Song | 863a33a | 2016-09-13 16:13:54 +0800 | [diff] [blame] | 53 | |
| 54 | sprintf(name + strlen(name), " Rev%d.%d", |
| 55 | SVR_MAJ(svr), SVR_MIN(svr)); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 56 | break; |
| 57 | } |
| 58 | |
| 59 | if (i == ARRAY_SIZE(cpu_type_list)) |
| 60 | strcpy(name, "unknown"); |
| 61 | } |
| 62 | |
| 63 | #ifndef CONFIG_SYS_DCACHE_OFF |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 64 | /* |
| 65 | * To start MMU before DDR is available, we create MMU table in SRAM. |
| 66 | * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three |
| 67 | * levels of translation tables here to cover 40-bit address space. |
| 68 | * We use 4KB granule size, with 40 bits physical address, T0SZ=24 |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 69 | * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose. |
| 70 | * Note, the debug print in cache_v8.c is not usable for debugging |
| 71 | * these early MMU tables because UART is not yet available. |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 72 | */ |
| 73 | static inline void early_mmu_setup(void) |
| 74 | { |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 75 | unsigned int el = current_el(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 76 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 77 | /* global data is already setup, no allocation yet */ |
| 78 | gd->arch.tlb_addr = CONFIG_SYS_FSL_OCRAM_BASE; |
| 79 | gd->arch.tlb_fillptr = gd->arch.tlb_addr; |
| 80 | gd->arch.tlb_size = EARLY_PGTABLE_SIZE; |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 81 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 82 | /* Create early page tables */ |
| 83 | setup_pgtables(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 84 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 85 | /* point TTBR to the new table */ |
| 86 | set_ttbr_tcr_mair(el, gd->arch.tlb_addr, |
| 87 | get_tcr(el, NULL, NULL) & |
| 88 | ~(TCR_ORGN_MASK | TCR_IRGN_MASK), |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 89 | MEMORY_ATTRIBUTES); |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 90 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 91 | set_sctlr(get_sctlr() | CR_M); |
| 92 | } |
| 93 | |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 94 | static void fix_pcie_mmu_map(void) |
| 95 | { |
York Sun | 4ce6fbf | 2017-03-27 11:41:01 -0700 | [diff] [blame] | 96 | #ifdef CONFIG_ARCH_LS2080A |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 97 | unsigned int i; |
| 98 | u32 svr, ver; |
| 99 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 100 | |
| 101 | svr = gur_in32(&gur->svr); |
| 102 | ver = SVR_SOC_VER(svr); |
| 103 | |
| 104 | /* Fix PCIE base and size for LS2088A */ |
| 105 | if ((ver == SVR_LS2088A) || (ver == SVR_LS2084A) || |
Priyanka Jain | 2b36178 | 2017-04-27 15:08:06 +0530 | [diff] [blame] | 106 | (ver == SVR_LS2048A) || (ver == SVR_LS2044A) || |
| 107 | (ver == SVR_LS2081A) || (ver == SVR_LS2041A)) { |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 108 | for (i = 0; i < ARRAY_SIZE(final_map); i++) { |
| 109 | switch (final_map[i].phys) { |
| 110 | case CONFIG_SYS_PCIE1_PHYS_ADDR: |
| 111 | final_map[i].phys = 0x2000000000ULL; |
| 112 | final_map[i].virt = 0x2000000000ULL; |
| 113 | final_map[i].size = 0x800000000ULL; |
| 114 | break; |
| 115 | case CONFIG_SYS_PCIE2_PHYS_ADDR: |
| 116 | final_map[i].phys = 0x2800000000ULL; |
| 117 | final_map[i].virt = 0x2800000000ULL; |
| 118 | final_map[i].size = 0x800000000ULL; |
| 119 | break; |
| 120 | case CONFIG_SYS_PCIE3_PHYS_ADDR: |
| 121 | final_map[i].phys = 0x3000000000ULL; |
| 122 | final_map[i].virt = 0x3000000000ULL; |
| 123 | final_map[i].size = 0x800000000ULL; |
| 124 | break; |
| 125 | case CONFIG_SYS_PCIE4_PHYS_ADDR: |
| 126 | final_map[i].phys = 0x3800000000ULL; |
| 127 | final_map[i].virt = 0x3800000000ULL; |
| 128 | final_map[i].size = 0x800000000ULL; |
| 129 | break; |
| 130 | default: |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | #endif |
| 136 | } |
| 137 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 138 | /* |
| 139 | * The final tables look similar to early tables, but different in detail. |
| 140 | * These tables are in DRAM. Sub tables are added to enable cache for |
| 141 | * QBMan and OCRAM. |
| 142 | * |
York Sun | 1ef95cc | 2016-06-24 16:46:18 -0700 | [diff] [blame] | 143 | * Put the MMU table in secure memory if gd->arch.secure_ram is valid. |
| 144 | * 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] | 145 | */ |
| 146 | static inline void final_mmu_setup(void) |
| 147 | { |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 148 | u64 tlb_addr_save = gd->arch.tlb_addr; |
York Sun | 0804d56 | 2015-12-04 11:57:08 -0800 | [diff] [blame] | 149 | unsigned int el = current_el(); |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 150 | int index; |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 151 | |
Hou Zhiqiang | 92fecb5 | 2017-03-03 12:35:09 +0800 | [diff] [blame] | 152 | /* fix the final_map before filling in the block entries */ |
| 153 | fix_pcie_mmu_map(); |
| 154 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 155 | mem_map = final_map; |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 156 | |
York Sun | 75488ed | 2017-03-06 09:02:30 -0800 | [diff] [blame] | 157 | /* Update mapping for DDR to actual size */ |
| 158 | for (index = 0; index < ARRAY_SIZE(final_map) - 2; index++) { |
| 159 | /* |
| 160 | * Find the entry for DDR mapping and update the address and |
| 161 | * size. Zero-sized mapping will be skipped when creating MMU |
| 162 | * table. |
| 163 | */ |
| 164 | switch (final_map[index].virt) { |
| 165 | case CONFIG_SYS_FSL_DRAM_BASE1: |
| 166 | final_map[index].virt = gd->bd->bi_dram[0].start; |
| 167 | final_map[index].phys = gd->bd->bi_dram[0].start; |
| 168 | final_map[index].size = gd->bd->bi_dram[0].size; |
| 169 | break; |
| 170 | #ifdef CONFIG_SYS_FSL_DRAM_BASE2 |
| 171 | case CONFIG_SYS_FSL_DRAM_BASE2: |
| 172 | #if (CONFIG_NR_DRAM_BANKS >= 2) |
| 173 | final_map[index].virt = gd->bd->bi_dram[1].start; |
| 174 | final_map[index].phys = gd->bd->bi_dram[1].start; |
| 175 | final_map[index].size = gd->bd->bi_dram[1].size; |
| 176 | #else |
| 177 | final_map[index].size = 0; |
| 178 | #endif |
| 179 | break; |
| 180 | #endif |
| 181 | #ifdef CONFIG_SYS_FSL_DRAM_BASE3 |
| 182 | case CONFIG_SYS_FSL_DRAM_BASE3: |
| 183 | #if (CONFIG_NR_DRAM_BANKS >= 3) |
| 184 | final_map[index].virt = gd->bd->bi_dram[2].start; |
| 185 | final_map[index].phys = gd->bd->bi_dram[2].start; |
| 186 | final_map[index].size = gd->bd->bi_dram[2].size; |
| 187 | #else |
| 188 | final_map[index].size = 0; |
| 189 | #endif |
| 190 | break; |
| 191 | #endif |
| 192 | default: |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | |
York Sun | 0804d56 | 2015-12-04 11:57:08 -0800 | [diff] [blame] | 197 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 198 | if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) { |
| 199 | if (el == 3) { |
| 200 | /* |
| 201 | * Only use gd->arch.secure_ram if the address is |
| 202 | * recalculated. Align to 4KB for MMU table. |
| 203 | */ |
| 204 | /* put page tables in secure ram */ |
| 205 | index = ARRAY_SIZE(final_map) - 2; |
| 206 | gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff; |
| 207 | final_map[index].virt = gd->arch.secure_ram & ~0x3; |
| 208 | final_map[index].phys = final_map[index].virt; |
| 209 | final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE; |
| 210 | final_map[index].attrs = PTE_BLOCK_OUTER_SHARE; |
York Sun | 1ef95cc | 2016-06-24 16:46:18 -0700 | [diff] [blame] | 211 | gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED; |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 212 | tlb_addr_save = gd->arch.tlb_addr; |
York Sun | 0804d56 | 2015-12-04 11:57:08 -0800 | [diff] [blame] | 213 | } else { |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 214 | /* Use allocated (board_f.c) memory for TLB */ |
| 215 | tlb_addr_save = gd->arch.tlb_allocated; |
| 216 | gd->arch.tlb_addr = tlb_addr_save; |
York Sun | 0804d56 | 2015-12-04 11:57:08 -0800 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 220 | |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 221 | /* Reset the fill ptr */ |
| 222 | gd->arch.tlb_fillptr = tlb_addr_save; |
| 223 | |
| 224 | /* Create normal system page tables */ |
| 225 | setup_pgtables(); |
| 226 | |
| 227 | /* Create emergency page tables */ |
| 228 | gd->arch.tlb_addr = gd->arch.tlb_fillptr; |
| 229 | gd->arch.tlb_emerg = gd->arch.tlb_addr; |
| 230 | setup_pgtables(); |
| 231 | gd->arch.tlb_addr = tlb_addr_save; |
| 232 | |
York Sun | cf64ced | 2017-03-06 09:02:31 -0800 | [diff] [blame] | 233 | /* Disable cache and MMU */ |
| 234 | dcache_disable(); /* TLBs are invalidated */ |
| 235 | invalidate_icache_all(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 236 | |
| 237 | /* point TTBR to the new table */ |
York Sun | 9da8f50 | 2016-06-24 16:46:23 -0700 | [diff] [blame] | 238 | set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL), |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 239 | MEMORY_ATTRIBUTES); |
York Sun | cf64ced | 2017-03-06 09:02:31 -0800 | [diff] [blame] | 240 | |
York Sun | eb6eac1 | 2016-07-22 10:52:23 -0700 | [diff] [blame] | 241 | set_sctlr(get_sctlr() | CR_M); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 242 | } |
| 243 | |
Alexander Graf | bc78b92 | 2016-03-21 20:26:12 +0100 | [diff] [blame] | 244 | u64 get_page_table_size(void) |
| 245 | { |
| 246 | return 0x10000; |
| 247 | } |
| 248 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 249 | int arch_cpu_init(void) |
| 250 | { |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 251 | /* |
| 252 | * This function is called before U-Boot relocates itself to speed up |
| 253 | * on system running. It is not necessary to run if performance is not |
| 254 | * critical. Skip if MMU is already enabled by SPL or other means. |
| 255 | */ |
| 256 | if (get_sctlr() & CR_M) |
| 257 | return 0; |
| 258 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 259 | icache_enable(); |
| 260 | __asm_invalidate_dcache_all(); |
| 261 | __asm_invalidate_tlb_all(); |
| 262 | early_mmu_setup(); |
| 263 | set_sctlr(get_sctlr() | CR_C); |
| 264 | return 0; |
| 265 | } |
| 266 | |
Hou Zhiqiang | a7befa5 | 2016-06-28 20:18:12 +0800 | [diff] [blame] | 267 | void mmu_setup(void) |
| 268 | { |
| 269 | final_mmu_setup(); |
| 270 | } |
| 271 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 272 | /* |
Hou Zhiqiang | a7befa5 | 2016-06-28 20:18:12 +0800 | [diff] [blame] | 273 | * This function is called from common/board_r.c. |
| 274 | * It recreates MMU table in main memory. |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 275 | */ |
| 276 | void enable_caches(void) |
| 277 | { |
Hou Zhiqiang | a7befa5 | 2016-06-28 20:18:12 +0800 | [diff] [blame] | 278 | mmu_setup(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 279 | __asm_invalidate_tlb_all(); |
Hou Zhiqiang | a7befa5 | 2016-06-28 20:18:12 +0800 | [diff] [blame] | 280 | icache_enable(); |
| 281 | dcache_enable(); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 282 | } |
| 283 | #endif |
| 284 | |
Priyanka Jain | 9a27670 | 2016-11-17 12:29:56 +0530 | [diff] [blame] | 285 | u32 initiator_type(u32 cluster, int init_id) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 286 | { |
| 287 | struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 288 | u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK; |
| 289 | u32 type = 0; |
| 290 | |
| 291 | type = gur_in32(&gur->tp_ityp[idx]); |
| 292 | if (type & TP_ITYP_AV) |
| 293 | return type; |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
York Sun | ed7fbe3 | 2016-09-13 12:40:30 -0700 | [diff] [blame] | 298 | u32 cpu_pos_mask(void) |
| 299 | { |
| 300 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 301 | int i = 0; |
| 302 | u32 cluster, type, mask = 0; |
| 303 | |
| 304 | do { |
| 305 | int j; |
| 306 | |
| 307 | cluster = gur_in32(&gur->tp_cluster[i].lower); |
| 308 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 309 | type = initiator_type(cluster, j); |
| 310 | if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)) |
| 311 | mask |= 1 << (i * TP_INIT_PER_CLUSTER + j); |
| 312 | } |
| 313 | i++; |
| 314 | } while ((cluster & TP_CLUSTER_EOC) == 0x0); |
| 315 | |
| 316 | return mask; |
| 317 | } |
| 318 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 319 | u32 cpu_mask(void) |
| 320 | { |
| 321 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 322 | int i = 0, count = 0; |
| 323 | u32 cluster, type, mask = 0; |
| 324 | |
| 325 | do { |
| 326 | int j; |
| 327 | |
| 328 | cluster = gur_in32(&gur->tp_cluster[i].lower); |
| 329 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 330 | type = initiator_type(cluster, j); |
| 331 | if (type) { |
| 332 | if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM) |
| 333 | mask |= 1 << count; |
| 334 | count++; |
| 335 | } |
| 336 | } |
| 337 | i++; |
| 338 | } while ((cluster & TP_CLUSTER_EOC) == 0x0); |
| 339 | |
| 340 | return mask; |
| 341 | } |
| 342 | |
| 343 | /* |
| 344 | * Return the number of cores on this SOC. |
| 345 | */ |
| 346 | int cpu_numcores(void) |
| 347 | { |
| 348 | return hweight32(cpu_mask()); |
| 349 | } |
| 350 | |
| 351 | int fsl_qoriq_core_to_cluster(unsigned int core) |
| 352 | { |
| 353 | struct ccsr_gur __iomem *gur = |
| 354 | (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 355 | int i = 0, count = 0; |
| 356 | u32 cluster; |
| 357 | |
| 358 | do { |
| 359 | int j; |
| 360 | |
| 361 | cluster = gur_in32(&gur->tp_cluster[i].lower); |
| 362 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 363 | if (initiator_type(cluster, j)) { |
| 364 | if (count == core) |
| 365 | return i; |
| 366 | count++; |
| 367 | } |
| 368 | } |
| 369 | i++; |
| 370 | } while ((cluster & TP_CLUSTER_EOC) == 0x0); |
| 371 | |
| 372 | return -1; /* cannot identify the cluster */ |
| 373 | } |
| 374 | |
| 375 | u32 fsl_qoriq_core_to_type(unsigned int core) |
| 376 | { |
| 377 | struct ccsr_gur __iomem *gur = |
| 378 | (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 379 | int i = 0, count = 0; |
| 380 | u32 cluster, type; |
| 381 | |
| 382 | do { |
| 383 | int j; |
| 384 | |
| 385 | cluster = gur_in32(&gur->tp_cluster[i].lower); |
| 386 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 387 | type = initiator_type(cluster, j); |
| 388 | if (type) { |
| 389 | if (count == core) |
| 390 | return type; |
| 391 | count++; |
| 392 | } |
| 393 | } |
| 394 | i++; |
| 395 | } while ((cluster & TP_CLUSTER_EOC) == 0x0); |
| 396 | |
| 397 | return -1; /* cannot identify the cluster */ |
| 398 | } |
| 399 | |
Priyanka Jain | 96b001f | 2016-11-17 12:29:51 +0530 | [diff] [blame] | 400 | #ifndef CONFIG_FSL_LSCH3 |
Sriram Dash | 9282d26 | 2016-06-13 09:58:32 +0530 | [diff] [blame] | 401 | uint get_svr(void) |
| 402 | { |
| 403 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 404 | |
| 405 | return gur_in32(&gur->svr); |
| 406 | } |
Priyanka Jain | 96b001f | 2016-11-17 12:29:51 +0530 | [diff] [blame] | 407 | #endif |
Sriram Dash | 9282d26 | 2016-06-13 09:58:32 +0530 | [diff] [blame] | 408 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 409 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 410 | int print_cpuinfo(void) |
| 411 | { |
| 412 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 413 | struct sys_info sysinfo; |
| 414 | char buf[32]; |
| 415 | unsigned int i, core; |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 416 | u32 type, rcw, svr = gur_in32(&gur->svr); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 417 | |
| 418 | puts("SoC: "); |
| 419 | |
| 420 | cpu_name(buf); |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 421 | printf(" %s (0x%x)\n", buf, svr); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 422 | memset((u8 *)buf, 0x00, ARRAY_SIZE(buf)); |
| 423 | get_sys_info(&sysinfo); |
| 424 | puts("Clock Configuration:"); |
| 425 | for_each_cpu(i, core, cpu_numcores(), cpu_mask()) { |
| 426 | if (!(i % 3)) |
| 427 | puts("\n "); |
| 428 | type = TP_ITYP_VER(fsl_qoriq_core_to_type(core)); |
| 429 | printf("CPU%d(%s):%-4s MHz ", core, |
| 430 | type == TY_ITYP_VER_A7 ? "A7 " : |
| 431 | (type == TY_ITYP_VER_A53 ? "A53" : |
Alison Wang | 7980839 | 2016-07-05 16:01:52 +0800 | [diff] [blame] | 432 | (type == TY_ITYP_VER_A57 ? "A57" : |
| 433 | (type == TY_ITYP_VER_A72 ? "A72" : " "))), |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 434 | strmhz(buf, sysinfo.freq_processor[core])); |
| 435 | } |
Hou Zhiqiang | 3f91cda | 2017-01-10 16:44:15 +0800 | [diff] [blame] | 436 | /* Display platform clock as Bus frequency. */ |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 437 | printf("\n Bus: %-4s MHz ", |
Hou Zhiqiang | 3f91cda | 2017-01-10 16:44:15 +0800 | [diff] [blame] | 438 | strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV)); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 439 | printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus)); |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 440 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 441 | printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0])); |
| 442 | #endif |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 443 | #ifdef CONFIG_SYS_FSL_HAS_DP_DDR |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 444 | if (soc_has_dp_ddr()) { |
| 445 | printf(" DP-DDR: %-4s MT/s", |
| 446 | strmhz(buf, sysinfo.freq_ddrbus2)); |
| 447 | } |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 448 | #endif |
| 449 | puts("\n"); |
| 450 | |
| 451 | /* |
| 452 | * Display the RCW, so that no one gets confused as to what RCW |
| 453 | * we're actually using for this boot. |
| 454 | */ |
| 455 | puts("Reset Configuration Word (RCW):"); |
| 456 | for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) { |
| 457 | rcw = gur_in32(&gur->rcwsr[i]); |
| 458 | if ((i % 4) == 0) |
| 459 | printf("\n %08x:", i * 4); |
| 460 | printf(" %08x", rcw); |
| 461 | } |
| 462 | puts("\n"); |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | #endif |
| 467 | |
| 468 | #ifdef CONFIG_FSL_ESDHC |
| 469 | int cpu_mmc_init(bd_t *bis) |
| 470 | { |
| 471 | return fsl_esdhc_mmc_init(bis); |
| 472 | } |
| 473 | #endif |
| 474 | |
| 475 | int cpu_eth_init(bd_t *bis) |
| 476 | { |
| 477 | int error = 0; |
| 478 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 479 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 480 | error = fsl_mc_ldpaa_init(bis); |
| 481 | #endif |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 482 | #ifdef CONFIG_FMAN_ENET |
| 483 | fm_standard_init(bis); |
| 484 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 485 | return error; |
| 486 | } |
| 487 | |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 488 | static inline int check_psci(void) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 489 | { |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 490 | unsigned int psci_ver; |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 491 | |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 492 | psci_ver = sec_firmware_support_psci_version(); |
| 493 | if (psci_ver == PSCI_INVALID_VER) |
| 494 | return 1; |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 499 | static void config_core_prefetch(void) |
| 500 | { |
| 501 | char *buf = NULL; |
| 502 | char buffer[HWCONFIG_BUFFER_SIZE]; |
| 503 | const char *prefetch_arg = NULL; |
| 504 | size_t arglen; |
| 505 | unsigned int mask; |
| 506 | struct pt_regs regs; |
| 507 | |
| 508 | if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0) |
| 509 | buf = buffer; |
| 510 | |
| 511 | prefetch_arg = hwconfig_subarg_f("core_prefetch", "disable", |
| 512 | &arglen, buf); |
| 513 | |
| 514 | if (prefetch_arg) { |
| 515 | mask = simple_strtoul(prefetch_arg, NULL, 0) & 0xff; |
| 516 | if (mask & 0x1) { |
| 517 | printf("Core0 prefetch can't be disabled\n"); |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | #define SIP_PREFETCH_DISABLE_64 0xC200FF13 |
| 522 | regs.regs[0] = SIP_PREFETCH_DISABLE_64; |
| 523 | regs.regs[1] = mask; |
| 524 | smc_call(®s); |
| 525 | |
| 526 | if (regs.regs[0]) |
| 527 | printf("Prefetch disable config failed for mask "); |
| 528 | else |
| 529 | printf("Prefetch disable config passed for mask "); |
| 530 | printf("0x%x\n", mask); |
| 531 | } |
| 532 | } |
| 533 | |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 534 | int arch_early_init_r(void) |
| 535 | { |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 536 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009635 |
Priyanka Jain | 823e042 | 2017-02-14 10:34:31 +0530 | [diff] [blame] | 537 | u32 svr_dev_id; |
| 538 | /* |
| 539 | * erratum A009635 is valid only for LS2080A SoC and |
| 540 | * its personalitiesi |
| 541 | */ |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 542 | svr_dev_id = get_svr(); |
| 543 | if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A))) |
Priyanka Jain | 823e042 | 2017-02-14 10:34:31 +0530 | [diff] [blame] | 544 | erratum_a009635(); |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 545 | #endif |
Shengzhou Liu | 15875a5 | 2016-11-21 11:36:48 +0800 | [diff] [blame] | 546 | #if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR) |
| 547 | erratum_a009942_check_cpo(); |
| 548 | #endif |
Yuantian Tang | aec3b14 | 2017-04-19 13:27:39 +0800 | [diff] [blame] | 549 | if (check_psci()) { |
| 550 | debug("PSCI: PSCI does not exist.\n"); |
| 551 | |
| 552 | /* if PSCI does not exist, boot secondary cores here */ |
| 553 | if (fsl_layerscape_wake_seconday_cores()) |
Hou Zhiqiang | 21c4d55 | 2016-06-28 20:18:15 +0800 | [diff] [blame] | 554 | printf("Did not wake secondary cores\n"); |
| 555 | } |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 556 | |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 557 | #ifdef CONFIG_SYS_FSL_HAS_RGMII |
| 558 | fsl_rgmii_init(); |
| 559 | #endif |
| 560 | |
Prabhakar Kushwaha | 0acce84 | 2017-11-10 11:32:52 +0530 | [diff] [blame] | 561 | config_core_prefetch(); |
| 562 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 563 | #ifdef CONFIG_SYS_HAS_SERDES |
| 564 | fsl_serdes_init(); |
| 565 | #endif |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 566 | #ifdef CONFIG_FMAN_ENET |
| 567 | fman_enet_init(); |
| 568 | #endif |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 569 | #ifdef CONFIG_SYS_DPAA_QBMAN |
| 570 | setup_qbman_portals(); |
| 571 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | int timer_init(void) |
| 576 | { |
| 577 | u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR; |
| 578 | #ifdef CONFIG_FSL_LSCH3 |
| 579 | u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR; |
| 580 | #endif |
Zhang Ying-22455 | 8fd4549 | 2018-01-09 16:25:46 +0800 | [diff] [blame] | 581 | #if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) |
Yunhui Cui | 3dfb82a | 2016-06-08 10:31:42 +0800 | [diff] [blame] | 582 | u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET; |
Priyanka Jain | 3d31ec7 | 2016-11-17 12:29:52 +0530 | [diff] [blame] | 583 | u32 svr_dev_id; |
Yunhui Cui | 3dfb82a | 2016-06-08 10:31:42 +0800 | [diff] [blame] | 584 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 585 | #ifdef COUNTER_FREQUENCY_REAL |
| 586 | unsigned long cntfrq = COUNTER_FREQUENCY_REAL; |
| 587 | |
| 588 | /* Update with accurate clock frequency */ |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 589 | if (current_el() == 3) |
| 590 | asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory"); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 591 | #endif |
| 592 | |
| 593 | #ifdef CONFIG_FSL_LSCH3 |
| 594 | /* Enable timebase for all clusters. |
| 595 | * It is safe to do so even some clusters are not enabled. |
| 596 | */ |
| 597 | out_le32(cltbenr, 0xf); |
| 598 | #endif |
| 599 | |
Zhang Ying-22455 | 8fd4549 | 2018-01-09 16:25:46 +0800 | [diff] [blame] | 600 | #if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) |
Yunhui Cui | 3dfb82a | 2016-06-08 10:31:42 +0800 | [diff] [blame] | 601 | /* |
| 602 | * In certain Layerscape SoCs, the clock for each core's |
| 603 | * has an enable bit in the PMU Physical Core Time Base Enable |
| 604 | * Register (PCTBENR), which allows the watchdog to operate. |
| 605 | */ |
| 606 | setbits_le32(pctbenr, 0xff); |
Priyanka Jain | 3d31ec7 | 2016-11-17 12:29:52 +0530 | [diff] [blame] | 607 | /* |
| 608 | * For LS2080A SoC and its personalities, timer controller |
| 609 | * offset is different |
| 610 | */ |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 611 | svr_dev_id = get_svr(); |
| 612 | if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A))) |
Priyanka Jain | 3d31ec7 | 2016-11-17 12:29:52 +0530 | [diff] [blame] | 613 | cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR; |
| 614 | |
Yunhui Cui | 3dfb82a | 2016-06-08 10:31:42 +0800 | [diff] [blame] | 615 | #endif |
| 616 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 617 | /* Enable clock for timer |
| 618 | * This is a global setting. |
| 619 | */ |
| 620 | out_le32(cntcr, 0x1); |
| 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 625 | __efi_runtime_data u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR; |
| 626 | |
| 627 | void __efi_runtime reset_cpu(ulong addr) |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 628 | { |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 629 | u32 val; |
| 630 | |
| 631 | /* Raise RESET_REQ_B */ |
| 632 | val = scfg_in32(rstcr); |
| 633 | val |= 0x02; |
| 634 | scfg_out32(rstcr, val); |
| 635 | } |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 636 | |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 637 | #ifdef CONFIG_EFI_LOADER |
| 638 | |
| 639 | void __efi_runtime EFIAPI efi_reset_system( |
| 640 | enum efi_reset_type reset_type, |
| 641 | efi_status_t reset_status, |
| 642 | unsigned long data_size, void *reset_data) |
| 643 | { |
| 644 | switch (reset_type) { |
| 645 | case EFI_RESET_COLD: |
| 646 | case EFI_RESET_WARM: |
Heinrich Schuchardt | 450d4c8 | 2018-02-06 22:00:22 +0100 | [diff] [blame^] | 647 | case EFI_RESET_PLATFORM_SPECIFIC: |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 648 | reset_cpu(0); |
| 649 | break; |
| 650 | case EFI_RESET_SHUTDOWN: |
| 651 | /* Nothing we can do */ |
| 652 | break; |
| 653 | } |
| 654 | |
| 655 | while (1) { } |
| 656 | } |
| 657 | |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 658 | efi_status_t efi_reset_system_init(void) |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 659 | { |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 660 | return efi_add_runtime_mmio(&rstcr, sizeof(*rstcr)); |
Alexander Graf | 12be31c | 2016-11-17 01:03:01 +0100 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | #endif |
| 664 | |
York Sun | 2db5408 | 2017-09-07 10:12:32 -0700 | [diff] [blame] | 665 | /* |
| 666 | * Calculate reserved memory with given memory bank |
| 667 | * Return aligned memory size on success |
| 668 | * Return (ram_size + needed size) for failure |
| 669 | */ |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 670 | phys_size_t board_reserve_ram_top(phys_size_t ram_size) |
| 671 | { |
| 672 | phys_size_t ram_top = ram_size; |
| 673 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 674 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
York Sun | 2db5408 | 2017-09-07 10:12:32 -0700 | [diff] [blame] | 675 | ram_top = mc_get_dram_block_size(); |
| 676 | if (ram_top > ram_size) |
| 677 | return ram_size + ram_top; |
| 678 | |
| 679 | ram_top = ram_size - ram_top; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 680 | /* The start address of MC reserved memory needs to be aligned. */ |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 681 | ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1); |
| 682 | #endif |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 683 | |
| 684 | return ram_size - ram_top; |
| 685 | } |
| 686 | |
| 687 | phys_size_t get_effective_memsize(void) |
| 688 | { |
| 689 | phys_size_t ea_size, rem = 0; |
| 690 | |
| 691 | /* |
| 692 | * 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] | 693 | * first region is 2GB space at 0x8000_0000. Secure memory needs to |
| 694 | * allocated from first region. If the memory extends to the second |
| 695 | * region (or the third region if applicable), Management Complex (MC) |
| 696 | * memory should be put into the highest region, i.e. the end of DDR |
| 697 | * memory. CONFIG_MAX_MEM_MAPPED is set to the size of first region so |
| 698 | * U-Boot doesn't relocate itself into higher address. Should DDR be |
| 699 | * configured to skip the first region, this function needs to be |
| 700 | * adjusted. |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 701 | */ |
| 702 | if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) { |
| 703 | ea_size = CONFIG_MAX_MEM_MAPPED; |
| 704 | rem = gd->ram_size - ea_size; |
| 705 | } else { |
| 706 | ea_size = gd->ram_size; |
| 707 | } |
| 708 | |
| 709 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
| 710 | /* Check if we have enough space for secure memory */ |
Sumit Garg | ed0deea | 2017-10-04 03:20:49 +0530 | [diff] [blame] | 711 | if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE) |
| 712 | ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE; |
| 713 | else |
| 714 | printf("Error: No enough space for secure memory.\n"); |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 715 | #endif |
| 716 | /* Check if we have enough memory for MC */ |
| 717 | if (rem < board_reserve_ram_top(rem)) { |
| 718 | /* Not enough memory in high region to reserve */ |
York Sun | 2db5408 | 2017-09-07 10:12:32 -0700 | [diff] [blame] | 719 | if (ea_size > board_reserve_ram_top(ea_size)) |
| 720 | ea_size -= board_reserve_ram_top(ea_size); |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 721 | else |
| 722 | printf("Error: No enough space for reserved memory.\n"); |
| 723 | } |
| 724 | |
| 725 | return ea_size; |
| 726 | } |
| 727 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 728 | int dram_init_banksize(void) |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 729 | { |
| 730 | #ifdef CONFIG_SYS_DP_DDR_BASE_PHY |
| 731 | phys_size_t dp_ddr_size; |
| 732 | #endif |
| 733 | |
| 734 | /* |
| 735 | * gd->ram_size has the total size of DDR memory, less reserved secure |
| 736 | * memory. The DDR extends from low region to high region(s) presuming |
| 737 | * no hole is created with DDR configuration. gd->arch.secure_ram tracks |
| 738 | * the location of secure memory. gd->arch.resv_ram tracks the location |
York Sun | c9e3e04 | 2017-09-28 08:42:12 -0700 | [diff] [blame] | 739 | * of reserved memory for Management Complex (MC). Because gd->ram_size |
| 740 | * is reduced by this function if secure memory is reserved, checking |
| 741 | * gd->arch.secure_ram should be done to avoid running it repeatedly. |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 742 | */ |
York Sun | c9e3e04 | 2017-09-28 08:42:12 -0700 | [diff] [blame] | 743 | |
| 744 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
| 745 | if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) { |
| 746 | debug("No need to run again, skip %s\n", __func__); |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | #endif |
| 751 | |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 752 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 753 | if (gd->ram_size > CONFIG_SYS_DDR_BLOCK1_SIZE) { |
| 754 | gd->bd->bi_dram[0].size = CONFIG_SYS_DDR_BLOCK1_SIZE; |
| 755 | gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE; |
| 756 | gd->bd->bi_dram[1].size = gd->ram_size - |
| 757 | CONFIG_SYS_DDR_BLOCK1_SIZE; |
| 758 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 759 | if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) { |
| 760 | gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE; |
| 761 | gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size - |
| 762 | CONFIG_SYS_DDR_BLOCK2_SIZE; |
| 763 | gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE; |
| 764 | } |
| 765 | #endif |
| 766 | } else { |
| 767 | gd->bd->bi_dram[0].size = gd->ram_size; |
| 768 | } |
| 769 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
Sumit Garg | ed0deea | 2017-10-04 03:20:49 +0530 | [diff] [blame] | 770 | if (gd->bd->bi_dram[0].size > |
| 771 | CONFIG_SYS_MEM_RESERVE_SECURE) { |
| 772 | gd->bd->bi_dram[0].size -= |
| 773 | CONFIG_SYS_MEM_RESERVE_SECURE; |
| 774 | gd->arch.secure_ram = gd->bd->bi_dram[0].start + |
| 775 | gd->bd->bi_dram[0].size; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 776 | gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED; |
| 777 | gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 778 | } |
| 779 | #endif /* CONFIG_SYS_MEM_RESERVE_SECURE */ |
| 780 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 781 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 782 | /* Assign memory for MC */ |
| 783 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 784 | if (gd->bd->bi_dram[2].size >= |
| 785 | board_reserve_ram_top(gd->bd->bi_dram[2].size)) { |
| 786 | gd->arch.resv_ram = gd->bd->bi_dram[2].start + |
| 787 | gd->bd->bi_dram[2].size - |
| 788 | board_reserve_ram_top(gd->bd->bi_dram[2].size); |
| 789 | } else |
| 790 | #endif |
| 791 | { |
| 792 | if (gd->bd->bi_dram[1].size >= |
| 793 | board_reserve_ram_top(gd->bd->bi_dram[1].size)) { |
| 794 | gd->arch.resv_ram = gd->bd->bi_dram[1].start + |
| 795 | gd->bd->bi_dram[1].size - |
| 796 | board_reserve_ram_top(gd->bd->bi_dram[1].size); |
| 797 | } else if (gd->bd->bi_dram[0].size > |
| 798 | board_reserve_ram_top(gd->bd->bi_dram[0].size)) { |
| 799 | gd->arch.resv_ram = gd->bd->bi_dram[0].start + |
| 800 | gd->bd->bi_dram[0].size - |
| 801 | board_reserve_ram_top(gd->bd->bi_dram[0].size); |
| 802 | } |
| 803 | } |
| 804 | #endif /* CONFIG_FSL_MC_ENET */ |
| 805 | |
| 806 | #ifdef CONFIG_SYS_DP_DDR_BASE_PHY |
| 807 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 808 | #error "This SoC shouldn't have DP DDR" |
| 809 | #endif |
| 810 | if (soc_has_dp_ddr()) { |
| 811 | /* initialize DP-DDR here */ |
| 812 | puts("DP-DDR: "); |
| 813 | /* |
| 814 | * DDR controller use 0 as the base address for binding. |
| 815 | * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access. |
| 816 | */ |
| 817 | dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY, |
| 818 | CONFIG_DP_DDR_CTRL, |
| 819 | CONFIG_DP_DDR_NUM_CTRLS, |
| 820 | CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR, |
| 821 | NULL, NULL, NULL); |
| 822 | if (dp_ddr_size) { |
| 823 | gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE; |
| 824 | gd->bd->bi_dram[2].size = dp_ddr_size; |
| 825 | } else { |
| 826 | puts("Not detected"); |
| 827 | } |
| 828 | } |
| 829 | #endif |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 830 | |
York Sun | c9e3e04 | 2017-09-28 08:42:12 -0700 | [diff] [blame] | 831 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
| 832 | debug("%s is called. gd->ram_size is reduced to %lu\n", |
| 833 | __func__, (ulong)gd->ram_size); |
| 834 | #endif |
| 835 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 836 | return 0; |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | #if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD) |
| 840 | void efi_add_known_memory(void) |
| 841 | { |
| 842 | int i; |
| 843 | phys_addr_t ram_start, start; |
| 844 | phys_size_t ram_size; |
| 845 | u64 pages; |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 846 | |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 847 | /* Add RAM */ |
| 848 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 849 | #ifdef CONFIG_SYS_DP_DDR_BASE_PHY |
| 850 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 851 | #error "This SoC shouldn't have DP DDR" |
| 852 | #endif |
| 853 | if (i == 2) |
| 854 | continue; /* skip DP-DDR */ |
| 855 | #endif |
| 856 | ram_start = gd->bd->bi_dram[i].start; |
| 857 | ram_size = gd->bd->bi_dram[i].size; |
| 858 | #ifdef CONFIG_RESV_RAM |
| 859 | if (gd->arch.resv_ram >= ram_start && |
| 860 | gd->arch.resv_ram < ram_start + ram_size) |
| 861 | ram_size = gd->arch.resv_ram - ram_start; |
| 862 | #endif |
| 863 | start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK; |
| 864 | pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; |
| 865 | |
| 866 | efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY, |
| 867 | false); |
| 868 | } |
York Sun | 928b681 | 2015-12-07 11:08:58 -0800 | [diff] [blame] | 869 | } |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 870 | #endif |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 871 | |
| 872 | /* |
| 873 | * Before DDR size is known, early MMU table have DDR mapped as device memory |
| 874 | * to avoid speculative access. To relocate U-Boot to DDR, "normal memory" |
| 875 | * needs to be set for these mappings. |
| 876 | * If a special case configures DDR with holes in the mapping, the holes need |
| 877 | * to be marked as invalid. This is not implemented in this function. |
| 878 | */ |
| 879 | void update_early_mmu_table(void) |
| 880 | { |
| 881 | if (!gd->arch.tlb_addr) |
| 882 | return; |
| 883 | |
| 884 | if (gd->ram_size <= CONFIG_SYS_FSL_DRAM_SIZE1) { |
| 885 | mmu_change_region_attr( |
| 886 | CONFIG_SYS_SDRAM_BASE, |
| 887 | gd->ram_size, |
| 888 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 889 | PTE_BLOCK_OUTER_SHARE | |
| 890 | PTE_BLOCK_NS | |
| 891 | PTE_TYPE_VALID); |
| 892 | } else { |
| 893 | mmu_change_region_attr( |
| 894 | CONFIG_SYS_SDRAM_BASE, |
| 895 | CONFIG_SYS_DDR_BLOCK1_SIZE, |
| 896 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 897 | PTE_BLOCK_OUTER_SHARE | |
| 898 | PTE_BLOCK_NS | |
| 899 | PTE_TYPE_VALID); |
| 900 | #ifdef CONFIG_SYS_DDR_BLOCK3_BASE |
| 901 | #ifndef CONFIG_SYS_DDR_BLOCK2_SIZE |
| 902 | #error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE" |
| 903 | #endif |
| 904 | if (gd->ram_size - CONFIG_SYS_DDR_BLOCK1_SIZE > |
| 905 | CONFIG_SYS_DDR_BLOCK2_SIZE) { |
| 906 | mmu_change_region_attr( |
| 907 | CONFIG_SYS_DDR_BLOCK2_BASE, |
| 908 | CONFIG_SYS_DDR_BLOCK2_SIZE, |
| 909 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 910 | PTE_BLOCK_OUTER_SHARE | |
| 911 | PTE_BLOCK_NS | |
| 912 | PTE_TYPE_VALID); |
| 913 | mmu_change_region_attr( |
| 914 | CONFIG_SYS_DDR_BLOCK3_BASE, |
| 915 | gd->ram_size - |
| 916 | CONFIG_SYS_DDR_BLOCK1_SIZE - |
| 917 | CONFIG_SYS_DDR_BLOCK2_SIZE, |
| 918 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 919 | PTE_BLOCK_OUTER_SHARE | |
| 920 | PTE_BLOCK_NS | |
| 921 | PTE_TYPE_VALID); |
| 922 | } else |
| 923 | #endif |
| 924 | { |
| 925 | mmu_change_region_attr( |
| 926 | CONFIG_SYS_DDR_BLOCK2_BASE, |
| 927 | gd->ram_size - |
| 928 | CONFIG_SYS_DDR_BLOCK1_SIZE, |
| 929 | PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 930 | PTE_BLOCK_OUTER_SHARE | |
| 931 | PTE_BLOCK_NS | |
| 932 | PTE_TYPE_VALID); |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | __weak int dram_init(void) |
| 938 | { |
Simon Glass | 0e0ac20 | 2017-04-06 12:47:04 -0600 | [diff] [blame] | 939 | fsl_initdram(); |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 940 | #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) |
| 941 | /* This will break-before-make MMU for DDR */ |
| 942 | update_early_mmu_table(); |
| 943 | #endif |
| 944 | |
| 945 | return 0; |
| 946 | } |