1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#undef DEBUG_PROM
17
18#include <stdarg.h>
19#include <linux/kernel.h>
20#include <linux/string.h>
21#include <linux/init.h>
22#include <linux/threads.h>
23#include <linux/spinlock.h>
24#include <linux/types.h>
25#include <linux/pci.h>
26#include <linux/proc_fs.h>
27#include <linux/stringify.h>
28#include <linux/delay.h>
29#include <linux/initrd.h>
30#include <linux/bitops.h>
31#include <asm/prom.h>
32#include <asm/rtas.h>
33#include <asm/page.h>
34#include <asm/processor.h>
35#include <asm/irq.h>
36#include <asm/io.h>
37#include <asm/smp.h>
38#include <asm/system.h>
39#include <asm/mmu.h>
40#include <asm/pgtable.h>
41#include <asm/pci.h>
42#include <asm/iommu.h>
43#include <asm/btext.h>
44#include <asm/sections.h>
45#include <asm/machdep.h>
46
47#include <linux/linux_logo.h>
48
49
50
51
52
53
54
55#define MAX_PROPERTY_LENGTH (1UL * 1024 * 1024)
56
57
58
59
60#define DEVTREE_CHUNK_SIZE 0x100000
61
62
63
64
65
66
67
68
69#define MEM_RESERVE_MAP_SIZE 8
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90#ifdef CONFIG_PPC64
91#define RELOC(x) (*PTRRELOC(&(x)))
92#define ADDR(x) (u32) add_reloc_offset((unsigned long)(x))
93#define OF_WORKAROUNDS 0
94#else
95#define RELOC(x) (x)
96#define ADDR(x) (u32) (x)
97#define OF_WORKAROUNDS of_workarounds
98int of_workarounds;
99#endif
100
101#define OF_WA_CLAIM 1
102#define OF_WA_LONGTRAIL 2
103
104#define PROM_BUG() do { \
105 prom_printf("kernel BUG at %s line 0x%x!\n", \
106 RELOC(__FILE__), __LINE__); \
107 __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \
108} while (0)
109
110#ifdef DEBUG_PROM
111#define prom_debug(x...) prom_printf(x)
112#else
113#define prom_debug(x...)
114#endif
115
116
117typedef u32 prom_arg_t;
118
119struct prom_args {
120 u32 service;
121 u32 nargs;
122 u32 nret;
123 prom_arg_t args[10];
124};
125
126struct prom_t {
127 ihandle root;
128 phandle chosen;
129 int cpu;
130 ihandle stdout;
131 ihandle mmumap;
132 ihandle memory;
133};
134
135struct mem_map_entry {
136 u64 base;
137 u64 size;
138};
139
140typedef u32 cell_t;
141
142extern void __start(unsigned long r3, unsigned long r4, unsigned long r5);
143
144#ifdef CONFIG_PPC64
145extern int enter_prom(struct prom_args *args, unsigned long entry);
146#else
147static inline int enter_prom(struct prom_args *args, unsigned long entry)
148{
149 return ((int (*)(struct prom_args *))entry)(args);
150}
151#endif
152
153extern void copy_and_flush(unsigned long dest, unsigned long src,
154 unsigned long size, unsigned long offset);
155
156
157static struct prom_t __initdata prom;
158
159static unsigned long prom_entry __initdata;
160
161#define PROM_SCRATCH_SIZE 256
162
163static char __initdata of_stdout_device[256];
164static char __initdata prom_scratch[PROM_SCRATCH_SIZE];
165
166static unsigned long __initdata dt_header_start;
167static unsigned long __initdata dt_struct_start, dt_struct_end;
168static unsigned long __initdata dt_string_start, dt_string_end;
169
170static unsigned long __initdata prom_initrd_start, prom_initrd_end;
171
172#ifdef CONFIG_PPC64
173static int __initdata prom_iommu_force_on;
174static int __initdata prom_iommu_off;
175static unsigned long __initdata prom_tce_alloc_start;
176static unsigned long __initdata prom_tce_alloc_end;
177#endif
178
179
180
181
182
183#define PLATFORM_PSERIES 0x0100
184#define PLATFORM_PSERIES_LPAR 0x0101
185#define PLATFORM_LPAR 0x0001
186#define PLATFORM_POWERMAC 0x0400
187#define PLATFORM_GENERIC 0x0500
188
189static int __initdata of_platform;
190
191static char __initdata prom_cmd_line[COMMAND_LINE_SIZE];
192
193static unsigned long __initdata prom_memory_limit;
194
195static unsigned long __initdata alloc_top;
196static unsigned long __initdata alloc_top_high;
197static unsigned long __initdata alloc_bottom;
198static unsigned long __initdata rmo_top;
199static unsigned long __initdata ram_top;
200
201static struct mem_map_entry __initdata mem_reserve_map[MEM_RESERVE_MAP_SIZE];
202static int __initdata mem_reserve_cnt;
203
204static cell_t __initdata regbuf[1024];
205
206
207
208
209
210
211
212
213
214#define PROM_ERROR (-1u)
215#define PHANDLE_VALID(p) ((p) != 0 && (p) != PROM_ERROR)
216#define IHANDLE_VALID(i) ((i) != 0 && (i) != PROM_ERROR)
217
218
219
220
221
222
223static int __init call_prom(const char *service, int nargs, int nret, ...)
224{
225 int i;
226 struct prom_args args;
227 va_list list;
228
229 args.service = ADDR(service);
230 args.nargs = nargs;
231 args.nret = nret;
232
233 va_start(list, nret);
234 for (i = 0; i < nargs; i++)
235 args.args[i] = va_arg(list, prom_arg_t);
236 va_end(list);
237
238 for (i = 0; i < nret; i++)
239 args.args[nargs+i] = 0;
240
241 if (enter_prom(&args, RELOC(prom_entry)) < 0)
242 return PROM_ERROR;
243
244 return (nret > 0) ? args.args[nargs] : 0;
245}
246
247static int __init call_prom_ret(const char *service, int nargs, int nret,
248 prom_arg_t *rets, ...)
249{
250 int i;
251 struct prom_args args;
252 va_list list;
253
254 args.service = ADDR(service);
255 args.nargs = nargs;
256 args.nret = nret;
257
258 va_start(list, rets);
259 for (i = 0; i < nargs; i++)
260 args.args[i] = va_arg(list, prom_arg_t);
261 va_end(list);
262
263 for (i = 0; i < nret; i++)
264 args.args[nargs+i] = 0;
265
266 if (enter_prom(&args, RELOC(prom_entry)) < 0)
267 return PROM_ERROR;
268
269 if (rets != NULL)
270 for (i = 1; i < nret; ++i)
271 rets[i-1] = args.args[nargs+i];
272
273 return (nret > 0) ? args.args[nargs] : 0;
274}
275
276
277static void __init prom_print(const char *msg)
278{
279 const char *p, *q;
280 struct prom_t *_prom = &RELOC(prom);
281
282 if (_prom->stdout == 0)
283 return;
284
285 for (p = msg; *p != 0; p = q) {
286 for (q = p; *q != 0 && *q != '\n'; ++q)
287 ;
288 if (q > p)
289 call_prom("write", 3, 1, _prom->stdout, p, q - p);
290 if (*q == 0)
291 break;
292 ++q;
293 call_prom("write", 3, 1, _prom->stdout, ADDR("\r\n"), 2);
294 }
295}
296
297
298static void __init prom_print_hex(unsigned long val)
299{
300 int i, nibbles = sizeof(val)*2;
301 char buf[sizeof(val)*2+1];
302 struct prom_t *_prom = &RELOC(prom);
303
304 for (i = nibbles-1; i >= 0; i--) {
305 buf[i] = (val & 0xf) + '0';
306 if (buf[i] > '9')
307 buf[i] += ('a'-'0'-10);
308 val >>= 4;
309 }
310 buf[nibbles] = '\0';
311 call_prom("write", 3, 1, _prom->stdout, buf, nibbles);
312}
313
314
315static void __init prom_printf(const char *format, ...)
316{
317 const char *p, *q, *s;
318 va_list args;
319 unsigned long v;
320 struct prom_t *_prom = &RELOC(prom);
321
322 va_start(args, format);
323#ifdef CONFIG_PPC64
324 format = PTRRELOC(format);
325#endif
326 for (p = format; *p != 0; p = q) {
327 for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q)
328 ;
329 if (q > p)
330 call_prom("write", 3, 1, _prom->stdout, p, q - p);
331 if (*q == 0)
332 break;
333 if (*q == '\n') {
334 ++q;
335 call_prom("write", 3, 1, _prom->stdout,
336 ADDR("\r\n"), 2);
337 continue;
338 }
339 ++q;
340 if (*q == 0)
341 break;
342 switch (*q) {
343 case 's':
344 ++q;
345 s = va_arg(args, const char *);
346 prom_print(s);
347 break;
348 case 'x':
349 ++q;
350 v = va_arg(args, unsigned long);
351 prom_print_hex(v);
352 break;
353 }
354 }
355}
356
357
358static unsigned int __init prom_claim(unsigned long virt, unsigned long size,
359 unsigned long align)
360{
361 struct prom_t *_prom = &RELOC(prom);
362
363 if (align == 0 && (OF_WORKAROUNDS & OF_WA_CLAIM)) {
364
365
366
367
368 int ret;
369 prom_arg_t result;
370
371 ret = call_prom_ret("call-method", 5, 2, &result,
372 ADDR("claim"), _prom->memory,
373 align, size, virt);
374 if (ret != 0 || result == -1)
375 return -1;
376 ret = call_prom_ret("call-method", 5, 2, &result,
377 ADDR("claim"), _prom->mmumap,
378 align, size, virt);
379 if (ret != 0) {
380 call_prom("call-method", 4, 1, ADDR("release"),
381 _prom->memory, size, virt);
382 return -1;
383 }
384
385 call_prom("call-method", 6, 1,
386 ADDR("map"), _prom->mmumap, 0x12, size, virt, virt);
387 return virt;
388 }
389 return call_prom("claim", 3, 1, (prom_arg_t)virt, (prom_arg_t)size,
390 (prom_arg_t)align);
391}
392
393static void __init __attribute__((noreturn)) prom_panic(const char *reason)
394{
395#ifdef CONFIG_PPC64
396 reason = PTRRELOC(reason);
397#endif
398 prom_print(reason);
399
400
401 if (RELOC(of_platform) == PLATFORM_POWERMAC)
402 asm("trap\n");
403
404
405 call_prom("exit", 0, 0);
406
407 for (;;)
408 ;
409}
410
411
412static int __init prom_next_node(phandle *nodep)
413{
414 phandle node;
415
416 if ((node = *nodep) != 0
417 && (*nodep = call_prom("child", 1, 1, node)) != 0)
418 return 1;
419 if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
420 return 1;
421 for (;;) {
422 if ((node = call_prom("parent", 1, 1, node)) == 0)
423 return 0;
424 if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
425 return 1;
426 }
427}
428
429static int inline prom_getprop(phandle node, const char *pname,
430 void *value, size_t valuelen)
431{
432 return call_prom("getprop", 4, 1, node, ADDR(pname),
433 (u32)(unsigned long) value, (u32) valuelen);
434}
435
436static int inline prom_getproplen(phandle node, const char *pname)
437{
438 return call_prom("getproplen", 2, 1, node, ADDR(pname));
439}
440
441static void add_string(char **str, const char *q)
442{
443 char *p = *str;
444
445 while (*q)
446 *p++ = *q++;
447 *p++ = ' ';
448 *str = p;
449}
450
451static char *tohex(unsigned int x)
452{
453 static char digits[] = "0123456789abcdef";
454 static char result[9];
455 int i;
456
457 result[8] = 0;
458 i = 8;
459 do {
460 --i;
461 result[i] = digits[x & 0xf];
462 x >>= 4;
463 } while (x != 0 && i > 0);
464 return &result[i];
465}
466
467static int __init prom_setprop(phandle node, const char *nodename,
468 const char *pname, void *value, size_t valuelen)
469{
470 char cmd[256], *p;
471
472 if (!(OF_WORKAROUNDS & OF_WA_LONGTRAIL))
473 return call_prom("setprop", 4, 1, node, ADDR(pname),
474 (u32)(unsigned long) value, (u32) valuelen);
475
476
477 p = cmd;
478 add_string(&p, "dev");
479 add_string(&p, nodename);
480 add_string(&p, tohex((u32)(unsigned long) value));
481 add_string(&p, tohex(valuelen));
482 add_string(&p, tohex(ADDR(pname)));
483 add_string(&p, tohex(strlen(RELOC(pname))));
484 add_string(&p, "property");
485 *p = 0;
486 return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd);
487}
488
489
490#define isxdigit(c) (('0' <= (c) && (c) <= '9') \
491 || ('a' <= (c) && (c) <= 'f') \
492 || ('A' <= (c) && (c) <= 'F'))
493
494#define isdigit(c) ('0' <= (c) && (c) <= '9')
495#define islower(c) ('a' <= (c) && (c) <= 'z')
496#define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c))
497
498unsigned long prom_strtoul(const char *cp, const char **endp)
499{
500 unsigned long result = 0, base = 10, value;
501
502 if (*cp == '0') {
503 base = 8;
504 cp++;
505 if (toupper(*cp) == 'X') {
506 cp++;
507 base = 16;
508 }
509 }
510
511 while (isxdigit(*cp) &&
512 (value = isdigit(*cp) ? *cp - '0' : toupper(*cp) - 'A' + 10) < base) {
513 result = result * base + value;
514 cp++;
515 }
516
517 if (endp)
518 *endp = cp;
519
520 return result;
521}
522
523unsigned long prom_memparse(const char *ptr, const char **retptr)
524{
525 unsigned long ret = prom_strtoul(ptr, retptr);
526 int shift = 0;
527
528
529
530
531
532
533 if ('G' == **retptr || 'g' == **retptr)
534 shift = 30;
535
536 if ('M' == **retptr || 'm' == **retptr)
537 shift = 20;
538
539 if ('K' == **retptr || 'k' == **retptr)
540 shift = 10;
541
542 if (shift) {
543 ret <<= shift;
544 (*retptr)++;
545 }
546
547 return ret;
548}
549
550
551
552
553
554static void __init early_cmdline_parse(void)
555{
556 struct prom_t *_prom = &RELOC(prom);
557 const char *opt;
558
559 char *p;
560 int l = 0;
561
562 RELOC(prom_cmd_line[0]) = 0;
563 p = RELOC(prom_cmd_line);
564 if ((long)_prom->chosen > 0)
565 l = prom_getprop(_prom->chosen, "bootargs", p, COMMAND_LINE_SIZE-1);
566#ifdef CONFIG_CMDLINE
567 if (l <= 0 || p[0] == '\0')
568 strlcpy(RELOC(prom_cmd_line),
569 RELOC(CONFIG_CMDLINE), sizeof(prom_cmd_line));
570#endif
571 prom_printf("command line: %s\n", RELOC(prom_cmd_line));
572
573#ifdef CONFIG_PPC64
574 opt = strstr(RELOC(prom_cmd_line), RELOC("iommu="));
575 if (opt) {
576 prom_printf("iommu opt is: %s\n", opt);
577 opt += 6;
578 while (*opt && *opt == ' ')
579 opt++;
580 if (!strncmp(opt, RELOC("off"), 3))
581 RELOC(prom_iommu_off) = 1;
582 else if (!strncmp(opt, RELOC("force"), 5))
583 RELOC(prom_iommu_force_on) = 1;
584 }
585#endif
586 opt = strstr(RELOC(prom_cmd_line), RELOC("mem="));
587 if (opt) {
588 opt += 4;
589 RELOC(prom_memory_limit) = prom_memparse(opt, (const char **)&opt);
590#ifdef CONFIG_PPC64
591
592 RELOC(prom_memory_limit) = ALIGN(RELOC(prom_memory_limit), 0x1000000);
593#endif
594 }
595}
596
597#ifdef CONFIG_PPC_PSERIES
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614#define W(x) ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
615 ((x) >> 8) & 0xff, (x) & 0xff
616
617
618#define OV_IGNORE 0x80
619#define OV_CESSATION_POLICY 0x40
620
621
622#define OV1_PPC_2_00 0x80
623#define OV1_PPC_2_01 0x40
624#define OV1_PPC_2_02 0x20
625#define OV1_PPC_2_03 0x10
626#define OV1_PPC_2_04 0x08
627#define OV1_PPC_2_05 0x04
628#define OV1_PPC_2_06 0x02
629
630
631#define OV2_REAL_MODE 0x20
632
633
634#define OV3_FP 0x80
635#define OV3_VMX 0x40
636#define OV3_DFP 0x20
637
638
639#define OV5_LPAR 0x80
640#define OV5_SPLPAR 0x40
641
642#define OV5_DRCONF_MEMORY 0x20
643#define OV5_LARGE_PAGES 0x10
644#define OV5_DONATE_DEDICATE_CPU 0x02
645
646#ifdef CONFIG_PCI_MSI
647#define OV5_MSI 0x01
648#else
649#define OV5_MSI 0x00
650#endif
651#ifdef CONFIG_PPC_SMLPAR
652#define OV5_CMO 0x80
653#else
654#define OV5_CMO 0x00
655#endif
656
657
658
659
660
661static unsigned char ibm_architecture_vec[] = {
662 W(0xfffe0000), W(0x003a0000),
663 W(0xffff0000), W(0x003e0000),
664 W(0xffff0000), W(0x003f0000),
665 W(0xffffffff), W(0x0f000003),
666 W(0xffffffff), W(0x0f000002),
667 W(0xfffffffe), W(0x0f000001),
668 5 - 1,
669
670
671 3 - 2,
672 0,
673 OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 |
674 OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06,
675
676
677 34 - 2,
678 OV2_REAL_MODE,
679 0, 0,
680 W(0xffffffff),
681 W(0xffffffff),
682 W(0xffffffff),
683 W(0xffffffff),
684 W(0xffffffff),
685 W(64),
686 W(0xffffffff),
687 0,
688 48,
689
690
691 3 - 2,
692 0,
693 OV3_FP | OV3_VMX | OV3_DFP,
694
695
696 2 - 2,
697 0,
698
699
700 5 - 2,
701 0,
702 OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY |
703 OV5_DONATE_DEDICATE_CPU | OV5_MSI,
704 0,
705 OV5_CMO,
706};
707
708
709static struct fake_elf {
710 Elf32_Ehdr elfhdr;
711 Elf32_Phdr phdr[2];
712 struct chrpnote {
713 u32 namesz;
714 u32 descsz;
715 u32 type;
716 char name[8];
717 struct chrpdesc {
718 u32 real_mode;
719 u32 real_base;
720 u32 real_size;
721 u32 virt_base;
722 u32 virt_size;
723 u32 load_base;
724 } chrpdesc;
725 } chrpnote;
726 struct rpanote {
727 u32 namesz;
728 u32 descsz;
729 u32 type;
730 char name[24];
731 struct rpadesc {
732 u32 lpar_affinity;
733 u32 min_rmo_size;
734 u32 min_rmo_percent;
735 u32 max_pft_size;
736 u32 splpar;
737 u32 min_load;
738 u32 new_mem_def;
739 u32 ignore_me;
740 } rpadesc;
741 } rpanote;
742} fake_elf = {
743 .elfhdr = {
744 .e_ident = { 0x7f, 'E', 'L', 'F',
745 ELFCLASS32, ELFDATA2MSB, EV_CURRENT },
746 .e_type = ET_EXEC,
747 .e_machine = EM_PPC,
748 .e_version = EV_CURRENT,
749 .e_phoff = offsetof(struct fake_elf, phdr),
750 .e_phentsize = sizeof(Elf32_Phdr),
751 .e_phnum = 2
752 },
753 .phdr = {
754 [0] = {
755 .p_type = PT_NOTE,
756 .p_offset = offsetof(struct fake_elf, chrpnote),
757 .p_filesz = sizeof(struct chrpnote)
758 }, [1] = {
759 .p_type = PT_NOTE,
760 .p_offset = offsetof(struct fake_elf, rpanote),
761 .p_filesz = sizeof(struct rpanote)
762 }
763 },
764 .chrpnote = {
765 .namesz = sizeof("PowerPC"),
766 .descsz = sizeof(struct chrpdesc),
767 .type = 0x1275,
768 .name = "PowerPC",
769 .chrpdesc = {
770 .real_mode = ~0U,
771 .real_base = ~0U,
772 .real_size = ~0U,
773 .virt_base = ~0U,
774 .virt_size = ~0U,
775 .load_base = ~0U
776 },
777 },
778 .rpanote = {
779 .namesz = sizeof("IBM,RPA-Client-Config"),
780 .descsz = sizeof(struct rpadesc),
781 .type = 0x12759999,
782 .name = "IBM,RPA-Client-Config",
783 .rpadesc = {
784 .lpar_affinity = 0,
785 .min_rmo_size = 64,
786 .min_rmo_percent = 0,
787 .max_pft_size = 48,
788 .splpar = 1,
789 .min_load = ~0U,
790 .new_mem_def = 0
791 }
792 }
793};
794
795static void __init prom_send_capabilities(void)
796{
797 ihandle elfloader, root;
798 prom_arg_t ret;
799
800 root = call_prom("open", 1, 1, ADDR("/"));
801 if (root != 0) {
802
803 prom_printf("Calling ibm,client-architecture-support...");
804 if (call_prom_ret("call-method", 3, 2, &ret,
805 ADDR("ibm,client-architecture-support"),
806 root,
807 ADDR(ibm_architecture_vec)) == 0) {
808
809 if (ret)
810 prom_printf("\nWARNING: ibm,client-architecture"
811 "-support call FAILED!\n");
812 call_prom("close", 1, 0, root);
813 prom_printf(" done\n");
814 return;
815 }
816 call_prom("close", 1, 0, root);
817 prom_printf(" not implemented\n");
818 }
819
820
821 elfloader = call_prom("open", 1, 1, ADDR("/packages/elf-loader"));
822 if (elfloader == 0) {
823 prom_printf("couldn't open /packages/elf-loader\n");
824 return;
825 }
826 call_prom("call-method", 3, 1, ADDR("process-elf-header"),
827 elfloader, ADDR(&fake_elf));
828 call_prom("close", 1, 0, elfloader);
829}
830#endif
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865static unsigned long __init alloc_up(unsigned long size, unsigned long align)
866{
867 unsigned long base = RELOC(alloc_bottom);
868 unsigned long addr = 0;
869
870 if (align)
871 base = _ALIGN_UP(base, align);
872 prom_debug("alloc_up(%x, %x)\n", size, align);
873 if (RELOC(ram_top) == 0)
874 prom_panic("alloc_up() called with mem not initialized\n");
875
876 if (align)
877 base = _ALIGN_UP(RELOC(alloc_bottom), align);
878 else
879 base = RELOC(alloc_bottom);
880
881 for(; (base + size) <= RELOC(alloc_top);
882 base = _ALIGN_UP(base + 0x100000, align)) {
883 prom_debug(" trying: 0x%x\n\r", base);
884 addr = (unsigned long)prom_claim(base, size, 0);
885 if (addr != PROM_ERROR && addr != 0)
886 break;
887 addr = 0;
888 if (align == 0)
889 break;
890 }
891 if (addr == 0)
892 return 0;
893 RELOC(alloc_bottom) = addr;
894
895 prom_debug(" -> %x\n", addr);
896 prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
897 prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
898 prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
899 prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
900 prom_debug(" ram_top : %x\n", RELOC(ram_top));
901
902 return addr;
903}
904
905
906
907
908
909
910static unsigned long __init alloc_down(unsigned long size, unsigned long align,
911 int highmem)
912{
913 unsigned long base, addr = 0;
914
915 prom_debug("alloc_down(%x, %x, %s)\n", size, align,
916 highmem ? RELOC("(high)") : RELOC("(low)"));
917 if (RELOC(ram_top) == 0)
918 prom_panic("alloc_down() called with mem not initialized\n");
919
920 if (highmem) {
921
922 addr = _ALIGN_DOWN(RELOC(alloc_top_high) - size, align);
923 if (addr <= RELOC(alloc_bottom))
924 return 0;
925
926
927
928
929 if (addr < RELOC(rmo_top)) {
930
931 if (RELOC(alloc_top) == RELOC(rmo_top))
932 RELOC(alloc_top) = RELOC(rmo_top) = addr;
933 else
934 return 0;
935 }
936 RELOC(alloc_top_high) = addr;
937 goto bail;
938 }
939
940 base = _ALIGN_DOWN(RELOC(alloc_top) - size, align);
941 for (; base > RELOC(alloc_bottom);
942 base = _ALIGN_DOWN(base - 0x100000, align)) {
943 prom_debug(" trying: 0x%x\n\r", base);
944 addr = (unsigned long)prom_claim(base, size, 0);
945 if (addr != PROM_ERROR && addr != 0)
946 break;
947 addr = 0;
948 }
949 if (addr == 0)
950 return 0;
951 RELOC(alloc_top) = addr;
952
953 bail:
954 prom_debug(" -> %x\n", addr);
955 prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
956 prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
957 prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
958 prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
959 prom_debug(" ram_top : %x\n", RELOC(ram_top));
960
961 return addr;
962}
963
964
965
966
967static unsigned long __init prom_next_cell(int s, cell_t **cellp)
968{
969 cell_t *p = *cellp;
970 unsigned long r = 0;
971
972
973 while (s > sizeof(unsigned long) / 4) {
974 p++;
975 s--;
976 }
977 r = *p++;
978#ifdef CONFIG_PPC64
979 if (s > 1) {
980 r <<= 32;
981 r |= *(p++);
982 }
983#endif
984 *cellp = p;
985 return r;
986}
987
988
989
990
991
992
993
994
995
996static void __init reserve_mem(u64 base, u64 size)
997{
998 u64 top = base + size;
999 unsigned long cnt = RELOC(mem_reserve_cnt);
1000
1001 if (size == 0)
1002 return;
1003
1004
1005
1006
1007
1008 base = _ALIGN_DOWN(base, PAGE_SIZE);
1009 top = _ALIGN_UP(top, PAGE_SIZE);
1010 size = top - base;
1011
1012 if (cnt >= (MEM_RESERVE_MAP_SIZE - 1))
1013 prom_panic("Memory reserve map exhausted !\n");
1014 RELOC(mem_reserve_map)[cnt].base = base;
1015 RELOC(mem_reserve_map)[cnt].size = size;
1016 RELOC(mem_reserve_cnt) = cnt + 1;
1017}
1018
1019
1020
1021
1022
1023static void __init prom_init_mem(void)
1024{
1025 phandle node;
1026 char *path, type[64];
1027 unsigned int plen;
1028 cell_t *p, *endp;
1029 struct prom_t *_prom = &RELOC(prom);
1030 u32 rac, rsc;
1031
1032
1033
1034
1035
1036
1037 rac = 2;
1038 prom_getprop(_prom->root, "#address-cells", &rac, sizeof(rac));
1039 rsc = 1;
1040 prom_getprop(_prom->root, "#size-cells", &rsc, sizeof(rsc));
1041 prom_debug("root_addr_cells: %x\n", (unsigned long) rac);
1042 prom_debug("root_size_cells: %x\n", (unsigned long) rsc);
1043
1044 prom_debug("scanning memory:\n");
1045 path = RELOC(prom_scratch);
1046
1047 for (node = 0; prom_next_node(&node); ) {
1048 type[0] = 0;
1049 prom_getprop(node, "device_type", type, sizeof(type));
1050
1051 if (type[0] == 0) {
1052
1053
1054
1055
1056 prom_getprop(node, "name", type, sizeof(type));
1057 }
1058 if (strcmp(type, RELOC("memory")))
1059 continue;
1060
1061 plen = prom_getprop(node, "reg", RELOC(regbuf), sizeof(regbuf));
1062 if (plen > sizeof(regbuf)) {
1063 prom_printf("memory node too large for buffer !\n");
1064 plen = sizeof(regbuf);
1065 }
1066 p = RELOC(regbuf);
1067 endp = p + (plen / sizeof(cell_t));
1068
1069#ifdef DEBUG_PROM
1070 memset(path, 0, PROM_SCRATCH_SIZE);
1071 call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
1072 prom_debug(" node %s :\n", path);
1073#endif
1074
1075 while ((endp - p) >= (rac + rsc)) {
1076 unsigned long base, size;
1077
1078 base = prom_next_cell(rac, &p);
1079 size = prom_next_cell(rsc, &p);
1080
1081 if (size == 0)
1082 continue;
1083 prom_debug(" %x %x\n", base, size);
1084 if (base == 0 && (RELOC(of_platform) & PLATFORM_LPAR))
1085 RELOC(rmo_top) = size;
1086 if ((base + size) > RELOC(ram_top))
1087 RELOC(ram_top) = base + size;
1088 }
1089 }
1090
1091 RELOC(alloc_bottom) = PAGE_ALIGN((unsigned long)&RELOC(_end) + 0x4000);
1092
1093
1094
1095
1096 if (RELOC(prom_initrd_start)) {
1097 if (RELOC(prom_initrd_end) > RELOC(alloc_bottom))
1098 RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(prom_initrd_end));
1099 }
1100
1101
1102
1103
1104
1105
1106
1107 RELOC(alloc_top_high) = RELOC(ram_top);
1108
1109 if (RELOC(prom_memory_limit)) {
1110 if (RELOC(prom_memory_limit) <= RELOC(alloc_bottom)) {
1111 prom_printf("Ignoring mem=%x <= alloc_bottom.\n",
1112 RELOC(prom_memory_limit));
1113 RELOC(prom_memory_limit) = 0;
1114 } else if (RELOC(prom_memory_limit) >= RELOC(ram_top)) {
1115 prom_printf("Ignoring mem=%x >= ram_top.\n",
1116 RELOC(prom_memory_limit));
1117 RELOC(prom_memory_limit) = 0;
1118 } else {
1119 RELOC(ram_top) = RELOC(prom_memory_limit);
1120 RELOC(rmo_top) = min(RELOC(rmo_top), RELOC(prom_memory_limit));
1121 }
1122 }
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132 if (!RELOC(rmo_top))
1133 RELOC(rmo_top) = RELOC(ram_top);
1134 RELOC(rmo_top) = min(0x30000000ul, RELOC(rmo_top));
1135 RELOC(alloc_top) = RELOC(rmo_top);
1136 RELOC(alloc_top_high) = RELOC(ram_top);
1137
1138 prom_printf("memory layout at init:\n");
1139 prom_printf(" memory_limit : %x (16 MB aligned)\n", RELOC(prom_memory_limit));
1140 prom_printf(" alloc_bottom : %x\n", RELOC(alloc_bottom));
1141 prom_printf(" alloc_top : %x\n", RELOC(alloc_top));
1142 prom_printf(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
1143 prom_printf(" rmo_top : %x\n", RELOC(rmo_top));
1144 prom_printf(" ram_top : %x\n", RELOC(ram_top));
1145}
1146
1147
1148
1149
1150
1151static void __init prom_instantiate_rtas(void)
1152{
1153 phandle rtas_node;
1154 ihandle rtas_inst;
1155 u32 base, entry = 0;
1156 u32 size = 0;
1157
1158 prom_debug("prom_instantiate_rtas: start...\n");
1159
1160 rtas_node = call_prom("finddevice", 1, 1, ADDR("/rtas"));
1161 prom_debug("rtas_node: %x\n", rtas_node);
1162 if (!PHANDLE_VALID(rtas_node))
1163 return;
1164
1165 prom_getprop(rtas_node, "rtas-size", &size, sizeof(size));
1166 if (size == 0)
1167 return;
1168
1169 base = alloc_down(size, PAGE_SIZE, 0);
1170 if (base == 0) {
1171 prom_printf("RTAS allocation failed !\n");
1172 return;
1173 }
1174
1175 rtas_inst = call_prom("open", 1, 1, ADDR("/rtas"));
1176 if (!IHANDLE_VALID(rtas_inst)) {
1177 prom_printf("opening rtas package failed (%x)\n", rtas_inst);
1178 return;
1179 }
1180
1181 prom_printf("instantiating rtas at 0x%x...", base);
1182
1183 if (call_prom_ret("call-method", 3, 2, &entry,
1184 ADDR("instantiate-rtas"),
1185 rtas_inst, base) != 0
1186 || entry == 0) {
1187 prom_printf(" failed\n");
1188 return;
1189 }
1190 prom_printf(" done\n");
1191
1192 reserve_mem(base, size);
1193
1194 prom_setprop(rtas_node, "/rtas", "linux,rtas-base",
1195 &base, sizeof(base));
1196 prom_setprop(rtas_node, "/rtas", "linux,rtas-entry",
1197 &entry, sizeof(entry));
1198
1199 prom_debug("rtas base = 0x%x\n", base);
1200 prom_debug("rtas entry = 0x%x\n", entry);
1201 prom_debug("rtas size = 0x%x\n", (long)size);
1202
1203 prom_debug("prom_instantiate_rtas: end...\n");
1204}
1205
1206#ifdef CONFIG_PPC64
1207
1208
1209
1210static void __init prom_initialize_tce_table(void)
1211{
1212 phandle node;
1213 ihandle phb_node;
1214 char compatible[64], type[64], model[64];
1215 char *path = RELOC(prom_scratch);
1216 u64 base, align;
1217 u32 minalign, minsize;
1218 u64 tce_entry, *tce_entryp;
1219 u64 local_alloc_top, local_alloc_bottom;
1220 u64 i;
1221
1222 if (RELOC(prom_iommu_off))
1223 return;
1224
1225 prom_debug("starting prom_initialize_tce_table\n");
1226
1227
1228 local_alloc_top = RELOC(alloc_top_high);
1229 local_alloc_bottom = local_alloc_top;
1230
1231
1232 for (node = 0; prom_next_node(&node); ) {
1233 compatible[0] = 0;
1234 type[0] = 0;
1235 model[0] = 0;
1236 prom_getprop(node, "compatible",
1237 compatible, sizeof(compatible));
1238 prom_getprop(node, "device_type", type, sizeof(type));
1239 prom_getprop(node, "model", model, sizeof(model));
1240
1241 if ((type[0] == 0) || (strstr(type, RELOC("pci")) == NULL))
1242 continue;
1243
1244
1245 if (compatible[0] != 0) {
1246 if ((strstr(compatible, RELOC("python")) == NULL) &&
1247 (strstr(compatible, RELOC("Speedwagon")) == NULL) &&
1248 (strstr(compatible, RELOC("Winnipeg")) == NULL))
1249 continue;
1250 } else if (model[0] != 0) {
1251 if ((strstr(model, RELOC("ython")) == NULL) &&
1252 (strstr(model, RELOC("peedwagon")) == NULL) &&
1253 (strstr(model, RELOC("innipeg")) == NULL))
1254 continue;
1255 }
1256
1257 if (prom_getprop(node, "tce-table-minalign", &minalign,
1258 sizeof(minalign)) == PROM_ERROR)
1259 minalign = 0;
1260 if (prom_getprop(node, "tce-table-minsize", &minsize,
1261 sizeof(minsize)) == PROM_ERROR)
1262 minsize = 4UL << 20;
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275 if (__is_processor(PV_POWER4) || __is_processor(PV_POWER4p))
1276 minsize = 8UL << 20;
1277 else
1278 minsize = 4UL << 20;
1279
1280
1281 align = max(minalign, minsize);
1282 base = alloc_down(minsize, align, 1);
1283 if (base == 0)
1284 prom_panic("ERROR, cannot find space for TCE table.\n");
1285 if (base < local_alloc_bottom)
1286 local_alloc_bottom = base;
1287
1288
1289 memset(path, 0, PROM_SCRATCH_SIZE);
1290
1291 if (call_prom("package-to-path", 3, 1, node,
1292 path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) {
1293 prom_printf("package-to-path failed\n");
1294 }
1295
1296
1297 prom_setprop(node, path, "linux,tce-base", &base, sizeof(base));
1298 prom_setprop(node, path, "linux,tce-size", &minsize, sizeof(minsize));
1299
1300 prom_debug("TCE table: %s\n", path);
1301 prom_debug("\tnode = 0x%x\n", node);
1302 prom_debug("\tbase = 0x%x\n", base);
1303 prom_debug("\tsize = 0x%x\n", minsize);
1304
1305
1306
1307
1308 tce_entryp = (u64 *)base;
1309 for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {
1310 tce_entry = (i << PAGE_SHIFT);
1311 tce_entry |= 0x3;
1312 *tce_entryp = tce_entry;
1313 }
1314
1315 prom_printf("opening PHB %s", path);
1316 phb_node = call_prom("open", 1, 1, path);
1317 if (phb_node == 0)
1318 prom_printf("... failed\n");
1319 else
1320 prom_printf("... done\n");
1321
1322 call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"),
1323 phb_node, -1, minsize,
1324 (u32) base, (u32) (base >> 32));
1325 call_prom("close", 1, 0, phb_node);
1326 }
1327
1328 reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom);
1329
1330
1331
1332 RELOC(prom_tce_alloc_start) = local_alloc_bottom;
1333 RELOC(prom_tce_alloc_end) = local_alloc_top;
1334
1335
1336 prom_debug("ending prom_initialize_tce_table\n");
1337}
1338#endif
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362#define LOW_ADDR(x) (((unsigned long) &(x)) & 0xff)
1363
1364static void __init prom_hold_cpus(void)
1365{
1366 unsigned long i;
1367 unsigned int reg;
1368 phandle node;
1369 char type[64];
1370 struct prom_t *_prom = &RELOC(prom);
1371 unsigned long *spinloop
1372 = (void *) LOW_ADDR(__secondary_hold_spinloop);
1373 unsigned long *acknowledge
1374 = (void *) LOW_ADDR(__secondary_hold_acknowledge);
1375 unsigned long secondary_hold = LOW_ADDR(__secondary_hold);
1376
1377 prom_debug("prom_hold_cpus: start...\n");
1378 prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop);
1379 prom_debug(" 1) *spinloop = 0x%x\n", *spinloop);
1380 prom_debug(" 1) acknowledge = 0x%x\n",
1381 (unsigned long)acknowledge);
1382 prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge);
1383 prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold);
1384
1385
1386
1387
1388
1389
1390 *spinloop = 0;
1391
1392
1393 for (node = 0; prom_next_node(&node); ) {
1394 type[0] = 0;
1395 prom_getprop(node, "device_type", type, sizeof(type));
1396 if (strcmp(type, RELOC("cpu")) != 0)
1397 continue;
1398
1399
1400 if (prom_getprop(node, "status", type, sizeof(type)) > 0)
1401 if (strcmp(type, RELOC("okay")) != 0)
1402 continue;
1403
1404 reg = -1;
1405 prom_getprop(node, "reg", ®, sizeof(reg));
1406
1407 prom_debug("cpu hw idx = 0x%x\n", reg);
1408
1409
1410
1411
1412
1413 *acknowledge = (unsigned long)-1;
1414
1415 if (reg != _prom->cpu) {
1416
1417 prom_printf("starting cpu hw idx %x... ", reg);
1418 call_prom("start-cpu", 3, 0, node,
1419 secondary_hold, reg);
1420
1421 for (i = 0; (i < 100000000) &&
1422 (*acknowledge == ((unsigned long)-1)); i++ )
1423 mb();
1424
1425 if (*acknowledge == reg)
1426 prom_printf("done\n");
1427 else
1428 prom_printf("failed: %x\n", *acknowledge);
1429 }
1430#ifdef CONFIG_SMP
1431 else
1432 prom_printf("boot cpu hw idx %x\n", reg);
1433#endif
1434 }
1435
1436 prom_debug("prom_hold_cpus: end...\n");
1437}
1438
1439
1440static void __init prom_init_client_services(unsigned long pp)
1441{
1442 struct prom_t *_prom = &RELOC(prom);
1443
1444
1445 RELOC(prom_entry) = pp;
1446
1447
1448 _prom->chosen = call_prom("finddevice", 1, 1, ADDR("/chosen"));
1449 if (!PHANDLE_VALID(_prom->chosen))
1450 prom_panic("cannot find chosen");
1451
1452
1453 _prom->root = call_prom("finddevice", 1, 1, ADDR("/"));
1454 if (!PHANDLE_VALID(_prom->root))
1455 prom_panic("cannot find device tree root");
1456
1457 _prom->mmumap = 0;
1458}
1459
1460#ifdef CONFIG_PPC32
1461
1462
1463
1464
1465
1466static void __init prom_find_mmu(void)
1467{
1468 struct prom_t *_prom = &RELOC(prom);
1469 phandle oprom;
1470 char version[64];
1471
1472 oprom = call_prom("finddevice", 1, 1, ADDR("/openprom"));
1473 if (!PHANDLE_VALID(oprom))
1474 return;
1475 if (prom_getprop(oprom, "model", version, sizeof(version)) <= 0)
1476 return;
1477 version[sizeof(version) - 1] = 0;
1478
1479 if (strcmp(version, "Open Firmware, 1.0.5") == 0)
1480 of_workarounds = OF_WA_CLAIM;
1481 else if (strncmp(version, "FirmWorks,3.", 12) == 0) {
1482 of_workarounds = OF_WA_CLAIM | OF_WA_LONGTRAIL;
1483 call_prom("interpret", 1, 1, "dev /memory 0 to allow-reclaim");
1484 } else
1485 return;
1486 _prom->memory = call_prom("open", 1, 1, ADDR("/memory"));
1487 prom_getprop(_prom->chosen, "mmu", &_prom->mmumap,
1488 sizeof(_prom->mmumap));
1489 if (!IHANDLE_VALID(_prom->memory) || !IHANDLE_VALID(_prom->mmumap))
1490 of_workarounds &= ~OF_WA_CLAIM;
1491}
1492#else
1493#define prom_find_mmu()
1494#endif
1495
1496static void __init prom_init_stdout(void)
1497{
1498 struct prom_t *_prom = &RELOC(prom);
1499 char *path = RELOC(of_stdout_device);
1500 char type[16];
1501 u32 val;
1502
1503 if (prom_getprop(_prom->chosen, "stdout", &val, sizeof(val)) <= 0)
1504 prom_panic("cannot find stdout");
1505
1506 _prom->stdout = val;
1507
1508
1509 memset(path, 0, 256);
1510 call_prom("instance-to-path", 3, 1, _prom->stdout, path, 255);
1511 val = call_prom("instance-to-package", 1, 1, _prom->stdout);
1512 prom_setprop(_prom->chosen, "/chosen", "linux,stdout-package",
1513 &val, sizeof(val));
1514 prom_printf("OF stdout device is: %s\n", RELOC(of_stdout_device));
1515 prom_setprop(_prom->chosen, "/chosen", "linux,stdout-path",
1516 path, strlen(path) + 1);
1517
1518
1519 memset(type, 0, sizeof(type));
1520 prom_getprop(val, "device_type", type, sizeof(type));
1521 if (strcmp(type, RELOC("display")) == 0)
1522 prom_setprop(val, path, "linux,boot-display", NULL, 0);
1523}
1524
1525static void __init prom_close_stdin(void)
1526{
1527 struct prom_t *_prom = &RELOC(prom);
1528 ihandle val;
1529
1530 if (prom_getprop(_prom->chosen, "stdin", &val, sizeof(val)) > 0)
1531 call_prom("close", 1, 0, val);
1532}
1533
1534static int __init prom_find_machine_type(void)
1535{
1536 struct prom_t *_prom = &RELOC(prom);
1537 char compat[256];
1538 int len, i = 0;
1539#ifdef CONFIG_PPC64
1540 phandle rtas;
1541 int x;
1542#endif
1543
1544
1545 len = prom_getprop(_prom->root, "compatible",
1546 compat, sizeof(compat)-1);
1547 if (len > 0) {
1548 compat[len] = 0;
1549 while (i < len) {
1550 char *p = &compat[i];
1551 int sl = strlen(p);
1552 if (sl == 0)
1553 break;
1554 if (strstr(p, RELOC("Power Macintosh")) ||
1555 strstr(p, RELOC("MacRISC")))
1556 return PLATFORM_POWERMAC;
1557#ifdef CONFIG_PPC64
1558
1559
1560
1561
1562 if (strstr(p, RELOC("IBM,CBEA")) ||
1563 strstr(p, RELOC("IBM,CPBW-1.0")))
1564 return PLATFORM_GENERIC;
1565#endif
1566 i += sl + 1;
1567 }
1568 }
1569#ifdef CONFIG_PPC64
1570
1571
1572
1573
1574
1575
1576 len = prom_getprop(_prom->root, "device_type",
1577 compat, sizeof(compat)-1);
1578 if (len <= 0)
1579 return PLATFORM_GENERIC;
1580 if (strcmp(compat, RELOC("chrp")))
1581 return PLATFORM_GENERIC;
1582
1583
1584 rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
1585 if (!PHANDLE_VALID(rtas))
1586 return PLATFORM_GENERIC;
1587 x = prom_getproplen(rtas, "ibm,hypertas-functions");
1588 if (x != PROM_ERROR) {
1589 prom_debug("Hypertas detected, assuming LPAR !\n");
1590 return PLATFORM_PSERIES_LPAR;
1591 }
1592 return PLATFORM_PSERIES;
1593#else
1594 return PLATFORM_GENERIC;
1595#endif
1596}
1597
1598static int __init prom_set_color(ihandle ih, int i, int r, int g, int b)
1599{
1600 return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r);
1601}
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611static void __init prom_check_displays(void)
1612{
1613 char type[16], *path;
1614 phandle node;
1615 ihandle ih;
1616 int i;
1617
1618 static unsigned char default_colors[] = {
1619 0x00, 0x00, 0x00,
1620 0x00, 0x00, 0xaa,
1621 0x00, 0xaa, 0x00,
1622 0x00, 0xaa, 0xaa,
1623 0xaa, 0x00, 0x00,
1624 0xaa, 0x00, 0xaa,
1625 0xaa, 0xaa, 0x00,
1626 0xaa, 0xaa, 0xaa,
1627 0x55, 0x55, 0x55,
1628 0x55, 0x55, 0xff,
1629 0x55, 0xff, 0x55,
1630 0x55, 0xff, 0xff,
1631 0xff, 0x55, 0x55,
1632 0xff, 0x55, 0xff,
1633 0xff, 0xff, 0x55,
1634 0xff, 0xff, 0xff
1635 };
1636 const unsigned char *clut;
1637
1638 prom_debug("Looking for displays\n");
1639 for (node = 0; prom_next_node(&node); ) {
1640 memset(type, 0, sizeof(type));
1641 prom_getprop(node, "device_type", type, sizeof(type));
1642 if (strcmp(type, RELOC("display")) != 0)
1643 continue;
1644
1645
1646 path = RELOC(prom_scratch);
1647 memset(path, 0, PROM_SCRATCH_SIZE);
1648
1649
1650
1651
1652
1653 if (call_prom("package-to-path", 3, 1, node, path,
1654 PROM_SCRATCH_SIZE-10) == PROM_ERROR)
1655 continue;
1656 prom_printf("found display : %s, opening... ", path);
1657
1658 ih = call_prom("open", 1, 1, path);
1659 if (ih == 0) {
1660 prom_printf("failed\n");
1661 continue;
1662 }
1663
1664
1665 prom_printf("done\n");
1666 prom_setprop(node, path, "linux,opened", NULL, 0);
1667
1668
1669
1670 clut = RELOC(default_colors);
1671 for (i = 0; i < 32; i++, clut += 3)
1672 if (prom_set_color(ih, i, clut[0], clut[1],
1673 clut[2]) != 0)
1674 break;
1675
1676#ifdef CONFIG_LOGO_LINUX_CLUT224
1677 clut = PTRRELOC(RELOC(logo_linux_clut224.clut));
1678 for (i = 0; i < RELOC(logo_linux_clut224.clutsize); i++, clut += 3)
1679 if (prom_set_color(ih, i + 32, clut[0], clut[1],
1680 clut[2]) != 0)
1681 break;
1682#endif
1683 }
1684}
1685
1686
1687
1688static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end,
1689 unsigned long needed, unsigned long align)
1690{
1691 void *ret;
1692
1693 *mem_start = _ALIGN(*mem_start, align);
1694 while ((*mem_start + needed) > *mem_end) {
1695 unsigned long room, chunk;
1696
1697 prom_debug("Chunk exhausted, claiming more at %x...\n",
1698 RELOC(alloc_bottom));
1699 room = RELOC(alloc_top) - RELOC(alloc_bottom);
1700 if (room > DEVTREE_CHUNK_SIZE)
1701 room = DEVTREE_CHUNK_SIZE;
1702 if (room < PAGE_SIZE)
1703 prom_panic("No memory for flatten_device_tree (no room)");
1704 chunk = alloc_up(room, 0);
1705 if (chunk == 0)
1706 prom_panic("No memory for flatten_device_tree (claim failed)");
1707 *mem_end = RELOC(alloc_top);
1708 }
1709
1710 ret = (void *)*mem_start;
1711 *mem_start += needed;
1712
1713 return ret;
1714}
1715
1716#define dt_push_token(token, mem_start, mem_end) \
1717 do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0)
1718
1719static unsigned long __init dt_find_string(char *str)
1720{
1721 char *s, *os;
1722
1723 s = os = (char *)RELOC(dt_string_start);
1724 s += 4;
1725 while (s < (char *)RELOC(dt_string_end)) {
1726 if (strcmp(s, str) == 0)
1727 return s - os;
1728 s += strlen(s) + 1;
1729 }
1730 return 0;
1731}
1732
1733
1734
1735
1736
1737#define MAX_PROPERTY_NAME 64
1738
1739static void __init scan_dt_build_strings(phandle node,
1740 unsigned long *mem_start,
1741 unsigned long *mem_end)
1742{
1743 char *prev_name, *namep, *sstart;
1744 unsigned long soff;
1745 phandle child;
1746
1747 sstart = (char *)RELOC(dt_string_start);
1748
1749
1750 prev_name = RELOC("");
1751 for (;;) {
1752
1753 namep = make_room(mem_start, mem_end, MAX_PROPERTY_NAME, 1);
1754 if (call_prom("nextprop", 3, 1, node, prev_name, namep) != 1) {
1755
1756 *mem_start = (unsigned long)namep;
1757 break;
1758 }
1759
1760
1761 if (strcmp(namep, RELOC("name")) == 0) {
1762 *mem_start = (unsigned long)namep;
1763 prev_name = RELOC("name");
1764 continue;
1765 }
1766
1767 soff = dt_find_string(namep);
1768 if (soff != 0) {
1769 *mem_start = (unsigned long)namep;
1770 namep = sstart + soff;
1771 } else {
1772
1773 *mem_start = (unsigned long)namep + strlen(namep) + 1;
1774 RELOC(dt_string_end) = *mem_start;
1775 }
1776 prev_name = namep;
1777 }
1778
1779
1780 child = call_prom("child", 1, 1, node);
1781 while (child != 0) {
1782 scan_dt_build_strings(child, mem_start, mem_end);
1783 child = call_prom("peer", 1, 1, child);
1784 }
1785}
1786
1787static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,
1788 unsigned long *mem_end)
1789{
1790 phandle child;
1791 char *namep, *prev_name, *sstart, *p, *ep, *lp, *path;
1792 unsigned long soff;
1793 unsigned char *valp;
1794 static char pname[MAX_PROPERTY_NAME];
1795 int l, room;
1796
1797 dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end);
1798
1799
1800 namep = (char *)*mem_start;
1801 room = *mem_end - *mem_start;
1802 if (room > 255)
1803 room = 255;
1804 l = call_prom("package-to-path", 3, 1, node, namep, room);
1805 if (l >= 0) {
1806
1807 if (l >= room) {
1808 if (l >= *mem_end - *mem_start)
1809 namep = make_room(mem_start, mem_end, l+1, 1);
1810 call_prom("package-to-path", 3, 1, node, namep, l);
1811 }
1812 namep[l] = '\0';
1813
1814
1815
1816
1817
1818 for (lp = p = namep, ep = namep + l; p < ep; p++) {
1819 if (*p == '/')
1820 lp = namep;
1821 else if (*p != 0)
1822 *lp++ = *p;
1823 }
1824 *lp = 0;
1825 *mem_start = _ALIGN((unsigned long)lp + 1, 4);
1826 }
1827
1828
1829 path = RELOC(prom_scratch);
1830 memset(path, 0, PROM_SCRATCH_SIZE);
1831 call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
1832
1833
1834 prev_name = RELOC("");
1835 sstart = (char *)RELOC(dt_string_start);
1836 for (;;) {
1837 if (call_prom("nextprop", 3, 1, node, prev_name,
1838 RELOC(pname)) != 1)
1839 break;
1840
1841
1842 if (strcmp(RELOC(pname), RELOC("name")) == 0) {
1843 prev_name = RELOC("name");
1844 continue;
1845 }
1846
1847
1848 soff = dt_find_string(RELOC(pname));
1849 if (soff == 0) {
1850 prom_printf("WARNING: Can't find string index for"
1851 " <%s>, node %s\n", RELOC(pname), path);
1852 break;
1853 }
1854 prev_name = sstart + soff;
1855
1856
1857 l = call_prom("getproplen", 2, 1, node, RELOC(pname));
1858
1859
1860 if (l == PROM_ERROR)
1861 continue;
1862 if (l > MAX_PROPERTY_LENGTH) {
1863 prom_printf("WARNING: ignoring large property ");
1864
1865 prom_printf("[%s] ", path);
1866 prom_printf("%s length 0x%x\n", RELOC(pname), l);
1867 continue;
1868 }
1869
1870
1871 dt_push_token(OF_DT_PROP, mem_start, mem_end);
1872 dt_push_token(l, mem_start, mem_end);
1873 dt_push_token(soff, mem_start, mem_end);
1874
1875
1876 valp = make_room(mem_start, mem_end, l, 4);
1877 call_prom("getprop", 4, 1, node, RELOC(pname), valp, l);
1878 *mem_start = _ALIGN(*mem_start, 4);
1879 }
1880
1881
1882 soff = dt_find_string(RELOC("linux,phandle"));
1883 if (soff == 0)
1884 prom_printf("WARNING: Can't find string index for"
1885 " <linux-phandle> node %s\n", path);
1886 else {
1887 dt_push_token(OF_DT_PROP, mem_start, mem_end);
1888 dt_push_token(4, mem_start, mem_end);
1889 dt_push_token(soff, mem_start, mem_end);
1890 valp = make_room(mem_start, mem_end, 4, 4);
1891 *(u32 *)valp = node;
1892 }
1893
1894
1895 child = call_prom("child", 1, 1, node);
1896 while (child != 0) {
1897 scan_dt_build_struct(child, mem_start, mem_end);
1898 child = call_prom("peer", 1, 1, child);
1899 }
1900
1901 dt_push_token(OF_DT_END_NODE, mem_start, mem_end);
1902}
1903
1904static void __init flatten_device_tree(void)
1905{
1906 phandle root;
1907 unsigned long mem_start, mem_end, room;
1908 struct boot_param_header *hdr;
1909 struct prom_t *_prom = &RELOC(prom);
1910 char *namep;
1911 u64 *rsvmap;
1912
1913
1914
1915
1916
1917 room = RELOC(alloc_top) - RELOC(alloc_bottom) - 0x4000;
1918 if (room > DEVTREE_CHUNK_SIZE)
1919 room = DEVTREE_CHUNK_SIZE;
1920 prom_debug("starting device tree allocs at %x\n", RELOC(alloc_bottom));
1921
1922
1923 mem_start = (unsigned long)alloc_up(room, PAGE_SIZE);
1924 if (mem_start == 0)
1925 prom_panic("Can't allocate initial device-tree chunk\n");
1926 mem_end = RELOC(alloc_top);
1927
1928
1929 root = call_prom("peer", 1, 1, (phandle)0);
1930 if (root == (phandle)0)
1931 prom_panic ("couldn't get device tree root\n");
1932
1933
1934 mem_start = _ALIGN(mem_start, 4);
1935 hdr = make_room(&mem_start, &mem_end,
1936 sizeof(struct boot_param_header), 4);
1937 RELOC(dt_header_start) = (unsigned long)hdr;
1938 rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8);
1939
1940
1941 mem_start = PAGE_ALIGN(mem_start);
1942 RELOC(dt_string_start) = mem_start;
1943 mem_start += 4;
1944
1945
1946 namep = make_room(&mem_start, &mem_end, 16, 1);
1947 strcpy(namep, RELOC("linux,phandle"));
1948 mem_start = (unsigned long)namep + strlen(namep) + 1;
1949
1950
1951 prom_printf("Building dt strings...\n");
1952 scan_dt_build_strings(root, &mem_start, &mem_end);
1953 RELOC(dt_string_end) = mem_start;
1954
1955
1956 mem_start = PAGE_ALIGN(mem_start);
1957 RELOC(dt_struct_start) = mem_start;
1958 prom_printf("Building dt structure...\n");
1959 scan_dt_build_struct(root, &mem_start, &mem_end);
1960 dt_push_token(OF_DT_END, &mem_start, &mem_end);
1961 RELOC(dt_struct_end) = PAGE_ALIGN(mem_start);
1962
1963
1964 hdr->boot_cpuid_phys = _prom->cpu;
1965 hdr->magic = OF_DT_HEADER;
1966 hdr->totalsize = RELOC(dt_struct_end) - RELOC(dt_header_start);
1967 hdr->off_dt_struct = RELOC(dt_struct_start) - RELOC(dt_header_start);
1968 hdr->off_dt_strings = RELOC(dt_string_start) - RELOC(dt_header_start);
1969 hdr->dt_strings_size = RELOC(dt_string_end) - RELOC(dt_string_start);
1970 hdr->off_mem_rsvmap = ((unsigned long)rsvmap) - RELOC(dt_header_start);
1971 hdr->version = OF_DT_VERSION;
1972
1973 hdr->last_comp_version = 0x10;
1974
1975
1976 memcpy(rsvmap, RELOC(mem_reserve_map), sizeof(mem_reserve_map));
1977
1978#ifdef DEBUG_PROM
1979 {
1980 int i;
1981 prom_printf("reserved memory map:\n");
1982 for (i = 0; i < RELOC(mem_reserve_cnt); i++)
1983 prom_printf(" %x - %x\n",
1984 RELOC(mem_reserve_map)[i].base,
1985 RELOC(mem_reserve_map)[i].size);
1986 }
1987#endif
1988
1989
1990
1991 RELOC(mem_reserve_cnt) = MEM_RESERVE_MAP_SIZE;
1992
1993 prom_printf("Device tree strings 0x%x -> 0x%x\n",
1994 RELOC(dt_string_start), RELOC(dt_string_end));
1995 prom_printf("Device tree struct 0x%x -> 0x%x\n",
1996 RELOC(dt_struct_start), RELOC(dt_struct_end));
1997
1998}
1999
2000#ifdef CONFIG_PPC_MAPLE
2001
2002
2003static void __init fixup_device_tree_maple(void)
2004{
2005 phandle isa;
2006 u32 rloc = 0x01002000;
2007 u32 isa_ranges[6];
2008 char *name;
2009
2010 name = "/ht@0/isa@4";
2011 isa = call_prom("finddevice", 1, 1, ADDR(name));
2012 if (!PHANDLE_VALID(isa)) {
2013 name = "/ht@0/isa@6";
2014 isa = call_prom("finddevice", 1, 1, ADDR(name));
2015 rloc = 0x01003000;
2016 }
2017 if (!PHANDLE_VALID(isa))
2018 return;
2019
2020 if (prom_getproplen(isa, "ranges") != 12)
2021 return;
2022 if (prom_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges))
2023 == PROM_ERROR)
2024 return;
2025
2026 if (isa_ranges[0] != 0x1 ||
2027 isa_ranges[1] != 0xf4000000 ||
2028 isa_ranges[2] != 0x00010000)
2029 return;
2030
2031 prom_printf("Fixing up bogus ISA range on Maple/Apache...\n");
2032
2033 isa_ranges[0] = 0x1;
2034 isa_ranges[1] = 0x0;
2035 isa_ranges[2] = rloc;
2036 isa_ranges[3] = 0x0;
2037 isa_ranges[4] = 0x0;
2038 isa_ranges[5] = 0x00010000;
2039 prom_setprop(isa, name, "ranges",
2040 isa_ranges, sizeof(isa_ranges));
2041}
2042
2043#define CPC925_MC_START 0xf8000000
2044#define CPC925_MC_LENGTH 0x1000000
2045
2046static void __init fixup_device_tree_maple_memory_controller(void)
2047{
2048 phandle mc;
2049 u32 mc_reg[4];
2050 char *name = "/hostbridge@f8000000";
2051 struct prom_t *_prom = &RELOC(prom);
2052 u32 ac, sc;
2053
2054 mc = call_prom("finddevice", 1, 1, ADDR(name));
2055 if (!PHANDLE_VALID(mc))
2056 return;
2057
2058 if (prom_getproplen(mc, "reg") != 8)
2059 return;
2060
2061 prom_getprop(_prom->root, "#address-cells", &ac, sizeof(ac));
2062 prom_getprop(_prom->root, "#size-cells", &sc, sizeof(sc));
2063 if ((ac != 2) || (sc != 2))
2064 return;
2065
2066 if (prom_getprop(mc, "reg", mc_reg, sizeof(mc_reg)) == PROM_ERROR)
2067 return;
2068
2069 if (mc_reg[0] != CPC925_MC_START || mc_reg[1] != CPC925_MC_LENGTH)
2070 return;
2071
2072 prom_printf("Fixing up bogus hostbridge on Maple...\n");
2073
2074 mc_reg[0] = 0x0;
2075 mc_reg[1] = CPC925_MC_START;
2076 mc_reg[2] = 0x0;
2077 mc_reg[3] = CPC925_MC_LENGTH;
2078 prom_setprop(mc, name, "reg", mc_reg, sizeof(mc_reg));
2079}
2080#else
2081#define fixup_device_tree_maple()
2082#define fixup_device_tree_maple_memory_controller()
2083#endif
2084
2085#ifdef CONFIG_PPC_CHRP
2086
2087
2088
2089
2090
2091static void __init fixup_device_tree_chrp(void)
2092{
2093 phandle ph;
2094 u32 prop[6];
2095 u32 rloc = 0x01006000;
2096 char *name;
2097 int rc;
2098
2099 name = "/pci@80000000/isa@c";
2100 ph = call_prom("finddevice", 1, 1, ADDR(name));
2101 if (!PHANDLE_VALID(ph)) {
2102 name = "/pci@ff500000/isa@6";
2103 ph = call_prom("finddevice", 1, 1, ADDR(name));
2104 rloc = 0x01003000;
2105 }
2106 if (PHANDLE_VALID(ph)) {
2107 rc = prom_getproplen(ph, "ranges");
2108 if (rc == 0 || rc == PROM_ERROR) {
2109 prom_printf("Fixing up missing ISA range on Pegasos...\n");
2110
2111 prop[0] = 0x1;
2112 prop[1] = 0x0;
2113 prop[2] = rloc;
2114 prop[3] = 0x0;
2115 prop[4] = 0x0;
2116 prop[5] = 0x00010000;
2117 prom_setprop(ph, name, "ranges", prop, sizeof(prop));
2118 }
2119 }
2120
2121 name = "/pci@80000000/ide@C,1";
2122 ph = call_prom("finddevice", 1, 1, ADDR(name));
2123 if (PHANDLE_VALID(ph)) {
2124 prom_printf("Fixing up IDE interrupt on Pegasos...\n");
2125 prop[0] = 14;
2126 prop[1] = 0x0;
2127 prom_setprop(ph, name, "interrupts", prop, 2*sizeof(u32));
2128 prom_printf("Fixing up IDE class-code on Pegasos...\n");
2129 rc = prom_getprop(ph, "class-code", prop, sizeof(u32));
2130 if (rc == sizeof(u32)) {
2131 prop[0] &= ~0x5;
2132 prom_setprop(ph, name, "class-code", prop, sizeof(u32));
2133 }
2134 }
2135}
2136#else
2137#define fixup_device_tree_chrp()
2138#endif
2139
2140#if defined(CONFIG_PPC64) && defined(CONFIG_PPC_PMAC)
2141static void __init fixup_device_tree_pmac(void)
2142{
2143 phandle u3, i2c, mpic;
2144 u32 u3_rev;
2145 u32 interrupts[2];
2146 u32 parent;
2147
2148
2149 u3 = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000"));
2150 if (!PHANDLE_VALID(u3))
2151 return;
2152 i2c = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/i2c@f8001000"));
2153 if (!PHANDLE_VALID(i2c))
2154 return;
2155 mpic = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/mpic@f8040000"));
2156 if (!PHANDLE_VALID(mpic))
2157 return;
2158
2159
2160 if (prom_getprop(u3, "device-rev", &u3_rev, sizeof(u3_rev))
2161 == PROM_ERROR)
2162 return;
2163 if (u3_rev < 0x35 || u3_rev > 0x39)
2164 return;
2165
2166 if (prom_getproplen(i2c, "interrupts") > 0)
2167 return;
2168
2169 prom_printf("fixing up bogus interrupts for u3 i2c...\n");
2170
2171
2172 interrupts[0] = 0;
2173 interrupts[1] = 1;
2174 prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupts",
2175 &interrupts, sizeof(interrupts));
2176 parent = (u32)mpic;
2177 prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupt-parent",
2178 &parent, sizeof(parent));
2179}
2180#else
2181#define fixup_device_tree_pmac()
2182#endif
2183
2184#ifdef CONFIG_PPC_EFIKA
2185
2186
2187
2188
2189
2190
2191static void __init fixup_device_tree_efika_add_phy(void)
2192{
2193 u32 node;
2194 char prop[64];
2195 int rv;
2196
2197
2198 node = call_prom("finddevice", 1, 1, ADDR("/builtin/ethernet"));
2199 if (!PHANDLE_VALID(node))
2200 return;
2201
2202
2203 rv = prom_getprop(node, "phy-handle", prop, sizeof(prop));
2204 if (!rv)
2205 return;
2206
2207
2208
2209
2210
2211
2212
2213 node = call_prom("finddevice", 1, 1, ADDR("/builtin/mdio"));
2214 if (!PHANDLE_VALID(node)) {
2215 prom_printf("Adding Ethernet MDIO node\n");
2216 call_prom("interpret", 1, 1,
2217 " s\" /builtin\" find-device"
2218 " new-device"
2219 " 1 encode-int s\" #address-cells\" property"
2220 " 0 encode-int s\" #size-cells\" property"
2221 " s\" mdio\" device-name"
2222 " s\" fsl,mpc5200b-mdio\" encode-string"
2223 " s\" compatible\" property"
2224 " 0xf0003000 0x400 reg"
2225 " 0x2 encode-int"
2226 " 0x5 encode-int encode+"
2227 " 0x3 encode-int encode+"
2228 " s\" interrupts\" property"
2229 " finish-device");
2230 };
2231
2232
2233
2234 node = call_prom("finddevice", 1, 1,
2235 ADDR("/builtin/mdio/ethernet-phy"));
2236 if (!PHANDLE_VALID(node)) {
2237 prom_printf("Adding Ethernet PHY node\n");
2238 call_prom("interpret", 1, 1,
2239 " s\" /builtin/mdio\" find-device"
2240 " new-device"
2241 " s\" ethernet-phy\" device-name"
2242 " 0x10 encode-int s\" reg\" property"
2243 " my-self"
2244 " ihandle>phandle"
2245 " finish-device"
2246 " s\" /builtin/ethernet\" find-device"
2247 " encode-int"
2248 " s\" phy-handle\" property"
2249 " device-end");
2250 }
2251}
2252
2253static void __init fixup_device_tree_efika(void)
2254{
2255 int sound_irq[3] = { 2, 2, 0 };
2256 int bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0,
2257 3,4,0, 3,5,0, 3,6,0, 3,7,0,
2258 3,8,0, 3,9,0, 3,10,0, 3,11,0,
2259 3,12,0, 3,13,0, 3,14,0, 3,15,0 };
2260 u32 node;
2261 char prop[64];
2262 int rv, len;
2263
2264
2265 node = call_prom("finddevice", 1, 1, ADDR("/"));
2266 if (!PHANDLE_VALID(node))
2267 return;
2268
2269 rv = prom_getprop(node, "model", prop, sizeof(prop));
2270 if (rv == PROM_ERROR)
2271 return;
2272 if (strcmp(prop, "EFIKA5K2"))
2273 return;
2274
2275 prom_printf("Applying EFIKA device tree fixups\n");
2276
2277
2278 node = call_prom("finddevice", 1, 1, ADDR("/"));
2279 rv = prom_getprop(node, "device_type", prop, sizeof(prop));
2280 if (rv != PROM_ERROR && (strcmp(prop, "chrp") == 0))
2281 prom_setprop(node, "/", "device_type", "efika", sizeof("efika"));
2282
2283
2284
2285 rv = prom_getprop(node, "CODEGEN,description", prop, sizeof(prop));
2286 if (rv != PROM_ERROR && (strstr(prop, "CHRP")))
2287 prom_setprop(node, "/", "CODEGEN,description",
2288 "Efika 5200B PowerPC System",
2289 sizeof("Efika 5200B PowerPC System"));
2290
2291
2292 node = call_prom("finddevice", 1, 1, ADDR("/builtin/bestcomm"));
2293 if (PHANDLE_VALID(node)) {
2294 len = prom_getproplen(node, "interrupts");
2295 if (len == 12) {
2296 prom_printf("Fixing bestcomm interrupts property\n");
2297 prom_setprop(node, "/builtin/bestcom", "interrupts",
2298 bcomm_irq, sizeof(bcomm_irq));
2299 }
2300 }
2301
2302
2303 node = call_prom("finddevice", 1, 1, ADDR("/builtin/sound"));
2304 if (PHANDLE_VALID(node)) {
2305 rv = prom_getprop(node, "interrupts", prop, sizeof(prop));
2306 if (rv == PROM_ERROR) {
2307 prom_printf("Adding sound interrupts property\n");
2308 prom_setprop(node, "/builtin/sound", "interrupts",
2309 sound_irq, sizeof(sound_irq));
2310 }
2311 }
2312
2313
2314 fixup_device_tree_efika_add_phy();
2315}
2316#else
2317#define fixup_device_tree_efika()
2318#endif
2319
2320static void __init fixup_device_tree(void)
2321{
2322 fixup_device_tree_maple();
2323 fixup_device_tree_maple_memory_controller();
2324 fixup_device_tree_chrp();
2325 fixup_device_tree_pmac();
2326 fixup_device_tree_efika();
2327}
2328
2329static void __init prom_find_boot_cpu(void)
2330{
2331 struct prom_t *_prom = &RELOC(prom);
2332 u32 getprop_rval;
2333 ihandle prom_cpu;
2334 phandle cpu_pkg;
2335
2336 _prom->cpu = 0;
2337 if (prom_getprop(_prom->chosen, "cpu", &prom_cpu, sizeof(prom_cpu)) <= 0)
2338 return;
2339
2340 cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu);
2341
2342 prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval));
2343 _prom->cpu = getprop_rval;
2344
2345 prom_debug("Booting CPU hw index = 0x%x\n", _prom->cpu);
2346}
2347
2348static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
2349{
2350#ifdef CONFIG_BLK_DEV_INITRD
2351 struct prom_t *_prom = &RELOC(prom);
2352
2353 if (r3 && r4 && r4 != 0xdeadbeef) {
2354 unsigned long val;
2355
2356 RELOC(prom_initrd_start) = is_kernel_addr(r3) ? __pa(r3) : r3;
2357 RELOC(prom_initrd_end) = RELOC(prom_initrd_start) + r4;
2358
2359 val = RELOC(prom_initrd_start);
2360 prom_setprop(_prom->chosen, "/chosen", "linux,initrd-start",
2361 &val, sizeof(val));
2362 val = RELOC(prom_initrd_end);
2363 prom_setprop(_prom->chosen, "/chosen", "linux,initrd-end",
2364 &val, sizeof(val));
2365
2366 reserve_mem(RELOC(prom_initrd_start),
2367 RELOC(prom_initrd_end) - RELOC(prom_initrd_start));
2368
2369 prom_debug("initrd_start=0x%x\n", RELOC(prom_initrd_start));
2370 prom_debug("initrd_end=0x%x\n", RELOC(prom_initrd_end));
2371 }
2372#endif
2373}
2374
2375
2376
2377
2378
2379
2380unsigned long __init prom_init(unsigned long r3, unsigned long r4,
2381 unsigned long pp,
2382 unsigned long r6, unsigned long r7,
2383 unsigned long kbase)
2384{
2385 struct prom_t *_prom;
2386 unsigned long hdr;
2387
2388#ifdef CONFIG_PPC32
2389 unsigned long offset = reloc_offset();
2390 reloc_got2(offset);
2391#endif
2392
2393 _prom = &RELOC(prom);
2394
2395
2396
2397
2398 memset(&RELOC(__bss_start), 0, __bss_stop - __bss_start);
2399
2400
2401
2402
2403
2404 prom_init_client_services(pp);
2405
2406
2407
2408
2409
2410 prom_find_mmu();
2411
2412
2413
2414
2415 prom_init_stdout();
2416
2417 prom_printf("Preparing to boot %s", RELOC(linux_banner));
2418
2419
2420
2421
2422
2423 RELOC(of_platform) = prom_find_machine_type();
2424
2425#ifndef CONFIG_RELOCATABLE
2426
2427 if (PHYSICAL_START > 0)
2428 prom_panic("Error: You can't boot a kdump kernel from OF!\n");
2429#endif
2430
2431
2432
2433
2434 prom_check_initrd(r3, r4);
2435
2436#ifdef CONFIG_PPC_PSERIES
2437
2438
2439
2440 if (RELOC(of_platform) == PLATFORM_PSERIES ||
2441 RELOC(of_platform) == PLATFORM_PSERIES_LPAR)
2442 prom_send_capabilities();
2443#endif
2444
2445
2446
2447
2448 if (RELOC(of_platform) != PLATFORM_POWERMAC)
2449 copy_and_flush(0, kbase, 0x100, 0);
2450
2451
2452
2453
2454 early_cmdline_parse();
2455
2456
2457
2458
2459 prom_init_mem();
2460
2461
2462
2463
2464 prom_find_boot_cpu();
2465
2466
2467
2468
2469 prom_check_displays();
2470
2471#ifdef CONFIG_PPC64
2472
2473
2474
2475
2476
2477 if (RELOC(of_platform) == PLATFORM_PSERIES)
2478 prom_initialize_tce_table();
2479#endif
2480
2481
2482
2483
2484
2485
2486 if (RELOC(of_platform) != PLATFORM_POWERMAC) {
2487 prom_instantiate_rtas();
2488 prom_hold_cpus();
2489 }
2490
2491
2492
2493
2494 if (RELOC(prom_memory_limit))
2495 prom_setprop(_prom->chosen, "/chosen", "linux,memory-limit",
2496 &RELOC(prom_memory_limit),
2497 sizeof(prom_memory_limit));
2498#ifdef CONFIG_PPC64
2499 if (RELOC(prom_iommu_off))
2500 prom_setprop(_prom->chosen, "/chosen", "linux,iommu-off",
2501 NULL, 0);
2502
2503 if (RELOC(prom_iommu_force_on))
2504 prom_setprop(_prom->chosen, "/chosen", "linux,iommu-force-on",
2505 NULL, 0);
2506
2507 if (RELOC(prom_tce_alloc_start)) {
2508 prom_setprop(_prom->chosen, "/chosen", "linux,tce-alloc-start",
2509 &RELOC(prom_tce_alloc_start),
2510 sizeof(prom_tce_alloc_start));
2511 prom_setprop(_prom->chosen, "/chosen", "linux,tce-alloc-end",
2512 &RELOC(prom_tce_alloc_end),
2513 sizeof(prom_tce_alloc_end));
2514 }
2515#endif
2516
2517
2518
2519
2520 fixup_device_tree();
2521
2522
2523
2524
2525 prom_printf("copying OF device tree...\n");
2526 flatten_device_tree();
2527
2528
2529
2530
2531
2532
2533 if (RELOC(of_platform) != PLATFORM_POWERMAC)
2534 prom_close_stdin();
2535
2536
2537
2538
2539
2540 prom_printf("Calling quiesce...\n");
2541 call_prom("quiesce", 0, 0);
2542
2543
2544
2545
2546
2547
2548 hdr = RELOC(dt_header_start);
2549 prom_printf("returning from prom_init\n");
2550 prom_debug("->dt_header_start=0x%x\n", hdr);
2551
2552#ifdef CONFIG_PPC32
2553 reloc_got2(-offset);
2554#endif
2555
2556 __start(hdr, kbase, 0);
2557
2558 return 0;
2559}
2560