mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 00:48:50 +00:00
ec866be6ec
STIMER0 interrupts are most naturally modeled as per-cpu IRQs. But because x86/x64 doesn't have per-cpu IRQs, the core STIMER0 interrupt handling machinery is done in code under arch/x86 and Linux IRQs are not used. Adding support for ARM64 means adding equivalent code using per-cpu IRQs under arch/arm64. A better model is to treat per-cpu IRQs as the normal path (which it is for modern architectures), and the x86/x64 path as the exception. Do this by incorporating standard Linux per-cpu IRQ allocation into the main SITMER0 driver code, and bypass it in the x86/x64 exception case. For x86/x64, special case code is retained under arch/x86, but no STIMER0 interrupt handling code is needed under arch/arm64. No functional change. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/1614721102-2241-11-git-send-email-mikelley@microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
105 lines
2.9 KiB
C
105 lines
2.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
* Definitions for the clocksource provided by the Hyper-V
|
|
* hypervisor to guest VMs, as described in the Hyper-V Top
|
|
* Level Functional Spec (TLFS).
|
|
*
|
|
* Copyright (C) 2019, Microsoft, Inc.
|
|
*
|
|
* Author: Michael Kelley <mikelley@microsoft.com>
|
|
*/
|
|
|
|
#ifndef __CLKSOURCE_HYPERV_TIMER_H
|
|
#define __CLKSOURCE_HYPERV_TIMER_H
|
|
|
|
#include <linux/clocksource.h>
|
|
#include <linux/math64.h>
|
|
#include <asm/mshyperv.h>
|
|
|
|
#define HV_MAX_MAX_DELTA_TICKS 0xffffffff
|
|
#define HV_MIN_DELTA_TICKS 1
|
|
|
|
/* Routines called by the VMbus driver */
|
|
extern int hv_stimer_alloc(bool have_percpu_irqs);
|
|
extern int hv_stimer_cleanup(unsigned int cpu);
|
|
extern void hv_stimer_legacy_init(unsigned int cpu, int sint);
|
|
extern void hv_stimer_legacy_cleanup(unsigned int cpu);
|
|
extern void hv_stimer_global_cleanup(void);
|
|
extern void hv_stimer0_isr(void);
|
|
|
|
#ifdef CONFIG_HYPERV_TIMER
|
|
extern u64 (*hv_read_reference_counter)(void);
|
|
extern void hv_init_clocksource(void);
|
|
|
|
extern struct ms_hyperv_tsc_page *hv_get_tsc_page(void);
|
|
|
|
static inline notrace u64
|
|
hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg, u64 *cur_tsc)
|
|
{
|
|
u64 scale, offset;
|
|
u32 sequence;
|
|
|
|
/*
|
|
* The protocol for reading Hyper-V TSC page is specified in Hypervisor
|
|
* Top-Level Functional Specification ver. 3.0 and above. To get the
|
|
* reference time we must do the following:
|
|
* - READ ReferenceTscSequence
|
|
* A special '0' value indicates the time source is unreliable and we
|
|
* need to use something else. The currently published specification
|
|
* versions (up to 4.0b) contain a mistake and wrongly claim '-1'
|
|
* instead of '0' as the special value, see commit c35b82ef0294.
|
|
* - ReferenceTime =
|
|
* ((RDTSC() * ReferenceTscScale) >> 64) + ReferenceTscOffset
|
|
* - READ ReferenceTscSequence again. In case its value has changed
|
|
* since our first reading we need to discard ReferenceTime and repeat
|
|
* the whole sequence as the hypervisor was updating the page in
|
|
* between.
|
|
*/
|
|
do {
|
|
sequence = READ_ONCE(tsc_pg->tsc_sequence);
|
|
if (!sequence)
|
|
return U64_MAX;
|
|
/*
|
|
* Make sure we read sequence before we read other values from
|
|
* TSC page.
|
|
*/
|
|
smp_rmb();
|
|
|
|
scale = READ_ONCE(tsc_pg->tsc_scale);
|
|
offset = READ_ONCE(tsc_pg->tsc_offset);
|
|
*cur_tsc = hv_get_raw_timer();
|
|
|
|
/*
|
|
* Make sure we read sequence after we read all other values
|
|
* from TSC page.
|
|
*/
|
|
smp_rmb();
|
|
|
|
} while (READ_ONCE(tsc_pg->tsc_sequence) != sequence);
|
|
|
|
return mul_u64_u64_shr(*cur_tsc, scale, 64) + offset;
|
|
}
|
|
|
|
static inline notrace u64
|
|
hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg)
|
|
{
|
|
u64 cur_tsc;
|
|
|
|
return hv_read_tsc_page_tsc(tsc_pg, &cur_tsc);
|
|
}
|
|
|
|
#else /* CONFIG_HYPERV_TIMER */
|
|
static inline struct ms_hyperv_tsc_page *hv_get_tsc_page(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg,
|
|
u64 *cur_tsc)
|
|
{
|
|
return U64_MAX;
|
|
}
|
|
#endif /* CONFIG_HYPERV_TIMER */
|
|
|
|
#endif
|