2 * Procedures for interfacing to Open Firmware.
4 * Paul Mackerras August 1996.
5 * Copyright (C) 1996-2005 Paul Mackerras.
7 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
8 * {engebret|bergner}@us.ibm.com
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
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>
34 #include <asm/processor.h>
38 #include <asm/system.h>
40 #include <asm/pgtable.h>
42 #include <asm/iommu.h>
43 #include <asm/btext.h>
44 #include <asm/sections.h>
45 #include <asm/machdep.h>
47 #include <linux/linux_logo.h>
50 * Properties whose value is longer than this get excluded from our
51 * copy of the device tree. This value does need to be big enough to
52 * ensure that we don't lose things like the interrupt-map property
53 * on a PCI-PCI bridge.
55 #define MAX_PROPERTY_LENGTH (1UL * 1024 * 1024)
58 * Eventually bump that one up
60 #define DEVTREE_CHUNK_SIZE 0x100000
63 * This is the size of the local memory reserve map that gets copied
64 * into the boot params passed to the kernel. That size is totally
65 * flexible as the kernel just reads the list until it encounters an
66 * entry with size 0, so it can be changed without breaking binary
69 #define MEM_RESERVE_MAP_SIZE 8
72 * prom_init() is called very early on, before the kernel text
73 * and data have been mapped to KERNELBASE. At this point the code
74 * is running at whatever address it has been loaded at.
75 * On ppc32 we compile with -mrelocatable, which means that references
76 * to extern and static variables get relocated automatically.
77 * On ppc64 we have to relocate the references explicitly with
78 * RELOC. (Note that strings count as static variables.)
80 * Because OF may have mapped I/O devices into the area starting at
81 * KERNELBASE, particularly on CHRP machines, we can't safely call
82 * OF once the kernel has been mapped to KERNELBASE. Therefore all
83 * OF calls must be done within prom_init().
85 * ADDR is used in calls to call_prom. The 4th and following
86 * arguments to call_prom should be 32-bit values.
87 * On ppc64, 64 bit values are truncated to 32 bits (and
88 * fortunately don't get interpreted as two arguments).
91 #define RELOC(x) (*PTRRELOC(&(x)))
92 #define ADDR(x) (u32) add_reloc_offset((unsigned long)(x))
93 #define OF_WORKAROUNDS 0
96 #define ADDR(x) (u32) (x)
97 #define OF_WORKAROUNDS of_workarounds
101 #define OF_WA_CLAIM 1 /* do phys/virt claim separately, then map */
102 #define OF_WA_LONGTRAIL 2 /* work around longtrail bugs */
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); \
111 #define prom_debug(x...) prom_printf(x)
113 #define prom_debug(x...)
117 typedef u32 prom_arg_t;
135 struct mem_map_entry {
142 extern void __start(unsigned long r3, unsigned long r4, unsigned long r5);
145 extern int enter_prom(struct prom_args *args, unsigned long entry);
147 static inline int enter_prom(struct prom_args *args, unsigned long entry)
149 return ((int (*)(struct prom_args *))entry)(args);
153 extern void copy_and_flush(unsigned long dest, unsigned long src,
154 unsigned long size, unsigned long offset);
157 static struct prom_t __initdata prom;
159 static unsigned long prom_entry __initdata;
161 #define PROM_SCRATCH_SIZE 256
163 static char __initdata of_stdout_device[256];
164 static char __initdata prom_scratch[PROM_SCRATCH_SIZE];
166 static unsigned long __initdata dt_header_start;
167 static unsigned long __initdata dt_struct_start, dt_struct_end;
168 static unsigned long __initdata dt_string_start, dt_string_end;
170 static unsigned long __initdata prom_initrd_start, prom_initrd_end;
173 static int __initdata prom_iommu_force_on;
174 static int __initdata prom_iommu_off;
175 static unsigned long __initdata prom_tce_alloc_start;
176 static unsigned long __initdata prom_tce_alloc_end;
179 /* Platforms codes are now obsolete in the kernel. Now only used within this
180 * file and ultimately gone too. Feel free to change them if you need, they
181 * are not shared with anything outside of this file anymore
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
189 static int __initdata of_platform;
191 static char __initdata prom_cmd_line[COMMAND_LINE_SIZE];
193 static unsigned long __initdata prom_memory_limit;
195 static unsigned long __initdata alloc_top;
196 static unsigned long __initdata alloc_top_high;
197 static unsigned long __initdata alloc_bottom;
198 static unsigned long __initdata rmo_top;
199 static unsigned long __initdata ram_top;
201 static struct mem_map_entry __initdata mem_reserve_map[MEM_RESERVE_MAP_SIZE];
202 static int __initdata mem_reserve_cnt;
204 static cell_t __initdata regbuf[1024];
208 * Error results ... some OF calls will return "-1" on error, some
209 * will return 0, some will return either. To simplify, here are
210 * macros to use with any ihandle or phandle return value to check if
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)
219 /* This is the one and *ONLY* place where we actually call open
223 static int __init call_prom(const char *service, int nargs, int nret, ...)
226 struct prom_args args;
229 args.service = ADDR(service);
233 va_start(list, nret);
234 for (i = 0; i < nargs; i++)
235 args.args[i] = va_arg(list, prom_arg_t);
238 for (i = 0; i < nret; i++)
239 args.args[nargs+i] = 0;
241 if (enter_prom(&args, RELOC(prom_entry)) < 0)
244 return (nret > 0) ? args.args[nargs] : 0;
247 static int __init call_prom_ret(const char *service, int nargs, int nret,
248 prom_arg_t *rets, ...)
251 struct prom_args args;
254 args.service = ADDR(service);
258 va_start(list, rets);
259 for (i = 0; i < nargs; i++)
260 args.args[i] = va_arg(list, prom_arg_t);
263 for (i = 0; i < nret; i++)
264 args.args[nargs+i] = 0;
266 if (enter_prom(&args, RELOC(prom_entry)) < 0)
270 for (i = 1; i < nret; ++i)
271 rets[i-1] = args.args[nargs+i];
273 return (nret > 0) ? args.args[nargs] : 0;
277 static void __init prom_print(const char *msg)
280 struct prom_t *_prom = &RELOC(prom);
282 if (_prom->stdout == 0)
285 for (p = msg; *p != 0; p = q) {
286 for (q = p; *q != 0 && *q != '\n'; ++q)
289 call_prom("write", 3, 1, _prom->stdout, p, q - p);
293 call_prom("write", 3, 1, _prom->stdout, ADDR("\r\n"), 2);
298 static void __init prom_print_hex(unsigned long val)
300 int i, nibbles = sizeof(val)*2;
301 char buf[sizeof(val)*2+1];
302 struct prom_t *_prom = &RELOC(prom);
304 for (i = nibbles-1; i >= 0; i--) {
305 buf[i] = (val & 0xf) + '0';
307 buf[i] += ('a'-'0'-10);
311 call_prom("write", 3, 1, _prom->stdout, buf, nibbles);
315 static void __init prom_printf(const char *format, ...)
317 const char *p, *q, *s;
320 struct prom_t *_prom = &RELOC(prom);
322 va_start(args, format);
324 format = PTRRELOC(format);
326 for (p = format; *p != 0; p = q) {
327 for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q)
330 call_prom("write", 3, 1, _prom->stdout, p, q - p);
335 call_prom("write", 3, 1, _prom->stdout,
345 s = va_arg(args, const char *);
350 v = va_arg(args, unsigned long);
358 static unsigned int __init prom_claim(unsigned long virt, unsigned long size,
361 struct prom_t *_prom = &RELOC(prom);
363 if (align == 0 && (OF_WORKAROUNDS & OF_WA_CLAIM)) {
365 * Old OF requires we claim physical and virtual separately
366 * and then map explicitly (assuming virtual mode)
371 ret = call_prom_ret("call-method", 5, 2, &result,
372 ADDR("claim"), _prom->memory,
374 if (ret != 0 || result == -1)
376 ret = call_prom_ret("call-method", 5, 2, &result,
377 ADDR("claim"), _prom->mmumap,
380 call_prom("call-method", 4, 1, ADDR("release"),
381 _prom->memory, size, virt);
384 /* the 0x12 is M (coherence) + PP == read/write */
385 call_prom("call-method", 6, 1,
386 ADDR("map"), _prom->mmumap, 0x12, size, virt, virt);
389 return call_prom("claim", 3, 1, (prom_arg_t)virt, (prom_arg_t)size,
393 static void __init __attribute__((noreturn)) prom_panic(const char *reason)
396 reason = PTRRELOC(reason);
399 /* Do not call exit because it clears the screen on pmac
400 * it also causes some sort of double-fault on early pmacs */
401 if (RELOC(of_platform) == PLATFORM_POWERMAC)
404 /* ToDo: should put up an SRC here on p/iSeries */
405 call_prom("exit", 0, 0);
407 for (;;) /* should never get here */
412 static int __init prom_next_node(phandle *nodep)
416 if ((node = *nodep) != 0
417 && (*nodep = call_prom("child", 1, 1, node)) != 0)
419 if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
422 if ((node = call_prom("parent", 1, 1, node)) == 0)
424 if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
429 static int inline prom_getprop(phandle node, const char *pname,
430 void *value, size_t valuelen)
432 return call_prom("getprop", 4, 1, node, ADDR(pname),
433 (u32)(unsigned long) value, (u32) valuelen);
436 static int inline prom_getproplen(phandle node, const char *pname)
438 return call_prom("getproplen", 2, 1, node, ADDR(pname));
441 static void add_string(char **str, const char *q)
451 static char *tohex(unsigned int x)
453 static char digits[] = "0123456789abcdef";
454 static char result[9];
461 result[i] = digits[x & 0xf];
463 } while (x != 0 && i > 0);
467 static int __init prom_setprop(phandle node, const char *nodename,
468 const char *pname, void *value, size_t valuelen)
472 if (!(OF_WORKAROUNDS & OF_WA_LONGTRAIL))
473 return call_prom("setprop", 4, 1, node, ADDR(pname),
474 (u32)(unsigned long) value, (u32) valuelen);
476 /* gah... setprop doesn't work on longtrail, have to use interpret */
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");
486 return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd);
489 /* We can't use the standard versions because of RELOC headaches. */
490 #define isxdigit(c) (('0' <= (c) && (c) <= '9') \
491 || ('a' <= (c) && (c) <= 'f') \
492 || ('A' <= (c) && (c) <= 'F'))
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))
498 unsigned long prom_strtoul(const char *cp, const char **endp)
500 unsigned long result = 0, base = 10, value;
505 if (toupper(*cp) == 'X') {
511 while (isxdigit(*cp) &&
512 (value = isdigit(*cp) ? *cp - '0' : toupper(*cp) - 'A' + 10) < base) {
513 result = result * base + value;
523 unsigned long prom_memparse(const char *ptr, const char **retptr)
525 unsigned long ret = prom_strtoul(ptr, retptr);
529 * We can't use a switch here because GCC *may* generate a
530 * jump table which won't work, because we're not running at
531 * the address we're linked at.
533 if ('G' == **retptr || 'g' == **retptr)
536 if ('M' == **retptr || 'm' == **retptr)
539 if ('K' == **retptr || 'k' == **retptr)
551 * Early parsing of the command line passed to the kernel, used for
552 * "mem=x" and the options that affect the iommu
554 static void __init early_cmdline_parse(void)
556 struct prom_t *_prom = &RELOC(prom);
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') /* dbl check */
568 strlcpy(RELOC(prom_cmd_line),
569 RELOC(CONFIG_CMDLINE), sizeof(prom_cmd_line));
570 #endif /* CONFIG_CMDLINE */
571 prom_printf("command line: %s\n", RELOC(prom_cmd_line));
574 opt = strstr(RELOC(prom_cmd_line), RELOC("iommu="));
576 prom_printf("iommu opt is: %s\n", opt);
578 while (*opt && *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;
586 opt = strstr(RELOC(prom_cmd_line), RELOC("mem="));
589 RELOC(prom_memory_limit) = prom_memparse(opt, (const char **)&opt);
591 /* Align to 16 MB == size of ppc64 large page */
592 RELOC(prom_memory_limit) = ALIGN(RELOC(prom_memory_limit), 0x1000000);
597 #ifdef CONFIG_PPC_PSERIES
599 * There are two methods for telling firmware what our capabilities are.
600 * Newer machines have an "ibm,client-architecture-support" method on the
601 * root node. For older machines, we have to call the "process-elf-header"
602 * method in the /packages/elf-loader node, passing it a fake 32-bit
603 * ELF header containing a couple of PT_NOTE sections that contain
604 * structures that contain various information.
608 * New method - extensible architecture description vector.
610 * Because the description vector contains a mix of byte and word
611 * values, we declare it as an unsigned char array, and use this
612 * macro to put word values in.
614 #define W(x) ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
615 ((x) >> 8) & 0xff, (x) & 0xff
617 /* Option vector bits - generic bits in byte 1 */
618 #define OV_IGNORE 0x80 /* ignore this vector */
619 #define OV_CESSATION_POLICY 0x40 /* halt if unsupported option present*/
621 /* Option vector 1: processor architectures supported */
622 #define OV1_PPC_2_00 0x80 /* set if we support PowerPC 2.00 */
623 #define OV1_PPC_2_01 0x40 /* set if we support PowerPC 2.01 */
624 #define OV1_PPC_2_02 0x20 /* set if we support PowerPC 2.02 */
625 #define OV1_PPC_2_03 0x10 /* set if we support PowerPC 2.03 */
626 #define OV1_PPC_2_04 0x08 /* set if we support PowerPC 2.04 */
627 #define OV1_PPC_2_05 0x04 /* set if we support PowerPC 2.05 */
628 #define OV1_PPC_2_06 0x02 /* set if we support PowerPC 2.06 */
630 /* Option vector 2: Open Firmware options supported */
631 #define OV2_REAL_MODE 0x20 /* set if we want OF in real mode */
633 /* Option vector 3: processor options supported */
634 #define OV3_FP 0x80 /* floating point */
635 #define OV3_VMX 0x40 /* VMX/Altivec */
636 #define OV3_DFP 0x20 /* decimal FP */
638 /* Option vector 5: PAPR/OF options supported */
639 #define OV5_LPAR 0x80 /* logical partitioning supported */
640 #define OV5_SPLPAR 0x40 /* shared-processor LPAR supported */
641 /* ibm,dynamic-reconfiguration-memory property supported */
642 #define OV5_DRCONF_MEMORY 0x20
643 #define OV5_LARGE_PAGES 0x10 /* large pages supported */
644 #define OV5_DONATE_DEDICATE_CPU 0x02 /* donate dedicated CPU support */
645 /* PCIe/MSI support. Without MSI full PCIe is not supported */
646 #ifdef CONFIG_PCI_MSI
647 #define OV5_MSI 0x01 /* PCIe/MSI support */
650 #endif /* CONFIG_PCI_MSI */
651 #ifdef CONFIG_PPC_SMLPAR
652 #define OV5_CMO 0x80 /* Cooperative Memory Overcommitment */
657 /* Option Vector 6: IBM PAPR hints */
658 #define OV6_LINUX 0x02 /* Linux is our OS */
661 * The architecture vector has an array of PVR mask/value pairs,
662 * followed by # option vectors - 1, followed by the option vectors.
664 static unsigned char ibm_architecture_vec[] = {
665 W(0xfffe0000), W(0x003a0000), /* POWER5/POWER5+ */
666 W(0xffff0000), W(0x003e0000), /* POWER6 */
667 W(0xffff0000), W(0x003f0000), /* POWER7 */
668 W(0xffffffff), W(0x0f000003), /* all 2.06-compliant */
669 W(0xffffffff), W(0x0f000002), /* all 2.05-compliant */
670 W(0xfffffffe), W(0x0f000001), /* all 2.04-compliant and earlier */
671 6 - 1, /* 6 option vectors */
673 /* option vector 1: processor architectures supported */
675 0, /* don't ignore, don't halt */
676 OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 |
677 OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06,
679 /* option vector 2: Open Firmware options supported */
683 W(0xffffffff), /* real_base */
684 W(0xffffffff), /* real_size */
685 W(0xffffffff), /* virt_base */
686 W(0xffffffff), /* virt_size */
687 W(0xffffffff), /* load_base */
688 W(64), /* 64MB min RMA */
689 W(0xffffffff), /* full client load */
690 0, /* min RMA percentage of total RAM */
691 48, /* max log_2(hash table size) */
693 /* option vector 3: processor options supported */
695 0, /* don't ignore, don't halt */
696 OV3_FP | OV3_VMX | OV3_DFP,
698 /* option vector 4: IBM PAPR implementation */
702 /* option vector 5: PAPR/OF options */
704 0, /* don't ignore, don't halt */
705 OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY |
706 OV5_DONATE_DEDICATE_CPU | OV5_MSI,
713 /* WARNING: The offset of the "number of cores" field below
714 * must match by the macro below. Update the definition if
715 * the structure layout changes.
717 #define IBM_ARCH_VEC_NRCORES_OFFSET 100
718 W(NR_CPUS), /* number of cores supported */
720 /* option vector 6: IBM PAPR hints */
728 /* Old method - ELF header with PT_NOTE sections */
729 static struct fake_elf {
736 char name[8]; /* "PowerPC" */
750 char name[24]; /* "IBM,RPA-Client-Config" */
764 .e_ident = { 0x7f, 'E', 'L', 'F',
765 ELFCLASS32, ELFDATA2MSB, EV_CURRENT },
766 .e_type = ET_EXEC, /* yeah right */
768 .e_version = EV_CURRENT,
769 .e_phoff = offsetof(struct fake_elf, phdr),
770 .e_phentsize = sizeof(Elf32_Phdr),
776 .p_offset = offsetof(struct fake_elf, chrpnote),
777 .p_filesz = sizeof(struct chrpnote)
780 .p_offset = offsetof(struct fake_elf, rpanote),
781 .p_filesz = sizeof(struct rpanote)
785 .namesz = sizeof("PowerPC"),
786 .descsz = sizeof(struct chrpdesc),
790 .real_mode = ~0U, /* ~0 means "don't care" */
799 .namesz = sizeof("IBM,RPA-Client-Config"),
800 .descsz = sizeof(struct rpadesc),
802 .name = "IBM,RPA-Client-Config",
805 .min_rmo_size = 64, /* in megabytes */
806 .min_rmo_percent = 0,
807 .max_pft_size = 48, /* 2^48 bytes max PFT size */
815 static int __init prom_count_smt_threads(void)
821 /* Pick up th first CPU node we can find */
822 for (node = 0; prom_next_node(&node); ) {
824 prom_getprop(node, "device_type", type, sizeof(type));
826 if (strcmp(type, RELOC("cpu")))
829 * There is an entry for each smt thread, each entry being
830 * 4 bytes long. All cpus should have the same number of
831 * smt threads, so return after finding the first.
833 plen = prom_getproplen(node, "ibm,ppc-interrupt-server#s");
834 if (plen == PROM_ERROR)
837 prom_debug("Found 0x%x smt threads per core\n", (unsigned long)plen);
840 if (plen < 1 || plen > 64) {
841 prom_printf("Threads per core 0x%x out of bounds, assuming 1\n",
842 (unsigned long)plen);
847 prom_debug("No threads found, assuming 1 per core\n");
854 static void __init prom_send_capabilities(void)
856 ihandle elfloader, root;
860 root = call_prom("open", 1, 1, ADDR("/"));
862 /* We need to tell the FW about the number of cores we support.
864 * To do that, we count the number of threads on the first core
865 * (we assume this is the same for all cores) and use it to
868 cores = (u32 *)PTRRELOC(&ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET]);
869 if (*cores != NR_CPUS) {
870 prom_printf("WARNING ! "
871 "ibm_architecture_vec structure inconsistent: 0x%x !\n",
874 *cores = NR_CPUS / prom_count_smt_threads();
875 prom_printf("Max number of cores passed to firmware: 0x%x\n",
876 (unsigned long)*cores);
879 /* try calling the ibm,client-architecture-support method */
880 prom_printf("Calling ibm,client-architecture-support...");
881 if (call_prom_ret("call-method", 3, 2, &ret,
882 ADDR("ibm,client-architecture-support"),
884 ADDR(ibm_architecture_vec)) == 0) {
885 /* the call exists... */
887 prom_printf("\nWARNING: ibm,client-architecture"
888 "-support call FAILED!\n");
889 call_prom("close", 1, 0, root);
890 prom_printf(" done\n");
893 call_prom("close", 1, 0, root);
894 prom_printf(" not implemented\n");
897 /* no ibm,client-architecture-support call, try the old way */
898 elfloader = call_prom("open", 1, 1, ADDR("/packages/elf-loader"));
899 if (elfloader == 0) {
900 prom_printf("couldn't open /packages/elf-loader\n");
903 call_prom("call-method", 3, 1, ADDR("process-elf-header"),
904 elfloader, ADDR(&fake_elf));
905 call_prom("close", 1, 0, elfloader);
910 * Memory allocation strategy... our layout is normally:
912 * at 14Mb or more we have vmlinux, then a gap and initrd. In some
913 * rare cases, initrd might end up being before the kernel though.
914 * We assume this won't override the final kernel at 0, we have no
915 * provision to handle that in this version, but it should hopefully
918 * alloc_top is set to the top of RMO, eventually shrink down if the
921 * alloc_bottom is set to the top of kernel/initrd
923 * from there, allocations are done this way : rtas is allocated
924 * topmost, and the device-tree is allocated from the bottom. We try
925 * to grow the device-tree allocation as we progress. If we can't,
926 * then we fail, we don't currently have a facility to restart
927 * elsewhere, but that shouldn't be necessary.
929 * Note that calls to reserve_mem have to be done explicitly, memory
930 * allocated with either alloc_up or alloc_down isn't automatically
936 * Allocates memory in the RMO upward from the kernel/initrd
938 * When align is 0, this is a special case, it means to allocate in place
939 * at the current location of alloc_bottom or fail (that is basically
940 * extending the previous allocation). Used for the device-tree flattening
942 static unsigned long __init alloc_up(unsigned long size, unsigned long align)
944 unsigned long base = RELOC(alloc_bottom);
945 unsigned long addr = 0;
948 base = _ALIGN_UP(base, align);
949 prom_debug("alloc_up(%x, %x)\n", size, align);
950 if (RELOC(ram_top) == 0)
951 prom_panic("alloc_up() called with mem not initialized\n");
954 base = _ALIGN_UP(RELOC(alloc_bottom), align);
956 base = RELOC(alloc_bottom);
958 for(; (base + size) <= RELOC(alloc_top);
959 base = _ALIGN_UP(base + 0x100000, align)) {
960 prom_debug(" trying: 0x%x\n\r", base);
961 addr = (unsigned long)prom_claim(base, size, 0);
962 if (addr != PROM_ERROR && addr != 0)
970 RELOC(alloc_bottom) = addr;
972 prom_debug(" -> %x\n", addr);
973 prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
974 prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
975 prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
976 prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
977 prom_debug(" ram_top : %x\n", RELOC(ram_top));
983 * Allocates memory downward, either from top of RMO, or if highmem
984 * is set, from the top of RAM. Note that this one doesn't handle
985 * failures. It does claim memory if highmem is not set.
987 static unsigned long __init alloc_down(unsigned long size, unsigned long align,
990 unsigned long base, addr = 0;
992 prom_debug("alloc_down(%x, %x, %s)\n", size, align,
993 highmem ? RELOC("(high)") : RELOC("(low)"));
994 if (RELOC(ram_top) == 0)
995 prom_panic("alloc_down() called with mem not initialized\n");
998 /* Carve out storage for the TCE table. */
999 addr = _ALIGN_DOWN(RELOC(alloc_top_high) - size, align);
1000 if (addr <= RELOC(alloc_bottom))
1002 /* Will we bump into the RMO ? If yes, check out that we
1003 * didn't overlap existing allocations there, if we did,
1004 * we are dead, we must be the first in town !
1006 if (addr < RELOC(rmo_top)) {
1007 /* Good, we are first */
1008 if (RELOC(alloc_top) == RELOC(rmo_top))
1009 RELOC(alloc_top) = RELOC(rmo_top) = addr;
1013 RELOC(alloc_top_high) = addr;
1017 base = _ALIGN_DOWN(RELOC(alloc_top) - size, align);
1018 for (; base > RELOC(alloc_bottom);
1019 base = _ALIGN_DOWN(base - 0x100000, align)) {
1020 prom_debug(" trying: 0x%x\n\r", base);
1021 addr = (unsigned long)prom_claim(base, size, 0);
1022 if (addr != PROM_ERROR && addr != 0)
1028 RELOC(alloc_top) = addr;
1031 prom_debug(" -> %x\n", addr);
1032 prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
1033 prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
1034 prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
1035 prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
1036 prom_debug(" ram_top : %x\n", RELOC(ram_top));
1042 * Parse a "reg" cell
1044 static unsigned long __init prom_next_cell(int s, cell_t **cellp)
1047 unsigned long r = 0;
1049 /* Ignore more than 2 cells */
1050 while (s > sizeof(unsigned long) / 4) {
1066 * Very dumb function for adding to the memory reserve list, but
1067 * we don't need anything smarter at this point
1069 * XXX Eventually check for collisions. They should NEVER happen.
1070 * If problems seem to show up, it would be a good start to track
1073 static void __init reserve_mem(u64 base, u64 size)
1075 u64 top = base + size;
1076 unsigned long cnt = RELOC(mem_reserve_cnt);
1081 /* We need to always keep one empty entry so that we
1082 * have our terminator with "size" set to 0 since we are
1083 * dumb and just copy this entire array to the boot params
1085 base = _ALIGN_DOWN(base, PAGE_SIZE);
1086 top = _ALIGN_UP(top, PAGE_SIZE);
1089 if (cnt >= (MEM_RESERVE_MAP_SIZE - 1))
1090 prom_panic("Memory reserve map exhausted !\n");
1091 RELOC(mem_reserve_map)[cnt].base = base;
1092 RELOC(mem_reserve_map)[cnt].size = size;
1093 RELOC(mem_reserve_cnt) = cnt + 1;
1097 * Initialize memory allocation mechanism, parse "memory" nodes and
1098 * obtain that way the top of memory and RMO to setup out local allocator
1100 static void __init prom_init_mem(void)
1103 char *path, type[64];
1106 struct prom_t *_prom = &RELOC(prom);
1110 * We iterate the memory nodes to find
1111 * 1) top of RMO (first node)
1115 prom_getprop(_prom->root, "#address-cells", &rac, sizeof(rac));
1117 prom_getprop(_prom->root, "#size-cells", &rsc, sizeof(rsc));
1118 prom_debug("root_addr_cells: %x\n", (unsigned long) rac);
1119 prom_debug("root_size_cells: %x\n", (unsigned long) rsc);
1121 prom_debug("scanning memory:\n");
1122 path = RELOC(prom_scratch);
1124 for (node = 0; prom_next_node(&node); ) {
1126 prom_getprop(node, "device_type", type, sizeof(type));
1130 * CHRP Longtrail machines have no device_type
1131 * on the memory node, so check the name instead...
1133 prom_getprop(node, "name", type, sizeof(type));
1135 if (strcmp(type, RELOC("memory")))
1138 plen = prom_getprop(node, "reg", RELOC(regbuf), sizeof(regbuf));
1139 if (plen > sizeof(regbuf)) {
1140 prom_printf("memory node too large for buffer !\n");
1141 plen = sizeof(regbuf);
1144 endp = p + (plen / sizeof(cell_t));
1147 memset(path, 0, PROM_SCRATCH_SIZE);
1148 call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
1149 prom_debug(" node %s :\n", path);
1150 #endif /* DEBUG_PROM */
1152 while ((endp - p) >= (rac + rsc)) {
1153 unsigned long base, size;
1155 base = prom_next_cell(rac, &p);
1156 size = prom_next_cell(rsc, &p);
1160 prom_debug(" %x %x\n", base, size);
1161 if (base == 0 && (RELOC(of_platform) & PLATFORM_LPAR))
1162 RELOC(rmo_top) = size;
1163 if ((base + size) > RELOC(ram_top))
1164 RELOC(ram_top) = base + size;
1168 RELOC(alloc_bottom) = PAGE_ALIGN((unsigned long)&RELOC(_end) + 0x4000);
1170 /* Check if we have an initrd after the kernel, if we do move our bottom
1173 if (RELOC(prom_initrd_start)) {
1174 if (RELOC(prom_initrd_end) > RELOC(alloc_bottom))
1175 RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(prom_initrd_end));
1179 * If prom_memory_limit is set we reduce the upper limits *except* for
1180 * alloc_top_high. This must be the real top of RAM so we can put
1184 RELOC(alloc_top_high) = RELOC(ram_top);
1186 if (RELOC(prom_memory_limit)) {
1187 if (RELOC(prom_memory_limit) <= RELOC(alloc_bottom)) {
1188 prom_printf("Ignoring mem=%x <= alloc_bottom.\n",
1189 RELOC(prom_memory_limit));
1190 RELOC(prom_memory_limit) = 0;
1191 } else if (RELOC(prom_memory_limit) >= RELOC(ram_top)) {
1192 prom_printf("Ignoring mem=%x >= ram_top.\n",
1193 RELOC(prom_memory_limit));
1194 RELOC(prom_memory_limit) = 0;
1196 RELOC(ram_top) = RELOC(prom_memory_limit);
1197 RELOC(rmo_top) = min(RELOC(rmo_top), RELOC(prom_memory_limit));
1202 * Setup our top alloc point, that is top of RMO or top of
1203 * segment 0 when running non-LPAR.
1204 * Some RS64 machines have buggy firmware where claims up at
1205 * 1GB fail. Cap at 768MB as a workaround.
1206 * Since 768MB is plenty of room, and we need to cap to something
1207 * reasonable on 32-bit, cap at 768MB on all machines.
1209 if (!RELOC(rmo_top))
1210 RELOC(rmo_top) = RELOC(ram_top);
1211 RELOC(rmo_top) = min(0x30000000ul, RELOC(rmo_top));
1212 RELOC(alloc_top) = RELOC(rmo_top);
1213 RELOC(alloc_top_high) = RELOC(ram_top);
1215 prom_printf("memory layout at init:\n");
1216 prom_printf(" memory_limit : %x (16 MB aligned)\n", RELOC(prom_memory_limit));
1217 prom_printf(" alloc_bottom : %x\n", RELOC(alloc_bottom));
1218 prom_printf(" alloc_top : %x\n", RELOC(alloc_top));
1219 prom_printf(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
1220 prom_printf(" rmo_top : %x\n", RELOC(rmo_top));
1221 prom_printf(" ram_top : %x\n", RELOC(ram_top));
1226 * Allocate room for and instantiate RTAS
1228 static void __init prom_instantiate_rtas(void)
1232 u32 base, entry = 0;
1235 prom_debug("prom_instantiate_rtas: start...\n");
1237 rtas_node = call_prom("finddevice", 1, 1, ADDR("/rtas"));
1238 prom_debug("rtas_node: %x\n", rtas_node);
1239 if (!PHANDLE_VALID(rtas_node))
1242 prom_getprop(rtas_node, "rtas-size", &size, sizeof(size));
1246 base = alloc_down(size, PAGE_SIZE, 0);
1248 prom_printf("RTAS allocation failed !\n");
1252 rtas_inst = call_prom("open", 1, 1, ADDR("/rtas"));
1253 if (!IHANDLE_VALID(rtas_inst)) {
1254 prom_printf("opening rtas package failed (%x)\n", rtas_inst);
1258 prom_printf("instantiating rtas at 0x%x...", base);
1260 if (call_prom_ret("call-method", 3, 2, &entry,
1261 ADDR("instantiate-rtas"),
1262 rtas_inst, base) != 0
1264 prom_printf(" failed\n");
1267 prom_printf(" done\n");
1269 reserve_mem(base, size);
1271 prom_setprop(rtas_node, "/rtas", "linux,rtas-base",
1272 &base, sizeof(base));
1273 prom_setprop(rtas_node, "/rtas", "linux,rtas-entry",
1274 &entry, sizeof(entry));
1276 prom_debug("rtas base = 0x%x\n", base);
1277 prom_debug("rtas entry = 0x%x\n", entry);
1278 prom_debug("rtas size = 0x%x\n", (long)size);
1280 prom_debug("prom_instantiate_rtas: end...\n");
1285 * Allocate room for and initialize TCE tables
1287 static void __init prom_initialize_tce_table(void)
1291 char compatible[64], type[64], model[64];
1292 char *path = RELOC(prom_scratch);
1294 u32 minalign, minsize;
1295 u64 tce_entry, *tce_entryp;
1296 u64 local_alloc_top, local_alloc_bottom;
1299 if (RELOC(prom_iommu_off))
1302 prom_debug("starting prom_initialize_tce_table\n");
1304 /* Cache current top of allocs so we reserve a single block */
1305 local_alloc_top = RELOC(alloc_top_high);
1306 local_alloc_bottom = local_alloc_top;
1308 /* Search all nodes looking for PHBs. */
1309 for (node = 0; prom_next_node(&node); ) {
1313 prom_getprop(node, "compatible",
1314 compatible, sizeof(compatible));
1315 prom_getprop(node, "device_type", type, sizeof(type));
1316 prom_getprop(node, "model", model, sizeof(model));
1318 if ((type[0] == 0) || (strstr(type, RELOC("pci")) == NULL))
1321 /* Keep the old logic intact to avoid regression. */
1322 if (compatible[0] != 0) {
1323 if ((strstr(compatible, RELOC("python")) == NULL) &&
1324 (strstr(compatible, RELOC("Speedwagon")) == NULL) &&
1325 (strstr(compatible, RELOC("Winnipeg")) == NULL))
1327 } else if (model[0] != 0) {
1328 if ((strstr(model, RELOC("ython")) == NULL) &&
1329 (strstr(model, RELOC("peedwagon")) == NULL) &&
1330 (strstr(model, RELOC("innipeg")) == NULL))
1334 if (prom_getprop(node, "tce-table-minalign", &minalign,
1335 sizeof(minalign)) == PROM_ERROR)
1337 if (prom_getprop(node, "tce-table-minsize", &minsize,
1338 sizeof(minsize)) == PROM_ERROR)
1339 minsize = 4UL << 20;
1342 * Even though we read what OF wants, we just set the table
1343 * size to 4 MB. This is enough to map 2GB of PCI DMA space.
1344 * By doing this, we avoid the pitfalls of trying to DMA to
1345 * MMIO space and the DMA alias hole.
1347 * On POWER4, firmware sets the TCE region by assuming
1348 * each TCE table is 8MB. Using this memory for anything
1349 * else will impact performance, so we always allocate 8MB.
1352 if (__is_processor(PV_POWER4) || __is_processor(PV_POWER4p))
1353 minsize = 8UL << 20;
1355 minsize = 4UL << 20;
1357 /* Align to the greater of the align or size */
1358 align = max(minalign, minsize);
1359 base = alloc_down(minsize, align, 1);
1361 prom_panic("ERROR, cannot find space for TCE table.\n");
1362 if (base < local_alloc_bottom)
1363 local_alloc_bottom = base;
1365 /* It seems OF doesn't null-terminate the path :-( */
1366 memset(path, 0, PROM_SCRATCH_SIZE);
1367 /* Call OF to setup the TCE hardware */
1368 if (call_prom("package-to-path", 3, 1, node,
1369 path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) {
1370 prom_printf("package-to-path failed\n");
1373 /* Save away the TCE table attributes for later use. */
1374 prom_setprop(node, path, "linux,tce-base", &base, sizeof(base));
1375 prom_setprop(node, path, "linux,tce-size", &minsize, sizeof(minsize));
1377 prom_debug("TCE table: %s\n", path);
1378 prom_debug("\tnode = 0x%x\n", node);
1379 prom_debug("\tbase = 0x%x\n", base);
1380 prom_debug("\tsize = 0x%x\n", minsize);
1382 /* Initialize the table to have a one-to-one mapping
1383 * over the allocated size.
1385 tce_entryp = (u64 *)base;
1386 for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {
1387 tce_entry = (i << PAGE_SHIFT);
1389 *tce_entryp = tce_entry;
1392 prom_printf("opening PHB %s", path);
1393 phb_node = call_prom("open", 1, 1, path);
1395 prom_printf("... failed\n");
1397 prom_printf("... done\n");
1399 call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"),
1400 phb_node, -1, minsize,
1401 (u32) base, (u32) (base >> 32));
1402 call_prom("close", 1, 0, phb_node);
1405 reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom);
1407 /* These are only really needed if there is a memory limit in
1408 * effect, but we don't know so export them always. */
1409 RELOC(prom_tce_alloc_start) = local_alloc_bottom;
1410 RELOC(prom_tce_alloc_end) = local_alloc_top;
1412 /* Flag the first invalid entry */
1413 prom_debug("ending prom_initialize_tce_table\n");
1418 * With CHRP SMP we need to use the OF to start the other processors.
1419 * We can't wait until smp_boot_cpus (the OF is trashed by then)
1420 * so we have to put the processors into a holding pattern controlled
1421 * by the kernel (not OF) before we destroy the OF.
1423 * This uses a chunk of low memory, puts some holding pattern
1424 * code there and sends the other processors off to there until
1425 * smp_boot_cpus tells them to do something. The holding pattern
1426 * checks that address until its cpu # is there, when it is that
1427 * cpu jumps to __secondary_start(). smp_boot_cpus() takes care
1428 * of setting those values.
1430 * We also use physical address 0x4 here to tell when a cpu
1431 * is in its holding pattern code.
1436 * We want to reference the copy of __secondary_hold_* in the
1437 * 0 - 0x100 address range
1439 #define LOW_ADDR(x) (((unsigned long) &(x)) & 0xff)
1441 static void __init prom_hold_cpus(void)
1447 struct prom_t *_prom = &RELOC(prom);
1448 unsigned long *spinloop
1449 = (void *) LOW_ADDR(__secondary_hold_spinloop);
1450 unsigned long *acknowledge
1451 = (void *) LOW_ADDR(__secondary_hold_acknowledge);
1452 unsigned long secondary_hold = LOW_ADDR(__secondary_hold);
1454 prom_debug("prom_hold_cpus: start...\n");
1455 prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop);
1456 prom_debug(" 1) *spinloop = 0x%x\n", *spinloop);
1457 prom_debug(" 1) acknowledge = 0x%x\n",
1458 (unsigned long)acknowledge);
1459 prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge);
1460 prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold);
1462 /* Set the common spinloop variable, so all of the secondary cpus
1463 * will block when they are awakened from their OF spinloop.
1464 * This must occur for both SMP and non SMP kernels, since OF will
1465 * be trashed when we move the kernel.
1470 for (node = 0; prom_next_node(&node); ) {
1472 prom_getprop(node, "device_type", type, sizeof(type));
1473 if (strcmp(type, RELOC("cpu")) != 0)
1476 /* Skip non-configured cpus. */
1477 if (prom_getprop(node, "status", type, sizeof(type)) > 0)
1478 if (strcmp(type, RELOC("okay")) != 0)
1482 prom_getprop(node, "reg", ®, sizeof(reg));
1484 prom_debug("cpu hw idx = 0x%x\n", reg);
1486 /* Init the acknowledge var which will be reset by
1487 * the secondary cpu when it awakens from its OF
1490 *acknowledge = (unsigned long)-1;
1492 if (reg != _prom->cpu) {
1493 /* Primary Thread of non-boot cpu */
1494 prom_printf("starting cpu hw idx %x... ", reg);
1495 call_prom("start-cpu", 3, 0, node,
1496 secondary_hold, reg);
1498 for (i = 0; (i < 100000000) &&
1499 (*acknowledge == ((unsigned long)-1)); i++ )
1502 if (*acknowledge == reg)
1503 prom_printf("done\n");
1505 prom_printf("failed: %x\n", *acknowledge);
1509 prom_printf("boot cpu hw idx %x\n", reg);
1510 #endif /* CONFIG_SMP */
1513 prom_debug("prom_hold_cpus: end...\n");
1517 static void __init prom_init_client_services(unsigned long pp)
1519 struct prom_t *_prom = &RELOC(prom);
1521 /* Get a handle to the prom entry point before anything else */
1522 RELOC(prom_entry) = pp;
1524 /* get a handle for the stdout device */
1525 _prom->chosen = call_prom("finddevice", 1, 1, ADDR("/chosen"));
1526 if (!PHANDLE_VALID(_prom->chosen))
1527 prom_panic("cannot find chosen"); /* msg won't be printed :( */
1529 /* get device tree root */
1530 _prom->root = call_prom("finddevice", 1, 1, ADDR("/"));
1531 if (!PHANDLE_VALID(_prom->root))
1532 prom_panic("cannot find device tree root"); /* msg won't be printed :( */
1539 * For really old powermacs, we need to map things we claim.
1540 * For that, we need the ihandle of the mmu.
1541 * Also, on the longtrail, we need to work around other bugs.
1543 static void __init prom_find_mmu(void)
1545 struct prom_t *_prom = &RELOC(prom);
1549 oprom = call_prom("finddevice", 1, 1, ADDR("/openprom"));
1550 if (!PHANDLE_VALID(oprom))
1552 if (prom_getprop(oprom, "model", version, sizeof(version)) <= 0)
1554 version[sizeof(version) - 1] = 0;
1555 /* XXX might need to add other versions here */
1556 if (strcmp(version, "Open Firmware, 1.0.5") == 0)
1557 of_workarounds = OF_WA_CLAIM;
1558 else if (strncmp(version, "FirmWorks,3.", 12) == 0) {
1559 of_workarounds = OF_WA_CLAIM | OF_WA_LONGTRAIL;
1560 call_prom("interpret", 1, 1, "dev /memory 0 to allow-reclaim");
1563 _prom->memory = call_prom("open", 1, 1, ADDR("/memory"));
1564 prom_getprop(_prom->chosen, "mmu", &_prom->mmumap,
1565 sizeof(_prom->mmumap));
1566 if (!IHANDLE_VALID(_prom->memory) || !IHANDLE_VALID(_prom->mmumap))
1567 of_workarounds &= ~OF_WA_CLAIM; /* hmmm */
1570 #define prom_find_mmu()
1573 static void __init prom_init_stdout(void)
1575 struct prom_t *_prom = &RELOC(prom);
1576 char *path = RELOC(of_stdout_device);
1580 if (prom_getprop(_prom->chosen, "stdout", &val, sizeof(val)) <= 0)
1581 prom_panic("cannot find stdout");
1583 _prom->stdout = val;
1585 /* Get the full OF pathname of the stdout device */
1586 memset(path, 0, 256);
1587 call_prom("instance-to-path", 3, 1, _prom->stdout, path, 255);
1588 val = call_prom("instance-to-package", 1, 1, _prom->stdout);
1589 prom_setprop(_prom->chosen, "/chosen", "linux,stdout-package",
1591 prom_printf("OF stdout device is: %s\n", RELOC(of_stdout_device));
1592 prom_setprop(_prom->chosen, "/chosen", "linux,stdout-path",
1593 path, strlen(path) + 1);
1595 /* If it's a display, note it */
1596 memset(type, 0, sizeof(type));
1597 prom_getprop(val, "device_type", type, sizeof(type));
1598 if (strcmp(type, RELOC("display")) == 0)
1599 prom_setprop(val, path, "linux,boot-display", NULL, 0);
1602 static void __init prom_close_stdin(void)
1604 struct prom_t *_prom = &RELOC(prom);
1607 if (prom_getprop(_prom->chosen, "stdin", &val, sizeof(val)) > 0)
1608 call_prom("close", 1, 0, val);
1611 static int __init prom_find_machine_type(void)
1613 struct prom_t *_prom = &RELOC(prom);
1621 /* Look for a PowerMac */
1622 len = prom_getprop(_prom->root, "compatible",
1623 compat, sizeof(compat)-1);
1627 char *p = &compat[i];
1631 if (strstr(p, RELOC("Power Macintosh")) ||
1632 strstr(p, RELOC("MacRISC")))
1633 return PLATFORM_POWERMAC;
1635 /* We must make sure we don't detect the IBM Cell
1636 * blades as pSeries due to some firmware issues,
1639 if (strstr(p, RELOC("IBM,CBEA")) ||
1640 strstr(p, RELOC("IBM,CPBW-1.0")))
1641 return PLATFORM_GENERIC;
1642 #endif /* CONFIG_PPC64 */
1647 /* If not a mac, try to figure out if it's an IBM pSeries or any other
1648 * PAPR compliant platform. We assume it is if :
1649 * - /device_type is "chrp" (please, do NOT use that for future
1653 len = prom_getprop(_prom->root, "device_type",
1654 compat, sizeof(compat)-1);
1656 return PLATFORM_GENERIC;
1657 if (strcmp(compat, RELOC("chrp")))
1658 return PLATFORM_GENERIC;
1660 /* Default to pSeries. We need to know if we are running LPAR */
1661 rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
1662 if (!PHANDLE_VALID(rtas))
1663 return PLATFORM_GENERIC;
1664 x = prom_getproplen(rtas, "ibm,hypertas-functions");
1665 if (x != PROM_ERROR) {
1666 prom_debug("Hypertas detected, assuming LPAR !\n");
1667 return PLATFORM_PSERIES_LPAR;
1669 return PLATFORM_PSERIES;
1671 return PLATFORM_GENERIC;
1675 static int __init prom_set_color(ihandle ih, int i, int r, int g, int b)
1677 return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r);
1681 * If we have a display that we don't know how to drive,
1682 * we will want to try to execute OF's open method for it
1683 * later. However, OF will probably fall over if we do that
1684 * we've taken over the MMU.
1685 * So we check whether we will need to open the display,
1686 * and if so, open it now.
1688 static void __init prom_check_displays(void)
1690 char type[16], *path;
1695 static unsigned char default_colors[] = {
1713 const unsigned char *clut;
1715 prom_debug("Looking for displays\n");
1716 for (node = 0; prom_next_node(&node); ) {
1717 memset(type, 0, sizeof(type));
1718 prom_getprop(node, "device_type", type, sizeof(type));
1719 if (strcmp(type, RELOC("display")) != 0)
1722 /* It seems OF doesn't null-terminate the path :-( */
1723 path = RELOC(prom_scratch);
1724 memset(path, 0, PROM_SCRATCH_SIZE);
1727 * leave some room at the end of the path for appending extra
1730 if (call_prom("package-to-path", 3, 1, node, path,
1731 PROM_SCRATCH_SIZE-10) == PROM_ERROR)
1733 prom_printf("found display : %s, opening... ", path);
1735 ih = call_prom("open", 1, 1, path);
1737 prom_printf("failed\n");
1742 prom_printf("done\n");
1743 prom_setprop(node, path, "linux,opened", NULL, 0);
1745 /* Setup a usable color table when the appropriate
1746 * method is available. Should update this to set-colors */
1747 clut = RELOC(default_colors);
1748 for (i = 0; i < 32; i++, clut += 3)
1749 if (prom_set_color(ih, i, clut[0], clut[1],
1753 #ifdef CONFIG_LOGO_LINUX_CLUT224
1754 clut = PTRRELOC(RELOC(logo_linux_clut224.clut));
1755 for (i = 0; i < RELOC(logo_linux_clut224.clutsize); i++, clut += 3)
1756 if (prom_set_color(ih, i + 32, clut[0], clut[1],
1759 #endif /* CONFIG_LOGO_LINUX_CLUT224 */
1764 /* Return (relocated) pointer to this much memory: moves initrd if reqd. */
1765 static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end,
1766 unsigned long needed, unsigned long align)
1770 *mem_start = _ALIGN(*mem_start, align);
1771 while ((*mem_start + needed) > *mem_end) {
1772 unsigned long room, chunk;
1774 prom_debug("Chunk exhausted, claiming more at %x...\n",
1775 RELOC(alloc_bottom));
1776 room = RELOC(alloc_top) - RELOC(alloc_bottom);
1777 if (room > DEVTREE_CHUNK_SIZE)
1778 room = DEVTREE_CHUNK_SIZE;
1779 if (room < PAGE_SIZE)
1780 prom_panic("No memory for flatten_device_tree (no room)");
1781 chunk = alloc_up(room, 0);
1783 prom_panic("No memory for flatten_device_tree (claim failed)");
1784 *mem_end = RELOC(alloc_top);
1787 ret = (void *)*mem_start;
1788 *mem_start += needed;
1793 #define dt_push_token(token, mem_start, mem_end) \
1794 do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0)
1796 static unsigned long __init dt_find_string(char *str)
1800 s = os = (char *)RELOC(dt_string_start);
1802 while (s < (char *)RELOC(dt_string_end)) {
1803 if (strcmp(s, str) == 0)
1811 * The Open Firmware 1275 specification states properties must be 31 bytes or
1812 * less, however not all firmwares obey this. Make it 64 bytes to be safe.
1814 #define MAX_PROPERTY_NAME 64
1816 static void __init scan_dt_build_strings(phandle node,
1817 unsigned long *mem_start,
1818 unsigned long *mem_end)
1820 char *prev_name, *namep, *sstart;
1824 sstart = (char *)RELOC(dt_string_start);
1826 /* get and store all property names */
1827 prev_name = RELOC("");
1829 /* 64 is max len of name including nul. */
1830 namep = make_room(mem_start, mem_end, MAX_PROPERTY_NAME, 1);
1831 if (call_prom("nextprop", 3, 1, node, prev_name, namep) != 1) {
1832 /* No more nodes: unwind alloc */
1833 *mem_start = (unsigned long)namep;
1838 if (strcmp(namep, RELOC("name")) == 0) {
1839 *mem_start = (unsigned long)namep;
1840 prev_name = RELOC("name");
1843 /* get/create string entry */
1844 soff = dt_find_string(namep);
1846 *mem_start = (unsigned long)namep;
1847 namep = sstart + soff;
1849 /* Trim off some if we can */
1850 *mem_start = (unsigned long)namep + strlen(namep) + 1;
1851 RELOC(dt_string_end) = *mem_start;
1856 /* do all our children */
1857 child = call_prom("child", 1, 1, node);
1858 while (child != 0) {
1859 scan_dt_build_strings(child, mem_start, mem_end);
1860 child = call_prom("peer", 1, 1, child);
1864 static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,
1865 unsigned long *mem_end)
1868 char *namep, *prev_name, *sstart, *p, *ep, *lp, *path;
1870 unsigned char *valp;
1871 static char pname[MAX_PROPERTY_NAME];
1874 dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end);
1876 /* get the node's full name */
1877 namep = (char *)*mem_start;
1878 room = *mem_end - *mem_start;
1881 l = call_prom("package-to-path", 3, 1, node, namep, room);
1883 /* Didn't fit? Get more room. */
1885 if (l >= *mem_end - *mem_start)
1886 namep = make_room(mem_start, mem_end, l+1, 1);
1887 call_prom("package-to-path", 3, 1, node, namep, l);
1891 /* Fixup an Apple bug where they have bogus \0 chars in the
1892 * middle of the path in some properties, and extract
1893 * the unit name (everything after the last '/').
1895 for (lp = p = namep, ep = namep + l; p < ep; p++) {
1902 *mem_start = _ALIGN((unsigned long)lp + 1, 4);
1905 /* get it again for debugging */
1906 path = RELOC(prom_scratch);
1907 memset(path, 0, PROM_SCRATCH_SIZE);
1908 call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
1910 /* get and store all properties */
1911 prev_name = RELOC("");
1912 sstart = (char *)RELOC(dt_string_start);
1914 if (call_prom("nextprop", 3, 1, node, prev_name,
1919 if (strcmp(RELOC(pname), RELOC("name")) == 0) {
1920 prev_name = RELOC("name");
1924 /* find string offset */
1925 soff = dt_find_string(RELOC(pname));
1927 prom_printf("WARNING: Can't find string index for"
1928 " <%s>, node %s\n", RELOC(pname), path);
1931 prev_name = sstart + soff;
1934 l = call_prom("getproplen", 2, 1, node, RELOC(pname));
1937 if (l == PROM_ERROR)
1939 if (l > MAX_PROPERTY_LENGTH) {
1940 prom_printf("WARNING: ignoring large property ");
1941 /* It seems OF doesn't null-terminate the path :-( */
1942 prom_printf("[%s] ", path);
1943 prom_printf("%s length 0x%x\n", RELOC(pname), l);
1947 /* push property head */
1948 dt_push_token(OF_DT_PROP, mem_start, mem_end);
1949 dt_push_token(l, mem_start, mem_end);
1950 dt_push_token(soff, mem_start, mem_end);
1952 /* push property content */
1953 valp = make_room(mem_start, mem_end, l, 4);
1954 call_prom("getprop", 4, 1, node, RELOC(pname), valp, l);
1955 *mem_start = _ALIGN(*mem_start, 4);
1958 /* Add a "linux,phandle" property. */
1959 soff = dt_find_string(RELOC("linux,phandle"));
1961 prom_printf("WARNING: Can't find string index for"
1962 " <linux-phandle> node %s\n", path);
1964 dt_push_token(OF_DT_PROP, mem_start, mem_end);
1965 dt_push_token(4, mem_start, mem_end);
1966 dt_push_token(soff, mem_start, mem_end);
1967 valp = make_room(mem_start, mem_end, 4, 4);
1968 *(u32 *)valp = node;
1971 /* do all our children */
1972 child = call_prom("child", 1, 1, node);
1973 while (child != 0) {
1974 scan_dt_build_struct(child, mem_start, mem_end);
1975 child = call_prom("peer", 1, 1, child);
1978 dt_push_token(OF_DT_END_NODE, mem_start, mem_end);
1981 static void __init flatten_device_tree(void)
1984 unsigned long mem_start, mem_end, room;
1985 struct boot_param_header *hdr;
1986 struct prom_t *_prom = &RELOC(prom);
1991 * Check how much room we have between alloc top & bottom (+/- a
1992 * few pages), crop to 4Mb, as this is our "chuck" size
1994 room = RELOC(alloc_top) - RELOC(alloc_bottom) - 0x4000;
1995 if (room > DEVTREE_CHUNK_SIZE)
1996 room = DEVTREE_CHUNK_SIZE;
1997 prom_debug("starting device tree allocs at %x\n", RELOC(alloc_bottom));
1999 /* Now try to claim that */
2000 mem_start = (unsigned long)alloc_up(room, PAGE_SIZE);
2002 prom_panic("Can't allocate initial device-tree chunk\n");
2003 mem_end = RELOC(alloc_top);
2005 /* Get root of tree */
2006 root = call_prom("peer", 1, 1, (phandle)0);
2007 if (root == (phandle)0)
2008 prom_panic ("couldn't get device tree root\n");
2010 /* Build header and make room for mem rsv map */
2011 mem_start = _ALIGN(mem_start, 4);
2012 hdr = make_room(&mem_start, &mem_end,
2013 sizeof(struct boot_param_header), 4);
2014 RELOC(dt_header_start) = (unsigned long)hdr;
2015 rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8);
2017 /* Start of strings */
2018 mem_start = PAGE_ALIGN(mem_start);
2019 RELOC(dt_string_start) = mem_start;
2020 mem_start += 4; /* hole */
2022 /* Add "linux,phandle" in there, we'll need it */
2023 namep = make_room(&mem_start, &mem_end, 16, 1);
2024 strcpy(namep, RELOC("linux,phandle"));
2025 mem_start = (unsigned long)namep + strlen(namep) + 1;
2027 /* Build string array */
2028 prom_printf("Building dt strings...\n");
2029 scan_dt_build_strings(root, &mem_start, &mem_end);
2030 RELOC(dt_string_end) = mem_start;
2032 /* Build structure */
2033 mem_start = PAGE_ALIGN(mem_start);
2034 RELOC(dt_struct_start) = mem_start;
2035 prom_printf("Building dt structure...\n");
2036 scan_dt_build_struct(root, &mem_start, &mem_end);
2037 dt_push_token(OF_DT_END, &mem_start, &mem_end);
2038 RELOC(dt_struct_end) = PAGE_ALIGN(mem_start);
2041 hdr->boot_cpuid_phys = _prom->cpu;
2042 hdr->magic = OF_DT_HEADER;
2043 hdr->totalsize = RELOC(dt_struct_end) - RELOC(dt_header_start);
2044 hdr->off_dt_struct = RELOC(dt_struct_start) - RELOC(dt_header_start);
2045 hdr->off_dt_strings = RELOC(dt_string_start) - RELOC(dt_header_start);
2046 hdr->dt_strings_size = RELOC(dt_string_end) - RELOC(dt_string_start);
2047 hdr->off_mem_rsvmap = ((unsigned long)rsvmap) - RELOC(dt_header_start);
2048 hdr->version = OF_DT_VERSION;
2049 /* Version 16 is not backward compatible */
2050 hdr->last_comp_version = 0x10;
2052 /* Copy the reserve map in */
2053 memcpy(rsvmap, RELOC(mem_reserve_map), sizeof(mem_reserve_map));
2058 prom_printf("reserved memory map:\n");
2059 for (i = 0; i < RELOC(mem_reserve_cnt); i++)
2060 prom_printf(" %x - %x\n",
2061 RELOC(mem_reserve_map)[i].base,
2062 RELOC(mem_reserve_map)[i].size);
2065 /* Bump mem_reserve_cnt to cause further reservations to fail
2066 * since it's too late.
2068 RELOC(mem_reserve_cnt) = MEM_RESERVE_MAP_SIZE;
2070 prom_printf("Device tree strings 0x%x -> 0x%x\n",
2071 RELOC(dt_string_start), RELOC(dt_string_end));
2072 prom_printf("Device tree struct 0x%x -> 0x%x\n",
2073 RELOC(dt_struct_start), RELOC(dt_struct_end));
2077 #ifdef CONFIG_PPC_MAPLE
2078 /* PIBS Version 1.05.0000 04/26/2005 has an incorrect /ht/isa/ranges property.
2079 * The values are bad, and it doesn't even have the right number of cells. */
2080 static void __init fixup_device_tree_maple(void)
2083 u32 rloc = 0x01002000; /* IO space; PCI device = 4 */
2087 name = "/ht@0/isa@4";
2088 isa = call_prom("finddevice", 1, 1, ADDR(name));
2089 if (!PHANDLE_VALID(isa)) {
2090 name = "/ht@0/isa@6";
2091 isa = call_prom("finddevice", 1, 1, ADDR(name));
2092 rloc = 0x01003000; /* IO space; PCI device = 6 */
2094 if (!PHANDLE_VALID(isa))
2097 if (prom_getproplen(isa, "ranges") != 12)
2099 if (prom_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges))
2103 if (isa_ranges[0] != 0x1 ||
2104 isa_ranges[1] != 0xf4000000 ||
2105 isa_ranges[2] != 0x00010000)
2108 prom_printf("Fixing up bogus ISA range on Maple/Apache...\n");
2110 isa_ranges[0] = 0x1;
2111 isa_ranges[1] = 0x0;
2112 isa_ranges[2] = rloc;
2113 isa_ranges[3] = 0x0;
2114 isa_ranges[4] = 0x0;
2115 isa_ranges[5] = 0x00010000;
2116 prom_setprop(isa, name, "ranges",
2117 isa_ranges, sizeof(isa_ranges));
2120 #define CPC925_MC_START 0xf8000000
2121 #define CPC925_MC_LENGTH 0x1000000
2122 /* The values for memory-controller don't have right number of cells */
2123 static void __init fixup_device_tree_maple_memory_controller(void)
2127 char *name = "/hostbridge@f8000000";
2128 struct prom_t *_prom = &RELOC(prom);
2131 mc = call_prom("finddevice", 1, 1, ADDR(name));
2132 if (!PHANDLE_VALID(mc))
2135 if (prom_getproplen(mc, "reg") != 8)
2138 prom_getprop(_prom->root, "#address-cells", &ac, sizeof(ac));
2139 prom_getprop(_prom->root, "#size-cells", &sc, sizeof(sc));
2140 if ((ac != 2) || (sc != 2))
2143 if (prom_getprop(mc, "reg", mc_reg, sizeof(mc_reg)) == PROM_ERROR)
2146 if (mc_reg[0] != CPC925_MC_START || mc_reg[1] != CPC925_MC_LENGTH)
2149 prom_printf("Fixing up bogus hostbridge on Maple...\n");
2152 mc_reg[1] = CPC925_MC_START;
2154 mc_reg[3] = CPC925_MC_LENGTH;
2155 prom_setprop(mc, name, "reg", mc_reg, sizeof(mc_reg));
2158 #define fixup_device_tree_maple()
2159 #define fixup_device_tree_maple_memory_controller()
2162 #ifdef CONFIG_PPC_CHRP
2164 * Pegasos and BriQ lacks the "ranges" property in the isa node
2165 * Pegasos needs decimal IRQ 14/15, not hexadecimal
2166 * Pegasos has the IDE configured in legacy mode, but advertised as native
2168 static void __init fixup_device_tree_chrp(void)
2172 u32 rloc = 0x01006000; /* IO space; PCI device = 12 */
2176 name = "/pci@80000000/isa@c";
2177 ph = call_prom("finddevice", 1, 1, ADDR(name));
2178 if (!PHANDLE_VALID(ph)) {
2179 name = "/pci@ff500000/isa@6";
2180 ph = call_prom("finddevice", 1, 1, ADDR(name));
2181 rloc = 0x01003000; /* IO space; PCI device = 6 */
2183 if (PHANDLE_VALID(ph)) {
2184 rc = prom_getproplen(ph, "ranges");
2185 if (rc == 0 || rc == PROM_ERROR) {
2186 prom_printf("Fixing up missing ISA range on Pegasos...\n");
2193 prop[5] = 0x00010000;
2194 prom_setprop(ph, name, "ranges", prop, sizeof(prop));
2198 name = "/pci@80000000/ide@C,1";
2199 ph = call_prom("finddevice", 1, 1, ADDR(name));
2200 if (PHANDLE_VALID(ph)) {
2201 prom_printf("Fixing up IDE interrupt on Pegasos...\n");
2204 prom_setprop(ph, name, "interrupts", prop, 2*sizeof(u32));
2205 prom_printf("Fixing up IDE class-code on Pegasos...\n");
2206 rc = prom_getprop(ph, "class-code", prop, sizeof(u32));
2207 if (rc == sizeof(u32)) {
2209 prom_setprop(ph, name, "class-code", prop, sizeof(u32));
2214 #define fixup_device_tree_chrp()
2217 #if defined(CONFIG_PPC64) && defined(CONFIG_PPC_PMAC)
2218 static void __init fixup_device_tree_pmac(void)
2220 phandle u3, i2c, mpic;
2225 /* Some G5s have a missing interrupt definition, fix it up here */
2226 u3 = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000"));
2227 if (!PHANDLE_VALID(u3))
2229 i2c = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/i2c@f8001000"));
2230 if (!PHANDLE_VALID(i2c))
2232 mpic = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/mpic@f8040000"));
2233 if (!PHANDLE_VALID(mpic))
2236 /* check if proper rev of u3 */
2237 if (prom_getprop(u3, "device-rev", &u3_rev, sizeof(u3_rev))
2240 if (u3_rev < 0x35 || u3_rev > 0x39)
2242 /* does it need fixup ? */
2243 if (prom_getproplen(i2c, "interrupts") > 0)
2246 prom_printf("fixing up bogus interrupts for u3 i2c...\n");
2248 /* interrupt on this revision of u3 is number 0 and level */
2251 prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupts",
2252 &interrupts, sizeof(interrupts));
2254 prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupt-parent",
2255 &parent, sizeof(parent));
2258 #define fixup_device_tree_pmac()
2261 #ifdef CONFIG_PPC_EFIKA
2263 * The MPC5200 FEC driver requires an phy-handle property to tell it how
2264 * to talk to the phy. If the phy-handle property is missing, then this
2265 * function is called to add the appropriate nodes and link it to the
2268 static void __init fixup_device_tree_efika_add_phy(void)
2274 /* Check if /builtin/ethernet exists - bail if it doesn't */
2275 node = call_prom("finddevice", 1, 1, ADDR("/builtin/ethernet"));
2276 if (!PHANDLE_VALID(node))
2279 /* Check if the phy-handle property exists - bail if it does */
2280 rv = prom_getprop(node, "phy-handle", prop, sizeof(prop));
2285 * At this point the ethernet device doesn't have a phy described.
2286 * Now we need to add the missing phy node and linkage
2289 /* Check for an MDIO bus node - if missing then create one */
2290 node = call_prom("finddevice", 1, 1, ADDR("/builtin/mdio"));
2291 if (!PHANDLE_VALID(node)) {
2292 prom_printf("Adding Ethernet MDIO node\n");
2293 call_prom("interpret", 1, 1,
2294 " s\" /builtin\" find-device"
2296 " 1 encode-int s\" #address-cells\" property"
2297 " 0 encode-int s\" #size-cells\" property"
2298 " s\" mdio\" device-name"
2299 " s\" fsl,mpc5200b-mdio\" encode-string"
2300 " s\" compatible\" property"
2301 " 0xf0003000 0x400 reg"
2303 " 0x5 encode-int encode+"
2304 " 0x3 encode-int encode+"
2305 " s\" interrupts\" property"
2309 /* Check for a PHY device node - if missing then create one and
2310 * give it's phandle to the ethernet node */
2311 node = call_prom("finddevice", 1, 1,
2312 ADDR("/builtin/mdio/ethernet-phy"));
2313 if (!PHANDLE_VALID(node)) {
2314 prom_printf("Adding Ethernet PHY node\n");
2315 call_prom("interpret", 1, 1,
2316 " s\" /builtin/mdio\" find-device"
2318 " s\" ethernet-phy\" device-name"
2319 " 0x10 encode-int s\" reg\" property"
2323 " s\" /builtin/ethernet\" find-device"
2325 " s\" phy-handle\" property"
2330 static void __init fixup_device_tree_efika(void)
2332 int sound_irq[3] = { 2, 2, 0 };
2333 int bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0,
2334 3,4,0, 3,5,0, 3,6,0, 3,7,0,
2335 3,8,0, 3,9,0, 3,10,0, 3,11,0,
2336 3,12,0, 3,13,0, 3,14,0, 3,15,0 };
2341 /* Check if we're really running on a EFIKA */
2342 node = call_prom("finddevice", 1, 1, ADDR("/"));
2343 if (!PHANDLE_VALID(node))
2346 rv = prom_getprop(node, "model", prop, sizeof(prop));
2347 if (rv == PROM_ERROR)
2349 if (strcmp(prop, "EFIKA5K2"))
2352 prom_printf("Applying EFIKA device tree fixups\n");
2354 /* Claiming to be 'chrp' is death */
2355 node = call_prom("finddevice", 1, 1, ADDR("/"));
2356 rv = prom_getprop(node, "device_type", prop, sizeof(prop));
2357 if (rv != PROM_ERROR && (strcmp(prop, "chrp") == 0))
2358 prom_setprop(node, "/", "device_type", "efika", sizeof("efika"));
2360 /* CODEGEN,description is exposed in /proc/cpuinfo so
2362 rv = prom_getprop(node, "CODEGEN,description", prop, sizeof(prop));
2363 if (rv != PROM_ERROR && (strstr(prop, "CHRP")))
2364 prom_setprop(node, "/", "CODEGEN,description",
2365 "Efika 5200B PowerPC System",
2366 sizeof("Efika 5200B PowerPC System"));
2368 /* Fixup bestcomm interrupts property */
2369 node = call_prom("finddevice", 1, 1, ADDR("/builtin/bestcomm"));
2370 if (PHANDLE_VALID(node)) {
2371 len = prom_getproplen(node, "interrupts");
2373 prom_printf("Fixing bestcomm interrupts property\n");
2374 prom_setprop(node, "/builtin/bestcom", "interrupts",
2375 bcomm_irq, sizeof(bcomm_irq));
2379 /* Fixup sound interrupts property */
2380 node = call_prom("finddevice", 1, 1, ADDR("/builtin/sound"));
2381 if (PHANDLE_VALID(node)) {
2382 rv = prom_getprop(node, "interrupts", prop, sizeof(prop));
2383 if (rv == PROM_ERROR) {
2384 prom_printf("Adding sound interrupts property\n");
2385 prom_setprop(node, "/builtin/sound", "interrupts",
2386 sound_irq, sizeof(sound_irq));
2390 /* Make sure ethernet phy-handle property exists */
2391 fixup_device_tree_efika_add_phy();
2394 #define fixup_device_tree_efika()
2397 static void __init fixup_device_tree(void)
2399 fixup_device_tree_maple();
2400 fixup_device_tree_maple_memory_controller();
2401 fixup_device_tree_chrp();
2402 fixup_device_tree_pmac();
2403 fixup_device_tree_efika();
2406 static void __init prom_find_boot_cpu(void)
2408 struct prom_t *_prom = &RELOC(prom);
2414 if (prom_getprop(_prom->chosen, "cpu", &prom_cpu, sizeof(prom_cpu)) <= 0)
2417 cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu);
2419 prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval));
2420 _prom->cpu = getprop_rval;
2422 prom_debug("Booting CPU hw index = 0x%x\n", _prom->cpu);
2425 static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
2427 #ifdef CONFIG_BLK_DEV_INITRD
2428 struct prom_t *_prom = &RELOC(prom);
2430 if (r3 && r4 && r4 != 0xdeadbeef) {
2433 RELOC(prom_initrd_start) = is_kernel_addr(r3) ? __pa(r3) : r3;
2434 RELOC(prom_initrd_end) = RELOC(prom_initrd_start) + r4;
2436 val = RELOC(prom_initrd_start);
2437 prom_setprop(_prom->chosen, "/chosen", "linux,initrd-start",
2439 val = RELOC(prom_initrd_end);
2440 prom_setprop(_prom->chosen, "/chosen", "linux,initrd-end",
2443 reserve_mem(RELOC(prom_initrd_start),
2444 RELOC(prom_initrd_end) - RELOC(prom_initrd_start));
2446 prom_debug("initrd_start=0x%x\n", RELOC(prom_initrd_start));
2447 prom_debug("initrd_end=0x%x\n", RELOC(prom_initrd_end));
2449 #endif /* CONFIG_BLK_DEV_INITRD */
2453 * We enter here early on, when the Open Firmware prom is still
2454 * handling exceptions and the MMU hash table for us.
2457 unsigned long __init prom_init(unsigned long r3, unsigned long r4,
2459 unsigned long r6, unsigned long r7,
2460 unsigned long kbase)
2462 struct prom_t *_prom;
2466 unsigned long offset = reloc_offset();
2470 _prom = &RELOC(prom);
2473 * First zero the BSS
2475 memset(&RELOC(__bss_start), 0, __bss_stop - __bss_start);
2478 * Init interface to Open Firmware, get some node references,
2481 prom_init_client_services(pp);
2484 * See if this OF is old enough that we need to do explicit maps
2485 * and other workarounds
2490 * Init prom stdout device
2494 prom_printf("Preparing to boot %s", RELOC(linux_banner));
2497 * Get default machine type. At this point, we do not differentiate
2498 * between pSeries SMP and pSeries LPAR
2500 RELOC(of_platform) = prom_find_machine_type();
2502 #ifndef CONFIG_RELOCATABLE
2503 /* Bail if this is a kdump kernel. */
2504 if (PHYSICAL_START > 0)
2505 prom_panic("Error: You can't boot a kdump kernel from OF!\n");
2509 * Check for an initrd
2511 prom_check_initrd(r3, r4);
2513 #ifdef CONFIG_PPC_PSERIES
2515 * On pSeries, inform the firmware about our capabilities
2517 if (RELOC(of_platform) == PLATFORM_PSERIES ||
2518 RELOC(of_platform) == PLATFORM_PSERIES_LPAR)
2519 prom_send_capabilities();
2523 * Copy the CPU hold code
2525 if (RELOC(of_platform) != PLATFORM_POWERMAC)
2526 copy_and_flush(0, kbase, 0x100, 0);
2529 * Do early parsing of command line
2531 early_cmdline_parse();
2534 * Initialize memory management within prom_init
2539 * Determine which cpu is actually running right _now_
2541 prom_find_boot_cpu();
2544 * Initialize display devices
2546 prom_check_displays();
2550 * Initialize IOMMU (TCE tables) on pSeries. Do that before anything else
2551 * that uses the allocator, we need to make sure we get the top of memory
2552 * available for us here...
2554 if (RELOC(of_platform) == PLATFORM_PSERIES)
2555 prom_initialize_tce_table();
2559 * On non-powermacs, try to instantiate RTAS and puts all CPUs
2560 * in spin-loops. PowerMacs don't have a working RTAS and use
2561 * a different way to spin CPUs
2563 if (RELOC(of_platform) != PLATFORM_POWERMAC) {
2564 prom_instantiate_rtas();
2569 * Fill in some infos for use by the kernel later on
2571 if (RELOC(prom_memory_limit))
2572 prom_setprop(_prom->chosen, "/chosen", "linux,memory-limit",
2573 &RELOC(prom_memory_limit),
2574 sizeof(prom_memory_limit));
2576 if (RELOC(prom_iommu_off))
2577 prom_setprop(_prom->chosen, "/chosen", "linux,iommu-off",
2580 if (RELOC(prom_iommu_force_on))
2581 prom_setprop(_prom->chosen, "/chosen", "linux,iommu-force-on",
2584 if (RELOC(prom_tce_alloc_start)) {
2585 prom_setprop(_prom->chosen, "/chosen", "linux,tce-alloc-start",
2586 &RELOC(prom_tce_alloc_start),
2587 sizeof(prom_tce_alloc_start));
2588 prom_setprop(_prom->chosen, "/chosen", "linux,tce-alloc-end",
2589 &RELOC(prom_tce_alloc_end),
2590 sizeof(prom_tce_alloc_end));
2595 * Fixup any known bugs in the device-tree
2597 fixup_device_tree();
2600 * Now finally create the flattened device-tree
2602 prom_printf("copying OF device tree...\n");
2603 flatten_device_tree();
2606 * in case stdin is USB and still active on IBM machines...
2607 * Unfortunately quiesce crashes on some powermacs if we have
2608 * closed stdin already (in particular the powerbook 101).
2610 if (RELOC(of_platform) != PLATFORM_POWERMAC)
2614 * Call OF "quiesce" method to shut down pending DMA's from
2617 prom_printf("Calling quiesce...\n");
2618 call_prom("quiesce", 0, 0);
2621 * And finally, call the kernel passing it the flattened device
2622 * tree and NULL as r5, thus triggering the new entry point which
2623 * is common to us and kexec
2625 hdr = RELOC(dt_header_start);
2626 prom_printf("returning from prom_init\n");
2627 prom_debug("->dt_header_start=0x%x\n", hdr);
2630 reloc_got2(-offset);
2633 __start(hdr, kbase, 0);