blob: 481051f95d9426e591a2fd4d3a9da13b4f3f4836 [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>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <lib/utils.h>
11
Roberto Vargas0a4c2612017-08-03 08:16:16 +010012#include "psci_private.h"
13
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010014u_register_t psci_mem_protect(unsigned int enable)
Roberto Vargas0a4c2612017-08-03 08:16:16 +010015{
16 int val;
17
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010018 assert(psci_plat_pm_ops->read_mem_protect != NULL);
19 assert(psci_plat_pm_ops->write_mem_protect != NULL);
Roberto Vargas0a4c2612017-08-03 08:16:16 +010020
21 if (psci_plat_pm_ops->read_mem_protect(&val) < 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 if (psci_plat_pm_ops->write_mem_protect(enable) < 0)
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010024 return (u_register_t) PSCI_E_NOT_SUPPORTED;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010025
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010026 return (val != 0) ? 1U : 0U;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010027}
28
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010029u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length)
Roberto Vargas0a4c2612017-08-03 08:16:16 +010030{
31 int ret;
32
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010033 assert(psci_plat_pm_ops->mem_protect_chk != NULL);
Roberto Vargas0a4c2612017-08-03 08:16:16 +010034
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010035 if ((length == 0U) || check_uptr_overflow(base, length - 1U))
36 return (u_register_t) PSCI_E_DENIED;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010037
38 ret = psci_plat_pm_ops->mem_protect_chk(base, length);
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010039 return (ret < 0) ?
40 (u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010041}