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 | */ | |
e8222502 BH |
12 | |
13 | #undef DEBUG | |
14 | ||
03501dab PM |
15 | #include <linux/module.h> |
16 | #include <linux/string.h> | |
17 | #include <linux/sched.h> | |
18 | #include <linux/init.h> | |
19 | #include <linux/kernel.h> | |
20 | #include <linux/reboot.h> | |
21 | #include <linux/delay.h> | |
22 | #include <linux/initrd.h> | |
e5c6c8e4 | 23 | #include <linux/platform_device.h> |
03501dab PM |
24 | #include <linux/ide.h> |
25 | #include <linux/seq_file.h> | |
26 | #include <linux/ioport.h> | |
27 | #include <linux/console.h> | |
28 | #include <linux/utsname.h> | |
894673ee | 29 | #include <linux/screen_info.h> |
03501dab PM |
30 | #include <linux/root_dev.h> |
31 | #include <linux/notifier.h> | |
32 | #include <linux/cpu.h> | |
33 | #include <linux/unistd.h> | |
34 | #include <linux/serial.h> | |
35 | #include <linux/serial_8250.h> | |
36 | #include <asm/io.h> | |
37 | #include <asm/prom.h> | |
38 | #include <asm/processor.h> | |
a7f290da | 39 | #include <asm/vdso_datapage.h> |
03501dab | 40 | #include <asm/pgtable.h> |
03501dab PM |
41 | #include <asm/smp.h> |
42 | #include <asm/elf.h> | |
43 | #include <asm/machdep.h> | |
44 | #include <asm/time.h> | |
45 | #include <asm/cputable.h> | |
46 | #include <asm/sections.h> | |
e8222502 | 47 | #include <asm/firmware.h> |
03501dab PM |
48 | #include <asm/btext.h> |
49 | #include <asm/nvram.h> | |
50 | #include <asm/setup.h> | |
51 | #include <asm/system.h> | |
52 | #include <asm/rtas.h> | |
53 | #include <asm/iommu.h> | |
54 | #include <asm/serial.h> | |
55 | #include <asm/cache.h> | |
56 | #include <asm/page.h> | |
57 | #include <asm/mmu.h> | |
58 | #include <asm/lmb.h> | |
fca5dcd4 | 59 | #include <asm/xmon.h> |
03501dab | 60 | |
66ba135c SR |
61 | #include "setup.h" |
62 | ||
03501dab | 63 | #ifdef DEBUG |
f9e4ec57 | 64 | #include <asm/udbg.h> |
03501dab PM |
65 | #define DBG(fmt...) udbg_printf(fmt) |
66 | #else | |
67 | #define DBG(fmt...) | |
68 | #endif | |
69 | ||
e8222502 BH |
70 | /* The main machine-dep calls structure |
71 | */ | |
72 | struct machdep_calls ppc_md; | |
73 | EXPORT_SYMBOL(ppc_md); | |
74 | struct machdep_calls *machine_id; | |
75 | EXPORT_SYMBOL(machine_id); | |
799d6046 | 76 | |
49b09853 PM |
77 | unsigned long klimit = (unsigned long) _end; |
78 | ||
03501dab PM |
79 | /* |
80 | * This still seems to be needed... -- paulus | |
81 | */ | |
82 | struct screen_info screen_info = { | |
83 | .orig_x = 0, | |
84 | .orig_y = 25, | |
85 | .orig_video_cols = 80, | |
86 | .orig_video_lines = 25, | |
87 | .orig_video_isVGA = 1, | |
88 | .orig_video_points = 16 | |
89 | }; | |
90 | ||
91 | #ifdef __DO_IRQ_CANON | |
92 | /* XXX should go elsewhere eventually */ | |
93 | int ppc_do_canonicalize_irqs; | |
94 | EXPORT_SYMBOL(ppc_do_canonicalize_irqs); | |
95 | #endif | |
96 | ||
97 | /* also used by kexec */ | |
98 | void machine_shutdown(void) | |
99 | { | |
3d1229d6 ME |
100 | if (ppc_md.machine_shutdown) |
101 | ppc_md.machine_shutdown(); | |
03501dab PM |
102 | } |
103 | ||
104 | void machine_restart(char *cmd) | |
105 | { | |
106 | machine_shutdown(); | |
b8e383d5 KG |
107 | if (ppc_md.restart) |
108 | ppc_md.restart(cmd); | |
03501dab PM |
109 | #ifdef CONFIG_SMP |
110 | smp_send_stop(); | |
111 | #endif | |
112 | printk(KERN_EMERG "System Halted, OK to turn off power\n"); | |
113 | local_irq_disable(); | |
114 | while (1) ; | |
115 | } | |
116 | ||
117 | void machine_power_off(void) | |
118 | { | |
119 | machine_shutdown(); | |
b8e383d5 KG |
120 | if (ppc_md.power_off) |
121 | ppc_md.power_off(); | |
03501dab PM |
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 | /* Used by the G5 thermal driver */ | |
130 | EXPORT_SYMBOL_GPL(machine_power_off); | |
131 | ||
132 | void (*pm_power_off)(void) = machine_power_off; | |
133 | EXPORT_SYMBOL_GPL(pm_power_off); | |
134 | ||
135 | void machine_halt(void) | |
136 | { | |
137 | machine_shutdown(); | |
b8e383d5 KG |
138 | if (ppc_md.halt) |
139 | ppc_md.halt(); | |
03501dab PM |
140 | #ifdef CONFIG_SMP |
141 | smp_send_stop(); | |
142 | #endif | |
143 | printk(KERN_EMERG "System Halted, OK to turn off power\n"); | |
144 | local_irq_disable(); | |
145 | while (1) ; | |
146 | } | |
147 | ||
148 | ||
149 | #ifdef CONFIG_TAU | |
150 | extern u32 cpu_temp(unsigned long cpu); | |
151 | extern u32 cpu_temp_both(unsigned long cpu); | |
152 | #endif /* CONFIG_TAU */ | |
153 | ||
154 | #ifdef CONFIG_SMP | |
155 | DEFINE_PER_CPU(unsigned int, pvr); | |
156 | #endif | |
157 | ||
158 | static int show_cpuinfo(struct seq_file *m, void *v) | |
159 | { | |
160 | unsigned long cpu_id = (unsigned long)v - 1; | |
161 | unsigned int pvr; | |
162 | unsigned short maj; | |
163 | unsigned short min; | |
164 | ||
165 | if (cpu_id == NR_CPUS) { | |
166 | #if defined(CONFIG_SMP) && defined(CONFIG_PPC32) | |
167 | unsigned long bogosum = 0; | |
168 | int i; | |
394e3902 AM |
169 | for_each_online_cpu(i) |
170 | bogosum += loops_per_jiffy; | |
03501dab PM |
171 | seq_printf(m, "total bogomips\t: %lu.%02lu\n", |
172 | bogosum/(500000/HZ), bogosum/(5000/HZ) % 100); | |
173 | #endif /* CONFIG_SMP && CONFIG_PPC32 */ | |
174 | seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq); | |
e8222502 BH |
175 | if (ppc_md.name) |
176 | seq_printf(m, "platform\t: %s\n", ppc_md.name); | |
03501dab PM |
177 | if (ppc_md.show_cpuinfo != NULL) |
178 | ppc_md.show_cpuinfo(m); | |
179 | ||
180 | return 0; | |
181 | } | |
182 | ||
183 | /* We only show online cpus: disable preempt (overzealous, I | |
184 | * knew) to prevent cpu going down. */ | |
185 | preempt_disable(); | |
186 | if (!cpu_online(cpu_id)) { | |
187 | preempt_enable(); | |
188 | return 0; | |
189 | } | |
190 | ||
191 | #ifdef CONFIG_SMP | |
03501dab | 192 | pvr = per_cpu(pvr, cpu_id); |
03501dab PM |
193 | #else |
194 | pvr = mfspr(SPRN_PVR); | |
195 | #endif | |
196 | maj = (pvr >> 8) & 0xFF; | |
197 | min = pvr & 0xFF; | |
198 | ||
199 | seq_printf(m, "processor\t: %lu\n", cpu_id); | |
200 | seq_printf(m, "cpu\t\t: "); | |
201 | ||
202 | if (cur_cpu_spec->pvr_mask) | |
203 | seq_printf(m, "%s", cur_cpu_spec->cpu_name); | |
204 | else | |
205 | seq_printf(m, "unknown (%08x)", pvr); | |
206 | ||
207 | #ifdef CONFIG_ALTIVEC | |
208 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) | |
209 | seq_printf(m, ", altivec supported"); | |
210 | #endif /* CONFIG_ALTIVEC */ | |
211 | ||
212 | seq_printf(m, "\n"); | |
213 | ||
214 | #ifdef CONFIG_TAU | |
215 | if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) { | |
216 | #ifdef CONFIG_TAU_AVERAGE | |
217 | /* more straightforward, but potentially misleading */ | |
218 | seq_printf(m, "temperature \t: %u C (uncalibrated)\n", | |
bccfd588 | 219 | cpu_temp(cpu_id)); |
03501dab PM |
220 | #else |
221 | /* show the actual temp sensor range */ | |
222 | u32 temp; | |
bccfd588 | 223 | temp = cpu_temp_both(cpu_id); |
03501dab PM |
224 | seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n", |
225 | temp & 0xff, temp >> 16); | |
226 | #endif | |
227 | } | |
228 | #endif /* CONFIG_TAU */ | |
229 | ||
230 | /* | |
231 | * Assume here that all clock rates are the same in a | |
232 | * smp system. -- Cort | |
233 | */ | |
234 | if (ppc_proc_freq) | |
235 | seq_printf(m, "clock\t\t: %lu.%06luMHz\n", | |
236 | ppc_proc_freq / 1000000, ppc_proc_freq % 1000000); | |
237 | ||
238 | if (ppc_md.show_percpuinfo != NULL) | |
239 | ppc_md.show_percpuinfo(m, cpu_id); | |
240 | ||
241 | /* If we are a Freescale core do a simple check so | |
242 | * we dont have to keep adding cases in the future */ | |
243 | if (PVR_VER(pvr) & 0x8000) { | |
244 | maj = PVR_MAJ(pvr); | |
245 | min = PVR_MIN(pvr); | |
246 | } else { | |
247 | switch (PVR_VER(pvr)) { | |
248 | case 0x0020: /* 403 family */ | |
249 | maj = PVR_MAJ(pvr) + 1; | |
250 | min = PVR_MIN(pvr); | |
251 | break; | |
252 | case 0x1008: /* 740P/750P ?? */ | |
253 | maj = ((pvr >> 8) & 0xFF) - 1; | |
254 | min = pvr & 0xFF; | |
255 | break; | |
256 | default: | |
257 | maj = (pvr >> 8) & 0xFF; | |
258 | min = pvr & 0xFF; | |
259 | break; | |
260 | } | |
261 | } | |
262 | ||
263 | seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n", | |
264 | maj, min, PVR_VER(pvr), PVR_REV(pvr)); | |
265 | ||
266 | #ifdef CONFIG_PPC32 | |
267 | seq_printf(m, "bogomips\t: %lu.%02lu\n", | |
268 | loops_per_jiffy / (500000/HZ), | |
269 | (loops_per_jiffy / (5000/HZ)) % 100); | |
270 | #endif | |
271 | ||
272 | #ifdef CONFIG_SMP | |
273 | seq_printf(m, "\n"); | |
274 | #endif | |
275 | ||
276 | preempt_enable(); | |
277 | return 0; | |
278 | } | |
279 | ||
280 | static void *c_start(struct seq_file *m, loff_t *pos) | |
281 | { | |
282 | unsigned long i = *pos; | |
283 | ||
284 | return i <= NR_CPUS ? (void *)(i + 1) : NULL; | |
285 | } | |
286 | ||
287 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) | |
288 | { | |
289 | ++*pos; | |
290 | return c_start(m, pos); | |
291 | } | |
292 | ||
293 | static void c_stop(struct seq_file *m, void *v) | |
294 | { | |
295 | } | |
296 | ||
297 | struct seq_operations cpuinfo_op = { | |
298 | .start =c_start, | |
299 | .next = c_next, | |
300 | .stop = c_stop, | |
301 | .show = show_cpuinfo, | |
302 | }; | |
303 | ||
a82765b6 DW |
304 | void __init check_for_initrd(void) |
305 | { | |
306 | #ifdef CONFIG_BLK_DEV_INITRD | |
a4dc7ff0 PM |
307 | const unsigned int *prop; |
308 | int len; | |
a82765b6 DW |
309 | |
310 | DBG(" -> check_for_initrd()\n"); | |
311 | ||
312 | if (of_chosen) { | |
a4dc7ff0 | 313 | prop = get_property(of_chosen, "linux,initrd-start", &len); |
a82765b6 | 314 | if (prop != NULL) { |
a4dc7ff0 PM |
315 | initrd_start = (unsigned long) |
316 | __va(of_read_ulong(prop, len / 4)); | |
a7f67bdf | 317 | prop = get_property(of_chosen, |
a4dc7ff0 | 318 | "linux,initrd-end", &len); |
a82765b6 | 319 | if (prop != NULL) { |
a4dc7ff0 PM |
320 | initrd_end = (unsigned long) |
321 | __va(of_read_ulong(prop, len / 4)); | |
a82765b6 DW |
322 | initrd_below_start_ok = 1; |
323 | } else | |
324 | initrd_start = 0; | |
325 | } | |
326 | } | |
327 | ||
328 | /* If we were passed an initrd, set the ROOT_DEV properly if the values | |
329 | * look sensible. If not, clear initrd reference. | |
330 | */ | |
51fae6de | 331 | if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) && |
a82765b6 DW |
332 | initrd_end > initrd_start) |
333 | ROOT_DEV = Root_RAM0; | |
6761c4a0 | 334 | else |
a82765b6 | 335 | initrd_start = initrd_end = 0; |
a82765b6 DW |
336 | |
337 | if (initrd_start) | |
338 | printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end); | |
339 | ||
340 | DBG(" <- check_for_initrd()\n"); | |
341 | #endif /* CONFIG_BLK_DEV_INITRD */ | |
342 | } | |
343 | ||
5ad57078 PM |
344 | #ifdef CONFIG_SMP |
345 | ||
346 | /** | |
347 | * setup_cpu_maps - initialize the following cpu maps: | |
348 | * cpu_possible_map | |
349 | * cpu_present_map | |
350 | * cpu_sibling_map | |
351 | * | |
352 | * Having the possible map set up early allows us to restrict allocations | |
353 | * of things like irqstacks to num_possible_cpus() rather than NR_CPUS. | |
354 | * | |
355 | * We do not initialize the online map here; cpus set their own bits in | |
356 | * cpu_online_map as they come up. | |
357 | * | |
358 | * This function is valid only for Open Firmware systems. finish_device_tree | |
359 | * must be called before using this. | |
360 | * | |
361 | * While we're here, we may as well set the "physical" cpu ids in the paca. | |
4df20460 AB |
362 | * |
363 | * NOTE: This must match the parsing done in early_init_dt_scan_cpus. | |
5ad57078 PM |
364 | */ |
365 | void __init smp_setup_cpu_maps(void) | |
366 | { | |
367 | struct device_node *dn = NULL; | |
368 | int cpu = 0; | |
5ad57078 PM |
369 | |
370 | while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) { | |
a7f67bdf | 371 | const int *intserv; |
5ad57078 PM |
372 | int j, len = sizeof(u32), nthreads = 1; |
373 | ||
a7f67bdf | 374 | intserv = get_property(dn, "ibm,ppc-interrupt-server#s", &len); |
5ad57078 PM |
375 | if (intserv) |
376 | nthreads = len / sizeof(int); | |
377 | else { | |
a7f67bdf | 378 | intserv = get_property(dn, "reg", NULL); |
5ad57078 PM |
379 | if (!intserv) |
380 | intserv = &cpu; /* assume logical == phys */ | |
381 | } | |
382 | ||
383 | for (j = 0; j < nthreads && cpu < NR_CPUS; j++) { | |
384 | cpu_set(cpu, cpu_present_map); | |
385 | set_hard_smp_processor_id(cpu, intserv[j]); | |
5ad57078 PM |
386 | cpu_set(cpu, cpu_possible_map); |
387 | cpu++; | |
388 | } | |
389 | } | |
390 | ||
5ad57078 PM |
391 | #ifdef CONFIG_PPC64 |
392 | /* | |
393 | * On pSeries LPAR, we need to know how many cpus | |
394 | * could possibly be added to this partition. | |
395 | */ | |
e8222502 | 396 | if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) && |
799d6046 | 397 | (dn = of_find_node_by_path("/rtas"))) { |
5ad57078 | 398 | int num_addr_cell, num_size_cell, maxcpus; |
a7f67bdf | 399 | const unsigned int *ireg; |
5ad57078 PM |
400 | |
401 | num_addr_cell = prom_n_addr_cells(dn); | |
402 | num_size_cell = prom_n_size_cells(dn); | |
403 | ||
a7f67bdf | 404 | ireg = get_property(dn, "ibm,lrdr-capacity", NULL); |
5ad57078 PM |
405 | |
406 | if (!ireg) | |
407 | goto out; | |
408 | ||
409 | maxcpus = ireg[num_addr_cell + num_size_cell]; | |
410 | ||
411 | /* Double maxcpus for processors which have SMT capability */ | |
412 | if (cpu_has_feature(CPU_FTR_SMT)) | |
413 | maxcpus *= 2; | |
414 | ||
415 | if (maxcpus > NR_CPUS) { | |
416 | printk(KERN_WARNING | |
417 | "Partition configured for %d cpus, " | |
418 | "operating system maximum is %d.\n", | |
419 | maxcpus, NR_CPUS); | |
420 | maxcpus = NR_CPUS; | |
421 | } else | |
422 | printk(KERN_INFO "Partition configured for %d cpus.\n", | |
423 | maxcpus); | |
424 | ||
425 | for (cpu = 0; cpu < maxcpus; cpu++) | |
426 | cpu_set(cpu, cpu_possible_map); | |
427 | out: | |
428 | of_node_put(dn); | |
429 | } | |
430 | ||
431 | /* | |
432 | * Do the sibling map; assume only two threads per processor. | |
433 | */ | |
0e551954 | 434 | for_each_possible_cpu(cpu) { |
5ad57078 PM |
435 | cpu_set(cpu, cpu_sibling_map[cpu]); |
436 | if (cpu_has_feature(CPU_FTR_SMT)) | |
437 | cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]); | |
438 | } | |
439 | ||
a7f290da | 440 | vdso_data->processorCount = num_present_cpus(); |
5ad57078 PM |
441 | #endif /* CONFIG_PPC64 */ |
442 | } | |
443 | #endif /* CONFIG_SMP */ | |
fca5dcd4 | 444 | |
e5c6c8e4 MN |
445 | static __init int add_pcspkr(void) |
446 | { | |
447 | struct device_node *np; | |
448 | struct platform_device *pd; | |
449 | int ret; | |
450 | ||
451 | np = of_find_compatible_node(NULL, NULL, "pnpPNP,100"); | |
452 | of_node_put(np); | |
453 | if (!np) | |
454 | return -ENODEV; | |
455 | ||
456 | pd = platform_device_alloc("pcspkr", -1); | |
457 | if (!pd) | |
458 | return -ENOMEM; | |
459 | ||
460 | ret = platform_device_add(pd); | |
461 | if (ret) | |
462 | platform_device_put(pd); | |
463 | ||
464 | return ret; | |
465 | } | |
466 | device_initcall(add_pcspkr); | |
95d465fd | 467 | |
e8222502 BH |
468 | void probe_machine(void) |
469 | { | |
470 | extern struct machdep_calls __machine_desc_start; | |
471 | extern struct machdep_calls __machine_desc_end; | |
472 | ||
473 | /* | |
474 | * Iterate all ppc_md structures until we find the proper | |
475 | * one for the current machine type | |
476 | */ | |
477 | DBG("Probing machine type ...\n"); | |
478 | ||
479 | for (machine_id = &__machine_desc_start; | |
480 | machine_id < &__machine_desc_end; | |
481 | machine_id++) { | |
482 | DBG(" %s ...", machine_id->name); | |
483 | memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls)); | |
484 | if (ppc_md.probe()) { | |
485 | DBG(" match !\n"); | |
486 | break; | |
487 | } | |
488 | DBG("\n"); | |
489 | } | |
490 | /* What can we do if we didn't find ? */ | |
491 | if (machine_id >= &__machine_desc_end) { | |
492 | DBG("No suitable machine found !\n"); | |
493 | for (;;); | |
494 | } | |
495 | ||
496 | printk(KERN_INFO "Using %s machine description\n", ppc_md.name); | |
497 | } | |
1269277a DW |
498 | |
499 | int check_legacy_ioport(unsigned long base_port) | |
500 | { | |
501 | if (ppc_md.check_legacy_ioport == NULL) | |
502 | return 0; | |
503 | return ppc_md.check_legacy_ioport(base_port); | |
504 | } | |
505 | EXPORT_SYMBOL(check_legacy_ioport); | |
7e990266 KG |
506 | |
507 | static int ppc_panic_event(struct notifier_block *this, | |
508 | unsigned long event, void *ptr) | |
509 | { | |
510 | ppc_md.panic(ptr); /* May not return */ | |
511 | return NOTIFY_DONE; | |
512 | } | |
513 | ||
514 | static struct notifier_block ppc_panic_block = { | |
515 | .notifier_call = ppc_panic_event, | |
516 | .priority = INT_MIN /* may not return; must be done last */ | |
517 | }; | |
518 | ||
519 | void __init setup_panic(void) | |
520 | { | |
521 | atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block); | |
522 | } |