blob: c1d62bf11f299ce427fb1043bf37fa9360143f0d [file] [log] [blame]
Paul Mackerras03501da2005-10-26 17:11:18 +10001/*
2 * Common boot and setup code for both 32-bit and 64-bit.
3 * Extracted from arch/powerpc/kernel/setup_64.c.
4 *
5 * Copyright (C) 2001 PPC64 Team, IBM Corp
6 *
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.
11 */
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>
33#include <asm/io.h>
34#include <asm/prom.h>
35#include <asm/processor.h>
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +110036#include <asm/vdso_datapage.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100037#include <asm/pgtable.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100038#include <asm/smp.h>
39#include <asm/elf.h>
40#include <asm/machdep.h>
41#include <asm/time.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>
48#include <asm/rtas.h>
49#include <asm/iommu.h>
50#include <asm/serial.h>
51#include <asm/cache.h>
52#include <asm/page.h>
53#include <asm/mmu.h>
54#include <asm/lmb.h>
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +110055#include <asm/xmon.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100056
Stephen Rothwell66ba1352005-11-09 11:01:06 +110057#include "setup.h"
58
Paul Mackerras03501da2005-10-26 17:11:18 +100059#undef DEBUG
60
61#ifdef DEBUG
Michael Ellermanf9e4ec52005-11-15 15:16:38 +110062#include <asm/udbg.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100063#define DBG(fmt...) udbg_printf(fmt)
64#else
65#define DBG(fmt...)
66#endif
67
Paul Mackerras799d6042005-11-10 13:37:51 +110068#ifdef CONFIG_PPC_MULTIPLATFORM
69int _machine = 0;
70EXPORT_SYMBOL(_machine);
71#endif
72
Paul Mackerras49b09852005-11-10 15:53:40 +110073unsigned long klimit = (unsigned long) _end;
74
Paul Mackerras03501da2005-10-26 17:11:18 +100075/*
76 * This still seems to be needed... -- paulus
77 */
78struct screen_info screen_info = {
79 .orig_x = 0,
80 .orig_y = 25,
81 .orig_video_cols = 80,
82 .orig_video_lines = 25,
83 .orig_video_isVGA = 1,
84 .orig_video_points = 16
85};
86
87#ifdef __DO_IRQ_CANON
88/* XXX should go elsewhere eventually */
89int ppc_do_canonicalize_irqs;
90EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
91#endif
92
93/* also used by kexec */
94void machine_shutdown(void)
95{
Michael Ellerman3d1229d2005-11-14 23:35:00 +110096 if (ppc_md.machine_shutdown)
97 ppc_md.machine_shutdown();
Paul Mackerras03501da2005-10-26 17:11:18 +100098}
99
100void machine_restart(char *cmd)
101{
102 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600103 if (ppc_md.restart)
104 ppc_md.restart(cmd);
Paul Mackerras03501da2005-10-26 17:11:18 +1000105#ifdef CONFIG_SMP
106 smp_send_stop();
107#endif
108 printk(KERN_EMERG "System Halted, OK to turn off power\n");
109 local_irq_disable();
110 while (1) ;
111}
112
113void machine_power_off(void)
114{
115 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600116 if (ppc_md.power_off)
117 ppc_md.power_off();
Paul Mackerras03501da2005-10-26 17:11:18 +1000118#ifdef CONFIG_SMP
119 smp_send_stop();
120#endif
121 printk(KERN_EMERG "System Halted, OK to turn off power\n");
122 local_irq_disable();
123 while (1) ;
124}
125/* Used by the G5 thermal driver */
126EXPORT_SYMBOL_GPL(machine_power_off);
127
128void (*pm_power_off)(void) = machine_power_off;
129EXPORT_SYMBOL_GPL(pm_power_off);
130
131void machine_halt(void)
132{
133 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600134 if (ppc_md.halt)
135 ppc_md.halt();
Paul Mackerras03501da2005-10-26 17:11:18 +1000136#ifdef CONFIG_SMP
137 smp_send_stop();
138#endif
139 printk(KERN_EMERG "System Halted, OK to turn off power\n");
140 local_irq_disable();
141 while (1) ;
142}
143
144
145#ifdef CONFIG_TAU
146extern u32 cpu_temp(unsigned long cpu);
147extern u32 cpu_temp_both(unsigned long cpu);
148#endif /* CONFIG_TAU */
149
150#ifdef CONFIG_SMP
151DEFINE_PER_CPU(unsigned int, pvr);
152#endif
153
154static int show_cpuinfo(struct seq_file *m, void *v)
155{
156 unsigned long cpu_id = (unsigned long)v - 1;
157 unsigned int pvr;
158 unsigned short maj;
159 unsigned short min;
160
161 if (cpu_id == NR_CPUS) {
162#if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
163 unsigned long bogosum = 0;
164 int i;
Andrew Morton394e3902006-03-23 03:01:05 -0800165 for_each_online_cpu(i)
166 bogosum += loops_per_jiffy;
Paul Mackerras03501da2005-10-26 17:11:18 +1000167 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
168 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
169#endif /* CONFIG_SMP && CONFIG_PPC32 */
170 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
171
172 if (ppc_md.show_cpuinfo != NULL)
173 ppc_md.show_cpuinfo(m);
174
175 return 0;
176 }
177
178 /* We only show online cpus: disable preempt (overzealous, I
179 * knew) to prevent cpu going down. */
180 preempt_disable();
181 if (!cpu_online(cpu_id)) {
182 preempt_enable();
183 return 0;
184 }
185
186#ifdef CONFIG_SMP
Paul Mackerras03501da2005-10-26 17:11:18 +1000187 pvr = per_cpu(pvr, cpu_id);
188#else
Paul Mackerras03501da2005-10-26 17:11:18 +1000189 pvr = mfspr(SPRN_PVR);
190#endif
191 maj = (pvr >> 8) & 0xFF;
192 min = pvr & 0xFF;
193
194 seq_printf(m, "processor\t: %lu\n", cpu_id);
195 seq_printf(m, "cpu\t\t: ");
196
197 if (cur_cpu_spec->pvr_mask)
198 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
199 else
200 seq_printf(m, "unknown (%08x)", pvr);
201
202#ifdef CONFIG_ALTIVEC
203 if (cpu_has_feature(CPU_FTR_ALTIVEC))
204 seq_printf(m, ", altivec supported");
205#endif /* CONFIG_ALTIVEC */
206
207 seq_printf(m, "\n");
208
209#ifdef CONFIG_TAU
210 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
211#ifdef CONFIG_TAU_AVERAGE
212 /* more straightforward, but potentially misleading */
213 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100214 cpu_temp(cpu_id));
Paul Mackerras03501da2005-10-26 17:11:18 +1000215#else
216 /* show the actual temp sensor range */
217 u32 temp;
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100218 temp = cpu_temp_both(cpu_id);
Paul Mackerras03501da2005-10-26 17:11:18 +1000219 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
220 temp & 0xff, temp >> 16);
221#endif
222 }
223#endif /* CONFIG_TAU */
224
225 /*
226 * Assume here that all clock rates are the same in a
227 * smp system. -- Cort
228 */
229 if (ppc_proc_freq)
230 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
231 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
232
233 if (ppc_md.show_percpuinfo != NULL)
234 ppc_md.show_percpuinfo(m, cpu_id);
235
236 /* If we are a Freescale core do a simple check so
237 * we dont have to keep adding cases in the future */
238 if (PVR_VER(pvr) & 0x8000) {
239 maj = PVR_MAJ(pvr);
240 min = PVR_MIN(pvr);
241 } else {
242 switch (PVR_VER(pvr)) {
243 case 0x0020: /* 403 family */
244 maj = PVR_MAJ(pvr) + 1;
245 min = PVR_MIN(pvr);
246 break;
247 case 0x1008: /* 740P/750P ?? */
248 maj = ((pvr >> 8) & 0xFF) - 1;
249 min = pvr & 0xFF;
250 break;
251 default:
252 maj = (pvr >> 8) & 0xFF;
253 min = pvr & 0xFF;
254 break;
255 }
256 }
257
258 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
259 maj, min, PVR_VER(pvr), PVR_REV(pvr));
260
261#ifdef CONFIG_PPC32
262 seq_printf(m, "bogomips\t: %lu.%02lu\n",
263 loops_per_jiffy / (500000/HZ),
264 (loops_per_jiffy / (5000/HZ)) % 100);
265#endif
266
267#ifdef CONFIG_SMP
268 seq_printf(m, "\n");
269#endif
270
271 preempt_enable();
272 return 0;
273}
274
275static void *c_start(struct seq_file *m, loff_t *pos)
276{
277 unsigned long i = *pos;
278
279 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
280}
281
282static void *c_next(struct seq_file *m, void *v, loff_t *pos)
283{
284 ++*pos;
285 return c_start(m, pos);
286}
287
288static void c_stop(struct seq_file *m, void *v)
289{
290}
291
292struct seq_operations cpuinfo_op = {
293 .start =c_start,
294 .next = c_next,
295 .stop = c_stop,
296 .show = show_cpuinfo,
297};
298
David Woodhousea82765b2005-11-02 22:34:20 +0000299void __init check_for_initrd(void)
300{
301#ifdef CONFIG_BLK_DEV_INITRD
302 unsigned long *prop;
303
304 DBG(" -> check_for_initrd()\n");
305
306 if (of_chosen) {
307 prop = (unsigned long *)get_property(of_chosen,
308 "linux,initrd-start", NULL);
309 if (prop != NULL) {
310 initrd_start = (unsigned long)__va(*prop);
311 prop = (unsigned long *)get_property(of_chosen,
312 "linux,initrd-end", NULL);
313 if (prop != NULL) {
314 initrd_end = (unsigned long)__va(*prop);
315 initrd_below_start_ok = 1;
316 } else
317 initrd_start = 0;
318 }
319 }
320
321 /* If we were passed an initrd, set the ROOT_DEV properly if the values
322 * look sensible. If not, clear initrd reference.
323 */
Michael Ellerman51fae6de2005-12-04 18:39:15 +1100324 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
David Woodhousea82765b2005-11-02 22:34:20 +0000325 initrd_end > initrd_start)
326 ROOT_DEV = Root_RAM0;
David Woodhouse6761c4a2005-11-11 08:07:11 +0000327 else
David Woodhousea82765b2005-11-02 22:34:20 +0000328 initrd_start = initrd_end = 0;
David Woodhousea82765b2005-11-02 22:34:20 +0000329
330 if (initrd_start)
331 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
332
333 DBG(" <- check_for_initrd()\n");
334#endif /* CONFIG_BLK_DEV_INITRD */
335}
336
Paul Mackerras5ad57072005-11-05 10:33:55 +1100337#ifdef CONFIG_SMP
338
339/**
340 * setup_cpu_maps - initialize the following cpu maps:
341 * cpu_possible_map
342 * cpu_present_map
343 * cpu_sibling_map
344 *
345 * Having the possible map set up early allows us to restrict allocations
346 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
347 *
348 * We do not initialize the online map here; cpus set their own bits in
349 * cpu_online_map as they come up.
350 *
351 * This function is valid only for Open Firmware systems. finish_device_tree
352 * must be called before using this.
353 *
354 * While we're here, we may as well set the "physical" cpu ids in the paca.
355 */
356void __init smp_setup_cpu_maps(void)
357{
358 struct device_node *dn = NULL;
359 int cpu = 0;
360 int swap_cpuid = 0;
361
362 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
363 int *intserv;
364 int j, len = sizeof(u32), nthreads = 1;
365
366 intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
367 &len);
368 if (intserv)
369 nthreads = len / sizeof(int);
370 else {
371 intserv = (int *) get_property(dn, "reg", NULL);
372 if (!intserv)
373 intserv = &cpu; /* assume logical == phys */
374 }
375
376 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
377 cpu_set(cpu, cpu_present_map);
378 set_hard_smp_processor_id(cpu, intserv[j]);
379
380 if (intserv[j] == boot_cpuid_phys)
381 swap_cpuid = cpu;
382 cpu_set(cpu, cpu_possible_map);
383 cpu++;
384 }
385 }
386
387 /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
388 * boot cpu is logical 0.
389 */
390 if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
391 u32 tmp;
392 tmp = get_hard_smp_processor_id(0);
393 set_hard_smp_processor_id(0, boot_cpuid_phys);
394 set_hard_smp_processor_id(swap_cpuid, tmp);
395 }
396
397#ifdef CONFIG_PPC64
398 /*
399 * On pSeries LPAR, we need to know how many cpus
400 * could possibly be added to this partition.
401 */
Paul Mackerras799d6042005-11-10 13:37:51 +1100402 if (_machine == PLATFORM_PSERIES_LPAR &&
403 (dn = of_find_node_by_path("/rtas"))) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100404 int num_addr_cell, num_size_cell, maxcpus;
405 unsigned int *ireg;
406
407 num_addr_cell = prom_n_addr_cells(dn);
408 num_size_cell = prom_n_size_cells(dn);
409
410 ireg = (unsigned int *)
411 get_property(dn, "ibm,lrdr-capacity", NULL);
412
413 if (!ireg)
414 goto out;
415
416 maxcpus = ireg[num_addr_cell + num_size_cell];
417
418 /* Double maxcpus for processors which have SMT capability */
419 if (cpu_has_feature(CPU_FTR_SMT))
420 maxcpus *= 2;
421
422 if (maxcpus > NR_CPUS) {
423 printk(KERN_WARNING
424 "Partition configured for %d cpus, "
425 "operating system maximum is %d.\n",
426 maxcpus, NR_CPUS);
427 maxcpus = NR_CPUS;
428 } else
429 printk(KERN_INFO "Partition configured for %d cpus.\n",
430 maxcpus);
431
432 for (cpu = 0; cpu < maxcpus; cpu++)
433 cpu_set(cpu, cpu_possible_map);
434 out:
435 of_node_put(dn);
436 }
437
438 /*
439 * Do the sibling map; assume only two threads per processor.
440 */
441 for_each_cpu(cpu) {
442 cpu_set(cpu, cpu_sibling_map[cpu]);
443 if (cpu_has_feature(CPU_FTR_SMT))
444 cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
445 }
446
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +1100447 vdso_data->processorCount = num_present_cpus();
Paul Mackerras5ad57072005-11-05 10:33:55 +1100448#endif /* CONFIG_PPC64 */
449}
450#endif /* CONFIG_SMP */
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +1100451
452#ifdef CONFIG_XMON
453static int __init early_xmon(char *p)
454{
455 /* ensure xmon is enabled */
456 if (p) {
457 if (strncmp(p, "on", 2) == 0)
458 xmon_init(1);
459 if (strncmp(p, "off", 3) == 0)
460 xmon_init(0);
461 if (strncmp(p, "early", 5) != 0)
462 return 0;
463 }
464 xmon_init(1);
465 debugger(NULL);
466
467 return 0;
468}
469early_param("xmon", early_xmon);
470#endif