blob: d7096078dcd7dd0a438e78dd7ceb42d24a92a1d8 [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"
10#include "psa_manifest/sid.h"
11
12enum tfm_platform_err_t tfm_platform_system_reset(void)
13{
14 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
Mate Toth-Pal179a1562019-11-08 11:40:27 +010015
Raef Coles046ffd82022-06-16 13:52:48 +010016 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
17 TFM_PLATFORM_API_ID_SYSTEM_RESET,
Mate Toth-Pal179a1562019-11-08 11:40:27 +010018 NULL, 0, NULL, 0);
Mate Toth-Pal179a1562019-11-08 11:40:27 +010019
20 if (status < PSA_SUCCESS) {
21 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
22 } else {
Raef Coles249aba92022-06-16 10:20:29 +010023 return (enum tfm_platform_err_t)status;
Mate Toth-Pal179a1562019-11-08 11:40:27 +010024 }
25
26}
27
28enum tfm_platform_err_t
29tfm_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;
Mate Toth-Pal179a1562019-11-08 11:40:27 +010036
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
Raef Coles046ffd82022-06-16 13:52:48 +010053 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
54 TFM_PLATFORM_API_ID_IOCTL,
Mate Toth-Pal179a1562019-11-08 11:40:27 +010055 in_vec, inlen,
56 output, outlen);
Mate Toth-Pal179a1562019-11-08 11:40:27 +010057
58 if (status < PSA_SUCCESS) {
59 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
60 } else {
Raef Coles249aba92022-06-16 10:20:29 +010061 return (enum tfm_platform_err_t)status;
Mate Toth-Pal179a1562019-11-08 11:40:27 +010062 }
63}
64
Raef Coles249aba92022-06-16 10:20:29 +010065enum tfm_platform_err_t
66tfm_platform_nv_counter_increment(uint32_t counter_id)
67{
68 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
Raef Coles249aba92022-06-16 10:20:29 +010069 struct psa_invec in_vec[1];
70
71 in_vec[0].base = &counter_id;
72 in_vec[0].len = sizeof(counter_id);
73
Raef Coles046ffd82022-06-16 13:52:48 +010074 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
75 TFM_PLATFORM_API_ID_NV_INCREMENT,
Raef Coles249aba92022-06-16 10:20:29 +010076 in_vec, 1, (psa_outvec *)NULL, 0);
77
Raef Coles249aba92022-06-16 10:20:29 +010078 if (status < PSA_SUCCESS) {
79 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
80 } else {
81 return (enum tfm_platform_err_t)status;
82 }
83}
84
85enum tfm_platform_err_t
86tfm_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;
Raef Coles249aba92022-06-16 10:20:29 +010090 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
Raef Coles046ffd82022-06-16 13:52:48 +010099 status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
100 TFM_PLATFORM_API_ID_NV_READ,
Raef Coles249aba92022-06-16 10:20:29 +0100101 in_vec, 1, out_vec, 1);
102
Raef Coles249aba92022-06-16 10:20:29 +0100103 if (status < PSA_SUCCESS) {
104 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
105 } else {
106 return (enum tfm_platform_err_t)status;
107 }
108}