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/vdso_datapage.h>
37 #include <asm/pgtable.h>
40 #include <asm/machdep.h>
42 #include <asm/cputable.h>
43 #include <asm/sections.h>
44 #include <asm/btext.h>
45 #include <asm/nvram.h>
46 #include <asm/setup.h>
47 #include <asm/system.h>
49 #include <asm/iommu.h>
50 #include <asm/serial.h>
51 #include <asm/cache.h>
63 #define DBG(fmt...) udbg_printf(fmt)
68 #ifdef CONFIG_PPC_MULTIPLATFORM
70 EXPORT_SYMBOL(_machine);
73 unsigned long klimit = (unsigned long) _end;
76 * This still seems to be needed... -- paulus
78 struct screen_info screen_info = {
81 .orig_video_cols = 80,
82 .orig_video_lines = 25,
83 .orig_video_isVGA = 1,
84 .orig_video_points = 16
88 /* XXX should go elsewhere eventually */
89 int ppc_do_canonicalize_irqs;
90 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
93 /* also used by kexec */
94 void machine_shutdown(void)
96 if (ppc_md.machine_shutdown)
97 ppc_md.machine_shutdown();
100 void machine_restart(char *cmd)
107 printk(KERN_EMERG "System Halted, OK to turn off power\n");
112 void machine_power_off(void)
119 printk(KERN_EMERG "System Halted, OK to turn off power\n");
123 /* Used by the G5 thermal driver */
124 EXPORT_SYMBOL_GPL(machine_power_off);
126 void (*pm_power_off)(void) = machine_power_off;
127 EXPORT_SYMBOL_GPL(pm_power_off);
129 void machine_halt(void)
136 printk(KERN_EMERG "System Halted, OK to turn off power\n");
143 extern u32 cpu_temp(unsigned long cpu);
144 extern u32 cpu_temp_both(unsigned long cpu);
145 #endif /* CONFIG_TAU */
148 DEFINE_PER_CPU(unsigned int, pvr);
151 static int show_cpuinfo(struct seq_file *m, void *v)
153 unsigned long cpu_id = (unsigned long)v - 1;
158 if (cpu_id == NR_CPUS) {
159 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
160 unsigned long bogosum = 0;
162 for (i = 0; i < NR_CPUS; ++i)
164 bogosum += loops_per_jiffy;
165 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
166 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
167 #endif /* CONFIG_SMP && CONFIG_PPC32 */
168 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
170 if (ppc_md.show_cpuinfo != NULL)
171 ppc_md.show_cpuinfo(m);
176 /* We only show online cpus: disable preempt (overzealous, I
177 * knew) to prevent cpu going down. */
179 if (!cpu_online(cpu_id)) {
185 pvr = per_cpu(pvr, cpu_id);
187 pvr = mfspr(SPRN_PVR);
189 maj = (pvr >> 8) & 0xFF;
192 seq_printf(m, "processor\t: %lu\n", cpu_id);
193 seq_printf(m, "cpu\t\t: ");
195 if (cur_cpu_spec->pvr_mask)
196 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
198 seq_printf(m, "unknown (%08x)", pvr);
200 #ifdef CONFIG_ALTIVEC
201 if (cpu_has_feature(CPU_FTR_ALTIVEC))
202 seq_printf(m, ", altivec supported");
203 #endif /* CONFIG_ALTIVEC */
208 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
209 #ifdef CONFIG_TAU_AVERAGE
210 /* more straightforward, but potentially misleading */
211 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
214 /* show the actual temp sensor range */
216 temp = cpu_temp_both(cpu_id);
217 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
218 temp & 0xff, temp >> 16);
221 #endif /* CONFIG_TAU */
224 * Assume here that all clock rates are the same in a
225 * smp system. -- Cort
228 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
229 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
231 if (ppc_md.show_percpuinfo != NULL)
232 ppc_md.show_percpuinfo(m, cpu_id);
234 /* If we are a Freescale core do a simple check so
235 * we dont have to keep adding cases in the future */
236 if (PVR_VER(pvr) & 0x8000) {
240 switch (PVR_VER(pvr)) {
241 case 0x0020: /* 403 family */
242 maj = PVR_MAJ(pvr) + 1;
245 case 0x1008: /* 740P/750P ?? */
246 maj = ((pvr >> 8) & 0xFF) - 1;
250 maj = (pvr >> 8) & 0xFF;
256 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
257 maj, min, PVR_VER(pvr), PVR_REV(pvr));
260 seq_printf(m, "bogomips\t: %lu.%02lu\n",
261 loops_per_jiffy / (500000/HZ),
262 (loops_per_jiffy / (5000/HZ)) % 100);
273 static void *c_start(struct seq_file *m, loff_t *pos)
275 unsigned long i = *pos;
277 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
280 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
283 return c_start(m, pos);
286 static void c_stop(struct seq_file *m, void *v)
290 struct seq_operations cpuinfo_op = {
294 .show = show_cpuinfo,
297 void __init check_for_initrd(void)
299 #ifdef CONFIG_BLK_DEV_INITRD
302 DBG(" -> check_for_initrd()\n");
305 prop = (unsigned long *)get_property(of_chosen,
306 "linux,initrd-start", NULL);
308 initrd_start = (unsigned long)__va(*prop);
309 prop = (unsigned long *)get_property(of_chosen,
310 "linux,initrd-end", NULL);
312 initrd_end = (unsigned long)__va(*prop);
313 initrd_below_start_ok = 1;
319 /* If we were passed an initrd, set the ROOT_DEV properly if the values
320 * look sensible. If not, clear initrd reference.
322 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
323 initrd_end > initrd_start)
324 ROOT_DEV = Root_RAM0;
326 initrd_start = initrd_end = 0;
329 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
331 DBG(" <- check_for_initrd()\n");
332 #endif /* CONFIG_BLK_DEV_INITRD */
338 * setup_cpu_maps - initialize the following cpu maps:
343 * Having the possible map set up early allows us to restrict allocations
344 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
346 * We do not initialize the online map here; cpus set their own bits in
347 * cpu_online_map as they come up.
349 * This function is valid only for Open Firmware systems. finish_device_tree
350 * must be called before using this.
352 * While we're here, we may as well set the "physical" cpu ids in the paca.
354 void __init smp_setup_cpu_maps(void)
356 struct device_node *dn = NULL;
360 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
362 int j, len = sizeof(u32), nthreads = 1;
364 intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
367 nthreads = len / sizeof(int);
369 intserv = (int *) get_property(dn, "reg", NULL);
371 intserv = &cpu; /* assume logical == phys */
374 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
375 cpu_set(cpu, cpu_present_map);
376 set_hard_smp_processor_id(cpu, intserv[j]);
378 if (intserv[j] == boot_cpuid_phys)
380 cpu_set(cpu, cpu_possible_map);
385 /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
386 * boot cpu is logical 0.
388 if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
390 tmp = get_hard_smp_processor_id(0);
391 set_hard_smp_processor_id(0, boot_cpuid_phys);
392 set_hard_smp_processor_id(swap_cpuid, tmp);
397 * On pSeries LPAR, we need to know how many cpus
398 * could possibly be added to this partition.
400 if (_machine == PLATFORM_PSERIES_LPAR &&
401 (dn = of_find_node_by_path("/rtas"))) {
402 int num_addr_cell, num_size_cell, maxcpus;
405 num_addr_cell = prom_n_addr_cells(dn);
406 num_size_cell = prom_n_size_cells(dn);
408 ireg = (unsigned int *)
409 get_property(dn, "ibm,lrdr-capacity", NULL);
414 maxcpus = ireg[num_addr_cell + num_size_cell];
416 /* Double maxcpus for processors which have SMT capability */
417 if (cpu_has_feature(CPU_FTR_SMT))
420 if (maxcpus > NR_CPUS) {
422 "Partition configured for %d cpus, "
423 "operating system maximum is %d.\n",
427 printk(KERN_INFO "Partition configured for %d cpus.\n",
430 for (cpu = 0; cpu < maxcpus; cpu++)
431 cpu_set(cpu, cpu_possible_map);
437 * Do the sibling map; assume only two threads per processor.
440 cpu_set(cpu, cpu_sibling_map[cpu]);
441 if (cpu_has_feature(CPU_FTR_SMT))
442 cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
445 vdso_data->processorCount = num_present_cpus();
446 #endif /* CONFIG_PPC64 */
448 #endif /* CONFIG_SMP */
451 static int __init early_xmon(char *p)
453 /* ensure xmon is enabled */
455 if (strncmp(p, "on", 2) == 0)
457 if (strncmp(p, "off", 3) == 0)
459 if (strncmp(p, "early", 5) != 0)
467 early_param("xmon", early_xmon);