blob: 84eb8b466b71affcd17e236231306022dcd1c743 [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>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -060010#include <asm/global_data.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060011#include <asm/processor.h>
Simon Glass7b51b572019-08-01 09:46:52 -060012#include <env.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060013#include <ioports.h>
Kumar Galadd6c9102008-03-26 08:53:53 -050014#include <lmb.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060015#include <asm/io.h>
Kumar Galac7259082009-09-03 08:41:31 -050016#include <asm/mmu.h>
Kumar Gala39a7e7f2009-09-17 01:44:39 -050017#include <asm/fsl_law.h>
York Sun5614e712013-09-30 09:22:09 -070018#include <fsl_ddr_sdram.h>
Simon Glassc05ed002020-05-10 11:40:11 -060019#include <linux/delay.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060020#include "mp.h"
21
22DECLARE_GLOBAL_DATA_PTR;
York Suneb539412012-10-08 07:44:25 +000023u32 fsl_ddr_get_intl3r(void);
Kumar Galaec2b74f2008-01-17 16:48:33 -060024
York Sunffd06e02012-10-08 07:44:30 +000025extern u32 __spin_table[];
26
Kumar Galaec2b74f2008-01-17 16:48:33 -060027u32 get_my_id()
28{
29 return mfspr(SPRN_PIR);
30}
31
Aaron Sierra9d64c6b2010-09-30 12:22:16 -050032/*
33 * Determine if U-Boot should keep secondary cores in reset, or let them out
34 * of reset and hold them in a spinloop
35 */
36int hold_cores_in_reset(int verbose)
37{
Robert P. J. Day62a3b7d2016-07-15 13:44:45 -040038 /* Default to no, overridden by 'y', 'yes', 'Y', 'Yes', or '1' */
Simon Glassbfebc8c2017-08-03 12:22:13 -060039 if (env_get_yesno("mp_holdoff") == 1) {
Aaron Sierra9d64c6b2010-09-30 12:22:16 -050040 if (verbose) {
41 puts("Secondary cores are being held in reset.\n");
42 puts("See 'mp_holdoff' environment variable\n");
43 }
44
45 return 1;
46 }
47
48 return 0;
49}
50
Michal Simek20b016a2018-06-13 08:56:31 +020051int cpu_reset(u32 nr)
Kumar Galaec2b74f2008-01-17 16:48:33 -060052{
Kim Phillips680c6132010-08-09 18:39:57 -050053 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Galaec2b74f2008-01-17 16:48:33 -060054 out_be32(&pic->pir, 1 << nr);
Kumar Galac840d262009-03-31 23:11:05 -050055 /* the dummy read works around an errata on early 85xx MP PICs */
Kumar Galaec2b74f2008-01-17 16:48:33 -060056 (void)in_be32(&pic->pir);
57 out_be32(&pic->pir, 0x0);
58
59 return 0;
60}
61
Michal Simek20b016a2018-06-13 08:56:31 +020062int cpu_status(u32 nr)
Kumar Galaec2b74f2008-01-17 16:48:33 -060063{
64 u32 *table, id = get_my_id();
65
Aaron Sierra9d64c6b2010-09-30 12:22:16 -050066 if (hold_cores_in_reset(1))
67 return 0;
68
Kumar Galaec2b74f2008-01-17 16:48:33 -060069 if (nr == id) {
York Sunffd06e02012-10-08 07:44:30 +000070 table = (u32 *)&__spin_table;
Kumar Gala348753d2008-07-14 14:03:02 -050071 printf("table base @ 0x%p\n", table);
York Sun0c9ab432013-03-25 07:40:00 +000072 } else if (is_core_disabled(nr)) {
73 puts("Disabled\n");
Kumar Galaec2b74f2008-01-17 16:48:33 -060074 } else {
York Sunffd06e02012-10-08 07:44:30 +000075 table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
Kumar Galaec2b74f2008-01-17 16:48:33 -060076 printf("Running on cpu %d\n", id);
77 printf("\n");
Kumar Gala348753d2008-07-14 14:03:02 -050078 printf("table @ 0x%p\n", table);
Kumar Gala79679d82008-03-26 08:34:25 -050079 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
Kumar Gala79679d82008-03-26 08:34:25 -050080 printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
York Sun3f0997b2012-10-08 07:44:29 +000081 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
Kumar Galaec2b74f2008-01-17 16:48:33 -060082 }
83
84 return 0;
85}
86
Kumar Galaa9c3ac72010-01-12 12:56:05 -060087#ifdef CONFIG_FSL_CORENET
Michal Simek20b016a2018-06-13 08:56:31 +020088int cpu_disable(u32 nr)
Kumar Gala4194b362010-01-12 11:42:43 -060089{
Kumar Galaa9c3ac72010-01-12 12:56:05 -060090 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
91
92 setbits_be32(&gur->coredisrl, 1 << nr);
93
94 return 0;
Kumar Gala4194b362010-01-12 11:42:43 -060095}
Kumar Gala8f3a7fa2010-06-09 22:33:53 -050096
97int is_core_disabled(int nr) {
98 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
99 u32 coredisrl = in_be32(&gur->coredisrl);
100
101 return (coredisrl & (1 << nr));
102}
Kumar Galaa9c3ac72010-01-12 12:56:05 -0600103#else
Michal Simek20b016a2018-06-13 08:56:31 +0200104int cpu_disable(u32 nr)
Kumar Galaa9c3ac72010-01-12 12:56:05 -0600105{
106 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
107
108 switch (nr) {
109 case 0:
110 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0);
111 break;
112 case 1:
113 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1);
114 break;
115 default:
116 printf("Invalid cpu number for disable %d\n", nr);
117 return 1;
118 }
119
120 return 0;
121}
Kumar Gala8f3a7fa2010-06-09 22:33:53 -0500122
123int is_core_disabled(int nr) {
124 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
125 u32 devdisr = in_be32(&gur->devdisr);
126
127 switch (nr) {
128 case 0:
129 return (devdisr & MPC85xx_DEVDISR_CPU0);
130 case 1:
131 return (devdisr & MPC85xx_DEVDISR_CPU1);
132 default:
133 printf("Invalid cpu number for disable %d\n", nr);
134 }
135
136 return 0;
137}
Kumar Galaa9c3ac72010-01-12 12:56:05 -0600138#endif
Kumar Gala4194b362010-01-12 11:42:43 -0600139
Kumar Gala79679d82008-03-26 08:34:25 -0500140static u8 boot_entry_map[4] = {
141 0,
142 BOOT_ENTRY_PIR,
143 BOOT_ENTRY_R3_LOWER,
Kumar Gala79679d82008-03-26 08:34:25 -0500144};
145
Simon Glass09140112020-05-10 11:40:03 -0600146int cpu_release(u32 nr, int argc, char *const argv[])
Kumar Galaec2b74f2008-01-17 16:48:33 -0600147{
York Sunffd06e02012-10-08 07:44:30 +0000148 u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
Kumar Gala79679d82008-03-26 08:34:25 -0500149 u64 boot_addr;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600150
Aaron Sierra9d64c6b2010-09-30 12:22:16 -0500151 if (hold_cores_in_reset(1))
152 return 0;
153
Kumar Galaec2b74f2008-01-17 16:48:33 -0600154 if (nr == get_my_id()) {
155 printf("Invalid to release the boot core.\n\n");
156 return 1;
157 }
158
Kumar Gala79679d82008-03-26 08:34:25 -0500159 if (argc != 4) {
Kumar Galaec2b74f2008-01-17 16:48:33 -0600160 printf("Invalid number of arguments to release.\n\n");
161 return 1;
162 }
163
Kumar Gala79679d82008-03-26 08:34:25 -0500164 boot_addr = simple_strtoull(argv[0], NULL, 16);
Kumar Gala79679d82008-03-26 08:34:25 -0500165
York Sun3f0997b2012-10-08 07:44:29 +0000166 /* handle pir, r3 */
167 for (i = 1; i < 3; i++) {
Kumar Galaec2b74f2008-01-17 16:48:33 -0600168 if (argv[i][0] != '-') {
Kumar Gala79679d82008-03-26 08:34:25 -0500169 u8 entry = boot_entry_map[i];
Simon Glass7e5f4602021-07-24 09:03:29 -0600170 val = hextoul(argv[i], NULL);
Kumar Gala79679d82008-03-26 08:34:25 -0500171 table[entry] = val;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600172 }
173 }
174
Kumar Gala79679d82008-03-26 08:34:25 -0500175 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
Kumar Galacf6cc012008-04-28 02:24:04 -0500176
177 /* ensure all table updates complete before final address write */
178 eieio();
179
Kumar Gala79679d82008-03-26 08:34:25 -0500180 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600181
182 return 0;
183}
184
York Suneb539412012-10-08 07:44:25 +0000185u32 determine_mp_bootpg(unsigned int *pagesize)
Kumar Galac840d262009-03-31 23:11:05 -0500186{
York Suneb539412012-10-08 07:44:25 +0000187 u32 bootpg;
188#ifdef CONFIG_SYS_FSL_ERRATUM_A004468
189 u32 svr = get_svr();
190 u32 granule_size, check;
191 struct law_entry e;
192#endif
193
York Sunffd06e02012-10-08 07:44:30 +0000194
195 /* use last 4K of mapped memory */
196 bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
197 CONFIG_MAX_MEM_MAPPED : gd->ram_size) +
198 CONFIG_SYS_SDRAM_BASE - 4096;
York Suneb539412012-10-08 07:44:25 +0000199 if (pagesize)
200 *pagesize = 4096;
Kumar Galac840d262009-03-31 23:11:05 -0500201
York Suneb539412012-10-08 07:44:25 +0000202#ifdef CONFIG_SYS_FSL_ERRATUM_A004468
203/*
204 * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
205 * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
206 * the way boot page chosen in u-boot avoids hitting this erratum. So only
207 * thw workaround for 3-way interleaving is needed.
208 *
209 * To make sure boot page translation works with 3-Way DDR interleaving
210 * enforce a check for the following constrains
211 * 8K granule size requires BRSIZE=8K and
212 * bootpg >> log2(BRSIZE) %3 == 1
213 * 4K and 1K granule size requires BRSIZE=4K and
214 * bootpg >> log2(BRSIZE) %3 == 0
215 */
216 if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) {
217 e = find_law(bootpg);
218 switch (e.trgt_id) {
219 case LAW_TRGT_IF_DDR_INTLV_123:
220 granule_size = fsl_ddr_get_intl3r() & 0x1f;
221 if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) {
222 if (pagesize)
223 *pagesize = 8192;
224 bootpg &= 0xffffe000; /* align to 8KB */
225 check = bootpg >> 13;
226 while ((check % 3) != 1)
227 check--;
228 bootpg = check << 13;
229 debug("Boot page (8K) at 0x%08x\n", bootpg);
230 break;
231 } else {
232 bootpg &= 0xfffff000; /* align to 4KB */
233 check = bootpg >> 12;
234 while ((check % 3) != 0)
235 check--;
236 bootpg = check << 12;
237 debug("Boot page (4K) at 0x%08x\n", bootpg);
238 }
239 break;
240 default:
241 break;
242 }
243 }
244#endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
245
246 return bootpg;
Kumar Galac840d262009-03-31 23:11:05 -0500247}
248
York Sunffd06e02012-10-08 07:44:30 +0000249phys_addr_t get_spin_phys_addr(void)
Kumar Galaec2b74f2008-01-17 16:48:33 -0600250{
York Sunffd06e02012-10-08 07:44:30 +0000251 return virt_to_phys(&__spin_table);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600252}
253
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500254#ifdef CONFIG_FSL_CORENET
York Suneb539412012-10-08 07:44:25 +0000255static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500256{
York Suneb539412012-10-08 07:44:25 +0000257 u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
York Sunffd06e02012-10-08 07:44:30 +0000258 u32 *table = (u32 *)&__spin_table;
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500259 volatile ccsr_gur_t *gur;
260 volatile ccsr_local_t *ccm;
261 volatile ccsr_rcpm_t *rcpm;
262 volatile ccsr_pic_t *pic;
263 int timeout = 10;
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500264 u32 mask = cpu_mask();
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500265 struct law_entry e;
266
267 gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
268 ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
269 rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
Kim Phillips680c6132010-08-09 18:39:57 -0500270 pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500271
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500272 whoami = in_be32(&pic->whoami);
273 cpu_up_mask = 1 << whoami;
274 out_be32(&ccm->bstrl, bootpg);
275
276 e = find_law(bootpg);
York Suneb539412012-10-08 07:44:25 +0000277 /* pagesize is only 4K or 8K */
278 if (pagesize == 8192)
279 brsize = LAW_SIZE_8K;
280 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
281 debug("BRSIZE is 0x%x\n", brsize);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500282
Dave Liuf5ecc6e2009-11-17 20:01:24 -0600283 /* readback to sync write */
284 in_be32(&ccm->bstrar);
285
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500286 /* disable time base at the platform */
287 out_be32(&rcpm->ctbenrl, cpu_up_mask);
288
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500289 out_be32(&gur->brrl, mask);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500290
291 /* wait for everyone */
292 while (timeout) {
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500293 unsigned int i, cpu, nr_cpus = cpu_numcores();
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500294
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500295 for_each_cpu(i, cpu, nr_cpus, mask) {
296 if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
297 cpu_up_mask |= (1 << cpu);
298 }
299
300 if ((cpu_up_mask & mask) == mask)
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500301 break;
302
303 udelay(100);
304 timeout--;
305 }
306
307 if (timeout == 0)
308 printf("CPU up timeout. CPU up mask is %x should be %x\n",
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500309 cpu_up_mask, mask);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500310
311 /* enable time base at the platform */
312 out_be32(&rcpm->ctbenrl, 0);
Kumar Gala7afc45a2011-03-13 10:55:53 -0500313
314 /* readback to sync write */
315 in_be32(&rcpm->ctbenrl);
316
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500317 mtspr(SPRN_TBWU, 0);
318 mtspr(SPRN_TBWL, 0);
Kumar Gala7afc45a2011-03-13 10:55:53 -0500319
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500320 out_be32(&rcpm->ctbenrl, mask);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500321
322#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
323 /*
324 * Disabling Boot Page Translation allows the memory region 0xfffff000
325 * to 0xffffffff to be used normally. Leaving Boot Page Translation
326 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
327 * unusable for normal operation but it does allow OSes to easily
328 * reset a processor core to put it back into U-Boot's spinloop.
329 */
Ed Swarthoute81241a2011-03-03 18:28:14 -0600330 clrbits_be32(&ccm->bstrar, LAW_EN);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500331#endif
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500332}
333#else
York Suneb539412012-10-08 07:44:25 +0000334static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
Kumar Galaec2b74f2008-01-17 16:48:33 -0600335{
336 u32 up, cpu_up_mask, whoami;
York Sunffd06e02012-10-08 07:44:30 +0000337 u32 *table = (u32 *)&__spin_table;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600338 volatile u32 bpcr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200339 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
340 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kim Phillips680c6132010-08-09 18:39:57 -0500341 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600342 u32 devdisr;
343 int timeout = 10;
344
345 whoami = in_be32(&pic->whoami);
346 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
347
348 /* disable time base at the platform */
349 devdisr = in_be32(&gur->devdisr);
350 if (whoami)
351 devdisr |= MPC85xx_DEVDISR_TB0;
352 else
353 devdisr |= MPC85xx_DEVDISR_TB1;
354 out_be32(&gur->devdisr, devdisr);
355
356 /* release the hounds */
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530357 up = ((1 << cpu_numcores()) - 1);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600358 bpcr = in_be32(&ecm->eebpcr);
359 bpcr |= (up << 24);
360 out_be32(&ecm->eebpcr, bpcr);
361 asm("sync; isync; msync");
362
363 cpu_up_mask = 1 << whoami;
364 /* wait for everyone */
365 while (timeout) {
366 int i;
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530367 for (i = 0; i < cpu_numcores(); i++) {
Kumar Gala97b3ecb2008-04-09 04:20:57 -0500368 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
Kumar Galaec2b74f2008-01-17 16:48:33 -0600369 cpu_up_mask |= (1 << i);
370 };
371
372 if ((cpu_up_mask & up) == up)
373 break;
374
375 udelay(100);
376 timeout--;
377 }
378
Kumar Gala97b3ecb2008-04-09 04:20:57 -0500379 if (timeout == 0)
380 printf("CPU up timeout. CPU up mask is %x should be %x\n",
381 cpu_up_mask, up);
382
Kumar Galaec2b74f2008-01-17 16:48:33 -0600383 /* enable time base at the platform */
384 if (whoami)
385 devdisr |= MPC85xx_DEVDISR_TB1;
386 else
387 devdisr |= MPC85xx_DEVDISR_TB0;
388 out_be32(&gur->devdisr, devdisr);
Kumar Gala7afc45a2011-03-13 10:55:53 -0500389
390 /* readback to sync write */
391 in_be32(&gur->devdisr);
392
Kumar Galaec2b74f2008-01-17 16:48:33 -0600393 mtspr(SPRN_TBWU, 0);
394 mtspr(SPRN_TBWL, 0);
395
396 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
397 out_be32(&gur->devdisr, devdisr);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500398
399#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
400 /*
401 * Disabling Boot Page Translation allows the memory region 0xfffff000
402 * to 0xffffffff to be used normally. Leaving Boot Page Translation
403 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
404 * unusable for normal operation but it does allow OSes to easily
405 * reset a processor core to put it back into U-Boot's spinloop.
406 */
407 clrbits_be32(&ecm->bptr, 0x80000000);
408#endif
Kumar Galaec2b74f2008-01-17 16:48:33 -0600409}
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500410#endif
Kumar Galaec2b74f2008-01-17 16:48:33 -0600411
Kumar Galadd6c9102008-03-26 08:53:53 -0500412void cpu_mp_lmb_reserve(struct lmb *lmb)
413{
York Suneb539412012-10-08 07:44:25 +0000414 u32 bootpg = determine_mp_bootpg(NULL);
Kumar Galadd6c9102008-03-26 08:53:53 -0500415
416 lmb_reserve(lmb, bootpg, 4096);
417}
418
Kumar Galaec2b74f2008-01-17 16:48:33 -0600419void setup_mp(void)
420{
York Sunffd06e02012-10-08 07:44:30 +0000421 extern u32 __secondary_start_page;
422 extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page;
York Suneb539412012-10-08 07:44:25 +0000423
York Sunffd06e02012-10-08 07:44:30 +0000424 int i;
425 ulong fixup = (u32)&__secondary_start_page;
York Suneb539412012-10-08 07:44:25 +0000426 u32 bootpg, bootpg_map, pagesize;
427
428 bootpg = determine_mp_bootpg(&pagesize);
429
430 /*
431 * pagesize is only 4K or 8K
432 * we only use the last 4K of boot page
433 * bootpg_map saves the address for the boot page
434 * 8K is used for the workaround of 3-way DDR interleaving
435 */
436
437 bootpg_map = bootpg;
438
439 if (pagesize == 8192)
440 bootpg += 4096; /* use 2nd half */
Kumar Galaec2b74f2008-01-17 16:48:33 -0600441
Aaron Sierra9d64c6b2010-09-30 12:22:16 -0500442 /* Some OSes expect secondary cores to be held in reset */
443 if (hold_cores_in_reset(0))
444 return;
445
York Sunffd06e02012-10-08 07:44:30 +0000446 /*
447 * Store the bootpg's cache-able half address for use by secondary
448 * CPU cores to continue to boot
449 */
450 __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
451
452 /* Store spin table's physical address for use by secondary cores */
453 __spin_table_addr = (u32)get_spin_phys_addr();
454
455 /* flush bootpg it before copying invalidate any staled cacheline */
456 flush_cache(bootpg, 4096);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500457
Kumar Galac7259082009-09-03 08:41:31 -0500458 /* look for the tlb covering the reset page, there better be one */
Tom Rini0b5870c2022-03-11 09:12:03 -0500459 i = find_tlb_idx((void *)BPTR_VIRT_ADDR, 1);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600460
Kumar Galac7259082009-09-03 08:41:31 -0500461 /* we found a match */
462 if (i != -1) {
463 /* map reset page to bootpg so we can copy code there */
464 disable_tlb(i);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500465
Tom Rini0b5870c2022-03-11 09:12:03 -0500466 set_tlb(1, BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
Kumar Galaabc76eb2009-11-17 20:21:20 -0600467 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
Kumar Galac7259082009-09-03 08:41:31 -0500468 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
469
Tom Rini0b5870c2022-03-11 09:12:03 -0500470 memcpy((void *)BPTR_VIRT_ADDR, (void *)fixup, 4096);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500471
York Suneb539412012-10-08 07:44:25 +0000472 plat_mp_up(bootpg_map, pagesize);
Kumar Galac7259082009-09-03 08:41:31 -0500473 } else {
474 puts("WARNING: No reset page TLB. "
475 "Skipping secondary core setup\n");
476 }
Kumar Galaec2b74f2008-01-17 16:48:33 -0600477}