blob: 4fc564b52e139d492f73acf1381a98e1d5d4f5a5 [file] [log] [blame]
Mate Toth-Pal179a1562019-11-08 11:40:27 +01001/*
Raef Coles249aba92022-06-16 10:20:29 +01002 * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
Mate Toth-Pal179a1562019-11-08 11:40:27 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <stdbool.h>
9#include "tfm_platform_api.h"
Kevin Peng0e340ea2023-08-15 17:51:44 +080010#include "psa/client.h"
Mate Toth-Pal179a1562019-11-08 11:40:27 +010011#include "psa_manifest/sid.h"
12
13enum tfm_platform_err_t tfm_platform_system_reset(void)
14{
15 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
Mate Toth-Pal179a1562019-11-08 11:40:27 +010016
Raef Coles046ffd82022-06-16 13:52:48 +010017 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
18 TFM_PLATFORM_API_ID_SYSTEM_RESET,
Mate Toth-Pal179a1562019-11-08 11:40:27 +010019 NULL, 0, NULL, 0);
Mate Toth-Pal179a1562019-11-08 11:40:27 +010020
21 if (status < PSA_SUCCESS) {
22 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
23 } else {
Raef Coles249aba92022-06-16 10:20:29 +010024 return (enum tfm_platform_err_t)status;
Mate Toth-Pal179a1562019-11-08 11:40:27 +010025 }
26
27}
28
29enum tfm_platform_err_t
30tfm_platform_ioctl(tfm_platform_ioctl_req_t request,
31 psa_invec *input, psa_outvec *output)
32{
33 tfm_platform_ioctl_req_t req = request;
34 struct psa_invec in_vec[2] = { {0} };
35 size_t inlen, outlen;
36 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
Mate Toth-Pal179a1562019-11-08 11:40:27 +010037
38 in_vec[0].base = &req;
39 in_vec[0].len = sizeof(req);
40 if (input != NULL) {
41 in_vec[1].base = input->base;
42 in_vec[1].len = input->len;
43 inlen = 2;
44 } else {
45 inlen = 1;
46 }
47
48 if (output != NULL) {
49 outlen = 1;
50 } else {
51 outlen = 0;
52 }
53
Raef Coles046ffd82022-06-16 13:52:48 +010054 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
55 TFM_PLATFORM_API_ID_IOCTL,
Mate Toth-Pal179a1562019-11-08 11:40:27 +010056 in_vec, inlen,
57 output, outlen);
Mate Toth-Pal179a1562019-11-08 11:40:27 +010058
59 if (status < PSA_SUCCESS) {
60 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
61 } else {
Raef Coles249aba92022-06-16 10:20:29 +010062 return (enum tfm_platform_err_t)status;
Mate Toth-Pal179a1562019-11-08 11:40:27 +010063 }
64}
65
Raef Coles249aba92022-06-16 10:20:29 +010066enum tfm_platform_err_t
67tfm_platform_nv_counter_increment(uint32_t counter_id)
68{
69 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
Raef Coles249aba92022-06-16 10:20:29 +010070 struct psa_invec in_vec[1];
71
72 in_vec[0].base = &counter_id;
73 in_vec[0].len = sizeof(counter_id);
74
Raef Coles046ffd82022-06-16 13:52:48 +010075 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
76 TFM_PLATFORM_API_ID_NV_INCREMENT,
Raef Coles249aba92022-06-16 10:20:29 +010077 in_vec, 1, (psa_outvec *)NULL, 0);
78
Raef Coles249aba92022-06-16 10:20:29 +010079 if (status < PSA_SUCCESS) {
80 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
81 } else {
82 return (enum tfm_platform_err_t)status;
83 }
84}
85
86enum tfm_platform_err_t
87tfm_platform_nv_counter_read(uint32_t counter_id,
88 uint32_t size, uint8_t *val)
89{
90 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
Raef Coles249aba92022-06-16 10:20:29 +010091 struct psa_invec in_vec[1];
92 struct psa_outvec out_vec[1];
93
94 in_vec[0].base = &counter_id;
95 in_vec[0].len = sizeof(counter_id);
96
97 out_vec[0].base = val;
98 out_vec[0].len = size;
99
Raef Coles046ffd82022-06-16 13:52:48 +0100100 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
101 TFM_PLATFORM_API_ID_NV_READ,
Raef Coles249aba92022-06-16 10:20:29 +0100102 in_vec, 1, out_vec, 1);
103
Raef Coles249aba92022-06-16 10:20:29 +0100104 if (status < PSA_SUCCESS) {
105 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
106 } else {
107 return (enum tfm_platform_err_t)status;
108 }
109}