blob: 8822cf29fefd081aa07fa4837a14bcf05086285c [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>
Simon Glass970b61e2019-11-14 12:57:09 -07007#include <cpu_func.h>
Simon Glassc301bd82019-08-01 09:46:49 -06008#include <env.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060010#include <asm/processor.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060011#include <env.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060012#include <ioports.h>
Kumar Gala5769ded2008-03-26 08:53:53 -050013#include <lmb.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060014#include <asm/io.h>
Kumar Gala8399e122009-09-03 08:41:31 -050015#include <asm/mmu.h>
Kumar Gala4d9190d2009-09-17 01:44:39 -050016#include <asm/fsl_law.h>
York Sunf0626592013-09-30 09:22:09 -070017#include <fsl_ddr_sdram.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060019#include "mp.h"
20
21DECLARE_GLOBAL_DATA_PTR;
York Suna28496f2012-10-08 07:44:25 +000022u32 fsl_ddr_get_intl3r(void);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060023
York Sun2394a0f2012-10-08 07:44:30 +000024extern u32 __spin_table[];
25
Kumar Gala36d6b3f2008-01-17 16:48:33 -060026u32 get_my_id()
27{
28 return mfspr(SPRN_PIR);
29}
30
Aaron Sierraec8863b2010-09-30 12:22:16 -050031/*
32 * Determine if U-Boot should keep secondary cores in reset, or let them out
33 * of reset and hold them in a spinloop
34 */
35int hold_cores_in_reset(int verbose)
36{
Robert P. J. Day8d56db92016-07-15 13:44:45 -040037 /* Default to no, overridden by 'y', 'yes', 'Y', 'Yes', or '1' */
Simon Glass22c34c22017-08-03 12:22:13 -060038 if (env_get_yesno("mp_holdoff") == 1) {
Aaron Sierraec8863b2010-09-30 12:22:16 -050039 if (verbose) {
40 puts("Secondary cores are being held in reset.\n");
41 puts("See 'mp_holdoff' environment variable\n");
42 }
43
44 return 1;
45 }
46
47 return 0;
48}
49
Michal Simek1669e182018-06-13 08:56:31 +020050int cpu_reset(u32 nr)
Kumar Gala36d6b3f2008-01-17 16:48:33 -060051{
Kim Phillips2ecbfeb2010-08-09 18:39:57 -050052 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060053 out_be32(&pic->pir, 1 << nr);
Kumar Galae1064b32009-03-31 23:11:05 -050054 /* the dummy read works around an errata on early 85xx MP PICs */
Kumar Gala36d6b3f2008-01-17 16:48:33 -060055 (void)in_be32(&pic->pir);
56 out_be32(&pic->pir, 0x0);
57
58 return 0;
59}
60
Michal Simek1669e182018-06-13 08:56:31 +020061int cpu_status(u32 nr)
Kumar Gala36d6b3f2008-01-17 16:48:33 -060062{
63 u32 *table, id = get_my_id();
64
Aaron Sierraec8863b2010-09-30 12:22:16 -050065 if (hold_cores_in_reset(1))
66 return 0;
67
Kumar Gala36d6b3f2008-01-17 16:48:33 -060068 if (nr == id) {
York Sun2394a0f2012-10-08 07:44:30 +000069 table = (u32 *)&__spin_table;
Kumar Gala275f4c12008-07-14 14:03:02 -050070 printf("table base @ 0x%p\n", table);
York Sunc0723062013-03-25 07:40:00 +000071 } else if (is_core_disabled(nr)) {
72 puts("Disabled\n");
Kumar Gala36d6b3f2008-01-17 16:48:33 -060073 } else {
York Sun2394a0f2012-10-08 07:44:30 +000074 table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
Kumar Gala36d6b3f2008-01-17 16:48:33 -060075 printf("Running on cpu %d\n", id);
76 printf("\n");
Kumar Gala275f4c12008-07-14 14:03:02 -050077 printf("table @ 0x%p\n", table);
Kumar Galadeeac572008-03-26 08:34:25 -050078 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
Kumar Galadeeac572008-03-26 08:34:25 -050079 printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
York Sun31a0c8c2012-10-08 07:44:29 +000080 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060081 }
82
83 return 0;
84}
85
Kumar Galac7bf0f92010-01-12 12:56:05 -060086#ifdef CONFIG_FSL_CORENET
Michal Simek1669e182018-06-13 08:56:31 +020087int cpu_disable(u32 nr)
Kumar Gala006e2c82010-01-12 11:42:43 -060088{
Kumar Galac7bf0f92010-01-12 12:56:05 -060089 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
90
91 setbits_be32(&gur->coredisrl, 1 << nr);
92
93 return 0;
94}
Kumar Gala819a4792010-06-09 22:33:53 -050095
96int is_core_disabled(int nr) {
97 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
98 u32 coredisrl = in_be32(&gur->coredisrl);
99
100 return (coredisrl & (1 << nr));
101}
Kumar Galac7bf0f92010-01-12 12:56:05 -0600102#else
Michal Simek1669e182018-06-13 08:56:31 +0200103int cpu_disable(u32 nr)
Kumar Galac7bf0f92010-01-12 12:56:05 -0600104{
105 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
106
107 switch (nr) {
108 case 0:
109 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0);
110 break;
111 case 1:
112 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1);
113 break;
114 default:
115 printf("Invalid cpu number for disable %d\n", nr);
116 return 1;
117 }
118
119 return 0;
Kumar Gala006e2c82010-01-12 11:42:43 -0600120}
Kumar Gala819a4792010-06-09 22:33:53 -0500121
122int is_core_disabled(int nr) {
123 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
124 u32 devdisr = in_be32(&gur->devdisr);
125
126 switch (nr) {
127 case 0:
128 return (devdisr & MPC85xx_DEVDISR_CPU0);
129 case 1:
130 return (devdisr & MPC85xx_DEVDISR_CPU1);
131 default:
132 printf("Invalid cpu number for disable %d\n", nr);
133 }
134
135 return 0;
136}
Kumar Galac7bf0f92010-01-12 12:56:05 -0600137#endif
Kumar Gala006e2c82010-01-12 11:42:43 -0600138
Kumar Galadeeac572008-03-26 08:34:25 -0500139static u8 boot_entry_map[4] = {
140 0,
141 BOOT_ENTRY_PIR,
142 BOOT_ENTRY_R3_LOWER,
Kumar Galadeeac572008-03-26 08:34:25 -0500143};
144
Simon Glassed38aef2020-05-10 11:40:03 -0600145int cpu_release(u32 nr, int argc, char *const argv[])
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600146{
York Sun2394a0f2012-10-08 07:44:30 +0000147 u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
Kumar Galadeeac572008-03-26 08:34:25 -0500148 u64 boot_addr;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600149
Aaron Sierraec8863b2010-09-30 12:22:16 -0500150 if (hold_cores_in_reset(1))
151 return 0;
152
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600153 if (nr == get_my_id()) {
154 printf("Invalid to release the boot core.\n\n");
155 return 1;
156 }
157
Kumar Galadeeac572008-03-26 08:34:25 -0500158 if (argc != 4) {
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600159 printf("Invalid number of arguments to release.\n\n");
160 return 1;
161 }
162
Kumar Galadeeac572008-03-26 08:34:25 -0500163 boot_addr = simple_strtoull(argv[0], NULL, 16);
Kumar Galadeeac572008-03-26 08:34:25 -0500164
York Sun31a0c8c2012-10-08 07:44:29 +0000165 /* handle pir, r3 */
166 for (i = 1; i < 3; i++) {
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600167 if (argv[i][0] != '-') {
Kumar Galadeeac572008-03-26 08:34:25 -0500168 u8 entry = boot_entry_map[i];
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600169 val = simple_strtoul(argv[i], NULL, 16);
Kumar Galadeeac572008-03-26 08:34:25 -0500170 table[entry] = val;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600171 }
172 }
173
Kumar Galadeeac572008-03-26 08:34:25 -0500174 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
Kumar Gala398dcd62008-04-28 02:24:04 -0500175
176 /* ensure all table updates complete before final address write */
177 eieio();
178
Kumar Galadeeac572008-03-26 08:34:25 -0500179 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600180
181 return 0;
182}
183
York Suna28496f2012-10-08 07:44:25 +0000184u32 determine_mp_bootpg(unsigned int *pagesize)
Kumar Galae1064b32009-03-31 23:11:05 -0500185{
York Suna28496f2012-10-08 07:44:25 +0000186 u32 bootpg;
187#ifdef CONFIG_SYS_FSL_ERRATUM_A004468
188 u32 svr = get_svr();
189 u32 granule_size, check;
190 struct law_entry e;
191#endif
192
York Sun2394a0f2012-10-08 07:44:30 +0000193
194 /* use last 4K of mapped memory */
195 bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
196 CONFIG_MAX_MEM_MAPPED : gd->ram_size) +
197 CONFIG_SYS_SDRAM_BASE - 4096;
York Suna28496f2012-10-08 07:44:25 +0000198 if (pagesize)
199 *pagesize = 4096;
Kumar Galae1064b32009-03-31 23:11:05 -0500200
York Suna28496f2012-10-08 07:44:25 +0000201#ifdef CONFIG_SYS_FSL_ERRATUM_A004468
202/*
203 * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
204 * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
205 * the way boot page chosen in u-boot avoids hitting this erratum. So only
206 * thw workaround for 3-way interleaving is needed.
207 *
208 * To make sure boot page translation works with 3-Way DDR interleaving
209 * enforce a check for the following constrains
210 * 8K granule size requires BRSIZE=8K and
211 * bootpg >> log2(BRSIZE) %3 == 1
212 * 4K and 1K granule size requires BRSIZE=4K and
213 * bootpg >> log2(BRSIZE) %3 == 0
214 */
215 if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) {
216 e = find_law(bootpg);
217 switch (e.trgt_id) {
218 case LAW_TRGT_IF_DDR_INTLV_123:
219 granule_size = fsl_ddr_get_intl3r() & 0x1f;
220 if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) {
221 if (pagesize)
222 *pagesize = 8192;
223 bootpg &= 0xffffe000; /* align to 8KB */
224 check = bootpg >> 13;
225 while ((check % 3) != 1)
226 check--;
227 bootpg = check << 13;
228 debug("Boot page (8K) at 0x%08x\n", bootpg);
229 break;
230 } else {
231 bootpg &= 0xfffff000; /* align to 4KB */
232 check = bootpg >> 12;
233 while ((check % 3) != 0)
234 check--;
235 bootpg = check << 12;
236 debug("Boot page (4K) at 0x%08x\n", bootpg);
237 }
238 break;
239 default:
240 break;
241 }
242 }
243#endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
244
245 return bootpg;
Kumar Galae1064b32009-03-31 23:11:05 -0500246}
247
York Sun2394a0f2012-10-08 07:44:30 +0000248phys_addr_t get_spin_phys_addr(void)
Peter Tyser7feaacb2009-10-23 15:55:47 -0500249{
York Sun2394a0f2012-10-08 07:44:30 +0000250 return virt_to_phys(&__spin_table);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600251}
252
Kumar Gala4d9190d2009-09-17 01:44:39 -0500253#ifdef CONFIG_FSL_CORENET
York Suna28496f2012-10-08 07:44:25 +0000254static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600255{
York Suna28496f2012-10-08 07:44:25 +0000256 u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
York Sun2394a0f2012-10-08 07:44:30 +0000257 u32 *table = (u32 *)&__spin_table;
Kumar Gala4d9190d2009-09-17 01:44:39 -0500258 volatile ccsr_gur_t *gur;
259 volatile ccsr_local_t *ccm;
260 volatile ccsr_rcpm_t *rcpm;
261 volatile ccsr_pic_t *pic;
262 int timeout = 10;
Timur Tabi47289422011-08-05 16:15:24 -0500263 u32 mask = cpu_mask();
Kumar Gala4d9190d2009-09-17 01:44:39 -0500264 struct law_entry e;
265
266 gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
267 ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
268 rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
Kim Phillips2ecbfeb2010-08-09 18:39:57 -0500269 pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500270
Kumar Gala4d9190d2009-09-17 01:44:39 -0500271 whoami = in_be32(&pic->whoami);
272 cpu_up_mask = 1 << whoami;
273 out_be32(&ccm->bstrl, bootpg);
274
275 e = find_law(bootpg);
York Suna28496f2012-10-08 07:44:25 +0000276 /* pagesize is only 4K or 8K */
277 if (pagesize == 8192)
278 brsize = LAW_SIZE_8K;
279 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
280 debug("BRSIZE is 0x%x\n", brsize);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500281
Dave Liu452ddb62009-11-17 20:01:24 -0600282 /* readback to sync write */
283 in_be32(&ccm->bstrar);
284
Kumar Gala4d9190d2009-09-17 01:44:39 -0500285 /* disable time base at the platform */
286 out_be32(&rcpm->ctbenrl, cpu_up_mask);
287
Timur Tabi47289422011-08-05 16:15:24 -0500288 out_be32(&gur->brrl, mask);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500289
290 /* wait for everyone */
291 while (timeout) {
Timur Tabi47289422011-08-05 16:15:24 -0500292 unsigned int i, cpu, nr_cpus = cpu_numcores();
Kumar Gala4d9190d2009-09-17 01:44:39 -0500293
Timur Tabi47289422011-08-05 16:15:24 -0500294 for_each_cpu(i, cpu, nr_cpus, mask) {
295 if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
296 cpu_up_mask |= (1 << cpu);
297 }
298
299 if ((cpu_up_mask & mask) == mask)
Kumar Gala4d9190d2009-09-17 01:44:39 -0500300 break;
301
302 udelay(100);
303 timeout--;
304 }
305
306 if (timeout == 0)
307 printf("CPU up timeout. CPU up mask is %x should be %x\n",
Timur Tabi47289422011-08-05 16:15:24 -0500308 cpu_up_mask, mask);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500309
310 /* enable time base at the platform */
311 out_be32(&rcpm->ctbenrl, 0);
Kumar Gala6c5025e2011-03-13 10:55:53 -0500312
313 /* readback to sync write */
314 in_be32(&rcpm->ctbenrl);
315
Kumar Gala4d9190d2009-09-17 01:44:39 -0500316 mtspr(SPRN_TBWU, 0);
317 mtspr(SPRN_TBWL, 0);
Kumar Gala6c5025e2011-03-13 10:55:53 -0500318
Timur Tabi47289422011-08-05 16:15:24 -0500319 out_be32(&rcpm->ctbenrl, mask);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500320
321#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
322 /*
323 * Disabling Boot Page Translation allows the memory region 0xfffff000
324 * to 0xffffffff to be used normally. Leaving Boot Page Translation
325 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
326 * unusable for normal operation but it does allow OSes to easily
327 * reset a processor core to put it back into U-Boot's spinloop.
328 */
Ed Swarthout853e2de2011-03-03 18:28:14 -0600329 clrbits_be32(&ccm->bstrar, LAW_EN);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500330#endif
Kumar Gala4d9190d2009-09-17 01:44:39 -0500331}
332#else
York Suna28496f2012-10-08 07:44:25 +0000333static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
Kumar Gala4d9190d2009-09-17 01:44:39 -0500334{
335 u32 up, cpu_up_mask, whoami;
York Sun2394a0f2012-10-08 07:44:30 +0000336 u32 *table = (u32 *)&__spin_table;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600337 volatile u32 bpcr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200338 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
339 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kim Phillips2ecbfeb2010-08-09 18:39:57 -0500340 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600341 u32 devdisr;
342 int timeout = 10;
343
344 whoami = in_be32(&pic->whoami);
345 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
346
347 /* disable time base at the platform */
348 devdisr = in_be32(&gur->devdisr);
349 if (whoami)
350 devdisr |= MPC85xx_DEVDISR_TB0;
351 else
352 devdisr |= MPC85xx_DEVDISR_TB1;
353 out_be32(&gur->devdisr, devdisr);
354
355 /* release the hounds */
Poonam Aggrwal4baef822009-07-31 12:08:14 +0530356 up = ((1 << cpu_numcores()) - 1);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600357 bpcr = in_be32(&ecm->eebpcr);
358 bpcr |= (up << 24);
359 out_be32(&ecm->eebpcr, bpcr);
360 asm("sync; isync; msync");
361
362 cpu_up_mask = 1 << whoami;
363 /* wait for everyone */
364 while (timeout) {
365 int i;
Poonam Aggrwal4baef822009-07-31 12:08:14 +0530366 for (i = 0; i < cpu_numcores(); i++) {
Kumar Gala615f14d2008-04-09 04:20:57 -0500367 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600368 cpu_up_mask |= (1 << i);
369 };
370
371 if ((cpu_up_mask & up) == up)
372 break;
373
374 udelay(100);
375 timeout--;
376 }
377
Kumar Gala615f14d2008-04-09 04:20:57 -0500378 if (timeout == 0)
379 printf("CPU up timeout. CPU up mask is %x should be %x\n",
380 cpu_up_mask, up);
381
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600382 /* enable time base at the platform */
383 if (whoami)
384 devdisr |= MPC85xx_DEVDISR_TB1;
385 else
386 devdisr |= MPC85xx_DEVDISR_TB0;
387 out_be32(&gur->devdisr, devdisr);
Kumar Gala6c5025e2011-03-13 10:55:53 -0500388
389 /* readback to sync write */
390 in_be32(&gur->devdisr);
391
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600392 mtspr(SPRN_TBWU, 0);
393 mtspr(SPRN_TBWL, 0);
394
395 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
396 out_be32(&gur->devdisr, devdisr);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500397
398#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
399 /*
400 * Disabling Boot Page Translation allows the memory region 0xfffff000
401 * to 0xffffffff to be used normally. Leaving Boot Page Translation
402 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
403 * unusable for normal operation but it does allow OSes to easily
404 * reset a processor core to put it back into U-Boot's spinloop.
405 */
406 clrbits_be32(&ecm->bptr, 0x80000000);
407#endif
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600408}
Kumar Gala4d9190d2009-09-17 01:44:39 -0500409#endif
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600410
Kumar Gala5769ded2008-03-26 08:53:53 -0500411void cpu_mp_lmb_reserve(struct lmb *lmb)
412{
York Suna28496f2012-10-08 07:44:25 +0000413 u32 bootpg = determine_mp_bootpg(NULL);
Kumar Gala5769ded2008-03-26 08:53:53 -0500414
415 lmb_reserve(lmb, bootpg, 4096);
416}
417
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600418void setup_mp(void)
419{
York Sun2394a0f2012-10-08 07:44:30 +0000420 extern u32 __secondary_start_page;
421 extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page;
York Suna28496f2012-10-08 07:44:25 +0000422
York Sun2394a0f2012-10-08 07:44:30 +0000423 int i;
424 ulong fixup = (u32)&__secondary_start_page;
York Suna28496f2012-10-08 07:44:25 +0000425 u32 bootpg, bootpg_map, pagesize;
426
427 bootpg = determine_mp_bootpg(&pagesize);
428
429 /*
430 * pagesize is only 4K or 8K
431 * we only use the last 4K of boot page
432 * bootpg_map saves the address for the boot page
433 * 8K is used for the workaround of 3-way DDR interleaving
434 */
435
436 bootpg_map = bootpg;
437
438 if (pagesize == 8192)
439 bootpg += 4096; /* use 2nd half */
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600440
Aaron Sierraec8863b2010-09-30 12:22:16 -0500441 /* Some OSes expect secondary cores to be held in reset */
442 if (hold_cores_in_reset(0))
443 return;
444
York Sun2394a0f2012-10-08 07:44:30 +0000445 /*
446 * Store the bootpg's cache-able half address for use by secondary
447 * CPU cores to continue to boot
448 */
449 __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
450
451 /* Store spin table's physical address for use by secondary cores */
452 __spin_table_addr = (u32)get_spin_phys_addr();
453
454 /* flush bootpg it before copying invalidate any staled cacheline */
455 flush_cache(bootpg, 4096);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500456
Kumar Gala8399e122009-09-03 08:41:31 -0500457 /* look for the tlb covering the reset page, there better be one */
York Sun2394a0f2012-10-08 07:44:30 +0000458 i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600459
Kumar Gala8399e122009-09-03 08:41:31 -0500460 /* we found a match */
461 if (i != -1) {
462 /* map reset page to bootpg so we can copy code there */
463 disable_tlb(i);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500464
Peter Tyser7feaacb2009-10-23 15:55:47 -0500465 set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
Kumar Gala4756ffa2009-11-17 20:21:20 -0600466 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
Kumar Gala8399e122009-09-03 08:41:31 -0500467 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
468
Peter Tyser7feaacb2009-10-23 15:55:47 -0500469 memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
470
York Suna28496f2012-10-08 07:44:25 +0000471 plat_mp_up(bootpg_map, pagesize);
Kumar Gala8399e122009-09-03 08:41:31 -0500472 } else {
473 puts("WARNING: No reset page TLB. "
474 "Skipping secondary core setup\n");
475 }
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600476}