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 	u32			vlpi_count[GICv4_ITS_LIST_MAX];
29 };
30 
31 /* Embedded in kvm_vcpu.arch */
32 struct its_vpe {
33 	struct page 		*vpt_page;
34 	struct its_vm		*its_vm;
35 	/* per-vPE VLPI tracking */
36 	atomic_t		vlpi_count;
37 	/* Doorbell interrupt */
38 	int			irq;
39 	irq_hw_number_t		vpe_db_lpi;
40 	/* VPE resident */
41 	bool			resident;
42 	/* VPT parse complete */
43 	bool			ready;
44 	union {
45 		/* GICv4.0 implementations */
46 		struct {
47 			/* VPE proxy mapping */
48 			int	vpe_proxy_event;
49 			/* Implementation Defined Area Invalid */
50 			bool	idai;
51 		};
52 		/* GICv4.1 implementations */
53 		struct {
54 			struct fwnode_handle	*fwnode;
55 			struct irq_domain	*sgi_domain;
56 			struct {
57 				u8	priority;
58 				bool	enabled;
59 				bool	group;
60 			}			sgi_config[16];
61 		};
62 	};
63 
64 	/* Track the VPE being mapped */
65 	atomic_t vmapp_count;
66 
67 	/*
68 	 * Ensures mutual exclusion between affinity setting of the
69 	 * vPE and vLPI operations using vpe->col_idx.
70 	 */
71 	raw_spinlock_t		vpe_lock;
72 	/*
73 	 * This collection ID is used to indirect the target
74 	 * redistributor for this VPE. The ID itself isn't involved in
75 	 * programming of the ITS.
76 	 */
77 	u16			col_idx;
78 	/* Unique (system-wide) VPE identifier */
79 	u16			vpe_id;
80 	/* Pending VLPIs on schedule out? */
81 	bool			pending_last;
82 };
83 
84 /*
85  * struct its_vlpi_map: structure describing the mapping of a
86  * VLPI. Only to be interpreted in the context of a physical interrupt
87  * it complements.  To be used as the vcpu_info passed to
88  * irq_set_vcpu_affinity().
89  *
90  * @vm:		Pointer to the GICv4 notion of a VM
91  * @vpe:	Pointer to the GICv4 notion of a virtual CPU (VPE)
92  * @vintid:	Virtual LPI number
93  * @properties:	Priority and enable bits (as written in the prop table)
94  * @db_enabled:	Is the VPE doorbell to be generated?
95  */
96 struct its_vlpi_map {
97 	struct its_vm		*vm;
98 	struct its_vpe		*vpe;
99 	u32			vintid;
100 	u8			properties;
101 	bool			db_enabled;
102 };
103 
104 enum its_vcpu_info_cmd_type {
105 	MAP_VLPI,
106 	GET_VLPI,
107 	PROP_UPDATE_VLPI,
108 	PROP_UPDATE_AND_INV_VLPI,
109 	SCHEDULE_VPE,
110 	DESCHEDULE_VPE,
111 	COMMIT_VPE,
112 	INVALL_VPE,
113 	PROP_UPDATE_VSGI,
114 };
115 
116 struct its_cmd_info {
117 	enum its_vcpu_info_cmd_type	cmd_type;
118 	union {
119 		struct its_vlpi_map	*map;
120 		u8			config;
121 		bool			req_db;
122 		struct {
123 			bool		g0en;
124 			bool		g1en;
125 		};
126 		struct {
127 			u8		priority;
128 			bool		group;
129 		};
130 	};
131 };
132 
133 int its_alloc_vcpu_irqs(struct its_vm *vm);
134 void its_free_vcpu_irqs(struct its_vm *vm);
135 int its_make_vpe_resident(struct its_vpe *vpe, bool g0en, bool g1en);
136 int its_make_vpe_non_resident(struct its_vpe *vpe, bool db);
137 int its_commit_vpe(struct its_vpe *vpe);
138 int its_invall_vpe(struct its_vpe *vpe);
139 int its_map_vlpi(int irq, struct its_vlpi_map *map);
140 int its_get_vlpi(int irq, struct its_vlpi_map *map);
141 int its_unmap_vlpi(int irq);
142 int its_prop_update_vlpi(int irq, u8 config, bool inv);
143 int its_prop_update_vsgi(int irq, u8 priority, bool group);
144 
145 struct irq_domain_ops;
146 int its_init_v4(struct irq_domain *domain,
147 		const struct irq_domain_ops *vpe_ops,
148 		const struct irq_domain_ops *sgi_ops);
149 
150 bool gic_cpuif_has_vsgi(void);
151 
152 #endif
153