1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 NXP Semiconductor, Inc.
7 #include <linux/libfdt.h>
8 #include <fdt_support.h>
9 #include <linux/sizes.h>
10 #include <linux/kernel.h>
12 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
13 #include <asm/armv8/sec_firmware.h>
16 int fdt_psci(void *fdt)
18 #if defined(CONFIG_ARMV7_PSCI) || defined(CONFIG_ARMV8_PSCI) || \
19 defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
21 unsigned int psci_ver = 0;
24 nodeoff = fdt_path_offset(fdt, "/cpus");
26 printf("couldn't find /cpus\n");
30 /* add 'enable-method = "psci"' to each cpu node */
31 for (tmp = fdt_first_subnode(fdt, nodeoff);
33 tmp = fdt_next_subnode(fdt, tmp)) {
34 const struct fdt_property *prop;
37 prop = fdt_get_property(fdt, tmp, "device_type", &len);
42 if (strcmp(prop->data, "cpu"))
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
50 fdt_setprop_string(fdt, tmp, "enable-method", "psci");
53 nodeoff = fdt_path_offset(fdt, "/psci");
57 nodeoff = fdt_path_offset(fdt, "/");
61 nodeoff = fdt_add_subnode(fdt, nodeoff, "psci");
66 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
67 psci_ver = sec_firmware_support_psci_version();
68 #elif defined(CONFIG_ARMV7_PSCI_1_0) || defined(CONFIG_ARMV8_PSCI)
69 psci_ver = ARM_PSCI_VER_1_0;
71 if (psci_ver >= ARM_PSCI_VER_1_0) {
72 tmp = fdt_setprop_string(fdt, nodeoff,
73 "compatible", "arm,psci-1.0");
78 if (psci_ver >= ARM_PSCI_VER_0_2) {
79 tmp = fdt_appendprop_string(fdt, nodeoff,
80 "compatible", "arm,psci-0.2");
85 #ifndef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
87 * The Secure firmware framework isn't able to support PSCI version 0.1.
89 if (psci_ver < ARM_PSCI_VER_0_2) {
90 tmp = fdt_appendprop_string(fdt, nodeoff,
91 "compatible", "arm,psci");
94 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_suspend",
95 ARM_PSCI_FN_CPU_SUSPEND);
98 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_off",
102 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_on",
106 tmp = fdt_setprop_u32(fdt, nodeoff, "migrate",
107 ARM_PSCI_FN_MIGRATE);
113 tmp = fdt_setprop_string(fdt, nodeoff, "method", "smc");