Platform: Added a Non-Volatile counters service

This patch introduces a new platform service exposing
the non-volatile counters. Secure partitions can use
this secure API to access the initialisation,
increment and read operations on the nv counters,
by setting "TFM_SP_PLATFORM_NV_COUNTER" as a dependency.

Change-Id: Ia564e24417dfd9bb95cc61634dbbea17caa5974c
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
diff --git a/interface/include/psa_manifest/sid.h b/interface/include/psa_manifest/sid.h
index 4e9e440..4b9b8c9 100644
--- a/interface/include/psa_manifest/sid.h
+++ b/interface/include/psa_manifest/sid.h
@@ -45,6 +45,8 @@
 #define TFM_SP_PLATFORM_SYSTEM_RESET_VERSION                       (1U)
 #define TFM_SP_PLATFORM_IOCTL_SID                                  (0x00000041U)
 #define TFM_SP_PLATFORM_IOCTL_VERSION                              (1U)
+#define TFM_SP_PLATFORM_NV_COUNTER_SID                             (0x00000042U)
+#define TFM_SP_PLATFORM_NV_COUNTER_VERSION                         (1U)
 
 /******** TFM_SP_INITIAL_ATTESTATION ********/
 #define TFM_ATTEST_GET_TOKEN_SID                                   (0x00000020U)
diff --git a/interface/include/tfm_platform_api.h b/interface/include/tfm_platform_api.h
index fbbd757..8c9b0db 100644
--- a/interface/include/tfm_platform_api.h
+++ b/interface/include/tfm_platform_api.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -23,6 +23,9 @@
 #define TFM_PLATFORM_API_VERSION_MAJOR (0)
 #define TFM_PLATFORM_API_VERSION_MINOR (3)
 
+#define TFM_PLATFORM_API_ID_NV_READ       (1010)
+#define TFM_PLATFORM_API_ID_NV_INCREMENT  (1011)
+
 /*!
  * \enum tfm_platform_err_t
  *
@@ -62,6 +65,31 @@
                                            psa_invec *input,
                                            psa_outvec *output);
 
+/*!
+ * \brief Increments the given non-volatile (NV) counter by one
+ *
+ * \param[in]  counter_id  NV counter ID.
+ *
+ * \return  TFM_PLATFORM_ERR_SUCCESS if the value is read correctly. Otherwise,
+ *          it returns TFM_PLATFORM_ERR_SYSTEM_ERROR.
+ */
+enum tfm_platform_err_t
+tfm_platform_nv_counter_increment(uint32_t counter_id);
+
+/*!
+ * \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_PLATFORM_ERR_SUCCESS if the value is read correctly. Otherwise,
+ *          it returns TFM_PLATFORM_ERR_SYSTEM_ERROR.
+ */
+enum tfm_platform_err_t
+tfm_platform_nv_counter_read(uint32_t counter_id,
+                             uint32_t size, uint8_t *val);
 
 #ifdef __cplusplus
 }
diff --git a/interface/include/tfm_veneers.h b/interface/include/tfm_veneers.h
index 5f9c5b6..d2d9207 100644
--- a/interface/include/tfm_veneers.h
+++ b/interface/include/tfm_veneers.h
@@ -112,6 +112,8 @@
 /******** TFM_SP_PLATFORM ********/
 psa_status_t tfm_platform_sp_system_reset_veneer(psa_invec *in_vec, size_t in_len, psa_outvec *out_vec, size_t out_len);
 psa_status_t tfm_platform_sp_ioctl_veneer(psa_invec *in_vec, size_t in_len, psa_outvec *out_vec, size_t out_len);
+psa_status_t tfm_platform_sp_nv_counter_read_veneer(psa_invec *in_vec, size_t in_len, psa_outvec *out_vec, size_t out_len);
+psa_status_t tfm_platform_sp_nv_counter_increment_veneer(psa_invec *in_vec, size_t in_len, psa_outvec *out_vec, size_t out_len);
 #endif /* TFM_PARTITION_PLATFORM */
 
 #ifdef TFM_PARTITION_INITIAL_ATTESTATION