1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#undef DEBUG_PROM
17
18
19#define __NO_FORTIFY
20
21#include <stdarg.h>
22#include <linux/kernel.h>
23#include <linux/string.h>
24#include <linux/init.h>
25#include <linux/threads.h>
26#include <linux/spinlock.h>
27#include <linux/types.h>
28#include <linux/pci.h>
29#include <linux/proc_fs.h>
30#include <linux/stringify.h>
31#include <linux/delay.h>
32#include <linux/initrd.h>
33#include <linux/bitops.h>
34#include <asm/prom.h>
35#include <asm/rtas.h>
36#include <asm/page.h>
37#include <asm/processor.h>
38#include <asm/irq.h>
39#include <asm/io.h>
40#include <asm/smp.h>
41#include <asm/mmu.h>
42#include <asm/pgtable.h>
43#include <asm/iommu.h>
44#include <asm/btext.h>
45#include <asm/sections.h>
46#include <asm/machdep.h>
47#include <asm/opal.h>
48#include <asm/asm-prototypes.h>
49
50#include <linux/linux_logo.h>
51
52
53
54
55#define DEVTREE_CHUNK_SIZE 0x100000
56
57
58
59
60
61
62
63
64#define MEM_RESERVE_MAP_SIZE 8
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85#define ADDR(x) (u32)(unsigned long)(x)
86
87#ifdef CONFIG_PPC64
88#define OF_WORKAROUNDS 0
89#else
90#define OF_WORKAROUNDS of_workarounds
91int of_workarounds;
92#endif
93
94#define OF_WA_CLAIM 1
95#define OF_WA_LONGTRAIL 2
96
97#define PROM_BUG() do { \
98 prom_printf("kernel BUG at %s line 0x%x!\n", \
99 __FILE__, __LINE__); \
100 __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \
101} while (0)
102
103#ifdef DEBUG_PROM
104#define prom_debug(x...) prom_printf(x)
105#else
106#define prom_debug(x...)
107#endif
108
109
110typedef u32 prom_arg_t;
111
112struct prom_args {
113 __be32 service;
114 __be32 nargs;
115 __be32 nret;
116 __be32 args[10];
117};
118
119struct prom_t {
120 ihandle root;
121 phandle chosen;
122 int cpu;
123 ihandle stdout;
124 ihandle mmumap;
125 ihandle memory;
126};
127
128struct mem_map_entry {
129 __be64 base;
130 __be64 size;
131};
132
133typedef __be32 cell_t;
134
135extern void __start(unsigned long r3, unsigned long r4, unsigned long r5,
136 unsigned long r6, unsigned long r7, unsigned long r8,
137 unsigned long r9);
138
139#ifdef CONFIG_PPC64
140extern int enter_prom(struct prom_args *args, unsigned long entry);
141#else
142static inline int enter_prom(struct prom_args *args, unsigned long entry)
143{
144 return ((int (*)(struct prom_args *))entry)(args);
145}
146#endif
147
148extern void copy_and_flush(unsigned long dest, unsigned long src,
149 unsigned long size, unsigned long offset);
150
151
152static struct prom_t __initdata prom;
153
154static unsigned long prom_entry __initdata;
155
156#define PROM_SCRATCH_SIZE 256
157
158static char __initdata of_stdout_device[256];
159static char __initdata prom_scratch[PROM_SCRATCH_SIZE];
160
161static unsigned long __initdata dt_header_start;
162static unsigned long __initdata dt_struct_start, dt_struct_end;
163static unsigned long __initdata dt_string_start, dt_string_end;
164
165static unsigned long __initdata prom_initrd_start, prom_initrd_end;
166
167#ifdef CONFIG_PPC64
168static int __initdata prom_iommu_force_on;
169static int __initdata prom_iommu_off;
170static unsigned long __initdata prom_tce_alloc_start;
171static unsigned long __initdata prom_tce_alloc_end;
172#endif
173
174static bool __initdata prom_radix_disable;
175
176struct platform_support {
177 bool hash_mmu;
178 bool radix_mmu;
179 bool radix_gtse;
180 bool xive;
181};
182
183
184
185
186
187#define PLATFORM_PSERIES 0x0100
188#define PLATFORM_PSERIES_LPAR 0x0101
189#define PLATFORM_LPAR 0x0001
190#define PLATFORM_POWERMAC 0x0400
191#define PLATFORM_GENERIC 0x0500
192#define PLATFORM_OPAL 0x0600
193
194static int __initdata of_platform;
195
196static char __initdata prom_cmd_line[COMMAND_LINE_SIZE];
197
198static unsigned long __initdata prom_memory_limit;
199
200static unsigned long __initdata alloc_top;
201static unsigned long __initdata alloc_top_high;
202static unsigned long __initdata alloc_bottom;
203static unsigned long __initdata rmo_top;
204static unsigned long __initdata ram_top;
205
206static struct mem_map_entry __initdata mem_reserve_map[MEM_RESERVE_MAP_SIZE];
207static int __initdata mem_reserve_cnt;
208
209static cell_t __initdata regbuf[1024];
210
211static bool rtas_has_query_cpu_stopped;
212
213
214
215
216
217
218
219
220
221#define PROM_ERROR (-1u)
222#define PHANDLE_VALID(p) ((p) != 0 && (p) != PROM_ERROR)
223#define IHANDLE_VALID(i) ((i) != 0 && (i) != PROM_ERROR)
224
225
226
227
228
229
230static int __init call_prom(const char *service, int nargs, int nret, ...)
231{
232 int i;
233 struct prom_args args;
234 va_list list;
235
236 args.service = cpu_to_be32(ADDR(service));
237 args.nargs = cpu_to_be32(nargs);
238 args.nret = cpu_to_be32(nret);
239
240 va_start(list, nret);
241 for (i = 0; i < nargs; i++)
242 args.args[i] = cpu_to_be32(va_arg(list, prom_arg_t));
243 va_end(list);
244
245 for (i = 0; i < nret; i++)
246 args.args[nargs+i] = 0;
247
248 if (enter_prom(&args, prom_entry) < 0)
249 return PROM_ERROR;
250
251 return (nret > 0) ? be32_to_cpu(args.args[nargs]) : 0;
252}
253
254static int __init call_prom_ret(const char *service, int nargs, int nret,
255 prom_arg_t *rets, ...)
256{
257 int i;
258 struct prom_args args;
259 va_list list;
260
261 args.service = cpu_to_be32(ADDR(service));
262 args.nargs = cpu_to_be32(nargs);
263 args.nret = cpu_to_be32(nret);
264
265 va_start(list, rets);
266 for (i = 0; i < nargs; i++)
267 args.args[i] = cpu_to_be32(va_arg(list, prom_arg_t));
268 va_end(list);
269
270 for (i = 0; i < nret; i++)
271 args.args[nargs+i] = 0;
272
273 if (enter_prom(&args, prom_entry) < 0)
274 return PROM_ERROR;
275
276 if (rets != NULL)
277 for (i = 1; i < nret; ++i)
278 rets[i-1] = be32_to_cpu(args.args[nargs+i]);
279
280 return (nret > 0) ? be32_to_cpu(args.args[nargs]) : 0;
281}
282
283
284static void __init prom_print(const char *msg)
285{
286 const char *p, *q;
287
288 if (prom.stdout == 0)
289 return;
290
291 for (p = msg; *p != 0; p = q) {
292 for (q = p; *q != 0 && *q != '\n'; ++q)
293 ;
294 if (q > p)
295 call_prom("write", 3, 1, prom.stdout, p, q - p);
296 if (*q == 0)
297 break;
298 ++q;
299 call_prom("write", 3, 1, prom.stdout, ADDR("\r\n"), 2);
300 }
301}
302
303
304static void __init prom_print_hex(unsigned long val)
305{
306 int i, nibbles = sizeof(val)*2;
307 char buf[sizeof(val)*2+1];
308
309 for (i = nibbles-1; i >= 0; i--) {
310 buf[i] = (val & 0xf) + '0';
311 if (buf[i] > '9')
312 buf[i] += ('a'-'0'-10);
313 val >>= 4;
314 }
315 buf[nibbles] = '\0';
316 call_prom("write", 3, 1, prom.stdout, buf, nibbles);
317}
318
319
320#define UL_DIGITS 21
321static void __init prom_print_dec(unsigned long val)
322{
323 int i, size;
324 char buf[UL_DIGITS+1];
325
326 for (i = UL_DIGITS-1; i >= 0; i--) {
327 buf[i] = (val % 10) + '0';
328 val = val/10;
329 if (val == 0)
330 break;
331 }
332
333 size = UL_DIGITS - i;
334 call_prom("write", 3, 1, prom.stdout, buf+i, size);
335}
336
337static void __init prom_printf(const char *format, ...)
338{
339 const char *p, *q, *s;
340 va_list args;
341 unsigned long v;
342 long vs;
343
344 va_start(args, format);
345 for (p = format; *p != 0; p = q) {
346 for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q)
347 ;
348 if (q > p)
349 call_prom("write", 3, 1, prom.stdout, p, q - p);
350 if (*q == 0)
351 break;
352 if (*q == '\n') {
353 ++q;
354 call_prom("write", 3, 1, prom.stdout,
355 ADDR("\r\n"), 2);
356 continue;
357 }
358 ++q;
359 if (*q == 0)
360 break;
361 switch (*q) {
362 case 's':
363 ++q;
364 s = va_arg(args, const char *);
365 prom_print(s);
366 break;
367 case 'x':
368 ++q;
369 v = va_arg(args, unsigned long);
370 prom_print_hex(v);
371 break;
372 case 'd':
373 ++q;
374 vs = va_arg(args, int);
375 if (vs < 0) {
376 prom_print("-");
377 vs = -vs;
378 }
379 prom_print_dec(vs);
380 break;
381 case 'l':
382 ++q;
383 if (*q == 0)
384 break;
385 else if (*q == 'x') {
386 ++q;
387 v = va_arg(args, unsigned long);
388 prom_print_hex(v);
389 } else if (*q == 'u') {
390 ++q;
391 v = va_arg(args, unsigned long);
392 prom_print_dec(v);
393 } else if (*q == 'd') {
394 ++q;
395 vs = va_arg(args, long);
396 if (vs < 0) {
397 prom_print("-");
398 vs = -vs;
399 }
400 prom_print_dec(vs);
401 }
402 break;
403 }
404 }
405 va_end(args);
406}
407
408
409static unsigned int __init prom_claim(unsigned long virt, unsigned long size,
410 unsigned long align)
411{
412
413 if (align == 0 && (OF_WORKAROUNDS & OF_WA_CLAIM)) {
414
415
416
417
418 int ret;
419 prom_arg_t result;
420
421 ret = call_prom_ret("call-method", 5, 2, &result,
422 ADDR("claim"), prom.memory,
423 align, size, virt);
424 if (ret != 0 || result == -1)
425 return -1;
426 ret = call_prom_ret("call-method", 5, 2, &result,
427 ADDR("claim"), prom.mmumap,
428 align, size, virt);
429 if (ret != 0) {
430 call_prom("call-method", 4, 1, ADDR("release"),
431 prom.memory, size, virt);
432 return -1;
433 }
434
435 call_prom("call-method", 6, 1,
436 ADDR("map"), prom.mmumap, 0x12, size, virt, virt);
437 return virt;
438 }
439 return call_prom("claim", 3, 1, (prom_arg_t)virt, (prom_arg_t)size,
440 (prom_arg_t)align);
441}
442
443static void __init __attribute__((noreturn)) prom_panic(const char *reason)
444{
445 prom_print(reason);
446
447
448 if (of_platform == PLATFORM_POWERMAC)
449 asm("trap\n");
450
451
452 call_prom("exit", 0, 0);
453
454 for (;;)
455 ;
456}
457
458
459static int __init prom_next_node(phandle *nodep)
460{
461 phandle node;
462
463 if ((node = *nodep) != 0
464 && (*nodep = call_prom("child", 1, 1, node)) != 0)
465 return 1;
466 if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
467 return 1;
468 for (;;) {
469 if ((node = call_prom("parent", 1, 1, node)) == 0)
470 return 0;
471 if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
472 return 1;
473 }
474}
475
476static inline int prom_getprop(phandle node, const char *pname,
477 void *value, size_t valuelen)
478{
479 return call_prom("getprop", 4, 1, node, ADDR(pname),
480 (u32)(unsigned long) value, (u32) valuelen);
481}
482
483static inline int prom_getproplen(phandle node, const char *pname)
484{
485 return call_prom("getproplen", 2, 1, node, ADDR(pname));
486}
487
488static void add_string(char **str, const char *q)
489{
490 char *p = *str;
491
492 while (*q)
493 *p++ = *q++;
494 *p++ = ' ';
495 *str = p;
496}
497
498static char *tohex(unsigned int x)
499{
500 static char digits[] = "0123456789abcdef";
501 static char result[9];
502 int i;
503
504 result[8] = 0;
505 i = 8;
506 do {
507 --i;
508 result[i] = digits[x & 0xf];
509 x >>= 4;
510 } while (x != 0 && i > 0);
511 return &result[i];
512}
513
514static int __init prom_setprop(phandle node, const char *nodename,
515 const char *pname, void *value, size_t valuelen)
516{
517 char cmd[256], *p;
518
519 if (!(OF_WORKAROUNDS & OF_WA_LONGTRAIL))
520 return call_prom("setprop", 4, 1, node, ADDR(pname),
521 (u32)(unsigned long) value, (u32) valuelen);
522
523
524 p = cmd;
525 add_string(&p, "dev");
526 add_string(&p, nodename);
527 add_string(&p, tohex((u32)(unsigned long) value));
528 add_string(&p, tohex(valuelen));
529 add_string(&p, tohex(ADDR(pname)));
530 add_string(&p, tohex(strlen(pname)));
531 add_string(&p, "property");
532 *p = 0;
533 return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd);
534}
535
536
537#define isxdigit(c) (('0' <= (c) && (c) <= '9') \
538 || ('a' <= (c) && (c) <= 'f') \
539 || ('A' <= (c) && (c) <= 'F'))
540
541#define isdigit(c) ('0' <= (c) && (c) <= '9')
542#define islower(c) ('a' <= (c) && (c) <= 'z')
543#define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c))
544
545static unsigned long prom_strtoul(const char *cp, const char **endp)
546{
547 unsigned long result = 0, base = 10, value;
548
549 if (*cp == '0') {
550 base = 8;
551 cp++;
552 if (toupper(*cp) == 'X') {
553 cp++;
554 base = 16;
555 }
556 }
557
558 while (isxdigit(*cp) &&
559 (value = isdigit(*cp) ? *cp - '0' : toupper(*cp) - 'A' + 10) < base) {
560 result = result * base + value;
561 cp++;
562 }
563
564 if (endp)
565 *endp = cp;
566
567 return result;
568}
569
570static unsigned long prom_memparse(const char *ptr, const char **retptr)
571{
572 unsigned long ret = prom_strtoul(ptr, retptr);
573 int shift = 0;
574
575
576
577
578
579
580 if ('G' == **retptr || 'g' == **retptr)
581 shift = 30;
582
583 if ('M' == **retptr || 'm' == **retptr)
584 shift = 20;
585
586 if ('K' == **retptr || 'k' == **retptr)
587 shift = 10;
588
589 if (shift) {
590 ret <<= shift;
591 (*retptr)++;
592 }
593
594 return ret;
595}
596
597
598
599
600
601static void __init early_cmdline_parse(void)
602{
603 const char *opt;
604
605 char *p;
606 int l = 0;
607
608 prom_cmd_line[0] = 0;
609 p = prom_cmd_line;
610 if ((long)prom.chosen > 0)
611 l = prom_getprop(prom.chosen, "bootargs", p, COMMAND_LINE_SIZE-1);
612#ifdef CONFIG_CMDLINE
613 if (l <= 0 || p[0] == '\0')
614 strlcpy(prom_cmd_line,
615 CONFIG_CMDLINE, sizeof(prom_cmd_line));
616#endif
617 prom_printf("command line: %s\n", prom_cmd_line);
618
619#ifdef CONFIG_PPC64
620 opt = strstr(prom_cmd_line, "iommu=");
621 if (opt) {
622 prom_printf("iommu opt is: %s\n", opt);
623 opt += 6;
624 while (*opt && *opt == ' ')
625 opt++;
626 if (!strncmp(opt, "off", 3))
627 prom_iommu_off = 1;
628 else if (!strncmp(opt, "force", 5))
629 prom_iommu_force_on = 1;
630 }
631#endif
632 opt = strstr(prom_cmd_line, "mem=");
633 if (opt) {
634 opt += 4;
635 prom_memory_limit = prom_memparse(opt, (const char **)&opt);
636#ifdef CONFIG_PPC64
637
638 prom_memory_limit = ALIGN(prom_memory_limit, 0x1000000);
639#endif
640 }
641
642 opt = strstr(prom_cmd_line, "disable_radix");
643 if (opt) {
644 prom_debug("Radix disabled from cmdline\n");
645 prom_radix_disable = true;
646 }
647}
648
649#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
650
651
652
653
654
655
656
657
658
659#define NUM_VECTORS(n) ((n) - 1)
660
661
662
663
664
665#define VECTOR_LENGTH(n) (1 + (n) - 2)
666
667struct option_vector1 {
668 u8 byte1;
669 u8 arch_versions;
670 u8 arch_versions3;
671} __packed;
672
673struct option_vector2 {
674 u8 byte1;
675 __be16 reserved;
676 __be32 real_base;
677 __be32 real_size;
678 __be32 virt_base;
679 __be32 virt_size;
680 __be32 load_base;
681 __be32 min_rma;
682 __be32 min_load;
683 u8 min_rma_percent;
684 u8 max_pft_size;
685} __packed;
686
687struct option_vector3 {
688 u8 byte1;
689 u8 byte2;
690} __packed;
691
692struct option_vector4 {
693 u8 byte1;
694 u8 min_vp_cap;
695} __packed;
696
697struct option_vector5 {
698 u8 byte1;
699 u8 byte2;
700 u8 byte3;
701 u8 cmo;
702 u8 associativity;
703 u8 bin_opts;
704 u8 micro_checkpoint;
705 u8 reserved0;
706 __be32 max_cpus;
707 __be16 papr_level;
708 __be16 reserved1;
709 u8 platform_facilities;
710 u8 reserved2;
711 __be16 reserved3;
712 u8 subprocessors;
713 u8 byte22;
714 u8 intarch;
715 u8 mmu;
716 u8 hash_ext;
717 u8 radix_ext;
718} __packed;
719
720struct option_vector6 {
721 u8 reserved;
722 u8 secondary_pteg;
723 u8 os_name;
724} __packed;
725
726struct ibm_arch_vec {
727 struct { u32 mask, val; } pvrs[12];
728
729 u8 num_vectors;
730
731 u8 vec1_len;
732 struct option_vector1 vec1;
733
734 u8 vec2_len;
735 struct option_vector2 vec2;
736
737 u8 vec3_len;
738 struct option_vector3 vec3;
739
740 u8 vec4_len;
741 struct option_vector4 vec4;
742
743 u8 vec5_len;
744 struct option_vector5 vec5;
745
746 u8 vec6_len;
747 struct option_vector6 vec6;
748} __packed;
749
750struct ibm_arch_vec __cacheline_aligned ibm_architecture_vec = {
751 .pvrs = {
752 {
753 .mask = cpu_to_be32(0xfffe0000),
754 .val = cpu_to_be32(0x003a0000),
755 },
756 {
757 .mask = cpu_to_be32(0xffff0000),
758 .val = cpu_to_be32(0x003e0000),
759 },
760 {
761 .mask = cpu_to_be32(0xffff0000),
762 .val = cpu_to_be32(0x003f0000),
763 },
764 {
765 .mask = cpu_to_be32(0xffff0000),
766 .val = cpu_to_be32(0x004b0000),
767 },
768 {
769 .mask = cpu_to_be32(0xffff0000),
770 .val = cpu_to_be32(0x004c0000),
771 },
772 {
773 .mask = cpu_to_be32(0xffff0000),
774 .val = cpu_to_be32(0x004d0000),
775 },
776 {
777 .mask = cpu_to_be32(0xffff0000),
778 .val = cpu_to_be32(0x004e0000),
779 },
780 {
781 .mask = cpu_to_be32(0xffffffff),
782 .val = cpu_to_be32(0x0f000005),
783 },
784 {
785 .mask = cpu_to_be32(0xffffffff),
786 .val = cpu_to_be32(0x0f000004),
787 },
788 {
789 .mask = cpu_to_be32(0xffffffff),
790 .val = cpu_to_be32(0x0f000003),
791 },
792 {
793 .mask = cpu_to_be32(0xffffffff),
794 .val = cpu_to_be32(0x0f000002),
795 },
796 {
797 .mask = cpu_to_be32(0xfffffffe),
798 .val = cpu_to_be32(0x0f000001),
799 },
800 },
801
802 .num_vectors = NUM_VECTORS(6),
803
804 .vec1_len = VECTOR_LENGTH(sizeof(struct option_vector1)),
805 .vec1 = {
806 .byte1 = 0,
807 .arch_versions = OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 |
808 OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06 | OV1_PPC_2_07,
809 .arch_versions3 = OV1_PPC_3_00,
810 },
811
812 .vec2_len = VECTOR_LENGTH(sizeof(struct option_vector2)),
813
814 .vec2 = {
815 .byte1 = OV2_REAL_MODE,
816 .reserved = 0,
817 .real_base = cpu_to_be32(0xffffffff),
818 .real_size = cpu_to_be32(0xffffffff),
819 .virt_base = cpu_to_be32(0xffffffff),
820 .virt_size = cpu_to_be32(0xffffffff),
821 .load_base = cpu_to_be32(0xffffffff),
822 .min_rma = cpu_to_be32(512),
823 .min_load = cpu_to_be32(0xffffffff),
824 .min_rma_percent = 0,
825 .max_pft_size = 48,
826 },
827
828 .vec3_len = VECTOR_LENGTH(sizeof(struct option_vector3)),
829
830 .vec3 = {
831 .byte1 = 0,
832 .byte2 = OV3_FP | OV3_VMX | OV3_DFP,
833 },
834
835 .vec4_len = VECTOR_LENGTH(sizeof(struct option_vector4)),
836
837 .vec4 = {
838 .byte1 = 0,
839 .min_vp_cap = OV4_MIN_ENT_CAP,
840 },
841
842 .vec5_len = VECTOR_LENGTH(sizeof(struct option_vector5)),
843
844 .vec5 = {
845 .byte1 = 0,
846 .byte2 = OV5_FEAT(OV5_LPAR) | OV5_FEAT(OV5_SPLPAR) | OV5_FEAT(OV5_LARGE_PAGES) |
847 OV5_FEAT(OV5_DRCONF_MEMORY) | OV5_FEAT(OV5_DONATE_DEDICATE_CPU) |
848#ifdef CONFIG_PCI_MSI
849
850 OV5_FEAT(OV5_MSI),
851#else
852 0,
853#endif
854 .byte3 = 0,
855 .cmo =
856#ifdef CONFIG_PPC_SMLPAR
857 OV5_FEAT(OV5_CMO) | OV5_FEAT(OV5_XCMO),
858#else
859 0,
860#endif
861 .associativity = OV5_FEAT(OV5_TYPE1_AFFINITY) | OV5_FEAT(OV5_PRRN),
862 .bin_opts = OV5_FEAT(OV5_RESIZE_HPT) | OV5_FEAT(OV5_HP_EVT),
863 .micro_checkpoint = 0,
864 .reserved0 = 0,
865 .max_cpus = cpu_to_be32(NR_CPUS),
866 .papr_level = 0,
867 .reserved1 = 0,
868 .platform_facilities = OV5_FEAT(OV5_PFO_HW_RNG) | OV5_FEAT(OV5_PFO_HW_ENCR) | OV5_FEAT(OV5_PFO_HW_842),
869 .reserved2 = 0,
870 .reserved3 = 0,
871 .subprocessors = 1,
872 .intarch = 0,
873 .mmu = 0,
874 .hash_ext = 0,
875 .radix_ext = 0,
876 },
877
878
879 .vec6_len = VECTOR_LENGTH(sizeof(struct option_vector6)),
880 .vec6 = {
881 .reserved = 0,
882 .secondary_pteg = 0,
883 .os_name = OV6_LINUX,
884 },
885};
886
887
888#ifdef __BIG_ENDIAN__
889static struct fake_elf {
890 Elf32_Ehdr elfhdr;
891 Elf32_Phdr phdr[2];
892 struct chrpnote {
893 u32 namesz;
894 u32 descsz;
895 u32 type;
896 char name[8];
897 struct chrpdesc {
898 u32 real_mode;
899 u32 real_base;
900 u32 real_size;
901 u32 virt_base;
902 u32 virt_size;
903 u32 load_base;
904 } chrpdesc;
905 } chrpnote;
906 struct rpanote {
907 u32 namesz;
908 u32 descsz;
909 u32 type;
910 char name[24];
911 struct rpadesc {
912 u32 lpar_affinity;
913 u32 min_rmo_size;
914 u32 min_rmo_percent;
915 u32 max_pft_size;
916 u32 splpar;
917 u32 min_load;
918 u32 new_mem_def;
919 u32 ignore_me;
920 } rpadesc;
921 } rpanote;
922} fake_elf = {
923 .elfhdr = {
924 .e_ident = { 0x7f, 'E', 'L', 'F',
925 ELFCLASS32, ELFDATA2MSB, EV_CURRENT },
926 .e_type = ET_EXEC,
927 .e_machine = EM_PPC,
928 .e_version = EV_CURRENT,
929 .e_phoff = offsetof(struct fake_elf, phdr),
930 .e_phentsize = sizeof(Elf32_Phdr),
931 .e_phnum = 2
932 },
933 .phdr = {
934 [0] = {
935 .p_type = PT_NOTE,
936 .p_offset = offsetof(struct fake_elf, chrpnote),
937 .p_filesz = sizeof(struct chrpnote)
938 }, [1] = {
939 .p_type = PT_NOTE,
940 .p_offset = offsetof(struct fake_elf, rpanote),
941 .p_filesz = sizeof(struct rpanote)
942 }
943 },
944 .chrpnote = {
945 .namesz = sizeof("PowerPC"),
946 .descsz = sizeof(struct chrpdesc),
947 .type = 0x1275,
948 .name = "PowerPC",
949 .chrpdesc = {
950 .real_mode = ~0U,
951 .real_base = ~0U,
952 .real_size = ~0U,
953 .virt_base = ~0U,
954 .virt_size = ~0U,
955 .load_base = ~0U
956 },
957 },
958 .rpanote = {
959 .namesz = sizeof("IBM,RPA-Client-Config"),
960 .descsz = sizeof(struct rpadesc),
961 .type = 0x12759999,
962 .name = "IBM,RPA-Client-Config",
963 .rpadesc = {
964 .lpar_affinity = 0,
965 .min_rmo_size = 64,
966 .min_rmo_percent = 0,
967 .max_pft_size = 48,
968 .splpar = 1,
969 .min_load = ~0U,
970 .new_mem_def = 0
971 }
972 }
973};
974#endif
975
976static int __init prom_count_smt_threads(void)
977{
978 phandle node;
979 char type[64];
980 unsigned int plen;
981
982
983 for (node = 0; prom_next_node(&node); ) {
984 type[0] = 0;
985 prom_getprop(node, "device_type", type, sizeof(type));
986
987 if (strcmp(type, "cpu"))
988 continue;
989
990
991
992
993
994 plen = prom_getproplen(node, "ibm,ppc-interrupt-server#s");
995 if (plen == PROM_ERROR)
996 break;
997 plen >>= 2;
998 prom_debug("Found %lu smt threads per core\n", (unsigned long)plen);
999
1000
1001 if (plen < 1 || plen > 64) {
1002 prom_printf("Threads per core %lu out of bounds, assuming 1\n",
1003 (unsigned long)plen);
1004 return 1;
1005 }
1006 return plen;
1007 }
1008 prom_debug("No threads found, assuming 1 per core\n");
1009
1010 return 1;
1011
1012}
1013
1014static void __init prom_parse_mmu_model(u8 val,
1015 struct platform_support *support)
1016{
1017 switch (val) {
1018 case OV5_FEAT(OV5_MMU_DYNAMIC):
1019 case OV5_FEAT(OV5_MMU_EITHER):
1020 prom_debug("MMU - either supported\n");
1021 support->radix_mmu = !prom_radix_disable;
1022 support->hash_mmu = true;
1023 break;
1024 case OV5_FEAT(OV5_MMU_RADIX):
1025 prom_debug("MMU - radix only\n");
1026 if (prom_radix_disable) {
1027
1028
1029
1030
1031 prom_printf("WARNING: Ignoring cmdline option disable_radix\n");
1032 }
1033 support->radix_mmu = true;
1034 break;
1035 case OV5_FEAT(OV5_MMU_HASH):
1036 prom_debug("MMU - hash only\n");
1037 support->hash_mmu = true;
1038 break;
1039 default:
1040 prom_debug("Unknown mmu support option: 0x%x\n", val);
1041 break;
1042 }
1043}
1044
1045static void __init prom_parse_xive_model(u8 val,
1046 struct platform_support *support)
1047{
1048 switch (val) {
1049 case OV5_FEAT(OV5_XIVE_EITHER):
1050 prom_debug("XIVE - either mode supported\n");
1051 support->xive = true;
1052 break;
1053 case OV5_FEAT(OV5_XIVE_EXPLOIT):
1054 prom_debug("XIVE - exploitation mode supported\n");
1055 support->xive = true;
1056 break;
1057 case OV5_FEAT(OV5_XIVE_LEGACY):
1058 prom_debug("XIVE - legacy mode supported\n");
1059 break;
1060 default:
1061 prom_debug("Unknown xive support option: 0x%x\n", val);
1062 break;
1063 }
1064}
1065
1066static void __init prom_parse_platform_support(u8 index, u8 val,
1067 struct platform_support *support)
1068{
1069 switch (index) {
1070 case OV5_INDX(OV5_MMU_SUPPORT):
1071 prom_parse_mmu_model(val & OV5_FEAT(OV5_MMU_SUPPORT), support);
1072 break;
1073 case OV5_INDX(OV5_RADIX_GTSE):
1074 if (val & OV5_FEAT(OV5_RADIX_GTSE)) {
1075 prom_debug("Radix - GTSE supported\n");
1076 support->radix_gtse = true;
1077 }
1078 break;
1079 case OV5_INDX(OV5_XIVE_SUPPORT):
1080 prom_parse_xive_model(val & OV5_FEAT(OV5_XIVE_SUPPORT),
1081 support);
1082 break;
1083 }
1084}
1085
1086static void __init prom_check_platform_support(void)
1087{
1088 struct platform_support supported = {
1089 .hash_mmu = false,
1090 .radix_mmu = false,
1091 .radix_gtse = false,
1092 .xive = false
1093 };
1094 int prop_len = prom_getproplen(prom.chosen,
1095 "ibm,arch-vec-5-platform-support");
1096 if (prop_len > 1) {
1097 int i;
1098 u8 vec[prop_len];
1099 prom_debug("Found ibm,arch-vec-5-platform-support, len: %d\n",
1100 prop_len);
1101 prom_getprop(prom.chosen, "ibm,arch-vec-5-platform-support",
1102 &vec, sizeof(vec));
1103 for (i = 0; i < prop_len; i += 2) {
1104 prom_debug("%d: index = 0x%x val = 0x%x\n", i / 2
1105 , vec[i]
1106 , vec[i + 1]);
1107 prom_parse_platform_support(vec[i], vec[i + 1],
1108 &supported);
1109 }
1110 }
1111
1112 if (supported.radix_mmu && supported.radix_gtse) {
1113
1114 prom_debug("Asking for radix with GTSE\n");
1115 ibm_architecture_vec.vec5.mmu = OV5_FEAT(OV5_MMU_RADIX);
1116 ibm_architecture_vec.vec5.radix_ext = OV5_FEAT(OV5_RADIX_GTSE);
1117 } else if (supported.hash_mmu) {
1118
1119 prom_debug("Asking for hash\n");
1120 ibm_architecture_vec.vec5.mmu = OV5_FEAT(OV5_MMU_HASH);
1121 } else {
1122
1123 prom_debug("Assuming legacy hash support\n");
1124 }
1125
1126 if (supported.xive) {
1127 prom_debug("Asking for XIVE\n");
1128 ibm_architecture_vec.vec5.intarch = OV5_FEAT(OV5_XIVE_EXPLOIT);
1129 }
1130}
1131
1132static void __init prom_send_capabilities(void)
1133{
1134 ihandle root;
1135 prom_arg_t ret;
1136 u32 cores;
1137
1138
1139 prom_check_platform_support();
1140
1141 root = call_prom("open", 1, 1, ADDR("/"));
1142 if (root != 0) {
1143
1144
1145
1146
1147
1148
1149
1150 cores = DIV_ROUND_UP(NR_CPUS, prom_count_smt_threads());
1151 prom_printf("Max number of cores passed to firmware: %lu (NR_CPUS = %lu)\n",
1152 cores, NR_CPUS);
1153
1154 ibm_architecture_vec.vec5.max_cpus = cpu_to_be32(cores);
1155
1156
1157 prom_printf("Calling ibm,client-architecture-support...");
1158 if (call_prom_ret("call-method", 3, 2, &ret,
1159 ADDR("ibm,client-architecture-support"),
1160 root,
1161 ADDR(&ibm_architecture_vec)) == 0) {
1162
1163 if (ret)
1164 prom_printf("\nWARNING: ibm,client-architecture"
1165 "-support call FAILED!\n");
1166 call_prom("close", 1, 0, root);
1167 prom_printf(" done\n");
1168 return;
1169 }
1170 call_prom("close", 1, 0, root);
1171 prom_printf(" not implemented\n");
1172 }
1173
1174#ifdef __BIG_ENDIAN__
1175 {
1176 ihandle elfloader;
1177
1178
1179 elfloader = call_prom("open", 1, 1,
1180 ADDR("/packages/elf-loader"));
1181 if (elfloader == 0) {
1182 prom_printf("couldn't open /packages/elf-loader\n");
1183 return;
1184 }
1185 call_prom("call-method", 3, 1, ADDR("process-elf-header"),
1186 elfloader, ADDR(&fake_elf));
1187 call_prom("close", 1, 0, elfloader);
1188 }
1189#endif
1190}
1191#endif
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226static unsigned long __init alloc_up(unsigned long size, unsigned long align)
1227{
1228 unsigned long base = alloc_bottom;
1229 unsigned long addr = 0;
1230
1231 if (align)
1232 base = _ALIGN_UP(base, align);
1233 prom_debug("alloc_up(%x, %x)\n", size, align);
1234 if (ram_top == 0)
1235 prom_panic("alloc_up() called with mem not initialized\n");
1236
1237 if (align)
1238 base = _ALIGN_UP(alloc_bottom, align);
1239 else
1240 base = alloc_bottom;
1241
1242 for(; (base + size) <= alloc_top;
1243 base = _ALIGN_UP(base + 0x100000, align)) {
1244 prom_debug(" trying: 0x%x\n\r", base);
1245 addr = (unsigned long)prom_claim(base, size, 0);
1246 if (addr != PROM_ERROR && addr != 0)
1247 break;
1248 addr = 0;
1249 if (align == 0)
1250 break;
1251 }
1252 if (addr == 0)
1253 return 0;
1254 alloc_bottom = addr + size;
1255
1256 prom_debug(" -> %x\n", addr);
1257 prom_debug(" alloc_bottom : %x\n", alloc_bottom);
1258 prom_debug(" alloc_top : %x\n", alloc_top);
1259 prom_debug(" alloc_top_hi : %x\n", alloc_top_high);
1260 prom_debug(" rmo_top : %x\n", rmo_top);
1261 prom_debug(" ram_top : %x\n", ram_top);
1262
1263 return addr;
1264}
1265
1266
1267
1268
1269
1270
1271static unsigned long __init alloc_down(unsigned long size, unsigned long align,
1272 int highmem)
1273{
1274 unsigned long base, addr = 0;
1275
1276 prom_debug("alloc_down(%x, %x, %s)\n", size, align,
1277 highmem ? "(high)" : "(low)");
1278 if (ram_top == 0)
1279 prom_panic("alloc_down() called with mem not initialized\n");
1280
1281 if (highmem) {
1282
1283 addr = _ALIGN_DOWN(alloc_top_high - size, align);
1284 if (addr <= alloc_bottom)
1285 return 0;
1286
1287
1288
1289
1290 if (addr < rmo_top) {
1291
1292 if (alloc_top == rmo_top)
1293 alloc_top = rmo_top = addr;
1294 else
1295 return 0;
1296 }
1297 alloc_top_high = addr;
1298 goto bail;
1299 }
1300
1301 base = _ALIGN_DOWN(alloc_top - size, align);
1302 for (; base > alloc_bottom;
1303 base = _ALIGN_DOWN(base - 0x100000, align)) {
1304 prom_debug(" trying: 0x%x\n\r", base);
1305 addr = (unsigned long)prom_claim(base, size, 0);
1306 if (addr != PROM_ERROR && addr != 0)
1307 break;
1308 addr = 0;
1309 }
1310 if (addr == 0)
1311 return 0;
1312 alloc_top = addr;
1313
1314 bail:
1315 prom_debug(" -> %x\n", addr);
1316 prom_debug(" alloc_bottom : %x\n", alloc_bottom);
1317 prom_debug(" alloc_top : %x\n", alloc_top);
1318 prom_debug(" alloc_top_hi : %x\n", alloc_top_high);
1319 prom_debug(" rmo_top : %x\n", rmo_top);
1320 prom_debug(" ram_top : %x\n", ram_top);
1321
1322 return addr;
1323}
1324
1325
1326
1327
1328static unsigned long __init prom_next_cell(int s, cell_t **cellp)
1329{
1330 cell_t *p = *cellp;
1331 unsigned long r = 0;
1332
1333
1334 while (s > sizeof(unsigned long) / 4) {
1335 p++;
1336 s--;
1337 }
1338 r = be32_to_cpu(*p++);
1339#ifdef CONFIG_PPC64
1340 if (s > 1) {
1341 r <<= 32;
1342 r |= be32_to_cpu(*(p++));
1343 }
1344#endif
1345 *cellp = p;
1346 return r;
1347}
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357static void __init reserve_mem(u64 base, u64 size)
1358{
1359 u64 top = base + size;
1360 unsigned long cnt = mem_reserve_cnt;
1361
1362 if (size == 0)
1363 return;
1364
1365
1366
1367
1368
1369 base = _ALIGN_DOWN(base, PAGE_SIZE);
1370 top = _ALIGN_UP(top, PAGE_SIZE);
1371 size = top - base;
1372
1373 if (cnt >= (MEM_RESERVE_MAP_SIZE - 1))
1374 prom_panic("Memory reserve map exhausted !\n");
1375 mem_reserve_map[cnt].base = cpu_to_be64(base);
1376 mem_reserve_map[cnt].size = cpu_to_be64(size);
1377 mem_reserve_cnt = cnt + 1;
1378}
1379
1380
1381
1382
1383
1384static void __init prom_init_mem(void)
1385{
1386 phandle node;
1387 char *path, type[64];
1388 unsigned int plen;
1389 cell_t *p, *endp;
1390 __be32 val;
1391 u32 rac, rsc;
1392
1393
1394
1395
1396
1397
1398 val = cpu_to_be32(2);
1399 prom_getprop(prom.root, "#address-cells", &val, sizeof(val));
1400 rac = be32_to_cpu(val);
1401 val = cpu_to_be32(1);
1402 prom_getprop(prom.root, "#size-cells", &val, sizeof(rsc));
1403 rsc = be32_to_cpu(val);
1404 prom_debug("root_addr_cells: %x\n", rac);
1405 prom_debug("root_size_cells: %x\n", rsc);
1406
1407 prom_debug("scanning memory:\n");
1408 path = prom_scratch;
1409
1410 for (node = 0; prom_next_node(&node); ) {
1411 type[0] = 0;
1412 prom_getprop(node, "device_type", type, sizeof(type));
1413
1414 if (type[0] == 0) {
1415
1416
1417
1418
1419 prom_getprop(node, "name", type, sizeof(type));
1420 }
1421 if (strcmp(type, "memory"))
1422 continue;
1423
1424 plen = prom_getprop(node, "reg", regbuf, sizeof(regbuf));
1425 if (plen > sizeof(regbuf)) {
1426 prom_printf("memory node too large for buffer !\n");
1427 plen = sizeof(regbuf);
1428 }
1429 p = regbuf;
1430 endp = p + (plen / sizeof(cell_t));
1431
1432#ifdef DEBUG_PROM
1433 memset(path, 0, PROM_SCRATCH_SIZE);
1434 call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
1435 prom_debug(" node %s :\n", path);
1436#endif
1437
1438 while ((endp - p) >= (rac + rsc)) {
1439 unsigned long base, size;
1440
1441 base = prom_next_cell(rac, &p);
1442 size = prom_next_cell(rsc, &p);
1443
1444 if (size == 0)
1445 continue;
1446 prom_debug(" %x %x\n", base, size);
1447 if (base == 0 && (of_platform & PLATFORM_LPAR))
1448 rmo_top = size;
1449 if ((base + size) > ram_top)
1450 ram_top = base + size;
1451 }
1452 }
1453
1454 alloc_bottom = PAGE_ALIGN((unsigned long)&_end + 0x4000);
1455
1456
1457
1458
1459
1460
1461
1462 alloc_top_high = ram_top;
1463
1464 if (prom_memory_limit) {
1465 if (prom_memory_limit <= alloc_bottom) {
1466 prom_printf("Ignoring mem=%x <= alloc_bottom.\n",
1467 prom_memory_limit);
1468 prom_memory_limit = 0;
1469 } else if (prom_memory_limit >= ram_top) {
1470 prom_printf("Ignoring mem=%x >= ram_top.\n",
1471 prom_memory_limit);
1472 prom_memory_limit = 0;
1473 } else {
1474 ram_top = prom_memory_limit;
1475 rmo_top = min(rmo_top, prom_memory_limit);
1476 }
1477 }
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487 if (!rmo_top)
1488 rmo_top = ram_top;
1489 rmo_top = min(0x30000000ul, rmo_top);
1490 alloc_top = rmo_top;
1491 alloc_top_high = ram_top;
1492
1493
1494
1495
1496
1497 if (prom_initrd_start &&
1498 prom_initrd_start < rmo_top &&
1499 prom_initrd_end > alloc_bottom)
1500 alloc_bottom = PAGE_ALIGN(prom_initrd_end);
1501
1502 prom_printf("memory layout at init:\n");
1503 prom_printf(" memory_limit : %x (16 MB aligned)\n", prom_memory_limit);
1504 prom_printf(" alloc_bottom : %x\n", alloc_bottom);
1505 prom_printf(" alloc_top : %x\n", alloc_top);
1506 prom_printf(" alloc_top_hi : %x\n", alloc_top_high);
1507 prom_printf(" rmo_top : %x\n", rmo_top);
1508 prom_printf(" ram_top : %x\n", ram_top);
1509}
1510
1511static void __init prom_close_stdin(void)
1512{
1513 __be32 val;
1514 ihandle stdin;
1515
1516 if (prom_getprop(prom.chosen, "stdin", &val, sizeof(val)) > 0) {
1517 stdin = be32_to_cpu(val);
1518 call_prom("close", 1, 0, stdin);
1519 }
1520}
1521
1522#ifdef CONFIG_PPC_POWERNV
1523
1524#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
1525static u64 __initdata prom_opal_base;
1526static u64 __initdata prom_opal_entry;
1527#endif
1528
1529
1530
1531
1532static void __init prom_instantiate_opal(void)
1533{
1534 phandle opal_node;
1535 ihandle opal_inst;
1536 u64 base, entry;
1537 u64 size = 0, align = 0x10000;
1538 __be64 val64;
1539 u32 rets[2];
1540
1541 prom_debug("prom_instantiate_opal: start...\n");
1542
1543 opal_node = call_prom("finddevice", 1, 1, ADDR("/ibm,opal"));
1544 prom_debug("opal_node: %x\n", opal_node);
1545 if (!PHANDLE_VALID(opal_node))
1546 return;
1547
1548 val64 = 0;
1549 prom_getprop(opal_node, "opal-runtime-size", &val64, sizeof(val64));
1550 size = be64_to_cpu(val64);
1551 if (size == 0)
1552 return;
1553 val64 = 0;
1554 prom_getprop(opal_node, "opal-runtime-alignment", &val64,sizeof(val64));
1555 align = be64_to_cpu(val64);
1556
1557 base = alloc_down(size, align, 0);
1558 if (base == 0) {
1559 prom_printf("OPAL allocation failed !\n");
1560 return;
1561 }
1562
1563 opal_inst = call_prom("open", 1, 1, ADDR("/ibm,opal"));
1564 if (!IHANDLE_VALID(opal_inst)) {
1565 prom_printf("opening opal package failed (%x)\n", opal_inst);
1566 return;
1567 }
1568
1569 prom_printf("instantiating opal at 0x%x...", base);
1570
1571 if (call_prom_ret("call-method", 4, 3, rets,
1572 ADDR("load-opal-runtime"),
1573 opal_inst,
1574 base >> 32, base & 0xffffffff) != 0
1575 || (rets[0] == 0 && rets[1] == 0)) {
1576 prom_printf(" failed\n");
1577 return;
1578 }
1579 entry = (((u64)rets[0]) << 32) | rets[1];
1580
1581 prom_printf(" done\n");
1582
1583 reserve_mem(base, size);
1584
1585 prom_debug("opal base = 0x%x\n", base);
1586 prom_debug("opal align = 0x%x\n", align);
1587 prom_debug("opal entry = 0x%x\n", entry);
1588 prom_debug("opal size = 0x%x\n", (long)size);
1589
1590 prom_setprop(opal_node, "/ibm,opal", "opal-base-address",
1591 &base, sizeof(base));
1592 prom_setprop(opal_node, "/ibm,opal", "opal-entry-address",
1593 &entry, sizeof(entry));
1594
1595#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
1596 prom_opal_base = base;
1597 prom_opal_entry = entry;
1598#endif
1599 prom_debug("prom_instantiate_opal: end...\n");
1600}
1601
1602#endif
1603
1604
1605
1606
1607static void __init prom_instantiate_rtas(void)
1608{
1609 phandle rtas_node;
1610 ihandle rtas_inst;
1611 u32 base, entry = 0;
1612 __be32 val;
1613 u32 size = 0;
1614
1615 prom_debug("prom_instantiate_rtas: start...\n");
1616
1617 rtas_node = call_prom("finddevice", 1, 1, ADDR("/rtas"));
1618 prom_debug("rtas_node: %x\n", rtas_node);
1619 if (!PHANDLE_VALID(rtas_node))
1620 return;
1621
1622 val = 0;
1623 prom_getprop(rtas_node, "rtas-size", &val, sizeof(size));
1624 size = be32_to_cpu(val);
1625 if (size == 0)
1626 return;
1627
1628 base = alloc_down(size, PAGE_SIZE, 0);
1629 if (base == 0)
1630 prom_panic("Could not allocate memory for RTAS\n");
1631
1632 rtas_inst = call_prom("open", 1, 1, ADDR("/rtas"));
1633 if (!IHANDLE_VALID(rtas_inst)) {
1634 prom_printf("opening rtas package failed (%x)\n", rtas_inst);
1635 return;
1636 }
1637
1638 prom_printf("instantiating rtas at 0x%x...", base);
1639
1640 if (call_prom_ret("call-method", 3, 2, &entry,
1641 ADDR("instantiate-rtas"),
1642 rtas_inst, base) != 0
1643 || entry == 0) {
1644 prom_printf(" failed\n");
1645 return;
1646 }
1647 prom_printf(" done\n");
1648
1649 reserve_mem(base, size);
1650
1651 val = cpu_to_be32(base);
1652 prom_setprop(rtas_node, "/rtas", "linux,rtas-base",
1653 &val, sizeof(val));
1654 val = cpu_to_be32(entry);
1655 prom_setprop(rtas_node, "/rtas", "linux,rtas-entry",
1656 &val, sizeof(val));
1657
1658
1659 if (prom_getprop(rtas_node, "query-cpu-stopped-state",
1660 &val, sizeof(val)) != PROM_ERROR)
1661 rtas_has_query_cpu_stopped = true;
1662
1663 prom_debug("rtas base = 0x%x\n", base);
1664 prom_debug("rtas entry = 0x%x\n", entry);
1665 prom_debug("rtas size = 0x%x\n", (long)size);
1666
1667 prom_debug("prom_instantiate_rtas: end...\n");
1668}
1669
1670#ifdef CONFIG_PPC64
1671
1672
1673
1674static void __init prom_instantiate_sml(void)
1675{
1676 phandle ibmvtpm_node;
1677 ihandle ibmvtpm_inst;
1678 u32 entry = 0, size = 0, succ = 0;
1679 u64 base;
1680 __be32 val;
1681
1682 prom_debug("prom_instantiate_sml: start...\n");
1683
1684 ibmvtpm_node = call_prom("finddevice", 1, 1, ADDR("/vdevice/vtpm"));
1685 prom_debug("ibmvtpm_node: %x\n", ibmvtpm_node);
1686 if (!PHANDLE_VALID(ibmvtpm_node))
1687 return;
1688
1689 ibmvtpm_inst = call_prom("open", 1, 1, ADDR("/vdevice/vtpm"));
1690 if (!IHANDLE_VALID(ibmvtpm_inst)) {
1691 prom_printf("opening vtpm package failed (%x)\n", ibmvtpm_inst);
1692 return;
1693 }
1694
1695 if (prom_getprop(ibmvtpm_node, "ibm,sml-efi-reformat-supported",
1696 &val, sizeof(val)) != PROM_ERROR) {
1697 if (call_prom_ret("call-method", 2, 2, &succ,
1698 ADDR("reformat-sml-to-efi-alignment"),
1699 ibmvtpm_inst) != 0 || succ == 0) {
1700 prom_printf("Reformat SML to EFI alignment failed\n");
1701 return;
1702 }
1703
1704 if (call_prom_ret("call-method", 2, 2, &size,
1705 ADDR("sml-get-allocated-size"),
1706 ibmvtpm_inst) != 0 || size == 0) {
1707 prom_printf("SML get allocated size failed\n");
1708 return;
1709 }
1710 } else {
1711 if (call_prom_ret("call-method", 2, 2, &size,
1712 ADDR("sml-get-handover-size"),
1713 ibmvtpm_inst) != 0 || size == 0) {
1714 prom_printf("SML get handover size failed\n");
1715 return;
1716 }
1717 }
1718
1719 base = alloc_down(size, PAGE_SIZE, 0);
1720 if (base == 0)
1721 prom_panic("Could not allocate memory for sml\n");
1722
1723 prom_printf("instantiating sml at 0x%x...", base);
1724
1725 memset((void *)base, 0, size);
1726
1727 if (call_prom_ret("call-method", 4, 2, &entry,
1728 ADDR("sml-handover"),
1729 ibmvtpm_inst, size, base) != 0 || entry == 0) {
1730 prom_printf("SML handover failed\n");
1731 return;
1732 }
1733 prom_printf(" done\n");
1734
1735 reserve_mem(base, size);
1736
1737 prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-base",
1738 &base, sizeof(base));
1739 prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-size",
1740 &size, sizeof(size));
1741
1742 prom_debug("sml base = 0x%x\n", base);
1743 prom_debug("sml size = 0x%x\n", (long)size);
1744
1745 prom_debug("prom_instantiate_sml: end...\n");
1746}
1747
1748
1749
1750
1751#ifdef __BIG_ENDIAN__
1752static void __init prom_initialize_tce_table(void)
1753{
1754 phandle node;
1755 ihandle phb_node;
1756 char compatible[64], type[64], model[64];
1757 char *path = prom_scratch;
1758 u64 base, align;
1759 u32 minalign, minsize;
1760 u64 tce_entry, *tce_entryp;
1761 u64 local_alloc_top, local_alloc_bottom;
1762 u64 i;
1763
1764 if (prom_iommu_off)
1765 return;
1766
1767 prom_debug("starting prom_initialize_tce_table\n");
1768
1769
1770 local_alloc_top = alloc_top_high;
1771 local_alloc_bottom = local_alloc_top;
1772
1773
1774 for (node = 0; prom_next_node(&node); ) {
1775 compatible[0] = 0;
1776 type[0] = 0;
1777 model[0] = 0;
1778 prom_getprop(node, "compatible",
1779 compatible, sizeof(compatible));
1780 prom_getprop(node, "device_type", type, sizeof(type));
1781 prom_getprop(node, "model", model, sizeof(model));
1782
1783 if ((type[0] == 0) || (strstr(type, "pci") == NULL))
1784 continue;
1785
1786
1787 if (compatible[0] != 0) {
1788 if ((strstr(compatible, "python") == NULL) &&
1789 (strstr(compatible, "Speedwagon") == NULL) &&
1790 (strstr(compatible, "Winnipeg") == NULL))
1791 continue;
1792 } else if (model[0] != 0) {
1793 if ((strstr(model, "ython") == NULL) &&
1794 (strstr(model, "peedwagon") == NULL) &&
1795 (strstr(model, "innipeg") == NULL))
1796 continue;
1797 }
1798
1799 if (prom_getprop(node, "tce-table-minalign", &minalign,
1800 sizeof(minalign)) == PROM_ERROR)
1801 minalign = 0;
1802 if (prom_getprop(node, "tce-table-minsize", &minsize,
1803 sizeof(minsize)) == PROM_ERROR)
1804 minsize = 4UL << 20;
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817 if (pvr_version_is(PVR_POWER4) || pvr_version_is(PVR_POWER4p))
1818 minsize = 8UL << 20;
1819 else
1820 minsize = 4UL << 20;
1821
1822
1823 align = max(minalign, minsize);
1824 base = alloc_down(minsize, align, 1);
1825 if (base == 0)
1826 prom_panic("ERROR, cannot find space for TCE table.\n");
1827 if (base < local_alloc_bottom)
1828 local_alloc_bottom = base;
1829
1830
1831 memset(path, 0, PROM_SCRATCH_SIZE);
1832
1833 if (call_prom("package-to-path", 3, 1, node,
1834 path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) {
1835 prom_printf("package-to-path failed\n");
1836 }
1837
1838
1839 prom_setprop(node, path, "linux,tce-base", &base, sizeof(base));
1840 prom_setprop(node, path, "linux,tce-size", &minsize, sizeof(minsize));
1841
1842 prom_debug("TCE table: %s\n", path);
1843 prom_debug("\tnode = 0x%x\n", node);
1844 prom_debug("\tbase = 0x%x\n", base);
1845 prom_debug("\tsize = 0x%x\n", minsize);
1846
1847
1848
1849
1850 tce_entryp = (u64 *)base;
1851 for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {
1852 tce_entry = (i << PAGE_SHIFT);
1853 tce_entry |= 0x3;
1854 *tce_entryp = tce_entry;
1855 }
1856
1857 prom_printf("opening PHB %s", path);
1858 phb_node = call_prom("open", 1, 1, path);
1859 if (phb_node == 0)
1860 prom_printf("... failed\n");
1861 else
1862 prom_printf("... done\n");
1863
1864 call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"),
1865 phb_node, -1, minsize,
1866 (u32) base, (u32) (base >> 32));
1867 call_prom("close", 1, 0, phb_node);
1868 }
1869
1870 reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom);
1871
1872
1873
1874 prom_tce_alloc_start = local_alloc_bottom;
1875 prom_tce_alloc_end = local_alloc_top;
1876
1877
1878 prom_debug("ending prom_initialize_tce_table\n");
1879}
1880#endif
1881#endif
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905#define LOW_ADDR(x) (((unsigned long) &(x)) & 0xff)
1906
1907static void __init prom_hold_cpus(void)
1908{
1909 unsigned long i;
1910 phandle node;
1911 char type[64];
1912 unsigned long *spinloop
1913 = (void *) LOW_ADDR(__secondary_hold_spinloop);
1914 unsigned long *acknowledge
1915 = (void *) LOW_ADDR(__secondary_hold_acknowledge);
1916 unsigned long secondary_hold = LOW_ADDR(__secondary_hold);
1917
1918
1919
1920
1921
1922
1923 if ((of_platform == PLATFORM_PSERIES ||
1924 of_platform == PLATFORM_PSERIES_LPAR) &&
1925 rtas_has_query_cpu_stopped) {
1926 prom_printf("prom_hold_cpus: skipped\n");
1927 return;
1928 }
1929
1930 prom_debug("prom_hold_cpus: start...\n");
1931 prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop);
1932 prom_debug(" 1) *spinloop = 0x%x\n", *spinloop);
1933 prom_debug(" 1) acknowledge = 0x%x\n",
1934 (unsigned long)acknowledge);
1935 prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge);
1936 prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold);
1937
1938
1939
1940
1941
1942
1943 *spinloop = 0;
1944
1945
1946 for (node = 0; prom_next_node(&node); ) {
1947 unsigned int cpu_no;
1948 __be32 reg;
1949
1950 type[0] = 0;
1951 prom_getprop(node, "device_type", type, sizeof(type));
1952 if (strcmp(type, "cpu") != 0)
1953 continue;
1954
1955
1956 if (prom_getprop(node, "status", type, sizeof(type)) > 0)
1957 if (strcmp(type, "okay") != 0)
1958 continue;
1959
1960 reg = cpu_to_be32(-1);
1961 prom_getprop(node, "reg", ®, sizeof(reg));
1962 cpu_no = be32_to_cpu(reg);
1963
1964 prom_debug("cpu hw idx = %lu\n", cpu_no);
1965
1966
1967
1968
1969
1970 *acknowledge = (unsigned long)-1;
1971
1972 if (cpu_no != prom.cpu) {
1973
1974 prom_printf("starting cpu hw idx %lu... ", cpu_no);
1975 call_prom("start-cpu", 3, 0, node,
1976 secondary_hold, cpu_no);
1977
1978 for (i = 0; (i < 100000000) &&
1979 (*acknowledge == ((unsigned long)-1)); i++ )
1980 mb();
1981
1982 if (*acknowledge == cpu_no)
1983 prom_printf("done\n");
1984 else
1985 prom_printf("failed: %x\n", *acknowledge);
1986 }
1987#ifdef CONFIG_SMP
1988 else
1989 prom_printf("boot cpu hw idx %lu\n", cpu_no);
1990#endif
1991 }
1992
1993 prom_debug("prom_hold_cpus: end...\n");
1994}
1995
1996
1997static void __init prom_init_client_services(unsigned long pp)
1998{
1999
2000 prom_entry = pp;
2001
2002
2003 prom.chosen = call_prom("finddevice", 1, 1, ADDR("/chosen"));
2004 if (!PHANDLE_VALID(prom.chosen))
2005 prom_panic("cannot find chosen");
2006
2007
2008 prom.root = call_prom("finddevice", 1, 1, ADDR("/"));
2009 if (!PHANDLE_VALID(prom.root))
2010 prom_panic("cannot find device tree root");
2011
2012 prom.mmumap = 0;
2013}
2014
2015#ifdef CONFIG_PPC32
2016
2017
2018
2019
2020
2021static void __init prom_find_mmu(void)
2022{
2023 phandle oprom;
2024 char version[64];
2025
2026 oprom = call_prom("finddevice", 1, 1, ADDR("/openprom"));
2027 if (!PHANDLE_VALID(oprom))
2028 return;
2029 if (prom_getprop(oprom, "model", version, sizeof(version)) <= 0)
2030 return;
2031 version[sizeof(version) - 1] = 0;
2032
2033 if (strcmp(version, "Open Firmware, 1.0.5") == 0)
2034 of_workarounds = OF_WA_CLAIM;
2035 else if (strncmp(version, "FirmWorks,3.", 12) == 0) {
2036 of_workarounds = OF_WA_CLAIM | OF_WA_LONGTRAIL;
2037 call_prom("interpret", 1, 1, "dev /memory 0 to allow-reclaim");
2038 } else
2039 return;
2040 prom.memory = call_prom("open", 1, 1, ADDR("/memory"));
2041 prom_getprop(prom.chosen, "mmu", &prom.mmumap,
2042 sizeof(prom.mmumap));
2043 prom.mmumap = be32_to_cpu(prom.mmumap);
2044 if (!IHANDLE_VALID(prom.memory) || !IHANDLE_VALID(prom.mmumap))
2045 of_workarounds &= ~OF_WA_CLAIM;
2046}
2047#else
2048#define prom_find_mmu()
2049#endif
2050
2051static void __init prom_init_stdout(void)
2052{
2053 char *path = of_stdout_device;
2054 char type[16];
2055 phandle stdout_node;
2056 __be32 val;
2057
2058 if (prom_getprop(prom.chosen, "stdout", &val, sizeof(val)) <= 0)
2059 prom_panic("cannot find stdout");
2060
2061 prom.stdout = be32_to_cpu(val);
2062
2063
2064 memset(path, 0, 256);
2065 call_prom("instance-to-path", 3, 1, prom.stdout, path, 255);
2066 prom_printf("OF stdout device is: %s\n", of_stdout_device);
2067 prom_setprop(prom.chosen, "/chosen", "linux,stdout-path",
2068 path, strlen(path) + 1);
2069
2070
2071 stdout_node = call_prom("instance-to-package", 1, 1, prom.stdout);
2072 if (stdout_node != PROM_ERROR) {
2073 val = cpu_to_be32(stdout_node);
2074 prom_setprop(prom.chosen, "/chosen", "linux,stdout-package",
2075 &val, sizeof(val));
2076
2077
2078 memset(type, 0, sizeof(type));
2079 prom_getprop(stdout_node, "device_type", type, sizeof(type));
2080 if (strcmp(type, "display") == 0)
2081 prom_setprop(stdout_node, path, "linux,boot-display", NULL, 0);
2082 }
2083}
2084
2085static int __init prom_find_machine_type(void)
2086{
2087 char compat[256];
2088 int len, i = 0;
2089#ifdef CONFIG_PPC64
2090 phandle rtas;
2091 int x;
2092#endif
2093
2094
2095 len = prom_getprop(prom.root, "compatible",
2096 compat, sizeof(compat)-1);
2097 if (len > 0) {
2098 compat[len] = 0;
2099 while (i < len) {
2100 char *p = &compat[i];
2101 int sl = strlen(p);
2102 if (sl == 0)
2103 break;
2104 if (strstr(p, "Power Macintosh") ||
2105 strstr(p, "MacRISC"))
2106 return PLATFORM_POWERMAC;
2107#ifdef CONFIG_PPC64
2108
2109
2110
2111
2112 if (strstr(p, "IBM,CBEA") ||
2113 strstr(p, "IBM,CPBW-1.0"))
2114 return PLATFORM_GENERIC;
2115#endif
2116 i += sl + 1;
2117 }
2118 }
2119#ifdef CONFIG_PPC64
2120
2121 if (PHANDLE_VALID(call_prom("finddevice", 1, 1, ADDR("/ibm,opal"))))
2122 return PLATFORM_OPAL;
2123
2124
2125
2126
2127
2128
2129
2130 len = prom_getprop(prom.root, "device_type",
2131 compat, sizeof(compat)-1);
2132 if (len <= 0)
2133 return PLATFORM_GENERIC;
2134 if (strcmp(compat, "chrp"))
2135 return PLATFORM_GENERIC;
2136
2137
2138 rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
2139 if (!PHANDLE_VALID(rtas))
2140 return PLATFORM_GENERIC;
2141 x = prom_getproplen(rtas, "ibm,hypertas-functions");
2142 if (x != PROM_ERROR) {
2143 prom_debug("Hypertas detected, assuming LPAR !\n");
2144 return PLATFORM_PSERIES_LPAR;
2145 }
2146 return PLATFORM_PSERIES;
2147#else
2148 return PLATFORM_GENERIC;
2149#endif
2150}
2151
2152static int __init prom_set_color(ihandle ih, int i, int r, int g, int b)
2153{
2154 return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r);
2155}
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165static void __init prom_check_displays(void)
2166{
2167 char type[16], *path;
2168 phandle node;
2169 ihandle ih;
2170 int i;
2171
2172 static unsigned char default_colors[] = {
2173 0x00, 0x00, 0x00,
2174 0x00, 0x00, 0xaa,
2175 0x00, 0xaa, 0x00,
2176 0x00, 0xaa, 0xaa,
2177 0xaa, 0x00, 0x00,
2178 0xaa, 0x00, 0xaa,
2179 0xaa, 0xaa, 0x00,
2180 0xaa, 0xaa, 0xaa,
2181 0x55, 0x55, 0x55,
2182 0x55, 0x55, 0xff,
2183 0x55, 0xff, 0x55,
2184 0x55, 0xff, 0xff,
2185 0xff, 0x55, 0x55,
2186 0xff, 0x55, 0xff,
2187 0xff, 0xff, 0x55,
2188 0xff, 0xff, 0xff
2189 };
2190 const unsigned char *clut;
2191
2192 prom_debug("Looking for displays\n");
2193 for (node = 0; prom_next_node(&node); ) {
2194 memset(type, 0, sizeof(type));
2195 prom_getprop(node, "device_type", type, sizeof(type));
2196 if (strcmp(type, "display") != 0)
2197 continue;
2198
2199
2200 path = prom_scratch;
2201 memset(path, 0, PROM_SCRATCH_SIZE);
2202
2203
2204
2205
2206
2207 if (call_prom("package-to-path", 3, 1, node, path,
2208 PROM_SCRATCH_SIZE-10) == PROM_ERROR)
2209 continue;
2210 prom_printf("found display : %s, opening... ", path);
2211
2212 ih = call_prom("open", 1, 1, path);
2213 if (ih == 0) {
2214 prom_printf("failed\n");
2215 continue;
2216 }
2217
2218
2219 prom_printf("done\n");
2220 prom_setprop(node, path, "linux,opened", NULL, 0);
2221
2222
2223
2224 clut = default_colors;
2225 for (i = 0; i < 16; i++, clut += 3)
2226 if (prom_set_color(ih, i, clut[0], clut[1],
2227 clut[2]) != 0)
2228 break;
2229
2230#ifdef CONFIG_LOGO_LINUX_CLUT224
2231 clut = PTRRELOC(logo_linux_clut224.clut);
2232 for (i = 0; i < logo_linux_clut224.clutsize; i++, clut += 3)
2233 if (prom_set_color(ih, i + 32, clut[0], clut[1],
2234 clut[2]) != 0)
2235 break;
2236#endif
2237
2238#ifdef CONFIG_PPC_EARLY_DEBUG_BOOTX
2239 if (prom_getprop(node, "linux,boot-display", NULL, 0) !=
2240 PROM_ERROR) {
2241 u32 width, height, pitch, addr;
2242
2243 prom_printf("Setting btext !\n");
2244 prom_getprop(node, "width", &width, 4);
2245 prom_getprop(node, "height", &height, 4);
2246 prom_getprop(node, "linebytes", &pitch, 4);
2247 prom_getprop(node, "address", &addr, 4);
2248 prom_printf("W=%d H=%d LB=%d addr=0x%x\n",
2249 width, height, pitch, addr);
2250 btext_setup_display(width, height, 8, pitch, addr);
2251 }
2252#endif
2253 }
2254}
2255
2256
2257
2258static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end,
2259 unsigned long needed, unsigned long align)
2260{
2261 void *ret;
2262
2263 *mem_start = _ALIGN(*mem_start, align);
2264 while ((*mem_start + needed) > *mem_end) {
2265 unsigned long room, chunk;
2266
2267 prom_debug("Chunk exhausted, claiming more at %x...\n",
2268 alloc_bottom);
2269 room = alloc_top - alloc_bottom;
2270 if (room > DEVTREE_CHUNK_SIZE)
2271 room = DEVTREE_CHUNK_SIZE;
2272 if (room < PAGE_SIZE)
2273 prom_panic("No memory for flatten_device_tree "
2274 "(no room)\n");
2275 chunk = alloc_up(room, 0);
2276 if (chunk == 0)
2277 prom_panic("No memory for flatten_device_tree "
2278 "(claim failed)\n");
2279 *mem_end = chunk + room;
2280 }
2281
2282 ret = (void *)*mem_start;
2283 *mem_start += needed;
2284
2285 return ret;
2286}
2287
2288#define dt_push_token(token, mem_start, mem_end) do { \
2289 void *room = make_room(mem_start, mem_end, 4, 4); \
2290 *(__be32 *)room = cpu_to_be32(token); \
2291 } while(0)
2292
2293static unsigned long __init dt_find_string(char *str)
2294{
2295 char *s, *os;
2296
2297 s = os = (char *)dt_string_start;
2298 s += 4;
2299 while (s < (char *)dt_string_end) {
2300 if (strcmp(s, str) == 0)
2301 return s - os;
2302 s += strlen(s) + 1;
2303 }
2304 return 0;
2305}
2306
2307
2308
2309
2310
2311#define MAX_PROPERTY_NAME 64
2312
2313static void __init scan_dt_build_strings(phandle node,
2314 unsigned long *mem_start,
2315 unsigned long *mem_end)
2316{
2317 char *prev_name, *namep, *sstart;
2318 unsigned long soff;
2319 phandle child;
2320
2321 sstart = (char *)dt_string_start;
2322
2323
2324 prev_name = "";
2325 for (;;) {
2326
2327 namep = make_room(mem_start, mem_end, MAX_PROPERTY_NAME, 1);
2328 if (call_prom("nextprop", 3, 1, node, prev_name, namep) != 1) {
2329
2330 *mem_start = (unsigned long)namep;
2331 break;
2332 }
2333
2334
2335 if (strcmp(namep, "name") == 0) {
2336 *mem_start = (unsigned long)namep;
2337 prev_name = "name";
2338 continue;
2339 }
2340
2341 soff = dt_find_string(namep);
2342 if (soff != 0) {
2343 *mem_start = (unsigned long)namep;
2344 namep = sstart + soff;
2345 } else {
2346
2347 *mem_start = (unsigned long)namep + strlen(namep) + 1;
2348 dt_string_end = *mem_start;
2349 }
2350 prev_name = namep;
2351 }
2352
2353
2354 child = call_prom("child", 1, 1, node);
2355 while (child != 0) {
2356 scan_dt_build_strings(child, mem_start, mem_end);
2357 child = call_prom("peer", 1, 1, child);
2358 }
2359}
2360
2361static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,
2362 unsigned long *mem_end)
2363{
2364 phandle child;
2365 char *namep, *prev_name, *sstart, *p, *ep, *lp, *path;
2366 unsigned long soff;
2367 unsigned char *valp;
2368 static char pname[MAX_PROPERTY_NAME];
2369 int l, room, has_phandle = 0;
2370
2371 dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end);
2372
2373
2374 namep = (char *)*mem_start;
2375 room = *mem_end - *mem_start;
2376 if (room > 255)
2377 room = 255;
2378 l = call_prom("package-to-path", 3, 1, node, namep, room);
2379 if (l >= 0) {
2380
2381 if (l >= room) {
2382 if (l >= *mem_end - *mem_start)
2383 namep = make_room(mem_start, mem_end, l+1, 1);
2384 call_prom("package-to-path", 3, 1, node, namep, l);
2385 }
2386 namep[l] = '\0';
2387
2388
2389
2390
2391
2392 for (lp = p = namep, ep = namep + l; p < ep; p++) {
2393 if (*p == '/')
2394 lp = namep;
2395 else if (*p != 0)
2396 *lp++ = *p;
2397 }
2398 *lp = 0;
2399 *mem_start = _ALIGN((unsigned long)lp + 1, 4);
2400 }
2401
2402
2403 path = prom_scratch;
2404 memset(path, 0, PROM_SCRATCH_SIZE);
2405 call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
2406
2407
2408 prev_name = "";
2409 sstart = (char *)dt_string_start;
2410 for (;;) {
2411 if (call_prom("nextprop", 3, 1, node, prev_name,
2412 pname) != 1)
2413 break;
2414
2415
2416 if (strcmp(pname, "name") == 0) {
2417 prev_name = "name";
2418 continue;
2419 }
2420
2421
2422 soff = dt_find_string(pname);
2423 if (soff == 0) {
2424 prom_printf("WARNING: Can't find string index for"
2425 " <%s>, node %s\n", pname, path);
2426 break;
2427 }
2428 prev_name = sstart + soff;
2429
2430
2431 l = call_prom("getproplen", 2, 1, node, pname);
2432
2433
2434 if (l == PROM_ERROR)
2435 continue;
2436
2437
2438 dt_push_token(OF_DT_PROP, mem_start, mem_end);
2439 dt_push_token(l, mem_start, mem_end);
2440 dt_push_token(soff, mem_start, mem_end);
2441
2442
2443 valp = make_room(mem_start, mem_end, l, 4);
2444 call_prom("getprop", 4, 1, node, pname, valp, l);
2445 *mem_start = _ALIGN(*mem_start, 4);
2446
2447 if (!strcmp(pname, "phandle"))
2448 has_phandle = 1;
2449 }
2450
2451
2452
2453
2454 if (!has_phandle) {
2455 soff = dt_find_string("linux,phandle");
2456 if (soff == 0)
2457 prom_printf("WARNING: Can't find string index for"
2458 " <linux-phandle> node %s\n", path);
2459 else {
2460 dt_push_token(OF_DT_PROP, mem_start, mem_end);
2461 dt_push_token(4, mem_start, mem_end);
2462 dt_push_token(soff, mem_start, mem_end);
2463 valp = make_room(mem_start, mem_end, 4, 4);
2464 *(__be32 *)valp = cpu_to_be32(node);
2465 }
2466 }
2467
2468
2469 child = call_prom("child", 1, 1, node);
2470 while (child != 0) {
2471 scan_dt_build_struct(child, mem_start, mem_end);
2472 child = call_prom("peer", 1, 1, child);
2473 }
2474
2475 dt_push_token(OF_DT_END_NODE, mem_start, mem_end);
2476}
2477
2478static void __init flatten_device_tree(void)
2479{
2480 phandle root;
2481 unsigned long mem_start, mem_end, room;
2482 struct boot_param_header *hdr;
2483 char *namep;
2484 u64 *rsvmap;
2485
2486
2487
2488
2489
2490 room = alloc_top - alloc_bottom - 0x4000;
2491 if (room > DEVTREE_CHUNK_SIZE)
2492 room = DEVTREE_CHUNK_SIZE;
2493 prom_debug("starting device tree allocs at %x\n", alloc_bottom);
2494
2495
2496 mem_start = (unsigned long)alloc_up(room, PAGE_SIZE);
2497 if (mem_start == 0)
2498 prom_panic("Can't allocate initial device-tree chunk\n");
2499 mem_end = mem_start + room;
2500
2501
2502 root = call_prom("peer", 1, 1, (phandle)0);
2503 if (root == (phandle)0)
2504 prom_panic ("couldn't get device tree root\n");
2505
2506
2507 mem_start = _ALIGN(mem_start, 4);
2508 hdr = make_room(&mem_start, &mem_end,
2509 sizeof(struct boot_param_header), 4);
2510 dt_header_start = (unsigned long)hdr;
2511 rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8);
2512
2513
2514 mem_start = PAGE_ALIGN(mem_start);
2515 dt_string_start = mem_start;
2516 mem_start += 4;
2517
2518
2519 namep = make_room(&mem_start, &mem_end, 16, 1);
2520 strcpy(namep, "linux,phandle");
2521 mem_start = (unsigned long)namep + strlen(namep) + 1;
2522
2523
2524 prom_printf("Building dt strings...\n");
2525 scan_dt_build_strings(root, &mem_start, &mem_end);
2526 dt_string_end = mem_start;
2527
2528
2529 mem_start = PAGE_ALIGN(mem_start);
2530 dt_struct_start = mem_start;
2531 prom_printf("Building dt structure...\n");
2532 scan_dt_build_struct(root, &mem_start, &mem_end);
2533 dt_push_token(OF_DT_END, &mem_start, &mem_end);
2534 dt_struct_end = PAGE_ALIGN(mem_start);
2535
2536
2537 hdr->boot_cpuid_phys = cpu_to_be32(prom.cpu);
2538 hdr->magic = cpu_to_be32(OF_DT_HEADER);
2539 hdr->totalsize = cpu_to_be32(dt_struct_end - dt_header_start);
2540 hdr->off_dt_struct = cpu_to_be32(dt_struct_start - dt_header_start);
2541 hdr->off_dt_strings = cpu_to_be32(dt_string_start - dt_header_start);
2542 hdr->dt_strings_size = cpu_to_be32(dt_string_end - dt_string_start);
2543 hdr->off_mem_rsvmap = cpu_to_be32(((unsigned long)rsvmap) - dt_header_start);
2544 hdr->version = cpu_to_be32(OF_DT_VERSION);
2545
2546 hdr->last_comp_version = cpu_to_be32(0x10);
2547
2548
2549 memcpy(rsvmap, mem_reserve_map, sizeof(mem_reserve_map));
2550
2551#ifdef DEBUG_PROM
2552 {
2553 int i;
2554 prom_printf("reserved memory map:\n");
2555 for (i = 0; i < mem_reserve_cnt; i++)
2556 prom_printf(" %x - %x\n",
2557 be64_to_cpu(mem_reserve_map[i].base),
2558 be64_to_cpu(mem_reserve_map[i].size));
2559 }
2560#endif
2561
2562
2563
2564 mem_reserve_cnt = MEM_RESERVE_MAP_SIZE;
2565
2566 prom_printf("Device tree strings 0x%x -> 0x%x\n",
2567 dt_string_start, dt_string_end);
2568 prom_printf("Device tree struct 0x%x -> 0x%x\n",
2569 dt_struct_start, dt_struct_end);
2570}
2571
2572#ifdef CONFIG_PPC_MAPLE
2573
2574
2575static void __init fixup_device_tree_maple(void)
2576{
2577 phandle isa;
2578 u32 rloc = 0x01002000;
2579 u32 isa_ranges[6];
2580 char *name;
2581
2582 name = "/ht@0/isa@4";
2583 isa = call_prom("finddevice", 1, 1, ADDR(name));
2584 if (!PHANDLE_VALID(isa)) {
2585 name = "/ht@0/isa@6";
2586 isa = call_prom("finddevice", 1, 1, ADDR(name));
2587 rloc = 0x01003000;
2588 }
2589 if (!PHANDLE_VALID(isa))
2590 return;
2591
2592 if (prom_getproplen(isa, "ranges") != 12)
2593 return;
2594 if (prom_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges))
2595 == PROM_ERROR)
2596 return;
2597
2598 if (isa_ranges[0] != 0x1 ||
2599 isa_ranges[1] != 0xf4000000 ||
2600 isa_ranges[2] != 0x00010000)
2601 return;
2602
2603 prom_printf("Fixing up bogus ISA range on Maple/Apache...\n");
2604
2605 isa_ranges[0] = 0x1;
2606 isa_ranges[1] = 0x0;
2607 isa_ranges[2] = rloc;
2608 isa_ranges[3] = 0x0;
2609 isa_ranges[4] = 0x0;
2610 isa_ranges[5] = 0x00010000;
2611 prom_setprop(isa, name, "ranges",
2612 isa_ranges, sizeof(isa_ranges));
2613}
2614
2615#define CPC925_MC_START 0xf8000000
2616#define CPC925_MC_LENGTH 0x1000000
2617
2618static void __init fixup_device_tree_maple_memory_controller(void)
2619{
2620 phandle mc;
2621 u32 mc_reg[4];
2622 char *name = "/hostbridge@f8000000";
2623 u32 ac, sc;
2624
2625 mc = call_prom("finddevice", 1, 1, ADDR(name));
2626 if (!PHANDLE_VALID(mc))
2627 return;
2628
2629 if (prom_getproplen(mc, "reg") != 8)
2630 return;
2631
2632 prom_getprop(prom.root, "#address-cells", &ac, sizeof(ac));
2633 prom_getprop(prom.root, "#size-cells", &sc, sizeof(sc));
2634 if ((ac != 2) || (sc != 2))
2635 return;
2636
2637 if (prom_getprop(mc, "reg", mc_reg, sizeof(mc_reg)) == PROM_ERROR)
2638 return;
2639
2640 if (mc_reg[0] != CPC925_MC_START || mc_reg[1] != CPC925_MC_LENGTH)
2641 return;
2642
2643 prom_printf("Fixing up bogus hostbridge on Maple...\n");
2644
2645 mc_reg[0] = 0x0;
2646 mc_reg[1] = CPC925_MC_START;
2647 mc_reg[2] = 0x0;
2648 mc_reg[3] = CPC925_MC_LENGTH;
2649 prom_setprop(mc, name, "reg", mc_reg, sizeof(mc_reg));
2650}
2651#else
2652#define fixup_device_tree_maple()
2653#define fixup_device_tree_maple_memory_controller()
2654#endif
2655
2656#ifdef CONFIG_PPC_CHRP
2657
2658
2659
2660
2661
2662static void __init fixup_device_tree_chrp(void)
2663{
2664 phandle ph;
2665 u32 prop[6];
2666 u32 rloc = 0x01006000;
2667 char *name;
2668 int rc;
2669
2670 name = "/pci@80000000/isa@c";
2671 ph = call_prom("finddevice", 1, 1, ADDR(name));
2672 if (!PHANDLE_VALID(ph)) {
2673 name = "/pci@ff500000/isa@6";
2674 ph = call_prom("finddevice", 1, 1, ADDR(name));
2675 rloc = 0x01003000;
2676 }
2677 if (PHANDLE_VALID(ph)) {
2678 rc = prom_getproplen(ph, "ranges");
2679 if (rc == 0 || rc == PROM_ERROR) {
2680 prom_printf("Fixing up missing ISA range on Pegasos...\n");
2681
2682 prop[0] = 0x1;
2683 prop[1] = 0x0;
2684 prop[2] = rloc;
2685 prop[3] = 0x0;
2686 prop[4] = 0x0;
2687 prop[5] = 0x00010000;
2688 prom_setprop(ph, name, "ranges", prop, sizeof(prop));
2689 }
2690 }
2691
2692 name = "/pci@80000000/ide@C,1";
2693 ph = call_prom("finddevice", 1, 1, ADDR(name));
2694 if (PHANDLE_VALID(ph)) {
2695 prom_printf("Fixing up IDE interrupt on Pegasos...\n");
2696 prop[0] = 14;
2697 prop[1] = 0x0;
2698 prom_setprop(ph, name, "interrupts", prop, 2*sizeof(u32));
2699 prom_printf("Fixing up IDE class-code on Pegasos...\n");
2700 rc = prom_getprop(ph, "class-code", prop, sizeof(u32));
2701 if (rc == sizeof(u32)) {
2702 prop[0] &= ~0x5;
2703 prom_setprop(ph, name, "class-code", prop, sizeof(u32));
2704 }
2705 }
2706}
2707#else
2708#define fixup_device_tree_chrp()
2709#endif
2710
2711#if defined(CONFIG_PPC64) && defined(CONFIG_PPC_PMAC)
2712static void __init fixup_device_tree_pmac(void)
2713{
2714 phandle u3, i2c, mpic;
2715 u32 u3_rev;
2716 u32 interrupts[2];
2717 u32 parent;
2718
2719
2720 u3 = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000"));
2721 if (!PHANDLE_VALID(u3))
2722 return;
2723 i2c = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/i2c@f8001000"));
2724 if (!PHANDLE_VALID(i2c))
2725 return;
2726 mpic = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/mpic@f8040000"));
2727 if (!PHANDLE_VALID(mpic))
2728 return;
2729
2730
2731 if (prom_getprop(u3, "device-rev", &u3_rev, sizeof(u3_rev))
2732 == PROM_ERROR)
2733 return;
2734 if (u3_rev < 0x35 || u3_rev > 0x39)
2735 return;
2736
2737 if (prom_getproplen(i2c, "interrupts") > 0)
2738 return;
2739
2740 prom_printf("fixing up bogus interrupts for u3 i2c...\n");
2741
2742
2743 interrupts[0] = 0;
2744 interrupts[1] = 1;
2745 prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupts",
2746 &interrupts, sizeof(interrupts));
2747 parent = (u32)mpic;
2748 prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupt-parent",
2749 &parent, sizeof(parent));
2750}
2751#else
2752#define fixup_device_tree_pmac()
2753#endif
2754
2755#ifdef CONFIG_PPC_EFIKA
2756
2757
2758
2759
2760
2761
2762static void __init fixup_device_tree_efika_add_phy(void)
2763{
2764 u32 node;
2765 char prop[64];
2766 int rv;
2767
2768
2769 node = call_prom("finddevice", 1, 1, ADDR("/builtin/ethernet"));
2770 if (!PHANDLE_VALID(node))
2771 return;
2772
2773
2774 rv = prom_getprop(node, "phy-handle", prop, sizeof(prop));
2775 if (!rv)
2776 return;
2777
2778
2779
2780
2781
2782
2783
2784 node = call_prom("finddevice", 1, 1, ADDR("/builtin/mdio"));
2785 if (!PHANDLE_VALID(node)) {
2786 prom_printf("Adding Ethernet MDIO node\n");
2787 call_prom("interpret", 1, 1,
2788 " s\" /builtin\" find-device"
2789 " new-device"
2790 " 1 encode-int s\" #address-cells\" property"
2791 " 0 encode-int s\" #size-cells\" property"
2792 " s\" mdio\" device-name"
2793 " s\" fsl,mpc5200b-mdio\" encode-string"
2794 " s\" compatible\" property"
2795 " 0xf0003000 0x400 reg"
2796 " 0x2 encode-int"
2797 " 0x5 encode-int encode+"
2798 " 0x3 encode-int encode+"
2799 " s\" interrupts\" property"
2800 " finish-device");
2801 };
2802
2803
2804
2805 node = call_prom("finddevice", 1, 1,
2806 ADDR("/builtin/mdio/ethernet-phy"));
2807 if (!PHANDLE_VALID(node)) {
2808 prom_printf("Adding Ethernet PHY node\n");
2809 call_prom("interpret", 1, 1,
2810 " s\" /builtin/mdio\" find-device"
2811 " new-device"
2812 " s\" ethernet-phy\" device-name"
2813 " 0x10 encode-int s\" reg\" property"
2814 " my-self"
2815 " ihandle>phandle"
2816 " finish-device"
2817 " s\" /builtin/ethernet\" find-device"
2818 " encode-int"
2819 " s\" phy-handle\" property"
2820 " device-end");
2821 }
2822}
2823
2824static void __init fixup_device_tree_efika(void)
2825{
2826 int sound_irq[3] = { 2, 2, 0 };
2827 int bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0,
2828 3,4,0, 3,5,0, 3,6,0, 3,7,0,
2829 3,8,0, 3,9,0, 3,10,0, 3,11,0,
2830 3,12,0, 3,13,0, 3,14,0, 3,15,0 };
2831 u32 node;
2832 char prop[64];
2833 int rv, len;
2834
2835
2836 node = call_prom("finddevice", 1, 1, ADDR("/"));
2837 if (!PHANDLE_VALID(node))
2838 return;
2839
2840 rv = prom_getprop(node, "model", prop, sizeof(prop));
2841 if (rv == PROM_ERROR)
2842 return;
2843 if (strcmp(prop, "EFIKA5K2"))
2844 return;
2845
2846 prom_printf("Applying EFIKA device tree fixups\n");
2847
2848
2849 node = call_prom("finddevice", 1, 1, ADDR("/"));
2850 rv = prom_getprop(node, "device_type", prop, sizeof(prop));
2851 if (rv != PROM_ERROR && (strcmp(prop, "chrp") == 0))
2852 prom_setprop(node, "/", "device_type", "efika", sizeof("efika"));
2853
2854
2855
2856 rv = prom_getprop(node, "CODEGEN,description", prop, sizeof(prop));
2857 if (rv != PROM_ERROR && (strstr(prop, "CHRP")))
2858 prom_setprop(node, "/", "CODEGEN,description",
2859 "Efika 5200B PowerPC System",
2860 sizeof("Efika 5200B PowerPC System"));
2861
2862
2863 node = call_prom("finddevice", 1, 1, ADDR("/builtin/bestcomm"));
2864 if (PHANDLE_VALID(node)) {
2865 len = prom_getproplen(node, "interrupts");
2866 if (len == 12) {
2867 prom_printf("Fixing bestcomm interrupts property\n");
2868 prom_setprop(node, "/builtin/bestcom", "interrupts",
2869 bcomm_irq, sizeof(bcomm_irq));
2870 }
2871 }
2872
2873
2874 node = call_prom("finddevice", 1, 1, ADDR("/builtin/sound"));
2875 if (PHANDLE_VALID(node)) {
2876 rv = prom_getprop(node, "interrupts", prop, sizeof(prop));
2877 if (rv == PROM_ERROR) {
2878 prom_printf("Adding sound interrupts property\n");
2879 prom_setprop(node, "/builtin/sound", "interrupts",
2880 sound_irq, sizeof(sound_irq));
2881 }
2882 }
2883
2884
2885 fixup_device_tree_efika_add_phy();
2886}
2887#else
2888#define fixup_device_tree_efika()
2889#endif
2890
2891#ifdef CONFIG_PPC_PASEMI_NEMO
2892
2893
2894
2895
2896
2897
2898static void __init fixup_device_tree_pasemi(void)
2899{
2900 u32 interrupts[2], parent, rval, val = 0;
2901 char *name, *pci_name;
2902 phandle iob, node;
2903
2904
2905 name = "/pxp@0,e0000000";
2906 iob = call_prom("finddevice", 1, 1, ADDR(name));
2907 if (!PHANDLE_VALID(iob))
2908 return;
2909
2910
2911 if (prom_getproplen(iob, "interrupt-controller") !=PROM_ERROR)
2912 return;
2913
2914 prom_printf("adding interrupt-controller property for SB600...\n");
2915
2916 prom_setprop(iob, name, "interrupt-controller", &val, 0);
2917
2918 pci_name = "/pxp@0,e0000000/pci@11";
2919 node = call_prom("finddevice", 1, 1, ADDR(pci_name));
2920 parent = ADDR(iob);
2921
2922 for( ; prom_next_node(&node); ) {
2923
2924 if (!PHANDLE_VALID(node))
2925 continue;
2926
2927 rval = prom_getproplen(node, "interrupts");
2928 if (rval == 0 || rval == PROM_ERROR)
2929 continue;
2930
2931 prom_getprop(node, "interrupts", &interrupts, sizeof(interrupts));
2932 if ((interrupts[0] < 212) || (interrupts[0] > 222))
2933 continue;
2934
2935
2936 if ((interrupts[0] >= 212) && (interrupts[0] <= 215))
2937 interrupts[0] -= 203;
2938 if ((interrupts[0] >= 216) && (interrupts[0] <= 220))
2939 interrupts[0] -= 213;
2940 if (interrupts[0] == 221)
2941 interrupts[0] = 14;
2942 if (interrupts[0] == 222)
2943 interrupts[0] = 8;
2944
2945 prom_setprop(node, pci_name, "interrupts", interrupts,
2946 sizeof(interrupts));
2947 prom_setprop(node, pci_name, "interrupt-parent", &parent,
2948 sizeof(parent));
2949 }
2950
2951
2952
2953
2954
2955
2956 name = "/pxp@0,e0000000/io-bridge@0";
2957 iob = call_prom("finddevice", 1, 1, ADDR(name));
2958 if (!PHANDLE_VALID(iob))
2959 return;
2960
2961
2962
2963 prom_printf("Changing device_type of SB600 node...\n");
2964
2965 prom_setprop(iob, name, "device_type", "isa", sizeof("isa"));
2966}
2967#else
2968static inline void fixup_device_tree_pasemi(void) { }
2969#endif
2970
2971static void __init fixup_device_tree(void)
2972{
2973 fixup_device_tree_maple();
2974 fixup_device_tree_maple_memory_controller();
2975 fixup_device_tree_chrp();
2976 fixup_device_tree_pmac();
2977 fixup_device_tree_efika();
2978 fixup_device_tree_pasemi();
2979}
2980
2981static void __init prom_find_boot_cpu(void)
2982{
2983 __be32 rval;
2984 ihandle prom_cpu;
2985 phandle cpu_pkg;
2986
2987 rval = 0;
2988 if (prom_getprop(prom.chosen, "cpu", &rval, sizeof(rval)) <= 0)
2989 return;
2990 prom_cpu = be32_to_cpu(rval);
2991
2992 cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu);
2993
2994 if (!PHANDLE_VALID(cpu_pkg))
2995 return;
2996
2997 prom_getprop(cpu_pkg, "reg", &rval, sizeof(rval));
2998 prom.cpu = be32_to_cpu(rval);
2999
3000 prom_debug("Booting CPU hw index = %lu\n", prom.cpu);
3001}
3002
3003static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
3004{
3005#ifdef CONFIG_BLK_DEV_INITRD
3006 if (r3 && r4 && r4 != 0xdeadbeef) {
3007 __be64 val;
3008
3009 prom_initrd_start = is_kernel_addr(r3) ? __pa(r3) : r3;
3010 prom_initrd_end = prom_initrd_start + r4;
3011
3012 val = cpu_to_be64(prom_initrd_start);
3013 prom_setprop(prom.chosen, "/chosen", "linux,initrd-start",
3014 &val, sizeof(val));
3015 val = cpu_to_be64(prom_initrd_end);
3016 prom_setprop(prom.chosen, "/chosen", "linux,initrd-end",
3017 &val, sizeof(val));
3018
3019 reserve_mem(prom_initrd_start,
3020 prom_initrd_end - prom_initrd_start);
3021
3022 prom_debug("initrd_start=0x%x\n", prom_initrd_start);
3023 prom_debug("initrd_end=0x%x\n", prom_initrd_end);
3024 }
3025#endif
3026}
3027
3028#ifdef CONFIG_PPC64
3029#ifdef CONFIG_RELOCATABLE
3030static void reloc_toc(void)
3031{
3032}
3033
3034static void unreloc_toc(void)
3035{
3036}
3037#else
3038static void __reloc_toc(unsigned long offset, unsigned long nr_entries)
3039{
3040 unsigned long i;
3041 unsigned long *toc_entry;
3042
3043
3044 asm volatile("addi %0,2,-0x8000" : "=b" (toc_entry));
3045
3046 for (i = 0; i < nr_entries; i++) {
3047 *toc_entry = *toc_entry + offset;
3048 toc_entry++;
3049 }
3050}
3051
3052static void reloc_toc(void)
3053{
3054 unsigned long offset = reloc_offset();
3055 unsigned long nr_entries =
3056 (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long);
3057
3058 __reloc_toc(offset, nr_entries);
3059
3060 mb();
3061}
3062
3063static void unreloc_toc(void)
3064{
3065 unsigned long offset = reloc_offset();
3066 unsigned long nr_entries =
3067 (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long);
3068
3069 mb();
3070
3071 __reloc_toc(-offset, nr_entries);
3072}
3073#endif
3074#endif
3075
3076
3077
3078
3079
3080
3081unsigned long __init prom_init(unsigned long r3, unsigned long r4,
3082 unsigned long pp,
3083 unsigned long r6, unsigned long r7,
3084 unsigned long kbase)
3085{
3086 unsigned long hdr;
3087
3088#ifdef CONFIG_PPC32
3089 unsigned long offset = reloc_offset();
3090 reloc_got2(offset);
3091#else
3092 reloc_toc();
3093#endif
3094
3095
3096
3097
3098 memset(&__bss_start, 0, __bss_stop - __bss_start);
3099
3100
3101
3102
3103
3104 prom_init_client_services(pp);
3105
3106
3107
3108
3109
3110 prom_find_mmu();
3111
3112
3113
3114
3115 prom_init_stdout();
3116
3117 prom_printf("Preparing to boot %s", linux_banner);
3118
3119
3120
3121
3122
3123 of_platform = prom_find_machine_type();
3124 prom_printf("Detected machine type: %x\n", of_platform);
3125
3126#ifndef CONFIG_NONSTATIC_KERNEL
3127
3128 if (PHYSICAL_START > 0)
3129 prom_panic("Error: You can't boot a kdump kernel from OF!\n");
3130#endif
3131
3132
3133
3134
3135 prom_check_initrd(r3, r4);
3136
3137
3138
3139
3140 early_cmdline_parse();
3141
3142#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
3143
3144
3145
3146 if (of_platform == PLATFORM_PSERIES ||
3147 of_platform == PLATFORM_PSERIES_LPAR)
3148 prom_send_capabilities();
3149#endif
3150
3151
3152
3153
3154 if (of_platform != PLATFORM_POWERMAC)
3155 copy_and_flush(0, kbase, 0x100, 0);
3156
3157
3158
3159
3160 prom_init_mem();
3161
3162
3163
3164
3165 prom_find_boot_cpu();
3166
3167
3168
3169
3170 prom_check_displays();
3171
3172#if defined(CONFIG_PPC64) && defined(__BIG_ENDIAN__)
3173
3174
3175
3176
3177
3178 if (of_platform == PLATFORM_PSERIES)
3179 prom_initialize_tce_table();
3180#endif
3181
3182
3183
3184
3185
3186 if (of_platform != PLATFORM_POWERMAC &&
3187 of_platform != PLATFORM_OPAL)
3188 prom_instantiate_rtas();
3189
3190#ifdef CONFIG_PPC_POWERNV
3191 if (of_platform == PLATFORM_OPAL)
3192 prom_instantiate_opal();
3193#endif
3194
3195#ifdef CONFIG_PPC64
3196
3197 prom_instantiate_sml();
3198#endif
3199
3200
3201
3202
3203
3204
3205
3206
3207 if (of_platform != PLATFORM_POWERMAC &&
3208 of_platform != PLATFORM_OPAL)
3209 prom_hold_cpus();
3210
3211
3212
3213
3214 if (prom_memory_limit) {
3215 __be64 val = cpu_to_be64(prom_memory_limit);
3216 prom_setprop(prom.chosen, "/chosen", "linux,memory-limit",
3217 &val, sizeof(val));
3218 }
3219#ifdef CONFIG_PPC64
3220 if (prom_iommu_off)
3221 prom_setprop(prom.chosen, "/chosen", "linux,iommu-off",
3222 NULL, 0);
3223
3224 if (prom_iommu_force_on)
3225 prom_setprop(prom.chosen, "/chosen", "linux,iommu-force-on",
3226 NULL, 0);
3227
3228 if (prom_tce_alloc_start) {
3229 prom_setprop(prom.chosen, "/chosen", "linux,tce-alloc-start",
3230 &prom_tce_alloc_start,
3231 sizeof(prom_tce_alloc_start));
3232 prom_setprop(prom.chosen, "/chosen", "linux,tce-alloc-end",
3233 &prom_tce_alloc_end,
3234 sizeof(prom_tce_alloc_end));
3235 }
3236#endif
3237
3238
3239
3240
3241 fixup_device_tree();
3242
3243
3244
3245
3246 prom_printf("copying OF device tree...\n");
3247 flatten_device_tree();
3248
3249
3250
3251
3252
3253
3254
3255 if (of_platform != PLATFORM_POWERMAC &&
3256 of_platform != PLATFORM_OPAL)
3257 prom_close_stdin();
3258
3259
3260
3261
3262
3263 prom_printf("Quiescing Open Firmware ...\n");
3264 call_prom("quiesce", 0, 0);
3265
3266
3267
3268
3269
3270
3271 hdr = dt_header_start;
3272
3273
3274 if (of_platform != PLATFORM_OPAL) {
3275 prom_printf("Booting Linux via __start() @ 0x%lx ...\n", kbase);
3276 prom_debug("->dt_header_start=0x%x\n", hdr);
3277 }
3278
3279#ifdef CONFIG_PPC32
3280 reloc_got2(-offset);
3281#else
3282 unreloc_toc();
3283#endif
3284
3285#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
3286
3287 __start(hdr, kbase, 0, 0, 0,
3288 prom_opal_base, prom_opal_entry);
3289#else
3290 __start(hdr, kbase, 0, 0, 0, 0, 0);
3291#endif
3292
3293 return 0;
3294}
3295