summaryrefslogtreecommitdiffstats
path: root/lib/psci/psci_mem_protect.c
blob: 385dcd2459e74ba12339cdb06caebfb89c2f3b1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright (c) 2017-2018, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
#include <limits.h>

#include <lib/utils.h>

#include "psci_private.h"

u_register_t psci_mem_protect(unsigned int enable)
{
	int val;

	assert(psci_plat_pm_ops->read_mem_protect != NULL);
	assert(psci_plat_pm_ops->write_mem_protect != NULL);

	if (psci_plat_pm_ops->read_mem_protect(&val) < 0)
		return (u_register_t) PSCI_E_NOT_SUPPORTED;
	if (psci_plat_pm_ops->write_mem_protect(enable) < 0)
		return (u_register_t) PSCI_E_NOT_SUPPORTED;

	return (val != 0) ? 1U : 0U;
}

u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length)
{
	int ret;

	assert(psci_plat_pm_ops->mem_protect_chk != NULL);

	if ((length == 0U) || check_uptr_overflow(base, length - 1U))
		return (u_register_t) PSCI_E_DENIED;

	ret = psci_plat_pm_ops->mem_protect_chk(base, length);
	return (ret < 0) ?
	       (u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS;
}