Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1 | /* |
Zelalem Aweke | b6301e6 | 2021-07-09 17:54:30 -0500 | [diff] [blame] | 2 | * Copyright (c) 2013-2021, Arm Limited and Contributors. All rights reserved. |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 8 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #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 Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 14 | |
| 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 | ******************************************************************************/ |
| 20 | void *cm_get_context(uint32_t security_state) |
| 21 | { |
Zelalem Aweke | b6301e6 | 2021-07-09 17:54:30 -0500 | [diff] [blame] | 22 | assert(sec_state_is_valid(security_state)); |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 23 | |
Zelalem Aweke | b6301e6 | 2021-07-09 17:54:30 -0500 | [diff] [blame] | 24 | return get_cpu_data(cpu_context[get_cpu_context_index(security_state)]); |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 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 | ******************************************************************************/ |
| 31 | void cm_set_context(void *context, uint32_t security_state) |
| 32 | { |
Zelalem Aweke | b6301e6 | 2021-07-09 17:54:30 -0500 | [diff] [blame] | 33 | assert(sec_state_is_valid(security_state)); |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 34 | |
Zelalem Aweke | b6301e6 | 2021-07-09 17:54:30 -0500 | [diff] [blame] | 35 | set_cpu_data(cpu_context[get_cpu_context_index(security_state)], |
| 36 | context); |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 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 | ******************************************************************************/ |
| 45 | void *cm_get_context_by_index(unsigned int cpu_idx, |
| 46 | unsigned int security_state) |
| 47 | { |
| 48 | assert(sec_state_is_valid(security_state)); |
| 49 | |
Zelalem Aweke | b6301e6 | 2021-07-09 17:54:30 -0500 | [diff] [blame] | 50 | return get_cpu_data_by_index(cpu_idx, |
| 51 | cpu_context[get_cpu_context_index(security_state)]); |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /******************************************************************************* |
| 55 | * This function sets the pointer to the current 'cpu_context' structure for the |
| 56 | * specified security state for the CPU identified by CPU index. |
| 57 | ******************************************************************************/ |
| 58 | void cm_set_context_by_index(unsigned int cpu_idx, void *context, |
| 59 | unsigned int security_state) |
| 60 | { |
| 61 | assert(sec_state_is_valid(security_state)); |
| 62 | |
Zelalem Aweke | b6301e6 | 2021-07-09 17:54:30 -0500 | [diff] [blame] | 63 | set_cpu_data_by_index(cpu_idx, |
| 64 | cpu_context[get_cpu_context_index(security_state)], |
| 65 | context); |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 66 | } |