10 #include "tfm_platform_system.h"
11 #include "tfm_plat_nv_counters.h"
16 #define NV_COUNTER_ID_SIZE sizeof(enum tfm_nv_counter_t)
17 #define NV_COUNTER_MAP_SIZE 3
30 #include "region_defs.h"
32 #define INPUT_BUFFER_SIZE 64
33 #define OUTPUT_BUFFER_SIZE 64
46 static bool nv_counter_access_grant(int32_t client_id,
47 enum tfm_nv_counter_t nv_counter_no)
53 (int32_t)nv_counter_no < 0 || nv_counter_no >= PLAT_NV_COUNTER_MAX) {
57 req_id = nv_counter_access_map[nv_counter_no];
62 if (client_id == req_id && req_id != 0) {
80 tfm_platform_hal_system_reset();
94 if ((num_invec < 1) || (num_invec > 2) ||
96 (in_vec[0].base == NULL) ||
101 input = (num_invec == 1) ? NULL : &in_vec[1];
105 return tfm_platform_hal_ioctl(request, input, output);
112 enum tfm_plat_err_t err;
113 enum tfm_nv_counter_t counter_id;
114 uint32_t counter_size;
115 int32_t status, client_id;
118 num_invec != 1 || num_outvec != 1) {
121 counter_id = *((
enum tfm_nv_counter_t *)in_vec[0].base);
122 counter_size = out_vec[0].
len;
129 if (!nv_counter_access_grant(client_id, counter_id)) {
132 err = tfm_plat_read_nv_counter(counter_id, counter_size,
133 (uint8_t *)out_vec[0].base);
134 if (err != TFM_PLAT_ERR_SUCCESS) {
145 enum tfm_plat_err_t err;
146 enum tfm_nv_counter_t counter_id;
147 int32_t client_id, status;
150 num_invec != 1 || num_outvec != 0) {
159 counter_id = *((
enum tfm_nv_counter_t *)in_vec[0].base);
161 if (!nv_counter_access_grant(client_id, counter_id)) {
164 err = tfm_plat_increment_nv_counter(counter_id);
165 if (err != TFM_PLAT_ERR_SUCCESS) {
175 platform_sp_system_reset_ipc(
const psa_msg_t *msg)
183 platform_sp_nv_counter_ipc(
const psa_msg_t *msg)
185 enum tfm_plat_err_t err = TFM_PLAT_ERR_SYSTEM_ERR;
188 enum tfm_nv_counter_t counter_id;
189 uint8_t counter_val = 0;
192 while ((in_len > 0) && (msg->
in_size[in_len - 1] == 0)) {
197 while ((out_len > 0) && (msg->
out_size[out_len - 1] == 0)) {
203 in_len != 1 || out_len != 0) {
213 if (!nv_counter_access_grant(msg->
client_id, counter_id)) {
217 err = tfm_plat_increment_nv_counter(counter_id);
223 in_len != 1 || out_len != 1) {
227 if (!nv_counter_access_grant(msg->
client_id, counter_id)) {
231 err = tfm_plat_read_nv_counter(counter_id, msg->
out_size[0],
234 if (err != TFM_PLAT_ERR_SUCCESS) {
244 if (err != TFM_PLAT_ERR_SUCCESS) {
251 platform_sp_ioctl_ipc(
const psa_msg_t *msg)
257 uint8_t input_buffer[INPUT_BUFFER_SIZE] = {0};
258 uint8_t output_buffer[OUTPUT_BUFFER_SIZE] = {0};
265 while ((in_len > 0) && (msg->
in_size[in_len - 1] == 0)) {
269 while ((out_len > 0) && (msg->
out_size[out_len - 1] == 0)) {
273 if ((in_len < 1) || (in_len > 2) ||
279 if (num !=
sizeof(request)) {
284 if (msg->
in_size[1] > INPUT_BUFFER_SIZE) {
291 invec.
base = input_buffer;
297 if (msg->
out_size[0] > OUTPUT_BUFFER_SIZE) {
300 outvec.
base = output_buffer;
305 ret = tfm_platform_hal_ioctl(request, input, output);
307 if (output != NULL) {
314 static void platform_signal_handle(
psa_signal_t signal, plat_func_t pfn)
319 status =
psa_get(signal, &msg);
343 enum tfm_plat_err_t err;
344 err = tfm_plat_init_nv_counter();
345 if (err != TFM_PLAT_ERR_SUCCESS) {
358 platform_signal_handle(TFM_SP_PLATFORM_SYSTEM_RESET_SIGNAL,
359 platform_sp_system_reset_ipc);
361 platform_signal_handle(TFM_SP_PLATFORM_IOCTL_SIGNAL,
362 platform_sp_ioctl_ipc);
364 platform_signal_handle(TFM_SP_PLATFORM_NV_COUNTER_SIGNAL,
365 platform_sp_nv_counter_ipc);
size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx, void *buffer, size_t num_bytes)
Read a message parameter or part of a message parameter from a client input vector.
#define PSA_IPC_DISCONNECT
int32_t tfm_spm_request_reset_vote(void)
Request a vote from SPM on a system reset.
#define PSA_ERROR_PROGRAMMER_ERROR
void psa_panic(void)
Terminate execution within the calling Secure Partition and will not return.
size_t in_size[PSA_MAX_IOVEC]
int32_t tfm_core_get_caller_client_id(int32_t *caller_client_id)
void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, const void *buffer, size_t num_bytes)
Write a message response to a client output vector.
void psa_reply(psa_handle_t msg_handle, psa_status_t status)
Complete handling of a specific message and unblock the client.
psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout)
Return the Secure Partition interrupt signals that have been asserted from a subset of signals provid...
size_t out_size[PSA_MAX_IOVEC]
psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg)
Retrieve the message which corresponds to a given RoT Service signal and remove the message from the ...
int32_t psa_status_t
Function return status.