TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
spm_func.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __SPM_FUNC_H__
9 #define __SPM_FUNC_H__
10 
11 #include <stdint.h>
12 #include "spm_partition_defs.h"
13 #include "tfm_arch.h"
14 #include "psa/client.h"
15 
16 #define SPM_PARTITION_STATE_UNINIT 0
17 #define SPM_PARTITION_STATE_IDLE 1
18 #define SPM_PARTITION_STATE_RUNNING 2
19 #define SPM_PARTITION_STATE_HANDLING_IRQ 3
20 #define SPM_PARTITION_STATE_SUSPENDED 4
21 #define SPM_PARTITION_STATE_BLOCKED 5
22 #define SPM_PARTITION_STATE_CLOSED 6
23 
24 #define EXC_NUM_THREAD_MODE (0)
25 #define EXC_NUM_SVCALL (11)
26 #define EXC_NUM_PENDSV (14)
27 #define EXC_NUM_SYSTICK (15)
28 
29 #define SPM_INVALID_PARTITION_IDX (~0U)
30 
31 /* Privileged definitions for partition thread mode */
32 #define TFM_PARTITION_UNPRIVILEGED_MODE 0
33 #define TFM_PARTITION_PRIVILEGED_MODE 1
34 
35 #define SPM_PART_FLAG_APP_ROT 0x01
36 #define SPM_PART_FLAG_PSA_ROT 0x02
37 #define SPM_PART_FLAG_IPC 0x04
38 
39 #define TFM_PRIORITY_HIGH 0
40 #define TFM_PRIORITY_NORMAL 0x7F
41 #define TFM_PRIORITY_LOW 0xFF
42 #define TFM_PRIORITY(LEVEL) TFM_PRIORITY_##LEVEL
43 
44 enum spm_err_t {
51 };
52 
58 struct iovec_args_t {
60  size_t in_len;
63  size_t out_len;
65 };
66 
67 /* The size of this struct must be multiple of 4 bytes as it is stacked to an
68  * uint32_t[] array
69  */
71  uint32_t partition_state;
72 };
73 
74 /* The size of this struct must be multiple of 4 bytes as it is stacked to an
75  * uint32_t[] array
76  */
78  uint32_t partition_state;
80 };
81 
86  uint32_t partition_state;
89  uint32_t stack_ptr;
90  uint32_t lr;
93  uint32_t *ctx_stack_ptr;
94  uint32_t signal_mask; /*
95  * Service signal mask passed by
96  * psa_wait()
97  */
98 };
99 
106  uint32_t partition_id;
107  uint32_t partition_flags;
111  int32_t *p_dependencies;
112 };
113 
122  const struct tfm_spm_partition_platform_data_t **platform_data_list;
123 };
124 
126  uint32_t is_init;
127  uint32_t partition_count;
130 };
131 
140 void tfm_spm_partition_push_interrupted_ctx(uint32_t partition_idx);
141 
150 void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx);
151 
160 void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx);
161 
170 void tfm_spm_partition_pop_handler_ctx(uint32_t partition_idx);
171 
181 const struct spm_partition_runtime_data_t *
182  tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
183 
191 
201 void tfm_spm_partition_store_context(uint32_t partition_idx, uint32_t stack_ptr,
202  uint32_t lr);
203 
213 void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
214 
223 void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
224  uint32_t caller_partition_idx);
225 
234 void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
235  int32_t caller_client_id);
236 
237 
256 enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
257  const int32_t *args);
258 
265 
273 void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
274 
283 void tfm_spm_partition_set_signal_mask(uint32_t partition_idx,
284  uint32_t signal_mask);
285 
290 
295  const uint32_t *svc_args, uint32_t lr);
296 
300 uint32_t tfm_spm_partition_return_handler(uint32_t lr);
301 
305 void tfm_spm_get_caller_client_id_handler(uint32_t *svc_args);
306 
310 void tfm_spm_memory_permission_check_handler(uint32_t *svc_args);
311 
328 int32_t tfm_spm_check_buffer_access(uint32_t partition_idx,
329  void *start_addr,
330  size_t len,
331  uint32_t alignment);
332 
336 extern uint32_t tfm_spm_depriv_req_handler(uint32_t *svc_args,
337  uint32_t excReturn);
338 
342 uint32_t tfm_spm_depriv_return_handler(uint32_t *irq_svc_args, uint32_t lr);
343 
347 void tfm_spm_enable_irq_handler(uint32_t *svc_args);
348 
352 void tfm_spm_disable_irq_handler(uint32_t *svc_args);
353 
357 void tfm_spm_psa_wait(uint32_t *svc_args);
358 
362 void tfm_spm_psa_eoi(uint32_t *svc_args);
363 
373 uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
374 
380 enum spm_err_t tfm_spm_db_init(void);
381 
390 uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags);
391 
396 void tfm_spm_request_handler(const struct tfm_state_context_t *svc_ctx);
397 
401 void tfm_spm_seal_psp_stacks(void);
402 
403 
404 #endif /* __SPM_FUNC_H__ */
void tfm_spm_psa_eoi(uint32_t *svc_args)
Handle request to record IRQ processed.
Definition: spm_func.c:1118
void(* sp_entry_point)(void)
enum spm_err_t tfm_spm_db_init(void)
Initialize partition database.
Definition: spm_func.c:1415
void tfm_spm_memory_permission_check_handler(uint32_t *svc_args)
Checks if a secure service's access to a memory location is permitted.
size_t in_len
Definition: spm_func.h:60
uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags)
Get the current partition mode.
Definition: spm_func.c:713
const struct spm_partition_runtime_data_t * tfm_spm_partition_get_runtime_data(uint32_t partition_idx)
Get the current runtime data of a partition.
Definition: spm_func.c:1292
const struct tfm_spm_partition_platform_data_t ** platform_data_list
Definition: spm_func.h:122
uint32_t tfm_spm_depriv_req_handler(uint32_t *svc_args, uint32_t excReturn)
Handle deprivileged request.
Definition: spm_func.c:921
void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx, int32_t caller_client_id)
Set the caller client ID for a given partition.
Definition: spm_func.c:1321
struct spm_partition_runtime_data_t runtime_data
Definition: spm_func.h:119
size_t out_len
Definition: spm_func.h:63
psa_outvec * orig_outvec
Definition: spm_func.h:92
void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state)
Set the current state of a partition.
Definition: spm_func.c:1297
sp_entry_point partition_init
Definition: spm_func.h:109
void tfm_spm_disable_irq_handler(uint32_t *svc_args)
Handle IRQ disable request.
Definition: spm_func.c:1060
void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx)
Save handler partition context on ctx stack.
Definition: spm_func.c:1248
psa_outvec out_vec[PSA_MAX_IOVEC]
Definition: spm_func.h:62
void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx, uint32_t caller_partition_idx)
Set the caller partition index for a given partition.
Definition: spm_func.c:1307
const struct spm_partition_static_data_t * static_data
Definition: spm_func.h:120
uint32_t tfm_spm_partition_return_handler(uint32_t lr)
Called when secure service returns.
Definition: spm_func.c:949
#define PSA_MAX_IOVEC
Definition: client.h:54
uint32_t running_partition_idx
Definition: spm_func.h:128
void tfm_spm_partition_set_signal_mask(uint32_t partition_idx, uint32_t signal_mask)
Set the signal mask for a given partition.
Definition: spm_func.c:1314
Runtime context information of a partition.
Definition: spm_func.h:85
uint32_t partition_count
Definition: spm_func.h:127
int32_t tfm_spm_check_buffer_access(uint32_t partition_idx, void *start_addr, size_t len, uint32_t alignment)
Check whether a buffer is ok for writing to by the privileged API function.
Definition: spm_func.c:818
void tfm_spm_get_caller_client_id_handler(uint32_t *svc_args)
Stores caller's client id in state context.
Definition: spm_func.c:851
void tfm_spm_psa_wait(uint32_t *svc_args)
Handle signal wait request.
Definition: spm_func.c:1087
void tfm_spm_secure_api_init_done(void)
Signal that secure partition initialisation is finished.
Definition: spm_func.c:730
spm_err_t
Definition: spm_func.h:44
void tfm_spm_enable_irq_handler(uint32_t *svc_args)
Handle IRQ enable request.
Definition: spm_func.c:1033
void tfm_spm_request_handler(const struct tfm_state_context_t *svc_ctx)
Handle an SPM request by a secure service.
Definition: spm_func.c:1382
enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx, const int32_t *args)
Set the iovec parameters for the partition.
Definition: spm_func.c:1328
void tfm_spm_seal_psp_stacks(void)
Function to seal the PSP stacks for Function mode.
Definition: spm_func.c:51
enum spm_err_t tfm_spm_partition_init(void)
Execute partition init function.
Definition: spm_func.c:1168
uint32_t tfm_spm_partition_request_svc_handler(const uint32_t *svc_args, uint32_t lr)
Called if veneer is running in thread mode.
Definition: spm_func.c:894
struct iovec_args_t iovec_args
Definition: spm_func.h:91
void tfm_spm_partition_cleanup_context(uint32_t partition_idx)
Clears the context info from the database for a partition.
Definition: spm_func.c:1362
uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx)
Get the id of the partition for its index from the db.
Definition: spm_func.c:707
void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx)
Restores interrupted partition context on ctx stack.
Definition: spm_func.c:1233
void tfm_spm_partition_pop_handler_ctx(uint32_t partition_idx)
Restores handler partition context on ctx stack.
Definition: spm_func.c:1263
uint32_t is_init
Definition: spm_func.h:126
void tfm_spm_partition_store_context(uint32_t partition_idx, uint32_t stack_ptr, uint32_t lr)
Save stack pointer and link register for partition in database.
Definition: spm_func.c:1282
struct spm_partition_desc_t * partitions
Definition: spm_func.h:129
uint32_t tfm_spm_partition_get_running_partition_idx(void)
Returns the index of the partition that has running state.
Definition: spm_func.c:1357
Holds the iovec parameters that are passed to a service.
Definition: spm_func.h:58
uint32_t tfm_spm_depriv_return_handler(uint32_t *irq_svc_args, uint32_t lr)
Handle request to return to privileged.
Definition: spm_func.c:976
psa_invec in_vec[PSA_MAX_IOVEC]
Definition: spm_func.h:59
void tfm_spm_partition_push_interrupted_ctx(uint32_t partition_idx)
Save interrupted partition context on ctx stack.
Definition: spm_func.c:1220
uint32_t caller_partition_idx
Definition: spm_func.h:79