1 /*
2 * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #include <stdbool.h>
9 #include "tfm_platform_api.h"
10 #include "psa_manifest/sid.h"
11
tfm_platform_system_reset(void)12 enum tfm_platform_err_t tfm_platform_system_reset(void)
13 {
14 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
15
16 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
17 TFM_PLATFORM_API_ID_SYSTEM_RESET,
18 NULL, 0, NULL, 0);
19
20 if (status < PSA_SUCCESS) {
21 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
22 } else {
23 return (enum tfm_platform_err_t)status;
24 }
25
26 }
27
28 enum tfm_platform_err_t
tfm_platform_ioctl(tfm_platform_ioctl_req_t request,psa_invec * input,psa_outvec * output)29 tfm_platform_ioctl(tfm_platform_ioctl_req_t request,
30 psa_invec *input, psa_outvec *output)
31 {
32 tfm_platform_ioctl_req_t req = request;
33 struct psa_invec in_vec[2] = { {0} };
34 size_t inlen, outlen;
35 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
36
37 in_vec[0].base = &req;
38 in_vec[0].len = sizeof(req);
39 if (input != NULL) {
40 in_vec[1].base = input->base;
41 in_vec[1].len = input->len;
42 inlen = 2;
43 } else {
44 inlen = 1;
45 }
46
47 if (output != NULL) {
48 outlen = 1;
49 } else {
50 outlen = 0;
51 }
52
53 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
54 TFM_PLATFORM_API_ID_IOCTL,
55 in_vec, inlen,
56 output, outlen);
57
58 if (status < PSA_SUCCESS) {
59 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
60 } else {
61 return (enum tfm_platform_err_t)status;
62 }
63 }
64
65 enum tfm_platform_err_t
tfm_platform_nv_counter_increment(uint32_t counter_id)66 tfm_platform_nv_counter_increment(uint32_t counter_id)
67 {
68 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
69 struct psa_invec in_vec[1];
70
71 in_vec[0].base = &counter_id;
72 in_vec[0].len = sizeof(counter_id);
73
74 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
75 TFM_PLATFORM_API_ID_NV_INCREMENT,
76 in_vec, 1, (psa_outvec *)NULL, 0);
77
78 if (status < PSA_SUCCESS) {
79 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
80 } else {
81 return (enum tfm_platform_err_t)status;
82 }
83 }
84
85 enum tfm_platform_err_t
tfm_platform_nv_counter_read(uint32_t counter_id,uint32_t size,uint8_t * val)86 tfm_platform_nv_counter_read(uint32_t counter_id,
87 uint32_t size, uint8_t *val)
88 {
89 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
90 struct psa_invec in_vec[1];
91 struct psa_outvec out_vec[1];
92
93 in_vec[0].base = &counter_id;
94 in_vec[0].len = sizeof(counter_id);
95
96 out_vec[0].base = val;
97 out_vec[0].len = size;
98
99 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
100 TFM_PLATFORM_API_ID_NV_READ,
101 in_vec, 1, out_vec, 1);
102
103 if (status < PSA_SUCCESS) {
104 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
105 } else {
106 return (enum tfm_platform_err_t)status;
107 }
108 }
109