xref: /linux/include/linux/irqchip/arm-gic-v4.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2016,2017 ARM Limited, All Rights Reserved.
4  * Author: Marc Zyngier <marc.zyngier@arm.com>
5  */
6 
7 #ifndef __LINUX_IRQCHIP_ARM_GIC_V4_H
8 #define __LINUX_IRQCHIP_ARM_GIC_V4_H
9 
10 struct its_vpe;
11 
12 /*
13  * Maximum number of ITTs when GITS_TYPER.VMOVP == 0, using the
14  * ITSList mechanism to perform inter-ITS synchronization.
15  */
16 #define GICv4_ITS_LIST_MAX		16
17 
18 /* Embedded in kvm.arch */
19 struct its_vm {
20 	struct fwnode_handle	*fwnode;
21 	struct irq_domain	*domain;
22 	struct page		*vprop_page;
23 	struct its_vpe		**vpes;
24 	int			nr_vpes;
25 	irq_hw_number_t		db_lpi_base;
26 	unsigned long		*db_bitmap;
27 	int			nr_db_lpis;
28 	/*
29 	 * Ensures mutual exclusion between updates to vlpi_count[]
30 	 * and map/unmap when using the ITSList mechanism.
31 	 *
32 	 * The lock order for any sequence involving the ITSList is
33 	 * vmapp_lock -> vpe_lock ->vmovp_lock.
34 	 */
35 	raw_spinlock_t		vmapp_lock;
36 	u32			vlpi_count[GICv4_ITS_LIST_MAX];
37 };
38 
39 /* Embedded in kvm_vcpu.arch */
40 struct its_vpe {
41 	struct page 		*vpt_page;
42 	struct its_vm		*its_vm;
43 	/* per-vPE VLPI tracking */
44 	atomic_t		vlpi_count;
45 	/* Doorbell interrupt */
46 	int			irq;
47 	irq_hw_number_t		vpe_db_lpi;
48 	/* VPE resident */
49 	bool			resident;
50 	/* VPT parse complete */
51 	bool			ready;
52 	union {
53 		/* GICv4.0 implementations */
54 		struct {
55 			/* VPE proxy mapping */
56 			int	vpe_proxy_event;
57 			/* Implementation Defined Area Invalid */
58 			bool	idai;
59 		};
60 		/* GICv4.1 implementations */
61 		struct {
62 			struct fwnode_handle	*fwnode;
63 			struct irq_domain	*sgi_domain;
64 			struct {
65 				u8	priority;
66 				bool	enabled;
67 				bool	group;
68 			}			sgi_config[16];
69 			atomic_t vmapp_count;
70 		};
71 	};
72 
73 	/*
74 	 * Ensures mutual exclusion between affinity setting of the
75 	 * vPE and vLPI operations using vpe->col_idx.
76 	 */
77 	raw_spinlock_t		vpe_lock;
78 	/*
79 	 * This collection ID is used to indirect the target
80 	 * redistributor for this VPE. The ID itself isn't involved in
81 	 * programming of the ITS.
82 	 */
83 	u16			col_idx;
84 	/* Unique (system-wide) VPE identifier */
85 	u16			vpe_id;
86 	/* Pending VLPIs on schedule out? */
87 	bool			pending_last;
88 };
89 
90 /*
91  * struct its_vlpi_map: structure describing the mapping of a
92  * VLPI. Only to be interpreted in the context of a physical interrupt
93  * it complements.  To be used as the vcpu_info passed to
94  * irq_set_vcpu_affinity().
95  *
96  * @vm:		Pointer to the GICv4 notion of a VM
97  * @vpe:	Pointer to the GICv4 notion of a virtual CPU (VPE)
98  * @vintid:	Virtual LPI number
99  * @properties:	Priority and enable bits (as written in the prop table)
100  * @db_enabled:	Is the VPE doorbell to be generated?
101  */
102 struct its_vlpi_map {
103 	struct its_vm		*vm;
104 	struct its_vpe		*vpe;
105 	u32			vintid;
106 	u8			properties;
107 	bool			db_enabled;
108 };
109 
110 enum its_vcpu_info_cmd_type {
111 	MAP_VLPI,
112 	GET_VLPI,
113 	PROP_UPDATE_VLPI,
114 	PROP_UPDATE_AND_INV_VLPI,
115 	SCHEDULE_VPE,
116 	DESCHEDULE_VPE,
117 	COMMIT_VPE,
118 	INVALL_VPE,
119 	PROP_UPDATE_VSGI,
120 };
121 
122 struct its_cmd_info {
123 	enum its_vcpu_info_cmd_type	cmd_type;
124 	union {
125 		struct its_vlpi_map	*map;
126 		u8			config;
127 		bool			req_db;
128 		struct {
129 			bool		g0en;
130 			bool		g1en;
131 		};
132 		struct {
133 			u8		priority;
134 			bool		group;
135 		};
136 	};
137 };
138 
139 int its_alloc_vcpu_irqs(struct its_vm *vm);
140 void its_free_vcpu_irqs(struct its_vm *vm);
141 int its_make_vpe_resident(struct its_vpe *vpe, bool g0en, bool g1en);
142 int its_make_vpe_non_resident(struct its_vpe *vpe, bool db);
143 int its_commit_vpe(struct its_vpe *vpe);
144 int its_invall_vpe(struct its_vpe *vpe);
145 int its_map_vlpi(int irq, struct its_vlpi_map *map);
146 int its_get_vlpi(int irq, struct its_vlpi_map *map);
147 int its_unmap_vlpi(int irq);
148 int its_prop_update_vlpi(int irq, u8 config, bool inv);
149 int its_prop_update_vsgi(int irq, u8 priority, bool group);
150 
151 struct irq_domain_ops;
152 int its_init_v4(struct irq_domain *domain,
153 		const struct irq_domain_ops *vpe_ops,
154 		const struct irq_domain_ops *sgi_ops);
155 
156 bool gic_cpuif_has_vsgi(void);
157 
158 #endif
159