Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1 | /* |
Roberto Vargas | 777dd43 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2018, 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> |
| 8 | #include <bl31.h> |
Soby Mathew | 0d78607 | 2016-03-24 16:56:29 +0000 | [diff] [blame] | 9 | #include <bl_common.h> |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 10 | #include <context.h> |
| 11 | #include <context_mgmt.h> |
| 12 | #include <cpu_data.h> |
| 13 | #include <platform.h> |
| 14 | |
| 15 | |
| 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 | ******************************************************************************/ |
| 21 | void *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 | ******************************************************************************/ |
| 32 | void 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 | ******************************************************************************/ |
| 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 | |
| 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 | ******************************************************************************/ |
| 57 | void 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 | } |
| 64 | |
| 65 | #if !ERROR_DEPRECATED |
| 66 | /* |
| 67 | * These context management helpers are deprecated but are maintained for use |
| 68 | * by SPDs which have not migrated to the new API. If ERROR_DEPRECATED |
| 69 | * is enabled, these are excluded from the build so as to force users to |
| 70 | * migrate to the new API. |
| 71 | */ |
| 72 | |
| 73 | /******************************************************************************* |
| 74 | * This function returns a pointer to the most recent 'cpu_context' structure |
| 75 | * for the CPU identified by MPIDR that was set as the context for the specified |
| 76 | * security state. NULL is returned if no such structure has been specified. |
| 77 | ******************************************************************************/ |
| 78 | void *cm_get_context_by_mpidr(uint64_t mpidr, uint32_t security_state) |
| 79 | { |
| 80 | assert(sec_state_is_valid(security_state)); |
| 81 | |
Dan Handley | 807d727 | 2018-02-27 13:00:43 +0000 | [diff] [blame] | 82 | /* |
| 83 | * Suppress deprecated declaration warning in compatibility function |
| 84 | */ |
| 85 | #pragma GCC diagnostic push |
| 86 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 87 | return cm_get_context_by_index(platform_get_core_pos(mpidr), security_state); |
Dan Handley | 807d727 | 2018-02-27 13:00:43 +0000 | [diff] [blame] | 88 | #pragma GCC diagnostic pop |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /******************************************************************************* |
| 92 | * This function sets the pointer to the current 'cpu_context' structure for the |
| 93 | * specified security state for the CPU identified by MPIDR |
| 94 | ******************************************************************************/ |
| 95 | void cm_set_context_by_mpidr(uint64_t mpidr, void *context, uint32_t security_state) |
| 96 | { |
| 97 | assert(sec_state_is_valid(security_state)); |
| 98 | |
Dan Handley | 807d727 | 2018-02-27 13:00:43 +0000 | [diff] [blame] | 99 | /* |
| 100 | * Suppress deprecated declaration warning in compatibility function |
| 101 | */ |
| 102 | #pragma GCC diagnostic push |
| 103 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 104 | cm_set_context_by_index(platform_get_core_pos(mpidr), |
| 105 | context, security_state); |
Dan Handley | 807d727 | 2018-02-27 13:00:43 +0000 | [diff] [blame] | 106 | #pragma GCC diagnostic pop |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /******************************************************************************* |
| 110 | * The following function provides a compatibility function for SPDs using the |
| 111 | * existing cm library routines. This function is expected to be invoked for |
| 112 | * initializing the cpu_context for the CPU specified by MPIDR for first use. |
| 113 | ******************************************************************************/ |
Roberto Vargas | 777dd43 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 114 | void cm_init_context(uint64_t mpidr, const entry_point_info_t *ep) |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 115 | { |
| 116 | if ((mpidr & MPIDR_AFFINITY_MASK) == |
| 117 | (read_mpidr_el1() & MPIDR_AFFINITY_MASK)) |
| 118 | cm_init_my_context(ep); |
Dan Handley | 807d727 | 2018-02-27 13:00:43 +0000 | [diff] [blame] | 119 | else { |
| 120 | /* |
| 121 | * Suppress deprecated declaration warning in compatibility |
| 122 | * function |
| 123 | */ |
| 124 | #pragma GCC diagnostic push |
| 125 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 126 | cm_init_context_by_index(platform_get_core_pos(mpidr), ep); |
Dan Handley | 807d727 | 2018-02-27 13:00:43 +0000 | [diff] [blame] | 127 | #pragma GCC diagnostic pop |
| 128 | } |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 129 | } |
Dan Handley | 807d727 | 2018-02-27 13:00:43 +0000 | [diff] [blame] | 130 | #endif /* ERROR_DEPRECATED */ |