powerpc/powernv: Detect OPAL v3 API version
[deliverable/linux.git] / arch / powerpc / platforms / powernv / setup.c
CommitLineData
55190f88
BH
1/*
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>
628daa8d 32#include <asm/rtas.h>
daea1175 33#include <asm/opal.h>
55190f88
BH
34
35#include "powernv.h"
36
37static void __init pnv_setup_arch(void)
38{
55190f88
BH
39 /* Initialize SMP */
40 pnv_smp_init();
41
61305a96
BH
42 /* Setup PCI */
43 pnv_pci_init();
55190f88 44
628daa8d
BH
45 /* Setup RTC and NVRAM callbacks */
46 if (firmware_has_feature(FW_FEATURE_OPAL))
47 opal_nvram_init();
55190f88
BH
48
49 /* Enable NAP mode */
50 powersave_nap = 1;
51
52 /* XXX PMCS */
53}
54
55static void __init pnv_init_early(void)
56{
daea1175
BH
57#ifdef CONFIG_HVC_OPAL
58 if (firmware_has_feature(FW_FEATURE_OPAL))
59 hvc_opal_init_early();
60 else
61#endif
62 add_preferred_console("hvc", 0, NULL);
55190f88
BH
63}
64
65static void __init pnv_init_IRQ(void)
66{
67 xics_init();
68
69 WARN_ON(!ppc_md.get_irq);
70}
71
72static void pnv_show_cpuinfo(struct seq_file *m)
73{
74 struct device_node *root;
75 const char *model = "";
76
77 root = of_find_node_by_path("/");
78 if (root)
79 model = of_get_property(root, "model", NULL);
80 seq_printf(m, "machine\t\t: PowerNV %s\n", model);
75b93da4
BH
81 if (firmware_has_feature(FW_FEATURE_OPALv3))
82 seq_printf(m, "firmware\t: OPAL v3\n");
83 else if (firmware_has_feature(FW_FEATURE_OPALv2))
14a43e69
BH
84 seq_printf(m, "firmware\t: OPAL v2\n");
85 else if (firmware_has_feature(FW_FEATURE_OPAL))
86 seq_printf(m, "firmware\t: OPAL v1\n");
87 else
88 seq_printf(m, "firmware\t: BML\n");
55190f88
BH
89 of_node_put(root);
90}
91
ec27329f 92static void __noreturn pnv_restart(char *cmd)
55190f88 93{
ec27329f
BH
94 long rc = OPAL_BUSY;
95
96 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
97 rc = opal_cec_reboot();
98 if (rc == OPAL_BUSY_EVENT)
99 opal_poll_events(NULL);
100 else
101 mdelay(10);
102 }
103 for (;;)
104 opal_poll_events(NULL);
55190f88
BH
105}
106
ec27329f 107static void __noreturn pnv_power_off(void)
55190f88 108{
ec27329f
BH
109 long rc = OPAL_BUSY;
110
111 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
112 rc = opal_cec_power_down(0);
113 if (rc == OPAL_BUSY_EVENT)
114 opal_poll_events(NULL);
115 else
116 mdelay(10);
117 }
118 for (;;)
119 opal_poll_events(NULL);
55190f88
BH
120}
121
ec27329f 122static void __noreturn pnv_halt(void)
55190f88 123{
ec27329f 124 pnv_power_off();
55190f88
BH
125}
126
628daa8d 127static void pnv_progress(char *s, unsigned short hex)
55190f88
BH
128{
129}
130
73ed148a
BH
131static void pnv_shutdown(void)
132{
133 /* Let the PCI code clear up IODA tables */
134 pnv_pci_shutdown();
135
136 /* And unregister all OPAL interrupts so they don't fire
137 * up while we kexec
138 */
139 opal_shutdown();
140}
141
628daa8d
BH
142#ifdef CONFIG_KEXEC
143static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
55190f88 144{
628daa8d 145 xics_kexec_teardown_cpu(secondary);
55190f88 146}
628daa8d 147#endif /* CONFIG_KEXEC */
55190f88 148
628daa8d 149static void __init pnv_setup_machdep_opal(void)
55190f88 150{
628daa8d
BH
151 ppc_md.get_boot_time = opal_get_boot_time;
152 ppc_md.get_rtc_time = opal_get_rtc_time;
153 ppc_md.set_rtc_time = opal_set_rtc_time;
154 ppc_md.restart = pnv_restart;
155 ppc_md.power_off = pnv_power_off;
156 ppc_md.halt = pnv_halt;
ed79ba9e 157 ppc_md.machine_check_exception = opal_machine_check;
55190f88
BH
158}
159
628daa8d
BH
160#ifdef CONFIG_PPC_POWERNV_RTAS
161static void __init pnv_setup_machdep_rtas(void)
55190f88 162{
628daa8d
BH
163 if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
164 ppc_md.get_boot_time = rtas_get_boot_time;
165 ppc_md.get_rtc_time = rtas_get_rtc_time;
166 ppc_md.set_rtc_time = rtas_set_rtc_time;
167 }
168 ppc_md.restart = rtas_restart;
169 ppc_md.power_off = rtas_power_off;
170 ppc_md.halt = rtas_halt;
55190f88 171}
628daa8d 172#endif /* CONFIG_PPC_POWERNV_RTAS */
55190f88
BH
173
174static int __init pnv_probe(void)
175{
176 unsigned long root = of_get_flat_dt_root();
177
178 if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
179 return 0;
180
181 hpte_init_native();
182
628daa8d
BH
183 if (firmware_has_feature(FW_FEATURE_OPAL))
184 pnv_setup_machdep_opal();
185#ifdef CONFIG_PPC_POWERNV_RTAS
186 else if (rtas.base)
187 pnv_setup_machdep_rtas();
188#endif /* CONFIG_PPC_POWERNV_RTAS */
189
55190f88
BH
190 pr_debug("PowerNV detected !\n");
191
192 return 1;
193}
194
195define_machine(powernv) {
196 .name = "PowerNV",
197 .probe = pnv_probe,
55190f88 198 .init_early = pnv_init_early,
628daa8d 199 .setup_arch = pnv_setup_arch,
55190f88
BH
200 .init_IRQ = pnv_init_IRQ,
201 .show_cpuinfo = pnv_show_cpuinfo,
55190f88 202 .progress = pnv_progress,
73ed148a 203 .machine_shutdown = pnv_shutdown,
55190f88
BH
204 .power_save = power7_idle,
205 .calibrate_decr = generic_calibrate_decr,
206#ifdef CONFIG_KEXEC
207 .kexec_cpu_down = pnv_kexec_cpu_down,
208#endif
209};
This page took 0.110359 seconds and 5 git commands to generate.