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