xref: /openbmc/linux/include/kvm/arm_vgic.h (revision fc3bc475231e12e9c0142f60100cf84d077c79e1)
17275acdfSMarc Zyngier /*
250926d82SMarc Zyngier  * Copyright (C) 2015, 2016 ARM Ltd.
37275acdfSMarc Zyngier  *
47275acdfSMarc Zyngier  * This program is free software; you can redistribute it and/or modify
57275acdfSMarc Zyngier  * it under the terms of the GNU General Public License version 2 as
67275acdfSMarc Zyngier  * published by the Free Software Foundation.
77275acdfSMarc Zyngier  *
87275acdfSMarc Zyngier  * This program is distributed in the hope that it will be useful,
97275acdfSMarc Zyngier  * but WITHOUT ANY WARRANTY; without even the implied warranty of
107275acdfSMarc Zyngier  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
117275acdfSMarc Zyngier  * GNU General Public License for more details.
127275acdfSMarc Zyngier  *
137275acdfSMarc Zyngier  * You should have received a copy of the GNU General Public License
1450926d82SMarc Zyngier  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
157275acdfSMarc Zyngier  */
1650926d82SMarc Zyngier #ifndef __KVM_ARM_VGIC_H
1750926d82SMarc Zyngier #define __KVM_ARM_VGIC_H
18b18b5778SChristoffer Dall 
197275acdfSMarc Zyngier #include <linux/kernel.h>
207275acdfSMarc Zyngier #include <linux/kvm.h>
217275acdfSMarc Zyngier #include <linux/irqreturn.h>
227275acdfSMarc Zyngier #include <linux/spinlock.h>
23fb5ee369SMarc Zyngier #include <linux/static_key.h>
247275acdfSMarc Zyngier #include <linux/types.h>
256777f77fSAndre Przywara #include <kvm/iodev.h>
26424c3383SAndre Przywara #include <linux/list.h>
275a7a8426SVladimir Murzin #include <linux/jump_label.h>
287275acdfSMarc Zyngier 
2974fe55dcSMarc Zyngier #include <linux/irqchip/arm-gic-v4.h>
3074fe55dcSMarc Zyngier 
31e25028c8SEric Auger #define VGIC_V3_MAX_CPUS	512
3250926d82SMarc Zyngier #define VGIC_V2_MAX_CPUS	8
335fb66da6SMarc Zyngier #define VGIC_NR_IRQS_LEGACY     256
347275acdfSMarc Zyngier #define VGIC_NR_SGIS		16
357275acdfSMarc Zyngier #define VGIC_NR_PPIS		16
367275acdfSMarc Zyngier #define VGIC_NR_PRIVATE_IRQS	(VGIC_NR_SGIS + VGIC_NR_PPIS)
3750926d82SMarc Zyngier #define VGIC_MAX_PRIVATE	(VGIC_NR_PRIVATE_IRQS - 1)
3850926d82SMarc Zyngier #define VGIC_MAX_SPI		1019
3950926d82SMarc Zyngier #define VGIC_MAX_RESERVED	1023
4050926d82SMarc Zyngier #define VGIC_MIN_LPI		8192
41180ae7b1SEric Auger #define KVM_IRQCHIP_NUM_PINS	(1020 - 32)
428d5c6b06SMarc Zyngier 
433cba4af3SChristoffer Dall #define irq_is_ppi(irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)
44ebb127f2SChristoffer Dall #define irq_is_spi(irq) ((irq) >= VGIC_NR_PRIVATE_IRQS && \
45ebb127f2SChristoffer Dall 			 (irq) <= VGIC_MAX_SPI)
463cba4af3SChristoffer Dall 
471a9b1305SMarc Zyngier enum vgic_type {
481a9b1305SMarc Zyngier 	VGIC_V2,		/* Good ol' GICv2 */
49b2fb1c0dSMarc Zyngier 	VGIC_V3,		/* New fancy GICv3 */
501a9b1305SMarc Zyngier };
511a9b1305SMarc Zyngier 
5250926d82SMarc Zyngier /* same for all guests, as depending only on the _host's_ GIC model */
5350926d82SMarc Zyngier struct vgic_global {
5450926d82SMarc Zyngier 	/* type of the host GIC */
551a9b1305SMarc Zyngier 	enum vgic_type		type;
5650926d82SMarc Zyngier 
57ca85f623SMarc Zyngier 	/* Physical address of vgic virtual cpu interface */
58ca85f623SMarc Zyngier 	phys_addr_t		vcpu_base;
5950926d82SMarc Zyngier 
601bb32a44SMarc Zyngier 	/* GICV mapping, kernel VA */
61bf8feb39SMarc Zyngier 	void __iomem		*vcpu_base_va;
621bb32a44SMarc Zyngier 	/* GICV mapping, HYP VA */
631bb32a44SMarc Zyngier 	void __iomem		*vcpu_hyp_va;
64bf8feb39SMarc Zyngier 
651bb32a44SMarc Zyngier 	/* virtual control interface mapping, kernel VA */
66ca85f623SMarc Zyngier 	void __iomem		*vctrl_base;
671bb32a44SMarc Zyngier 	/* virtual control interface mapping, HYP VA */
681bb32a44SMarc Zyngier 	void __iomem		*vctrl_hyp;
6950926d82SMarc Zyngier 
7050926d82SMarc Zyngier 	/* Number of implemented list registers */
7150926d82SMarc Zyngier 	int			nr_lr;
7250926d82SMarc Zyngier 
7350926d82SMarc Zyngier 	/* Maintenance IRQ number */
7450926d82SMarc Zyngier 	unsigned int		maint_irq;
7550926d82SMarc Zyngier 
7650926d82SMarc Zyngier 	/* maximum number of VCPUs allowed (GICv2 limits us to 8) */
773caa2d8cSAndre Przywara 	int			max_gic_vcpus;
7850926d82SMarc Zyngier 
79b5d84ff6SAndre Przywara 	/* Only needed for the legacy KVM_CREATE_IRQCHIP */
80b5d84ff6SAndre Przywara 	bool			can_emulate_gicv2;
815a7a8426SVladimir Murzin 
82e7c48059SMarc Zyngier 	/* Hardware has GICv4? */
83e7c48059SMarc Zyngier 	bool			has_gicv4;
84e7c48059SMarc Zyngier 
855a7a8426SVladimir Murzin 	/* GIC system register CPU interface */
865a7a8426SVladimir Murzin 	struct static_key_false gicv3_cpuif;
87d017d7b0SVijaya Kumar K 
88d017d7b0SVijaya Kumar K 	u32			ich_vtr_el2;
89ca85f623SMarc Zyngier };
90ca85f623SMarc Zyngier 
9150926d82SMarc Zyngier extern struct vgic_global kvm_vgic_global_state;
9250926d82SMarc Zyngier 
9350926d82SMarc Zyngier #define VGIC_V2_MAX_LRS		(1 << 6)
9450926d82SMarc Zyngier #define VGIC_V3_MAX_LRS		16
9550926d82SMarc Zyngier #define VGIC_V3_LR_INDEX(lr)	(VGIC_V3_MAX_LRS - 1 - lr)
9650926d82SMarc Zyngier 
9750926d82SMarc Zyngier enum vgic_irq_config {
9850926d82SMarc Zyngier 	VGIC_CONFIG_EDGE = 0,
9950926d82SMarc Zyngier 	VGIC_CONFIG_LEVEL
100b26e5fdaSAndre Przywara };
101b26e5fdaSAndre Przywara 
10250926d82SMarc Zyngier struct vgic_irq {
1038fa3adb8SJulien Thierry 	raw_spinlock_t irq_lock;	/* Protects the content of the struct */
1043802411dSAndre Przywara 	struct list_head lpi_list;	/* Used to link all LPIs together */
10550926d82SMarc Zyngier 	struct list_head ap_list;
10650926d82SMarc Zyngier 
10750926d82SMarc Zyngier 	struct kvm_vcpu *vcpu;		/* SGIs and PPIs: The VCPU
10850926d82SMarc Zyngier 					 * SPIs and LPIs: The VCPU whose ap_list
10950926d82SMarc Zyngier 					 * this is queued on.
11050926d82SMarc Zyngier 					 */
11150926d82SMarc Zyngier 
11250926d82SMarc Zyngier 	struct kvm_vcpu *target_vcpu;	/* The VCPU that this interrupt should
11350926d82SMarc Zyngier 					 * be sent to, as a result of the
11450926d82SMarc Zyngier 					 * targets reg (v2) or the
11550926d82SMarc Zyngier 					 * affinity reg (v3).
11650926d82SMarc Zyngier 					 */
11750926d82SMarc Zyngier 
11850926d82SMarc Zyngier 	u32 intid;			/* Guest visible INTID */
11950926d82SMarc Zyngier 	bool line_level;		/* Level only */
1208694e4daSChristoffer Dall 	bool pending_latch;		/* The pending latch state used to calculate
1218694e4daSChristoffer Dall 					 * the pending state for both level
1228694e4daSChristoffer Dall 					 * and edge triggered IRQs. */
12350926d82SMarc Zyngier 	bool active;			/* not used for LPIs */
12450926d82SMarc Zyngier 	bool enabled;
12550926d82SMarc Zyngier 	bool hw;			/* Tied to HW IRQ */
1265dd4b924SAndre Przywara 	struct kref refcount;		/* Used for LPIs */
12750926d82SMarc Zyngier 	u32 hwintid;			/* HW INTID number */
12847bbd31fSEric Auger 	unsigned int host_irq;		/* linux irq corresponding to hwintid */
12950926d82SMarc Zyngier 	union {
13050926d82SMarc Zyngier 		u8 targets;			/* GICv2 target VCPUs mask */
13150926d82SMarc Zyngier 		u32 mpidr;			/* GICv3 target VCPU */
13250926d82SMarc Zyngier 	};
13350926d82SMarc Zyngier 	u8 source;			/* GICv2 SGIs only */
13453692908SMarc Zyngier 	u8 active_source;		/* GICv2 SGIs only */
13550926d82SMarc Zyngier 	u8 priority;
1368df3c8f3SChristoffer Dall 	u8 group;			/* 0 == group 0, 1 == group 1 */
13750926d82SMarc Zyngier 	enum vgic_irq_config config;	/* Level or edge */
138c6ccd30eSChristoffer Dall 
139b6909a65SChristoffer Dall 	/*
140b6909a65SChristoffer Dall 	 * Callback function pointer to in-kernel devices that can tell us the
141b6909a65SChristoffer Dall 	 * state of the input level of mapped level-triggered IRQ faster than
142b6909a65SChristoffer Dall 	 * peaking into the physical GIC.
143b6909a65SChristoffer Dall 	 *
144b6909a65SChristoffer Dall 	 * Always called in non-preemptible section and the functions can use
145b6909a65SChristoffer Dall 	 * kvm_arm_get_running_vcpu() to get the vcpu pointer for private
146b6909a65SChristoffer Dall 	 * IRQs.
147b6909a65SChristoffer Dall 	 */
148b6909a65SChristoffer Dall 	bool (*get_input_level)(int vintid);
149b6909a65SChristoffer Dall 
150c6ccd30eSChristoffer Dall 	void *owner;			/* Opaque pointer to reserve an interrupt
151c6ccd30eSChristoffer Dall 					   for in-kernel devices. */
15250926d82SMarc Zyngier };
15350926d82SMarc Zyngier 
15450926d82SMarc Zyngier struct vgic_register_region;
15559c5ab40SAndre Przywara struct vgic_its;
15659c5ab40SAndre Przywara 
15759c5ab40SAndre Przywara enum iodev_type {
15859c5ab40SAndre Przywara 	IODEV_CPUIF,
15959c5ab40SAndre Przywara 	IODEV_DIST,
16059c5ab40SAndre Przywara 	IODEV_REDIST,
16159c5ab40SAndre Przywara 	IODEV_ITS
16259c5ab40SAndre Przywara };
16350926d82SMarc Zyngier 
1646777f77fSAndre Przywara struct vgic_io_device {
16550926d82SMarc Zyngier 	gpa_t base_addr;
16659c5ab40SAndre Przywara 	union {
1676777f77fSAndre Przywara 		struct kvm_vcpu *redist_vcpu;
16859c5ab40SAndre Przywara 		struct vgic_its *its;
16959c5ab40SAndre Przywara 	};
17050926d82SMarc Zyngier 	const struct vgic_register_region *regions;
17159c5ab40SAndre Przywara 	enum iodev_type iodev_type;
17250926d82SMarc Zyngier 	int nr_regions;
1736777f77fSAndre Przywara 	struct kvm_io_device dev;
1746777f77fSAndre Przywara };
1756777f77fSAndre Przywara 
17659c5ab40SAndre Przywara struct vgic_its {
17759c5ab40SAndre Przywara 	/* The base address of the ITS control register frame */
17859c5ab40SAndre Przywara 	gpa_t			vgic_its_base;
17959c5ab40SAndre Przywara 
18059c5ab40SAndre Przywara 	bool			enabled;
18159c5ab40SAndre Przywara 	struct vgic_io_device	iodev;
182bb717644SMarc Zyngier 	struct kvm_device	*dev;
183424c3383SAndre Przywara 
184424c3383SAndre Przywara 	/* These registers correspond to GITS_BASER{0,1} */
185424c3383SAndre Przywara 	u64			baser_device_table;
186424c3383SAndre Przywara 	u64			baser_coll_table;
187424c3383SAndre Przywara 
188424c3383SAndre Przywara 	/* Protects the command queue */
189424c3383SAndre Przywara 	struct mutex		cmd_lock;
190424c3383SAndre Przywara 	u64			cbaser;
191424c3383SAndre Przywara 	u32			creadr;
192424c3383SAndre Przywara 	u32			cwriter;
193424c3383SAndre Przywara 
19471afe470SEric Auger 	/* migration ABI revision in use */
19571afe470SEric Auger 	u32			abi_rev;
19671afe470SEric Auger 
197424c3383SAndre Przywara 	/* Protects the device and collection lists */
198424c3383SAndre Przywara 	struct mutex		its_lock;
199424c3383SAndre Przywara 	struct list_head	device_list;
200424c3383SAndre Przywara 	struct list_head	collection_list;
20159c5ab40SAndre Przywara };
20259c5ab40SAndre Przywara 
20310f92c4cSChristoffer Dall struct vgic_state_iter;
20410f92c4cSChristoffer Dall 
205dbd9733aSEric Auger struct vgic_redist_region {
206dbd9733aSEric Auger 	u32 index;
207dbd9733aSEric Auger 	gpa_t base;
208dbd9733aSEric Auger 	u32 count; /* number of redistributors or 0 if single region */
209dbd9733aSEric Auger 	u32 free_index; /* index of the next free redistributor */
210dbd9733aSEric Auger 	struct list_head list;
211dbd9733aSEric Auger };
212dbd9733aSEric Auger 
2137275acdfSMarc Zyngier struct vgic_dist {
214f982cf4eSMarc Zyngier 	bool			in_kernel;
2157275acdfSMarc Zyngier 	bool			ready;
21650926d82SMarc Zyngier 	bool			initialized;
2177275acdfSMarc Zyngier 
21859892136SAndre Przywara 	/* vGIC model the kernel emulates for the guest (GICv2 or GICv3) */
21959892136SAndre Przywara 	u32			vgic_model;
22059892136SAndre Przywara 
221aa075b0fSChristoffer Dall 	/* Implementation revision as reported in the GICD_IIDR */
222aa075b0fSChristoffer Dall 	u32			implementation_rev;
223aa075b0fSChristoffer Dall 
22432f8777eSChristoffer Dall 	/* Userspace can write to GICv2 IGROUPR */
22532f8777eSChristoffer Dall 	bool			v2_groups_user_writable;
22632f8777eSChristoffer Dall 
2270e4e82f1SAndre Przywara 	/* Do injected MSIs require an additional device ID? */
2280e4e82f1SAndre Przywara 	bool			msis_require_devid;
2290e4e82f1SAndre Przywara 
23050926d82SMarc Zyngier 	int			nr_spis;
231c1bfb577SMarc Zyngier 
23250926d82SMarc Zyngier 	/* base addresses in guest physical address space: */
23350926d82SMarc Zyngier 	gpa_t			vgic_dist_base;		/* distributor */
234a0675c25SAndre Przywara 	union {
23550926d82SMarc Zyngier 		/* either a GICv2 CPU interface */
23650926d82SMarc Zyngier 		gpa_t			vgic_cpu_base;
23750926d82SMarc Zyngier 		/* or a number of GICv3 redistributor regions */
238dbd9733aSEric Auger 		struct list_head rd_regions;
239a0675c25SAndre Przywara 	};
2407275acdfSMarc Zyngier 
24150926d82SMarc Zyngier 	/* distributor enabled */
24250926d82SMarc Zyngier 	bool			enabled;
2437275acdfSMarc Zyngier 
24450926d82SMarc Zyngier 	struct vgic_irq		*spis;
2457275acdfSMarc Zyngier 
246a9cf86f6SAndre Przywara 	struct vgic_io_device	dist_iodev;
2470aa1de57SAndre Przywara 
2481085fdc6SAndre Przywara 	bool			has_its;
2491085fdc6SAndre Przywara 
2500aa1de57SAndre Przywara 	/*
2510aa1de57SAndre Przywara 	 * Contains the attributes and gpa of the LPI configuration table.
2520aa1de57SAndre Przywara 	 * Since we report GICR_TYPER.CommonLPIAff as 0b00, we can share
2530aa1de57SAndre Przywara 	 * one address across all redistributors.
2540aa1de57SAndre Przywara 	 * GICv3 spec: 6.1.2 "LPI Configuration tables"
2550aa1de57SAndre Przywara 	 */
2560aa1de57SAndre Przywara 	u64			propbaser;
2573802411dSAndre Przywara 
2583802411dSAndre Przywara 	/* Protects the lpi_list and the count value below. */
259*fc3bc475SJulien Thierry 	raw_spinlock_t		lpi_list_lock;
2603802411dSAndre Przywara 	struct list_head	lpi_list_head;
2613802411dSAndre Przywara 	int			lpi_list_count;
26210f92c4cSChristoffer Dall 
26310f92c4cSChristoffer Dall 	/* used by vgic-debug */
26410f92c4cSChristoffer Dall 	struct vgic_state_iter *iter;
26574fe55dcSMarc Zyngier 
26674fe55dcSMarc Zyngier 	/*
26774fe55dcSMarc Zyngier 	 * GICv4 ITS per-VM data, containing the IRQ domain, the VPE
26874fe55dcSMarc Zyngier 	 * array, the property table pointer as well as allocation
26974fe55dcSMarc Zyngier 	 * data. This essentially ties the Linux IRQ core and ITS
27074fe55dcSMarc Zyngier 	 * together, and avoids leaking KVM's data structures anywhere
27174fe55dcSMarc Zyngier 	 * else.
27274fe55dcSMarc Zyngier 	 */
27374fe55dcSMarc Zyngier 	struct its_vm		its_vm;
2747275acdfSMarc Zyngier };
2757275acdfSMarc Zyngier 
276eede821dSMarc Zyngier struct vgic_v2_cpu_if {
277eede821dSMarc Zyngier 	u32		vgic_hcr;
278eede821dSMarc Zyngier 	u32		vgic_vmcr;
279eede821dSMarc Zyngier 	u32		vgic_apr;
2808f186d52SMarc Zyngier 	u32		vgic_lr[VGIC_V2_MAX_LRS];
281eede821dSMarc Zyngier };
282eede821dSMarc Zyngier 
283b2fb1c0dSMarc Zyngier struct vgic_v3_cpu_if {
284b2fb1c0dSMarc Zyngier 	u32		vgic_hcr;
285b2fb1c0dSMarc Zyngier 	u32		vgic_vmcr;
2862f5fa41aSAndre Przywara 	u32		vgic_sre;	/* Restored only, change ignored */
287b2fb1c0dSMarc Zyngier 	u32		vgic_ap0r[4];
288b2fb1c0dSMarc Zyngier 	u32		vgic_ap1r[4];
289b2fb1c0dSMarc Zyngier 	u64		vgic_lr[VGIC_V3_MAX_LRS];
29074fe55dcSMarc Zyngier 
29174fe55dcSMarc Zyngier 	/*
29274fe55dcSMarc Zyngier 	 * GICv4 ITS per-VPE data, containing the doorbell IRQ, the
29374fe55dcSMarc Zyngier 	 * pending table pointer, the its_vm pointer and a few other
29474fe55dcSMarc Zyngier 	 * HW specific things. As for the its_vm structure, this is
29574fe55dcSMarc Zyngier 	 * linking the Linux IRQ subsystem and the ITS together.
29674fe55dcSMarc Zyngier 	 */
29774fe55dcSMarc Zyngier 	struct its_vpe	its_vpe;
298b2fb1c0dSMarc Zyngier };
299b2fb1c0dSMarc Zyngier 
3007275acdfSMarc Zyngier struct vgic_cpu {
3017275acdfSMarc Zyngier 	/* CPU vif control registers for world switch */
302eede821dSMarc Zyngier 	union {
303eede821dSMarc Zyngier 		struct vgic_v2_cpu_if	vgic_v2;
304b2fb1c0dSMarc Zyngier 		struct vgic_v3_cpu_if	vgic_v3;
305eede821dSMarc Zyngier 	};
3066c3d63c9SMarc Zyngier 
30750926d82SMarc Zyngier 	unsigned int used_lrs;
30850926d82SMarc Zyngier 	struct vgic_irq private_irqs[VGIC_NR_PRIVATE_IRQS];
30950926d82SMarc Zyngier 
31050926d82SMarc Zyngier 	spinlock_t ap_list_lock;	/* Protects the ap_list */
31150926d82SMarc Zyngier 
31250926d82SMarc Zyngier 	/*
31350926d82SMarc Zyngier 	 * List of IRQs that this VCPU should consider because they are either
31450926d82SMarc Zyngier 	 * Active or Pending (hence the name; AP list), or because they recently
31550926d82SMarc Zyngier 	 * were one of the two and need to be migrated off this list to another
31650926d82SMarc Zyngier 	 * VCPU.
31750926d82SMarc Zyngier 	 */
31850926d82SMarc Zyngier 	struct list_head ap_list_head;
31959f00ff9SMarc Zyngier 
3208f6cdc1cSAndre Przywara 	/*
3218f6cdc1cSAndre Przywara 	 * Members below are used with GICv3 emulation only and represent
3228f6cdc1cSAndre Przywara 	 * parts of the redistributor.
3238f6cdc1cSAndre Przywara 	 */
3248f6cdc1cSAndre Przywara 	struct vgic_io_device	rd_iodev;
3258f6cdc1cSAndre Przywara 	struct vgic_io_device	sgi_iodev;
326dbd9733aSEric Auger 	struct vgic_redist_region *rdreg;
3270aa1de57SAndre Przywara 
3280aa1de57SAndre Przywara 	/* Contains the attributes and gpa of the LPI pending tables. */
3290aa1de57SAndre Przywara 	u64 pendbaser;
3300aa1de57SAndre Przywara 
3310aa1de57SAndre Przywara 	bool lpis_enabled;
332d017d7b0SVijaya Kumar K 
333d017d7b0SVijaya Kumar K 	/* Cache guest priority bits */
334d017d7b0SVijaya Kumar K 	u32 num_pri_bits;
335d017d7b0SVijaya Kumar K 
336d017d7b0SVijaya Kumar K 	/* Cache guest interrupt ID bits */
337d017d7b0SVijaya Kumar K 	u32 num_id_bits;
3387275acdfSMarc Zyngier };
3397275acdfSMarc Zyngier 
340fb5ee369SMarc Zyngier extern struct static_key_false vgic_v2_cpuif_trap;
34159da1cbfSMarc Zyngier extern struct static_key_false vgic_v3_cpuif_trap;
342fb5ee369SMarc Zyngier 
343ce01e4e8SChristoffer Dall int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write);
3446c3d63c9SMarc Zyngier void kvm_vgic_early_init(struct kvm *kvm);
3451aab6f46SChristoffer Dall int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu);
34659892136SAndre Przywara int kvm_vgic_create(struct kvm *kvm, u32 type);
347c1bfb577SMarc Zyngier void kvm_vgic_destroy(struct kvm *kvm);
348c1bfb577SMarc Zyngier void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu);
34950926d82SMarc Zyngier int kvm_vgic_map_resources(struct kvm *kvm);
35050926d82SMarc Zyngier int kvm_vgic_hyp_init(void);
3515b0d2cc2SChristoffer Dall void kvm_vgic_init_cpu_hardware(void);
35250926d82SMarc Zyngier 
35350926d82SMarc Zyngier int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
354cb3f0ad8SChristoffer Dall 			bool level, void *owner);
35547bbd31fSEric Auger int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq,
356b6909a65SChristoffer Dall 			  u32 vintid, bool (*get_input_level)(int vindid));
35747bbd31fSEric Auger int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid);
35847bbd31fSEric Auger bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int vintid);
3597275acdfSMarc Zyngier 
36050926d82SMarc Zyngier int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu);
36150926d82SMarc Zyngier 
362328e5664SChristoffer Dall void kvm_vgic_load(struct kvm_vcpu *vcpu);
363328e5664SChristoffer Dall void kvm_vgic_put(struct kvm_vcpu *vcpu);
364328e5664SChristoffer Dall 
365f982cf4eSMarc Zyngier #define irqchip_in_kernel(k)	(!!((k)->arch.vgic.in_kernel))
36650926d82SMarc Zyngier #define vgic_initialized(k)	((k)->arch.vgic.initialized)
367c52edf5fSChristoffer Dall #define vgic_ready(k)		((k)->arch.vgic.ready)
3682defaff4SAndre Przywara #define vgic_valid_spi(k, i)	(((i) >= VGIC_NR_PRIVATE_IRQS) && \
36950926d82SMarc Zyngier 			((i) < (k)->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS))
3707275acdfSMarc Zyngier 
37150926d82SMarc Zyngier bool kvm_vcpu_has_pending_irqs(struct kvm_vcpu *vcpu);
37250926d82SMarc Zyngier void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu);
37350926d82SMarc Zyngier void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu);
374413aa807SChristoffer Dall void kvm_vgic_reset_mapped_irq(struct kvm_vcpu *vcpu, u32 vintid);
37550926d82SMarc Zyngier 
3766249f2a4SMarc Zyngier void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg, bool allow_group1);
3778f186d52SMarc Zyngier 
37850926d82SMarc Zyngier /**
37950926d82SMarc Zyngier  * kvm_vgic_get_max_vcpus - Get the maximum number of VCPUs allowed by HW
38050926d82SMarc Zyngier  *
38150926d82SMarc Zyngier  * The host's GIC naturally limits the maximum amount of VCPUs a guest
38250926d82SMarc Zyngier  * can use.
38350926d82SMarc Zyngier  */
38450926d82SMarc Zyngier static inline int kvm_vgic_get_max_vcpus(void)
38550926d82SMarc Zyngier {
38650926d82SMarc Zyngier 	return kvm_vgic_global_state.max_gic_vcpus;
38750926d82SMarc Zyngier }
38850926d82SMarc Zyngier 
3890e4e82f1SAndre Przywara int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi);
3900e4e82f1SAndre Przywara 
391180ae7b1SEric Auger /**
392180ae7b1SEric Auger  * kvm_vgic_setup_default_irq_routing:
393180ae7b1SEric Auger  * Setup a default flat gsi routing table mapping all SPIs
394180ae7b1SEric Auger  */
395180ae7b1SEric Auger int kvm_vgic_setup_default_irq_routing(struct kvm *kvm);
396180ae7b1SEric Auger 
397c6ccd30eSChristoffer Dall int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner);
398c6ccd30eSChristoffer Dall 
399196b1364SMarc Zyngier struct kvm_kernel_irq_routing_entry;
400196b1364SMarc Zyngier 
401196b1364SMarc Zyngier int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int irq,
402196b1364SMarc Zyngier 			       struct kvm_kernel_irq_routing_entry *irq_entry);
403196b1364SMarc Zyngier 
404196b1364SMarc Zyngier int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int irq,
405196b1364SMarc Zyngier 				 struct kvm_kernel_irq_routing_entry *irq_entry);
406196b1364SMarc Zyngier 
407df9ba959SMarc Zyngier void kvm_vgic_v4_enable_doorbell(struct kvm_vcpu *vcpu);
408df9ba959SMarc Zyngier void kvm_vgic_v4_disable_doorbell(struct kvm_vcpu *vcpu);
409df9ba959SMarc Zyngier 
41050926d82SMarc Zyngier #endif /* __KVM_ARM_VGIC_H */
411