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"
22 void gicv3_set_gicv3state(CPUState
*cpu
, GICv3CPUState
*s
)
24 ARMCPU
*arm_cpu
= ARM_CPU(cpu
);
25 CPUARMState
*env
= &arm_cpu
->env
;
27 env
->gicv3state
= (void *)s
;
30 static GICv3CPUState
*icc_cs_from_env(CPUARMState
*env
)
32 return env
->gicv3state
;
35 static bool gicv3_use_ns_bank(CPUARMState
*env
)
37 /* Return true if we should use the NonSecure bank for a banked GIC
38 * CPU interface register. Note that this differs from the
39 * access_secure_reg() function because GICv3 banked registers are
40 * banked even for AArch64, unlike the other CPU system registers.
42 return !arm_is_secure_below_el3(env
);
45 /* The minimum BPR for the virtual interface is a configurable property */
46 static inline int icv_min_vbpr(GICv3CPUState
*cs
)
48 return 7 - cs
->vprebits
;
51 /* Simple accessor functions for LR fields */
52 static uint32_t ich_lr_vintid(uint64_t lr
)
54 return extract64(lr
, ICH_LR_EL2_VINTID_SHIFT
, ICH_LR_EL2_VINTID_LENGTH
);
57 static uint32_t ich_lr_pintid(uint64_t lr
)
59 return extract64(lr
, ICH_LR_EL2_PINTID_SHIFT
, ICH_LR_EL2_PINTID_LENGTH
);
62 static uint32_t ich_lr_prio(uint64_t lr
)
64 return extract64(lr
, ICH_LR_EL2_PRIORITY_SHIFT
, ICH_LR_EL2_PRIORITY_LENGTH
);
67 static int ich_lr_state(uint64_t lr
)
69 return extract64(lr
, ICH_LR_EL2_STATE_SHIFT
, ICH_LR_EL2_STATE_LENGTH
);
72 static bool icv_access(CPUARMState
*env
, int hcr_flags
)
74 /* Return true if this ICC_ register access should really be
75 * directed to an ICV_ access. hcr_flags is a mask of
76 * HCR_EL2 bits to check: we treat this as an ICV_ access
77 * if we are in NS EL1 and at least one of the specified
78 * HCR_EL2 bits is set.
80 * ICV registers fall into four categories:
81 * * access if NS EL1 and HCR_EL2.FMO == 1:
82 * all ICV regs with '0' in their name
83 * * access if NS EL1 and HCR_EL2.IMO == 1:
84 * all ICV regs with '1' in their name
85 * * access if NS EL1 and either IMO or FMO == 1:
88 return (env
->cp15
.hcr_el2
& hcr_flags
) && arm_current_el(env
) == 1
89 && !arm_is_secure_below_el3(env
);
92 static int read_vbpr(GICv3CPUState
*cs
, int grp
)
94 /* Read VBPR value out of the VMCR field (caller must handle
95 * VCBPR effects if required)
97 if (grp
== GICV3_G0
) {
98 return extract64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VBPR0_SHIFT
,
99 ICH_VMCR_EL2_VBPR0_LENGTH
);
101 return extract64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VBPR1_SHIFT
,
102 ICH_VMCR_EL2_VBPR1_LENGTH
);
106 static void write_vbpr(GICv3CPUState
*cs
, int grp
, int value
)
108 /* Write new VBPR1 value, handling the "writing a value less than
109 * the minimum sets it to the minimum" semantics.
111 int min
= icv_min_vbpr(cs
);
113 if (grp
!= GICV3_G0
) {
117 value
= MAX(value
, min
);
119 if (grp
== GICV3_G0
) {
120 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VBPR0_SHIFT
,
121 ICH_VMCR_EL2_VBPR0_LENGTH
, value
);
123 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VBPR1_SHIFT
,
124 ICH_VMCR_EL2_VBPR1_LENGTH
, value
);
128 static uint32_t icv_fullprio_mask(GICv3CPUState
*cs
)
130 /* Return a mask word which clears the unimplemented priority bits
131 * from a priority value for a virtual interrupt. (Not to be confused
132 * with the group priority, whose mask depends on the value of VBPR
133 * for the interrupt group.)
135 return ~0U << (8 - cs
->vpribits
);
138 static int ich_highest_active_virt_prio(GICv3CPUState
*cs
)
140 /* Calculate the current running priority based on the set bits
141 * in the ICH Active Priority Registers.
144 int aprmax
= 1 << (cs
->vprebits
- 5);
146 assert(aprmax
<= ARRAY_SIZE(cs
->ich_apr
[0]));
148 for (i
= 0; i
< aprmax
; i
++) {
149 uint32_t apr
= cs
->ich_apr
[GICV3_G0
][i
] |
150 cs
->ich_apr
[GICV3_G1NS
][i
];
155 return (i
* 32 + ctz32(apr
)) << (icv_min_vbpr(cs
) + 1);
157 /* No current active interrupts: return idle priority */
161 static int hppvi_index(GICv3CPUState
*cs
)
163 /* Return the list register index of the highest priority pending
164 * virtual interrupt, as per the HighestPriorityVirtualInterrupt
165 * pseudocode. If no pending virtual interrupts, return -1.
169 /* Note that a list register entry with a priority of 0xff will
170 * never be reported by this function; this is the architecturally
175 if (!(cs
->ich_vmcr_el2
& (ICH_VMCR_EL2_VENG0
| ICH_VMCR_EL2_VENG1
))) {
176 /* Both groups disabled, definitely nothing to do */
180 for (i
= 0; i
< cs
->num_list_regs
; i
++) {
181 uint64_t lr
= cs
->ich_lr_el2
[i
];
184 if (ich_lr_state(lr
) != ICH_LR_EL2_STATE_PENDING
) {
189 /* Ignore interrupts if relevant group enable not set */
190 if (lr
& ICH_LR_EL2_GROUP
) {
191 if (!(cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG1
)) {
195 if (!(cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG0
)) {
200 thisprio
= ich_lr_prio(lr
);
202 if (thisprio
< prio
) {
211 static uint32_t icv_gprio_mask(GICv3CPUState
*cs
, int group
)
213 /* Return a mask word which clears the subpriority bits from
214 * a priority value for a virtual interrupt in the specified group.
215 * This depends on the VBPR value.
216 * If using VBPR0 then:
217 * a BPR of 0 means the group priority bits are [7:1];
218 * a BPR of 1 means they are [7:2], and so on down to
219 * a BPR of 7 meaning no group priority bits at all.
220 * If using VBPR1 then:
221 * a BPR of 0 is impossible (the minimum value is 1)
222 * a BPR of 1 means the group priority bits are [7:1];
223 * a BPR of 2 means they are [7:2], and so on down to
224 * a BPR of 7 meaning the group priority is [7].
226 * Which BPR to use depends on the group of the interrupt and
227 * the current ICH_VMCR_EL2.VCBPR settings.
229 * This corresponds to the VGroupBits() pseudocode.
233 if (group
== GICV3_G1NS
&& cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VCBPR
) {
237 bpr
= read_vbpr(cs
, group
);
238 if (group
== GICV3_G1NS
) {
243 return ~0U << (bpr
+ 1);
246 static bool icv_hppi_can_preempt(GICv3CPUState
*cs
, uint64_t lr
)
248 /* Return true if we can signal this virtual interrupt defined by
249 * the given list register value; see the pseudocode functions
250 * CanSignalVirtualInterrupt and CanSignalVirtualInt.
251 * Compare also icc_hppi_can_preempt() which is the non-virtual
252 * equivalent of these checks.
255 uint32_t mask
, prio
, rprio
, vpmr
;
257 if (!(cs
->ich_hcr_el2
& ICH_HCR_EL2_EN
)) {
258 /* Virtual interface disabled */
262 /* We don't need to check that this LR is in Pending state because
263 * that has already been done in hppvi_index().
266 prio
= ich_lr_prio(lr
);
267 vpmr
= extract64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VPMR_SHIFT
,
268 ICH_VMCR_EL2_VPMR_LENGTH
);
271 /* Priority mask masks this interrupt */
275 rprio
= ich_highest_active_virt_prio(cs
);
277 /* No running interrupt so we can preempt */
281 grp
= (lr
& ICH_LR_EL2_GROUP
) ? GICV3_G1NS
: GICV3_G0
;
283 mask
= icv_gprio_mask(cs
, grp
);
285 /* We only preempt a running interrupt if the pending interrupt's
286 * group priority is sufficient (the subpriorities are not considered).
288 if ((prio
& mask
) < (rprio
& mask
)) {
295 static uint32_t eoi_maintenance_interrupt_state(GICv3CPUState
*cs
,
298 /* Return a set of bits indicating the EOI maintenance interrupt status
299 * for each list register. The EOI maintenance interrupt status is
300 * 1 if LR.State == 0 && LR.HW == 0 && LR.EOI == 1
301 * (see the GICv3 spec for the ICH_EISR_EL2 register).
302 * If misr is not NULL then we should also collect the information
303 * about the MISR.EOI, MISR.NP and MISR.U bits.
307 bool seenpending
= false;
310 for (i
= 0; i
< cs
->num_list_regs
; i
++) {
311 uint64_t lr
= cs
->ich_lr_el2
[i
];
313 if ((lr
& (ICH_LR_EL2_STATE_MASK
| ICH_LR_EL2_HW
| ICH_LR_EL2_EOI
))
317 if ((lr
& ICH_LR_EL2_STATE_MASK
)) {
320 if (ich_lr_state(lr
) == ICH_LR_EL2_STATE_PENDING
) {
326 if (validcount
< 2 && (cs
->ich_hcr_el2
& ICH_HCR_EL2_UIE
)) {
327 *misr
|= ICH_MISR_EL2_U
;
329 if (!seenpending
&& (cs
->ich_hcr_el2
& ICH_HCR_EL2_NPIE
)) {
330 *misr
|= ICH_MISR_EL2_NP
;
333 *misr
|= ICH_MISR_EL2_EOI
;
339 static uint32_t maintenance_interrupt_state(GICv3CPUState
*cs
)
341 /* Return a set of bits indicating the maintenance interrupt status
342 * (as seen in the ICH_MISR_EL2 register).
346 /* Scan list registers and fill in the U, NP and EOI bits */
347 eoi_maintenance_interrupt_state(cs
, &value
);
349 if (cs
->ich_hcr_el2
& (ICH_HCR_EL2_LRENPIE
| ICH_HCR_EL2_EOICOUNT_MASK
)) {
350 value
|= ICH_MISR_EL2_LRENP
;
353 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_VGRP0EIE
) &&
354 (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG0
)) {
355 value
|= ICH_MISR_EL2_VGRP0E
;
358 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_VGRP0DIE
) &&
359 !(cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG1
)) {
360 value
|= ICH_MISR_EL2_VGRP0D
;
362 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_VGRP1EIE
) &&
363 (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG1
)) {
364 value
|= ICH_MISR_EL2_VGRP1E
;
367 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_VGRP1DIE
) &&
368 !(cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VENG1
)) {
369 value
|= ICH_MISR_EL2_VGRP1D
;
375 static void gicv3_cpuif_virt_update(GICv3CPUState
*cs
)
377 /* Tell the CPU about any pending virtual interrupts or
378 * maintenance interrupts, following a change to the state
379 * of the CPU interface relevant to virtual interrupts.
381 * CAUTION: this function will call qemu_set_irq() on the
382 * CPU maintenance IRQ line, which is typically wired up
383 * to the GIC as a per-CPU interrupt. This means that it
384 * will recursively call back into the GIC code via
385 * gicv3_redist_set_irq() and thus into the CPU interface code's
386 * gicv3_cpuif_update(). It is therefore important that this
387 * function is only called as the final action of a CPU interface
388 * register write implementation, after all the GIC state
389 * fields have been updated. gicv3_cpuif_update() also must
390 * not cause this function to be called, but that happens
391 * naturally as a result of there being no architectural
392 * linkage between the physical and virtual GIC logic.
399 idx
= hppvi_index(cs
);
400 trace_gicv3_cpuif_virt_update(gicv3_redist_affid(cs
), idx
);
402 uint64_t lr
= cs
->ich_lr_el2
[idx
];
404 if (icv_hppi_can_preempt(cs
, lr
)) {
405 /* Virtual interrupts are simple: G0 are always FIQ, and G1 IRQ */
406 if (lr
& ICH_LR_EL2_GROUP
) {
414 if (cs
->ich_hcr_el2
& ICH_HCR_EL2_EN
) {
415 maintlevel
= maintenance_interrupt_state(cs
);
418 trace_gicv3_cpuif_virt_set_irqs(gicv3_redist_affid(cs
), fiqlevel
,
419 irqlevel
, maintlevel
);
421 qemu_set_irq(cs
->parent_vfiq
, fiqlevel
);
422 qemu_set_irq(cs
->parent_virq
, irqlevel
);
423 qemu_set_irq(cs
->maintenance_irq
, maintlevel
);
426 static uint64_t icv_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
428 GICv3CPUState
*cs
= icc_cs_from_env(env
);
429 int regno
= ri
->opc2
& 3;
430 int grp
= ri
->crm
& 1 ? GICV3_G0
: GICV3_G1NS
;
431 uint64_t value
= cs
->ich_apr
[grp
][regno
];
433 trace_gicv3_icv_ap_read(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
437 static void icv_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
440 GICv3CPUState
*cs
= icc_cs_from_env(env
);
441 int regno
= ri
->opc2
& 3;
442 int grp
= ri
->crm
& 1 ? GICV3_G0
: GICV3_G1NS
;
444 trace_gicv3_icv_ap_write(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
446 cs
->ich_apr
[grp
][regno
] = value
& 0xFFFFFFFFU
;
448 gicv3_cpuif_virt_update(cs
);
452 static uint64_t icv_bpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
454 GICv3CPUState
*cs
= icc_cs_from_env(env
);
455 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1NS
;
459 if (grp
== GICV3_G1NS
&& (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VCBPR
)) {
460 /* reads return bpr0 + 1 saturated to 7, writes ignored */
465 bpr
= read_vbpr(cs
, grp
);
472 trace_gicv3_icv_bpr_read(ri
->crm
== 8 ? 0 : 1, gicv3_redist_affid(cs
), bpr
);
477 static void icv_bpr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
480 GICv3CPUState
*cs
= icc_cs_from_env(env
);
481 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1NS
;
483 trace_gicv3_icv_bpr_write(ri
->crm
== 8 ? 0 : 1,
484 gicv3_redist_affid(cs
), value
);
486 if (grp
== GICV3_G1NS
&& (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VCBPR
)) {
487 /* reads return bpr0 + 1 saturated to 7, writes ignored */
491 write_vbpr(cs
, grp
, value
);
493 gicv3_cpuif_virt_update(cs
);
496 static uint64_t icv_pmr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
498 GICv3CPUState
*cs
= icc_cs_from_env(env
);
501 value
= extract64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VPMR_SHIFT
,
502 ICH_VMCR_EL2_VPMR_LENGTH
);
504 trace_gicv3_icv_pmr_read(gicv3_redist_affid(cs
), value
);
508 static void icv_pmr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
511 GICv3CPUState
*cs
= icc_cs_from_env(env
);
513 trace_gicv3_icv_pmr_write(gicv3_redist_affid(cs
), value
);
515 value
&= icv_fullprio_mask(cs
);
517 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VPMR_SHIFT
,
518 ICH_VMCR_EL2_VPMR_LENGTH
, value
);
520 gicv3_cpuif_virt_update(cs
);
523 static uint64_t icv_igrpen_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
525 GICv3CPUState
*cs
= icc_cs_from_env(env
);
529 enbit
= ri
->opc2
& 1 ? ICH_VMCR_EL2_VENG1_SHIFT
: ICH_VMCR_EL2_VENG0_SHIFT
;
530 value
= extract64(cs
->ich_vmcr_el2
, enbit
, 1);
532 trace_gicv3_icv_igrpen_read(ri
->opc2
& 1 ? 1 : 0,
533 gicv3_redist_affid(cs
), value
);
537 static void icv_igrpen_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
540 GICv3CPUState
*cs
= icc_cs_from_env(env
);
543 trace_gicv3_icv_igrpen_write(ri
->opc2
& 1 ? 1 : 0,
544 gicv3_redist_affid(cs
), value
);
546 enbit
= ri
->opc2
& 1 ? ICH_VMCR_EL2_VENG1_SHIFT
: ICH_VMCR_EL2_VENG0_SHIFT
;
548 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, enbit
, 1, value
);
549 gicv3_cpuif_virt_update(cs
);
552 static uint64_t icv_ctlr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
554 GICv3CPUState
*cs
= icc_cs_from_env(env
);
557 /* Note that the fixed fields here (A3V, SEIS, IDbits, PRIbits)
558 * should match the ones reported in ich_vtr_read().
560 value
= ICC_CTLR_EL1_A3V
| (1 << ICC_CTLR_EL1_IDBITS_SHIFT
) |
561 (7 << ICC_CTLR_EL1_PRIBITS_SHIFT
);
563 if (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VEOIM
) {
564 value
|= ICC_CTLR_EL1_EOIMODE
;
567 if (cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VCBPR
) {
568 value
|= ICC_CTLR_EL1_CBPR
;
571 trace_gicv3_icv_ctlr_read(gicv3_redist_affid(cs
), value
);
575 static void icv_ctlr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
578 GICv3CPUState
*cs
= icc_cs_from_env(env
);
580 trace_gicv3_icv_ctlr_write(gicv3_redist_affid(cs
), value
);
582 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VCBPR_SHIFT
,
583 1, value
& ICC_CTLR_EL1_CBPR
? 1 : 0);
584 cs
->ich_vmcr_el2
= deposit64(cs
->ich_vmcr_el2
, ICH_VMCR_EL2_VEOIM_SHIFT
,
585 1, value
& ICC_CTLR_EL1_EOIMODE
? 1 : 0);
587 gicv3_cpuif_virt_update(cs
);
590 static uint64_t icv_rpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
592 GICv3CPUState
*cs
= icc_cs_from_env(env
);
593 int prio
= ich_highest_active_virt_prio(cs
);
595 trace_gicv3_icv_rpr_read(gicv3_redist_affid(cs
), prio
);
599 static uint64_t icv_hppir_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
601 GICv3CPUState
*cs
= icc_cs_from_env(env
);
602 int grp
= ri
->crm
== 8 ? GICV3_G0
: GICV3_G1NS
;
603 int idx
= hppvi_index(cs
);
604 uint64_t value
= INTID_SPURIOUS
;
607 uint64_t lr
= cs
->ich_lr_el2
[idx
];
608 int thisgrp
= (lr
& ICH_LR_EL2_GROUP
) ? GICV3_G1NS
: GICV3_G0
;
610 if (grp
== thisgrp
) {
611 value
= ich_lr_vintid(lr
);
615 trace_gicv3_icv_hppir_read(grp
, gicv3_redist_affid(cs
), value
);
619 static void icv_activate_irq(GICv3CPUState
*cs
, int idx
, int grp
)
621 /* Activate the interrupt in the specified list register
622 * by moving it from Pending to Active state, and update the
623 * Active Priority Registers.
625 uint32_t mask
= icv_gprio_mask(cs
, grp
);
626 int prio
= ich_lr_prio(cs
->ich_lr_el2
[idx
]) & mask
;
627 int aprbit
= prio
>> (8 - cs
->vprebits
);
628 int regno
= aprbit
/ 32;
629 int regbit
= aprbit
% 32;
631 cs
->ich_lr_el2
[idx
] &= ~ICH_LR_EL2_STATE_PENDING_BIT
;
632 cs
->ich_lr_el2
[idx
] |= ICH_LR_EL2_STATE_ACTIVE_BIT
;
633 cs
->ich_apr
[grp
][regno
] |= (1 << regbit
);
636 static uint64_t icv_iar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
638 GICv3CPUState
*cs
= icc_cs_from_env(env
);
639 int grp
= ri
->crm
== 8 ? GICV3_G0
: GICV3_G1NS
;
640 int idx
= hppvi_index(cs
);
641 uint64_t intid
= INTID_SPURIOUS
;
644 uint64_t lr
= cs
->ich_lr_el2
[idx
];
645 int thisgrp
= (lr
& ICH_LR_EL2_GROUP
) ? GICV3_G1NS
: GICV3_G0
;
647 if (thisgrp
== grp
&& icv_hppi_can_preempt(cs
, lr
)) {
648 intid
= ich_lr_vintid(lr
);
649 if (intid
< INTID_SECURE
) {
650 icv_activate_irq(cs
, idx
, grp
);
652 /* Interrupt goes from Pending to Invalid */
653 cs
->ich_lr_el2
[idx
] &= ~ICH_LR_EL2_STATE_PENDING_BIT
;
654 /* We will now return the (bogus) ID from the list register,
655 * as per the pseudocode.
661 trace_gicv3_icv_iar_read(ri
->crm
== 8 ? 0 : 1,
662 gicv3_redist_affid(cs
), intid
);
666 static int icc_highest_active_prio(GICv3CPUState
*cs
)
668 /* Calculate the current running priority based on the set bits
669 * in the Active Priority Registers.
673 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[0]); i
++) {
674 uint32_t apr
= cs
->icc_apr
[GICV3_G0
][i
] |
675 cs
->icc_apr
[GICV3_G1
][i
] | cs
->icc_apr
[GICV3_G1NS
][i
];
680 return (i
* 32 + ctz32(apr
)) << (GIC_MIN_BPR
+ 1);
682 /* No current active interrupts: return idle priority */
686 static uint32_t icc_gprio_mask(GICv3CPUState
*cs
, int group
)
688 /* Return a mask word which clears the subpriority bits from
689 * a priority value for an interrupt in the specified group.
690 * This depends on the BPR value. For CBPR0 (S or NS):
691 * a BPR of 0 means the group priority bits are [7:1];
692 * a BPR of 1 means they are [7:2], and so on down to
693 * a BPR of 7 meaning no group priority bits at all.
695 * a BPR of 0 is impossible (the minimum value is 1)
696 * a BPR of 1 means the group priority bits are [7:1];
697 * a BPR of 2 means they are [7:2], and so on down to
698 * a BPR of 7 meaning the group priority is [7].
700 * Which BPR to use depends on the group of the interrupt and
701 * the current ICC_CTLR.CBPR settings.
703 * This corresponds to the GroupBits() pseudocode.
707 if ((group
== GICV3_G1
&& cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
) ||
708 (group
== GICV3_G1NS
&&
709 cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
713 bpr
= cs
->icc_bpr
[group
] & 7;
715 if (group
== GICV3_G1NS
) {
720 return ~0U << (bpr
+ 1);
723 static bool icc_no_enabled_hppi(GICv3CPUState
*cs
)
725 /* Return true if there is no pending interrupt, or the
726 * highest priority pending interrupt is in a group which has been
727 * disabled at the CPU interface by the ICC_IGRPEN* register enable bits.
729 return cs
->hppi
.prio
== 0xff || (cs
->icc_igrpen
[cs
->hppi
.grp
] == 0);
732 static bool icc_hppi_can_preempt(GICv3CPUState
*cs
)
734 /* Return true if we have a pending interrupt of sufficient
735 * priority to preempt.
740 if (icc_no_enabled_hppi(cs
)) {
744 if (cs
->hppi
.prio
>= cs
->icc_pmr_el1
) {
745 /* Priority mask masks this interrupt */
749 rprio
= icc_highest_active_prio(cs
);
751 /* No currently running interrupt so we can preempt */
755 mask
= icc_gprio_mask(cs
, cs
->hppi
.grp
);
757 /* We only preempt a running interrupt if the pending interrupt's
758 * group priority is sufficient (the subpriorities are not considered).
760 if ((cs
->hppi
.prio
& mask
) < (rprio
& mask
)) {
767 void gicv3_cpuif_update(GICv3CPUState
*cs
)
769 /* Tell the CPU about its highest priority pending interrupt */
772 ARMCPU
*cpu
= ARM_CPU(cs
->cpu
);
773 CPUARMState
*env
= &cpu
->env
;
775 g_assert(qemu_mutex_iothread_locked());
777 trace_gicv3_cpuif_update(gicv3_redist_affid(cs
), cs
->hppi
.irq
,
778 cs
->hppi
.grp
, cs
->hppi
.prio
);
780 if (cs
->hppi
.grp
== GICV3_G1
&& !arm_feature(env
, ARM_FEATURE_EL3
)) {
781 /* If a Security-enabled GIC sends a G1S interrupt to a
782 * Security-disabled CPU, we must treat it as if it were G0.
784 cs
->hppi
.grp
= GICV3_G0
;
787 if (icc_hppi_can_preempt(cs
)) {
788 /* We have an interrupt: should we signal it as IRQ or FIQ?
789 * This is described in the GICv3 spec section 4.6.2.
793 switch (cs
->hppi
.grp
) {
798 isfiq
= (!arm_is_secure(env
) ||
799 (arm_current_el(env
) == 3 && arm_el_is_aa64(env
, 3)));
802 isfiq
= arm_is_secure(env
);
805 g_assert_not_reached();
815 trace_gicv3_cpuif_set_irqs(gicv3_redist_affid(cs
), fiqlevel
, irqlevel
);
817 qemu_set_irq(cs
->parent_fiq
, fiqlevel
);
818 qemu_set_irq(cs
->parent_irq
, irqlevel
);
821 static uint64_t icc_pmr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
823 GICv3CPUState
*cs
= icc_cs_from_env(env
);
824 uint32_t value
= cs
->icc_pmr_el1
;
826 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
827 return icv_pmr_read(env
, ri
);
830 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_is_secure(env
) &&
831 (env
->cp15
.scr_el3
& SCR_FIQ
)) {
832 /* NS access and Group 0 is inaccessible to NS: return the
833 * NS view of the current priority
835 if ((value
& 0x80) == 0) {
836 /* Secure priorities not visible to NS */
838 } else if (value
!= 0xff) {
839 value
= (value
<< 1) & 0xff;
843 trace_gicv3_icc_pmr_read(gicv3_redist_affid(cs
), value
);
848 static void icc_pmr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
851 GICv3CPUState
*cs
= icc_cs_from_env(env
);
853 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
854 return icv_pmr_write(env
, ri
, value
);
857 trace_gicv3_icc_pmr_write(gicv3_redist_affid(cs
), value
);
861 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_is_secure(env
) &&
862 (env
->cp15
.scr_el3
& SCR_FIQ
)) {
863 /* NS access and Group 0 is inaccessible to NS: return the
864 * NS view of the current priority
866 if (!(cs
->icc_pmr_el1
& 0x80)) {
867 /* Current PMR in the secure range, don't allow NS to change it */
870 value
= (value
>> 1) | 0x80;
872 cs
->icc_pmr_el1
= value
;
873 gicv3_cpuif_update(cs
);
876 static void icc_activate_irq(GICv3CPUState
*cs
, int irq
)
878 /* Move the interrupt from the Pending state to Active, and update
879 * the Active Priority Registers
881 uint32_t mask
= icc_gprio_mask(cs
, cs
->hppi
.grp
);
882 int prio
= cs
->hppi
.prio
& mask
;
883 int aprbit
= prio
>> 1;
884 int regno
= aprbit
/ 32;
885 int regbit
= aprbit
% 32;
887 cs
->icc_apr
[cs
->hppi
.grp
][regno
] |= (1 << regbit
);
889 if (irq
< GIC_INTERNAL
) {
890 cs
->gicr_iactiver0
= deposit32(cs
->gicr_iactiver0
, irq
, 1, 1);
891 cs
->gicr_ipendr0
= deposit32(cs
->gicr_ipendr0
, irq
, 1, 0);
892 gicv3_redist_update(cs
);
894 gicv3_gicd_active_set(cs
->gic
, irq
);
895 gicv3_gicd_pending_clear(cs
->gic
, irq
);
896 gicv3_update(cs
->gic
, irq
, 1);
900 static uint64_t icc_hppir0_value(GICv3CPUState
*cs
, CPUARMState
*env
)
902 /* Return the highest priority pending interrupt register value
907 if (cs
->hppi
.prio
== 0xff) {
908 return INTID_SPURIOUS
;
911 /* Check whether we can return the interrupt or if we should return
912 * a special identifier, as per the CheckGroup0ForSpecialIdentifiers
913 * pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM
916 irq_is_secure
= (!(cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) &&
917 (cs
->hppi
.grp
!= GICV3_G1NS
));
919 if (cs
->hppi
.grp
!= GICV3_G0
&& !arm_is_el3_or_mon(env
)) {
920 return INTID_SPURIOUS
;
922 if (irq_is_secure
&& !arm_is_secure(env
)) {
923 /* Secure interrupts not visible to Nonsecure */
924 return INTID_SPURIOUS
;
927 if (cs
->hppi
.grp
!= GICV3_G0
) {
928 /* Indicate to EL3 that there's a Group 1 interrupt for the other
931 return irq_is_secure
? INTID_SECURE
: INTID_NONSECURE
;
937 static uint64_t icc_hppir1_value(GICv3CPUState
*cs
, CPUARMState
*env
)
939 /* Return the highest priority pending interrupt register value
944 if (cs
->hppi
.prio
== 0xff) {
945 return INTID_SPURIOUS
;
948 /* Check whether we can return the interrupt or if we should return
949 * a special identifier, as per the CheckGroup1ForSpecialIdentifiers
950 * pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM
953 irq_is_secure
= (!(cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) &&
954 (cs
->hppi
.grp
!= GICV3_G1NS
));
956 if (cs
->hppi
.grp
== GICV3_G0
) {
957 /* Group 0 interrupts not visible via HPPIR1 */
958 return INTID_SPURIOUS
;
961 if (!arm_is_secure(env
)) {
962 /* Secure interrupts not visible in Non-secure */
963 return INTID_SPURIOUS
;
965 } else if (!arm_is_el3_or_mon(env
) && arm_is_secure(env
)) {
966 /* Group 1 non-secure interrupts not visible in Secure EL1 */
967 return INTID_SPURIOUS
;
973 static uint64_t icc_iar0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
975 GICv3CPUState
*cs
= icc_cs_from_env(env
);
978 if (icv_access(env
, HCR_FMO
)) {
979 return icv_iar_read(env
, ri
);
982 if (!icc_hppi_can_preempt(cs
)) {
983 intid
= INTID_SPURIOUS
;
985 intid
= icc_hppir0_value(cs
, env
);
988 if (!(intid
>= INTID_SECURE
&& intid
<= INTID_SPURIOUS
)) {
989 icc_activate_irq(cs
, intid
);
992 trace_gicv3_icc_iar0_read(gicv3_redist_affid(cs
), intid
);
996 static uint64_t icc_iar1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
998 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1001 if (icv_access(env
, HCR_IMO
)) {
1002 return icv_iar_read(env
, ri
);
1005 if (!icc_hppi_can_preempt(cs
)) {
1006 intid
= INTID_SPURIOUS
;
1008 intid
= icc_hppir1_value(cs
, env
);
1011 if (!(intid
>= INTID_SECURE
&& intid
<= INTID_SPURIOUS
)) {
1012 icc_activate_irq(cs
, intid
);
1015 trace_gicv3_icc_iar1_read(gicv3_redist_affid(cs
), intid
);
1019 static void icc_drop_prio(GICv3CPUState
*cs
, int grp
)
1021 /* Drop the priority of the currently active interrupt in
1022 * the specified group.
1024 * Note that we can guarantee (because of the requirement to nest
1025 * ICC_IAR reads [which activate an interrupt and raise priority]
1026 * with ICC_EOIR writes [which drop the priority for the interrupt])
1027 * that the interrupt we're being called for is the highest priority
1028 * active interrupt, meaning that it has the lowest set bit in the
1031 * If the guest does not honour the ordering constraints then the
1032 * behaviour of the GIC is UNPREDICTABLE, which for us means that
1033 * the values of the APR registers might become incorrect and the
1034 * running priority will be wrong, so interrupts that should preempt
1035 * might not do so, and interrupts that should not preempt might do so.
1039 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[grp
]); i
++) {
1040 uint64_t *papr
= &cs
->icc_apr
[grp
][i
];
1045 /* Clear the lowest set bit */
1050 /* running priority change means we need an update for this cpu i/f */
1051 gicv3_cpuif_update(cs
);
1054 static bool icc_eoi_split(CPUARMState
*env
, GICv3CPUState
*cs
)
1056 /* Return true if we should split priority drop and interrupt
1057 * deactivation, ie whether the relevant EOIMode bit is set.
1059 if (arm_is_el3_or_mon(env
)) {
1060 return cs
->icc_ctlr_el3
& ICC_CTLR_EL3_EOIMODE_EL3
;
1062 if (arm_is_secure_below_el3(env
)) {
1063 return cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_EOIMODE
;
1065 return cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
;
1069 static int icc_highest_active_group(GICv3CPUState
*cs
)
1071 /* Return the group with the highest priority active interrupt.
1072 * We can do this by just comparing the APRs to see which one
1073 * has the lowest set bit.
1074 * (If more than one group is active at the same priority then
1075 * we're in UNPREDICTABLE territory.)
1079 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[0]); i
++) {
1080 int g0ctz
= ctz32(cs
->icc_apr
[GICV3_G0
][i
]);
1081 int g1ctz
= ctz32(cs
->icc_apr
[GICV3_G1
][i
]);
1082 int g1nsctz
= ctz32(cs
->icc_apr
[GICV3_G1NS
][i
]);
1084 if (g1nsctz
< g0ctz
&& g1nsctz
< g1ctz
) {
1087 if (g1ctz
< g0ctz
) {
1094 /* No set active bits? UNPREDICTABLE; return -1 so the caller
1095 * ignores the spurious EOI attempt.
1100 static void icc_deactivate_irq(GICv3CPUState
*cs
, int irq
)
1102 if (irq
< GIC_INTERNAL
) {
1103 cs
->gicr_iactiver0
= deposit32(cs
->gicr_iactiver0
, irq
, 1, 0);
1104 gicv3_redist_update(cs
);
1106 gicv3_gicd_active_clear(cs
->gic
, irq
);
1107 gicv3_update(cs
->gic
, irq
, 1);
1111 static bool icv_eoi_split(CPUARMState
*env
, GICv3CPUState
*cs
)
1113 /* Return true if we should split priority drop and interrupt
1114 * deactivation, ie whether the virtual EOIMode bit is set.
1116 return cs
->ich_vmcr_el2
& ICH_VMCR_EL2_VEOIM
;
1119 static int icv_find_active(GICv3CPUState
*cs
, int irq
)
1121 /* Given an interrupt number for an active interrupt, return the index
1122 * of the corresponding list register, or -1 if there is no match.
1123 * Corresponds to FindActiveVirtualInterrupt pseudocode.
1127 for (i
= 0; i
< cs
->num_list_regs
; i
++) {
1128 uint64_t lr
= cs
->ich_lr_el2
[i
];
1130 if ((lr
& ICH_LR_EL2_STATE_ACTIVE_BIT
) && ich_lr_vintid(lr
) == irq
) {
1138 static void icv_deactivate_irq(GICv3CPUState
*cs
, int idx
)
1140 /* Deactivate the interrupt in the specified list register index */
1141 uint64_t lr
= cs
->ich_lr_el2
[idx
];
1143 if (lr
& ICH_LR_EL2_HW
) {
1144 /* Deactivate the associated physical interrupt */
1145 int pirq
= ich_lr_pintid(lr
);
1147 if (pirq
< INTID_SECURE
) {
1148 icc_deactivate_irq(cs
, pirq
);
1152 /* Clear the 'active' part of the state, so ActivePending->Pending
1153 * and Active->Invalid.
1155 lr
&= ~ICH_LR_EL2_STATE_ACTIVE_BIT
;
1156 cs
->ich_lr_el2
[idx
] = lr
;
1159 static void icv_increment_eoicount(GICv3CPUState
*cs
)
1161 /* Increment the EOICOUNT field in ICH_HCR_EL2 */
1162 int eoicount
= extract64(cs
->ich_hcr_el2
, ICH_HCR_EL2_EOICOUNT_SHIFT
,
1163 ICH_HCR_EL2_EOICOUNT_LENGTH
);
1165 cs
->ich_hcr_el2
= deposit64(cs
->ich_hcr_el2
, ICH_HCR_EL2_EOICOUNT_SHIFT
,
1166 ICH_HCR_EL2_EOICOUNT_LENGTH
, eoicount
+ 1);
1169 static int icv_drop_prio(GICv3CPUState
*cs
)
1171 /* Drop the priority of the currently active virtual interrupt
1172 * (favouring group 0 if there is a set active bit at
1173 * the same priority for both group 0 and group 1).
1174 * Return the priority value for the bit we just cleared,
1175 * or 0xff if no bits were set in the AP registers at all.
1176 * Note that though the ich_apr[] are uint64_t only the low
1177 * 32 bits are actually relevant.
1180 int aprmax
= 1 << (cs
->vprebits
- 5);
1182 assert(aprmax
<= ARRAY_SIZE(cs
->ich_apr
[0]));
1184 for (i
= 0; i
< aprmax
; i
++) {
1185 uint64_t *papr0
= &cs
->ich_apr
[GICV3_G0
][i
];
1186 uint64_t *papr1
= &cs
->ich_apr
[GICV3_G1NS
][i
];
1187 int apr0count
, apr1count
;
1189 if (!*papr0
&& !*papr1
) {
1193 /* We can't just use the bit-twiddling hack icc_drop_prio() does
1194 * because we need to return the bit number we cleared so
1195 * it can be compared against the list register's priority field.
1197 apr0count
= ctz32(*papr0
);
1198 apr1count
= ctz32(*papr1
);
1200 if (apr0count
<= apr1count
) {
1201 *papr0
&= *papr0
- 1;
1202 return (apr0count
+ i
* 32) << (icv_min_vbpr(cs
) + 1);
1204 *papr1
&= *papr1
- 1;
1205 return (apr1count
+ i
* 32) << (icv_min_vbpr(cs
) + 1);
1211 static void icv_dir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1214 /* Deactivate interrupt */
1215 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1217 int irq
= value
& 0xffffff;
1219 trace_gicv3_icv_dir_write(gicv3_redist_affid(cs
), value
);
1221 if (irq
>= cs
->gic
->num_irq
) {
1222 /* Also catches special interrupt numbers and LPIs */
1226 if (!icv_eoi_split(env
, cs
)) {
1230 idx
= icv_find_active(cs
, irq
);
1233 /* No list register matching this, so increment the EOI count
1234 * (might trigger a maintenance interrupt)
1236 icv_increment_eoicount(cs
);
1238 icv_deactivate_irq(cs
, idx
);
1241 gicv3_cpuif_virt_update(cs
);
1244 static void icv_eoir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1247 /* End of Interrupt */
1248 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1249 int irq
= value
& 0xffffff;
1250 int grp
= ri
->crm
== 8 ? GICV3_G0
: GICV3_G1NS
;
1253 trace_gicv3_icv_eoir_write(ri
->crm
== 8 ? 0 : 1,
1254 gicv3_redist_affid(cs
), value
);
1256 if (irq
>= cs
->gic
->num_irq
) {
1257 /* Also catches special interrupt numbers and LPIs */
1261 /* We implement the IMPDEF choice of "drop priority before doing
1262 * error checks" (because that lets us avoid scanning the AP
1265 dropprio
= icv_drop_prio(cs
);
1266 if (dropprio
== 0xff) {
1267 /* No active interrupt. It is CONSTRAINED UNPREDICTABLE
1268 * whether the list registers are checked in this
1269 * situation; we choose not to.
1274 idx
= icv_find_active(cs
, irq
);
1277 /* No valid list register corresponding to EOI ID */
1278 icv_increment_eoicount(cs
);
1280 uint64_t lr
= cs
->ich_lr_el2
[idx
];
1281 int thisgrp
= (lr
& ICH_LR_EL2_GROUP
) ? GICV3_G1NS
: GICV3_G0
;
1282 int lr_gprio
= ich_lr_prio(lr
) & icv_gprio_mask(cs
, grp
);
1284 if (thisgrp
== grp
&& lr_gprio
== dropprio
) {
1285 if (!icv_eoi_split(env
, cs
)) {
1286 /* Priority drop and deactivate not split: deactivate irq now */
1287 icv_deactivate_irq(cs
, idx
);
1292 gicv3_cpuif_virt_update(cs
);
1295 static void icc_eoir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1298 /* End of Interrupt */
1299 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1300 int irq
= value
& 0xffffff;
1303 if (icv_access(env
, ri
->crm
== 8 ? HCR_FMO
: HCR_IMO
)) {
1304 icv_eoir_write(env
, ri
, value
);
1308 trace_gicv3_icc_eoir_write(ri
->crm
== 8 ? 0 : 1,
1309 gicv3_redist_affid(cs
), value
);
1316 if (arm_is_secure(env
)) {
1323 if (irq
>= cs
->gic
->num_irq
) {
1324 /* This handles two cases:
1325 * 1. If software writes the ID of a spurious interrupt [ie 1020-1023]
1326 * to the GICC_EOIR, the GIC ignores that write.
1327 * 2. If software writes the number of a non-existent interrupt
1328 * this must be a subcase of "value written does not match the last
1329 * valid interrupt value read from the Interrupt Acknowledge
1330 * register" and so this is UNPREDICTABLE. We choose to ignore it.
1335 if (icc_highest_active_group(cs
) != grp
) {
1339 icc_drop_prio(cs
, grp
);
1341 if (!icc_eoi_split(env
, cs
)) {
1342 /* Priority drop and deactivate not split: deactivate irq now */
1343 icc_deactivate_irq(cs
, irq
);
1347 static uint64_t icc_hppir0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1349 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1352 if (icv_access(env
, HCR_FMO
)) {
1353 return icv_hppir_read(env
, ri
);
1356 value
= icc_hppir0_value(cs
, env
);
1357 trace_gicv3_icc_hppir0_read(gicv3_redist_affid(cs
), value
);
1361 static uint64_t icc_hppir1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1363 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1366 if (icv_access(env
, HCR_IMO
)) {
1367 return icv_hppir_read(env
, ri
);
1370 value
= icc_hppir1_value(cs
, env
);
1371 trace_gicv3_icc_hppir1_read(gicv3_redist_affid(cs
), value
);
1375 static uint64_t icc_bpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1377 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1378 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1
;
1379 bool satinc
= false;
1382 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1383 return icv_bpr_read(env
, ri
);
1386 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1390 if (grp
== GICV3_G1
&& !arm_is_el3_or_mon(env
) &&
1391 (cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
)) {
1392 /* CBPR_EL1S means secure EL1 or AArch32 EL3 !Mon BPR1 accesses
1398 if (grp
== GICV3_G1NS
&& arm_current_el(env
) < 3 &&
1399 (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
1400 /* reads return bpr0 + 1 sat to 7, writes ignored */
1405 bpr
= cs
->icc_bpr
[grp
];
1411 trace_gicv3_icc_bpr_read(ri
->crm
== 8 ? 0 : 1, gicv3_redist_affid(cs
), bpr
);
1416 static void icc_bpr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1419 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1420 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1
;
1423 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1424 icv_bpr_write(env
, ri
, value
);
1428 trace_gicv3_icc_bpr_write(ri
->crm
== 8 ? 0 : 1,
1429 gicv3_redist_affid(cs
), value
);
1431 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1435 if (grp
== GICV3_G1
&& !arm_is_el3_or_mon(env
) &&
1436 (cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
)) {
1437 /* CBPR_EL1S means secure EL1 or AArch32 EL3 !Mon BPR1 accesses
1443 if (grp
== GICV3_G1NS
&& arm_current_el(env
) < 3 &&
1444 (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
1445 /* reads return bpr0 + 1 sat to 7, writes ignored */
1449 minval
= (grp
== GICV3_G1NS
) ? GIC_MIN_BPR_NS
: GIC_MIN_BPR
;
1450 if (value
< minval
) {
1454 cs
->icc_bpr
[grp
] = value
& 7;
1455 gicv3_cpuif_update(cs
);
1458 static uint64_t icc_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1460 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1463 int regno
= ri
->opc2
& 3;
1464 int grp
= ri
->crm
& 1 ? GICV3_G0
: GICV3_G1
;
1466 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1467 return icv_ap_read(env
, ri
);
1470 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1474 value
= cs
->icc_apr
[grp
][regno
];
1476 trace_gicv3_icc_ap_read(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
1480 static void icc_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1483 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1485 int regno
= ri
->opc2
& 3;
1486 int grp
= ri
->crm
& 1 ? GICV3_G0
: GICV3_G1
;
1488 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1489 icv_ap_write(env
, ri
, value
);
1493 trace_gicv3_icc_ap_write(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
1495 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1499 /* It's not possible to claim that a Non-secure interrupt is active
1500 * at a priority outside the Non-secure range (128..255), since this
1501 * would otherwise allow malicious NS code to block delivery of S interrupts
1502 * by writing a bad value to these registers.
1504 if (grp
== GICV3_G1NS
&& regno
< 2 && arm_feature(env
, ARM_FEATURE_EL3
)) {
1508 cs
->icc_apr
[grp
][regno
] = value
& 0xFFFFFFFFU
;
1509 gicv3_cpuif_update(cs
);
1512 static void icc_dir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1515 /* Deactivate interrupt */
1516 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1517 int irq
= value
& 0xffffff;
1518 bool irq_is_secure
, single_sec_state
, irq_is_grp0
;
1519 bool route_fiq_to_el3
, route_irq_to_el3
, route_fiq_to_el2
, route_irq_to_el2
;
1521 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
1522 icv_dir_write(env
, ri
, value
);
1526 trace_gicv3_icc_dir_write(gicv3_redist_affid(cs
), value
);
1528 if (irq
>= cs
->gic
->num_irq
) {
1529 /* Also catches special interrupt numbers and LPIs */
1533 if (!icc_eoi_split(env
, cs
)) {
1537 int grp
= gicv3_irq_group(cs
->gic
, cs
, irq
);
1539 single_sec_state
= cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
;
1540 irq_is_secure
= !single_sec_state
&& (grp
!= GICV3_G1NS
);
1541 irq_is_grp0
= grp
== GICV3_G0
;
1543 /* Check whether we're allowed to deactivate this interrupt based
1544 * on its group and the current CPU state.
1545 * These checks are laid out to correspond to the spec's pseudocode.
1547 route_fiq_to_el3
= env
->cp15
.scr_el3
& SCR_FIQ
;
1548 route_irq_to_el3
= env
->cp15
.scr_el3
& SCR_IRQ
;
1549 /* No need to include !IsSecure in route_*_to_el2 as it's only
1550 * tested in cases where we know !IsSecure is true.
1552 route_fiq_to_el2
= env
->cp15
.hcr_el2
& HCR_FMO
;
1553 route_irq_to_el2
= env
->cp15
.hcr_el2
& HCR_FMO
;
1555 switch (arm_current_el(env
)) {
1559 if (single_sec_state
&& irq_is_grp0
&& !route_fiq_to_el3
) {
1562 if (!irq_is_secure
&& !irq_is_grp0
&& !route_irq_to_el3
) {
1567 if (!arm_is_secure_below_el3(env
)) {
1568 if (single_sec_state
&& irq_is_grp0
&&
1569 !route_fiq_to_el3
&& !route_fiq_to_el2
) {
1572 if (!irq_is_secure
&& !irq_is_grp0
&&
1573 !route_irq_to_el3
&& !route_irq_to_el2
) {
1577 if (irq_is_grp0
&& !route_fiq_to_el3
) {
1581 (!irq_is_secure
|| !single_sec_state
) &&
1582 !route_irq_to_el3
) {
1588 g_assert_not_reached();
1591 icc_deactivate_irq(cs
, irq
);
1594 static uint64_t icc_rpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1596 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1599 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
1600 return icv_rpr_read(env
, ri
);
1603 prio
= icc_highest_active_prio(cs
);
1605 if (arm_feature(env
, ARM_FEATURE_EL3
) &&
1606 !arm_is_secure(env
) && (env
->cp15
.scr_el3
& SCR_FIQ
)) {
1607 /* NS GIC access and Group 0 is inaccessible to NS */
1608 if ((prio
& 0x80) == 0) {
1609 /* NS mustn't see priorities in the Secure half of the range */
1611 } else if (prio
!= 0xff) {
1612 /* Non-idle priority: show the Non-secure view of it */
1613 prio
= (prio
<< 1) & 0xff;
1617 trace_gicv3_icc_rpr_read(gicv3_redist_affid(cs
), prio
);
1621 static void icc_generate_sgi(CPUARMState
*env
, GICv3CPUState
*cs
,
1622 uint64_t value
, int grp
, bool ns
)
1624 GICv3State
*s
= cs
->gic
;
1626 /* Extract Aff3/Aff2/Aff1 and shift into the bottom 24 bits */
1627 uint64_t aff
= extract64(value
, 48, 8) << 16 |
1628 extract64(value
, 32, 8) << 8 |
1629 extract64(value
, 16, 8);
1630 uint32_t targetlist
= extract64(value
, 0, 16);
1631 uint32_t irq
= extract64(value
, 24, 4);
1632 bool irm
= extract64(value
, 40, 1);
1635 if (grp
== GICV3_G1
&& s
->gicd_ctlr
& GICD_CTLR_DS
) {
1636 /* If GICD_CTLR.DS == 1, the Distributor treats Secure Group 1
1637 * interrupts as Group 0 interrupts and must send Secure Group 0
1638 * interrupts to the target CPUs.
1643 trace_gicv3_icc_generate_sgi(gicv3_redist_affid(cs
), irq
, irm
,
1646 for (i
= 0; i
< s
->num_cpu
; i
++) {
1647 GICv3CPUState
*ocs
= &s
->cpu
[i
];
1650 /* IRM == 1 : route to all CPUs except self */
1655 /* IRM == 0 : route to Aff3.Aff2.Aff1.n for all n in [0..15]
1656 * where the corresponding bit is set in targetlist
1660 if (ocs
->gicr_typer
>> 40 != aff
) {
1663 aff0
= extract64(ocs
->gicr_typer
, 32, 8);
1664 if (aff0
> 15 || extract32(targetlist
, aff0
, 1) == 0) {
1669 /* The redistributor will check against its own GICR_NSACR as needed */
1670 gicv3_redist_send_sgi(ocs
, grp
, irq
, ns
);
1674 static void icc_sgi0r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1677 /* Generate Secure Group 0 SGI. */
1678 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1679 bool ns
= !arm_is_secure(env
);
1681 icc_generate_sgi(env
, cs
, value
, GICV3_G0
, ns
);
1684 static void icc_sgi1r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1687 /* Generate Group 1 SGI for the current Security state */
1688 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1690 bool ns
= !arm_is_secure(env
);
1692 grp
= ns
? GICV3_G1NS
: GICV3_G1
;
1693 icc_generate_sgi(env
, cs
, value
, grp
, ns
);
1696 static void icc_asgi1r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1699 /* Generate Group 1 SGI for the Security state that is not
1702 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1704 bool ns
= !arm_is_secure(env
);
1706 grp
= ns
? GICV3_G1
: GICV3_G1NS
;
1707 icc_generate_sgi(env
, cs
, value
, grp
, ns
);
1710 static uint64_t icc_igrpen_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1712 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1713 int grp
= ri
->opc2
& 1 ? GICV3_G1
: GICV3_G0
;
1716 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1717 return icv_igrpen_read(env
, ri
);
1720 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1724 value
= cs
->icc_igrpen
[grp
];
1725 trace_gicv3_icc_igrpen_read(ri
->opc2
& 1 ? 1 : 0,
1726 gicv3_redist_affid(cs
), value
);
1730 static void icc_igrpen_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1733 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1734 int grp
= ri
->opc2
& 1 ? GICV3_G1
: GICV3_G0
;
1736 if (icv_access(env
, grp
== GICV3_G0
? HCR_FMO
: HCR_IMO
)) {
1737 icv_igrpen_write(env
, ri
, value
);
1741 trace_gicv3_icc_igrpen_write(ri
->opc2
& 1 ? 1 : 0,
1742 gicv3_redist_affid(cs
), value
);
1744 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
1748 cs
->icc_igrpen
[grp
] = value
& ICC_IGRPEN_ENABLE
;
1749 gicv3_cpuif_update(cs
);
1752 static uint64_t icc_igrpen1_el3_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1754 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1757 /* IGRPEN1_EL3 bits 0 and 1 are r/w aliases into IGRPEN1_EL1 NS and S */
1758 value
= cs
->icc_igrpen
[GICV3_G1NS
] | (cs
->icc_igrpen
[GICV3_G1
] << 1);
1759 trace_gicv3_icc_igrpen1_el3_read(gicv3_redist_affid(cs
), value
);
1763 static void icc_igrpen1_el3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1766 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1768 trace_gicv3_icc_igrpen1_el3_write(gicv3_redist_affid(cs
), value
);
1770 /* IGRPEN1_EL3 bits 0 and 1 are r/w aliases into IGRPEN1_EL1 NS and S */
1771 cs
->icc_igrpen
[GICV3_G1NS
] = extract32(value
, 0, 1);
1772 cs
->icc_igrpen
[GICV3_G1
] = extract32(value
, 1, 1);
1773 gicv3_cpuif_update(cs
);
1776 static uint64_t icc_ctlr_el1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1778 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1779 int bank
= gicv3_use_ns_bank(env
) ? GICV3_NS
: GICV3_S
;
1782 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
1783 return icv_ctlr_read(env
, ri
);
1786 value
= cs
->icc_ctlr_el1
[bank
];
1787 trace_gicv3_icc_ctlr_read(gicv3_redist_affid(cs
), value
);
1791 static void icc_ctlr_el1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1794 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1795 int bank
= gicv3_use_ns_bank(env
) ? GICV3_NS
: GICV3_S
;
1798 if (icv_access(env
, HCR_FMO
| HCR_IMO
)) {
1799 icv_ctlr_write(env
, ri
, value
);
1803 trace_gicv3_icc_ctlr_write(gicv3_redist_affid(cs
), value
);
1805 /* Only CBPR and EOIMODE can be RW;
1806 * for us PMHE is RAZ/WI (we don't implement 1-of-N interrupts or
1807 * the asseciated priority-based routing of them);
1808 * if EL3 is implemented and GICD_CTLR.DS == 0, then PMHE and CBPR are RO.
1810 if (arm_feature(env
, ARM_FEATURE_EL3
) &&
1811 ((cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) == 0)) {
1812 mask
= ICC_CTLR_EL1_EOIMODE
;
1814 mask
= ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
;
1817 cs
->icc_ctlr_el1
[bank
] &= ~mask
;
1818 cs
->icc_ctlr_el1
[bank
] |= (value
& mask
);
1819 gicv3_cpuif_update(cs
);
1823 static uint64_t icc_ctlr_el3_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1825 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1828 value
= cs
->icc_ctlr_el3
;
1829 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
) {
1830 value
|= ICC_CTLR_EL3_EOIMODE_EL1NS
;
1832 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
) {
1833 value
|= ICC_CTLR_EL3_CBPR_EL1NS
;
1835 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
) {
1836 value
|= ICC_CTLR_EL3_EOIMODE_EL1S
;
1838 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
) {
1839 value
|= ICC_CTLR_EL3_CBPR_EL1S
;
1842 trace_gicv3_icc_ctlr_el3_read(gicv3_redist_affid(cs
), value
);
1846 static void icc_ctlr_el3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1849 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1852 trace_gicv3_icc_ctlr_el3_write(gicv3_redist_affid(cs
), value
);
1854 /* *_EL1NS and *_EL1S bits are aliases into the ICC_CTLR_EL1 bits. */
1855 cs
->icc_ctlr_el1
[GICV3_NS
] &= (ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
);
1856 if (value
& ICC_CTLR_EL3_EOIMODE_EL1NS
) {
1857 cs
->icc_ctlr_el1
[GICV3_NS
] |= ICC_CTLR_EL1_EOIMODE
;
1859 if (value
& ICC_CTLR_EL3_CBPR_EL1NS
) {
1860 cs
->icc_ctlr_el1
[GICV3_NS
] |= ICC_CTLR_EL1_CBPR
;
1863 cs
->icc_ctlr_el1
[GICV3_S
] &= (ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
);
1864 if (value
& ICC_CTLR_EL3_EOIMODE_EL1S
) {
1865 cs
->icc_ctlr_el1
[GICV3_S
] |= ICC_CTLR_EL1_EOIMODE
;
1867 if (value
& ICC_CTLR_EL3_CBPR_EL1S
) {
1868 cs
->icc_ctlr_el1
[GICV3_S
] |= ICC_CTLR_EL1_CBPR
;
1871 /* The only bit stored in icc_ctlr_el3 which is writeable is EOIMODE_EL3: */
1872 mask
= ICC_CTLR_EL3_EOIMODE_EL3
;
1874 cs
->icc_ctlr_el3
&= ~mask
;
1875 cs
->icc_ctlr_el3
|= (value
& mask
);
1876 gicv3_cpuif_update(cs
);
1879 static CPAccessResult
gicv3_irqfiq_access(CPUARMState
*env
,
1880 const ARMCPRegInfo
*ri
, bool isread
)
1882 CPAccessResult r
= CP_ACCESS_OK
;
1883 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1884 int el
= arm_current_el(env
);
1886 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_TC
) &&
1887 el
== 1 && !arm_is_secure_below_el3(env
)) {
1888 /* Takes priority over a possible EL3 trap */
1889 return CP_ACCESS_TRAP_EL2
;
1892 if ((env
->cp15
.scr_el3
& (SCR_FIQ
| SCR_IRQ
)) == (SCR_FIQ
| SCR_IRQ
)) {
1895 if (arm_is_secure_below_el3(env
) ||
1896 ((env
->cp15
.hcr_el2
& (HCR_IMO
| HCR_FMO
)) == 0)) {
1897 r
= CP_ACCESS_TRAP_EL3
;
1901 r
= CP_ACCESS_TRAP_EL3
;
1904 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
1905 r
= CP_ACCESS_TRAP_EL3
;
1909 g_assert_not_reached();
1913 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
1919 static CPAccessResult
gicv3_dir_access(CPUARMState
*env
,
1920 const ARMCPRegInfo
*ri
, bool isread
)
1922 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1924 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_TDIR
) &&
1925 arm_current_el(env
) == 1 && !arm_is_secure_below_el3(env
)) {
1926 /* Takes priority over a possible EL3 trap */
1927 return CP_ACCESS_TRAP_EL2
;
1930 return gicv3_irqfiq_access(env
, ri
, isread
);
1933 static CPAccessResult
gicv3_sgi_access(CPUARMState
*env
,
1934 const ARMCPRegInfo
*ri
, bool isread
)
1936 if ((env
->cp15
.hcr_el2
& (HCR_IMO
| HCR_FMO
)) &&
1937 arm_current_el(env
) == 1 && !arm_is_secure_below_el3(env
)) {
1938 /* Takes priority over a possible EL3 trap */
1939 return CP_ACCESS_TRAP_EL2
;
1942 return gicv3_irqfiq_access(env
, ri
, isread
);
1945 static CPAccessResult
gicv3_fiq_access(CPUARMState
*env
,
1946 const ARMCPRegInfo
*ri
, bool isread
)
1948 CPAccessResult r
= CP_ACCESS_OK
;
1949 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1950 int el
= arm_current_el(env
);
1952 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_TALL0
) &&
1953 el
== 1 && !arm_is_secure_below_el3(env
)) {
1954 /* Takes priority over a possible EL3 trap */
1955 return CP_ACCESS_TRAP_EL2
;
1958 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
1961 if (arm_is_secure_below_el3(env
) ||
1962 ((env
->cp15
.hcr_el2
& HCR_FMO
) == 0)) {
1963 r
= CP_ACCESS_TRAP_EL3
;
1967 r
= CP_ACCESS_TRAP_EL3
;
1970 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
1971 r
= CP_ACCESS_TRAP_EL3
;
1975 g_assert_not_reached();
1979 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
1985 static CPAccessResult
gicv3_irq_access(CPUARMState
*env
,
1986 const ARMCPRegInfo
*ri
, bool isread
)
1988 CPAccessResult r
= CP_ACCESS_OK
;
1989 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1990 int el
= arm_current_el(env
);
1992 if ((cs
->ich_hcr_el2
& ICH_HCR_EL2_TALL1
) &&
1993 el
== 1 && !arm_is_secure_below_el3(env
)) {
1994 /* Takes priority over a possible EL3 trap */
1995 return CP_ACCESS_TRAP_EL2
;
1998 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
2001 if (arm_is_secure_below_el3(env
) ||
2002 ((env
->cp15
.hcr_el2
& HCR_IMO
) == 0)) {
2003 r
= CP_ACCESS_TRAP_EL3
;
2007 r
= CP_ACCESS_TRAP_EL3
;
2010 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
2011 r
= CP_ACCESS_TRAP_EL3
;
2015 g_assert_not_reached();
2019 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
2025 static void icc_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2027 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2029 cs
->icc_ctlr_el1
[GICV3_S
] = ICC_CTLR_EL1_A3V
|
2030 (1 << ICC_CTLR_EL1_IDBITS_SHIFT
) |
2031 (7 << ICC_CTLR_EL1_PRIBITS_SHIFT
);
2032 cs
->icc_ctlr_el1
[GICV3_NS
] = ICC_CTLR_EL1_A3V
|
2033 (1 << ICC_CTLR_EL1_IDBITS_SHIFT
) |
2034 (7 << ICC_CTLR_EL1_PRIBITS_SHIFT
);
2035 cs
->icc_pmr_el1
= 0;
2036 cs
->icc_bpr
[GICV3_G0
] = GIC_MIN_BPR
;
2037 cs
->icc_bpr
[GICV3_G1
] = GIC_MIN_BPR
;
2038 cs
->icc_bpr
[GICV3_G1NS
] = GIC_MIN_BPR_NS
;
2039 memset(cs
->icc_apr
, 0, sizeof(cs
->icc_apr
));
2040 memset(cs
->icc_igrpen
, 0, sizeof(cs
->icc_igrpen
));
2041 cs
->icc_ctlr_el3
= ICC_CTLR_EL3_NDS
| ICC_CTLR_EL3_A3V
|
2042 (1 << ICC_CTLR_EL3_IDBITS_SHIFT
) |
2043 (7 << ICC_CTLR_EL3_PRIBITS_SHIFT
);
2045 memset(cs
->ich_apr
, 0, sizeof(cs
->ich_apr
));
2046 cs
->ich_hcr_el2
= 0;
2047 memset(cs
->ich_lr_el2
, 0, sizeof(cs
->ich_lr_el2
));
2048 cs
->ich_vmcr_el2
= ICH_VMCR_EL2_VFIQEN
|
2049 ((icv_min_vbpr(cs
) + 1) << ICH_VMCR_EL2_VBPR1_SHIFT
) |
2050 (icv_min_vbpr(cs
) << ICH_VMCR_EL2_VBPR0_SHIFT
);
2053 static const ARMCPRegInfo gicv3_cpuif_reginfo
[] = {
2054 { .name
= "ICC_PMR_EL1", .state
= ARM_CP_STATE_BOTH
,
2055 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 6, .opc2
= 0,
2056 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2057 .access
= PL1_RW
, .accessfn
= gicv3_irqfiq_access
,
2058 .readfn
= icc_pmr_read
,
2059 .writefn
= icc_pmr_write
,
2060 /* We hang the whole cpu interface reset routine off here
2061 * rather than parcelling it out into one little function
2064 .resetfn
= icc_reset
,
2066 { .name
= "ICC_IAR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2067 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 0,
2068 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2069 .access
= PL1_R
, .accessfn
= gicv3_fiq_access
,
2070 .readfn
= icc_iar0_read
,
2072 { .name
= "ICC_EOIR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2073 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 1,
2074 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2075 .access
= PL1_W
, .accessfn
= gicv3_fiq_access
,
2076 .writefn
= icc_eoir_write
,
2078 { .name
= "ICC_HPPIR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2079 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 2,
2080 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2081 .access
= PL1_R
, .accessfn
= gicv3_fiq_access
,
2082 .readfn
= icc_hppir0_read
,
2084 { .name
= "ICC_BPR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2085 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 3,
2086 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2087 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2088 .readfn
= icc_bpr_read
,
2089 .writefn
= icc_bpr_write
,
2091 { .name
= "ICC_AP0R0_EL1", .state
= ARM_CP_STATE_BOTH
,
2092 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 4,
2093 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2094 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2095 .readfn
= icc_ap_read
,
2096 .writefn
= icc_ap_write
,
2098 { .name
= "ICC_AP0R1_EL1", .state
= ARM_CP_STATE_BOTH
,
2099 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 5,
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_AP0R2_EL1", .state
= ARM_CP_STATE_BOTH
,
2106 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 6,
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_AP0R3_EL1", .state
= ARM_CP_STATE_BOTH
,
2113 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 7,
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 /* All the ICC_AP1R*_EL1 registers are banked */
2120 { .name
= "ICC_AP1R0_EL1", .state
= ARM_CP_STATE_BOTH
,
2121 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 0,
2122 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2123 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2124 .readfn
= icc_ap_read
,
2125 .writefn
= icc_ap_write
,
2127 { .name
= "ICC_AP1R1_EL1", .state
= ARM_CP_STATE_BOTH
,
2128 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 1,
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_AP1R2_EL1", .state
= ARM_CP_STATE_BOTH
,
2135 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 2,
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_AP1R3_EL1", .state
= ARM_CP_STATE_BOTH
,
2142 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 3,
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_DIR_EL1", .state
= ARM_CP_STATE_BOTH
,
2149 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 1,
2150 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2151 .access
= PL1_W
, .accessfn
= gicv3_dir_access
,
2152 .writefn
= icc_dir_write
,
2154 { .name
= "ICC_RPR_EL1", .state
= ARM_CP_STATE_BOTH
,
2155 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 3,
2156 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2157 .access
= PL1_R
, .accessfn
= gicv3_irqfiq_access
,
2158 .readfn
= icc_rpr_read
,
2160 { .name
= "ICC_SGI1R_EL1", .state
= ARM_CP_STATE_AA64
,
2161 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 5,
2162 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2163 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2164 .writefn
= icc_sgi1r_write
,
2166 { .name
= "ICC_SGI1R",
2167 .cp
= 15, .opc1
= 0, .crm
= 12,
2168 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2169 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2170 .writefn
= icc_sgi1r_write
,
2172 { .name
= "ICC_ASGI1R_EL1", .state
= ARM_CP_STATE_AA64
,
2173 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 6,
2174 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2175 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2176 .writefn
= icc_asgi1r_write
,
2178 { .name
= "ICC_ASGI1R",
2179 .cp
= 15, .opc1
= 1, .crm
= 12,
2180 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2181 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2182 .writefn
= icc_asgi1r_write
,
2184 { .name
= "ICC_SGI0R_EL1", .state
= ARM_CP_STATE_AA64
,
2185 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 7,
2186 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2187 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2188 .writefn
= icc_sgi0r_write
,
2190 { .name
= "ICC_SGI0R",
2191 .cp
= 15, .opc1
= 2, .crm
= 12,
2192 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2193 .access
= PL1_W
, .accessfn
= gicv3_sgi_access
,
2194 .writefn
= icc_sgi0r_write
,
2196 { .name
= "ICC_IAR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2197 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 0,
2198 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2199 .access
= PL1_R
, .accessfn
= gicv3_irq_access
,
2200 .readfn
= icc_iar1_read
,
2202 { .name
= "ICC_EOIR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2203 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 1,
2204 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2205 .access
= PL1_W
, .accessfn
= gicv3_irq_access
,
2206 .writefn
= icc_eoir_write
,
2208 { .name
= "ICC_HPPIR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2209 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 2,
2210 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2211 .access
= PL1_R
, .accessfn
= gicv3_irq_access
,
2212 .readfn
= icc_hppir1_read
,
2214 /* This register is banked */
2215 { .name
= "ICC_BPR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2216 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 3,
2217 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2218 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2219 .readfn
= icc_bpr_read
,
2220 .writefn
= icc_bpr_write
,
2222 /* This register is banked */
2223 { .name
= "ICC_CTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
2224 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 4,
2225 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2226 .access
= PL1_RW
, .accessfn
= gicv3_irqfiq_access
,
2227 .readfn
= icc_ctlr_el1_read
,
2228 .writefn
= icc_ctlr_el1_write
,
2230 { .name
= "ICC_SRE_EL1", .state
= ARM_CP_STATE_BOTH
,
2231 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 5,
2232 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
2234 /* We don't support IRQ/FIQ bypass and system registers are
2235 * always enabled, so all our bits are RAZ/WI or RAO/WI.
2236 * This register is banked but since it's constant we don't
2237 * need to do anything special.
2241 { .name
= "ICC_IGRPEN0_EL1", .state
= ARM_CP_STATE_BOTH
,
2242 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 6,
2243 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2244 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
2245 .readfn
= icc_igrpen_read
,
2246 .writefn
= icc_igrpen_write
,
2248 /* This register is banked */
2249 { .name
= "ICC_IGRPEN1_EL1", .state
= ARM_CP_STATE_BOTH
,
2250 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 7,
2251 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2252 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
2253 .readfn
= icc_igrpen_read
,
2254 .writefn
= icc_igrpen_write
,
2256 { .name
= "ICC_SRE_EL2", .state
= ARM_CP_STATE_BOTH
,
2257 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 5,
2258 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
2260 /* We don't support IRQ/FIQ bypass and system registers are
2261 * always enabled, so all our bits are RAZ/WI or RAO/WI.
2265 { .name
= "ICC_CTLR_EL3", .state
= ARM_CP_STATE_BOTH
,
2266 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 4,
2267 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2269 .readfn
= icc_ctlr_el3_read
,
2270 .writefn
= icc_ctlr_el3_write
,
2272 { .name
= "ICC_SRE_EL3", .state
= ARM_CP_STATE_BOTH
,
2273 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 5,
2274 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
2276 /* We don't support IRQ/FIQ bypass and system registers are
2277 * always enabled, so all our bits are RAZ/WI or RAO/WI.
2281 { .name
= "ICC_IGRPEN1_EL3", .state
= ARM_CP_STATE_BOTH
,
2282 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 7,
2283 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2285 .readfn
= icc_igrpen1_el3_read
,
2286 .writefn
= icc_igrpen1_el3_write
,
2291 static uint64_t ich_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2293 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2294 int regno
= ri
->opc2
& 3;
2295 int grp
= ri
->crm
& 1 ? GICV3_G0
: GICV3_G1NS
;
2298 value
= cs
->ich_apr
[grp
][regno
];
2299 trace_gicv3_ich_ap_read(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
2303 static void ich_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2306 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2307 int regno
= ri
->opc2
& 3;
2308 int grp
= ri
->crm
& 1 ? GICV3_G0
: GICV3_G1NS
;
2310 trace_gicv3_ich_ap_write(ri
->crm
& 1, regno
, gicv3_redist_affid(cs
), value
);
2312 cs
->ich_apr
[grp
][regno
] = value
& 0xFFFFFFFFU
;
2313 gicv3_cpuif_virt_update(cs
);
2316 static uint64_t ich_hcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2318 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2319 uint64_t value
= cs
->ich_hcr_el2
;
2321 trace_gicv3_ich_hcr_read(gicv3_redist_affid(cs
), value
);
2325 static void ich_hcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2328 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2330 trace_gicv3_ich_hcr_write(gicv3_redist_affid(cs
), value
);
2332 value
&= ICH_HCR_EL2_EN
| ICH_HCR_EL2_UIE
| ICH_HCR_EL2_LRENPIE
|
2333 ICH_HCR_EL2_NPIE
| ICH_HCR_EL2_VGRP0EIE
| ICH_HCR_EL2_VGRP0DIE
|
2334 ICH_HCR_EL2_VGRP1EIE
| ICH_HCR_EL2_VGRP1DIE
| ICH_HCR_EL2_TC
|
2335 ICH_HCR_EL2_TALL0
| ICH_HCR_EL2_TALL1
| ICH_HCR_EL2_TSEI
|
2336 ICH_HCR_EL2_TDIR
| ICH_HCR_EL2_EOICOUNT_MASK
;
2338 cs
->ich_hcr_el2
= value
;
2339 gicv3_cpuif_virt_update(cs
);
2342 static uint64_t ich_vmcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2344 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2345 uint64_t value
= cs
->ich_vmcr_el2
;
2347 trace_gicv3_ich_vmcr_read(gicv3_redist_affid(cs
), value
);
2351 static void ich_vmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2354 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2356 trace_gicv3_ich_vmcr_write(gicv3_redist_affid(cs
), value
);
2358 value
&= ICH_VMCR_EL2_VENG0
| ICH_VMCR_EL2_VENG1
| ICH_VMCR_EL2_VCBPR
|
2359 ICH_VMCR_EL2_VEOIM
| ICH_VMCR_EL2_VBPR1_MASK
|
2360 ICH_VMCR_EL2_VBPR0_MASK
| ICH_VMCR_EL2_VPMR_MASK
;
2361 value
|= ICH_VMCR_EL2_VFIQEN
;
2363 cs
->ich_vmcr_el2
= value
;
2364 /* Enforce "writing BPRs to less than minimum sets them to the minimum"
2365 * by reading and writing back the fields.
2367 write_vbpr(cs
, GICV3_G1
, read_vbpr(cs
, GICV3_G0
));
2368 write_vbpr(cs
, GICV3_G1
, read_vbpr(cs
, GICV3_G1
));
2370 gicv3_cpuif_virt_update(cs
);
2373 static uint64_t ich_lr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2375 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2376 int regno
= ri
->opc2
| ((ri
->crm
& 1) << 3);
2379 /* This read function handles all of:
2380 * 64-bit reads of the whole LR
2381 * 32-bit reads of the low half of the LR
2382 * 32-bit reads of the high half of the LR
2384 if (ri
->state
== ARM_CP_STATE_AA32
) {
2385 if (ri
->crm
>= 14) {
2386 value
= extract64(cs
->ich_lr_el2
[regno
], 32, 32);
2387 trace_gicv3_ich_lrc_read(regno
, gicv3_redist_affid(cs
), value
);
2389 value
= extract64(cs
->ich_lr_el2
[regno
], 0, 32);
2390 trace_gicv3_ich_lr32_read(regno
, gicv3_redist_affid(cs
), value
);
2393 value
= cs
->ich_lr_el2
[regno
];
2394 trace_gicv3_ich_lr_read(regno
, gicv3_redist_affid(cs
), value
);
2400 static void ich_lr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2403 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2404 int regno
= ri
->opc2
| ((ri
->crm
& 1) << 3);
2406 /* This write function handles all of:
2407 * 64-bit writes to the whole LR
2408 * 32-bit writes to the low half of the LR
2409 * 32-bit writes to the high half of the LR
2411 if (ri
->state
== ARM_CP_STATE_AA32
) {
2412 if (ri
->crm
>= 14) {
2413 trace_gicv3_ich_lrc_write(regno
, gicv3_redist_affid(cs
), value
);
2414 value
= deposit64(cs
->ich_lr_el2
[regno
], 32, 32, value
);
2416 trace_gicv3_ich_lr32_write(regno
, gicv3_redist_affid(cs
), value
);
2417 value
= deposit64(cs
->ich_lr_el2
[regno
], 0, 32, value
);
2420 trace_gicv3_ich_lr_write(regno
, gicv3_redist_affid(cs
), value
);
2423 /* Enforce RES0 bits in priority field */
2424 if (cs
->vpribits
< 8) {
2425 value
= deposit64(value
, ICH_LR_EL2_PRIORITY_SHIFT
,
2426 8 - cs
->vpribits
, 0);
2429 cs
->ich_lr_el2
[regno
] = value
;
2430 gicv3_cpuif_virt_update(cs
);
2433 static uint64_t ich_vtr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2435 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2438 value
= ((cs
->num_list_regs
- 1) << ICH_VTR_EL2_LISTREGS_SHIFT
)
2439 | ICH_VTR_EL2_TDS
| ICH_VTR_EL2_NV4
| ICH_VTR_EL2_A3V
2440 | (1 << ICH_VTR_EL2_IDBITS_SHIFT
)
2441 | ((cs
->vprebits
- 1) << ICH_VTR_EL2_PREBITS_SHIFT
)
2442 | ((cs
->vpribits
- 1) << ICH_VTR_EL2_PRIBITS_SHIFT
);
2444 trace_gicv3_ich_vtr_read(gicv3_redist_affid(cs
), value
);
2448 static uint64_t ich_misr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2450 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2451 uint64_t value
= maintenance_interrupt_state(cs
);
2453 trace_gicv3_ich_misr_read(gicv3_redist_affid(cs
), value
);
2457 static uint64_t ich_eisr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2459 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2460 uint64_t value
= eoi_maintenance_interrupt_state(cs
, NULL
);
2462 trace_gicv3_ich_eisr_read(gicv3_redist_affid(cs
), value
);
2466 static uint64_t ich_elrsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2468 GICv3CPUState
*cs
= icc_cs_from_env(env
);
2472 for (i
= 0; i
< cs
->num_list_regs
; i
++) {
2473 uint64_t lr
= cs
->ich_lr_el2
[i
];
2475 if ((lr
& ICH_LR_EL2_STATE_MASK
) == 0 &&
2476 ((lr
& ICH_LR_EL2_HW
) != 0 || (lr
& ICH_LR_EL2_EOI
) == 0)) {
2481 trace_gicv3_ich_elrsr_read(gicv3_redist_affid(cs
), value
);
2485 static const ARMCPRegInfo gicv3_cpuif_hcr_reginfo
[] = {
2486 { .name
= "ICH_AP0R0_EL2", .state
= ARM_CP_STATE_BOTH
,
2487 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 8, .opc2
= 0,
2488 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2490 .readfn
= ich_ap_read
,
2491 .writefn
= ich_ap_write
,
2493 { .name
= "ICH_AP1R0_EL2", .state
= ARM_CP_STATE_BOTH
,
2494 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 0,
2495 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2497 .readfn
= ich_ap_read
,
2498 .writefn
= ich_ap_write
,
2500 { .name
= "ICH_HCR_EL2", .state
= ARM_CP_STATE_BOTH
,
2501 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 0,
2502 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2504 .readfn
= ich_hcr_read
,
2505 .writefn
= ich_hcr_write
,
2507 { .name
= "ICH_VTR_EL2", .state
= ARM_CP_STATE_BOTH
,
2508 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 1,
2509 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2511 .readfn
= ich_vtr_read
,
2513 { .name
= "ICH_MISR_EL2", .state
= ARM_CP_STATE_BOTH
,
2514 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 2,
2515 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2517 .readfn
= ich_misr_read
,
2519 { .name
= "ICH_EISR_EL2", .state
= ARM_CP_STATE_BOTH
,
2520 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 3,
2521 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2523 .readfn
= ich_eisr_read
,
2525 { .name
= "ICH_ELRSR_EL2", .state
= ARM_CP_STATE_BOTH
,
2526 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 5,
2527 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2529 .readfn
= ich_elrsr_read
,
2531 { .name
= "ICH_VMCR_EL2", .state
= ARM_CP_STATE_BOTH
,
2532 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 11, .opc2
= 7,
2533 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2535 .readfn
= ich_vmcr_read
,
2536 .writefn
= ich_vmcr_write
,
2541 static const ARMCPRegInfo gicv3_cpuif_ich_apxr1_reginfo
[] = {
2542 { .name
= "ICH_AP0R1_EL2", .state
= ARM_CP_STATE_BOTH
,
2543 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 8, .opc2
= 1,
2544 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2546 .readfn
= ich_ap_read
,
2547 .writefn
= ich_ap_write
,
2549 { .name
= "ICH_AP1R1_EL2", .state
= ARM_CP_STATE_BOTH
,
2550 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 1,
2551 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2553 .readfn
= ich_ap_read
,
2554 .writefn
= ich_ap_write
,
2559 static const ARMCPRegInfo gicv3_cpuif_ich_apxr23_reginfo
[] = {
2560 { .name
= "ICH_AP0R2_EL2", .state
= ARM_CP_STATE_BOTH
,
2561 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 8, .opc2
= 2,
2562 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2564 .readfn
= ich_ap_read
,
2565 .writefn
= ich_ap_write
,
2567 { .name
= "ICH_AP0R3_EL2", .state
= ARM_CP_STATE_BOTH
,
2568 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 8, .opc2
= 3,
2569 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2571 .readfn
= ich_ap_read
,
2572 .writefn
= ich_ap_write
,
2574 { .name
= "ICH_AP1R2_EL2", .state
= ARM_CP_STATE_BOTH
,
2575 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 2,
2576 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2578 .readfn
= ich_ap_read
,
2579 .writefn
= ich_ap_write
,
2581 { .name
= "ICH_AP1R3_EL2", .state
= ARM_CP_STATE_BOTH
,
2582 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 3,
2583 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2585 .readfn
= ich_ap_read
,
2586 .writefn
= ich_ap_write
,
2591 static void gicv3_cpuif_el_change_hook(ARMCPU
*cpu
, void *opaque
)
2593 GICv3CPUState
*cs
= opaque
;
2595 gicv3_cpuif_update(cs
);
2598 void gicv3_init_cpuif(GICv3State
*s
)
2600 /* Called from the GICv3 realize function; register our system
2601 * registers with the CPU
2605 for (i
= 0; i
< s
->num_cpu
; i
++) {
2606 ARMCPU
*cpu
= ARM_CPU(qemu_get_cpu(i
));
2607 GICv3CPUState
*cs
= &s
->cpu
[i
];
2609 /* Note that we can't just use the GICv3CPUState as an opaque pointer
2610 * in define_arm_cp_regs_with_opaque(), because when we're called back
2611 * it might be with code translated by CPU 0 but run by CPU 1, in
2612 * which case we'd get the wrong value.
2613 * So instead we define the regs with no ri->opaque info, and
2614 * get back to the GICv3CPUState from the CPUARMState.
2616 define_arm_cp_regs(cpu
, gicv3_cpuif_reginfo
);
2617 if (arm_feature(&cpu
->env
, ARM_FEATURE_EL2
)
2618 && cpu
->gic_num_lrs
) {
2621 cs
->maintenance_irq
= cpu
->gicv3_maintenance_interrupt
;
2623 cs
->num_list_regs
= cpu
->gic_num_lrs
;
2624 cs
->vpribits
= cpu
->gic_vpribits
;
2625 cs
->vprebits
= cpu
->gic_vprebits
;
2627 /* Check against architectural constraints: getting these
2628 * wrong would be a bug in the CPU code defining these,
2629 * and the implementation relies on them holding.
2631 g_assert(cs
->vprebits
<= cs
->vpribits
);
2632 g_assert(cs
->vprebits
>= 5 && cs
->vprebits
<= 7);
2633 g_assert(cs
->vpribits
>= 5 && cs
->vpribits
<= 8);
2635 define_arm_cp_regs(cpu
, gicv3_cpuif_hcr_reginfo
);
2637 for (j
= 0; j
< cs
->num_list_regs
; j
++) {
2638 /* Note that the AArch64 LRs are 64-bit; the AArch32 LRs
2639 * are split into two cp15 regs, LR (the low part, with the
2640 * same encoding as the AArch64 LR) and LRC (the high part).
2642 ARMCPRegInfo lr_regset
[] = {
2643 { .name
= "ICH_LRn_EL2", .state
= ARM_CP_STATE_BOTH
,
2644 .opc0
= 3, .opc1
= 4, .crn
= 12,
2645 .crm
= 12 + (j
>> 3), .opc2
= j
& 7,
2646 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2648 .readfn
= ich_lr_read
,
2649 .writefn
= ich_lr_write
,
2651 { .name
= "ICH_LRCn_EL2", .state
= ARM_CP_STATE_AA32
,
2652 .cp
= 15, .opc1
= 4, .crn
= 12,
2653 .crm
= 14 + (j
>> 3), .opc2
= j
& 7,
2654 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
2656 .readfn
= ich_lr_read
,
2657 .writefn
= ich_lr_write
,
2661 define_arm_cp_regs(cpu
, lr_regset
);
2663 if (cs
->vprebits
>= 6) {
2664 define_arm_cp_regs(cpu
, gicv3_cpuif_ich_apxr1_reginfo
);
2666 if (cs
->vprebits
== 7) {
2667 define_arm_cp_regs(cpu
, gicv3_cpuif_ich_apxr23_reginfo
);
2670 arm_register_el_change_hook(cpu
, gicv3_cpuif_el_change_hook
, cs
);