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" |
Kevin Peng | 0e340ea | 2023-08-15 17:51:44 +0800 | [diff] [blame] | 10 | #include "psa/client.h" |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 11 | #include "psa_manifest/sid.h" |
| 12 | |
| 13 | enum tfm_platform_err_t tfm_platform_system_reset(void) |
| 14 | { |
| 15 | psa_status_t status = PSA_ERROR_CONNECTION_REFUSED; |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 16 | |
Raef Coles | 046ffd8 | 2022-06-16 13:52:48 +0100 | [diff] [blame] | 17 | status = psa_call(TFM_PLATFORM_SERVICE_HANDLE, |
| 18 | TFM_PLATFORM_API_ID_SYSTEM_RESET, |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 19 | NULL, 0, NULL, 0); |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 20 | |
| 21 | if (status < PSA_SUCCESS) { |
| 22 | return TFM_PLATFORM_ERR_SYSTEM_ERROR; |
| 23 | } else { |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 24 | return (enum tfm_platform_err_t)status; |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | } |
| 28 | |
| 29 | enum tfm_platform_err_t |
| 30 | tfm_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-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 37 | |
| 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 Coles | 046ffd8 | 2022-06-16 13:52:48 +0100 | [diff] [blame] | 54 | status = psa_call(TFM_PLATFORM_SERVICE_HANDLE, |
| 55 | TFM_PLATFORM_API_ID_IOCTL, |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 56 | in_vec, inlen, |
| 57 | output, outlen); |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 58 | |
| 59 | if (status < PSA_SUCCESS) { |
| 60 | return TFM_PLATFORM_ERR_SYSTEM_ERROR; |
| 61 | } else { |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 62 | return (enum tfm_platform_err_t)status; |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 66 | enum tfm_platform_err_t |
| 67 | tfm_platform_nv_counter_increment(uint32_t counter_id) |
| 68 | { |
| 69 | psa_status_t status = PSA_ERROR_CONNECTION_REFUSED; |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 70 | struct psa_invec in_vec[1]; |
| 71 | |
| 72 | in_vec[0].base = &counter_id; |
| 73 | in_vec[0].len = sizeof(counter_id); |
| 74 | |
Raef Coles | 046ffd8 | 2022-06-16 13:52:48 +0100 | [diff] [blame] | 75 | status = psa_call(TFM_PLATFORM_SERVICE_HANDLE, |
| 76 | TFM_PLATFORM_API_ID_NV_INCREMENT, |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 77 | in_vec, 1, (psa_outvec *)NULL, 0); |
| 78 | |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 79 | if (status < PSA_SUCCESS) { |
| 80 | return TFM_PLATFORM_ERR_SYSTEM_ERROR; |
| 81 | } else { |
| 82 | return (enum tfm_platform_err_t)status; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | enum tfm_platform_err_t |
| 87 | tfm_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 Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 91 | 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 Coles | 046ffd8 | 2022-06-16 13:52:48 +0100 | [diff] [blame] | 100 | status = psa_call(TFM_PLATFORM_SERVICE_HANDLE, |
| 101 | TFM_PLATFORM_API_ID_NV_READ, |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 102 | in_vec, 1, out_vec, 1); |
| 103 | |
Raef Coles | 249aba9 | 2022-06-16 10:20:29 +0100 | [diff] [blame] | 104 | if (status < PSA_SUCCESS) { |
| 105 | return TFM_PLATFORM_ERR_SYSTEM_ERROR; |
| 106 | } else { |
| 107 | return (enum tfm_platform_err_t)status; |
| 108 | } |
| 109 | } |