York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 9 | #include <asm/errno.h> |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 10 | #include <asm/system.h> |
| 11 | #include <asm/armv8/mmu.h> |
| 12 | #include <asm/io.h> |
Prabhakar Kushwaha | 2b4bf50 | 2015-05-28 14:54:06 +0530 | [diff] [blame] | 13 | #include <asm/arch-fsl-lsch3/soc.h> |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 14 | #include <asm/arch-fsl-lsch3/immap_lsch3.h> |
Bhupesh Sharma | 25b8efe | 2015-03-19 09:20:43 -0700 | [diff] [blame] | 15 | #include <fsl_debug_server.h> |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 16 | #include <fsl-mc/fsl_mc.h> |
Minghuan Lian | 0e3a2b9 | 2015-03-20 19:28:16 -0700 | [diff] [blame] | 17 | #include <asm/arch/fsl_serdes.h> |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 18 | #ifdef CONFIG_FSL_ESDHC |
| 19 | #include <fsl_esdhc.h> |
| 20 | #endif |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 21 | #include "cpu.h" |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 22 | #include "mp.h" |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 23 | #include "speed.h" |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
Prabhakar Kushwaha | 2b4bf50 | 2015-05-28 14:54:06 +0530 | [diff] [blame] | 27 | static struct cpu_type cpu_type_list[] = { |
| 28 | #ifdef CONFIG_LS2085A |
| 29 | CPU_TYPE_ENTRY(LS2085, LS2085, 8), |
| 30 | CPU_TYPE_ENTRY(LS2080, LS2080, 8), |
| 31 | CPU_TYPE_ENTRY(LS2045, LS2045, 4), |
| 32 | #endif |
| 33 | }; |
| 34 | |
| 35 | void cpu_name(char *name) |
| 36 | { |
| 37 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 38 | unsigned int i, svr, ver; |
| 39 | |
| 40 | svr = in_le32(&gur->svr); |
| 41 | ver = SVR_SOC_VER(svr); |
| 42 | |
| 43 | for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++) |
| 44 | if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) { |
| 45 | strcpy(name, cpu_type_list[i].name); |
| 46 | |
| 47 | if (IS_E_PROCESSOR(svr)) |
| 48 | strcat(name, "E"); |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | if (i == ARRAY_SIZE(cpu_type_list)) |
| 53 | strcpy(name, "unknown"); |
| 54 | } |
| 55 | |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 56 | #ifndef CONFIG_SYS_DCACHE_OFF |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 57 | |
| 58 | #define SECTION_SHIFT_L0 39UL |
| 59 | #define SECTION_SHIFT_L1 30UL |
| 60 | #define SECTION_SHIFT_L2 21UL |
| 61 | #define BLOCK_SIZE_L0 0x8000000000 |
| 62 | #define BLOCK_SIZE_L1 0x40000000 |
| 63 | #define BLOCK_SIZE_L2 0x200000 |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 64 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 65 | #define NUM_OF_ENTRY 512 |
| 66 | |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 67 | #define TCR_EL2_PS_40BIT (2 << 16) |
| 68 | #define LSCH3_VA_BITS (40) |
| 69 | #define LSCH3_TCR (TCR_TG0_4K | \ |
| 70 | TCR_EL2_PS_40BIT | \ |
| 71 | TCR_SHARED_NON | \ |
| 72 | TCR_ORGN_NC | \ |
| 73 | TCR_IRGN_NC | \ |
| 74 | TCR_T0SZ(LSCH3_VA_BITS)) |
Zhichun Hua | d75fcc5 | 2015-06-29 15:50:42 +0800 | [diff] [blame] | 75 | #define LSCH3_TCR_FINAL (TCR_TG0_4K | \ |
| 76 | TCR_EL2_PS_40BIT | \ |
| 77 | TCR_SHARED_OUTER | \ |
| 78 | TCR_ORGN_WBWA | \ |
| 79 | TCR_IRGN_WBWA | \ |
| 80 | TCR_T0SZ(LSCH3_VA_BITS)) |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 81 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 82 | #define CONFIG_SYS_FSL_CCSR_BASE 0x00000000 |
| 83 | #define CONFIG_SYS_FSL_CCSR_SIZE 0x10000000 |
| 84 | #define CONFIG_SYS_FSL_QSPI_BASE1 0x20000000 |
| 85 | #define CONFIG_SYS_FSL_QSPI_SIZE1 0x10000000 |
| 86 | #define CONFIG_SYS_FSL_IFC_BASE1 0x30000000 |
| 87 | #define CONFIG_SYS_FSL_IFC_SIZE1 0x10000000 |
| 88 | #define CONFIG_SYS_FSL_IFC_SIZE1_1 0x400000 |
| 89 | #define CONFIG_SYS_FSL_DRAM_BASE1 0x80000000 |
| 90 | #define CONFIG_SYS_FSL_DRAM_SIZE1 0x80000000 |
| 91 | #define CONFIG_SYS_FSL_QSPI_BASE2 0x400000000 |
| 92 | #define CONFIG_SYS_FSL_QSPI_SIZE2 0x100000000 |
| 93 | #define CONFIG_SYS_FSL_IFC_BASE2 0x500000000 |
| 94 | #define CONFIG_SYS_FSL_IFC_SIZE2 0x100000000 |
| 95 | #define CONFIG_SYS_FSL_DCSR_BASE 0x700000000 |
| 96 | #define CONFIG_SYS_FSL_DCSR_SIZE 0x40000000 |
| 97 | #define CONFIG_SYS_FSL_MC_BASE 0x80c000000 |
| 98 | #define CONFIG_SYS_FSL_MC_SIZE 0x4000000 |
| 99 | #define CONFIG_SYS_FSL_NI_BASE 0x810000000 |
| 100 | #define CONFIG_SYS_FSL_NI_SIZE 0x8000000 |
| 101 | #define CONFIG_SYS_FSL_QBMAN_BASE 0x818000000 |
| 102 | #define CONFIG_SYS_FSL_QBMAN_SIZE 0x8000000 |
| 103 | #define CONFIG_SYS_FSL_QBMAN_SIZE_1 0x4000000 |
| 104 | #define CONFIG_SYS_PCIE1_PHYS_SIZE 0x200000000 |
| 105 | #define CONFIG_SYS_PCIE2_PHYS_SIZE 0x200000000 |
| 106 | #define CONFIG_SYS_PCIE3_PHYS_SIZE 0x200000000 |
| 107 | #define CONFIG_SYS_PCIE4_PHYS_SIZE 0x200000000 |
| 108 | #define CONFIG_SYS_FSL_WRIOP1_BASE 0x4300000000 |
| 109 | #define CONFIG_SYS_FSL_WRIOP1_SIZE 0x100000000 |
| 110 | #define CONFIG_SYS_FSL_AIOP1_BASE 0x4b00000000 |
| 111 | #define CONFIG_SYS_FSL_AIOP1_SIZE 0x100000000 |
| 112 | #define CONFIG_SYS_FSL_PEBUF_BASE 0x4c00000000 |
| 113 | #define CONFIG_SYS_FSL_PEBUF_SIZE 0x400000000 |
| 114 | #define CONFIG_SYS_FSL_DRAM_BASE2 0x8080000000 |
| 115 | #define CONFIG_SYS_FSL_DRAM_SIZE2 0x7F80000000 |
| 116 | |
| 117 | struct sys_mmu_table { |
| 118 | u64 virt_addr; |
| 119 | u64 phys_addr; |
| 120 | u64 size; |
| 121 | u64 memory_type; |
| 122 | u64 share; |
| 123 | }; |
| 124 | |
| 125 | static const struct sys_mmu_table lsch3_early_mmu_table[] = { |
| 126 | { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE, |
| 127 | CONFIG_SYS_FSL_CCSR_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 128 | { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE, |
| 129 | CONFIG_SYS_FSL_OCRAM_SIZE, MT_NORMAL, PMD_SECT_NON_SHARE }, |
| 130 | /* For IFC Region #1, only the first 4MB is cache-enabled */ |
| 131 | { CONFIG_SYS_FSL_IFC_BASE1, CONFIG_SYS_FSL_IFC_BASE1, |
| 132 | CONFIG_SYS_FSL_IFC_SIZE1_1, MT_NORMAL, PMD_SECT_NON_SHARE }, |
| 133 | { CONFIG_SYS_FSL_IFC_BASE1 + CONFIG_SYS_FSL_IFC_SIZE1_1, |
| 134 | CONFIG_SYS_FSL_IFC_BASE1 + CONFIG_SYS_FSL_IFC_SIZE1_1, |
| 135 | CONFIG_SYS_FSL_IFC_SIZE1 - CONFIG_SYS_FSL_IFC_SIZE1_1, |
| 136 | MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 137 | { CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FSL_IFC_BASE1, |
| 138 | CONFIG_SYS_FSL_IFC_SIZE1, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 139 | { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1, |
| 140 | CONFIG_SYS_FSL_DRAM_SIZE1, MT_NORMAL, PMD_SECT_OUTER_SHARE }, |
| 141 | { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE, |
| 142 | CONFIG_SYS_FSL_DCSR_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 143 | { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2, |
| 144 | CONFIG_SYS_FSL_DRAM_SIZE2, MT_NORMAL, PMD_SECT_OUTER_SHARE }, |
| 145 | }; |
| 146 | |
| 147 | static const struct sys_mmu_table lsch3_final_mmu_table[] = { |
| 148 | { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE, |
| 149 | CONFIG_SYS_FSL_CCSR_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 150 | { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE, |
| 151 | CONFIG_SYS_FSL_OCRAM_SIZE, MT_NORMAL, PMD_SECT_NON_SHARE }, |
| 152 | { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1, |
| 153 | CONFIG_SYS_FSL_DRAM_SIZE1, MT_NORMAL, PMD_SECT_OUTER_SHARE }, |
| 154 | { CONFIG_SYS_FSL_QSPI_BASE2, CONFIG_SYS_FSL_QSPI_BASE2, |
| 155 | CONFIG_SYS_FSL_QSPI_SIZE2, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 156 | { CONFIG_SYS_FSL_IFC_BASE2, CONFIG_SYS_FSL_IFC_BASE2, |
| 157 | CONFIG_SYS_FSL_IFC_SIZE2, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 158 | { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE, |
| 159 | CONFIG_SYS_FSL_DCSR_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 160 | { CONFIG_SYS_FSL_MC_BASE, CONFIG_SYS_FSL_MC_BASE, |
| 161 | CONFIG_SYS_FSL_MC_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 162 | { CONFIG_SYS_FSL_NI_BASE, CONFIG_SYS_FSL_NI_BASE, |
| 163 | CONFIG_SYS_FSL_NI_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 164 | /* For QBMAN portal, only the first 64MB is cache-enabled */ |
| 165 | { CONFIG_SYS_FSL_QBMAN_BASE, CONFIG_SYS_FSL_QBMAN_BASE, |
| 166 | CONFIG_SYS_FSL_QBMAN_SIZE_1, MT_NORMAL, PMD_SECT_NON_SHARE }, |
| 167 | { CONFIG_SYS_FSL_QBMAN_BASE + CONFIG_SYS_FSL_QBMAN_SIZE_1, |
| 168 | CONFIG_SYS_FSL_QBMAN_BASE + CONFIG_SYS_FSL_QBMAN_SIZE_1, |
| 169 | CONFIG_SYS_FSL_QBMAN_SIZE - CONFIG_SYS_FSL_QBMAN_SIZE_1, |
| 170 | MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 171 | { CONFIG_SYS_PCIE1_PHYS_ADDR, CONFIG_SYS_PCIE1_PHYS_ADDR, |
| 172 | CONFIG_SYS_PCIE1_PHYS_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 173 | { CONFIG_SYS_PCIE2_PHYS_ADDR, CONFIG_SYS_PCIE2_PHYS_ADDR, |
| 174 | CONFIG_SYS_PCIE2_PHYS_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 175 | { CONFIG_SYS_PCIE3_PHYS_ADDR, CONFIG_SYS_PCIE3_PHYS_ADDR, |
| 176 | CONFIG_SYS_PCIE3_PHYS_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 177 | #ifdef CONFIG_LS2085A |
| 178 | { CONFIG_SYS_PCIE4_PHYS_ADDR, CONFIG_SYS_PCIE4_PHYS_ADDR, |
| 179 | CONFIG_SYS_PCIE4_PHYS_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 180 | #endif |
| 181 | { CONFIG_SYS_FSL_WRIOP1_BASE, CONFIG_SYS_FSL_WRIOP1_BASE, |
| 182 | CONFIG_SYS_FSL_WRIOP1_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 183 | { CONFIG_SYS_FSL_AIOP1_BASE, CONFIG_SYS_FSL_AIOP1_BASE, |
| 184 | CONFIG_SYS_FSL_AIOP1_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 185 | { CONFIG_SYS_FSL_PEBUF_BASE, CONFIG_SYS_FSL_PEBUF_BASE, |
| 186 | CONFIG_SYS_FSL_PEBUF_SIZE, MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE }, |
| 187 | { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2, |
| 188 | CONFIG_SYS_FSL_DRAM_SIZE2, MT_NORMAL, PMD_SECT_OUTER_SHARE }, |
| 189 | }; |
| 190 | |
| 191 | struct table_info { |
| 192 | u64 *ptr; |
| 193 | u64 table_base; |
| 194 | u64 entry_size; |
| 195 | }; |
| 196 | |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 197 | /* |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 198 | * Set the block entries according to the information of the table. |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 199 | */ |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 200 | static int set_block_entry(const struct sys_mmu_table *list, |
| 201 | struct table_info *table) |
| 202 | { |
| 203 | u64 block_size = 0, block_shift = 0; |
| 204 | u64 block_addr, index; |
| 205 | int j; |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 206 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 207 | if (table->entry_size == BLOCK_SIZE_L1) { |
| 208 | block_size = BLOCK_SIZE_L1; |
| 209 | block_shift = SECTION_SHIFT_L1; |
| 210 | } else if (table->entry_size == BLOCK_SIZE_L2) { |
| 211 | block_size = BLOCK_SIZE_L2; |
| 212 | block_shift = SECTION_SHIFT_L2; |
| 213 | } else { |
| 214 | return -EINVAL; |
| 215 | } |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 216 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 217 | block_addr = list->phys_addr; |
| 218 | index = (list->virt_addr - table->table_base) >> block_shift; |
| 219 | |
| 220 | for (j = 0; j < (list->size >> block_shift); j++) { |
| 221 | set_pgtable_section(table->ptr, |
| 222 | index, |
| 223 | block_addr, |
| 224 | list->memory_type, |
| 225 | list->share); |
| 226 | block_addr += block_size; |
| 227 | index++; |
| 228 | } |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Find the corresponding table entry for the list. |
| 235 | */ |
| 236 | static int find_table(const struct sys_mmu_table *list, |
| 237 | struct table_info *table, u64 *level0_table) |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 238 | { |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 239 | u64 index = 0, level = 0; |
| 240 | u64 *level_table = level0_table; |
| 241 | u64 temp_base = 0, block_size = 0, block_shift = 0; |
| 242 | |
| 243 | while (level < 3) { |
| 244 | if (level == 0) { |
| 245 | block_size = BLOCK_SIZE_L0; |
| 246 | block_shift = SECTION_SHIFT_L0; |
| 247 | } else if (level == 1) { |
| 248 | block_size = BLOCK_SIZE_L1; |
| 249 | block_shift = SECTION_SHIFT_L1; |
| 250 | } else if (level == 2) { |
| 251 | block_size = BLOCK_SIZE_L2; |
| 252 | block_shift = SECTION_SHIFT_L2; |
| 253 | } |
| 254 | |
| 255 | index = 0; |
| 256 | while (list->virt_addr >= temp_base) { |
| 257 | index++; |
| 258 | temp_base += block_size; |
| 259 | } |
| 260 | |
| 261 | temp_base -= block_size; |
| 262 | |
| 263 | if ((level_table[index - 1] & PMD_TYPE_MASK) == |
| 264 | PMD_TYPE_TABLE) { |
| 265 | level_table = (u64 *)(level_table[index - 1] & |
| 266 | ~PMD_TYPE_MASK); |
| 267 | level++; |
| 268 | continue; |
| 269 | } else { |
| 270 | if (level == 0) |
| 271 | return -EINVAL; |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 272 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 273 | if ((list->phys_addr + list->size) > |
| 274 | (temp_base + block_size * NUM_OF_ENTRY)) |
| 275 | return -EINVAL; |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 276 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 277 | /* |
| 278 | * Check the address and size of the list member is |
| 279 | * aligned with the block size. |
| 280 | */ |
| 281 | if (((list->phys_addr & (block_size - 1)) != 0) || |
| 282 | ((list->size & (block_size - 1)) != 0)) |
| 283 | return -EINVAL; |
| 284 | |
| 285 | table->ptr = level_table; |
| 286 | table->table_base = temp_base - |
| 287 | ((index - 1) << block_shift); |
| 288 | table->entry_size = block_size; |
| 289 | |
| 290 | return 0; |
| 291 | } |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 292 | } |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 293 | return -EINVAL; |
| 294 | } |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 295 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 296 | /* |
| 297 | * To start MMU before DDR is available, we create MMU table in SRAM. |
| 298 | * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three |
| 299 | * levels of translation tables here to cover 40-bit address space. |
| 300 | * We use 4KB granule size, with 40 bits physical address, T0SZ=24 |
| 301 | * Level 0 IA[39], table address @0 |
| 302 | * Level 1 IA[38:30], table address @0x1000, 0x2000 |
| 303 | * Level 2 IA[29:21], table address @0x3000, 0x4000 |
| 304 | * Address above 0x5000 is free for other purpose. |
| 305 | */ |
| 306 | static inline void early_mmu_setup(void) |
| 307 | { |
| 308 | unsigned int el, i; |
| 309 | u64 *level0_table = (u64 *)CONFIG_SYS_FSL_OCRAM_BASE; |
| 310 | u64 *level1_table0 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE + 0x1000); |
| 311 | u64 *level1_table1 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE + 0x2000); |
| 312 | u64 *level2_table0 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE + 0x3000); |
| 313 | u64 *level2_table1 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE + 0x4000); |
| 314 | struct table_info table = {level0_table, 0, BLOCK_SIZE_L0}; |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 315 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 316 | /* Invalidate all table entries */ |
| 317 | memset(level0_table, 0, 0x5000); |
York Sun | 820a18f | 2015-03-20 19:28:11 -0700 | [diff] [blame] | 318 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 319 | /* Fill in the table entries */ |
| 320 | set_pgtable_table(level0_table, 0, level1_table0); |
| 321 | set_pgtable_table(level0_table, 1, level1_table1); |
| 322 | set_pgtable_table(level1_table0, 0, level2_table0); |
| 323 | set_pgtable_table(level1_table0, |
| 324 | CONFIG_SYS_FLASH_BASE >> SECTION_SHIFT_L1, |
| 325 | level2_table1); |
York Sun | 820a18f | 2015-03-20 19:28:11 -0700 | [diff] [blame] | 326 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 327 | /* Find the table and fill in the block entries */ |
| 328 | for (i = 0; i < ARRAY_SIZE(lsch3_early_mmu_table); i++) { |
| 329 | if (find_table(&lsch3_early_mmu_table[i], |
| 330 | &table, level0_table) == 0) { |
| 331 | /* |
| 332 | * If find_table() returns error, it cannot be dealt |
| 333 | * with here. Breakpoint can be added for debugging. |
| 334 | */ |
| 335 | set_block_entry(&lsch3_early_mmu_table[i], &table); |
| 336 | /* |
| 337 | * If set_block_entry() returns error, it cannot be |
| 338 | * dealt with here too. |
| 339 | */ |
| 340 | } |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | el = current_el(); |
| 344 | set_ttbr_tcr_mair(el, (u64)level0_table, LSCH3_TCR, MEMORY_ATTRIBUTES); |
| 345 | set_sctlr(get_sctlr() | CR_M); |
| 346 | } |
| 347 | |
| 348 | /* |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 349 | * The final tables look similar to early tables, but different in detail. |
| 350 | * These tables are in DRAM. Sub tables are added to enable cache for |
| 351 | * QBMan and OCRAM. |
| 352 | * |
| 353 | * Level 1 table 0 contains 512 entries for each 1GB from 0 to 512GB. |
| 354 | * Level 1 table 1 contains 512 entries for each 1GB from 512GB to 1TB. |
| 355 | * Level 2 table 0 contains 512 entries for each 2MB from 0 to 1GB. |
| 356 | * Level 2 table 1 contains 512 entries for each 2MB from 32GB to 33GB. |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 357 | */ |
| 358 | static inline void final_mmu_setup(void) |
| 359 | { |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 360 | unsigned int el, i; |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 361 | u64 *level0_table = (u64 *)gd->arch.tlb_addr; |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 362 | u64 *level1_table0 = (u64 *)(gd->arch.tlb_addr + 0x1000); |
| 363 | u64 *level1_table1 = (u64 *)(gd->arch.tlb_addr + 0x2000); |
| 364 | u64 *level2_table0 = (u64 *)(gd->arch.tlb_addr + 0x3000); |
| 365 | u64 *level2_table1 = (u64 *)(gd->arch.tlb_addr + 0x4000); |
| 366 | struct table_info table = {level0_table, 0, BLOCK_SIZE_L0}; |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 367 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 368 | /* Invalidate all table entries */ |
| 369 | memset(level0_table, 0, PGTABLE_SIZE); |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 370 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 371 | /* Fill in the table entries */ |
| 372 | set_pgtable_table(level0_table, 0, level1_table0); |
| 373 | set_pgtable_table(level0_table, 1, level1_table1); |
| 374 | set_pgtable_table(level1_table0, 0, level2_table0); |
| 375 | set_pgtable_table(level1_table0, |
| 376 | CONFIG_SYS_FSL_QBMAN_BASE >> SECTION_SHIFT_L1, |
| 377 | level2_table1); |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 378 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 379 | /* Find the table and fill in the block entries */ |
| 380 | for (i = 0; i < ARRAY_SIZE(lsch3_final_mmu_table); i++) { |
| 381 | if (find_table(&lsch3_final_mmu_table[i], |
| 382 | &table, level0_table) == 0) { |
| 383 | if (set_block_entry(&lsch3_final_mmu_table[i], |
| 384 | &table) != 0) { |
| 385 | printf("MMU error: could not set block entry for %p\n", |
| 386 | &lsch3_final_mmu_table[i]); |
| 387 | } |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 388 | |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 389 | } else { |
| 390 | printf("MMU error: could not find the table for %p\n", |
| 391 | &lsch3_final_mmu_table[i]); |
| 392 | } |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /* flush new MMU table */ |
| 396 | flush_dcache_range(gd->arch.tlb_addr, |
Alison Wang | 7f8e178 | 2015-08-18 11:22:05 +0800 | [diff] [blame] | 397 | gd->arch.tlb_addr + gd->arch.tlb_size); |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 398 | |
| 399 | /* point TTBR to the new table */ |
| 400 | el = current_el(); |
Zhichun Hua | d75fcc5 | 2015-06-29 15:50:42 +0800 | [diff] [blame] | 401 | set_ttbr_tcr_mair(el, (u64)level0_table, LSCH3_TCR_FINAL, |
| 402 | MEMORY_ATTRIBUTES); |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 403 | /* |
| 404 | * MMU is already enabled, just need to invalidate TLB to load the |
| 405 | * new table. The new table is compatible with the current table, if |
| 406 | * MMU somehow walks through the new table before invalidation TLB, |
| 407 | * it still works. So we don't need to turn off MMU here. |
| 408 | */ |
| 409 | } |
| 410 | |
| 411 | int arch_cpu_init(void) |
| 412 | { |
| 413 | icache_enable(); |
| 414 | __asm_invalidate_dcache_all(); |
| 415 | __asm_invalidate_tlb_all(); |
| 416 | early_mmu_setup(); |
| 417 | set_sctlr(get_sctlr() | CR_C); |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | /* |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 422 | * This function is called from lib/board.c. |
| 423 | * It recreates MMU table in main memory. MMU and d-cache are enabled earlier. |
| 424 | * There is no need to disable d-cache for this operation. |
| 425 | */ |
| 426 | void enable_caches(void) |
| 427 | { |
| 428 | final_mmu_setup(); |
| 429 | __asm_invalidate_tlb_all(); |
| 430 | } |
| 431 | #endif |
| 432 | |
| 433 | static inline u32 initiator_type(u32 cluster, int init_id) |
| 434 | { |
| 435 | struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 436 | u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK; |
| 437 | u32 type = in_le32(&gur->tp_ityp[idx]); |
| 438 | |
| 439 | if (type & TP_ITYP_AV) |
| 440 | return type; |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | u32 cpu_mask(void) |
| 446 | { |
| 447 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 448 | int i = 0, count = 0; |
| 449 | u32 cluster, type, mask = 0; |
| 450 | |
| 451 | do { |
| 452 | int j; |
| 453 | cluster = in_le32(&gur->tp_cluster[i].lower); |
| 454 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 455 | type = initiator_type(cluster, j); |
| 456 | if (type) { |
| 457 | if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM) |
| 458 | mask |= 1 << count; |
| 459 | count++; |
| 460 | } |
| 461 | } |
| 462 | i++; |
| 463 | } while ((cluster & TP_CLUSTER_EOC) != TP_CLUSTER_EOC); |
| 464 | |
| 465 | return mask; |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * Return the number of cores on this SOC. |
| 470 | */ |
| 471 | int cpu_numcores(void) |
| 472 | { |
| 473 | return hweight32(cpu_mask()); |
| 474 | } |
| 475 | |
| 476 | int fsl_qoriq_core_to_cluster(unsigned int core) |
| 477 | { |
| 478 | struct ccsr_gur __iomem *gur = |
| 479 | (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 480 | int i = 0, count = 0; |
| 481 | u32 cluster; |
| 482 | |
| 483 | do { |
| 484 | int j; |
| 485 | cluster = in_le32(&gur->tp_cluster[i].lower); |
| 486 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 487 | if (initiator_type(cluster, j)) { |
| 488 | if (count == core) |
| 489 | return i; |
| 490 | count++; |
| 491 | } |
| 492 | } |
| 493 | i++; |
| 494 | } while ((cluster & TP_CLUSTER_EOC) != TP_CLUSTER_EOC); |
| 495 | |
| 496 | return -1; /* cannot identify the cluster */ |
| 497 | } |
| 498 | |
| 499 | u32 fsl_qoriq_core_to_type(unsigned int core) |
| 500 | { |
| 501 | struct ccsr_gur __iomem *gur = |
| 502 | (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 503 | int i = 0, count = 0; |
| 504 | u32 cluster, type; |
| 505 | |
| 506 | do { |
| 507 | int j; |
| 508 | cluster = in_le32(&gur->tp_cluster[i].lower); |
| 509 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 510 | type = initiator_type(cluster, j); |
| 511 | if (type) { |
| 512 | if (count == core) |
| 513 | return type; |
| 514 | count++; |
| 515 | } |
| 516 | } |
| 517 | i++; |
| 518 | } while ((cluster & TP_CLUSTER_EOC) != TP_CLUSTER_EOC); |
| 519 | |
| 520 | return -1; /* cannot identify the cluster */ |
| 521 | } |
| 522 | |
| 523 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 524 | int print_cpuinfo(void) |
| 525 | { |
Bhupesh Sharma | c6af127 | 2015-03-20 19:28:20 -0700 | [diff] [blame] | 526 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 527 | struct sys_info sysinfo; |
| 528 | char buf[32]; |
| 529 | unsigned int i, core; |
| 530 | u32 type; |
| 531 | |
Prabhakar Kushwaha | 2b4bf50 | 2015-05-28 14:54:06 +0530 | [diff] [blame] | 532 | puts("SoC: "); |
| 533 | |
| 534 | cpu_name(buf); |
| 535 | printf(" %s (0x%x)\n", buf, in_le32(&gur->svr)); |
| 536 | |
| 537 | memset((u8 *)buf, 0x00, ARRAY_SIZE(buf)); |
| 538 | |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 539 | get_sys_info(&sysinfo); |
| 540 | puts("Clock Configuration:"); |
| 541 | for_each_cpu(i, core, cpu_numcores(), cpu_mask()) { |
| 542 | if (!(i % 3)) |
| 543 | puts("\n "); |
| 544 | type = TP_ITYP_VER(fsl_qoriq_core_to_type(core)); |
| 545 | printf("CPU%d(%s):%-4s MHz ", core, |
| 546 | type == TY_ITYP_VER_A7 ? "A7 " : |
| 547 | (type == TY_ITYP_VER_A53 ? "A53" : |
| 548 | (type == TY_ITYP_VER_A57 ? "A57" : " ")), |
| 549 | strmhz(buf, sysinfo.freq_processor[core])); |
| 550 | } |
| 551 | printf("\n Bus: %-4s MHz ", |
| 552 | strmhz(buf, sysinfo.freq_systembus)); |
York Sun | 33279fe | 2015-05-28 14:54:05 +0530 | [diff] [blame] | 553 | printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus)); |
| 554 | printf(" DP-DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus2)); |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 555 | puts("\n"); |
| 556 | |
Bhupesh Sharma | c6af127 | 2015-03-20 19:28:20 -0700 | [diff] [blame] | 557 | /* Display the RCW, so that no one gets confused as to what RCW |
| 558 | * we're actually using for this boot. |
| 559 | */ |
| 560 | puts("Reset Configuration Word (RCW):"); |
| 561 | for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) { |
| 562 | u32 rcw = in_le32(&gur->rcwsr[i]); |
| 563 | |
| 564 | if ((i % 4) == 0) |
| 565 | printf("\n %02x:", i * 4); |
| 566 | printf(" %08x", rcw); |
| 567 | } |
| 568 | puts("\n"); |
| 569 | |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | #endif |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 573 | |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 574 | #ifdef CONFIG_FSL_ESDHC |
| 575 | int cpu_mmc_init(bd_t *bis) |
| 576 | { |
| 577 | return fsl_esdhc_mmc_init(bis); |
| 578 | } |
| 579 | #endif |
| 580 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 581 | int cpu_eth_init(bd_t *bis) |
| 582 | { |
| 583 | int error = 0; |
| 584 | |
| 585 | #ifdef CONFIG_FSL_MC_ENET |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 586 | error = fsl_mc_ldpaa_init(bis); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 587 | #endif |
| 588 | return error; |
| 589 | } |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 590 | |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 591 | int arch_early_init_r(void) |
| 592 | { |
| 593 | int rv; |
| 594 | rv = fsl_lsch3_wake_seconday_cores(); |
| 595 | |
| 596 | if (rv) |
| 597 | printf("Did not wake secondary cores\n"); |
| 598 | |
Minghuan Lian | 0e3a2b9 | 2015-03-20 19:28:16 -0700 | [diff] [blame] | 599 | #ifdef CONFIG_SYS_HAS_SERDES |
| 600 | fsl_serdes_init(); |
| 601 | #endif |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 602 | return 0; |
| 603 | } |
York Sun | 77a1097 | 2015-03-20 19:28:08 -0700 | [diff] [blame] | 604 | |
| 605 | int timer_init(void) |
| 606 | { |
| 607 | u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR; |
| 608 | u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR; |
| 609 | #ifdef COUNTER_FREQUENCY_REAL |
| 610 | unsigned long cntfrq = COUNTER_FREQUENCY_REAL; |
| 611 | |
| 612 | /* Update with accurate clock frequency */ |
| 613 | asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory"); |
| 614 | #endif |
| 615 | |
| 616 | /* Enable timebase for all clusters. |
| 617 | * It is safe to do so even some clusters are not enabled. |
| 618 | */ |
| 619 | out_le32(cltbenr, 0xf); |
| 620 | |
| 621 | /* Enable clock for timer |
| 622 | * This is a global setting. |
| 623 | */ |
| 624 | out_le32(cntcr, 0x1); |
| 625 | |
| 626 | return 0; |
| 627 | } |
pankaj chauhan | 6b99e7d | 2015-03-20 19:28:09 -0700 | [diff] [blame] | 628 | |
| 629 | void reset_cpu(ulong addr) |
| 630 | { |
| 631 | u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR; |
| 632 | u32 val; |
| 633 | |
| 634 | /* Raise RESET_REQ_B */ |
| 635 | val = in_le32(rstcr); |
| 636 | val |= 0x02; |
| 637 | out_le32(rstcr, val); |
| 638 | } |