blob: be800a3bc9ebbfad81d6ecb6e9c7ff647edd7282 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hou Zhiqiangdae02772016-06-28 20:18:16 +08002/*
3 * Copyright 2016 NXP Semiconductor, Inc.
Hou Zhiqiangdae02772016-06-28 20:18:16 +08004 */
5
Simon Glass274e0b02020-05-10 11:39:56 -06006#include <asm/cache.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +09007#include <linux/libfdt.h>
Hou Zhiqiangdae02772016-06-28 20:18:16 +08008#include <fdt_support.h>
9#include <linux/sizes.h>
10#include <linux/kernel.h>
11#include <asm/psci.h>
Michael Walle16fd24c2020-11-18 17:45:54 +010012#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
Hou Zhiqiangdae02772016-06-28 20:18:16 +080013#include <asm/armv8/sec_firmware.h>
14#endif
15
16int fdt_psci(void *fdt)
17{
macro.wave.z@gmail.com05725ed2016-12-08 11:58:25 +080018#if defined(CONFIG_ARMV7_PSCI) || defined(CONFIG_ARMV8_PSCI) || \
Hou Zhiqiang6be115d2017-01-16 17:31:48 +080019 defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
Hou Zhiqiangdae02772016-06-28 20:18:16 +080020 int nodeoff;
21 unsigned int psci_ver = 0;
Hou Zhiqiangdae02772016-06-28 20:18:16 +080022 int tmp;
23
24 nodeoff = fdt_path_offset(fdt, "/cpus");
25 if (nodeoff < 0) {
26 printf("couldn't find /cpus\n");
27 return nodeoff;
28 }
29
30 /* add 'enable-method = "psci"' to each cpu node */
31 for (tmp = fdt_first_subnode(fdt, nodeoff);
32 tmp >= 0;
33 tmp = fdt_next_subnode(fdt, tmp)) {
34 const struct fdt_property *prop;
35 int len;
36
37 prop = fdt_get_property(fdt, tmp, "device_type", &len);
38 if (!prop)
39 continue;
40 if (len < 4)
41 continue;
42 if (strcmp(prop->data, "cpu"))
43 continue;
44
45 /*
46 * Not checking rv here, our approach is to skip over errors in
47 * individual cpu nodes, hopefully some of the nodes are
48 * processed correctly and those will boot
49 */
50 fdt_setprop_string(fdt, tmp, "enable-method", "psci");
51 }
52
Hou Zhiqiangdae02772016-06-28 20:18:16 +080053 nodeoff = fdt_path_offset(fdt, "/psci");
54 if (nodeoff >= 0)
55 goto init_psci_node;
56
Hou Zhiqiangdae02772016-06-28 20:18:16 +080057 nodeoff = fdt_path_offset(fdt, "/");
58 if (nodeoff < 0)
59 return nodeoff;
60
61 nodeoff = fdt_add_subnode(fdt, nodeoff, "psci");
62 if (nodeoff < 0)
63 return nodeoff;
64
65init_psci_node:
Michael Walle16fd24c2020-11-18 17:45:54 +010066#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
Hou Zhiqiangdae02772016-06-28 20:18:16 +080067 psci_ver = sec_firmware_support_psci_version();
macro.wave.z@gmail.com05725ed2016-12-08 11:58:25 +080068#elif defined(CONFIG_ARMV7_PSCI_1_0) || defined(CONFIG_ARMV8_PSCI)
Hou Zhiqiang72bc1f32016-07-29 18:26:37 +080069 psci_ver = ARM_PSCI_VER_1_0;
Stephen Warren4660cea2018-06-22 13:03:17 -060070#elif defined(CONFIG_ARMV7_PSCI_0_2)
71 psci_ver = ARM_PSCI_VER_0_2;
Hou Zhiqiangdae02772016-06-28 20:18:16 +080072#endif
Andre Heider7f2ef302018-02-09 08:10:22 +010073 if (psci_ver >= ARM_PSCI_VER_1_0) {
Hou Zhiqiang25f68612016-07-29 18:26:36 +080074 tmp = fdt_setprop_string(fdt, nodeoff,
75 "compatible", "arm,psci-1.0");
76 if (tmp)
77 return tmp;
Andre Heider7f2ef302018-02-09 08:10:22 +010078 }
79
80 if (psci_ver >= ARM_PSCI_VER_0_2) {
Hou Zhiqiang25f68612016-07-29 18:26:36 +080081 tmp = fdt_appendprop_string(fdt, nodeoff,
82 "compatible", "arm,psci-0.2");
83 if (tmp)
84 return tmp;
Andre Heider7f2ef302018-02-09 08:10:22 +010085 }
86
Michael Walle16fd24c2020-11-18 17:45:54 +010087#if !CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
Hou Zhiqiang25f68612016-07-29 18:26:36 +080088 /*
89 * The Secure firmware framework isn't able to support PSCI version 0.1.
90 */
Andre Heider7f2ef302018-02-09 08:10:22 +010091 if (psci_ver < ARM_PSCI_VER_0_2) {
Hou Zhiqiang25f68612016-07-29 18:26:36 +080092 tmp = fdt_appendprop_string(fdt, nodeoff,
93 "compatible", "arm,psci");
94 if (tmp)
95 return tmp;
96 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_suspend",
97 ARM_PSCI_FN_CPU_SUSPEND);
98 if (tmp)
99 return tmp;
100 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_off",
101 ARM_PSCI_FN_CPU_OFF);
102 if (tmp)
103 return tmp;
104 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_on",
105 ARM_PSCI_FN_CPU_ON);
106 if (tmp)
107 return tmp;
108 tmp = fdt_setprop_u32(fdt, nodeoff, "migrate",
109 ARM_PSCI_FN_MIGRATE);
110 if (tmp)
111 return tmp;
Hou Zhiqiangdae02772016-06-28 20:18:16 +0800112 }
Andre Heider7f2ef302018-02-09 08:10:22 +0100113#endif
Hou Zhiqiangdae02772016-06-28 20:18:16 +0800114
Hou Zhiqiangdae02772016-06-28 20:18:16 +0800115 tmp = fdt_setprop_string(fdt, nodeoff, "method", "smc");
116 if (tmp)
117 return tmp;
118
Stephen Warren874a9062018-06-22 13:03:18 -0600119 tmp = fdt_setprop_string(fdt, nodeoff, "status", "okay");
120 if (tmp)
121 return tmp;
122
Hou Zhiqiangdae02772016-06-28 20:18:16 +0800123#endif
124 return 0;
125}