blob: 84438af96c052b7e465d6b6a03d333ba9e7b37ba [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 Herrenschmidt55190f82011-09-19 17:44:52 +000034
35#include "powernv.h"
36
37static void __init pnv_setup_arch(void)
38{
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000039 /* Initialize SMP */
40 pnv_smp_init();
41
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000042 /* Setup PCI */
43 pnv_pci_init();
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000044
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +000045 /* Setup RTC and NVRAM callbacks */
46 if (firmware_has_feature(FW_FEATURE_OPAL))
47 opal_nvram_init();
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000048
49 /* Enable NAP mode */
50 powersave_nap = 1;
51
52 /* XXX PMCS */
53}
54
55static void __init pnv_init_early(void)
56{
Benjamin Herrenschmidtdaea1172011-09-19 17:44:59 +000057#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);
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000063}
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);
Benjamin Herrenschmidt75b93da2013-05-14 15:10:02 +100081 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))
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000084 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");
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000089 of_node_put(root);
90}
91
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +000092static void __noreturn pnv_restart(char *cmd)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000093{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +000094 long rc = OPAL_BUSY;
95
Gavin Shane8e71fa2013-06-20 18:13:23 +080096 opal_notifier_disable();
97
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +000098 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
99 rc = opal_cec_reboot();
100 if (rc == OPAL_BUSY_EVENT)
101 opal_poll_events(NULL);
102 else
103 mdelay(10);
104 }
105 for (;;)
106 opal_poll_events(NULL);
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000107}
108
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000109static void __noreturn pnv_power_off(void)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000110{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000111 long rc = OPAL_BUSY;
112
Gavin Shane8e71fa2013-06-20 18:13:23 +0800113 opal_notifier_disable();
114
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000115 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
116 rc = opal_cec_power_down(0);
117 if (rc == OPAL_BUSY_EVENT)
118 opal_poll_events(NULL);
119 else
120 mdelay(10);
121 }
122 for (;;)
123 opal_poll_events(NULL);
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000124}
125
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000126static void __noreturn pnv_halt(void)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000127{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000128 pnv_power_off();
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000129}
130
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000131static void pnv_progress(char *s, unsigned short hex)
132{
133}
134
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000135static void pnv_shutdown(void)
136{
137 /* Let the PCI code clear up IODA tables */
138 pnv_pci_shutdown();
139
140 /* And unregister all OPAL interrupts so they don't fire
141 * up while we kexec
142 */
143 opal_shutdown();
144}
145
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000146#ifdef CONFIG_KEXEC
147static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
148{
149 xics_kexec_teardown_cpu(secondary);
150}
151#endif /* CONFIG_KEXEC */
152
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000153static void __init pnv_setup_machdep_opal(void)
154{
155 ppc_md.get_boot_time = opal_get_boot_time;
156 ppc_md.get_rtc_time = opal_get_rtc_time;
157 ppc_md.set_rtc_time = opal_set_rtc_time;
158 ppc_md.restart = pnv_restart;
159 ppc_md.power_off = pnv_power_off;
160 ppc_md.halt = pnv_halt;
Benjamin Herrenschmidted79ba92011-09-19 17:45:04 +0000161 ppc_md.machine_check_exception = opal_machine_check;
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000162}
163
164#ifdef CONFIG_PPC_POWERNV_RTAS
165static void __init pnv_setup_machdep_rtas(void)
166{
167 if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
168 ppc_md.get_boot_time = rtas_get_boot_time;
169 ppc_md.get_rtc_time = rtas_get_rtc_time;
170 ppc_md.set_rtc_time = rtas_set_rtc_time;
171 }
172 ppc_md.restart = rtas_restart;
173 ppc_md.power_off = rtas_power_off;
174 ppc_md.halt = rtas_halt;
175}
176#endif /* CONFIG_PPC_POWERNV_RTAS */
177
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000178static int __init pnv_probe(void)
179{
180 unsigned long root = of_get_flat_dt_root();
181
182 if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
183 return 0;
184
185 hpte_init_native();
186
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000187 if (firmware_has_feature(FW_FEATURE_OPAL))
188 pnv_setup_machdep_opal();
189#ifdef CONFIG_PPC_POWERNV_RTAS
190 else if (rtas.base)
191 pnv_setup_machdep_rtas();
192#endif /* CONFIG_PPC_POWERNV_RTAS */
193
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000194 pr_debug("PowerNV detected !\n");
195
196 return 1;
197}
198
199define_machine(powernv) {
200 .name = "PowerNV",
201 .probe = pnv_probe,
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000202 .init_early = pnv_init_early,
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000203 .setup_arch = pnv_setup_arch,
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000204 .init_IRQ = pnv_init_IRQ,
205 .show_cpuinfo = pnv_show_cpuinfo,
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000206 .progress = pnv_progress,
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000207 .machine_shutdown = pnv_shutdown,
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000208 .power_save = power7_idle,
209 .calibrate_decr = generic_calibrate_decr,
210#ifdef CONFIG_KEXEC
211 .kexec_cpu_down = pnv_kexec_cpu_down,
212#endif
213};