Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <limits.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <lib/utils.h> |
| 11 | |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 12 | #include "psci_private.h" |
| 13 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 14 | u_register_t psci_mem_protect(unsigned int enable) |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 15 | { |
| 16 | int val; |
| 17 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 18 | assert(psci_plat_pm_ops->read_mem_protect != NULL); |
| 19 | assert(psci_plat_pm_ops->write_mem_protect != NULL); |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 20 | |
| 21 | if (psci_plat_pm_ops->read_mem_protect(&val) < 0) |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 22 | return (u_register_t) PSCI_E_NOT_SUPPORTED; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 23 | if (psci_plat_pm_ops->write_mem_protect(enable) < 0) |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 24 | return (u_register_t) PSCI_E_NOT_SUPPORTED; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 25 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 26 | return (val != 0) ? 1U : 0U; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 27 | } |
| 28 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 29 | u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length) |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 30 | { |
| 31 | int ret; |
| 32 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 33 | assert(psci_plat_pm_ops->mem_protect_chk != NULL); |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 34 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 35 | if ((length == 0U) || check_uptr_overflow(base, length - 1U)) |
| 36 | return (u_register_t) PSCI_E_DENIED; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 37 | |
| 38 | ret = psci_plat_pm_ops->mem_protect_chk(base, length); |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 39 | return (ret < 0) ? |
| 40 | (u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 41 | } |