183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a47a12beSStefan Roese /*
3e81241afSEd Swarthout * Copyright 2008-2011 Freescale Semiconductor, Inc.
4a47a12beSStefan Roese */
5a47a12beSStefan Roese
6a47a12beSStefan Roese #include <common.h>
7a47a12beSStefan Roese #include <asm/processor.h>
8a47a12beSStefan Roese #include <ioports.h>
9a47a12beSStefan Roese #include <lmb.h>
10a47a12beSStefan Roese #include <asm/io.h>
11a47a12beSStefan Roese #include <asm/mmu.h>
12a47a12beSStefan Roese #include <asm/fsl_law.h>
135614e71bSYork Sun #include <fsl_ddr_sdram.h>
14a47a12beSStefan Roese #include "mp.h"
15a47a12beSStefan Roese
16a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
17eb539412SYork Sun u32 fsl_ddr_get_intl3r(void);
18a47a12beSStefan Roese
19ffd06e02SYork Sun extern u32 __spin_table[];
20ffd06e02SYork Sun
get_my_id()21a47a12beSStefan Roese u32 get_my_id()
22a47a12beSStefan Roese {
23a47a12beSStefan Roese return mfspr(SPRN_PIR);
24a47a12beSStefan Roese }
25a47a12beSStefan Roese
269d64c6bbSAaron Sierra /*
279d64c6bbSAaron Sierra * Determine if U-Boot should keep secondary cores in reset, or let them out
289d64c6bbSAaron Sierra * of reset and hold them in a spinloop
299d64c6bbSAaron Sierra */
hold_cores_in_reset(int verbose)309d64c6bbSAaron Sierra int hold_cores_in_reset(int verbose)
319d64c6bbSAaron Sierra {
3262a3b7ddSRobert P. J. Day /* Default to no, overridden by 'y', 'yes', 'Y', 'Yes', or '1' */
33bfebc8c9SSimon Glass if (env_get_yesno("mp_holdoff") == 1) {
349d64c6bbSAaron Sierra if (verbose) {
359d64c6bbSAaron Sierra puts("Secondary cores are being held in reset.\n");
369d64c6bbSAaron Sierra puts("See 'mp_holdoff' environment variable\n");
379d64c6bbSAaron Sierra }
389d64c6bbSAaron Sierra
399d64c6bbSAaron Sierra return 1;
409d64c6bbSAaron Sierra }
419d64c6bbSAaron Sierra
429d64c6bbSAaron Sierra return 0;
439d64c6bbSAaron Sierra }
449d64c6bbSAaron Sierra
cpu_reset(u32 nr)45*20b016a3SMichal Simek int cpu_reset(u32 nr)
46a47a12beSStefan Roese {
47680c613aSKim Phillips volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
48a47a12beSStefan Roese out_be32(&pic->pir, 1 << nr);
49a47a12beSStefan Roese /* the dummy read works around an errata on early 85xx MP PICs */
50a47a12beSStefan Roese (void)in_be32(&pic->pir);
51a47a12beSStefan Roese out_be32(&pic->pir, 0x0);
52a47a12beSStefan Roese
53a47a12beSStefan Roese return 0;
54a47a12beSStefan Roese }
55a47a12beSStefan Roese
cpu_status(u32 nr)56*20b016a3SMichal Simek int cpu_status(u32 nr)
57a47a12beSStefan Roese {
58a47a12beSStefan Roese u32 *table, id = get_my_id();
59a47a12beSStefan Roese
609d64c6bbSAaron Sierra if (hold_cores_in_reset(1))
619d64c6bbSAaron Sierra return 0;
629d64c6bbSAaron Sierra
63a47a12beSStefan Roese if (nr == id) {
64ffd06e02SYork Sun table = (u32 *)&__spin_table;
65a47a12beSStefan Roese printf("table base @ 0x%p\n", table);
660c9ab437SYork Sun } else if (is_core_disabled(nr)) {
670c9ab437SYork Sun puts("Disabled\n");
68a47a12beSStefan Roese } else {
69ffd06e02SYork Sun table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
70a47a12beSStefan Roese printf("Running on cpu %d\n", id);
71a47a12beSStefan Roese printf("\n");
72a47a12beSStefan Roese printf("table @ 0x%p\n", table);
73a47a12beSStefan Roese printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
74a47a12beSStefan Roese printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
753f0997b3SYork Sun printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
76a47a12beSStefan Roese }
77a47a12beSStefan Roese
78a47a12beSStefan Roese return 0;
79a47a12beSStefan Roese }
80a47a12beSStefan Roese
81a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
cpu_disable(u32 nr)82*20b016a3SMichal Simek int cpu_disable(u32 nr)
83a47a12beSStefan Roese {
84a47a12beSStefan Roese volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
85a47a12beSStefan Roese
86a47a12beSStefan Roese setbits_be32(&gur->coredisrl, 1 << nr);
87a47a12beSStefan Roese
88a47a12beSStefan Roese return 0;
89a47a12beSStefan Roese }
908f3a7fa4SKumar Gala
is_core_disabled(int nr)918f3a7fa4SKumar Gala int is_core_disabled(int nr) {
928f3a7fa4SKumar Gala ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
938f3a7fa4SKumar Gala u32 coredisrl = in_be32(&gur->coredisrl);
948f3a7fa4SKumar Gala
958f3a7fa4SKumar Gala return (coredisrl & (1 << nr));
968f3a7fa4SKumar Gala }
97a47a12beSStefan Roese #else
cpu_disable(u32 nr)98*20b016a3SMichal Simek int cpu_disable(u32 nr)
99a47a12beSStefan Roese {
100a47a12beSStefan Roese volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
101a47a12beSStefan Roese
102a47a12beSStefan Roese switch (nr) {
103a47a12beSStefan Roese case 0:
104a47a12beSStefan Roese setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0);
105a47a12beSStefan Roese break;
106a47a12beSStefan Roese case 1:
107a47a12beSStefan Roese setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1);
108a47a12beSStefan Roese break;
109a47a12beSStefan Roese default:
110a47a12beSStefan Roese printf("Invalid cpu number for disable %d\n", nr);
111a47a12beSStefan Roese return 1;
112a47a12beSStefan Roese }
113a47a12beSStefan Roese
114a47a12beSStefan Roese return 0;
115a47a12beSStefan Roese }
1168f3a7fa4SKumar Gala
is_core_disabled(int nr)1178f3a7fa4SKumar Gala int is_core_disabled(int nr) {
1188f3a7fa4SKumar Gala ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
1198f3a7fa4SKumar Gala u32 devdisr = in_be32(&gur->devdisr);
1208f3a7fa4SKumar Gala
1218f3a7fa4SKumar Gala switch (nr) {
1228f3a7fa4SKumar Gala case 0:
1238f3a7fa4SKumar Gala return (devdisr & MPC85xx_DEVDISR_CPU0);
1248f3a7fa4SKumar Gala case 1:
1258f3a7fa4SKumar Gala return (devdisr & MPC85xx_DEVDISR_CPU1);
1268f3a7fa4SKumar Gala default:
1278f3a7fa4SKumar Gala printf("Invalid cpu number for disable %d\n", nr);
1288f3a7fa4SKumar Gala }
1298f3a7fa4SKumar Gala
1308f3a7fa4SKumar Gala return 0;
1318f3a7fa4SKumar Gala }
132a47a12beSStefan Roese #endif
133a47a12beSStefan Roese
134a47a12beSStefan Roese static u8 boot_entry_map[4] = {
135a47a12beSStefan Roese 0,
136a47a12beSStefan Roese BOOT_ENTRY_PIR,
137a47a12beSStefan Roese BOOT_ENTRY_R3_LOWER,
138a47a12beSStefan Roese };
139a47a12beSStefan Roese
cpu_release(u32 nr,int argc,char * const argv[])140*20b016a3SMichal Simek int cpu_release(u32 nr, int argc, char * const argv[])
141a47a12beSStefan Roese {
142ffd06e02SYork Sun u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
143a47a12beSStefan Roese u64 boot_addr;
144a47a12beSStefan Roese
1459d64c6bbSAaron Sierra if (hold_cores_in_reset(1))
1469d64c6bbSAaron Sierra return 0;
1479d64c6bbSAaron Sierra
148a47a12beSStefan Roese if (nr == get_my_id()) {
149a47a12beSStefan Roese printf("Invalid to release the boot core.\n\n");
150a47a12beSStefan Roese return 1;
151a47a12beSStefan Roese }
152a47a12beSStefan Roese
153a47a12beSStefan Roese if (argc != 4) {
154a47a12beSStefan Roese printf("Invalid number of arguments to release.\n\n");
155a47a12beSStefan Roese return 1;
156a47a12beSStefan Roese }
157a47a12beSStefan Roese
158a47a12beSStefan Roese boot_addr = simple_strtoull(argv[0], NULL, 16);
159a47a12beSStefan Roese
1603f0997b3SYork Sun /* handle pir, r3 */
1613f0997b3SYork Sun for (i = 1; i < 3; i++) {
162a47a12beSStefan Roese if (argv[i][0] != '-') {
163a47a12beSStefan Roese u8 entry = boot_entry_map[i];
164a47a12beSStefan Roese val = simple_strtoul(argv[i], NULL, 16);
165a47a12beSStefan Roese table[entry] = val;
166a47a12beSStefan Roese }
167a47a12beSStefan Roese }
168a47a12beSStefan Roese
169a47a12beSStefan Roese table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
170a47a12beSStefan Roese
171a47a12beSStefan Roese /* ensure all table updates complete before final address write */
172a47a12beSStefan Roese eieio();
173a47a12beSStefan Roese
174a47a12beSStefan Roese table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
175a47a12beSStefan Roese
176a47a12beSStefan Roese return 0;
177a47a12beSStefan Roese }
178a47a12beSStefan Roese
determine_mp_bootpg(unsigned int * pagesize)179eb539412SYork Sun u32 determine_mp_bootpg(unsigned int *pagesize)
180a47a12beSStefan Roese {
181eb539412SYork Sun u32 bootpg;
182eb539412SYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
183eb539412SYork Sun u32 svr = get_svr();
184eb539412SYork Sun u32 granule_size, check;
185eb539412SYork Sun struct law_entry e;
186eb539412SYork Sun #endif
187eb539412SYork Sun
188ffd06e02SYork Sun
189ffd06e02SYork Sun /* use last 4K of mapped memory */
190ffd06e02SYork Sun bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
191ffd06e02SYork Sun CONFIG_MAX_MEM_MAPPED : gd->ram_size) +
192ffd06e02SYork Sun CONFIG_SYS_SDRAM_BASE - 4096;
193eb539412SYork Sun if (pagesize)
194eb539412SYork Sun *pagesize = 4096;
195a47a12beSStefan Roese
196eb539412SYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
197eb539412SYork Sun /*
198eb539412SYork Sun * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
199eb539412SYork Sun * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
200eb539412SYork Sun * the way boot page chosen in u-boot avoids hitting this erratum. So only
201eb539412SYork Sun * thw workaround for 3-way interleaving is needed.
202eb539412SYork Sun *
203eb539412SYork Sun * To make sure boot page translation works with 3-Way DDR interleaving
204eb539412SYork Sun * enforce a check for the following constrains
205eb539412SYork Sun * 8K granule size requires BRSIZE=8K and
206eb539412SYork Sun * bootpg >> log2(BRSIZE) %3 == 1
207eb539412SYork Sun * 4K and 1K granule size requires BRSIZE=4K and
208eb539412SYork Sun * bootpg >> log2(BRSIZE) %3 == 0
209eb539412SYork Sun */
210eb539412SYork Sun if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) {
211eb539412SYork Sun e = find_law(bootpg);
212eb539412SYork Sun switch (e.trgt_id) {
213eb539412SYork Sun case LAW_TRGT_IF_DDR_INTLV_123:
214eb539412SYork Sun granule_size = fsl_ddr_get_intl3r() & 0x1f;
215eb539412SYork Sun if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) {
216eb539412SYork Sun if (pagesize)
217eb539412SYork Sun *pagesize = 8192;
218eb539412SYork Sun bootpg &= 0xffffe000; /* align to 8KB */
219eb539412SYork Sun check = bootpg >> 13;
220eb539412SYork Sun while ((check % 3) != 1)
221eb539412SYork Sun check--;
222eb539412SYork Sun bootpg = check << 13;
223eb539412SYork Sun debug("Boot page (8K) at 0x%08x\n", bootpg);
224eb539412SYork Sun break;
225eb539412SYork Sun } else {
226eb539412SYork Sun bootpg &= 0xfffff000; /* align to 4KB */
227eb539412SYork Sun check = bootpg >> 12;
228eb539412SYork Sun while ((check % 3) != 0)
229eb539412SYork Sun check--;
230eb539412SYork Sun bootpg = check << 12;
231eb539412SYork Sun debug("Boot page (4K) at 0x%08x\n", bootpg);
232eb539412SYork Sun }
233eb539412SYork Sun break;
234eb539412SYork Sun default:
235eb539412SYork Sun break;
236eb539412SYork Sun }
237eb539412SYork Sun }
238eb539412SYork Sun #endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
239eb539412SYork Sun
240eb539412SYork Sun return bootpg;
241a47a12beSStefan Roese }
242a47a12beSStefan Roese
get_spin_phys_addr(void)243ffd06e02SYork Sun phys_addr_t get_spin_phys_addr(void)
244a47a12beSStefan Roese {
245ffd06e02SYork Sun return virt_to_phys(&__spin_table);
246a47a12beSStefan Roese }
247a47a12beSStefan Roese
248a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
plat_mp_up(unsigned long bootpg,unsigned int pagesize)249eb539412SYork Sun static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
250a47a12beSStefan Roese {
251eb539412SYork Sun u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
252ffd06e02SYork Sun u32 *table = (u32 *)&__spin_table;
253a47a12beSStefan Roese volatile ccsr_gur_t *gur;
254a47a12beSStefan Roese volatile ccsr_local_t *ccm;
255a47a12beSStefan Roese volatile ccsr_rcpm_t *rcpm;
256a47a12beSStefan Roese volatile ccsr_pic_t *pic;
257a47a12beSStefan Roese int timeout = 10;
258fbb9ecf7STimur Tabi u32 mask = cpu_mask();
259a47a12beSStefan Roese struct law_entry e;
260a47a12beSStefan Roese
261a47a12beSStefan Roese gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
262a47a12beSStefan Roese ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
263a47a12beSStefan Roese rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
264680c613aSKim Phillips pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
265a47a12beSStefan Roese
266a47a12beSStefan Roese whoami = in_be32(&pic->whoami);
267a47a12beSStefan Roese cpu_up_mask = 1 << whoami;
268a47a12beSStefan Roese out_be32(&ccm->bstrl, bootpg);
269a47a12beSStefan Roese
270a47a12beSStefan Roese e = find_law(bootpg);
271eb539412SYork Sun /* pagesize is only 4K or 8K */
272eb539412SYork Sun if (pagesize == 8192)
273eb539412SYork Sun brsize = LAW_SIZE_8K;
274eb539412SYork Sun out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
275eb539412SYork Sun debug("BRSIZE is 0x%x\n", brsize);
276a47a12beSStefan Roese
277a47a12beSStefan Roese /* readback to sync write */
278a47a12beSStefan Roese in_be32(&ccm->bstrar);
279a47a12beSStefan Roese
280a47a12beSStefan Roese /* disable time base at the platform */
281a47a12beSStefan Roese out_be32(&rcpm->ctbenrl, cpu_up_mask);
282a47a12beSStefan Roese
283fbb9ecf7STimur Tabi out_be32(&gur->brrl, mask);
284a47a12beSStefan Roese
285a47a12beSStefan Roese /* wait for everyone */
286a47a12beSStefan Roese while (timeout) {
287fbb9ecf7STimur Tabi unsigned int i, cpu, nr_cpus = cpu_numcores();
288a47a12beSStefan Roese
289fbb9ecf7STimur Tabi for_each_cpu(i, cpu, nr_cpus, mask) {
290fbb9ecf7STimur Tabi if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
291fbb9ecf7STimur Tabi cpu_up_mask |= (1 << cpu);
292fbb9ecf7STimur Tabi }
293fbb9ecf7STimur Tabi
294fbb9ecf7STimur Tabi if ((cpu_up_mask & mask) == mask)
295a47a12beSStefan Roese break;
296a47a12beSStefan Roese
297a47a12beSStefan Roese udelay(100);
298a47a12beSStefan Roese timeout--;
299a47a12beSStefan Roese }
300a47a12beSStefan Roese
301a47a12beSStefan Roese if (timeout == 0)
302a47a12beSStefan Roese printf("CPU up timeout. CPU up mask is %x should be %x\n",
303fbb9ecf7STimur Tabi cpu_up_mask, mask);
304a47a12beSStefan Roese
305a47a12beSStefan Roese /* enable time base at the platform */
306a47a12beSStefan Roese out_be32(&rcpm->ctbenrl, 0);
3077afc45adSKumar Gala
3087afc45adSKumar Gala /* readback to sync write */
3097afc45adSKumar Gala in_be32(&rcpm->ctbenrl);
3107afc45adSKumar Gala
311a47a12beSStefan Roese mtspr(SPRN_TBWU, 0);
312a47a12beSStefan Roese mtspr(SPRN_TBWL, 0);
3137afc45adSKumar Gala
314fbb9ecf7STimur Tabi out_be32(&rcpm->ctbenrl, mask);
315a47a12beSStefan Roese
316a47a12beSStefan Roese #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
317a47a12beSStefan Roese /*
318a47a12beSStefan Roese * Disabling Boot Page Translation allows the memory region 0xfffff000
319a47a12beSStefan Roese * to 0xffffffff to be used normally. Leaving Boot Page Translation
320a47a12beSStefan Roese * enabled remaps 0xfffff000 to SDRAM which makes that memory region
321a47a12beSStefan Roese * unusable for normal operation but it does allow OSes to easily
322a47a12beSStefan Roese * reset a processor core to put it back into U-Boot's spinloop.
323a47a12beSStefan Roese */
324e81241afSEd Swarthout clrbits_be32(&ccm->bstrar, LAW_EN);
325a47a12beSStefan Roese #endif
326a47a12beSStefan Roese }
327a47a12beSStefan Roese #else
plat_mp_up(unsigned long bootpg,unsigned int pagesize)328eb539412SYork Sun static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
329a47a12beSStefan Roese {
330a47a12beSStefan Roese u32 up, cpu_up_mask, whoami;
331ffd06e02SYork Sun u32 *table = (u32 *)&__spin_table;
332a47a12beSStefan Roese volatile u32 bpcr;
333a47a12beSStefan Roese volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
334a47a12beSStefan Roese volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
335680c613aSKim Phillips volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
336a47a12beSStefan Roese u32 devdisr;
337a47a12beSStefan Roese int timeout = 10;
338a47a12beSStefan Roese
339a47a12beSStefan Roese whoami = in_be32(&pic->whoami);
340a47a12beSStefan Roese out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
341a47a12beSStefan Roese
342a47a12beSStefan Roese /* disable time base at the platform */
343a47a12beSStefan Roese devdisr = in_be32(&gur->devdisr);
344a47a12beSStefan Roese if (whoami)
345a47a12beSStefan Roese devdisr |= MPC85xx_DEVDISR_TB0;
346a47a12beSStefan Roese else
347a47a12beSStefan Roese devdisr |= MPC85xx_DEVDISR_TB1;
348a47a12beSStefan Roese out_be32(&gur->devdisr, devdisr);
349a47a12beSStefan Roese
350a47a12beSStefan Roese /* release the hounds */
351a47a12beSStefan Roese up = ((1 << cpu_numcores()) - 1);
352a47a12beSStefan Roese bpcr = in_be32(&ecm->eebpcr);
353a47a12beSStefan Roese bpcr |= (up << 24);
354a47a12beSStefan Roese out_be32(&ecm->eebpcr, bpcr);
355a47a12beSStefan Roese asm("sync; isync; msync");
356a47a12beSStefan Roese
357a47a12beSStefan Roese cpu_up_mask = 1 << whoami;
358a47a12beSStefan Roese /* wait for everyone */
359a47a12beSStefan Roese while (timeout) {
360a47a12beSStefan Roese int i;
361a47a12beSStefan Roese for (i = 0; i < cpu_numcores(); i++) {
362a47a12beSStefan Roese if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
363a47a12beSStefan Roese cpu_up_mask |= (1 << i);
364a47a12beSStefan Roese };
365a47a12beSStefan Roese
366a47a12beSStefan Roese if ((cpu_up_mask & up) == up)
367a47a12beSStefan Roese break;
368a47a12beSStefan Roese
369a47a12beSStefan Roese udelay(100);
370a47a12beSStefan Roese timeout--;
371a47a12beSStefan Roese }
372a47a12beSStefan Roese
373a47a12beSStefan Roese if (timeout == 0)
374a47a12beSStefan Roese printf("CPU up timeout. CPU up mask is %x should be %x\n",
375a47a12beSStefan Roese cpu_up_mask, up);
376a47a12beSStefan Roese
377a47a12beSStefan Roese /* enable time base at the platform */
378a47a12beSStefan Roese if (whoami)
379a47a12beSStefan Roese devdisr |= MPC85xx_DEVDISR_TB1;
380a47a12beSStefan Roese else
381a47a12beSStefan Roese devdisr |= MPC85xx_DEVDISR_TB0;
382a47a12beSStefan Roese out_be32(&gur->devdisr, devdisr);
3837afc45adSKumar Gala
3847afc45adSKumar Gala /* readback to sync write */
3857afc45adSKumar Gala in_be32(&gur->devdisr);
3867afc45adSKumar Gala
387a47a12beSStefan Roese mtspr(SPRN_TBWU, 0);
388a47a12beSStefan Roese mtspr(SPRN_TBWL, 0);
389a47a12beSStefan Roese
390a47a12beSStefan Roese devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
391a47a12beSStefan Roese out_be32(&gur->devdisr, devdisr);
392a47a12beSStefan Roese
393a47a12beSStefan Roese #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
394a47a12beSStefan Roese /*
395a47a12beSStefan Roese * Disabling Boot Page Translation allows the memory region 0xfffff000
396a47a12beSStefan Roese * to 0xffffffff to be used normally. Leaving Boot Page Translation
397a47a12beSStefan Roese * enabled remaps 0xfffff000 to SDRAM which makes that memory region
398a47a12beSStefan Roese * unusable for normal operation but it does allow OSes to easily
399a47a12beSStefan Roese * reset a processor core to put it back into U-Boot's spinloop.
400a47a12beSStefan Roese */
401a47a12beSStefan Roese clrbits_be32(&ecm->bptr, 0x80000000);
402a47a12beSStefan Roese #endif
403a47a12beSStefan Roese }
404a47a12beSStefan Roese #endif
405a47a12beSStefan Roese
cpu_mp_lmb_reserve(struct lmb * lmb)406a47a12beSStefan Roese void cpu_mp_lmb_reserve(struct lmb *lmb)
407a47a12beSStefan Roese {
408eb539412SYork Sun u32 bootpg = determine_mp_bootpg(NULL);
409a47a12beSStefan Roese
410a47a12beSStefan Roese lmb_reserve(lmb, bootpg, 4096);
411a47a12beSStefan Roese }
412a47a12beSStefan Roese
setup_mp(void)413a47a12beSStefan Roese void setup_mp(void)
414a47a12beSStefan Roese {
415ffd06e02SYork Sun extern u32 __secondary_start_page;
416ffd06e02SYork Sun extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page;
417eb539412SYork Sun
418ffd06e02SYork Sun int i;
419ffd06e02SYork Sun ulong fixup = (u32)&__secondary_start_page;
420eb539412SYork Sun u32 bootpg, bootpg_map, pagesize;
421eb539412SYork Sun
422eb539412SYork Sun bootpg = determine_mp_bootpg(&pagesize);
423eb539412SYork Sun
424eb539412SYork Sun /*
425eb539412SYork Sun * pagesize is only 4K or 8K
426eb539412SYork Sun * we only use the last 4K of boot page
427eb539412SYork Sun * bootpg_map saves the address for the boot page
428eb539412SYork Sun * 8K is used for the workaround of 3-way DDR interleaving
429eb539412SYork Sun */
430eb539412SYork Sun
431eb539412SYork Sun bootpg_map = bootpg;
432eb539412SYork Sun
433eb539412SYork Sun if (pagesize == 8192)
434eb539412SYork Sun bootpg += 4096; /* use 2nd half */
435a47a12beSStefan Roese
4369d64c6bbSAaron Sierra /* Some OSes expect secondary cores to be held in reset */
4379d64c6bbSAaron Sierra if (hold_cores_in_reset(0))
4389d64c6bbSAaron Sierra return;
4399d64c6bbSAaron Sierra
440ffd06e02SYork Sun /*
441ffd06e02SYork Sun * Store the bootpg's cache-able half address for use by secondary
442ffd06e02SYork Sun * CPU cores to continue to boot
443ffd06e02SYork Sun */
444ffd06e02SYork Sun __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
445ffd06e02SYork Sun
446ffd06e02SYork Sun /* Store spin table's physical address for use by secondary cores */
447ffd06e02SYork Sun __spin_table_addr = (u32)get_spin_phys_addr();
448ffd06e02SYork Sun
449ffd06e02SYork Sun /* flush bootpg it before copying invalidate any staled cacheline */
450ffd06e02SYork Sun flush_cache(bootpg, 4096);
451a47a12beSStefan Roese
452a47a12beSStefan Roese /* look for the tlb covering the reset page, there better be one */
453ffd06e02SYork Sun i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
454a47a12beSStefan Roese
455a47a12beSStefan Roese /* we found a match */
456a47a12beSStefan Roese if (i != -1) {
457a47a12beSStefan Roese /* map reset page to bootpg so we can copy code there */
458a47a12beSStefan Roese disable_tlb(i);
459a47a12beSStefan Roese
460a47a12beSStefan Roese set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
461a47a12beSStefan Roese MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
462a47a12beSStefan Roese 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
463a47a12beSStefan Roese
464a47a12beSStefan Roese memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
465a47a12beSStefan Roese
466eb539412SYork Sun plat_mp_up(bootpg_map, pagesize);
467a47a12beSStefan Roese } else {
468a47a12beSStefan Roese puts("WARNING: No reset page TLB. "
469a47a12beSStefan Roese "Skipping secondary core setup\n");
470a47a12beSStefan Roese }
471a47a12beSStefan Roese }
472