blob: 0c1edf463f883ab11b77b770377ccc9bfb5f4150 [file] [log] [blame]
Mate Toth-Pal179a1562019-11-08 11:40:27 +01001/*
2 * Copyright (c) 2019, 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
12enum tfm_platform_err_t tfm_platform_system_reset(void)
13{
14 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
15 psa_handle_t handle = PSA_NULL_HANDLE;
16
17 handle = psa_connect(TFM_SP_PLATFORM_SYSTEM_RESET_SID,
18 TFM_SP_PLATFORM_SYSTEM_RESET_VERSION);
19 if (handle <= 0) {
20 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
21 }
22
23 status = psa_call(handle, PSA_IPC_CALL,
24 NULL, 0, NULL, 0);
25 psa_close(handle);
26
27 if (status < PSA_SUCCESS) {
28 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
29 } else {
30 return (enum tfm_platform_err_t) status;
31 }
32
33}
34
35enum tfm_platform_err_t
36tfm_platform_ioctl(tfm_platform_ioctl_req_t request,
37 psa_invec *input, psa_outvec *output)
38{
39 tfm_platform_ioctl_req_t req = request;
40 struct psa_invec in_vec[2] = { {0} };
41 size_t inlen, outlen;
42 psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
43 psa_handle_t handle = PSA_NULL_HANDLE;
44
45 in_vec[0].base = &req;
46 in_vec[0].len = sizeof(req);
47 if (input != NULL) {
48 in_vec[1].base = input->base;
49 in_vec[1].len = input->len;
50 inlen = 2;
51 } else {
52 inlen = 1;
53 }
54
55 if (output != NULL) {
56 outlen = 1;
57 } else {
58 outlen = 0;
59 }
60
61 handle = psa_connect(TFM_SP_PLATFORM_IOCTL_SID,
62 TFM_SP_PLATFORM_IOCTL_VERSION);
63 if (handle <= 0) {
64 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
65 }
66
67 status = psa_call(handle, PSA_IPC_CALL,
68 in_vec, inlen,
69 output, outlen);
70 psa_close(handle);
71
72 if (status < PSA_SUCCESS) {
73 return TFM_PLATFORM_ERR_SYSTEM_ERROR;
74 } else {
75 return (enum tfm_platform_err_t) status;
76 }
77}
78