3 * Common boot and setup code.
5 * Copyright (C) 2001 PPC64 Team, IBM Corp
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
15 #include <linux/config.h>
16 #include <linux/module.h>
17 #include <linux/string.h>
18 #include <linux/sched.h>
19 #include <linux/init.h>
20 #include <linux/reboot.h>
21 #include <linux/delay.h>
22 #include <linux/initrd.h>
23 #include <linux/ide.h>
24 #include <linux/seq_file.h>
25 #include <linux/ioport.h>
26 #include <linux/console.h>
27 #include <linux/version.h>
28 #include <linux/tty.h>
29 #include <linux/root_dev.h>
30 #include <linux/notifier.h>
31 #include <linux/cpu.h>
32 #include <linux/unistd.h>
33 #include <linux/serial.h>
34 #include <linux/serial_8250.h>
37 #include <asm/processor.h>
38 #include <asm/pgtable.h>
39 #include <asm/bootinfo.h>
42 #include <asm/machdep.h>
43 #include <asm/iSeries/LparData.h>
46 #include <asm/ppcdebug.h>
48 #include <asm/cputable.h>
49 #include <asm/sections.h>
50 #include <asm/btext.h>
51 #include <asm/nvram.h>
52 #include <asm/setup.h>
53 #include <asm/system.h>
55 #include <asm/iommu.h>
56 #include <asm/serial.h>
59 #define DBG(fmt...) udbg_printf(fmt)
65 * Here are some early debugging facilities. You can enable one
66 * but your kernel will not boot on anything else if you do so
69 /* This one is for use on LPAR machines that support an HVC console
72 extern void udbg_init_debug_lpar(void);
73 /* This one is for use on Apple G5 machines
75 extern void udbg_init_pmac_realmode(void);
76 /* That's RTAS panel debug */
77 extern void call_rtas_display_status_delay(unsigned char c);
78 /* Here's maple real mode debug */
79 extern void udbg_init_maple_realmode(void);
81 #define EARLY_DEBUG_INIT() do {} while(0)
84 #define EARLY_DEBUG_INIT() udbg_init_debug_lpar()
85 #define EARLY_DEBUG_INIT() udbg_init_maple_realmode()
86 #define EARLY_DEBUG_INIT() udbg_init_pmac_realmode()
87 #define EARLY_DEBUG_INIT() \
88 do { ppc_md.udbg_putc = call_rtas_display_status_delay; } while(0)
91 /* extern void *stab; */
92 extern HTAB htab_data;
93 extern unsigned long klimit;
95 extern void mm_init_ppc64(void);
96 extern int idle_setup(void);
97 extern void stab_initialize(unsigned long stab);
98 extern void htab_initialize(void);
99 extern void early_init_devtree(void *flat_dt);
100 extern void unflatten_device_tree(void);
102 extern void smp_release_cpus(void);
104 unsigned long decr_overclock = 1;
105 unsigned long decr_overclock_proc0 = 1;
106 unsigned long decr_overclock_set = 0;
107 unsigned long decr_overclock_proc0_set = 0;
111 int boot_cpuid_phys = 0;
115 * These are used in binfmt_elf.c to put aux entries on the stack
116 * for each elf executable being started.
122 /* The main machine-dep calls structure
124 struct machdep_calls ppc_md;
126 #ifdef CONFIG_MAGIC_SYSRQ
127 unsigned long SYSRQ_KEY;
128 #endif /* CONFIG_MAGIC_SYSRQ */
131 static int ppc64_panic_event(struct notifier_block *, unsigned long, void *);
132 static struct notifier_block ppc64_panic_block = {
133 .notifier_call = ppc64_panic_event,
134 .priority = INT_MIN /* may not return; must be done last */
138 * Perhaps we can put the pmac screen_info[] here
139 * on pmac as well so we don't need the ifdef's.
140 * Until we get multiple-console support in here
142 * Maybe tie it to serial consoles, since this is really what
143 * these processors use on existing boards. -- Dan
145 struct screen_info screen_info = {
148 .orig_video_cols = 80,
149 .orig_video_lines = 25,
150 .orig_video_isVGA = 1,
151 .orig_video_points = 16
155 * Initialize the PPCDBG state. Called before relocation has been enabled.
157 void __init ppcdbg_initialize(void)
159 naca->debug_switch = PPC_DEBUG_DEFAULT; /* | PPCDBG_BUSWALK | */
160 /* PPCDBG_PHBINIT | PPCDBG_MM | PPCDBG_MMINIT | PPCDBG_TCEINIT | PPCDBG_TCE */;
164 * Early boot console based on udbg
166 static struct console udbg_console = {
168 .write = udbg_console_write,
169 .flags = CON_PRINTBUFFER,
172 static int early_console_initialized;
174 void __init disable_early_printk(void)
176 if (!early_console_initialized)
178 unregister_console(&udbg_console);
179 early_console_initialized = 0;
182 #if defined(CONFIG_PPC_MULTIPLATFORM) && defined(CONFIG_SMP)
184 static int smt_enabled_cmdline;
186 /* Look for ibm,smt-enabled OF option */
187 static void check_smt_enabled(void)
189 struct device_node *dn;
192 /* Allow the command line to overrule the OF option */
193 if (smt_enabled_cmdline)
196 dn = of_find_node_by_path("/options");
199 smt_option = (char *)get_property(dn, "ibm,smt-enabled", NULL);
202 if (!strcmp(smt_option, "on"))
203 smt_enabled_at_boot = 1;
204 else if (!strcmp(smt_option, "off"))
205 smt_enabled_at_boot = 0;
210 /* Look for smt-enabled= cmdline option */
211 static int __init early_smt_enabled(char *p)
213 smt_enabled_cmdline = 1;
218 if (!strcmp(p, "on") || !strcmp(p, "1"))
219 smt_enabled_at_boot = 1;
220 else if (!strcmp(p, "off") || !strcmp(p, "0"))
221 smt_enabled_at_boot = 0;
225 early_param("smt-enabled", early_smt_enabled);
228 * setup_cpu_maps - initialize the following cpu maps:
233 * Having the possible map set up early allows us to restrict allocations
234 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
236 * We do not initialize the online map here; cpus set their own bits in
237 * cpu_online_map as they come up.
239 * This function is valid only for Open Firmware systems. finish_device_tree
240 * must be called before using this.
242 * While we're here, we may as well set the "physical" cpu ids in the paca.
244 static void __init setup_cpu_maps(void)
246 struct device_node *dn = NULL;
252 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
254 int j, len = sizeof(u32), nthreads;
256 intserv = (u32 *)get_property(dn, "ibm,ppc-interrupt-server#s",
259 intserv = (u32 *)get_property(dn, "reg", NULL);
261 nthreads = len / sizeof(u32);
263 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
265 * Only spin up secondary threads if SMT is enabled.
266 * We must leave space in the logical map for the
269 if (j == 0 || smt_enabled_at_boot) {
270 cpu_set(cpu, cpu_present_map);
271 set_hard_smp_processor_id(cpu, intserv[j]);
273 if (intserv[j] == boot_cpuid_phys)
275 cpu_set(cpu, cpu_possible_map);
280 /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
281 * boot cpu is logical 0.
283 if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
285 tmp = get_hard_smp_processor_id(0);
286 set_hard_smp_processor_id(0, boot_cpuid_phys);
287 set_hard_smp_processor_id(swap_cpuid, tmp);
291 * On pSeries LPAR, we need to know how many cpus
292 * could possibly be added to this partition.
294 if (systemcfg->platform == PLATFORM_PSERIES_LPAR &&
295 (dn = of_find_node_by_path("/rtas"))) {
296 int num_addr_cell, num_size_cell, maxcpus;
299 num_addr_cell = prom_n_addr_cells(dn);
300 num_size_cell = prom_n_size_cells(dn);
302 ireg = (unsigned int *)
303 get_property(dn, "ibm,lrdr-capacity", NULL);
308 maxcpus = ireg[num_addr_cell + num_size_cell];
310 /* Double maxcpus for processors which have SMT capability */
311 if (cur_cpu_spec->cpu_features & CPU_FTR_SMT)
314 if (maxcpus > NR_CPUS) {
316 "Partition configured for %d cpus, "
317 "operating system maximum is %d.\n",
321 printk(KERN_INFO "Partition configured for %d cpus.\n",
324 for (cpu = 0; cpu < maxcpus; cpu++)
325 cpu_set(cpu, cpu_possible_map);
331 * Do the sibling map; assume only two threads per processor.
334 cpu_set(cpu, cpu_sibling_map[cpu]);
335 if (cur_cpu_spec->cpu_features & CPU_FTR_SMT)
336 cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
339 systemcfg->processorCount = num_present_cpus();
341 #endif /* defined(CONFIG_PPC_MULTIPLATFORM) && defined(CONFIG_SMP) */
344 #ifdef CONFIG_PPC_MULTIPLATFORM
346 extern struct machdep_calls pSeries_md;
347 extern struct machdep_calls pmac_md;
348 extern struct machdep_calls maple_md;
350 /* Ultimately, stuff them in an elf section like initcalls... */
351 static struct machdep_calls __initdata *machines[] = {
352 #ifdef CONFIG_PPC_PSERIES
354 #endif /* CONFIG_PPC_PSERIES */
355 #ifdef CONFIG_PPC_PMAC
357 #endif /* CONFIG_PPC_PMAC */
358 #ifdef CONFIG_PPC_MAPLE
360 #endif /* CONFIG_PPC_MAPLE */
365 * Early initialization entry point. This is called by head.S
366 * with MMU translation disabled. We rely on the "feature" of
367 * the CPU that ignores the top 2 bits of the address in real
368 * mode so we can access kernel globals normally provided we
369 * only toy with things in the RMO region. From here, we do
370 * some early parsing of the device-tree to setup out LMB
371 * data structures, and allocate & initialize the hash table
372 * and segment tables so we can start running with translation
375 * It is this function which will call the probe() callback of
376 * the various platform types and copy the matching one to the
377 * global ppc_md structure. Your platform can eventually do
378 * some very early initializations from the probe() routine, but
379 * this is not recommended, be very careful as, for example, the
380 * device-tree is not accessible via normal means at this point.
383 void __init early_setup(unsigned long dt_ptr)
385 struct paca_struct *lpaca = get_paca();
386 static struct machdep_calls **mach;
389 * Enable early debugging if any specified (see top of
394 DBG(" -> early_setup()\n");
397 * Fill the default DBG level in naca (do we want to keep
398 * that old mecanism around forever ?)
403 * Do early initializations using the flattened device
404 * tree, like retreiving the physical memory map or
405 * calculating/retreiving the hash table size
407 early_init_devtree(__va(dt_ptr));
410 * Iterate all ppc_md structures until we find the proper
411 * one for the current machine type
413 DBG("Probing machine type for platform %x...\n",
414 systemcfg->platform);
416 for (mach = machines; *mach; mach++) {
417 if ((*mach)->probe(systemcfg->platform))
420 /* What can we do if we didn't find ? */
422 DBG("No suitable machine found !\n");
427 /* our udbg callbacks got overriden by the above, let's put them
428 * back in. Ultimately, I want those things to be split from the
433 DBG("Found, Initializing memory management...\n");
436 * Initialize stab / SLB management
438 stab_initialize(lpaca->stab_real);
441 * Initialize the MMU Hash table and create the linear mapping
446 DBG(" <- early_setup()\n");
451 * Initialize some remaining members of the naca and systemcfg structures
452 * (at least until we get rid of them completely). This is mostly some
453 * cache informations about the CPU that will be used by cache flush
454 * routines and/or provided to userland
456 static void __init initialize_naca(void)
458 struct device_node *np;
459 unsigned long num_cpus = 0;
461 DBG(" -> initialize_naca()\n");
463 for (np = NULL; (np = of_find_node_by_type(np, "cpu"));) {
466 /* We're assuming *all* of the CPUs have the same
467 * d-cache and i-cache sizes... -Peter
470 if ( num_cpus == 1 ) {
475 /* Then read cache informations */
476 if (systemcfg->platform == PLATFORM_POWERMAC) {
477 dc = "d-cache-block-size";
478 ic = "i-cache-block-size";
480 dc = "d-cache-line-size";
481 ic = "i-cache-line-size";
485 lsize = cur_cpu_spec->dcache_bsize;
486 sizep = (u32 *)get_property(np, "d-cache-size", NULL);
489 lsizep = (u32 *) get_property(np, dc, NULL);
493 if (sizep == 0 || lsizep == 0)
494 DBG("Argh, can't find dcache properties ! "
495 "sizep: %p, lsizep: %p\n", sizep, lsizep);
497 systemcfg->dCacheL1Size = size;
498 systemcfg->dCacheL1LineSize = lsize;
499 naca->dCacheL1LogLineSize = __ilog2(lsize);
500 naca->dCacheL1LinesPerPage = PAGE_SIZE/(lsize);
503 lsize = cur_cpu_spec->icache_bsize;
504 sizep = (u32 *)get_property(np, "i-cache-size", NULL);
507 lsizep = (u32 *)get_property(np, ic, NULL);
510 if (sizep == 0 || lsizep == 0)
511 DBG("Argh, can't find icache properties ! "
512 "sizep: %p, lsizep: %p\n", sizep, lsizep);
514 systemcfg->iCacheL1Size = size;
515 systemcfg->iCacheL1LineSize = lsize;
516 naca->iCacheL1LogLineSize = __ilog2(lsize);
517 naca->iCacheL1LinesPerPage = PAGE_SIZE/(lsize);
522 /* Add an eye catcher and the systemcfg layout version number */
523 strcpy(systemcfg->eye_catcher, "SYSTEMCFG:PPC64");
524 systemcfg->version.major = SYSTEMCFG_MAJOR;
525 systemcfg->version.minor = SYSTEMCFG_MINOR;
526 systemcfg->processor = mfspr(SPRN_PVR);
528 DBG(" <- initialize_naca()\n");
531 static void __init check_for_initrd(void)
533 #ifdef CONFIG_BLK_DEV_INITRD
536 DBG(" -> check_for_initrd()\n");
538 prop = (u64 *)get_property(of_chosen, "linux,initrd-start", NULL);
540 initrd_start = (unsigned long)__va(*prop);
541 prop = (u64 *)get_property(of_chosen, "linux,initrd-end", NULL);
543 initrd_end = (unsigned long)__va(*prop);
544 initrd_below_start_ok = 1;
549 /* If we were passed an initrd, set the ROOT_DEV properly if the values
550 * look sensible. If not, clear initrd reference.
552 if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
553 initrd_end > initrd_start)
554 ROOT_DEV = Root_RAM0;
556 initrd_start = initrd_end = 0;
559 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
561 DBG(" <- check_for_initrd()\n");
562 #endif /* CONFIG_BLK_DEV_INITRD */
565 #endif /* CONFIG_PPC_MULTIPLATFORM */
568 * Do some initial setup of the system. The parameters are those which
569 * were passed in from the bootloader.
571 void __init setup_system(void)
573 DBG(" -> setup_system()\n");
575 #ifdef CONFIG_PPC_ISERIES
576 /* pSeries systems are identified in prom.c via OF. */
577 if (itLpNaca.xLparInstalled == 1)
578 systemcfg->platform = PLATFORM_ISERIES_LPAR;
581 #else /* CONFIG_PPC_ISERIES */
584 * Unflatten the device-tree passed by prom_init or kexec
586 unflatten_device_tree();
589 * Fill the naca & systemcfg structures with informations
590 * retreived from the device-tree. Need to be called before
591 * finish_device_tree() since the later requires some of the
592 * informations filled up here to properly parse the interrupt
594 * It also sets up the cache line sizes which allows to call
595 * routines like flush_icache_range (used by the hash init
600 #ifdef CONFIG_PPC_PSERIES
602 * Initialize RTAS if available
605 #endif /* CONFIG_PPC_PSERIES */
608 * Check if we have an initrd provided via the device-tree
613 * Do some platform specific early initializations, that includes
614 * setting up the hash table pointers. It also sets up some interrupt-mapping
615 * related options that will be used by finish_device_tree()
620 * "Finish" the device-tree, that is do the actual parsing of
621 * some of the properties like the interrupt map
623 finish_device_tree();
628 #ifdef CONFIG_XMON_DEFAULT
632 * Register early console
634 early_console_initialized = 1;
635 register_console(&udbg_console);
637 #endif /* !CONFIG_PPC_ISERIES */
639 /* Save unparsed command line copy for /proc/cmdline */
640 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
644 #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_ISERIES)
646 * iSeries has already initialized the cpu maps at this point.
650 /* Release secondary cpus out of their spinloops at 0x60 now that
651 * we can map physical -> logical CPU ids
654 #endif /* defined(CONFIG_SMP) && !defined(CONFIG_PPC_ISERIES) */
656 printk("Starting Linux PPC64 %s\n", UTS_RELEASE);
658 printk("-----------------------------------------------------\n");
659 printk("naca = 0x%p\n", naca);
660 printk("naca->pftSize = 0x%lx\n", naca->pftSize);
661 printk("naca->debug_switch = 0x%lx\n", naca->debug_switch);
662 printk("naca->interrupt_controller = 0x%ld\n", naca->interrupt_controller);
663 printk("systemcfg = 0x%p\n", systemcfg);
664 printk("systemcfg->platform = 0x%x\n", systemcfg->platform);
665 printk("systemcfg->processorCount = 0x%lx\n", systemcfg->processorCount);
666 printk("systemcfg->physicalMemorySize = 0x%lx\n", systemcfg->physicalMemorySize);
667 printk("systemcfg->dCacheL1LineSize = 0x%x\n", systemcfg->dCacheL1LineSize);
668 printk("systemcfg->iCacheL1LineSize = 0x%x\n", systemcfg->iCacheL1LineSize);
669 printk("htab_data.htab = 0x%p\n", htab_data.htab);
670 printk("htab_data.num_ptegs = 0x%lx\n", htab_data.htab_num_ptegs);
671 printk("-----------------------------------------------------\n");
675 DBG(" <- setup_system()\n");
679 void machine_restart(char *cmd)
681 if (ppc_md.nvram_sync)
686 EXPORT_SYMBOL(machine_restart);
688 void machine_power_off(void)
690 if (ppc_md.nvram_sync)
695 EXPORT_SYMBOL(machine_power_off);
697 void machine_halt(void)
699 if (ppc_md.nvram_sync)
704 EXPORT_SYMBOL(machine_halt);
706 unsigned long ppc_proc_freq;
707 unsigned long ppc_tb_freq;
709 static int ppc64_panic_event(struct notifier_block *this,
710 unsigned long event, void *ptr)
712 ppc_md.panic((char *)ptr); /* May not return */
718 DEFINE_PER_CPU(unsigned int, pvr);
721 static int show_cpuinfo(struct seq_file *m, void *v)
723 unsigned long cpu_id = (unsigned long)v - 1;
728 if (cpu_id == NR_CPUS) {
729 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
731 if (ppc_md.get_cpuinfo != NULL)
732 ppc_md.get_cpuinfo(m);
737 /* We only show online cpus: disable preempt (overzealous, I
738 * knew) to prevent cpu going down. */
740 if (!cpu_online(cpu_id)) {
746 pvr = per_cpu(pvr, cpu_id);
748 pvr = mfspr(SPRN_PVR);
750 maj = (pvr >> 8) & 0xFF;
753 seq_printf(m, "processor\t: %lu\n", cpu_id);
754 seq_printf(m, "cpu\t\t: ");
756 if (cur_cpu_spec->pvr_mask)
757 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
759 seq_printf(m, "unknown (%08x)", pvr);
761 #ifdef CONFIG_ALTIVEC
762 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
763 seq_printf(m, ", altivec supported");
764 #endif /* CONFIG_ALTIVEC */
769 * Assume here that all clock rates are the same in a
770 * smp system. -- Cort
772 seq_printf(m, "clock\t\t: %lu.%06luMHz\n", ppc_proc_freq / 1000000,
773 ppc_proc_freq % 1000000);
775 seq_printf(m, "revision\t: %hd.%hd\n\n", maj, min);
781 static void *c_start(struct seq_file *m, loff_t *pos)
783 return *pos <= NR_CPUS ? (void *)((*pos)+1) : NULL;
785 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
788 return c_start(m, pos);
790 static void c_stop(struct seq_file *m, void *v)
793 struct seq_operations cpuinfo_op = {
797 .show = show_cpuinfo,
800 #if 0 /* XXX not currently used */
801 unsigned long memory_limit;
803 static int __init early_parsemem(char *p)
808 memory_limit = memparse(p, &p);
812 early_param("mem", early_parsemem);
815 #ifdef CONFIG_PPC_MULTIPLATFORM
816 static int __init set_preferred_console(void)
818 struct device_node *prom_stdout = NULL;
823 DBG(" -> set_preferred_console()\n");
825 /* The user has requested a console so this is already set up. */
826 if (strstr(saved_command_line, "console=")) {
827 DBG(" console was specified !\n");
832 DBG(" of_chosen is NULL !\n");
835 /* We are getting a weird phandle from OF ... */
836 /* ... So use the full path instead */
837 name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
839 DBG(" no linux,stdout-path !\n");
842 prom_stdout = of_find_node_by_path(name);
844 DBG(" can't find stdout package %s !\n", name);
847 DBG("stdout is %s\n", prom_stdout->full_name);
849 name = (char *)get_property(prom_stdout, "name", NULL);
851 DBG(" stdout package has no name !\n");
854 spd = (u32 *)get_property(prom_stdout, "current-speed", NULL);
858 #ifdef CONFIG_SERIAL_8250_CONSOLE
859 else if (strcmp(name, "serial") == 0) {
861 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
877 /* We dont recognise the serial port */
882 #endif /* CONFIG_SERIAL_8250_CONSOLE */
883 #ifdef CONFIG_PPC_PSERIES
884 else if (strcmp(name, "vty") == 0) {
885 u32 *reg = (u32 *)get_property(prom_stdout, "reg", NULL);
886 char *compat = (char *)get_property(prom_stdout, "compatible", NULL);
888 if (reg && compat && (strcmp(compat, "hvterm-protocol") == 0)) {
889 /* Host Virtual Serial Interface */
901 of_node_put(prom_stdout);
902 DBG("Found hvsi console at offset %d\n", offset);
903 return add_preferred_console("hvsi", offset, NULL);
905 /* pSeries LPAR virtual console */
906 of_node_put(prom_stdout);
907 DBG("Found hvc console\n");
908 return add_preferred_console("hvc", 0, NULL);
911 #endif /* CONFIG_PPC_PSERIES */
912 #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
913 else if (strcmp(name, "ch-a") == 0)
915 else if (strcmp(name, "ch-b") == 0)
917 #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
920 of_node_put(prom_stdout);
922 DBG("Found serial console at ttyS%d\n", offset);
925 static char __initdata opt[16];
926 sprintf(opt, "%d", *spd);
927 return add_preferred_console("ttyS", offset, opt);
929 return add_preferred_console("ttyS", offset, NULL);
932 DBG("No preferred console found !\n");
933 of_node_put(prom_stdout);
936 console_initcall(set_preferred_console);
937 #endif /* CONFIG_PPC_MULTIPLATFORM */
939 #ifdef CONFIG_IRQSTACKS
940 static void __init irqstack_early_init(void)
945 * interrupt stacks must be under 256MB, we cannot afford to take
946 * SLB misses on them.
949 softirq_ctx[i] = (struct thread_info *)__va(lmb_alloc_base(THREAD_SIZE,
950 THREAD_SIZE, 0x10000000));
951 hardirq_ctx[i] = (struct thread_info *)__va(lmb_alloc_base(THREAD_SIZE,
952 THREAD_SIZE, 0x10000000));
956 #define irqstack_early_init()
960 * Stack space used when we detect a bad kernel stack pointer, and
961 * early in SMP boots before relocation is enabled.
963 static void __init emergency_stack_init(void)
969 * Emergency stacks must be under 256MB, we cannot afford to take
970 * SLB misses on them. The ABI also requires them to be 128-byte
973 * Since we use these as temporary stacks during secondary CPU
974 * bringup, we need to get at them in real mode. This means they
975 * must also be within the RMO region.
977 limit = min(0x10000000UL, lmb.rmo_size);
980 paca[i].emergency_sp = __va(lmb_alloc_base(PAGE_SIZE, 128,
985 * Called into from start_kernel, after lock_kernel has been called.
986 * Initializes bootmem, which is unsed to manage page allocation until
987 * mem_init is called.
989 void __init setup_arch(char **cmdline_p)
991 extern int panic_timeout;
992 extern void do_init_bootmem(void);
994 ppc64_boot_msg(0x12, "Setup Arch");
996 *cmdline_p = cmd_line;
999 * Set cache line size based on type of cpu as a default.
1000 * Systems with OF can look in the properties on the cpu node(s)
1001 * for a possibly more accurate value.
1003 dcache_bsize = systemcfg->dCacheL1LineSize;
1004 icache_bsize = systemcfg->iCacheL1LineSize;
1006 /* reboot on panic */
1007 panic_timeout = 180;
1010 notifier_chain_register(&panic_notifier_list, &ppc64_panic_block);
1012 init_mm.start_code = PAGE_OFFSET;
1013 init_mm.end_code = (unsigned long) _etext;
1014 init_mm.end_data = (unsigned long) _edata;
1015 init_mm.brk = klimit;
1017 irqstack_early_init();
1018 emergency_stack_init();
1020 /* set up the bootmem stuff with available memory */
1023 ppc_md.setup_arch();
1025 /* Select the correct idle loop for the platform. */
1029 ppc64_boot_msg(0x15, "Setup Done");
1033 /* ToDo: do something useful if ppc_md is not yet setup. */
1034 #define PPC64_LINUX_FUNCTION 0x0f000000
1035 #define PPC64_IPL_MESSAGE 0xc0000000
1036 #define PPC64_TERM_MESSAGE 0xb0000000
1037 #define PPC64_ATTN_MESSAGE 0xa0000000
1038 #define PPC64_DUMP_MESSAGE 0xd0000000
1040 static void ppc64_do_msg(unsigned int src, const char *msg)
1042 if (ppc_md.progress) {
1045 sprintf(buf, "%08x \n", src);
1046 ppc_md.progress(buf, 0);
1047 sprintf(buf, "%-16s", msg);
1048 ppc_md.progress(buf, 0);
1052 /* Print a boot progress message. */
1053 void ppc64_boot_msg(unsigned int src, const char *msg)
1055 ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
1056 printk("[boot]%04x %s\n", src, msg);
1059 /* Print a termination message (print only -- does not stop the kernel) */
1060 void ppc64_terminate_msg(unsigned int src, const char *msg)
1062 ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_TERM_MESSAGE|src, msg);
1063 printk("[terminate]%04x %s\n", src, msg);
1066 /* Print something that needs attention (device error, etc) */
1067 void ppc64_attention_msg(unsigned int src, const char *msg)
1069 ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_ATTN_MESSAGE|src, msg);
1070 printk("[attention]%04x %s\n", src, msg);
1073 /* Print a dump progress message. */
1074 void ppc64_dump_msg(unsigned int src, const char *msg)
1076 ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_DUMP_MESSAGE|src, msg);
1077 printk("[dump]%04x %s\n", src, msg);
1080 int set_spread_lpevents( char * str )
1082 /* The parameter is the number of processors to share in processing lp events */
1084 unsigned long val = simple_strtoul( str, NULL, 0 );
1085 if ( ( val > 0 ) && ( val <= NR_CPUS ) ) {
1086 for ( i=1; i<val; ++i )
1087 paca[i].lpqueue_ptr = paca[0].lpqueue_ptr;
1088 printk("lpevent processing spread over %ld processors\n", val);
1091 printk("invalid spreaqd_lpevents %ld\n", val);
1095 /* This should only be called on processor 0 during calibrate decr */
1096 void setup_default_decr(void)
1098 struct paca_struct *lpaca = get_paca();
1100 if ( decr_overclock_set && !decr_overclock_proc0_set )
1101 decr_overclock_proc0 = decr_overclock;
1103 lpaca->default_decr = tb_ticks_per_jiffy / decr_overclock_proc0;
1104 lpaca->next_jiffy_update_tb = get_tb() + tb_ticks_per_jiffy;
1107 int set_decr_overclock_proc0( char * str )
1109 unsigned long val = simple_strtoul( str, NULL, 0 );
1110 if ( ( val >= 1 ) && ( val <= 48 ) ) {
1111 decr_overclock_proc0_set = 1;
1112 decr_overclock_proc0 = val;
1113 printk("proc 0 decrementer overclock factor of %ld\n", val);
1116 printk("invalid proc 0 decrementer overclock factor of %ld\n", val);
1120 int set_decr_overclock( char * str )
1122 unsigned long val = simple_strtoul( str, NULL, 0 );
1123 if ( ( val >= 1 ) && ( val <= 48 ) ) {
1124 decr_overclock_set = 1;
1125 decr_overclock = val;
1126 printk("decrementer overclock factor of %ld\n", val);
1129 printk("invalid decrementer overclock factor of %ld\n", val);
1134 __setup("spread_lpevents=", set_spread_lpevents );
1135 __setup("decr_overclock_proc0=", set_decr_overclock_proc0 );
1136 __setup("decr_overclock=", set_decr_overclock );
1138 #ifndef CONFIG_PPC_ISERIES
1140 * This function can be used by platforms to "find" legacy serial ports.
1141 * It works for "serial" nodes under an "isa" node, and will try to
1142 * respect the "ibm,aix-loc" property if any. It works with up to 8
1146 #define MAX_LEGACY_SERIAL_PORTS 8
1147 static struct plat_serial8250_port serial_ports[MAX_LEGACY_SERIAL_PORTS+1];
1148 static unsigned int old_serial_count;
1150 void __init generic_find_legacy_serial_ports(unsigned int *default_speed)
1152 struct device_node *np;
1155 struct isa_reg_property {
1160 struct pci_reg_property {
1161 struct pci_address addr;
1166 DBG(" -> generic_find_legacy_serial_port()\n");
1168 naca->serialPortAddr = 0;
1172 np = of_find_node_by_path("/");
1176 /* First fill our array */
1177 for (np = NULL; (np = of_find_node_by_type(np, "serial"));) {
1178 struct device_node *isa, *pci;
1179 struct isa_reg_property *reg;
1180 unsigned long phys_size, addr_size, io_base;
1182 u32 *interrupts, *clk, *spd;
1184 int index, rlen, rentsize;
1186 /* Ok, first check if it's under an "isa" parent */
1187 isa = of_get_parent(np);
1188 if (!isa || strcmp(isa->name, "isa")) {
1189 DBG("%s: no isa parent found\n", np->full_name);
1193 /* Now look for an "ibm,aix-loc" property that gives us ordering
1196 typep = (char *)get_property(np, "ibm,aix-loc", NULL);
1198 /* Get the ISA port number */
1199 reg = (struct isa_reg_property *)get_property(np, "reg", NULL);
1202 /* We assume the interrupt number isn't translated ... */
1203 interrupts = (u32 *)get_property(np, "interrupts", NULL);
1204 /* get clock freq. if present */
1205 clk = (u32 *)get_property(np, "clock-frequency", NULL);
1206 /* get default speed if present */
1207 spd = (u32 *)get_property(np, "current-speed", NULL);
1208 /* Default to locate at end of array */
1209 index = old_serial_count; /* end of the array by default */
1211 /* If we have a location index, then use it */
1212 if (typep && *typep == 'S') {
1213 index = simple_strtol(typep+1, NULL, 0) - 1;
1214 /* if index is out of range, use end of array instead */
1215 if (index >= MAX_LEGACY_SERIAL_PORTS)
1216 index = old_serial_count;
1217 /* if our index is still out of range, that mean that
1218 * array is full, we could scan for a free slot but that
1219 * make little sense to bother, just skip the port
1221 if (index >= MAX_LEGACY_SERIAL_PORTS)
1223 if (index >= old_serial_count)
1224 old_serial_count = index + 1;
1225 /* Check if there is a port who already claimed our slot */
1226 if (serial_ports[index].iobase != 0) {
1227 /* if we still have some room, move it, else override */
1228 if (old_serial_count < MAX_LEGACY_SERIAL_PORTS) {
1229 DBG("Moved legacy port %d -> %d\n", index,
1231 serial_ports[old_serial_count++] =
1232 serial_ports[index];
1234 DBG("Replacing legacy port %d\n", index);
1238 if (index >= MAX_LEGACY_SERIAL_PORTS)
1240 if (index >= old_serial_count)
1241 old_serial_count = index + 1;
1243 /* Now fill the entry */
1244 memset(&serial_ports[index], 0, sizeof(struct plat_serial8250_port));
1245 serial_ports[index].uartclk = clk ? *clk : BASE_BAUD * 16;
1246 serial_ports[index].iobase = reg->address;
1247 serial_ports[index].irq = interrupts ? interrupts[0] : 0;
1248 serial_ports[index].flags = ASYNC_BOOT_AUTOCONF;
1250 DBG("Added legacy port, index: %d, port: %x, irq: %d, clk: %d\n",
1252 serial_ports[index].iobase,
1253 serial_ports[index].irq,
1254 serial_ports[index].uartclk);
1256 /* Get phys address of IO reg for port 1 */
1260 pci = of_get_parent(isa);
1262 DBG("%s: no pci parent found\n", np->full_name);
1266 rangesp = (u32 *)get_property(pci, "ranges", &rlen);
1267 if (rangesp == NULL) {
1273 /* we need the #size-cells of the PCI bridge node itself */
1275 sizeprop = (u32 *)get_property(pci, "#size-cells", NULL);
1276 if (sizeprop != NULL)
1277 phys_size = *sizeprop;
1278 /* we need the parent #addr-cells */
1279 addr_size = prom_n_addr_cells(pci);
1280 rentsize = 3 + addr_size + phys_size;
1282 for (;rlen >= rentsize; rlen -= rentsize,rangesp += rentsize) {
1283 if (((rangesp[0] >> 24) & 0x3) != 1)
1284 continue; /* not IO space */
1285 io_base = rangesp[3];
1287 io_base = (io_base << 32) | rangesp[4];
1290 naca->serialPortAddr = io_base + reg->address;
1291 if (default_speed && spd)
1292 *default_speed = *spd;
1299 DBG(" <- generic_find_legacy_serial_port()\n");
1302 static struct platform_device serial_device = {
1303 .name = "serial8250",
1306 .platform_data = serial_ports,
1310 static int __init serial_dev_init(void)
1312 return platform_device_register(&serial_device);
1314 arch_initcall(serial_dev_init);
1316 #endif /* CONFIG_PPC_ISERIES */
1318 int check_legacy_ioport(unsigned long base_port)
1320 if (ppc_md.check_legacy_ioport == NULL)
1322 return ppc_md.check_legacy_ioport(base_port);
1324 EXPORT_SYMBOL(check_legacy_ioport);
1327 static int __init early_xmon(char *p)
1329 /* ensure xmon is enabled */
1335 early_param("xmon", early_xmon);
1342 local_irq_disable();