blob: e602d848fc1ab7291fe04dc56745bc41e28b8b1c [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Zyngier1a89dd92013-01-21 19:36:12 -05002/*
Marc Zyngier50926d82016-05-28 11:27:11 +01003 * Copyright (C) 2015, 2016 ARM Ltd.
Marc Zyngier1a89dd92013-01-21 19:36:12 -05004 */
Marc Zyngier50926d82016-05-28 11:27:11 +01005#ifndef __KVM_ARM_VGIC_H
6#define __KVM_ARM_VGIC_H
Christoffer Dallb18b5772015-11-23 07:20:05 -08007
Marc Zyngierb47ef922013-01-21 19:36:14 -05008#include <linux/kernel.h>
9#include <linux/kvm.h>
Marc Zyngierb47ef922013-01-21 19:36:14 -050010#include <linux/irqreturn.h>
11#include <linux/spinlock.h>
Marc Zyngierfb5ee362016-09-06 09:28:45 +010012#include <linux/static_key.h>
Marc Zyngierb47ef922013-01-21 19:36:14 -050013#include <linux/types.h>
Andre Przywara6777f772015-03-26 14:39:34 +000014#include <kvm/iodev.h>
Andre Przywara424c3382016-07-15 12:43:32 +010015#include <linux/list.h>
Vladimir Murzin5a7a8422016-09-12 15:49:15 +010016#include <linux/jump_label.h>
Marc Zyngier1a89dd92013-01-21 19:36:12 -050017
Marc Zyngier74fe55d2017-10-27 15:28:38 +010018#include <linux/irqchip/arm-gic-v4.h>
19
Eric Augere25028c2018-05-22 09:55:18 +020020#define VGIC_V3_MAX_CPUS 512
Marc Zyngier50926d82016-05-28 11:27:11 +010021#define VGIC_V2_MAX_CPUS 8
22#define VGIC_NR_IRQS_LEGACY 256
Marc Zyngierb47ef922013-01-21 19:36:14 -050023#define VGIC_NR_SGIS 16
24#define VGIC_NR_PPIS 16
25#define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS)
Marc Zyngier50926d82016-05-28 11:27:11 +010026#define VGIC_MAX_PRIVATE (VGIC_NR_PRIVATE_IRQS - 1)
27#define VGIC_MAX_SPI 1019
28#define VGIC_MAX_RESERVED 1023
29#define VGIC_MIN_LPI 8192
Eric Auger180ae7b2016-07-22 16:20:41 +000030#define KVM_IRQCHIP_NUM_PINS (1020 - 32)
Marc Zyngier8d5c6b02013-06-03 15:55:02 +010031
Christoffer Dall3cba4af2017-05-02 20:11:49 +020032#define irq_is_ppi(irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)
Christoffer Dallebb127f2017-05-16 19:53:50 +020033#define irq_is_spi(irq) ((irq) >= VGIC_NR_PRIVATE_IRQS && \
34 (irq) <= VGIC_MAX_SPI)
Christoffer Dall3cba4af2017-05-02 20:11:49 +020035
Marc Zyngier1a9b1302013-06-21 11:57:56 +010036enum vgic_type {
37 VGIC_V2, /* Good ol' GICv2 */
Marc Zyngierb2fb1c02013-07-12 15:15:23 +010038 VGIC_V3, /* New fancy GICv3 */
Marc Zyngier1a9b1302013-06-21 11:57:56 +010039};
40
Marc Zyngier50926d82016-05-28 11:27:11 +010041/* same for all guests, as depending only on the _host's_ GIC model */
42struct vgic_global {
43 /* type of the host GIC */
44 enum vgic_type type;
Marc Zyngier8d5c6b02013-06-03 15:55:02 +010045
Marc Zyngierca85f622013-06-18 19:17:28 +010046 /* Physical address of vgic virtual cpu interface */
Marc Zyngier50926d82016-05-28 11:27:11 +010047 phys_addr_t vcpu_base;
48
Marc Zyngier1bb32a42017-12-04 16:43:23 +000049 /* GICV mapping, kernel VA */
Marc Zyngierbf8feb32016-09-06 09:28:46 +010050 void __iomem *vcpu_base_va;
Marc Zyngier1bb32a42017-12-04 16:43:23 +000051 /* GICV mapping, HYP VA */
52 void __iomem *vcpu_hyp_va;
Marc Zyngierbf8feb32016-09-06 09:28:46 +010053
Marc Zyngier1bb32a42017-12-04 16:43:23 +000054 /* virtual control interface mapping, kernel VA */
Marc Zyngier50926d82016-05-28 11:27:11 +010055 void __iomem *vctrl_base;
Marc Zyngier1bb32a42017-12-04 16:43:23 +000056 /* virtual control interface mapping, HYP VA */
57 void __iomem *vctrl_hyp;
Marc Zyngier50926d82016-05-28 11:27:11 +010058
59 /* Number of implemented list registers */
60 int nr_lr;
61
62 /* Maintenance IRQ number */
63 unsigned int maint_irq;
64
65 /* maximum number of VCPUs allowed (GICv2 limits us to 8) */
66 int max_gic_vcpus;
67
Andre Przywarab5d84ff62014-06-03 10:26:03 +020068 /* Only needed for the legacy KVM_CREATE_IRQCHIP */
Marc Zyngier50926d82016-05-28 11:27:11 +010069 bool can_emulate_gicv2;
Vladimir Murzin5a7a8422016-09-12 15:49:15 +010070
Marc Zyngiere7c48052017-10-27 15:28:37 +010071 /* Hardware has GICv4? */
72 bool has_gicv4;
Marc Zyngierae699ad2020-03-04 20:33:20 +000073 bool has_gicv4_1;
Marc Zyngiere7c48052017-10-27 15:28:37 +010074
Marc Zyngierf6c3e242021-03-15 21:56:47 +000075 /* Pseudo GICv3 from outer space */
76 bool no_hw_deactivation;
77
Vladimir Murzin5a7a8422016-09-12 15:49:15 +010078 /* GIC system register CPU interface */
79 struct static_key_false gicv3_cpuif;
Vijaya Kumar Kd017d7b2017-01-26 19:50:51 +053080
81 u32 ich_vtr_el2;
Marc Zyngierca85f622013-06-18 19:17:28 +010082};
83
Marc Zyngier50926d82016-05-28 11:27:11 +010084extern struct vgic_global kvm_vgic_global_state;
85
86#define VGIC_V2_MAX_LRS (1 << 6)
87#define VGIC_V3_MAX_LRS 16
88#define VGIC_V3_LR_INDEX(lr) (VGIC_V3_MAX_LRS - 1 - lr)
89
90enum vgic_irq_config {
91 VGIC_CONFIG_EDGE = 0,
92 VGIC_CONFIG_LEVEL
Andre Przywarab26e5fd2014-06-02 16:19:12 +020093};
94
Marc Zyngierdb75f1a2021-03-01 17:39:39 +000095/*
96 * Per-irq ops overriding some common behavious.
97 *
98 * Always called in non-preemptible section and the functions can use
99 * kvm_arm_get_running_vcpu() to get the vcpu pointer for private IRQs.
100 */
101struct irq_ops {
Marc Zyngier354920e2021-03-15 13:11:58 +0000102 /* Per interrupt flags for special-cased interrupts */
103 unsigned long flags;
104
105#define VGIC_IRQ_SW_RESAMPLE BIT(0) /* Clear the active state for resampling */
106
Marc Zyngierdb75f1a2021-03-01 17:39:39 +0000107 /*
108 * Callback function pointer to in-kernel devices that can tell us the
109 * state of the input level of mapped level-triggered IRQ faster than
110 * peaking into the physical GIC.
111 */
112 bool (*get_input_level)(int vintid);
113};
114
Marc Zyngier50926d82016-05-28 11:27:11 +0100115struct vgic_irq {
Julien Thierry8fa3adb2019-01-07 15:06:15 +0000116 raw_spinlock_t irq_lock; /* Protects the content of the struct */
Andre Przywara38024112016-07-15 12:43:33 +0100117 struct list_head lpi_list; /* Used to link all LPIs together */
Marc Zyngier50926d82016-05-28 11:27:11 +0100118 struct list_head ap_list;
119
120 struct kvm_vcpu *vcpu; /* SGIs and PPIs: The VCPU
121 * SPIs and LPIs: The VCPU whose ap_list
122 * this is queued on.
123 */
124
125 struct kvm_vcpu *target_vcpu; /* The VCPU that this interrupt should
126 * be sent to, as a result of the
127 * targets reg (v2) or the
128 * affinity reg (v3).
129 */
130
131 u32 intid; /* Guest visible INTID */
Marc Zyngier50926d82016-05-28 11:27:11 +0100132 bool line_level; /* Level only */
Christoffer Dall8694e4d2017-01-23 14:07:18 +0100133 bool pending_latch; /* The pending latch state used to calculate
134 * the pending state for both level
135 * and edge triggered IRQs. */
Marc Zyngier50926d82016-05-28 11:27:11 +0100136 bool active; /* not used for LPIs */
137 bool enabled;
138 bool hw; /* Tied to HW IRQ */
Andre Przywara5dd4b922016-07-15 12:43:27 +0100139 struct kref refcount; /* Used for LPIs */
Marc Zyngier50926d82016-05-28 11:27:11 +0100140 u32 hwintid; /* HW INTID number */
Eric Auger47bbd312017-10-27 15:28:32 +0100141 unsigned int host_irq; /* linux irq corresponding to hwintid */
Marc Zyngier50926d82016-05-28 11:27:11 +0100142 union {
143 u8 targets; /* GICv2 target VCPUs mask */
144 u32 mpidr; /* GICv3 target VCPU */
145 };
146 u8 source; /* GICv2 SGIs only */
Marc Zyngier53692902018-04-18 10:39:04 +0100147 u8 active_source; /* GICv2 SGIs only */
Marc Zyngier50926d82016-05-28 11:27:11 +0100148 u8 priority;
Christoffer Dall8df3c8f2018-07-16 15:06:21 +0200149 u8 group; /* 0 == group 0, 1 == group 1 */
Marc Zyngier50926d82016-05-28 11:27:11 +0100150 enum vgic_irq_config config; /* Level or edge */
Christoffer Dallc6ccd302017-05-04 13:24:20 +0200151
Marc Zyngierdb75f1a2021-03-01 17:39:39 +0000152 struct irq_ops *ops;
Christoffer Dallb6909a62017-10-27 19:30:09 +0200153
Christoffer Dallc6ccd302017-05-04 13:24:20 +0200154 void *owner; /* Opaque pointer to reserve an interrupt
155 for in-kernel devices. */
Marc Zyngier50926d82016-05-28 11:27:11 +0100156};
157
Marc Zyngier354920e2021-03-15 13:11:58 +0000158static inline bool vgic_irq_needs_resampling(struct vgic_irq *irq)
159{
160 return irq->ops && (irq->ops->flags & VGIC_IRQ_SW_RESAMPLE);
161}
162
Marc Zyngier50926d82016-05-28 11:27:11 +0100163struct vgic_register_region;
Andre Przywara59c5ab42016-07-15 12:43:30 +0100164struct vgic_its;
165
166enum iodev_type {
167 IODEV_CPUIF,
168 IODEV_DIST,
169 IODEV_REDIST,
170 IODEV_ITS
171};
Marc Zyngier50926d82016-05-28 11:27:11 +0100172
Andre Przywara6777f772015-03-26 14:39:34 +0000173struct vgic_io_device {
Marc Zyngier50926d82016-05-28 11:27:11 +0100174 gpa_t base_addr;
Andre Przywara59c5ab42016-07-15 12:43:30 +0100175 union {
176 struct kvm_vcpu *redist_vcpu;
177 struct vgic_its *its;
178 };
Marc Zyngier50926d82016-05-28 11:27:11 +0100179 const struct vgic_register_region *regions;
Andre Przywara59c5ab42016-07-15 12:43:30 +0100180 enum iodev_type iodev_type;
Marc Zyngier50926d82016-05-28 11:27:11 +0100181 int nr_regions;
Andre Przywara6777f772015-03-26 14:39:34 +0000182 struct kvm_io_device dev;
183};
184
Andre Przywara59c5ab42016-07-15 12:43:30 +0100185struct vgic_its {
186 /* The base address of the ITS control register frame */
187 gpa_t vgic_its_base;
188
189 bool enabled;
190 struct vgic_io_device iodev;
Marc Zyngierbb717642016-07-17 21:35:07 +0100191 struct kvm_device *dev;
Andre Przywara424c3382016-07-15 12:43:32 +0100192
193 /* These registers correspond to GITS_BASER{0,1} */
194 u64 baser_device_table;
195 u64 baser_coll_table;
196
197 /* Protects the command queue */
198 struct mutex cmd_lock;
199 u64 cbaser;
200 u32 creadr;
201 u32 cwriter;
202
Eric Auger71afe472017-04-13 09:06:20 +0200203 /* migration ABI revision in use */
204 u32 abi_rev;
205
Andre Przywara424c3382016-07-15 12:43:32 +0100206 /* Protects the device and collection lists */
207 struct mutex its_lock;
208 struct list_head device_list;
209 struct list_head collection_list;
Andre Przywara59c5ab42016-07-15 12:43:30 +0100210};
211
Christoffer Dall10f92c42017-01-17 23:09:13 +0100212struct vgic_state_iter;
213
Eric Augerdbd97332018-05-22 09:55:08 +0200214struct vgic_redist_region {
215 u32 index;
216 gpa_t base;
217 u32 count; /* number of redistributors or 0 if single region */
218 u32 free_index; /* index of the next free redistributor */
219 struct list_head list;
220};
221
Marc Zyngier1a89dd92013-01-21 19:36:12 -0500222struct vgic_dist {
Marc Zyngierf982cf42014-05-15 10:03:25 +0100223 bool in_kernel;
Marc Zyngier01ac5e32013-01-21 19:36:16 -0500224 bool ready;
Marc Zyngier50926d82016-05-28 11:27:11 +0100225 bool initialized;
Marc Zyngierb47ef922013-01-21 19:36:14 -0500226
Andre Przywara598921362014-06-03 09:33:10 +0200227 /* vGIC model the kernel emulates for the guest (GICv2 or GICv3) */
228 u32 vgic_model;
229
Christoffer Dallaa075b02018-07-16 15:06:19 +0200230 /* Implementation revision as reported in the GICD_IIDR */
231 u32 implementation_rev;
232
Christoffer Dall32f87772018-07-16 15:06:26 +0200233 /* Userspace can write to GICv2 IGROUPR */
234 bool v2_groups_user_writable;
235
Andre Przywara0e4e82f2016-07-15 12:43:38 +0100236 /* Do injected MSIs require an additional device ID? */
237 bool msis_require_devid;
238
Marc Zyngier50926d82016-05-28 11:27:11 +0100239 int nr_spis;
Marc Zyngierc1bfb572014-07-08 12:09:01 +0100240
Marc Zyngier50926d82016-05-28 11:27:11 +0100241 /* base addresses in guest physical address space: */
242 gpa_t vgic_dist_base; /* distributor */
Andre Przywaraa0675c22014-06-07 00:54:51 +0200243 union {
Marc Zyngier50926d82016-05-28 11:27:11 +0100244 /* either a GICv2 CPU interface */
245 gpa_t vgic_cpu_base;
246 /* or a number of GICv3 redistributor regions */
Eric Augerdbd97332018-05-22 09:55:08 +0200247 struct list_head rd_regions;
Andre Przywaraa0675c22014-06-07 00:54:51 +0200248 };
Marc Zyngierb47ef922013-01-21 19:36:14 -0500249
Marc Zyngier50926d82016-05-28 11:27:11 +0100250 /* distributor enabled */
251 bool enabled;
Marc Zyngierb47ef922013-01-21 19:36:14 -0500252
Marc Zyngierbacf2c62020-03-04 20:33:26 +0000253 /* Wants SGIs without active state */
254 bool nassgireq;
255
Marc Zyngier50926d82016-05-28 11:27:11 +0100256 struct vgic_irq *spis;
Marc Zyngierb47ef922013-01-21 19:36:14 -0500257
Andre Przywaraa9cf86f2015-03-26 14:39:35 +0000258 struct vgic_io_device dist_iodev;
Andre Przywara0aa1de52016-07-15 12:43:29 +0100259
Andre Przywara1085fdc2016-07-15 12:43:31 +0100260 bool has_its;
261
Andre Przywara0aa1de52016-07-15 12:43:29 +0100262 /*
263 * Contains the attributes and gpa of the LPI configuration table.
264 * Since we report GICR_TYPER.CommonLPIAff as 0b00, we can share
265 * one address across all redistributors.
Zenghui Yubad36e42019-10-29 15:19:18 +0800266 * GICv3 spec: IHI 0069E 6.1.1 "LPI Configuration tables"
Andre Przywara0aa1de52016-07-15 12:43:29 +0100267 */
268 u64 propbaser;
Andre Przywara38024112016-07-15 12:43:33 +0100269
270 /* Protects the lpi_list and the count value below. */
Julien Thierryfc3bc472019-01-07 15:06:16 +0000271 raw_spinlock_t lpi_list_lock;
Andre Przywara38024112016-07-15 12:43:33 +0100272 struct list_head lpi_list_head;
273 int lpi_list_count;
Christoffer Dall10f92c42017-01-17 23:09:13 +0100274
Marc Zyngier24cab822019-03-18 10:13:01 +0000275 /* LPI translation cache */
276 struct list_head lpi_translation_cache;
277
Christoffer Dall10f92c42017-01-17 23:09:13 +0100278 /* used by vgic-debug */
279 struct vgic_state_iter *iter;
Marc Zyngier74fe55d2017-10-27 15:28:38 +0100280
281 /*
282 * GICv4 ITS per-VM data, containing the IRQ domain, the VPE
283 * array, the property table pointer as well as allocation
284 * data. This essentially ties the Linux IRQ core and ITS
285 * together, and avoids leaking KVM's data structures anywhere
286 * else.
287 */
288 struct its_vm its_vm;
Marc Zyngier1a89dd92013-01-21 19:36:12 -0500289};
290
Marc Zyngiereede8212013-05-30 10:20:36 +0100291struct vgic_v2_cpu_if {
292 u32 vgic_hcr;
293 u32 vgic_vmcr;
Marc Zyngiereede8212013-05-30 10:20:36 +0100294 u32 vgic_apr;
Marc Zyngier8f186d52014-02-04 18:13:03 +0000295 u32 vgic_lr[VGIC_V2_MAX_LRS];
Christoffer Dallfc5d1f12018-12-01 08:41:28 -0800296
297 unsigned int used_lrs;
Marc Zyngiereede8212013-05-30 10:20:36 +0100298};
299
Marc Zyngierb2fb1c02013-07-12 15:15:23 +0100300struct vgic_v3_cpu_if {
Marc Zyngierb2fb1c02013-07-12 15:15:23 +0100301 u32 vgic_hcr;
302 u32 vgic_vmcr;
Andre Przywara2f5fa412014-06-03 08:58:15 +0200303 u32 vgic_sre; /* Restored only, change ignored */
Marc Zyngierb2fb1c02013-07-12 15:15:23 +0100304 u32 vgic_ap0r[4];
305 u32 vgic_ap1r[4];
306 u64 vgic_lr[VGIC_V3_MAX_LRS];
Marc Zyngier74fe55d2017-10-27 15:28:38 +0100307
308 /*
309 * GICv4 ITS per-VPE data, containing the doorbell IRQ, the
310 * pending table pointer, the its_vm pointer and a few other
311 * HW specific things. As for the its_vm structure, this is
312 * linking the Linux IRQ subsystem and the ITS together.
313 */
314 struct its_vpe its_vpe;
Christoffer Dallfc5d1f12018-12-01 08:41:28 -0800315
316 unsigned int used_lrs;
Marc Zyngierb2fb1c02013-07-12 15:15:23 +0100317};
318
Marc Zyngier1a89dd92013-01-21 19:36:12 -0500319struct vgic_cpu {
Marc Zyngier9d949dc2013-01-21 19:36:14 -0500320 /* CPU vif control registers for world switch */
Marc Zyngiereede8212013-05-30 10:20:36 +0100321 union {
322 struct vgic_v2_cpu_if vgic_v2;
Marc Zyngierb2fb1c02013-07-12 15:15:23 +0100323 struct vgic_v3_cpu_if vgic_v3;
Marc Zyngiereede8212013-05-30 10:20:36 +0100324 };
Marc Zyngier6c3d63c2014-06-23 17:37:18 +0100325
Marc Zyngier50926d82016-05-28 11:27:11 +0100326 struct vgic_irq private_irqs[VGIC_NR_PRIVATE_IRQS];
Marc Zyngier59f00ff2016-02-02 19:35:34 +0000327
Julien Thierrye08d8d22019-01-07 15:06:17 +0000328 raw_spinlock_t ap_list_lock; /* Protects the ap_list */
Marc Zyngier50926d82016-05-28 11:27:11 +0100329
330 /*
331 * List of IRQs that this VCPU should consider because they are either
332 * Active or Pending (hence the name; AP list), or because they recently
333 * were one of the two and need to be migrated off this list to another
334 * VCPU.
335 */
336 struct list_head ap_list_head;
337
Andre Przywara8f6cdc12016-07-15 12:43:22 +0100338 /*
339 * Members below are used with GICv3 emulation only and represent
340 * parts of the redistributor.
341 */
342 struct vgic_io_device rd_iodev;
Eric Augerdbd97332018-05-22 09:55:08 +0200343 struct vgic_redist_region *rdreg;
Eric Auger28e9d4b2021-04-05 18:39:40 +0200344 u32 rdreg_index;
Andre Przywara0aa1de52016-07-15 12:43:29 +0100345
346 /* Contains the attributes and gpa of the LPI pending tables. */
347 u64 pendbaser;
348
349 bool lpis_enabled;
Vijaya Kumar Kd017d7b2017-01-26 19:50:51 +0530350
351 /* Cache guest priority bits */
352 u32 num_pri_bits;
353
354 /* Cache guest interrupt ID bits */
355 u32 num_id_bits;
Marc Zyngier1a89dd92013-01-21 19:36:12 -0500356};
357
Marc Zyngierfb5ee362016-09-06 09:28:45 +0100358extern struct static_key_false vgic_v2_cpuif_trap;
Marc Zyngier59da1cb2017-06-09 12:49:33 +0100359extern struct static_key_false vgic_v3_cpuif_trap;
Marc Zyngierfb5ee362016-09-06 09:28:45 +0100360
Christoffer Dallce01e4e2013-09-23 14:55:56 -0700361int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write);
Marc Zyngier6c3d63c2014-06-23 17:37:18 +0100362void kvm_vgic_early_init(struct kvm *kvm);
Christoffer Dall1aab6f42017-05-08 12:30:24 +0200363int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu);
Andre Przywara598921362014-06-03 09:33:10 +0200364int kvm_vgic_create(struct kvm *kvm, u32 type);
Marc Zyngierc1bfb572014-07-08 12:09:01 +0100365void kvm_vgic_destroy(struct kvm *kvm);
Marc Zyngierc1bfb572014-07-08 12:09:01 +0100366void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu);
Marc Zyngier50926d82016-05-28 11:27:11 +0100367int kvm_vgic_map_resources(struct kvm *kvm);
368int kvm_vgic_hyp_init(void);
Christoffer Dall5b0d2cc2017-03-18 13:56:56 +0100369void kvm_vgic_init_cpu_hardware(void);
Marc Zyngier50926d82016-05-28 11:27:11 +0100370
371int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
Christoffer Dallcb3f0ad2017-05-16 12:41:18 +0200372 bool level, void *owner);
Eric Auger47bbd312017-10-27 15:28:32 +0100373int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq,
Marc Zyngierdb75f1a2021-03-01 17:39:39 +0000374 u32 vintid, struct irq_ops *ops);
Eric Auger47bbd312017-10-27 15:28:32 +0100375int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid);
376bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int vintid);
Marc Zyngier1a89dd92013-01-21 19:36:12 -0500377
Marc Zyngier50926d82016-05-28 11:27:11 +0100378int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu);
379
Christoffer Dall328e5662016-03-24 11:21:04 +0100380void kvm_vgic_load(struct kvm_vcpu *vcpu);
381void kvm_vgic_put(struct kvm_vcpu *vcpu);
Marc Zyngier5eeaf102019-08-02 10:28:32 +0100382void kvm_vgic_vmcr_sync(struct kvm_vcpu *vcpu);
Christoffer Dall328e5662016-03-24 11:21:04 +0100383
Marc Zyngierf982cf42014-05-15 10:03:25 +0100384#define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel))
Marc Zyngier50926d82016-05-28 11:27:11 +0100385#define vgic_initialized(k) ((k)->arch.vgic.initialized)
Christoffer Dallc52edf52014-12-09 14:28:09 +0100386#define vgic_ready(k) ((k)->arch.vgic.ready)
Andre Przywara2defaff2016-03-07 17:32:29 +0700387#define vgic_valid_spi(k, i) (((i) >= VGIC_NR_PRIVATE_IRQS) && \
Marc Zyngier50926d82016-05-28 11:27:11 +0100388 ((i) < (k)->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS))
Marc Zyngier9d949dc2013-01-21 19:36:14 -0500389
Marc Zyngier50926d82016-05-28 11:27:11 +0100390bool kvm_vcpu_has_pending_irqs(struct kvm_vcpu *vcpu);
391void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu);
392void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu);
Christoffer Dall413aa802018-03-05 11:36:38 +0100393void kvm_vgic_reset_mapped_irq(struct kvm_vcpu *vcpu, u32 vintid);
Marc Zyngier50926d82016-05-28 11:27:11 +0100394
Marc Zyngier6249f2a2018-08-06 12:51:19 +0100395void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg, bool allow_group1);
Marc Zyngier8f186d52014-02-04 18:13:03 +0000396
Marc Zyngier50926d82016-05-28 11:27:11 +0100397/**
398 * kvm_vgic_get_max_vcpus - Get the maximum number of VCPUs allowed by HW
399 *
400 * The host's GIC naturally limits the maximum amount of VCPUs a guest
401 * can use.
402 */
403static inline int kvm_vgic_get_max_vcpus(void)
404{
405 return kvm_vgic_global_state.max_gic_vcpus;
406}
407
Eric Auger180ae7b2016-07-22 16:20:41 +0000408/**
409 * kvm_vgic_setup_default_irq_routing:
410 * Setup a default flat gsi routing table mapping all SPIs
411 */
412int kvm_vgic_setup_default_irq_routing(struct kvm *kvm);
413
Christoffer Dallc6ccd302017-05-04 13:24:20 +0200414int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner);
415
Marc Zyngier196b1362017-10-27 15:28:39 +0100416struct kvm_kernel_irq_routing_entry;
417
418int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int irq,
419 struct kvm_kernel_irq_routing_entry *irq_entry);
420
421int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int irq,
422 struct kvm_kernel_irq_routing_entry *irq_entry);
423
Marc Zyngier8e01d9a2019-10-27 14:41:59 +0000424int vgic_v4_load(struct kvm_vcpu *vcpu);
Shenming Lu57e3ceb2020-11-28 22:18:57 +0800425void vgic_v4_commit(struct kvm_vcpu *vcpu);
Marc Zyngier8e01d9a2019-10-27 14:41:59 +0000426int vgic_v4_put(struct kvm_vcpu *vcpu, bool need_db);
Marc Zyngierdf9ba952017-10-27 15:28:49 +0100427
Marc Zyngier50926d82016-05-28 11:27:11 +0100428#endif /* __KVM_ARM_VGIC_H */