blob: 857146b67ff9c5fb9349418f6fa1726fc95fee73 [file] [log] [blame]
Roberto Vargas0a4c2612017-08-03 08:16:16 +01001/*
Antonio Nino Diazf5c60012018-07-16 23:36:10 +01002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Roberto Vargas0a4c2612017-08-03 08:16:16 +01003 *
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 Diazf5c60012018-07-16 23:36:10 +010012u_register_t psci_mem_protect(unsigned int enable)
Roberto Vargas0a4c2612017-08-03 08:16:16 +010013{
14 int val;
15
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010016 assert(psci_plat_pm_ops->read_mem_protect != NULL);
17 assert(psci_plat_pm_ops->write_mem_protect != NULL);
Roberto Vargas0a4c2612017-08-03 08:16:16 +010018
19 if (psci_plat_pm_ops->read_mem_protect(&val) < 0)
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010020 return (u_register_t) PSCI_E_NOT_SUPPORTED;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010021 if (psci_plat_pm_ops->write_mem_protect(enable) < 0)
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010022 return (u_register_t) PSCI_E_NOT_SUPPORTED;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010023
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010024 return (val != 0) ? 1U : 0U;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010025}
26
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010027u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length)
Roberto Vargas0a4c2612017-08-03 08:16:16 +010028{
29 int ret;
30
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010031 assert(psci_plat_pm_ops->mem_protect_chk != NULL);
Roberto Vargas0a4c2612017-08-03 08:16:16 +010032
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010033 if ((length == 0U) || check_uptr_overflow(base, length - 1U))
34 return (u_register_t) PSCI_E_DENIED;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010035
36 ret = psci_plat_pm_ops->mem_protect_chk(base, length);
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010037 return (ret < 0) ?
38 (u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010039}