TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
spm_func.c File Reference
#include <stdint.h>
#include <stdbool.h>
#include <arm_cmse.h>
#include "tfm_nspm.h"
#include "tfm_api.h"
#include "tfm_arch.h"
#include "tfm_irq_list.h"
#include "psa/service.h"
#include "tfm_core_mem_check.h"
#include "tfm_peripherals_def.h"
#include "tfm_secure_api.h"
#include "tfm_spm_hal.h"
#include "tfm_core_trustzone.h"
#include "spm_func.h"
#include "region_defs.h"
#include "region.h"
#include "spm_partition_defs.h"
#include "psa_manifest/pid.h"
#include "tfm/tfm_spm_services.h"
#include "tfm_spm_db_func.inc"
Include dependency graph for spm_func.c:

Go to the source code of this file.

Macros

#define EXC_RETURN_SECURE_FUNCTION   0xFFFFFFFD
 
#define EXC_RETURN_SECURE_HANDLER   0xFFFFFFF1
 

Functions

 REGION_DECLARE_T (Image $$, TFM_SECURE_STACK,$$ZI $$Base, uint32_t)
 
 REGION_DECLARE_T (Image $$, TFM_SECURE_STACK,$$ZI $$Limit, struct iovec_args_t)[]
 
 REGION_DECLARE_T (Image $$, ARM_LIB_STACK_SEAL,$$ZI $$Base, uint32_t)
 
void tfm_spm_seal_psp_stacks (void)
 Function to seal the PSP stacks for Function mode. More...
 
uint32_t tfm_spm_partition_get_partition_id (uint32_t partition_idx)
 Get the id of the partition for its index from the db. More...
 
uint32_t tfm_spm_partition_get_privileged_mode (uint32_t partition_flags)
 Get the current partition mode. More...
 
bool tfm_is_partition_privileged (uint32_t partition_idx)
 Return whether a secure partition is privileged. More...
 
void tfm_spm_secure_api_init_done (void)
 Signal that secure partition initialisation is finished. More...
 
enum tfm_status_e tfm_spm_sfn_request_handler (struct tfm_sfn_req_s *desc_ptr, uint32_t excReturn)
 
int32_t tfm_spm_sfn_request_thread_mode (struct tfm_sfn_req_s *desc_ptr)
 
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. More...
 
void tfm_spm_get_caller_client_id_handler (uint32_t *svc_args)
 Stores caller's client id in state context. More...
 
uint32_t tfm_spm_partition_request_svc_handler (const uint32_t *svc_ctx, uint32_t excReturn)
 Called if veneer is running in thread mode. More...
 
uint32_t tfm_spm_depriv_req_handler (uint32_t *svc_args, uint32_t excReturn)
 Handle deprivileged request. More...
 
uint32_t tfm_spm_partition_return_handler (uint32_t lr)
 Called when secure service returns. More...
 
uint32_t tfm_spm_depriv_return_handler (uint32_t *irq_svc_args, uint32_t lr)
 Handle request to return to privileged. More...
 
void tfm_spm_enable_irq_handler (uint32_t *svc_args)
 Handle IRQ enable request. More...
 
void tfm_spm_disable_irq_handler (uint32_t *svc_args)
 Handle IRQ disable request. More...
 
void tfm_spm_psa_wait (uint32_t *svc_args)
 Handle signal wait request. More...
 
void tfm_spm_psa_eoi (uint32_t *svc_args)
 Handle request to record IRQ processed. More...
 
enum spm_err_t tfm_spm_partition_init (void)
 Execute partition init function. More...
 
void tfm_spm_partition_push_interrupted_ctx (uint32_t partition_idx)
 Save interrupted partition context on ctx stack. More...
 
void tfm_spm_partition_pop_interrupted_ctx (uint32_t partition_idx)
 Restores interrupted partition context on ctx stack. More...
 
void tfm_spm_partition_push_handler_ctx (uint32_t partition_idx)
 Save handler partition context on ctx stack. More...
 
void tfm_spm_partition_pop_handler_ctx (uint32_t partition_idx)
 Restores handler partition context on ctx stack. More...
 
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. More...
 
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. More...
 
void tfm_spm_partition_set_state (uint32_t partition_idx, uint32_t state)
 Set the current state of a partition. More...
 
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. More...
 
void tfm_spm_partition_set_signal_mask (uint32_t partition_idx, uint32_t signal_mask)
 Set the signal mask for a given partition. More...
 
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. More...
 
enum spm_err_t tfm_spm_partition_set_iovec (uint32_t partition_idx, const int32_t *args)
 Set the iovec parameters for the partition. More...
 
uint32_t tfm_spm_partition_get_running_partition_idx (void)
 Returns the index of the partition that has running state. More...
 
void tfm_spm_partition_cleanup_context (uint32_t partition_idx)
 Clears the context info from the database for a partition. More...
 
void tfm_spm_request_handler (const struct tfm_state_context_t *svc_ctx)
 Handle an SPM request by a secure service. More...
 
enum spm_err_t tfm_spm_db_init (void)
 Initialize partition database. More...
 

Macro Definition Documentation

#define EXC_RETURN_SECURE_FUNCTION   0xFFFFFFFD

Definition at line 29 of file spm_func.c.

#define EXC_RETURN_SECURE_HANDLER   0xFFFFFFF1

Definition at line 30 of file spm_func.c.

Function Documentation

REGION_DECLARE_T ( Image  $$,
TFM_SECURE_STACK  ,
  $$ZI,
uint32_t   
)
REGION_DECLARE_T ( Image  $$,
TFM_SECURE_STACK  ,
  $$ZI,
struct iovec_args_t   
)
REGION_DECLARE_T ( Image  $$,
ARM_LIB_STACK_SEAL  ,
  $$ZI,
uint32_t   
)
bool tfm_is_partition_privileged ( uint32_t  partition_idx)

Return whether a secure partition is privileged.

Parameters
[in]partition_idxThe index of the partition in the partition_db.
Returns
True if the partition is privileged, false otherwise.

Definition at line 722 of file spm_func.c.

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.

This function checks whether the caller partition owns the buffer, can write to it, and the buffer has proper alignment.

Parameters
[in]partition_idxPartition index
[in]start_addrThe start address of the buffer
[in]lenThe length of the buffer
[in]alignmentThe expected alignment (in bits)
Returns
1 if the check passes, 0 otherwise.
Note
For a 0 long buffer the check fails.

Definition at line 818 of file spm_func.c.

Here is the caller graph for this function:

enum spm_err_t tfm_spm_db_init ( void  )

Initialize partition database.

Returns
Error code spm_err_t

Definition at line 1415 of file spm_func.c.

uint32_t tfm_spm_depriv_req_handler ( uint32_t *  svc_args,
uint32_t  excReturn 
)

Handle deprivileged request.

Definition at line 921 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t tfm_spm_depriv_return_handler ( uint32_t *  irq_svc_args,
uint32_t  lr 
)

Handle request to return to privileged.

Definition at line 976 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void tfm_spm_disable_irq_handler ( uint32_t *  svc_args)

Handle IRQ disable request.

Definition at line 1060 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void tfm_spm_enable_irq_handler ( uint32_t *  svc_args)

Handle IRQ enable request.

Definition at line 1033 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void tfm_spm_get_caller_client_id_handler ( uint32_t *  svc_args)

Stores caller's client id in state context.

Definition at line 851 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void tfm_spm_partition_cleanup_context ( uint32_t  partition_idx)

Clears the context info from the database for a partition.

Parameters
[in]partition_idxPartition index
Note
This function doesn't check if partition_idx is valid.

Definition at line 1362 of file spm_func.c.

uint32_t tfm_spm_partition_get_partition_id ( uint32_t  partition_idx)

Get the id of the partition for its index from the db.

Parameters
[in]partition_idxPartition index
Returns
Partition ID for that partition
Note
This function doesn't check if partition_idx is valid.

Definition at line 707 of file spm_func.c.

Here is the caller graph for this function:

uint32_t tfm_spm_partition_get_privileged_mode ( uint32_t  partition_flags)

Get the current partition mode.

Parameters
[in]partition_flagsFlags of current partition
Return values
TFM_PARTITION_PRIVILEGED_MODEPrivileged mode
TFM_PARTITION_UNPRIVILEGED_MODEUnprivileged mode

Definition at line 713 of file spm_func.c.

Here is the caller graph for this function:

uint32_t tfm_spm_partition_get_running_partition_idx ( void  )

Returns the index of the partition that has running state.

Returns
The index of the partition with the running state, if there is any set. 0 otherwise.

Definition at line 1357 of file spm_func.c.

Here is the caller graph for this function:

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.

Parameters
[in]partition_idxPartition index
Returns
The runtime data of the specified partition
Note
This function doesn't check if partition_idx is valid.

Definition at line 1292 of file spm_func.c.

Here is the caller graph for this function:

enum spm_err_t tfm_spm_partition_init ( void  )

Execute partition init function.

Returns
Error code spm_err_t

Definition at line 1168 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void tfm_spm_partition_pop_handler_ctx ( uint32_t  partition_idx)

Restores handler partition context on ctx stack.

Parameters
[in]partition_idxPartition index
Note
This function doesn't check if partition_idx is valid.
This function doesn't whether the ctx stack underflows.

Definition at line 1263 of file spm_func.c.

Here is the call graph for this function:

void tfm_spm_partition_pop_interrupted_ctx ( uint32_t  partition_idx)

Restores interrupted partition context on ctx stack.

Parameters
[in]partition_idxPartition index
Note
This function doesn't check if partition_idx is valid.
This function doesn't whether the ctx stack underflows.

Definition at line 1233 of file spm_func.c.

Here is the call graph for this function:

void tfm_spm_partition_push_handler_ctx ( uint32_t  partition_idx)

Save handler partition context on ctx stack.

Parameters
[in]partition_idxPartition index
Note
This function doesn't check if partition_idx is valid.
This function doesn't whether the ctx stack overflows.

Definition at line 1248 of file spm_func.c.

void tfm_spm_partition_push_interrupted_ctx ( uint32_t  partition_idx)

Save interrupted partition context on ctx stack.

Parameters
[in]partition_idxPartition index
Note
This function doesn't check if partition_idx is valid.
This function doesn't whether the ctx stack overflows.

Definition at line 1220 of file spm_func.c.

uint32_t tfm_spm_partition_request_svc_handler ( const uint32_t *  svc_ctx,
uint32_t  excReturn 
)

Called if veneer is running in thread mode.

Definition at line 894 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t tfm_spm_partition_return_handler ( uint32_t  lr)

Called when secure service returns.

Definition at line 949 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]partition_idxPartition index
[in]caller_client_idThe ID of the calling client
Note
This function doesn't check if any of the partition_idxs are valid.

Definition at line 1321 of file spm_func.c.

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.

Parameters
[in]partition_idxPartition index
[in]caller_partition_idxThe index of the caller partition
Note
This function doesn't check if any of the partition_idxs are valid.

Definition at line 1307 of file spm_func.c.

Here is the caller graph for this function:

enum spm_err_t tfm_spm_partition_set_iovec ( uint32_t  partition_idx,
const int32_t *  args 
)

Set the iovec parameters for the partition.

Parameters
[in]partition_idxPartition index
[in]argsThe arguments of the secure function

args is expected to be of type int32_t[4] where: args[0] is in_vec args[1] is in_len args[2] is out_vec args[3] is out_len

Returns
Error code spm_err_t
Note
This function doesn't check if partition_idx is valid.
This function assumes that the iovecs that are passed in args are valid, and does no sanity check on them at all.

Definition at line 1328 of file spm_func.c.

void tfm_spm_partition_set_signal_mask ( uint32_t  partition_idx,
uint32_t  signal_mask 
)

Set the signal mask for a given partition.

Parameters
[in]partition_idxPartition index
[in]signal_maskThe signal mask to be set for the partition
Note
This function doesn't check if any of the partition_idxs are valid.

Definition at line 1314 of file spm_func.c.

Here is the caller graph for this function:

void tfm_spm_partition_set_state ( uint32_t  partition_idx,
uint32_t  state 
)

Set the current state of a partition.

Parameters
[in]partition_idxPartition index
[in]stateThe state to be set
Note
This function doesn't check if partition_idx is valid.
The state has to have the value set of spm_part_state_t.

Definition at line 1297 of file spm_func.c.

Here is the caller graph for this function:

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.

Parameters
[in]partition_idxPartition index
[in]stack_ptrStack pointer to be stored
[in]lrLink register to be stored
Note
This function doesn't check if partition_idx is valid.

Definition at line 1282 of file spm_func.c.

void tfm_spm_psa_eoi ( uint32_t *  svc_args)

Handle request to record IRQ processed.

SVC handler for psa_eoi.

Definition at line 1118 of file spm_func.c.

void tfm_spm_psa_wait ( uint32_t *  svc_args)

Handle signal wait request.

SVC handler for psa_wait.

Definition at line 1087 of file spm_func.c.

void tfm_spm_request_handler ( const struct tfm_state_context_t svc_ctx)

Handle an SPM request by a secure service.

Parameters
[in]svc_ctxThe stacked SVC context

Definition at line 1382 of file spm_func.c.

void tfm_spm_seal_psp_stacks ( void  )

Function to seal the PSP stacks for Function mode.

Definition at line 51 of file spm_func.c.

Here is the caller graph for this function:

void tfm_spm_secure_api_init_done ( void  )

Signal that secure partition initialisation is finished.

Definition at line 730 of file spm_func.c.

Here is the caller graph for this function:

enum tfm_status_e tfm_spm_sfn_request_handler ( struct tfm_sfn_req_s desc_ptr,
uint32_t  excReturn 
)

Definition at line 735 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t tfm_spm_sfn_request_thread_mode ( struct tfm_sfn_req_s desc_ptr)

Definition at line 780 of file spm_func.c.

Here is the call graph for this function:

Here is the caller graph for this function: