This source file includes following definitions.
- its_alloc_vcpu_irqs
- its_free_vcpu_irqs
- its_send_vpe_cmd
- its_schedule_vpe
- its_invall_vpe
- its_map_vlpi
- its_get_vlpi
- its_unmap_vlpi
- its_prop_update_vlpi
- its_init_v4
1
2
3
4
5
6
7 #include <linux/interrupt.h>
8 #include <linux/irq.h>
9 #include <linux/irqdomain.h>
10 #include <linux/msi.h>
11 #include <linux/sched.h>
12
13 #include <linux/irqchip/arm-gic-v4.h>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 static struct irq_domain *gic_domain;
87 static const struct irq_domain_ops *vpe_domain_ops;
88
89 int its_alloc_vcpu_irqs(struct its_vm *vm)
90 {
91 int vpe_base_irq, i;
92
93 vm->fwnode = irq_domain_alloc_named_id_fwnode("GICv4-vpe",
94 task_pid_nr(current));
95 if (!vm->fwnode)
96 goto err;
97
98 vm->domain = irq_domain_create_hierarchy(gic_domain, 0, vm->nr_vpes,
99 vm->fwnode, vpe_domain_ops,
100 vm);
101 if (!vm->domain)
102 goto err;
103
104 for (i = 0; i < vm->nr_vpes; i++) {
105 vm->vpes[i]->its_vm = vm;
106 vm->vpes[i]->idai = true;
107 }
108
109 vpe_base_irq = __irq_domain_alloc_irqs(vm->domain, -1, vm->nr_vpes,
110 NUMA_NO_NODE, vm,
111 false, NULL);
112 if (vpe_base_irq <= 0)
113 goto err;
114
115 for (i = 0; i < vm->nr_vpes; i++)
116 vm->vpes[i]->irq = vpe_base_irq + i;
117
118 return 0;
119
120 err:
121 if (vm->domain)
122 irq_domain_remove(vm->domain);
123 if (vm->fwnode)
124 irq_domain_free_fwnode(vm->fwnode);
125
126 return -ENOMEM;
127 }
128
129 void its_free_vcpu_irqs(struct its_vm *vm)
130 {
131 irq_domain_free_irqs(vm->vpes[0]->irq, vm->nr_vpes);
132 irq_domain_remove(vm->domain);
133 irq_domain_free_fwnode(vm->fwnode);
134 }
135
136 static int its_send_vpe_cmd(struct its_vpe *vpe, struct its_cmd_info *info)
137 {
138 return irq_set_vcpu_affinity(vpe->irq, info);
139 }
140
141 int its_schedule_vpe(struct its_vpe *vpe, bool on)
142 {
143 struct its_cmd_info info;
144
145 WARN_ON(preemptible());
146
147 info.cmd_type = on ? SCHEDULE_VPE : DESCHEDULE_VPE;
148
149 return its_send_vpe_cmd(vpe, &info);
150 }
151
152 int its_invall_vpe(struct its_vpe *vpe)
153 {
154 struct its_cmd_info info = {
155 .cmd_type = INVALL_VPE,
156 };
157
158 return its_send_vpe_cmd(vpe, &info);
159 }
160
161 int its_map_vlpi(int irq, struct its_vlpi_map *map)
162 {
163 struct its_cmd_info info = {
164 .cmd_type = MAP_VLPI,
165 {
166 .map = map,
167 },
168 };
169 int ret;
170
171
172
173
174
175 irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY);
176
177 ret = irq_set_vcpu_affinity(irq, &info);
178 if (ret)
179 irq_clear_status_flags(irq, IRQ_DISABLE_UNLAZY);
180
181 return ret;
182 }
183
184 int its_get_vlpi(int irq, struct its_vlpi_map *map)
185 {
186 struct its_cmd_info info = {
187 .cmd_type = GET_VLPI,
188 {
189 .map = map,
190 },
191 };
192
193 return irq_set_vcpu_affinity(irq, &info);
194 }
195
196 int its_unmap_vlpi(int irq)
197 {
198 irq_clear_status_flags(irq, IRQ_DISABLE_UNLAZY);
199 return irq_set_vcpu_affinity(irq, NULL);
200 }
201
202 int its_prop_update_vlpi(int irq, u8 config, bool inv)
203 {
204 struct its_cmd_info info = {
205 .cmd_type = inv ? PROP_UPDATE_AND_INV_VLPI : PROP_UPDATE_VLPI,
206 {
207 .config = config,
208 },
209 };
210
211 return irq_set_vcpu_affinity(irq, &info);
212 }
213
214 int its_init_v4(struct irq_domain *domain, const struct irq_domain_ops *ops)
215 {
216 if (domain) {
217 pr_info("ITS: Enabling GICv4 support\n");
218 gic_domain = domain;
219 vpe_domain_ops = ops;
220 return 0;
221 }
222
223 pr_err("ITS: No GICv4 VPE domain allocated\n");
224 return -ENODEV;
225 }