4 * Copyright 2011 IBM Corp.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
14 #include <linux/cpu.h>
15 #include <linux/errno.h>
16 #include <linux/sched.h>
17 #include <linux/kernel.h>
18 #include <linux/tty.h>
19 #include <linux/reboot.h>
20 #include <linux/init.h>
21 #include <linux/console.h>
22 #include <linux/delay.h>
23 #include <linux/irq.h>
24 #include <linux/seq_file.h>
26 #include <linux/of_fdt.h>
27 #include <linux/interrupt.h>
28 #include <linux/bug.h>
30 #include <asm/machdep.h>
31 #include <asm/firmware.h>
35 #include <asm/kexec.h>
39 static void __init pnv_setup_arch(void)
47 /* Setup RTC and NVRAM callbacks */
48 if (firmware_has_feature(FW_FEATURE_OPAL))
57 static void __init pnv_init_early(void)
60 * Initialize the LPC bus now so that legacy serial
61 * ports can be found on it
65 #ifdef CONFIG_HVC_OPAL
66 if (firmware_has_feature(FW_FEATURE_OPAL))
67 hvc_opal_init_early();
70 add_preferred_console("hvc", 0, NULL);
73 static void __init pnv_init_IRQ(void)
77 WARN_ON(!ppc_md.get_irq);
80 static void pnv_show_cpuinfo(struct seq_file *m)
82 struct device_node *root;
83 const char *model = "";
85 root = of_find_node_by_path("/");
87 model = of_get_property(root, "model", NULL);
88 seq_printf(m, "machine\t\t: PowerNV %s\n", model);
89 if (firmware_has_feature(FW_FEATURE_OPALv3))
90 seq_printf(m, "firmware\t: OPAL v3\n");
91 else if (firmware_has_feature(FW_FEATURE_OPALv2))
92 seq_printf(m, "firmware\t: OPAL v2\n");
93 else if (firmware_has_feature(FW_FEATURE_OPAL))
94 seq_printf(m, "firmware\t: OPAL v1\n");
96 seq_printf(m, "firmware\t: BML\n");
100 static void __noreturn pnv_restart(char *cmd)
104 opal_notifier_disable();
106 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
107 rc = opal_cec_reboot();
108 if (rc == OPAL_BUSY_EVENT)
109 opal_poll_events(NULL);
114 opal_poll_events(NULL);
117 static void __noreturn pnv_power_off(void)
121 opal_notifier_disable();
123 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
124 rc = opal_cec_power_down(0);
125 if (rc == OPAL_BUSY_EVENT)
126 opal_poll_events(NULL);
131 opal_poll_events(NULL);
134 static void __noreturn pnv_halt(void)
139 static void pnv_progress(char *s, unsigned short hex)
143 static void pnv_shutdown(void)
145 /* Let the PCI code clear up IODA tables */
148 /* And unregister all OPAL interrupts so they don't fire
155 static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
157 xics_kexec_teardown_cpu(secondary);
159 /* Return secondary CPUs to firmware on OPAL v3 */
160 if (firmware_has_feature(FW_FEATURE_OPALv3) && secondary) {
162 get_paca()->kexec_state = KEXEC_STATE_REAL_MODE;
165 /* Return the CPU to OPAL */
169 #endif /* CONFIG_KEXEC */
171 static void __init pnv_setup_machdep_opal(void)
173 ppc_md.get_boot_time = opal_get_boot_time;
174 ppc_md.get_rtc_time = opal_get_rtc_time;
175 ppc_md.set_rtc_time = opal_set_rtc_time;
176 ppc_md.restart = pnv_restart;
177 ppc_md.power_off = pnv_power_off;
178 ppc_md.halt = pnv_halt;
179 ppc_md.machine_check_exception = opal_machine_check;
182 #ifdef CONFIG_PPC_POWERNV_RTAS
183 static void __init pnv_setup_machdep_rtas(void)
185 if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
186 ppc_md.get_boot_time = rtas_get_boot_time;
187 ppc_md.get_rtc_time = rtas_get_rtc_time;
188 ppc_md.set_rtc_time = rtas_set_rtc_time;
190 ppc_md.restart = rtas_restart;
191 ppc_md.power_off = rtas_power_off;
192 ppc_md.halt = rtas_halt;
194 #endif /* CONFIG_PPC_POWERNV_RTAS */
196 static int __init pnv_probe(void)
198 unsigned long root = of_get_flat_dt_root();
200 if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
205 if (firmware_has_feature(FW_FEATURE_OPAL))
206 pnv_setup_machdep_opal();
207 #ifdef CONFIG_PPC_POWERNV_RTAS
209 pnv_setup_machdep_rtas();
210 #endif /* CONFIG_PPC_POWERNV_RTAS */
212 pr_debug("PowerNV detected !\n");
217 define_machine(powernv) {
220 .init_early = pnv_init_early,
221 .setup_arch = pnv_setup_arch,
222 .init_IRQ = pnv_init_IRQ,
223 .show_cpuinfo = pnv_show_cpuinfo,
224 .progress = pnv_progress,
225 .machine_shutdown = pnv_shutdown,
226 .power_save = power7_idle,
227 .calibrate_decr = generic_calibrate_decr,
229 .kexec_cpu_down = pnv_kexec_cpu_down,