![]() |
TF-M Reference Manual
1.2.0
TrustedFirmware-M
|
#include <stdint.h>
#include "spm_partition_defs.h"
#include "tfm_arch.h"
#include "tfm_list.h"
#include "tfm_wait.h"
#include "tfm_secure_api.h"
#include "tfm_thread.h"
#include "psa/service.h"
Go to the source code of this file.
Data Structures | |
struct | tfm_msg_body_t |
struct | partition_static_t |
struct | partition_t |
struct | spm_partition_db_t |
struct | tfm_spm_service_db_t |
struct | tfm_spm_service_t |
struct | tfm_conn_handle_t |
Macros | |
#define | TFM_VERSION_POLICY_RELAXED 0 |
#define | TFM_VERSION_POLICY_STRICT 1 |
#define | TFM_HANDLE_STATUS_IDLE 0 |
#define | TFM_HANDLE_STATUS_ACTIVE 1 |
#define | TFM_HANDLE_STATUS_CONNECT_ERROR 2 |
#define | PART_REGION_ADDR(partition, region) (uint32_t)®ION_NAME(Image$$, partition, region) |
#define | TFM_CONN_HANDLE_MAX_NUM 16 |
#define | SPM_INVALID_PARTITION_IDX (~0U) |
#define | TFM_PARTITION_UNPRIVILEGED_MODE 0 |
#define | TFM_PARTITION_PRIVILEGED_MODE 1 |
#define | SPM_PART_FLAG_APP_ROT 0x01 |
#define | SPM_PART_FLAG_PSA_ROT 0x02 |
#define | SPM_PART_FLAG_IPC 0x04 |
#define | TFM_PRIORITY_HIGH THRD_PRIOR_HIGHEST |
#define | TFM_PRIORITY_NORMAL THRD_PRIOR_MEDIUM |
#define | TFM_PRIORITY_LOW THRD_PRIOR_LOWEST |
#define | TFM_PRIORITY(LEVEL) TFM_PRIORITY_##LEVEL |
#define | TFM_MSG_MAGIC 0x15154343 |
Functions | |
enum spm_err_t | tfm_spm_db_init (void) |
Initialize partition database. More... | |
uint32_t | tfm_spm_partition_get_privileged_mode (uint32_t partition_flags) |
Get the current partition mode. More... | |
void | tfm_spm_request_handler (const struct tfm_state_context_t *svc_ctx) |
Handle an SPM request by a secure service. More... | |
uint32_t | tfm_spm_partition_get_running_partition_id (void) |
Get the running partition ID. More... | |
struct tfm_conn_handle_t * | tfm_spm_create_conn_handle (struct tfm_spm_service_t *service, int32_t client_id) |
Create connection handle for client connect. More... | |
int32_t | tfm_spm_validate_conn_handle (const struct tfm_conn_handle_t *conn_handle, int32_t client_id) |
Validate connection handle for client connect. More... | |
int32_t | tfm_spm_free_conn_handle (struct tfm_spm_service_t *service, struct tfm_conn_handle_t *conn_handle) |
Free connection handle which not used anymore. More... | |
struct tfm_msg_body_t * | tfm_spm_get_msg_by_signal (struct partition_t *partition, psa_signal_t signal) |
Get the msg context by signal. More... | |
struct partition_t * | tfm_spm_get_running_partition (void) |
Get current running partition context. More... | |
struct tfm_spm_service_t * | tfm_spm_get_service_by_sid (uint32_t sid) |
Get the service context by service ID. More... | |
struct tfm_msg_body_t * | tfm_spm_get_msg_from_handle (psa_handle_t msg_handle) |
Get message context by message handle. More... | |
struct tfm_msg_body_t * | tfm_spm_get_msg_buffer_from_conn_handle (struct tfm_conn_handle_t *conn_handle) |
Get message context by connect handle. More... | |
void | tfm_spm_fill_msg (struct tfm_msg_body_t *msg, struct tfm_spm_service_t *service, psa_handle_t handle, int32_t type, int32_t client_id, psa_invec *invec, size_t in_len, psa_outvec *outvec, size_t out_len, psa_outvec *caller_outvec) |
Fill the message for PSA client call. More... | |
int32_t | tfm_spm_send_event (struct tfm_spm_service_t *service, struct tfm_msg_body_t *msg) |
Send message and wake up the SP who is waiting on message queue, block the current thread and scheduler triggered. More... | |
int32_t | tfm_spm_check_client_version (struct tfm_spm_service_t *service, uint32_t version) |
Check the client version according to version policy. More... | |
int32_t | tfm_spm_check_authorization (uint32_t sid, struct tfm_spm_service_t *service, bool ns_caller) |
Check the client access authorization. More... | |
int32_t | tfm_memory_check (const void *buffer, size_t len, bool ns_caller, enum tfm_memory_access_e access, uint32_t privileged) |
Check the memory reference is valid. More... | |
void | tfm_pendsv_do_schedule (struct tfm_arch_ctx_t *p_actx) |
uint32_t | tfm_spm_init (void) |
SPM initialization implementation. More... | |
void | tfm_spm_enable_irq (uint32_t *args) |
SVC handler of enabling irq_line of the specified irq_signal. More... | |
void | tfm_spm_disable_irq (uint32_t *args) |
SVC handler of disabling irq_line of the specified irq_signal. More... | |
void | tfm_spm_validate_caller (struct partition_t *p_cur_sp, uint32_t *p_ctx, uint32_t exc_return, bool ns_caller) |
Validate the whether NS caller re-enter. More... | |
psa_handle_t | tfm_spm_to_user_handle (struct tfm_conn_handle_t *handle_instance) |
Converts a handle instance into a corresponded user handle. More... | |
struct tfm_conn_handle_t * | tfm_spm_to_handle_instance (psa_handle_t user_handle) |
Converts a user handle into a corresponded handle instance. More... | |
void | tfm_core_handler_mode (void) |
Move to handler mode by a SVC for specific purpose. More... | |
int32_t | tfm_spm_set_rhandle (struct tfm_spm_service_t *service, struct tfm_conn_handle_t *conn_handle, void *rhandle) |
Set reverse handle value for connection. More... | |
void | update_caller_outvec_len (struct tfm_msg_body_t *msg) |
void | notify_with_signal (int32_t partition_id, psa_signal_t signal) |
notify the partition with the signal. More... | |
int32_t | get_irq_line_for_signal (int32_t partition_id, psa_signal_t signal, IRQn_Type *irq_line) |
Return the IRQ line number associated with a signal. More... | |
#define PART_REGION_ADDR | ( | partition, | |
region | |||
) | (uint32_t)®ION_NAME(Image$$, partition, region) |
#define TFM_PRIORITY_HIGH THRD_PRIOR_HIGHEST |
#define TFM_PRIORITY_LOW THRD_PRIOR_LOWEST |
#define TFM_PRIORITY_NORMAL THRD_PRIOR_MEDIUM |
enum spm_err_t |
enum tfm_memory_access_e |
int32_t get_irq_line_for_signal | ( | int32_t | partition_id, |
psa_signal_t | signal, | ||
IRQn_Type * | irq_line | ||
) |
Return the IRQ line number associated with a signal.
[in] | partition_id | The ID of the partition in which we look for the signal. |
[in] | signal | The signal we do the query for. |
[out] | irq_line | The irq line associated with signal |
IPC_SUCCESS | Execution successful, irq_line contains a valid value. |
IPC_ERROR_GENERIC | There was an error finding the IRQ line for the signal. irq_line is unchanged. |
Definition at line 881 of file spm_ipc.c.
void notify_with_signal | ( | int32_t | partition_id, |
psa_signal_t | signal | ||
) |
notify the partition with the signal.
[in] | partition_id | The ID of the partition to be notified. |
[in] | signal | The signal that the partition is to be notified with. |
void | Success. |
Does not return | If partition_id is invalid. |
Definition at line 831 of file spm_ipc.c.
void tfm_core_handler_mode | ( | void | ) |
Move to handler mode by a SVC for specific purpose.
Definition at line 157 of file tfm_core_svcalls_ipc.c.
int32_t tfm_memory_check | ( | const void * | buffer, |
size_t | len, | ||
bool | ns_caller, | ||
enum tfm_memory_access_e | access, | ||
uint32_t | privileged | ||
) |
Check the memory reference is valid.
[in] | buffer | Pointer of memory reference |
[in] | len | Length of memory reference in bytes |
[in] | ns_caller | From non-secure caller |
[in] | access | Type of access specified by the tfm_memory_access_e |
[in] | privileged | Privileged mode or unprivileged mode: TFM_PARTITION_UNPRIVILEGED_MODE TFM_PARTITION_PRIVILEGED_MODE |
IPC_SUCCESS | Success |
IPC_ERROR_BAD_PARAMETERS | Bad parameters input |
IPC_ERROR_MEMORY_CHECK | Check failed |
Definition at line 596 of file spm_ipc.c.
void tfm_pendsv_do_schedule | ( | struct tfm_arch_ctx_t * | p_actx | ) |
int32_t tfm_spm_check_authorization | ( | uint32_t | sid, |
struct tfm_spm_service_t * | service, | ||
bool | ns_caller | ||
) |
Check the client access authorization.
[in] | sid | Target RoT Service identity |
[in] | service | Target service context pointer, which can be get by partition management functions |
[in] | ns_caller | Whether from NS caller |
IPC_SUCCESS | Success |
IPC_ERROR_GENERIC | Authorization check failed |
Definition at line 416 of file spm_ipc.c.
int32_t tfm_spm_check_client_version | ( | struct tfm_spm_service_t * | service, |
uint32_t | version | ||
) |
Check the client version according to version policy.
[in] | service | Target service context pointer, which can be get by partition management functions |
[in] | version | Client support version |
IPC_SUCCESS | Success |
IPC_ERROR_BAD_PARAMETERS | Bad parameters input |
IPC_ERROR_VERSION | Check failed |
Definition at line 394 of file spm_ipc.c.
struct tfm_conn_handle_t* tfm_spm_create_conn_handle | ( | struct tfm_spm_service_t * | service, |
int32_t | client_id | ||
) |
Create connection handle for client connect.
[in] | service | Target service context pointer |
[in] | client_id | Partition ID of the sender of the message |
NULL | Create failed |
Not NULL | Service handle created |
Definition at line 137 of file spm_ipc.c.
enum spm_err_t tfm_spm_db_init | ( | void | ) |
Initialize partition database.
Definition at line 1415 of file spm_func.c.
void tfm_spm_disable_irq | ( | uint32_t * | args | ) |
SVC handler of disabling irq_line of the specified irq_signal.
[in] | args | Include all input arguments: irq_signal. |
void | Success. |
Does not return | The call is invalid, one or more of the following are true:
|
Definition at line 925 of file spm_ipc.c.
void tfm_spm_enable_irq | ( | uint32_t * | args | ) |
SVC handler of enabling irq_line of the specified irq_signal.
[in] | args | Include all input arguments: irq_signal. |
void | Success. |
Does not return | The call is invalid, one or more of the following are true:
|
Definition at line 897 of file spm_ipc.c.
void tfm_spm_fill_msg | ( | struct tfm_msg_body_t * | msg, |
struct tfm_spm_service_t * | service, | ||
psa_handle_t | handle, | ||
int32_t | type, | ||
int32_t | client_id, | ||
psa_invec * | invec, | ||
size_t | in_len, | ||
psa_outvec * | outvec, | ||
size_t | out_len, | ||
psa_outvec * | caller_outvec | ||
) |
Fill the message for PSA client call.
[in] | msg | Service Message Queue buffer pointer |
[in] | service | Target service context pointer, which can be obtained by partition management functions |
[in] | handle | Connect handle return by psa_connect(). |
[in] | type | Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or PSA_IPC_DISCONNECT |
[in] | client_id | Partition ID of the sender of the message |
[in] | invec | Array of input psa_invec structures |
[in] | in_len | Number of input psa_invec structures |
[in] | outvec | Array of output psa_outvec structures |
[in] | out_len | Number of output psa_outvec structures |
[in] | caller_outvec | Array of caller output psa_outvec structures |
Definition at line 498 of file spm_ipc.c.
int32_t tfm_spm_free_conn_handle | ( | struct tfm_spm_service_t * | service, |
struct tfm_conn_handle_t * | conn_handle | ||
) |
Free connection handle which not used anymore.
[in] | service | Target service context pointer |
[in] | conn_handle | Connection handle created by tfm_spm_create_conn_handle() |
IPC_SUCCESS | Success |
IPC_ERROR_BAD_PARAMETERS | Bad parameters input |
Does not return | Panic for not find service by handle |
Definition at line 179 of file spm_ipc.c.
struct tfm_msg_body_t* tfm_spm_get_msg_buffer_from_conn_handle | ( | struct tfm_conn_handle_t * | conn_handle | ) |
Get message context by connect handle.
[in] | conn_handle | Service connect handle. |
Definition at line 491 of file spm_ipc.c.
struct tfm_msg_body_t* tfm_spm_get_msg_by_signal | ( | struct partition_t * | partition, |
psa_signal_t | signal | ||
) |
Get the msg context by signal.
[in] | partition | Partition context pointer partition_t structures |
[in] | signal | Signal associated with inputs to the Secure Partition, psa_signal_t |
NULL | Failed |
Not NULL | Target service context pointer, tfm_msg_body_t structures |
Definition at line 233 of file spm_ipc.c.
struct tfm_msg_body_t* tfm_spm_get_msg_from_handle | ( | psa_handle_t | msg_handle | ) |
Get message context by message handle.
[in] | msg_handle | Message handle which is a reference generated by the SPM to a specific message. |
Definition at line 450 of file spm_ipc.c.
struct partition_t* tfm_spm_get_running_partition | ( | void | ) |
Get current running partition context.
NULL | Failed |
Not NULL | Return the parttion context pointer partition_t structures |
Definition at line 384 of file spm_ipc.c.
struct tfm_spm_service_t* tfm_spm_get_service_by_sid | ( | uint32_t | sid | ) |
Get the service context by service ID.
[in] | sid | RoT Service identity |
NULL | Failed |
Not NULL | Target service context pointer, tfm_spm_service_t structures |
Definition at line 351 of file spm_ipc.c.
uint32_t tfm_spm_init | ( | void | ) |
SPM initialization implementation.
This function must be called under handler mode.
This | function returns an EXC_RETURN value. Other faults would panic the execution and never returned. |
Definition at line 641 of file spm_ipc.c.
uint32_t tfm_spm_partition_get_privileged_mode | ( | uint32_t | partition_flags | ) |
Get the current partition mode.
[in] | partition_flags | Flags of current partition |
TFM_PARTITION_PRIVILEGED_MODE | Privileged mode |
TFM_PARTITION_UNPRIVILEGED_MODE | Unprivileged mode |
Definition at line 713 of file spm_func.c.
uint32_t tfm_spm_partition_get_running_partition_id | ( | void | ) |
void tfm_spm_request_handler | ( | const struct tfm_state_context_t * | svc_ctx | ) |
Handle an SPM request by a secure service.
[in] | svc_ctx | The stacked SVC context |
Definition at line 1382 of file spm_func.c.
int32_t tfm_spm_send_event | ( | struct tfm_spm_service_t * | service, |
struct tfm_msg_body_t * | msg | ||
) |
Send message and wake up the SP who is waiting on message queue, block the current thread and scheduler triggered.
[in] | service | Target service context pointer, which can be obtained by partition management functions |
[in] | msg | message created by tfm_spm_create_msg() tfm_msg_body_t structures |
IPC_SUCCESS | Success |
IPC_ERROR_BAD_PARAMETERS | Bad parameters input |
IPC_ERROR_GENERIC | Failed to enqueue message to service message queue |
Definition at line 556 of file spm_ipc.c.
int32_t tfm_spm_set_rhandle | ( | struct tfm_spm_service_t * | service, |
struct tfm_conn_handle_t * | conn_handle, | ||
void * | rhandle | ||
) |
Set reverse handle value for connection.
[in] | service | Target service context pointer |
[in] | conn_handle | Connection handle created by tfm_spm_create_conn_handle() |
[in] | rhandle | rhandle need to save |
IPC_SUCCESS | Success |
IPC_ERROR_BAD_PARAMETERS | Bad parameters input |
Does not return | Panic for not find handle node |
Definition at line 196 of file spm_ipc.c.
struct tfm_conn_handle_t* tfm_spm_to_handle_instance | ( | psa_handle_t | user_handle | ) |
psa_handle_t tfm_spm_to_user_handle | ( | struct tfm_conn_handle_t * | handle_instance | ) |
void tfm_spm_validate_caller | ( | struct partition_t * | p_cur_sp, |
uint32_t * | p_ctx, | ||
uint32_t | exc_return, | ||
bool | ns_caller | ||
) |
Validate the whether NS caller re-enter.
[in] | p_cur_sp | Pointer to current partition. |
[in] | p_ctx | Pointer to current stack context. |
[in] | exc_return | EXC_RETURN value. |
[in] | ns_caller | If 'true', call from non-secure client. Or from secure client. |
void | Success. |
Definition at line 953 of file spm_ipc.c.
int32_t tfm_spm_validate_conn_handle | ( | const struct tfm_conn_handle_t * | conn_handle, |
int32_t | client_id | ||
) |
Validate connection handle for client connect.
[in] | conn_handle | Handle to be validated |
[in] | client_id | Partition ID of the sender of the message |
IPC_SUCCESS | Success |
IPC_ERROR_GENERIC | Invalid handle |
Definition at line 161 of file spm_ipc.c.
void update_caller_outvec_len | ( | struct tfm_msg_body_t * | msg | ) |