Platform: Extend NV counter interface

This patch adds the tfm_plat_set_nv_counter() function to the NV counter
interface for supported platforms: AN521, AN519, Musca-A and Musca-B1.
To set a NV counter to a specified value can take a lot of time and
leads to early flash wear out when incrementing the counter by one.

Change-Id: I8702de54d373aff3201669540c541a24815cf09b
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/platform/include/tfm_plat_nv_counters.h b/platform/include/tfm_plat_nv_counters.h
index d79c235..9b86112 100644
--- a/platform/include/tfm_plat_nv_counters.h
+++ b/platform/include/tfm_plat_nv_counters.h
@@ -13,6 +13,14 @@
  *
  * \note The interfaces defined in this file must be implemented for each
  *       SoC.
+ * \note The interface must be implemented in a fail-safe way that is
+ *       resistant to asynchronous power failures or it can use hardware
+ *       counters that have this capability, if supported by the platform.
+ *       When a counter incrementation was interrupted it must be able to
+ *       continue the incrementation process or recover the previous consistent
+ *       status of the counters. If the counters have reached a stable status
+ *       (every counter incrementation operation has finished), from that point
+ *       their value cannot decrease due to any kind of power failure.
  */
 
 #include <stdint.h>
@@ -64,6 +72,31 @@
 enum tfm_plat_err_t tfm_plat_increment_nv_counter(
                                               enum tfm_nv_counter_t counter_id);
 
+/**
+ * \brief Sets the given non-volatile (NV) counter to the specified value.
+ *
+ * \param[in] counter_id  NV counter ID.
+ * \param[in] value       New value of the NV counter. The maximum value that
+ *                        can be set depends on the constraints of the
+ *                        underlying implementation, but it always must be
+ *                        greater than or equal to the current NV counter value.
+ *
+ * \retval TFM_PLAT_ERR_SUCCESS         The NV counter is set successfully
+ * \retval TFM_PLAT_ERR_INVALID_INPUT   The new value is less than the current
+ *                                      counter value
+ * \retval TFM_PLAT_ERR_MAX_VALUE       The new value is greater than the
+ *                                      maximum value of the NV counter
+ * \retval TFM_PLAT_ERR_UNSUPPORTED     The function is not implemented for
+ *                                      the given platform or the new value is
+ *                                      not representable on the underlying
+ *                                      counter implementation
+ * \retval TFM_PLAT_ERR_SYSTEM_ERR      An unspecified error occurred
+ *                                      (none of the other standard error codes
+ *                                      are applicable)
+ */
+enum tfm_plat_err_t tfm_plat_set_nv_counter(enum tfm_nv_counter_t counter_id,
+                                            uint32_t value);
+
 #ifdef __cplusplus
 }
 #endif