Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Tamas Ban | 8bd24b7 | 2019-02-19 12:13:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, 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 | 8bd24b7 | 2019-02-19 12:13:13 +0000 | [diff] [blame] | 14 | #include "tfm_memory_utils.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 = |
Edison Ai | bb614aa | 2018-11-21 15:15:00 +0800 | [diff] [blame] | 121 | SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT; |
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); |
Edison Ai | bb614aa | 2018-11-21 15:15:00 +0800 | [diff] [blame] | 145 | #ifdef TFM_PSA_API |
| 146 | if (part->static_data.partition_flags & SPM_PART_FLAG_IPC) { |
| 147 | continue; |
| 148 | } |
| 149 | #endif |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 150 | if (part->static_data.partition_init == NULL) { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 151 | tfm_spm_partition_set_state(idx, SPM_PARTITION_STATE_IDLE); |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 152 | tfm_spm_partition_set_caller_partition_idx(idx, |
| 153 | SPM_INVALID_PARTITION_IDX); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 154 | } else { |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 155 | int32_t res; |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 156 | |
| 157 | desc.args = args; |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 158 | desc.ns_caller = 0; |
Mate Toth-Pal | b8ce0dd | 2018-07-25 10:18:34 +0200 | [diff] [blame] | 159 | desc.iovec_api = TFM_SFN_API_IOVEC; |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 160 | desc.sfn = (sfn_t)part->static_data.partition_init; |
| 161 | desc.sp_id = part->static_data.partition_id; |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 162 | res = tfm_core_sfn_request(&desc); |
| 163 | if (res == TFM_SUCCESS) { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 164 | tfm_spm_partition_set_state(idx, SPM_PARTITION_STATE_IDLE); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 165 | } else { |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 166 | tfm_spm_partition_err_handler(part, TFM_INIT_FAILURE, res); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 167 | fail_cnt++; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 172 | tfm_secure_api_init_done(); |
| 173 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 174 | if (fail_cnt == 0) { |
| 175 | return SPM_ERR_OK; |
| 176 | } else { |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 177 | return SPM_ERR_PARTITION_NOT_AVAILABLE; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| 181 | #if TFM_LVL != 1 |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 182 | 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] | 183 | { |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 184 | struct spm_partition_desc_t *part; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 185 | if (!g_spm_partition_db.is_init) { |
| 186 | return SPM_ERR_PARTITION_DB_NOT_INIT; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 189 | part = &g_spm_partition_db.partitions[partition_idx]; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 190 | |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 191 | return tfm_spm_hal_partition_sandbox_config(&(part->memory_data), |
| 192 | part->platform_data); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 193 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 196 | 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] | 197 | { |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 198 | /* This function takes a partition id and disables the |
| 199 | * SPM partition for that partition |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 200 | */ |
| 201 | |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 202 | struct spm_partition_desc_t *part; |
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 | part = &g_spm_partition_db.partitions[partition_idx]; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 205 | |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 206 | return tfm_spm_hal_partition_sandbox_deconfig(&(part->memory_data), |
| 207 | part->platform_data); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 210 | uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 211 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 212 | return g_spm_partition_db.partitions[partition_idx]. |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 213 | memory_data.stack_bottom; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 216 | uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 217 | { |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 218 | return g_spm_partition_db.partitions[partition_idx].memory_data.stack_top; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 221 | uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx) |
| 222 | { |
| 223 | return g_spm_partition_db.partitions[partition_idx]. |
| 224 | memory_data.zi_start; |
| 225 | } |
| 226 | |
| 227 | uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx) |
| 228 | { |
| 229 | return g_spm_partition_db.partitions[partition_idx]. |
| 230 | memory_data.zi_limit; |
| 231 | } |
| 232 | |
| 233 | uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx) |
| 234 | { |
| 235 | return g_spm_partition_db.partitions[partition_idx]. |
| 236 | memory_data.rw_start; |
| 237 | } |
| 238 | |
| 239 | uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx) |
| 240 | { |
| 241 | return g_spm_partition_db.partitions[partition_idx]. |
| 242 | memory_data.rw_limit; |
| 243 | } |
| 244 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 245 | 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] | 246 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 247 | g_spm_partition_db.partitions[partition_idx]. |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 248 | runtime_data.stack_ptr = stack_ptr; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 249 | } |
| 250 | #endif |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 251 | |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 252 | void tfm_spm_partition_store_context(uint32_t partition_idx, |
| 253 | uint32_t stack_ptr, uint32_t lr) |
| 254 | { |
| 255 | g_spm_partition_db.partitions[partition_idx]. |
| 256 | runtime_data.stack_ptr = stack_ptr; |
| 257 | g_spm_partition_db.partitions[partition_idx]. |
| 258 | runtime_data.lr = lr; |
| 259 | } |
| 260 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 261 | 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] | 262 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 263 | return g_spm_partition_db.partitions[partition_idx].static_data. |
| 264 | partition_id; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 265 | } |
| 266 | |
Mate Toth-Pal | 5939871 | 2018-02-28 17:06:40 +0100 | [diff] [blame] | 267 | uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx) |
| 268 | { |
| 269 | return g_spm_partition_db.partitions[partition_idx].static_data. |
| 270 | partition_flags; |
| 271 | } |
| 272 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 273 | const struct spm_partition_runtime_data_t * |
Mate Toth-Pal | 5939871 | 2018-02-28 17:06:40 +0100 | [diff] [blame] | 274 | tfm_spm_partition_get_runtime_data(uint32_t partition_idx) |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 275 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 276 | return &(g_spm_partition_db.partitions[partition_idx].runtime_data); |
| 277 | } |
| 278 | |
| 279 | void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state) |
| 280 | { |
| 281 | g_spm_partition_db.partitions[partition_idx].runtime_data.partition_state = |
| 282 | state; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 283 | if (state == SPM_PARTITION_STATE_RUNNING) { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 284 | g_spm_partition_db.running_partition_idx = partition_idx; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 288 | void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx, |
| 289 | uint32_t caller_partition_idx) |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 290 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 291 | g_spm_partition_db.partitions[partition_idx].runtime_data. |
| 292 | caller_partition_idx = caller_partition_idx; |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 293 | } |
| 294 | |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 295 | void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx, |
| 296 | int32_t caller_client_id) |
| 297 | { |
| 298 | g_spm_partition_db.partitions[partition_idx].runtime_data. |
| 299 | caller_client_id = caller_client_id; |
| 300 | } |
| 301 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 302 | 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] | 303 | uint32_t share) |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 304 | { |
| 305 | enum spm_err_t ret = SPM_ERR_OK; |
| 306 | |
| 307 | #if TFM_LVL != 1 |
| 308 | /* Only need to set configuration on levels higher than 1 */ |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 309 | ret = tfm_spm_hal_set_share_region(share); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 310 | #endif |
| 311 | |
| 312 | if (ret == SPM_ERR_OK) { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 313 | g_spm_partition_db.partitions[partition_idx].runtime_data.share = share; |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 314 | } |
| 315 | return ret; |
| 316 | } |
| 317 | |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 318 | void tfm_spm_partition_set_iovec(uint32_t partition_idx, int32_t *args) |
| 319 | { |
| 320 | struct spm_partition_runtime_data_t *runtime_data = |
| 321 | &g_spm_partition_db.partitions[partition_idx].runtime_data; |
| 322 | int32_t i; |
| 323 | |
| 324 | runtime_data->iovec_args.in_len = args[1]; |
| 325 | for (i = 0; i < runtime_data->iovec_args.in_len; ++i) { |
| 326 | runtime_data->iovec_args.in_vec[i].base = |
| 327 | ((psa_invec *)args[0])[i].base; |
| 328 | runtime_data->iovec_args.in_vec[i].len = ((psa_invec *)args[0])[i].len; |
| 329 | } |
| 330 | runtime_data->iovec_args.out_len = args[3]; |
| 331 | for (i = 0; i < runtime_data->iovec_args.out_len; ++i) { |
| 332 | runtime_data->iovec_args.out_vec[i].base = |
| 333 | ((psa_outvec *)args[2])[i].base; |
| 334 | runtime_data->iovec_args.out_vec[i].len = |
| 335 | ((psa_outvec *)args[2])[i].len; |
| 336 | } |
| 337 | runtime_data->orig_outvec = (psa_outvec *)args[2]; |
Mate Toth-Pal | 2a6f8c2 | 2018-12-13 16:37:17 +0100 | [diff] [blame] | 338 | runtime_data->iovec_api = 1; |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 341 | uint32_t tfm_spm_partition_get_running_partition_idx(void) |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 342 | { |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 343 | return g_spm_partition_db.running_partition_idx; |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 344 | } |
| 345 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 346 | void tfm_spm_partition_cleanup_context(uint32_t partition_idx) |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 347 | { |
Mate Toth-Pal | 936c33b | 2018-04-10 14:02:07 +0200 | [diff] [blame] | 348 | struct spm_partition_desc_t *partition = |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 349 | &(g_spm_partition_db.partitions[partition_idx]); |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 350 | int32_t i; |
| 351 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 352 | partition->runtime_data.caller_partition_idx = SPM_INVALID_PARTITION_IDX; |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 353 | partition->runtime_data.share = 0; |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 354 | partition->runtime_data.iovec_args.in_len = 0; |
| 355 | for (i = 0; i < PSA_MAX_IOVEC; ++i) { |
| 356 | partition->runtime_data.iovec_args.in_vec[i].base = 0; |
| 357 | partition->runtime_data.iovec_args.in_vec[i].len = 0; |
| 358 | } |
| 359 | partition->runtime_data.iovec_args.out_len = 0; |
| 360 | for (i = 0; i < PSA_MAX_IOVEC; ++i) { |
| 361 | partition->runtime_data.iovec_args.out_vec[i].base = 0; |
| 362 | partition->runtime_data.iovec_args.out_vec[i].len = 0; |
| 363 | } |
| 364 | partition->runtime_data.orig_outvec = 0; |
Mate Toth-Pal | 2a6f8c2 | 2018-12-13 16:37:17 +0100 | [diff] [blame] | 365 | partition->runtime_data.iovec_api = 0; |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 366 | } |