xref: /openbmc/u-boot/arch/arm/cpu/armv7/virt-dt.c (revision 72719d2f)
1 /*
2  * Copyright (C) 2013 - ARM Ltd
3  * Author: Marc Zyngier <marc.zyngier@arm.com>
4  *
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.
8  *
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.
13  *
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/>.
16  */
17 
18 #include <common.h>
19 #include <errno.h>
20 #include <stdio_dev.h>
21 #include <linux/ctype.h>
22 #include <linux/types.h>
23 #include <asm/global_data.h>
24 #include <libfdt.h>
25 #include <fdt_support.h>
26 #include <asm/armv7.h>
27 #include <asm/psci.h>
28 
29 int armv7_apply_memory_carveout(u64 *start, u64 *size)
30 {
31 #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
32 	if (*start + *size < CONFIG_ARMV7_SECURE_BASE ||
33 	    *start >= (u64)CONFIG_ARMV7_SECURE_BASE +
34 		      CONFIG_ARMV7_SECURE_RESERVE_SIZE)
35 		return 0;
36 
37 	/* carveout must be at the beginning or the end of the bank */
38 	if (*start == CONFIG_ARMV7_SECURE_BASE ||
39 	    *start + *size == (u64)CONFIG_ARMV7_SECURE_BASE +
40 			      CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
41 		if (*size < CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
42 			debug("Secure monitor larger than RAM bank!?\n");
43 			return -EINVAL;
44 		}
45 		*size -= CONFIG_ARMV7_SECURE_RESERVE_SIZE;
46 		if (*start == CONFIG_ARMV7_SECURE_BASE)
47 			*start += CONFIG_ARMV7_SECURE_RESERVE_SIZE;
48 		return 0;
49 	}
50 	debug("Secure monitor not located at beginning or end of RAM bank\n");
51 	return -EINVAL;
52 #else /* !CONFIG_ARMV7_SECURE_RESERVE_SIZE */
53 	return 0;
54 #endif
55 }
56 
57 int psci_update_dt(void *fdt)
58 {
59 #ifdef CONFIG_ARMV7_NONSEC
60 	if (!armv7_boot_nonsec())
61 		return 0;
62 #endif
63 #ifndef CONFIG_ARMV7_SECURE_BASE
64 	/* secure code lives in RAM, keep it alive */
65 	fdt_add_mem_rsv(fdt, (unsigned long)__secure_start,
66 			__secure_end - __secure_start);
67 #endif
68 
69 	return fdt_psci(fdt);
70 }
71