2012-11-20 18:06:00 +08:00
|
|
|
/*
|
|
|
|
* arch/arm64/include/asm/arch_timer.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
* Author: Marc Zyngier <marc.zyngier@arm.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_ARCH_TIMER_H
|
|
|
|
#define __ASM_ARCH_TIMER_H
|
|
|
|
|
|
|
|
#include <asm/barrier.h>
|
2016-09-08 20:55:35 +08:00
|
|
|
#include <asm/sysreg.h>
|
2012-11-20 18:06:00 +08:00
|
|
|
|
2015-01-06 08:38:41 +08:00
|
|
|
#include <linux/bug.h>
|
2012-11-20 18:06:00 +08:00
|
|
|
#include <linux/init.h>
|
2016-09-22 16:35:17 +08:00
|
|
|
#include <linux/jump_label.h>
|
2017-02-21 02:34:48 +08:00
|
|
|
#include <linux/smp.h>
|
2012-11-20 18:06:00 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
#include <clocksource/arm_arch_timer.h>
|
|
|
|
|
2017-02-07 00:47:41 +08:00
|
|
|
#if IS_ENABLED(CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND)
|
2016-09-22 16:35:17 +08:00
|
|
|
extern struct static_key_false arch_timer_read_ool_enabled;
|
2017-02-07 00:47:41 +08:00
|
|
|
#define needs_unstable_timer_counter_workaround() \
|
2016-09-22 16:35:17 +08:00
|
|
|
static_branch_unlikely(&arch_timer_read_ool_enabled)
|
|
|
|
#else
|
2017-02-07 00:47:41 +08:00
|
|
|
#define needs_unstable_timer_counter_workaround() false
|
2016-09-22 16:35:17 +08:00
|
|
|
#endif
|
|
|
|
|
2017-01-20 01:20:59 +08:00
|
|
|
enum arch_timer_erratum_match_type {
|
|
|
|
ate_match_dt,
|
2017-03-21 00:47:59 +08:00
|
|
|
ate_match_local_cap_id,
|
2017-01-20 01:20:59 +08:00
|
|
|
};
|
2016-09-22 16:35:17 +08:00
|
|
|
|
2017-01-27 18:27:09 +08:00
|
|
|
struct clock_event_device;
|
|
|
|
|
2017-02-07 00:47:41 +08:00
|
|
|
struct arch_timer_erratum_workaround {
|
2017-01-20 01:20:59 +08:00
|
|
|
enum arch_timer_erratum_match_type match_type;
|
|
|
|
const void *id;
|
|
|
|
const char *desc;
|
2017-02-07 00:47:41 +08:00
|
|
|
u32 (*read_cntp_tval_el0)(void);
|
|
|
|
u32 (*read_cntv_tval_el0)(void);
|
|
|
|
u64 (*read_cntvct_el0)(void);
|
2017-01-27 18:27:09 +08:00
|
|
|
int (*set_next_event_phys)(unsigned long, struct clock_event_device *);
|
|
|
|
int (*set_next_event_virt)(unsigned long, struct clock_event_device *);
|
2017-02-07 00:47:41 +08:00
|
|
|
};
|
|
|
|
|
2017-02-21 02:34:48 +08:00
|
|
|
DECLARE_PER_CPU(const struct arch_timer_erratum_workaround *,
|
|
|
|
timer_unstable_counter_workaround);
|
2016-09-22 16:35:17 +08:00
|
|
|
|
2017-02-21 02:34:48 +08:00
|
|
|
#define arch_timer_reg_read_stable(reg) \
|
|
|
|
({ \
|
|
|
|
u64 _val; \
|
|
|
|
if (needs_unstable_timer_counter_workaround()) { \
|
|
|
|
const struct arch_timer_erratum_workaround *wa; \
|
|
|
|
preempt_disable(); \
|
|
|
|
wa = __this_cpu_read(timer_unstable_counter_workaround); \
|
|
|
|
if (wa && wa->read_##reg) \
|
|
|
|
_val = wa->read_##reg(); \
|
|
|
|
else \
|
|
|
|
_val = read_sysreg(reg); \
|
|
|
|
preempt_enable(); \
|
|
|
|
} else { \
|
|
|
|
_val = read_sysreg(reg); \
|
|
|
|
} \
|
|
|
|
_val; \
|
2016-09-22 16:35:17 +08:00
|
|
|
})
|
|
|
|
|
2013-07-19 07:59:28 +08:00
|
|
|
/*
|
|
|
|
* These register accessors are marked inline so the compiler can
|
|
|
|
* nicely work out which register we want, and chuck away the rest of
|
|
|
|
* the code.
|
|
|
|
*/
|
|
|
|
static __always_inline
|
2013-07-19 07:59:31 +08:00
|
|
|
void arch_timer_reg_write_cp15(int access, enum arch_timer_reg reg, u32 val)
|
2012-11-20 18:06:00 +08:00
|
|
|
{
|
|
|
|
if (access == ARCH_TIMER_PHYS_ACCESS) {
|
|
|
|
switch (reg) {
|
|
|
|
case ARCH_TIMER_REG_CTRL:
|
2016-09-08 20:55:35 +08:00
|
|
|
write_sysreg(val, cntp_ctl_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
break;
|
|
|
|
case ARCH_TIMER_REG_TVAL:
|
2016-09-08 20:55:35 +08:00
|
|
|
write_sysreg(val, cntp_tval_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (access == ARCH_TIMER_VIRT_ACCESS) {
|
|
|
|
switch (reg) {
|
|
|
|
case ARCH_TIMER_REG_CTRL:
|
2016-09-08 20:55:35 +08:00
|
|
|
write_sysreg(val, cntv_ctl_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
break;
|
|
|
|
case ARCH_TIMER_REG_TVAL:
|
2016-09-08 20:55:35 +08:00
|
|
|
write_sysreg(val, cntv_tval_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isb();
|
|
|
|
}
|
|
|
|
|
2013-07-19 07:59:28 +08:00
|
|
|
static __always_inline
|
2013-07-19 07:59:31 +08:00
|
|
|
u32 arch_timer_reg_read_cp15(int access, enum arch_timer_reg reg)
|
2012-11-20 18:06:00 +08:00
|
|
|
{
|
|
|
|
if (access == ARCH_TIMER_PHYS_ACCESS) {
|
|
|
|
switch (reg) {
|
|
|
|
case ARCH_TIMER_REG_CTRL:
|
2016-09-08 20:55:35 +08:00
|
|
|
return read_sysreg(cntp_ctl_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
case ARCH_TIMER_REG_TVAL:
|
2016-09-22 16:35:17 +08:00
|
|
|
return arch_timer_reg_read_stable(cntp_tval_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
}
|
|
|
|
} else if (access == ARCH_TIMER_VIRT_ACCESS) {
|
|
|
|
switch (reg) {
|
|
|
|
case ARCH_TIMER_REG_CTRL:
|
2016-09-08 20:55:35 +08:00
|
|
|
return read_sysreg(cntv_ctl_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
case ARCH_TIMER_REG_TVAL:
|
2016-09-22 16:35:17 +08:00
|
|
|
return arch_timer_reg_read_stable(cntv_tval_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 20:55:35 +08:00
|
|
|
BUG();
|
2012-11-20 18:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 arch_timer_get_cntfrq(void)
|
|
|
|
{
|
2016-09-08 20:55:35 +08:00
|
|
|
return read_sysreg(cntfrq_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
}
|
|
|
|
|
2013-08-13 22:57:53 +08:00
|
|
|
static inline u32 arch_timer_get_cntkctl(void)
|
2012-11-20 18:06:00 +08:00
|
|
|
{
|
2016-09-08 20:55:35 +08:00
|
|
|
return read_sysreg(cntkctl_el1);
|
2013-08-13 22:57:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void arch_timer_set_cntkctl(u32 cntkctl)
|
|
|
|
{
|
2016-09-08 20:55:35 +08:00
|
|
|
write_sysreg(cntkctl, cntkctl_el1);
|
2013-08-13 22:57:53 +08:00
|
|
|
}
|
|
|
|
|
2014-11-24 15:02:44 +08:00
|
|
|
static inline u64 arch_counter_get_cntpct(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* AArch64 kernel and user space mandate the use of CNTVCT.
|
|
|
|
*/
|
|
|
|
BUG();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:06:00 +08:00
|
|
|
static inline u64 arch_counter_get_cntvct(void)
|
|
|
|
{
|
|
|
|
isb();
|
2016-09-22 16:35:17 +08:00
|
|
|
return arch_timer_reg_read_stable(cntvct_el0);
|
2012-11-20 18:06:00 +08:00
|
|
|
}
|
|
|
|
|
2013-04-11 07:27:51 +08:00
|
|
|
static inline int arch_timer_arch_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:06:00 +08:00
|
|
|
#endif
|