2 * ARM Generic Interrupt Controller v3
4 * Copyright (c) 2016 Linaro Limited
5 * Written by Peter Maydell
7 * This code is licensed under the GPL, version 2 or (at your option)
11 /* This file contains the code for the system register interface
12 * portions of the GICv3.
15 #include "qemu/osdep.h"
16 #include "qemu/bitops.h"
17 #include "qemu/main-loop.h"
19 #include "gicv3_internal.h"
23 void gicv3_set_gicv3state(CPUState
*cpu
, GICv3CPUState
*s
)
25 ARMCPU
*arm_cpu
= ARM_CPU(cpu
);
26 CPUARMState
*env
= &arm_cpu
->env
;
28 env
->gicv3state
= (void *)s
;
31 static GICv3CPUState
*icc_cs_from_env(CPUARMState
*env
)
33 return env
->gicv3state
;
36 static bool gicv3_use_ns_bank(CPUARMState
*env
)
38 /* Return true if we should use the NonSecure bank for a banked GIC
39 * CPU interface register. Note that this differs from the
40 * access_secure_reg() function because GICv3 banked registers are
41 * banked even for AArch64, unlike the other CPU system registers.
43 return !arm_is_secure_below_el3(env
);
46 /* The minimum BPR for the virtual interface is a configurable property */
47 static inline int icv_min_vbpr(GICv3CPUState
*cs
)
49 return 7 - cs
->vprebits
;
52 /* Simple accessor functions for LR fields */
53 static uint32_t ich_lr_vintid(uint64_t lr
)
55 return extract64(lr
, ICH_LR_EL2_VINTID_SHIFT
, ICH_LR_EL2_VINTID_LENGTH
);
58 static uint32_t ich_lr_pintid(uint64_t lr
)
60 return extract64(lr
, ICH_LR_EL2_PINTID_SHIFT
, ICH_LR_EL2_PINTID_LENGTH
);
63 static uint32_t ich_lr_prio(uint64_t lr
)
65 return extract64(lr
, ICH_LR_EL2_PRIORITY_SHIFT
, ICH_LR_EL2_PRIORITY_LENGTH
);
68 static int ich_lr_state(uint64_t lr
)
70 return extract64(lr
, ICH_LR_EL2_STATE_SHIFT
, ICH_LR_EL2_STATE_LENGTH
);
73 static bool icv_access(CPUARMState
*env
, int hcr_flags
)
75 /* Return true if this ICC_ register access should really be
76 * directed to an ICV_ access. hcr_flags is a mask of
77 * HCR_EL2 bits to check: we treat this as an ICV_ access
78 * if we are in NS EL1 and at least one of the specified
79 * HCR_EL2 bits is set.
81 * ICV registers fall into four categories:
82 * * access if NS EL1 and HCR_EL2.FMO == 1:
83 * all ICV regs with '0' in their name
84 * * access if NS EL1 and HCR_EL2.IMO == 1:
85 * all ICV regs with '1' in their name
86 * * access if NS EL1 and either IMO or FMO == 1:
89 uint64_t hcr_el2
= arm_hcr_el2_eff(env
);
90 bool flagmatch
= hcr_el2
& hcr_flags
& (HCR_IMO
| HCR_FMO
);
92 return flagmatch
&& arm_current_el(env
) == 1
93 && !arm_is_secure_below_el3(env
);
96 static int read_vbpr(GICv3CPUState
*cs
, int grp
)
98 /* Read VBPR value out of the VMCR field (caller must handle
99 * VCBPR effects if required)
101 if (grp
== GICV3_G0
) {
102 return extract64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VBPR0_SHIFT
,
103 ICH_VMCR_EL2_VBPR0_LENGTH
);
105 return extract64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VBPR1_SHIFT
,
106 ICH_VMCR_EL2_VBPR1_LENGTH
);
110 static void write_vbpr(GICv3CPUState
*cs
, int grp
, int value
)
112 /* Write new VBPR1 value, handling the "writing a value less than
113 * the minimum sets it to the minimum" semantics.
115 int min
= icv_min_vbpr(cs
);
117 if (grp
!= GICV3_G0
) {
121 value
= MAX(value
, min
);
123 if (grp
== GICV3_G0
) {
124 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VBPR0_SHIFT
,
125 ICH_VMCR_EL2_VBPR0_LENGTH
, value
);
127 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VBPR1_SHIFT
,
128 ICH_VMCR_EL2_VBPR1_LENGTH
, value
);
132 static uint32_t icv_fullprio_mask(GICv3CPUState
*cs
)
134 /* Return a mask word which clears the unimplemented priority bits
135 * from a priority value for a virtual interrupt. (Not to be confused
136 * with the group priority, whose mask depends on the value of VBPR
137 * for the interrupt group.)
139 return ~0U << (8 - cs
->vpribits
);
142 static int ich_highest_active_virt_prio(GICv3CPUState
*cs
)
144 /* Calculate the current running priority based on the set bits
145 * in the ICH Active Priority Registers.
148 int aprmax
= 1 << (cs
->vprebits
- 5);
150 assert(aprmax
<= ARRAY_SIZE(cs
->ich_apr
[0]));
152 for (i
= 0; i
< aprmax
; i
++) {
153 uint32_t apr
= cs
->ich_apr
[GICV3_G0
][i
] |
154 cs
->ich_apr
[GICV3_G1NS
][i
];
159 return (i
* 32 + ctz32(apr
)) << (icv_min_vbpr(cs
) + 1);
161 /* No current active interrupts: return idle priority */
165 static int hppvi_index(GICv3CPUState
*cs
)
167 /* Return the list register index of the highest priority pending
168 * virtual interrupt, as per the HighestPriorityVirtualInterrupt
169 * pseudocode. If no pending virtual interrupts, return -1.
173 /* Note that a list register entry with a priority of 0xff will
174 * never be reported by this function; this is the architecturally
179 if (!(cs
->ich_vmcr_el2
& (ICH_VMCR_EL2_VENG0
| ICH_VMCR_EL2_VENG1
))) {
180 /* Both groups disabled, definitely nothing to do */
184 for (i
= 0; i
< cs
->num_list_regs
; i
++) {
185 uint64_t lr
= cs
->ich_lr_el2
[i
];
188 if (ich_lr_state(lr
) != ICH_LR_EL2_STATE_PENDING
) {
193 /* Ignore interrupts if relevant group enable not set */
194 if (lr
& ICH_LR_EL2_GROUP
) {
195 if (!(cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG1
)) {
199 if (!(cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG0
)) {
204 thisprio
= ich_lr_prio(lr
);
206 if (thisprio
< prio
) {
215 static uint32_t icv_gprio_mask(GICv3CPUState
*cs
, int group
)
217 /* Return a mask word which clears the subpriority bits from
218 * a priority value for a virtual interrupt in the specified group.
219 * This depends on the VBPR value.
220 * If using VBPR0 then:
221 * a BPR of 0 means the group priority bits are [7:1];
222 * a BPR of 1 means they are [7:2], and so on down to
223 * a BPR of 7 meaning no group priority bits at all.
224 * If using VBPR1 then:
225 * a BPR of 0 is impossible (the minimum value is 1)
226 * a BPR of 1 means the group priority bits are [7:1];
227 * a BPR of 2 means they are [7:2], and so on down to
228 * a BPR of 7 meaning the group priority is [7].
230 * Which BPR to use depends on the group of the interrupt and
231 * the current ICH_VMCR_EL2.VCBPR settings.
233 * This corresponds to the VGroupBits() pseudocode.
237 if (group
== GICV3_G1NS
&& cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VCBPR
) {
241 bpr
= read_vbpr(cs
, group
);
242 if (group
== GICV3_G1NS
) {
247 return ~0U << (bpr
+ 1);
250 static bool icv_hppi_can_preempt(GICv3CPUState
*cs
, uint64_t lr
)
252 /* Return true if we can signal this virtual interrupt defined by
253 * the given list register value; see the pseudocode functions
254 * CanSignalVirtualInterrupt and CanSignalVirtualInt.
255 * Compare also icc_hppi_can_preempt() which is the non-virtual
256 * equivalent of these checks.
259 uint32_t mask
, prio
, rprio
, vpmr
;
261 if (!(cs
->ich_hcr_el2
& ICH_HCR_EL2_EN
)) {
262 /* Virtual interface disabled */
266 /* We don't need to check that this LR is in Pending state because
267 * that has already been done in hppvi_index().
270 prio
= ich_lr_prio(lr
);
271 vpmr
= extract64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VPMR_SHIFT
,
272 ICH_VMCR_EL2_VPMR_LENGTH
);
275 /* Priority mask masks this interrupt */
279 rprio
= ich_highest_active_virt_prio(cs
);
281 /* No running interrupt so we can preempt */
285 grp
= (lr
& ICH_LR_EL2_GROUP
) ? GICV3_G1NS
: GICV3_G0
;
287 mask
= icv_gprio_mask(cs
, grp
);
289 /* We only preempt a running interrupt if the pending interrupt's
290 * group priority is sufficient (the subpriorities are not considered).
292 if ((prio
& mask
) < (rprio
& mask
)) {
299 static uint32_t eoi_maintenance_interrupt_state(GICv3CPUState
*cs
,
302 /* Return a set of bits indicating the EOI maintenance interrupt status
303 * for each list register. The EOI maintenance interrupt status is
304 * 1 if LR.State == 0 && LR.HW == 0 && LR.EOI == 1
305 * (see the GICv3 spec for the ICH_EISR_EL2 register).
306 * If misr is not NULL then we should also collect the information
307 * about the MISR.EOI, MISR.NP and MISR.U bits.
311 bool seenpending
= false;
314 for (i
= 0; i
< cs
->num_list_regs
; i
++) {
315 uint64_t lr
= cs
->ich_lr_el2
[i
];
317 if ((lr
& (ICH_LR_EL2_STATE_MASK
| ICH_LR_EL2_HW
| ICH_LR_EL2_EOI
))
321 if ((lr
& ICH_LR_EL2_STATE_MASK
)) {
324 if (ich_lr_state(lr
) == ICH_LR_EL2_STATE_PENDING
) {
330 if (validcount
< 2 && (cs
->ich_hcr_el2
& ICH_HCR_EL2_UIE
)) {
331 *misr
|= ICH_MISR_EL2_U
;
333 if (!seenpending
&& (cs
->ich_hcr_el2
& ICH_HCR_EL2_NPIE
)) {
334 *misr
|= ICH_MISR_EL2_NP
;
337 *misr
|= ICH_MISR_EL2_EOI
;
343 static uint32_t maintenance_interrupt_state(GICv3CPUState
*cs
)
345 /* Return a set of bits indicating the maintenance interrupt status
346 * (as seen in the ICH_MISR_EL2 register).
350 /* Scan list registers and fill in the U, NP and EOI bits */
351 eoi_maintenance_interrupt_state(cs
, &value
);
353 if (cs
->ich_hcr_el2
& (ICH_HCR_EL2_LRENPIE
| ICH_HCR_EL2_EOICOUNT_MASK
)) {
354 value
|= ICH_MISR_EL2_LRENP
;
357 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_VGRP0EIE
) &&
358 (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG0
)) {
359 value
|= ICH_MISR_EL2_VGRP0E
;
362 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_VGRP0DIE
) &&
363 !(cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG1
)) {
364 value
|= ICH_MISR_EL2_VGRP0D
;
366 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_VGRP1EIE
) &&
367 (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG1
)) {
368 value
|= ICH_MISR_EL2_VGRP1E
;
371 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_VGRP1DIE
) &&
372 !(cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG1
)) {
373 value
|= ICH_MISR_EL2_VGRP1D
;
379 static void gicv3_cpuif_virt_update(GICv3CPUState
*cs
)
381 /* Tell the CPU about any pending virtual interrupts or
382 * maintenance interrupts, following a change to the state
383 * of the CPU interface relevant to virtual interrupts.
385 * CAUTION: this function will call qemu_set_irq() on the
386 * CPU maintenance IRQ line, which is typically wired up
387 * to the GIC as a per-CPU interrupt. This means that it
388 * will recursively call back into the GIC code via
389 * gicv3_redist_set_irq() and thus into the CPU interface code's
390 * gicv3_cpuif_update(). It is therefore important that this
391 * function is only called as the final action of a CPU interface
392 * register write implementation, after all the GIC state
393 * fields have been updated. gicv3_cpuif_update() also must
394 * not cause this function to be called, but that happens
395 * naturally as a result of there being no architectural
396 * linkage between the physical and virtual GIC logic.
402 ARMCPU
*cpu
= ARM_CPU(cs
->cpu
);
404 idx
= hppvi_index(cs
);
405 trace_gicv3_cpuif_virt_update(gicv3_redist_affid(cs
), idx
);
407 uint64_t lr
= cs
->ich_lr_el2
[idx
];
409 if (icv_hppi_can_preempt(cs
, lr
)) {
410 /* Virtual interrupts are simple: G0 are always FIQ, and G1 IRQ */
411 if (lr
& ICH_LR_EL2_GROUP
) {
419 if (cs
->ich_hcr_el2
& ICH_HCR_EL2_EN
) {
420 maintlevel
= maintenance_interrupt_state(cs
);
423 trace_gicv3_cpuif_virt_set_irqs(gicv3_redist_affid(cs
), fiqlevel
,
424 irqlevel
, maintlevel
);
426 qemu_set_irq(cs
->parent_vfiq
, fiqlevel
);
427 qemu_set_irq(cs
->parent_virq
, irqlevel
);
428 qemu_set_irq(cpu
->gicv3_maintenance_interrupt
, maintlevel
);
431 static uint64_t icv_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
433 GICv3CPUState
*cs
= icc_cs_from_env(env
);
434 int regno
= ri
->opc2
& 3;
435 int grp
= (ri
->crm
& 1) ? GICV3_G1NS
: GICV3_G0
;
436 uint64_t value
= cs
->ich_apr
[grp
][regno
];
438 trace_gicv3_icv_ap_read(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
442 static void icv_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
445 GICv3CPUState
*cs
= icc_cs_from_env(env
);
446 int regno
= ri
->opc2
& 3;
447 int grp
= (ri
->crm
& 1) ? GICV3_G1NS
: GICV3_G0
;
449 trace_gicv3_icv_ap_write(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
451 cs
->ich_apr
[grp
][regno
] = value
& 0xFFFFFFFFU
;
453 gicv3_cpuif_virt_update(cs
);
457 static uint64_t icv_bpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
459 GICv3CPUState
*cs
= icc_cs_from_env(env
);
460 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1NS
;
464 if (grp
== GICV3_G1NS
&& (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VCBPR
)) {
465 /* reads return bpr0 + 1 saturated to 7, writes ignored */
470 bpr
= read_vbpr(cs
, grp
);
477 trace_gicv3_icv_bpr_read(ri
->crm
== 8 ? 0 : 1, gicv3_redist_affid(cs
), bpr
);
482 static void icv_bpr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
485 GICv3CPUState
*cs
= icc_cs_from_env(env
);
486 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1NS
;
488 trace_gicv3_icv_bpr_write(ri
->crm
== 8 ? 0 : 1,
489 gicv3_redist_affid(cs
), value
);
491 if (grp
== GICV3_G1NS
&& (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VCBPR
)) {
492 /* reads return bpr0 + 1 saturated to 7, writes ignored */
496 write_vbpr(cs
, grp
, value
);
498 gicv3_cpuif_virt_update(cs
);
501 static uint64_t icv_pmr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
503 GICv3CPUState
*cs
= icc_cs_from_env(env
);
506 value
= extract64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VPMR_SHIFT
,
507 ICH_VMCR_EL2_VPMR_LENGTH
);
509 trace_gicv3_icv_pmr_read(gicv3_redist_affid(cs
), value
);
513 static void icv_pmr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
516 GICv3CPUState
*cs
= icc_cs_from_env(env
);
518 trace_gicv3_icv_pmr_write(gicv3_redist_affid(cs
), value
);
520 value
&= icv_fullprio_mask(cs
);
522 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VPMR_SHIFT
,
523 ICH_VMCR_EL2_VPMR_LENGTH
, value
);
525 gicv3_cpuif_virt_update(cs
);
528 static uint64_t icv_igrpen_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
530 GICv3CPUState
*cs
= icc_cs_from_env(env
);
534 enbit
= ri
->opc2
& 1 ? ICH_VMCR_EL2_VENG1_SHIFT
: ICH_VMCR_EL2_VENG0_SHIFT
;
535 value
= extract64(cs
->ich_vmcr_el2
, enbit
, 1);
537 trace_gicv3_icv_igrpen_read(ri
->opc2
& 1 ? 1 : 0,
538 gicv3_redist_affid(cs
), value
);
542 static void icv_igrpen_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
545 GICv3CPUState
*cs
= icc_cs_from_env(env
);
548 trace_gicv3_icv_igrpen_write(ri
->opc2
& 1 ? 1 : 0,
549 gicv3_redist_affid(cs
), value
);
551 enbit
= ri
->opc2
& 1 ? ICH_VMCR_EL2_VENG1_SHIFT
: ICH_VMCR_EL2_VENG0_SHIFT
;
553 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, enbit
, 1, value
);
554 gicv3_cpuif_virt_update(cs
);
557 static uint64_t icv_ctlr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
559 GICv3CPUState
*cs
= icc_cs_from_env(env
);
562 /* Note that the fixed fields here (A3V, SEIS, IDbits, PRIbits)
563 * should match the ones reported in ich_vtr_read().
565 value
= ICC_CTLR_EL1_A3V
| (1 << ICC_CTLR_EL1_IDBITS_SHIFT
) |
566 (7 << ICC_CTLR_EL1_PRIBITS_SHIFT
);
568 if (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VEOIM
) {
569 value
|= ICC_CTLR_EL1_EOIMODE
;
572 if (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VCBPR
) {
573 value
|= ICC_CTLR_EL1_CBPR
;
576 trace_gicv3_icv_ctlr_read(gicv3_redist_affid(cs
), value
);
580 static void icv_ctlr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
583 GICv3CPUState
*cs
= icc_cs_from_env(env
);
585 trace_gicv3_icv_ctlr_write(gicv3_redist_affid(cs
), value
);
587 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VCBPR_SHIFT
,
588 1, value
& ICC_CTLR_EL1_CBPR
? 1 : 0);
589 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VEOIM_SHIFT
,
590 1, value
& ICC_CTLR_EL1_EOIMODE
? 1 : 0);
592 gicv3_cpuif_virt_update(cs
);
595 static uint64_t icv_rpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
597 GICv3CPUState
*cs
= icc_cs_from_env(env
);
598 int prio
= ich_highest_active_virt_prio(cs
);
600 trace_gicv3_icv_rpr_read(gicv3_redist_affid(cs
), prio
);
604 static uint64_t icv_hppir_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
606 GICv3CPUState
*cs
= icc_cs_from_env(env
);
607 int grp
= ri
->crm
== 8 ? GICV3_G0
: GICV3_G1NS
;
608 int idx
= hppvi_index(cs
);
609 uint64_t value
= INTID_SPURIOUS
;
612 uint64_t lr
= cs
->ich_lr_el2
[idx
];
613 int thisgrp
= (lr
& ICH_LR_EL2_GROUP
) ? GICV3_G1NS
: GICV3_G0
;
615 if (grp
== thisgrp
) {
616 value
= ich_lr_vintid(lr
);
620 trace_gicv3_icv_hppir_read(grp
, gicv3_redist_affid(cs
), value
);
624 static void icv_activate_irq(GICv3CPUState
*cs
, int idx
, int grp
)
626 /* Activate the interrupt in the specified list register
627 * by moving it from Pending to Active state, and update the
628 * Active Priority Registers.
630 uint32_t mask
= icv_gprio_mask(cs
, grp
);
631 int prio
= ich_lr_prio(cs
->ich_lr_el2
[idx
]) & mask
;
632 int aprbit
= prio
>> (8 - cs
->vprebits
);
633 int regno
= aprbit
/ 32;
634 int regbit
= aprbit
% 32;
636 cs
->ich_lr_el2
[idx
] &= ~ICH_LR_EL2_STATE_PENDING_BIT
;
637 cs
->ich_lr_el2
[idx
] |= ICH_LR_EL2_STATE_ACTIVE_BIT
;
638 cs
->ich_apr
[grp
][regno
] |= (1 << regbit
);
641 static uint64_t icv_iar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
643 GICv3CPUState
*cs
= icc_cs_from_env(env
);
644 int grp
= ri
->crm
== 8 ? GICV3_G0
: GICV3_G1NS
;
645 int idx
= hppvi_index(cs
);
646 uint64_t intid
= INTID_SPURIOUS
;
649 uint64_t lr
= cs
->ich_lr_el2
[idx
];
650 int thisgrp
= (lr
& ICH_LR_EL2_GROUP
) ? GICV3_G1NS
: GICV3_G0
;
652 if (thisgrp
== grp
&& icv_hppi_can_preempt(cs
, lr
)) {
653 intid
= ich_lr_vintid(lr
);
654 if (intid
< INTID_SECURE
) {
655 icv_activate_irq(cs
, idx
, grp
);
657 /* Interrupt goes from Pending to Invalid */
658 cs
->ich_lr_el2
[idx
] &= ~ICH_LR_EL2_STATE_PENDING_BIT
;
659 /* We will now return the (bogus) ID from the list register,
660 * as per the pseudocode.
666 trace_gicv3_icv_iar_read(ri
->crm
== 8 ? 0 : 1,
667 gicv3_redist_affid(cs
), intid
);
669 gicv3_cpuif_virt_update(cs
);
674 static int icc_highest_active_prio(GICv3CPUState
*cs
)
676 /* Calculate the current running priority based on the set bits
677 * in the Active Priority Registers.
681 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[0]); i
++) {
682 uint32_t apr
= cs
->icc_apr
[GICV3_G0
][i
] |
683 cs
->icc_apr
[GICV3_G1
][i
] | cs
->icc_apr
[GICV3_G1NS
][i
];
688 return (i
* 32 + ctz32(apr
)) << (GIC_MIN_BPR
+ 1);
690 /* No current active interrupts: return idle priority */
694 static uint32_t icc_gprio_mask(GICv3CPUState
*cs
, int group
)
696 /* Return a mask word which clears the subpriority bits from
697 * a priority value for an interrupt in the specified group.
698 * This depends on the BPR value. For CBPR0 (S or NS):
699 * a BPR of 0 means the group priority bits are [7:1];
700 * a BPR of 1 means they are [7:2], and so on down to
701 * a BPR of 7 meaning no group priority bits at all.
703 * a BPR of 0 is impossible (the minimum value is 1)
704 * a BPR of 1 means the group priority bits are [7:1];
705 * a BPR of 2 means they are [7:2], and so on down to
706 * a BPR of 7 meaning the group priority is [7].
708 * Which BPR to use depends on the group of the interrupt and
709 * the current ICC_CTLR.CBPR settings.
711 * This corresponds to the GroupBits() pseudocode.
715 if ((group
== GICV3_G1
&& cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
) ||
716 (group
== GICV3_G1NS
&&
717 cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
721 bpr
= cs
->icc_bpr
[group
] & 7;
723 if (group
== GICV3_G1NS
) {
728 return ~0U << (bpr
+ 1);
731 static bool icc_no_enabled_hppi(GICv3CPUState
*cs
)
733 /* Return true if there is no pending interrupt, or the
734 * highest priority pending interrupt is in a group which has been
735 * disabled at the CPU interface by the ICC_IGRPEN* register enable bits.
737 return cs
->hppi
.prio
== 0xff || (cs
->icc_igrpen
[cs
->hppi
.grp
] == 0);
740 static bool icc_hppi_can_preempt(GICv3CPUState
*cs
)
742 /* Return true if we have a pending interrupt of sufficient
743 * priority to preempt.
748 if (icc_no_enabled_hppi(cs
)) {
752 if (cs
->hppi
.prio
>= cs
->icc_pmr_el1
) {
753 /* Priority mask masks this interrupt */
757 rprio
= icc_highest_active_prio(cs
);
759 /* No currently running interrupt so we can preempt */
763 mask
= icc_gprio_mask(cs
, cs
->hppi
.grp
);
765 /* We only preempt a running interrupt if the pending interrupt's
766 * group priority is sufficient (the subpriorities are not considered).
768 if ((cs
->hppi
.prio
& mask
) < (rprio
& mask
)) {
775 void gicv3_cpuif_update(GICv3CPUState
*cs
)
777 /* Tell the CPU about its highest priority pending interrupt */
780 ARMCPU
*cpu
= ARM_CPU(cs
->cpu
);
781 CPUARMState
*env
= &cpu
->env
;
783 g_assert(qemu_mutex_iothread_locked());
785 trace_gicv3_cpuif_update(gicv3_redist_affid(cs
), cs
->hppi
.irq
,
786 cs
->hppi
.grp
, cs
->hppi
.prio
);
788 if (cs
->hppi
.grp
== GICV3_G1
&& !arm_feature(env
, ARM_FEATURE_EL3
)) {
789 /* If a Security-enabled GIC sends a G1S interrupt to a
790 * Security-disabled CPU, we must treat it as if it were G0.
792 cs
->hppi
.grp
= GICV3_G0
;
795 if (icc_hppi_can_preempt(cs
)) {
796 /* We have an interrupt: should we signal it as IRQ or FIQ?
797 * This is described in the GICv3 spec section 4.6.2.
801 switch (cs
->hppi
.grp
) {
806 isfiq
= (!arm_is_secure(env
) ||
807 (arm_current_el(env
) == 3 && arm_el_is_aa64(env
, 3)));
810 isfiq
= arm_is_secure(env
);
813 g_assert_not_reached();
823 trace_gicv3_cpuif_set_irqs(gicv3_redist_affid(cs
), fiqlevel
, irqlevel
);
825 qemu_set_irq(cs
->parent_fiq
, fiqlevel
);
826 qemu_set_irq(cs
->parent_irq
, irqlevel
);
829 static uint64_t icc_pmr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
831 GICv3CPUState
*cs
= icc_cs_from_env(env
);
832 uint32_t value
= cs
->icc_pmr_el1
;
834 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
835 return icv_pmr_read(env
, ri
);
838 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_is_secure(env
) &&
839 (env
->cp15
.scr_el3
& SCR_FIQ
)) {
840 /* NS access and Group 0 is inaccessible to NS: return the
841 * NS view of the current priority
843 if ((value
& 0x80) == 0) {
844 /* Secure priorities not visible to NS */
846 } else if (value
!= 0xff) {
847 value
= (value
<< 1) & 0xff;
851 trace_gicv3_icc_pmr_read(gicv3_redist_affid(cs
), value
);
856 static void icc_pmr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
859 GICv3CPUState
*cs
= icc_cs_from_env(env
);
861 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
862 return icv_pmr_write(env
, ri
, value
);
865 trace_gicv3_icc_pmr_write(gicv3_redist_affid(cs
), value
);
869 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_is_secure(env
) &&
870 (env
->cp15
.scr_el3
& SCR_FIQ
)) {
871 /* NS access and Group 0 is inaccessible to NS: return the
872 * NS view of the current priority
874 if (!(cs
->icc_pmr_el1
& 0x80)) {
875 /* Current PMR in the secure range, don't allow NS to change it */
878 value
= (value
>> 1) | 0x80;
880 cs
->icc_pmr_el1
= value
;
881 gicv3_cpuif_update(cs
);
884 static void icc_activate_irq(GICv3CPUState
*cs
, int irq
)
886 /* Move the interrupt from the Pending state to Active, and update
887 * the Active Priority Registers
889 uint32_t mask
= icc_gprio_mask(cs
, cs
->hppi
.grp
);
890 int prio
= cs
->hppi
.prio
& mask
;
891 int aprbit
= prio
>> 1;
892 int regno
= aprbit
/ 32;
893 int regbit
= aprbit
% 32;
895 cs
->icc_apr
[cs
->hppi
.grp
][regno
] |= (1 << regbit
);
897 if (irq
< GIC_INTERNAL
) {
898 cs
->gicr_iactiver0
= deposit32(cs
->gicr_iactiver0
, irq
, 1, 1);
899 cs
->gicr_ipendr0
= deposit32(cs
->gicr_ipendr0
, irq
, 1, 0);
900 gicv3_redist_update(cs
);
902 gicv3_gicd_active_set(cs
->gic
, irq
);
903 gicv3_gicd_pending_clear(cs
->gic
, irq
);
904 gicv3_update(cs
->gic
, irq
, 1);
908 static uint64_t icc_hppir0_value(GICv3CPUState
*cs
, CPUARMState
*env
)
910 /* Return the highest priority pending interrupt register value
915 if (cs
->hppi
.prio
== 0xff) {
916 return INTID_SPURIOUS
;
919 /* Check whether we can return the interrupt or if we should return
920 * a special identifier, as per the CheckGroup0ForSpecialIdentifiers
921 * pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM
924 irq_is_secure
= (!(cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) &&
925 (cs
->hppi
.grp
!= GICV3_G1NS
));
927 if (cs
->hppi
.grp
!= GICV3_G0
&& !arm_is_el3_or_mon(env
)) {
928 return INTID_SPURIOUS
;
930 if (irq_is_secure
&& !arm_is_secure(env
)) {
931 /* Secure interrupts not visible to Nonsecure */
932 return INTID_SPURIOUS
;
935 if (cs
->hppi
.grp
!= GICV3_G0
) {
936 /* Indicate to EL3 that there's a Group 1 interrupt for the other
939 return irq_is_secure
? INTID_SECURE
: INTID_NONSECURE
;
945 static uint64_t icc_hppir1_value(GICv3CPUState
*cs
, CPUARMState
*env
)
947 /* Return the highest priority pending interrupt register value
952 if (cs
->hppi
.prio
== 0xff) {
953 return INTID_SPURIOUS
;
956 /* Check whether we can return the interrupt or if we should return
957 * a special identifier, as per the CheckGroup1ForSpecialIdentifiers
958 * pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM
961 irq_is_secure
= (!(cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) &&
962 (cs
->hppi
.grp
!= GICV3_G1NS
));
964 if (cs
->hppi
.grp
== GICV3_G0
) {
965 /* Group 0 interrupts not visible via HPPIR1 */
966 return INTID_SPURIOUS
;
969 if (!arm_is_secure(env
)) {
970 /* Secure interrupts not visible in Non-secure */
971 return INTID_SPURIOUS
;
973 } else if (!arm_is_el3_or_mon(env
) && arm_is_secure(env
)) {
974 /* Group 1 non-secure interrupts not visible in Secure EL1 */
975 return INTID_SPURIOUS
;
981 static uint64_t icc_iar0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
983 GICv3CPUState
*cs
= icc_cs_from_env(env
);
986 if (icv_access(env
, HCR_FMO
)) {
987 return icv_iar_read(env
, ri
);
990 if (!icc_hppi_can_preempt(cs
)) {
991 intid
= INTID_SPURIOUS
;
993 intid
= icc_hppir0_value(cs
, env
);
996 if (!(intid
>= INTID_SECURE
&& intid
<= INTID_SPURIOUS
)) {
997 icc_activate_irq(cs
, intid
);
1000 trace_gicv3_icc_iar0_read(gicv3_redist_affid(cs
), intid
);
1004 static uint64_t icc_iar1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1006 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1009 if (icv_access(env
, HCR_IMO
)) {
1010 return icv_iar_read(env
, ri
);
1013 if (!icc_hppi_can_preempt(cs
)) {
1014 intid
= INTID_SPURIOUS
;
1016 intid
= icc_hppir1_value(cs
, env
);
1019 if (!(intid
>= INTID_SECURE
&& intid
<= INTID_SPURIOUS
)) {
1020 icc_activate_irq(cs
, intid
);
1023 trace_gicv3_icc_iar1_read(gicv3_redist_affid(cs
), intid
);
1027 static void icc_drop_prio(GICv3CPUState
*cs
, int grp
)
1029 /* Drop the priority of the currently active interrupt in
1030 * the specified group.
1032 * Note that we can guarantee (because of the requirement to nest
1033 * ICC_IAR reads [which activate an interrupt and raise priority]
1034 * with ICC_EOIR writes [which drop the priority for the interrupt])
1035 * that the interrupt we're being called for is the highest priority
1036 * active interrupt, meaning that it has the lowest set bit in the
1039 * If the guest does not honour the ordering constraints then the
1040 * behaviour of the GIC is UNPREDICTABLE, which for us means that
1041 * the values of the APR registers might become incorrect and the
1042 * running priority will be wrong, so interrupts that should preempt
1043 * might not do so, and interrupts that should not preempt might do so.
1047 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[grp
]); i
++) {
1048 uint64_t *papr
= &cs
->icc_apr
[grp
][i
];
1053 /* Clear the lowest set bit */
1058 /* running priority change means we need an update for this cpu i/f */
1059 gicv3_cpuif_update(cs
);
1062 static bool icc_eoi_split(CPUARMState
*env
, GICv3CPUState
*cs
)
1064 /* Return true if we should split priority drop and interrupt
1065 * deactivation, ie whether the relevant EOIMode bit is set.
1067 if (arm_is_el3_or_mon(env
)) {
1068 return cs
->icc_ctlr_el3
& ICC_CTLR_EL3_EOIMODE_EL3
;
1070 if (arm_is_secure_below_el3(env
)) {
1071 return cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_EOIMODE
;
1073 return cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
;
1077 static int icc_highest_active_group(GICv3CPUState
*cs
)
1079 /* Return the group with the highest priority active interrupt.
1080 * We can do this by just comparing the APRs to see which one
1081 * has the lowest set bit.
1082 * (If more than one group is active at the same priority then
1083 * we're in UNPREDICTABLE territory.)
1087 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[0]); i
++) {
1088 int g0ctz
= ctz32(cs
->icc_apr
[GICV3_G0
][i
]);
1089 int g1ctz
= ctz32(cs
->icc_apr
[GICV3_G1
][i
]);
1090 int g1nsctz
= ctz32(cs
->icc_apr
[GICV3_G1NS
][i
]);
1092 if (g1nsctz
< g0ctz
&& g1nsctz
< g1ctz
) {
1095 if (g1ctz
< g0ctz
) {
1102 /* No set active bits? UNPREDICTABLE; return -1 so the caller
1103 * ignores the spurious EOI attempt.
1108 static void icc_deactivate_irq(GICv3CPUState
*cs
, int irq
)
1110 if (irq
< GIC_INTERNAL
) {
1111 cs
->gicr_iactiver0
= deposit32(cs
->gicr_iactiver0
, irq
, 1, 0);
1112 gicv3_redist_update(cs
);
1114 gicv3_gicd_active_clear(cs
->gic
, irq
);
1115 gicv3_update(cs
->gic
, irq
, 1);
1119 static bool icv_eoi_split(CPUARMState
*env
, GICv3CPUState
*cs
)
1121 /* Return true if we should split priority drop and interrupt
1122 * deactivation, ie whether the virtual EOIMode bit is set.
1124 return cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VEOIM
;
1127 static int icv_find_active(GICv3CPUState
*cs
, int irq
)
1129 /* Given an interrupt number for an active interrupt, return the index
1130 * of the corresponding list register, or -1 if there is no match.
1131 * Corresponds to FindActiveVirtualInterrupt pseudocode.
1135 for (i
= 0; i
< cs
->num_list_regs
; i
++) {
1136 uint64_t lr
= cs
->ich_lr_el2
[i
];
1138 if ((lr
& ICH_LR_EL2_STATE_ACTIVE_BIT
) && ich_lr_vintid(lr
) == irq
) {
1146 static void icv_deactivate_irq(GICv3CPUState
*cs
, int idx
)
1148 /* Deactivate the interrupt in the specified list register index */
1149 uint64_t lr
= cs
->ich_lr_el2
[idx
];
1151 if (lr
& ICH_LR_EL2_HW
) {
1152 /* Deactivate the associated physical interrupt */
1153 int pirq
= ich_lr_pintid(lr
);
1155 if (pirq
< INTID_SECURE
) {
1156 icc_deactivate_irq(cs
, pirq
);
1160 /* Clear the 'active' part of the state, so ActivePending->Pending
1161 * and Active->Invalid.
1163 lr
&= ~ICH_LR_EL2_STATE_ACTIVE_BIT
;
1164 cs
->ich_lr_el2
[idx
] = lr
;
1167 static void icv_increment_eoicount(GICv3CPUState
*cs
)
1169 /* Increment the EOICOUNT field in ICH_HCR_EL2 */
1170 int eoicount
= extract64(cs
->ich_hcr_el2
, ICH_HCR_EL2_EOICOUNT_SHIFT
,
1171 ICH_HCR_EL2_EOICOUNT_LENGTH
);
1173 cs
->ich_hcr_el2
= deposit64(cs
->ich_hcr_el2
, ICH_HCR_EL2_EOICOUNT_SHIFT
,
1174 ICH_HCR_EL2_EOICOUNT_LENGTH
, eoicount
+ 1);
1177 static int icv_drop_prio(GICv3CPUState
*cs
)
1179 /* Drop the priority of the currently active virtual interrupt
1180 * (favouring group 0 if there is a set active bit at
1181 * the same priority for both group 0 and group 1).
1182 * Return the priority value for the bit we just cleared,
1183 * or 0xff if no bits were set in the AP registers at all.
1184 * Note that though the ich_apr[] are uint64_t only the low
1185 * 32 bits are actually relevant.
1188 int aprmax
= 1 << (cs
->vprebits
- 5);
1190 assert(aprmax
<= ARRAY_SIZE(cs
->ich_apr
[0]));
1192 for (i
= 0; i
< aprmax
; i
++) {
1193 uint64_t *papr0
= &cs
->ich_apr
[GICV3_G0
][i
];
1194 uint64_t *papr1
= &cs
->ich_apr
[GICV3_G1NS
][i
];
1195 int apr0count
, apr1count
;
1197 if (!*papr0
&& !*papr1
) {
1201 /* We can't just use the bit-twiddling hack icc_drop_prio() does
1202 * because we need to return the bit number we cleared so
1203 * it can be compared against the list register's priority field.
1205 apr0count
= ctz32(*papr0
);
1206 apr1count
= ctz32(*papr1
);
1208 if (apr0count
<= apr1count
) {
1209 *papr0
&= *papr0
- 1;
1210 return (apr0count
+ i
* 32) << (icv_min_vbpr(cs
) + 1);
1212 *papr1
&= *papr1
- 1;
1213 return (apr1count
+ i
* 32) << (icv_min_vbpr(cs
) + 1);
1219 static void icv_dir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1222 /* Deactivate interrupt */
1223 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1225 int irq
= value
& 0xffffff;
1227 trace_gicv3_icv_dir_write(gicv3_redist_affid(cs
), value
);
1229 if (irq
>= cs
->gic
->num_irq
) {
1230 /* Also catches special interrupt numbers and LPIs */
1234 if (!icv_eoi_split(env
, cs
)) {
1238 idx
= icv_find_active(cs
, irq
);
1241 /* No list register matching this, so increment the EOI count
1242 * (might trigger a maintenance interrupt)
1244 icv_increment_eoicount(cs
);
1246 icv_deactivate_irq(cs
, idx
);
1249 gicv3_cpuif_virt_update(cs
);
1252 static void icv_eoir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1255 /* End of Interrupt */
1256 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1257 int irq
= value
& 0xffffff;
1258 int grp
= ri
->crm
== 8 ? GICV3_G0
: GICV3_G1NS
;
1261 trace_gicv3_icv_eoir_write(ri
->crm
== 8 ? 0 : 1,
1262 gicv3_redist_affid(cs
), value
);
1264 if (irq
>= cs
->gic
->num_irq
) {
1265 /* Also catches special interrupt numbers and LPIs */
1269 /* We implement the IMPDEF choice of "drop priority before doing
1270 * error checks" (because that lets us avoid scanning the AP
1273 dropprio
= icv_drop_prio(cs
);
1274 if (dropprio
== 0xff) {
1275 /* No active interrupt. It is CONSTRAINED UNPREDICTABLE
1276 * whether the list registers are checked in this
1277 * situation; we choose not to.
1282 idx
= icv_find_active(cs
, irq
);
1285 /* No valid list register corresponding to EOI ID */
1286 icv_increment_eoicount(cs
);
1288 uint64_t lr
= cs
->ich_lr_el2
[idx
];
1289 int thisgrp
= (lr
& ICH_LR_EL2_GROUP
) ? GICV3_G1NS
: GICV3_G0
;
1290 int lr_gprio
= ich_lr_prio(lr
) & icv_gprio_mask(cs
, grp
);
1292 if (thisgrp
== grp
&& lr_gprio
== dropprio
) {
1293 if (!icv_eoi_split(env
, cs
)) {
1294 /* Priority drop and deactivate not split: deactivate irq now */
1295 icv_deactivate_irq(cs
, idx
);
1300 gicv3_cpuif_virt_update(cs
);
1303 static void icc_eoir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1306 /* End of Interrupt */
1307 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1308 int irq
= value
& 0xffffff;
1311 if (icv_access(env
, ri
->crm
== 8 ? HCR_FMO
: HCR_IMO
)) {
1312 icv_eoir_write(env
, ri
, value
);
1316 trace_gicv3_icc_eoir_write(ri
->crm
== 8 ? 0 : 1,
1317 gicv3_redist_affid(cs
), value
);
1324 if (arm_is_secure(env
)) {
1331 if (irq
>= cs
->gic
->num_irq
) {
1332 /* This handles two cases:
1333 * 1. If software writes the ID of a spurious interrupt [ie 1020-1023]
1334 * to the GICC_EOIR, the GIC ignores that write.
1335 * 2. If software writes the number of a non-existent interrupt
1336 * this must be a subcase of "value written does not match the last
1337 * valid interrupt value read from the Interrupt Acknowledge
1338 * register" and so this is UNPREDICTABLE. We choose to ignore it.
1343 if (icc_highest_active_group(cs
) != grp
) {
1347 icc_drop_prio(cs
, grp
);
1349 if (!icc_eoi_split(env
, cs
)) {
1350 /* Priority drop and deactivate not split: deactivate irq now */
1351 icc_deactivate_irq(cs
, irq
);
1355 static uint64_t icc_hppir0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1357 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1360 if (icv_access(env
, HCR_FMO
)) {
1361 return icv_hppir_read(env
, ri
);
1364 value
= icc_hppir0_value(cs
, env
);
1365 trace_gicv3_icc_hppir0_read(gicv3_redist_affid(cs
), value
);
1369 static uint64_t icc_hppir1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1371 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1374 if (icv_access(env
, HCR_IMO
)) {
1375 return icv_hppir_read(env
, ri
);
1378 value
= icc_hppir1_value(cs
, env
);
1379 trace_gicv3_icc_hppir1_read(gicv3_redist_affid(cs
), value
);
1383 static uint64_t icc_bpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1385 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1386 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1
;
1387 bool satinc
= false;
1390 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1391 return icv_bpr_read(env
, ri
);
1394 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1398 if (grp
== GICV3_G1
&& !arm_is_el3_or_mon(env
) &&
1399 (cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
)) {
1400 /* CBPR_EL1S means secure EL1 or AArch32 EL3 !Mon BPR1 accesses
1406 if (grp
== GICV3_G1NS
&& arm_current_el(env
) < 3 &&
1407 (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
1408 /* reads return bpr0 + 1 sat to 7, writes ignored */
1413 bpr
= cs
->icc_bpr
[grp
];
1419 trace_gicv3_icc_bpr_read(ri
->crm
== 8 ? 0 : 1, gicv3_redist_affid(cs
), bpr
);
1424 static void icc_bpr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1427 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1428 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1
;
1431 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1432 icv_bpr_write(env
, ri
, value
);
1436 trace_gicv3_icc_bpr_write(ri
->crm
== 8 ? 0 : 1,
1437 gicv3_redist_affid(cs
), value
);
1439 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1443 if (grp
== GICV3_G1
&& !arm_is_el3_or_mon(env
) &&
1444 (cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
)) {
1445 /* CBPR_EL1S means secure EL1 or AArch32 EL3 !Mon BPR1 accesses
1451 if (grp
== GICV3_G1NS
&& arm_current_el(env
) < 3 &&
1452 (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
1453 /* reads return bpr0 + 1 sat to 7, writes ignored */
1457 minval
= (grp
== GICV3_G1NS
) ? GIC_MIN_BPR_NS
: GIC_MIN_BPR
;
1458 if (value
< minval
) {
1462 cs
->icc_bpr
[grp
] = value
& 7;
1463 gicv3_cpuif_update(cs
);
1466 static uint64_t icc_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1468 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1471 int regno
= ri
->opc2
& 3;
1472 int grp
= (ri
->crm
& 1) ? GICV3_G1
: GICV3_G0
;
1474 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1475 return icv_ap_read(env
, ri
);
1478 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1482 value
= cs
->icc_apr
[grp
][regno
];
1484 trace_gicv3_icc_ap_read(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
1488 static void icc_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1491 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1493 int regno
= ri
->opc2
& 3;
1494 int grp
= (ri
->crm
& 1) ? GICV3_G1
: GICV3_G0
;
1496 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1497 icv_ap_write(env
, ri
, value
);
1501 trace_gicv3_icc_ap_write(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
1503 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1507 /* It's not possible to claim that a Non-secure interrupt is active
1508 * at a priority outside the Non-secure range (128..255), since this
1509 * would otherwise allow malicious NS code to block delivery of S interrupts
1510 * by writing a bad value to these registers.
1512 if (grp
== GICV3_G1NS
&& regno
< 2 && arm_feature(env
, ARM_FEATURE_EL3
)) {
1516 cs
->icc_apr
[grp
][regno
] = value
& 0xFFFFFFFFU
;
1517 gicv3_cpuif_update(cs
);
1520 static void icc_dir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1523 /* Deactivate interrupt */
1524 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1525 int irq
= value
& 0xffffff;
1526 bool irq_is_secure
, single_sec_state
, irq_is_grp0
;
1527 bool route_fiq_to_el3
, route_irq_to_el3
, route_fiq_to_el2
, route_irq_to_el2
;
1529 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
1530 icv_dir_write(env
, ri
, value
);
1534 trace_gicv3_icc_dir_write(gicv3_redist_affid(cs
), value
);
1536 if (irq
>= cs
->gic
->num_irq
) {
1537 /* Also catches special interrupt numbers and LPIs */
1541 if (!icc_eoi_split(env
, cs
)) {
1545 int grp
= gicv3_irq_group(cs
->gic
, cs
, irq
);
1547 single_sec_state
= cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
;
1548 irq_is_secure
= !single_sec_state
&& (grp
!= GICV3_G1NS
);
1549 irq_is_grp0
= grp
== GICV3_G0
;
1551 /* Check whether we're allowed to deactivate this interrupt based
1552 * on its group and the current CPU state.
1553 * These checks are laid out to correspond to the spec's pseudocode.
1555 route_fiq_to_el3
= env
->cp15
.scr_el3
& SCR_FIQ
;
1556 route_irq_to_el3
= env
->cp15
.scr_el3
& SCR_IRQ
;
1557 /* No need to include !IsSecure in route_*_to_el2 as it's only
1558 * tested in cases where we know !IsSecure is true.
1560 uint64_t hcr_el2
= arm_hcr_el2_eff(env
);
1561 route_fiq_to_el2
= hcr_el2
& HCR_FMO
;
1562 route_irq_to_el2
= hcr_el2
& HCR_IMO
;
1564 switch (arm_current_el(env
)) {
1568 if (single_sec_state
&& irq_is_grp0
&& !route_fiq_to_el3
) {
1571 if (!irq_is_secure
&& !irq_is_grp0
&& !route_irq_to_el3
) {
1576 if (!arm_is_secure_below_el3(env
)) {
1577 if (single_sec_state
&& irq_is_grp0
&&
1578 !route_fiq_to_el3
&& !route_fiq_to_el2
) {
1581 if (!irq_is_secure
&& !irq_is_grp0
&&
1582 !route_irq_to_el3
&& !route_irq_to_el2
) {
1586 if (irq_is_grp0
&& !route_fiq_to_el3
) {
1590 (!irq_is_secure
|| !single_sec_state
) &&
1591 !route_irq_to_el3
) {
1597 g_assert_not_reached();
1600 icc_deactivate_irq(cs
, irq
);
1603 static uint64_t icc_rpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1605 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1608 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
1609 return icv_rpr_read(env
, ri
);
1612 prio
= icc_highest_active_prio(cs
);
1614 if (arm_feature(env
, ARM_FEATURE_EL3
) &&
1615 !arm_is_secure(env
) && (env
->cp15
.scr_el3
& SCR_FIQ
)) {
1616 /* NS GIC access and Group 0 is inaccessible to NS */
1617 if ((prio
& 0x80) == 0) {
1618 /* NS mustn't see priorities in the Secure half of the range */
1620 } else if (prio
!= 0xff) {
1621 /* Non-idle priority: show the Non-secure view of it */
1622 prio
= (prio
<< 1) & 0xff;
1626 trace_gicv3_icc_rpr_read(gicv3_redist_affid(cs
), prio
);
1630 static void icc_generate_sgi(CPUARMState
*env
, GICv3CPUState
*cs
,
1631 uint64_t value
, int grp
, bool ns
)
1633 GICv3State
*s
= cs
->gic
;
1635 /* Extract Aff3/Aff2/Aff1 and shift into the bottom 24 bits */
1636 uint64_t aff
= extract64(value
, 48, 8) << 16 |
1637 extract64(value
, 32, 8) << 8 |
1638 extract64(value
, 16, 8);
1639 uint32_t targetlist
= extract64(value
, 0, 16);
1640 uint32_t irq
= extract64(value
, 24, 4);
1641 bool irm
= extract64(value
, 40, 1);
1644 if (grp
== GICV3_G1
&& s
->gicd_ctlr
& GICD_CTLR_DS
) {
1645 /* If GICD_CTLR.DS == 1, the Distributor treats Secure Group 1
1646 * interrupts as Group 0 interrupts and must send Secure Group 0
1647 * interrupts to the target CPUs.
1652 trace_gicv3_icc_generate_sgi(gicv3_redist_affid(cs
), irq
, irm
,
1655 for (i
= 0; i
< s
->num_cpu
; i
++) {
1656 GICv3CPUState
*ocs
= &s
->cpu
[i
];
1659 /* IRM == 1 : route to all CPUs except self */
1664 /* IRM == 0 : route to Aff3.Aff2.Aff1.n for all n in [0..15]
1665 * where the corresponding bit is set in targetlist
1669 if (ocs
->gicr_typer
>> 40 != aff
) {
1672 aff0
= extract64(ocs
->gicr_typer
, 32, 8);
1673 if (aff0
> 15 || extract32(targetlist
, aff0
, 1) == 0) {
1678 /* The redistributor will check against its own GICR_NSACR as needed */
1679 gicv3_redist_send_sgi(ocs
, grp
, irq
, ns
);
1683 static void icc_sgi0r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1686 /* Generate Secure Group 0 SGI. */
1687 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1688 bool ns
= !arm_is_secure(env
);
1690 icc_generate_sgi(env
, cs
, value
, GICV3_G0
, ns
);
1693 static void icc_sgi1r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1696 /* Generate Group 1 SGI for the current Security state */
1697 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1699 bool ns
= !arm_is_secure(env
);
1701 grp
= ns
? GICV3_G1NS
: GICV3_G1
;
1702 icc_generate_sgi(env
, cs
, value
, grp
, ns
);
1705 static void icc_asgi1r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1708 /* Generate Group 1 SGI for the Security state that is not
1711 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1713 bool ns
= !arm_is_secure(env
);
1715 grp
= ns
? GICV3_G1
: GICV3_G1NS
;
1716 icc_generate_sgi(env
, cs
, value
, grp
, ns
);
1719 static uint64_t icc_igrpen_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1721 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1722 int grp
= ri
->opc2
& 1 ? GICV3_G1
: GICV3_G0
;
1725 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1726 return icv_igrpen_read(env
, ri
);
1729 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1733 value
= cs
->icc_igrpen
[grp
];
1734 trace_gicv3_icc_igrpen_read(ri
->opc2
& 1 ? 1 : 0,
1735 gicv3_redist_affid(cs
), value
);
1739 static void icc_igrpen_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1742 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1743 int grp
= ri
->opc2
& 1 ? GICV3_G1
: GICV3_G0
;
1745 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1746 icv_igrpen_write(env
, ri
, value
);
1750 trace_gicv3_icc_igrpen_write(ri
->opc2
& 1 ? 1 : 0,
1751 gicv3_redist_affid(cs
), value
);
1753 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1757 cs
->icc_igrpen
[grp
] = value
& ICC_IGRPEN_ENABLE
;
1758 gicv3_cpuif_update(cs
);
1761 static uint64_t icc_igrpen1_el3_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1763 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1766 /* IGRPEN1_EL3 bits 0 and 1 are r/w aliases into IGRPEN1_EL1 NS and S */
1767 value
= cs
->icc_igrpen
[GICV3_G1NS
] | (cs
->icc_igrpen
[GICV3_G1
] << 1);
1768 trace_gicv3_icc_igrpen1_el3_read(gicv3_redist_affid(cs
), value
);
1772 static void icc_igrpen1_el3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1775 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1777 trace_gicv3_icc_igrpen1_el3_write(gicv3_redist_affid(cs
), value
);
1779 /* IGRPEN1_EL3 bits 0 and 1 are r/w aliases into IGRPEN1_EL1 NS and S */
1780 cs
->icc_igrpen
[GICV3_G1NS
] = extract32(value
, 0, 1);
1781 cs
->icc_igrpen
[GICV3_G1
] = extract32(value
, 1, 1);
1782 gicv3_cpuif_update(cs
);
1785 static uint64_t icc_ctlr_el1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1787 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1788 int bank
= gicv3_use_ns_bank(env
) ? GICV3_NS
: GICV3_S
;
1791 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
1792 return icv_ctlr_read(env
, ri
);
1795 value
= cs
->icc_ctlr_el1
[bank
];
1796 trace_gicv3_icc_ctlr_read(gicv3_redist_affid(cs
), value
);
1800 static void icc_ctlr_el1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1803 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1804 int bank
= gicv3_use_ns_bank(env
) ? GICV3_NS
: GICV3_S
;
1807 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
1808 icv_ctlr_write(env
, ri
, value
);
1812 trace_gicv3_icc_ctlr_write(gicv3_redist_affid(cs
), value
);
1814 /* Only CBPR and EOIMODE can be RW;
1815 * for us PMHE is RAZ/WI (we don't implement 1-of-N interrupts or
1816 * the asseciated priority-based routing of them);
1817 * if EL3 is implemented and GICD_CTLR.DS == 0, then PMHE and CBPR are RO.
1819 if (arm_feature(env
, ARM_FEATURE_EL3
) &&
1820 ((cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) == 0)) {
1821 mask
= ICC_CTLR_EL1_EOIMODE
;
1823 mask
= ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
;
1826 cs
->icc_ctlr_el1
[bank
] &= ~mask
;
1827 cs
->icc_ctlr_el1
[bank
] |= (value
& mask
);
1828 gicv3_cpuif_update(cs
);
1832 static uint64_t icc_ctlr_el3_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1834 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1837 value
= cs
->icc_ctlr_el3
;
1838 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
) {
1839 value
|= ICC_CTLR_EL3_EOIMODE_EL1NS
;
1841 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
) {
1842 value
|= ICC_CTLR_EL3_CBPR_EL1NS
;
1844 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
) {
1845 value
|= ICC_CTLR_EL3_EOIMODE_EL1S
;
1847 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
) {
1848 value
|= ICC_CTLR_EL3_CBPR_EL1S
;
1851 trace_gicv3_icc_ctlr_el3_read(gicv3_redist_affid(cs
), value
);
1855 static void icc_ctlr_el3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1858 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1861 trace_gicv3_icc_ctlr_el3_write(gicv3_redist_affid(cs
), value
);
1863 /* *_EL1NS and *_EL1S bits are aliases into the ICC_CTLR_EL1 bits. */
1864 cs
->icc_ctlr_el1
[GICV3_NS
] &= ~(ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
);
1865 if (value
& ICC_CTLR_EL3_EOIMODE_EL1NS
) {
1866 cs
->icc_ctlr_el1
[GICV3_NS
] |= ICC_CTLR_EL1_EOIMODE
;
1868 if (value
& ICC_CTLR_EL3_CBPR_EL1NS
) {
1869 cs
->icc_ctlr_el1
[GICV3_NS
] |= ICC_CTLR_EL1_CBPR
;
1872 cs
->icc_ctlr_el1
[GICV3_S
] &= ~(ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
);
1873 if (value
& ICC_CTLR_EL3_EOIMODE_EL1S
) {
1874 cs
->icc_ctlr_el1
[GICV3_S
] |= ICC_CTLR_EL1_EOIMODE
;
1876 if (value
& ICC_CTLR_EL3_CBPR_EL1S
) {
1877 cs
->icc_ctlr_el1
[GICV3_S
] |= ICC_CTLR_EL1_CBPR
;
1880 /* The only bit stored in icc_ctlr_el3 which is writeable is EOIMODE_EL3: */
1881 mask
= ICC_CTLR_EL3_EOIMODE_EL3
;
1883 cs
->icc_ctlr_el3
&= ~mask
;
1884 cs
->icc_ctlr_el3
|= (value
& mask
);
1885 gicv3_cpuif_update(cs
);
1888 static CPAccessResult
gicv3_irqfiq_access(CPUARMState
*env
,
1889 const ARMCPRegInfo
*ri
, bool isread
)
1891 CPAccessResult r
= CP_ACCESS_OK
;
1892 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1893 int el
= arm_current_el(env
);
1895 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_TC
) &&
1896 el
== 1 && !arm_is_secure_below_el3(env
)) {
1897 /* Takes priority over a possible EL3 trap */
1898 return CP_ACCESS_TRAP_EL2
;
1901 if ((env
->cp15
.scr_el3
& (SCR_FIQ
| SCR_IRQ
)) == (SCR_FIQ
| SCR_IRQ
)) {
1904 /* Note that arm_hcr_el2_eff takes secure state into account. */
1905 if ((arm_hcr_el2_eff(env
) & (HCR_IMO
| HCR_FMO
)) == 0) {
1906 r
= CP_ACCESS_TRAP_EL3
;
1910 r
= CP_ACCESS_TRAP_EL3
;
1913 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
1914 r
= CP_ACCESS_TRAP_EL3
;
1918 g_assert_not_reached();
1922 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
1928 static CPAccessResult
gicv3_dir_access(CPUARMState
*env
,
1929 const ARMCPRegInfo
*ri
, bool isread
)
1931 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1933 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_TDIR
) &&
1934 arm_current_el(env
) == 1 && !arm_is_secure_below_el3(env
)) {
1935 /* Takes priority over a possible EL3 trap */
1936 return CP_ACCESS_TRAP_EL2
;
1939 return gicv3_irqfiq_access(env
, ri
, isread
);
1942 static CPAccessResult
gicv3_sgi_access(CPUARMState
*env
,
1943 const ARMCPRegInfo
*ri
, bool isread
)
1945 if (arm_current_el(env
) == 1 &&
1946 (arm_hcr_el2_eff(env
) & (HCR_IMO
| HCR_FMO
)) != 0) {
1947 /* Takes priority over a possible EL3 trap */
1948 return CP_ACCESS_TRAP_EL2
;
1951 return gicv3_irqfiq_access(env
, ri
, isread
);
1954 static CPAccessResult
gicv3_fiq_access(CPUARMState
*env
,
1955 const ARMCPRegInfo
*ri
, bool isread
)
1957 CPAccessResult r
= CP_ACCESS_OK
;
1958 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1959 int el
= arm_current_el(env
);
1961 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_TALL0
) &&
1962 el
== 1 && !arm_is_secure_below_el3(env
)) {
1963 /* Takes priority over a possible EL3 trap */
1964 return CP_ACCESS_TRAP_EL2
;
1967 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
1970 if ((arm_hcr_el2_eff(env
) & HCR_FMO
) == 0) {
1971 r
= CP_ACCESS_TRAP_EL3
;
1975 r
= CP_ACCESS_TRAP_EL3
;
1978 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
1979 r
= CP_ACCESS_TRAP_EL3
;
1983 g_assert_not_reached();
1987 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
1993 static CPAccessResult
gicv3_irq_access(CPUARMState
*env
,
1994 const ARMCPRegInfo
*ri
, bool isread
)
1996 CPAccessResult r
= CP_ACCESS_OK
;
1997 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1998 int el
= arm_current_el(env
);
2000 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_TALL1
) &&
2001 el
== 1 && !arm_is_secure_below_el3(env
)) {
2002 /* Takes priority over a possible EL3 trap */
2003 return CP_ACCESS_TRAP_EL2
;
2006 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
2009 if ((arm_hcr_el2_eff(env
) & HCR_IMO
) == 0) {
2010 r
= CP_ACCESS_TRAP_EL3
;
2014 r
= CP_ACCESS_TRAP_EL3
;
2017 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
2018 r
= CP_ACCESS_TRAP_EL3
;
2022 g_assert_not_reached();
2026 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
2032 static void icc_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2034 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2036 cs
->icc_ctlr_el1
[GICV3_S
] = ICC_CTLR_EL1_A3V
|
2037 (1 << ICC_CTLR_EL1_IDBITS_SHIFT
) |
2038 (7 << ICC_CTLR_EL1_PRIBITS_SHIFT
);
2039 cs
->icc_ctlr_el1
[GICV3_NS
] = ICC_CTLR_EL1_A3V
|
2040 (1 << ICC_CTLR_EL1_IDBITS_SHIFT
) |
2041 (7 << ICC_CTLR_EL1_PRIBITS_SHIFT
);
2042 cs
->icc_pmr_el1
= 0;
2043 cs
->icc_bpr
[GICV3_G0
] = GIC_MIN_BPR
;
2044 cs
->icc_bpr
[GICV3_G1
] = GIC_MIN_BPR
;
2045 cs
->icc_bpr
[GICV3_G1NS
] = GIC_MIN_BPR_NS
;
2046 memset(cs
->icc_apr
, 0, sizeof(cs
->icc_apr
));
2047 memset(cs
->icc_igrpen
, 0, sizeof(cs
->icc_igrpen
));
2048 cs
->icc_ctlr_el3
= ICC_CTLR_EL3_NDS
| ICC_CTLR_EL3_A3V
|
2049 (1 << ICC_CTLR_EL3_IDBITS_SHIFT
) |
2050 (7 << ICC_CTLR_EL3_PRIBITS_SHIFT
);
2052 memset(cs
->ich_apr
, 0, sizeof(cs
->ich_apr
));
2053 cs
->ich_hcr_el2
= 0;
2054 memset(cs
->ich_lr_el2
, 0, sizeof(cs
->ich_lr_el2
));
2055 cs
->ich_vmcr_el2
= ICH_VMCR_EL2_VFIQEN
|
2056 ((icv_min_vbpr(cs
) + 1) << ICH_VMCR_EL2_VBPR1_SHIFT
) |
2057 (icv_min_vbpr(cs
) << ICH_VMCR_EL2_VBPR0_SHIFT
);
2060 static const ARMCPRegInfo gicv3_cpuif_reginfo
[] = {
2061 { .name
= "ICC_PMR_EL1", .state
= ARM_CP_STATE_BOTH
,
2062 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 6, .opc2
= 0,
2063 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2064 .access
= PL1_RW
, .accessfn
= gicv3_irqfiq_access
,
2065 .readfn
= icc_pmr_read
,
2066 .writefn
= icc_pmr_write
,
2067 /* We hang the whole cpu interface reset routine off here
2068 * rather than parcelling it out into one little function
2071 .resetfn
= icc_reset
,
2073 { .name
= "ICC_IAR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2074 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 0,
2075 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2076 .access
= PL1_R
, .accessfn
= gicv3_fiq_access
,
2077 .readfn
= icc_iar0_read
,
2079 { .name
= "ICC_EOIR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2080 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 1,
2081 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2082 .access
= PL1_W
, .accessfn
= gicv3_fiq_access
,
2083 .writefn
= icc_eoir_write
,
2085 { .name
= "ICC_HPPIR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2086 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 2,
2087 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2088 .access
= PL1_R
, .accessfn
= gicv3_fiq_access
,
2089 .readfn
= icc_hppir0_read
,
2091 { .name
= "ICC_BPR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2092 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 3,
2093 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2094 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2095 .readfn
= icc_bpr_read
,
2096 .writefn
= icc_bpr_write
,
2098 { .name
= "ICC_AP0R0_EL1", .state
= ARM_CP_STATE_BOTH
,
2099 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 4,
2100 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2101 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2102 .readfn
= icc_ap_read
,
2103 .writefn
= icc_ap_write
,
2105 { .name
= "ICC_AP0R1_EL1", .state
= ARM_CP_STATE_BOTH
,
2106 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 5,
2107 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2108 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2109 .readfn
= icc_ap_read
,
2110 .writefn
= icc_ap_write
,
2112 { .name
= "ICC_AP0R2_EL1", .state
= ARM_CP_STATE_BOTH
,
2113 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 6,
2114 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2115 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2116 .readfn
= icc_ap_read
,
2117 .writefn
= icc_ap_write
,
2119 { .name
= "ICC_AP0R3_EL1", .state
= ARM_CP_STATE_BOTH
,
2120 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 7,
2121 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2122 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2123 .readfn
= icc_ap_read
,
2124 .writefn
= icc_ap_write
,
2126 /* All the ICC_AP1R*_EL1 registers are banked */
2127 { .name
= "ICC_AP1R0_EL1", .state
= ARM_CP_STATE_BOTH
,
2128 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 0,
2129 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2130 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2131 .readfn
= icc_ap_read
,
2132 .writefn
= icc_ap_write
,
2134 { .name
= "ICC_AP1R1_EL1", .state
= ARM_CP_STATE_BOTH
,
2135 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 1,
2136 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2137 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2138 .readfn
= icc_ap_read
,
2139 .writefn
= icc_ap_write
,
2141 { .name
= "ICC_AP1R2_EL1", .state
= ARM_CP_STATE_BOTH
,
2142 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 2,
2143 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2144 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2145 .readfn
= icc_ap_read
,
2146 .writefn
= icc_ap_write
,
2148 { .name
= "ICC_AP1R3_EL1", .state
= ARM_CP_STATE_BOTH
,
2149 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 3,
2150 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2151 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2152 .readfn
= icc_ap_read
,
2153 .writefn
= icc_ap_write
,
2155 { .name
= "ICC_DIR_EL1", .state
= ARM_CP_STATE_BOTH
,
2156 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 1,
2157 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2158 .access
= PL1_W
, .accessfn
= gicv3_dir_access
,
2159 .writefn
= icc_dir_write
,
2161 { .name
= "ICC_RPR_EL1", .state
= ARM_CP_STATE_BOTH
,
2162 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 3,
2163 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2164 .access
= PL1_R
, .accessfn
= gicv3_irqfiq_access
,
2165 .readfn
= icc_rpr_read
,
2167 { .name
= "ICC_SGI1R_EL1", .state
= ARM_CP_STATE_AA64
,
2168 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 5,
2169 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2170 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2171 .writefn
= icc_sgi1r_write
,
2173 { .name
= "ICC_SGI1R",
2174 .cp
= 15, .opc1
= 0, .crm
= 12,
2175 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2176 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2177 .writefn
= icc_sgi1r_write
,
2179 { .name
= "ICC_ASGI1R_EL1", .state
= ARM_CP_STATE_AA64
,
2180 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 6,
2181 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2182 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2183 .writefn
= icc_asgi1r_write
,
2185 { .name
= "ICC_ASGI1R",
2186 .cp
= 15, .opc1
= 1, .crm
= 12,
2187 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2188 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2189 .writefn
= icc_asgi1r_write
,
2191 { .name
= "ICC_SGI0R_EL1", .state
= ARM_CP_STATE_AA64
,
2192 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 7,
2193 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2194 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2195 .writefn
= icc_sgi0r_write
,
2197 { .name
= "ICC_SGI0R",
2198 .cp
= 15, .opc1
= 2, .crm
= 12,
2199 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2200 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2201 .writefn
= icc_sgi0r_write
,
2203 { .name
= "ICC_IAR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2204 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 0,
2205 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2206 .access
= PL1_R
, .accessfn
= gicv3_irq_access
,
2207 .readfn
= icc_iar1_read
,
2209 { .name
= "ICC_EOIR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2210 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 1,
2211 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2212 .access
= PL1_W
, .accessfn
= gicv3_irq_access
,
2213 .writefn
= icc_eoir_write
,
2215 { .name
= "ICC_HPPIR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2216 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 2,
2217 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2218 .access
= PL1_R
, .accessfn
= gicv3_irq_access
,
2219 .readfn
= icc_hppir1_read
,
2221 /* This register is banked */
2222 { .name
= "ICC_BPR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2223 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 3,
2224 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2225 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2226 .readfn
= icc_bpr_read
,
2227 .writefn
= icc_bpr_write
,
2229 /* This register is banked */
2230 { .name
= "ICC_CTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
2231 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 4,
2232 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2233 .access
= PL1_RW
, .accessfn
= gicv3_irqfiq_access
,
2234 .readfn
= icc_ctlr_el1_read
,
2235 .writefn
= icc_ctlr_el1_write
,
2237 { .name
= "ICC_SRE_EL1", .state
= ARM_CP_STATE_BOTH
,
2238 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 5,
2239 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
2241 /* We don't support IRQ/FIQ bypass and system registers are
2242 * always enabled, so all our bits are RAZ/WI or RAO/WI.
2243 * This register is banked but since it's constant we don't
2244 * need to do anything special.
2248 { .name
= "ICC_IGRPEN0_EL1", .state
= ARM_CP_STATE_BOTH
,
2249 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 6,
2250 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2251 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2252 .readfn
= icc_igrpen_read
,
2253 .writefn
= icc_igrpen_write
,
2255 /* This register is banked */
2256 { .name
= "ICC_IGRPEN1_EL1", .state
= ARM_CP_STATE_BOTH
,
2257 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 7,
2258 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2259 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2260 .readfn
= icc_igrpen_read
,
2261 .writefn
= icc_igrpen_write
,
2263 { .name
= "ICC_SRE_EL2", .state
= ARM_CP_STATE_BOTH
,
2264 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 5,
2265 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
2267 /* We don't support IRQ/FIQ bypass and system registers are
2268 * always enabled, so all our bits are RAZ/WI or RAO/WI.
2272 { .name
= "ICC_CTLR_EL3", .state
= ARM_CP_STATE_BOTH
,
2273 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 4,
2274 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2276 .readfn
= icc_ctlr_el3_read
,
2277 .writefn
= icc_ctlr_el3_write
,
2279 { .name
= "ICC_SRE_EL3", .state
= ARM_CP_STATE_BOTH
,
2280 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 5,
2281 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
2283 /* We don't support IRQ/FIQ bypass and system registers are
2284 * always enabled, so all our bits are RAZ/WI or RAO/WI.
2288 { .name
= "ICC_IGRPEN1_EL3", .state
= ARM_CP_STATE_BOTH
,
2289 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 7,
2290 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2292 .readfn
= icc_igrpen1_el3_read
,
2293 .writefn
= icc_igrpen1_el3_write
,
2298 static uint64_t ich_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2300 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2301 int regno
= ri
->opc2
& 3;
2302 int grp
= (ri
->crm
& 1) ? GICV3_G1NS
: GICV3_G0
;
2305 value
= cs
->ich_apr
[grp
][regno
];
2306 trace_gicv3_ich_ap_read(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
2310 static void ich_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2313 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2314 int regno
= ri
->opc2
& 3;
2315 int grp
= (ri
->crm
& 1) ? GICV3_G1NS
: GICV3_G0
;
2317 trace_gicv3_ich_ap_write(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
2319 cs
->ich_apr
[grp
][regno
] = value
& 0xFFFFFFFFU
;
2320 gicv3_cpuif_virt_update(cs
);
2323 static uint64_t ich_hcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2325 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2326 uint64_t value
= cs
->ich_hcr_el2
;
2328 trace_gicv3_ich_hcr_read(gicv3_redist_affid(cs
), value
);
2332 static void ich_hcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2335 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2337 trace_gicv3_ich_hcr_write(gicv3_redist_affid(cs
), value
);
2339 value
&= ICH_HCR_EL2_EN
| ICH_HCR_EL2_UIE
| ICH_HCR_EL2_LRENPIE
|
2340 ICH_HCR_EL2_NPIE
| ICH_HCR_EL2_VGRP0EIE
| ICH_HCR_EL2_VGRP0DIE
|
2341 ICH_HCR_EL2_VGRP1EIE
| ICH_HCR_EL2_VGRP1DIE
| ICH_HCR_EL2_TC
|
2342 ICH_HCR_EL2_TALL0
| ICH_HCR_EL2_TALL1
| ICH_HCR_EL2_TSEI
|
2343 ICH_HCR_EL2_TDIR
| ICH_HCR_EL2_EOICOUNT_MASK
;
2345 cs
->ich_hcr_el2
= value
;
2346 gicv3_cpuif_virt_update(cs
);
2349 static uint64_t ich_vmcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2351 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2352 uint64_t value
= cs
->ich_vmcr_el2
;
2354 trace_gicv3_ich_vmcr_read(gicv3_redist_affid(cs
), value
);
2358 static void ich_vmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2361 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2363 trace_gicv3_ich_vmcr_write(gicv3_redist_affid(cs
), value
);
2365 value
&= ICH_VMCR_EL2_VENG0
| ICH_VMCR_EL2_VENG1
| ICH_VMCR_EL2_VCBPR
|
2366 ICH_VMCR_EL2_VEOIM
| ICH_VMCR_EL2_VBPR1_MASK
|
2367 ICH_VMCR_EL2_VBPR0_MASK
| ICH_VMCR_EL2_VPMR_MASK
;
2368 value
|= ICH_VMCR_EL2_VFIQEN
;
2370 cs
->ich_vmcr_el2
= value
;
2371 /* Enforce "writing BPRs to less than minimum sets them to the minimum"
2372 * by reading and writing back the fields.
2374 write_vbpr(cs
, GICV3_G0
, read_vbpr(cs
, GICV3_G0
));
2375 write_vbpr(cs
, GICV3_G1
, read_vbpr(cs
, GICV3_G1
));
2377 gicv3_cpuif_virt_update(cs
);
2380 static uint64_t ich_lr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2382 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2383 int regno
= ri
->opc2
| ((ri
->crm
& 1) << 3);
2386 /* This read function handles all of:
2387 * 64-bit reads of the whole LR
2388 * 32-bit reads of the low half of the LR
2389 * 32-bit reads of the high half of the LR
2391 if (ri
->state
== ARM_CP_STATE_AA32
) {
2392 if (ri
->crm
>= 14) {
2393 value
= extract64(cs
->ich_lr_el2
[regno
], 32, 32);
2394 trace_gicv3_ich_lrc_read(regno
, gicv3_redist_affid(cs
), value
);
2396 value
= extract64(cs
->ich_lr_el2
[regno
], 0, 32);
2397 trace_gicv3_ich_lr32_read(regno
, gicv3_redist_affid(cs
), value
);
2400 value
= cs
->ich_lr_el2
[regno
];
2401 trace_gicv3_ich_lr_read(regno
, gicv3_redist_affid(cs
), value
);
2407 static void ich_lr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2410 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2411 int regno
= ri
->opc2
| ((ri
->crm
& 1) << 3);
2413 /* This write function handles all of:
2414 * 64-bit writes to the whole LR
2415 * 32-bit writes to the low half of the LR
2416 * 32-bit writes to the high half of the LR
2418 if (ri
->state
== ARM_CP_STATE_AA32
) {
2419 if (ri
->crm
>= 14) {
2420 trace_gicv3_ich_lrc_write(regno
, gicv3_redist_affid(cs
), value
);
2421 value
= deposit64(cs
->ich_lr_el2
[regno
], 32, 32, value
);
2423 trace_gicv3_ich_lr32_write(regno
, gicv3_redist_affid(cs
), value
);
2424 value
= deposit64(cs
->ich_lr_el2
[regno
], 0, 32, value
);
2427 trace_gicv3_ich_lr_write(regno
, gicv3_redist_affid(cs
), value
);
2430 /* Enforce RES0 bits in priority field */
2431 if (cs
->vpribits
< 8) {
2432 value
= deposit64(value
, ICH_LR_EL2_PRIORITY_SHIFT
,
2433 8 - cs
->vpribits
, 0);
2436 cs
->ich_lr_el2
[regno
] = value
;
2437 gicv3_cpuif_virt_update(cs
);
2440 static uint64_t ich_vtr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2442 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2445 value
= ((cs
->num_list_regs
- 1) << ICH_VTR_EL2_LISTREGS_SHIFT
)
2446 | ICH_VTR_EL2_TDS
| ICH_VTR_EL2_NV4
| ICH_VTR_EL2_A3V
2447 | (1 << ICH_VTR_EL2_IDBITS_SHIFT
)
2448 | ((cs
->vprebits
- 1) << ICH_VTR_EL2_PREBITS_SHIFT
)
2449 | ((cs
->vpribits
- 1) << ICH_VTR_EL2_PRIBITS_SHIFT
);
2451 trace_gicv3_ich_vtr_read(gicv3_redist_affid(cs
), value
);
2455 static uint64_t ich_misr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2457 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2458 uint64_t value
= maintenance_interrupt_state(cs
);
2460 trace_gicv3_ich_misr_read(gicv3_redist_affid(cs
), value
);
2464 static uint64_t ich_eisr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2466 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2467 uint64_t value
= eoi_maintenance_interrupt_state(cs
, NULL
);
2469 trace_gicv3_ich_eisr_read(gicv3_redist_affid(cs
), value
);
2473 static uint64_t ich_elrsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2475 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2479 for (i
= 0; i
< cs
->num_list_regs
; i
++) {
2480 uint64_t lr
= cs
->ich_lr_el2
[i
];
2482 if ((lr
& ICH_LR_EL2_STATE_MASK
) == 0 &&
2483 ((lr
& ICH_LR_EL2_HW
) != 0 || (lr
& ICH_LR_EL2_EOI
) == 0)) {
2488 trace_gicv3_ich_elrsr_read(gicv3_redist_affid(cs
), value
);
2492 static const ARMCPRegInfo gicv3_cpuif_hcr_reginfo
[] = {
2493 { .name
= "ICH_AP0R0_EL2", .state
= ARM_CP_STATE_BOTH
,
2494 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 8, .opc2
= 0,
2495 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2497 .readfn
= ich_ap_read
,
2498 .writefn
= ich_ap_write
,
2500 { .name
= "ICH_AP1R0_EL2", .state
= ARM_CP_STATE_BOTH
,
2501 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 0,
2502 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2504 .readfn
= ich_ap_read
,
2505 .writefn
= ich_ap_write
,
2507 { .name
= "ICH_HCR_EL2", .state
= ARM_CP_STATE_BOTH
,
2508 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 0,
2509 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2511 .readfn
= ich_hcr_read
,
2512 .writefn
= ich_hcr_write
,
2514 { .name
= "ICH_VTR_EL2", .state
= ARM_CP_STATE_BOTH
,
2515 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 1,
2516 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2518 .readfn
= ich_vtr_read
,
2520 { .name
= "ICH_MISR_EL2", .state
= ARM_CP_STATE_BOTH
,
2521 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 2,
2522 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2524 .readfn
= ich_misr_read
,
2526 { .name
= "ICH_EISR_EL2", .state
= ARM_CP_STATE_BOTH
,
2527 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 3,
2528 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2530 .readfn
= ich_eisr_read
,
2532 { .name
= "ICH_ELRSR_EL2", .state
= ARM_CP_STATE_BOTH
,
2533 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 5,
2534 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2536 .readfn
= ich_elrsr_read
,
2538 { .name
= "ICH_VMCR_EL2", .state
= ARM_CP_STATE_BOTH
,
2539 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 7,
2540 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2542 .readfn
= ich_vmcr_read
,
2543 .writefn
= ich_vmcr_write
,
2548 static const ARMCPRegInfo gicv3_cpuif_ich_apxr1_reginfo
[] = {
2549 { .name
= "ICH_AP0R1_EL2", .state
= ARM_CP_STATE_BOTH
,
2550 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 8, .opc2
= 1,
2551 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2553 .readfn
= ich_ap_read
,
2554 .writefn
= ich_ap_write
,
2556 { .name
= "ICH_AP1R1_EL2", .state
= ARM_CP_STATE_BOTH
,
2557 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 1,
2558 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2560 .readfn
= ich_ap_read
,
2561 .writefn
= ich_ap_write
,
2566 static const ARMCPRegInfo gicv3_cpuif_ich_apxr23_reginfo
[] = {
2567 { .name
= "ICH_AP0R2_EL2", .state
= ARM_CP_STATE_BOTH
,
2568 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 8, .opc2
= 2,
2569 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2571 .readfn
= ich_ap_read
,
2572 .writefn
= ich_ap_write
,
2574 { .name
= "ICH_AP0R3_EL2", .state
= ARM_CP_STATE_BOTH
,
2575 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 8, .opc2
= 3,
2576 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2578 .readfn
= ich_ap_read
,
2579 .writefn
= ich_ap_write
,
2581 { .name
= "ICH_AP1R2_EL2", .state
= ARM_CP_STATE_BOTH
,
2582 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 2,
2583 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2585 .readfn
= ich_ap_read
,
2586 .writefn
= ich_ap_write
,
2588 { .name
= "ICH_AP1R3_EL2", .state
= ARM_CP_STATE_BOTH
,
2589 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 3,
2590 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2592 .readfn
= ich_ap_read
,
2593 .writefn
= ich_ap_write
,
2598 static void gicv3_cpuif_el_change_hook(ARMCPU
*cpu
, void *opaque
)
2600 GICv3CPUState
*cs
= opaque
;
2602 gicv3_cpuif_update(cs
);
2605 void gicv3_init_cpuif(GICv3State
*s
)
2607 /* Called from the GICv3 realize function; register our system
2608 * registers with the CPU
2612 for (i
= 0; i
< s
->num_cpu
; i
++) {
2613 ARMCPU
*cpu
= ARM_CPU(qemu_get_cpu(i
));
2614 GICv3CPUState
*cs
= &s
->cpu
[i
];
2616 /* Note that we can't just use the GICv3CPUState as an opaque pointer
2617 * in define_arm_cp_regs_with_opaque(), because when we're called back
2618 * it might be with code translated by CPU 0 but run by CPU 1, in
2619 * which case we'd get the wrong value.
2620 * So instead we define the regs with no ri->opaque info, and
2621 * get back to the GICv3CPUState from the CPUARMState.
2623 define_arm_cp_regs(cpu
, gicv3_cpuif_reginfo
);
2624 if (arm_feature(&cpu
->env
, ARM_FEATURE_EL2
)
2625 && cpu
->gic_num_lrs
) {
2628 cs
->num_list_regs
= cpu
->gic_num_lrs
;
2629 cs
->vpribits
= cpu
->gic_vpribits
;
2630 cs
->vprebits
= cpu
->gic_vprebits
;
2632 /* Check against architectural constraints: getting these
2633 * wrong would be a bug in the CPU code defining these,
2634 * and the implementation relies on them holding.
2636 g_assert(cs
->vprebits
<= cs
->vpribits
);
2637 g_assert(cs
->vprebits
>= 5 && cs
->vprebits
<= 7);
2638 g_assert(cs
->vpribits
>= 5 && cs
->vpribits
<= 8);
2640 define_arm_cp_regs(cpu
, gicv3_cpuif_hcr_reginfo
);
2642 for (j
= 0; j
< cs
->num_list_regs
; j
++) {
2643 /* Note that the AArch64 LRs are 64-bit; the AArch32 LRs
2644 * are split into two cp15 regs, LR (the low part, with the
2645 * same encoding as the AArch64 LR) and LRC (the high part).
2647 ARMCPRegInfo lr_regset
[] = {
2648 { .name
= "ICH_LRn_EL2", .state
= ARM_CP_STATE_BOTH
,
2649 .opc0
= 3, .opc1
= 4, .crn
= 12,
2650 .crm
= 12 + (j
>> 3), .opc2
= j
& 7,
2651 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2653 .readfn
= ich_lr_read
,
2654 .writefn
= ich_lr_write
,
2656 { .name
= "ICH_LRCn_EL2", .state
= ARM_CP_STATE_AA32
,
2657 .cp
= 15, .opc1
= 4, .crn
= 12,
2658 .crm
= 14 + (j
>> 3), .opc2
= j
& 7,
2659 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2661 .readfn
= ich_lr_read
,
2662 .writefn
= ich_lr_write
,
2666 define_arm_cp_regs(cpu
, lr_regset
);
2668 if (cs
->vprebits
>= 6) {
2669 define_arm_cp_regs(cpu
, gicv3_cpuif_ich_apxr1_reginfo
);
2671 if (cs
->vprebits
== 7) {
2672 define_arm_cp_regs(cpu
, gicv3_cpuif_ich_apxr23_reginfo
);
2675 arm_register_el_change_hook(cpu
, gicv3_cpuif_el_change_hook
, cs
);