arm_arch_timer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. * Author: Marc Zyngier <[email protected]>
  5. */
  6. #ifndef __ASM_ARM_KVM_ARCH_TIMER_H
  7. #define __ASM_ARM_KVM_ARCH_TIMER_H
  8. #include <linux/clocksource.h>
  9. #include <linux/hrtimer.h>
  10. enum kvm_arch_timers {
  11. TIMER_PTIMER,
  12. TIMER_VTIMER,
  13. NR_KVM_TIMERS
  14. };
  15. enum kvm_arch_timer_regs {
  16. TIMER_REG_CNT,
  17. TIMER_REG_CVAL,
  18. TIMER_REG_TVAL,
  19. TIMER_REG_CTL,
  20. };
  21. struct arch_timer_context {
  22. struct kvm_vcpu *vcpu;
  23. /* Timer IRQ */
  24. struct kvm_irq_level irq;
  25. /* Emulated Timer (may be unused) */
  26. struct hrtimer hrtimer;
  27. /*
  28. * We have multiple paths which can save/restore the timer state onto
  29. * the hardware, so we need some way of keeping track of where the
  30. * latest state is.
  31. */
  32. bool loaded;
  33. /* Duplicated state from arch_timer.c for convenience */
  34. u32 host_timer_irq;
  35. u32 host_timer_irq_flags;
  36. };
  37. struct timer_map {
  38. struct arch_timer_context *direct_vtimer;
  39. struct arch_timer_context *direct_ptimer;
  40. struct arch_timer_context *emul_ptimer;
  41. };
  42. struct arch_timer_cpu {
  43. struct arch_timer_context timers[NR_KVM_TIMERS];
  44. /* Background timer used when the guest is not running */
  45. struct hrtimer bg_timer;
  46. /* Is the timer enabled */
  47. bool enabled;
  48. };
  49. int kvm_timer_hyp_init(bool);
  50. int kvm_timer_enable(struct kvm_vcpu *vcpu);
  51. int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu);
  52. void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu);
  53. void kvm_timer_sync_user(struct kvm_vcpu *vcpu);
  54. bool kvm_timer_should_notify_user(struct kvm_vcpu *vcpu);
  55. void kvm_timer_update_run(struct kvm_vcpu *vcpu);
  56. void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu);
  57. u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid);
  58. int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value);
  59. int kvm_arm_timer_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
  60. int kvm_arm_timer_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
  61. int kvm_arm_timer_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
  62. u64 kvm_phys_timer_read(void);
  63. void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu);
  64. void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu);
  65. void kvm_timer_init_vhe(void);
  66. bool kvm_arch_timer_get_input_level(int vintid);
  67. #define vcpu_timer(v) (&(v)->arch.timer_cpu)
  68. #define vcpu_get_timer(v,t) (&vcpu_timer(v)->timers[(t)])
  69. #define vcpu_vtimer(v) (&(v)->arch.timer_cpu.timers[TIMER_VTIMER])
  70. #define vcpu_ptimer(v) (&(v)->arch.timer_cpu.timers[TIMER_PTIMER])
  71. #define arch_timer_ctx_index(ctx) ((ctx) - vcpu_timer((ctx)->vcpu)->timers)
  72. u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu,
  73. enum kvm_arch_timers tmr,
  74. enum kvm_arch_timer_regs treg);
  75. void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu,
  76. enum kvm_arch_timers tmr,
  77. enum kvm_arch_timer_regs treg,
  78. u64 val);
  79. /* Needed for tracing */
  80. u32 timer_get_ctl(struct arch_timer_context *ctxt);
  81. u64 timer_get_cval(struct arch_timer_context *ctxt);
  82. #endif