blob: 7626eb8e728459d14a19f02415303455be08aa75 [file] [log] [blame]
Kumar Gala36d6b3f2008-01-17 16:48:33 -06001/*
Poonam Aggrwal4baef822009-07-31 12:08:14 +05302 * Copyright 2008-2009 Freescale Semiconductor, Inc.
Kumar Gala36d6b3f2008-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 Gala5769ded2008-03-26 08:53:53 -050026#include <lmb.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060027#include <asm/io.h>
Kumar Gala8399e122009-09-03 08:41:31 -050028#include <asm/mmu.h>
Kumar Gala4d9190d2009-09-17 01:44:39 -050029#include <asm/fsl_law.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060030#include "mp.h"
31
32DECLARE_GLOBAL_DATA_PTR;
33
Kumar Gala36d6b3f2008-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-VILLARD03836942008-10-16 15:01:15 +020041 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060042 out_be32(&pic->pir, 1 << nr);
Kumar Galae1064b32009-03-31 23:11:05 -050043 /* the dummy read works around an errata on early 85xx MP PICs */
Kumar Gala36d6b3f2008-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 Tyser7feaacb2009-10-23 15:55:47 -050055 table = (u32 *)get_spin_virt_addr();
Kumar Gala275f4c12008-07-14 14:03:02 -050056 printf("table base @ 0x%p\n", table);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060057 } else {
Peter Tyser7feaacb2009-10-23 15:55:47 -050058 table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
Kumar Gala36d6b3f2008-01-17 16:48:33 -060059 printf("Running on cpu %d\n", id);
60 printf("\n");
Kumar Gala275f4c12008-07-14 14:03:02 -050061 printf("table @ 0x%p\n", table);
Kumar Galadeeac572008-03-26 08:34:25 -050062 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
Kumar Gala36d6b3f2008-01-17 16:48:33 -060063 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
Kumar Galadeeac572008-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 Gala36d6b3f2008-01-17 16:48:33 -060066 }
67
68 return 0;
69}
70
Kumar Galadeeac572008-03-26 08:34:25 -050071static u8 boot_entry_map[4] = {
72 0,
73 BOOT_ENTRY_PIR,
74 BOOT_ENTRY_R3_LOWER,
75 BOOT_ENTRY_R6_LOWER,
76};
77
78int cpu_release(int nr, int argc, char *argv[])
Kumar Gala36d6b3f2008-01-17 16:48:33 -060079{
Peter Tyser7feaacb2009-10-23 15:55:47 -050080 u32 i, val, *table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
Kumar Galadeeac572008-03-26 08:34:25 -050081 u64 boot_addr;
Kumar Gala36d6b3f2008-01-17 16:48:33 -060082
83 if (nr == get_my_id()) {
84 printf("Invalid to release the boot core.\n\n");
85 return 1;
86 }
87
Kumar Galadeeac572008-03-26 08:34:25 -050088 if (argc != 4) {
Kumar Gala36d6b3f2008-01-17 16:48:33 -060089 printf("Invalid number of arguments to release.\n\n");
90 return 1;
91 }
92
Kumar Galadeeac572008-03-26 08:34:25 -050093 boot_addr = simple_strtoull(argv[0], NULL, 16);
Kumar Galadeeac572008-03-26 08:34:25 -050094
95 /* handle pir, r3, r6 */
96 for (i = 1; i < 4; i++) {
Kumar Gala36d6b3f2008-01-17 16:48:33 -060097 if (argv[i][0] != '-') {
Kumar Galadeeac572008-03-26 08:34:25 -050098 u8 entry = boot_entry_map[i];
Kumar Gala36d6b3f2008-01-17 16:48:33 -060099 val = simple_strtoul(argv[i], NULL, 16);
Kumar Galadeeac572008-03-26 08:34:25 -0500100 table[entry] = val;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600101 }
102 }
103
Kumar Galadeeac572008-03-26 08:34:25 -0500104 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
Kumar Gala398dcd62008-04-28 02:24:04 -0500105
106 /* ensure all table updates complete before final address write */
107 eieio();
108
Kumar Galadeeac572008-03-26 08:34:25 -0500109 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600110
111 return 0;
112}
113
Kumar Galae1064b32009-03-31 23:11:05 -0500114u32 determine_mp_bootpg(void)
115{
116 /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
117 if ((u64)gd->ram_size > 0xfffff000)
118 return (0xfffff000);
119
120 return (gd->ram_size - 4096);
121}
122
Peter Tyser7feaacb2009-10-23 15:55:47 -0500123ulong get_spin_phys_addr(void)
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600124{
125 extern ulong __secondary_start_page;
126 extern ulong __spin_table;
127
Peter Tyser7feaacb2009-10-23 15:55:47 -0500128 return (determine_mp_bootpg() +
129 (ulong)&__spin_table - (ulong)&__secondary_start_page);
130}
131
132ulong get_spin_virt_addr(void)
133{
134 extern ulong __secondary_start_page;
135 extern ulong __spin_table;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600136
Peter Tyser7feaacb2009-10-23 15:55:47 -0500137 return (CONFIG_BPTR_VIRT_ADDR +
138 (ulong)&__spin_table - (ulong)&__secondary_start_page);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600139}
140
Kumar Gala4d9190d2009-09-17 01:44:39 -0500141#ifdef CONFIG_FSL_CORENET
142static void plat_mp_up(unsigned long bootpg)
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600143{
144 u32 up, cpu_up_mask, whoami;
Peter Tyser7feaacb2009-10-23 15:55:47 -0500145 u32 *table = (u32 *)get_spin_virt_addr();
Kumar Gala4d9190d2009-09-17 01:44:39 -0500146 volatile ccsr_gur_t *gur;
147 volatile ccsr_local_t *ccm;
148 volatile ccsr_rcpm_t *rcpm;
149 volatile ccsr_pic_t *pic;
150 int timeout = 10;
151 u32 nr_cpus;
152 struct law_entry e;
153
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);
158
159 nr_cpus = ((in_be32(&pic->frr) >> 8) & 0xff) + 1;
160
161 whoami = in_be32(&pic->whoami);
162 cpu_up_mask = 1 << whoami;
163 out_be32(&ccm->bstrl, bootpg);
164
165 e = find_law(bootpg);
166 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | LAW_SIZE_4K);
167
168 /* disable time base at the platform */
169 out_be32(&rcpm->ctbenrl, cpu_up_mask);
170
171 /* release the hounds */
172 up = ((1 << nr_cpus) - 1);
173 out_be32(&gur->brrl, up);
174
175 /* wait for everyone */
176 while (timeout) {
177 int i;
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);
181 };
182
183 if ((cpu_up_mask & up) == up)
184 break;
185
186 udelay(100);
187 timeout--;
188 }
189
190 if (timeout == 0)
191 printf("CPU up timeout. CPU up mask is %x should be %x\n",
192 cpu_up_mask, up);
193
194 /* enable time base at the platform */
195 out_be32(&rcpm->ctbenrl, 0);
196 mtspr(SPRN_TBWU, 0);
197 mtspr(SPRN_TBWL, 0);
198 out_be32(&rcpm->ctbenrl, (1 << nr_cpus) - 1);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500199
200#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
201 /*
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.
207 */
208 clrbits_be32(&ecm->bptr, 0x80000000);
209#endif
Kumar Gala4d9190d2009-09-17 01:44:39 -0500210}
211#else
212static void plat_mp_up(unsigned long bootpg)
213{
214 u32 up, cpu_up_mask, whoami;
Peter Tyser7feaacb2009-10-23 15:55:47 -0500215 u32 *table = (u32 *)get_spin_virt_addr();
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600216 volatile u32 bpcr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200217 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);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600220 u32 devdisr;
221 int timeout = 10;
222
223 whoami = in_be32(&pic->whoami);
224 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
225
226 /* disable time base at the platform */
227 devdisr = in_be32(&gur->devdisr);
228 if (whoami)
229 devdisr |= MPC85xx_DEVDISR_TB0;
230 else
231 devdisr |= MPC85xx_DEVDISR_TB1;
232 out_be32(&gur->devdisr, devdisr);
233
234 /* release the hounds */
Poonam Aggrwal4baef822009-07-31 12:08:14 +0530235 up = ((1 << cpu_numcores()) - 1);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600236 bpcr = in_be32(&ecm->eebpcr);
237 bpcr |= (up << 24);
238 out_be32(&ecm->eebpcr, bpcr);
239 asm("sync; isync; msync");
240
241 cpu_up_mask = 1 << whoami;
242 /* wait for everyone */
243 while (timeout) {
244 int i;
Poonam Aggrwal4baef822009-07-31 12:08:14 +0530245 for (i = 0; i < cpu_numcores(); i++) {
Kumar Gala615f14d2008-04-09 04:20:57 -0500246 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600247 cpu_up_mask |= (1 << i);
248 };
249
250 if ((cpu_up_mask & up) == up)
251 break;
252
253 udelay(100);
254 timeout--;
255 }
256
Kumar Gala615f14d2008-04-09 04:20:57 -0500257 if (timeout == 0)
258 printf("CPU up timeout. CPU up mask is %x should be %x\n",
259 cpu_up_mask, up);
260
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600261 /* enable time base at the platform */
262 if (whoami)
263 devdisr |= MPC85xx_DEVDISR_TB1;
264 else
265 devdisr |= MPC85xx_DEVDISR_TB0;
266 out_be32(&gur->devdisr, devdisr);
267 mtspr(SPRN_TBWU, 0);
268 mtspr(SPRN_TBWL, 0);
269
270 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
271 out_be32(&gur->devdisr, devdisr);
Peter Tyser7feaacb2009-10-23 15:55:47 -0500272
273#ifdef CONFIG_MPC8xxx_DISABLE_BPTR
274 /*
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.
280 */
281 clrbits_be32(&ecm->bptr, 0x80000000);
282#endif
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600283}
Kumar Gala4d9190d2009-09-17 01:44:39 -0500284#endif
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600285
Kumar Gala5769ded2008-03-26 08:53:53 -0500286void cpu_mp_lmb_reserve(struct lmb *lmb)
287{
Kumar Galae1064b32009-03-31 23:11:05 -0500288 u32 bootpg = determine_mp_bootpg();
Kumar Gala5769ded2008-03-26 08:53:53 -0500289
290 lmb_reserve(lmb, bootpg, 4096);
291}
292
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600293void setup_mp(void)
294{
295 extern ulong __secondary_start_page;
Peter Tyser7feaacb2009-10-23 15:55:47 -0500296 extern ulong __bootpg_addr;
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600297 ulong fixup = (ulong)&__secondary_start_page;
Kumar Galae1064b32009-03-31 23:11:05 -0500298 u32 bootpg = determine_mp_bootpg();
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600299
Peter Tyser7feaacb2009-10-23 15:55:47 -0500300 /* Store the bootpg's SDRAM address for use by secondary CPU cores */
301 __bootpg_addr = bootpg;
302
Kumar Gala8399e122009-09-03 08:41:31 -0500303 /* look for the tlb covering the reset page, there better be one */
Peter Tyser7feaacb2009-10-23 15:55:47 -0500304 int i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600305
Kumar Gala8399e122009-09-03 08:41:31 -0500306 /* we found a match */
307 if (i != -1) {
308 /* map reset page to bootpg so we can copy code there */
309 disable_tlb(i);
Kumar Gala4d9190d2009-09-17 01:44:39 -0500310
Peter Tyser7feaacb2009-10-23 15:55:47 -0500311 set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
Kumar Gala8399e122009-09-03 08:41:31 -0500312 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I, /* perms, wimge */
313 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
314
Peter Tyser7feaacb2009-10-23 15:55:47 -0500315 memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
316
Kumar Gala4d9190d2009-09-17 01:44:39 -0500317 plat_mp_up(bootpg);
Kumar Gala8399e122009-09-03 08:41:31 -0500318 } else {
319 puts("WARNING: No reset page TLB. "
320 "Skipping secondary core setup\n");
321 }
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600322}