The Secure Request Framework (SRF) exists to provide a reusable infastructure for implementing multiple secure operations via a single non-secure-callable entry point.
This framework is designed to be generic with no dependency on or knowledge of any particular hardware operation. It can be used directly by user code.
Through the SRF, the secure world exposes one or more operations, which are roughly equivalent to a function. These operations can be combined into a module - a unit of integration between different entities which wish to expose their operations. For example, the Peripheral Driver Library (PDL) would be one module.
The non-secure world invokes an operation by submitting a secure request via the mtb_srf_request_submit API. This request is then passed to the secure world, where its memory addresses are validated, as are the permissions required to perform the operation. A default validation strategy is performed through mtb_srf_memory_validate, and further operation specific validation should be done inside the operation itself. The default mtb_srf_memory_validate API checks that all memory passed in is accessible to the NS side, ensured the minimum number of inVec and outVec are present, and that a legal number of ioVec (input-output vectors) have been provided (discussed further below). This API is defined weakly to enable overriding with a custom implementation.
This framework requires the user manage a mtb_srf_config.h file that contains macros for the various modules that use the SRF. The file comes with the default macros for user and PDL module IDs. Should a library be added to the project that uses SRF, that library should generate a relevant error message requesting that its module ID is added to the mtb_srf_config.h file. The exact values of the module IDs do not matter, as long as they are unique and unsigned integers. The number of SRF modules should be defined as MTB_SRF_MODULE_COUNT. The SRF uses this macro internally to determine how many module IDs exist in a given project.
cy_stc_smif_context_t SMIFContext;
cy_stc_smif_mem_config_t memConfig;
#define MTB_SRF_MODULE_USER_DEMO (0U)
typedef enum
{
APP_SRF_USER_SUBMODULE_SMIF,
APP_SRF_USER_SUBMODULE_SYSCLK,
APP_SRF_USER_SUBMODULE_MAX = APP_SRF_USER_SUBMODULE_SYSCLK
} CY_PDL_SRF_SUBMODULE;
#define APP_SRF_SMIF_OP_WRITE (0U)
#define APP_SRF_SMIF_OP_READ (1U)
uint8_t inputs_ptr_ns_cnt,
uint8_t outputs_ptr_cnt_ns)
{
cy_rslt_t result = (cy_rslt_t)Cy_SMIF_MemWrite(inputs_ns->
request.
base,
(
const uint8_t*)inputs_ptr_ns[0].
base,
inputs_ptr_ns[0].
len, &SMIFContext);
CY_UNUSED_PARAMETER(outputs_ns);
CY_UNUSED_PARAMETER(outputs_ptr_ns);
CY_UNUSED_PARAMETER(inputs_ptr_ns_cnt);
CY_UNUSED_PARAMETER(outputs_ptr_cnt_ns);
return result;
}
{
{
.
base = (
void*)SMIF0_BASE,
.sub_block = 0,
.write_allowed = true,
},
};
{
{
.submodule_id = APP_SRF_USER_SUBMODULE_SMIF,
.op_id = APP_SRF_SMIF_OP_WRITE,
.write_required = true,
.impl = app_srf_submod_smif_write_fn,
.input_values_len = 1U * sizeof(uint32_t),
.output_values_len = 0UL,
.input_len ={ 0UL, 0UL, 0UL },
.needs_copy ={ false, false, false },
.output_len ={ 0UL, 0UL, 0UL },
.allowed_rsc = &app_srf_smif_permission[0],
.num_allowed = sizeof(app_srf_smif_permission) / sizeof(app_srf_smif_permission[0]),
},
};
{
app_srf_smif_operations,
app_srf_sysclk_operations,
};
size_t app_srf_num_operations[APP_SRF_USER_SUBMODULE_MAX + 1] =
{
sizeof(app_srf_smif_operations) / sizeof(app_srf_smif_operations[0]),
sizeof(app_srf_sysclk_operations) / sizeof(app_srf_sysclk_operations[0]),
};
{
.op_by_submod = app_srf_operations,
.num_op_by_submod = app_srf_num_operations,
.num_submod = sizeof(app_srf_num_operations) / sizeof(app_srf_num_operations[0]),
};
cy_rslt_t snippet_mtb_srf_register_module_api(void)
{
cy_rslt_t result = CY_RSLT_SUCCESS;
if (result != CY_RSLT_SUCCESS)
{
}
(void)result;
return result;
}
#endif
size_t len
Size of memory buffer in bytes.
Definition: mtb_srf_iovec.h:74
const void * base
Start address of the memory buffer.
Definition: mtb_srf_iovec.h:73
uint8_t input_values[]
Flexible size array for non-pointer input arguments.
Definition: mtb_srf_iovec.h:94
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
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
void * base
Register base address for the hardware resource. If not applicable, set to NULL.
Definition: mtb_srf.h:161
uint8_t module_id
Module ID for this operation. Must be unique within this operation.
Definition: mtb_srf.h:174
uint8_t module_id
ID for this module. Must be globally unique.
Definition: mtb_srf.h:214
cy_rslt_t mtb_srf_init(mtb_srf_context_s_t *context_s)
Initialize the SRF.
cy_rslt_t mtb_srf_module_register(mtb_srf_context_s_t *context_s, mtb_srf_module_s_t *module_s)
Register a module for use.
Module structure.
Definition: mtb_srf.h:213
Operation description structure.
Definition: mtb_srf.h:173
Permission structure.
Definition: mtb_srf.h:160
#define MTB_SRF_MODULE_PDL_DEMO (0U)
typedef enum
{
CY_PDL_SRF_SUBMODULE_SYSCLK,
CY_PDL_SRF_SUBMODULE_SYSPM,
CY_PDL_SRF_SUBMODULE_MAX = CY_PDL_SRF_SUBMODULE_SYSPM
} CY_PDL_SRF_SUBMODULE;
#define CY_SYSCLK_SRF_OP_HF_GET_FREQUENCY (0U)
#define CY_SYSCLK_SRF_OP_HF_GET_ENABLED (1U)
#define CY_SYSPM_SRF_OP_ENTER_SLEEP (0U)
#define CY_SYSPM_SRF_OP_ENTER_DEEPSLEEP (1U)
{
cy_rslt_t result = CY_RSLT_SUCCESS;
outVec_cnt_ns);
return result;
}
cy_rslt_t snippet_mtb_srf_submit_request_api(void)
{
cy_rslt_t result = CY_RSLT_SUCCESS;
if (result != CY_RSLT_SUCCESS)
{
return result;
}
output->
len = 1UL *
sizeof(uint32_t);
uint8_t inVec_cnt = 1;
uint8_t outVec_cnt = 1;
return result;
}
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
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
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.
cy_rslt_t mtb_srf_request_execute(mtb_srf_context_s_t *context_s, mtb_srf_invec_ns_t *inVec_ns, uint8_t inVec_cnt_ns, mtb_srf_outvec_ns_t *outVec_ns, uint8_t outVec_cnt_ns)
Execute a request.
|
|
#define | MTB_SRF_ERR_BAD_PARAM CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 0) |
| | An invalid parameter value is passed in.
|
| |
|
#define | MTB_SRF_ERR_UNKNOWN_OPERATION CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 1) |
| | Unknown operation requested.
|
| |
|
#define | MTB_SRF_ERR_UNKNOWN_MODULE CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 2) |
| | Unknown module requested.
|
| |
|
#define | MTB_SRF_ERR_SECURITY_POLICY_VIOLATION CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 3) |
| | Request violates resource security permissions.
|
| |
|
#define | MTB_SRF_ERR_MODULE_ID_INVALID CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 4) |
| | Module index provided at registration is invalid.
|
| |
|
#define | MTB_SRF_ERR_ALLOCATE_FREE CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 5) |
| | Failed to allocate/free secure request.
|
| |
|
#define | MTB_SRF_ERR_RINGBUF_EMPTY CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 6) |
| | Ringbuffer is empty.
|
| |
|
#define | MTB_SRF_ERR_RINGBUF_FULL CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 7) |
| | Ringbuffer is full.
|
| |
|
#define | MTB_SRF_ERR_ARGBUFF_FULL CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_MIDDLEWARE_SRF, 8) |
| | No space left in secure argument buffer.
|
| |
|
#define | _MTB_SRF_DATA_ALIGN |
| | This define can be used for aligning address of the data structures with enabled Data Cache.
|
| |
|
#define | MTB_SRF_NEVER_TIMEOUT (0xFFFFFFFFU) |
| | Indicates that an operation should wait indefinitely.
|
| |