Marc Zyngier | e771a3d | 2014-07-12 14:24:07 +0100 | [diff] [blame] | 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> |
Jan Kiszka | d6b72da | 2015-04-21 07:18:32 +0200 | [diff] [blame] | 19 | #include <errno.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 20 | #include <log.h> |
Marc Zyngier | e771a3d | 2014-07-12 14:24:07 +0100 | [diff] [blame] | 21 | #include <stdio_dev.h> |
| 22 | #include <linux/ctype.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <asm/global_data.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 25 | #include <linux/libfdt.h> |
Marc Zyngier | e771a3d | 2014-07-12 14:24:07 +0100 | [diff] [blame] | 26 | #include <fdt_support.h> |
| 27 | #include <asm/armv7.h> |
| 28 | #include <asm/psci.h> |
| 29 | |
Jan Kiszka | d6b72da | 2015-04-21 07:18:32 +0200 | [diff] [blame] | 30 | int armv7_apply_memory_carveout(u64 *start, u64 *size) |
| 31 | { |
| 32 | #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE |
| 33 | if (*start + *size < CONFIG_ARMV7_SECURE_BASE || |
| 34 | *start >= (u64)CONFIG_ARMV7_SECURE_BASE + |
| 35 | CONFIG_ARMV7_SECURE_RESERVE_SIZE) |
| 36 | return 0; |
| 37 | |
| 38 | /* carveout must be at the beginning or the end of the bank */ |
| 39 | if (*start == CONFIG_ARMV7_SECURE_BASE || |
| 40 | *start + *size == (u64)CONFIG_ARMV7_SECURE_BASE + |
| 41 | CONFIG_ARMV7_SECURE_RESERVE_SIZE) { |
| 42 | if (*size < CONFIG_ARMV7_SECURE_RESERVE_SIZE) { |
| 43 | debug("Secure monitor larger than RAM bank!?\n"); |
| 44 | return -EINVAL; |
| 45 | } |
| 46 | *size -= CONFIG_ARMV7_SECURE_RESERVE_SIZE; |
| 47 | if (*start == CONFIG_ARMV7_SECURE_BASE) |
| 48 | *start += CONFIG_ARMV7_SECURE_RESERVE_SIZE; |
| 49 | return 0; |
| 50 | } |
| 51 | debug("Secure monitor not located at beginning or end of RAM bank\n"); |
| 52 | return -EINVAL; |
| 53 | #else /* !CONFIG_ARMV7_SECURE_RESERVE_SIZE */ |
| 54 | return 0; |
| 55 | #endif |
| 56 | } |
| 57 | |
Tom Rini | dd09f7e | 2015-03-05 20:19:36 -0500 | [diff] [blame] | 58 | int psci_update_dt(void *fdt) |
Marc Zyngier | e771a3d | 2014-07-12 14:24:07 +0100 | [diff] [blame] | 59 | { |
Jan Kiszka | 104d6fb | 2015-04-21 07:18:24 +0200 | [diff] [blame] | 60 | #ifdef CONFIG_ARMV7_NONSEC |
Ian Campbell | 97a8196 | 2014-12-21 09:45:11 +0000 | [diff] [blame] | 61 | if (!armv7_boot_nonsec()) |
| 62 | return 0; |
Tom Rini | dd09f7e | 2015-03-05 20:19:36 -0500 | [diff] [blame] | 63 | #endif |
Marc Zyngier | e771a3d | 2014-07-12 14:24:07 +0100 | [diff] [blame] | 64 | #ifndef CONFIG_ARMV7_SECURE_BASE |
| 65 | /* secure code lives in RAM, keep it alive */ |
| 66 | fdt_add_mem_rsv(fdt, (unsigned long)__secure_start, |
| 67 | __secure_end - __secure_start); |
| 68 | #endif |
| 69 | |
| 70 | return fdt_psci(fdt); |
| 71 | } |