|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [PATCH v3 35/43] arm64: implement the timer helpers for arm64
Implement the timer helpers:
read_virtual_count/write_timer_ctl/set_vtimer_compare()/read_frequency().
This patch also removes the arm32 timer code.
Signed-off-by: Huang Shijie <shijie.huang@xxxxxxx>
---
arch/arm/time.c | 27 ++-------------------------
include/arm/arm64/time.h | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 25 deletions(-)
create mode 100644 include/arm/arm64/time.h
diff --git a/arch/arm/time.c b/arch/arm/time.c
index 8d68cf0..4c355cc 100644
--- a/arch/arm/time.c
+++ b/arch/arm/time.c
@@ -6,6 +6,7 @@
#include <mini-os/time.h>
#include <mini-os/lib.h>
#include <inttypes.h>
+#include <mini-os/arm64/time.h>
//#define VTIMER_DEBUG
#ifdef VTIMER_DEBUG
@@ -57,13 +58,6 @@ static inline uint64_t ns_to_ticks(s_time_t ns)
*/
static struct timespec shadow_ts;
-static inline uint64_t read_virtual_count(void)
-{
- uint32_t c_lo, c_hi;
- __asm__ __volatile__("mrrc p15, 1, %0, %1, c14":"=r"(c_lo), "=r"(c_hi));
- return (((uint64_t) c_hi) << 32) + c_lo;
-}
-
/* monotonic_clock(): returns # of nanoseconds passed since time_init()
* Note: This function is required to return accurate
* time even in the absence of multiple timer ticks.
@@ -85,23 +79,6 @@ int gettimeofday(struct timeval *tv, void *tz)
return 0;
}
-/* Set the timer and mask. */
-void write_timer_ctl(uint32_t value) {
- __asm__ __volatile__(
- "mcr p15, 0, %0, c14, c3, 1\n"
- "isb"::"r"(value));
-}
-
-void set_vtimer_compare(uint64_t value) {
- DEBUG("New CompareValue : %llx\n", value);
-
- __asm__ __volatile__("mcrr p15, 3, %0, %H0, c14"
- ::"r"(value));
-
- /* Enable timer and unmask the output signal */
- write_timer_ctl(1);
-}
-
void unset_vtimer_compare(void) {
/* Disable timer and mask the output signal */
write_timer_ctl(2);
@@ -127,7 +104,7 @@ void init_time(void)
{
printk("Initialising timer interface\n");
- __asm__ __volatile__("mrc p15, 0, %0, c14, c0, 0":"=r"(counter_freq));
+ counter_freq = read_frequency();
cntvct_at_init = read_virtual_count();
printk("Virtual Count register is %"PRIX64", freq = %d Hz\n",
cntvct_at_init, counter_freq);
diff --git a/include/arm/arm64/time.h b/include/arm/arm64/time.h
new file mode 100644
index 0000000..3b309af
--- /dev/null
+++ b/include/arm/arm64/time.h
@@ -0,0 +1,34 @@
+#ifndef __ARM64_TIME_H
+#define __ARM64_TIME_H
+
+static inline uint64_t read_virtual_count(void)
+{
+ uint64_t c;
+
+ __asm__ __volatile__("mrs %0, cntvct_el0":"=r"(c));
+ return c;
+}
+
+/* Set the timer and mask. */
+static inline void write_timer_ctl(uint32_t value)
+{
+ __asm__ __volatile__("msr cntv_ctl_el0, %0" :: "r" (value));
+}
+
+static inline void set_vtimer_compare(uint64_t value)
+{
+ __asm__ __volatile__("msr cntv_cval_el0, %0" : : "r" (value));
+
+ /* Enable timer and unmask the output signal */
+ write_timer_ctl(1);
+}
+
+static inline uint32_t read_frequency(void)
+{
+ uint32_t counter_freq;
+
+ __asm__ __volatile__("mrs %0, cntfrq_el0":"=r"(counter_freq));
+ return counter_freq;
+}
+
+#endif
--
2.7.4
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |