blob: 0f8c8cd6677dd7e5f735d73583909d0ebf021983 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Galaec2b74f2008-01-17 16:48:33 -06002/*
Ed Swarthoute81241a2011-03-03 18:28:14 -06003 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Kumar Galaec2b74f2008-01-17 16:48:33 -06004 */
5
6#include <common.h>
Simon Glass62f9b652019-11-14 12:57:09 -07007#include <cpu_func.h>
Simon Glass6bf6dbe2019-08-01 09:46:49 -06008#include <env.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -06009#include <asm/processor.h>
Simon Glass7b51b572019-08-01 09:46:52 -060010#include <env.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060011#include <ioports.h>
Kumar Galadd6c9102008-03-26 08:53:53 -050012#include <lmb.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060013#include <asm/io.h>
Kumar Galac7259082009-09-03 08:41:31 -050014#include <asm/mmu.h>
Kumar Gala39a7e7f2009-09-17 01:44:39 -050015#include <asm/fsl_law.h>
York Sun5614e712013-09-30 09:22:09 -070016#include <fsl_ddr_sdram.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060017#include "mp.h"
18
19DECLARE_GLOBAL_DATA_PTR;
York Suneb539412012-10-08 07:44:25 +000020u32 fsl_ddr_get_intl3r(void);
Kumar Galaec2b74f2008-01-17 16:48:33 -060021
York Sunffd06e02012-10-08 07:44:30 +000022extern u32 __spin_table[];
23
Kumar Galaec2b74f2008-01-17 16:48:33 -060024u32 get_my_id()
25{
26 return mfspr(SPRN_PIR);
27}
28
Aaron Sierra9d64c6b2010-09-30 12:22:16 -050029/*
30 * Determine if U-Boot should keep secondary cores in reset, or let them out
31 * of reset and hold them in a spinloop
32 */
33int hold_cores_in_reset(int verbose)
34{
Robert P. J. Day62a3b7d2016-07-15 13:44:45 -040035 /* Default to no, overridden by 'y', 'yes', 'Y', 'Yes', or '1' */
Simon Glassbfebc8c2017-08-03 12:22:13 -060036 if (env_get_yesno("mp_holdoff") == 1) {
Aaron Sierra9d64c6b2010-09-30 12:22:16 -050037 if (verbose) {
38 puts("Secondary cores are being held in reset.\n");
39 puts("See 'mp_holdoff' environment variable\n");
40 }
41
42 return 1;
43 }
44
45 return 0;
46}
47
Michal Simek20b016a2018-06-13 08:56:31 +020048int cpu_reset(u32 nr)
Kumar Galaec2b74f2008-01-17 16:48:33 -060049{
Kim Phillips680c6132010-08-09 18:39:57 -050050 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Galaec2b74f2008-01-17 16:48:33 -060051 out_be32(&pic->pir, 1 << nr);
Kumar Galac840d262009-03-31 23:11:05 -050052 /* the dummy read works around an errata on early 85xx MP PICs */
Kumar Galaec2b74f2008-01-17 16:48:33 -060053 (void)in_be32(&pic->pir);
54 out_be32(&pic->pir, 0x0);
55
56 return 0;
57}
58
Michal Simek20b016a2018-06-13 08:56:31 +020059int cpu_status(u32 nr)
Kumar Galaec2b74f2008-01-17 16:48:33 -060060{
61 u32 *table, id = get_my_id();
62
Aaron Sierra9d64c6b2010-09-30 12:22:16 -050063 if (hold_cores_in_reset(1))
64 return 0;
65
Kumar Galaec2b74f2008-01-17 16:48:33 -060066 if (nr == id) {
York Sunffd06e02012-10-08 07:44:30 +000067 table = (u32 *)&__spin_table;
Kumar Gala348753d2008-07-14 14:03:02 -050068 printf("table base @ 0x%p\n", table);
York Sun0c9ab432013-03-25 07:40:00 +000069 } else if (is_core_disabled(nr)) {
70 puts("Disabled\n");
Kumar Galaec2b74f2008-01-17 16:48:33 -060071 } else {
York Sunffd06e02012-10-08 07:44:30 +000072 table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
Kumar Galaec2b74f2008-01-17 16:48:33 -060073 printf("Running on cpu %d\n", id);
74 printf("\n");
Kumar Gala348753d2008-07-14 14:03:02 -050075 printf("table @ 0x%p\n", table);
Kumar Gala79679d82008-03-26 08:34:25 -050076 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
Kumar Gala79679d82008-03-26 08:34:25 -050077 printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
York Sun3f0997b2012-10-08 07:44:29 +000078 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
Kumar Galaec2b74f2008-01-17 16:48:33 -060079 }
80
81 return 0;
82}
83
Kumar Galaa9c3ac72010-01-12 12:56:05 -060084#ifdef CONFIG_FSL_CORENET
Michal Simek20b016a2018-06-13 08:56:31 +020085int cpu_disable(u32 nr)
Kumar Gala4194b362010-01-12 11:42:43 -060086{
Kumar Galaa9c3ac72010-01-12 12:56:05 -060087 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
88
89 setbits_be32(&gur->coredisrl, 1 << nr);
90
91 return 0;
Kumar Gala4194b362010-01-12 11:42:43 -060092}
Kumar Gala8f3a7fa2010-06-09 22:33:53 -050093
94int is_core_disabled(int nr) {
95 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
96 u32 coredisrl = in_be32(&gur->coredisrl);
97
98 return (coredisrl & (1 << nr));
99}
Kumar Galaa9c3ac72010-01-12 12:56:05 -0600100#else
Michal Simek20b016a2018-06-13 08:56:31 +0200101int cpu_disable(u32 nr)
Kumar Galaa9c3ac72010-01-12 12:56:05 -0600102{
103 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
104
105 switch (nr) {
106 case 0:
107 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0);
108 break;
109 case 1:
110 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1);
111 break;
112 default:
113 printf("Invalid cpu number for disable %d\n", nr);
114 return 1;
115 }
116
117 return 0;
118}
Kumar Gala8f3a7fa2010-06-09 22:33:53 -0500119
120int is_core_disabled(int nr) {
121 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
122 u32 devdisr = in_be32(&gur->devdisr);
123
124 switch (nr) {
125 case 0:
126 return (devdisr & MPC85xx_DEVDISR_CPU0);
127 case 1:
128 return (devdisr & MPC85xx_DEVDISR_CPU1);
129 default:
130 printf("Invalid cpu number for disable %d\n", nr);
131 }
132
133 return 0;
134}
Kumar Galaa9c3ac72010-01-12 12:56:05 -0600135#endif
Kumar Gala4194b362010-01-12 11:42:43 -0600136
Kumar Gala79679d82008-03-26 08:34:25 -0500137static u8 boot_entry_map[4] = {
138 0,
139 BOOT_ENTRY_PIR,
140 BOOT_ENTRY_R3_LOWER,
Kumar Gala79679d82008-03-26 08:34:25 -0500141};
142
Simon Glass09140112020-05-10 11:40:03 -0600143int cpu_release(u32 nr, int argc, char *const argv[])
Kumar Galaec2b74f2008-01-17 16:48:33 -0600144{
York Sunffd06e02012-10-08 07:44:30 +0000145 u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
Kumar Gala79679d82008-03-26 08:34:25 -0500146 u64 boot_addr;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600147
Aaron Sierra9d64c6b2010-09-30 12:22:16 -0500148 if (hold_cores_in_reset(1))
149 return 0;
150
Kumar Galaec2b74f2008-01-17 16:48:33 -0600151 if (nr == get_my_id()) {
152 printf("Invalid to release the boot core.\n\n");
153 return 1;
154 }
155
Kumar Gala79679d82008-03-26 08:34:25 -0500156 if (argc != 4) {
Kumar Galaec2b74f2008-01-17 16:48:33 -0600157 printf("Invalid number of arguments to release.\n\n");
158 return 1;
159 }
160
Kumar Gala79679d82008-03-26 08:34:25 -0500161 boot_addr = simple_strtoull(argv[0], NULL, 16);
Kumar Gala79679d82008-03-26 08:34:25 -0500162
York Sun3f0997b2012-10-08 07:44:29 +0000163 /* handle pir, r3 */
164 for (i = 1; i < 3; i++) {
Kumar Galaec2b74f2008-01-17 16:48:33 -0600165 if (argv[i][0] != '-') {
Kumar Gala79679d82008-03-26 08:34:25 -0500166 u8 entry = boot_entry_map[i];
Kumar Galaec2b74f2008-01-17 16:48:33 -0600167 val = simple_strtoul(argv[i], NULL, 16);
Kumar Gala79679d82008-03-26 08:34:25 -0500168 table[entry] = val;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600169 }
170 }
171
Kumar Gala79679d82008-03-26 08:34:25 -0500172 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
Kumar Galacf6cc012008-04-28 02:24:04 -0500173
174 /* ensure all table updates complete before final address write */
175 eieio();
176
Kumar Gala79679d82008-03-26 08:34:25 -0500177 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600178
179 return 0;
180}
181
York Suneb539412012-10-08 07:44:25 +0000182u32 determine_mp_bootpg(unsigned int *pagesize)
Kumar Galac840d262009-03-31 23:11:05 -0500183{
York Suneb539412012-10-08 07:44:25 +0000184 u32 bootpg;
185#ifdef CONFIG_SYS_FSL_ERRATUM_A004468
186 u32 svr = get_svr();
187 u32 granule_size, check;
188 struct law_entry e;
189#endif
190
York Sunffd06e02012-10-08 07:44:30 +0000191
192 /* use last 4K of mapped memory */
193 bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
194 CONFIG_MAX_MEM_MAPPED : gd->ram_size) +
195 CONFIG_SYS_SDRAM_BASE - 4096;
York Suneb539412012-10-08 07:44:25 +0000196 if (pagesize)
197 *pagesize = 4096;
Kumar Galac840d262009-03-31 23:11:05 -0500198
York Suneb539412012-10-08 07:44:25 +0000199#ifdef CONFIG_SYS_FSL_ERRATUM_A004468
200/*
201 * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
202 * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
203 * the way boot page chosen in u-boot avoids hitting this erratum. So only
204 * thw workaround for 3-way interleaving is needed.
205 *
206 * To make sure boot page translation works with 3-Way DDR interleaving
207 * enforce a check for the following constrains
208 * 8K granule size requires BRSIZE=8K and
209 * bootpg >> log2(BRSIZE) %3 == 1
210 * 4K and 1K granule size requires BRSIZE=4K and
211 * bootpg >> log2(BRSIZE) %3 == 0
212 */
213 if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) {
214 e = find_law(bootpg);
215 switch (e.trgt_id) {
216 case LAW_TRGT_IF_DDR_INTLV_123:
217 granule_size = fsl_ddr_get_intl3r() & 0x1f;
218 if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) {
219 if (pagesize)
220 *pagesize = 8192;
221 bootpg &= 0xffffe000; /* align to 8KB */
222 check = bootpg >> 13;
223 while ((check % 3) != 1)
224 check--;
225 bootpg = check << 13;
226 debug("Boot page (8K) at 0x%08x\n", bootpg);
227 break;
228 } else {
229 bootpg &= 0xfffff000; /* align to 4KB */
230 check = bootpg >> 12;
231 while ((check % 3) != 0)
232 check--;
233 bootpg = check << 12;
234 debug("Boot page (4K) at 0x%08x\n", bootpg);
235 }
236 break;
237 default:
238 break;
239 }
240 }
241#endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
242
243 return bootpg;
Kumar Galac840d262009-03-31 23:11:05 -0500244}
245
York Sunffd06e02012-10-08 07:44:30 +0000246phys_addr_t get_spin_phys_addr(void)
Kumar Galaec2b74f2008-01-17 16:48:33 -0600247{
York Sunffd06e02012-10-08 07:44:30 +0000248 return virt_to_phys(&__spin_table);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600249}
250
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500251#ifdef CONFIG_FSL_CORENET
York Suneb539412012-10-08 07:44:25 +0000252static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500253{
York Suneb539412012-10-08 07:44:25 +0000254 u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
York Sunffd06e02012-10-08 07:44:30 +0000255 u32 *table = (u32 *)&__spin_table;
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500256 volatile ccsr_gur_t *gur;
257 volatile ccsr_local_t *ccm;
258 volatile ccsr_rcpm_t *rcpm;
259 volatile ccsr_pic_t *pic;
260 int timeout = 10;
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500261 u32 mask = cpu_mask();
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500262 struct law_entry e;
263
264 gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
265 ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
266 rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
Kim Phillips680c6132010-08-09 18:39:57 -0500267 pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500268
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500269 whoami = in_be32(&pic->whoami);
270 cpu_up_mask = 1 << whoami;
271 out_be32(&ccm->bstrl, bootpg);
272
273 e = find_law(bootpg);
York Suneb539412012-10-08 07:44:25 +0000274 /* pagesize is only 4K or 8K */
275 if (pagesize == 8192)
276 brsize = LAW_SIZE_8K;
277 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
278 debug("BRSIZE is 0x%x\n", brsize);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500279
Dave Liuf5ecc6e2009-11-17 20:01:24 -0600280 /* readback to sync write */
281 in_be32(&ccm->bstrar);
282
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500283 /* disable time base at the platform */
284 out_be32(&rcpm->ctbenrl, cpu_up_mask);
285
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500286 out_be32(&gur->brrl, mask);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500287
288 /* wait for everyone */
289 while (timeout) {
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500290 unsigned int i, cpu, nr_cpus = cpu_numcores();
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500291
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500292 for_each_cpu(i, cpu, nr_cpus, mask) {
293 if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
294 cpu_up_mask |= (1 << cpu);
295 }
296
297 if ((cpu_up_mask & mask) == mask)
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500298 break;
299
300 udelay(100);
301 timeout--;
302 }
303
304 if (timeout == 0)
305 printf("CPU up timeout. CPU up mask is %x should be %x\n",
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500306 cpu_up_mask, mask);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500307
308 /* enable time base at the platform */
309 out_be32(&rcpm->ctbenrl, 0);
Kumar Gala7afc45a2011-03-13 10:55:53 -0500310
311 /* readback to sync write */
312 in_be32(&rcpm->ctbenrl);
313
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500314 mtspr(SPRN_TBWU, 0);
315 mtspr(SPRN_TBWL, 0);
Kumar Gala7afc45a2011-03-13 10:55:53 -0500316
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500317 out_be32(&rcpm->ctbenrl, mask);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500318
319#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
320 /*
321 * Disabling Boot Page Translation allows the memory region 0xfffff000
322 * to 0xffffffff to be used normally. Leaving Boot Page Translation
323 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
324 * unusable for normal operation but it does allow OSes to easily
325 * reset a processor core to put it back into U-Boot's spinloop.
326 */
Ed Swarthoute81241a2011-03-03 18:28:14 -0600327 clrbits_be32(&ccm->bstrar, LAW_EN);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500328#endif
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500329}
330#else
York Suneb539412012-10-08 07:44:25 +0000331static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
Kumar Galaec2b74f2008-01-17 16:48:33 -0600332{
333 u32 up, cpu_up_mask, whoami;
York Sunffd06e02012-10-08 07:44:30 +0000334 u32 *table = (u32 *)&__spin_table;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600335 volatile u32 bpcr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200336 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
337 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kim Phillips680c6132010-08-09 18:39:57 -0500338 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600339 u32 devdisr;
340 int timeout = 10;
341
342 whoami = in_be32(&pic->whoami);
343 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
344
345 /* disable time base at the platform */
346 devdisr = in_be32(&gur->devdisr);
347 if (whoami)
348 devdisr |= MPC85xx_DEVDISR_TB0;
349 else
350 devdisr |= MPC85xx_DEVDISR_TB1;
351 out_be32(&gur->devdisr, devdisr);
352
353 /* release the hounds */
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530354 up = ((1 << cpu_numcores()) - 1);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600355 bpcr = in_be32(&ecm->eebpcr);
356 bpcr |= (up << 24);
357 out_be32(&ecm->eebpcr, bpcr);
358 asm("sync; isync; msync");
359
360 cpu_up_mask = 1 << whoami;
361 /* wait for everyone */
362 while (timeout) {
363 int i;
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530364 for (i = 0; i < cpu_numcores(); i++) {
Kumar Gala97b3ecb2008-04-09 04:20:57 -0500365 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
Kumar Galaec2b74f2008-01-17 16:48:33 -0600366 cpu_up_mask |= (1 << i);
367 };
368
369 if ((cpu_up_mask & up) == up)
370 break;
371
372 udelay(100);
373 timeout--;
374 }
375
Kumar Gala97b3ecb2008-04-09 04:20:57 -0500376 if (timeout == 0)
377 printf("CPU up timeout. CPU up mask is %x should be %x\n",
378 cpu_up_mask, up);
379
Kumar Galaec2b74f2008-01-17 16:48:33 -0600380 /* enable time base at the platform */
381 if (whoami)
382 devdisr |= MPC85xx_DEVDISR_TB1;
383 else
384 devdisr |= MPC85xx_DEVDISR_TB0;
385 out_be32(&gur->devdisr, devdisr);
Kumar Gala7afc45a2011-03-13 10:55:53 -0500386
387 /* readback to sync write */
388 in_be32(&gur->devdisr);
389
Kumar Galaec2b74f2008-01-17 16:48:33 -0600390 mtspr(SPRN_TBWU, 0);
391 mtspr(SPRN_TBWL, 0);
392
393 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
394 out_be32(&gur->devdisr, devdisr);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500395
396#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
397 /*
398 * Disabling Boot Page Translation allows the memory region 0xfffff000
399 * to 0xffffffff to be used normally. Leaving Boot Page Translation
400 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
401 * unusable for normal operation but it does allow OSes to easily
402 * reset a processor core to put it back into U-Boot's spinloop.
403 */
404 clrbits_be32(&ecm->bptr, 0x80000000);
405#endif
Kumar Galaec2b74f2008-01-17 16:48:33 -0600406}
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500407#endif
Kumar Galaec2b74f2008-01-17 16:48:33 -0600408
Kumar Galadd6c9102008-03-26 08:53:53 -0500409void cpu_mp_lmb_reserve(struct lmb *lmb)
410{
York Suneb539412012-10-08 07:44:25 +0000411 u32 bootpg = determine_mp_bootpg(NULL);
Kumar Galadd6c9102008-03-26 08:53:53 -0500412
413 lmb_reserve(lmb, bootpg, 4096);
414}
415
Kumar Galaec2b74f2008-01-17 16:48:33 -0600416void setup_mp(void)
417{
York Sunffd06e02012-10-08 07:44:30 +0000418 extern u32 __secondary_start_page;
419 extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page;
York Suneb539412012-10-08 07:44:25 +0000420
York Sunffd06e02012-10-08 07:44:30 +0000421 int i;
422 ulong fixup = (u32)&__secondary_start_page;
York Suneb539412012-10-08 07:44:25 +0000423 u32 bootpg, bootpg_map, pagesize;
424
425 bootpg = determine_mp_bootpg(&pagesize);
426
427 /*
428 * pagesize is only 4K or 8K
429 * we only use the last 4K of boot page
430 * bootpg_map saves the address for the boot page
431 * 8K is used for the workaround of 3-way DDR interleaving
432 */
433
434 bootpg_map = bootpg;
435
436 if (pagesize == 8192)
437 bootpg += 4096; /* use 2nd half */
Kumar Galaec2b74f2008-01-17 16:48:33 -0600438
Aaron Sierra9d64c6b2010-09-30 12:22:16 -0500439 /* Some OSes expect secondary cores to be held in reset */
440 if (hold_cores_in_reset(0))
441 return;
442
York Sunffd06e02012-10-08 07:44:30 +0000443 /*
444 * Store the bootpg's cache-able half address for use by secondary
445 * CPU cores to continue to boot
446 */
447 __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
448
449 /* Store spin table's physical address for use by secondary cores */
450 __spin_table_addr = (u32)get_spin_phys_addr();
451
452 /* flush bootpg it before copying invalidate any staled cacheline */
453 flush_cache(bootpg, 4096);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500454
Kumar Galac7259082009-09-03 08:41:31 -0500455 /* look for the tlb covering the reset page, there better be one */
York Sunffd06e02012-10-08 07:44:30 +0000456 i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600457
Kumar Galac7259082009-09-03 08:41:31 -0500458 /* we found a match */
459 if (i != -1) {
460 /* map reset page to bootpg so we can copy code there */
461 disable_tlb(i);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500462
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500463 set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
Kumar Galaabc76eb2009-11-17 20:21:20 -0600464 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
Kumar Galac7259082009-09-03 08:41:31 -0500465 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
466
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500467 memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
468
York Suneb539412012-10-08 07:44:25 +0000469 plat_mp_up(bootpg_map, pagesize);
Kumar Galac7259082009-09-03 08:41:31 -0500470 } else {
471 puts("WARNING: No reset page TLB. "
472 "Skipping secondary core setup\n");
473 }
Kumar Galaec2b74f2008-01-17 16:48:33 -0600474}