2 * Copyright (C) 2012-2015 - ARM Ltd
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/compiler.h>
19 #include <linux/irqchip/arm-gic-v3.h>
20 #include <linux/kvm_host.h>
22 #include <asm/kvm_emulate.h>
23 #include <asm/kvm_hyp.h>
25 #define vtr_to_max_lr_idx(v) ((v) & 0xf)
26 #define vtr_to_nr_pre_bits(v) ((((u32)(v) >> 26) & 7) + 1)
27 #define vtr_to_nr_apr_regs(v) (1 << (vtr_to_nr_pre_bits(v) - 5))
29 static u64 __hyp_text
__gic_v3_get_lr(unsigned int lr
)
33 return read_gicreg(ICH_LR0_EL2
);
35 return read_gicreg(ICH_LR1_EL2
);
37 return read_gicreg(ICH_LR2_EL2
);
39 return read_gicreg(ICH_LR3_EL2
);
41 return read_gicreg(ICH_LR4_EL2
);
43 return read_gicreg(ICH_LR5_EL2
);
45 return read_gicreg(ICH_LR6_EL2
);
47 return read_gicreg(ICH_LR7_EL2
);
49 return read_gicreg(ICH_LR8_EL2
);
51 return read_gicreg(ICH_LR9_EL2
);
53 return read_gicreg(ICH_LR10_EL2
);
55 return read_gicreg(ICH_LR11_EL2
);
57 return read_gicreg(ICH_LR12_EL2
);
59 return read_gicreg(ICH_LR13_EL2
);
61 return read_gicreg(ICH_LR14_EL2
);
63 return read_gicreg(ICH_LR15_EL2
);
69 static void __hyp_text
__gic_v3_set_lr(u64 val
, int lr
)
73 write_gicreg(val
, ICH_LR0_EL2
);
76 write_gicreg(val
, ICH_LR1_EL2
);
79 write_gicreg(val
, ICH_LR2_EL2
);
82 write_gicreg(val
, ICH_LR3_EL2
);
85 write_gicreg(val
, ICH_LR4_EL2
);
88 write_gicreg(val
, ICH_LR5_EL2
);
91 write_gicreg(val
, ICH_LR6_EL2
);
94 write_gicreg(val
, ICH_LR7_EL2
);
97 write_gicreg(val
, ICH_LR8_EL2
);
100 write_gicreg(val
, ICH_LR9_EL2
);
103 write_gicreg(val
, ICH_LR10_EL2
);
106 write_gicreg(val
, ICH_LR11_EL2
);
109 write_gicreg(val
, ICH_LR12_EL2
);
112 write_gicreg(val
, ICH_LR13_EL2
);
115 write_gicreg(val
, ICH_LR14_EL2
);
118 write_gicreg(val
, ICH_LR15_EL2
);
123 static void __hyp_text
save_maint_int_state(struct kvm_vcpu
*vcpu
, int nr_lr
)
125 struct vgic_v3_cpu_if
*cpu_if
= &vcpu
->arch
.vgic_cpu
.vgic_v3
;
129 expect_mi
= !!(cpu_if
->vgic_hcr
& ICH_HCR_UIE
);
131 for (i
= 0; i
< nr_lr
; i
++) {
132 if (!(vcpu
->arch
.vgic_cpu
.live_lrs
& (1UL << i
)))
135 expect_mi
|= (!(cpu_if
->vgic_lr
[i
] & ICH_LR_HW
) &&
136 (cpu_if
->vgic_lr
[i
] & ICH_LR_EOI
));
140 cpu_if
->vgic_misr
= read_gicreg(ICH_MISR_EL2
);
142 if (cpu_if
->vgic_misr
& ICH_MISR_EOI
)
143 cpu_if
->vgic_eisr
= read_gicreg(ICH_EISR_EL2
);
145 cpu_if
->vgic_eisr
= 0;
147 cpu_if
->vgic_misr
= 0;
148 cpu_if
->vgic_eisr
= 0;
152 static void __hyp_text
__vgic_v3_write_ap0rn(u32 val
, int n
)
156 write_gicreg(val
, ICH_AP0R0_EL2
);
159 write_gicreg(val
, ICH_AP0R1_EL2
);
162 write_gicreg(val
, ICH_AP0R2_EL2
);
165 write_gicreg(val
, ICH_AP0R3_EL2
);
170 static void __hyp_text
__vgic_v3_write_ap1rn(u32 val
, int n
)
174 write_gicreg(val
, ICH_AP1R0_EL2
);
177 write_gicreg(val
, ICH_AP1R1_EL2
);
180 write_gicreg(val
, ICH_AP1R2_EL2
);
183 write_gicreg(val
, ICH_AP1R3_EL2
);
188 static u32 __hyp_text
__vgic_v3_read_ap0rn(int n
)
194 val
= read_gicreg(ICH_AP0R0_EL2
);
197 val
= read_gicreg(ICH_AP0R1_EL2
);
200 val
= read_gicreg(ICH_AP0R2_EL2
);
203 val
= read_gicreg(ICH_AP0R3_EL2
);
212 static u32 __hyp_text
__vgic_v3_read_ap1rn(int n
)
218 val
= read_gicreg(ICH_AP1R0_EL2
);
221 val
= read_gicreg(ICH_AP1R1_EL2
);
224 val
= read_gicreg(ICH_AP1R2_EL2
);
227 val
= read_gicreg(ICH_AP1R3_EL2
);
236 void __hyp_text
__vgic_v3_save_state(struct kvm_vcpu
*vcpu
)
238 struct vgic_v3_cpu_if
*cpu_if
= &vcpu
->arch
.vgic_cpu
.vgic_v3
;
242 * Make sure stores to the GIC via the memory mapped interface
243 * are now visible to the system register interface.
245 if (!cpu_if
->vgic_sre
)
248 cpu_if
->vgic_vmcr
= read_gicreg(ICH_VMCR_EL2
);
250 if (vcpu
->arch
.vgic_cpu
.live_lrs
) {
252 u32 max_lr_idx
, nr_pre_bits
;
254 cpu_if
->vgic_elrsr
= read_gicreg(ICH_ELSR_EL2
);
256 write_gicreg(0, ICH_HCR_EL2
);
257 val
= read_gicreg(ICH_VTR_EL2
);
258 max_lr_idx
= vtr_to_max_lr_idx(val
);
259 nr_pre_bits
= vtr_to_nr_pre_bits(val
);
261 save_maint_int_state(vcpu
, max_lr_idx
+ 1);
263 for (i
= 0; i
<= max_lr_idx
; i
++) {
264 if (!(vcpu
->arch
.vgic_cpu
.live_lrs
& (1UL << i
)))
267 if (cpu_if
->vgic_elrsr
& (1 << i
))
268 cpu_if
->vgic_lr
[i
] &= ~ICH_LR_STATE
;
270 cpu_if
->vgic_lr
[i
] = __gic_v3_get_lr(i
);
272 __gic_v3_set_lr(0, i
);
275 switch (nr_pre_bits
) {
277 cpu_if
->vgic_ap0r
[3] = __vgic_v3_read_ap0rn(3);
278 cpu_if
->vgic_ap0r
[2] = __vgic_v3_read_ap0rn(2);
280 cpu_if
->vgic_ap0r
[1] = __vgic_v3_read_ap0rn(1);
282 cpu_if
->vgic_ap0r
[0] = __vgic_v3_read_ap0rn(0);
285 switch (nr_pre_bits
) {
287 cpu_if
->vgic_ap1r
[3] = __vgic_v3_read_ap1rn(3);
288 cpu_if
->vgic_ap1r
[2] = __vgic_v3_read_ap1rn(2);
290 cpu_if
->vgic_ap1r
[1] = __vgic_v3_read_ap1rn(1);
292 cpu_if
->vgic_ap1r
[0] = __vgic_v3_read_ap1rn(0);
295 vcpu
->arch
.vgic_cpu
.live_lrs
= 0;
297 cpu_if
->vgic_misr
= 0;
298 cpu_if
->vgic_eisr
= 0;
299 cpu_if
->vgic_elrsr
= 0xffff;
300 cpu_if
->vgic_ap0r
[0] = 0;
301 cpu_if
->vgic_ap0r
[1] = 0;
302 cpu_if
->vgic_ap0r
[2] = 0;
303 cpu_if
->vgic_ap0r
[3] = 0;
304 cpu_if
->vgic_ap1r
[0] = 0;
305 cpu_if
->vgic_ap1r
[1] = 0;
306 cpu_if
->vgic_ap1r
[2] = 0;
307 cpu_if
->vgic_ap1r
[3] = 0;
310 val
= read_gicreg(ICC_SRE_EL2
);
311 write_gicreg(val
| ICC_SRE_EL2_ENABLE
, ICC_SRE_EL2
);
313 if (!cpu_if
->vgic_sre
) {
314 /* Make sure ENABLE is set at EL2 before setting SRE at EL1 */
316 write_gicreg(1, ICC_SRE_EL1
);
320 void __hyp_text
__vgic_v3_restore_state(struct kvm_vcpu
*vcpu
)
322 struct vgic_v3_cpu_if
*cpu_if
= &vcpu
->arch
.vgic_cpu
.vgic_v3
;
324 u32 max_lr_idx
, nr_pre_bits
;
329 * VFIQEn is RES1 if ICC_SRE_EL1.SRE is 1. This causes a
330 * Group0 interrupt (as generated in GICv2 mode) to be
331 * delivered as a FIQ to the guest, with potentially fatal
332 * consequences. So we must make sure that ICC_SRE_EL1 has
333 * been actually programmed with the value we want before
334 * starting to mess with the rest of the GIC.
336 if (!cpu_if
->vgic_sre
) {
337 write_gicreg(0, ICC_SRE_EL1
);
341 val
= read_gicreg(ICH_VTR_EL2
);
342 max_lr_idx
= vtr_to_max_lr_idx(val
);
343 nr_pre_bits
= vtr_to_nr_pre_bits(val
);
345 for (i
= 0; i
<= max_lr_idx
; i
++) {
346 if (cpu_if
->vgic_lr
[i
] & ICH_LR_STATE
)
347 live_lrs
|= (1 << i
);
350 write_gicreg(cpu_if
->vgic_vmcr
, ICH_VMCR_EL2
);
353 write_gicreg(cpu_if
->vgic_hcr
, ICH_HCR_EL2
);
355 switch (nr_pre_bits
) {
357 __vgic_v3_write_ap0rn(cpu_if
->vgic_ap0r
[3], 3);
358 __vgic_v3_write_ap0rn(cpu_if
->vgic_ap0r
[2], 2);
360 __vgic_v3_write_ap0rn(cpu_if
->vgic_ap0r
[1], 1);
362 __vgic_v3_write_ap0rn(cpu_if
->vgic_ap0r
[0], 0);
365 switch (nr_pre_bits
) {
367 __vgic_v3_write_ap1rn(cpu_if
->vgic_ap1r
[3], 3);
368 __vgic_v3_write_ap1rn(cpu_if
->vgic_ap1r
[2], 2);
370 __vgic_v3_write_ap1rn(cpu_if
->vgic_ap1r
[1], 1);
372 __vgic_v3_write_ap1rn(cpu_if
->vgic_ap1r
[0], 0);
375 for (i
= 0; i
<= max_lr_idx
; i
++) {
376 if (!(live_lrs
& (1 << i
)))
379 __gic_v3_set_lr(cpu_if
->vgic_lr
[i
], i
);
384 * Ensures that the above will have reached the
385 * (re)distributors. This ensure the guest will read the
386 * correct values from the memory-mapped interface.
388 if (!cpu_if
->vgic_sre
) {
392 vcpu
->arch
.vgic_cpu
.live_lrs
= live_lrs
;
395 * Prevent the guest from touching the GIC system registers if
396 * SRE isn't enabled for GICv3 emulation.
398 write_gicreg(read_gicreg(ICC_SRE_EL2
) & ~ICC_SRE_EL2_ENABLE
,
402 void __hyp_text
__vgic_v3_init_lrs(void)
404 int max_lr_idx
= vtr_to_max_lr_idx(read_gicreg(ICH_VTR_EL2
));
407 for (i
= 0; i
<= max_lr_idx
; i
++)
408 __gic_v3_set_lr(0, i
);
411 u64 __hyp_text
__vgic_v3_get_ich_vtr_el2(void)
413 return read_gicreg(ICH_VTR_EL2
);
416 u64 __hyp_text
__vgic_v3_read_vmcr(void)
418 return read_gicreg(ICH_VMCR_EL2
);
421 void __hyp_text
__vgic_v3_write_vmcr(u32 vmcr
)
423 write_gicreg(vmcr
, ICH_VMCR_EL2
);
428 static int __hyp_text
__vgic_v3_bpr_min(void)
430 /* See Pseudocode for VPriorityGroup */
431 return 8 - vtr_to_nr_pre_bits(read_gicreg(ICH_VTR_EL2
));
434 static int __hyp_text
__vgic_v3_get_group(struct kvm_vcpu
*vcpu
)
436 u32 esr
= kvm_vcpu_get_hsr(vcpu
);
437 u8 crm
= (esr
& ESR_ELx_SYS64_ISS_CRM_MASK
) >> ESR_ELx_SYS64_ISS_CRM_SHIFT
;
442 #define GICv3_IDLE_PRIORITY 0xff
444 static int __hyp_text
__vgic_v3_highest_priority_lr(struct kvm_vcpu
*vcpu
,
448 unsigned int used_lrs
= vcpu
->arch
.vgic_cpu
.used_lrs
;
449 u8 priority
= GICv3_IDLE_PRIORITY
;
452 for (i
= 0; i
< used_lrs
; i
++) {
453 u64 val
= __gic_v3_get_lr(i
);
454 u8 lr_prio
= (val
& ICH_LR_PRIORITY_MASK
) >> ICH_LR_PRIORITY_SHIFT
;
456 /* Not pending in the state? */
457 if ((val
& ICH_LR_STATE
) != ICH_LR_PENDING_BIT
)
460 /* Group-0 interrupt, but Group-0 disabled? */
461 if (!(val
& ICH_LR_GROUP
) && !(vmcr
& ICH_VMCR_ENG0_MASK
))
464 /* Group-1 interrupt, but Group-1 disabled? */
465 if ((val
& ICH_LR_GROUP
) && !(vmcr
& ICH_VMCR_ENG1_MASK
))
468 /* Not the highest priority? */
469 if (lr_prio
>= priority
)
472 /* This is a candidate */
479 *lr_val
= ICC_IAR1_EL1_SPURIOUS
;
484 static int __hyp_text
__vgic_v3_find_active_lr(struct kvm_vcpu
*vcpu
,
485 int intid
, u64
*lr_val
)
487 unsigned int used_lrs
= vcpu
->arch
.vgic_cpu
.used_lrs
;
490 for (i
= 0; i
< used_lrs
; i
++) {
491 u64 val
= __gic_v3_get_lr(i
);
493 if ((val
& ICH_LR_VIRTUAL_ID_MASK
) == intid
&&
494 (val
& ICH_LR_ACTIVE_BIT
)) {
500 *lr_val
= ICC_IAR1_EL1_SPURIOUS
;
504 static int __hyp_text
__vgic_v3_get_highest_active_priority(void)
506 u8 nr_apr_regs
= vtr_to_nr_apr_regs(read_gicreg(ICH_VTR_EL2
));
510 for (i
= 0; i
< nr_apr_regs
; i
++) {
514 * The ICH_AP0Rn_EL2 and ICH_AP1Rn_EL2 registers
515 * contain the active priority levels for this VCPU
516 * for the maximum number of supported priority
517 * levels, and we return the full priority level only
518 * if the BPR is programmed to its minimum, otherwise
519 * we return a combination of the priority level and
520 * subpriority, as determined by the setting of the
521 * BPR, but without the full subpriority.
523 val
= __vgic_v3_read_ap0rn(i
);
524 val
|= __vgic_v3_read_ap1rn(i
);
530 return (hap
+ __ffs(val
)) << __vgic_v3_bpr_min();
533 return GICv3_IDLE_PRIORITY
;
536 static unsigned int __hyp_text
__vgic_v3_get_bpr0(u32 vmcr
)
538 return (vmcr
& ICH_VMCR_BPR0_MASK
) >> ICH_VMCR_BPR0_SHIFT
;
541 static unsigned int __hyp_text
__vgic_v3_get_bpr1(u32 vmcr
)
545 if (vmcr
& ICH_VMCR_CBPR_MASK
) {
546 bpr
= __vgic_v3_get_bpr0(vmcr
);
550 bpr
= (vmcr
& ICH_VMCR_BPR1_MASK
) >> ICH_VMCR_BPR1_SHIFT
;
557 * Convert a priority to a preemption level, taking the relevant BPR
558 * into account by zeroing the sub-priority bits.
560 static u8 __hyp_text
__vgic_v3_pri_to_pre(u8 pri
, u32 vmcr
, int grp
)
565 bpr
= __vgic_v3_get_bpr0(vmcr
) + 1;
567 bpr
= __vgic_v3_get_bpr1(vmcr
);
569 return pri
& (GENMASK(7, 0) << bpr
);
573 * The priority value is independent of any of the BPR values, so we
574 * normalize it using the minumal BPR value. This guarantees that no
575 * matter what the guest does with its BPR, we can always set/get the
576 * same value of a priority.
578 static void __hyp_text
__vgic_v3_set_active_priority(u8 pri
, u32 vmcr
, int grp
)
584 pre
= __vgic_v3_pri_to_pre(pri
, vmcr
, grp
);
585 ap
= pre
>> __vgic_v3_bpr_min();
589 val
= __vgic_v3_read_ap0rn(apr
);
590 __vgic_v3_write_ap0rn(val
| BIT(ap
% 32), apr
);
592 val
= __vgic_v3_read_ap1rn(apr
);
593 __vgic_v3_write_ap1rn(val
| BIT(ap
% 32), apr
);
597 static int __hyp_text
__vgic_v3_clear_highest_active_priority(void)
599 u8 nr_apr_regs
= vtr_to_nr_apr_regs(read_gicreg(ICH_VTR_EL2
));
603 for (i
= 0; i
< nr_apr_regs
; i
++) {
607 ap0
= __vgic_v3_read_ap0rn(i
);
608 ap1
= __vgic_v3_read_ap1rn(i
);
614 c0
= ap0
? __ffs(ap0
) : 32;
615 c1
= ap1
? __ffs(ap1
) : 32;
617 /* Always clear the LSB, which is the highest priority */
620 __vgic_v3_write_ap0rn(ap0
, i
);
624 __vgic_v3_write_ap1rn(ap1
, i
);
628 /* Rescale to 8 bits of priority */
629 return hap
<< __vgic_v3_bpr_min();
632 return GICv3_IDLE_PRIORITY
;
635 static void __hyp_text
__vgic_v3_read_iar(struct kvm_vcpu
*vcpu
, u32 vmcr
, int rt
)
641 grp
= __vgic_v3_get_group(vcpu
);
643 lr
= __vgic_v3_highest_priority_lr(vcpu
, vmcr
, &lr_val
);
647 if (grp
!= !!(lr_val
& ICH_LR_GROUP
))
650 pmr
= (vmcr
& ICH_VMCR_PMR_MASK
) >> ICH_VMCR_PMR_SHIFT
;
651 lr_prio
= (lr_val
& ICH_LR_PRIORITY_MASK
) >> ICH_LR_PRIORITY_SHIFT
;
655 if (__vgic_v3_get_highest_active_priority() <= __vgic_v3_pri_to_pre(lr_prio
, vmcr
, grp
))
658 lr_val
&= ~ICH_LR_STATE
;
659 /* No active state for LPIs */
660 if ((lr_val
& ICH_LR_VIRTUAL_ID_MASK
) <= VGIC_MAX_SPI
)
661 lr_val
|= ICH_LR_ACTIVE_BIT
;
662 __gic_v3_set_lr(lr_val
, lr
);
663 __vgic_v3_set_active_priority(lr_prio
, vmcr
, grp
);
664 vcpu_set_reg(vcpu
, rt
, lr_val
& ICH_LR_VIRTUAL_ID_MASK
);
668 vcpu_set_reg(vcpu
, rt
, ICC_IAR1_EL1_SPURIOUS
);
671 static void __hyp_text
__vgic_v3_clear_active_lr(int lr
, u64 lr_val
)
673 lr_val
&= ~ICH_LR_ACTIVE_BIT
;
674 if (lr_val
& ICH_LR_HW
) {
677 pid
= (lr_val
& ICH_LR_PHYS_ID_MASK
) >> ICH_LR_PHYS_ID_SHIFT
;
681 __gic_v3_set_lr(lr_val
, lr
);
684 static void __hyp_text
__vgic_v3_bump_eoicount(void)
688 hcr
= read_gicreg(ICH_HCR_EL2
);
689 hcr
+= 1 << ICH_HCR_EOIcount_SHIFT
;
690 write_gicreg(hcr
, ICH_HCR_EL2
);
693 static void __hyp_text
__vgic_v3_write_eoir(struct kvm_vcpu
*vcpu
, u32 vmcr
, int rt
)
695 u32 vid
= vcpu_get_reg(vcpu
, rt
);
697 u8 lr_prio
, act_prio
;
700 grp
= __vgic_v3_get_group(vcpu
);
702 /* Drop priority in any case */
703 act_prio
= __vgic_v3_clear_highest_active_priority();
705 /* If EOIing an LPI, no deactivate to be performed */
706 if (vid
>= VGIC_MIN_LPI
)
709 /* EOImode == 1, nothing to be done here */
710 if (vmcr
& ICH_VMCR_EOIM_MASK
)
713 lr
= __vgic_v3_find_active_lr(vcpu
, vid
, &lr_val
);
715 __vgic_v3_bump_eoicount();
719 lr_prio
= (lr_val
& ICH_LR_PRIORITY_MASK
) >> ICH_LR_PRIORITY_SHIFT
;
721 /* If priorities or group do not match, the guest has fscked-up. */
722 if (grp
!= !!(lr_val
& ICH_LR_GROUP
) ||
723 __vgic_v3_pri_to_pre(lr_prio
, vmcr
, grp
) != act_prio
)
726 /* Let's now perform the deactivation */
727 __vgic_v3_clear_active_lr(lr
, lr_val
);
730 static void __hyp_text
__vgic_v3_read_igrpen1(struct kvm_vcpu
*vcpu
, u32 vmcr
, int rt
)
732 vcpu_set_reg(vcpu
, rt
, !!(vmcr
& ICH_VMCR_ENG1_MASK
));
735 static void __hyp_text
__vgic_v3_write_igrpen1(struct kvm_vcpu
*vcpu
, u32 vmcr
, int rt
)
737 u64 val
= vcpu_get_reg(vcpu
, rt
);
740 vmcr
|= ICH_VMCR_ENG1_MASK
;
742 vmcr
&= ~ICH_VMCR_ENG1_MASK
;
744 __vgic_v3_write_vmcr(vmcr
);
747 static void __hyp_text
__vgic_v3_read_bpr1(struct kvm_vcpu
*vcpu
, u32 vmcr
, int rt
)
749 vcpu_set_reg(vcpu
, rt
, __vgic_v3_get_bpr1(vmcr
));
752 static void __hyp_text
__vgic_v3_write_bpr1(struct kvm_vcpu
*vcpu
, u32 vmcr
, int rt
)
754 u64 val
= vcpu_get_reg(vcpu
, rt
);
755 u8 bpr_min
= __vgic_v3_bpr_min();
757 if (vmcr
& ICH_VMCR_CBPR_MASK
)
760 /* Enforce BPR limiting */
764 val
<<= ICH_VMCR_BPR1_SHIFT
;
765 val
&= ICH_VMCR_BPR1_MASK
;
766 vmcr
&= ~ICH_VMCR_BPR1_MASK
;
769 __vgic_v3_write_vmcr(vmcr
);
772 static void __hyp_text
__vgic_v3_read_apxrn(struct kvm_vcpu
*vcpu
, int rt
, int n
)
776 if (!__vgic_v3_get_group(vcpu
))
777 val
= __vgic_v3_read_ap0rn(n
);
779 val
= __vgic_v3_read_ap1rn(n
);
781 vcpu_set_reg(vcpu
, rt
, val
);
784 static void __hyp_text
__vgic_v3_write_apxrn(struct kvm_vcpu
*vcpu
, int rt
, int n
)
786 u32 val
= vcpu_get_reg(vcpu
, rt
);
788 if (!__vgic_v3_get_group(vcpu
))
789 __vgic_v3_write_ap0rn(val
, n
);
791 __vgic_v3_write_ap1rn(val
, n
);
794 static void __hyp_text
__vgic_v3_read_apxr0(struct kvm_vcpu
*vcpu
,
797 __vgic_v3_read_apxrn(vcpu
, rt
, 0);
800 static void __hyp_text
__vgic_v3_read_apxr1(struct kvm_vcpu
*vcpu
,
803 __vgic_v3_read_apxrn(vcpu
, rt
, 1);
806 static void __hyp_text
__vgic_v3_read_apxr2(struct kvm_vcpu
*vcpu
,
809 __vgic_v3_read_apxrn(vcpu
, rt
, 2);
812 static void __hyp_text
__vgic_v3_read_apxr3(struct kvm_vcpu
*vcpu
,
815 __vgic_v3_read_apxrn(vcpu
, rt
, 3);
818 static void __hyp_text
__vgic_v3_write_apxr0(struct kvm_vcpu
*vcpu
,
821 __vgic_v3_write_apxrn(vcpu
, rt
, 0);
824 static void __hyp_text
__vgic_v3_write_apxr1(struct kvm_vcpu
*vcpu
,
827 __vgic_v3_write_apxrn(vcpu
, rt
, 1);
830 static void __hyp_text
__vgic_v3_write_apxr2(struct kvm_vcpu
*vcpu
,
833 __vgic_v3_write_apxrn(vcpu
, rt
, 2);
836 static void __hyp_text
__vgic_v3_write_apxr3(struct kvm_vcpu
*vcpu
,
839 __vgic_v3_write_apxrn(vcpu
, rt
, 3);
842 static void __hyp_text
__vgic_v3_read_hppir(struct kvm_vcpu
*vcpu
,
848 grp
= __vgic_v3_get_group(vcpu
);
850 lr
= __vgic_v3_highest_priority_lr(vcpu
, vmcr
, &lr_val
);
854 lr_grp
= !!(lr_val
& ICH_LR_GROUP
);
856 lr_val
= ICC_IAR1_EL1_SPURIOUS
;
859 vcpu_set_reg(vcpu
, rt
, lr_val
& ICH_LR_VIRTUAL_ID_MASK
);
862 int __hyp_text
__vgic_v3_perform_cpuif_access(struct kvm_vcpu
*vcpu
)
867 void (*fn
)(struct kvm_vcpu
*, u32
, int);
871 esr
= kvm_vcpu_get_hsr(vcpu
);
872 if (vcpu_mode_is_32bit(vcpu
)) {
873 if (!kvm_condition_valid(vcpu
))
876 sysreg
= esr_cp15_to_sysreg(esr
);
878 sysreg
= esr_sys64_to_sysreg(esr
);
881 is_read
= (esr
& ESR_ELx_SYS64_ISS_DIR_MASK
) == ESR_ELx_SYS64_ISS_DIR_READ
;
885 fn
= __vgic_v3_read_iar
;
888 fn
= __vgic_v3_write_eoir
;
892 fn
= __vgic_v3_read_igrpen1
;
894 fn
= __vgic_v3_write_igrpen1
;
898 fn
= __vgic_v3_read_bpr1
;
900 fn
= __vgic_v3_write_bpr1
;
902 case ICC_AP1Rn_EL1(0):
904 fn
= __vgic_v3_read_apxr0
;
906 fn
= __vgic_v3_write_apxr0
;
908 case ICC_AP1Rn_EL1(1):
910 fn
= __vgic_v3_read_apxr1
;
912 fn
= __vgic_v3_write_apxr1
;
914 case ICC_AP1Rn_EL1(2):
916 fn
= __vgic_v3_read_apxr2
;
918 fn
= __vgic_v3_write_apxr2
;
920 case ICC_AP1Rn_EL1(3):
922 fn
= __vgic_v3_read_apxr3
;
924 fn
= __vgic_v3_write_apxr3
;
927 fn
= __vgic_v3_read_hppir
;
933 vmcr
= __vgic_v3_read_vmcr();
934 rt
= kvm_vcpu_sys_get_rt(vcpu
);