Merge master.kernel.org:/home/rmk/linux-2.6-serial
[deliverable/linux.git] / arch / powerpc / kernel / setup-common.c
1 /*
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>
36 #include <asm/vdso_datapage.h>
37 #include <asm/pgtable.h>
38 #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>
55 #include <asm/xmon.h>
56
57 #include "setup.h"
58
59 #undef DEBUG
60
61 #ifdef DEBUG
62 #include <asm/udbg.h>
63 #define DBG(fmt...) udbg_printf(fmt)
64 #else
65 #define DBG(fmt...)
66 #endif
67
68 #ifdef CONFIG_PPC_MULTIPLATFORM
69 int _machine = 0;
70 EXPORT_SYMBOL(_machine);
71 #endif
72
73 unsigned long klimit = (unsigned long) _end;
74
75 /*
76 * This still seems to be needed... -- paulus
77 */
78 struct 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 */
89 int ppc_do_canonicalize_irqs;
90 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
91 #endif
92
93 /* also used by kexec */
94 void machine_shutdown(void)
95 {
96 if (ppc_md.machine_shutdown)
97 ppc_md.machine_shutdown();
98 }
99
100 void machine_restart(char *cmd)
101 {
102 machine_shutdown();
103 if (ppc_md.restart)
104 ppc_md.restart(cmd);
105 #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
113 void machine_power_off(void)
114 {
115 machine_shutdown();
116 if (ppc_md.power_off)
117 ppc_md.power_off();
118 #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 */
126 EXPORT_SYMBOL_GPL(machine_power_off);
127
128 void (*pm_power_off)(void) = machine_power_off;
129 EXPORT_SYMBOL_GPL(pm_power_off);
130
131 void machine_halt(void)
132 {
133 machine_shutdown();
134 if (ppc_md.halt)
135 ppc_md.halt();
136 #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
146 extern u32 cpu_temp(unsigned long cpu);
147 extern u32 cpu_temp_both(unsigned long cpu);
148 #endif /* CONFIG_TAU */
149
150 #ifdef CONFIG_SMP
151 DEFINE_PER_CPU(unsigned int, pvr);
152 #endif
153
154 static 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;
165 for (i = 0; i < NR_CPUS; ++i)
166 if (cpu_online(i))
167 bogosum += loops_per_jiffy;
168 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
169 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
170 #endif /* CONFIG_SMP && CONFIG_PPC32 */
171 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
172
173 if (ppc_md.show_cpuinfo != NULL)
174 ppc_md.show_cpuinfo(m);
175
176 return 0;
177 }
178
179 /* We only show online cpus: disable preempt (overzealous, I
180 * knew) to prevent cpu going down. */
181 preempt_disable();
182 if (!cpu_online(cpu_id)) {
183 preempt_enable();
184 return 0;
185 }
186
187 #ifdef CONFIG_SMP
188 pvr = per_cpu(pvr, cpu_id);
189 #else
190 pvr = mfspr(SPRN_PVR);
191 #endif
192 maj = (pvr >> 8) & 0xFF;
193 min = pvr & 0xFF;
194
195 seq_printf(m, "processor\t: %lu\n", cpu_id);
196 seq_printf(m, "cpu\t\t: ");
197
198 if (cur_cpu_spec->pvr_mask)
199 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
200 else
201 seq_printf(m, "unknown (%08x)", pvr);
202
203 #ifdef CONFIG_ALTIVEC
204 if (cpu_has_feature(CPU_FTR_ALTIVEC))
205 seq_printf(m, ", altivec supported");
206 #endif /* CONFIG_ALTIVEC */
207
208 seq_printf(m, "\n");
209
210 #ifdef CONFIG_TAU
211 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
212 #ifdef CONFIG_TAU_AVERAGE
213 /* more straightforward, but potentially misleading */
214 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
215 cpu_temp(cpu_id));
216 #else
217 /* show the actual temp sensor range */
218 u32 temp;
219 temp = cpu_temp_both(cpu_id);
220 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
221 temp & 0xff, temp >> 16);
222 #endif
223 }
224 #endif /* CONFIG_TAU */
225
226 /*
227 * Assume here that all clock rates are the same in a
228 * smp system. -- Cort
229 */
230 if (ppc_proc_freq)
231 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
232 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
233
234 if (ppc_md.show_percpuinfo != NULL)
235 ppc_md.show_percpuinfo(m, cpu_id);
236
237 /* If we are a Freescale core do a simple check so
238 * we dont have to keep adding cases in the future */
239 if (PVR_VER(pvr) & 0x8000) {
240 maj = PVR_MAJ(pvr);
241 min = PVR_MIN(pvr);
242 } else {
243 switch (PVR_VER(pvr)) {
244 case 0x0020: /* 403 family */
245 maj = PVR_MAJ(pvr) + 1;
246 min = PVR_MIN(pvr);
247 break;
248 case 0x1008: /* 740P/750P ?? */
249 maj = ((pvr >> 8) & 0xFF) - 1;
250 min = pvr & 0xFF;
251 break;
252 default:
253 maj = (pvr >> 8) & 0xFF;
254 min = pvr & 0xFF;
255 break;
256 }
257 }
258
259 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
260 maj, min, PVR_VER(pvr), PVR_REV(pvr));
261
262 #ifdef CONFIG_PPC32
263 seq_printf(m, "bogomips\t: %lu.%02lu\n",
264 loops_per_jiffy / (500000/HZ),
265 (loops_per_jiffy / (5000/HZ)) % 100);
266 #endif
267
268 #ifdef CONFIG_SMP
269 seq_printf(m, "\n");
270 #endif
271
272 preempt_enable();
273 return 0;
274 }
275
276 static void *c_start(struct seq_file *m, loff_t *pos)
277 {
278 unsigned long i = *pos;
279
280 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
281 }
282
283 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
284 {
285 ++*pos;
286 return c_start(m, pos);
287 }
288
289 static void c_stop(struct seq_file *m, void *v)
290 {
291 }
292
293 struct seq_operations cpuinfo_op = {
294 .start =c_start,
295 .next = c_next,
296 .stop = c_stop,
297 .show = show_cpuinfo,
298 };
299
300 void __init check_for_initrd(void)
301 {
302 #ifdef CONFIG_BLK_DEV_INITRD
303 unsigned long *prop;
304
305 DBG(" -> check_for_initrd()\n");
306
307 if (of_chosen) {
308 prop = (unsigned long *)get_property(of_chosen,
309 "linux,initrd-start", NULL);
310 if (prop != NULL) {
311 initrd_start = (unsigned long)__va(*prop);
312 prop = (unsigned long *)get_property(of_chosen,
313 "linux,initrd-end", NULL);
314 if (prop != NULL) {
315 initrd_end = (unsigned long)__va(*prop);
316 initrd_below_start_ok = 1;
317 } else
318 initrd_start = 0;
319 }
320 }
321
322 /* If we were passed an initrd, set the ROOT_DEV properly if the values
323 * look sensible. If not, clear initrd reference.
324 */
325 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
326 initrd_end > initrd_start)
327 ROOT_DEV = Root_RAM0;
328 else
329 initrd_start = initrd_end = 0;
330
331 if (initrd_start)
332 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
333
334 DBG(" <- check_for_initrd()\n");
335 #endif /* CONFIG_BLK_DEV_INITRD */
336 }
337
338 #ifdef CONFIG_SMP
339
340 /**
341 * setup_cpu_maps - initialize the following cpu maps:
342 * cpu_possible_map
343 * cpu_present_map
344 * cpu_sibling_map
345 *
346 * Having the possible map set up early allows us to restrict allocations
347 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
348 *
349 * We do not initialize the online map here; cpus set their own bits in
350 * cpu_online_map as they come up.
351 *
352 * This function is valid only for Open Firmware systems. finish_device_tree
353 * must be called before using this.
354 *
355 * While we're here, we may as well set the "physical" cpu ids in the paca.
356 */
357 void __init smp_setup_cpu_maps(void)
358 {
359 struct device_node *dn = NULL;
360 int cpu = 0;
361 int swap_cpuid = 0;
362
363 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
364 int *intserv;
365 int j, len = sizeof(u32), nthreads = 1;
366
367 intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
368 &len);
369 if (intserv)
370 nthreads = len / sizeof(int);
371 else {
372 intserv = (int *) get_property(dn, "reg", NULL);
373 if (!intserv)
374 intserv = &cpu; /* assume logical == phys */
375 }
376
377 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
378 cpu_set(cpu, cpu_present_map);
379 set_hard_smp_processor_id(cpu, intserv[j]);
380
381 if (intserv[j] == boot_cpuid_phys)
382 swap_cpuid = cpu;
383 cpu_set(cpu, cpu_possible_map);
384 cpu++;
385 }
386 }
387
388 /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
389 * boot cpu is logical 0.
390 */
391 if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
392 u32 tmp;
393 tmp = get_hard_smp_processor_id(0);
394 set_hard_smp_processor_id(0, boot_cpuid_phys);
395 set_hard_smp_processor_id(swap_cpuid, tmp);
396 }
397
398 #ifdef CONFIG_PPC64
399 /*
400 * On pSeries LPAR, we need to know how many cpus
401 * could possibly be added to this partition.
402 */
403 if (_machine == PLATFORM_PSERIES_LPAR &&
404 (dn = of_find_node_by_path("/rtas"))) {
405 int num_addr_cell, num_size_cell, maxcpus;
406 unsigned int *ireg;
407
408 num_addr_cell = prom_n_addr_cells(dn);
409 num_size_cell = prom_n_size_cells(dn);
410
411 ireg = (unsigned int *)
412 get_property(dn, "ibm,lrdr-capacity", NULL);
413
414 if (!ireg)
415 goto out;
416
417 maxcpus = ireg[num_addr_cell + num_size_cell];
418
419 /* Double maxcpus for processors which have SMT capability */
420 if (cpu_has_feature(CPU_FTR_SMT))
421 maxcpus *= 2;
422
423 if (maxcpus > NR_CPUS) {
424 printk(KERN_WARNING
425 "Partition configured for %d cpus, "
426 "operating system maximum is %d.\n",
427 maxcpus, NR_CPUS);
428 maxcpus = NR_CPUS;
429 } else
430 printk(KERN_INFO "Partition configured for %d cpus.\n",
431 maxcpus);
432
433 for (cpu = 0; cpu < maxcpus; cpu++)
434 cpu_set(cpu, cpu_possible_map);
435 out:
436 of_node_put(dn);
437 }
438
439 /*
440 * Do the sibling map; assume only two threads per processor.
441 */
442 for_each_cpu(cpu) {
443 cpu_set(cpu, cpu_sibling_map[cpu]);
444 if (cpu_has_feature(CPU_FTR_SMT))
445 cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
446 }
447
448 vdso_data->processorCount = num_present_cpus();
449 #endif /* CONFIG_PPC64 */
450 }
451 #endif /* CONFIG_SMP */
452
453 #ifdef CONFIG_XMON
454 static int __init early_xmon(char *p)
455 {
456 /* ensure xmon is enabled */
457 if (p) {
458 if (strncmp(p, "on", 2) == 0)
459 xmon_init(1);
460 if (strncmp(p, "off", 3) == 0)
461 xmon_init(0);
462 if (strncmp(p, "early", 5) != 0)
463 return 0;
464 }
465 xmon_init(1);
466 debugger(NULL);
467
468 return 0;
469 }
470 early_param("xmon", early_xmon);
471 #endif
This page took 0.043538 seconds and 6 git commands to generate.