blob: 41e139e7df350897c188cc1872c91fd8f6ada746 [file] [log] [blame]
Hou Zhiqiang45684ae2016-06-28 20:18:16 +08001/*
2 * Copyright 2016 NXP Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <libfdt.h>
9#include <fdt_support.h>
10#include <linux/sizes.h>
11#include <linux/kernel.h>
12#include <asm/psci.h>
13#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
14#include <asm/armv8/sec_firmware.h>
15#endif
16
17int fdt_psci(void *fdt)
18{
macro.wave.z@gmail.com2d16a1a2016-12-08 11:58:21 +080019#if defined(CONFIG_FSL_PPA_ARMV8_PSCI) || defined(CONFIG_ARMV7_PSCI)
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080020 int nodeoff;
21 unsigned int psci_ver = 0;
Hou Zhiqiang45684ae2016-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 Zhiqiang45684ae2016-06-28 20:18:16 +080053 nodeoff = fdt_path_offset(fdt, "/psci");
54 if (nodeoff >= 0)
55 goto init_psci_node;
56
Hou Zhiqiang45684ae2016-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:
66#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
67 psci_ver = sec_firmware_support_psci_version();
Hou Zhiqiangbded2182016-07-29 18:26:37 +080068#elif defined(CONFIG_ARMV7_PSCI_1_0)
69 psci_ver = ARM_PSCI_VER_1_0;
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080070#endif
71 switch (psci_ver) {
Hou Zhiqiang2c774162016-07-29 18:26:36 +080072 case ARM_PSCI_VER_1_0:
73 tmp = fdt_setprop_string(fdt, nodeoff,
74 "compatible", "arm,psci-1.0");
75 if (tmp)
76 return tmp;
77 case ARM_PSCI_VER_0_2:
78 tmp = fdt_appendprop_string(fdt, nodeoff,
79 "compatible", "arm,psci-0.2");
80 if (tmp)
81 return tmp;
Hou Zhiqiang45684ae2016-06-28 20:18:16 +080082 default:
Hou Zhiqiang2c774162016-07-29 18:26:36 +080083 /*
84 * The Secure firmware framework isn't able to support PSCI version 0.1.
85 */
86#ifndef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
87 tmp = fdt_appendprop_string(fdt, nodeoff,
88 "compatible", "arm,psci");
89 if (tmp)
90 return tmp;
91 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_suspend",
92 ARM_PSCI_FN_CPU_SUSPEND);
93 if (tmp)
94 return tmp;
95 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_off",
96 ARM_PSCI_FN_CPU_OFF);
97 if (tmp)
98 return tmp;
99 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_on",
100 ARM_PSCI_FN_CPU_ON);
101 if (tmp)
102 return tmp;
103 tmp = fdt_setprop_u32(fdt, nodeoff, "migrate",
104 ARM_PSCI_FN_MIGRATE);
105 if (tmp)
106 return tmp;
107#endif
Hou Zhiqiang45684ae2016-06-28 20:18:16 +0800108 break;
109 }
110
Hou Zhiqiang45684ae2016-06-28 20:18:16 +0800111 tmp = fdt_setprop_string(fdt, nodeoff, "method", "smc");
112 if (tmp)
113 return tmp;
114
Hou Zhiqiang45684ae2016-06-28 20:18:16 +0800115#endif
116 return 0;
117}