blob: 0fac0a6c951ead5b664d01e3835acd1c76b0be4f [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 Herrenschmidtdaea1172011-09-19 17:44:59 +000032#include <asm/opal.h>
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000033
34#include "powernv.h"
35
36static void __init pnv_setup_arch(void)
37{
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000038 /* Initialize SMP */
39 pnv_smp_init();
40
41 /* XXX PCI */
42
43 /* XXX NVRAM */
44
45 /* Enable NAP mode */
46 powersave_nap = 1;
47
48 /* XXX PMCS */
49}
50
51static void __init pnv_init_early(void)
52{
Benjamin Herrenschmidtdaea1172011-09-19 17:44:59 +000053#ifdef CONFIG_HVC_OPAL
54 if (firmware_has_feature(FW_FEATURE_OPAL))
55 hvc_opal_init_early();
56 else
57#endif
58 add_preferred_console("hvc", 0, NULL);
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000059}
60
61static void __init pnv_init_IRQ(void)
62{
63 xics_init();
64
65 WARN_ON(!ppc_md.get_irq);
66}
67
68static void pnv_show_cpuinfo(struct seq_file *m)
69{
70 struct device_node *root;
71 const char *model = "";
72
73 root = of_find_node_by_path("/");
74 if (root)
75 model = of_get_property(root, "model", NULL);
76 seq_printf(m, "machine\t\t: PowerNV %s\n", model);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000077 if (firmware_has_feature(FW_FEATURE_OPALv2))
78 seq_printf(m, "firmware\t: OPAL v2\n");
79 else if (firmware_has_feature(FW_FEATURE_OPAL))
80 seq_printf(m, "firmware\t: OPAL v1\n");
81 else
82 seq_printf(m, "firmware\t: BML\n");
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000083 of_node_put(root);
84}
85
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +000086static void __noreturn pnv_restart(char *cmd)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000087{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +000088 long rc = OPAL_BUSY;
89
90 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
91 rc = opal_cec_reboot();
92 if (rc == OPAL_BUSY_EVENT)
93 opal_poll_events(NULL);
94 else
95 mdelay(10);
96 }
97 for (;;)
98 opal_poll_events(NULL);
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +000099}
100
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000101static void __noreturn pnv_power_off(void)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000102{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000103 long rc = OPAL_BUSY;
104
105 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
106 rc = opal_cec_power_down(0);
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_halt(void)
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000117{
Benjamin Herrenschmidtec273292011-09-19 18:28:03 +0000118 pnv_power_off();
Benjamin Herrenschmidt55190f82011-09-19 17:44:52 +0000119}
120
121static unsigned long __init pnv_get_boot_time(void)
122{
123 return 0;
124}
125
126static void pnv_get_rtc_time(struct rtc_time *rtc_tm)
127{
128}
129
130static int pnv_set_rtc_time(struct rtc_time *tm)
131{
132 return 0;
133}
134
135static void pnv_progress(char *s, unsigned short hex)
136{
137}
138
139#ifdef CONFIG_KEXEC
140static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
141{
142 xics_kexec_teardown_cpu(secondary);
143}
144#endif /* CONFIG_KEXEC */
145
146static int __init pnv_probe(void)
147{
148 unsigned long root = of_get_flat_dt_root();
149
150 if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
151 return 0;
152
153 hpte_init_native();
154
155 pr_debug("PowerNV detected !\n");
156
157 return 1;
158}
159
160define_machine(powernv) {
161 .name = "PowerNV",
162 .probe = pnv_probe,
163 .setup_arch = pnv_setup_arch,
164 .init_early = pnv_init_early,
165 .init_IRQ = pnv_init_IRQ,
166 .show_cpuinfo = pnv_show_cpuinfo,
167 .restart = pnv_restart,
168 .power_off = pnv_power_off,
169 .halt = pnv_halt,
170 .get_boot_time = pnv_get_boot_time,
171 .get_rtc_time = pnv_get_rtc_time,
172 .set_rtc_time = pnv_set_rtc_time,
173 .progress = pnv_progress,
174 .power_save = power7_idle,
175 .calibrate_decr = generic_calibrate_decr,
176#ifdef CONFIG_KEXEC
177 .kexec_cpu_down = pnv_kexec_cpu_down,
178#endif
179};