aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshwin Chaugule <ashwin.chaugule@linaro.org>2014-04-17 14:38:41 -0400
committerAshwin Chaugule <ashwin.chaugule@linaro.org>2014-05-15 10:16:00 -0400
commite71246a23acbc89e9cb4ebf1558d60e65733479f (patch)
tree733dd0f1f714b4b6473c7dade260861f5e51f551
parent4447a208f7fc2e2dff8c6a8df2a1fd6dd72fb3e2 (diff)
PSCI: Add initial support for PSCIv0.2 functions
The PSCIv0.2 spec defines standard values of function IDs and introduces a few new functions. Detect version of PSCI and appropriately select the right PSCI functions. Signed-off-by: Ashwin Chaugule <ashwin.chaugule@linaro.org> Reviewed-by: Rob Herring <robh@kernel.org> Acked-by: Catalin Marinas <catalin.marinas@arm.com>
-rw-r--r--arch/arm/include/asm/psci.h7
-rw-r--r--arch/arm/kernel/psci.c196
-rw-r--r--arch/arm64/include/asm/psci.h2
-rw-r--r--arch/arm64/kernel/psci.c200
4 files changed, 328 insertions, 77 deletions
diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
index c4ae171850f8..b93e34a9fdf1 100644
--- a/arch/arm/include/asm/psci.h
+++ b/arch/arm/include/asm/psci.h
@@ -29,16 +29,19 @@ struct psci_operations {
29 int (*cpu_off)(struct psci_power_state state); 29 int (*cpu_off)(struct psci_power_state state);
30 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point); 30 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
31 int (*migrate)(unsigned long cpuid); 31 int (*migrate)(unsigned long cpuid);
32 int (*affinity_info)(unsigned long target_affinity,
33 unsigned long lowest_affinity_level);
34 int (*migrate_info_type)(void);
32}; 35};
33 36
34extern struct psci_operations psci_ops; 37extern struct psci_operations psci_ops;
35extern struct smp_operations psci_smp_ops; 38extern struct smp_operations psci_smp_ops;
36 39
37#ifdef CONFIG_ARM_PSCI 40#ifdef CONFIG_ARM_PSCI
38void psci_init(void); 41int psci_init(void);
39bool psci_smp_available(void); 42bool psci_smp_available(void);
40#else 43#else
41static inline void psci_init(void) { } 44static inline int psci_init(void) { }
42static inline bool psci_smp_available(void) { return false; } 45static inline bool psci_smp_available(void) { return false; }
43#endif 46#endif
44 47
diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
index 46931880093d..f73891b6b730 100644
--- a/arch/arm/kernel/psci.c
+++ b/arch/arm/kernel/psci.c
@@ -17,63 +17,58 @@
17 17
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/of.h> 19#include <linux/of.h>
20#include <linux/reboot.h>
21#include <linux/pm.h>
22#include <uapi/linux/psci.h>
20 23
21#include <asm/compiler.h> 24#include <asm/compiler.h>
22#include <asm/errno.h> 25#include <asm/errno.h>
23#include <asm/opcodes-sec.h> 26#include <asm/opcodes-sec.h>
24#include <asm/opcodes-virt.h> 27#include <asm/opcodes-virt.h>
25#include <asm/psci.h> 28#include <asm/psci.h>
29#include <asm/system_misc.h>
26 30
27struct psci_operations psci_ops; 31struct psci_operations psci_ops;
28 32
29static int (*invoke_psci_fn)(u32, u32, u32, u32); 33static int (*invoke_psci_fn)(u32, u32, u32, u32);
34typedef int (*psci_initcall_t)(const struct device_node *);
30 35
31enum psci_function { 36enum psci_function {
32 PSCI_FN_CPU_SUSPEND, 37 PSCI_FN_CPU_SUSPEND,
33 PSCI_FN_CPU_ON, 38 PSCI_FN_CPU_ON,
34 PSCI_FN_CPU_OFF, 39 PSCI_FN_CPU_OFF,
35 PSCI_FN_MIGRATE, 40 PSCI_FN_MIGRATE,
41 PSCI_FN_AFFINITY_INFO,
42 PSCI_FN_MIGRATE_INFO_TYPE,
36 PSCI_FN_MAX, 43 PSCI_FN_MAX,
37}; 44};
38 45
39static u32 psci_function_id[PSCI_FN_MAX]; 46static u32 psci_function_id[PSCI_FN_MAX];
40 47
41#define PSCI_RET_SUCCESS 0
42#define PSCI_RET_EOPNOTSUPP -1
43#define PSCI_RET_EINVAL -2
44#define PSCI_RET_EPERM -3
45
46static int psci_to_linux_errno(int errno) 48static int psci_to_linux_errno(int errno)
47{ 49{
48 switch (errno) { 50 switch (errno) {
49 case PSCI_RET_SUCCESS: 51 case PSCI_RET_SUCCESS:
50 return 0; 52 return 0;
51 case PSCI_RET_EOPNOTSUPP: 53 case PSCI_RET_NOT_SUPPORTED:
52 return -EOPNOTSUPP; 54 return -EOPNOTSUPP;
53 case PSCI_RET_EINVAL: 55 case PSCI_RET_INVALID_PARAMS:
54 return -EINVAL; 56 return -EINVAL;
55 case PSCI_RET_EPERM: 57 case PSCI_RET_DENIED:
56 return -EPERM; 58 return -EPERM;
57 }; 59 };
58 60
59 return -EINVAL; 61 return -EINVAL;
60} 62}
61 63
62#define PSCI_POWER_STATE_ID_MASK 0xffff
63#define PSCI_POWER_STATE_ID_SHIFT 0
64#define PSCI_POWER_STATE_TYPE_MASK 0x1
65#define PSCI_POWER_STATE_TYPE_SHIFT 16
66#define PSCI_POWER_STATE_AFFL_MASK 0x3
67#define PSCI_POWER_STATE_AFFL_SHIFT 24
68
69static u32 psci_power_state_pack(struct psci_power_state state) 64static u32 psci_power_state_pack(struct psci_power_state state)
70{ 65{
71 return ((state.id & PSCI_POWER_STATE_ID_MASK) 66 return ((state.id << PSCI_0_2_POWER_STATE_ID_SHIFT)
72 << PSCI_POWER_STATE_ID_SHIFT) | 67 & PSCI_0_2_POWER_STATE_ID_MASK) |
73 ((state.type & PSCI_POWER_STATE_TYPE_MASK) 68 ((state.type << PSCI_0_2_POWER_STATE_TYPE_SHIFT)
74 << PSCI_POWER_STATE_TYPE_SHIFT) | 69 & PSCI_0_2_POWER_STATE_TYPE_MASK) |
75 ((state.affinity_level & PSCI_POWER_STATE_AFFL_MASK) 70 ((state.affinity_level << PSCI_0_2_POWER_STATE_AFFL_SHIFT)
76 << PSCI_POWER_STATE_AFFL_SHIFT); 71 & PSCI_0_2_POWER_STATE_AFFL_MASK);
77} 72}
78 73
79/* 74/*
@@ -110,6 +105,14 @@ static noinline int __invoke_psci_fn_smc(u32 function_id, u32 arg0, u32 arg1,
110 return function_id; 105 return function_id;
111} 106}
112 107
108static int psci_get_version(void)
109{
110 int err;
111
112 err = invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
113 return err;
114}
115
113static int psci_cpu_suspend(struct psci_power_state state, 116static int psci_cpu_suspend(struct psci_power_state state,
114 unsigned long entry_point) 117 unsigned long entry_point)
115{ 118{
@@ -153,26 +156,36 @@ static int psci_migrate(unsigned long cpuid)
153 return psci_to_linux_errno(err); 156 return psci_to_linux_errno(err);
154} 157}
155 158
156static const struct of_device_id psci_of_match[] __initconst = { 159static int psci_affinity_info(unsigned long target_affinity,
157 { .compatible = "arm,psci", }, 160 unsigned long lowest_affinity_level)
158 {}, 161{
159}; 162 int err;
163 u32 fn;
164
165 fn = psci_function_id[PSCI_FN_AFFINITY_INFO];
166 err = invoke_psci_fn(fn, target_affinity, lowest_affinity_level, 0);
167 return err;
168}
160 169
161void __init psci_init(void) 170static int psci_migrate_info_type(void)
162{ 171{
163 struct device_node *np; 172 int err;
164 const char *method; 173 u32 fn;
165 u32 id;
166 174
167 np = of_find_matching_node(NULL, psci_of_match); 175 fn = psci_function_id[PSCI_FN_MIGRATE_INFO_TYPE];
168 if (!np) 176 err = invoke_psci_fn(fn, 0, 0, 0);
169 return; 177 return err;
178}
179
180static int get_set_conduit_method(struct device_node *np)
181{
182 const char *method;
170 183
171 pr_info("probing function IDs from device-tree\n"); 184 pr_info("probing for conduit method from DT.\n");
172 185
173 if (of_property_read_string(np, "method", &method)) { 186 if (of_property_read_string(np, "method", &method)) {
174 pr_warning("missing \"method\" property\n"); 187 pr_warn("missing \"method\" property\n");
175 goto out_put_node; 188 return -ENXIO;
176 } 189 }
177 190
178 if (!strcmp("hvc", method)) { 191 if (!strcmp("hvc", method)) {
@@ -180,10 +193,99 @@ void __init psci_init(void)
180 } else if (!strcmp("smc", method)) { 193 } else if (!strcmp("smc", method)) {
181 invoke_psci_fn = __invoke_psci_fn_smc; 194 invoke_psci_fn = __invoke_psci_fn_smc;
182 } else { 195 } else {
183 pr_warning("invalid \"method\" property: %s\n", method); 196 pr_warn("invalid \"method\" property: %s\n", method);
197 return -EINVAL;
198 }
199 return 0;
200}
201
202static void psci_sys_reset(enum reboot_mode reboot_mode, const char *cmd)
203{
204 invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
205}
206
207static void psci_sys_poweroff(void)
208{
209 invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
210}
211
212/*
213 * PSCI Function IDs for v0.2+ are well defined so use
214 * standard values.
215 */
216static int psci_0_2_init(struct device_node *np)
217{
218 int err, ver;
219
220 err = get_set_conduit_method(np);
221
222 if (err)
223 goto out_put_node;
224
225 ver = psci_get_version();
226
227 if (ver == PSCI_RET_NOT_SUPPORTED) {
228 /* PSCI v0.2 mandates implementation of PSCI_ID_VERSION. */
229 pr_err("PSCI firmware does not comply with the v0.2 spec.\n");
230 err = -EOPNOTSUPP;
184 goto out_put_node; 231 goto out_put_node;
232 } else {
233 pr_info("PSCIv%d.%d detected in firmware.\n",
234 PSCI_VERSION_MAJOR(ver),
235 PSCI_VERSION_MINOR(ver));
236
237 if (PSCI_VERSION_MAJOR(ver) == 0 &&
238 PSCI_VERSION_MINOR(ver) < 2) {
239 err = -EINVAL;
240 pr_err("Conflicting PSCI version detected.\n");
241 goto out_put_node;
242 }
185 } 243 }
186 244
245 pr_info("Using standard PSCI v0.2 function IDs\n");
246 psci_function_id[PSCI_FN_CPU_SUSPEND] = PSCI_0_2_FN_CPU_SUSPEND;
247 psci_ops.cpu_suspend = psci_cpu_suspend;
248
249 psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF;
250 psci_ops.cpu_off = psci_cpu_off;
251
252 psci_function_id[PSCI_FN_CPU_ON] = PSCI_0_2_FN_CPU_ON;
253 psci_ops.cpu_on = psci_cpu_on;
254
255 psci_function_id[PSCI_FN_MIGRATE] = PSCI_0_2_FN_MIGRATE;
256 psci_ops.migrate = psci_migrate;
257
258 psci_function_id[PSCI_FN_AFFINITY_INFO] = PSCI_0_2_FN_AFFINITY_INFO;
259 psci_ops.affinity_info = psci_affinity_info;
260
261 psci_function_id[PSCI_FN_MIGRATE_INFO_TYPE] =
262 PSCI_0_2_FN_MIGRATE_INFO_TYPE;
263 psci_ops.migrate_info_type = psci_migrate_info_type;
264
265 arm_pm_restart = psci_sys_reset;
266
267 pm_power_off = psci_sys_poweroff;
268
269out_put_node:
270 of_node_put(np);
271 return err;
272}
273
274/*
275 * PSCI < v0.2 get PSCI Function IDs via DT.
276 */
277static int psci_0_1_init(struct device_node *np)
278{
279 u32 id;
280 int err;
281
282 err = get_set_conduit_method(np);
283
284 if (err)
285 goto out_put_node;
286
287 pr_info("Using PSCI v0.1 Function IDs from DT\n");
288
187 if (!of_property_read_u32(np, "cpu_suspend", &id)) { 289 if (!of_property_read_u32(np, "cpu_suspend", &id)) {
188 psci_function_id[PSCI_FN_CPU_SUSPEND] = id; 290 psci_function_id[PSCI_FN_CPU_SUSPEND] = id;
189 psci_ops.cpu_suspend = psci_cpu_suspend; 291 psci_ops.cpu_suspend = psci_cpu_suspend;
@@ -206,5 +308,25 @@ void __init psci_init(void)
206 308
207out_put_node: 309out_put_node:
208 of_node_put(np); 310 of_node_put(np);
209 return; 311 return err;
312}
313
314static const struct of_device_id psci_of_match[] __initconst = {
315 { .compatible = "arm,psci", .data = psci_0_1_init},
316 { .compatible = "arm,psci-0.2", .data = psci_0_2_init},
317 {},
318};
319
320int __init psci_init(void)
321{
322 struct device_node *np;
323 const struct of_device_id *matched_np;
324 psci_initcall_t init_fn;
325
326 np = of_find_matching_node_and_match(NULL, psci_of_match, &matched_np);
327 if (!np)
328 return -ENODEV;
329
330 init_fn = (psci_initcall_t)matched_np->data;
331 return init_fn(np);
210} 332}
diff --git a/arch/arm64/include/asm/psci.h b/arch/arm64/include/asm/psci.h
index d15ab8b46336..e5312ea0ec1a 100644
--- a/arch/arm64/include/asm/psci.h
+++ b/arch/arm64/include/asm/psci.h
@@ -14,6 +14,6 @@
14#ifndef __ASM_PSCI_H 14#ifndef __ASM_PSCI_H
15#define __ASM_PSCI_H 15#define __ASM_PSCI_H
16 16
17void psci_init(void); 17int psci_init(void);
18 18
19#endif /* __ASM_PSCI_H */ 19#endif /* __ASM_PSCI_H */
diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
index ea4828a4aa96..90df6e641227 100644
--- a/arch/arm64/kernel/psci.c
+++ b/arch/arm64/kernel/psci.c
@@ -18,12 +18,16 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/of.h> 19#include <linux/of.h>
20#include <linux/smp.h> 20#include <linux/smp.h>
21#include <linux/reboot.h>
22#include <linux/pm.h>
23#include <uapi/linux/psci.h>
21 24
22#include <asm/compiler.h> 25#include <asm/compiler.h>
23#include <asm/cpu_ops.h> 26#include <asm/cpu_ops.h>
24#include <asm/errno.h> 27#include <asm/errno.h>
25#include <asm/psci.h> 28#include <asm/psci.h>
26#include <asm/smp_plat.h> 29#include <asm/smp_plat.h>
30#include <asm/system_misc.h>
27 31
28#define PSCI_POWER_STATE_TYPE_STANDBY 0 32#define PSCI_POWER_STATE_TYPE_STANDBY 0
29#define PSCI_POWER_STATE_TYPE_POWER_DOWN 1 33#define PSCI_POWER_STATE_TYPE_POWER_DOWN 1
@@ -40,58 +44,52 @@ struct psci_operations {
40 int (*cpu_off)(struct psci_power_state state); 44 int (*cpu_off)(struct psci_power_state state);
41 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point); 45 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
42 int (*migrate)(unsigned long cpuid); 46 int (*migrate)(unsigned long cpuid);
47 int (*affinity_info)(unsigned long target_affinity,
48 unsigned long lowest_affinity_level);
49 int (*migrate_info_type)(void);
43}; 50};
44 51
45static struct psci_operations psci_ops; 52static struct psci_operations psci_ops;
46 53
47static int (*invoke_psci_fn)(u64, u64, u64, u64); 54static int (*invoke_psci_fn)(u64, u64, u64, u64);
55typedef int (*psci_initcall_t)(const struct device_node *);
48 56
49enum psci_function { 57enum psci_function {
50 PSCI_FN_CPU_SUSPEND, 58 PSCI_FN_CPU_SUSPEND,
51 PSCI_FN_CPU_ON, 59 PSCI_FN_CPU_ON,
52 PSCI_FN_CPU_OFF, 60 PSCI_FN_CPU_OFF,
53 PSCI_FN_MIGRATE, 61 PSCI_FN_MIGRATE,
62 PSCI_FN_AFFINITY_INFO,
63 PSCI_FN_MIGRATE_INFO_TYPE,
54 PSCI_FN_MAX, 64 PSCI_FN_MAX,
55}; 65};
56 66
57static u32 psci_function_id[PSCI_FN_MAX]; 67static u32 psci_function_id[PSCI_FN_MAX];
58 68
59#define PSCI_RET_SUCCESS 0
60#define PSCI_RET_EOPNOTSUPP -1
61#define PSCI_RET_EINVAL -2
62#define PSCI_RET_EPERM -3
63
64static int psci_to_linux_errno(int errno) 69static int psci_to_linux_errno(int errno)
65{ 70{
66 switch (errno) { 71 switch (errno) {
67 case PSCI_RET_SUCCESS: 72 case PSCI_RET_SUCCESS:
68 return 0; 73 return 0;
69 case PSCI_RET_EOPNOTSUPP: 74 case PSCI_RET_NOT_SUPPORTED:
70 return -EOPNOTSUPP; 75 return -EOPNOTSUPP;
71 case PSCI_RET_EINVAL: 76 case PSCI_RET_INVALID_PARAMS:
72 return -EINVAL; 77 return -EINVAL;
73 case PSCI_RET_EPERM: 78 case PSCI_RET_DENIED:
74 return -EPERM; 79 return -EPERM;
75 }; 80 };
76 81
77 return -EINVAL; 82 return -EINVAL;
78} 83}
79 84
80#define PSCI_POWER_STATE_ID_MASK 0xffff
81#define PSCI_POWER_STATE_ID_SHIFT 0
82#define PSCI_POWER_STATE_TYPE_MASK 0x1
83#define PSCI_POWER_STATE_TYPE_SHIFT 16
84#define PSCI_POWER_STATE_AFFL_MASK 0x3
85#define PSCI_POWER_STATE_AFFL_SHIFT 24
86
87static u32 psci_power_state_pack(struct psci_power_state state) 85static u32 psci_power_state_pack(struct psci_power_state state)
88{ 86{
89 return ((state.id & PSCI_POWER_STATE_ID_MASK) 87 return ((state.id << PSCI_0_2_POWER_STATE_ID_SHIFT)
90 << PSCI_POWER_STATE_ID_SHIFT) | 88 & PSCI_0_2_POWER_STATE_ID_MASK) |
91 ((state.type & PSCI_POWER_STATE_TYPE_MASK) 89 ((state.type << PSCI_0_2_POWER_STATE_TYPE_SHIFT)
92 << PSCI_POWER_STATE_TYPE_SHIFT) | 90 & PSCI_0_2_POWER_STATE_TYPE_MASK) |
93 ((state.affinity_level & PSCI_POWER_STATE_AFFL_MASK) 91 ((state.affinity_level << PSCI_0_2_POWER_STATE_AFFL_SHIFT)
94 << PSCI_POWER_STATE_AFFL_SHIFT); 92 & PSCI_0_2_POWER_STATE_AFFL_MASK);
95} 93}
96 94
97/* 95/*
@@ -128,6 +126,14 @@ static noinline int __invoke_psci_fn_smc(u64 function_id, u64 arg0, u64 arg1,
128 return function_id; 126 return function_id;
129} 127}
130 128
129static int psci_get_version(void)
130{
131 int err;
132
133 err = invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
134 return err;
135}
136
131static int psci_cpu_suspend(struct psci_power_state state, 137static int psci_cpu_suspend(struct psci_power_state state,
132 unsigned long entry_point) 138 unsigned long entry_point)
133{ 139{
@@ -171,26 +177,36 @@ static int psci_migrate(unsigned long cpuid)
171 return psci_to_linux_errno(err); 177 return psci_to_linux_errno(err);
172} 178}
173 179
174static const struct of_device_id psci_of_match[] __initconst = { 180static int psci_affinity_info(unsigned long target_affinity,
175 { .compatible = "arm,psci", }, 181 unsigned long lowest_affinity_level)
176 {}, 182{
177}; 183 int err;
184 u32 fn;
185
186 fn = psci_function_id[PSCI_FN_AFFINITY_INFO];
187 err = invoke_psci_fn(fn, target_affinity, lowest_affinity_level, 0);
188 return err;
189}
178 190
179void __init psci_init(void) 191static int psci_migrate_info_type(void)
180{ 192{
181 struct device_node *np; 193 int err;
182 const char *method; 194 u32 fn;
183 u32 id;
184 195
185 np = of_find_matching_node(NULL, psci_of_match); 196 fn = psci_function_id[PSCI_FN_MIGRATE_INFO_TYPE];
186 if (!np) 197 err = invoke_psci_fn(fn, 0, 0, 0);
187 return; 198 return err;
199}
200
201static int get_set_conduit_method(struct device_node *np)
202{
203 const char *method;
188 204
189 pr_info("probing function IDs from device-tree\n"); 205 pr_info("probing for conduit method from DT.\n");
190 206
191 if (of_property_read_string(np, "method", &method)) { 207 if (of_property_read_string(np, "method", &method)) {
192 pr_warning("missing \"method\" property\n"); 208 pr_warn("missing \"method\" property\n");
193 goto out_put_node; 209 return -ENXIO;
194 } 210 }
195 211
196 if (!strcmp("hvc", method)) { 212 if (!strcmp("hvc", method)) {
@@ -198,10 +214,99 @@ void __init psci_init(void)
198 } else if (!strcmp("smc", method)) { 214 } else if (!strcmp("smc", method)) {
199 invoke_psci_fn = __invoke_psci_fn_smc; 215 invoke_psci_fn = __invoke_psci_fn_smc;
200 } else { 216 } else {
201 pr_warning("invalid \"method\" property: %s\n", method); 217 pr_warn("invalid \"method\" property: %s\n", method);
218 return -EINVAL;
219 }
220 return 0;
221}
222
223static void psci_sys_reset(enum reboot_mode reboot_mode, const char *cmd)
224{
225 invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
226}
227
228static void psci_sys_poweroff(void)
229{
230 invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
231}
232
233/*
234 * PSCI Function IDs for v0.2+ are well defined so use
235 * standard values.
236 */
237static int psci_0_2_init(struct device_node *np)
238{
239 int err, ver;
240
241 err = get_set_conduit_method(np);
242
243 if (err)
244 goto out_put_node;
245
246 ver = psci_get_version();
247
248 if (ver == PSCI_RET_NOT_SUPPORTED) {
249 /* PSCI v0.2 mandates implementation of PSCI_ID_VERSION. */
250 pr_err("PSCI firmware does not comply with the v0.2 spec.\n");
251 err = -EOPNOTSUPP;
202 goto out_put_node; 252 goto out_put_node;
253 } else {
254 pr_info("PSCIv%d.%d detected in firmware.\n",
255 PSCI_VERSION_MAJOR(ver),
256 PSCI_VERSION_MINOR(ver));
257
258 if (PSCI_VERSION_MAJOR(ver) == 0 &&
259 PSCI_VERSION_MINOR(ver) < 2) {
260 err = -EINVAL;
261 pr_err("Conflicting PSCI version detected.\n");
262 goto out_put_node;
263 }
203 } 264 }
204 265
266 pr_info("Using standard PSCI v0.2 function IDs\n");
267 psci_function_id[PSCI_FN_CPU_SUSPEND] = PSCI_0_2_FN64_CPU_SUSPEND;
268 psci_ops.cpu_suspend = psci_cpu_suspend;
269
270 psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF;
271 psci_ops.cpu_off = psci_cpu_off;
272
273 psci_function_id[PSCI_FN_CPU_ON] = PSCI_0_2_FN64_CPU_ON;
274 psci_ops.cpu_on = psci_cpu_on;
275
276 psci_function_id[PSCI_FN_MIGRATE] = PSCI_0_2_FN64_MIGRATE;
277 psci_ops.migrate = psci_migrate;
278
279 psci_function_id[PSCI_FN_AFFINITY_INFO] = PSCI_0_2_FN64_AFFINITY_INFO;
280 psci_ops.affinity_info = psci_affinity_info;
281
282 psci_function_id[PSCI_FN_MIGRATE_INFO_TYPE] =
283 PSCI_0_2_FN_MIGRATE_INFO_TYPE;
284 psci_ops.migrate_info_type = psci_migrate_info_type;
285
286 arm_pm_restart = psci_sys_reset;
287
288 pm_power_off = psci_sys_poweroff;
289
290out_put_node:
291 of_node_put(np);
292 return err;
293}
294
295/*
296 * PSCI < v0.2 get PSCI Function IDs via DT.
297 */
298static int psci_0_1_init(struct device_node *np)
299{
300 u32 id;
301 int err;
302
303 err = get_set_conduit_method(np);
304
305 if (err)
306 goto out_put_node;
307
308 pr_info("Using PSCI v0.1 Function IDs from DT\n");
309
205 if (!of_property_read_u32(np, "cpu_suspend", &id)) { 310 if (!of_property_read_u32(np, "cpu_suspend", &id)) {
206 psci_function_id[PSCI_FN_CPU_SUSPEND] = id; 311 psci_function_id[PSCI_FN_CPU_SUSPEND] = id;
207 psci_ops.cpu_suspend = psci_cpu_suspend; 312 psci_ops.cpu_suspend = psci_cpu_suspend;
@@ -224,7 +329,28 @@ void __init psci_init(void)
224 329
225out_put_node: 330out_put_node:
226 of_node_put(np); 331 of_node_put(np);
227 return; 332 return err;
333}
334
335static const struct of_device_id psci_of_match[] __initconst = {
336 { .compatible = "arm,psci", .data = psci_0_1_init},
337 { .compatible = "arm,psci-0.2", .data = psci_0_2_init},
338 {},
339};
340
341int __init psci_init(void)
342{
343 struct device_node *np;
344 const struct of_device_id *matched_np;
345 psci_initcall_t init_fn;
346
347 np = of_find_matching_node_and_match(NULL, psci_of_match, &matched_np);
348
349 if (!np)
350 return -ENODEV;
351
352 init_fn = (psci_initcall_t)matched_np->data;
353 return init_fn(np);
228} 354}
229 355
230#ifdef CONFIG_SMP 356#ifdef CONFIG_SMP