diff options
-rw-r--r-- | include/lib/aarch32/arch_helpers.h | 12 | ||||
-rw-r--r-- | include/lib/aarch64/arch_helpers.h | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/include/lib/aarch32/arch_helpers.h b/include/lib/aarch32/arch_helpers.h index ee7ed3145..3e6e6f9cc 100644 --- a/include/lib/aarch32/arch_helpers.h +++ b/include/lib/aarch32/arch_helpers.h @@ -442,4 +442,16 @@ static inline void disable_fiq(void) void disable_mmu_icache(void); +/* Read the count value of the system counter. */ +static inline uint64_t syscounter_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 read64_cntpct(); +} + #endif /* ARCH_HELPERS_H */ diff --git a/include/lib/aarch64/arch_helpers.h b/include/lib/aarch64/arch_helpers.h index 1d9202d04..053f8ba67 100644 --- a/include/lib/aarch64/arch_helpers.h +++ b/include/lib/aarch64/arch_helpers.h @@ -468,4 +468,16 @@ static inline uint64_t el_implemented(unsigned int el) } } +/* Read the count value of the system counter. */ +static inline uint64_t syscounter_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_cntpct_el0(); +} + #endif /* ARCH_HELPERS_H */ |