Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 8 | /* This file contains the APIs exported by the SPM to tfm core */ |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 9 | |
| 10 | #include <stdio.h> |
Mate Toth-Pal | 7345a4b | 2018-03-08 16:10:28 +0100 | [diff] [blame] | 11 | #include <string.h> |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 12 | #include "spm_api.h" |
Mate Toth-Pal | e147533 | 2018-04-09 17:28:49 +0200 | [diff] [blame] | 13 | #include "platform/include/tfm_spm_hal.h" |
| 14 | #include "spm_db_setup.h" |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 15 | #include "tfm_internal.h" |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 16 | #include "tfm_api.h" |
Mate Toth-Pal | ce61afa | 2018-08-03 13:51:01 +0200 | [diff] [blame] | 17 | #include "tfm_nspm.h" |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 18 | #include "secure_fw/core/tfm_core.h" |
Mate Toth-Pal | e147533 | 2018-04-09 17:28:49 +0200 | [diff] [blame] | 19 | #include "platform_retarget.h" |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 20 | #include "tfm_peripherals_def.h" |
Mate Toth-Pal | e147533 | 2018-04-09 17:28:49 +0200 | [diff] [blame] | 21 | #include "spm_partition_defs.h" |
| 22 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 23 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 24 | struct spm_partition_db_t g_spm_partition_db = {0,}; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 25 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 26 | typedef enum { |
| 27 | TFM_INIT_FAILURE, |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 28 | } sp_error_type_t; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 29 | |
| 30 | /* |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 31 | * This function is called when a secure partition causes an error. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 32 | * In case of an error in the error handling, a non-zero value have to be |
| 33 | * returned. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 34 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 35 | static void tfm_spm_partition_err_handler( |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 36 | struct spm_partition_desc_t *partition, |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 37 | sp_error_type_t err_type, |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 38 | int32_t err_code) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 39 | { |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 40 | #ifdef TFM_CORE_DEBUG |
| 41 | if (err_type == TFM_INIT_FAILURE) { |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 42 | printf("Partition init failed for partition id 0x%08X\r\n", |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 43 | partition->static_data.partition_id); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 44 | } else { |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 45 | printf("Unknown partition error %d for partition id 0x%08X\r\n", |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 46 | err_type, partition->static_data.partition_id); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 47 | } |
| 48 | #endif |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 49 | tfm_spm_partition_set_state(partition->static_data.partition_id, |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 50 | SPM_PARTITION_STATE_CLOSED); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 53 | uint32_t get_partition_idx(uint32_t partition_id) |
| 54 | { |
| 55 | int i; |
| 56 | |
| 57 | if (partition_id == INVALID_PARTITION_ID) { |
| 58 | return SPM_INVALID_PARTITION_IDX; |
| 59 | } |
| 60 | |
| 61 | for (i = 0; i < g_spm_partition_db.partition_count; ++i) { |
| 62 | if (g_spm_partition_db.partitions[i].static_data.partition_id == |
| 63 | partition_id) { |
| 64 | return i; |
| 65 | } |
| 66 | } |
| 67 | return SPM_INVALID_PARTITION_IDX; |
| 68 | } |
| 69 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 70 | enum spm_err_t tfm_spm_db_init(void) |
| 71 | { |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 72 | struct spm_partition_desc_t *part_ptr; |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 73 | |
Mate Toth-Pal | 7345a4b | 2018-03-08 16:10:28 +0100 | [diff] [blame] | 74 | memset (&g_spm_partition_db, 0, sizeof(g_spm_partition_db)); |
| 75 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 76 | /* This function initialises partition db */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 77 | g_spm_partition_db.running_partition_idx = SPM_INVALID_PARTITION_IDX; |
| 78 | g_spm_partition_db.partition_count = 0; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 79 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 80 | /* There are a few partitions that are used by TF-M internally. |
| 81 | * These are explicitly added to the partition db here. |
| 82 | */ |
| 83 | |
| 84 | /* For the non secure Execution environment */ |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 85 | #if TFM_LVL != 1 |
| 86 | extern uint32_t Stack_Mem[]; |
| 87 | extern uint32_t Stack_top[]; |
| 88 | #endif |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 89 | if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { |
| 90 | return SPM_ERR_INVALID_CONFIG; |
| 91 | } |
| 92 | part_ptr = &(g_spm_partition_db.partitions[ |
| 93 | g_spm_partition_db.partition_count]); |
| 94 | part_ptr->static_data.partition_id = TFM_SP_NON_SECURE_ID; |
Mate Toth-Pal | 5939871 | 2018-02-28 17:06:40 +0100 | [diff] [blame] | 95 | part_ptr->static_data.partition_flags = 0; |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 96 | |
| 97 | #if TFM_LVL != 1 |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 98 | part_ptr->memory_data.stack_bottom = (uint32_t)Stack_Mem; |
| 99 | part_ptr->memory_data.stack_top = (uint32_t)Stack_top; |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 100 | /* Since RW, ZI and stack are configured as one MPU region, configure |
| 101 | * RW start address to Stack_Mem to get RW access to stack |
| 102 | */ |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 103 | part_ptr->memory_data.rw_start = (uint32_t)Stack_Mem; |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 104 | #endif |
| 105 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 106 | part_ptr->runtime_data.partition_state = SPM_PARTITION_STATE_UNINIT; |
Miklos Balint | 12735bc | 2018-08-01 15:45:18 +0200 | [diff] [blame] | 107 | tfm_nspm_configure_clients(); |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 108 | ++g_spm_partition_db.partition_count; |
| 109 | |
| 110 | /* For the TF-M core environment itself */ |
| 111 | if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { |
| 112 | return SPM_ERR_INVALID_CONFIG; |
| 113 | } |
| 114 | part_ptr = &(g_spm_partition_db.partitions[ |
| 115 | g_spm_partition_db.partition_count]); |
| 116 | part_ptr->static_data.partition_id = TFM_SP_CORE_ID; |
Mate Toth-Pal | 5939871 | 2018-02-28 17:06:40 +0100 | [diff] [blame] | 117 | part_ptr->static_data.partition_flags = |
| 118 | SPM_PART_FLAG_SECURE | SPM_PART_FLAG_TRUSTED; |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 119 | part_ptr->runtime_data.partition_state = SPM_PARTITION_STATE_UNINIT; |
| 120 | ++g_spm_partition_db.partition_count; |
| 121 | |
| 122 | /* Add user-defined secure partitions */ |
Miklos Balint | d306ab1 | 2018-05-18 16:58:18 +0200 | [diff] [blame] | 123 | #include "secure_fw/services/tfm_partition_list.inc" |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 124 | |
Mate Toth-Pal | 7345a4b | 2018-03-08 16:10:28 +0100 | [diff] [blame] | 125 | g_spm_partition_db.is_init = 1; |
| 126 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 127 | return SPM_ERR_OK; |
| 128 | } |
| 129 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 130 | enum spm_err_t tfm_spm_partition_init(void) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 131 | { |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 132 | struct spm_partition_desc_t *part; |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 133 | struct tfm_sfn_req_s desc; |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 134 | int32_t args[4] = {0}; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 135 | int32_t fail_cnt = 0; |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 136 | uint32_t idx; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 137 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 138 | /* Call the init function for each partition */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 139 | for (idx = 0; idx < g_spm_partition_db.partition_count; ++idx) { |
| 140 | part = &g_spm_partition_db.partitions[idx]; |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 141 | tfm_spm_hal_configure_default_isolation(part->platform_data); |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 142 | if (part->static_data.partition_init == NULL) { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 143 | tfm_spm_partition_set_state(idx, SPM_PARTITION_STATE_IDLE); |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 144 | tfm_spm_partition_set_caller_partition_idx(idx, |
| 145 | SPM_INVALID_PARTITION_IDX); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 146 | } else { |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 147 | int32_t res; |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 148 | |
| 149 | desc.args = args; |
| 150 | desc.exc_num = EXC_NUM_THREAD_MODE; |
| 151 | desc.ns_caller = 0; |
| 152 | desc.sfn = (sfn_t)part->static_data.partition_init; |
| 153 | desc.sp_id = part->static_data.partition_id; |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 154 | res = tfm_core_sfn_request(&desc); |
| 155 | if (res == TFM_SUCCESS) { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 156 | tfm_spm_partition_set_state(idx, SPM_PARTITION_STATE_IDLE); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 157 | } else { |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 158 | tfm_spm_partition_err_handler(part, TFM_INIT_FAILURE, res); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 159 | fail_cnt++; |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 164 | tfm_secure_api_init_done(); |
| 165 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 166 | if (fail_cnt == 0) { |
| 167 | return SPM_ERR_OK; |
| 168 | } else { |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 169 | return SPM_ERR_PARTITION_NOT_AVAILABLE; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
| 173 | #if TFM_LVL != 1 |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 174 | enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 175 | { |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 176 | struct spm_partition_desc_t *part; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 177 | if (!g_spm_partition_db.is_init) { |
| 178 | return SPM_ERR_PARTITION_DB_NOT_INIT; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 181 | part = &g_spm_partition_db.partitions[partition_idx]; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 182 | |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 183 | return tfm_spm_hal_partition_sandbox_config(&(part->memory_data), |
| 184 | part->platform_data); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 185 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 188 | enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 189 | { |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 190 | /* This function takes a partition id and disables the |
| 191 | * SPM partition for that partition |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 192 | */ |
| 193 | |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 194 | struct spm_partition_desc_t *part; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 195 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 196 | part = &g_spm_partition_db.partitions[partition_idx]; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 197 | |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 198 | return tfm_spm_hal_partition_sandbox_deconfig(&(part->memory_data), |
| 199 | part->platform_data); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 202 | uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 203 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 204 | return g_spm_partition_db.partitions[partition_idx]. |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 205 | memory_data.stack_bottom; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 208 | uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 209 | { |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 210 | return g_spm_partition_db.partitions[partition_idx].memory_data.stack_top; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 213 | uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx) |
| 214 | { |
| 215 | return g_spm_partition_db.partitions[partition_idx]. |
| 216 | memory_data.zi_start; |
| 217 | } |
| 218 | |
| 219 | uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx) |
| 220 | { |
| 221 | return g_spm_partition_db.partitions[partition_idx]. |
| 222 | memory_data.zi_limit; |
| 223 | } |
| 224 | |
| 225 | uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx) |
| 226 | { |
| 227 | return g_spm_partition_db.partitions[partition_idx]. |
| 228 | memory_data.rw_start; |
| 229 | } |
| 230 | |
| 231 | uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx) |
| 232 | { |
| 233 | return g_spm_partition_db.partitions[partition_idx]. |
| 234 | memory_data.rw_limit; |
| 235 | } |
| 236 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 237 | void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 238 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 239 | g_spm_partition_db.partitions[partition_idx]. |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 240 | runtime_data.stack_ptr = stack_ptr; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 241 | } |
| 242 | #endif |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 243 | |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 244 | void tfm_spm_partition_store_context(uint32_t partition_idx, |
| 245 | uint32_t stack_ptr, uint32_t lr) |
| 246 | { |
| 247 | g_spm_partition_db.partitions[partition_idx]. |
| 248 | runtime_data.stack_ptr = stack_ptr; |
| 249 | g_spm_partition_db.partitions[partition_idx]. |
| 250 | runtime_data.lr = lr; |
| 251 | } |
| 252 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 253 | uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx) |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 254 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 255 | return g_spm_partition_db.partitions[partition_idx].static_data. |
| 256 | partition_id; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Mate Toth-Pal | 5939871 | 2018-02-28 17:06:40 +0100 | [diff] [blame] | 259 | uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx) |
| 260 | { |
| 261 | return g_spm_partition_db.partitions[partition_idx].static_data. |
| 262 | partition_flags; |
| 263 | } |
| 264 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 265 | const struct spm_partition_runtime_data_t * |
Mate Toth-Pal | 5939871 | 2018-02-28 17:06:40 +0100 | [diff] [blame] | 266 | tfm_spm_partition_get_runtime_data(uint32_t partition_idx) |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 267 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 268 | return &(g_spm_partition_db.partitions[partition_idx].runtime_data); |
| 269 | } |
| 270 | |
| 271 | void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state) |
| 272 | { |
| 273 | g_spm_partition_db.partitions[partition_idx].runtime_data.partition_state = |
| 274 | state; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 275 | if (state == SPM_PARTITION_STATE_RUNNING) { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 276 | g_spm_partition_db.running_partition_idx = partition_idx; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 280 | void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx, |
| 281 | uint32_t caller_partition_idx) |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 282 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 283 | g_spm_partition_db.partitions[partition_idx].runtime_data. |
| 284 | caller_partition_idx = caller_partition_idx; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 287 | void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx, |
| 288 | int32_t caller_client_id) |
| 289 | { |
| 290 | g_spm_partition_db.partitions[partition_idx].runtime_data. |
| 291 | caller_client_id = caller_client_id; |
| 292 | } |
| 293 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 294 | enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx, |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 295 | uint32_t share) |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 296 | { |
| 297 | enum spm_err_t ret = SPM_ERR_OK; |
| 298 | |
| 299 | #if TFM_LVL != 1 |
| 300 | /* Only need to set configuration on levels higher than 1 */ |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 301 | ret = tfm_spm_hal_set_share_region(share); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 302 | #endif |
| 303 | |
| 304 | if (ret == SPM_ERR_OK) { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 305 | g_spm_partition_db.partitions[partition_idx].runtime_data.share = share; |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 306 | } |
| 307 | return ret; |
| 308 | } |
| 309 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 310 | uint32_t tfm_spm_partition_get_running_partition_idx(void) |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 311 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 312 | return g_spm_partition_db.running_partition_idx; |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 313 | } |
| 314 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 315 | void tfm_spm_partition_cleanup_context(uint32_t partition_idx) |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 316 | { |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 317 | struct spm_partition_desc_t *partition = |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 318 | &(g_spm_partition_db.partitions[partition_idx]); |
| 319 | partition->runtime_data.caller_partition_idx = SPM_INVALID_PARTITION_IDX; |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 320 | partition->runtime_data.share = 0; |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 321 | } |