timer-sr.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2012-2015 - ARM Ltd
  3. * Author: Marc Zyngier <marc.zyngier@arm.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <clocksource/arm_arch_timer.h>
  18. #include <linux/compiler.h>
  19. #include <linux/kvm_host.h>
  20. #include <asm/kvm_hyp.h>
  21. void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high)
  22. {
  23. u64 cntvoff = (u64)cntvoff_high << 32 | cntvoff_low;
  24. write_sysreg(cntvoff, cntvoff_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 __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu)
  31. {
  32. u64 val;
  33. /* Allow physical timer/counter access for the host */
  34. val = read_sysreg(cnthctl_el2);
  35. val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
  36. write_sysreg(val, cnthctl_el2);
  37. }
  38. /*
  39. * Should only be called on non-VHE systems.
  40. * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
  41. */
  42. void __hyp_text __timer_enable_traps(struct kvm_vcpu *vcpu)
  43. {
  44. u64 val;
  45. /*
  46. * Disallow physical timer access for the guest
  47. * Physical counter access is allowed
  48. */
  49. val = read_sysreg(cnthctl_el2);
  50. val &= ~CNTHCTL_EL1PCEN;
  51. val |= CNTHCTL_EL1PCTEN;
  52. write_sysreg(val, cnthctl_el2);
  53. }