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