1
2
3
4
5
6#include <linux/init.h>
7#include <linux/kernel.h>
8#include <linux/linkage.h>
9#include <linux/mm.h>
10#include <linux/blkdev.h>
11#include <linux/memblock.h>
12#include <linux/pm.h>
13#include <linux/smp.h>
14
15#include <asm/bootinfo.h>
16#include <asm/reboot.h>
17#include <asm/setup.h>
18#include <asm/sibyte/board.h>
19#include <asm/smp-ops.h>
20
21#include <asm/fw/cfe/cfe_api.h>
22#include <asm/fw/cfe/cfe_error.h>
23
24
25#ifdef CONFIG_64BIT
26#define MAX_RAM_SIZE (~0ULL)
27#else
28#ifdef CONFIG_HIGHMEM
29#ifdef CONFIG_PHYS_ADDR_T_64BIT
30#define MAX_RAM_SIZE (~0ULL)
31#else
32#define MAX_RAM_SIZE (0xffffffffULL)
33#endif
34#else
35#define MAX_RAM_SIZE (0x1fffffffULL)
36#endif
37#endif
38
39#define SIBYTE_MAX_MEM_REGIONS 8
40phys_addr_t board_mem_region_addrs[SIBYTE_MAX_MEM_REGIONS];
41phys_addr_t board_mem_region_sizes[SIBYTE_MAX_MEM_REGIONS];
42unsigned int board_mem_region_count;
43
44int cfe_cons_handle;
45
46#ifdef CONFIG_BLK_DEV_INITRD
47extern unsigned long initrd_start, initrd_end;
48#endif
49
50static void __noreturn cfe_linux_exit(void *arg)
51{
52 int warm = *(int *)arg;
53
54 if (smp_processor_id()) {
55 static int reboot_smp;
56
57
58 if (!reboot_smp) {
59
60 reboot_smp = 1;
61 smp_call_function(cfe_linux_exit, arg, 0);
62 }
63 } else {
64 printk("Passing control back to CFE...\n");
65 cfe_exit(warm, 0);
66 printk("cfe_exit returned??\n");
67 }
68 while (1);
69}
70
71static void __noreturn cfe_linux_restart(char *command)
72{
73 static const int zero;
74
75 cfe_linux_exit((void *)&zero);
76}
77
78static void __noreturn cfe_linux_halt(void)
79{
80 static const int one = 1;
81
82 cfe_linux_exit((void *)&one);
83}
84
85static __init void prom_meminit(void)
86{
87 u64 addr, size, type;
88 int mem_flags = 0;
89 unsigned int idx;
90 int rd_flag;
91#ifdef CONFIG_BLK_DEV_INITRD
92 unsigned long initrd_pstart;
93 unsigned long initrd_pend;
94
95 initrd_pstart = CPHYSADDR(initrd_start);
96 initrd_pend = CPHYSADDR(initrd_end);
97 if (initrd_start &&
98 ((initrd_pstart > MAX_RAM_SIZE)
99 || (initrd_pend > MAX_RAM_SIZE))) {
100 panic("initrd out of addressable memory");
101 }
102
103#endif
104
105 for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
106 idx++) {
107 rd_flag = 0;
108 if (type == CFE_MI_AVAILABLE) {
109
110
111
112
113#ifdef CONFIG_BLK_DEV_INITRD
114 if (initrd_start) {
115 if ((initrd_pstart > addr) &&
116 (initrd_pstart < (addr + size))) {
117 memblock_add(addr,
118 initrd_pstart - addr);
119 rd_flag = 1;
120 }
121 if ((initrd_pend > addr) &&
122 (initrd_pend < (addr + size))) {
123 memblock_add(initrd_pend,
124 (addr + size) - initrd_pend);
125 rd_flag = 1;
126 }
127 }
128#endif
129 if (!rd_flag) {
130 if (addr > MAX_RAM_SIZE)
131 continue;
132 if (addr+size > MAX_RAM_SIZE)
133 size = MAX_RAM_SIZE - (addr+size) + 1;
134
135
136
137
138
139
140
141 if (size > 512)
142 size -= 512;
143 memblock_add(addr, size);
144 }
145 board_mem_region_addrs[board_mem_region_count] = addr;
146 board_mem_region_sizes[board_mem_region_count] = size;
147 board_mem_region_count++;
148 if (board_mem_region_count ==
149 SIBYTE_MAX_MEM_REGIONS) {
150
151
152
153 while(1);
154 }
155 }
156 }
157#ifdef CONFIG_BLK_DEV_INITRD
158 if (initrd_start) {
159 memblock_add(initrd_pstart, initrd_pend - initrd_pstart);
160 memblock_reserve(initrd_pstart, initrd_pend - initrd_pstart);
161 }
162#endif
163}
164
165#ifdef CONFIG_BLK_DEV_INITRD
166static int __init initrd_setup(char *str)
167{
168 char rdarg[64];
169 int idx;
170 char *tmp, *endptr;
171 unsigned long initrd_size;
172
173
174 for (idx = 0; idx < sizeof(rdarg)-1; idx++) {
175 if (!str[idx] || (str[idx] == ' ')) break;
176 rdarg[idx] = str[idx];
177 }
178
179 rdarg[idx] = 0;
180 str = rdarg;
181
182
183
184
185
186 for (tmp = str; *tmp != '@'; tmp++) {
187 if (!*tmp) {
188 goto fail;
189 }
190 }
191 *tmp = 0;
192 tmp++;
193 if (!*tmp) {
194 goto fail;
195 }
196 initrd_size = simple_strtoul(str, &endptr, 16);
197 if (*endptr) {
198 *(tmp-1) = '@';
199 goto fail;
200 }
201 *(tmp-1) = '@';
202 initrd_start = simple_strtoul(tmp, &endptr, 16);
203 if (*endptr) {
204 goto fail;
205 }
206 initrd_end = initrd_start + initrd_size;
207 printk("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
208 return 1;
209 fail:
210 printk("Bad initrd argument. Disabling initrd\n");
211 initrd_start = 0;
212 initrd_end = 0;
213 return 1;
214}
215
216#endif
217
218extern const struct plat_smp_ops sb_smp_ops;
219extern const struct plat_smp_ops bcm1480_smp_ops;
220
221
222
223
224void __init prom_init(void)
225{
226 uint64_t cfe_ept, cfe_handle;
227 unsigned int cfe_eptseal;
228 int argc = fw_arg0;
229 char **envp = (char **) fw_arg2;
230 int *prom_vec = (int *) fw_arg3;
231
232 _machine_restart = cfe_linux_restart;
233 _machine_halt = cfe_linux_halt;
234 pm_power_off = cfe_linux_halt;
235
236
237
238
239
240 if (argc < 0) {
241 cfe_handle = (uint64_t)(long)argc;
242 cfe_ept = (long)envp;
243 cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
244 } else {
245 if ((int32_t)(long)prom_vec < 0) {
246
247
248
249
250
251 cfe_handle = (uint64_t)(long)prom_vec;
252 cfe_ept = (uint64_t)((int32_t)0x9fc00500);
253 cfe_eptseal = CFE_EPTSEAL;
254 } else {
255
256
257
258
259
260 cfe_handle = (uint64_t)((int32_t *)prom_vec)[0];
261 cfe_ept = (uint64_t)((int32_t *)prom_vec)[2];
262 cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
263 }
264 }
265 if (cfe_eptseal != CFE_EPTSEAL) {
266
267 printk("CFE's entrypoint seal doesn't match. Spinning.");
268 while (1) ;
269 }
270 cfe_init(cfe_handle, cfe_ept);
271
272
273
274
275 cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
276 if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, COMMAND_LINE_SIZE) < 0) {
277 if (argc >= 0) {
278
279
280 printk("LINUX_CMDLINE not defined in cfe.");
281 while (1) ;
282 }
283 }
284
285#ifdef CONFIG_BLK_DEV_INITRD
286 {
287 char *ptr;
288
289
290 for (ptr = arcs_cmdline; *ptr; ptr++) {
291 while (*ptr == ' ') {
292 ptr++;
293 }
294 if (!strncmp(ptr, "initrd=", 7)) {
295 initrd_setup(ptr+7);
296 break;
297 } else {
298 while (*ptr && (*ptr != ' ')) {
299 ptr++;
300 }
301 }
302 }
303 }
304#endif
305
306
307 arcs_cmdline[COMMAND_LINE_SIZE-1] = 0;
308
309 prom_meminit();
310
311#if defined(CONFIG_SIBYTE_BCM112X) || defined(CONFIG_SIBYTE_SB1250)
312 register_smp_ops(&sb_smp_ops);
313#endif
314#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
315 register_smp_ops(&bcm1480_smp_ops);
316#endif
317}
318
319void prom_putchar(char c)
320{
321 int ret;
322
323 while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)
324 ;
325}
326