1 /*
2  * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __PS_NV_COUNTERS_H__
9 #define __PS_NV_COUNTERS_H__
10 
11 /* NOTE: This API abstracts PS NV counters operations. This API detaches the
12  *       use of NV counters from the TF-M NV counters implementation, provided
13  *       by the platform, and provides a mechanism to compile in a different
14  *       API implementation for test purposes. A PS test suite may provide
15  *       its own custom implementation to be able to test different PS service
16  *       use cases.
17  */
18 
19 #include <stdint.h>
20 #include "psa/protected_storage.h"
21 #include "tfm_plat_nv_counters.h"
22 
23 #define TFM_PS_NV_COUNTER_1        PLAT_NV_COUNTER_PS_0
24 #define TFM_PS_NV_COUNTER_2        PLAT_NV_COUNTER_PS_1
25 #define TFM_PS_NV_COUNTER_3        PLAT_NV_COUNTER_PS_2
26 
27 #define PS_NV_COUNTER_SIZE         4 /* In bytes */
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /**
34  * \brief Reads the given non-volatile (NV) counter.
35  *
36  * \param[in]  counter_id  NV counter ID.
37  * \param[out] val         Pointer to store the current NV counter value.
38  *
39  * \return  PSA_SUCCESS if the value is read correctly, otherwise
40  *          PSA_ERROR_GENERIC_ERROR
41  */
42 psa_status_t ps_read_nv_counter(enum tfm_nv_counter_t counter_id,
43                                 uint32_t *val);
44 
45 /**
46  * \brief Increments the given non-volatile (NV) counter.
47  *
48  * \param[in] counter_id  NV counter ID.
49  *
50  * \return  If the counter is incremented correctly, it returns
51  *          PSA_SUCCESS. Otherwise, PSA_ERROR_GENERIC_ERROR.
52  */
53 psa_status_t ps_increment_nv_counter(enum tfm_nv_counter_t counter_id);
54 
55 #ifdef __cplusplus
56 }
57 #endif
58 
59 #endif /* __PS_NV_COUNTERS_H__ */
60