2 * Copyright 2008-2009 Freescale Semiconductor, Inc.
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include <asm/processor.h>
29 #include <asm/fsl_law.h>
32 DECLARE_GLOBAL_DATA_PTR;
36 return mfspr(SPRN_PIR);
41 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
42 out_be32(&pic->pir, 1 << nr);
43 /* the dummy read works around an errata on early 85xx MP PICs */
44 (void)in_be32(&pic->pir);
45 out_be32(&pic->pir, 0x0);
50 int cpu_status(int nr)
52 u32 *table, id = get_my_id();
55 table = (u32 *)get_spin_virt_addr();
56 printf("table base @ 0x%p\n", table);
58 table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
59 printf("Running on cpu %d\n", id);
61 printf("table @ 0x%p\n", table);
62 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
63 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
64 printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
65 printf(" r6 - 0x%08x\n", table[BOOT_ENTRY_R6_LOWER]);
71 static u8 boot_entry_map[4] = {
78 int cpu_release(int nr, int argc, char *argv[])
80 u32 i, val, *table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
83 if (nr == get_my_id()) {
84 printf("Invalid to release the boot core.\n\n");
89 printf("Invalid number of arguments to release.\n\n");
93 boot_addr = simple_strtoull(argv[0], NULL, 16);
95 /* handle pir, r3, r6 */
96 for (i = 1; i < 4; i++) {
97 if (argv[i][0] != '-') {
98 u8 entry = boot_entry_map[i];
99 val = simple_strtoul(argv[i], NULL, 16);
104 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
106 /* ensure all table updates complete before final address write */
109 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
114 u32 determine_mp_bootpg(void)
116 /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
117 if ((u64)gd->ram_size > 0xfffff000)
120 return (gd->ram_size - 4096);
123 ulong get_spin_phys_addr(void)
125 extern ulong __secondary_start_page;
126 extern ulong __spin_table;
128 return (determine_mp_bootpg() +
129 (ulong)&__spin_table - (ulong)&__secondary_start_page);
132 ulong get_spin_virt_addr(void)
134 extern ulong __secondary_start_page;
135 extern ulong __spin_table;
137 return (CONFIG_BPTR_VIRT_ADDR +
138 (ulong)&__spin_table - (ulong)&__secondary_start_page);
141 #ifdef CONFIG_FSL_CORENET
142 static void plat_mp_up(unsigned long bootpg)
144 u32 up, cpu_up_mask, whoami;
145 u32 *table = (u32 *)get_spin_virt_addr();
146 volatile ccsr_gur_t *gur;
147 volatile ccsr_local_t *ccm;
148 volatile ccsr_rcpm_t *rcpm;
149 volatile ccsr_pic_t *pic;
154 gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
155 ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
156 rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
157 pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
159 nr_cpus = ((in_be32(&pic->frr) >> 8) & 0xff) + 1;
161 whoami = in_be32(&pic->whoami);
162 cpu_up_mask = 1 << whoami;
163 out_be32(&ccm->bstrl, bootpg);
165 e = find_law(bootpg);
166 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | LAW_SIZE_4K);
168 /* disable time base at the platform */
169 out_be32(&rcpm->ctbenrl, cpu_up_mask);
171 /* release the hounds */
172 up = ((1 << nr_cpus) - 1);
173 out_be32(&gur->brrl, up);
175 /* wait for everyone */
178 for (i = 0; i < nr_cpus; i++) {
179 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
180 cpu_up_mask |= (1 << i);
183 if ((cpu_up_mask & up) == up)
191 printf("CPU up timeout. CPU up mask is %x should be %x\n",
194 /* enable time base at the platform */
195 out_be32(&rcpm->ctbenrl, 0);
198 out_be32(&rcpm->ctbenrl, (1 << nr_cpus) - 1);
200 #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
202 * Disabling Boot Page Translation allows the memory region 0xfffff000
203 * to 0xffffffff to be used normally. Leaving Boot Page Translation
204 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
205 * unusable for normal operation but it does allow OSes to easily
206 * reset a processor core to put it back into U-Boot's spinloop.
208 clrbits_be32(&ecm->bptr, 0x80000000);
212 static void plat_mp_up(unsigned long bootpg)
214 u32 up, cpu_up_mask, whoami;
215 u32 *table = (u32 *)get_spin_virt_addr();
217 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
218 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
219 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
223 whoami = in_be32(&pic->whoami);
224 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
226 /* disable time base at the platform */
227 devdisr = in_be32(&gur->devdisr);
229 devdisr |= MPC85xx_DEVDISR_TB0;
231 devdisr |= MPC85xx_DEVDISR_TB1;
232 out_be32(&gur->devdisr, devdisr);
234 /* release the hounds */
235 up = ((1 << cpu_numcores()) - 1);
236 bpcr = in_be32(&ecm->eebpcr);
238 out_be32(&ecm->eebpcr, bpcr);
239 asm("sync; isync; msync");
241 cpu_up_mask = 1 << whoami;
242 /* wait for everyone */
245 for (i = 0; i < cpu_numcores(); i++) {
246 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
247 cpu_up_mask |= (1 << i);
250 if ((cpu_up_mask & up) == up)
258 printf("CPU up timeout. CPU up mask is %x should be %x\n",
261 /* enable time base at the platform */
263 devdisr |= MPC85xx_DEVDISR_TB1;
265 devdisr |= MPC85xx_DEVDISR_TB0;
266 out_be32(&gur->devdisr, devdisr);
270 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
271 out_be32(&gur->devdisr, devdisr);
273 #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
275 * Disabling Boot Page Translation allows the memory region 0xfffff000
276 * to 0xffffffff to be used normally. Leaving Boot Page Translation
277 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
278 * unusable for normal operation but it does allow OSes to easily
279 * reset a processor core to put it back into U-Boot's spinloop.
281 clrbits_be32(&ecm->bptr, 0x80000000);
286 void cpu_mp_lmb_reserve(struct lmb *lmb)
288 u32 bootpg = determine_mp_bootpg();
290 lmb_reserve(lmb, bootpg, 4096);
295 extern ulong __secondary_start_page;
296 extern ulong __bootpg_addr;
297 ulong fixup = (ulong)&__secondary_start_page;
298 u32 bootpg = determine_mp_bootpg();
300 /* Store the bootpg's SDRAM address for use by secondary CPU cores */
301 __bootpg_addr = bootpg;
303 /* look for the tlb covering the reset page, there better be one */
304 int i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
306 /* we found a match */
308 /* map reset page to bootpg so we can copy code there */
311 set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
312 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I, /* perms, wimge */
313 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
315 memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
319 puts("WARNING: No reset page TLB. "
320 "Skipping secondary core setup\n");