sibyte cleanups
[openwrt/svn-archive/archive.git] / target / linux / sibyte / patches / 002-sibyte_remove_standalone_support.patch
1 CFE is the only supported and used bootloader on the SiByte boards,
2 the standalone kernel support has been never used outside Broadcom.
3 Remove it and make the kernel use CFE by default.
4
5 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
6
7 --- a/arch/mips/Makefile
8 +++ b/arch/mips/Makefile
9 @@ -167,7 +167,6 @@ libs-$(CONFIG_ARC) += arch/mips/fw/arc/
10 libs-$(CONFIG_CFE) += arch/mips/fw/cfe/
11 libs-$(CONFIG_SNIPROM) += arch/mips/fw/sni/
12 libs-y += arch/mips/fw/lib/
13 -libs-$(CONFIG_SIBYTE_CFE) += arch/mips/sibyte/cfe/
14
15 #
16 # Board-dependent options and extra files
17 --- a/arch/mips/sibyte/cfe/console.c
18 +++ /dev/null
19 @@ -1,79 +0,0 @@
20 -#include <linux/init.h>
21 -#include <linux/errno.h>
22 -#include <linux/console.h>
23 -
24 -#include <asm/sibyte/board.h>
25 -
26 -#include <asm/fw/cfe/cfe_api.h>
27 -#include <asm/fw/cfe/cfe_error.h>
28 -
29 -extern int cfe_cons_handle;
30 -
31 -static void cfe_console_write(struct console *cons, const char *str,
32 - unsigned int count)
33 -{
34 - int i, last, written;
35 -
36 - for (i=0, last=0; i<count; i++) {
37 - if (!str[i])
38 - /* XXXKW can/should this ever happen? */
39 - return;
40 - if (str[i] == '\n') {
41 - do {
42 - written = cfe_write(cfe_cons_handle, &str[last], i-last);
43 - if (written < 0)
44 - ;
45 - last += written;
46 - } while (last < i);
47 - while (cfe_write(cfe_cons_handle, "\r", 1) <= 0)
48 - ;
49 - }
50 - }
51 - if (last != count) {
52 - do {
53 - written = cfe_write(cfe_cons_handle, &str[last], count-last);
54 - if (written < 0)
55 - ;
56 - last += written;
57 - } while (last < count);
58 - }
59 -
60 -}
61 -
62 -static int cfe_console_setup(struct console *cons, char *str)
63 -{
64 - char consdev[32];
65 - /* XXXKW think about interaction with 'console=' cmdline arg */
66 - /* If none of the console options are configured, the build will break. */
67 - if (cfe_getenv("BOOT_CONSOLE", consdev, 32) >= 0) {
68 -#ifdef CONFIG_SERIAL_SB1250_DUART
69 - if (!strcmp(consdev, "uart0")) {
70 - setleds("u0cn");
71 - } else if (!strcmp(consdev, "uart1")) {
72 - setleds("u1cn");
73 -#endif
74 -#ifdef CONFIG_VGA_CONSOLE
75 - } else if (!strcmp(consdev, "pcconsole0")) {
76 - setleds("pccn");
77 -#endif
78 - } else
79 - return -ENODEV;
80 - }
81 - return 0;
82 -}
83 -
84 -static struct console sb1250_cfe_cons = {
85 - .name = "cfe",
86 - .write = cfe_console_write,
87 - .setup = cfe_console_setup,
88 - .flags = CON_PRINTBUFFER,
89 - .index = -1,
90 -};
91 -
92 -static int __init sb1250_cfe_console_init(void)
93 -{
94 - register_console(&sb1250_cfe_cons);
95 - return 0;
96 -}
97 -
98 -console_initcall(sb1250_cfe_console_init);
99 --- a/arch/mips/sibyte/cfe/Makefile
100 +++ /dev/null
101 @@ -1,2 +0,0 @@
102 -lib-y = setup.o
103 -lib-$(CONFIG_SIBYTE_CFE_CONSOLE) += console.o
104 --- a/arch/mips/sibyte/cfe/setup.c
105 +++ /dev/null
106 @@ -1,350 +0,0 @@
107 -/*
108 - * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
109 - *
110 - * This program is free software; you can redistribute it and/or
111 - * modify it under the terms of the GNU General Public License
112 - * as published by the Free Software Foundation; either version 2
113 - * of the License, or (at your option) any later version.
114 - *
115 - * This program is distributed in the hope that it will be useful,
116 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
117 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118 - * GNU General Public License for more details.
119 - *
120 - * You should have received a copy of the GNU General Public License
121 - * along with this program; if not, write to the Free Software
122 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
123 - */
124 -
125 -#include <linux/init.h>
126 -#include <linux/kernel.h>
127 -#include <linux/linkage.h>
128 -#include <linux/mm.h>
129 -#include <linux/blkdev.h>
130 -#include <linux/bootmem.h>
131 -#include <linux/pm.h>
132 -#include <linux/smp.h>
133 -
134 -#include <asm/bootinfo.h>
135 -#include <asm/reboot.h>
136 -#include <asm/sibyte/board.h>
137 -#include <asm/smp-ops.h>
138 -
139 -#include <asm/fw/cfe/cfe_api.h>
140 -#include <asm/fw/cfe/cfe_error.h>
141 -
142 -/* Max ram addressable in 32-bit segments */
143 -#ifdef CONFIG_64BIT
144 -#define MAX_RAM_SIZE (~0ULL)
145 -#else
146 -#ifdef CONFIG_HIGHMEM
147 -#ifdef CONFIG_64BIT_PHYS_ADDR
148 -#define MAX_RAM_SIZE (~0ULL)
149 -#else
150 -#define MAX_RAM_SIZE (0xffffffffULL)
151 -#endif
152 -#else
153 -#define MAX_RAM_SIZE (0x1fffffffULL)
154 -#endif
155 -#endif
156 -
157 -#define SIBYTE_MAX_MEM_REGIONS 8
158 -phys_t board_mem_region_addrs[SIBYTE_MAX_MEM_REGIONS];
159 -phys_t board_mem_region_sizes[SIBYTE_MAX_MEM_REGIONS];
160 -unsigned int board_mem_region_count;
161 -
162 -int cfe_cons_handle;
163 -
164 -#ifdef CONFIG_BLK_DEV_INITRD
165 -extern unsigned long initrd_start, initrd_end;
166 -#endif
167 -
168 -static void __noreturn cfe_linux_exit(void *arg)
169 -{
170 - int warm = *(int *)arg;
171 -
172 - if (smp_processor_id()) {
173 - static int reboot_smp;
174 -
175 - /* Don't repeat the process from another CPU */
176 - if (!reboot_smp) {
177 - /* Get CPU 0 to do the cfe_exit */
178 - reboot_smp = 1;
179 - smp_call_function(cfe_linux_exit, arg, 0);
180 - }
181 - } else {
182 - printk("Passing control back to CFE...\n");
183 - cfe_exit(warm, 0);
184 - printk("cfe_exit returned??\n");
185 - }
186 - while (1);
187 -}
188 -
189 -static void __noreturn cfe_linux_restart(char *command)
190 -{
191 - static const int zero;
192 -
193 - cfe_linux_exit((void *)&zero);
194 -}
195 -
196 -static void __noreturn cfe_linux_halt(void)
197 -{
198 - static const int one = 1;
199 -
200 - cfe_linux_exit((void *)&one);
201 -}
202 -
203 -static __init void prom_meminit(void)
204 -{
205 - u64 addr, size, type; /* regardless of 64BIT_PHYS_ADDR */
206 - int mem_flags = 0;
207 - unsigned int idx;
208 - int rd_flag;
209 -#ifdef CONFIG_BLK_DEV_INITRD
210 - unsigned long initrd_pstart;
211 - unsigned long initrd_pend;
212 -
213 - initrd_pstart = CPHYSADDR(initrd_start);
214 - initrd_pend = CPHYSADDR(initrd_end);
215 - if (initrd_start &&
216 - ((initrd_pstart > MAX_RAM_SIZE)
217 - || (initrd_pend > MAX_RAM_SIZE))) {
218 - panic("initrd out of addressable memory");
219 - }
220 -
221 -#endif /* INITRD */
222 -
223 - for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
224 - idx++) {
225 - rd_flag = 0;
226 - if (type == CFE_MI_AVAILABLE) {
227 - /*
228 - * See if this block contains (any portion of) the
229 - * ramdisk
230 - */
231 -#ifdef CONFIG_BLK_DEV_INITRD
232 - if (initrd_start) {
233 - if ((initrd_pstart > addr) &&
234 - (initrd_pstart < (addr + size))) {
235 - add_memory_region(addr,
236 - initrd_pstart - addr,
237 - BOOT_MEM_RAM);
238 - rd_flag = 1;
239 - }
240 - if ((initrd_pend > addr) &&
241 - (initrd_pend < (addr + size))) {
242 - add_memory_region(initrd_pend,
243 - (addr + size) - initrd_pend,
244 - BOOT_MEM_RAM);
245 - rd_flag = 1;
246 - }
247 - }
248 -#endif
249 - if (!rd_flag) {
250 - if (addr > MAX_RAM_SIZE)
251 - continue;
252 - if (addr+size > MAX_RAM_SIZE)
253 - size = MAX_RAM_SIZE - (addr+size) + 1;
254 - /*
255 - * memcpy/__copy_user prefetch, which
256 - * will cause a bus error for
257 - * KSEG/KUSEG addrs not backed by RAM.
258 - * Hence, reserve some padding for the
259 - * prefetch distance.
260 - */
261 - if (size > 512)
262 - size -= 512;
263 - add_memory_region(addr, size, BOOT_MEM_RAM);
264 - }
265 - board_mem_region_addrs[board_mem_region_count] = addr;
266 - board_mem_region_sizes[board_mem_region_count] = size;
267 - board_mem_region_count++;
268 - if (board_mem_region_count ==
269 - SIBYTE_MAX_MEM_REGIONS) {
270 - /*
271 - * Too many regions. Need to configure more
272 - */
273 - while(1);
274 - }
275 - }
276 - }
277 -#ifdef CONFIG_BLK_DEV_INITRD
278 - if (initrd_start) {
279 - add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
280 - BOOT_MEM_RESERVED);
281 - }
282 -#endif
283 -}
284 -
285 -#ifdef CONFIG_BLK_DEV_INITRD
286 -static int __init initrd_setup(char *str)
287 -{
288 - char rdarg[64];
289 - int idx;
290 - char *tmp, *endptr;
291 - unsigned long initrd_size;
292 -
293 - /* Make a copy of the initrd argument so we can smash it up here */
294 - for (idx = 0; idx < sizeof(rdarg)-1; idx++) {
295 - if (!str[idx] || (str[idx] == ' ')) break;
296 - rdarg[idx] = str[idx];
297 - }
298 -
299 - rdarg[idx] = 0;
300 - str = rdarg;
301 -
302 - /*
303 - *Initrd location comes in the form "<hex size of ramdisk in bytes>@<location in memory>"
304 - * e.g. initrd=3abfd@80010000. This is set up by the loader.
305 - */
306 - for (tmp = str; *tmp != '@'; tmp++) {
307 - if (!*tmp) {
308 - goto fail;
309 - }
310 - }
311 - *tmp = 0;
312 - tmp++;
313 - if (!*tmp) {
314 - goto fail;
315 - }
316 - initrd_size = simple_strtoul(str, &endptr, 16);
317 - if (*endptr) {
318 - *(tmp-1) = '@';
319 - goto fail;
320 - }
321 - *(tmp-1) = '@';
322 - initrd_start = simple_strtoul(tmp, &endptr, 16);
323 - if (*endptr) {
324 - goto fail;
325 - }
326 - initrd_end = initrd_start + initrd_size;
327 - printk("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
328 - return 1;
329 - fail:
330 - printk("Bad initrd argument. Disabling initrd\n");
331 - initrd_start = 0;
332 - initrd_end = 0;
333 - return 1;
334 -}
335 -
336 -#endif
337 -
338 -extern struct plat_smp_ops sb_smp_ops;
339 -extern struct plat_smp_ops bcm1480_smp_ops;
340 -
341 -/*
342 - * prom_init is called just after the cpu type is determined, from setup_arch()
343 - */
344 -void __init prom_init(void)
345 -{
346 - uint64_t cfe_ept, cfe_handle;
347 - unsigned int cfe_eptseal;
348 - int argc = fw_arg0;
349 - char **envp = (char **) fw_arg2;
350 - int *prom_vec = (int *) fw_arg3;
351 -
352 - _machine_restart = cfe_linux_restart;
353 - _machine_halt = cfe_linux_halt;
354 - pm_power_off = cfe_linux_halt;
355 -
356 - /*
357 - * Check if a loader was used; if NOT, the 4 arguments are
358 - * what CFE gives us (handle, 0, EPT and EPTSEAL)
359 - */
360 - if (argc < 0) {
361 - cfe_handle = (uint64_t)(long)argc;
362 - cfe_ept = (long)envp;
363 - cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
364 - } else {
365 - if ((int32_t)(long)prom_vec < 0) {
366 - /*
367 - * Old loader; all it gives us is the handle,
368 - * so use the "known" entrypoint and assume
369 - * the seal.
370 - */
371 - cfe_handle = (uint64_t)(long)prom_vec;
372 - cfe_ept = (uint64_t)((int32_t)0x9fc00500);
373 - cfe_eptseal = CFE_EPTSEAL;
374 - } else {
375 - /*
376 - * Newer loaders bundle the handle/ept/eptseal
377 - * Note: prom_vec is in the loader's useg
378 - * which is still alive in the TLB.
379 - */
380 - cfe_handle = (uint64_t)((int32_t *)prom_vec)[0];
381 - cfe_ept = (uint64_t)((int32_t *)prom_vec)[2];
382 - cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
383 - }
384 - }
385 - if (cfe_eptseal != CFE_EPTSEAL) {
386 - /* too early for panic to do any good */
387 - printk("CFE's entrypoint seal doesn't match. Spinning.");
388 - while (1) ;
389 - }
390 - cfe_init(cfe_handle, cfe_ept);
391 - /*
392 - * Get the handle for (at least) prom_putchar, possibly for
393 - * boot console
394 - */
395 - cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
396 - if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, CL_SIZE) < 0) {
397 - if (argc < 0) {
398 - /*
399 - * It's OK for direct boot to not provide a
400 - * command line
401 - */
402 - strcpy(arcs_cmdline, "root=/dev/ram0 ");
403 - } else {
404 - /* The loader should have set the command line */
405 - /* too early for panic to do any good */
406 - printk("LINUX_CMDLINE not defined in cfe.");
407 - while (1) ;
408 - }
409 - }
410 -
411 -#ifdef CONFIG_BLK_DEV_INITRD
412 - {
413 - char *ptr;
414 - /* Need to find out early whether we've got an initrd. So scan
415 - the list looking now */
416 - for (ptr = arcs_cmdline; *ptr; ptr++) {
417 - while (*ptr == ' ') {
418 - ptr++;
419 - }
420 - if (!strncmp(ptr, "initrd=", 7)) {
421 - initrd_setup(ptr+7);
422 - break;
423 - } else {
424 - while (*ptr && (*ptr != ' ')) {
425 - ptr++;
426 - }
427 - }
428 - }
429 - }
430 -#endif /* CONFIG_BLK_DEV_INITRD */
431 -
432 - /* Not sure this is needed, but it's the safe way. */
433 - arcs_cmdline[CL_SIZE-1] = 0;
434 -
435 - prom_meminit();
436 -
437 -#if defined(CONFIG_SIBYTE_BCM112X) || defined(CONFIG_SIBYTE_SB1250)
438 - register_smp_ops(&sb_smp_ops);
439 -#endif
440 -#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
441 - register_smp_ops(&bcm1480_smp_ops);
442 -#endif
443 -}
444 -
445 -void __init prom_free_prom_memory(void)
446 -{
447 - /* Not sure what I'm supposed to do here. Nothing, I think */
448 -}
449 -
450 -void prom_putchar(char c)
451 -{
452 - int ret;
453 -
454 - while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)
455 - ;
456 -}
457 --- /dev/null
458 +++ b/arch/mips/sibyte/common/cfe.c
459 @@ -0,0 +1,350 @@
460 +/*
461 + * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
462 + *
463 + * This program is free software; you can redistribute it and/or
464 + * modify it under the terms of the GNU General Public License
465 + * as published by the Free Software Foundation; either version 2
466 + * of the License, or (at your option) any later version.
467 + *
468 + * This program is distributed in the hope that it will be useful,
469 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
470 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
471 + * GNU General Public License for more details.
472 + *
473 + * You should have received a copy of the GNU General Public License
474 + * along with this program; if not, write to the Free Software
475 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
476 + */
477 +
478 +#include <linux/init.h>
479 +#include <linux/kernel.h>
480 +#include <linux/linkage.h>
481 +#include <linux/mm.h>
482 +#include <linux/blkdev.h>
483 +#include <linux/bootmem.h>
484 +#include <linux/pm.h>
485 +#include <linux/smp.h>
486 +
487 +#include <asm/bootinfo.h>
488 +#include <asm/reboot.h>
489 +#include <asm/sibyte/board.h>
490 +#include <asm/smp-ops.h>
491 +
492 +#include <asm/fw/cfe/cfe_api.h>
493 +#include <asm/fw/cfe/cfe_error.h>
494 +
495 +/* Max ram addressable in 32-bit segments */
496 +#ifdef CONFIG_64BIT
497 +#define MAX_RAM_SIZE (~0ULL)
498 +#else
499 +#ifdef CONFIG_HIGHMEM
500 +#ifdef CONFIG_64BIT_PHYS_ADDR
501 +#define MAX_RAM_SIZE (~0ULL)
502 +#else
503 +#define MAX_RAM_SIZE (0xffffffffULL)
504 +#endif
505 +#else
506 +#define MAX_RAM_SIZE (0x1fffffffULL)
507 +#endif
508 +#endif
509 +
510 +#define SIBYTE_MAX_MEM_REGIONS 8
511 +phys_t board_mem_region_addrs[SIBYTE_MAX_MEM_REGIONS];
512 +phys_t board_mem_region_sizes[SIBYTE_MAX_MEM_REGIONS];
513 +unsigned int board_mem_region_count;
514 +
515 +int cfe_cons_handle;
516 +
517 +#ifdef CONFIG_BLK_DEV_INITRD
518 +extern unsigned long initrd_start, initrd_end;
519 +#endif
520 +
521 +static void __noreturn cfe_linux_exit(void *arg)
522 +{
523 + int warm = *(int *)arg;
524 +
525 + if (smp_processor_id()) {
526 + static int reboot_smp;
527 +
528 + /* Don't repeat the process from another CPU */
529 + if (!reboot_smp) {
530 + /* Get CPU 0 to do the cfe_exit */
531 + reboot_smp = 1;
532 + smp_call_function(cfe_linux_exit, arg, 0);
533 + }
534 + } else {
535 + printk("Passing control back to CFE...\n");
536 + cfe_exit(warm, 0);
537 + printk("cfe_exit returned??\n");
538 + }
539 + while (1);
540 +}
541 +
542 +static void __noreturn cfe_linux_restart(char *command)
543 +{
544 + static const int zero;
545 +
546 + cfe_linux_exit((void *)&zero);
547 +}
548 +
549 +static void __noreturn cfe_linux_halt(void)
550 +{
551 + static const int one = 1;
552 +
553 + cfe_linux_exit((void *)&one);
554 +}
555 +
556 +static __init void prom_meminit(void)
557 +{
558 + u64 addr, size, type; /* regardless of 64BIT_PHYS_ADDR */
559 + int mem_flags = 0;
560 + unsigned int idx;
561 + int rd_flag;
562 +#ifdef CONFIG_BLK_DEV_INITRD
563 + unsigned long initrd_pstart;
564 + unsigned long initrd_pend;
565 +
566 + initrd_pstart = CPHYSADDR(initrd_start);
567 + initrd_pend = CPHYSADDR(initrd_end);
568 + if (initrd_start &&
569 + ((initrd_pstart > MAX_RAM_SIZE)
570 + || (initrd_pend > MAX_RAM_SIZE))) {
571 + panic("initrd out of addressable memory");
572 + }
573 +
574 +#endif /* INITRD */
575 +
576 + for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
577 + idx++) {
578 + rd_flag = 0;
579 + if (type == CFE_MI_AVAILABLE) {
580 + /*
581 + * See if this block contains (any portion of) the
582 + * ramdisk
583 + */
584 +#ifdef CONFIG_BLK_DEV_INITRD
585 + if (initrd_start) {
586 + if ((initrd_pstart > addr) &&
587 + (initrd_pstart < (addr + size))) {
588 + add_memory_region(addr,
589 + initrd_pstart - addr,
590 + BOOT_MEM_RAM);
591 + rd_flag = 1;
592 + }
593 + if ((initrd_pend > addr) &&
594 + (initrd_pend < (addr + size))) {
595 + add_memory_region(initrd_pend,
596 + (addr + size) - initrd_pend,
597 + BOOT_MEM_RAM);
598 + rd_flag = 1;
599 + }
600 + }
601 +#endif
602 + if (!rd_flag) {
603 + if (addr > MAX_RAM_SIZE)
604 + continue;
605 + if (addr+size > MAX_RAM_SIZE)
606 + size = MAX_RAM_SIZE - (addr+size) + 1;
607 + /*
608 + * memcpy/__copy_user prefetch, which
609 + * will cause a bus error for
610 + * KSEG/KUSEG addrs not backed by RAM.
611 + * Hence, reserve some padding for the
612 + * prefetch distance.
613 + */
614 + if (size > 512)
615 + size -= 512;
616 + add_memory_region(addr, size, BOOT_MEM_RAM);
617 + }
618 + board_mem_region_addrs[board_mem_region_count] = addr;
619 + board_mem_region_sizes[board_mem_region_count] = size;
620 + board_mem_region_count++;
621 + if (board_mem_region_count ==
622 + SIBYTE_MAX_MEM_REGIONS) {
623 + /*
624 + * Too many regions. Need to configure more
625 + */
626 + while(1);
627 + }
628 + }
629 + }
630 +#ifdef CONFIG_BLK_DEV_INITRD
631 + if (initrd_start) {
632 + add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
633 + BOOT_MEM_RESERVED);
634 + }
635 +#endif
636 +}
637 +
638 +#ifdef CONFIG_BLK_DEV_INITRD
639 +static int __init initrd_setup(char *str)
640 +{
641 + char rdarg[64];
642 + int idx;
643 + char *tmp, *endptr;
644 + unsigned long initrd_size;
645 +
646 + /* Make a copy of the initrd argument so we can smash it up here */
647 + for (idx = 0; idx < sizeof(rdarg)-1; idx++) {
648 + if (!str[idx] || (str[idx] == ' ')) break;
649 + rdarg[idx] = str[idx];
650 + }
651 +
652 + rdarg[idx] = 0;
653 + str = rdarg;
654 +
655 + /*
656 + *Initrd location comes in the form "<hex size of ramdisk in bytes>@<location in memory>"
657 + * e.g. initrd=3abfd@80010000. This is set up by the loader.
658 + */
659 + for (tmp = str; *tmp != '@'; tmp++) {
660 + if (!*tmp) {
661 + goto fail;
662 + }
663 + }
664 + *tmp = 0;
665 + tmp++;
666 + if (!*tmp) {
667 + goto fail;
668 + }
669 + initrd_size = simple_strtoul(str, &endptr, 16);
670 + if (*endptr) {
671 + *(tmp-1) = '@';
672 + goto fail;
673 + }
674 + *(tmp-1) = '@';
675 + initrd_start = simple_strtoul(tmp, &endptr, 16);
676 + if (*endptr) {
677 + goto fail;
678 + }
679 + initrd_end = initrd_start + initrd_size;
680 + printk("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
681 + return 1;
682 + fail:
683 + printk("Bad initrd argument. Disabling initrd\n");
684 + initrd_start = 0;
685 + initrd_end = 0;
686 + return 1;
687 +}
688 +
689 +#endif
690 +
691 +extern struct plat_smp_ops sb_smp_ops;
692 +extern struct plat_smp_ops bcm1480_smp_ops;
693 +
694 +/*
695 + * prom_init is called just after the cpu type is determined, from setup_arch()
696 + */
697 +void __init prom_init(void)
698 +{
699 + uint64_t cfe_ept, cfe_handle;
700 + unsigned int cfe_eptseal;
701 + int argc = fw_arg0;
702 + char **envp = (char **) fw_arg2;
703 + int *prom_vec = (int *) fw_arg3;
704 +
705 + _machine_restart = cfe_linux_restart;
706 + _machine_halt = cfe_linux_halt;
707 + pm_power_off = cfe_linux_halt;
708 +
709 + /*
710 + * Check if a loader was used; if NOT, the 4 arguments are
711 + * what CFE gives us (handle, 0, EPT and EPTSEAL)
712 + */
713 + if (argc < 0) {
714 + cfe_handle = (uint64_t)(long)argc;
715 + cfe_ept = (long)envp;
716 + cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
717 + } else {
718 + if ((int32_t)(long)prom_vec < 0) {
719 + /*
720 + * Old loader; all it gives us is the handle,
721 + * so use the "known" entrypoint and assume
722 + * the seal.
723 + */
724 + cfe_handle = (uint64_t)(long)prom_vec;
725 + cfe_ept = (uint64_t)((int32_t)0x9fc00500);
726 + cfe_eptseal = CFE_EPTSEAL;
727 + } else {
728 + /*
729 + * Newer loaders bundle the handle/ept/eptseal
730 + * Note: prom_vec is in the loader's useg
731 + * which is still alive in the TLB.
732 + */
733 + cfe_handle = (uint64_t)((int32_t *)prom_vec)[0];
734 + cfe_ept = (uint64_t)((int32_t *)prom_vec)[2];
735 + cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
736 + }
737 + }
738 + if (cfe_eptseal != CFE_EPTSEAL) {
739 + /* too early for panic to do any good */
740 + printk("CFE's entrypoint seal doesn't match. Spinning.");
741 + while (1) ;
742 + }
743 + cfe_init(cfe_handle, cfe_ept);
744 + /*
745 + * Get the handle for (at least) prom_putchar, possibly for
746 + * boot console
747 + */
748 + cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
749 + if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, CL_SIZE) < 0) {
750 + if (argc < 0) {
751 + /*
752 + * It's OK for direct boot to not provide a
753 + * command line
754 + */
755 + strcpy(arcs_cmdline, "root=/dev/ram0 ");
756 + } else {
757 + /* The loader should have set the command line */
758 + /* too early for panic to do any good */
759 + printk("LINUX_CMDLINE not defined in cfe.");
760 + while (1) ;
761 + }
762 + }
763 +
764 +#ifdef CONFIG_BLK_DEV_INITRD
765 + {
766 + char *ptr;
767 + /* Need to find out early whether we've got an initrd. So scan
768 + the list looking now */
769 + for (ptr = arcs_cmdline; *ptr; ptr++) {
770 + while (*ptr == ' ') {
771 + ptr++;
772 + }
773 + if (!strncmp(ptr, "initrd=", 7)) {
774 + initrd_setup(ptr+7);
775 + break;
776 + } else {
777 + while (*ptr && (*ptr != ' ')) {
778 + ptr++;
779 + }
780 + }
781 + }
782 + }
783 +#endif /* CONFIG_BLK_DEV_INITRD */
784 +
785 + /* Not sure this is needed, but it's the safe way. */
786 + arcs_cmdline[CL_SIZE-1] = 0;
787 +
788 + prom_meminit();
789 +
790 +#if defined(CONFIG_SIBYTE_BCM112X) || defined(CONFIG_SIBYTE_SB1250)
791 + register_smp_ops(&sb_smp_ops);
792 +#endif
793 +#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
794 + register_smp_ops(&bcm1480_smp_ops);
795 +#endif
796 +}
797 +
798 +void __init prom_free_prom_memory(void)
799 +{
800 + /* Not sure what I'm supposed to do here. Nothing, I think */
801 +}
802 +
803 +void prom_putchar(char c)
804 +{
805 + int ret;
806 +
807 + while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)
808 + ;
809 +}
810 --- /dev/null
811 +++ b/arch/mips/sibyte/common/cfe_console.c
812 @@ -0,0 +1,79 @@
813 +#include <linux/init.h>
814 +#include <linux/errno.h>
815 +#include <linux/console.h>
816 +
817 +#include <asm/sibyte/board.h>
818 +
819 +#include <asm/fw/cfe/cfe_api.h>
820 +#include <asm/fw/cfe/cfe_error.h>
821 +
822 +extern int cfe_cons_handle;
823 +
824 +static void cfe_console_write(struct console *cons, const char *str,
825 + unsigned int count)
826 +{
827 + int i, last, written;
828 +
829 + for (i=0, last=0; i<count; i++) {
830 + if (!str[i])
831 + /* XXXKW can/should this ever happen? */
832 + return;
833 + if (str[i] == '\n') {
834 + do {
835 + written = cfe_write(cfe_cons_handle, &str[last], i-last);
836 + if (written < 0)
837 + ;
838 + last += written;
839 + } while (last < i);
840 + while (cfe_write(cfe_cons_handle, "\r", 1) <= 0)
841 + ;
842 + }
843 + }
844 + if (last != count) {
845 + do {
846 + written = cfe_write(cfe_cons_handle, &str[last], count-last);
847 + if (written < 0)
848 + ;
849 + last += written;
850 + } while (last < count);
851 + }
852 +
853 +}
854 +
855 +static int cfe_console_setup(struct console *cons, char *str)
856 +{
857 + char consdev[32];
858 + /* XXXKW think about interaction with 'console=' cmdline arg */
859 + /* If none of the console options are configured, the build will break. */
860 + if (cfe_getenv("BOOT_CONSOLE", consdev, 32) >= 0) {
861 +#ifdef CONFIG_SERIAL_SB1250_DUART
862 + if (!strcmp(consdev, "uart0")) {
863 + setleds("u0cn");
864 + } else if (!strcmp(consdev, "uart1")) {
865 + setleds("u1cn");
866 +#endif
867 +#ifdef CONFIG_VGA_CONSOLE
868 + } else if (!strcmp(consdev, "pcconsole0")) {
869 + setleds("pccn");
870 +#endif
871 + } else
872 + return -ENODEV;
873 + }
874 + return 0;
875 +}
876 +
877 +static struct console sb1250_cfe_cons = {
878 + .name = "cfe",
879 + .write = cfe_console_write,
880 + .setup = cfe_console_setup,
881 + .flags = CON_PRINTBUFFER,
882 + .index = -1,
883 +};
884 +
885 +static int __init sb1250_cfe_console_init(void)
886 +{
887 + register_console(&sb1250_cfe_cons);
888 + return 0;
889 +}
890 +
891 +console_initcall(sb1250_cfe_console_init);
892 --- a/arch/mips/sibyte/common/Makefile
893 +++ b/arch/mips/sibyte/common/Makefile
894 @@ -1,5 +1,5 @@
895 -obj-y :=
896 -
897 +obj-y := cfe.o
898 +obj-$(CONFIG_SIBYTE_CFE_CONSOLE) += cfe_console.o
899 obj-$(CONFIG_SIBYTE_TBPROF) += sb_tbprof.o
900
901 EXTRA_CFLAGS += -Werror
902 --- a/arch/mips/sibyte/Kconfig
903 +++ b/arch/mips/sibyte/Kconfig
904 @@ -75,6 +75,8 @@ config SIBYTE_SB1xxx_SOC
905 select SWAP_IO_SPACE
906 select SYS_SUPPORTS_32BIT_KERNEL
907 select SYS_SUPPORTS_64BIT_KERNEL
908 + select CFE
909 + select SYS_HAS_EARLY_PRINTK
910
911 choice
912 prompt "SiByte SOC Stepping"
913 @@ -136,34 +138,14 @@ config SB1_CERR_STALL
914 bool "Stall (rather than panic) on fatal cache error"
915 depends on SIBYTE_SB1xxx_SOC
916
917 -config SIBYTE_CFE
918 - bool "Booting from CFE"
919 - depends on SIBYTE_SB1xxx_SOC
920 - select CFE
921 - select SYS_HAS_EARLY_PRINTK
922 - help
923 - Make use of the CFE API for enumerating available memory,
924 - controlling secondary CPUs, and possibly console output.
925 -
926 config SIBYTE_CFE_CONSOLE
927 bool "Use firmware console"
928 - depends on SIBYTE_CFE
929 + depends on SIBYTE_SB1xxx_SOC
930 help
931 Use the CFE API's console write routines during boot. Other console
932 options (VT console, sb1250 duart console, etc.) should not be
933 configured.
934
935 -config SIBYTE_STANDALONE
936 - bool
937 - depends on SIBYTE_SB1xxx_SOC && !SIBYTE_CFE
938 - select SYS_HAS_EARLY_PRINTK
939 - default y
940 -
941 -config SIBYTE_STANDALONE_RAM_SIZE
942 - int "Memory size (in megabytes)"
943 - depends on SIBYTE_STANDALONE
944 - default "32"
945 -
946 config SIBYTE_BUS_WATCHER
947 bool "Support for Bus Watcher statistics"
948 depends on SIBYTE_SB1xxx_SOC
949 --- a/arch/mips/sibyte/sb1250/Makefile
950 +++ b/arch/mips/sibyte/sb1250/Makefile
951 @@ -1,7 +1,6 @@
952 obj-y := setup.o irq.o time.o
953
954 obj-$(CONFIG_SMP) += smp.o
955 -obj-$(CONFIG_SIBYTE_STANDALONE) += prom.o
956 obj-$(CONFIG_SIBYTE_BUS_WATCHER) += bus_watcher.o
957
958 EXTRA_CFLAGS += -Werror
959 --- a/arch/mips/sibyte/sb1250/prom.c
960 +++ /dev/null
961 @@ -1,96 +0,0 @@
962 -/*
963 - * Copyright (C) 2000, 2001 Broadcom Corporation
964 - *
965 - * This program is free software; you can redistribute it and/or
966 - * modify it under the terms of the GNU General Public License
967 - * as published by the Free Software Foundation; either version 2
968 - * of the License, or (at your option) any later version.
969 - *
970 - * This program is distributed in the hope that it will be useful,
971 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
972 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
973 - * GNU General Public License for more details.
974 - *
975 - * You should have received a copy of the GNU General Public License
976 - * along with this program; if not, write to the Free Software
977 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
978 - */
979 -
980 -#include <linux/init.h>
981 -#include <linux/kernel.h>
982 -#include <linux/mm.h>
983 -#include <linux/blkdev.h>
984 -#include <linux/bootmem.h>
985 -#include <linux/smp.h>
986 -#include <linux/initrd.h>
987 -#include <linux/pm.h>
988 -
989 -#include <asm/bootinfo.h>
990 -#include <asm/reboot.h>
991 -
992 -#define MAX_RAM_SIZE ((CONFIG_SIBYTE_STANDALONE_RAM_SIZE * 1024 * 1024) - 1)
993 -
994 -static __init void prom_meminit(void)
995 -{
996 -#ifdef CONFIG_BLK_DEV_INITRD
997 - unsigned long initrd_pstart;
998 - unsigned long initrd_pend;
999 -
1000 - initrd_pstart = __pa(initrd_start);
1001 - initrd_pend = __pa(initrd_end);
1002 - if (initrd_start &&
1003 - ((initrd_pstart > MAX_RAM_SIZE)
1004 - || (initrd_pend > MAX_RAM_SIZE))) {
1005 - panic("initrd out of addressable memory");
1006 - }
1007 -
1008 - add_memory_region(0, initrd_pstart,
1009 - BOOT_MEM_RAM);
1010 - add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
1011 - BOOT_MEM_RESERVED);
1012 - add_memory_region(initrd_pend,
1013 - (CONFIG_SIBYTE_STANDALONE_RAM_SIZE * 1024 * 1024) - initrd_pend,
1014 - BOOT_MEM_RAM);
1015 -#else
1016 - add_memory_region(0, CONFIG_SIBYTE_STANDALONE_RAM_SIZE * 1024 * 1024,
1017 - BOOT_MEM_RAM);
1018 -#endif
1019 -}
1020 -
1021 -void prom_cpu0_exit(void *unused)
1022 -{
1023 - while (1) ;
1024 -}
1025 -
1026 -static void prom_linux_exit(void)
1027 -{
1028 -#ifdef CONFIG_SMP
1029 - if (smp_processor_id()) {
1030 - smp_call_function(prom_cpu0_exit, NULL, 1);
1031 - }
1032 -#endif
1033 - while(1);
1034 -}
1035 -
1036 -/*
1037 - * prom_init is called just after the cpu type is determined, from setup_arch()
1038 - */
1039 -void __init prom_init(void)
1040 -{
1041 - _machine_restart = (void (*)(char *))prom_linux_exit;
1042 - _machine_halt = prom_linux_exit;
1043 - pm_power_off = prom_linux_exit;
1044 -
1045 - strcpy(arcs_cmdline, "root=/dev/ram0 ");
1046 -
1047 - prom_meminit();
1048 -}
1049 -
1050 -void __init prom_free_prom_memory(void)
1051 -{
1052 - /* Not sure what I'm supposed to do here. Nothing, I think */
1053 -}
1054 -
1055 -void prom_putchar(char c)
1056 -{
1057 -}
1058 --- a/arch/mips/sibyte/swarm/setup.c
1059 +++ b/arch/mips/sibyte/swarm/setup.c
1060 @@ -136,16 +136,6 @@ void __init plat_mem_setup(void)
1061 if (m41t81_probe())
1062 swarm_rtc_type = RTC_M4LT81;
1063
1064 - printk("This kernel optimized for "
1065 - "board"
1066 - " runs "
1067 -#ifdef CONFIG_SIBYTE_CFE
1068 - "with"
1069 -#else
1070 - "without"
1071 -#endif
1072 - " CFE\n");
1073 -
1074 #ifdef CONFIG_VT
1075 screen_info = (struct screen_info) {
1076 0, 0, /* orig-x, orig-y */