psci_mem_protect.c 1012 Bytes
Newer Older
1
/*
2
 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
#include <limits.h>
9
10
11

#include <lib/utils.h>

12
13
#include "psci_private.h"

14
u_register_t psci_mem_protect(unsigned int enable)
15
16
17
{
	int val;

18
19
	assert(psci_plat_pm_ops->read_mem_protect != NULL);
	assert(psci_plat_pm_ops->write_mem_protect != NULL);
20
21

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

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

29
u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length)
30
31
32
{
	int ret;

33
	assert(psci_plat_pm_ops->mem_protect_chk != NULL);
34

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

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