2 * Copyright (C) 2013 - ARM Ltd
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio_dev.h>
21 #include <linux/ctype.h>
22 #include <linux/types.h>
23 #include <asm/global_data.h>
25 #include <fdt_support.h>
26 #include <asm/armv7.h>
29 static int fdt_psci(void *fdt)
31 #ifdef CONFIG_ARMV7_PSCI
35 nodeoff = fdt_path_offset(fdt, "/cpus");
37 printf("couldn't find /cpus\n");
41 /* add 'enable-method = "psci"' to each cpu node */
42 for (tmp = fdt_first_subnode(fdt, nodeoff);
44 tmp = fdt_next_subnode(fdt, tmp)) {
45 const struct fdt_property *prop;
48 prop = fdt_get_property(fdt, tmp, "device_type", &len);
53 if (strcmp(prop->data, "cpu"))
56 fdt_setprop_string(fdt, tmp, "enable-method", "psci");
59 nodeoff = fdt_path_offset(fdt, "/psci");
61 nodeoff = fdt_path_offset(fdt, "/");
65 nodeoff = fdt_add_subnode(fdt, nodeoff, "psci");
70 tmp = fdt_setprop_string(fdt, nodeoff, "compatible", "arm,psci");
73 tmp = fdt_setprop_string(fdt, nodeoff, "method", "smc");
76 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_suspend", ARM_PSCI_FN_CPU_SUSPEND);
79 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_off", ARM_PSCI_FN_CPU_OFF);
82 tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_on", ARM_PSCI_FN_CPU_ON);
85 tmp = fdt_setprop_u32(fdt, nodeoff, "migrate", ARM_PSCI_FN_MIGRATE);
92 int armv7_apply_memory_carveout(u64 *start, u64 *size)
94 #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
95 if (*start + *size < CONFIG_ARMV7_SECURE_BASE ||
96 *start >= (u64)CONFIG_ARMV7_SECURE_BASE +
97 CONFIG_ARMV7_SECURE_RESERVE_SIZE)
100 /* carveout must be at the beginning or the end of the bank */
101 if (*start == CONFIG_ARMV7_SECURE_BASE ||
102 *start + *size == (u64)CONFIG_ARMV7_SECURE_BASE +
103 CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
104 if (*size < CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
105 debug("Secure monitor larger than RAM bank!?\n");
108 *size -= CONFIG_ARMV7_SECURE_RESERVE_SIZE;
109 if (*start == CONFIG_ARMV7_SECURE_BASE)
110 *start += CONFIG_ARMV7_SECURE_RESERVE_SIZE;
113 debug("Secure monitor not located at beginning or end of RAM bank\n");
115 #else /* !CONFIG_ARMV7_SECURE_RESERVE_SIZE */
120 int psci_update_dt(void *fdt)
122 #ifdef CONFIG_ARMV7_NONSEC
123 if (!armv7_boot_nonsec())
126 #ifndef CONFIG_ARMV7_SECURE_BASE
127 /* secure code lives in RAM, keep it alive */
128 fdt_add_mem_rsv(fdt, (unsigned long)__secure_start,
129 __secure_end - __secure_start);
132 return fdt_psci(fdt);