This library provides support for sending requests from an alternative core to the core with the secure paritition.
The non-secure partition acts as a relay to unpack the request sent over Infineon's interprocessor communication library (MTB-IPC) and submit it in the same way as other non-secure requests. The library also provides functionality to signal completion so the requesting core can view the results. This is accomplished through two roles: Client and Relay. The Client owns a pool of requests that are tied to IPC semaphores that will signal completion. The relay receives unpacks requests on the core containing the secure region before processing and signalling. This requires each of the contexts to be set up to create the relay relationship and begin submitting requests. Refer to SRF documentation Secure Request Framework for more information on secure requests and request pools. The APIs for submiting a request remain the same on all cores, but a client context must be set up on the core that needs IPC in order for the request to be sent correctly.
Refer to Code Snippets for more information.
Prerequisites
The IPC components of the SRF IPC integration must be set up prior to transfer. Please refer to MTB-IPC documentation on how to setup an IPC instance and a mailbox for request transfer. The MTB SRF IPC will by default consume MTB_SRF_IPC_SEMA_COUNT + 3 semaphores for its own use.
Request pool data memory allocation
Request pool data memory allocation can be done with help of MTB_SRF_IPC_REQUEST_DATA_ALLOC macro, but using it is not mandatory, so user can allocate memory for the shared memory in any convenient for them way. This struct is necessary to store and keep track of all shared objects during operation.
Custom Packet
Many APIs can be overridden with macros to allow custom implementations. To support this, the mtb_srf_ipc_packet_t type can be overriden via the define MTB_SRF_IPC_CUSTOM_PACKET_TYPE. However, the various APIs have minimum requirements on what this type defines.
mtb_srf_ipc_request_submit, overridden via MTB_SRF_CUSTOM_IPC_REQUEST_SUBMIT, requires all the default packet struct members to operate.
mtb_srf_ipc_process_request, overridden via MTB_SRF_CUSTOM_PROCESS_REQUEST, requires the ioVec pointers and counts (inVec_ptr, inVec_cnt_ns, outVec_ptr, outVec_cnt_ns).
mtb_srf_ipc_signal_complete, which cannot be overriden, requires the semaphore_idx member.
All other APIs interact with the packet type as a pointer and aren't affected by the contents.
Code Snippets
Register a Client and transfer request
uint32_t IPC_SEMAPHORE_INDEXES[] = { 1UL, 2UL, 3UL, 4UL, 5UL, 6UL };
#define IPC_NUM_REQ_IN_POOL (6UL)
mtb_srf_ipc_client_context_t example_srf_client_context;
cy_rslt_t snippet_mtb_srf_ipc_client(void)
{
mtb_ipc_mbox_sender_t sender;
mtb_srf_ipc_pool_t ipc_pool;
mtb_ipc_semaphore_t ipc_semaphores[IPC_NUM_REQ_IN_POOL];
client_cfg.
pool = &ipc_pool;
if (result != CY_RSLT_SUCCESS)
{
return result;
}
output->
len = 1UL *
sizeof(uint32_t);
uint8_t inVec_cnt = 1;
uint8_t outVec_cnt = 1;
outVec_cnt);
return result;
}
cy_rslt_t mtb_srf_setup_client_context(mtb_srf_ipc_client_context_t *client_context, mtb_srf_ipc_client_context_cfg_t *cfg)
Initializes an secure request pool instance.
cy_rslt_t mtb_srf_ipc_pool_init(mtb_srf_ipc_pool_t *pool, mtb_srf_ipc_pool_cfg_t *cfg)
Initializes an secure request pool instance.
mtb_srf_ipc_packet_t * request_pool
Pointer to a section of memory allocated by the caller for the request pool.
Definition: mtb_srf_ipc_init.h:186
mtb_ipc_semaphore_t * request_semaphores
Pointer to array of initialized IPC semaphore handles.
Definition: mtb_srf_ipc_init.h:191
uint32_t num_semaphores
Numnber of semaphore.
Definition: mtb_srf_ipc_init.h:193
mtb_srf_ipc_pool_t * pool
Pool of memory and semaphores used to allocate for requests from a client process through the relay p...
Definition: mtb_srf_ipc_init.h:203
uint32_t num_requests
Numnber of requests.
Definition: mtb_srf_ipc_init.h:188
mtb_ipc_mbox_sender_t * mailbox_handle
Pointer to the mailbox used to sed/receive data over IPC.
Definition: mtb_srf_ipc_init.h:205
A Client context config used to configure a client context.
Definition: mtb_srf_ipc_init.h:200
Default request structure for use in IPC-enabled SRF This couples normal SRF data with an IPC semapho...
Definition: mtb_srf_ipc.h:129
IPC Pool config, used to setup an SRF IPC pool.
Definition: mtb_srf_ipc_init.h:182
cy_rslt_t mtb_srf_pool_allocate(mtb_srf_pool_t *pool, mtb_srf_invec_ns_t **inVec, mtb_srf_outvec_ns_t **outVec, uint32_t timeout_us)
Allocate secure request object within an secure request pool.
Definition: mtb_srf_pool.c:104
size_t len
Size of the input_values array.
Definition: mtb_srf_iovec.h:91
uint32_t sub_block
Sub-block index for this operation.
Definition: mtb_srf_iovec.h:57
size_t len
Size of the output_values array.
Definition: mtb_srf_iovec.h:106
void * base
Register base address for the operation.
Definition: mtb_srf_iovec.h:56
mtb_srf_request_ns_t request
Request information.
Definition: mtb_srf_iovec.h:90
uint8_t module_id
ID of the module containing the requested operation.
Definition: mtb_srf_iovec.h:50
uint8_t submodule_id
ID of the submodule containing within the module.
Definition: mtb_srf_iovec.h:52
uint8_t op_id
ID of the requested operation within the submodule.
Definition: mtb_srf_iovec.h:54
An input vector - a section of memory to be used along with the length.
Definition: mtb_srf_iovec.h:72
An input structure.
Definition: mtb_srf_iovec.h:104
An output vector - a section of memory to be used along with the length.
Definition: mtb_srf_iovec.h:79
#define _MTB_SRF_DATA_ALIGN
This define can be used for aligning address of the data structures with enabled Data Cache.
Definition: mtb_srf.h:130
cy_rslt_t mtb_srf_request_submit(mtb_srf_invec_ns_t *inVec_ns, uint8_t inVec_cnt_ns, mtb_srf_outvec_ns_t *outVec_ns, uint8_t outVec_cnt_ns)
Submit a request from the non-secure side to the secure.
Register a Relay
#define IPC_NUM_REQ_IN_POOL (6UL)
cy_rslt_t snippet_mtb_srf_ipc_relay_setup(void)
{
mtb_ipc_mbox_receiver_t receiver;
mtb_srf_ipc_relay_context_t relay;
mtb_ipc_semaphore_t ipc_semaphores[IPC_NUM_REQ_IN_POOL];
cy_rslt_t result = mtb_srf_setup_relay_context(&relay, &cfg);
return result;
}
mtb_ipc_semaphore_t * request_semaphores
Pointer to array of initialized IPC semaphore handles.
Definition: mtb_srf_ipc_init.h:219
uint32_t num_requests
Number of entries in the pool on the client core.
Definition: mtb_srf_ipc_init.h:221
uint32_t num_semaphores
Number of semaphores.
Definition: mtb_srf_ipc_init.h:216
mtb_ipc_mbox_receiver_t * mailbox
Mailbox object for receiving secure requests over IPC.
Definition: mtb_srf_ipc_init.h:214
Config to setup a relay context.
Definition: mtb_srf_ipc_init.h:212
Start Relay (Non-RTOS)
mtb_srf_ipc_relay_context_t cb_relay;
void ipc_callback(void* callback_arg, mtb_ipc_mbox_event_t event)
{
CY_UNUSED_PARAMETER(callback_arg);
CY_UNUSED_PARAMETER(event);
}
cy_rslt_t snippet_mtb_srf_ipc_relay_nonrtos(void)
{
mtb_ipc_mbox_receiver_enable_event(cb_relay.mailbox_handle,
MTB_IPC_MBOX_FULL,
true);
mtb_ipc_mbox_receiver_register_callback(cb_relay.mailbox_handle, ipc_callback, NULL);
return result;
}
cy_rslt_t mtb_srf_ipc_receive_request(mtb_srf_ipc_relay_context_t *relay_context, uint64_t timeout_us)
Receives an SRF request over IPC and adds to either the queue if using an RTOS or the ringbuffer.
Definition: mtb_srf_ipc.c:627
cy_rslt_t mtb_srf_ipc_process_pending_request(mtb_srf_ipc_relay_context_t *relay_context)
Process the SRF request pending in either the queue if using an RTOS or the ringbuffer.
Definition: mtb_srf_ipc.c:706
Start Relay (RTOS)
#if defined(CY_RTOS_AWARE) || defined(COMPONENT_RTOS_AWARE)
cy_rslt_t snippet_mtb_srf_ipc_relay_rtos(void)
{
mtb_srf_ipc_relay_context_t relay;
cy_thread_t receive;
cy_thread_t process;
uint64_t thread_stack_receive[300];
uint64_t thread_stack_process[300];
cy_rslt_t result = cy_rtos_thread_create(&receive, &mtb_srf_ipc_receive_thread,
"Receive Thread", &thread_stack_receive,
sizeof(thread_stack_receive),
CY_RTOS_PRIORITY_NORMAL, (cy_thread_arg_t)&relay);
result = cy_rtos_thread_create(&process, &mtb_srf_ipc_process_thread,
"Process Thread", &thread_stack_process,
sizeof(thread_stack_process),
CY_RTOS_PRIORITY_NORMAL, (cy_thread_arg_t)&relay);
return result;
}
Quick init of Client
uint32_t IPC_SEMAPHORE_INDEXES_SIMPLE[] = { 1UL, 2UL, 3UL, 4UL, 5UL, 6UL };
cy_rslt_t snippet_mtb_srf_ipc_client_init(void)
{
mtb_ipc_t ipc_inst_simple;
mtb_ipc_mbox_sender_t ipc_sender_simple;
mtb_srf_ipc_pool_t srf_ipc_pool_simple;
mtb_ipc_semaphore_t ipc_semaphores[IPC_NUM_REQ_IN_POOL];
{
.mailbox_handle = &ipc_sender_simple,
.ipc_sem_indexes = IPC_SEMAPHORE_INDEXES_SIMPLE,
.srf_ipc_requests = srf_ipc_requests_simple,
.srf_ipc_pool = &srf_ipc_pool_simple,
.semaphore_handles = ipc_semaphores,
.mbox_idx = 0UL,
.num_semaphores = IPC_NUM_REQ_IN_POOL,
.num_requests = IPC_NUM_REQ_IN_POOL
};
return result;
}
cy_rslt_t mtb_srf_ipc_client_init(mtb_srf_ipc_client_context_t *context, mtb_srf_ipc_client_init_cfg_t *cfg)
Initializes Semaphores, Mailbox, and sets up Client context This function requires that the IPC secti...
mtb_ipc_t * ipc_instance
Pointer to the initialized IPC instance.
Definition: mtb_srf_ipc_init.h:245
Config struct to set up entire SRF system including IPC mailbox, semaphores and Client context.
Definition: mtb_srf_ipc_init.h:237
Quick init of Relay
CY_SECTION_SHAREDMEM mtb_ipc_mbox_data_t srf_ipc_mbox_data _MTB_IPC_DATA_ALIGN;
CY_SECTION_SHAREDMEM mtb_ipc_semaphore_data_t sem_data_simple[IPC_NUM_REQ_IN_POOL];
uint32_t IPC_SEMAPHORE_INDEXES_SIMPLE[] = { 1UL, 2UL, 3UL, 4UL, 5UL, 6UL };
cy_rslt_t snippet_mtb_srf_ipc_relay_init(void)
{
mtb_ipc_t ipc_inst_simple;
mtb_ipc_mbox_receiver_t ipc_receiver_simple;
mtb_srf_ipc_relay_context_t mtb_srf_relay_context;
mtb_ipc_semaphore_t sem_arr_simple[IPC_NUM_REQ_IN_POOL];
{
.mailbox_handle = &ipc_receiver_simple,
.ipc_sem_indexes = IPC_SEMAPHORE_INDEXES_SIMPLE,
.mailbox_data = &srf_ipc_mbox_data,
.semaphore_data = sem_data_simple,
.semaphore_handles = sem_arr_simple,
.mbox_idx = 0UL,
.mbox_read_sema_idx = 10UL,
.mbox_write_sema_idx = 11UL,
.num_semaphores = IPC_NUM_REQ_IN_POOL,
.num_requests = IPC_NUM_REQ_IN_POOL
};
#if (defined(CY_RTOS_AWARE) || defined(COMPONENT_RTOS_AWARE))
cy_queue_t rtos_queue;
relay_init_simple.ipc_req_queue = &rtos_queue;
#endif
cy_rslt_t result = mtb_srf_ipc_relay_init(&mtb_srf_relay_context, &relay_init_simple);
return result;
}
mtb_ipc_t * ipc_instance
Pointer to the initialized IPC instance.
Definition: mtb_srf_ipc_init.h:275
Config struct to set up entire SRF system including IPC mailbox, semaphores and Relay context.
Definition: mtb_srf_ipc_init.h:263
|
| cy_rslt_t | mtb_srf_ipc_request_submit (mtb_srf_ipc_client_context_t *client_context, mtb_srf_invec_ns_t *inVec_ns, uint8_t inVec_cnt_ns, mtb_srf_outvec_ns_t *outVec_ns, uint8_t outVec_cnt_ns) |
| | Submit a request from another core to a TrustZone enabled core. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_pool_semaphore_alloc (mtb_srf_ipc_pool_t *pool, uint16_t *sema_idx, uint32_t timeout_us) |
| | Allocate IPC semaphore to use in signalling. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_pool_req_alloc (mtb_srf_ipc_pool_t *pool, mtb_srf_ipc_packet_t **req, uint32_t timeout_us) |
| | Allocate secure request object within an SRF IPC request pool to act as a packet. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_pool_semaphore_free (mtb_srf_ipc_pool_t *pool, uint16_t sema_idx) |
| | Deallocate an IPC semaphore. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_pool_req_free (mtb_srf_ipc_pool_t *pool, const mtb_srf_ipc_packet_t *req) |
| | Free secure request object within an SRF IPC request pool. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_request_send (mtb_srf_ipc_client_context_t *client_context, mtb_srf_ipc_packet_t *request, uint64_t timeout_us) |
| | Sends a request from the non-secure side to the secure and blocks for a timeout until request is processed. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_receive_request (mtb_srf_ipc_relay_context_t *relay_context, uint64_t timeout_us) |
| | Receives an SRF request over IPC and adds to either the queue if using an RTOS or the ringbuffer. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_process_request (mtb_srf_ipc_packet_t *request) |
| | Process the SRF request from IPC. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_process_pending_request (mtb_srf_ipc_relay_context_t *relay_context) |
| | Process the SRF request pending in either the queue if using an RTOS or the ringbuffer. More...
|
| |
| cy_rslt_t | mtb_srf_ipc_signal_complete (mtb_srf_ipc_relay_context_t *relay_context, mtb_srf_ipc_packet_t *request) |
| | Signals to client that secure request has been completed and output can be read. More...
|
| |
◆ mtb_srf_ipc_request_submit()
| cy_rslt_t mtb_srf_ipc_request_submit |
( |
mtb_srf_ipc_client_context_t * |
client_context, |
|
|
mtb_srf_invec_ns_t * |
inVec_ns, |
|
|
uint8_t |
inVec_cnt_ns, |
|
|
mtb_srf_outvec_ns_t * |
outVec_ns, |
|
|
uint8_t |
outVec_cnt_ns |
|
) |
| |
Submit a request from another core to a TrustZone enabled core.
- Note
- Calling this API is handled internally. When the IPC library is present, calling mtb_srf_request_submit from another core will redirect to this API. If the default mtb_srf_request_submit is disabled via the Makefile define MTB_SRF_CUSTOM_REQUEST_SUBMIT, it becomes the user's responsibility to call this on non-Trustzone cores.
- Parameters
-
| [in,out] | client_context | Stores state that client process needs to track between calls. |
| [in,out] | inVec_ns | Vector for all operation and SRF input |
| [in] | inVec_cnt_ns | Number of input vectors in inVec_ns array |
| [in,out] | outVec_ns | Vector for all operation and SRF output |
| [in] | outVec_cnt_ns | Number of output vectors in outVec_ns array |
- Returns
- the status of submission
◆ mtb_srf_ipc_pool_semaphore_alloc()
| cy_rslt_t mtb_srf_ipc_pool_semaphore_alloc |
( |
mtb_srf_ipc_pool_t * |
pool, |
|
|
uint16_t * |
sema_idx, |
|
|
uint32_t |
timeout_us |
|
) |
| |
Allocate IPC semaphore to use in signalling.
- Parameters
-
| [in,out] | pool | The pool object that was populated by mtb_srf_pool_init |
| [in,out] | sema_idx | Pointer to the semaphore index that will be allocated. |
| [in] | timeout_us | Timeout to wait in microsecond. Set to 0 to perform no wait. |
- Returns
- the status of allocate request
◆ mtb_srf_ipc_pool_req_alloc()
| cy_rslt_t mtb_srf_ipc_pool_req_alloc |
( |
mtb_srf_ipc_pool_t * |
pool, |
|
|
mtb_srf_ipc_packet_t ** |
req, |
|
|
uint32_t |
timeout_us |
|
) |
| |
Allocate secure request object within an SRF IPC request pool to act as a packet.
- Parameters
-
| [in,out] | pool | The pool object that was populated by mtb_srf_pool_init |
| [in,out] | req | Pointer to an SRF IPC request object. |
| [in] | timeout_us | Timeout to wait in microsecond. Set to 0 to perform no wait. |
- Note
- The timeout_us must always be 0 if allocation is invoked from an interrupt context.
- Returns
- the status of allocate request
◆ mtb_srf_ipc_pool_semaphore_free()
| cy_rslt_t mtb_srf_ipc_pool_semaphore_free |
( |
mtb_srf_ipc_pool_t * |
pool, |
|
|
uint16_t |
sema_idx |
|
) |
| |
Deallocate an IPC semaphore.
- Parameters
-
| [in,out] | pool | The pool object that was populated by mtb_srf_pool_init |
| [in,out] | sema_idx | Index of semaphore to be deallocated from the pool. |
- Returns
- the status of allocate request
◆ mtb_srf_ipc_pool_req_free()
Free secure request object within an SRF IPC request pool.
- Parameters
-
| [in,out] | pool | The pool object that was populated by mtb_srf_pool_init |
| [in] | req | Pointer to an MB SRF request for the pool to free |
- Returns
- the status of free request
◆ mtb_srf_ipc_request_send()
| cy_rslt_t mtb_srf_ipc_request_send |
( |
mtb_srf_ipc_client_context_t * |
client_context, |
|
|
mtb_srf_ipc_packet_t * |
request, |
|
|
uint64_t |
timeout_us |
|
) |
| |
Sends a request from the non-secure side to the secure and blocks for a timeout until request is processed.
This is a function that should be added any implementation of mtb_srf_request_submit, either within the BSP or custom.
- Parameters
-
| [in,out] | client_context | Stores state that client process needs to track between calls. |
| [in,out] | request | Pointer to SRF IPC request object that will be sent by mailbox. If this is of a type other than default mtb_srf_ipc_packet_t, then please override mtb_srf_ipc_process_request to handle additional parameters. |
| [in] | timeout_us | Timeout (in uS) to attempt to send request over IPC and subsequently wait for a response. |
- Returns
- the status of submission
◆ mtb_srf_ipc_receive_request()
| cy_rslt_t mtb_srf_ipc_receive_request |
( |
mtb_srf_ipc_relay_context_t * |
relay_context, |
|
|
uint64_t |
timeout_us |
|
) |
| |
Receives an SRF request over IPC and adds to either the queue if using an RTOS or the ringbuffer.
- Parameters
-
| [in,out] | relay_context | Stores state that client process needs to track between calls. |
| [in] | timeout_us | Timeout (in uS) to attempt to receive request over IPC. |
- Returns
- the status of the receive.
No RTOS so we add to ring buffer
◆ mtb_srf_ipc_process_request()
Process the SRF request from IPC.
- Parameters
-
| [in,out] | request | Secure request to prepare for processing. If this is of a type other than default mtb_srf_ipc_packet_t, please override this function to handle additional parameters. |
- Returns
- the status of the request submit.
◆ mtb_srf_ipc_process_pending_request()
| cy_rslt_t mtb_srf_ipc_process_pending_request |
( |
mtb_srf_ipc_relay_context_t * |
relay_context | ) |
|
Process the SRF request pending in either the queue if using an RTOS or the ringbuffer.
- Parameters
-
| [in,out] | relay_context | Stores state that client process needs to track between calls. |
- Returns
- the status of the request submit.
◆ mtb_srf_ipc_signal_complete()
| cy_rslt_t mtb_srf_ipc_signal_complete |
( |
mtb_srf_ipc_relay_context_t * |
relay_context, |
|
|
mtb_srf_ipc_packet_t * |
request |
|
) |
| |
Signals to client that secure request has been completed and output can be read.
- Parameters
-
| [in,out] | relay_context | Stores state that client process needs to track between calls. |
| [in] | request | Secure request to prepare for processing. |
- Returns
- the status of the signalling