blob: 903b3357048aa0d0dcdefbab91a9e3fa038edd8a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hou Zhiqiang45684ae2016-06-28 20:18:16 +08002/*
3 * Copyright 2016 NXP Semiconductor, Inc.
Hou Zhiqiang45684ae2016-06-28 20:18:16 +08004 */
5
6#include <common.h>
Simon Glass90526e92020-05-10 11:39:56 -06007#include <asm/cache.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +09008#include <linux/libfdt.h>
Hou Zhiqiang45684ae2016-06-28 20:18:16 +08009#include <fdt_support.h>
10#include <linux/sizes.h>
11#include <linux/kernel.h>
12#include <asm/psci.h>
Michael Walle59b07a22020-11-18 17:45:54 +010013#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080014#include <asm/armv8/sec_firmware.h>
15#endif
16
17int fdt_psci(void *fdt)
18{
macro.wave.z@gmail.com9a561752016-12-08 11:58:25 +080019#if defined(CONFIG_ARMV7_PSCI) || defined(CONFIG_ARMV8_PSCI) || \
Hou Zhiqiangdaa92642017-01-16 17:31:48 +080020 defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080021 int nodeoff;
22 unsigned int psci_ver = 0;
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080023 int tmp;
24
25 nodeoff = fdt_path_offset(fdt, "/cpus");
26 if (nodeoff < 0) {
27 printf("couldn't find /cpus\n");
28 return nodeoff;
29 }
30
31 /* add 'enable-method = "psci"' to each cpu node */
32 for (tmp = fdt_first_subnode(fdt, nodeoff);
33 tmp >= 0;
34 tmp = fdt_next_subnode(fdt, tmp)) {
35 const struct fdt_property *prop;
36 int len;
37
38 prop = fdt_get_property(fdt, tmp, "device_type", &len);
39 if (!prop)
40 continue;
41 if (len < 4)
42 continue;
43 if (strcmp(prop->data, "cpu"))
44 continue;
45
46 /*
47 * Not checking rv here, our approach is to skip over errors in
48 * individual cpu nodes, hopefully some of the nodes are
49 * processed correctly and those will boot
50 */
51 fdt_setprop_string(fdt, tmp, "enable-method", "psci");
52 }
53
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080054 nodeoff = fdt_path_offset(fdt, "/psci");
55 if (nodeoff >= 0)
56 goto init_psci_node;
57
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080058 nodeoff = fdt_path_offset(fdt, "/");
59 if (nodeoff < 0)
60 return nodeoff;
61
62 nodeoff = fdt_add_subnode(fdt, nodeoff, "psci");
63 if (nodeoff < 0)
64 return nodeoff;
65
66init_psci_node:
Michael Walle59b07a22020-11-18 17:45:54 +010067#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080068 psci_ver = sec_firmware_support_psci_version();
macro.wave.z@gmail.com9a561752016-12-08 11:58:25 +080069#elif defined(CONFIG_ARMV7_PSCI_1_0) || defined(CONFIG_ARMV8_PSCI)
Hou Zhiqiangbded2182016-07-29 18:26:37 +080070 psci_ver = ARM_PSCI_VER_1_0;
Stephen Warren326bd722018-06-22 13:03:17 -060071#elif defined(CONFIG_ARMV7_PSCI_0_2)
72 psci_ver = ARM_PSCI_VER_0_2;
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080073#endif
Andre Heider678382c2018-02-09 08:10:22 +010074 if (psci_ver >= ARM_PSCI_VER_1_0) {
Hou Zhiqiang2c774162016-07-29 18:26:36 +080075 tmp = fdt_setprop_string(fdt, nodeoff,
76 "compatible", "arm,psci-1.0");
77 if (tmp)
78 return tmp;
Andre Heider678382c2018-02-09 08:10:22 +010079 }
80
81 if (psci_ver >= ARM_PSCI_VER_0_2) {
Hou Zhiqiang2c774162016-07-29 18:26:36 +080082 tmp = fdt_appendprop_string(fdt, nodeoff,
83 "compatible", "arm,psci-0.2");
84 if (tmp)
85 return tmp;
Andre Heider678382c2018-02-09 08:10:22 +010086 }
87
Michael Walle59b07a22020-11-18 17:45:54 +010088#if !CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
Hou Zhiqiang2c774162016-07-29 18:26:36 +080089 /*
90 * The Secure firmware framework isn't able to support PSCI version 0.1.
91 */
Andre Heider678382c2018-02-09 08:10:22 +010092 if (psci_ver < ARM_PSCI_VER_0_2) {
Hou Zhiqiang2c774162016-07-29 18:26:36 +080093 tmp = fdt_appendprop_string(fdt, nodeoff,
94 "compatible", "arm,psci");
95 if (tmp)
96 return tmp;
97 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_suspend",
98 ARM_PSCI_FN_CPU_SUSPEND);
99 if (tmp)
100 return tmp;
101 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_off",
102 ARM_PSCI_FN_CPU_OFF);
103 if (tmp)
104 return tmp;
105 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_on",
106 ARM_PSCI_FN_CPU_ON);
107 if (tmp)
108 return tmp;
109 tmp = fdt_setprop_u32(fdt, nodeoff, "migrate",
110 ARM_PSCI_FN_MIGRATE);
111 if (tmp)
112 return tmp;
Hou Zhiqiang45684ae2016-06-28 20:18:16 +0800113 }
Andre Heider678382c2018-02-09 08:10:22 +0100114#endif
Hou Zhiqiang45684ae2016-06-28 20:18:16 +0800115
Hou Zhiqiang45684ae2016-06-28 20:18:16 +0800116 tmp = fdt_setprop_string(fdt, nodeoff, "method", "smc");
117 if (tmp)
118 return tmp;
119
Stephen Warren74c69cd2018-06-22 13:03:18 -0600120 tmp = fdt_setprop_string(fdt, nodeoff, "status", "okay");
121 if (tmp)
122 return tmp;
123
Hou Zhiqiang45684ae2016-06-28 20:18:16 +0800124#endif
125 return 0;
126}