Secure Request Pool Library provides an implementation of secure request pool mtb_srf_pool_t, which is composed of multiple secure request objects mtb_srf_request_ns_t.
Secure request objects need to be accessible by both the secure and non-secure world. In practice, this means that they should be allocated out of the "shared memory" region rather than e.g. off the stack. This, in turn, means that any RAM which is allocated for secure request pool description struct mtb_srf_pool_t is statically allocated for the lifetime of the program. Therefore, it would be inefficient for every secure request client to allocate its own secure request object. There needs to be a means for sharing. This need is satisfied by a secure request pool, which allows multiple secure request clients to share a small number of pre-allocated secure request pool description struct. A secure request pool is specific to a particular non-secure processing environment. I.e. in a system where both the CM33_NS and the CM55 are making secure requests, there would be two secure request pools, one for the CM33_NS and one for the CM55. Usage of this mechanism is optional. If needed to satisfy some special case, a secure request client can allocate their own custom secure request object and use that instead.
Features:
There are three parameters which define a secure request pool:
Pool initialization can be performed explicitly via the mtb_srf_pool_init function.
A secure request pool consolidates three user-provided memory allocations:
The input and output argument arrays are shared equally between all requests in the pool. For example, if a secure reqest pool contains three entries and args_in_length is 12, then each secure request would support up to 4 input arguments. The benefit is that the pool initialization process is simpler because there are fewer allocations required
A default pool is defined in the BSP and initialized as part of the non-secure application initialization. This default pool is expected to be sufficient for the majority of uses cases, so users should generally not need to do any manual allocation or management of pools.
Secure request object allocation is performed via the mtb_srf_pool_allocate function. Secure request object free is performed via the mtb_srf_pool_free function.
Init sequence for secure request pool
Allocation/Free operation
Macros | |
| #define | MTB_SRF_ROUND_UP(N, S) ((((N) + (S) - 1UL) / (S)) * (S)) |
| Round up. | |
| #define | MTB_SRF_POOL_ALIGNMENT (4UL) |
| Address alignment value of pool in bytes. | |
Functions | |
| 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. More... | |
| cy_rslt_t | mtb_srf_pool_free (mtb_srf_pool_t *pool, const mtb_srf_invec_ns_t *inVec, const mtb_srf_outvec_ns_t *outVec) |
| Free secure request object within an secure request pool. More... | |
| cy_rslt_t | mtb_srf_pool_get_entry_len (mtb_srf_pool_t *pool, size_t *input_len_per_entry, size_t *output_len_per_entry) |
| Get the input and output length per entry configuration of a pool that were set at initalization. More... | |
| 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.
| [in,out] | pool | The pool object that was populated by mtb_srf_pool_init |
| [in,out] | inVec | Pointer to an array of input vectors for the pool to allocate |
| [in,out] | outVec | Pointer to an array of output vectors for the pool to allocate |
| [in] | timeout_us | Timeout to wait in microsecond. Set to 0 to perform no wait. |
Allocate secure request object within an secure request pool.
| cy_rslt_t mtb_srf_pool_free | ( | mtb_srf_pool_t * | pool, |
| const mtb_srf_invec_ns_t * | inVec, | ||
| const mtb_srf_outvec_ns_t * | outVec | ||
| ) |
Free secure request object within an secure request pool.
| [in,out] | pool | The pool object that was populated by mtb_srf_pool_init |
| [in] | inVec | Pointer to an input vectors for the pool to free |
| [in] | outVec | Pointer to an output vectors for the pool to free. This must belong to the same request as inVec |
Free secure request object within an secure request pool.
| cy_rslt_t mtb_srf_pool_get_entry_len | ( | mtb_srf_pool_t * | pool, |
| size_t * | input_len_per_entry, | ||
| size_t * | output_len_per_entry | ||
| ) |
Get the input and output length per entry configuration of a pool that were set at initalization.
| [in,out] | pool | The pool object that was populated by mtb_srf_pool_init |
| [in,out] | input_len_per_entry | Value to store the input length per entry |
| [in,out] | output_len_per_entry | Value to store the output length per entry |