2 * Common boot and setup code for both 32-bit and 64-bit.
3 * Extracted from arch/powerpc/kernel/setup_64.c.
5 * Copyright (C) 2001 PPC64 Team, IBM Corp
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.
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>
23 #include <linux/platform_device.h>
24 #include <linux/seq_file.h>
25 #include <linux/ioport.h>
26 #include <linux/console.h>
27 #include <linux/utsname.h>
28 #include <linux/screen_info.h>
29 #include <linux/root_dev.h>
30 #include <linux/notifier.h>
31 #include <linux/cpu.h>
32 #include <linux/unistd.h>
33 #include <linux/serial.h>
34 #include <linux/serial_8250.h>
37 #include <asm/processor.h>
38 #include <asm/vdso_datapage.h>
39 #include <asm/pgtable.h>
42 #include <asm/machdep.h>
44 #include <asm/cputable.h>
45 #include <asm/sections.h>
46 #include <asm/firmware.h>
47 #include <asm/btext.h>
48 #include <asm/nvram.h>
49 #include <asm/setup.h>
50 #include <asm/system.h>
52 #include <asm/iommu.h>
53 #include <asm/serial.h>
54 #include <asm/cache.h>
64 #define DBG(fmt...) udbg_printf(fmt)
69 /* The main machine-dep calls structure
71 struct machdep_calls ppc_md
;
72 EXPORT_SYMBOL(ppc_md
);
73 struct machdep_calls
*machine_id
;
74 EXPORT_SYMBOL(machine_id
);
76 unsigned long klimit
= (unsigned long) _end
;
79 * This still seems to be needed... -- paulus
81 struct screen_info screen_info
= {
84 .orig_video_cols
= 80,
85 .orig_video_lines
= 25,
86 .orig_video_isVGA
= 1,
87 .orig_video_points
= 16
91 /* XXX should go elsewhere eventually */
92 int ppc_do_canonicalize_irqs
;
93 EXPORT_SYMBOL(ppc_do_canonicalize_irqs
);
96 /* also used by kexec */
97 void machine_shutdown(void)
99 if (ppc_md
.machine_shutdown
)
100 ppc_md
.machine_shutdown();
103 void machine_restart(char *cmd
)
111 printk(KERN_EMERG
"System Halted, OK to turn off power\n");
116 void machine_power_off(void)
119 if (ppc_md
.power_off
)
124 printk(KERN_EMERG
"System Halted, OK to turn off power\n");
128 /* Used by the G5 thermal driver */
129 EXPORT_SYMBOL_GPL(machine_power_off
);
131 void (*pm_power_off
)(void) = machine_power_off
;
132 EXPORT_SYMBOL_GPL(pm_power_off
);
134 void machine_halt(void)
142 printk(KERN_EMERG
"System Halted, OK to turn off power\n");
149 extern u32
cpu_temp(unsigned long cpu
);
150 extern u32
cpu_temp_both(unsigned long cpu
);
151 #endif /* CONFIG_TAU */
154 DEFINE_PER_CPU(unsigned int, pvr
);
157 static int show_cpuinfo(struct seq_file
*m
, void *v
)
159 unsigned long cpu_id
= (unsigned long)v
- 1;
164 if (cpu_id
== NR_CPUS
) {
165 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
166 unsigned long bogosum
= 0;
168 for_each_online_cpu(i
)
169 bogosum
+= loops_per_jiffy
;
170 seq_printf(m
, "total bogomips\t: %lu.%02lu\n",
171 bogosum
/(500000/HZ
), bogosum
/(5000/HZ
) % 100);
172 #endif /* CONFIG_SMP && CONFIG_PPC32 */
173 seq_printf(m
, "timebase\t: %lu\n", ppc_tb_freq
);
175 seq_printf(m
, "platform\t: %s\n", ppc_md
.name
);
176 if (ppc_md
.show_cpuinfo
!= NULL
)
177 ppc_md
.show_cpuinfo(m
);
182 /* We only show online cpus: disable preempt (overzealous, I
183 * knew) to prevent cpu going down. */
185 if (!cpu_online(cpu_id
)) {
191 pvr
= per_cpu(pvr
, cpu_id
);
193 pvr
= mfspr(SPRN_PVR
);
195 maj
= (pvr
>> 8) & 0xFF;
198 seq_printf(m
, "processor\t: %lu\n", cpu_id
);
199 seq_printf(m
, "cpu\t\t: ");
201 if (cur_cpu_spec
->pvr_mask
)
202 seq_printf(m
, "%s", cur_cpu_spec
->cpu_name
);
204 seq_printf(m
, "unknown (%08x)", pvr
);
206 #ifdef CONFIG_ALTIVEC
207 if (cpu_has_feature(CPU_FTR_ALTIVEC
))
208 seq_printf(m
, ", altivec supported");
209 #endif /* CONFIG_ALTIVEC */
214 if (cur_cpu_spec
->cpu_features
& CPU_FTR_TAU
) {
215 #ifdef CONFIG_TAU_AVERAGE
216 /* more straightforward, but potentially misleading */
217 seq_printf(m
, "temperature \t: %u C (uncalibrated)\n",
220 /* show the actual temp sensor range */
222 temp
= cpu_temp_both(cpu_id
);
223 seq_printf(m
, "temperature \t: %u-%u C (uncalibrated)\n",
224 temp
& 0xff, temp
>> 16);
227 #endif /* CONFIG_TAU */
230 * Assume here that all clock rates are the same in a
231 * smp system. -- Cort
234 seq_printf(m
, "clock\t\t: %lu.%06luMHz\n",
235 ppc_proc_freq
/ 1000000, ppc_proc_freq
% 1000000);
237 if (ppc_md
.show_percpuinfo
!= NULL
)
238 ppc_md
.show_percpuinfo(m
, cpu_id
);
240 /* If we are a Freescale core do a simple check so
241 * we dont have to keep adding cases in the future */
242 if (PVR_VER(pvr
) & 0x8000) {
246 switch (PVR_VER(pvr
)) {
247 case 0x0020: /* 403 family */
248 maj
= PVR_MAJ(pvr
) + 1;
251 case 0x1008: /* 740P/750P ?? */
252 maj
= ((pvr
>> 8) & 0xFF) - 1;
256 maj
= (pvr
>> 8) & 0xFF;
262 seq_printf(m
, "revision\t: %hd.%hd (pvr %04x %04x)\n",
263 maj
, min
, PVR_VER(pvr
), PVR_REV(pvr
));
266 seq_printf(m
, "bogomips\t: %lu.%02lu\n",
267 loops_per_jiffy
/ (500000/HZ
),
268 (loops_per_jiffy
/ (5000/HZ
)) % 100);
279 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
281 unsigned long i
= *pos
;
283 return i
<= NR_CPUS
? (void *)(i
+ 1) : NULL
;
286 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
289 return c_start(m
, pos
);
292 static void c_stop(struct seq_file
*m
, void *v
)
296 struct seq_operations cpuinfo_op
= {
300 .show
= show_cpuinfo
,
303 void __init
check_for_initrd(void)
305 #ifdef CONFIG_BLK_DEV_INITRD
306 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
307 initrd_start
, initrd_end
);
309 /* If we were passed an initrd, set the ROOT_DEV properly if the values
310 * look sensible. If not, clear initrd reference.
312 if (is_kernel_addr(initrd_start
) && is_kernel_addr(initrd_end
) &&
313 initrd_end
> initrd_start
)
314 ROOT_DEV
= Root_RAM0
;
316 initrd_start
= initrd_end
= 0;
319 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start
, initrd_end
);
321 DBG(" <- check_for_initrd()\n");
322 #endif /* CONFIG_BLK_DEV_INITRD */
328 * setup_cpu_maps - initialize the following cpu maps:
333 * Having the possible map set up early allows us to restrict allocations
334 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
336 * We do not initialize the online map here; cpus set their own bits in
337 * cpu_online_map as they come up.
339 * This function is valid only for Open Firmware systems. finish_device_tree
340 * must be called before using this.
342 * While we're here, we may as well set the "physical" cpu ids in the paca.
344 * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
346 void __init
smp_setup_cpu_maps(void)
348 struct device_node
*dn
= NULL
;
351 while ((dn
= of_find_node_by_type(dn
, "cpu")) && cpu
< NR_CPUS
) {
353 int j
, len
= sizeof(u32
), nthreads
= 1;
355 intserv
= of_get_property(dn
, "ibm,ppc-interrupt-server#s",
358 nthreads
= len
/ sizeof(int);
360 intserv
= of_get_property(dn
, "reg", NULL
);
362 intserv
= &cpu
; /* assume logical == phys */
365 for (j
= 0; j
< nthreads
&& cpu
< NR_CPUS
; j
++) {
366 cpu_set(cpu
, cpu_present_map
);
367 set_hard_smp_processor_id(cpu
, intserv
[j
]);
368 cpu_set(cpu
, cpu_possible_map
);
375 * On pSeries LPAR, we need to know how many cpus
376 * could possibly be added to this partition.
378 if (machine_is(pseries
) && firmware_has_feature(FW_FEATURE_LPAR
) &&
379 (dn
= of_find_node_by_path("/rtas"))) {
380 int num_addr_cell
, num_size_cell
, maxcpus
;
381 const unsigned int *ireg
;
383 num_addr_cell
= of_n_addr_cells(dn
);
384 num_size_cell
= of_n_size_cells(dn
);
386 ireg
= of_get_property(dn
, "ibm,lrdr-capacity", NULL
);
391 maxcpus
= ireg
[num_addr_cell
+ num_size_cell
];
393 /* Double maxcpus for processors which have SMT capability */
394 if (cpu_has_feature(CPU_FTR_SMT
))
397 if (maxcpus
> NR_CPUS
) {
399 "Partition configured for %d cpus, "
400 "operating system maximum is %d.\n",
404 printk(KERN_INFO
"Partition configured for %d cpus.\n",
407 for (cpu
= 0; cpu
< maxcpus
; cpu
++)
408 cpu_set(cpu
, cpu_possible_map
);
414 * Do the sibling map; assume only two threads per processor.
416 for_each_possible_cpu(cpu
) {
417 cpu_set(cpu
, cpu_sibling_map
[cpu
]);
418 if (cpu_has_feature(CPU_FTR_SMT
))
419 cpu_set(cpu
^ 0x1, cpu_sibling_map
[cpu
]);
422 vdso_data
->processorCount
= num_present_cpus();
423 #endif /* CONFIG_PPC64 */
425 #endif /* CONFIG_SMP */
427 static __init
int add_pcspkr(void)
429 struct device_node
*np
;
430 struct platform_device
*pd
;
433 np
= of_find_compatible_node(NULL
, NULL
, "pnpPNP,100");
438 pd
= platform_device_alloc("pcspkr", -1);
442 ret
= platform_device_add(pd
);
444 platform_device_put(pd
);
448 device_initcall(add_pcspkr
);
450 void probe_machine(void)
452 extern struct machdep_calls __machine_desc_start
;
453 extern struct machdep_calls __machine_desc_end
;
456 * Iterate all ppc_md structures until we find the proper
457 * one for the current machine type
459 DBG("Probing machine type ...\n");
461 for (machine_id
= &__machine_desc_start
;
462 machine_id
< &__machine_desc_end
;
464 DBG(" %s ...", machine_id
->name
);
465 memcpy(&ppc_md
, machine_id
, sizeof(struct machdep_calls
));
466 if (ppc_md
.probe()) {
472 /* What can we do if we didn't find ? */
473 if (machine_id
>= &__machine_desc_end
) {
474 DBG("No suitable machine found !\n");
478 printk(KERN_INFO
"Using %s machine description\n", ppc_md
.name
);
481 /* Match a class of boards, not a specific device configuration. */
482 int check_legacy_ioport(unsigned long base_port
)
484 struct device_node
*parent
, *np
= NULL
;
489 np
= of_find_node_by_type(NULL
, "8042");
491 case FDC_BASE
: /* FDC1 */
492 np
= of_find_node_by_type(NULL
, "fdc");
494 #ifdef CONFIG_PPC_PREP
501 /* ipmi is supposed to fail here */
506 parent
= of_get_parent(np
);
508 if (strcmp(parent
->type
, "isa") == 0)
515 EXPORT_SYMBOL(check_legacy_ioport
);
517 static int ppc_panic_event(struct notifier_block
*this,
518 unsigned long event
, void *ptr
)
520 ppc_md
.panic(ptr
); /* May not return */
524 static struct notifier_block ppc_panic_block
= {
525 .notifier_call
= ppc_panic_event
,
526 .priority
= INT_MIN
/* may not return; must be done last */
529 void __init
setup_panic(void)
531 atomic_notifier_chain_register(&panic_notifier_list
, &ppc_panic_block
);
534 #ifdef CONFIG_CHECK_CACHE_COHERENCY
536 * For platforms that have configurable cache-coherency. This function
537 * checks that the cache coherency setting of the kernel matches the setting
538 * left by the firmware, as indicated in the device tree. Since a mismatch
539 * will eventually result in DMA failures, we print * and error and call
540 * BUG() in that case.
543 #ifdef CONFIG_NOT_COHERENT_CACHE
544 #define KERNEL_COHERENCY 0
546 #define KERNEL_COHERENCY 1
549 static int __init
check_cache_coherency(void)
551 struct device_node
*np
;
553 int devtree_coherency
;
555 np
= of_find_node_by_path("/");
556 prop
= of_get_property(np
, "coherency-off", NULL
);
559 devtree_coherency
= prop
? 0 : 1;
561 if (devtree_coherency
!= KERNEL_COHERENCY
) {
563 "kernel coherency:%s != device tree_coherency:%s\n",
564 KERNEL_COHERENCY
? "on" : "off",
565 devtree_coherency
? "on" : "off");
572 late_initcall(check_cache_coherency
);
573 #endif /* CONFIG_CHECK_CACHE_COHERENCY */