blob: d41979fa7d1230da8884472cba0f42f58052d0b4 [file] [log] [blame]
Yatharth Kochar6c0566c2015-10-02 17:56:48 +01001/*
Roberto Vargas777dd432018-02-12 12:36:17 +00002 * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
Yatharth Kochar6c0566c2015-10-02 17:56:48 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kochar6c0566c2015-10-02 17:56:48 +01005 */
6
7#include <assert.h>
Yatharth Kochar6c0566c2015-10-02 17:56:48 +01008
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <bl31/bl31.h>
10#include <common/bl_common.h>
11#include <context.h>
12#include <lib/el3_runtime/context_mgmt.h>
13#include <lib/el3_runtime/cpu_data.h>
14#include <plat/common/platform.h>
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010015
16/*******************************************************************************
17 * This function returns a pointer to the most recent 'cpu_context' structure
18 * for the calling CPU that was set as the context for the specified security
19 * state. NULL is returned if no such structure has been specified.
20 ******************************************************************************/
21void *cm_get_context(uint32_t security_state)
22{
23 assert(security_state <= NON_SECURE);
24
25 return get_cpu_data(cpu_context[security_state]);
26}
27
28/*******************************************************************************
29 * This function sets the pointer to the current 'cpu_context' structure for the
30 * specified security state for the calling CPU
31 ******************************************************************************/
32void cm_set_context(void *context, uint32_t security_state)
33{
34 assert(security_state <= NON_SECURE);
35
36 set_cpu_data(cpu_context[security_state], context);
37}
38
39/*******************************************************************************
40 * This function returns a pointer to the most recent 'cpu_context' structure
41 * for the CPU identified by `cpu_idx` that was set as the context for the
42 * specified security state. NULL is returned if no such structure has been
43 * specified.
44 ******************************************************************************/
45void *cm_get_context_by_index(unsigned int cpu_idx,
46 unsigned int security_state)
47{
48 assert(sec_state_is_valid(security_state));
49
50 return get_cpu_data_by_index(cpu_idx, cpu_context[security_state]);
51}
52
53/*******************************************************************************
54 * This function sets the pointer to the current 'cpu_context' structure for the
55 * specified security state for the CPU identified by CPU index.
56 ******************************************************************************/
57void cm_set_context_by_index(unsigned int cpu_idx, void *context,
58 unsigned int security_state)
59{
60 assert(sec_state_is_valid(security_state));
61
62 set_cpu_data_by_index(cpu_idx, cpu_context[security_state], context);
63}