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> |
| 9 | #include <utils.h> |
| 10 | #include "psci_private.h" |
| 11 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 12 | u_register_t psci_mem_protect(unsigned int enable) |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 13 | { |
| 14 | int val; |
| 15 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 16 | assert(psci_plat_pm_ops->read_mem_protect != NULL); |
| 17 | assert(psci_plat_pm_ops->write_mem_protect != NULL); |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 18 | |
| 19 | if (psci_plat_pm_ops->read_mem_protect(&val) < 0) |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 20 | return (u_register_t) PSCI_E_NOT_SUPPORTED; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 21 | if (psci_plat_pm_ops->write_mem_protect(enable) < 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 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 24 | return (val != 0) ? 1U : 0U; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 25 | } |
| 26 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 27 | 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] | 28 | { |
| 29 | int ret; |
| 30 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 31 | assert(psci_plat_pm_ops->mem_protect_chk != NULL); |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 32 | |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 33 | if ((length == 0U) || check_uptr_overflow(base, length - 1U)) |
| 34 | return (u_register_t) PSCI_E_DENIED; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 35 | |
| 36 | ret = psci_plat_pm_ops->mem_protect_chk(base, length); |
Antonio Nino Diaz | f5c6001 | 2018-07-16 23:36:10 +0100 | [diff] [blame] | 37 | return (ret < 0) ? |
| 38 | (u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS; |
Roberto Vargas | 0a4c261 | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 39 | } |