xref: /OK3568_Linux_fs/u-boot/arch/arm/cpu/armv7/virt-dt.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2013 - ARM Ltd
3*4882a593Smuzhiyun  * Author: Marc Zyngier <marc.zyngier@arm.com>
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
6*4882a593Smuzhiyun  * it under the terms of the GNU General Public License version 2 as
7*4882a593Smuzhiyun  * published by the Free Software Foundation.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful,
10*4882a593Smuzhiyun  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*4882a593Smuzhiyun  * GNU General Public License for more details.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
15*4882a593Smuzhiyun  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #include <common.h>
19*4882a593Smuzhiyun #include <errno.h>
20*4882a593Smuzhiyun #include <stdio_dev.h>
21*4882a593Smuzhiyun #include <linux/ctype.h>
22*4882a593Smuzhiyun #include <linux/types.h>
23*4882a593Smuzhiyun #include <asm/global_data.h>
24*4882a593Smuzhiyun #include <linux/libfdt.h>
25*4882a593Smuzhiyun #include <fdt_support.h>
26*4882a593Smuzhiyun #include <asm/armv7.h>
27*4882a593Smuzhiyun #include <asm/psci.h>
28*4882a593Smuzhiyun 
armv7_apply_memory_carveout(u64 * start,u64 * size)29*4882a593Smuzhiyun int armv7_apply_memory_carveout(u64 *start, u64 *size)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
32*4882a593Smuzhiyun 	if (*start + *size < CONFIG_ARMV7_SECURE_BASE ||
33*4882a593Smuzhiyun 	    *start >= (u64)CONFIG_ARMV7_SECURE_BASE +
34*4882a593Smuzhiyun 		      CONFIG_ARMV7_SECURE_RESERVE_SIZE)
35*4882a593Smuzhiyun 		return 0;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	/* carveout must be at the beginning or the end of the bank */
38*4882a593Smuzhiyun 	if (*start == CONFIG_ARMV7_SECURE_BASE ||
39*4882a593Smuzhiyun 	    *start + *size == (u64)CONFIG_ARMV7_SECURE_BASE +
40*4882a593Smuzhiyun 			      CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
41*4882a593Smuzhiyun 		if (*size < CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
42*4882a593Smuzhiyun 			debug("Secure monitor larger than RAM bank!?\n");
43*4882a593Smuzhiyun 			return -EINVAL;
44*4882a593Smuzhiyun 		}
45*4882a593Smuzhiyun 		*size -= CONFIG_ARMV7_SECURE_RESERVE_SIZE;
46*4882a593Smuzhiyun 		if (*start == CONFIG_ARMV7_SECURE_BASE)
47*4882a593Smuzhiyun 			*start += CONFIG_ARMV7_SECURE_RESERVE_SIZE;
48*4882a593Smuzhiyun 		return 0;
49*4882a593Smuzhiyun 	}
50*4882a593Smuzhiyun 	debug("Secure monitor not located at beginning or end of RAM bank\n");
51*4882a593Smuzhiyun 	return -EINVAL;
52*4882a593Smuzhiyun #else /* !CONFIG_ARMV7_SECURE_RESERVE_SIZE */
53*4882a593Smuzhiyun 	return 0;
54*4882a593Smuzhiyun #endif
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun 
psci_update_dt(void * fdt)57*4882a593Smuzhiyun int psci_update_dt(void *fdt)
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun #ifdef CONFIG_ARMV7_NONSEC
60*4882a593Smuzhiyun 	if (!armv7_boot_nonsec())
61*4882a593Smuzhiyun 		return 0;
62*4882a593Smuzhiyun #endif
63*4882a593Smuzhiyun #ifndef CONFIG_ARMV7_SECURE_BASE
64*4882a593Smuzhiyun 	/* secure code lives in RAM, keep it alive */
65*4882a593Smuzhiyun 	fdt_add_mem_rsv(fdt, (unsigned long)__secure_start,
66*4882a593Smuzhiyun 			__secure_end - __secure_start);
67*4882a593Smuzhiyun #endif
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	return fdt_psci(fdt);
70*4882a593Smuzhiyun }
71