xref: /rk3399_ARM-atf/bl31/bl31_context_mgmt.c (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
1bbf8f6f9SYatharth Kochar /*
29fb8af33SRoberto Vargas  * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
3bbf8f6f9SYatharth Kochar  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5bbf8f6f9SYatharth Kochar  */
6bbf8f6f9SYatharth Kochar 
7bbf8f6f9SYatharth Kochar #include <assert.h>
8bbf8f6f9SYatharth Kochar 
9*09d40e0eSAntonio Nino Diaz #include <bl31/bl31.h>
10*09d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
11*09d40e0eSAntonio Nino Diaz #include <context.h>
12*09d40e0eSAntonio Nino Diaz #include <lib/el3_runtime/context_mgmt.h>
13*09d40e0eSAntonio Nino Diaz #include <lib/el3_runtime/cpu_data.h>
14*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
15bbf8f6f9SYatharth Kochar 
16bbf8f6f9SYatharth Kochar /*******************************************************************************
17bbf8f6f9SYatharth Kochar  * This function returns a pointer to the most recent 'cpu_context' structure
18bbf8f6f9SYatharth Kochar  * for the calling CPU that was set as the context for the specified security
19bbf8f6f9SYatharth Kochar  * state. NULL is returned if no such structure has been specified.
20bbf8f6f9SYatharth Kochar  ******************************************************************************/
21bbf8f6f9SYatharth Kochar void *cm_get_context(uint32_t security_state)
22bbf8f6f9SYatharth Kochar {
23bbf8f6f9SYatharth Kochar 	assert(security_state <= NON_SECURE);
24bbf8f6f9SYatharth Kochar 
25bbf8f6f9SYatharth Kochar 	return get_cpu_data(cpu_context[security_state]);
26bbf8f6f9SYatharth Kochar }
27bbf8f6f9SYatharth Kochar 
28bbf8f6f9SYatharth Kochar /*******************************************************************************
29bbf8f6f9SYatharth Kochar  * This function sets the pointer to the current 'cpu_context' structure for the
30bbf8f6f9SYatharth Kochar  * specified security state for the calling CPU
31bbf8f6f9SYatharth Kochar  ******************************************************************************/
32bbf8f6f9SYatharth Kochar void cm_set_context(void *context, uint32_t security_state)
33bbf8f6f9SYatharth Kochar {
34bbf8f6f9SYatharth Kochar 	assert(security_state <= NON_SECURE);
35bbf8f6f9SYatharth Kochar 
36bbf8f6f9SYatharth Kochar 	set_cpu_data(cpu_context[security_state], context);
37bbf8f6f9SYatharth Kochar }
38bbf8f6f9SYatharth Kochar 
39bbf8f6f9SYatharth Kochar /*******************************************************************************
40bbf8f6f9SYatharth Kochar  * This function returns a pointer to the most recent 'cpu_context' structure
41bbf8f6f9SYatharth Kochar  * for the CPU identified by `cpu_idx` that was set as the context for the
42bbf8f6f9SYatharth Kochar  * specified security state. NULL is returned if no such structure has been
43bbf8f6f9SYatharth Kochar  * specified.
44bbf8f6f9SYatharth Kochar  ******************************************************************************/
45bbf8f6f9SYatharth Kochar void *cm_get_context_by_index(unsigned int cpu_idx,
46bbf8f6f9SYatharth Kochar 				unsigned int security_state)
47bbf8f6f9SYatharth Kochar {
48bbf8f6f9SYatharth Kochar 	assert(sec_state_is_valid(security_state));
49bbf8f6f9SYatharth Kochar 
50bbf8f6f9SYatharth Kochar 	return get_cpu_data_by_index(cpu_idx, cpu_context[security_state]);
51bbf8f6f9SYatharth Kochar }
52bbf8f6f9SYatharth Kochar 
53bbf8f6f9SYatharth Kochar /*******************************************************************************
54bbf8f6f9SYatharth Kochar  * This function sets the pointer to the current 'cpu_context' structure for the
55bbf8f6f9SYatharth Kochar  * specified security state for the CPU identified by CPU index.
56bbf8f6f9SYatharth Kochar  ******************************************************************************/
57bbf8f6f9SYatharth Kochar void cm_set_context_by_index(unsigned int cpu_idx, void *context,
58bbf8f6f9SYatharth Kochar 				unsigned int security_state)
59bbf8f6f9SYatharth Kochar {
60bbf8f6f9SYatharth Kochar 	assert(sec_state_is_valid(security_state));
61bbf8f6f9SYatharth Kochar 
62bbf8f6f9SYatharth Kochar 	set_cpu_data_by_index(cpu_idx, cpu_context[security_state], context);
63bbf8f6f9SYatharth Kochar }
64