powerpc: Simplify and clean up the xmon terminal I/O
[deliverable/linux.git] / arch / powerpc / kernel / setup-common.c
CommitLineData
03501dab
PM
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/pgtable.h>
03501dab
PM
37#include <asm/smp.h>
38#include <asm/elf.h>
39#include <asm/machdep.h>
40#include <asm/time.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>
47#include <asm/rtas.h>
48#include <asm/iommu.h>
49#include <asm/serial.h>
50#include <asm/cache.h>
51#include <asm/page.h>
52#include <asm/mmu.h>
53#include <asm/lmb.h>
fca5dcd4 54#include <asm/xmon.h>
03501dab
PM
55
56#undef DEBUG
57
58#ifdef DEBUG
59#define DBG(fmt...) udbg_printf(fmt)
60#else
61#define DBG(fmt...)
62#endif
63
64/*
65 * This still seems to be needed... -- paulus
66 */
67struct screen_info screen_info = {
68 .orig_x = 0,
69 .orig_y = 25,
70 .orig_video_cols = 80,
71 .orig_video_lines = 25,
72 .orig_video_isVGA = 1,
73 .orig_video_points = 16
74};
75
76#ifdef __DO_IRQ_CANON
77/* XXX should go elsewhere eventually */
78int ppc_do_canonicalize_irqs;
79EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
80#endif
81
82/* also used by kexec */
83void machine_shutdown(void)
84{
85 if (ppc_md.nvram_sync)
86 ppc_md.nvram_sync();
87}
88
89void machine_restart(char *cmd)
90{
91 machine_shutdown();
92 ppc_md.restart(cmd);
93#ifdef CONFIG_SMP
94 smp_send_stop();
95#endif
96 printk(KERN_EMERG "System Halted, OK to turn off power\n");
97 local_irq_disable();
98 while (1) ;
99}
100
101void machine_power_off(void)
102{
103 machine_shutdown();
104 ppc_md.power_off();
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/* Used by the G5 thermal driver */
113EXPORT_SYMBOL_GPL(machine_power_off);
114
115void (*pm_power_off)(void) = machine_power_off;
116EXPORT_SYMBOL_GPL(pm_power_off);
117
118void machine_halt(void)
119{
120 machine_shutdown();
121 ppc_md.halt();
122#ifdef CONFIG_SMP
123 smp_send_stop();
124#endif
125 printk(KERN_EMERG "System Halted, OK to turn off power\n");
126 local_irq_disable();
127 while (1) ;
128}
129
130
131#ifdef CONFIG_TAU
132extern u32 cpu_temp(unsigned long cpu);
133extern u32 cpu_temp_both(unsigned long cpu);
134#endif /* CONFIG_TAU */
135
136#ifdef CONFIG_SMP
137DEFINE_PER_CPU(unsigned int, pvr);
138#endif
139
140static int show_cpuinfo(struct seq_file *m, void *v)
141{
142 unsigned long cpu_id = (unsigned long)v - 1;
143 unsigned int pvr;
144 unsigned short maj;
145 unsigned short min;
146
147 if (cpu_id == NR_CPUS) {
148#if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
149 unsigned long bogosum = 0;
150 int i;
151 for (i = 0; i < NR_CPUS; ++i)
152 if (cpu_online(i))
153 bogosum += loops_per_jiffy;
154 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
155 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
156#endif /* CONFIG_SMP && CONFIG_PPC32 */
157 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
158
159 if (ppc_md.show_cpuinfo != NULL)
160 ppc_md.show_cpuinfo(m);
161
162 return 0;
163 }
164
165 /* We only show online cpus: disable preempt (overzealous, I
166 * knew) to prevent cpu going down. */
167 preempt_disable();
168 if (!cpu_online(cpu_id)) {
169 preempt_enable();
170 return 0;
171 }
172
173#ifdef CONFIG_SMP
03501dab 174 pvr = per_cpu(pvr, cpu_id);
03501dab
PM
175#else
176 pvr = mfspr(SPRN_PVR);
177#endif
178 maj = (pvr >> 8) & 0xFF;
179 min = pvr & 0xFF;
180
181 seq_printf(m, "processor\t: %lu\n", cpu_id);
182 seq_printf(m, "cpu\t\t: ");
183
184 if (cur_cpu_spec->pvr_mask)
185 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
186 else
187 seq_printf(m, "unknown (%08x)", pvr);
188
189#ifdef CONFIG_ALTIVEC
190 if (cpu_has_feature(CPU_FTR_ALTIVEC))
191 seq_printf(m, ", altivec supported");
192#endif /* CONFIG_ALTIVEC */
193
194 seq_printf(m, "\n");
195
196#ifdef CONFIG_TAU
197 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
198#ifdef CONFIG_TAU_AVERAGE
199 /* more straightforward, but potentially misleading */
200 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
bccfd588 201 cpu_temp(cpu_id));
03501dab
PM
202#else
203 /* show the actual temp sensor range */
204 u32 temp;
bccfd588 205 temp = cpu_temp_both(cpu_id);
03501dab
PM
206 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
207 temp & 0xff, temp >> 16);
208#endif
209 }
210#endif /* CONFIG_TAU */
211
212 /*
213 * Assume here that all clock rates are the same in a
214 * smp system. -- Cort
215 */
216 if (ppc_proc_freq)
217 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
218 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
219
220 if (ppc_md.show_percpuinfo != NULL)
221 ppc_md.show_percpuinfo(m, cpu_id);
222
223 /* If we are a Freescale core do a simple check so
224 * we dont have to keep adding cases in the future */
225 if (PVR_VER(pvr) & 0x8000) {
226 maj = PVR_MAJ(pvr);
227 min = PVR_MIN(pvr);
228 } else {
229 switch (PVR_VER(pvr)) {
230 case 0x0020: /* 403 family */
231 maj = PVR_MAJ(pvr) + 1;
232 min = PVR_MIN(pvr);
233 break;
234 case 0x1008: /* 740P/750P ?? */
235 maj = ((pvr >> 8) & 0xFF) - 1;
236 min = pvr & 0xFF;
237 break;
238 default:
239 maj = (pvr >> 8) & 0xFF;
240 min = pvr & 0xFF;
241 break;
242 }
243 }
244
245 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
246 maj, min, PVR_VER(pvr), PVR_REV(pvr));
247
248#ifdef CONFIG_PPC32
249 seq_printf(m, "bogomips\t: %lu.%02lu\n",
250 loops_per_jiffy / (500000/HZ),
251 (loops_per_jiffy / (5000/HZ)) % 100);
252#endif
253
254#ifdef CONFIG_SMP
255 seq_printf(m, "\n");
256#endif
257
258 preempt_enable();
259 return 0;
260}
261
262static void *c_start(struct seq_file *m, loff_t *pos)
263{
264 unsigned long i = *pos;
265
266 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
267}
268
269static void *c_next(struct seq_file *m, void *v, loff_t *pos)
270{
271 ++*pos;
272 return c_start(m, pos);
273}
274
275static void c_stop(struct seq_file *m, void *v)
276{
277}
278
279struct seq_operations cpuinfo_op = {
280 .start =c_start,
281 .next = c_next,
282 .stop = c_stop,
283 .show = show_cpuinfo,
284};
285
286#ifdef CONFIG_PPC_MULTIPLATFORM
287static int __init set_preferred_console(void)
288{
289 struct device_node *prom_stdout = NULL;
290 char *name;
291 u32 *spd;
292 int offset = 0;
293
294 DBG(" -> set_preferred_console()\n");
295
296 /* The user has requested a console so this is already set up. */
297 if (strstr(saved_command_line, "console=")) {
298 DBG(" console was specified !\n");
299 return -EBUSY;
300 }
301
302 if (!of_chosen) {
303 DBG(" of_chosen is NULL !\n");
304 return -ENODEV;
305 }
306 /* We are getting a weird phandle from OF ... */
307 /* ... So use the full path instead */
308 name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
309 if (name == NULL) {
310 DBG(" no linux,stdout-path !\n");
311 return -ENODEV;
312 }
313 prom_stdout = of_find_node_by_path(name);
314 if (!prom_stdout) {
315 DBG(" can't find stdout package %s !\n", name);
316 return -ENODEV;
317 }
318 DBG("stdout is %s\n", prom_stdout->full_name);
319
320 name = (char *)get_property(prom_stdout, "name", NULL);
321 if (!name) {
322 DBG(" stdout package has no name !\n");
323 goto not_found;
324 }
325 spd = (u32 *)get_property(prom_stdout, "current-speed", NULL);
326
327 if (0)
328 ;
329#ifdef CONFIG_SERIAL_8250_CONSOLE
330 else if (strcmp(name, "serial") == 0) {
331 int i;
332 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
333 if (i > 8) {
334 switch (reg[1]) {
335 case 0x3f8:
336 offset = 0;
337 break;
338 case 0x2f8:
339 offset = 1;
340 break;
341 case 0x898:
342 offset = 2;
343 break;
344 case 0x890:
345 offset = 3;
346 break;
347 default:
348 /* We dont recognise the serial port */
349 goto not_found;
350 }
351 }
352 }
353#endif /* CONFIG_SERIAL_8250_CONSOLE */
354#ifdef CONFIG_PPC_PSERIES
355 else if (strcmp(name, "vty") == 0) {
356 u32 *reg = (u32 *)get_property(prom_stdout, "reg", NULL);
357 char *compat = (char *)get_property(prom_stdout, "compatible", NULL);
358
359 if (reg && compat && (strcmp(compat, "hvterm-protocol") == 0)) {
360 /* Host Virtual Serial Interface */
03501dab
PM
361 switch (reg[0]) {
362 case 0x30000000:
363 offset = 0;
364 break;
365 case 0x30000001:
366 offset = 1;
367 break;
368 default:
369 goto not_found;
370 }
371 of_node_put(prom_stdout);
372 DBG("Found hvsi console at offset %d\n", offset);
373 return add_preferred_console("hvsi", offset, NULL);
374 } else {
375 /* pSeries LPAR virtual console */
376 of_node_put(prom_stdout);
377 DBG("Found hvc console\n");
378 return add_preferred_console("hvc", 0, NULL);
379 }
380 }
381#endif /* CONFIG_PPC_PSERIES */
382#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
383 else if (strcmp(name, "ch-a") == 0)
384 offset = 0;
385 else if (strcmp(name, "ch-b") == 0)
386 offset = 1;
387#endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
388 else
389 goto not_found;
390 of_node_put(prom_stdout);
391
392 DBG("Found serial console at ttyS%d\n", offset);
393
394 if (spd) {
395 static char __initdata opt[16];
396 sprintf(opt, "%d", *spd);
397 return add_preferred_console("ttyS", offset, opt);
398 } else
399 return add_preferred_console("ttyS", offset, NULL);
400
401 not_found:
402 DBG("No preferred console found !\n");
403 of_node_put(prom_stdout);
404 return -ENODEV;
405}
406console_initcall(set_preferred_console);
407#endif /* CONFIG_PPC_MULTIPLATFORM */
5ad57078 408
a82765b6
DW
409void __init check_for_initrd(void)
410{
411#ifdef CONFIG_BLK_DEV_INITRD
412 unsigned long *prop;
413
414 DBG(" -> check_for_initrd()\n");
415
416 if (of_chosen) {
417 prop = (unsigned long *)get_property(of_chosen,
418 "linux,initrd-start", NULL);
419 if (prop != NULL) {
420 initrd_start = (unsigned long)__va(*prop);
421 prop = (unsigned long *)get_property(of_chosen,
422 "linux,initrd-end", NULL);
423 if (prop != NULL) {
424 initrd_end = (unsigned long)__va(*prop);
425 initrd_below_start_ok = 1;
426 } else
427 initrd_start = 0;
428 }
429 }
430
431 /* If we were passed an initrd, set the ROOT_DEV properly if the values
432 * look sensible. If not, clear initrd reference.
433 */
434 if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
435 initrd_end > initrd_start)
436 ROOT_DEV = Root_RAM0;
437 else {
438 printk("Bogus initrd %08lx %08lx\n", initrd_start, initrd_end);
439 initrd_start = initrd_end = 0;
440 }
441
442 if (initrd_start)
443 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
444
445 DBG(" <- check_for_initrd()\n");
446#endif /* CONFIG_BLK_DEV_INITRD */
447}
448
5ad57078
PM
449#ifdef CONFIG_SMP
450
451/**
452 * setup_cpu_maps - initialize the following cpu maps:
453 * cpu_possible_map
454 * cpu_present_map
455 * cpu_sibling_map
456 *
457 * Having the possible map set up early allows us to restrict allocations
458 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
459 *
460 * We do not initialize the online map here; cpus set their own bits in
461 * cpu_online_map as they come up.
462 *
463 * This function is valid only for Open Firmware systems. finish_device_tree
464 * must be called before using this.
465 *
466 * While we're here, we may as well set the "physical" cpu ids in the paca.
467 */
468void __init smp_setup_cpu_maps(void)
469{
470 struct device_node *dn = NULL;
471 int cpu = 0;
472 int swap_cpuid = 0;
473
474 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
475 int *intserv;
476 int j, len = sizeof(u32), nthreads = 1;
477
478 intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
479 &len);
480 if (intserv)
481 nthreads = len / sizeof(int);
482 else {
483 intserv = (int *) get_property(dn, "reg", NULL);
484 if (!intserv)
485 intserv = &cpu; /* assume logical == phys */
486 }
487
488 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
489 cpu_set(cpu, cpu_present_map);
490 set_hard_smp_processor_id(cpu, intserv[j]);
491
492 if (intserv[j] == boot_cpuid_phys)
493 swap_cpuid = cpu;
494 cpu_set(cpu, cpu_possible_map);
495 cpu++;
496 }
497 }
498
499 /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
500 * boot cpu is logical 0.
501 */
502 if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
503 u32 tmp;
504 tmp = get_hard_smp_processor_id(0);
505 set_hard_smp_processor_id(0, boot_cpuid_phys);
506 set_hard_smp_processor_id(swap_cpuid, tmp);
507 }
508
509#ifdef CONFIG_PPC64
510 /*
511 * On pSeries LPAR, we need to know how many cpus
512 * could possibly be added to this partition.
513 */
514 if (systemcfg->platform == PLATFORM_PSERIES_LPAR &&
515 (dn = of_find_node_by_path("/rtas"))) {
516 int num_addr_cell, num_size_cell, maxcpus;
517 unsigned int *ireg;
518
519 num_addr_cell = prom_n_addr_cells(dn);
520 num_size_cell = prom_n_size_cells(dn);
521
522 ireg = (unsigned int *)
523 get_property(dn, "ibm,lrdr-capacity", NULL);
524
525 if (!ireg)
526 goto out;
527
528 maxcpus = ireg[num_addr_cell + num_size_cell];
529
530 /* Double maxcpus for processors which have SMT capability */
531 if (cpu_has_feature(CPU_FTR_SMT))
532 maxcpus *= 2;
533
534 if (maxcpus > NR_CPUS) {
535 printk(KERN_WARNING
536 "Partition configured for %d cpus, "
537 "operating system maximum is %d.\n",
538 maxcpus, NR_CPUS);
539 maxcpus = NR_CPUS;
540 } else
541 printk(KERN_INFO "Partition configured for %d cpus.\n",
542 maxcpus);
543
544 for (cpu = 0; cpu < maxcpus; cpu++)
545 cpu_set(cpu, cpu_possible_map);
546 out:
547 of_node_put(dn);
548 }
549
550 /*
551 * Do the sibling map; assume only two threads per processor.
552 */
553 for_each_cpu(cpu) {
554 cpu_set(cpu, cpu_sibling_map[cpu]);
555 if (cpu_has_feature(CPU_FTR_SMT))
556 cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
557 }
558
559 systemcfg->processorCount = num_present_cpus();
560#endif /* CONFIG_PPC64 */
561}
562#endif /* CONFIG_SMP */
fca5dcd4
PM
563
564#ifdef CONFIG_XMON
565static int __init early_xmon(char *p)
566{
567 /* ensure xmon is enabled */
568 if (p) {
569 if (strncmp(p, "on", 2) == 0)
570 xmon_init(1);
571 if (strncmp(p, "off", 3) == 0)
572 xmon_init(0);
573 if (strncmp(p, "early", 5) != 0)
574 return 0;
575 }
576 xmon_init(1);
577 debugger(NULL);
578
579 return 0;
580}
581early_param("xmon", early_xmon);
582#endif
This page took 0.075812 seconds and 5 git commands to generate.