1caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
27275acdfSMarc Zyngier /*
350926d82SMarc Zyngier * Copyright (C) 2015, 2016 ARM Ltd.
47275acdfSMarc Zyngier */
550926d82SMarc Zyngier #ifndef __KVM_ARM_VGIC_H
650926d82SMarc Zyngier #define __KVM_ARM_VGIC_H
7b18b5778SChristoffer Dall
86c9eeb5fSAndy Shevchenko #include <linux/bits.h>
97275acdfSMarc Zyngier #include <linux/kvm.h>
107275acdfSMarc Zyngier #include <linux/irqreturn.h>
116c9eeb5fSAndy Shevchenko #include <linux/kref.h>
126c9eeb5fSAndy Shevchenko #include <linux/mutex.h>
137275acdfSMarc Zyngier #include <linux/spinlock.h>
14fb5ee369SMarc Zyngier #include <linux/static_key.h>
157275acdfSMarc Zyngier #include <linux/types.h>
161d6f83f6SOliver Upton #include <linux/xarray.h>
176777f77fSAndre Przywara #include <kvm/iodev.h>
18424c3383SAndre Przywara #include <linux/list.h>
195a7a8426SVladimir Murzin #include <linux/jump_label.h>
207275acdfSMarc Zyngier
2174fe55dcSMarc Zyngier #include <linux/irqchip/arm-gic-v4.h>
2274fe55dcSMarc Zyngier
23e25028c8SEric Auger #define VGIC_V3_MAX_CPUS 512
2450926d82SMarc Zyngier #define VGIC_V2_MAX_CPUS 8
255fb66da6SMarc Zyngier #define VGIC_NR_IRQS_LEGACY 256
267275acdfSMarc Zyngier #define VGIC_NR_SGIS 16
277275acdfSMarc Zyngier #define VGIC_NR_PPIS 16
287275acdfSMarc Zyngier #define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS)
2950926d82SMarc Zyngier #define VGIC_MAX_PRIVATE (VGIC_NR_PRIVATE_IRQS - 1)
3050926d82SMarc Zyngier #define VGIC_MAX_SPI 1019
3150926d82SMarc Zyngier #define VGIC_MAX_RESERVED 1023
3250926d82SMarc Zyngier #define VGIC_MIN_LPI 8192
33180ae7b1SEric Auger #define KVM_IRQCHIP_NUM_PINS (1020 - 32)
348d5c6b06SMarc Zyngier
353cba4af3SChristoffer Dall #define irq_is_ppi(irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)
36ebb127f2SChristoffer Dall #define irq_is_spi(irq) ((irq) >= VGIC_NR_PRIVATE_IRQS && \
37ebb127f2SChristoffer Dall (irq) <= VGIC_MAX_SPI)
383cba4af3SChristoffer Dall
391a9b1305SMarc Zyngier enum vgic_type {
401a9b1305SMarc Zyngier VGIC_V2, /* Good ol' GICv2 */
41b2fb1c0dSMarc Zyngier VGIC_V3, /* New fancy GICv3 */
421a9b1305SMarc Zyngier };
431a9b1305SMarc Zyngier
4450926d82SMarc Zyngier /* same for all guests, as depending only on the _host's_ GIC model */
4550926d82SMarc Zyngier struct vgic_global {
4650926d82SMarc Zyngier /* type of the host GIC */
471a9b1305SMarc Zyngier enum vgic_type type;
4850926d82SMarc Zyngier
49ca85f623SMarc Zyngier /* Physical address of vgic virtual cpu interface */
50ca85f623SMarc Zyngier phys_addr_t vcpu_base;
5150926d82SMarc Zyngier
521bb32a44SMarc Zyngier /* GICV mapping, kernel VA */
53bf8feb39SMarc Zyngier void __iomem *vcpu_base_va;
541bb32a44SMarc Zyngier /* GICV mapping, HYP VA */
551bb32a44SMarc Zyngier void __iomem *vcpu_hyp_va;
56bf8feb39SMarc Zyngier
571bb32a44SMarc Zyngier /* virtual control interface mapping, kernel VA */
58ca85f623SMarc Zyngier void __iomem *vctrl_base;
591bb32a44SMarc Zyngier /* virtual control interface mapping, HYP VA */
601bb32a44SMarc Zyngier void __iomem *vctrl_hyp;
6150926d82SMarc Zyngier
6250926d82SMarc Zyngier /* Number of implemented list registers */
6350926d82SMarc Zyngier int nr_lr;
6450926d82SMarc Zyngier
6550926d82SMarc Zyngier /* Maintenance IRQ number */
6650926d82SMarc Zyngier unsigned int maint_irq;
6750926d82SMarc Zyngier
6850926d82SMarc Zyngier /* maximum number of VCPUs allowed (GICv2 limits us to 8) */
693caa2d8cSAndre Przywara int max_gic_vcpus;
7050926d82SMarc Zyngier
71b5d84ff6SAndre Przywara /* Only needed for the legacy KVM_CREATE_IRQCHIP */
72b5d84ff6SAndre Przywara bool can_emulate_gicv2;
735a7a8426SVladimir Murzin
74e7c48059SMarc Zyngier /* Hardware has GICv4? */
75e7c48059SMarc Zyngier bool has_gicv4;
76ae699ad3SMarc Zyngier bool has_gicv4_1;
77e7c48059SMarc Zyngier
78f6c3e24fSMarc Zyngier /* Pseudo GICv3 from outer space */
79f6c3e24fSMarc Zyngier bool no_hw_deactivation;
80f6c3e24fSMarc Zyngier
815a7a8426SVladimir Murzin /* GIC system register CPU interface */
825a7a8426SVladimir Murzin struct static_key_false gicv3_cpuif;
83d017d7b0SVijaya Kumar K
84d017d7b0SVijaya Kumar K u32 ich_vtr_el2;
85ca85f623SMarc Zyngier };
86ca85f623SMarc Zyngier
8750926d82SMarc Zyngier extern struct vgic_global kvm_vgic_global_state;
8850926d82SMarc Zyngier
8950926d82SMarc Zyngier #define VGIC_V2_MAX_LRS (1 << 6)
9050926d82SMarc Zyngier #define VGIC_V3_MAX_LRS 16
9150926d82SMarc Zyngier #define VGIC_V3_LR_INDEX(lr) (VGIC_V3_MAX_LRS - 1 - lr)
9250926d82SMarc Zyngier
9350926d82SMarc Zyngier enum vgic_irq_config {
9450926d82SMarc Zyngier VGIC_CONFIG_EDGE = 0,
9550926d82SMarc Zyngier VGIC_CONFIG_LEVEL
96b26e5fdaSAndre Przywara };
97b26e5fdaSAndre Przywara
98db75f1a3SMarc Zyngier /*
99db75f1a3SMarc Zyngier * Per-irq ops overriding some common behavious.
100db75f1a3SMarc Zyngier *
101db75f1a3SMarc Zyngier * Always called in non-preemptible section and the functions can use
102db75f1a3SMarc Zyngier * kvm_arm_get_running_vcpu() to get the vcpu pointer for private IRQs.
103db75f1a3SMarc Zyngier */
104db75f1a3SMarc Zyngier struct irq_ops {
105354920e7SMarc Zyngier /* Per interrupt flags for special-cased interrupts */
106354920e7SMarc Zyngier unsigned long flags;
107354920e7SMarc Zyngier
108354920e7SMarc Zyngier #define VGIC_IRQ_SW_RESAMPLE BIT(0) /* Clear the active state for resampling */
109354920e7SMarc Zyngier
110db75f1a3SMarc Zyngier /*
111db75f1a3SMarc Zyngier * Callback function pointer to in-kernel devices that can tell us the
112db75f1a3SMarc Zyngier * state of the input level of mapped level-triggered IRQ faster than
113db75f1a3SMarc Zyngier * peaking into the physical GIC.
114db75f1a3SMarc Zyngier */
115db75f1a3SMarc Zyngier bool (*get_input_level)(int vintid);
116db75f1a3SMarc Zyngier };
117db75f1a3SMarc Zyngier
11850926d82SMarc Zyngier struct vgic_irq {
1198fa3adb8SJulien Thierry raw_spinlock_t irq_lock; /* Protects the content of the struct */
120a5c7f011SOliver Upton struct rcu_head rcu;
12150926d82SMarc Zyngier struct list_head ap_list;
12250926d82SMarc Zyngier
12350926d82SMarc Zyngier struct kvm_vcpu *vcpu; /* SGIs and PPIs: The VCPU
12450926d82SMarc Zyngier * SPIs and LPIs: The VCPU whose ap_list
12550926d82SMarc Zyngier * this is queued on.
12650926d82SMarc Zyngier */
12750926d82SMarc Zyngier
12850926d82SMarc Zyngier struct kvm_vcpu *target_vcpu; /* The VCPU that this interrupt should
12950926d82SMarc Zyngier * be sent to, as a result of the
13050926d82SMarc Zyngier * targets reg (v2) or the
13150926d82SMarc Zyngier * affinity reg (v3).
13250926d82SMarc Zyngier */
13350926d82SMarc Zyngier
13450926d82SMarc Zyngier u32 intid; /* Guest visible INTID */
13550926d82SMarc Zyngier bool line_level; /* Level only */
1368694e4daSChristoffer Dall bool pending_latch; /* The pending latch state used to calculate
1378694e4daSChristoffer Dall * the pending state for both level
1388694e4daSChristoffer Dall * and edge triggered IRQs. */
13950926d82SMarc Zyngier bool active; /* not used for LPIs */
14050926d82SMarc Zyngier bool enabled;
14150926d82SMarc Zyngier bool hw; /* Tied to HW IRQ */
1425dd4b924SAndre Przywara struct kref refcount; /* Used for LPIs */
14350926d82SMarc Zyngier u32 hwintid; /* HW INTID number */
14447bbd31fSEric Auger unsigned int host_irq; /* linux irq corresponding to hwintid */
14550926d82SMarc Zyngier union {
14650926d82SMarc Zyngier u8 targets; /* GICv2 target VCPUs mask */
14750926d82SMarc Zyngier u32 mpidr; /* GICv3 target VCPU */
14850926d82SMarc Zyngier };
14950926d82SMarc Zyngier u8 source; /* GICv2 SGIs only */
15053692908SMarc Zyngier u8 active_source; /* GICv2 SGIs only */
15150926d82SMarc Zyngier u8 priority;
1528df3c8f3SChristoffer Dall u8 group; /* 0 == group 0, 1 == group 1 */
15350926d82SMarc Zyngier enum vgic_irq_config config; /* Level or edge */
154c6ccd30eSChristoffer Dall
155db75f1a3SMarc Zyngier struct irq_ops *ops;
156b6909a65SChristoffer Dall
157c6ccd30eSChristoffer Dall void *owner; /* Opaque pointer to reserve an interrupt
158c6ccd30eSChristoffer Dall for in-kernel devices. */
15950926d82SMarc Zyngier };
16050926d82SMarc Zyngier
vgic_irq_needs_resampling(struct vgic_irq * irq)161354920e7SMarc Zyngier static inline bool vgic_irq_needs_resampling(struct vgic_irq *irq)
162354920e7SMarc Zyngier {
163354920e7SMarc Zyngier return irq->ops && (irq->ops->flags & VGIC_IRQ_SW_RESAMPLE);
164354920e7SMarc Zyngier }
165354920e7SMarc Zyngier
16650926d82SMarc Zyngier struct vgic_register_region;
16759c5ab40SAndre Przywara struct vgic_its;
16859c5ab40SAndre Przywara
16959c5ab40SAndre Przywara enum iodev_type {
17059c5ab40SAndre Przywara IODEV_CPUIF,
17159c5ab40SAndre Przywara IODEV_DIST,
17259c5ab40SAndre Przywara IODEV_REDIST,
17359c5ab40SAndre Przywara IODEV_ITS
17459c5ab40SAndre Przywara };
17550926d82SMarc Zyngier
1766777f77fSAndre Przywara struct vgic_io_device {
17750926d82SMarc Zyngier gpa_t base_addr;
17859c5ab40SAndre Przywara union {
1796777f77fSAndre Przywara struct kvm_vcpu *redist_vcpu;
18059c5ab40SAndre Przywara struct vgic_its *its;
18159c5ab40SAndre Przywara };
18250926d82SMarc Zyngier const struct vgic_register_region *regions;
18359c5ab40SAndre Przywara enum iodev_type iodev_type;
18450926d82SMarc Zyngier int nr_regions;
1856777f77fSAndre Przywara struct kvm_io_device dev;
1866777f77fSAndre Przywara };
1876777f77fSAndre Przywara
18859c5ab40SAndre Przywara struct vgic_its {
18959c5ab40SAndre Przywara /* The base address of the ITS control register frame */
19059c5ab40SAndre Przywara gpa_t vgic_its_base;
19159c5ab40SAndre Przywara
19259c5ab40SAndre Przywara bool enabled;
19359c5ab40SAndre Przywara struct vgic_io_device iodev;
194bb717644SMarc Zyngier struct kvm_device *dev;
195424c3383SAndre Przywara
196424c3383SAndre Przywara /* These registers correspond to GITS_BASER{0,1} */
197424c3383SAndre Przywara u64 baser_device_table;
198424c3383SAndre Przywara u64 baser_coll_table;
199424c3383SAndre Przywara
200424c3383SAndre Przywara /* Protects the command queue */
201424c3383SAndre Przywara struct mutex cmd_lock;
202424c3383SAndre Przywara u64 cbaser;
203424c3383SAndre Przywara u32 creadr;
204424c3383SAndre Przywara u32 cwriter;
205424c3383SAndre Przywara
20671afe470SEric Auger /* migration ABI revision in use */
20771afe470SEric Auger u32 abi_rev;
20871afe470SEric Auger
209424c3383SAndre Przywara /* Protects the device and collection lists */
210424c3383SAndre Przywara struct mutex its_lock;
211424c3383SAndre Przywara struct list_head device_list;
212424c3383SAndre Przywara struct list_head collection_list;
2138201d102SOliver Upton
2148201d102SOliver Upton /*
2158201d102SOliver Upton * Caches the (device_id, event_id) -> vgic_irq translation for
2168201d102SOliver Upton * LPIs that are mapped and enabled.
2178201d102SOliver Upton */
2188201d102SOliver Upton struct xarray translation_cache;
21959c5ab40SAndre Przywara };
22059c5ab40SAndre Przywara
22110f92c4cSChristoffer Dall struct vgic_state_iter;
22210f92c4cSChristoffer Dall
223dbd9733aSEric Auger struct vgic_redist_region {
224dbd9733aSEric Auger u32 index;
225dbd9733aSEric Auger gpa_t base;
226dbd9733aSEric Auger u32 count; /* number of redistributors or 0 if single region */
227dbd9733aSEric Auger u32 free_index; /* index of the next free redistributor */
228dbd9733aSEric Auger struct list_head list;
229dbd9733aSEric Auger };
230dbd9733aSEric Auger
2317275acdfSMarc Zyngier struct vgic_dist {
232f982cf4eSMarc Zyngier bool in_kernel;
2337275acdfSMarc Zyngier bool ready;
23450926d82SMarc Zyngier bool initialized;
2357275acdfSMarc Zyngier
23659892136SAndre Przywara /* vGIC model the kernel emulates for the guest (GICv2 or GICv3) */
23759892136SAndre Przywara u32 vgic_model;
23859892136SAndre Przywara
239aa075b0fSChristoffer Dall /* Implementation revision as reported in the GICD_IIDR */
240aa075b0fSChristoffer Dall u32 implementation_rev;
24149a1a2c7SMarc Zyngier #define KVM_VGIC_IMP_REV_2 2 /* GICv2 restorable groups */
24249a1a2c7SMarc Zyngier #define KVM_VGIC_IMP_REV_3 3 /* GICv3 GICR_CTLR.{IW,CES,RWP} */
24349a1a2c7SMarc Zyngier #define KVM_VGIC_IMP_REV_LATEST KVM_VGIC_IMP_REV_3
244aa075b0fSChristoffer Dall
24532f8777eSChristoffer Dall /* Userspace can write to GICv2 IGROUPR */
24632f8777eSChristoffer Dall bool v2_groups_user_writable;
24732f8777eSChristoffer Dall
2480e4e82f1SAndre Przywara /* Do injected MSIs require an additional device ID? */
2490e4e82f1SAndre Przywara bool msis_require_devid;
2500e4e82f1SAndre Przywara
25150926d82SMarc Zyngier int nr_spis;
252c1bfb577SMarc Zyngier
25350926d82SMarc Zyngier /* base addresses in guest physical address space: */
25450926d82SMarc Zyngier gpa_t vgic_dist_base; /* distributor */
255a0675c25SAndre Przywara union {
25650926d82SMarc Zyngier /* either a GICv2 CPU interface */
25750926d82SMarc Zyngier gpa_t vgic_cpu_base;
25850926d82SMarc Zyngier /* or a number of GICv3 redistributor regions */
259dbd9733aSEric Auger struct list_head rd_regions;
260a0675c25SAndre Przywara };
2617275acdfSMarc Zyngier
26250926d82SMarc Zyngier /* distributor enabled */
26350926d82SMarc Zyngier bool enabled;
2647275acdfSMarc Zyngier
265bacf2c60SMarc Zyngier /* Wants SGIs without active state */
266bacf2c60SMarc Zyngier bool nassgireq;
267bacf2c60SMarc Zyngier
26850926d82SMarc Zyngier struct vgic_irq *spis;
2697275acdfSMarc Zyngier
270a9cf86f6SAndre Przywara struct vgic_io_device dist_iodev;
2710aa1de57SAndre Przywara
2721085fdc6SAndre Przywara bool has_its;
273a23eaf93SGavin Shan bool table_write_in_progress;
2741085fdc6SAndre Przywara
2750aa1de57SAndre Przywara /*
2760aa1de57SAndre Przywara * Contains the attributes and gpa of the LPI configuration table.
2770aa1de57SAndre Przywara * Since we report GICR_TYPER.CommonLPIAff as 0b00, we can share
2780aa1de57SAndre Przywara * one address across all redistributors.
279bad36e4eSZenghui Yu * GICv3 spec: IHI 0069E 6.1.1 "LPI Configuration tables"
2800aa1de57SAndre Przywara */
2810aa1de57SAndre Przywara u64 propbaser;
2823802411dSAndre Przywara
28385d3ccc8SOliver Upton #define LPI_XA_MARK_DEBUG_ITER XA_MARK_0
2841d6f83f6SOliver Upton struct xarray lpi_xa;
28510f92c4cSChristoffer Dall
28610f92c4cSChristoffer Dall /* used by vgic-debug */
28710f92c4cSChristoffer Dall struct vgic_state_iter *iter;
28874fe55dcSMarc Zyngier
28974fe55dcSMarc Zyngier /*
29074fe55dcSMarc Zyngier * GICv4 ITS per-VM data, containing the IRQ domain, the VPE
29174fe55dcSMarc Zyngier * array, the property table pointer as well as allocation
29274fe55dcSMarc Zyngier * data. This essentially ties the Linux IRQ core and ITS
29374fe55dcSMarc Zyngier * together, and avoids leaking KVM's data structures anywhere
29474fe55dcSMarc Zyngier * else.
29574fe55dcSMarc Zyngier */
29674fe55dcSMarc Zyngier struct its_vm its_vm;
2977275acdfSMarc Zyngier };
2987275acdfSMarc Zyngier
299eede821dSMarc Zyngier struct vgic_v2_cpu_if {
300eede821dSMarc Zyngier u32 vgic_hcr;
301eede821dSMarc Zyngier u32 vgic_vmcr;
302eede821dSMarc Zyngier u32 vgic_apr;
3038f186d52SMarc Zyngier u32 vgic_lr[VGIC_V2_MAX_LRS];
304fc5d1f1aSChristoffer Dall
305fc5d1f1aSChristoffer Dall unsigned int used_lrs;
306eede821dSMarc Zyngier };
307eede821dSMarc Zyngier
308b2fb1c0dSMarc Zyngier struct vgic_v3_cpu_if {
309b2fb1c0dSMarc Zyngier u32 vgic_hcr;
310b2fb1c0dSMarc Zyngier u32 vgic_vmcr;
3112f5fa41aSAndre Przywara u32 vgic_sre; /* Restored only, change ignored */
312b2fb1c0dSMarc Zyngier u32 vgic_ap0r[4];
313b2fb1c0dSMarc Zyngier u32 vgic_ap1r[4];
314b2fb1c0dSMarc Zyngier u64 vgic_lr[VGIC_V3_MAX_LRS];
31574fe55dcSMarc Zyngier
31674fe55dcSMarc Zyngier /*
31774fe55dcSMarc Zyngier * GICv4 ITS per-VPE data, containing the doorbell IRQ, the
31874fe55dcSMarc Zyngier * pending table pointer, the its_vm pointer and a few other
31974fe55dcSMarc Zyngier * HW specific things. As for the its_vm structure, this is
32074fe55dcSMarc Zyngier * linking the Linux IRQ subsystem and the ITS together.
32174fe55dcSMarc Zyngier */
32274fe55dcSMarc Zyngier struct its_vpe its_vpe;
323fc5d1f1aSChristoffer Dall
324fc5d1f1aSChristoffer Dall unsigned int used_lrs;
325b2fb1c0dSMarc Zyngier };
326b2fb1c0dSMarc Zyngier
3277275acdfSMarc Zyngier struct vgic_cpu {
3287275acdfSMarc Zyngier /* CPU vif control registers for world switch */
329eede821dSMarc Zyngier union {
330eede821dSMarc Zyngier struct vgic_v2_cpu_if vgic_v2;
331b2fb1c0dSMarc Zyngier struct vgic_v3_cpu_if vgic_v3;
332eede821dSMarc Zyngier };
3336c3d63c9SMarc Zyngier
334*03b3d00aSMarc Zyngier struct vgic_irq *private_irqs;
33550926d82SMarc Zyngier
336e08d8d29SJulien Thierry raw_spinlock_t ap_list_lock; /* Protects the ap_list */
33750926d82SMarc Zyngier
33850926d82SMarc Zyngier /*
33950926d82SMarc Zyngier * List of IRQs that this VCPU should consider because they are either
34050926d82SMarc Zyngier * Active or Pending (hence the name; AP list), or because they recently
34150926d82SMarc Zyngier * were one of the two and need to be migrated off this list to another
34250926d82SMarc Zyngier * VCPU.
34350926d82SMarc Zyngier */
34450926d82SMarc Zyngier struct list_head ap_list_head;
34559f00ff9SMarc Zyngier
3468f6cdc1cSAndre Przywara /*
3478f6cdc1cSAndre Przywara * Members below are used with GICv3 emulation only and represent
3488f6cdc1cSAndre Przywara * parts of the redistributor.
3498f6cdc1cSAndre Przywara */
3508f6cdc1cSAndre Przywara struct vgic_io_device rd_iodev;
351dbd9733aSEric Auger struct vgic_redist_region *rdreg;
35228e9d4bcSEric Auger u32 rdreg_index;
3534645d11fSMarc Zyngier atomic_t syncr_busy;
3540aa1de57SAndre Przywara
3550aa1de57SAndre Przywara /* Contains the attributes and gpa of the LPI pending tables. */
3560aa1de57SAndre Przywara u64 pendbaser;
35794828468SMarc Zyngier /* GICR_CTLR.{ENABLE_LPIS,RWP} */
35894828468SMarc Zyngier atomic_t ctlr;
359d017d7b0SVijaya Kumar K
360d017d7b0SVijaya Kumar K /* Cache guest priority bits */
361d017d7b0SVijaya Kumar K u32 num_pri_bits;
362d017d7b0SVijaya Kumar K
363d017d7b0SVijaya Kumar K /* Cache guest interrupt ID bits */
364d017d7b0SVijaya Kumar K u32 num_id_bits;
3657275acdfSMarc Zyngier };
3667275acdfSMarc Zyngier
367fb5ee369SMarc Zyngier extern struct static_key_false vgic_v2_cpuif_trap;
36859da1cbfSMarc Zyngier extern struct static_key_false vgic_v3_cpuif_trap;
369fb5ee369SMarc Zyngier
3709f968c92SMarc Zyngier int kvm_set_legacy_vgic_v2_addr(struct kvm *kvm, struct kvm_arm_device_addr *dev_addr);
3716c3d63c9SMarc Zyngier void kvm_vgic_early_init(struct kvm *kvm);
3721aab6f46SChristoffer Dall int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu);
37359892136SAndre Przywara int kvm_vgic_create(struct kvm *kvm, u32 type);
374c1bfb577SMarc Zyngier void kvm_vgic_destroy(struct kvm *kvm);
375c1bfb577SMarc Zyngier void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu);
37650926d82SMarc Zyngier int kvm_vgic_map_resources(struct kvm *kvm);
37750926d82SMarc Zyngier int kvm_vgic_hyp_init(void);
3785b0d2cc2SChristoffer Dall void kvm_vgic_init_cpu_hardware(void);
37950926d82SMarc Zyngier
3809a0a75d3SMarc Zyngier int kvm_vgic_inject_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,
3819a0a75d3SMarc Zyngier unsigned int intid, bool level, void *owner);
38247bbd31fSEric Auger int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq,
383db75f1a3SMarc Zyngier u32 vintid, struct irq_ops *ops);
38447bbd31fSEric Auger int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid);
38581dc9504SMarc Zyngier int kvm_vgic_get_map(struct kvm_vcpu *vcpu, unsigned int vintid);
38647bbd31fSEric Auger bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int vintid);
3877275acdfSMarc Zyngier
38850926d82SMarc Zyngier int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu);
38950926d82SMarc Zyngier
390328e5664SChristoffer Dall void kvm_vgic_load(struct kvm_vcpu *vcpu);
391328e5664SChristoffer Dall void kvm_vgic_put(struct kvm_vcpu *vcpu);
392328e5664SChristoffer Dall
393f982cf4eSMarc Zyngier #define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel))
39450926d82SMarc Zyngier #define vgic_initialized(k) ((k)->arch.vgic.initialized)
395c52edf5fSChristoffer Dall #define vgic_ready(k) ((k)->arch.vgic.ready)
3962defaff4SAndre Przywara #define vgic_valid_spi(k, i) (((i) >= VGIC_NR_PRIVATE_IRQS) && \
39750926d82SMarc Zyngier ((i) < (k)->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS))
3987275acdfSMarc Zyngier
39950926d82SMarc Zyngier bool kvm_vcpu_has_pending_irqs(struct kvm_vcpu *vcpu);
40050926d82SMarc Zyngier void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu);
40150926d82SMarc Zyngier void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu);
402413aa807SChristoffer Dall void kvm_vgic_reset_mapped_irq(struct kvm_vcpu *vcpu, u32 vintid);
40350926d82SMarc Zyngier
4046249f2a4SMarc Zyngier void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg, bool allow_group1);
4058f186d52SMarc Zyngier
40650926d82SMarc Zyngier /**
40750926d82SMarc Zyngier * kvm_vgic_get_max_vcpus - Get the maximum number of VCPUs allowed by HW
40850926d82SMarc Zyngier *
40950926d82SMarc Zyngier * The host's GIC naturally limits the maximum amount of VCPUs a guest
41050926d82SMarc Zyngier * can use.
41150926d82SMarc Zyngier */
kvm_vgic_get_max_vcpus(void)41250926d82SMarc Zyngier static inline int kvm_vgic_get_max_vcpus(void)
41350926d82SMarc Zyngier {
41450926d82SMarc Zyngier return kvm_vgic_global_state.max_gic_vcpus;
41550926d82SMarc Zyngier }
41650926d82SMarc Zyngier
417180ae7b1SEric Auger /**
418180ae7b1SEric Auger * kvm_vgic_setup_default_irq_routing:
419180ae7b1SEric Auger * Setup a default flat gsi routing table mapping all SPIs
420180ae7b1SEric Auger */
421180ae7b1SEric Auger int kvm_vgic_setup_default_irq_routing(struct kvm *kvm);
422180ae7b1SEric Auger
423c6ccd30eSChristoffer Dall int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner);
424c6ccd30eSChristoffer Dall
425196b1364SMarc Zyngier struct kvm_kernel_irq_routing_entry;
426196b1364SMarc Zyngier
427196b1364SMarc Zyngier int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int irq,
428196b1364SMarc Zyngier struct kvm_kernel_irq_routing_entry *irq_entry);
429196b1364SMarc Zyngier
430196b1364SMarc Zyngier int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int irq,
431196b1364SMarc Zyngier struct kvm_kernel_irq_routing_entry *irq_entry);
432196b1364SMarc Zyngier
4338e01d9a3SMarc Zyngier int vgic_v4_load(struct kvm_vcpu *vcpu);
43457e3cebdSShenming Lu void vgic_v4_commit(struct kvm_vcpu *vcpu);
435b321c31cSMarc Zyngier int vgic_v4_put(struct kvm_vcpu *vcpu);
436df9ba959SMarc Zyngier
437466d27e4SMarc Zyngier /* CPU HP callbacks */
438466d27e4SMarc Zyngier void kvm_vgic_cpu_up(void);
439466d27e4SMarc Zyngier void kvm_vgic_cpu_down(void);
440466d27e4SMarc Zyngier
44150926d82SMarc Zyngier #endif /* __KVM_ARM_VGIC_H */
442