1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 NXP Semiconductor, Inc.
8 #include <linux/libfdt.h>
9 #include <fdt_support.h>
10 #include <linux/sizes.h>
11 #include <linux/kernel.h>
13 #if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
14 #include <asm/armv8/sec_firmware.h>
17 int fdt_psci(void *fdt)
19 #if defined(CONFIG_ARMV7_PSCI) || defined(CONFIG_ARMV8_PSCI) || \
20 defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
22 unsigned int psci_ver = 0;
25 nodeoff = fdt_path_offset(fdt, "/cpus");
27 printf("couldn't find /cpus\n");
31 /* add 'enable-method = "psci"' to each cpu node */
32 for (tmp = fdt_first_subnode(fdt, nodeoff);
34 tmp = fdt_next_subnode(fdt, tmp)) {
35 const struct fdt_property *prop;
38 prop = fdt_get_property(fdt, tmp, "device_type", &len);
43 if (strcmp(prop->data, "cpu"))
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
51 fdt_setprop_string(fdt, tmp, "enable-method", "psci");
54 nodeoff = fdt_path_offset(fdt, "/psci");
58 nodeoff = fdt_path_offset(fdt, "/");
62 nodeoff = fdt_add_subnode(fdt, nodeoff, "psci");
67 #if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
68 psci_ver = sec_firmware_support_psci_version();
69 #elif defined(CONFIG_ARMV7_PSCI_1_0) || defined(CONFIG_ARMV8_PSCI)
70 psci_ver = ARM_PSCI_VER_1_0;
71 #elif defined(CONFIG_ARMV7_PSCI_0_2)
72 psci_ver = ARM_PSCI_VER_0_2;
74 if (psci_ver >= ARM_PSCI_VER_1_0) {
75 tmp = fdt_setprop_string(fdt, nodeoff,
76 "compatible", "arm,psci-1.0");
81 if (psci_ver >= ARM_PSCI_VER_0_2) {
82 tmp = fdt_appendprop_string(fdt, nodeoff,
83 "compatible", "arm,psci-0.2");
88 #if !CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
90 * The Secure firmware framework isn't able to support PSCI version 0.1.
92 if (psci_ver < ARM_PSCI_VER_0_2) {
93 tmp = fdt_appendprop_string(fdt, nodeoff,
94 "compatible", "arm,psci");
97 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_suspend",
98 ARM_PSCI_FN_CPU_SUSPEND);
101 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_off",
102 ARM_PSCI_FN_CPU_OFF);
105 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_on",
109 tmp = fdt_setprop_u32(fdt, nodeoff, "migrate",
110 ARM_PSCI_FN_MIGRATE);
116 tmp = fdt_setprop_string(fdt, nodeoff, "method", "smc");
120 tmp = fdt_setprop_string(fdt, nodeoff, "status", "okay");