blob: a88564536457a456edb3e0a2858af99785cf040b [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Mate Toth-Pal65291f32018-02-23 14:35:22 +01002 * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Miklos Balint386b8b52017-11-29 13:12:32 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Mate Toth-Pal349714a2018-02-23 15:30:24 +01008/* This file contains the APIs exported by the SPM to tfm core */
Miklos Balint386b8b52017-11-29 13:12:32 +00009
10#include <stdio.h>
Miklos Balint386b8b52017-11-29 13:12:32 +000011#include "spm_api.h"
Mate Toth-Pal65291f32018-02-23 14:35:22 +010012#include "spm_db.h"
13#include "tfm_api.h"
Miklos Balint386b8b52017-11-29 13:12:32 +000014#include "mpu_armv8m_drv.h"
15#include "region_defs.h"
16#include "secure_fw/core/tfm_core.h"
17
Mate Toth-Pal349714a2018-02-23 15:30:24 +010018struct spm_partition_db_t g_spm_partition_db = {0,};
Miklos Balint386b8b52017-11-29 13:12:32 +000019
20#define MPU_REGION_VENEERS 0
21#define MPU_REGION_TFM_UNPRIV_CODE 1
22#define MPU_REGION_TFM_UNPRIV_DATA 2
23#define MPU_REGION_NS_DATA 3
Mate Toth-Pal349714a2018-02-23 15:30:24 +010024#define PARTITION_REGION_RO 4
25#define PARTITION_REGION_RW_STACK 5
26#define PARTITION_REGION_PERIPH 6
27#define PARTITION_REGION_SHARE 7
Miklos Balint386b8b52017-11-29 13:12:32 +000028
29/* This should move to platform retarget */
30struct mpu_armv8m_dev_t dev_mpu_s = { MPU_BASE };
31
32typedef enum {
33 TFM_INIT_FAILURE,
34} ss_error_type_t;
35
36/*
Mate Toth-Pal349714a2018-02-23 15:30:24 +010037 * This function is called when a secure partition causes an error.
Mate Toth-Pal65291f32018-02-23 14:35:22 +010038 * In case of an error in the error handling, a non-zero value have to be
39 * returned.
Miklos Balint386b8b52017-11-29 13:12:32 +000040 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010041static void tfm_spm_partition_err_handler(
42 struct spm_partition_region_t *partition,
Mate Toth-Pal65291f32018-02-23 14:35:22 +010043 ss_error_type_t err_type,
44 int32_t err_code)
Miklos Balint386b8b52017-11-29 13:12:32 +000045{
Miklos Balint386b8b52017-11-29 13:12:32 +000046#ifdef TFM_CORE_DEBUG
47 if (err_type == TFM_INIT_FAILURE) {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010048 printf("Partition init failed for partition id 0x%08X\r\n",
49 partition->partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000050 } else {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010051 printf("Unknown partition error %d for partition id 0x%08X\r\n",
52 err_type, partition->partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000053 }
54#endif
Mate Toth-Pal349714a2018-02-23 15:30:24 +010055 tfm_spm_partition_set_state(partition->partition_id,
56 SPM_PARTITION_STATE_CLOSED);
Miklos Balint386b8b52017-11-29 13:12:32 +000057}
58
59enum spm_err_t tfm_spm_db_init(void)
60{
Mate Toth-Pal349714a2018-02-23 15:30:24 +010061 /* This function initialises partition db */
62 g_spm_partition_db.is_init = 1;
63 g_spm_partition_db.running_partition_id = INVALID_PARITION_ID;
Miklos Balint386b8b52017-11-29 13:12:32 +000064
Mate Toth-Pal349714a2018-02-23 15:30:24 +010065 g_spm_partition_db.partition_count =
66 create_user_partition_db(&g_spm_partition_db, SPM_MAX_PARTITIONS);
Miklos Balint386b8b52017-11-29 13:12:32 +000067
68 return SPM_ERR_OK;
69}
70
71#if TFM_LVL != 1
72REGION_DECLARE(Image$$, TFM_UNPRIV_CODE, $$RO$$Base);
73REGION_DECLARE(Image$$, TFM_UNPRIV_CODE, $$RO$$Limit);
74REGION_DECLARE(Image$$, TFM_UNPRIV_RO_DATA, $$RW$$Base);
75REGION_DECLARE(Image$$, TFM_UNPRIV_RO_DATA, $$ZI$$Limit);
76REGION_DECLARE(Image$$, TFM_UNPRIV_SCRATCH, $$ZI$$Base);
77REGION_DECLARE(Image$$, TFM_UNPRIV_SCRATCH, $$ZI$$Limit);
78
79enum spm_err_t tfm_spm_mpu_init(void)
80{
81 mpu_armv8m_clean(&dev_mpu_s);
82
83 struct mpu_armv8m_region_cfg_t region_cfg;
84
85 /* Veneer region */
86 region_cfg.region_nr = MPU_REGION_VENEERS;
87 region_cfg.region_base = CMSE_VENEER_REGION_START;
88 region_cfg.region_limit = CMSE_VENEER_REGION_LIMIT;
89 region_cfg.attr_access = MPU_ARMV8M_AP_RO_PRIV_UNPRIV;
90 region_cfg.attr_sh = MPU_ARMV8M_SH_NONE;
91 region_cfg.attr_exec = MPU_ARMV8M_XN_EXEC_OK;
92 mpu_armv8m_region_enable(&dev_mpu_s, &region_cfg);
93
94 /* TFM Core unprivileged code region */
95 region_cfg.region_nr = MPU_REGION_TFM_UNPRIV_CODE;
96 region_cfg.region_base =
97 (uint32_t)&REGION_NAME(Image$$, TFM_UNPRIV_CODE, $$RO$$Base);
98 region_cfg.region_limit =
99 (uint32_t)&REGION_NAME(Image$$, TFM_UNPRIV_CODE, $$RO$$Limit);
100 region_cfg.attr_access = MPU_ARMV8M_AP_RO_PRIV_UNPRIV;
101 region_cfg.attr_sh = MPU_ARMV8M_SH_NONE;
102 region_cfg.attr_exec = MPU_ARMV8M_XN_EXEC_OK;
103 mpu_armv8m_region_enable(&dev_mpu_s, &region_cfg);
104
105 /* TFM Core unprivileged data region */
106 region_cfg.region_nr = MPU_REGION_TFM_UNPRIV_DATA;
107 region_cfg.region_base =
108 (uint32_t)&REGION_NAME(Image$$, TFM_UNPRIV_RO_DATA, $$RW$$Base);
109 region_cfg.region_limit =
110 (uint32_t)&REGION_NAME(Image$$, TFM_UNPRIV_RO_DATA, $$ZI$$Limit);
111 region_cfg.attr_access = MPU_ARMV8M_AP_RO_PRIV_UNPRIV;
112 region_cfg.attr_sh = MPU_ARMV8M_SH_NONE;
113 region_cfg.attr_exec = MPU_ARMV8M_XN_EXEC_NEVER;
114 mpu_armv8m_region_enable(&dev_mpu_s, &region_cfg);
115
116 /* TFM Core unprivileged non-secure data region */
117 region_cfg.region_nr = MPU_REGION_NS_DATA;
118 region_cfg.region_base = NS_DATA_START;
119 region_cfg.region_limit = NS_DATA_LIMIT;
120 region_cfg.attr_access = MPU_ARMV8M_AP_RW_PRIV_UNPRIV;
121 region_cfg.attr_sh = MPU_ARMV8M_SH_NONE;
122 region_cfg.attr_exec = MPU_ARMV8M_XN_EXEC_NEVER;
123 mpu_armv8m_region_enable(&dev_mpu_s, &region_cfg);
124
125 mpu_armv8m_enable(&dev_mpu_s, 1, 1);
126
127 return SPM_ERR_OK;
128}
129
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100130/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100131 * Set share region to which the partition needs access
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100132 */
133static enum spm_err_t tfm_spm_set_share_region(
134 enum tfm_buffer_share_region_e share)
Miklos Balint386b8b52017-11-29 13:12:32 +0000135{
136 enum spm_err_t res = SPM_ERR_INVALID_CONFIG;
137 uint32_t scratch_base =
138 (uint32_t)&REGION_NAME(Image$$, TFM_UNPRIV_SCRATCH, $$ZI$$Base);
139 uint32_t scratch_limit =
140 (uint32_t)&REGION_NAME(Image$$, TFM_UNPRIV_SCRATCH, $$ZI$$Limit);
141
142 mpu_armv8m_disable(&dev_mpu_s);
143
144 if (share == TFM_BUFFER_SHARE_DISABLE) {
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100145 mpu_armv8m_region_disable(&dev_mpu_s, PARTITION_REGION_SHARE);
Miklos Balint386b8b52017-11-29 13:12:32 +0000146 } else {
147 struct mpu_armv8m_region_cfg_t region_cfg;
148
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100149 region_cfg.region_nr = PARTITION_REGION_SHARE;
Miklos Balint386b8b52017-11-29 13:12:32 +0000150 region_cfg.attr_access = MPU_ARMV8M_AP_RW_PRIV_UNPRIV;
151 region_cfg.attr_sh = MPU_ARMV8M_SH_NONE;
152 region_cfg.attr_exec = MPU_ARMV8M_XN_EXEC_NEVER;
153 switch (share) {
154 case TFM_BUFFER_SHARE_SCRATCH:
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100155 /* Use scratch area for SP-to-SP data sharing */
Miklos Balint386b8b52017-11-29 13:12:32 +0000156 region_cfg.region_base = scratch_base;
157 region_cfg.region_limit = scratch_limit;
158 res = SPM_ERR_OK;
159 break;
160 case TFM_BUFFER_SHARE_NS_CODE:
161 region_cfg.region_base = NS_CODE_START;
162 region_cfg.region_limit = NS_CODE_LIMIT;
163 /* Only allow read access to NS code region and keep
164 * exec.never attribute
165 */
166 region_cfg.attr_access = MPU_ARMV8M_AP_RO_PRIV_UNPRIV;
167 res = SPM_ERR_OK;
168 break;
169 default:
170 res = SPM_ERR_INVALID_CONFIG;
171 break;
172 }
173 if (res == SPM_ERR_OK) {
174 mpu_armv8m_region_enable(&dev_mpu_s, &region_cfg);
175 }
176 }
177 mpu_armv8m_enable(&dev_mpu_s, 1, 1);
178
179 return res;
180}
181#endif
182
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100183enum spm_err_t tfm_spm_partition_init(void)
Miklos Balint386b8b52017-11-29 13:12:32 +0000184{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100185 struct spm_partition_region_t *serv;
Miklos Balint386b8b52017-11-29 13:12:32 +0000186 int32_t fail_cnt = 0;
187 uint32_t i;
188
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100189 /* Call the init function for each partition */
Miklos Balint386b8b52017-11-29 13:12:32 +0000190 /* FixMe: This implementation only fits level 1 isolation.
191 * On higher levels MPU (and PPC) configuration need to be in place to have
192 * proper isolation during init.
193 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100194 for (i = 0; i < g_spm_partition_db.partition_count; ++i) {
195 serv = &g_spm_partition_db.partitions[i];
Miklos Balint386b8b52017-11-29 13:12:32 +0000196 if (serv->periph_start) {
197 ppc_configure_to_secure(serv->periph_ppc_bank,
198 serv->periph_ppc_loc);
199 }
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100200 if (serv->partition_init == NULL) {
201 tfm_spm_partition_set_state(serv->partition_id,
202 SPM_PARTITION_STATE_IDLE);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100203 } else {
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100204 int32_t ret = serv->partition_init();
Miklos Balint386b8b52017-11-29 13:12:32 +0000205
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100206 if (ret == TFM_SUCCESS) {
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100207 tfm_spm_partition_set_state(
208 serv->partition_id, SPM_PARTITION_STATE_IDLE);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100209 } else {
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100210 tfm_spm_partition_err_handler(serv, TFM_INIT_FAILURE, ret);
Miklos Balint386b8b52017-11-29 13:12:32 +0000211 fail_cnt++;
212 }
213 }
214 }
215
216 if (fail_cnt == 0) {
217 return SPM_ERR_OK;
218 } else {
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100219 return SPM_ERR_PARTITION_NOT_AVAILABLE;
Miklos Balint386b8b52017-11-29 13:12:32 +0000220 }
221}
222
223#if TFM_LVL != 1
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100224enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_id)
Miklos Balint386b8b52017-11-29 13:12:32 +0000225{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100226 /* This function takes a partition id and enables the
227 * SPM partition for that partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000228 */
229
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100230 struct spm_partition_region_t *serv;
Miklos Balint386b8b52017-11-29 13:12:32 +0000231 struct mpu_armv8m_region_cfg_t region_cfg;
232
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100233 if (!g_spm_partition_db.is_init) {
234 return SPM_ERR_PARTITION_DB_NOT_INIT;
Miklos Balint386b8b52017-11-29 13:12:32 +0000235 }
236
237 /*brute force id*/
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100238 serv = &g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)];
Miklos Balint386b8b52017-11-29 13:12:32 +0000239
240 mpu_armv8m_disable(&dev_mpu_s);
241
242 /* Configure Regions */
243
244 /* RO region*/
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100245 region_cfg.region_nr = PARTITION_REGION_RO;
Miklos Balint386b8b52017-11-29 13:12:32 +0000246 region_cfg.region_base = serv->ro_start;
247 region_cfg.region_limit = serv->ro_limit;
248 region_cfg.attr_access = MPU_ARMV8M_AP_RO_PRIV_UNPRIV;
249 region_cfg.attr_sh = MPU_ARMV8M_SH_NONE;
250 region_cfg.attr_exec = MPU_ARMV8M_XN_EXEC_OK;
251
252 mpu_armv8m_region_enable(&dev_mpu_s, &region_cfg);
253
254 /* RW, ZI and stack as one region*/
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100255 region_cfg.region_nr = PARTITION_REGION_RW_STACK;
Miklos Balint386b8b52017-11-29 13:12:32 +0000256 region_cfg.region_base = serv->rw_start;
257 region_cfg.region_limit = serv->stack_top;
258 region_cfg.attr_access = MPU_ARMV8M_AP_RW_PRIV_UNPRIV;
259 region_cfg.attr_sh = MPU_ARMV8M_SH_NONE;
260 region_cfg.attr_exec = MPU_ARMV8M_XN_EXEC_NEVER;
261
262 mpu_armv8m_region_enable(&dev_mpu_s, &region_cfg);
263
264 if (serv->periph_start) {
265 /* Peripheral */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100266 region_cfg.region_nr = PARTITION_REGION_PERIPH;
Miklos Balint386b8b52017-11-29 13:12:32 +0000267 region_cfg.region_base = serv->periph_start;
268 region_cfg.region_limit = serv->periph_limit;
269 region_cfg.attr_access = MPU_ARMV8M_AP_RW_PRIV_UNPRIV;
270 region_cfg.attr_sh = MPU_ARMV8M_SH_NONE;
271 region_cfg.attr_exec = MPU_ARMV8M_XN_EXEC_NEVER;
272 mpu_armv8m_region_enable(&dev_mpu_s, &region_cfg);
273
274 ppc_en_secure_unpriv(serv->periph_ppc_bank, serv->periph_ppc_loc);
275 }
276
277 mpu_armv8m_enable(&dev_mpu_s, 1, 1);
278
279#ifndef UNPRIV_JUMP_TO_NS
280 /* FixMe: if jump_to_ns_code() from unprivileged is solved,
281 * this code can be removed
282 */
283 /* Initialization is done, set thread mode to unprivileged.
284 */
285 CONTROL_Type ctrl;
286
287 ctrl.w = __get_CONTROL();
288 ctrl.b.nPRIV = 1;
289 __set_CONTROL(ctrl.w);
290 __DSB();
291 __ISB();
292#endif
293
294 return SPM_ERR_OK;
295}
296
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100297enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_id)
Miklos Balint386b8b52017-11-29 13:12:32 +0000298{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100299 /* This function takes a partition id and disables the
300 * SPM partition for that partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000301 */
302
303#ifndef UNPRIV_JUMP_TO_NS
304 /* FixMe: if jump_to_ns_code() from unprivileged is solved,
305 * this code can be removed
306 */
307 CONTROL_Type ctrl;
308
309 ctrl.w = __get_CONTROL();
310 ctrl.b.nPRIV = 0;
311 __set_CONTROL(ctrl.w);
312 __DSB();
313 __ISB();
314#endif
315
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100316 struct spm_partition_region_t *serv;
Miklos Balint386b8b52017-11-29 13:12:32 +0000317
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100318 serv = &g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)];
Miklos Balint386b8b52017-11-29 13:12:32 +0000319
320 if (serv->periph_start) {
321 /* Peripheral */
322 ppc_clr_secure_unpriv(serv->periph_ppc_bank, serv->periph_ppc_loc);
323 }
324
325 mpu_armv8m_disable(&dev_mpu_s);
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100326 mpu_armv8m_region_disable(&dev_mpu_s, PARTITION_REGION_RO);
327 mpu_armv8m_region_disable(&dev_mpu_s, PARTITION_REGION_RW_STACK);
328 mpu_armv8m_region_disable(&dev_mpu_s, PARTITION_REGION_PERIPH);
329 mpu_armv8m_region_disable(&dev_mpu_s, PARTITION_REGION_SHARE);
Miklos Balint386b8b52017-11-29 13:12:32 +0000330 mpu_armv8m_enable(&dev_mpu_s, 1, 1);
331
332 return SPM_ERR_OK;
333}
334
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100335uint32_t tfm_spm_partition_get_stack(uint32_t partition_id)
Miklos Balint386b8b52017-11-29 13:12:32 +0000336{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100337 return g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].
338 stack_ptr;
Miklos Balint386b8b52017-11-29 13:12:32 +0000339}
340
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100341uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_id)
Miklos Balint386b8b52017-11-29 13:12:32 +0000342{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100343 return g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].
344 stack_bottom;
Miklos Balint386b8b52017-11-29 13:12:32 +0000345}
346
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100347uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_id)
Miklos Balint386b8b52017-11-29 13:12:32 +0000348{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100349 return
350 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].stack_top;
Miklos Balint386b8b52017-11-29 13:12:32 +0000351}
352
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100353void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr)
Miklos Balint386b8b52017-11-29 13:12:32 +0000354{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100355 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].stack_ptr =
356 stack_ptr;
Miklos Balint386b8b52017-11-29 13:12:32 +0000357}
358#endif
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100359
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100360uint32_t tfm_spm_partition_get_state(uint32_t partition_id)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100361{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100362 return g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].
363 partition_state;
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100364}
365
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100366uint32_t tfm_spm_partition_get_caller_partition_id(uint32_t partition_id)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100367{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100368 return g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].
369 caller_partition_id;
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100370}
371
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100372uint32_t tfm_spm_partition_get_orig_psp(uint32_t partition_id)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100373{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100374 return
375 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].orig_psp;
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100376}
377
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100378uint32_t tfm_spm_partition_get_orig_psplim(uint32_t partition_id)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100379{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100380 return g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100381 orig_psplim;
382}
383
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100384uint32_t tfm_spm_partition_get_orig_lr(uint32_t partition_id)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100385{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100386 return g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].
387 orig_lr;
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100388}
389
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100390uint32_t tfm_spm_partition_get_share(uint32_t partition_id)
391{
392 return g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].share;
393}
394
395void tfm_spm_partition_set_state(uint32_t partition_id, uint32_t state)
396{
397 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].
398 partition_state = state;
399 if (state == SPM_PARTITION_STATE_RUNNING) {
400 g_spm_partition_db.running_partition_id = partition_id;
401 }
402}
403
404void tfm_spm_partition_set_caller_partition_id(uint32_t partition_id,
405 uint32_t caller_partition_id)
406{
407 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].
408 caller_partition_id = caller_partition_id;
409}
410
411void tfm_spm_partition_set_orig_psp(uint32_t partition_id,
412 uint32_t orig_psp)
413{
414 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].orig_psp =
415 orig_psp;
416}
417
418void tfm_spm_partition_set_orig_psplim(uint32_t partition_id,
419 uint32_t orig_psplim)
420{
421 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].orig_psplim =
422 orig_psplim;
423}
424
425void tfm_spm_partition_set_orig_lr(uint32_t partition_id, uint32_t orig_lr)
426{
427 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].orig_lr =
428 orig_lr;
429}
430
431enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_id,
432 uint32_t share)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100433{
434 enum spm_err_t ret = SPM_ERR_OK;
435
436#if TFM_LVL != 1
437 /* Only need to set configuration on levels higher than 1 */
438 ret = tfm_spm_set_share_region(share);
439#endif
440
441 if (ret == SPM_ERR_OK) {
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100442 g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)].share =
443 share;
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100444 }
445 return ret;
446}
447
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100448uint32_t tfm_spm_partition_get_running_partition_id(void)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100449{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100450 return g_spm_partition_db.running_partition_id;
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100451}
452
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100453void tfm_spm_partition_cleanup_context(uint32_t partition_id)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100454{
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100455 struct spm_partition_region_t *partition =
456 &g_spm_partition_db.partitions[PARTITION_ID_GET(partition_id)];
457 partition->partition_state = 0;
458 partition->caller_partition_id = 0;
459 partition->orig_psp = 0;
460 partition->orig_psplim = 0;
461 partition->orig_lr = 0;
462 partition->share = 0;
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100463}