blob: e239dcfa224c2727bd6411aada2eb65120ad4a8a [file] [log] [blame]
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +00001/*
2 * PowerNV setup code.
3 *
4 * Copyright 2011 IBM Corp.
5 *
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.
10 */
11
12#undef DEBUG
13
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>
25#include <linux/of.h>
26#include <linux/interrupt.h>
27#include <linux/bug.h>
28
29#include <asm/machdep.h>
30#include <asm/firmware.h>
31#include <asm/xics.h>
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +000032#include <asm/rtas.h>
Benjamin Herrenschmidtdaea1172011-09-19 17:44:59 +000033#include <asm/opal.h>
Benjamin Herrenschmidt13906db2013-08-21 13:03:20 +100034#include <asm/kexec.h>
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000035
36#include "powernv.h"
37
38static void __init pnv_setup_arch(void)
39{
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000040 /* Initialize SMP */
41 pnv_smp_init();
42
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000043 /* Setup PCI */
44 pnv_pci_init();
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000045
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +000046 /* Setup RTC and NVRAM callbacks */
47 if (firmware_has_feature(FW_FEATURE_OPAL))
48 opal_nvram_init();
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000049
50 /* Enable NAP mode */
51 powersave_nap = 1;
52
53 /* XXX PMCS */
54}
55
56static void __init pnv_init_early(void)
57{
Benjamin Herrenschmidt3fafe9c2013-07-15 13:03:11 +100058 /*
59 * Initialize the LPC bus now so that legacy serial
60 * ports can be found on it
61 */
62 opal_lpc_init();
63
Benjamin Herrenschmidtdaea1172011-09-19 17:44:59 +000064#ifdef CONFIG_HVC_OPAL
65 if (firmware_has_feature(FW_FEATURE_OPAL))
66 hvc_opal_init_early();
67 else
68#endif
69 add_preferred_console("hvc", 0, NULL);
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000070}
71
72static void __init pnv_init_IRQ(void)
73{
74 xics_init();
75
76 WARN_ON(!ppc_md.get_irq);
77}
78
79static void pnv_show_cpuinfo(struct seq_file *m)
80{
81 struct device_node *root;
82 const char *model = "";
83
84 root = of_find_node_by_path("/");
85 if (root)
86 model = of_get_property(root, "model", NULL);
87 seq_printf(m, "machine\t\t: PowerNV %s\n", model);
Benjamin Herrenschmidt75b93da2013-05-14 15:10:02 +100088 if (firmware_has_feature(FW_FEATURE_OPALv3))
89 seq_printf(m, "firmware\t: OPAL v3\n");
90 else if (firmware_has_feature(FW_FEATURE_OPALv2))
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000091 seq_printf(m, "firmware\t: OPAL v2\n");
92 else if (firmware_has_feature(FW_FEATURE_OPAL))
93 seq_printf(m, "firmware\t: OPAL v1\n");
94 else
95 seq_printf(m, "firmware\t: BML\n");
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000096 of_node_put(root);
97}
98
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +000099static void __noreturn pnv_restart(char *cmd)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000100{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000101 long rc = OPAL_BUSY;
102
Gavin Shane8e71fa2013-06-20 18:13:23 +0800103 opal_notifier_disable();
104
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000105 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
106 rc = opal_cec_reboot();
107 if (rc == OPAL_BUSY_EVENT)
108 opal_poll_events(NULL);
109 else
110 mdelay(10);
111 }
112 for (;;)
113 opal_poll_events(NULL);
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000114}
115
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000116static void __noreturn pnv_power_off(void)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000117{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000118 long rc = OPAL_BUSY;
119
Gavin Shane8e71fa2013-06-20 18:13:23 +0800120 opal_notifier_disable();
121
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000122 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
123 rc = opal_cec_power_down(0);
124 if (rc == OPAL_BUSY_EVENT)
125 opal_poll_events(NULL);
126 else
127 mdelay(10);
128 }
129 for (;;)
130 opal_poll_events(NULL);
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000131}
132
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000133static void __noreturn pnv_halt(void)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000134{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000135 pnv_power_off();
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000136}
137
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000138static void pnv_progress(char *s, unsigned short hex)
139{
140}
141
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000142static void pnv_shutdown(void)
143{
144 /* Let the PCI code clear up IODA tables */
145 pnv_pci_shutdown();
146
147 /* And unregister all OPAL interrupts so they don't fire
148 * up while we kexec
149 */
150 opal_shutdown();
151}
152
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000153#ifdef CONFIG_KEXEC
154static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
155{
156 xics_kexec_teardown_cpu(secondary);
Benjamin Herrenschmidt13906db2013-08-21 13:03:20 +1000157
158 /* Return secondary CPUs to firmware on OPAL v3 */
159 if (firmware_has_feature(FW_FEATURE_OPALv3) && secondary) {
160 mb();
161 get_paca()->kexec_state = KEXEC_STATE_REAL_MODE;
162 mb();
163
164 /* Return the CPU to OPAL */
165 opal_return_cpu();
166 }
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000167}
168#endif /* CONFIG_KEXEC */
169
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000170static void __init pnv_setup_machdep_opal(void)
171{
172 ppc_md.get_boot_time = opal_get_boot_time;
173 ppc_md.get_rtc_time = opal_get_rtc_time;
174 ppc_md.set_rtc_time = opal_set_rtc_time;
175 ppc_md.restart = pnv_restart;
176 ppc_md.power_off = pnv_power_off;
177 ppc_md.halt = pnv_halt;
Benjamin Herrenschmidted79ba92011-09-19 17:45:04 +0000178 ppc_md.machine_check_exception = opal_machine_check;
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000179}
180
181#ifdef CONFIG_PPC_POWERNV_RTAS
182static void __init pnv_setup_machdep_rtas(void)
183{
184 if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
185 ppc_md.get_boot_time = rtas_get_boot_time;
186 ppc_md.get_rtc_time = rtas_get_rtc_time;
187 ppc_md.set_rtc_time = rtas_set_rtc_time;
188 }
189 ppc_md.restart = rtas_restart;
190 ppc_md.power_off = rtas_power_off;
191 ppc_md.halt = rtas_halt;
192}
193#endif /* CONFIG_PPC_POWERNV_RTAS */
194
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000195static int __init pnv_probe(void)
196{
197 unsigned long root = of_get_flat_dt_root();
198
199 if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
200 return 0;
201
202 hpte_init_native();
203
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000204 if (firmware_has_feature(FW_FEATURE_OPAL))
205 pnv_setup_machdep_opal();
206#ifdef CONFIG_PPC_POWERNV_RTAS
207 else if (rtas.base)
208 pnv_setup_machdep_rtas();
209#endif /* CONFIG_PPC_POWERNV_RTAS */
210
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000211 pr_debug("PowerNV detected !\n");
212
213 return 1;
214}
215
216define_machine(powernv) {
217 .name = "PowerNV",
218 .probe = pnv_probe,
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000219 .init_early = pnv_init_early,
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000220 .setup_arch = pnv_setup_arch,
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000221 .init_IRQ = pnv_init_IRQ,
222 .show_cpuinfo = pnv_show_cpuinfo,
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000223 .progress = pnv_progress,
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000224 .machine_shutdown = pnv_shutdown,
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000225 .power_save = power7_idle,
226 .calibrate_decr = generic_calibrate_decr,
227#ifdef CONFIG_KEXEC
228 .kexec_cpu_down = pnv_kexec_cpu_down,
229#endif
230};