timer-sr.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2012-2015 - ARM Ltd
  4. * Author: Marc Zyngier <[email protected]>
  5. */
  6. #include <clocksource/arm_arch_timer.h>
  7. #include <linux/compiler.h>
  8. #include <linux/kvm_host.h>
  9. #include <asm/kvm_hyp.h>
  10. void __kvm_timer_set_cntvoff(u64 cntvoff)
  11. {
  12. write_sysreg(cntvoff, cntvoff_el2);
  13. }
  14. /*
  15. * Should only be called on non-VHE systems.
  16. * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
  17. */
  18. void __timer_disable_traps(struct kvm_vcpu *vcpu)
  19. {
  20. u64 val;
  21. /* Allow physical timer/counter access for the host */
  22. val = read_sysreg(cnthctl_el2);
  23. val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
  24. write_sysreg(val, cnthctl_el2);
  25. }
  26. /*
  27. * Should only be called on non-VHE systems.
  28. * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
  29. */
  30. void __timer_enable_traps(struct kvm_vcpu *vcpu)
  31. {
  32. u64 val;
  33. /*
  34. * Disallow physical timer access for the guest
  35. * Physical counter access is allowed
  36. */
  37. val = read_sysreg(cnthctl_el2);
  38. val &= ~CNTHCTL_EL1PCEN;
  39. val |= CNTHCTL_EL1PCTEN;
  40. write_sysreg(val, cnthctl_el2);
  41. }