blob: b5c6020c7f1c2385586fa3fb96c0c13d5b303dbe [file] [log] [blame]
Kumar Galaec2b74f2008-01-17 16:48:33 -06001/*
Poonam Aggrwal0e870982009-07-31 12:08:14 +05302 * Copyright 2008-2009 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) {
55 table = (u32 *)get_spin_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 {
58 table = (u32 *)get_spin_addr() + nr * NUM_BOOT_ENTRY;
59 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 Gala79679d82008-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 Galaec2b74f2008-01-17 16:48:33 -060079{
80 u32 i, val, *table = (u32 *)get_spin_addr() + nr * NUM_BOOT_ENTRY;
Kumar Gala79679d82008-03-26 08:34:25 -050081 u64 boot_addr;
Kumar Galaec2b74f2008-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 Gala79679d82008-03-26 08:34:25 -050088 if (argc != 4) {
Kumar Galaec2b74f2008-01-17 16:48:33 -060089 printf("Invalid number of arguments to release.\n\n");
90 return 1;
91 }
92
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020093#ifdef CONFIG_SYS_64BIT_STRTOUL
Kumar Gala79679d82008-03-26 08:34:25 -050094 boot_addr = simple_strtoull(argv[0], NULL, 16);
95#else
96 boot_addr = simple_strtoul(argv[0], NULL, 16);
97#endif
98
99 /* handle pir, r3, r6 */
100 for (i = 1; i < 4; i++) {
Kumar Galaec2b74f2008-01-17 16:48:33 -0600101 if (argv[i][0] != '-') {
Kumar Gala79679d82008-03-26 08:34:25 -0500102 u8 entry = boot_entry_map[i];
Kumar Galaec2b74f2008-01-17 16:48:33 -0600103 val = simple_strtoul(argv[i], NULL, 16);
Kumar Gala79679d82008-03-26 08:34:25 -0500104 table[entry] = val;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600105 }
106 }
107
Kumar Gala79679d82008-03-26 08:34:25 -0500108 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
Kumar Galacf6cc012008-04-28 02:24:04 -0500109
110 /* ensure all table updates complete before final address write */
111 eieio();
112
Kumar Gala79679d82008-03-26 08:34:25 -0500113 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600114
115 return 0;
116}
117
Kumar Galac840d262009-03-31 23:11:05 -0500118u32 determine_mp_bootpg(void)
119{
120 /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
121 if ((u64)gd->ram_size > 0xfffff000)
122 return (0xfffff000);
123
124 return (gd->ram_size - 4096);
125}
126
Kumar Galaec2b74f2008-01-17 16:48:33 -0600127ulong get_spin_addr(void)
128{
129 extern ulong __secondary_start_page;
130 extern ulong __spin_table;
131
132 ulong addr =
133 (ulong)&__spin_table - (ulong)&__secondary_start_page;
134 addr += 0xfffff000;
135
136 return addr;
137}
138
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500139#ifdef CONFIG_FSL_CORENET
140static void plat_mp_up(unsigned long bootpg)
141{
142 u32 up, cpu_up_mask, whoami;
143 u32 *table = (u32 *)get_spin_addr();
144 volatile ccsr_gur_t *gur;
145 volatile ccsr_local_t *ccm;
146 volatile ccsr_rcpm_t *rcpm;
147 volatile ccsr_pic_t *pic;
148 int timeout = 10;
149 u32 nr_cpus;
150 struct law_entry e;
151
152 gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
153 ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
154 rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
155 pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
156
157 nr_cpus = ((in_be32(&pic->frr) >> 8) & 0xff) + 1;
158
159 whoami = in_be32(&pic->whoami);
160 cpu_up_mask = 1 << whoami;
161 out_be32(&ccm->bstrl, bootpg);
162
163 e = find_law(bootpg);
164 out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | LAW_SIZE_4K);
165
166 /* disable time base at the platform */
167 out_be32(&rcpm->ctbenrl, cpu_up_mask);
168
169 /* release the hounds */
170 up = ((1 << nr_cpus) - 1);
171 out_be32(&gur->brrl, up);
172
173 /* wait for everyone */
174 while (timeout) {
175 int i;
176 for (i = 0; i < nr_cpus; i++) {
177 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
178 cpu_up_mask |= (1 << i);
179 };
180
181 if ((cpu_up_mask & up) == up)
182 break;
183
184 udelay(100);
185 timeout--;
186 }
187
188 if (timeout == 0)
189 printf("CPU up timeout. CPU up mask is %x should be %x\n",
190 cpu_up_mask, up);
191
192 /* enable time base at the platform */
193 out_be32(&rcpm->ctbenrl, 0);
194 mtspr(SPRN_TBWU, 0);
195 mtspr(SPRN_TBWL, 0);
196 out_be32(&rcpm->ctbenrl, (1 << nr_cpus) - 1);
197}
198#else
199static void plat_mp_up(unsigned long bootpg)
Kumar Galaec2b74f2008-01-17 16:48:33 -0600200{
201 u32 up, cpu_up_mask, whoami;
202 u32 *table = (u32 *)get_spin_addr();
203 volatile u32 bpcr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200204 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
205 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
206 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600207 u32 devdisr;
208 int timeout = 10;
209
210 whoami = in_be32(&pic->whoami);
211 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
212
213 /* disable time base at the platform */
214 devdisr = in_be32(&gur->devdisr);
215 if (whoami)
216 devdisr |= MPC85xx_DEVDISR_TB0;
217 else
218 devdisr |= MPC85xx_DEVDISR_TB1;
219 out_be32(&gur->devdisr, devdisr);
220
221 /* release the hounds */
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530222 up = ((1 << cpu_numcores()) - 1);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600223 bpcr = in_be32(&ecm->eebpcr);
224 bpcr |= (up << 24);
225 out_be32(&ecm->eebpcr, bpcr);
226 asm("sync; isync; msync");
227
228 cpu_up_mask = 1 << whoami;
229 /* wait for everyone */
230 while (timeout) {
231 int i;
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530232 for (i = 0; i < cpu_numcores(); i++) {
Kumar Gala97b3ecb2008-04-09 04:20:57 -0500233 if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
Kumar Galaec2b74f2008-01-17 16:48:33 -0600234 cpu_up_mask |= (1 << i);
235 };
236
237 if ((cpu_up_mask & up) == up)
238 break;
239
240 udelay(100);
241 timeout--;
242 }
243
Kumar Gala97b3ecb2008-04-09 04:20:57 -0500244 if (timeout == 0)
245 printf("CPU up timeout. CPU up mask is %x should be %x\n",
246 cpu_up_mask, up);
247
Kumar Galaec2b74f2008-01-17 16:48:33 -0600248 /* enable time base at the platform */
249 if (whoami)
250 devdisr |= MPC85xx_DEVDISR_TB1;
251 else
252 devdisr |= MPC85xx_DEVDISR_TB0;
253 out_be32(&gur->devdisr, devdisr);
254 mtspr(SPRN_TBWU, 0);
255 mtspr(SPRN_TBWL, 0);
256
257 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
258 out_be32(&gur->devdisr, devdisr);
259}
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500260#endif
Kumar Galaec2b74f2008-01-17 16:48:33 -0600261
Kumar Galadd6c9102008-03-26 08:53:53 -0500262void cpu_mp_lmb_reserve(struct lmb *lmb)
263{
Kumar Galac840d262009-03-31 23:11:05 -0500264 u32 bootpg = determine_mp_bootpg();
Kumar Galadd6c9102008-03-26 08:53:53 -0500265
266 lmb_reserve(lmb, bootpg, 4096);
267}
268
Kumar Galaec2b74f2008-01-17 16:48:33 -0600269void setup_mp(void)
270{
271 extern ulong __secondary_start_page;
272 ulong fixup = (ulong)&__secondary_start_page;
Kumar Galac840d262009-03-31 23:11:05 -0500273 u32 bootpg = determine_mp_bootpg();
Kumar Galaec2b74f2008-01-17 16:48:33 -0600274
Kumar Galac7259082009-09-03 08:41:31 -0500275 /* look for the tlb covering the reset page, there better be one */
276 int i = find_tlb_idx((void *)0xfffff000, 1);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600277
Kumar Galac7259082009-09-03 08:41:31 -0500278 /* we found a match */
279 if (i != -1) {
280 /* map reset page to bootpg so we can copy code there */
281 disable_tlb(i);
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500282
Kumar Galac7259082009-09-03 08:41:31 -0500283 set_tlb(1, 0xfffff000, bootpg, /* tlb, epn, rpn */
284 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_M, /* perms, wimge */
285 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
286
287 memcpy((void *)0xfffff000, (void *)fixup, 4096);
288 flush_cache(0xfffff000, 4096);
289
290 disable_tlb(i);
291
292 /* setup reset page back to 1:1, we'll use HW boot translation
293 * to map this where we want
294 */
295 set_tlb(1, 0xfffff000, 0xfffff000, /* tlb, epn, rpn */
296 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I, /* perms, wimge */
297 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
298
Kumar Gala39a7e7f2009-09-17 01:44:39 -0500299 plat_mp_up(bootpg);
Kumar Galac7259082009-09-03 08:41:31 -0500300 } else {
301 puts("WARNING: No reset page TLB. "
302 "Skipping secondary core setup\n");
303 }
Kumar Galaec2b74f2008-01-17 16:48:33 -0600304}