| #ifndef __ASMARM_ARCH_TIMER_H |
| #define __ASMARM_ARCH_TIMER_H |
| |
| #include <linux/ioport.h> |
| #include <linux/clocksource.h> |
| #include <asm/errno.h> |
| |
| #define ARCH_TIMER_USR_PCT_ACCESS_EN (1 << 0) /* physical counter */ |
| #define ARCH_TIMER_USR_VCT_ACCESS_EN (1 << 1) /* virtual counter */ |
| #define ARCH_TIMER_VIRT_EVT_EN (1 << 2) |
| #define ARCH_TIMER_EVT_TRIGGER_SHIFT (4) |
| #define ARCH_TIMER_EVT_TRIGGER_MASK (0xF << ARCH_TIMER_EVT_TRIGGER_SHIFT) |
| #define ARCH_TIMER_USR_VT_ACCESS_EN (1 << 8) /* virtual timer registers */ |
| #define ARCH_TIMER_USR_PT_ACCESS_EN (1 << 9) /* physical timer registers */ |
| |
| struct arch_timer { |
| struct resource res[3]; |
| }; |
| |
| #ifdef CONFIG_ARM_ARCH_TIMER |
| int arch_timer_register(struct arch_timer *); |
| int arch_timer_of_register(void); |
| cycle_t arch_counter_get_cntpct(void); |
| |
| static inline u32 arch_timer_get_cntkctl(void) |
| { |
| u32 cntkctl; |
| asm volatile("mrc p15, 0, %0, c14, c1, 0" : "=r" (cntkctl)); |
| return cntkctl; |
| } |
| |
| static inline void arch_timer_set_cntkctl(u32 cntkctl) |
| { |
| asm volatile("mcr p15, 0, %0, c14, c1, 0" : : "r" (cntkctl)); |
| } |
| |
| static inline void arch_counter_set_user_access(void) |
| { |
| u32 cntkctl = arch_timer_get_cntkctl(); |
| |
| /* Disable user access to the timers and the physical counter */ |
| /* Also disable virtual event stream */ |
| cntkctl &= ~(ARCH_TIMER_USR_PT_ACCESS_EN |
| | ARCH_TIMER_USR_VT_ACCESS_EN |
| | ARCH_TIMER_VIRT_EVT_EN |
| | ARCH_TIMER_USR_PCT_ACCESS_EN); |
| |
| /* Enable user access to the virtual counter */ |
| if (IS_ENABLED(CONFIG_ARM_ARCH_TIMER_VCT_ACCESS)) |
| cntkctl |= ARCH_TIMER_USR_VCT_ACCESS_EN; |
| else |
| cntkctl &= ~ARCH_TIMER_USR_VCT_ACCESS_EN; |
| |
| arch_timer_set_cntkctl(cntkctl); |
| } |
| |
| static inline void arch_timer_evtstrm_enable(int divider) |
| { |
| u32 cntkctl = arch_timer_get_cntkctl(); |
| cntkctl &= ~ARCH_TIMER_EVT_TRIGGER_MASK; |
| /* Set the divider and enable virtual event stream */ |
| cntkctl |= (divider << ARCH_TIMER_EVT_TRIGGER_SHIFT) |
| | ARCH_TIMER_VIRT_EVT_EN; |
| arch_timer_set_cntkctl(cntkctl); |
| elf_hwcap |= HWCAP_EVTSTRM; |
| } |
| #else |
| static inline int arch_timer_register(struct arch_timer *at) |
| { |
| return -ENXIO; |
| } |
| |
| static inline int arch_timer_of_register(void) |
| { |
| return -ENXIO; |
| } |
| |
| static inline cycle_t arch_counter_get_cntpct(void) |
| { |
| return 0; |
| } |
| #endif |
| |
| #endif |