Platform: Add NV counter interface
This patch adds the TF-M non-volatile(NV) counter interface.
Change-Id: I2b87dfadf9c53bd755f26867de678a4e837bbdcb
Signed-off-by: Marc Moreno <marc.morenoberengue@arm.com>
diff --git a/platform/ext/readme.md b/platform/ext/readme.md
index 55c9057..78c465a 100644
--- a/platform/ext/readme.md
+++ b/platform/ext/readme.md
@@ -116,6 +116,16 @@
**Note**: The sectors must be consecutive.
+## Expose target support for HW components
+
+Services may require HW components to be supported by the target
+to enable some features (e.g. SST service with rollback protection, etc).
+The following definitions need to be set in the <TARGET_NAME>.cmake file if the
+target has the following HW components:
+
+ - `TARGET_NV_COUNTERS_ENABLE`
+ Specifies that the target has non-volatile (NV) counters.
+
--------------
*Copyright (c) 2017-2018, Arm Limited. All rights reserved.*
diff --git a/platform/include/tfm_plat_defs.h b/platform/include/tfm_plat_defs.h
index 308b002..5b6d169 100644
--- a/platform/include/tfm_plat_defs.h
+++ b/platform/include/tfm_plat_defs.h
@@ -18,6 +18,7 @@
enum tfm_plat_err_t {
TFM_PLAT_ERR_SUCCESS = 0,
TFM_PLAT_ERR_SYSTEM_ERR,
+ TFM_PLAT_ERR_MAX_VALUE,
/* Following entry is only to ensure the error code of int size */
TFM_PLAT_ERR_FORCE_INT_SIZE = INT_MAX
};
diff --git a/platform/include/tfm_plat_nv_counters.h b/platform/include/tfm_plat_nv_counters.h
new file mode 100644
index 0000000..c987ed7
--- /dev/null
+++ b/platform/include/tfm_plat_nv_counters.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_PLAT_NV_COUNTERS_H__
+#define __TFM_PLAT_NV_COUNTERS_H__
+
+/**
+ * \file tfm_plat_nv_counters.h
+ *
+ * \note The interfaces defined in this file must be implemented for each
+ * SoC.
+ */
+
+#include <stdint.h>
+#include "tfm_plat_defs.h"
+
+enum tfm_nv_counter_t {
+ TFM_SST_NV_COUNTER_1 = 0,
+ TFM_SST_NV_COUNTER_2,
+ TFM_SST_NV_COUNTER_3,
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Initialises all non-volatile (NV) counters.
+ *
+ * \return TFM_PLAT_ERR_SUCCESS if the initialization succeeds, otherwise
+ * TFM_PLAT_ERR_SYSTEM_ERR
+ */
+enum tfm_plat_err_t tfm_plat_init_nv_counter(void);
+
+/**
+ * \brief Reads the given non-volatile (NV) counter.
+ *
+ * \param[in] counter_id NV counter ID.
+ * \param[in] size Size of the buffer to store NV counter value
+ * in bytes.
+ * \param[out] val Pointer to store the current NV counter value.
+ *
+ * \return TFM_PLAT_ERR_SUCCESS if the value is read correctly. Otherwise,
+ * it returns TFM_PLAT_ERR_SYSTEM_ERR.
+ */
+enum tfm_plat_err_t tfm_plat_read_nv_counter(enum tfm_nv_counter_t counter_id,
+ uint32_t size, uint8_t *val);
+
+/**
+ * \brief Increments the given non-volatile (NV) counter.
+ *
+ * \param[in] counter_id NV counter ID.
+ *
+ * \return When the NV counter reaches its maximum value, the
+ * TFM_PLAT_ERR_MAX_VALUE error is returned to indicate the value
+ * cannot be incremented. Otherwise, it returns TFM_PLAT_ERR_SUCCESS.
+ */
+enum tfm_plat_err_t tfm_plat_increment_nv_counter(
+ enum tfm_nv_counter_t counter_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_PLAT_NV_COUNTERS_H__ */