blob: 6ae7f0a72ca4903f0802a8d62b657679d226c2f4 [file] [log] [blame]
Kumar Galaec2b74f2008-01-17 16:48:33 -06001/*
Kumar Gala4194b362010-01-12 11:42:43 -06002 * Copyright 2008-2010 Freescale Semiconductor, Inc.
Kumar Galaec2b74f2008-01-17 16:48:33 -06003 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
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.
11 *
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.
16 *
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,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <asm/processor.h>
25#include <ioports.h>
Kumar Galadd6c9102008-03-26 08:53:53 -050026#include <lmb.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060027#include <asm/io.h>
Kumar Galac7259082009-09-03 08:41:31 -050028#include <asm/mmu.h>
Kumar Gala39a7e7f2009-09-17 01:44:39 -050029#include <asm/fsl_law.h>
Kumar Galaec2b74f2008-01-17 16:48:33 -060030#include "mp.h"
31
32DECLARE_GLOBAL_DATA_PTR;
33
Kumar Galaec2b74f2008-01-17 16:48:33 -060034u32 get_my_id()
35{
36 return mfspr(SPRN_PIR);
37}
38
39int cpu_reset(int nr)
40{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
Kumar Galaec2b74f2008-01-17 16:48:33 -060042 out_be32(&pic->pir, 1 << nr);
Kumar Galac840d262009-03-31 23:11:05 -050043 /* the dummy read works around an errata on early 85xx MP PICs */
Kumar Galaec2b74f2008-01-17 16:48:33 -060044 (void)in_be32(&pic->pir);
45 out_be32(&pic->pir, 0x0);
46
47 return 0;
48}
49
50int cpu_status(int nr)
51{
52 u32 *table, id = get_my_id();
53
54 if (nr == id) {
Peter Tyser5ccd29c2009-10-23 15:55:47 -050055 table = (u32 *)get_spin_virt_addr();
Kumar Gala348753d2008-07-14 14:03:02 -050056 printf("table base @ 0x%p\n", table);
Kumar Galaec2b74f2008-01-17 16:48:33 -060057 } else {
Peter Tyser5ccd29c2009-10-23 15:55:47 -050058 table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
Kumar Galaec2b74f2008-01-17 16:48:33 -060059 printf("Running on cpu %d\n", id);
60 printf("\n");
Kumar Gala348753d2008-07-14 14:03:02 -050061 printf("table @ 0x%p\n", table);
Kumar Gala79679d82008-03-26 08:34:25 -050062 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
Kumar Galaec2b74f2008-01-17 16:48:33 -060063 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
Kumar Gala79679d82008-03-26 08:34:25 -050064 printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
65 printf(" r6 - 0x%08x\n", table[BOOT_ENTRY_R6_LOWER]);
Kumar Galaec2b74f2008-01-17 16:48:33 -060066 }
67
68 return 0;
69}
70
Kumar Gala4194b362010-01-12 11:42:43 -060071int cpu_disable(int nr)
72{
73 /* dummy function so common/cmd_mp.c will build */
74 return 1;
75}
76
Kumar Gala79679d82008-03-26 08:34:25 -050077static u8 boot_entry_map[4] = {
78 0,
79 BOOT_ENTRY_PIR,
80 BOOT_ENTRY_R3_LOWER,
81 BOOT_ENTRY_R6_LOWER,
82};
83
84int cpu_release(int nr, int argc, char *argv[])
Kumar Galaec2b74f2008-01-17 16:48:33 -060085{
Peter Tyser5ccd29c2009-10-23 15:55:47 -050086 u32 i, val, *table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
Kumar Gala79679d82008-03-26 08:34:25 -050087 u64 boot_addr;
Kumar Galaec2b74f2008-01-17 16:48:33 -060088
89 if (nr == get_my_id()) {
90 printf("Invalid to release the boot core.\n\n");
91 return 1;
92 }
93
Kumar Gala79679d82008-03-26 08:34:25 -050094 if (argc != 4) {
Kumar Galaec2b74f2008-01-17 16:48:33 -060095 printf("Invalid number of arguments to release.\n\n");
96 return 1;
97 }
98
Kumar Gala79679d82008-03-26 08:34:25 -050099 boot_addr = simple_strtoull(argv[0], NULL, 16);
Kumar Gala79679d82008-03-26 08:34:25 -0500100
101 /* handle pir, r3, r6 */
102 for (i = 1; i < 4; i++) {
Kumar Galaec2b74f2008-01-17 16:48:33 -0600103 if (argv[i][0] != '-') {
Kumar Gala79679d82008-03-26 08:34:25 -0500104 u8 entry = boot_entry_map[i];
Kumar Galaec2b74f2008-01-17 16:48:33 -0600105 val = simple_strtoul(argv[i], NULL, 16);
Kumar Gala79679d82008-03-26 08:34:25 -0500106 table[entry] = val;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600107 }
108 }
109
Kumar Gala79679d82008-03-26 08:34:25 -0500110 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
Kumar Galacf6cc012008-04-28 02:24:04 -0500111
112 /* ensure all table updates complete before final address write */
113 eieio();
114
Kumar Gala79679d82008-03-26 08:34:25 -0500115 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600116
117 return 0;
118}
119
Kumar Galac840d262009-03-31 23:11:05 -0500120u32 determine_mp_bootpg(void)
121{
122 /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
123 if ((u64)gd->ram_size > 0xfffff000)
124 return (0xfffff000);
125
126 return (gd->ram_size - 4096);
127}
128
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500129ulong get_spin_phys_addr(void)
Kumar Galaec2b74f2008-01-17 16:48:33 -0600130{
131 extern ulong __secondary_start_page;
132 extern ulong __spin_table;
133
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500134 return (determine_mp_bootpg() +
135 (ulong)&__spin_table - (ulong)&__secondary_start_page);
136}
Kumar Galaec2b74f2008-01-17 16:48:33 -0600137
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500138ulong get_spin_virt_addr(void)
139{
140 extern ulong __secondary_start_page;
141 extern ulong __spin_table;
142
143 return (CONFIG_BPTR_VIRT_ADDR +
144 (ulong)&__spin_table - (ulong)&__secondary_start_page);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600145}
146
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500147#ifdef CONFIG_FSL_CORENET
148static void plat_mp_up(unsigned long bootpg)
149{
150 u32 up, cpu_up_mask, whoami;
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500151 u32 *table = (u32 *)get_spin_virt_addr();
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500152 volatile ccsr_gur_t *gur;
153 volatile ccsr_local_t *ccm;
154 volatile ccsr_rcpm_t *rcpm;
155 volatile ccsr_pic_t *pic;
156 int timeout = 10;
157 u32 nr_cpus;
158 struct law_entry e;
159
160 gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
161 ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
162 rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
163 pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
164
165 nr_cpus = ((in_be32(&pic->frr) >> 8) & 0xff) + 1;
166
167 whoami = in_be32(&pic->whoami);
168 cpu_up_mask = 1 << whoami;
169 out_be32(&ccm->bstrl, bootpg);
170
171 e = find_law(bootpg);
172 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | LAW_SIZE_4K);
173
Dave Liuf5ecc6e2009-11-17 20:01:24 -0600174 /* readback to sync write */
175 in_be32(&ccm->bstrar);
176
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500177 /* disable time base at the platform */
178 out_be32(&rcpm->ctbenrl, cpu_up_mask);
179
180 /* release the hounds */
181 up = ((1 << nr_cpus) - 1);
182 out_be32(&gur->brrl, up);
183
184 /* wait for everyone */
185 while (timeout) {
186 int i;
187 for (i = 0; i < nr_cpus; i++) {
188 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
189 cpu_up_mask |= (1 << i);
190 };
191
192 if ((cpu_up_mask & up) == up)
193 break;
194
195 udelay(100);
196 timeout--;
197 }
198
199 if (timeout == 0)
200 printf("CPU up timeout. CPU up mask is %x should be %x\n",
201 cpu_up_mask, up);
202
203 /* enable time base at the platform */
204 out_be32(&rcpm->ctbenrl, 0);
205 mtspr(SPRN_TBWU, 0);
206 mtspr(SPRN_TBWL, 0);
207 out_be32(&rcpm->ctbenrl, (1 << nr_cpus) - 1);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500208
209#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
210 /*
211 * Disabling Boot Page Translation allows the memory region 0xfffff000
212 * to 0xffffffff to be used normally. Leaving Boot Page Translation
213 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
214 * unusable for normal operation but it does allow OSes to easily
215 * reset a processor core to put it back into U-Boot's spinloop.
216 */
217 clrbits_be32(&ecm->bptr, 0x80000000);
218#endif
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500219}
220#else
221static void plat_mp_up(unsigned long bootpg)
Kumar Galaec2b74f2008-01-17 16:48:33 -0600222{
223 u32 up, cpu_up_mask, whoami;
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500224 u32 *table = (u32 *)get_spin_virt_addr();
Kumar Galaec2b74f2008-01-17 16:48:33 -0600225 volatile u32 bpcr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200226 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
227 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
228 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600229 u32 devdisr;
230 int timeout = 10;
231
232 whoami = in_be32(&pic->whoami);
233 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
234
235 /* disable time base at the platform */
236 devdisr = in_be32(&gur->devdisr);
237 if (whoami)
238 devdisr |= MPC85xx_DEVDISR_TB0;
239 else
240 devdisr |= MPC85xx_DEVDISR_TB1;
241 out_be32(&gur->devdisr, devdisr);
242
243 /* release the hounds */
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530244 up = ((1 << cpu_numcores()) - 1);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600245 bpcr = in_be32(&ecm->eebpcr);
246 bpcr |= (up << 24);
247 out_be32(&ecm->eebpcr, bpcr);
248 asm("sync; isync; msync");
249
250 cpu_up_mask = 1 << whoami;
251 /* wait for everyone */
252 while (timeout) {
253 int i;
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530254 for (i = 0; i < cpu_numcores(); i++) {
Kumar Gala97b3ecb2008-04-09 04:20:57 -0500255 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
Kumar Galaec2b74f2008-01-17 16:48:33 -0600256 cpu_up_mask |= (1 << i);
257 };
258
259 if ((cpu_up_mask & up) == up)
260 break;
261
262 udelay(100);
263 timeout--;
264 }
265
Kumar Gala97b3ecb2008-04-09 04:20:57 -0500266 if (timeout == 0)
267 printf("CPU up timeout. CPU up mask is %x should be %x\n",
268 cpu_up_mask, up);
269
Kumar Galaec2b74f2008-01-17 16:48:33 -0600270 /* enable time base at the platform */
271 if (whoami)
272 devdisr |= MPC85xx_DEVDISR_TB1;
273 else
274 devdisr |= MPC85xx_DEVDISR_TB0;
275 out_be32(&gur->devdisr, devdisr);
276 mtspr(SPRN_TBWU, 0);
277 mtspr(SPRN_TBWL, 0);
278
279 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
280 out_be32(&gur->devdisr, devdisr);
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500281
282#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
283 /*
284 * Disabling Boot Page Translation allows the memory region 0xfffff000
285 * to 0xffffffff to be used normally. Leaving Boot Page Translation
286 * enabled remaps 0xfffff000 to SDRAM which makes that memory region
287 * unusable for normal operation but it does allow OSes to easily
288 * reset a processor core to put it back into U-Boot's spinloop.
289 */
290 clrbits_be32(&ecm->bptr, 0x80000000);
291#endif
Kumar Galaec2b74f2008-01-17 16:48:33 -0600292}
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500293#endif
Kumar Galaec2b74f2008-01-17 16:48:33 -0600294
Kumar Galadd6c9102008-03-26 08:53:53 -0500295void cpu_mp_lmb_reserve(struct lmb *lmb)
296{
Kumar Galac840d262009-03-31 23:11:05 -0500297 u32 bootpg = determine_mp_bootpg();
Kumar Galadd6c9102008-03-26 08:53:53 -0500298
299 lmb_reserve(lmb, bootpg, 4096);
300}
301
Kumar Galaec2b74f2008-01-17 16:48:33 -0600302void setup_mp(void)
303{
304 extern ulong __secondary_start_page;
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500305 extern ulong __bootpg_addr;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600306 ulong fixup = (ulong)&__secondary_start_page;
Kumar Galac840d262009-03-31 23:11:05 -0500307 u32 bootpg = determine_mp_bootpg();
Kumar Galaec2b74f2008-01-17 16:48:33 -0600308
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500309 /* Store the bootpg's SDRAM address for use by secondary CPU cores */
310 __bootpg_addr = bootpg;
311
Kumar Galac7259082009-09-03 08:41:31 -0500312 /* look for the tlb covering the reset page, there better be one */
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500313 int i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600314
Kumar Galac7259082009-09-03 08:41:31 -0500315 /* we found a match */
316 if (i != -1) {
317 /* map reset page to bootpg so we can copy code there */
318 disable_tlb(i);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500319
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500320 set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
Kumar Galaabc76eb2009-11-17 20:21:20 -0600321 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
Kumar Galac7259082009-09-03 08:41:31 -0500322 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
323
Peter Tyser5ccd29c2009-10-23 15:55:47 -0500324 memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
325
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500326 plat_mp_up(bootpg);
Kumar Galac7259082009-09-03 08:41:31 -0500327 } else {
328 puts("WARNING: No reset page TLB. "
329 "Skipping secondary core setup\n");
330 }
Kumar Galaec2b74f2008-01-17 16:48:33 -0600331}