]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arm/cpu/armv8/fsl-layerscape/cpu.c
armv8/fsl-layerscape: print SoC revsion number
[people/ms/u-boot.git] / arch / arm / cpu / armv8 / fsl-layerscape / cpu.c
CommitLineData
2f78eae5 1/*
9f3183d2 2 * Copyright 2014-2015 Freescale Semiconductor, Inc.
2f78eae5
YS
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/io.h>
1221ce45 9#include <linux/errno.h>
2f78eae5
YS
10#include <asm/system.h>
11#include <asm/armv8/mmu.h>
12#include <asm/io.h>
9f3183d2
MH
13#include <asm/arch/fsl_serdes.h>
14#include <asm/arch/soc.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/speed.h>
17#ifdef CONFIG_MP
18#include <asm/arch/mp.h>
19#endif
20#include <fm_eth.h>
7b3bd9a7 21#include <fsl-mc/fsl_mc.h>
8b06460e
YL
22#ifdef CONFIG_FSL_ESDHC
23#include <fsl_esdhc.h>
24#endif
032d5bb4
HZ
25#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
26#include <asm/armv8/sec_firmware.h>
27#endif
2f78eae5
YS
28
29DECLARE_GLOBAL_DATA_PTR;
30
5ad5823d 31struct mm_region *mem_map = early_map;
7985cdf7 32
22629665
PK
33void cpu_name(char *name)
34{
35 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
36 unsigned int i, svr, ver;
37
9f3183d2 38 svr = gur_in32(&gur->svr);
22629665
PK
39 ver = SVR_SOC_VER(svr);
40
41 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
42 if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) {
43 strcpy(name, cpu_type_list[i].name);
44
45 if (IS_E_PROCESSOR(svr))
46 strcat(name, "E");
5d1a7a9d
WS
47
48 sprintf(name + strlen(name), " Rev%d.%d",
49 SVR_MAJ(svr), SVR_MIN(svr));
22629665
PK
50 break;
51 }
52
53 if (i == ARRAY_SIZE(cpu_type_list))
54 strcpy(name, "unknown");
55}
56
2f78eae5 57#ifndef CONFIG_SYS_DCACHE_OFF
99799220
AW
58/*
59 * To start MMU before DDR is available, we create MMU table in SRAM.
60 * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three
61 * levels of translation tables here to cover 40-bit address space.
62 * We use 4KB granule size, with 40 bits physical address, T0SZ=24
5ad5823d
YS
63 * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose.
64 * Note, the debug print in cache_v8.c is not usable for debugging
65 * these early MMU tables because UART is not yet available.
99799220
AW
66 */
67static inline void early_mmu_setup(void)
68{
5ad5823d 69 unsigned int el = current_el();
99799220 70
5ad5823d
YS
71 /* global data is already setup, no allocation yet */
72 gd->arch.tlb_addr = CONFIG_SYS_FSL_OCRAM_BASE;
73 gd->arch.tlb_fillptr = gd->arch.tlb_addr;
74 gd->arch.tlb_size = EARLY_PGTABLE_SIZE;
99799220 75
5ad5823d
YS
76 /* Create early page tables */
77 setup_pgtables();
9f3183d2 78
5ad5823d
YS
79 /* point TTBR to the new table */
80 set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
81 get_tcr(el, NULL, NULL) &
82 ~(TCR_ORGN_MASK | TCR_IRGN_MASK),
9f3183d2 83 MEMORY_ATTRIBUTES);
c107c0c0 84
5ad5823d 85 set_sctlr(get_sctlr() | CR_M);
c107c0c0 86}
c107c0c0 87
2f78eae5 88/*
99799220
AW
89 * The final tables look similar to early tables, but different in detail.
90 * These tables are in DRAM. Sub tables are added to enable cache for
91 * QBMan and OCRAM.
92 *
e61a7534
YS
93 * Put the MMU table in secure memory if gd->arch.secure_ram is valid.
94 * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0.
2f78eae5
YS
95 */
96static inline void final_mmu_setup(void)
97{
5ad5823d 98 u64 tlb_addr_save = gd->arch.tlb_addr;
c107c0c0 99 unsigned int el = current_el();
c107c0c0 100#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
5ad5823d 101 int index;
c107c0c0 102#endif
2f78eae5 103
5ad5823d 104 mem_map = final_map;
2f78eae5 105
c107c0c0 106#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
5ad5823d
YS
107 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
108 if (el == 3) {
109 /*
110 * Only use gd->arch.secure_ram if the address is
111 * recalculated. Align to 4KB for MMU table.
112 */
113 /* put page tables in secure ram */
114 index = ARRAY_SIZE(final_map) - 2;
115 gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff;
116 final_map[index].virt = gd->arch.secure_ram & ~0x3;
117 final_map[index].phys = final_map[index].virt;
118 final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE;
119 final_map[index].attrs = PTE_BLOCK_OUTER_SHARE;
e61a7534 120 gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED;
5ad5823d 121 tlb_addr_save = gd->arch.tlb_addr;
c107c0c0 122 } else {
5ad5823d
YS
123 /* Use allocated (board_f.c) memory for TLB */
124 tlb_addr_save = gd->arch.tlb_allocated;
125 gd->arch.tlb_addr = tlb_addr_save;
c107c0c0
YS
126 }
127 }
128#endif
2f78eae5 129
5ad5823d
YS
130 /* Reset the fill ptr */
131 gd->arch.tlb_fillptr = tlb_addr_save;
132
133 /* Create normal system page tables */
134 setup_pgtables();
135
136 /* Create emergency page tables */
137 gd->arch.tlb_addr = gd->arch.tlb_fillptr;
138 gd->arch.tlb_emerg = gd->arch.tlb_addr;
139 setup_pgtables();
140 gd->arch.tlb_addr = tlb_addr_save;
141
2f78eae5 142 /* flush new MMU table */
5ad5823d
YS
143 flush_dcache_range(gd->arch.tlb_addr,
144 gd->arch.tlb_addr + gd->arch.tlb_size);
2f78eae5
YS
145
146 /* point TTBR to the new table */
5ad5823d 147 set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
db14f11d 148 MEMORY_ATTRIBUTES);
2f78eae5 149 /*
ed7a3943 150 * EL3 MMU is already enabled, just need to invalidate TLB to load the
2f78eae5
YS
151 * new table. The new table is compatible with the current table, if
152 * MMU somehow walks through the new table before invalidation TLB,
153 * it still works. So we don't need to turn off MMU here.
ed7a3943
YS
154 * When EL2 MMU table is created by calling this function, MMU needs
155 * to be enabled.
2f78eae5 156 */
ed7a3943 157 set_sctlr(get_sctlr() | CR_M);
2f78eae5
YS
158}
159
c05016ab
AG
160u64 get_page_table_size(void)
161{
162 return 0x10000;
163}
164
2f78eae5
YS
165int arch_cpu_init(void)
166{
167 icache_enable();
168 __asm_invalidate_dcache_all();
169 __asm_invalidate_tlb_all();
170 early_mmu_setup();
171 set_sctlr(get_sctlr() | CR_C);
172 return 0;
173}
174
85cdf38e
HZ
175void mmu_setup(void)
176{
177 final_mmu_setup();
178}
179
2f78eae5 180/*
85cdf38e
HZ
181 * This function is called from common/board_r.c.
182 * It recreates MMU table in main memory.
2f78eae5
YS
183 */
184void enable_caches(void)
185{
85cdf38e 186 mmu_setup();
2f78eae5 187 __asm_invalidate_tlb_all();
85cdf38e
HZ
188 icache_enable();
189 dcache_enable();
2f78eae5
YS
190}
191#endif
192
193static inline u32 initiator_type(u32 cluster, int init_id)
194{
195 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
196 u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
9f3183d2 197 u32 type = 0;
2f78eae5 198
9f3183d2 199 type = gur_in32(&gur->tp_ityp[idx]);
2f78eae5
YS
200 if (type & TP_ITYP_AV)
201 return type;
202
203 return 0;
204}
205
206u32 cpu_mask(void)
207{
208 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
209 int i = 0, count = 0;
210 u32 cluster, type, mask = 0;
211
212 do {
213 int j;
9f3183d2
MH
214
215 cluster = gur_in32(&gur->tp_cluster[i].lower);
2f78eae5
YS
216 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
217 type = initiator_type(cluster, j);
218 if (type) {
219 if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
220 mask |= 1 << count;
221 count++;
222 }
223 }
224 i++;
9f3183d2 225 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
2f78eae5
YS
226
227 return mask;
228}
229
230/*
231 * Return the number of cores on this SOC.
232 */
233int cpu_numcores(void)
234{
235 return hweight32(cpu_mask());
236}
237
238int fsl_qoriq_core_to_cluster(unsigned int core)
239{
240 struct ccsr_gur __iomem *gur =
241 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
242 int i = 0, count = 0;
243 u32 cluster;
244
245 do {
246 int j;
9f3183d2
MH
247
248 cluster = gur_in32(&gur->tp_cluster[i].lower);
2f78eae5
YS
249 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
250 if (initiator_type(cluster, j)) {
251 if (count == core)
252 return i;
253 count++;
254 }
255 }
256 i++;
9f3183d2 257 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
2f78eae5
YS
258
259 return -1; /* cannot identify the cluster */
260}
261
262u32 fsl_qoriq_core_to_type(unsigned int core)
263{
264 struct ccsr_gur __iomem *gur =
265 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
266 int i = 0, count = 0;
267 u32 cluster, type;
268
269 do {
270 int j;
9f3183d2
MH
271
272 cluster = gur_in32(&gur->tp_cluster[i].lower);
2f78eae5
YS
273 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
274 type = initiator_type(cluster, j);
275 if (type) {
276 if (count == core)
277 return type;
278 count++;
279 }
280 }
281 i++;
9f3183d2 282 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
2f78eae5
YS
283
284 return -1; /* cannot identify the cluster */
285}
286
6fb522dc
SD
287uint get_svr(void)
288{
289 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
290
291 return gur_in32(&gur->svr);
292}
293
2f78eae5
YS
294#ifdef CONFIG_DISPLAY_CPUINFO
295int print_cpuinfo(void)
296{
d27bf906 297 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
2f78eae5
YS
298 struct sys_info sysinfo;
299 char buf[32];
300 unsigned int i, core;
3c1d218a 301 u32 type, rcw, svr = gur_in32(&gur->svr);
2f78eae5 302
22629665
PK
303 puts("SoC: ");
304
305 cpu_name(buf);
3c1d218a 306 printf(" %s (0x%x)\n", buf, svr);
22629665 307 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
2f78eae5
YS
308 get_sys_info(&sysinfo);
309 puts("Clock Configuration:");
310 for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
311 if (!(i % 3))
312 puts("\n ");
313 type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
314 printf("CPU%d(%s):%-4s MHz ", core,
315 type == TY_ITYP_VER_A7 ? "A7 " :
316 (type == TY_ITYP_VER_A53 ? "A53" :
79119a4d
AW
317 (type == TY_ITYP_VER_A57 ? "A57" :
318 (type == TY_ITYP_VER_A72 ? "A72" : " "))),
2f78eae5
YS
319 strmhz(buf, sysinfo.freq_processor[core]));
320 }
321 printf("\n Bus: %-4s MHz ",
322 strmhz(buf, sysinfo.freq_systembus));
d4c711f0 323 printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
e8297341
SX
324#ifdef CONFIG_SYS_DPAA_FMAN
325 printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0]));
326#endif
44937214 327#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
3c1d218a
YS
328 if (soc_has_dp_ddr()) {
329 printf(" DP-DDR: %-4s MT/s",
330 strmhz(buf, sysinfo.freq_ddrbus2));
331 }
9f3183d2 332#endif
2f78eae5
YS
333 puts("\n");
334
9f3183d2
MH
335 /*
336 * Display the RCW, so that no one gets confused as to what RCW
d27bf906
BS
337 * we're actually using for this boot.
338 */
339 puts("Reset Configuration Word (RCW):");
340 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
9f3183d2 341 rcw = gur_in32(&gur->rcwsr[i]);
d27bf906 342 if ((i % 4) == 0)
9f3183d2 343 printf("\n %08x:", i * 4);
d27bf906
BS
344 printf(" %08x", rcw);
345 }
346 puts("\n");
347
2f78eae5
YS
348 return 0;
349}
350#endif
b940ca64 351
8b06460e
YL
352#ifdef CONFIG_FSL_ESDHC
353int cpu_mmc_init(bd_t *bis)
354{
355 return fsl_esdhc_mmc_init(bis);
356}
357#endif
358
b940ca64
GR
359int cpu_eth_init(bd_t *bis)
360{
361 int error = 0;
362
363#ifdef CONFIG_FSL_MC_ENET
a2a55e51 364 error = fsl_mc_ldpaa_init(bis);
e8297341
SX
365#endif
366#ifdef CONFIG_FMAN_ENET
367 fm_standard_init(bis);
b940ca64
GR
368#endif
369 return error;
370}
40f8dec5 371
40f8dec5
YS
372int arch_early_init_r(void)
373{
9f3183d2
MH
374#ifdef CONFIG_MP
375 int rv = 1;
032d5bb4 376 u32 psci_ver = 0xffffffff;
b4017364
PK
377#endif
378
379#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
380 erratum_a009635();
381#endif
40f8dec5 382
b4017364 383#ifdef CONFIG_MP
032d5bb4
HZ
384#if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && defined(CONFIG_ARMV8_PSCI)
385 /* Check the psci version to determine if the psci is supported */
386 psci_ver = sec_firmware_support_psci_version();
387#endif
388 if (psci_ver == 0xffffffff) {
389 rv = fsl_layerscape_wake_seconday_cores();
390 if (rv)
391 printf("Did not wake secondary cores\n");
392 }
9f3183d2 393#endif
40f8dec5 394
31d34c6c
ML
395#ifdef CONFIG_SYS_HAS_SERDES
396 fsl_serdes_init();
e8297341
SX
397#endif
398#ifdef CONFIG_FMAN_ENET
399 fman_enet_init();
31d34c6c 400#endif
40f8dec5
YS
401 return 0;
402}
207774b2
YS
403
404int timer_init(void)
405{
406 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
9f3183d2 407#ifdef CONFIG_FSL_LSCH3
207774b2 408 u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
9f3183d2 409#endif
a758177f
YC
410#ifdef CONFIG_LS2080A
411 u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET;
412#endif
207774b2
YS
413#ifdef COUNTER_FREQUENCY_REAL
414 unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
415
416 /* Update with accurate clock frequency */
417 asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
418#endif
419
9f3183d2 420#ifdef CONFIG_FSL_LSCH3
207774b2
YS
421 /* Enable timebase for all clusters.
422 * It is safe to do so even some clusters are not enabled.
423 */
424 out_le32(cltbenr, 0xf);
9f3183d2 425#endif
207774b2 426
a758177f
YC
427#ifdef CONFIG_LS2080A
428 /*
429 * In certain Layerscape SoCs, the clock for each core's
430 * has an enable bit in the PMU Physical Core Time Base Enable
431 * Register (PCTBENR), which allows the watchdog to operate.
432 */
433 setbits_le32(pctbenr, 0xff);
434#endif
435
207774b2
YS
436 /* Enable clock for timer
437 * This is a global setting.
438 */
439 out_le32(cntcr, 0x1);
440
441 return 0;
442}
05d2e21b 443
444void reset_cpu(ulong addr)
445{
446 u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
447 u32 val;
448
449 /* Raise RESET_REQ_B */
9f3183d2 450 val = scfg_in32(rstcr);
05d2e21b 451 val |= 0x02;
9f3183d2 452 scfg_out32(rstcr, val);
05d2e21b 453}
c0492141
YS
454
455phys_size_t board_reserve_ram_top(phys_size_t ram_size)
456{
457 phys_size_t ram_top = ram_size;
458
459#ifdef CONFIG_SYS_MEM_TOP_HIDE
460#error CONFIG_SYS_MEM_TOP_HIDE not to be used together with this function
461#endif
c0492141
YS
462
463/* Carve the MC private DRAM block from the end of DRAM */
464#ifdef CONFIG_FSL_MC_ENET
465 ram_top -= mc_get_dram_block_size();
466 ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
467#endif
468
469 return ram_top;
470}