blob: b0aa72ed6e0213a28db99b4feae0d0322be892e4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Gala36d6b3f2008-01-17 16:48:33 -06002/*
Ed Swarthout853e2de2011-03-03 18:28:14 -06003 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Kumar Gala36d6b3f2008-01-17 16:48:33 -06004 */
5
6#include <common.h>
7#include <asm/processor.h>
8#include <ioports.h>
Kumar Gala5769ded2008-03-26 08:53:53 -05009#include <lmb.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060010#include <asm/io.h>
Kumar Gala8399e122009-09-03 08:41:31 -050011#include <asm/mmu.h>
Kumar Gala4d9190d2009-09-17 01:44:39 -050012#include <asm/fsl_law.h>
York Sunf0626592013-09-30 09:22:09 -070013#include <fsl_ddr_sdram.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060014#include "mp.h"
15
16DECLARE_GLOBAL_DATA_PTR;
York Suna28496f2012-10-08 07:44:25 +000017u32 fsl_ddr_get_intl3r(void);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060018
York Sun2394a0f2012-10-08 07:44:30 +000019extern u32 __spin_table[];
20
Kumar Gala36d6b3f2008-01-17 16:48:33 -060021u32 get_my_id()
22{
23 return mfspr(SPRN_PIR);
24}
25
Aaron Sierraec8863b2010-09-30 12:22:16 -050026/*
27 * Determine if U-Boot should keep secondary cores in reset, or let them out
28 * of reset and hold them in a spinloop
29 */
30int hold_cores_in_reset(int verbose)
31{
Robert P. J. Day8d56db92016-07-15 13:44:45 -040032 /* Default to no, overridden by 'y', 'yes', 'Y', 'Yes', or '1' */
Simon Glass22c34c22017-08-03 12:22:13 -060033 if (env_get_yesno("mp_holdoff") == 1) {
Aaron Sierraec8863b2010-09-30 12:22:16 -050034 if (verbose) {
35 puts("Secondary cores are being held in reset.\n");
36 puts("See 'mp_holdoff' environment variable\n");
37 }
38
39 return 1;
40 }
41
42 return 0;
43}
44
Michal Simek1669e182018-06-13 08:56:31 +020045int cpu_reset(u32 nr)
Kumar Gala36d6b3f2008-01-17 16:48:33 -060046{
Kim Phillips2ecbfeb2010-08-09 18:39:57 -050047 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060048 out_be32(&pic->pir, 1 << nr);
Kumar Galae1064b32009-03-31 23:11:05 -050049 /* the dummy read works around an errata on early 85xx MP PICs */
Kumar Gala36d6b3f2008-01-17 16:48:33 -060050 (void)in_be32(&pic->pir);
51 out_be32(&pic->pir, 0x0);
52
53 return 0;
54}
55
Michal Simek1669e182018-06-13 08:56:31 +020056int cpu_status(u32 nr)
Kumar Gala36d6b3f2008-01-17 16:48:33 -060057{
58 u32 *table, id = get_my_id();
59
Aaron Sierraec8863b2010-09-30 12:22:16 -050060 if (hold_cores_in_reset(1))
61 return 0;
62
Kumar Gala36d6b3f2008-01-17 16:48:33 -060063 if (nr == id) {
York Sun2394a0f2012-10-08 07:44:30 +000064 table = (u32 *)&__spin_table;
Kumar Gala275f4c12008-07-14 14:03:02 -050065 printf("table base @ 0x%p\n", table);
York Sunc0723062013-03-25 07:40:00 +000066 } else if (is_core_disabled(nr)) {
67 puts("Disabled\n");
Kumar Gala36d6b3f2008-01-17 16:48:33 -060068 } else {
York Sun2394a0f2012-10-08 07:44:30 +000069 table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
Kumar Gala36d6b3f2008-01-17 16:48:33 -060070 printf("Running on cpu %d\n", id);
71 printf("\n");
Kumar Gala275f4c12008-07-14 14:03:02 -050072 printf("table @ 0x%p\n", table);
Kumar Galadeeac572008-03-26 08:34:25 -050073 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
Kumar Galadeeac572008-03-26 08:34:25 -050074 printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
York Sun31a0c8c2012-10-08 07:44:29 +000075 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060076 }
77
78 return 0;
79}
80
Kumar Galac7bf0f92010-01-12 12:56:05 -060081#ifdef CONFIG_FSL_CORENET
Michal Simek1669e182018-06-13 08:56:31 +020082int cpu_disable(u32 nr)
Kumar Gala006e2c82010-01-12 11:42:43 -060083{
Kumar Galac7bf0f92010-01-12 12:56:05 -060084 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
85
86 setbits_be32(&gur->coredisrl, 1 << nr);
87
88 return 0;
89}
Kumar Gala819a4792010-06-09 22:33:53 -050090
91int is_core_disabled(int nr) {
92 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
93 u32 coredisrl = in_be32(&gur->coredisrl);
94
95 return (coredisrl & (1 << nr));
96}
Kumar Galac7bf0f92010-01-12 12:56:05 -060097#else
Michal Simek1669e182018-06-13 08:56:31 +020098int cpu_disable(u32 nr)
Kumar Galac7bf0f92010-01-12 12:56:05 -060099{
100 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
101
102 switch (nr) {
103 case 0:
104 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0);
105 break;
106 case 1:
107 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1);
108 break;
109 default:
110 printf("Invalid cpu number for disable %d\n", nr);
111 return 1;
112 }
113
114 return 0;
Kumar Gala006e2c82010-01-12 11:42:43 -0600115}
Kumar Gala819a4792010-06-09 22:33:53 -0500116
117int is_core_disabled(int nr) {
118 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
119 u32 devdisr = in_be32(&gur->devdisr);
120
121 switch (nr) {
122 case 0:
123 return (devdisr & MPC85xx_DEVDISR_CPU0);
124 case 1:
125 return (devdisr & MPC85xx_DEVDISR_CPU1);
126 default:
127 printf("Invalid cpu number for disable %d\n", nr);
128 }
129
130 return 0;
131}
Kumar Galac7bf0f92010-01-12 12:56:05 -0600132#endif
Kumar Gala006e2c82010-01-12 11:42:43 -0600133
Kumar Galadeeac572008-03-26 08:34:25 -0500134static u8 boot_entry_map[4] = {
135 0,
136 BOOT_ENTRY_PIR,
137 BOOT_ENTRY_R3_LOWER,
Kumar Galadeeac572008-03-26 08:34:25 -0500138};
139
Michal Simek1669e182018-06-13 08:56:31 +0200140int cpu_release(u32 nr, int argc, char * const argv[])
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600141{
York Sun2394a0f2012-10-08 07:44:30 +0000142 u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
Kumar Galadeeac572008-03-26 08:34:25 -0500143 u64 boot_addr;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600144
Aaron Sierraec8863b2010-09-30 12:22:16 -0500145 if (hold_cores_in_reset(1))
146 return 0;
147
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600148 if (nr == get_my_id()) {
149 printf("Invalid to release the boot core.\n\n");
150 return 1;
151 }
152
Kumar Galadeeac572008-03-26 08:34:25 -0500153 if (argc != 4) {
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600154 printf("Invalid number of arguments to release.\n\n");
155 return 1;
156 }
157
Kumar Galadeeac572008-03-26 08:34:25 -0500158 boot_addr = simple_strtoull(argv[0], NULL, 16);
Kumar Galadeeac572008-03-26 08:34:25 -0500159
York Sun31a0c8c2012-10-08 07:44:29 +0000160 /* handle pir, r3 */
161 for (i = 1; i < 3; i++) {
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600162 if (argv[i][0] != '-') {
Kumar Galadeeac572008-03-26 08:34:25 -0500163 u8 entry = boot_entry_map[i];
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600164 val = simple_strtoul(argv[i], NULL, 16);
Kumar Galadeeac572008-03-26 08:34:25 -0500165 table[entry] = val;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600166 }
167 }
168
Kumar Galadeeac572008-03-26 08:34:25 -0500169 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
Kumar Gala398dcd62008-04-28 02:24:04 -0500170
171 /* ensure all table updates complete before final address write */
172 eieio();
173
Kumar Galadeeac572008-03-26 08:34:25 -0500174 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600175
176 return 0;
177}
178
York Suna28496f2012-10-08 07:44:25 +0000179u32 determine_mp_bootpg(unsigned int *pagesize)
Kumar Galae1064b32009-03-31 23:11:05 -0500180{
York Suna28496f2012-10-08 07:44:25 +0000181 u32 bootpg;
182#ifdef CONFIG_SYS_FSL_ERRATUM_A004468
183 u32 svr = get_svr();
184 u32 granule_size, check;
185 struct law_entry e;
186#endif
187
York Sun2394a0f2012-10-08 07:44:30 +0000188
189 /* use last 4K of mapped memory */
190 bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
191 CONFIG_MAX_MEM_MAPPED : gd->ram_size) +
192 CONFIG_SYS_SDRAM_BASE - 4096;
York Suna28496f2012-10-08 07:44:25 +0000193 if (pagesize)
194 *pagesize = 4096;
Kumar Galae1064b32009-03-31 23:11:05 -0500195
York Suna28496f2012-10-08 07:44:25 +0000196#ifdef CONFIG_SYS_FSL_ERRATUM_A004468
197/*
198 * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
199 * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
200 * the way boot page chosen in u-boot avoids hitting this erratum. So only
201 * thw workaround for 3-way interleaving is needed.
202 *
203 * To make sure boot page translation works with 3-Way DDR interleaving
204 * enforce a check for the following constrains
205 * 8K granule size requires BRSIZE=8K and
206 * bootpg >> log2(BRSIZE) %3 == 1
207 * 4K and 1K granule size requires BRSIZE=4K and
208 * bootpg >> log2(BRSIZE) %3 == 0
209 */
210 if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) {
211 e = find_law(bootpg);
212 switch (e.trgt_id) {
213 case LAW_TRGT_IF_DDR_INTLV_123:
214 granule_size = fsl_ddr_get_intl3r() & 0x1f;
215 if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) {
216 if (pagesize)
217 *pagesize = 8192;
218 bootpg &= 0xffffe000; /* align to 8KB */
219 check = bootpg >> 13;
220 while ((check % 3) != 1)
221 check--;
222 bootpg = check << 13;
223 debug("Boot page (8K) at 0x%08x\n", bootpg);
224 break;
225 } else {
226 bootpg &= 0xfffff000; /* align to 4KB */
227 check = bootpg >> 12;
228 while ((check % 3) != 0)
229 check--;
230 bootpg = check << 12;
231 debug("Boot page (4K) at 0x%08x\n", bootpg);
232 }
233 break;
234 default:
235 break;
236 }
237 }
238#endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
239
240 return bootpg;
Kumar Galae1064b32009-03-31 23:11:05 -0500241}
242
York Sun2394a0f2012-10-08 07:44:30 +0000243phys_addr_t get_spin_phys_addr(void)
Peter Tyser7feaacb2009-10-23 15:55:47 -0500244{
York Sun2394a0f2012-10-08 07:44:30 +0000245 return virt_to_phys(&__spin_table);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600246}
247
Kumar Gala4d9190d2009-09-17 01:44:39 -0500248#ifdef CONFIG_FSL_CORENET
York Suna28496f2012-10-08 07:44:25 +0000249static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600250{
York Suna28496f2012-10-08 07:44:25 +0000251 u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
York Sun2394a0f2012-10-08 07:44:30 +0000252 u32 *table = (u32 *)&__spin_table;
Kumar Gala4d9190d2009-09-17 01:44:39 -0500253 volatile ccsr_gur_t *gur;
254 volatile ccsr_local_t *ccm;
255 volatile ccsr_rcpm_t *rcpm;
256 volatile ccsr_pic_t *pic;
257 int timeout = 10;
Timur Tabi47289422011-08-05 16:15:24 -0500258 u32 mask = cpu_mask();
Kumar Gala4d9190d2009-09-17 01:44:39 -0500259 struct law_entry e;
260
261 gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
262 ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
263 rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
Kim Phillips2ecbfeb2010-08-09 18:39:57 -0500264 pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500265
Kumar Gala4d9190d2009-09-17 01:44:39 -0500266 whoami = in_be32(&pic->whoami);
267 cpu_up_mask = 1 << whoami;
268 out_be32(&ccm->bstrl, bootpg);
269
270 e = find_law(bootpg);
York Suna28496f2012-10-08 07:44:25 +0000271 /* pagesize is only 4K or 8K */
272 if (pagesize == 8192)
273 brsize = LAW_SIZE_8K;
274 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
275 debug("BRSIZE is 0x%x\n", brsize);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500276
Dave Liu452ddb62009-11-17 20:01:24 -0600277 /* readback to sync write */
278 in_be32(&ccm->bstrar);
279
Kumar Gala4d9190d2009-09-17 01:44:39 -0500280 /* disable time base at the platform */
281 out_be32(&rcpm->ctbenrl, cpu_up_mask);
282
Timur Tabi47289422011-08-05 16:15:24 -0500283 out_be32(&gur->brrl, mask);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500284
285 /* wait for everyone */
286 while (timeout) {
Timur Tabi47289422011-08-05 16:15:24 -0500287 unsigned int i, cpu, nr_cpus = cpu_numcores();
Kumar Gala4d9190d2009-09-17 01:44:39 -0500288
Timur Tabi47289422011-08-05 16:15:24 -0500289 for_each_cpu(i, cpu, nr_cpus, mask) {
290 if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
291 cpu_up_mask |= (1 << cpu);
292 }
293
294 if ((cpu_up_mask & mask) == mask)
Kumar Gala4d9190d2009-09-17 01:44:39 -0500295 break;
296
297 udelay(100);
298 timeout--;
299 }
300
301 if (timeout == 0)
302 printf("CPU up timeout. CPU up mask is %x should be %x\n",
Timur Tabi47289422011-08-05 16:15:24 -0500303 cpu_up_mask, mask);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500304
305 /* enable time base at the platform */
306 out_be32(&rcpm->ctbenrl, 0);
Kumar Gala6c5025e2011-03-13 10:55:53 -0500307
308 /* readback to sync write */
309 in_be32(&rcpm->ctbenrl);
310
Kumar Gala4d9190d2009-09-17 01:44:39 -0500311 mtspr(SPRN_TBWU, 0);
312 mtspr(SPRN_TBWL, 0);
Kumar Gala6c5025e2011-03-13 10:55:53 -0500313
Timur Tabi47289422011-08-05 16:15:24 -0500314 out_be32(&rcpm->ctbenrl, mask);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500315
316#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
317 /*
318 * Disabling Boot Page Translation allows the memory region 0xfffff000
319 * to 0xffffffff to be used normally. Leaving Boot Page Translation
320 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
321 * unusable for normal operation but it does allow OSes to easily
322 * reset a processor core to put it back into U-Boot's spinloop.
323 */
Ed Swarthout853e2de2011-03-03 18:28:14 -0600324 clrbits_be32(&ccm->bstrar, LAW_EN);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500325#endif
Kumar Gala4d9190d2009-09-17 01:44:39 -0500326}
327#else
York Suna28496f2012-10-08 07:44:25 +0000328static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
Kumar Gala4d9190d2009-09-17 01:44:39 -0500329{
330 u32 up, cpu_up_mask, whoami;
York Sun2394a0f2012-10-08 07:44:30 +0000331 u32 *table = (u32 *)&__spin_table;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600332 volatile u32 bpcr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200333 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
334 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kim Phillips2ecbfeb2010-08-09 18:39:57 -0500335 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600336 u32 devdisr;
337 int timeout = 10;
338
339 whoami = in_be32(&pic->whoami);
340 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
341
342 /* disable time base at the platform */
343 devdisr = in_be32(&gur->devdisr);
344 if (whoami)
345 devdisr |= MPC85xx_DEVDISR_TB0;
346 else
347 devdisr |= MPC85xx_DEVDISR_TB1;
348 out_be32(&gur->devdisr, devdisr);
349
350 /* release the hounds */
Poonam Aggrwal4baef822009-07-31 12:08:14 +0530351 up = ((1 << cpu_numcores()) - 1);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600352 bpcr = in_be32(&ecm->eebpcr);
353 bpcr |= (up << 24);
354 out_be32(&ecm->eebpcr, bpcr);
355 asm("sync; isync; msync");
356
357 cpu_up_mask = 1 << whoami;
358 /* wait for everyone */
359 while (timeout) {
360 int i;
Poonam Aggrwal4baef822009-07-31 12:08:14 +0530361 for (i = 0; i < cpu_numcores(); i++) {
Kumar Gala615f14d2008-04-09 04:20:57 -0500362 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600363 cpu_up_mask |= (1 << i);
364 };
365
366 if ((cpu_up_mask & up) == up)
367 break;
368
369 udelay(100);
370 timeout--;
371 }
372
Kumar Gala615f14d2008-04-09 04:20:57 -0500373 if (timeout == 0)
374 printf("CPU up timeout. CPU up mask is %x should be %x\n",
375 cpu_up_mask, up);
376
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600377 /* enable time base at the platform */
378 if (whoami)
379 devdisr |= MPC85xx_DEVDISR_TB1;
380 else
381 devdisr |= MPC85xx_DEVDISR_TB0;
382 out_be32(&gur->devdisr, devdisr);
Kumar Gala6c5025e2011-03-13 10:55:53 -0500383
384 /* readback to sync write */
385 in_be32(&gur->devdisr);
386
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600387 mtspr(SPRN_TBWU, 0);
388 mtspr(SPRN_TBWL, 0);
389
390 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
391 out_be32(&gur->devdisr, devdisr);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500392
393#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
394 /*
395 * Disabling Boot Page Translation allows the memory region 0xfffff000
396 * to 0xffffffff to be used normally. Leaving Boot Page Translation
397 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
398 * unusable for normal operation but it does allow OSes to easily
399 * reset a processor core to put it back into U-Boot's spinloop.
400 */
401 clrbits_be32(&ecm->bptr, 0x80000000);
402#endif
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600403}
Kumar Gala4d9190d2009-09-17 01:44:39 -0500404#endif
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600405
Kumar Gala5769ded2008-03-26 08:53:53 -0500406void cpu_mp_lmb_reserve(struct lmb *lmb)
407{
York Suna28496f2012-10-08 07:44:25 +0000408 u32 bootpg = determine_mp_bootpg(NULL);
Kumar Gala5769ded2008-03-26 08:53:53 -0500409
410 lmb_reserve(lmb, bootpg, 4096);
411}
412
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600413void setup_mp(void)
414{
York Sun2394a0f2012-10-08 07:44:30 +0000415 extern u32 __secondary_start_page;
416 extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page;
York Suna28496f2012-10-08 07:44:25 +0000417
York Sun2394a0f2012-10-08 07:44:30 +0000418 int i;
419 ulong fixup = (u32)&__secondary_start_page;
York Suna28496f2012-10-08 07:44:25 +0000420 u32 bootpg, bootpg_map, pagesize;
421
422 bootpg = determine_mp_bootpg(&pagesize);
423
424 /*
425 * pagesize is only 4K or 8K
426 * we only use the last 4K of boot page
427 * bootpg_map saves the address for the boot page
428 * 8K is used for the workaround of 3-way DDR interleaving
429 */
430
431 bootpg_map = bootpg;
432
433 if (pagesize == 8192)
434 bootpg += 4096; /* use 2nd half */
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600435
Aaron Sierraec8863b2010-09-30 12:22:16 -0500436 /* Some OSes expect secondary cores to be held in reset */
437 if (hold_cores_in_reset(0))
438 return;
439
York Sun2394a0f2012-10-08 07:44:30 +0000440 /*
441 * Store the bootpg's cache-able half address for use by secondary
442 * CPU cores to continue to boot
443 */
444 __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
445
446 /* Store spin table's physical address for use by secondary cores */
447 __spin_table_addr = (u32)get_spin_phys_addr();
448
449 /* flush bootpg it before copying invalidate any staled cacheline */
450 flush_cache(bootpg, 4096);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500451
Kumar Gala8399e122009-09-03 08:41:31 -0500452 /* look for the tlb covering the reset page, there better be one */
York Sun2394a0f2012-10-08 07:44:30 +0000453 i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600454
Kumar Gala8399e122009-09-03 08:41:31 -0500455 /* we found a match */
456 if (i != -1) {
457 /* map reset page to bootpg so we can copy code there */
458 disable_tlb(i);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500459
Peter Tyser7feaacb2009-10-23 15:55:47 -0500460 set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
Kumar Gala4756ffa2009-11-17 20:21:20 -0600461 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
Kumar Gala8399e122009-09-03 08:41:31 -0500462 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
463
Peter Tyser7feaacb2009-10-23 15:55:47 -0500464 memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
465
York Suna28496f2012-10-08 07:44:25 +0000466 plat_mp_up(bootpg_map, pagesize);
Kumar Gala8399e122009-09-03 08:41:31 -0500467 } else {
468 puts("WARNING: No reset page TLB. "
469 "Skipping secondary core setup\n");
470 }
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600471}