2 * Common boot and setup code for both 32-bit and 64-bit.
3 * Extracted from arch/powerpc/kernel/setup_64.c.
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/module.h>
16 #include <linux/string.h>
17 #include <linux/sched.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/reboot.h>
21 #include <linux/delay.h>
22 #include <linux/initrd.h>
23 #include <linux/platform_device.h>
24 #include <linux/seq_file.h>
25 #include <linux/ioport.h>
26 #include <linux/console.h>
27 #include <linux/utsname.h>
28 #include <linux/screen_info.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>
35 #include <linux/debugfs.h>
36 #include <linux/percpu.h>
37 #include <linux/lmb.h>
38 #include <linux/of_platform.h>
39 #include <linux/platform_device.h>
42 #include <asm/processor.h>
43 #include <asm/vdso_datapage.h>
44 #include <asm/pgtable.h>
47 #include <asm/machdep.h>
49 #include <asm/cputable.h>
50 #include <asm/sections.h>
51 #include <asm/firmware.h>
52 #include <asm/btext.h>
53 #include <asm/nvram.h>
54 #include <asm/setup.h>
55 #include <asm/system.h>
57 #include <asm/iommu.h>
58 #include <asm/serial.h>
59 #include <asm/cache.h>
63 #include <asm/cputhreads.h>
64 #include <mm/mmu_decl.h>
70 #define DBG(fmt...) udbg_printf(fmt)
75 /* The main machine-dep calls structure
77 struct machdep_calls ppc_md;
78 EXPORT_SYMBOL(ppc_md);
79 struct machdep_calls *machine_id;
80 EXPORT_SYMBOL(machine_id);
82 unsigned long klimit = (unsigned long) _end;
84 char cmd_line[COMMAND_LINE_SIZE];
87 * This still seems to be needed... -- paulus
89 struct screen_info screen_info = {
92 .orig_video_cols = 80,
93 .orig_video_lines = 25,
94 .orig_video_isVGA = 1,
95 .orig_video_points = 16
99 /* XXX should go elsewhere eventually */
100 int ppc_do_canonicalize_irqs;
101 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
104 /* also used by kexec */
105 void machine_shutdown(void)
107 if (ppc_md.machine_shutdown)
108 ppc_md.machine_shutdown();
111 void machine_restart(char *cmd)
119 printk(KERN_EMERG "System Halted, OK to turn off power\n");
124 void machine_power_off(void)
127 if (ppc_md.power_off)
132 printk(KERN_EMERG "System Halted, OK to turn off power\n");
136 /* Used by the G5 thermal driver */
137 EXPORT_SYMBOL_GPL(machine_power_off);
139 void (*pm_power_off)(void) = machine_power_off;
140 EXPORT_SYMBOL_GPL(pm_power_off);
142 void machine_halt(void)
150 printk(KERN_EMERG "System Halted, OK to turn off power\n");
157 extern u32 cpu_temp(unsigned long cpu);
158 extern u32 cpu_temp_both(unsigned long cpu);
159 #endif /* CONFIG_TAU */
162 DEFINE_PER_CPU(unsigned int, pvr);
165 static int show_cpuinfo(struct seq_file *m, void *v)
167 unsigned long cpu_id = (unsigned long)v - 1;
172 if (cpu_id == NR_CPUS) {
173 struct device_node *root;
174 const char *model = NULL;
175 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
176 unsigned long bogosum = 0;
178 for_each_online_cpu(i)
179 bogosum += loops_per_jiffy;
180 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
181 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
182 #endif /* CONFIG_SMP && CONFIG_PPC32 */
183 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
185 seq_printf(m, "platform\t: %s\n", ppc_md.name);
186 root = of_find_node_by_path("/");
188 model = of_get_property(root, "model", NULL);
190 seq_printf(m, "model\t\t: %s\n", model);
193 if (ppc_md.show_cpuinfo != NULL)
194 ppc_md.show_cpuinfo(m);
197 /* Display the amount of memory */
198 seq_printf(m, "Memory\t\t: %d MB\n",
199 (unsigned int)(total_memory / (1024 * 1024)));
205 /* We only show online cpus: disable preempt (overzealous, I
206 * knew) to prevent cpu going down. */
208 if (!cpu_online(cpu_id)) {
214 pvr = per_cpu(pvr, cpu_id);
216 pvr = mfspr(SPRN_PVR);
218 maj = (pvr >> 8) & 0xFF;
221 seq_printf(m, "processor\t: %lu\n", cpu_id);
222 seq_printf(m, "cpu\t\t: ");
224 if (cur_cpu_spec->pvr_mask)
225 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
227 seq_printf(m, "unknown (%08x)", pvr);
229 #ifdef CONFIG_ALTIVEC
230 if (cpu_has_feature(CPU_FTR_ALTIVEC))
231 seq_printf(m, ", altivec supported");
232 #endif /* CONFIG_ALTIVEC */
237 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
238 #ifdef CONFIG_TAU_AVERAGE
239 /* more straightforward, but potentially misleading */
240 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
243 /* show the actual temp sensor range */
245 temp = cpu_temp_both(cpu_id);
246 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
247 temp & 0xff, temp >> 16);
250 #endif /* CONFIG_TAU */
253 * Assume here that all clock rates are the same in a
254 * smp system. -- Cort
257 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
258 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
260 if (ppc_md.show_percpuinfo != NULL)
261 ppc_md.show_percpuinfo(m, cpu_id);
263 /* If we are a Freescale core do a simple check so
264 * we dont have to keep adding cases in the future */
265 if (PVR_VER(pvr) & 0x8000) {
266 switch (PVR_VER(pvr)) {
267 case 0x8000: /* 7441/7450/7451, Voyager */
268 case 0x8001: /* 7445/7455, Apollo 6 */
269 case 0x8002: /* 7447/7457, Apollo 7 */
270 case 0x8003: /* 7447A, Apollo 7 PM */
271 case 0x8004: /* 7448, Apollo 8 */
272 case 0x800c: /* 7410, Nitro */
273 maj = ((pvr >> 8) & 0xF);
276 default: /* e500/book-e */
282 switch (PVR_VER(pvr)) {
283 case 0x0020: /* 403 family */
284 maj = PVR_MAJ(pvr) + 1;
287 case 0x1008: /* 740P/750P ?? */
288 maj = ((pvr >> 8) & 0xFF) - 1;
292 maj = (pvr >> 8) & 0xFF;
298 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
299 maj, min, PVR_VER(pvr), PVR_REV(pvr));
302 seq_printf(m, "bogomips\t: %lu.%02lu\n",
303 loops_per_jiffy / (500000/HZ),
304 (loops_per_jiffy / (5000/HZ)) % 100);
315 static void *c_start(struct seq_file *m, loff_t *pos)
317 unsigned long i = *pos;
319 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
322 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
325 return c_start(m, pos);
328 static void c_stop(struct seq_file *m, void *v)
332 struct seq_operations cpuinfo_op = {
336 .show = show_cpuinfo,
339 void __init check_for_initrd(void)
341 #ifdef CONFIG_BLK_DEV_INITRD
342 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
343 initrd_start, initrd_end);
345 /* If we were passed an initrd, set the ROOT_DEV properly if the values
346 * look sensible. If not, clear initrd reference.
348 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
349 initrd_end > initrd_start)
350 ROOT_DEV = Root_RAM0;
352 initrd_start = initrd_end = 0;
355 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
357 DBG(" <- check_for_initrd()\n");
358 #endif /* CONFIG_BLK_DEV_INITRD */
363 int threads_per_core, threads_shift;
364 cpumask_t threads_core_mask;
366 static void __init cpu_init_thread_core_maps(int tpc)
370 threads_per_core = tpc;
371 threads_core_mask = CPU_MASK_NONE;
373 /* This implementation only supports power of 2 number of threads
374 * for simplicity and performance
376 threads_shift = ilog2(tpc);
377 BUG_ON(tpc != (1 << threads_shift));
379 for (i = 0; i < tpc; i++)
380 cpu_set(i, threads_core_mask);
382 printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n",
383 tpc, tpc > 1 ? "s" : "");
384 printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift);
389 * setup_cpu_maps - initialize the following cpu maps:
393 * Having the possible map set up early allows us to restrict allocations
394 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
396 * We do not initialize the online map here; cpus set their own bits in
397 * cpu_online_map as they come up.
399 * This function is valid only for Open Firmware systems. finish_device_tree
400 * must be called before using this.
402 * While we're here, we may as well set the "physical" cpu ids in the paca.
404 * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
406 void __init smp_setup_cpu_maps(void)
408 struct device_node *dn = NULL;
412 DBG("smp_setup_cpu_maps()\n");
414 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
418 DBG(" * %s...\n", dn->full_name);
420 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
423 nthreads = len / sizeof(int);
424 DBG(" ibm,ppc-interrupt-server#s -> %d threads\n",
427 DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n");
428 intserv = of_get_property(dn, "reg", NULL);
430 intserv = &cpu; /* assume logical == phys */
433 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
434 DBG(" thread %d -> cpu %d (hard id %d)\n",
436 cpu_set(cpu, cpu_present_map);
437 set_hard_smp_processor_id(cpu, intserv[j]);
438 cpu_set(cpu, cpu_possible_map);
443 /* If no SMT supported, nthreads is forced to 1 */
444 if (!cpu_has_feature(CPU_FTR_SMT)) {
445 DBG(" SMT disabled ! nthreads forced to 1\n");
451 * On pSeries LPAR, we need to know how many cpus
452 * could possibly be added to this partition.
454 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) &&
455 (dn = of_find_node_by_path("/rtas"))) {
456 int num_addr_cell, num_size_cell, maxcpus;
457 const unsigned int *ireg;
459 num_addr_cell = of_n_addr_cells(dn);
460 num_size_cell = of_n_size_cells(dn);
462 ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL);
467 maxcpus = ireg[num_addr_cell + num_size_cell];
469 /* Double maxcpus for processors which have SMT capability */
470 if (cpu_has_feature(CPU_FTR_SMT))
473 if (maxcpus > NR_CPUS) {
475 "Partition configured for %d cpus, "
476 "operating system maximum is %d.\n",
480 printk(KERN_INFO "Partition configured for %d cpus.\n",
483 for (cpu = 0; cpu < maxcpus; cpu++)
484 cpu_set(cpu, cpu_possible_map);
488 vdso_data->processorCount = num_present_cpus();
489 #endif /* CONFIG_PPC64 */
491 /* Initialize CPU <=> thread mapping/
493 * WARNING: We assume that the number of threads is the same for
494 * every CPU in the system. If that is not the case, then some code
495 * here will have to be reworked
497 cpu_init_thread_core_maps(nthreads);
499 #endif /* CONFIG_SMP */
501 #ifdef CONFIG_PCSPKR_PLATFORM
502 static __init int add_pcspkr(void)
504 struct device_node *np;
505 struct platform_device *pd;
508 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
513 pd = platform_device_alloc("pcspkr", -1);
517 ret = platform_device_add(pd);
519 platform_device_put(pd);
523 device_initcall(add_pcspkr);
524 #endif /* CONFIG_PCSPKR_PLATFORM */
526 void probe_machine(void)
528 extern struct machdep_calls __machine_desc_start;
529 extern struct machdep_calls __machine_desc_end;
532 * Iterate all ppc_md structures until we find the proper
533 * one for the current machine type
535 DBG("Probing machine type ...\n");
537 for (machine_id = &__machine_desc_start;
538 machine_id < &__machine_desc_end;
540 DBG(" %s ...", machine_id->name);
541 memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
542 if (ppc_md.probe()) {
548 /* What can we do if we didn't find ? */
549 if (machine_id >= &__machine_desc_end) {
550 DBG("No suitable machine found !\n");
554 printk(KERN_INFO "Using %s machine description\n", ppc_md.name);
557 /* Match a class of boards, not a specific device configuration. */
558 int check_legacy_ioport(unsigned long base_port)
560 struct device_node *parent, *np = NULL;
565 if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303")))
566 np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03");
568 parent = of_get_parent(np);
573 np = of_find_node_by_type(NULL, "8042");
574 /* Pegasos has no device_type on its 8042 node, look for the
577 np = of_find_node_by_name(NULL, "8042");
579 case FDC_BASE: /* FDC1 */
580 np = of_find_node_by_type(NULL, "fdc");
582 #ifdef CONFIG_PPC_PREP
589 /* ipmi is supposed to fail here */
594 parent = of_get_parent(np);
596 if (strcmp(parent->type, "isa") == 0)
603 EXPORT_SYMBOL(check_legacy_ioport);
605 static int ppc_panic_event(struct notifier_block *this,
606 unsigned long event, void *ptr)
608 ppc_md.panic(ptr); /* May not return */
612 static struct notifier_block ppc_panic_block = {
613 .notifier_call = ppc_panic_event,
614 .priority = INT_MIN /* may not return; must be done last */
617 void __init setup_panic(void)
619 atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block);
622 #ifdef CONFIG_CHECK_CACHE_COHERENCY
624 * For platforms that have configurable cache-coherency. This function
625 * checks that the cache coherency setting of the kernel matches the setting
626 * left by the firmware, as indicated in the device tree. Since a mismatch
627 * will eventually result in DMA failures, we print * and error and call
628 * BUG() in that case.
631 #ifdef CONFIG_NOT_COHERENT_CACHE
632 #define KERNEL_COHERENCY 0
634 #define KERNEL_COHERENCY 1
637 static int __init check_cache_coherency(void)
639 struct device_node *np;
641 int devtree_coherency;
643 np = of_find_node_by_path("/");
644 prop = of_get_property(np, "coherency-off", NULL);
647 devtree_coherency = prop ? 0 : 1;
649 if (devtree_coherency != KERNEL_COHERENCY) {
651 "kernel coherency:%s != device tree_coherency:%s\n",
652 KERNEL_COHERENCY ? "on" : "off",
653 devtree_coherency ? "on" : "off");
660 late_initcall(check_cache_coherency);
661 #endif /* CONFIG_CHECK_CACHE_COHERENCY */
663 #ifdef CONFIG_DEBUG_FS
664 struct dentry *powerpc_debugfs_root;
666 static int powerpc_debugfs_init(void)
668 powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL);
670 return powerpc_debugfs_root == NULL;
672 arch_initcall(powerpc_debugfs_init);
675 static int ppc_dflt_bus_notify(struct notifier_block *nb,
676 unsigned long action, void *data)
678 struct device *dev = data;
680 /* We are only intereted in device addition */
681 if (action != BUS_NOTIFY_ADD_DEVICE)
684 set_dma_ops(dev, &dma_direct_ops);
689 static struct notifier_block ppc_dflt_plat_bus_notifier = {
690 .notifier_call = ppc_dflt_bus_notify,
694 static struct notifier_block ppc_dflt_of_bus_notifier = {
695 .notifier_call = ppc_dflt_bus_notify,
699 static int __init setup_bus_notifier(void)
701 bus_register_notifier(&platform_bus_type, &ppc_dflt_plat_bus_notifier);
702 bus_register_notifier(&of_platform_bus_type, &ppc_dflt_of_bus_notifier);
707 arch_initcall(setup_bus_notifier);