Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 1 | /* |
Raef Coles | 046ffd8 | 2022-06-16 13:52:48 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2022, Arm Limited. All rights reserved. |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __TFM_PLATFORM_API__ |
| 9 | #define __TFM_PLATFORM_API__ |
| 10 | |
| 11 | #include <limits.h> |
Tamas Kaman | 262dc7b | 2019-03-20 13:37:12 +0100 | [diff] [blame] | 12 | #include <stdbool.h> |
Miklos Balint | c7b1b6c | 2019-04-24 12:38:36 +0200 | [diff] [blame] | 13 | #include <stdint.h> |
Kevin Peng | 0e340ea | 2023-08-15 17:51:44 +0800 | [diff] [blame^] | 14 | #include "psa/client.h" |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
| 20 | /** |
| 21 | * \brief TFM secure partition platform API version |
| 22 | */ |
| 23 | #define TFM_PLATFORM_API_VERSION_MAJOR (0) |
Miklos Balint | c7b1b6c | 2019-04-24 12:38:36 +0200 | [diff] [blame] | 24 | #define TFM_PLATFORM_API_VERSION_MINOR (3) |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 25 | |
Galanakis, Minos | ef5118b | 2020-01-21 15:27:14 +0000 | [diff] [blame] | 26 | #define TFM_PLATFORM_API_ID_NV_READ (1010) |
| 27 | #define TFM_PLATFORM_API_ID_NV_INCREMENT (1011) |
Raef Coles | 046ffd8 | 2022-06-16 13:52:48 +0100 | [diff] [blame] | 28 | #define TFM_PLATFORM_API_ID_SYSTEM_RESET (1012) |
| 29 | #define TFM_PLATFORM_API_ID_IOCTL (1013) |
Galanakis, Minos | ef5118b | 2020-01-21 15:27:14 +0000 | [diff] [blame] | 30 | |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 31 | /*! |
| 32 | * \enum tfm_platform_err_t |
| 33 | * |
| 34 | * \brief Platform service error types |
| 35 | * |
| 36 | */ |
| 37 | enum tfm_platform_err_t { |
| 38 | TFM_PLATFORM_ERR_SUCCESS = 0, |
Mate Toth-Pal | 8af8b03 | 2019-07-18 10:49:00 +0200 | [diff] [blame] | 39 | TFM_PLATFORM_ERR_SYSTEM_ERROR, |
Tamas Kaman | 262dc7b | 2019-03-20 13:37:12 +0100 | [diff] [blame] | 40 | TFM_PLATFORM_ERR_INVALID_PARAM, |
Miklos Balint | c7b1b6c | 2019-04-24 12:38:36 +0200 | [diff] [blame] | 41 | TFM_PLATFORM_ERR_NOT_SUPPORTED, |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 42 | |
| 43 | /* Following entry is only to ensure the error code of int size */ |
| 44 | TFM_PLATFORM_ERR_FORCE_INT_SIZE = INT_MAX |
| 45 | }; |
| 46 | |
Miklos Balint | c7b1b6c | 2019-04-24 12:38:36 +0200 | [diff] [blame] | 47 | typedef int32_t tfm_platform_ioctl_req_t; |
| 48 | |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 49 | /*! |
| 50 | * \brief Resets the system. |
| 51 | * |
| 52 | * \return Returns values as specified by the \ref tfm_platform_err_t |
| 53 | */ |
| 54 | enum tfm_platform_err_t tfm_platform_system_reset(void); |
| 55 | |
Tamas Kaman | 262dc7b | 2019-03-20 13:37:12 +0100 | [diff] [blame] | 56 | /*! |
Miklos Balint | c7b1b6c | 2019-04-24 12:38:36 +0200 | [diff] [blame] | 57 | * \brief Performs a platform-specific service |
Tamas Kaman | 262dc7b | 2019-03-20 13:37:12 +0100 | [diff] [blame] | 58 | * |
Miklos Balint | c7b1b6c | 2019-04-24 12:38:36 +0200 | [diff] [blame] | 59 | * \param[in] request Request identifier (valid values vary |
Tamas Kaman | 262dc7b | 2019-03-20 13:37:12 +0100 | [diff] [blame] | 60 | * based on the platform) |
Miklos Balint | c7b1b6c | 2019-04-24 12:38:36 +0200 | [diff] [blame] | 61 | * \param[in] input Input buffer to the requested service (or NULL) |
| 62 | * \param[in,out] output Output buffer to the requested service (or NULL) |
Tamas Kaman | 262dc7b | 2019-03-20 13:37:12 +0100 | [diff] [blame] | 63 | * |
| 64 | * \return Returns values as specified by the \ref tfm_platform_err_t |
| 65 | */ |
Miklos Balint | c7b1b6c | 2019-04-24 12:38:36 +0200 | [diff] [blame] | 66 | enum tfm_platform_err_t tfm_platform_ioctl(tfm_platform_ioctl_req_t request, |
| 67 | psa_invec *input, |
| 68 | psa_outvec *output); |
Tamas Kaman | 262dc7b | 2019-03-20 13:37:12 +0100 | [diff] [blame] | 69 | |
Galanakis, Minos | ef5118b | 2020-01-21 15:27:14 +0000 | [diff] [blame] | 70 | /*! |
| 71 | * \brief Increments the given non-volatile (NV) counter by one |
| 72 | * |
| 73 | * \param[in] counter_id NV counter ID. |
| 74 | * |
| 75 | * \return TFM_PLATFORM_ERR_SUCCESS if the value is read correctly. Otherwise, |
| 76 | * it returns TFM_PLATFORM_ERR_SYSTEM_ERROR. |
| 77 | */ |
| 78 | enum tfm_platform_err_t |
| 79 | tfm_platform_nv_counter_increment(uint32_t counter_id); |
| 80 | |
| 81 | /*! |
| 82 | * \brief Reads the given non-volatile (NV) counter |
| 83 | * |
| 84 | * \param[in] counter_id NV counter ID. |
| 85 | * \param[in] size Size of the buffer to store NV counter value |
| 86 | * in bytes. |
| 87 | * \param[out] val Pointer to store the current NV counter value. |
| 88 | * |
| 89 | * \return TFM_PLATFORM_ERR_SUCCESS if the value is read correctly. Otherwise, |
| 90 | * it returns TFM_PLATFORM_ERR_SYSTEM_ERROR. |
| 91 | */ |
| 92 | enum tfm_platform_err_t |
| 93 | tfm_platform_nv_counter_read(uint32_t counter_id, |
| 94 | uint32_t size, uint8_t *val); |
Tamas Kaman | 262dc7b | 2019-03-20 13:37:12 +0100 | [diff] [blame] | 95 | |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 96 | #ifdef __cplusplus |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | #endif /* __TFM_PLATFORM_API__ */ |