Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 1 | /* |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2019-2022, Arm Limited. All rights reserved. |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 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 | |
| 12 | enum 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 { |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame^] | 30 | return (enum tfm_platform_err_t)status; |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | } |
| 34 | |
| 35 | enum tfm_platform_err_t |
| 36 | tfm_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 { |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame^] | 75 | return (enum tfm_platform_err_t)status; |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame^] | 79 | enum tfm_platform_err_t |
| 80 | tfm_platform_nv_counter_increment(uint32_t counter_id) |
| 81 | { |
| 82 | psa_status_t status = PSA_ERROR_CONNECTION_REFUSED; |
| 83 | psa_handle_t handle = PSA_NULL_HANDLE; |
| 84 | struct psa_invec in_vec[1]; |
| 85 | |
| 86 | in_vec[0].base = &counter_id; |
| 87 | in_vec[0].len = sizeof(counter_id); |
| 88 | |
| 89 | handle = psa_connect(TFM_SP_PLATFORM_NV_COUNTER_SID, |
| 90 | TFM_SP_PLATFORM_NV_COUNTER_VERSION); |
| 91 | if (handle <= 0) { |
| 92 | return TFM_PLATFORM_ERR_SYSTEM_ERROR; |
| 93 | } |
| 94 | |
| 95 | status = psa_call(handle, TFM_PLATFORM_API_ID_NV_INCREMENT, |
| 96 | in_vec, 1, (psa_outvec *)NULL, 0); |
| 97 | |
| 98 | psa_close(handle); |
| 99 | |
| 100 | if (status < PSA_SUCCESS) { |
| 101 | return TFM_PLATFORM_ERR_SYSTEM_ERROR; |
| 102 | } else { |
| 103 | return (enum tfm_platform_err_t)status; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | enum tfm_platform_err_t |
| 108 | tfm_platform_nv_counter_read(uint32_t counter_id, |
| 109 | uint32_t size, uint8_t *val) |
| 110 | { |
| 111 | psa_status_t status = PSA_ERROR_CONNECTION_REFUSED; |
| 112 | psa_handle_t handle = PSA_NULL_HANDLE; |
| 113 | struct psa_invec in_vec[1]; |
| 114 | struct psa_outvec out_vec[1]; |
| 115 | |
| 116 | in_vec[0].base = &counter_id; |
| 117 | in_vec[0].len = sizeof(counter_id); |
| 118 | |
| 119 | out_vec[0].base = val; |
| 120 | out_vec[0].len = size; |
| 121 | |
| 122 | handle = psa_connect(TFM_SP_PLATFORM_NV_COUNTER_SID, |
| 123 | TFM_SP_PLATFORM_NV_COUNTER_VERSION); |
| 124 | if (handle <= 0) { |
| 125 | return TFM_PLATFORM_ERR_SYSTEM_ERROR; |
| 126 | } |
| 127 | |
| 128 | status = psa_call(handle, TFM_PLATFORM_API_ID_NV_READ, |
| 129 | in_vec, 1, out_vec, 1); |
| 130 | |
| 131 | psa_close(handle); |
| 132 | |
| 133 | if (status < PSA_SUCCESS) { |
| 134 | return TFM_PLATFORM_ERR_SYSTEM_ERROR; |
| 135 | } else { |
| 136 | return (enum tfm_platform_err_t)status; |
| 137 | } |
| 138 | } |