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/ide.h>
25 #include <linux/seq_file.h>
26 #include <linux/ioport.h>
27 #include <linux/console.h>
28 #include <linux/utsname.h>
29 #include <linux/screen_info.h>
30 #include <linux/root_dev.h>
31 #include <linux/notifier.h>
32 #include <linux/cpu.h>
33 #include <linux/unistd.h>
34 #include <linux/serial.h>
35 #include <linux/serial_8250.h>
38 #include <asm/processor.h>
39 #include <asm/vdso_datapage.h>
40 #include <asm/pgtable.h>
43 #include <asm/machdep.h>
45 #include <asm/cputable.h>
46 #include <asm/sections.h>
47 #include <asm/firmware.h>
48 #include <asm/btext.h>
49 #include <asm/nvram.h>
50 #include <asm/setup.h>
51 #include <asm/system.h>
53 #include <asm/iommu.h>
54 #include <asm/serial.h>
55 #include <asm/cache.h>
65 #define DBG(fmt...) udbg_printf(fmt)
70 /* The main machine-dep calls structure
72 struct machdep_calls ppc_md;
73 EXPORT_SYMBOL(ppc_md);
74 struct machdep_calls *machine_id;
75 EXPORT_SYMBOL(machine_id);
77 unsigned long klimit = (unsigned long) _end;
80 * This still seems to be needed... -- paulus
82 struct screen_info screen_info = {
85 .orig_video_cols = 80,
86 .orig_video_lines = 25,
87 .orig_video_isVGA = 1,
88 .orig_video_points = 16
92 /* XXX should go elsewhere eventually */
93 int ppc_do_canonicalize_irqs;
94 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
97 /* also used by kexec */
98 void machine_shutdown(void)
100 if (ppc_md.machine_shutdown)
101 ppc_md.machine_shutdown();
104 void machine_restart(char *cmd)
112 printk(KERN_EMERG "System Halted, OK to turn off power\n");
117 void machine_power_off(void)
120 if (ppc_md.power_off)
125 printk(KERN_EMERG "System Halted, OK to turn off power\n");
129 /* Used by the G5 thermal driver */
130 EXPORT_SYMBOL_GPL(machine_power_off);
132 void (*pm_power_off)(void) = machine_power_off;
133 EXPORT_SYMBOL_GPL(pm_power_off);
135 void machine_halt(void)
143 printk(KERN_EMERG "System Halted, OK to turn off power\n");
150 extern u32 cpu_temp(unsigned long cpu);
151 extern u32 cpu_temp_both(unsigned long cpu);
152 #endif /* CONFIG_TAU */
155 DEFINE_PER_CPU(unsigned int, pvr);
158 static int show_cpuinfo(struct seq_file *m, void *v)
160 unsigned long cpu_id = (unsigned long)v - 1;
165 if (cpu_id == NR_CPUS) {
166 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
167 unsigned long bogosum = 0;
169 for_each_online_cpu(i)
170 bogosum += loops_per_jiffy;
171 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
172 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
173 #endif /* CONFIG_SMP && CONFIG_PPC32 */
174 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
176 seq_printf(m, "platform\t: %s\n", ppc_md.name);
177 if (ppc_md.show_cpuinfo != NULL)
178 ppc_md.show_cpuinfo(m);
183 /* We only show online cpus: disable preempt (overzealous, I
184 * knew) to prevent cpu going down. */
186 if (!cpu_online(cpu_id)) {
192 pvr = per_cpu(pvr, cpu_id);
194 pvr = mfspr(SPRN_PVR);
196 maj = (pvr >> 8) & 0xFF;
199 seq_printf(m, "processor\t: %lu\n", cpu_id);
200 seq_printf(m, "cpu\t\t: ");
202 if (cur_cpu_spec->pvr_mask)
203 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
205 seq_printf(m, "unknown (%08x)", pvr);
207 #ifdef CONFIG_ALTIVEC
208 if (cpu_has_feature(CPU_FTR_ALTIVEC))
209 seq_printf(m, ", altivec supported");
210 #endif /* CONFIG_ALTIVEC */
215 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
216 #ifdef CONFIG_TAU_AVERAGE
217 /* more straightforward, but potentially misleading */
218 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
221 /* show the actual temp sensor range */
223 temp = cpu_temp_both(cpu_id);
224 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
225 temp & 0xff, temp >> 16);
228 #endif /* CONFIG_TAU */
231 * Assume here that all clock rates are the same in a
232 * smp system. -- Cort
235 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
236 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
238 if (ppc_md.show_percpuinfo != NULL)
239 ppc_md.show_percpuinfo(m, cpu_id);
241 /* If we are a Freescale core do a simple check so
242 * we dont have to keep adding cases in the future */
243 if (PVR_VER(pvr) & 0x8000) {
247 switch (PVR_VER(pvr)) {
248 case 0x0020: /* 403 family */
249 maj = PVR_MAJ(pvr) + 1;
252 case 0x1008: /* 740P/750P ?? */
253 maj = ((pvr >> 8) & 0xFF) - 1;
257 maj = (pvr >> 8) & 0xFF;
263 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
264 maj, min, PVR_VER(pvr), PVR_REV(pvr));
267 seq_printf(m, "bogomips\t: %lu.%02lu\n",
268 loops_per_jiffy / (500000/HZ),
269 (loops_per_jiffy / (5000/HZ)) % 100);
280 static void *c_start(struct seq_file *m, loff_t *pos)
282 unsigned long i = *pos;
284 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
287 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
290 return c_start(m, pos);
293 static void c_stop(struct seq_file *m, void *v)
297 struct seq_operations cpuinfo_op = {
301 .show = show_cpuinfo,
304 void __init check_for_initrd(void)
306 #ifdef CONFIG_BLK_DEV_INITRD
309 DBG(" -> check_for_initrd()\n");
312 prop = (unsigned long *)get_property(of_chosen,
313 "linux,initrd-start", NULL);
315 initrd_start = (unsigned long)__va(*prop);
316 prop = (unsigned long *)get_property(of_chosen,
317 "linux,initrd-end", NULL);
319 initrd_end = (unsigned long)__va(*prop);
320 initrd_below_start_ok = 1;
326 /* If we were passed an initrd, set the ROOT_DEV properly if the values
327 * look sensible. If not, clear initrd reference.
329 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
330 initrd_end > initrd_start)
331 ROOT_DEV = Root_RAM0;
333 initrd_start = initrd_end = 0;
336 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
338 DBG(" <- check_for_initrd()\n");
339 #endif /* CONFIG_BLK_DEV_INITRD */
345 * setup_cpu_maps - initialize the following cpu maps:
350 * Having the possible map set up early allows us to restrict allocations
351 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
353 * We do not initialize the online map here; cpus set their own bits in
354 * cpu_online_map as they come up.
356 * This function is valid only for Open Firmware systems. finish_device_tree
357 * must be called before using this.
359 * While we're here, we may as well set the "physical" cpu ids in the paca.
361 * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
363 void __init smp_setup_cpu_maps(void)
365 struct device_node *dn = NULL;
368 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
370 int j, len = sizeof(u32), nthreads = 1;
372 intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
375 nthreads = len / sizeof(int);
377 intserv = (int *) get_property(dn, "reg", NULL);
379 intserv = &cpu; /* assume logical == phys */
382 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
383 cpu_set(cpu, cpu_present_map);
384 set_hard_smp_processor_id(cpu, intserv[j]);
385 cpu_set(cpu, cpu_possible_map);
392 * On pSeries LPAR, we need to know how many cpus
393 * could possibly be added to this partition.
395 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) &&
396 (dn = of_find_node_by_path("/rtas"))) {
397 int num_addr_cell, num_size_cell, maxcpus;
400 num_addr_cell = prom_n_addr_cells(dn);
401 num_size_cell = prom_n_size_cells(dn);
403 ireg = (unsigned int *)
404 get_property(dn, "ibm,lrdr-capacity", NULL);
409 maxcpus = ireg[num_addr_cell + num_size_cell];
411 /* Double maxcpus for processors which have SMT capability */
412 if (cpu_has_feature(CPU_FTR_SMT))
415 if (maxcpus > NR_CPUS) {
417 "Partition configured for %d cpus, "
418 "operating system maximum is %d.\n",
422 printk(KERN_INFO "Partition configured for %d cpus.\n",
425 for (cpu = 0; cpu < maxcpus; cpu++)
426 cpu_set(cpu, cpu_possible_map);
432 * Do the sibling map; assume only two threads per processor.
434 for_each_possible_cpu(cpu) {
435 cpu_set(cpu, cpu_sibling_map[cpu]);
436 if (cpu_has_feature(CPU_FTR_SMT))
437 cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
440 vdso_data->processorCount = num_present_cpus();
441 #endif /* CONFIG_PPC64 */
443 #endif /* CONFIG_SMP */
445 int __initdata do_early_xmon;
447 static int __init early_xmon(char *p)
449 /* ensure xmon is enabled */
451 if (strncmp(p, "on", 2) == 0)
453 if (strncmp(p, "off", 3) == 0)
455 if (strncmp(p, "early", 5) != 0)
463 early_param("xmon", early_xmon);
466 static __init int add_pcspkr(void)
468 struct device_node *np;
469 struct platform_device *pd;
472 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
477 pd = platform_device_alloc("pcspkr", -1);
481 ret = platform_device_add(pd);
483 platform_device_put(pd);
487 device_initcall(add_pcspkr);
489 void probe_machine(void)
491 extern struct machdep_calls __machine_desc_start;
492 extern struct machdep_calls __machine_desc_end;
495 * Iterate all ppc_md structures until we find the proper
496 * one for the current machine type
498 DBG("Probing machine type ...\n");
500 for (machine_id = &__machine_desc_start;
501 machine_id < &__machine_desc_end;
503 DBG(" %s ...", machine_id->name);
504 memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
505 if (ppc_md.probe()) {
511 /* What can we do if we didn't find ? */
512 if (machine_id >= &__machine_desc_end) {
513 DBG("No suitable machine found !\n");
517 printk(KERN_INFO "Using %s machine description\n", ppc_md.name);
520 int check_legacy_ioport(unsigned long base_port)
522 if (ppc_md.check_legacy_ioport == NULL)
524 return ppc_md.check_legacy_ioport(base_port);
526 EXPORT_SYMBOL(check_legacy_ioport);
528 static int ppc_panic_event(struct notifier_block *this,
529 unsigned long event, void *ptr)
531 ppc_md.panic(ptr); /* May not return */
535 static struct notifier_block ppc_panic_block = {
536 .notifier_call = ppc_panic_event,
537 .priority = INT_MIN /* may not return; must be done last */
540 void __init setup_panic(void)
542 atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block);