2 * Copyright 2014 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/system.h>
10 #include <asm/armv8/mmu.h>
12 #include <asm/arch-fsl-lsch3/soc.h>
13 #include <asm/arch-fsl-lsch3/immap_lsch3.h>
14 #include <fsl_debug_server.h>
15 #include <fsl-mc/fsl_mc.h>
16 #include <asm/arch/fsl_serdes.h>
17 #ifdef CONFIG_FSL_ESDHC
18 #include <fsl_esdhc.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 static struct cpu_type cpu_type_list[] = {
28 CPU_TYPE_ENTRY(LS2085, LS2085, 8),
29 CPU_TYPE_ENTRY(LS2080, LS2080, 8),
30 CPU_TYPE_ENTRY(LS2045, LS2045, 4),
34 void cpu_name(char *name)
36 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
37 unsigned int i, svr, ver;
39 svr = in_le32(&gur->svr);
40 ver = SVR_SOC_VER(svr);
42 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
43 if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) {
44 strcpy(name, cpu_type_list[i].name);
46 if (IS_E_PROCESSOR(svr))
51 if (i == ARRAY_SIZE(cpu_type_list))
52 strcpy(name, "unknown");
55 #ifndef CONFIG_SYS_DCACHE_OFF
57 * To start MMU before DDR is available, we create MMU table in SRAM.
58 * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three
59 * levels of translation tables here to cover 40-bit address space.
60 * We use 4KB granule size, with 40 bits physical address, T0SZ=24
61 * Level 0 IA[39], table address @0
62 * Level 1 IA[31:30], table address @0x1000, 0x2000
63 * Level 2 IA[29:21], table address @0x3000, 0x4000
64 * Address above 0x5000 is free for other purpose.
67 #define SECTION_SHIFT_L0 39UL
68 #define SECTION_SHIFT_L1 30UL
69 #define SECTION_SHIFT_L2 21UL
70 #define BLOCK_SIZE_L0 0x8000000000UL
71 #define BLOCK_SIZE_L1 (1 << SECTION_SHIFT_L1)
72 #define BLOCK_SIZE_L2 (1 << SECTION_SHIFT_L2)
73 #define CONFIG_SYS_IFC_BASE 0x30000000
74 #define CONFIG_SYS_IFC_SIZE 0x10000000
75 #define CONFIG_SYS_IFC_BASE2 0x500000000
76 #define CONFIG_SYS_IFC_SIZE2 0x100000000
77 #define TCR_EL2_PS_40BIT (2 << 16)
78 #define LSCH3_VA_BITS (40)
79 #define LSCH3_TCR (TCR_TG0_4K | \
84 TCR_T0SZ(LSCH3_VA_BITS))
88 * Let's start from the same layout as early MMU and modify as needed.
89 * IFC regions will be cache-inhibit.
91 #define FINAL_QBMAN_CACHED_MEM 0x818000000UL
92 #define FINAL_QBMAN_CACHED_SIZE 0x4000000
95 static inline void early_mmu_setup(void)
99 u64 section_l1t0, section_l1t1, section_l2t0, section_l2t1;
100 u64 *level0_table = (u64 *)CONFIG_SYS_FSL_OCRAM_BASE;
101 u64 *level1_table_0 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE + 0x1000);
102 u64 *level1_table_1 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE + 0x2000);
103 u64 *level2_table_0 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE + 0x3000);
104 u64 *level2_table_1 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE + 0x4000);
107 (u64)level1_table_0 | PMD_TYPE_TABLE;
109 (u64)level1_table_1 | PMD_TYPE_TABLE;
112 * set level 1 table 0 to cache_inhibit, covering 0 to 512GB
113 * set level 1 table 1 to cache enabled, covering 512GB to 1TB
114 * set level 2 table to cache-inhibit, covering 0 to 1GB
117 section_l1t1 = BLOCK_SIZE_L0;
119 section_l2t1 = CONFIG_SYS_FLASH_BASE;
120 for (i = 0; i < 512; i++) {
121 set_pgtable_section(level1_table_0, i, section_l1t0,
123 set_pgtable_section(level1_table_1, i, section_l1t1,
125 set_pgtable_section(level2_table_0, i, section_l2t0,
127 set_pgtable_section(level2_table_1, i, section_l2t1,
129 section_l1t0 += BLOCK_SIZE_L1;
130 section_l1t1 += BLOCK_SIZE_L1;
131 section_l2t0 += BLOCK_SIZE_L2;
132 section_l2t1 += BLOCK_SIZE_L2;
136 (u64)level2_table_0 | PMD_TYPE_TABLE;
138 0x40000000 | PMD_SECT_AF | PMD_TYPE_SECT |
139 PMD_ATTRINDX(MT_DEVICE_NGNRNE);
141 0x80000000 | PMD_SECT_AF | PMD_TYPE_SECT |
142 PMD_ATTRINDX(MT_NORMAL);
144 0xc0000000 | PMD_SECT_AF | PMD_TYPE_SECT |
145 PMD_ATTRINDX(MT_NORMAL);
147 /* Rewerite table to enable cache for OCRAM */
148 set_pgtable_section(level2_table_0,
149 CONFIG_SYS_FSL_OCRAM_BASE >> SECTION_SHIFT_L2,
150 CONFIG_SYS_FSL_OCRAM_BASE,
153 #if defined(CONFIG_SYS_NOR0_CSPR_EARLY) && defined(CONFIG_SYS_NOR_AMASK_EARLY)
154 /* Rewrite table to enable cache for two entries (4MB) */
155 section_l2t1 = CONFIG_SYS_IFC_BASE;
156 set_pgtable_section(level2_table_0,
157 section_l2t1 >> SECTION_SHIFT_L2,
160 section_l2t1 += BLOCK_SIZE_L2;
161 set_pgtable_section(level2_table_0,
162 section_l2t1 >> SECTION_SHIFT_L2,
167 /* Create a mapping for 256MB IFC region to final flash location */
168 level1_table_0[CONFIG_SYS_FLASH_BASE >> SECTION_SHIFT_L1] =
169 (u64)level2_table_1 | PMD_TYPE_TABLE;
170 section_l2t1 = CONFIG_SYS_IFC_BASE;
171 for (i = 0; i < 0x10000000 >> SECTION_SHIFT_L2; i++) {
172 set_pgtable_section(level2_table_1, i,
173 section_l2t1, MT_DEVICE_NGNRNE);
174 section_l2t1 += BLOCK_SIZE_L2;
178 set_ttbr_tcr_mair(el, (u64)level0_table, LSCH3_TCR, MEMORY_ATTRIBUTES);
179 set_sctlr(get_sctlr() | CR_M);
183 * This final tale looks similar to early table, but different in detail.
184 * These tables are in regular memory. Cache on IFC is disabled. One sub table
185 * is added to enable cache for QBMan.
187 static inline void final_mmu_setup(void)
190 u64 i, tbl_base, tbl_limit, section_base;
191 u64 section_l1t0, section_l1t1, section_l2;
192 u64 *level0_table = (u64 *)gd->arch.tlb_addr;
193 u64 *level1_table_0 = (u64 *)(gd->arch.tlb_addr + 0x1000);
194 u64 *level1_table_1 = (u64 *)(gd->arch.tlb_addr + 0x2000);
195 u64 *level2_table_0 = (u64 *)(gd->arch.tlb_addr + 0x3000);
196 u64 *level2_table_1 = (u64 *)(gd->arch.tlb_addr + 0x4000);
200 (u64)level1_table_0 | PMD_TYPE_TABLE;
202 (u64)level1_table_1 | PMD_TYPE_TABLE;
205 * set level 1 table 0 to cache_inhibit, covering 0 to 512GB
206 * set level 1 table 1 to cache enabled, covering 512GB to 1TB
207 * set level 2 table 0 to cache-inhibit, covering 0 to 1GB
210 section_l1t1 = BLOCK_SIZE_L0 | PMD_SECT_OUTER_SHARE;
212 for (i = 0; i < 512; i++) {
213 set_pgtable_section(level1_table_0, i, section_l1t0,
215 set_pgtable_section(level1_table_1, i, section_l1t1,
217 set_pgtable_section(level2_table_0, i, section_l2,
219 section_l1t0 += BLOCK_SIZE_L1;
220 section_l1t1 += BLOCK_SIZE_L1;
221 section_l2 += BLOCK_SIZE_L2;
225 (u64)level2_table_0 | PMD_TYPE_TABLE;
227 0x80000000 | PMD_SECT_AF | PMD_TYPE_SECT |
228 PMD_SECT_OUTER_SHARE | PMD_ATTRINDX(MT_NORMAL);
230 0xc0000000 | PMD_SECT_AF | PMD_TYPE_SECT |
231 PMD_SECT_OUTER_SHARE | PMD_ATTRINDX(MT_NORMAL);
233 /* Rewrite table to enable cache */
234 set_pgtable_section(level2_table_0,
235 CONFIG_SYS_FSL_OCRAM_BASE >> SECTION_SHIFT_L2,
236 CONFIG_SYS_FSL_OCRAM_BASE,
240 * Fill in other part of tables if cache is needed
241 * If finer granularity than 1GB is needed, sub table
244 section_base = FINAL_QBMAN_CACHED_MEM & ~(BLOCK_SIZE_L1 - 1);
245 i = section_base >> SECTION_SHIFT_L1;
246 level1_table_0[i] = (u64)level2_table_1 | PMD_TYPE_TABLE;
247 section_l2 = section_base;
248 for (i = 0; i < 512; i++) {
249 set_pgtable_section(level2_table_1, i, section_l2,
251 section_l2 += BLOCK_SIZE_L2;
253 tbl_base = FINAL_QBMAN_CACHED_MEM & (BLOCK_SIZE_L1 - 1);
254 tbl_limit = (FINAL_QBMAN_CACHED_MEM + FINAL_QBMAN_CACHED_SIZE) &
256 for (i = tbl_base >> SECTION_SHIFT_L2;
257 i < tbl_limit >> SECTION_SHIFT_L2; i++) {
258 section_l2 = section_base + (i << SECTION_SHIFT_L2);
259 set_pgtable_section(level2_table_1, i,
260 section_l2, MT_NORMAL);
263 /* flush new MMU table */
264 flush_dcache_range(gd->arch.tlb_addr,
265 gd->arch.tlb_addr + gd->arch.tlb_size);
267 /* point TTBR to the new table */
269 asm volatile("dsb sy");
271 asm volatile("msr ttbr0_el1, %0"
272 : : "r" ((u64)level0_table) : "memory");
273 } else if (el == 2) {
274 asm volatile("msr ttbr0_el2, %0"
275 : : "r" ((u64)level0_table) : "memory");
276 } else if (el == 3) {
277 asm volatile("msr ttbr0_el3, %0"
278 : : "r" ((u64)level0_table) : "memory");
285 * MMU is already enabled, just need to invalidate TLB to load the
286 * new table. The new table is compatible with the current table, if
287 * MMU somehow walks through the new table before invalidation TLB,
288 * it still works. So we don't need to turn off MMU here.
292 int arch_cpu_init(void)
295 __asm_invalidate_dcache_all();
296 __asm_invalidate_tlb_all();
298 set_sctlr(get_sctlr() | CR_C);
303 * This function is called from lib/board.c.
304 * It recreates MMU table in main memory. MMU and d-cache are enabled earlier.
305 * There is no need to disable d-cache for this operation.
307 void enable_caches(void)
310 __asm_invalidate_tlb_all();
314 static inline u32 initiator_type(u32 cluster, int init_id)
316 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
317 u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
318 u32 type = in_le32(&gur->tp_ityp[idx]);
320 if (type & TP_ITYP_AV)
328 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
329 int i = 0, count = 0;
330 u32 cluster, type, mask = 0;
334 cluster = in_le32(&gur->tp_cluster[i].lower);
335 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
336 type = initiator_type(cluster, j);
338 if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
344 } while ((cluster & TP_CLUSTER_EOC) != TP_CLUSTER_EOC);
350 * Return the number of cores on this SOC.
352 int cpu_numcores(void)
354 return hweight32(cpu_mask());
357 int fsl_qoriq_core_to_cluster(unsigned int core)
359 struct ccsr_gur __iomem *gur =
360 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
361 int i = 0, count = 0;
366 cluster = in_le32(&gur->tp_cluster[i].lower);
367 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
368 if (initiator_type(cluster, j)) {
375 } while ((cluster & TP_CLUSTER_EOC) != TP_CLUSTER_EOC);
377 return -1; /* cannot identify the cluster */
380 u32 fsl_qoriq_core_to_type(unsigned int core)
382 struct ccsr_gur __iomem *gur =
383 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
384 int i = 0, count = 0;
389 cluster = in_le32(&gur->tp_cluster[i].lower);
390 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
391 type = initiator_type(cluster, j);
399 } while ((cluster & TP_CLUSTER_EOC) != TP_CLUSTER_EOC);
401 return -1; /* cannot identify the cluster */
404 #ifdef CONFIG_DISPLAY_CPUINFO
405 int print_cpuinfo(void)
407 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
408 struct sys_info sysinfo;
410 unsigned int i, core;
416 printf(" %s (0x%x)\n", buf, in_le32(&gur->svr));
418 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
420 get_sys_info(&sysinfo);
421 puts("Clock Configuration:");
422 for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
425 type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
426 printf("CPU%d(%s):%-4s MHz ", core,
427 type == TY_ITYP_VER_A7 ? "A7 " :
428 (type == TY_ITYP_VER_A53 ? "A53" :
429 (type == TY_ITYP_VER_A57 ? "A57" : " ")),
430 strmhz(buf, sysinfo.freq_processor[core]));
432 printf("\n Bus: %-4s MHz ",
433 strmhz(buf, sysinfo.freq_systembus));
434 printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
435 printf(" DP-DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus2));
438 /* Display the RCW, so that no one gets confused as to what RCW
439 * we're actually using for this boot.
441 puts("Reset Configuration Word (RCW):");
442 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
443 u32 rcw = in_le32(&gur->rcwsr[i]);
446 printf("\n %02x:", i * 4);
447 printf(" %08x", rcw);
455 #ifdef CONFIG_FSL_ESDHC
456 int cpu_mmc_init(bd_t *bis)
458 return fsl_esdhc_mmc_init(bis);
462 int cpu_eth_init(bd_t *bis)
466 #ifdef CONFIG_FSL_MC_ENET
467 error = fsl_mc_ldpaa_init(bis);
472 int arch_early_init_r(void)
475 rv = fsl_lsch3_wake_seconday_cores();
478 printf("Did not wake secondary cores\n");
480 #ifdef CONFIG_SYS_HAS_SERDES
488 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
489 u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
490 #ifdef COUNTER_FREQUENCY_REAL
491 unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
493 /* Update with accurate clock frequency */
494 asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
497 /* Enable timebase for all clusters.
498 * It is safe to do so even some clusters are not enabled.
500 out_le32(cltbenr, 0xf);
502 /* Enable clock for timer
503 * This is a global setting.
505 out_le32(cntcr, 0x1);
510 void reset_cpu(ulong addr)
512 u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
515 /* Raise RESET_REQ_B */
516 val = in_le32(rstcr);
518 out_le32(rstcr, val);