Christoffer Dall | 64a959d | 2015-11-24 16:51:12 +0100 | [diff] [blame] | 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 | |
Eric Auger | 9097773 | 2015-12-01 15:02:35 +0100 | [diff] [blame] | 19 | #include <linux/irqchip/arm-gic-common.h> |
| 20 | |
Marc Zyngier | 2b0cda8 | 2016-04-26 11:06:47 +0100 | [diff] [blame] | 21 | #define PRODUCT_ID_KVM 0x4b /* ASCII code K */ |
| 22 | #define IMPLEMENTER_ARM 0x43b |
| 23 | |
Eric Auger | e2c1f9a | 2015-12-21 16:36:04 +0100 | [diff] [blame] | 24 | #define VGIC_ADDR_UNDEF (-1) |
| 25 | #define IS_VGIC_ADDR_UNDEF(_x) ((_x) == VGIC_ADDR_UNDEF) |
| 26 | |
Andre Przywara | fd59ed3 | 2016-01-27 14:54:30 +0000 | [diff] [blame] | 27 | #define INTERRUPT_ID_BITS_SPIS 10 |
Andre Przywara | 33d3bc9 | 2016-07-15 12:43:34 +0100 | [diff] [blame] | 28 | #define INTERRUPT_ID_BITS_ITS 16 |
Andre Przywara | 055658b | 2015-12-01 14:34:02 +0000 | [diff] [blame] | 29 | #define VGIC_PRI_BITS 5 |
| 30 | |
Marc Zyngier | 0919e84 | 2015-11-26 17:19:25 +0000 | [diff] [blame] | 31 | #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS) |
| 32 | |
Andre Przywara | e4823a7 | 2015-12-03 11:47:37 +0000 | [diff] [blame] | 33 | struct vgic_vmcr { |
| 34 | u32 ctlr; |
| 35 | u32 abpr; |
| 36 | u32 bpr; |
| 37 | u32 pmr; |
| 38 | }; |
| 39 | |
Christoffer Dall | 64a959d | 2015-11-24 16:51:12 +0100 | [diff] [blame] | 40 | struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, |
| 41 | u32 intid); |
Andre Przywara | 5dd4b92 | 2016-07-15 12:43:27 +0100 | [diff] [blame] | 42 | void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq); |
Christoffer Dall | 81eeb95 | 2015-11-25 10:02:16 -0800 | [diff] [blame] | 43 | bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq); |
Marc Zyngier | 2b0cda8 | 2016-04-26 11:06:47 +0100 | [diff] [blame] | 44 | void vgic_kick_vcpus(struct kvm *kvm); |
Christoffer Dall | 64a959d | 2015-11-24 16:51:12 +0100 | [diff] [blame] | 45 | |
Andre Przywara | 1085fdc | 2016-07-15 12:43:31 +0100 | [diff] [blame] | 46 | int vgic_check_ioaddr(struct kvm *kvm, phys_addr_t *ioaddr, |
| 47 | phys_addr_t addr, phys_addr_t alignment); |
| 48 | |
Marc Zyngier | 140b086 | 2015-11-26 17:19:25 +0000 | [diff] [blame] | 49 | void vgic_v2_process_maintenance(struct kvm_vcpu *vcpu); |
| 50 | void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu); |
| 51 | void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr); |
| 52 | void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr); |
| 53 | void vgic_v2_set_underflow(struct kvm_vcpu *vcpu); |
Eric Auger | f94591e | 2015-12-21 17:34:52 +0100 | [diff] [blame] | 54 | int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr); |
Christoffer Dall | c3199f2 | 2016-04-25 01:11:37 +0200 | [diff] [blame] | 55 | int vgic_v2_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write, |
| 56 | int offset, u32 *val); |
Andre Przywara | 878c569 | 2015-12-03 11:48:42 +0000 | [diff] [blame] | 57 | int vgic_v2_cpuif_uaccess(struct kvm_vcpu *vcpu, bool is_write, |
| 58 | int offset, u32 *val); |
Andre Przywara | e4823a7 | 2015-12-03 11:47:37 +0000 | [diff] [blame] | 59 | void vgic_v2_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); |
| 60 | void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); |
Eric Auger | ad275b8b | 2015-12-21 18:09:38 +0100 | [diff] [blame] | 61 | void vgic_v2_enable(struct kvm_vcpu *vcpu); |
Eric Auger | 9097773 | 2015-12-01 15:02:35 +0100 | [diff] [blame] | 62 | int vgic_v2_probe(const struct gic_kvm_info *info); |
Eric Auger | b0442ee | 2015-12-21 15:04:42 +0100 | [diff] [blame] | 63 | int vgic_v2_map_resources(struct kvm *kvm); |
Andre Przywara | fb848db | 2016-04-26 21:32:49 +0100 | [diff] [blame] | 64 | int vgic_register_dist_iodev(struct kvm *kvm, gpa_t dist_base_address, |
| 65 | enum vgic_type); |
Marc Zyngier | 140b086 | 2015-11-26 17:19:25 +0000 | [diff] [blame] | 66 | |
Marc Zyngier | d97594e | 2016-07-17 11:27:23 +0100 | [diff] [blame] | 67 | static inline void vgic_get_irq_kref(struct vgic_irq *irq) |
| 68 | { |
| 69 | if (irq->intid < VGIC_MIN_LPI) |
| 70 | return; |
| 71 | |
| 72 | kref_get(&irq->refcount); |
| 73 | } |
| 74 | |
Marc Zyngier | 59529f6 | 2015-11-30 13:09:53 +0000 | [diff] [blame] | 75 | #ifdef CONFIG_KVM_ARM_VGIC_V3 |
| 76 | void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu); |
| 77 | void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu); |
| 78 | void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr); |
| 79 | void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr); |
| 80 | void vgic_v3_set_underflow(struct kvm_vcpu *vcpu); |
Andre Przywara | e4823a7 | 2015-12-03 11:47:37 +0000 | [diff] [blame] | 81 | void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); |
| 82 | void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); |
Eric Auger | ad275b8b | 2015-12-21 18:09:38 +0100 | [diff] [blame] | 83 | void vgic_v3_enable(struct kvm_vcpu *vcpu); |
Eric Auger | 9097773 | 2015-12-01 15:02:35 +0100 | [diff] [blame] | 84 | int vgic_v3_probe(const struct gic_kvm_info *info); |
Eric Auger | b0442ee | 2015-12-21 15:04:42 +0100 | [diff] [blame] | 85 | int vgic_v3_map_resources(struct kvm *kvm); |
Andre Przywara | ed9b8ce | 2015-12-01 14:34:34 +0000 | [diff] [blame] | 86 | int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address); |
Vladimir Murzin | 7a1ff70 | 2016-09-12 15:49:18 +0100 | [diff] [blame^] | 87 | |
| 88 | #ifdef CONFIG_KVM_ARM_VGIC_V3_ITS |
Andre Przywara | c773576 | 2016-08-08 16:45:43 +0100 | [diff] [blame] | 89 | int vgic_register_its_iodevs(struct kvm *kvm); |
Andre Przywara | 59c5ab4 | 2016-07-15 12:43:30 +0100 | [diff] [blame] | 90 | bool vgic_has_its(struct kvm *kvm); |
Andre Przywara | 0e4e82f | 2016-07-15 12:43:38 +0100 | [diff] [blame] | 91 | int kvm_vgic_register_its_device(void); |
Andre Przywara | 33d3bc9 | 2016-07-15 12:43:34 +0100 | [diff] [blame] | 92 | void vgic_enable_lpis(struct kvm_vcpu *vcpu); |
Andre Przywara | 2891a7d | 2016-07-15 12:43:37 +0100 | [diff] [blame] | 93 | int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi); |
Vladimir Murzin | 7a1ff70 | 2016-09-12 15:49:18 +0100 | [diff] [blame^] | 94 | #endif |
| 95 | |
Marc Zyngier | 59529f6 | 2015-11-30 13:09:53 +0000 | [diff] [blame] | 96 | #else |
| 97 | static inline void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | static inline void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu) |
| 102 | { |
| 103 | } |
| 104 | |
| 105 | static inline void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, |
| 106 | struct vgic_irq *irq, int lr) |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | static inline void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr) |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | static inline void vgic_v3_set_underflow(struct kvm_vcpu *vcpu) |
| 115 | { |
| 116 | } |
Andre Przywara | ed9b8ce | 2015-12-01 14:34:34 +0000 | [diff] [blame] | 117 | |
Andre Przywara | e4823a7 | 2015-12-03 11:47:37 +0000 | [diff] [blame] | 118 | static inline |
| 119 | void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr) |
| 120 | { |
| 121 | } |
| 122 | |
| 123 | static inline |
| 124 | void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr) |
| 125 | { |
| 126 | } |
| 127 | |
Eric Auger | ad275b8b | 2015-12-21 18:09:38 +0100 | [diff] [blame] | 128 | static inline void vgic_v3_enable(struct kvm_vcpu *vcpu) |
| 129 | { |
| 130 | } |
| 131 | |
Eric Auger | 9097773 | 2015-12-01 15:02:35 +0100 | [diff] [blame] | 132 | static inline int vgic_v3_probe(const struct gic_kvm_info *info) |
| 133 | { |
| 134 | return -ENODEV; |
| 135 | } |
| 136 | |
Eric Auger | b0442ee | 2015-12-21 15:04:42 +0100 | [diff] [blame] | 137 | static inline int vgic_v3_map_resources(struct kvm *kvm) |
| 138 | { |
| 139 | return -ENODEV; |
| 140 | } |
| 141 | |
Andre Przywara | ed9b8ce | 2015-12-01 14:34:34 +0000 | [diff] [blame] | 142 | static inline int vgic_register_redist_iodevs(struct kvm *kvm, |
| 143 | gpa_t dist_base_address) |
| 144 | { |
| 145 | return -ENODEV; |
| 146 | } |
Andre Przywara | 59c5ab4 | 2016-07-15 12:43:30 +0100 | [diff] [blame] | 147 | |
Andre Przywara | c773576 | 2016-08-08 16:45:43 +0100 | [diff] [blame] | 148 | static inline int vgic_register_its_iodevs(struct kvm *kvm) |
| 149 | { |
| 150 | return -ENODEV; |
| 151 | } |
| 152 | |
Andre Przywara | 59c5ab4 | 2016-07-15 12:43:30 +0100 | [diff] [blame] | 153 | static inline bool vgic_has_its(struct kvm *kvm) |
| 154 | { |
| 155 | return false; |
| 156 | } |
| 157 | |
Andre Przywara | 0e4e82f | 2016-07-15 12:43:38 +0100 | [diff] [blame] | 158 | static inline int kvm_vgic_register_its_device(void) |
| 159 | { |
| 160 | return -ENODEV; |
| 161 | } |
| 162 | |
Andre Przywara | 33d3bc9 | 2016-07-15 12:43:34 +0100 | [diff] [blame] | 163 | static inline void vgic_enable_lpis(struct kvm_vcpu *vcpu) |
| 164 | { |
| 165 | } |
Andre Przywara | 2891a7d | 2016-07-15 12:43:37 +0100 | [diff] [blame] | 166 | |
| 167 | static inline int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi) |
| 168 | { |
| 169 | return -ENODEV; |
| 170 | } |
Marc Zyngier | 59529f6 | 2015-11-30 13:09:53 +0000 | [diff] [blame] | 171 | #endif |
| 172 | |
Andre Przywara | 42c8870 | 2016-07-15 12:43:23 +0100 | [diff] [blame] | 173 | int kvm_register_vgic_device(unsigned long type); |
Eric Auger | ad275b8b | 2015-12-21 18:09:38 +0100 | [diff] [blame] | 174 | int vgic_lazy_init(struct kvm *kvm); |
| 175 | int vgic_init(struct kvm *kvm); |
Eric Auger | c86c772 | 2015-11-30 14:01:58 +0100 | [diff] [blame] | 176 | |
Christoffer Dall | 64a959d | 2015-11-24 16:51:12 +0100 | [diff] [blame] | 177 | #endif |