blob: 68ad705c5dc0a73423a2e6c699f006d6ef72dd61 [file] [log] [blame]
Roberto Vargas0a4c2612017-08-03 08:16:16 +01001/*
Govindraj Rajaeee28e72023-08-01 15:52:40 -05002 * 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
Prasad Kummari37a7ed22025-04-22 20:50:01 +053021 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;
Prasad Kummari37a7ed22025-04-22 20:50:01 +053023 }
24 if (psci_plat_pm_ops->write_mem_protect(enable) < 0) {
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010025 return (u_register_t) PSCI_E_NOT_SUPPORTED;
Prasad Kummari37a7ed22025-04-22 20:50:01 +053026 }
Roberto Vargas0a4c2612017-08-03 08:16:16 +010027
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010028 return (val != 0) ? 1U : 0U;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010029}
30
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010031u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length)
Roberto Vargas0a4c2612017-08-03 08:16:16 +010032{
33 int ret;
34
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010035 assert(psci_plat_pm_ops->mem_protect_chk != NULL);
Roberto Vargas0a4c2612017-08-03 08:16:16 +010036
Prasad Kummari37a7ed22025-04-22 20:50:01 +053037 if ((length == 0U) || check_uptr_overflow(base, length - 1U)) {
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010038 return (u_register_t) PSCI_E_DENIED;
Prasad Kummari37a7ed22025-04-22 20:50:01 +053039 }
Roberto Vargas0a4c2612017-08-03 08:16:16 +010040
41 ret = psci_plat_pm_ops->mem_protect_chk(base, length);
Antonio Nino Diazf5c60012018-07-16 23:36:10 +010042 return (ret < 0) ?
43 (u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS;
Roberto Vargas0a4c2612017-08-03 08:16:16 +010044}