blob: 100045f3d98a7a805e05aa4ff7991b8564b6d05b [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 Przywara33d3bc92016-07-15 12:43:34 +010028#define INTERRUPT_ID_BITS_ITS 16
Andre Przywara055658b2015-12-01 14:34:02 +000029#define VGIC_PRI_BITS 5
30
Marc Zyngier0919e842015-11-26 17:19:25 +000031#define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS)
32
Andre Przywarae4823a72015-12-03 11:47:37 +000033struct vgic_vmcr {
34 u32 ctlr;
35 u32 abpr;
36 u32 bpr;
37 u32 pmr;
38};
39
Christoffer Dall64a959d2015-11-24 16:51:12 +010040struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,
41 u32 intid);
Andre Przywara5dd4b922016-07-15 12:43:27 +010042void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq);
Christoffer Dall81eeb952015-11-25 10:02:16 -080043bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq);
Marc Zyngier2b0cda82016-04-26 11:06:47 +010044void vgic_kick_vcpus(struct kvm *kvm);
Christoffer Dall64a959d2015-11-24 16:51:12 +010045
Andre Przywara1085fdc2016-07-15 12:43:31 +010046int vgic_check_ioaddr(struct kvm *kvm, phys_addr_t *ioaddr,
47 phys_addr_t addr, phys_addr_t alignment);
48
Marc Zyngier140b0862015-11-26 17:19:25 +000049void vgic_v2_process_maintenance(struct kvm_vcpu *vcpu);
50void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu);
51void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);
52void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr);
53void vgic_v2_set_underflow(struct kvm_vcpu *vcpu);
Eric Augerf94591e2015-12-21 17:34:52 +010054int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr);
Christoffer Dallc3199f22016-04-25 01:11:37 +020055int vgic_v2_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write,
56 int offset, u32 *val);
Andre Przywara878c5692015-12-03 11:48:42 +000057int vgic_v2_cpuif_uaccess(struct kvm_vcpu *vcpu, bool is_write,
58 int offset, u32 *val);
Andre Przywarae4823a72015-12-03 11:47:37 +000059void vgic_v2_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
60void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
Eric Augerad275b8b2015-12-21 18:09:38 +010061void vgic_v2_enable(struct kvm_vcpu *vcpu);
Eric Auger90977732015-12-01 15:02:35 +010062int vgic_v2_probe(const struct gic_kvm_info *info);
Eric Augerb0442ee2015-12-21 15:04:42 +010063int vgic_v2_map_resources(struct kvm *kvm);
Andre Przywarafb848db2016-04-26 21:32:49 +010064int vgic_register_dist_iodev(struct kvm *kvm, gpa_t dist_base_address,
65 enum vgic_type);
Marc Zyngier140b0862015-11-26 17:19:25 +000066
Marc Zyngierd97594e2016-07-17 11:27:23 +010067static 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 Zyngier59529f62015-11-30 13:09:53 +000075#ifdef CONFIG_KVM_ARM_VGIC_V3
76void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu);
77void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu);
78void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);
79void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr);
80void vgic_v3_set_underflow(struct kvm_vcpu *vcpu);
Andre Przywarae4823a72015-12-03 11:47:37 +000081void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
82void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
Eric Augerad275b8b2015-12-21 18:09:38 +010083void vgic_v3_enable(struct kvm_vcpu *vcpu);
Eric Auger90977732015-12-01 15:02:35 +010084int vgic_v3_probe(const struct gic_kvm_info *info);
Eric Augerb0442ee2015-12-21 15:04:42 +010085int vgic_v3_map_resources(struct kvm *kvm);
Andre Przywaraed9b8ce2015-12-01 14:34:34 +000086int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address);
Vladimir Murzin7a1ff702016-09-12 15:49:18 +010087
88#ifdef CONFIG_KVM_ARM_VGIC_V3_ITS
Andre Przywarac7735762016-08-08 16:45:43 +010089int vgic_register_its_iodevs(struct kvm *kvm);
Andre Przywara59c5ab42016-07-15 12:43:30 +010090bool vgic_has_its(struct kvm *kvm);
Andre Przywara0e4e82f2016-07-15 12:43:38 +010091int kvm_vgic_register_its_device(void);
Andre Przywara33d3bc92016-07-15 12:43:34 +010092void vgic_enable_lpis(struct kvm_vcpu *vcpu);
Andre Przywara2891a7d2016-07-15 12:43:37 +010093int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi);
Vladimir Murzin7a1ff702016-09-12 15:49:18 +010094#endif
95
Marc Zyngier59529f62015-11-30 13:09:53 +000096#else
97static inline void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu)
98{
99}
100
101static inline void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu)
102{
103}
104
105static inline void vgic_v3_populate_lr(struct kvm_vcpu *vcpu,
106 struct vgic_irq *irq, int lr)
107{
108}
109
110static inline void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr)
111{
112}
113
114static inline void vgic_v3_set_underflow(struct kvm_vcpu *vcpu)
115{
116}
Andre Przywaraed9b8ce2015-12-01 14:34:34 +0000117
Andre Przywarae4823a72015-12-03 11:47:37 +0000118static inline
119void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr)
120{
121}
122
123static inline
124void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr)
125{
126}
127
Eric Augerad275b8b2015-12-21 18:09:38 +0100128static inline void vgic_v3_enable(struct kvm_vcpu *vcpu)
129{
130}
131
Eric Auger90977732015-12-01 15:02:35 +0100132static inline int vgic_v3_probe(const struct gic_kvm_info *info)
133{
134 return -ENODEV;
135}
136
Eric Augerb0442ee2015-12-21 15:04:42 +0100137static inline int vgic_v3_map_resources(struct kvm *kvm)
138{
139 return -ENODEV;
140}
141
Andre Przywaraed9b8ce2015-12-01 14:34:34 +0000142static inline int vgic_register_redist_iodevs(struct kvm *kvm,
143 gpa_t dist_base_address)
144{
145 return -ENODEV;
146}
Andre Przywara59c5ab42016-07-15 12:43:30 +0100147
Andre Przywarac7735762016-08-08 16:45:43 +0100148static inline int vgic_register_its_iodevs(struct kvm *kvm)
149{
150 return -ENODEV;
151}
152
Andre Przywara59c5ab42016-07-15 12:43:30 +0100153static inline bool vgic_has_its(struct kvm *kvm)
154{
155 return false;
156}
157
Andre Przywara0e4e82f2016-07-15 12:43:38 +0100158static inline int kvm_vgic_register_its_device(void)
159{
160 return -ENODEV;
161}
162
Andre Przywara33d3bc92016-07-15 12:43:34 +0100163static inline void vgic_enable_lpis(struct kvm_vcpu *vcpu)
164{
165}
Andre Przywara2891a7d2016-07-15 12:43:37 +0100166
167static inline int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)
168{
169 return -ENODEV;
170}
Marc Zyngier59529f62015-11-30 13:09:53 +0000171#endif
172
Andre Przywara42c88702016-07-15 12:43:23 +0100173int kvm_register_vgic_device(unsigned long type);
Eric Augerad275b8b2015-12-21 18:09:38 +0100174int vgic_lazy_init(struct kvm *kvm);
175int vgic_init(struct kvm *kvm);
Eric Augerc86c7722015-11-30 14:01:58 +0100176
Christoffer Dall64a959d2015-11-24 16:51:12 +0100177#endif