Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2012 ARM Ltd.
0004  * Author: Marc Zyngier <marc.zyngier@arm.com>
0005  */
0006 
0007 #ifndef __ASM_ARM_KVM_ARCH_TIMER_H
0008 #define __ASM_ARM_KVM_ARCH_TIMER_H
0009 
0010 #include <linux/clocksource.h>
0011 #include <linux/hrtimer.h>
0012 
0013 enum kvm_arch_timers {
0014     TIMER_PTIMER,
0015     TIMER_VTIMER,
0016     NR_KVM_TIMERS
0017 };
0018 
0019 enum kvm_arch_timer_regs {
0020     TIMER_REG_CNT,
0021     TIMER_REG_CVAL,
0022     TIMER_REG_TVAL,
0023     TIMER_REG_CTL,
0024 };
0025 
0026 struct arch_timer_context {
0027     struct kvm_vcpu         *vcpu;
0028 
0029     /* Timer IRQ */
0030     struct kvm_irq_level        irq;
0031 
0032     /* Emulated Timer (may be unused) */
0033     struct hrtimer          hrtimer;
0034 
0035     /*
0036      * We have multiple paths which can save/restore the timer state onto
0037      * the hardware, so we need some way of keeping track of where the
0038      * latest state is.
0039      */
0040     bool                loaded;
0041 
0042     /* Duplicated state from arch_timer.c for convenience */
0043     u32             host_timer_irq;
0044     u32             host_timer_irq_flags;
0045 };
0046 
0047 struct timer_map {
0048     struct arch_timer_context *direct_vtimer;
0049     struct arch_timer_context *direct_ptimer;
0050     struct arch_timer_context *emul_ptimer;
0051 };
0052 
0053 struct arch_timer_cpu {
0054     struct arch_timer_context timers[NR_KVM_TIMERS];
0055 
0056     /* Background timer used when the guest is not running */
0057     struct hrtimer          bg_timer;
0058 
0059     /* Is the timer enabled */
0060     bool            enabled;
0061 };
0062 
0063 int kvm_timer_hyp_init(bool);
0064 int kvm_timer_enable(struct kvm_vcpu *vcpu);
0065 int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu);
0066 void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu);
0067 void kvm_timer_sync_user(struct kvm_vcpu *vcpu);
0068 bool kvm_timer_should_notify_user(struct kvm_vcpu *vcpu);
0069 void kvm_timer_update_run(struct kvm_vcpu *vcpu);
0070 void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu);
0071 
0072 u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid);
0073 int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value);
0074 
0075 int kvm_arm_timer_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
0076 int kvm_arm_timer_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
0077 int kvm_arm_timer_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
0078 
0079 u64 kvm_phys_timer_read(void);
0080 
0081 void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu);
0082 void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu);
0083 
0084 void kvm_timer_init_vhe(void);
0085 
0086 bool kvm_arch_timer_get_input_level(int vintid);
0087 
0088 #define vcpu_timer(v)   (&(v)->arch.timer_cpu)
0089 #define vcpu_get_timer(v,t) (&vcpu_timer(v)->timers[(t)])
0090 #define vcpu_vtimer(v)  (&(v)->arch.timer_cpu.timers[TIMER_VTIMER])
0091 #define vcpu_ptimer(v)  (&(v)->arch.timer_cpu.timers[TIMER_PTIMER])
0092 
0093 #define arch_timer_ctx_index(ctx)   ((ctx) - vcpu_timer((ctx)->vcpu)->timers)
0094 
0095 u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu,
0096                   enum kvm_arch_timers tmr,
0097                   enum kvm_arch_timer_regs treg);
0098 void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu,
0099                 enum kvm_arch_timers tmr,
0100                 enum kvm_arch_timer_regs treg,
0101                 u64 val);
0102 
0103 /* Needed for tracing */
0104 u32 timer_get_ctl(struct arch_timer_context *ctxt);
0105 u64 timer_get_cval(struct arch_timer_context *ctxt);
0106 
0107 #endif