blob: 9175ee35d32f1a9f3cdccd43f194a0c33301961f [file] [log] [blame]
Yatharth Kochar6c0566c2015-10-02 17:56:48 +01001/*
Zelalem87675d42020-02-03 14:56:42 -06002 * Copyright (c) 2013-2020, 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>
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010014
15/*******************************************************************************
16 * This function returns a pointer to the most recent 'cpu_context' structure
17 * for the calling CPU that was set as the context for the specified security
18 * state. NULL is returned if no such structure has been specified.
19 ******************************************************************************/
20void *cm_get_context(uint32_t security_state)
21{
22 assert(security_state <= NON_SECURE);
23
24 return get_cpu_data(cpu_context[security_state]);
25}
26
27/*******************************************************************************
28 * This function sets the pointer to the current 'cpu_context' structure for the
29 * specified security state for the calling CPU
30 ******************************************************************************/
31void cm_set_context(void *context, uint32_t security_state)
32{
33 assert(security_state <= NON_SECURE);
34
35 set_cpu_data(cpu_context[security_state], context);
36}
37
38/*******************************************************************************
39 * This function returns a pointer to the most recent 'cpu_context' structure
40 * for the CPU identified by `cpu_idx` that was set as the context for the
41 * specified security state. NULL is returned if no such structure has been
42 * specified.
43 ******************************************************************************/
44void *cm_get_context_by_index(unsigned int cpu_idx,
45 unsigned int security_state)
46{
47 assert(sec_state_is_valid(security_state));
48
49 return get_cpu_data_by_index(cpu_idx, cpu_context[security_state]);
50}
51
52/*******************************************************************************
53 * This function sets the pointer to the current 'cpu_context' structure for the
54 * specified security state for the CPU identified by CPU index.
55 ******************************************************************************/
56void cm_set_context_by_index(unsigned int cpu_idx, void *context,
57 unsigned int security_state)
58{
59 assert(sec_state_is_valid(security_state));
60
61 set_cpu_data_by_index(cpu_idx, cpu_context[security_state], context);
62}