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.
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/string.h>
15 #include <linux/sched.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/reboot.h>
19 #include <linux/delay.h>
20 #include <linux/initrd.h>
21 #include <linux/ide.h>
22 #include <linux/seq_file.h>
23 #include <linux/ioport.h>
24 #include <linux/console.h>
25 #include <linux/utsname.h>
26 #include <linux/tty.h>
27 #include <linux/root_dev.h>
28 #include <linux/notifier.h>
29 #include <linux/cpu.h>
30 #include <linux/unistd.h>
31 #include <linux/serial.h>
32 #include <linux/serial_8250.h>
35 #include <asm/processor.h>
36 #include <asm/pgtable.h>
39 #include <asm/machdep.h>
41 #include <asm/cputable.h>
42 #include <asm/sections.h>
43 #include <asm/btext.h>
44 #include <asm/nvram.h>
45 #include <asm/setup.h>
46 #include <asm/system.h>
48 #include <asm/iommu.h>
49 #include <asm/serial.h>
50 #include <asm/cache.h>
58 #define DBG(fmt...) udbg_printf(fmt)
64 * This still seems to be needed... -- paulus
66 struct screen_info screen_info = {
69 .orig_video_cols = 80,
70 .orig_video_lines = 25,
71 .orig_video_isVGA = 1,
72 .orig_video_points = 16
76 /* XXX should go elsewhere eventually */
77 int ppc_do_canonicalize_irqs;
78 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
81 /* also used by kexec */
82 void machine_shutdown(void)
84 if (ppc_md.nvram_sync)
88 void machine_restart(char *cmd)
95 printk(KERN_EMERG "System Halted, OK to turn off power\n");
100 void machine_power_off(void)
107 printk(KERN_EMERG "System Halted, OK to turn off power\n");
111 /* Used by the G5 thermal driver */
112 EXPORT_SYMBOL_GPL(machine_power_off);
114 void (*pm_power_off)(void) = machine_power_off;
115 EXPORT_SYMBOL_GPL(pm_power_off);
117 void machine_halt(void)
124 printk(KERN_EMERG "System Halted, OK to turn off power\n");
131 extern u32 cpu_temp(unsigned long cpu);
132 extern u32 cpu_temp_both(unsigned long cpu);
133 #endif /* CONFIG_TAU */
136 DEFINE_PER_CPU(unsigned int, pvr);
139 static int show_cpuinfo(struct seq_file *m, void *v)
141 unsigned long cpu_id = (unsigned long)v - 1;
146 if (cpu_id == NR_CPUS) {
147 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
148 unsigned long bogosum = 0;
150 for (i = 0; i < NR_CPUS; ++i)
152 bogosum += loops_per_jiffy;
153 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
154 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
155 #endif /* CONFIG_SMP && CONFIG_PPC32 */
156 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
158 if (ppc_md.show_cpuinfo != NULL)
159 ppc_md.show_cpuinfo(m);
164 /* We only show online cpus: disable preempt (overzealous, I
165 * knew) to prevent cpu going down. */
167 if (!cpu_online(cpu_id)) {
173 pvr = per_cpu(pvr, cpu_id);
175 pvr = mfspr(SPRN_PVR);
177 maj = (pvr >> 8) & 0xFF;
180 seq_printf(m, "processor\t: %lu\n", cpu_id);
181 seq_printf(m, "cpu\t\t: ");
183 if (cur_cpu_spec->pvr_mask)
184 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
186 seq_printf(m, "unknown (%08x)", pvr);
188 #ifdef CONFIG_ALTIVEC
189 if (cpu_has_feature(CPU_FTR_ALTIVEC))
190 seq_printf(m, ", altivec supported");
191 #endif /* CONFIG_ALTIVEC */
196 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
197 #ifdef CONFIG_TAU_AVERAGE
198 /* more straightforward, but potentially misleading */
199 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
202 /* show the actual temp sensor range */
204 temp = cpu_temp_both(cpu_id);
205 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
206 temp & 0xff, temp >> 16);
209 #endif /* CONFIG_TAU */
212 * Assume here that all clock rates are the same in a
213 * smp system. -- Cort
216 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
217 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
219 if (ppc_md.show_percpuinfo != NULL)
220 ppc_md.show_percpuinfo(m, cpu_id);
222 /* If we are a Freescale core do a simple check so
223 * we dont have to keep adding cases in the future */
224 if (PVR_VER(pvr) & 0x8000) {
228 switch (PVR_VER(pvr)) {
229 case 0x0020: /* 403 family */
230 maj = PVR_MAJ(pvr) + 1;
233 case 0x1008: /* 740P/750P ?? */
234 maj = ((pvr >> 8) & 0xFF) - 1;
238 maj = (pvr >> 8) & 0xFF;
244 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
245 maj, min, PVR_VER(pvr), PVR_REV(pvr));
248 seq_printf(m, "bogomips\t: %lu.%02lu\n",
249 loops_per_jiffy / (500000/HZ),
250 (loops_per_jiffy / (5000/HZ)) % 100);
261 static void *c_start(struct seq_file *m, loff_t *pos)
263 unsigned long i = *pos;
265 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
268 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
271 return c_start(m, pos);
274 static void c_stop(struct seq_file *m, void *v)
278 struct seq_operations cpuinfo_op = {
282 .show = show_cpuinfo,
285 #ifdef CONFIG_PPC_MULTIPLATFORM
286 static int __init set_preferred_console(void)
288 struct device_node *prom_stdout = NULL;
293 DBG(" -> set_preferred_console()\n");
295 /* The user has requested a console so this is already set up. */
296 if (strstr(saved_command_line, "console=")) {
297 DBG(" console was specified !\n");
302 DBG(" of_chosen is NULL !\n");
305 /* We are getting a weird phandle from OF ... */
306 /* ... So use the full path instead */
307 name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
309 DBG(" no linux,stdout-path !\n");
312 prom_stdout = of_find_node_by_path(name);
314 DBG(" can't find stdout package %s !\n", name);
317 DBG("stdout is %s\n", prom_stdout->full_name);
319 name = (char *)get_property(prom_stdout, "name", NULL);
321 DBG(" stdout package has no name !\n");
324 spd = (u32 *)get_property(prom_stdout, "current-speed", NULL);
328 #ifdef CONFIG_SERIAL_8250_CONSOLE
329 else if (strcmp(name, "serial") == 0) {
331 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
347 /* We dont recognise the serial port */
352 #endif /* CONFIG_SERIAL_8250_CONSOLE */
353 #ifdef CONFIG_PPC_PSERIES
354 else if (strcmp(name, "vty") == 0) {
355 u32 *reg = (u32 *)get_property(prom_stdout, "reg", NULL);
356 char *compat = (char *)get_property(prom_stdout, "compatible", NULL);
358 if (reg && compat && (strcmp(compat, "hvterm-protocol") == 0)) {
359 /* Host Virtual Serial Interface */
370 of_node_put(prom_stdout);
371 DBG("Found hvsi console at offset %d\n", offset);
372 return add_preferred_console("hvsi", offset, NULL);
374 /* pSeries LPAR virtual console */
375 of_node_put(prom_stdout);
376 DBG("Found hvc console\n");
377 return add_preferred_console("hvc", 0, NULL);
380 #endif /* CONFIG_PPC_PSERIES */
381 #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
382 else if (strcmp(name, "ch-a") == 0)
384 else if (strcmp(name, "ch-b") == 0)
386 #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
389 of_node_put(prom_stdout);
391 DBG("Found serial console at ttyS%d\n", offset);
394 static char __initdata opt[16];
395 sprintf(opt, "%d", *spd);
396 return add_preferred_console("ttyS", offset, opt);
398 return add_preferred_console("ttyS", offset, NULL);
401 DBG("No preferred console found !\n");
402 of_node_put(prom_stdout);
405 console_initcall(set_preferred_console);
406 #endif /* CONFIG_PPC_MULTIPLATFORM */
408 void __init check_for_initrd(void)
410 #ifdef CONFIG_BLK_DEV_INITRD
413 DBG(" -> check_for_initrd()\n");
416 prop = (unsigned long *)get_property(of_chosen,
417 "linux,initrd-start", NULL);
419 initrd_start = (unsigned long)__va(*prop);
420 prop = (unsigned long *)get_property(of_chosen,
421 "linux,initrd-end", NULL);
423 initrd_end = (unsigned long)__va(*prop);
424 initrd_below_start_ok = 1;
430 /* If we were passed an initrd, set the ROOT_DEV properly if the values
431 * look sensible. If not, clear initrd reference.
433 if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
434 initrd_end > initrd_start)
435 ROOT_DEV = Root_RAM0;
437 printk("Bogus initrd %08lx %08lx\n", initrd_start, initrd_end);
438 initrd_start = initrd_end = 0;
442 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
444 DBG(" <- check_for_initrd()\n");
445 #endif /* CONFIG_BLK_DEV_INITRD */
451 * setup_cpu_maps - initialize the following cpu maps:
456 * Having the possible map set up early allows us to restrict allocations
457 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
459 * We do not initialize the online map here; cpus set their own bits in
460 * cpu_online_map as they come up.
462 * This function is valid only for Open Firmware systems. finish_device_tree
463 * must be called before using this.
465 * While we're here, we may as well set the "physical" cpu ids in the paca.
467 void __init smp_setup_cpu_maps(void)
469 struct device_node *dn = NULL;
473 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
475 int j, len = sizeof(u32), nthreads = 1;
477 intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
480 nthreads = len / sizeof(int);
482 intserv = (int *) get_property(dn, "reg", NULL);
484 intserv = &cpu; /* assume logical == phys */
487 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
488 cpu_set(cpu, cpu_present_map);
489 set_hard_smp_processor_id(cpu, intserv[j]);
491 if (intserv[j] == boot_cpuid_phys)
493 cpu_set(cpu, cpu_possible_map);
498 /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
499 * boot cpu is logical 0.
501 if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
503 tmp = get_hard_smp_processor_id(0);
504 set_hard_smp_processor_id(0, boot_cpuid_phys);
505 set_hard_smp_processor_id(swap_cpuid, tmp);
510 * On pSeries LPAR, we need to know how many cpus
511 * could possibly be added to this partition.
513 if (systemcfg->platform == PLATFORM_PSERIES_LPAR &&
514 (dn = of_find_node_by_path("/rtas"))) {
515 int num_addr_cell, num_size_cell, maxcpus;
518 num_addr_cell = prom_n_addr_cells(dn);
519 num_size_cell = prom_n_size_cells(dn);
521 ireg = (unsigned int *)
522 get_property(dn, "ibm,lrdr-capacity", NULL);
527 maxcpus = ireg[num_addr_cell + num_size_cell];
529 /* Double maxcpus for processors which have SMT capability */
530 if (cpu_has_feature(CPU_FTR_SMT))
533 if (maxcpus > NR_CPUS) {
535 "Partition configured for %d cpus, "
536 "operating system maximum is %d.\n",
540 printk(KERN_INFO "Partition configured for %d cpus.\n",
543 for (cpu = 0; cpu < maxcpus; cpu++)
544 cpu_set(cpu, cpu_possible_map);
550 * Do the sibling map; assume only two threads per processor.
553 cpu_set(cpu, cpu_sibling_map[cpu]);
554 if (cpu_has_feature(CPU_FTR_SMT))
555 cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
558 systemcfg->processorCount = num_present_cpus();
559 #endif /* CONFIG_PPC64 */
561 #endif /* CONFIG_SMP */