diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h index 57c7618..5cf828e 100644 --- a/arch/arm/include/asm/system.h +++ b/arch/arm/include/asm/system.h @@ -77,6 +77,30 @@ return val; } + +static inline void set_cntfrq(unsigned long cntfrq) +{ + asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory"); +} + +static inline unsigned long get_cntfrq(void) +{ + unsigned long cntfrq; + + asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq)); + return cntfrq; +} + +static inline unsigned long get_cntpct(void) +{ + unsigned long cntpct; + + isb(); + asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct)); + + return cntpct; +} + #endif static inline unsigned int get_cr(void) { diff --git a/drivers/clocksource/armv8-timer.c b/drivers/clocksource/armv8-timer.c index 57b0b69..c5306dc 100644 --- a/drivers/clocksource/armv8-timer.c +++ b/drivers/clocksource/armv8-timer.c @@ -22,12 +22,7 @@ uint64_t armv8_clocksource_read(void) { - unsigned long cntpct; - - isb(); - asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct)); - - return cntpct; + return get_cntpct(); } static struct clocksource cs = { @@ -38,11 +33,7 @@ static int armv8_timer_probe(struct device_d *dev) { - unsigned long cntfrq; - - asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq)); - - cs.mult = clocksource_hz2mult(cntfrq, cs.shift); + cs.mult = clocksource_hz2mult(get_cntfrq(), cs.shift); return init_clock(&cs); }