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