2 * Copyright 2008-2011 Freescale Semiconductor, Inc.
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include <asm/processor.h>
29 #include <asm/fsl_law.h>
30 #include <asm/fsl_ddr_sdram.h>
33 DECLARE_GLOBAL_DATA_PTR
;
34 u32
fsl_ddr_get_intl3r(void);
36 extern u32 __spin_table
[];
40 return mfspr(SPRN_PIR
);
44 * Determine if U-Boot should keep secondary cores in reset, or let them out
45 * of reset and hold them in a spinloop
47 int hold_cores_in_reset(int verbose
)
49 /* Default to no, overriden by 'y', 'yes', 'Y', 'Yes', or '1' */
50 if (getenv_yesno("mp_holdoff") == 1) {
52 puts("Secondary cores are being held in reset.\n");
53 puts("See 'mp_holdoff' environment variable\n");
64 volatile ccsr_pic_t
*pic
= (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR
);
65 out_be32(&pic
->pir
, 1 << nr
);
66 /* the dummy read works around an errata on early 85xx MP PICs */
67 (void)in_be32(&pic
->pir
);
68 out_be32(&pic
->pir
, 0x0);
73 int cpu_status(int nr
)
75 u32
*table
, id
= get_my_id();
77 if (hold_cores_in_reset(1))
81 table
= (u32
*)&__spin_table
;
82 printf("table base @ 0x%p\n", table
);
83 } else if (is_core_disabled(nr
)) {
86 table
= (u32
*)&__spin_table
+ nr
* NUM_BOOT_ENTRY
;
87 printf("Running on cpu %d\n", id
);
89 printf("table @ 0x%p\n", table
);
90 printf(" addr - 0x%08x\n", table
[BOOT_ENTRY_ADDR_LOWER
]);
91 printf(" r3 - 0x%08x\n", table
[BOOT_ENTRY_R3_LOWER
]);
92 printf(" pir - 0x%08x\n", table
[BOOT_ENTRY_PIR
]);
98 #ifdef CONFIG_FSL_CORENET
99 int cpu_disable(int nr
)
101 volatile ccsr_gur_t
*gur
= (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR
);
103 setbits_be32(&gur
->coredisrl
, 1 << nr
);
108 int is_core_disabled(int nr
) {
109 ccsr_gur_t
*gur
= (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR
);
110 u32 coredisrl
= in_be32(&gur
->coredisrl
);
112 return (coredisrl
& (1 << nr
));
115 int cpu_disable(int nr
)
117 volatile ccsr_gur_t
*gur
= (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR
);
121 setbits_be32(&gur
->devdisr
, MPC85xx_DEVDISR_CPU0
);
124 setbits_be32(&gur
->devdisr
, MPC85xx_DEVDISR_CPU1
);
127 printf("Invalid cpu number for disable %d\n", nr
);
134 int is_core_disabled(int nr
) {
135 ccsr_gur_t
*gur
= (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR
);
136 u32 devdisr
= in_be32(&gur
->devdisr
);
140 return (devdisr
& MPC85xx_DEVDISR_CPU0
);
142 return (devdisr
& MPC85xx_DEVDISR_CPU1
);
144 printf("Invalid cpu number for disable %d\n", nr
);
151 static u8 boot_entry_map
[4] = {
157 int cpu_release(int nr
, int argc
, char * const argv
[])
159 u32 i
, val
, *table
= (u32
*)&__spin_table
+ nr
* NUM_BOOT_ENTRY
;
162 if (hold_cores_in_reset(1))
165 if (nr
== get_my_id()) {
166 printf("Invalid to release the boot core.\n\n");
171 printf("Invalid number of arguments to release.\n\n");
175 boot_addr
= simple_strtoull(argv
[0], NULL
, 16);
178 for (i
= 1; i
< 3; i
++) {
179 if (argv
[i
][0] != '-') {
180 u8 entry
= boot_entry_map
[i
];
181 val
= simple_strtoul(argv
[i
], NULL
, 16);
186 table
[BOOT_ENTRY_ADDR_UPPER
] = (u32
)(boot_addr
>> 32);
188 /* ensure all table updates complete before final address write */
191 table
[BOOT_ENTRY_ADDR_LOWER
] = (u32
)(boot_addr
& 0xffffffff);
196 u32
determine_mp_bootpg(unsigned int *pagesize
)
199 #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
201 u32 granule_size
, check
;
206 /* use last 4K of mapped memory */
207 bootpg
= ((gd
->ram_size
> CONFIG_MAX_MEM_MAPPED
) ?
208 CONFIG_MAX_MEM_MAPPED
: gd
->ram_size
) +
209 CONFIG_SYS_SDRAM_BASE
- 4096;
213 #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
215 * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
216 * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
217 * the way boot page chosen in u-boot avoids hitting this erratum. So only
218 * thw workaround for 3-way interleaving is needed.
220 * To make sure boot page translation works with 3-Way DDR interleaving
221 * enforce a check for the following constrains
222 * 8K granule size requires BRSIZE=8K and
223 * bootpg >> log2(BRSIZE) %3 == 1
224 * 4K and 1K granule size requires BRSIZE=4K and
225 * bootpg >> log2(BRSIZE) %3 == 0
227 if (SVR_SOC_VER(svr
) == SVR_T4240
&& SVR_MAJ(svr
) < 2) {
228 e
= find_law(bootpg
);
230 case LAW_TRGT_IF_DDR_INTLV_123
:
231 granule_size
= fsl_ddr_get_intl3r() & 0x1f;
232 if (granule_size
== FSL_DDR_3WAY_8KB_INTERLEAVING
) {
235 bootpg
&= 0xffffe000; /* align to 8KB */
236 check
= bootpg
>> 13;
237 while ((check
% 3) != 1)
239 bootpg
= check
<< 13;
240 debug("Boot page (8K) at 0x%08x\n", bootpg
);
243 bootpg
&= 0xfffff000; /* align to 4KB */
244 check
= bootpg
>> 12;
245 while ((check
% 3) != 0)
247 bootpg
= check
<< 12;
248 debug("Boot page (4K) at 0x%08x\n", bootpg
);
255 #endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
260 phys_addr_t
get_spin_phys_addr(void)
262 return virt_to_phys(&__spin_table
);
265 #ifdef CONFIG_FSL_CORENET
266 static void plat_mp_up(unsigned long bootpg
, unsigned int pagesize
)
268 u32 cpu_up_mask
, whoami
, brsize
= LAW_SIZE_4K
;
269 u32
*table
= (u32
*)&__spin_table
;
270 volatile ccsr_gur_t
*gur
;
271 volatile ccsr_local_t
*ccm
;
272 volatile ccsr_rcpm_t
*rcpm
;
273 volatile ccsr_pic_t
*pic
;
275 u32 mask
= cpu_mask();
278 gur
= (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR
);
279 ccm
= (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR
);
280 rcpm
= (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR
);
281 pic
= (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR
);
283 whoami
= in_be32(&pic
->whoami
);
284 cpu_up_mask
= 1 << whoami
;
285 out_be32(&ccm
->bstrl
, bootpg
);
287 e
= find_law(bootpg
);
288 /* pagesize is only 4K or 8K */
289 if (pagesize
== 8192)
290 brsize
= LAW_SIZE_8K
;
291 out_be32(&ccm
->bstrar
, LAW_EN
| e
.trgt_id
<< 20 | brsize
);
292 debug("BRSIZE is 0x%x\n", brsize
);
294 /* readback to sync write */
295 in_be32(&ccm
->bstrar
);
297 /* disable time base at the platform */
298 out_be32(&rcpm
->ctbenrl
, cpu_up_mask
);
300 out_be32(&gur
->brrl
, mask
);
302 /* wait for everyone */
304 unsigned int i
, cpu
, nr_cpus
= cpu_numcores();
306 for_each_cpu(i
, cpu
, nr_cpus
, mask
) {
307 if (table
[cpu
* NUM_BOOT_ENTRY
+ BOOT_ENTRY_ADDR_LOWER
])
308 cpu_up_mask
|= (1 << cpu
);
311 if ((cpu_up_mask
& mask
) == mask
)
319 printf("CPU up timeout. CPU up mask is %x should be %x\n",
322 /* enable time base at the platform */
323 out_be32(&rcpm
->ctbenrl
, 0);
325 /* readback to sync write */
326 in_be32(&rcpm
->ctbenrl
);
331 out_be32(&rcpm
->ctbenrl
, mask
);
333 #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
335 * Disabling Boot Page Translation allows the memory region 0xfffff000
336 * to 0xffffffff to be used normally. Leaving Boot Page Translation
337 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
338 * unusable for normal operation but it does allow OSes to easily
339 * reset a processor core to put it back into U-Boot's spinloop.
341 clrbits_be32(&ccm
->bstrar
, LAW_EN
);
345 static void plat_mp_up(unsigned long bootpg
, unsigned int pagesize
)
347 u32 up
, cpu_up_mask
, whoami
;
348 u32
*table
= (u32
*)&__spin_table
;
350 volatile ccsr_local_ecm_t
*ecm
= (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR
);
351 volatile ccsr_gur_t
*gur
= (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR
);
352 volatile ccsr_pic_t
*pic
= (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR
);
356 whoami
= in_be32(&pic
->whoami
);
357 out_be32(&ecm
->bptr
, 0x80000000 | (bootpg
>> 12));
359 /* disable time base at the platform */
360 devdisr
= in_be32(&gur
->devdisr
);
362 devdisr
|= MPC85xx_DEVDISR_TB0
;
364 devdisr
|= MPC85xx_DEVDISR_TB1
;
365 out_be32(&gur
->devdisr
, devdisr
);
367 /* release the hounds */
368 up
= ((1 << cpu_numcores()) - 1);
369 bpcr
= in_be32(&ecm
->eebpcr
);
371 out_be32(&ecm
->eebpcr
, bpcr
);
372 asm("sync; isync; msync");
374 cpu_up_mask
= 1 << whoami
;
375 /* wait for everyone */
378 for (i
= 0; i
< cpu_numcores(); i
++) {
379 if (table
[i
* NUM_BOOT_ENTRY
+ BOOT_ENTRY_ADDR_LOWER
])
380 cpu_up_mask
|= (1 << i
);
383 if ((cpu_up_mask
& up
) == up
)
391 printf("CPU up timeout. CPU up mask is %x should be %x\n",
394 /* enable time base at the platform */
396 devdisr
|= MPC85xx_DEVDISR_TB1
;
398 devdisr
|= MPC85xx_DEVDISR_TB0
;
399 out_be32(&gur
->devdisr
, devdisr
);
401 /* readback to sync write */
402 in_be32(&gur
->devdisr
);
407 devdisr
&= ~(MPC85xx_DEVDISR_TB0
| MPC85xx_DEVDISR_TB1
);
408 out_be32(&gur
->devdisr
, devdisr
);
410 #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
412 * Disabling Boot Page Translation allows the memory region 0xfffff000
413 * to 0xffffffff to be used normally. Leaving Boot Page Translation
414 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
415 * unusable for normal operation but it does allow OSes to easily
416 * reset a processor core to put it back into U-Boot's spinloop.
418 clrbits_be32(&ecm
->bptr
, 0x80000000);
423 void cpu_mp_lmb_reserve(struct lmb
*lmb
)
425 u32 bootpg
= determine_mp_bootpg(NULL
);
427 lmb_reserve(lmb
, bootpg
, 4096);
432 extern u32 __secondary_start_page
;
433 extern u32 __bootpg_addr
, __spin_table_addr
, __second_half_boot_page
;
436 ulong fixup
= (u32
)&__secondary_start_page
;
437 u32 bootpg
, bootpg_map
, pagesize
;
439 bootpg
= determine_mp_bootpg(&pagesize
);
442 * pagesize is only 4K or 8K
443 * we only use the last 4K of boot page
444 * bootpg_map saves the address for the boot page
445 * 8K is used for the workaround of 3-way DDR interleaving
450 if (pagesize
== 8192)
451 bootpg
+= 4096; /* use 2nd half */
453 /* Some OSes expect secondary cores to be held in reset */
454 if (hold_cores_in_reset(0))
458 * Store the bootpg's cache-able half address for use by secondary
459 * CPU cores to continue to boot
461 __bootpg_addr
= (u32
)virt_to_phys(&__second_half_boot_page
);
463 /* Store spin table's physical address for use by secondary cores */
464 __spin_table_addr
= (u32
)get_spin_phys_addr();
466 /* flush bootpg it before copying invalidate any staled cacheline */
467 flush_cache(bootpg
, 4096);
469 /* look for the tlb covering the reset page, there better be one */
470 i
= find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR
, 1);
472 /* we found a match */
474 /* map reset page to bootpg so we can copy code there */
477 set_tlb(1, CONFIG_BPTR_VIRT_ADDR
, bootpg
, /* tlb, epn, rpn */
478 MAS3_SX
|MAS3_SW
|MAS3_SR
, MAS2_I
|MAS2_G
, /* perms, wimge */
479 0, i
, BOOKE_PAGESZ_4K
, 1); /* ts, esel, tsize, iprot */
481 memcpy((void *)CONFIG_BPTR_VIRT_ADDR
, (void *)fixup
, 4096);
483 plat_mp_up(bootpg_map
, pagesize
);
485 puts("WARNING: No reset page TLB. "
486 "Skipping secondary core setup\n");