vgic.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2015, 2016 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __KVM_ARM_VGIC_NEW_H__
  17. #define __KVM_ARM_VGIC_NEW_H__
  18. #include <linux/irqchip/arm-gic-common.h>
  19. #define PRODUCT_ID_KVM 0x4b /* ASCII code K */
  20. #define IMPLEMENTER_ARM 0x43b
  21. #define VGIC_ADDR_UNDEF (-1)
  22. #define IS_VGIC_ADDR_UNDEF(_x) ((_x) == VGIC_ADDR_UNDEF)
  23. #define INTERRUPT_ID_BITS_SPIS 10
  24. #define INTERRUPT_ID_BITS_ITS 16
  25. #define VGIC_PRI_BITS 5
  26. #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS)
  27. struct vgic_vmcr {
  28. u32 ctlr;
  29. u32 abpr;
  30. u32 bpr;
  31. u32 pmr;
  32. };
  33. struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,
  34. u32 intid);
  35. void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq);
  36. bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq);
  37. void vgic_kick_vcpus(struct kvm *kvm);
  38. int vgic_check_ioaddr(struct kvm *kvm, phys_addr_t *ioaddr,
  39. phys_addr_t addr, phys_addr_t alignment);
  40. void vgic_v2_process_maintenance(struct kvm_vcpu *vcpu);
  41. void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu);
  42. void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);
  43. void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr);
  44. void vgic_v2_set_underflow(struct kvm_vcpu *vcpu);
  45. int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr);
  46. int vgic_v2_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write,
  47. int offset, u32 *val);
  48. int vgic_v2_cpuif_uaccess(struct kvm_vcpu *vcpu, bool is_write,
  49. int offset, u32 *val);
  50. void vgic_v2_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
  51. void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
  52. void vgic_v2_enable(struct kvm_vcpu *vcpu);
  53. int vgic_v2_probe(const struct gic_kvm_info *info);
  54. int vgic_v2_map_resources(struct kvm *kvm);
  55. int vgic_register_dist_iodev(struct kvm *kvm, gpa_t dist_base_address,
  56. enum vgic_type);
  57. static inline void vgic_get_irq_kref(struct vgic_irq *irq)
  58. {
  59. if (irq->intid < VGIC_MIN_LPI)
  60. return;
  61. kref_get(&irq->refcount);
  62. }
  63. void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu);
  64. void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu);
  65. void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);
  66. void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr);
  67. void vgic_v3_set_underflow(struct kvm_vcpu *vcpu);
  68. void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
  69. void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
  70. void vgic_v3_enable(struct kvm_vcpu *vcpu);
  71. int vgic_v3_probe(const struct gic_kvm_info *info);
  72. int vgic_v3_map_resources(struct kvm *kvm);
  73. int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address);
  74. #ifdef CONFIG_KVM_ARM_VGIC_V3_ITS
  75. int vgic_register_its_iodevs(struct kvm *kvm);
  76. bool vgic_has_its(struct kvm *kvm);
  77. int kvm_vgic_register_its_device(void);
  78. void vgic_enable_lpis(struct kvm_vcpu *vcpu);
  79. int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi);
  80. #else
  81. static inline int vgic_register_its_iodevs(struct kvm *kvm)
  82. {
  83. return -ENODEV;
  84. }
  85. static inline bool vgic_has_its(struct kvm *kvm)
  86. {
  87. return false;
  88. }
  89. static inline int kvm_vgic_register_its_device(void)
  90. {
  91. return -ENODEV;
  92. }
  93. static inline void vgic_enable_lpis(struct kvm_vcpu *vcpu)
  94. {
  95. }
  96. static inline int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)
  97. {
  98. return -ENODEV;
  99. }
  100. #endif
  101. int kvm_register_vgic_device(unsigned long type);
  102. int vgic_lazy_init(struct kvm *kvm);
  103. int vgic_init(struct kvm *kvm);
  104. #endif