bl31_context_mgmt.c 2.54 KB
Newer Older
Achin Gupta's avatar
Achin Gupta committed
1
/*
2
 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
Achin Gupta's avatar
Achin Gupta committed
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta's avatar
Achin Gupta committed
5
6
 */

7
#include <assert.h>
Achin Gupta's avatar
Achin Gupta committed
8

9
10
11
12
13
#include <bl31/bl31.h>
#include <common/bl_common.h>
#include <context.h>
#include <lib/el3_runtime/context_mgmt.h>
#include <lib/el3_runtime/cpu_data.h>
14
15
16
17
18
19
20
21

/*******************************************************************************
 * This function returns a pointer to the most recent 'cpu_context' structure
 * for the calling CPU that was set as the context for the specified security
 * state. NULL is returned if no such structure has been specified.
 ******************************************************************************/
void *cm_get_context(uint32_t security_state)
{
johpow01's avatar
johpow01 committed
22
23
24
#if ENABLE_RME
	assert(sec_state_is_valid(security_state));
#else /* ENABLE_RME */
25
	assert(security_state <= NON_SECURE);
johpow01's avatar
johpow01 committed
26
#endif
27
28
29
30
31
32
33
34
35
36

	return get_cpu_data(cpu_context[security_state]);
}

/*******************************************************************************
 * This function sets the pointer to the current 'cpu_context' structure for the
 * specified security state for the calling CPU
 ******************************************************************************/
void cm_set_context(void *context, uint32_t security_state)
{
johpow01's avatar
johpow01 committed
37
38
39
#if ENABLE_RME
	assert(sec_state_is_valid(security_state));
#else /* ENABLE_RME */
40
	assert(security_state <= NON_SECURE);
johpow01's avatar
johpow01 committed
41
#endif
42
43
44
45

	set_cpu_data(cpu_context[security_state], context);
}

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
 * This function returns a pointer to the most recent 'cpu_context' structure
 * for the CPU identified by `cpu_idx` that was set as the context for the
 * specified security state. NULL is returned if no such structure has been
 * specified.
 ******************************************************************************/
void *cm_get_context_by_index(unsigned int cpu_idx,
				unsigned int security_state)
{
	assert(sec_state_is_valid(security_state));

	return get_cpu_data_by_index(cpu_idx, cpu_context[security_state]);
}

/*******************************************************************************
 * This function sets the pointer to the current 'cpu_context' structure for the
 * specified security state for the CPU identified by CPU index.
 ******************************************************************************/
void cm_set_context_by_index(unsigned int cpu_idx, void *context,
				unsigned int security_state)
{
	assert(sec_state_is_valid(security_state));

	set_cpu_data_by_index(cpu_idx, cpu_context[security_state], context);
}