Commit a1b2dde7 authored by Marc Zyngier's avatar Marc Zyngier Committed by Russell King

ARM: 7522/1: arch_timers: register a time/cycle counter

Some subsystems (KVM for example) need access to a cycle counter.
In the KVM case, this is used to measure the time delta between
host and guest in order to accurately generate timer events for
the guest.
Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent f48b5f12
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
#define __ASMARM_ARCH_TIMER_H #define __ASMARM_ARCH_TIMER_H
#include <asm/errno.h> #include <asm/errno.h>
#include <linux/clocksource.h>
#ifdef CONFIG_ARM_ARCH_TIMER #ifdef CONFIG_ARM_ARCH_TIMER
#define ARCH_HAS_READ_CURRENT_TIMER #define ARCH_HAS_READ_CURRENT_TIMER
int arch_timer_of_register(void); int arch_timer_of_register(void);
int arch_timer_sched_clock_init(void); int arch_timer_sched_clock_init(void);
struct timecounter *arch_timer_get_timecounter(void);
#else #else
static inline int arch_timer_of_register(void) static inline int arch_timer_of_register(void)
{ {
...@@ -17,6 +19,11 @@ static inline int arch_timer_sched_clock_init(void) ...@@ -17,6 +19,11 @@ static inline int arch_timer_sched_clock_init(void)
{ {
return -ENXIO; return -ENXIO;
} }
static inline struct timecounter *arch_timer_get_timecounter(void)
{
return NULL;
}
#endif #endif
#endif #endif
...@@ -333,6 +333,15 @@ int read_current_timer(unsigned long *timer_val) ...@@ -333,6 +333,15 @@ int read_current_timer(unsigned long *timer_val)
return 0; return 0;
} }
static cycle_t arch_counter_read_cc(const struct cyclecounter *cc)
{
/*
* Always use the physical counter for the clocksource.
* CNTHCTL.PL1PCTEN must be set to 1.
*/
return arch_counter_get_cntpct();
}
static struct clocksource clocksource_counter = { static struct clocksource clocksource_counter = {
.name = "arch_sys_counter", .name = "arch_sys_counter",
.rating = 400, .rating = 400,
...@@ -341,6 +350,18 @@ static struct clocksource clocksource_counter = { ...@@ -341,6 +350,18 @@ static struct clocksource clocksource_counter = {
.flags = CLOCK_SOURCE_IS_CONTINUOUS, .flags = CLOCK_SOURCE_IS_CONTINUOUS,
}; };
static struct cyclecounter cyclecounter = {
.read = arch_counter_read_cc,
.mask = CLOCKSOURCE_MASK(56),
};
static struct timecounter timecounter;
struct timecounter *arch_timer_get_timecounter(void)
{
return &timecounter;
}
static void __cpuinit arch_timer_stop(struct clock_event_device *clk) static void __cpuinit arch_timer_stop(struct clock_event_device *clk)
{ {
pr_debug("arch_timer_teardown disable IRQ%d cpu #%d\n", pr_debug("arch_timer_teardown disable IRQ%d cpu #%d\n",
...@@ -380,6 +401,10 @@ static int __init arch_timer_register(void) ...@@ -380,6 +401,10 @@ static int __init arch_timer_register(void)
} }
clocksource_register_hz(&clocksource_counter, arch_timer_rate); clocksource_register_hz(&clocksource_counter, arch_timer_rate);
cyclecounter.mult = clocksource_counter.mult;
cyclecounter.shift = clocksource_counter.shift;
timecounter_init(&timecounter, &cyclecounter,
arch_counter_get_cntpct());
if (arch_timer_use_virtual) { if (arch_timer_use_virtual) {
ppi = arch_timer_ppi[VIRT_PPI]; ppi = arch_timer_ppi[VIRT_PPI];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment