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