Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2016 NXP Semiconductor, Inc. |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 7 | #include <linux/libfdt.h> |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 8 | #include <fdt_support.h> |
| 9 | #include <linux/sizes.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <asm/psci.h> |
| 12 | #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT |
| 13 | #include <asm/armv8/sec_firmware.h> |
| 14 | #endif |
| 15 | |
| 16 | int fdt_psci(void *fdt) |
| 17 | { |
macro.wave.z@gmail.com | 9a56175 | 2016-12-08 11:58:25 +0800 | [diff] [blame] | 18 | #if defined(CONFIG_ARMV7_PSCI) || defined(CONFIG_ARMV8_PSCI) || \ |
Hou Zhiqiang | daa9264 | 2017-01-16 17:31:48 +0800 | [diff] [blame] | 19 | defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI) |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 20 | int nodeoff; |
| 21 | unsigned int psci_ver = 0; |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 22 | 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 Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 53 | nodeoff = fdt_path_offset(fdt, "/psci"); |
| 54 | if (nodeoff >= 0) |
| 55 | goto init_psci_node; |
| 56 | |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 57 | 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 | |
| 65 | init_psci_node: |
| 66 | #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT |
| 67 | psci_ver = sec_firmware_support_psci_version(); |
macro.wave.z@gmail.com | 9a56175 | 2016-12-08 11:58:25 +0800 | [diff] [blame] | 68 | #elif defined(CONFIG_ARMV7_PSCI_1_0) || defined(CONFIG_ARMV8_PSCI) |
Hou Zhiqiang | bded218 | 2016-07-29 18:26:37 +0800 | [diff] [blame] | 69 | psci_ver = ARM_PSCI_VER_1_0; |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 70 | #endif |
Andre Heider | 678382c | 2018-02-09 08:10:22 +0100 | [diff] [blame] | 71 | if (psci_ver >= ARM_PSCI_VER_1_0) { |
Hou Zhiqiang | 2c77416 | 2016-07-29 18:26:36 +0800 | [diff] [blame] | 72 | tmp = fdt_setprop_string(fdt, nodeoff, |
| 73 | "compatible", "arm,psci-1.0"); |
| 74 | if (tmp) |
| 75 | return tmp; |
Andre Heider | 678382c | 2018-02-09 08:10:22 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | if (psci_ver >= ARM_PSCI_VER_0_2) { |
Hou Zhiqiang | 2c77416 | 2016-07-29 18:26:36 +0800 | [diff] [blame] | 79 | tmp = fdt_appendprop_string(fdt, nodeoff, |
| 80 | "compatible", "arm,psci-0.2"); |
| 81 | if (tmp) |
| 82 | return tmp; |
Andre Heider | 678382c | 2018-02-09 08:10:22 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | #ifndef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT |
Hou Zhiqiang | 2c77416 | 2016-07-29 18:26:36 +0800 | [diff] [blame] | 86 | /* |
| 87 | * The Secure firmware framework isn't able to support PSCI version 0.1. |
| 88 | */ |
Andre Heider | 678382c | 2018-02-09 08:10:22 +0100 | [diff] [blame] | 89 | if (psci_ver < ARM_PSCI_VER_0_2) { |
Hou Zhiqiang | 2c77416 | 2016-07-29 18:26:36 +0800 | [diff] [blame] | 90 | tmp = fdt_appendprop_string(fdt, nodeoff, |
| 91 | "compatible", "arm,psci"); |
| 92 | if (tmp) |
| 93 | return tmp; |
| 94 | tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_suspend", |
| 95 | ARM_PSCI_FN_CPU_SUSPEND); |
| 96 | if (tmp) |
| 97 | return tmp; |
| 98 | tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_off", |
| 99 | ARM_PSCI_FN_CPU_OFF); |
| 100 | if (tmp) |
| 101 | return tmp; |
| 102 | tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_on", |
| 103 | ARM_PSCI_FN_CPU_ON); |
| 104 | if (tmp) |
| 105 | return tmp; |
| 106 | tmp = fdt_setprop_u32(fdt, nodeoff, "migrate", |
| 107 | ARM_PSCI_FN_MIGRATE); |
| 108 | if (tmp) |
| 109 | return tmp; |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 110 | } |
Andre Heider | 678382c | 2018-02-09 08:10:22 +0100 | [diff] [blame] | 111 | #endif |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 112 | |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 113 | tmp = fdt_setprop_string(fdt, nodeoff, "method", "smc"); |
| 114 | if (tmp) |
| 115 | return tmp; |
| 116 | |
Hou Zhiqiang | 45684ae | 2016-06-28 20:18:16 +0800 | [diff] [blame] | 117 | #endif |
| 118 | return 0; |
| 119 | } |