1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2008-2011 Freescale Semiconductor, Inc.
8 #include <asm/processor.h>
14 #include <asm/fsl_law.h>
15 #include <fsl_ddr_sdram.h>
18 DECLARE_GLOBAL_DATA_PTR;
19 u32 fsl_ddr_get_intl3r(void);
21 extern u32 __spin_table[];
25 return mfspr(SPRN_PIR);
29 * Determine if U-Boot should keep secondary cores in reset, or let them out
30 * of reset and hold them in a spinloop
32 int hold_cores_in_reset(int verbose)
34 /* Default to no, overridden by 'y', 'yes', 'Y', 'Yes', or '1' */
35 if (env_get_yesno("mp_holdoff") == 1) {
37 puts("Secondary cores are being held in reset.\n");
38 puts("See 'mp_holdoff' environment variable\n");
49 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
50 out_be32(&pic->pir, 1 << nr);
51 /* the dummy read works around an errata on early 85xx MP PICs */
52 (void)in_be32(&pic->pir);
53 out_be32(&pic->pir, 0x0);
58 int cpu_status(u32 nr)
60 u32 *table, id = get_my_id();
62 if (hold_cores_in_reset(1))
66 table = (u32 *)&__spin_table;
67 printf("table base @ 0x%p\n", table);
68 } else if (is_core_disabled(nr)) {
71 table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
72 printf("Running on cpu %d\n", id);
74 printf("table @ 0x%p\n", table);
75 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
76 printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
77 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
83 #ifdef CONFIG_FSL_CORENET
84 int cpu_disable(u32 nr)
86 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
88 setbits_be32(&gur->coredisrl, 1 << nr);
93 int is_core_disabled(int nr) {
94 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
95 u32 coredisrl = in_be32(&gur->coredisrl);
97 return (coredisrl & (1 << nr));
100 int cpu_disable(u32 nr)
102 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
106 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0);
109 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1);
112 printf("Invalid cpu number for disable %d\n", nr);
119 int is_core_disabled(int nr) {
120 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
121 u32 devdisr = in_be32(&gur->devdisr);
125 return (devdisr & MPC85xx_DEVDISR_CPU0);
127 return (devdisr & MPC85xx_DEVDISR_CPU1);
129 printf("Invalid cpu number for disable %d\n", nr);
136 static u8 boot_entry_map[4] = {
142 int cpu_release(u32 nr, int argc, char * const argv[])
144 u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
147 if (hold_cores_in_reset(1))
150 if (nr == get_my_id()) {
151 printf("Invalid to release the boot core.\n\n");
156 printf("Invalid number of arguments to release.\n\n");
160 boot_addr = simple_strtoull(argv[0], NULL, 16);
163 for (i = 1; i < 3; i++) {
164 if (argv[i][0] != '-') {
165 u8 entry = boot_entry_map[i];
166 val = simple_strtoul(argv[i], NULL, 16);
171 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
173 /* ensure all table updates complete before final address write */
176 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
181 u32 determine_mp_bootpg(unsigned int *pagesize)
184 #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
186 u32 granule_size, check;
191 /* use last 4K of mapped memory */
192 bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
193 CONFIG_MAX_MEM_MAPPED : gd->ram_size) +
194 CONFIG_SYS_SDRAM_BASE - 4096;
198 #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
200 * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
201 * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
202 * the way boot page chosen in u-boot avoids hitting this erratum. So only
203 * thw workaround for 3-way interleaving is needed.
205 * To make sure boot page translation works with 3-Way DDR interleaving
206 * enforce a check for the following constrains
207 * 8K granule size requires BRSIZE=8K and
208 * bootpg >> log2(BRSIZE) %3 == 1
209 * 4K and 1K granule size requires BRSIZE=4K and
210 * bootpg >> log2(BRSIZE) %3 == 0
212 if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) {
213 e = find_law(bootpg);
215 case LAW_TRGT_IF_DDR_INTLV_123:
216 granule_size = fsl_ddr_get_intl3r() & 0x1f;
217 if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) {
220 bootpg &= 0xffffe000; /* align to 8KB */
221 check = bootpg >> 13;
222 while ((check % 3) != 1)
224 bootpg = check << 13;
225 debug("Boot page (8K) at 0x%08x\n", bootpg);
228 bootpg &= 0xfffff000; /* align to 4KB */
229 check = bootpg >> 12;
230 while ((check % 3) != 0)
232 bootpg = check << 12;
233 debug("Boot page (4K) at 0x%08x\n", bootpg);
240 #endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
245 phys_addr_t get_spin_phys_addr(void)
247 return virt_to_phys(&__spin_table);
250 #ifdef CONFIG_FSL_CORENET
251 static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
253 u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
254 u32 *table = (u32 *)&__spin_table;
255 volatile ccsr_gur_t *gur;
256 volatile ccsr_local_t *ccm;
257 volatile ccsr_rcpm_t *rcpm;
258 volatile ccsr_pic_t *pic;
260 u32 mask = cpu_mask();
263 gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
264 ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
265 rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
266 pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
268 whoami = in_be32(&pic->whoami);
269 cpu_up_mask = 1 << whoami;
270 out_be32(&ccm->bstrl, bootpg);
272 e = find_law(bootpg);
273 /* pagesize is only 4K or 8K */
274 if (pagesize == 8192)
275 brsize = LAW_SIZE_8K;
276 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
277 debug("BRSIZE is 0x%x\n", brsize);
279 /* readback to sync write */
280 in_be32(&ccm->bstrar);
282 /* disable time base at the platform */
283 out_be32(&rcpm->ctbenrl, cpu_up_mask);
285 out_be32(&gur->brrl, mask);
287 /* wait for everyone */
289 unsigned int i, cpu, nr_cpus = cpu_numcores();
291 for_each_cpu(i, cpu, nr_cpus, mask) {
292 if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
293 cpu_up_mask |= (1 << cpu);
296 if ((cpu_up_mask & mask) == mask)
304 printf("CPU up timeout. CPU up mask is %x should be %x\n",
307 /* enable time base at the platform */
308 out_be32(&rcpm->ctbenrl, 0);
310 /* readback to sync write */
311 in_be32(&rcpm->ctbenrl);
316 out_be32(&rcpm->ctbenrl, mask);
318 #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
320 * Disabling Boot Page Translation allows the memory region 0xfffff000
321 * to 0xffffffff to be used normally. Leaving Boot Page Translation
322 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
323 * unusable for normal operation but it does allow OSes to easily
324 * reset a processor core to put it back into U-Boot's spinloop.
326 clrbits_be32(&ccm->bstrar, LAW_EN);
330 static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
332 u32 up, cpu_up_mask, whoami;
333 u32 *table = (u32 *)&__spin_table;
335 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
336 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
337 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
341 whoami = in_be32(&pic->whoami);
342 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
344 /* disable time base at the platform */
345 devdisr = in_be32(&gur->devdisr);
347 devdisr |= MPC85xx_DEVDISR_TB0;
349 devdisr |= MPC85xx_DEVDISR_TB1;
350 out_be32(&gur->devdisr, devdisr);
352 /* release the hounds */
353 up = ((1 << cpu_numcores()) - 1);
354 bpcr = in_be32(&ecm->eebpcr);
356 out_be32(&ecm->eebpcr, bpcr);
357 asm("sync; isync; msync");
359 cpu_up_mask = 1 << whoami;
360 /* wait for everyone */
363 for (i = 0; i < cpu_numcores(); i++) {
364 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
365 cpu_up_mask |= (1 << i);
368 if ((cpu_up_mask & up) == up)
376 printf("CPU up timeout. CPU up mask is %x should be %x\n",
379 /* enable time base at the platform */
381 devdisr |= MPC85xx_DEVDISR_TB1;
383 devdisr |= MPC85xx_DEVDISR_TB0;
384 out_be32(&gur->devdisr, devdisr);
386 /* readback to sync write */
387 in_be32(&gur->devdisr);
392 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
393 out_be32(&gur->devdisr, devdisr);
395 #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
397 * Disabling Boot Page Translation allows the memory region 0xfffff000
398 * to 0xffffffff to be used normally. Leaving Boot Page Translation
399 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
400 * unusable for normal operation but it does allow OSes to easily
401 * reset a processor core to put it back into U-Boot's spinloop.
403 clrbits_be32(&ecm->bptr, 0x80000000);
408 void cpu_mp_lmb_reserve(struct lmb *lmb)
410 u32 bootpg = determine_mp_bootpg(NULL);
412 lmb_reserve(lmb, bootpg, 4096);
417 extern u32 __secondary_start_page;
418 extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page;
421 ulong fixup = (u32)&__secondary_start_page;
422 u32 bootpg, bootpg_map, pagesize;
424 bootpg = determine_mp_bootpg(&pagesize);
427 * pagesize is only 4K or 8K
428 * we only use the last 4K of boot page
429 * bootpg_map saves the address for the boot page
430 * 8K is used for the workaround of 3-way DDR interleaving
435 if (pagesize == 8192)
436 bootpg += 4096; /* use 2nd half */
438 /* Some OSes expect secondary cores to be held in reset */
439 if (hold_cores_in_reset(0))
443 * Store the bootpg's cache-able half address for use by secondary
444 * CPU cores to continue to boot
446 __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
448 /* Store spin table's physical address for use by secondary cores */
449 __spin_table_addr = (u32)get_spin_phys_addr();
451 /* flush bootpg it before copying invalidate any staled cacheline */
452 flush_cache(bootpg, 4096);
454 /* look for the tlb covering the reset page, there better be one */
455 i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
457 /* we found a match */
459 /* map reset page to bootpg so we can copy code there */
462 set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
463 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
464 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
466 memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
468 plat_mp_up(bootpg_map, pagesize);
470 puts("WARNING: No reset page TLB. "
471 "Skipping secondary core setup\n");