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