blob: 5dc7ed5e2707a372e737a37917566233ca8ac561 [file] [log] [blame]
Marc Zyngierb32cf0e2014-07-12 14:24:07 +01001/*
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
Jan Kiszkacb334402015-04-21 07:18:32 +020018#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Marc Zyngierb32cf0e2014-07-12 14:24:07 +010020#include <stdio_dev.h>
21#include <linux/ctype.h>
22#include <linux/types.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090023#include <linux/libfdt.h>
Marc Zyngierb32cf0e2014-07-12 14:24:07 +010024#include <fdt_support.h>
25#include <asm/armv7.h>
26#include <asm/psci.h>
27
Jan Kiszkacb334402015-04-21 07:18:32 +020028int armv7_apply_memory_carveout(u64 *start, u64 *size)
29{
30#ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
31 if (*start + *size < CONFIG_ARMV7_SECURE_BASE ||
32 *start >= (u64)CONFIG_ARMV7_SECURE_BASE +
33 CONFIG_ARMV7_SECURE_RESERVE_SIZE)
34 return 0;
35
36 /* carveout must be at the beginning or the end of the bank */
37 if (*start == CONFIG_ARMV7_SECURE_BASE ||
38 *start + *size == (u64)CONFIG_ARMV7_SECURE_BASE +
39 CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
40 if (*size < CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
41 debug("Secure monitor larger than RAM bank!?\n");
42 return -EINVAL;
43 }
44 *size -= CONFIG_ARMV7_SECURE_RESERVE_SIZE;
45 if (*start == CONFIG_ARMV7_SECURE_BASE)
46 *start += CONFIG_ARMV7_SECURE_RESERVE_SIZE;
47 return 0;
48 }
49 debug("Secure monitor not located at beginning or end of RAM bank\n");
50 return -EINVAL;
51#else /* !CONFIG_ARMV7_SECURE_RESERVE_SIZE */
52 return 0;
53#endif
54}
55
Tom Rinifb02cc12015-03-05 20:19:36 -050056int psci_update_dt(void *fdt)
Marc Zyngierb32cf0e2014-07-12 14:24:07 +010057{
Jan Kiszkaac31b5a2015-04-21 07:18:24 +020058#ifdef CONFIG_ARMV7_NONSEC
Ian Campbell68bc8f52014-12-21 09:45:11 +000059 if (!armv7_boot_nonsec())
60 return 0;
Tom Rinifb02cc12015-03-05 20:19:36 -050061#endif
Marc Zyngierb32cf0e2014-07-12 14:24:07 +010062#ifndef CONFIG_ARMV7_SECURE_BASE
63 /* secure code lives in RAM, keep it alive */
64 fdt_add_mem_rsv(fdt, (unsigned long)__secure_start,
65 __secure_end - __secure_start);
66#endif
67
68 return fdt_psci(fdt);
69}