blob: d79c235715b30546787b06656139c40d32051f5d [file] [log] [blame]
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +01001/*
David Vincze2dbfab52019-05-10 14:39:01 +02002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +01003 *
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
21enum tfm_nv_counter_t {
David Vincze2dbfab52019-05-10 14:39:01 +020022 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 Vinczefc6d5f12019-03-19 17:44:30 +010025 PLAT_NV_COUNTER_3, /* Used by bootloader */
26 PLAT_NV_COUNTER_MAX
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010027};
28
29#ifdef __cplusplus
30extern "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 */
39enum 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 */
52enum 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 */
64enum 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__ */