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