Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 1 | /* |
David Vincze | 2dbfab5 | 2019-05-10 14:39:01 +0200 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __TFM_PLAT_NV_COUNTERS_H__ |
| 9 | #define __TFM_PLAT_NV_COUNTERS_H__ |
| 10 | |
| 11 | /** |
| 12 | * \file tfm_plat_nv_counters.h |
| 13 | * |
| 14 | * \note The interfaces defined in this file must be implemented for each |
| 15 | * SoC. |
| 16 | */ |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | #include "tfm_plat_defs.h" |
| 20 | |
| 21 | enum tfm_nv_counter_t { |
David Vincze | 2dbfab5 | 2019-05-10 14:39:01 +0200 | [diff] [blame] | 22 | PLAT_NV_COUNTER_0 = 0, /* Used by SST service */ |
| 23 | PLAT_NV_COUNTER_1, /* Used by SST service */ |
| 24 | PLAT_NV_COUNTER_2, /* Used by SST service */ |
David Vincze | fc6d5f1 | 2019-03-19 17:44:30 +0100 | [diff] [blame^] | 25 | PLAT_NV_COUNTER_3, /* Used by bootloader */ |
| 26 | PLAT_NV_COUNTER_MAX |
Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | #ifdef __cplusplus |
| 30 | extern "C" { |
| 31 | #endif |
| 32 | |
| 33 | /** |
| 34 | * \brief Initialises all non-volatile (NV) counters. |
| 35 | * |
| 36 | * \return TFM_PLAT_ERR_SUCCESS if the initialization succeeds, otherwise |
| 37 | * TFM_PLAT_ERR_SYSTEM_ERR |
| 38 | */ |
| 39 | enum tfm_plat_err_t tfm_plat_init_nv_counter(void); |
| 40 | |
| 41 | /** |
| 42 | * \brief Reads the given non-volatile (NV) counter. |
| 43 | * |
| 44 | * \param[in] counter_id NV counter ID. |
| 45 | * \param[in] size Size of the buffer to store NV counter value |
| 46 | * in bytes. |
| 47 | * \param[out] val Pointer to store the current NV counter value. |
| 48 | * |
| 49 | * \return TFM_PLAT_ERR_SUCCESS if the value is read correctly. Otherwise, |
| 50 | * it returns TFM_PLAT_ERR_SYSTEM_ERR. |
| 51 | */ |
| 52 | enum tfm_plat_err_t tfm_plat_read_nv_counter(enum tfm_nv_counter_t counter_id, |
| 53 | uint32_t size, uint8_t *val); |
| 54 | |
| 55 | /** |
| 56 | * \brief Increments the given non-volatile (NV) counter. |
| 57 | * |
| 58 | * \param[in] counter_id NV counter ID. |
| 59 | * |
| 60 | * \return When the NV counter reaches its maximum value, the |
| 61 | * TFM_PLAT_ERR_MAX_VALUE error is returned to indicate the value |
| 62 | * cannot be incremented. Otherwise, it returns TFM_PLAT_ERR_SUCCESS. |
| 63 | */ |
| 64 | enum tfm_plat_err_t tfm_plat_increment_nv_counter( |
| 65 | enum tfm_nv_counter_t counter_id); |
| 66 | |
| 67 | #ifdef __cplusplus |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | #endif /* __TFM_PLAT_NV_COUNTERS_H__ */ |