4 * Procedures for interfacing to Open Firmware.
6 * Paul Mackerras August 1996.
7 * Copyright (C) 1996 Paul Mackerras.
9 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
10 * {engebret|bergner}@us.ibm.com
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
21 #include <linux/config.h>
22 #include <linux/kernel.h>
23 #include <linux/string.h>
24 #include <linux/init.h>
25 #include <linux/version.h>
26 #include <linux/threads.h>
27 #include <linux/spinlock.h>
28 #include <linux/types.h>
29 #include <linux/pci.h>
30 #include <linux/proc_fs.h>
31 #include <linux/stringify.h>
32 #include <linux/delay.h>
33 #include <linux/initrd.h>
34 #include <linux/bitops.h>
37 #include <asm/abs_addr.h>
39 #include <asm/processor.h>
43 #include <asm/system.h>
45 #include <asm/pgtable.h>
47 #include <asm/iommu.h>
48 #include <asm/bootinfo.h>
49 #include <asm/ppcdebug.h>
50 #include <asm/btext.h>
51 #include <asm/sections.h>
52 #include <asm/machdep.h>
54 #ifdef CONFIG_LOGO_LINUX_CLUT224
55 #include <linux/linux_logo.h>
56 extern const struct linux_logo logo_linux_clut224;
60 * Properties whose value is longer than this get excluded from our
61 * copy of the device tree. This value does need to be big enough to
62 * ensure that we don't lose things like the interrupt-map property
63 * on a PCI-PCI bridge.
65 #define MAX_PROPERTY_LENGTH (1UL * 1024 * 1024)
68 * Eventually bump that one up
70 #define DEVTREE_CHUNK_SIZE 0x100000
73 * This is the size of the local memory reserve map that gets copied
74 * into the boot params passed to the kernel. That size is totally
75 * flexible as the kernel just reads the list until it encounters an
76 * entry with size 0, so it can be changed without breaking binary
79 #define MEM_RESERVE_MAP_SIZE 8
82 * prom_init() is called very early on, before the kernel text
83 * and data have been mapped to KERNELBASE. At this point the code
84 * is running at whatever address it has been loaded at, so
85 * references to extern and static variables must be relocated
86 * explicitly. The procedure reloc_offset() returns the address
87 * we're currently running at minus the address we were linked at.
88 * (Note that strings count as static variables.)
90 * Because OF may have mapped I/O devices into the area starting at
91 * KERNELBASE, particularly on CHRP machines, we can't safely call
92 * OF once the kernel has been mapped to KERNELBASE. Therefore all
93 * OF calls should be done within prom_init(), and prom_init()
94 * and all routines called within it must be careful to relocate
95 * references as necessary.
97 * Note that the bss is cleared *after* prom_init runs, so we have
98 * to make sure that any static or extern variables it accesses
99 * are put in the data segment.
103 #define PROM_BUG() do { \
104 prom_printf("kernel BUG at %s line 0x%x!\n", \
105 RELOC(__FILE__), __LINE__); \
106 __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \
110 #define prom_debug(x...) prom_printf(x)
112 #define prom_debug(x...)
116 typedef u32 prom_arg_t;
123 prom_arg_t *rets; /* Pointer to return values in args[16]. */
133 struct prom_args args;
134 unsigned long version;
135 unsigned long root_size_cells;
136 unsigned long root_addr_cells;
139 struct pci_reg_property {
140 struct pci_address addr;
145 struct mem_map_entry {
152 extern void __start(unsigned long r3, unsigned long r4, unsigned long r5);
154 extern unsigned long reloc_offset(void);
155 extern void enter_prom(struct prom_args *args, unsigned long entry);
156 extern void copy_and_flush(unsigned long dest, unsigned long src,
157 unsigned long size, unsigned long offset);
159 extern unsigned long klimit;
162 static struct prom_t __initdata prom;
164 #define PROM_SCRATCH_SIZE 256
166 static char __initdata of_stdout_device[256];
167 static char __initdata prom_scratch[PROM_SCRATCH_SIZE];
169 static unsigned long __initdata dt_header_start;
170 static unsigned long __initdata dt_struct_start, dt_struct_end;
171 static unsigned long __initdata dt_string_start, dt_string_end;
173 static unsigned long __initdata prom_initrd_start, prom_initrd_end;
175 static int __initdata iommu_force_on;
176 static int __initdata ppc64_iommu_off;
177 static int __initdata of_platform;
179 static char __initdata prom_cmd_line[COMMAND_LINE_SIZE];
181 static unsigned long __initdata alloc_top;
182 static unsigned long __initdata alloc_top_high;
183 static unsigned long __initdata alloc_bottom;
184 static unsigned long __initdata rmo_top;
185 static unsigned long __initdata ram_top;
187 static struct mem_map_entry __initdata mem_reserve_map[MEM_RESERVE_MAP_SIZE];
188 static int __initdata mem_reserve_cnt;
190 static cell_t __initdata regbuf[1024];
193 #define MAX_CPU_THREADS 2
199 unsigned int threadid;
200 } hmt_thread_data[NR_CPUS];
201 #endif /* CONFIG_HMT */
204 * This are used in calls to call_prom. The 4th and following
205 * arguments to call_prom should be 32-bit values. 64 bit values
206 * are truncated to 32 bits (and fortunately don't get interpreted
209 #define ADDR(x) (u32) ((unsigned long)(x) - offset)
211 /* This is the one and *ONLY* place where we actually call open
212 * firmware from, since we need to make sure we're running in 32b
213 * mode when we do. We switch back to 64b mode upon return.
216 #define PROM_ERROR (-1)
218 static int __init call_prom(const char *service, int nargs, int nret, ...)
221 unsigned long offset = reloc_offset();
222 struct prom_t *_prom = PTRRELOC(&prom);
225 _prom->args.service = ADDR(service);
226 _prom->args.nargs = nargs;
227 _prom->args.nret = nret;
228 _prom->args.rets = (prom_arg_t *)&(_prom->args.args[nargs]);
230 va_start(list, nret);
231 for (i=0; i < nargs; i++)
232 _prom->args.args[i] = va_arg(list, prom_arg_t);
235 for (i=0; i < nret ;i++)
236 _prom->args.rets[i] = 0;
238 enter_prom(&_prom->args, _prom->entry);
240 return (nret > 0) ? _prom->args.rets[0] : 0;
244 static unsigned int __init prom_claim(unsigned long virt, unsigned long size,
247 return (unsigned int)call_prom("claim", 3, 1,
248 (prom_arg_t)virt, (prom_arg_t)size,
252 static void __init prom_print(const char *msg)
255 unsigned long offset = reloc_offset();
256 struct prom_t *_prom = PTRRELOC(&prom);
258 if (_prom->stdout == 0)
261 for (p = msg; *p != 0; p = q) {
262 for (q = p; *q != 0 && *q != '\n'; ++q)
265 call_prom("write", 3, 1, _prom->stdout, p, q - p);
269 call_prom("write", 3, 1, _prom->stdout, ADDR("\r\n"), 2);
274 static void __init prom_print_hex(unsigned long val)
276 unsigned long offset = reloc_offset();
277 int i, nibbles = sizeof(val)*2;
278 char buf[sizeof(val)*2+1];
279 struct prom_t *_prom = PTRRELOC(&prom);
281 for (i = nibbles-1; i >= 0; i--) {
282 buf[i] = (val & 0xf) + '0';
284 buf[i] += ('a'-'0'-10);
288 call_prom("write", 3, 1, _prom->stdout, buf, nibbles);
292 static void __init prom_printf(const char *format, ...)
294 unsigned long offset = reloc_offset();
295 const char *p, *q, *s;
298 struct prom_t *_prom = PTRRELOC(&prom);
300 va_start(args, format);
301 for (p = PTRRELOC(format); *p != 0; p = q) {
302 for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q)
305 call_prom("write", 3, 1, _prom->stdout, p, q - p);
310 call_prom("write", 3, 1, _prom->stdout,
320 s = va_arg(args, const char *);
325 v = va_arg(args, unsigned long);
333 static void __init __attribute__((noreturn)) prom_panic(const char *reason)
335 unsigned long offset = reloc_offset();
337 prom_print(PTRRELOC(reason));
338 /* ToDo: should put up an SRC here */
339 call_prom("exit", 0, 0);
341 for (;;) /* should never get here */
346 static int __init prom_next_node(phandle *nodep)
350 if ((node = *nodep) != 0
351 && (*nodep = call_prom("child", 1, 1, node)) != 0)
353 if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
356 if ((node = call_prom("parent", 1, 1, node)) == 0)
358 if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
363 static int __init prom_getprop(phandle node, const char *pname,
364 void *value, size_t valuelen)
366 unsigned long offset = reloc_offset();
368 return call_prom("getprop", 4, 1, node, ADDR(pname),
369 (u32)(unsigned long) value, (u32) valuelen);
372 static int __init prom_getproplen(phandle node, const char *pname)
374 unsigned long offset = reloc_offset();
376 return call_prom("getproplen", 2, 1, node, ADDR(pname));
379 static int __init prom_setprop(phandle node, const char *pname,
380 void *value, size_t valuelen)
382 unsigned long offset = reloc_offset();
384 return call_prom("setprop", 4, 1, node, ADDR(pname),
385 (u32)(unsigned long) value, (u32) valuelen);
390 * Early parsing of the command line passed to the kernel, used for
391 * the options that affect the iommu
393 static void __init early_cmdline_parse(void)
395 unsigned long offset = reloc_offset();
396 struct prom_t *_prom = PTRRELOC(&prom);
400 RELOC(prom_cmd_line[0]) = 0;
401 p = RELOC(prom_cmd_line);
402 if ((long)_prom->chosen > 0)
403 l = prom_getprop(_prom->chosen, "bootargs", p, COMMAND_LINE_SIZE-1);
404 #ifdef CONFIG_CMDLINE
405 if (l == 0) /* dbl check */
406 strlcpy(RELOC(prom_cmd_line),
407 RELOC(CONFIG_CMDLINE), sizeof(prom_cmd_line));
408 #endif /* CONFIG_CMDLINE */
409 prom_printf("command line: %s\n", RELOC(prom_cmd_line));
411 opt = strstr(RELOC(prom_cmd_line), RELOC("iommu="));
413 prom_printf("iommu opt is: %s\n", opt);
415 while (*opt && *opt == ' ')
417 if (!strncmp(opt, RELOC("off"), 3))
418 RELOC(ppc64_iommu_off) = 1;
419 else if (!strncmp(opt, RELOC("force"), 5))
420 RELOC(iommu_force_on) = 1;
425 * Memory allocation strategy... our layout is normally:
427 * at 14Mb or more we vmlinux, then a gap and initrd. In some rare cases, initrd
428 * might end up beeing before the kernel though. We assume this won't override
429 * the final kernel at 0, we have no provision to handle that in this version,
430 * but it should hopefully never happen.
432 * alloc_top is set to the top of RMO, eventually shrink down if the TCEs overlap
433 * alloc_bottom is set to the top of kernel/initrd
435 * from there, allocations are done that way : rtas is allocated topmost, and
436 * the device-tree is allocated from the bottom. We try to grow the device-tree
437 * allocation as we progress. If we can't, then we fail, we don't currently have
438 * a facility to restart elsewhere, but that shouldn't be necessary neither
440 * Note that calls to reserve_mem have to be done explicitely, memory allocated
441 * with either alloc_up or alloc_down isn't automatically reserved.
446 * Allocates memory in the RMO upward from the kernel/initrd
448 * When align is 0, this is a special case, it means to allocate in place
449 * at the current location of alloc_bottom or fail (that is basically
450 * extending the previous allocation). Used for the device-tree flattening
452 static unsigned long __init alloc_up(unsigned long size, unsigned long align)
454 unsigned long offset = reloc_offset();
455 unsigned long base = _ALIGN_UP(RELOC(alloc_bottom), align);
456 unsigned long addr = 0;
458 prom_debug("alloc_up(%x, %x)\n", size, align);
459 if (RELOC(ram_top) == 0)
460 prom_panic("alloc_up() called with mem not initialized\n");
463 base = _ALIGN_UP(RELOC(alloc_bottom), align);
465 base = RELOC(alloc_bottom);
467 for(; (base + size) <= RELOC(alloc_top);
468 base = _ALIGN_UP(base + 0x100000, align)) {
469 prom_debug(" trying: 0x%x\n\r", base);
470 addr = (unsigned long)prom_claim(base, size, 0);
471 if ((int)addr != PROM_ERROR)
479 RELOC(alloc_bottom) = addr;
481 prom_debug(" -> %x\n", addr);
482 prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
483 prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
484 prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
485 prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
486 prom_debug(" ram_top : %x\n", RELOC(ram_top));
492 * Allocates memory downard, either from top of RMO, or if highmem
493 * is set, from the top of RAM. Note that this one doesn't handle
494 * failures. In does claim memory if highmem is not set.
496 static unsigned long __init alloc_down(unsigned long size, unsigned long align,
499 unsigned long offset = reloc_offset();
500 unsigned long base, addr = 0;
502 prom_debug("alloc_down(%x, %x, %s)\n", size, align,
503 highmem ? RELOC("(high)") : RELOC("(low)"));
504 if (RELOC(ram_top) == 0)
505 prom_panic("alloc_down() called with mem not initialized\n");
508 /* Carve out storage for the TCE table. */
509 addr = _ALIGN_DOWN(RELOC(alloc_top_high) - size, align);
510 if (addr <= RELOC(alloc_bottom))
513 /* Will we bump into the RMO ? If yes, check out that we
514 * didn't overlap existing allocations there, if we did,
515 * we are dead, we must be the first in town !
517 if (addr < RELOC(rmo_top)) {
518 /* Good, we are first */
519 if (RELOC(alloc_top) == RELOC(rmo_top))
520 RELOC(alloc_top) = RELOC(rmo_top) = addr;
524 RELOC(alloc_top_high) = addr;
529 base = _ALIGN_DOWN(RELOC(alloc_top) - size, align);
530 for(; base > RELOC(alloc_bottom); base = _ALIGN_DOWN(base - 0x100000, align)) {
531 prom_debug(" trying: 0x%x\n\r", base);
532 addr = (unsigned long)prom_claim(base, size, 0);
533 if ((int)addr != PROM_ERROR)
539 RELOC(alloc_top) = addr;
542 prom_debug(" -> %x\n", addr);
543 prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
544 prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
545 prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
546 prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
547 prom_debug(" ram_top : %x\n", RELOC(ram_top));
555 static unsigned long __init prom_next_cell(int s, cell_t **cellp)
560 /* Ignore more than 2 cells */
576 * Very dumb function for adding to the memory reserve list, but
577 * we don't need anything smarter at this point
579 * XXX Eventually check for collisions. They should NEVER happen
580 * if problems seem to show up, it would be a good start to track
583 static void reserve_mem(unsigned long base, unsigned long size)
585 unsigned long offset = reloc_offset();
586 unsigned long top = base + size;
587 unsigned long cnt = RELOC(mem_reserve_cnt);
592 /* We need to always keep one empty entry so that we
593 * have our terminator with "size" set to 0 since we are
594 * dumb and just copy this entire array to the boot params
596 base = _ALIGN_DOWN(base, PAGE_SIZE);
597 top = _ALIGN_UP(top, PAGE_SIZE);
600 if (cnt >= (MEM_RESERVE_MAP_SIZE - 1))
601 prom_panic("Memory reserve map exhausted !\n");
602 RELOC(mem_reserve_map)[cnt].base = base;
603 RELOC(mem_reserve_map)[cnt].size = size;
604 RELOC(mem_reserve_cnt) = cnt + 1;
608 * Initialize memory allocation mecanism, parse "memory" nodes and
609 * obtain that way the top of memory and RMO to setup out local allocator
611 static void __init prom_init_mem(void)
614 char *path, type[64];
617 unsigned long offset = reloc_offset();
618 struct prom_t *_prom = PTRRELOC(&prom);
621 * We iterate the memory nodes to find
622 * 1) top of RMO (first node)
625 prom_debug("root_addr_cells: %x\n", (long)_prom->root_addr_cells);
626 prom_debug("root_size_cells: %x\n", (long)_prom->root_size_cells);
628 prom_debug("scanning memory:\n");
629 path = RELOC(prom_scratch);
631 for (node = 0; prom_next_node(&node); ) {
633 prom_getprop(node, "device_type", type, sizeof(type));
635 if (strcmp(type, RELOC("memory")))
638 plen = prom_getprop(node, "reg", RELOC(regbuf), sizeof(regbuf));
639 if (plen > sizeof(regbuf)) {
640 prom_printf("memory node too large for buffer !\n");
641 plen = sizeof(regbuf);
644 endp = p + (plen / sizeof(cell_t));
647 memset(path, 0, PROM_SCRATCH_SIZE);
648 call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
649 prom_debug(" node %s :\n", path);
650 #endif /* DEBUG_PROM */
652 while ((endp - p) >= (_prom->root_addr_cells + _prom->root_size_cells)) {
653 unsigned long base, size;
655 base = prom_next_cell(_prom->root_addr_cells, &p);
656 size = prom_next_cell(_prom->root_size_cells, &p);
660 prom_debug(" %x %x\n", base, size);
662 RELOC(rmo_top) = size;
663 if ((base + size) > RELOC(ram_top))
664 RELOC(ram_top) = base + size;
668 /* Setup our top/bottom alloc points, that is top of RMO or top of
669 * segment 0 when running non-LPAR
671 if ( RELOC(of_platform) == PLATFORM_PSERIES_LPAR )
672 RELOC(alloc_top) = RELOC(rmo_top);
674 RELOC(alloc_top) = RELOC(rmo_top) = min(0x40000000ul, RELOC(ram_top));
675 RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(klimit) - offset + 0x4000);
676 RELOC(alloc_top_high) = RELOC(ram_top);
678 /* Check if we have an initrd after the kernel, if we do move our bottom
681 if (RELOC(prom_initrd_start)) {
682 if ((RELOC(prom_initrd_start) + RELOC(prom_initrd_end))
683 > RELOC(alloc_bottom))
684 RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(prom_initrd_end));
687 prom_printf("memory layout at init:\n");
688 prom_printf(" alloc_bottom : %x\n", RELOC(alloc_bottom));
689 prom_printf(" alloc_top : %x\n", RELOC(alloc_top));
690 prom_printf(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
691 prom_printf(" rmo_top : %x\n", RELOC(rmo_top));
692 prom_printf(" ram_top : %x\n", RELOC(ram_top));
697 * Allocate room for and instanciate RTAS
699 static void __init prom_instantiate_rtas(void)
701 unsigned long offset = reloc_offset();
702 struct prom_t *_prom = PTRRELOC(&prom);
703 phandle prom_rtas, rtas_node;
707 prom_debug("prom_instantiate_rtas: start...\n");
709 prom_rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
710 prom_debug("prom_rtas: %x\n", prom_rtas);
711 if (prom_rtas == (phandle) -1)
714 prom_getprop(prom_rtas, "rtas-size", &size, sizeof(size));
718 base = alloc_down(size, PAGE_SIZE, 0);
720 prom_printf("RTAS allocation failed !\n");
723 prom_printf("instantiating rtas at 0x%x", base);
725 rtas_node = call_prom("open", 1, 1, ADDR("/rtas"));
728 if (call_prom("call-method", 3, 2,
729 ADDR("instantiate-rtas"),
730 rtas_node, base) != PROM_ERROR) {
731 entry = (long)_prom->args.rets[1];
734 prom_printf(" failed\n");
737 prom_printf(" done\n");
739 reserve_mem(base, size);
741 prom_setprop(prom_rtas, "linux,rtas-base", &base, sizeof(base));
742 prom_setprop(prom_rtas, "linux,rtas-entry", &entry, sizeof(entry));
744 prom_debug("rtas base = 0x%x\n", base);
745 prom_debug("rtas entry = 0x%x\n", entry);
746 prom_debug("rtas size = 0x%x\n", (long)size);
748 prom_debug("prom_instantiate_rtas: end...\n");
753 * Allocate room for and initialize TCE tables
755 static void __init prom_initialize_tce_table(void)
759 unsigned long offset = reloc_offset();
760 char compatible[64], type[64], model[64];
761 char *path = RELOC(prom_scratch);
763 u32 minalign, minsize;
764 u64 tce_entry, *tce_entryp;
765 u64 local_alloc_top, local_alloc_bottom;
768 if (RELOC(ppc64_iommu_off))
771 prom_debug("starting prom_initialize_tce_table\n");
773 /* Cache current top of allocs so we reserve a single block */
774 local_alloc_top = RELOC(alloc_top_high);
775 local_alloc_bottom = local_alloc_top;
777 /* Search all nodes looking for PHBs. */
778 for (node = 0; prom_next_node(&node); ) {
782 prom_getprop(node, "compatible",
783 compatible, sizeof(compatible));
784 prom_getprop(node, "device_type", type, sizeof(type));
785 prom_getprop(node, "model", model, sizeof(model));
787 if ((type[0] == 0) || (strstr(type, RELOC("pci")) == NULL))
790 /* Keep the old logic in tack to avoid regression. */
791 if (compatible[0] != 0) {
792 if ((strstr(compatible, RELOC("python")) == NULL) &&
793 (strstr(compatible, RELOC("Speedwagon")) == NULL) &&
794 (strstr(compatible, RELOC("Winnipeg")) == NULL))
796 } else if (model[0] != 0) {
797 if ((strstr(model, RELOC("ython")) == NULL) &&
798 (strstr(model, RELOC("peedwagon")) == NULL) &&
799 (strstr(model, RELOC("innipeg")) == NULL))
803 if (prom_getprop(node, "tce-table-minalign", &minalign,
804 sizeof(minalign)) == PROM_ERROR)
806 if (prom_getprop(node, "tce-table-minsize", &minsize,
807 sizeof(minsize)) == PROM_ERROR)
811 * Even though we read what OF wants, we just set the table
812 * size to 4 MB. This is enough to map 2GB of PCI DMA space.
813 * By doing this, we avoid the pitfalls of trying to DMA to
814 * MMIO space and the DMA alias hole.
816 * On POWER4, firmware sets the TCE region by assuming
817 * each TCE table is 8MB. Using this memory for anything
818 * else will impact performance, so we always allocate 8MB.
821 if (__is_processor(PV_POWER4) || __is_processor(PV_POWER4p))
826 /* Align to the greater of the align or size */
827 align = max(minalign, minsize);
828 base = alloc_down(minsize, align, 1);
830 prom_panic("ERROR, cannot find space for TCE table.\n");
831 if (base < local_alloc_bottom)
832 local_alloc_bottom = base;
834 /* Save away the TCE table attributes for later use. */
835 prom_setprop(node, "linux,tce-base", &base, sizeof(base));
836 prom_setprop(node, "linux,tce-size", &minsize, sizeof(minsize));
838 /* It seems OF doesn't null-terminate the path :-( */
839 memset(path, 0, sizeof(path));
840 /* Call OF to setup the TCE hardware */
841 if (call_prom("package-to-path", 3, 1, node,
842 path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) {
843 prom_printf("package-to-path failed\n");
846 prom_debug("TCE table: %s\n", path);
847 prom_debug("\tnode = 0x%x\n", node);
848 prom_debug("\tbase = 0x%x\n", base);
849 prom_debug("\tsize = 0x%x\n", minsize);
851 /* Initialize the table to have a one-to-one mapping
852 * over the allocated size.
854 tce_entryp = (unsigned long *)base;
855 for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {
856 tce_entry = (i << PAGE_SHIFT);
858 *tce_entryp = tce_entry;
861 prom_printf("opening PHB %s", path);
862 phb_node = call_prom("open", 1, 1, path);
863 if ( (long)phb_node <= 0)
864 prom_printf("... failed\n");
866 prom_printf("... done\n");
868 call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"),
869 phb_node, -1, minsize,
870 (u32) base, (u32) (base >> 32));
871 call_prom("close", 1, 0, phb_node);
874 reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom);
876 /* Flag the first invalid entry */
877 prom_debug("ending prom_initialize_tce_table\n");
881 * With CHRP SMP we need to use the OF to start the other
882 * processors so we can't wait until smp_boot_cpus (the OF is
883 * trashed by then) so we have to put the processors into
884 * a holding pattern controlled by the kernel (not OF) before
887 * This uses a chunk of low memory, puts some holding pattern
888 * code there and sends the other processors off to there until
889 * smp_boot_cpus tells them to do something. The holding pattern
890 * checks that address until its cpu # is there, when it is that
891 * cpu jumps to __secondary_start(). smp_boot_cpus() takes care
892 * of setting those values.
894 * We also use physical address 0x4 here to tell when a cpu
895 * is in its holding pattern code.
897 * Fixup comment... DRENG / PPPBBB - Peter
901 static void __init prom_hold_cpus(void)
906 unsigned long offset = reloc_offset();
909 unsigned int interrupt_server[MAX_CPU_THREADS];
910 unsigned int cpu_threads, hw_cpu_num;
912 extern void __secondary_hold(void);
913 extern unsigned long __secondary_hold_spinloop;
914 extern unsigned long __secondary_hold_acknowledge;
915 unsigned long *spinloop
916 = (void *)virt_to_abs(&__secondary_hold_spinloop);
917 unsigned long *acknowledge
918 = (void *)virt_to_abs(&__secondary_hold_acknowledge);
919 unsigned long secondary_hold
920 = virt_to_abs(*PTRRELOC((unsigned long *)__secondary_hold));
921 struct prom_t *_prom = PTRRELOC(&prom);
923 prom_debug("prom_hold_cpus: start...\n");
924 prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop);
925 prom_debug(" 1) *spinloop = 0x%x\n", *spinloop);
926 prom_debug(" 1) acknowledge = 0x%x\n",
927 (unsigned long)acknowledge);
928 prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge);
929 prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold);
931 /* Set the common spinloop variable, so all of the secondary cpus
932 * will block when they are awakened from their OF spinloop.
933 * This must occur for both SMP and non SMP kernels, since OF will
934 * be trashed when we move the kernel.
939 for (i=0; i < NR_CPUS; i++) {
940 RELOC(hmt_thread_data)[i].pir = 0xdeadbeef;
944 for (node = 0; prom_next_node(&node); ) {
946 prom_getprop(node, "device_type", type, sizeof(type));
947 if (strcmp(type, RELOC("cpu")) != 0)
950 /* Skip non-configured cpus. */
951 if (prom_getprop(node, "status", type, sizeof(type)) > 0)
952 if (strcmp(type, RELOC("okay")) != 0)
956 prom_getprop(node, "reg", ®, sizeof(reg));
958 prom_debug("\ncpuid = 0x%x\n", cpuid);
959 prom_debug("cpu hw idx = 0x%x\n", reg);
961 /* Init the acknowledge var which will be reset by
962 * the secondary cpu when it awakens from its OF
965 *acknowledge = (unsigned long)-1;
967 propsize = prom_getprop(node, "ibm,ppc-interrupt-server#s",
969 sizeof(interrupt_server));
971 /* no property. old hardware has no SMT */
973 interrupt_server[0] = reg; /* fake it with phys id */
975 /* We have a threaded processor */
976 cpu_threads = propsize / sizeof(u32);
977 if (cpu_threads > MAX_CPU_THREADS) {
978 prom_printf("SMT: too many threads!\n"
979 "SMT: found %x, max is %x\n",
980 cpu_threads, MAX_CPU_THREADS);
981 cpu_threads = 1; /* ToDo: panic? */
985 hw_cpu_num = interrupt_server[0];
986 if (hw_cpu_num != _prom->cpu) {
987 /* Primary Thread of non-boot cpu */
988 prom_printf("%x : starting cpu hw idx %x... ", cpuid, reg);
989 call_prom("start-cpu", 3, 0, node,
990 secondary_hold, reg);
992 for ( i = 0 ; (i < 100000000) &&
993 (*acknowledge == ((unsigned long)-1)); i++ )
996 if (*acknowledge == reg) {
997 prom_printf("done\n");
998 /* We have to get every CPU out of OF,
999 * even if we never start it. */
1000 if (cpuid >= NR_CPUS)
1003 prom_printf("failed: %x\n", *acknowledge);
1008 prom_printf("%x : boot cpu %x\n", cpuid, reg);
1012 /* Init paca for secondary threads. They start later. */
1013 for (i=1; i < cpu_threads; i++) {
1015 if (cpuid >= NR_CPUS)
1018 #endif /* CONFIG_SMP */
1022 /* Only enable HMT on processors that provide support. */
1023 if (__is_processor(PV_PULSAR) ||
1024 __is_processor(PV_ICESTAR) ||
1025 __is_processor(PV_SSTAR)) {
1026 prom_printf(" starting secondary threads\n");
1028 for (i = 0; i < NR_CPUS; i += 2) {
1033 unsigned long pir = mfspr(SPRN_PIR);
1034 if (__is_processor(PV_PULSAR)) {
1035 RELOC(hmt_thread_data)[i].pir =
1038 RELOC(hmt_thread_data)[i].pir =
1044 prom_printf("Processor is not HMT capable\n");
1048 if (cpuid > NR_CPUS)
1049 prom_printf("WARNING: maximum CPUs (" __stringify(NR_CPUS)
1050 ") exceeded: ignoring extras\n");
1052 prom_debug("prom_hold_cpus: end...\n");
1056 static void __init prom_init_client_services(unsigned long pp)
1058 unsigned long offset = reloc_offset();
1059 struct prom_t *_prom = PTRRELOC(&prom);
1061 /* Get a handle to the prom entry point before anything else */
1064 /* Init default value for phys size */
1065 _prom->root_size_cells = 1;
1066 _prom->root_addr_cells = 2;
1068 /* get a handle for the stdout device */
1069 _prom->chosen = call_prom("finddevice", 1, 1, ADDR("/chosen"));
1070 if ((long)_prom->chosen <= 0)
1071 prom_panic("cannot find chosen"); /* msg won't be printed :( */
1073 /* get device tree root */
1074 _prom->root = call_prom("finddevice", 1, 1, ADDR("/"));
1075 if ((long)_prom->root <= 0)
1076 prom_panic("cannot find device tree root"); /* msg won't be printed :( */
1079 static void __init prom_init_stdout(void)
1081 unsigned long offset = reloc_offset();
1082 struct prom_t *_prom = PTRRELOC(&prom);
1083 char *path = RELOC(of_stdout_device);
1087 if (prom_getprop(_prom->chosen, "stdout", &val, sizeof(val)) <= 0)
1088 prom_panic("cannot find stdout");
1090 _prom->stdout = val;
1092 /* Get the full OF pathname of the stdout device */
1093 memset(path, 0, 256);
1094 call_prom("instance-to-path", 3, 1, _prom->stdout, path, 255);
1095 val = call_prom("instance-to-package", 1, 1, _prom->stdout);
1096 prom_setprop(_prom->chosen, "linux,stdout-package", &val, sizeof(val));
1097 prom_printf("OF stdout device is: %s\n", RELOC(of_stdout_device));
1098 prom_setprop(_prom->chosen, "linux,stdout-path",
1099 RELOC(of_stdout_device), strlen(RELOC(of_stdout_device))+1);
1101 /* If it's a display, note it */
1102 memset(type, 0, sizeof(type));
1103 prom_getprop(val, "device_type", type, sizeof(type));
1104 if (strcmp(type, RELOC("display")) == 0) {
1105 _prom->disp_node = val;
1106 prom_setprop(val, "linux,boot-display", NULL, 0);
1110 static void __init prom_close_stdin(void)
1112 unsigned long offset = reloc_offset();
1113 struct prom_t *_prom = PTRRELOC(&prom);
1116 if (prom_getprop(_prom->chosen, "stdin", &val, sizeof(val)) > 0)
1117 call_prom("close", 1, 0, val);
1120 static int __init prom_find_machine_type(void)
1122 unsigned long offset = reloc_offset();
1123 struct prom_t *_prom = PTRRELOC(&prom);
1128 len = prom_getprop(_prom->root, "compatible",
1129 compat, sizeof(compat)-1);
1133 char *p = &compat[i];
1137 if (strstr(p, RELOC("Power Macintosh")) ||
1138 strstr(p, RELOC("MacRISC4")))
1139 return PLATFORM_POWERMAC;
1140 if (strstr(p, RELOC("Momentum,Maple")))
1141 return PLATFORM_MAPLE;
1145 /* Default to pSeries. We need to know if we are running LPAR */
1146 rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
1147 if (rtas != (phandle) -1) {
1149 x = prom_getproplen(rtas, "ibm,hypertas-functions");
1150 if (x != PROM_ERROR) {
1151 prom_printf("Hypertas detected, assuming LPAR !\n");
1152 return PLATFORM_PSERIES_LPAR;
1155 return PLATFORM_PSERIES;
1158 static int __init prom_set_color(ihandle ih, int i, int r, int g, int b)
1160 unsigned long offset = reloc_offset();
1162 return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r);
1166 * If we have a display that we don't know how to drive,
1167 * we will want to try to execute OF's open method for it
1168 * later. However, OF will probably fall over if we do that
1169 * we've taken over the MMU.
1170 * So we check whether we will need to open the display,
1171 * and if so, open it now.
1173 static void __init prom_check_displays(void)
1175 unsigned long offset = reloc_offset();
1176 struct prom_t *_prom = PTRRELOC(&prom);
1177 char type[16], *path;
1182 static unsigned char default_colors[] = {
1200 const unsigned char *clut;
1202 prom_printf("Looking for displays\n");
1203 for (node = 0; prom_next_node(&node); ) {
1204 memset(type, 0, sizeof(type));
1205 prom_getprop(node, "device_type", type, sizeof(type));
1206 if (strcmp(type, RELOC("display")) != 0)
1209 /* It seems OF doesn't null-terminate the path :-( */
1210 path = RELOC(prom_scratch);
1211 memset(path, 0, PROM_SCRATCH_SIZE);
1214 * leave some room at the end of the path for appending extra
1217 if (call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-10) < 0)
1219 prom_printf("found display : %s, opening ... ", path);
1221 ih = call_prom("open", 1, 1, path);
1222 if (ih == (ihandle)0 || ih == (ihandle)-1) {
1223 prom_printf("failed\n");
1228 prom_printf("done\n");
1229 prom_setprop(node, "linux,opened", NULL, 0);
1232 * stdout wasn't a display node, pick the first we can find
1235 if (_prom->disp_node == 0)
1236 _prom->disp_node = node;
1238 /* Setup a useable color table when the appropriate
1239 * method is available. Should update this to set-colors */
1240 clut = RELOC(default_colors);
1241 for (i = 0; i < 32; i++, clut += 3)
1242 if (prom_set_color(ih, i, clut[0], clut[1],
1246 #ifdef CONFIG_LOGO_LINUX_CLUT224
1247 clut = PTRRELOC(RELOC(logo_linux_clut224.clut));
1248 for (i = 0; i < RELOC(logo_linux_clut224.clutsize); i++, clut += 3)
1249 if (prom_set_color(ih, i + 32, clut[0], clut[1],
1252 #endif /* CONFIG_LOGO_LINUX_CLUT224 */
1257 /* Return (relocated) pointer to this much memory: moves initrd if reqd. */
1258 static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end,
1259 unsigned long needed, unsigned long align)
1261 unsigned long offset = reloc_offset();
1264 *mem_start = _ALIGN(*mem_start, align);
1265 while ((*mem_start + needed) > *mem_end) {
1266 unsigned long room, chunk;
1268 prom_debug("Chunk exhausted, claiming more at %x...\n",
1269 RELOC(alloc_bottom));
1270 room = RELOC(alloc_top) - RELOC(alloc_bottom);
1271 if (room > DEVTREE_CHUNK_SIZE)
1272 room = DEVTREE_CHUNK_SIZE;
1273 if (room < PAGE_SIZE)
1274 prom_panic("No memory for flatten_device_tree (no room)");
1275 chunk = alloc_up(room, 0);
1277 prom_panic("No memory for flatten_device_tree (claim failed)");
1278 *mem_end = RELOC(alloc_top);
1281 ret = (void *)*mem_start;
1282 *mem_start += needed;
1287 #define dt_push_token(token, mem_start, mem_end) \
1288 do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0)
1290 static unsigned long __init dt_find_string(char *str)
1292 unsigned long offset = reloc_offset();
1295 s = os = (char *)RELOC(dt_string_start);
1297 while (s < (char *)RELOC(dt_string_end)) {
1298 if (strcmp(s, str) == 0)
1305 static void __init scan_dt_build_strings(phandle node, unsigned long *mem_start,
1306 unsigned long *mem_end)
1308 unsigned long offset = reloc_offset();
1309 char *prev_name, *namep, *sstart;
1313 sstart = (char *)RELOC(dt_string_start);
1315 /* get and store all property names */
1316 prev_name = RELOC("");
1319 /* 32 is max len of name including nul. */
1320 namep = make_room(mem_start, mem_end, 32, 1);
1321 if (call_prom("nextprop", 3, 1, node, prev_name, namep) <= 0) {
1322 /* No more nodes: unwind alloc */
1323 *mem_start = (unsigned long)namep;
1326 soff = dt_find_string(namep);
1328 *mem_start = (unsigned long)namep;
1329 namep = sstart + soff;
1331 /* Trim off some if we can */
1332 *mem_start = (unsigned long)namep + strlen(namep) + 1;
1333 RELOC(dt_string_end) = *mem_start;
1338 /* do all our children */
1339 child = call_prom("child", 1, 1, node);
1340 while (child != (phandle)0) {
1341 scan_dt_build_strings(child, mem_start, mem_end);
1342 child = call_prom("peer", 1, 1, child);
1346 static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,
1347 unsigned long *mem_end)
1351 char *namep, *prev_name, *sstart;
1353 unsigned char *valp;
1354 unsigned long offset = reloc_offset();
1358 path = RELOC(prom_scratch);
1360 dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end);
1362 /* get the node's full name */
1363 namep = (char *)*mem_start;
1364 l = call_prom("package-to-path", 3, 1, node,
1365 namep, *mem_end - *mem_start);
1367 /* Didn't fit? Get more room. */
1368 if (l+1 > *mem_end - *mem_start) {
1369 namep = make_room(mem_start, mem_end, l+1, 1);
1370 call_prom("package-to-path", 3, 1, node, namep, l);
1373 *mem_start = _ALIGN(((unsigned long) namep) + strlen(namep) + 1, 4);
1376 /* get it again for debugging */
1377 memset(path, 0, PROM_SCRATCH_SIZE);
1378 call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
1380 /* get and store all properties */
1381 prev_name = RELOC("");
1382 sstart = (char *)RELOC(dt_string_start);
1384 if (call_prom("nextprop", 3, 1, node, prev_name, pname) <= 0)
1387 /* find string offset */
1388 soff = dt_find_string(pname);
1390 prom_printf("WARNING: Can't find string index for <%s>, node %s\n",
1394 prev_name = sstart + soff;
1397 l = call_prom("getproplen", 2, 1, node, pname);
1402 if (l > MAX_PROPERTY_LENGTH) {
1403 prom_printf("WARNING: ignoring large property ");
1404 /* It seems OF doesn't null-terminate the path :-( */
1405 prom_printf("[%s] ", path);
1406 prom_printf("%s length 0x%x\n", pname, l);
1410 /* push property head */
1411 dt_push_token(OF_DT_PROP, mem_start, mem_end);
1412 dt_push_token(l, mem_start, mem_end);
1413 dt_push_token(soff, mem_start, mem_end);
1415 /* push property content */
1416 align = (l >= 8) ? 8 : 4;
1417 valp = make_room(mem_start, mem_end, l, align);
1418 call_prom("getprop", 4, 1, node, pname, valp, l);
1419 *mem_start = _ALIGN(*mem_start, 4);
1422 /* Add a "linux,phandle" property. */
1423 soff = dt_find_string(RELOC("linux,phandle"));
1425 prom_printf("WARNING: Can't find string index for <linux-phandle>"
1426 " node %s\n", path);
1428 dt_push_token(OF_DT_PROP, mem_start, mem_end);
1429 dt_push_token(4, mem_start, mem_end);
1430 dt_push_token(soff, mem_start, mem_end);
1431 valp = make_room(mem_start, mem_end, 4, 4);
1432 *(u32 *)valp = node;
1435 /* do all our children */
1436 child = call_prom("child", 1, 1, node);
1437 while (child != (phandle)0) {
1438 scan_dt_build_struct(child, mem_start, mem_end);
1439 child = call_prom("peer", 1, 1, child);
1442 dt_push_token(OF_DT_END_NODE, mem_start, mem_end);
1445 static void __init flatten_device_tree(void)
1448 unsigned long offset = reloc_offset();
1449 unsigned long mem_start, mem_end, room;
1450 struct boot_param_header *hdr;
1455 * Check how much room we have between alloc top & bottom (+/- a
1456 * few pages), crop to 4Mb, as this is our "chuck" size
1458 room = RELOC(alloc_top) - RELOC(alloc_bottom) - 0x4000;
1459 if (room > DEVTREE_CHUNK_SIZE)
1460 room = DEVTREE_CHUNK_SIZE;
1461 prom_debug("starting device tree allocs at %x\n", RELOC(alloc_bottom));
1463 /* Now try to claim that */
1464 mem_start = (unsigned long)alloc_up(room, PAGE_SIZE);
1466 prom_panic("Can't allocate initial device-tree chunk\n");
1467 mem_end = RELOC(alloc_top);
1469 /* Get root of tree */
1470 root = call_prom("peer", 1, 1, (phandle)0);
1471 if (root == (phandle)0)
1472 prom_panic ("couldn't get device tree root\n");
1474 /* Build header and make room for mem rsv map */
1475 mem_start = _ALIGN(mem_start, 4);
1476 hdr = make_room(&mem_start, &mem_end, sizeof(struct boot_param_header), 4);
1477 RELOC(dt_header_start) = (unsigned long)hdr;
1478 rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8);
1480 /* Start of strings */
1481 mem_start = PAGE_ALIGN(mem_start);
1482 RELOC(dt_string_start) = mem_start;
1483 mem_start += 4; /* hole */
1485 /* Add "linux,phandle" in there, we'll need it */
1486 namep = make_room(&mem_start, &mem_end, 16, 1);
1487 strcpy(namep, RELOC("linux,phandle"));
1488 mem_start = (unsigned long)namep + strlen(namep) + 1;
1489 RELOC(dt_string_end) = mem_start;
1491 /* Build string array */
1492 prom_printf("Building dt strings...\n");
1493 scan_dt_build_strings(root, &mem_start, &mem_end);
1495 /* Build structure */
1496 mem_start = PAGE_ALIGN(mem_start);
1497 RELOC(dt_struct_start) = mem_start;
1498 prom_printf("Building dt structure...\n");
1499 scan_dt_build_struct(root, &mem_start, &mem_end);
1500 dt_push_token(OF_DT_END, &mem_start, &mem_end);
1501 RELOC(dt_struct_end) = PAGE_ALIGN(mem_start);
1504 hdr->magic = OF_DT_HEADER;
1505 hdr->totalsize = RELOC(dt_struct_end) - RELOC(dt_header_start);
1506 hdr->off_dt_struct = RELOC(dt_struct_start) - RELOC(dt_header_start);
1507 hdr->off_dt_strings = RELOC(dt_string_start) - RELOC(dt_header_start);
1508 hdr->off_mem_rsvmap = ((unsigned long)rsvmap) - RELOC(dt_header_start);
1509 hdr->version = OF_DT_VERSION;
1510 hdr->last_comp_version = 1;
1512 /* Reserve the whole thing and copy the reserve map in, we
1513 * also bump mem_reserve_cnt to cause further reservations to
1514 * fail since it's too late.
1516 reserve_mem(RELOC(dt_header_start), hdr->totalsize);
1517 memcpy(rsvmap, RELOC(mem_reserve_map), sizeof(mem_reserve_map));
1522 prom_printf("reserved memory map:\n");
1523 for (i = 0; i < RELOC(mem_reserve_cnt); i++)
1524 prom_printf(" %x - %x\n", RELOC(mem_reserve_map)[i].base,
1525 RELOC(mem_reserve_map)[i].size);
1528 RELOC(mem_reserve_cnt) = MEM_RESERVE_MAP_SIZE;
1530 prom_printf("Device tree strings 0x%x -> 0x%x\n",
1531 RELOC(dt_string_start), RELOC(dt_string_end));
1532 prom_printf("Device tree struct 0x%x -> 0x%x\n",
1533 RELOC(dt_struct_start), RELOC(dt_struct_end));
1537 static void __init prom_find_boot_cpu(void)
1539 unsigned long offset = reloc_offset();
1540 struct prom_t *_prom = PTRRELOC(&prom);
1545 if (prom_getprop(_prom->chosen, "cpu", &prom_cpu, sizeof(prom_cpu)) <= 0)
1546 prom_panic("cannot find boot cpu");
1548 cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu);
1550 prom_setprop(cpu_pkg, "linux,boot-cpu", NULL, 0);
1551 prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval));
1552 _prom->cpu = getprop_rval;
1554 prom_debug("Booting CPU hw index = 0x%x\n", _prom->cpu);
1557 static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
1559 #ifdef CONFIG_BLK_DEV_INITRD
1560 unsigned long offset = reloc_offset();
1561 struct prom_t *_prom = PTRRELOC(&prom);
1563 if ( r3 && r4 && r4 != 0xdeadbeef) {
1566 RELOC(prom_initrd_start) = (r3 >= KERNELBASE) ? __pa(r3) : r3;
1567 RELOC(prom_initrd_end) = RELOC(prom_initrd_start) + r4;
1569 val = (u64)RELOC(prom_initrd_start);
1570 prom_setprop(_prom->chosen, "linux,initrd-start", &val, sizeof(val));
1571 val = (u64)RELOC(prom_initrd_end);
1572 prom_setprop(_prom->chosen, "linux,initrd-end", &val, sizeof(val));
1574 reserve_mem(RELOC(prom_initrd_start),
1575 RELOC(prom_initrd_end) - RELOC(prom_initrd_start));
1577 prom_debug("initrd_start=0x%x\n", RELOC(prom_initrd_start));
1578 prom_debug("initrd_end=0x%x\n", RELOC(prom_initrd_end));
1580 #endif /* CONFIG_BLK_DEV_INITRD */
1584 * We enter here early on, when the Open Firmware prom is still
1585 * handling exceptions and the MMU hash table for us.
1588 unsigned long __init prom_init(unsigned long r3, unsigned long r4, unsigned long pp,
1589 unsigned long r6, unsigned long r7)
1591 unsigned long offset = reloc_offset();
1592 struct prom_t *_prom = PTRRELOC(&prom);
1593 unsigned long phys = KERNELBASE - offset;
1597 * First zero the BSS
1599 memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start);
1602 * Init interface to Open Firmware, get some node references,
1605 prom_init_client_services(pp);
1608 * Init prom stdout device
1611 prom_debug("klimit=0x%x\n", RELOC(klimit));
1612 prom_debug("offset=0x%x\n", offset);
1615 * Check for an initrd
1617 prom_check_initrd(r3, r4);
1620 * Get default machine type. At this point, we do not differenciate
1621 * between pSeries SMP and pSeries LPAR
1623 RELOC(of_platform) = prom_find_machine_type();
1624 getprop_rval = RELOC(of_platform);
1625 prom_setprop(_prom->chosen, "linux,platform",
1626 &getprop_rval, sizeof(getprop_rval));
1629 * On pSeries, copy the CPU hold code
1631 if (RELOC(of_platform) & PLATFORM_PSERIES)
1632 copy_and_flush(0, KERNELBASE - offset, 0x100, 0);
1635 * Get memory cells format
1638 prom_getprop(_prom->root, "#size-cells",
1639 &getprop_rval, sizeof(getprop_rval));
1640 _prom->root_size_cells = getprop_rval;
1642 prom_getprop(_prom->root, "#address-cells",
1643 &getprop_rval, sizeof(getprop_rval));
1644 _prom->root_addr_cells = getprop_rval;
1647 * Do early parsing of command line
1649 early_cmdline_parse();
1652 * Initialize memory management within prom_init
1657 * Determine which cpu is actually running right _now_
1659 prom_find_boot_cpu();
1662 * Initialize display devices
1664 prom_check_displays();
1667 * Initialize IOMMU (TCE tables) on pSeries. Do that before anything else
1668 * that uses the allocator, we need to make sure we get the top of memory
1669 * available for us here...
1671 if (RELOC(of_platform) == PLATFORM_PSERIES)
1672 prom_initialize_tce_table();
1675 * On non-powermacs, try to instantiate RTAS and puts all CPUs
1676 * in spin-loops. PowerMacs don't have a working RTAS and use
1677 * a different way to spin CPUs
1679 if (RELOC(of_platform) != PLATFORM_POWERMAC) {
1680 prom_instantiate_rtas();
1685 * Fill in some infos for use by the kernel later on
1687 if (RELOC(ppc64_iommu_off))
1688 prom_setprop(_prom->chosen, "linux,iommu-off", NULL, 0);
1689 if (RELOC(iommu_force_on))
1690 prom_setprop(_prom->chosen, "linux,iommu-force-on", NULL, 0);
1693 * Now finally create the flattened device-tree
1695 prom_printf("copying OF device tree ...\n");
1696 flatten_device_tree();
1698 /* in case stdin is USB and still active on IBM machines... */
1702 * Call OF "quiesce" method to shut down pending DMA's from
1705 prom_printf("Calling quiesce ...\n");
1706 call_prom("quiesce", 0, 0);
1709 * And finally, call the kernel passing it the flattened device
1710 * tree and NULL as r5, thus triggering the new entry point which
1711 * is common to us and kexec
1713 prom_printf("returning from prom_init\n");
1714 prom_debug("->dt_header_start=0x%x\n", RELOC(dt_header_start));
1715 prom_debug("->phys=0x%x\n", phys);
1717 __start(RELOC(dt_header_start), phys, 0);