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/screen_info.h>
28 #include <linux/root_dev.h>
29 #include <linux/notifier.h>
30 #include <linux/cpu.h>
31 #include <linux/unistd.h>
32 #include <linux/serial.h>
33 #include <linux/serial_8250.h>
34 #include <linux/debugfs.h>
35 #include <linux/percpu.h>
36 #include <linux/memblock.h>
37 #include <linux/of_platform.h>
41 #include <asm/processor.h>
42 #include <asm/vdso_datapage.h>
43 #include <asm/pgtable.h>
46 #include <asm/machdep.h>
48 #include <asm/cputable.h>
49 #include <asm/sections.h>
50 #include <asm/firmware.h>
51 #include <asm/btext.h>
52 #include <asm/nvram.h>
53 #include <asm/setup.h>
54 #include <asm/system.h>
56 #include <asm/iommu.h>
57 #include <asm/serial.h>
58 #include <asm/cache.h>
62 #include <asm/cputhreads.h>
63 #include <mm/mmu_decl.h>
69 #define DBG(fmt...) udbg_printf(fmt)
74 /* The main machine-dep calls structure
76 struct machdep_calls ppc_md
;
77 EXPORT_SYMBOL(ppc_md
);
78 struct machdep_calls
*machine_id
;
79 EXPORT_SYMBOL(machine_id
);
81 unsigned long klimit
= (unsigned long) _end
;
83 char cmd_line
[COMMAND_LINE_SIZE
];
86 * This still seems to be needed... -- paulus
88 struct screen_info screen_info
= {
91 .orig_video_cols
= 80,
92 .orig_video_lines
= 25,
93 .orig_video_isVGA
= 1,
94 .orig_video_points
= 16
97 /* Variables required to store legacy IO irq routing */
99 EXPORT_SYMBOL_GPL(of_i8042_kbd_irq
);
100 int of_i8042_aux_irq
;
101 EXPORT_SYMBOL_GPL(of_i8042_aux_irq
);
103 #ifdef __DO_IRQ_CANON
104 int ppc_do_canonicalize_irqs
;
105 EXPORT_SYMBOL(ppc_do_canonicalize_irqs
);
108 /* also used by kexec */
109 void machine_shutdown(void)
111 if (ppc_md
.machine_shutdown
)
112 ppc_md
.machine_shutdown();
115 void machine_restart(char *cmd
)
123 printk(KERN_EMERG
"System Halted, OK to turn off power\n");
128 void machine_power_off(void)
131 if (ppc_md
.power_off
)
136 printk(KERN_EMERG
"System Halted, OK to turn off power\n");
140 /* Used by the G5 thermal driver */
141 EXPORT_SYMBOL_GPL(machine_power_off
);
143 void (*pm_power_off
)(void) = machine_power_off
;
144 EXPORT_SYMBOL_GPL(pm_power_off
);
146 void machine_halt(void)
154 printk(KERN_EMERG
"System Halted, OK to turn off power\n");
161 extern u32
cpu_temp(unsigned long cpu
);
162 extern u32
cpu_temp_both(unsigned long cpu
);
163 #endif /* CONFIG_TAU */
166 DEFINE_PER_CPU(unsigned int, cpu_pvr
);
169 static void show_cpuinfo_summary(struct seq_file
*m
)
171 struct device_node
*root
;
172 const char *model
= NULL
;
173 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
174 unsigned long bogosum
= 0;
176 for_each_online_cpu(i
)
177 bogosum
+= loops_per_jiffy
;
178 seq_printf(m
, "total bogomips\t: %lu.%02lu\n",
179 bogosum
/(500000/HZ
), bogosum
/(5000/HZ
) % 100);
180 #endif /* CONFIG_SMP && CONFIG_PPC32 */
181 seq_printf(m
, "timebase\t: %lu\n", ppc_tb_freq
);
183 seq_printf(m
, "platform\t: %s\n", ppc_md
.name
);
184 root
= of_find_node_by_path("/");
186 model
= of_get_property(root
, "model", NULL
);
188 seq_printf(m
, "model\t\t: %s\n", model
);
191 if (ppc_md
.show_cpuinfo
!= NULL
)
192 ppc_md
.show_cpuinfo(m
);
195 /* Display the amount of memory */
196 seq_printf(m
, "Memory\t\t: %d MB\n",
197 (unsigned int)(total_memory
/ (1024 * 1024)));
201 static int show_cpuinfo(struct seq_file
*m
, void *v
)
203 unsigned long cpu_id
= (unsigned long)v
- 1;
208 /* We only show online cpus: disable preempt (overzealous, I
209 * knew) to prevent cpu going down. */
211 if (!cpu_online(cpu_id
)) {
217 pvr
= per_cpu(cpu_pvr
, cpu_id
);
219 pvr
= mfspr(SPRN_PVR
);
221 maj
= (pvr
>> 8) & 0xFF;
224 seq_printf(m
, "processor\t: %lu\n", cpu_id
);
225 seq_printf(m
, "cpu\t\t: ");
227 if (cur_cpu_spec
->pvr_mask
)
228 seq_printf(m
, "%s", cur_cpu_spec
->cpu_name
);
230 seq_printf(m
, "unknown (%08x)", pvr
);
232 #ifdef CONFIG_ALTIVEC
233 if (cpu_has_feature(CPU_FTR_ALTIVEC
))
234 seq_printf(m
, ", altivec supported");
235 #endif /* CONFIG_ALTIVEC */
240 if (cur_cpu_spec
->cpu_features
& CPU_FTR_TAU
) {
241 #ifdef CONFIG_TAU_AVERAGE
242 /* more straightforward, but potentially misleading */
243 seq_printf(m
, "temperature \t: %u C (uncalibrated)\n",
246 /* show the actual temp sensor range */
248 temp
= cpu_temp_both(cpu_id
);
249 seq_printf(m
, "temperature \t: %u-%u C (uncalibrated)\n",
250 temp
& 0xff, temp
>> 16);
253 #endif /* CONFIG_TAU */
256 * Assume here that all clock rates are the same in a
257 * smp system. -- Cort
260 seq_printf(m
, "clock\t\t: %lu.%06luMHz\n",
261 ppc_proc_freq
/ 1000000, ppc_proc_freq
% 1000000);
263 if (ppc_md
.show_percpuinfo
!= NULL
)
264 ppc_md
.show_percpuinfo(m
, cpu_id
);
266 /* If we are a Freescale core do a simple check so
267 * we dont have to keep adding cases in the future */
268 if (PVR_VER(pvr
) & 0x8000) {
269 switch (PVR_VER(pvr
)) {
270 case 0x8000: /* 7441/7450/7451, Voyager */
271 case 0x8001: /* 7445/7455, Apollo 6 */
272 case 0x8002: /* 7447/7457, Apollo 7 */
273 case 0x8003: /* 7447A, Apollo 7 PM */
274 case 0x8004: /* 7448, Apollo 8 */
275 case 0x800c: /* 7410, Nitro */
276 maj
= ((pvr
>> 8) & 0xF);
279 default: /* e500/book-e */
285 switch (PVR_VER(pvr
)) {
286 case 0x0020: /* 403 family */
287 maj
= PVR_MAJ(pvr
) + 1;
290 case 0x1008: /* 740P/750P ?? */
291 maj
= ((pvr
>> 8) & 0xFF) - 1;
295 maj
= (pvr
>> 8) & 0xFF;
301 seq_printf(m
, "revision\t: %hd.%hd (pvr %04x %04x)\n",
302 maj
, min
, PVR_VER(pvr
), PVR_REV(pvr
));
305 seq_printf(m
, "bogomips\t: %lu.%02lu\n",
306 loops_per_jiffy
/ (500000/HZ
),
307 (loops_per_jiffy
/ (5000/HZ
)) % 100);
316 /* If this is the last cpu, print the summary */
317 if (cpumask_next(cpu_id
, cpu_online_mask
) >= nr_cpu_ids
)
318 show_cpuinfo_summary(m
);
323 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
325 if (*pos
== 0) /* just in case, cpu 0 is not the first */
326 *pos
= cpumask_first(cpu_online_mask
);
328 *pos
= cpumask_next(*pos
- 1, cpu_online_mask
);
329 if ((*pos
) < nr_cpu_ids
)
330 return (void *)(unsigned long)(*pos
+ 1);
334 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
337 return c_start(m
, pos
);
340 static void c_stop(struct seq_file
*m
, void *v
)
344 const struct seq_operations cpuinfo_op
= {
348 .show
= show_cpuinfo
,
351 void __init
check_for_initrd(void)
353 #ifdef CONFIG_BLK_DEV_INITRD
354 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
355 initrd_start
, initrd_end
);
357 /* If we were passed an initrd, set the ROOT_DEV properly if the values
358 * look sensible. If not, clear initrd reference.
360 if (is_kernel_addr(initrd_start
) && is_kernel_addr(initrd_end
) &&
361 initrd_end
> initrd_start
)
362 ROOT_DEV
= Root_RAM0
;
364 initrd_start
= initrd_end
= 0;
367 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start
, initrd_end
);
369 DBG(" <- check_for_initrd()\n");
370 #endif /* CONFIG_BLK_DEV_INITRD */
375 int threads_per_core
, threads_shift
;
376 cpumask_t threads_core_mask
;
378 static void __init
cpu_init_thread_core_maps(int tpc
)
382 threads_per_core
= tpc
;
383 threads_core_mask
= CPU_MASK_NONE
;
385 /* This implementation only supports power of 2 number of threads
386 * for simplicity and performance
388 threads_shift
= ilog2(tpc
);
389 BUG_ON(tpc
!= (1 << threads_shift
));
391 for (i
= 0; i
< tpc
; i
++)
392 cpu_set(i
, threads_core_mask
);
394 printk(KERN_INFO
"CPU maps initialized for %d thread%s per core\n",
395 tpc
, tpc
> 1 ? "s" : "");
396 printk(KERN_DEBUG
" (thread shift is %d)\n", threads_shift
);
401 * setup_cpu_maps - initialize the following cpu maps:
405 * Having the possible map set up early allows us to restrict allocations
406 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
408 * We do not initialize the online map here; cpus set their own bits in
409 * cpu_online_mask as they come up.
411 * This function is valid only for Open Firmware systems. finish_device_tree
412 * must be called before using this.
414 * While we're here, we may as well set the "physical" cpu ids in the paca.
416 * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
418 void __init
smp_setup_cpu_maps(void)
420 struct device_node
*dn
= NULL
;
424 DBG("smp_setup_cpu_maps()\n");
426 while ((dn
= of_find_node_by_type(dn
, "cpu")) && cpu
< NR_CPUS
) {
430 DBG(" * %s...\n", dn
->full_name
);
432 intserv
= of_get_property(dn
, "ibm,ppc-interrupt-server#s",
435 nthreads
= len
/ sizeof(int);
436 DBG(" ibm,ppc-interrupt-server#s -> %d threads\n",
439 DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n");
440 intserv
= of_get_property(dn
, "reg", NULL
);
442 intserv
= &cpu
; /* assume logical == phys */
445 for (j
= 0; j
< nthreads
&& cpu
< NR_CPUS
; j
++) {
446 DBG(" thread %d -> cpu %d (hard id %d)\n",
448 set_cpu_present(cpu
, true);
449 set_hard_smp_processor_id(cpu
, intserv
[j
]);
450 set_cpu_possible(cpu
, true);
455 /* If no SMT supported, nthreads is forced to 1 */
456 if (!cpu_has_feature(CPU_FTR_SMT
)) {
457 DBG(" SMT disabled ! nthreads forced to 1\n");
463 * On pSeries LPAR, we need to know how many cpus
464 * could possibly be added to this partition.
466 if (machine_is(pseries
) && firmware_has_feature(FW_FEATURE_LPAR
) &&
467 (dn
= of_find_node_by_path("/rtas"))) {
468 int num_addr_cell
, num_size_cell
, maxcpus
;
469 const unsigned int *ireg
;
471 num_addr_cell
= of_n_addr_cells(dn
);
472 num_size_cell
= of_n_size_cells(dn
);
474 ireg
= of_get_property(dn
, "ibm,lrdr-capacity", NULL
);
479 maxcpus
= ireg
[num_addr_cell
+ num_size_cell
];
481 /* Double maxcpus for processors which have SMT capability */
482 if (cpu_has_feature(CPU_FTR_SMT
))
485 if (maxcpus
> NR_CPUS
) {
487 "Partition configured for %d cpus, "
488 "operating system maximum is %d.\n",
492 printk(KERN_INFO
"Partition configured for %d cpus.\n",
495 for (cpu
= 0; cpu
< maxcpus
; cpu
++)
496 set_cpu_possible(cpu
, true);
500 vdso_data
->processorCount
= num_present_cpus();
501 #endif /* CONFIG_PPC64 */
503 /* Initialize CPU <=> thread mapping/
505 * WARNING: We assume that the number of threads is the same for
506 * every CPU in the system. If that is not the case, then some code
507 * here will have to be reworked
509 cpu_init_thread_core_maps(nthreads
);
513 #endif /* CONFIG_SMP */
515 #ifdef CONFIG_PCSPKR_PLATFORM
516 static __init
int add_pcspkr(void)
518 struct device_node
*np
;
519 struct platform_device
*pd
;
522 np
= of_find_compatible_node(NULL
, NULL
, "pnpPNP,100");
527 pd
= platform_device_alloc("pcspkr", -1);
531 ret
= platform_device_add(pd
);
533 platform_device_put(pd
);
537 device_initcall(add_pcspkr
);
538 #endif /* CONFIG_PCSPKR_PLATFORM */
540 void probe_machine(void)
542 extern struct machdep_calls __machine_desc_start
;
543 extern struct machdep_calls __machine_desc_end
;
546 * Iterate all ppc_md structures until we find the proper
547 * one for the current machine type
549 DBG("Probing machine type ...\n");
551 for (machine_id
= &__machine_desc_start
;
552 machine_id
< &__machine_desc_end
;
554 DBG(" %s ...", machine_id
->name
);
555 memcpy(&ppc_md
, machine_id
, sizeof(struct machdep_calls
));
556 if (ppc_md
.probe()) {
562 /* What can we do if we didn't find ? */
563 if (machine_id
>= &__machine_desc_end
) {
564 DBG("No suitable machine found !\n");
568 printk(KERN_INFO
"Using %s machine description\n", ppc_md
.name
);
571 /* Match a class of boards, not a specific device configuration. */
572 int check_legacy_ioport(unsigned long base_port
)
574 struct device_node
*parent
, *np
= NULL
;
579 if (!(np
= of_find_compatible_node(NULL
, NULL
, "pnpPNP,303")))
580 np
= of_find_compatible_node(NULL
, NULL
, "pnpPNP,f03");
582 parent
= of_get_parent(np
);
584 of_i8042_kbd_irq
= irq_of_parse_and_map(parent
, 0);
585 if (!of_i8042_kbd_irq
)
586 of_i8042_kbd_irq
= 1;
588 of_i8042_aux_irq
= irq_of_parse_and_map(parent
, 1);
589 if (!of_i8042_aux_irq
)
590 of_i8042_aux_irq
= 12;
596 np
= of_find_node_by_type(NULL
, "8042");
597 /* Pegasos has no device_type on its 8042 node, look for the
600 np
= of_find_node_by_name(NULL
, "8042");
602 case FDC_BASE
: /* FDC1 */
603 np
= of_find_node_by_type(NULL
, "fdc");
605 #ifdef CONFIG_PPC_PREP
612 /* ipmi is supposed to fail here */
617 parent
= of_get_parent(np
);
619 if (strcmp(parent
->type
, "isa") == 0)
626 EXPORT_SYMBOL(check_legacy_ioport
);
628 static int ppc_panic_event(struct notifier_block
*this,
629 unsigned long event
, void *ptr
)
631 ppc_md
.panic(ptr
); /* May not return */
635 static struct notifier_block ppc_panic_block
= {
636 .notifier_call
= ppc_panic_event
,
637 .priority
= INT_MIN
/* may not return; must be done last */
640 void __init
setup_panic(void)
642 atomic_notifier_chain_register(&panic_notifier_list
, &ppc_panic_block
);
645 #ifdef CONFIG_CHECK_CACHE_COHERENCY
647 * For platforms that have configurable cache-coherency. This function
648 * checks that the cache coherency setting of the kernel matches the setting
649 * left by the firmware, as indicated in the device tree. Since a mismatch
650 * will eventually result in DMA failures, we print * and error and call
651 * BUG() in that case.
654 #ifdef CONFIG_NOT_COHERENT_CACHE
655 #define KERNEL_COHERENCY 0
657 #define KERNEL_COHERENCY 1
660 static int __init
check_cache_coherency(void)
662 struct device_node
*np
;
664 int devtree_coherency
;
666 np
= of_find_node_by_path("/");
667 prop
= of_get_property(np
, "coherency-off", NULL
);
670 devtree_coherency
= prop
? 0 : 1;
672 if (devtree_coherency
!= KERNEL_COHERENCY
) {
674 "kernel coherency:%s != device tree_coherency:%s\n",
675 KERNEL_COHERENCY
? "on" : "off",
676 devtree_coherency
? "on" : "off");
683 late_initcall(check_cache_coherency
);
684 #endif /* CONFIG_CHECK_CACHE_COHERENCY */
686 #ifdef CONFIG_DEBUG_FS
687 struct dentry
*powerpc_debugfs_root
;
688 EXPORT_SYMBOL(powerpc_debugfs_root
);
690 static int powerpc_debugfs_init(void)
692 powerpc_debugfs_root
= debugfs_create_dir("powerpc", NULL
);
694 return powerpc_debugfs_root
== NULL
;
696 arch_initcall(powerpc_debugfs_init
);
699 static int ppc_dflt_bus_notify(struct notifier_block
*nb
,
700 unsigned long action
, void *data
)
702 struct device
*dev
= data
;
704 /* We are only intereted in device addition */
705 if (action
!= BUS_NOTIFY_ADD_DEVICE
)
708 set_dma_ops(dev
, &dma_direct_ops
);
713 static struct notifier_block ppc_dflt_plat_bus_notifier
= {
714 .notifier_call
= ppc_dflt_bus_notify
,
718 static int __init
setup_bus_notifier(void)
720 bus_register_notifier(&platform_bus_type
, &ppc_dflt_plat_bus_notifier
);
724 arch_initcall(setup_bus_notifier
);