1bbf8f6f9SYatharth Kochar /* 2c5ea4f8aSZelalem Aweke * Copyright (c) 2013-2021, 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 909d40e0eSAntonio Nino Diaz #include <bl31/bl31.h> 1009d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 1109d40e0eSAntonio Nino Diaz #include <context.h> 1209d40e0eSAntonio Nino Diaz #include <lib/el3_runtime/context_mgmt.h> 1309d40e0eSAntonio Nino Diaz #include <lib/el3_runtime/cpu_data.h> 14bbf8f6f9SYatharth Kochar 15bbf8f6f9SYatharth Kochar /******************************************************************************* 16bbf8f6f9SYatharth Kochar * This function returns a pointer to the most recent 'cpu_context' structure 17bbf8f6f9SYatharth Kochar * for the calling CPU that was set as the context for the specified security 18bbf8f6f9SYatharth Kochar * state. NULL is returned if no such structure has been specified. 19bbf8f6f9SYatharth Kochar ******************************************************************************/ 20*f05b4894SMaheedhar Bollapalli void *cm_get_context(size_t security_state) 21bbf8f6f9SYatharth Kochar { 22c5ea4f8aSZelalem Aweke assert(sec_state_is_valid(security_state)); 23bbf8f6f9SYatharth Kochar 24c5ea4f8aSZelalem Aweke return get_cpu_data(cpu_context[get_cpu_context_index(security_state)]); 25bbf8f6f9SYatharth Kochar } 26bbf8f6f9SYatharth Kochar 27bbf8f6f9SYatharth Kochar /******************************************************************************* 28bbf8f6f9SYatharth Kochar * This function sets the pointer to the current 'cpu_context' structure for the 29bbf8f6f9SYatharth Kochar * specified security state for the calling CPU 30bbf8f6f9SYatharth Kochar ******************************************************************************/ 31bbf8f6f9SYatharth Kochar void cm_set_context(void *context, uint32_t security_state) 32bbf8f6f9SYatharth Kochar { 33c5ea4f8aSZelalem Aweke assert(sec_state_is_valid(security_state)); 34bbf8f6f9SYatharth Kochar 35c5ea4f8aSZelalem Aweke set_cpu_data(cpu_context[get_cpu_context_index(security_state)], 36c5ea4f8aSZelalem Aweke 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, 46*f05b4894SMaheedhar Bollapalli size_t security_state) 47bbf8f6f9SYatharth Kochar { 48bbf8f6f9SYatharth Kochar assert(sec_state_is_valid(security_state)); 49bbf8f6f9SYatharth Kochar 50c5ea4f8aSZelalem Aweke return get_cpu_data_by_index(cpu_idx, 51c5ea4f8aSZelalem Aweke cpu_context[get_cpu_context_index(security_state)]); 52bbf8f6f9SYatharth Kochar } 53bbf8f6f9SYatharth Kochar 54bbf8f6f9SYatharth Kochar /******************************************************************************* 55bbf8f6f9SYatharth Kochar * This function sets the pointer to the current 'cpu_context' structure for the 56bbf8f6f9SYatharth Kochar * specified security state for the CPU identified by CPU index. 57bbf8f6f9SYatharth Kochar ******************************************************************************/ 58bbf8f6f9SYatharth Kochar void cm_set_context_by_index(unsigned int cpu_idx, void *context, 59bbf8f6f9SYatharth Kochar unsigned int security_state) 60bbf8f6f9SYatharth Kochar { 61bbf8f6f9SYatharth Kochar assert(sec_state_is_valid(security_state)); 62bbf8f6f9SYatharth Kochar 63c5ea4f8aSZelalem Aweke set_cpu_data_by_index(cpu_idx, 64c5ea4f8aSZelalem Aweke cpu_context[get_cpu_context_index(security_state)], 65c5ea4f8aSZelalem Aweke context); 66bbf8f6f9SYatharth Kochar } 67