feat: add helper functions for SP sleep

This patch introduces new helper utilities: virtualcounter_read() and
sp_sleep_elapsed_time() which are further used in sp_sleep() utility.

This patch also adds a needed isb when reading the virtual counter,
to prevent reading stale values, as well as reducing the number of
reads of the virtual counter required. Refer Arm ARM D11.2.2

Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
Change-Id: Icaf1777e85ee2efc043bfa83d630edf54bf5a099
diff --git a/include/lib/aarch64/arch_helpers.h b/include/lib/aarch64/arch_helpers.h
index 696cd01..8287422 100644
--- a/include/lib/aarch64/arch_helpers.h
+++ b/include/lib/aarch64/arch_helpers.h
@@ -562,4 +562,16 @@
 	return read_cntpct_el0();
 }
 
+/* Read the value of the Counter-timer virtual count. */
+static inline uint64_t virtualcounter_read(void)
+{
+	/*
+	 * The instruction barrier is needed to guarantee that we read an
+	 * accurate value. Otherwise, the CPU might speculatively read it and
+	 * return a stale value.
+	 */
+	isb();
+	return read_cntvct_el0();
+}
+
 #endif /* ARCH_HELPERS_H */