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