blob: 7b10fba0a64413e906aa02f69227db20585f1986 [file] [log] [blame]
Kumar Galaec2b74f2008-01-17 16:48:33 -06001/*
2 * Copyright 2008 Freescale Semiconductor.
3 *
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>
28#include "mp.h"
29
30DECLARE_GLOBAL_DATA_PTR;
31
Kumar Galaec2b74f2008-01-17 16:48:33 -060032u32 get_my_id()
33{
34 return mfspr(SPRN_PIR);
35}
36
37int cpu_reset(int nr)
38{
39 volatile ccsr_pic_t *pic = (void *)(CFG_MPC85xx_PIC_ADDR);
40 out_be32(&pic->pir, 1 << nr);
41 (void)in_be32(&pic->pir);
42 out_be32(&pic->pir, 0x0);
43
44 return 0;
45}
46
47int cpu_status(int nr)
48{
49 u32 *table, id = get_my_id();
50
51 if (nr == id) {
52 table = (u32 *)get_spin_addr();
53 printf("table base @ 0x%08x\n", table);
54 } else {
55 table = (u32 *)get_spin_addr() + nr * NUM_BOOT_ENTRY;
56 printf("Running on cpu %d\n", id);
57 printf("\n");
58 printf("table @ 0x%08x:\n", table);
Kumar Gala79679d82008-03-26 08:34:25 -050059 printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
Kumar Galaec2b74f2008-01-17 16:48:33 -060060 printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
Kumar Gala79679d82008-03-26 08:34:25 -050061 printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
62 printf(" r6 - 0x%08x\n", table[BOOT_ENTRY_R6_LOWER]);
Kumar Galaec2b74f2008-01-17 16:48:33 -060063 }
64
65 return 0;
66}
67
Kumar Gala79679d82008-03-26 08:34:25 -050068static u8 boot_entry_map[4] = {
69 0,
70 BOOT_ENTRY_PIR,
71 BOOT_ENTRY_R3_LOWER,
72 BOOT_ENTRY_R6_LOWER,
73};
74
75int cpu_release(int nr, int argc, char *argv[])
Kumar Galaec2b74f2008-01-17 16:48:33 -060076{
77 u32 i, val, *table = (u32 *)get_spin_addr() + nr * NUM_BOOT_ENTRY;
Kumar Gala79679d82008-03-26 08:34:25 -050078 u64 boot_addr;
Kumar Galaec2b74f2008-01-17 16:48:33 -060079
80 if (nr == get_my_id()) {
81 printf("Invalid to release the boot core.\n\n");
82 return 1;
83 }
84
Kumar Gala79679d82008-03-26 08:34:25 -050085 if (argc != 4) {
Kumar Galaec2b74f2008-01-17 16:48:33 -060086 printf("Invalid number of arguments to release.\n\n");
87 return 1;
88 }
89
Kumar Gala79679d82008-03-26 08:34:25 -050090#ifdef CFG_64BIT_STRTOUL
91 boot_addr = simple_strtoull(argv[0], NULL, 16);
92#else
93 boot_addr = simple_strtoul(argv[0], NULL, 16);
94#endif
95
96 /* handle pir, r3, r6 */
97 for (i = 1; i < 4; i++) {
Kumar Galaec2b74f2008-01-17 16:48:33 -060098 if (argv[i][0] != '-') {
Kumar Gala79679d82008-03-26 08:34:25 -050099 u8 entry = boot_entry_map[i];
Kumar Galaec2b74f2008-01-17 16:48:33 -0600100 val = simple_strtoul(argv[i], NULL, 16);
Kumar Gala79679d82008-03-26 08:34:25 -0500101 table[entry] = val;
Kumar Galaec2b74f2008-01-17 16:48:33 -0600102 }
103 }
104
Kumar Gala79679d82008-03-26 08:34:25 -0500105 table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
106 table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
Kumar Galaec2b74f2008-01-17 16:48:33 -0600107
108 return 0;
109}
110
111ulong get_spin_addr(void)
112{
113 extern ulong __secondary_start_page;
114 extern ulong __spin_table;
115
116 ulong addr =
117 (ulong)&__spin_table - (ulong)&__secondary_start_page;
118 addr += 0xfffff000;
119
120 return addr;
121}
122
123static void pq3_mp_up(unsigned long bootpg)
124{
125 u32 up, cpu_up_mask, whoami;
126 u32 *table = (u32 *)get_spin_addr();
127 volatile u32 bpcr;
128 volatile ccsr_local_ecm_t *ecm = (void *)(CFG_MPC85xx_ECM_ADDR);
129 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
130 volatile ccsr_pic_t *pic = (void *)(CFG_MPC85xx_PIC_ADDR);
131 u32 devdisr;
132 int timeout = 10;
133
134 whoami = in_be32(&pic->whoami);
135 out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
136
137 /* disable time base at the platform */
138 devdisr = in_be32(&gur->devdisr);
139 if (whoami)
140 devdisr |= MPC85xx_DEVDISR_TB0;
141 else
142 devdisr |= MPC85xx_DEVDISR_TB1;
143 out_be32(&gur->devdisr, devdisr);
144
145 /* release the hounds */
146 up = ((1 << CONFIG_NR_CPUS) - 1);
147 bpcr = in_be32(&ecm->eebpcr);
148 bpcr |= (up << 24);
149 out_be32(&ecm->eebpcr, bpcr);
150 asm("sync; isync; msync");
151
152 cpu_up_mask = 1 << whoami;
153 /* wait for everyone */
154 while (timeout) {
155 int i;
156 for (i = 1; i < CONFIG_NR_CPUS; i++) {
157 if (table[i * NUM_BOOT_ENTRY])
158 cpu_up_mask |= (1 << i);
159 };
160
161 if ((cpu_up_mask & up) == up)
162 break;
163
164 udelay(100);
165 timeout--;
166 }
167
168 /* enable time base at the platform */
169 if (whoami)
170 devdisr |= MPC85xx_DEVDISR_TB1;
171 else
172 devdisr |= MPC85xx_DEVDISR_TB0;
173 out_be32(&gur->devdisr, devdisr);
174 mtspr(SPRN_TBWU, 0);
175 mtspr(SPRN_TBWL, 0);
176
177 devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
178 out_be32(&gur->devdisr, devdisr);
179}
180
Kumar Galadd6c9102008-03-26 08:53:53 -0500181void cpu_mp_lmb_reserve(struct lmb *lmb)
182{
183 u32 bootpg;
184
185 /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
186 if ((u64)gd->ram_size > 0xfffff000)
187 bootpg = 0xfffff000;
188 else
189 bootpg = gd->ram_size - 4096;
190
191 lmb_reserve(lmb, bootpg, 4096);
192}
193
Kumar Galaec2b74f2008-01-17 16:48:33 -0600194void setup_mp(void)
195{
196 extern ulong __secondary_start_page;
197 ulong fixup = (ulong)&__secondary_start_page;
198 u32 bootpg;
199
200 /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
201 if ((u64)gd->ram_size > 0xfffff000)
202 bootpg = 0xfffff000;
203 else
204 bootpg = gd->ram_size - 4096;
205
206 memcpy((void *)bootpg, (void *)fixup, 4096);
207 flush_cache(bootpg, 4096);
208
209 pq3_mp_up(bootpg);
210}