blob: 5b79c340f17e2edfb4193158452167de67e2f709 [file] [log] [blame]
Christoffer Dall64a959d2015-11-24 16:51:12 +01001/*
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 Auger90977732015-12-01 15:02:35 +010019#include <linux/irqchip/arm-gic-common.h>
20
Marc Zyngier2b0cda82016-04-26 11:06:47 +010021#define PRODUCT_ID_KVM 0x4b /* ASCII code K */
22#define IMPLEMENTER_ARM 0x43b
23
Eric Augere2c1f9a2015-12-21 16:36:04 +010024#define VGIC_ADDR_UNDEF (-1)
25#define IS_VGIC_ADDR_UNDEF(_x) ((_x) == VGIC_ADDR_UNDEF)
26
Andre Przywarafd59ed32016-01-27 14:54:30 +000027#define INTERRUPT_ID_BITS_SPIS 10
Andre Przywara055658b2015-12-01 14:34:02 +000028#define VGIC_PRI_BITS 5
29
Marc Zyngier0919e842015-11-26 17:19:25 +000030#define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS)
31
Andre Przywarae4823a72015-12-03 11:47:37 +000032struct vgic_vmcr {
33 u32 ctlr;
34 u32 abpr;
35 u32 bpr;
36 u32 pmr;
37};
38
Christoffer Dall64a959d2015-11-24 16:51:12 +010039struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,
40 u32 intid);
Andre Przywara5dd4b922016-07-15 12:43:27 +010041void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq);
Christoffer Dall81eeb952015-11-25 10:02:16 -080042bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq);
Marc Zyngier2b0cda82016-04-26 11:06:47 +010043void vgic_kick_vcpus(struct kvm *kvm);
Christoffer Dall64a959d2015-11-24 16:51:12 +010044
Marc Zyngier140b0862015-11-26 17:19:25 +000045void vgic_v2_process_maintenance(struct kvm_vcpu *vcpu);
46void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu);
47void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);
48void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr);
49void vgic_v2_set_underflow(struct kvm_vcpu *vcpu);
Eric Augerf94591e2015-12-21 17:34:52 +010050int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr);
Christoffer Dallc3199f22016-04-25 01:11:37 +020051int vgic_v2_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write,
52 int offset, u32 *val);
Andre Przywara878c5692015-12-03 11:48:42 +000053int vgic_v2_cpuif_uaccess(struct kvm_vcpu *vcpu, bool is_write,
54 int offset, u32 *val);
Andre Przywarae4823a72015-12-03 11:47:37 +000055void vgic_v2_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
56void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
Eric Augerad275b8b2015-12-21 18:09:38 +010057void vgic_v2_enable(struct kvm_vcpu *vcpu);
Eric Auger90977732015-12-01 15:02:35 +010058int vgic_v2_probe(const struct gic_kvm_info *info);
Eric Augerb0442ee2015-12-21 15:04:42 +010059int vgic_v2_map_resources(struct kvm *kvm);
Andre Przywarafb848db2016-04-26 21:32:49 +010060int vgic_register_dist_iodev(struct kvm *kvm, gpa_t dist_base_address,
61 enum vgic_type);
Marc Zyngier140b0862015-11-26 17:19:25 +000062
Marc Zyngier59529f62015-11-30 13:09:53 +000063#ifdef CONFIG_KVM_ARM_VGIC_V3
64void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu);
65void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu);
66void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);
67void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr);
68void vgic_v3_set_underflow(struct kvm_vcpu *vcpu);
Andre Przywarae4823a72015-12-03 11:47:37 +000069void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
70void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
Eric Augerad275b8b2015-12-21 18:09:38 +010071void vgic_v3_enable(struct kvm_vcpu *vcpu);
Eric Auger90977732015-12-01 15:02:35 +010072int vgic_v3_probe(const struct gic_kvm_info *info);
Eric Augerb0442ee2015-12-21 15:04:42 +010073int vgic_v3_map_resources(struct kvm *kvm);
Andre Przywaraed9b8ce2015-12-01 14:34:34 +000074int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address);
Marc Zyngier59529f62015-11-30 13:09:53 +000075#else
76static inline void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu)
77{
78}
79
80static inline void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu)
81{
82}
83
84static inline void vgic_v3_populate_lr(struct kvm_vcpu *vcpu,
85 struct vgic_irq *irq, int lr)
86{
87}
88
89static inline void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr)
90{
91}
92
93static inline void vgic_v3_set_underflow(struct kvm_vcpu *vcpu)
94{
95}
Andre Przywaraed9b8ce2015-12-01 14:34:34 +000096
Andre Przywarae4823a72015-12-03 11:47:37 +000097static inline
98void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr)
99{
100}
101
102static inline
103void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr)
104{
105}
106
Eric Augerad275b8b2015-12-21 18:09:38 +0100107static inline void vgic_v3_enable(struct kvm_vcpu *vcpu)
108{
109}
110
Eric Auger90977732015-12-01 15:02:35 +0100111static inline int vgic_v3_probe(const struct gic_kvm_info *info)
112{
113 return -ENODEV;
114}
115
Eric Augerb0442ee2015-12-21 15:04:42 +0100116static inline int vgic_v3_map_resources(struct kvm *kvm)
117{
118 return -ENODEV;
119}
120
Andre Przywaraed9b8ce2015-12-01 14:34:34 +0000121static inline int vgic_register_redist_iodevs(struct kvm *kvm,
122 gpa_t dist_base_address)
123{
124 return -ENODEV;
125}
Marc Zyngier59529f62015-11-30 13:09:53 +0000126#endif
127
Andre Przywara42c88702016-07-15 12:43:23 +0100128int kvm_register_vgic_device(unsigned long type);
Eric Augerad275b8b2015-12-21 18:09:38 +0100129int vgic_lazy_init(struct kvm *kvm);
130int vgic_init(struct kvm *kvm);
Eric Augerc86c7722015-11-30 14:01:58 +0100131
Christoffer Dall64a959d2015-11-24 16:51:12 +0100132#endif