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"
17 #include "gicv3_internal.h"
20 static GICv3CPUState
*icc_cs_from_env(CPUARMState
*env
)
22 /* Given the CPU, find the right GICv3CPUState struct.
23 * Since we registered the CPU interface with the EL change hook as
24 * the opaque pointer, we can just directly get from the CPU to it.
26 return arm_get_el_change_hook_opaque(arm_env_get_cpu(env
));
29 static bool gicv3_use_ns_bank(CPUARMState
*env
)
31 /* Return true if we should use the NonSecure bank for a banked GIC
32 * CPU interface register. Note that this differs from the
33 * access_secure_reg() function because GICv3 banked registers are
34 * banked even for AArch64, unlike the other CPU system registers.
36 return !arm_is_secure_below_el3(env
);
39 static int icc_highest_active_prio(GICv3CPUState
*cs
)
41 /* Calculate the current running priority based on the set bits
42 * in the Active Priority Registers.
46 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[0]); i
++) {
47 uint32_t apr
= cs
->icc_apr
[GICV3_G0
][i
] |
48 cs
->icc_apr
[GICV3_G1
][i
] | cs
->icc_apr
[GICV3_G1NS
][i
];
53 return (i
* 32 + ctz32(apr
)) << (GIC_MIN_BPR
+ 1);
55 /* No current active interrupts: return idle priority */
59 static uint32_t icc_gprio_mask(GICv3CPUState
*cs
, int group
)
61 /* Return a mask word which clears the subpriority bits from
62 * a priority value for an interrupt in the specified group.
63 * This depends on the BPR value:
64 * a BPR of 0 means the group priority bits are [7:1];
65 * a BPR of 1 means they are [7:2], and so on down to
66 * a BPR of 7 meaning no group priority bits at all.
67 * Which BPR to use depends on the group of the interrupt and
68 * the current ICC_CTLR.CBPR settings.
70 if ((group
== GICV3_G1
&& cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
) ||
71 (group
== GICV3_G1NS
&&
72 cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
76 return ~0U << ((cs
->icc_bpr
[group
] & 7) + 1);
79 static bool icc_no_enabled_hppi(GICv3CPUState
*cs
)
81 /* Return true if there is no pending interrupt, or the
82 * highest priority pending interrupt is in a group which has been
83 * disabled at the CPU interface by the ICC_IGRPEN* register enable bits.
85 return cs
->hppi
.prio
== 0xff || (cs
->icc_igrpen
[cs
->hppi
.grp
] == 0);
88 static bool icc_hppi_can_preempt(GICv3CPUState
*cs
)
90 /* Return true if we have a pending interrupt of sufficient
91 * priority to preempt.
96 if (icc_no_enabled_hppi(cs
)) {
100 if (cs
->hppi
.prio
>= cs
->icc_pmr_el1
) {
101 /* Priority mask masks this interrupt */
105 rprio
= icc_highest_active_prio(cs
);
107 /* No currently running interrupt so we can preempt */
111 mask
= icc_gprio_mask(cs
, cs
->hppi
.grp
);
113 /* We only preempt a running interrupt if the pending interrupt's
114 * group priority is sufficient (the subpriorities are not considered).
116 if ((cs
->hppi
.prio
& mask
) < (rprio
& mask
)) {
123 void gicv3_cpuif_update(GICv3CPUState
*cs
)
125 /* Tell the CPU about its highest priority pending interrupt */
128 ARMCPU
*cpu
= ARM_CPU(cs
->cpu
);
129 CPUARMState
*env
= &cpu
->env
;
131 trace_gicv3_cpuif_update(gicv3_redist_affid(cs
), cs
->hppi
.irq
,
132 cs
->hppi
.grp
, cs
->hppi
.prio
);
134 if (cs
->hppi
.grp
== GICV3_G1
&& !arm_feature(env
, ARM_FEATURE_EL3
)) {
135 /* If a Security-enabled GIC sends a G1S interrupt to a
136 * Security-disabled CPU, we must treat it as if it were G0.
138 cs
->hppi
.grp
= GICV3_G0
;
141 if (icc_hppi_can_preempt(cs
)) {
142 /* We have an interrupt: should we signal it as IRQ or FIQ?
143 * This is described in the GICv3 spec section 4.6.2.
147 switch (cs
->hppi
.grp
) {
152 isfiq
= (!arm_is_secure(env
) ||
153 (arm_current_el(env
) == 3 && arm_el_is_aa64(env
, 3)));
156 isfiq
= arm_is_secure(env
);
159 g_assert_not_reached();
169 trace_gicv3_cpuif_set_irqs(gicv3_redist_affid(cs
), fiqlevel
, irqlevel
);
171 qemu_set_irq(cs
->parent_fiq
, fiqlevel
);
172 qemu_set_irq(cs
->parent_irq
, irqlevel
);
175 static uint64_t icc_pmr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
177 GICv3CPUState
*cs
= icc_cs_from_env(env
);
178 uint32_t value
= cs
->icc_pmr_el1
;
180 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_is_secure(env
) &&
181 (env
->cp15
.scr_el3
& SCR_FIQ
)) {
182 /* NS access and Group 0 is inaccessible to NS: return the
183 * NS view of the current priority
186 /* Secure priorities not visible to NS */
188 } else if (value
!= 0xff) {
189 value
= (value
<< 1) & 0xff;
193 trace_gicv3_icc_pmr_read(gicv3_redist_affid(cs
), value
);
198 static void icc_pmr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
201 GICv3CPUState
*cs
= icc_cs_from_env(env
);
203 trace_gicv3_icc_pmr_write(gicv3_redist_affid(cs
), value
);
207 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_is_secure(env
) &&
208 (env
->cp15
.scr_el3
& SCR_FIQ
)) {
209 /* NS access and Group 0 is inaccessible to NS: return the
210 * NS view of the current priority
212 if (!(cs
->icc_pmr_el1
& 0x80)) {
213 /* Current PMR in the secure range, don't allow NS to change it */
216 value
= (value
>> 1) & 0x80;
218 cs
->icc_pmr_el1
= value
;
219 gicv3_cpuif_update(cs
);
222 static void icc_activate_irq(GICv3CPUState
*cs
, int irq
)
224 /* Move the interrupt from the Pending state to Active, and update
225 * the Active Priority Registers
227 uint32_t mask
= icc_gprio_mask(cs
, cs
->hppi
.grp
);
228 int prio
= cs
->hppi
.prio
& mask
;
229 int aprbit
= prio
>> 1;
230 int regno
= aprbit
/ 32;
231 int regbit
= aprbit
% 32;
233 cs
->icc_apr
[cs
->hppi
.grp
][regno
] |= (1 << regbit
);
235 if (irq
< GIC_INTERNAL
) {
236 cs
->gicr_iactiver0
= deposit32(cs
->gicr_iactiver0
, irq
, 1, 1);
237 cs
->gicr_ipendr0
= deposit32(cs
->gicr_ipendr0
, irq
, 1, 0);
238 gicv3_redist_update(cs
);
240 gicv3_gicd_active_set(cs
->gic
, irq
);
241 gicv3_gicd_pending_clear(cs
->gic
, irq
);
242 gicv3_update(cs
->gic
, irq
, 1);
246 static uint64_t icc_hppir0_value(GICv3CPUState
*cs
, CPUARMState
*env
)
248 /* Return the highest priority pending interrupt register value
253 if (cs
->hppi
.prio
== 0xff) {
254 return INTID_SPURIOUS
;
257 /* Check whether we can return the interrupt or if we should return
258 * a special identifier, as per the CheckGroup0ForSpecialIdentifiers
259 * pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM
262 irq_is_secure
= (!(cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) &&
263 (cs
->hppi
.grp
!= GICV3_G1NS
));
265 if (cs
->hppi
.grp
!= GICV3_G0
&& !arm_is_el3_or_mon(env
)) {
266 return INTID_SPURIOUS
;
268 if (irq_is_secure
&& !arm_is_secure(env
)) {
269 /* Secure interrupts not visible to Nonsecure */
270 return INTID_SPURIOUS
;
273 if (cs
->hppi
.grp
!= GICV3_G0
) {
274 /* Indicate to EL3 that there's a Group 1 interrupt for the other
277 return irq_is_secure
? INTID_SECURE
: INTID_NONSECURE
;
283 static uint64_t icc_hppir1_value(GICv3CPUState
*cs
, CPUARMState
*env
)
285 /* Return the highest priority pending interrupt register value
290 if (cs
->hppi
.prio
== 0xff) {
291 return INTID_SPURIOUS
;
294 /* Check whether we can return the interrupt or if we should return
295 * a special identifier, as per the CheckGroup1ForSpecialIdentifiers
296 * pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM
299 irq_is_secure
= (!(cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) &&
300 (cs
->hppi
.grp
!= GICV3_G1NS
));
302 if (cs
->hppi
.grp
== GICV3_G0
) {
303 /* Group 0 interrupts not visible via HPPIR1 */
304 return INTID_SPURIOUS
;
307 if (!arm_is_secure(env
)) {
308 /* Secure interrupts not visible in Non-secure */
309 return INTID_SPURIOUS
;
311 } else if (!arm_is_el3_or_mon(env
) && arm_is_secure(env
)) {
312 /* Group 1 non-secure interrupts not visible in Secure EL1 */
313 return INTID_SPURIOUS
;
319 static uint64_t icc_iar0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
321 GICv3CPUState
*cs
= icc_cs_from_env(env
);
324 if (!icc_hppi_can_preempt(cs
)) {
325 intid
= INTID_SPURIOUS
;
327 intid
= icc_hppir0_value(cs
, env
);
330 if (!(intid
>= INTID_SECURE
&& intid
<= INTID_SPURIOUS
)) {
331 icc_activate_irq(cs
, intid
);
334 trace_gicv3_icc_iar0_read(gicv3_redist_affid(cs
), intid
);
338 static uint64_t icc_iar1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
340 GICv3CPUState
*cs
= icc_cs_from_env(env
);
343 if (!icc_hppi_can_preempt(cs
)) {
344 intid
= INTID_SPURIOUS
;
346 intid
= icc_hppir1_value(cs
, env
);
349 if (!(intid
>= INTID_SECURE
&& intid
<= INTID_SPURIOUS
)) {
350 icc_activate_irq(cs
, intid
);
353 trace_gicv3_icc_iar1_read(gicv3_redist_affid(cs
), intid
);
357 static void icc_drop_prio(GICv3CPUState
*cs
, int grp
)
359 /* Drop the priority of the currently active interrupt in
360 * the specified group.
362 * Note that we can guarantee (because of the requirement to nest
363 * ICC_IAR reads [which activate an interrupt and raise priority]
364 * with ICC_EOIR writes [which drop the priority for the interrupt])
365 * that the interrupt we're being called for is the highest priority
366 * active interrupt, meaning that it has the lowest set bit in the
369 * If the guest does not honour the ordering constraints then the
370 * behaviour of the GIC is UNPREDICTABLE, which for us means that
371 * the values of the APR registers might become incorrect and the
372 * running priority will be wrong, so interrupts that should preempt
373 * might not do so, and interrupts that should not preempt might do so.
377 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[grp
]); i
++) {
378 uint64_t *papr
= &cs
->icc_apr
[grp
][i
];
383 /* Clear the lowest set bit */
388 /* running priority change means we need an update for this cpu i/f */
389 gicv3_cpuif_update(cs
);
392 static bool icc_eoi_split(CPUARMState
*env
, GICv3CPUState
*cs
)
394 /* Return true if we should split priority drop and interrupt
395 * deactivation, ie whether the relevant EOIMode bit is set.
397 if (arm_is_el3_or_mon(env
)) {
398 return cs
->icc_ctlr_el3
& ICC_CTLR_EL3_EOIMODE_EL3
;
400 if (arm_is_secure_below_el3(env
)) {
401 return cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_EOIMODE
;
403 return cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
;
407 static int icc_highest_active_group(GICv3CPUState
*cs
)
409 /* Return the group with the highest priority active interrupt.
410 * We can do this by just comparing the APRs to see which one
411 * has the lowest set bit.
412 * (If more than one group is active at the same priority then
413 * we're in UNPREDICTABLE territory.)
417 for (i
= 0; i
< ARRAY_SIZE(cs
->icc_apr
[0]); i
++) {
418 int g0ctz
= ctz32(cs
->icc_apr
[GICV3_G0
][i
]);
419 int g1ctz
= ctz32(cs
->icc_apr
[GICV3_G1
][i
]);
420 int g1nsctz
= ctz32(cs
->icc_apr
[GICV3_G1NS
][i
]);
422 if (g1nsctz
< g0ctz
&& g1nsctz
< g1ctz
) {
432 /* No set active bits? UNPREDICTABLE; return -1 so the caller
433 * ignores the spurious EOI attempt.
438 static void icc_deactivate_irq(GICv3CPUState
*cs
, int irq
)
440 if (irq
< GIC_INTERNAL
) {
441 cs
->gicr_iactiver0
= deposit32(cs
->gicr_iactiver0
, irq
, 1, 0);
442 gicv3_redist_update(cs
);
444 gicv3_gicd_active_clear(cs
->gic
, irq
);
445 gicv3_update(cs
->gic
, irq
, 1);
449 static void icc_eoir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
452 /* End of Interrupt */
453 GICv3CPUState
*cs
= icc_cs_from_env(env
);
454 int irq
= value
& 0xffffff;
457 trace_gicv3_icc_eoir_write(gicv3_redist_affid(cs
), value
);
464 if (arm_is_secure(env
)) {
471 if (irq
>= cs
->gic
->num_irq
) {
472 /* This handles two cases:
473 * 1. If software writes the ID of a spurious interrupt [ie 1020-1023]
474 * to the GICC_EOIR, the GIC ignores that write.
475 * 2. If software writes the number of a non-existent interrupt
476 * this must be a subcase of "value written does not match the last
477 * valid interrupt value read from the Interrupt Acknowledge
478 * register" and so this is UNPREDICTABLE. We choose to ignore it.
483 if (icc_highest_active_group(cs
) != grp
) {
487 icc_drop_prio(cs
, grp
);
489 if (!icc_eoi_split(env
, cs
)) {
490 /* Priority drop and deactivate not split: deactivate irq now */
491 icc_deactivate_irq(cs
, irq
);
495 static uint64_t icc_hppir0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
497 GICv3CPUState
*cs
= icc_cs_from_env(env
);
498 uint64_t value
= icc_hppir0_value(cs
, env
);
500 trace_gicv3_icc_hppir0_read(gicv3_redist_affid(cs
), value
);
504 static uint64_t icc_hppir1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
506 GICv3CPUState
*cs
= icc_cs_from_env(env
);
507 uint64_t value
= icc_hppir1_value(cs
, env
);
509 trace_gicv3_icc_hppir1_read(gicv3_redist_affid(cs
), value
);
513 static uint64_t icc_bpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
515 GICv3CPUState
*cs
= icc_cs_from_env(env
);
516 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1
;
520 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
524 if (grp
== GICV3_G1
&& !arm_is_el3_or_mon(env
) &&
525 (cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
)) {
526 /* CBPR_EL1S means secure EL1 or AArch32 EL3 !Mon BPR1 accesses
532 if (grp
== GICV3_G1NS
&& arm_current_el(env
) < 3 &&
533 (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
534 /* reads return bpr0 + 1 sat to 7, writes ignored */
539 bpr
= cs
->icc_bpr
[grp
];
545 trace_gicv3_icc_bpr_read(gicv3_redist_affid(cs
), bpr
);
550 static void icc_bpr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
553 GICv3CPUState
*cs
= icc_cs_from_env(env
);
554 int grp
= (ri
->crm
== 8) ? GICV3_G0
: GICV3_G1
;
556 trace_gicv3_icc_pmr_write(gicv3_redist_affid(cs
), value
);
558 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
562 if (grp
== GICV3_G1
&& !arm_is_el3_or_mon(env
) &&
563 (cs
->icc_ctlr_el1
[GICV3_S
] & ICC_CTLR_EL1_CBPR
)) {
564 /* CBPR_EL1S means secure EL1 or AArch32 EL3 !Mon BPR1 accesses
570 if (grp
== GICV3_G1NS
&& arm_current_el(env
) < 3 &&
571 (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
)) {
572 /* reads return bpr0 + 1 sat to 7, writes ignored */
576 cs
->icc_bpr
[grp
] = value
& 7;
577 gicv3_cpuif_update(cs
);
580 static uint64_t icc_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
582 GICv3CPUState
*cs
= icc_cs_from_env(env
);
585 int regno
= ri
->opc2
& 3;
586 int grp
= ri
->crm
& 1 ? GICV3_G0
: GICV3_G1
;
588 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
592 value
= cs
->icc_apr
[grp
][regno
];
594 trace_gicv3_icc_ap_read(regno
, gicv3_redist_affid(cs
), value
);
598 static void icc_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
601 GICv3CPUState
*cs
= icc_cs_from_env(env
);
603 int regno
= ri
->opc2
& 3;
604 int grp
= ri
->crm
& 1 ? GICV3_G0
: GICV3_G1
;
606 trace_gicv3_icc_ap_write(regno
, gicv3_redist_affid(cs
), value
);
608 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
612 /* It's not possible to claim that a Non-secure interrupt is active
613 * at a priority outside the Non-secure range (128..255), since this
614 * would otherwise allow malicious NS code to block delivery of S interrupts
615 * by writing a bad value to these registers.
617 if (grp
== GICV3_G1NS
&& regno
< 2 && arm_feature(env
, ARM_FEATURE_EL3
)) {
621 cs
->icc_apr
[grp
][regno
] = value
& 0xFFFFFFFFU
;
622 gicv3_cpuif_update(cs
);
625 static void icc_dir_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
628 /* Deactivate interrupt */
629 GICv3CPUState
*cs
= icc_cs_from_env(env
);
630 int irq
= value
& 0xffffff;
631 bool irq_is_secure
, single_sec_state
, irq_is_grp0
;
632 bool route_fiq_to_el3
, route_irq_to_el3
, route_fiq_to_el2
, route_irq_to_el2
;
634 trace_gicv3_icc_dir_write(gicv3_redist_affid(cs
), value
);
636 if (irq
>= cs
->gic
->num_irq
) {
637 /* Also catches special interrupt numbers and LPIs */
641 if (!icc_eoi_split(env
, cs
)) {
645 int grp
= gicv3_irq_group(cs
->gic
, cs
, irq
);
647 single_sec_state
= cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
;
648 irq_is_secure
= !single_sec_state
&& (grp
!= GICV3_G1NS
);
649 irq_is_grp0
= grp
== GICV3_G0
;
651 /* Check whether we're allowed to deactivate this interrupt based
652 * on its group and the current CPU state.
653 * These checks are laid out to correspond to the spec's pseudocode.
655 route_fiq_to_el3
= env
->cp15
.scr_el3
& SCR_FIQ
;
656 route_irq_to_el3
= env
->cp15
.scr_el3
& SCR_IRQ
;
657 /* No need to include !IsSecure in route_*_to_el2 as it's only
658 * tested in cases where we know !IsSecure is true.
660 route_fiq_to_el2
= env
->cp15
.hcr_el2
& HCR_FMO
;
661 route_irq_to_el2
= env
->cp15
.hcr_el2
& HCR_FMO
;
663 switch (arm_current_el(env
)) {
667 if (single_sec_state
&& irq_is_grp0
&& !route_fiq_to_el3
) {
670 if (!irq_is_secure
&& !irq_is_grp0
&& !route_irq_to_el3
) {
675 if (!arm_is_secure_below_el3(env
)) {
676 if (single_sec_state
&& irq_is_grp0
&&
677 !route_fiq_to_el3
&& !route_fiq_to_el2
) {
680 if (!irq_is_secure
&& !irq_is_grp0
&&
681 !route_irq_to_el3
&& !route_irq_to_el2
) {
685 if (irq_is_grp0
&& !route_fiq_to_el3
) {
689 (!irq_is_secure
|| !single_sec_state
) &&
696 g_assert_not_reached();
699 icc_deactivate_irq(cs
, irq
);
702 static uint64_t icc_rpr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
704 GICv3CPUState
*cs
= icc_cs_from_env(env
);
705 int prio
= icc_highest_active_prio(cs
);
707 if (arm_feature(env
, ARM_FEATURE_EL3
) &&
708 !arm_is_secure(env
) && (env
->cp15
.scr_el3
& SCR_FIQ
)) {
709 /* NS GIC access and Group 0 is inaccessible to NS */
711 /* NS mustn't see priorities in the Secure half of the range */
713 } else if (prio
!= 0xff) {
714 /* Non-idle priority: show the Non-secure view of it */
715 prio
= (prio
<< 1) & 0xff;
719 trace_gicv3_icc_rpr_read(gicv3_redist_affid(cs
), prio
);
723 static void icc_generate_sgi(CPUARMState
*env
, GICv3CPUState
*cs
,
724 uint64_t value
, int grp
, bool ns
)
726 GICv3State
*s
= cs
->gic
;
728 /* Extract Aff3/Aff2/Aff1 and shift into the bottom 24 bits */
729 uint64_t aff
= extract64(value
, 48, 8) << 16 |
730 extract64(value
, 32, 8) << 8 |
731 extract64(value
, 16, 8);
732 uint32_t targetlist
= extract64(value
, 0, 16);
733 uint32_t irq
= extract64(value
, 24, 4);
734 bool irm
= extract64(value
, 40, 1);
737 if (grp
== GICV3_G1
&& s
->gicd_ctlr
& GICD_CTLR_DS
) {
738 /* If GICD_CTLR.DS == 1, the Distributor treats Secure Group 1
739 * interrupts as Group 0 interrupts and must send Secure Group 0
740 * interrupts to the target CPUs.
745 trace_gicv3_icc_generate_sgi(gicv3_redist_affid(cs
), irq
, irm
,
748 for (i
= 0; i
< s
->num_cpu
; i
++) {
749 GICv3CPUState
*ocs
= &s
->cpu
[i
];
752 /* IRM == 1 : route to all CPUs except self */
757 /* IRM == 0 : route to Aff3.Aff2.Aff1.n for all n in [0..15]
758 * where the corresponding bit is set in targetlist
762 if (ocs
->gicr_typer
>> 40 != aff
) {
765 aff0
= extract64(ocs
->gicr_typer
, 32, 8);
766 if (aff0
> 15 || extract32(targetlist
, aff0
, 1) == 0) {
771 /* The redistributor will check against its own GICR_NSACR as needed */
772 gicv3_redist_send_sgi(ocs
, grp
, irq
, ns
);
776 static void icc_sgi0r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
779 /* Generate Secure Group 0 SGI. */
780 GICv3CPUState
*cs
= icc_cs_from_env(env
);
781 bool ns
= !arm_is_secure(env
);
783 icc_generate_sgi(env
, cs
, value
, GICV3_G0
, ns
);
786 static void icc_sgi1r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
789 /* Generate Group 1 SGI for the current Security state */
790 GICv3CPUState
*cs
= icc_cs_from_env(env
);
792 bool ns
= !arm_is_secure(env
);
794 grp
= ns
? GICV3_G1NS
: GICV3_G1
;
795 icc_generate_sgi(env
, cs
, value
, grp
, ns
);
798 static void icc_asgi1r_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
801 /* Generate Group 1 SGI for the Security state that is not
804 GICv3CPUState
*cs
= icc_cs_from_env(env
);
806 bool ns
= !arm_is_secure(env
);
808 grp
= ns
? GICV3_G1
: GICV3_G1NS
;
809 icc_generate_sgi(env
, cs
, value
, grp
, ns
);
812 static uint64_t icc_igrpen_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
814 GICv3CPUState
*cs
= icc_cs_from_env(env
);
815 int grp
= ri
->opc2
& 1 ? GICV3_G1
: GICV3_G0
;
818 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
822 value
= cs
->icc_igrpen
[grp
];
823 trace_gicv3_icc_igrpen_read(gicv3_redist_affid(cs
), value
);
827 static void icc_igrpen_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
830 GICv3CPUState
*cs
= icc_cs_from_env(env
);
831 int grp
= ri
->opc2
& 1 ? GICV3_G1
: GICV3_G0
;
833 trace_gicv3_icc_igrpen_write(gicv3_redist_affid(cs
), value
);
835 if (grp
== GICV3_G1
&& gicv3_use_ns_bank(env
)) {
839 cs
->icc_igrpen
[grp
] = value
& ICC_IGRPEN_ENABLE
;
840 gicv3_cpuif_update(cs
);
843 static uint64_t icc_igrpen1_el3_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
845 GICv3CPUState
*cs
= icc_cs_from_env(env
);
847 /* IGRPEN1_EL3 bits 0 and 1 are r/w aliases into IGRPEN1_EL1 NS and S */
848 return cs
->icc_igrpen
[GICV3_G1NS
] | (cs
->icc_igrpen
[GICV3_G1
] << 1);
851 static void icc_igrpen1_el3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
854 GICv3CPUState
*cs
= icc_cs_from_env(env
);
856 trace_gicv3_icc_igrpen1_el3_write(gicv3_redist_affid(cs
), value
);
858 /* IGRPEN1_EL3 bits 0 and 1 are r/w aliases into IGRPEN1_EL1 NS and S */
859 cs
->icc_igrpen
[GICV3_G1NS
] = extract32(value
, 0, 1);
860 cs
->icc_igrpen
[GICV3_G1
] = extract32(value
, 1, 1);
861 gicv3_cpuif_update(cs
);
864 static uint64_t icc_ctlr_el1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
866 GICv3CPUState
*cs
= icc_cs_from_env(env
);
867 int bank
= gicv3_use_ns_bank(env
) ? GICV3_NS
: GICV3_S
;
870 value
= cs
->icc_ctlr_el1
[bank
];
871 trace_gicv3_icc_ctlr_read(gicv3_redist_affid(cs
), value
);
875 static void icc_ctlr_el1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
878 GICv3CPUState
*cs
= icc_cs_from_env(env
);
879 int bank
= gicv3_use_ns_bank(env
) ? GICV3_NS
: GICV3_S
;
882 trace_gicv3_icc_ctlr_write(gicv3_redist_affid(cs
), value
);
884 /* Only CBPR and EOIMODE can be RW;
885 * for us PMHE is RAZ/WI (we don't implement 1-of-N interrupts or
886 * the asseciated priority-based routing of them);
887 * if EL3 is implemented and GICD_CTLR.DS == 0, then PMHE and CBPR are RO.
889 if (arm_feature(env
, ARM_FEATURE_EL3
) &&
890 ((cs
->gic
->gicd_ctlr
& GICD_CTLR_DS
) == 0)) {
891 mask
= ICC_CTLR_EL1_EOIMODE
;
893 mask
= ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
;
896 cs
->icc_ctlr_el1
[bank
] &= ~mask
;
897 cs
->icc_ctlr_el1
[bank
] |= (value
& mask
);
898 gicv3_cpuif_update(cs
);
902 static uint64_t icc_ctlr_el3_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
904 GICv3CPUState
*cs
= icc_cs_from_env(env
);
907 value
= cs
->icc_ctlr_el3
;
908 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
) {
909 value
|= ICC_CTLR_EL3_EOIMODE_EL1NS
;
911 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
) {
912 value
|= ICC_CTLR_EL3_CBPR_EL1NS
;
914 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_EOIMODE
) {
915 value
|= ICC_CTLR_EL3_EOIMODE_EL1S
;
917 if (cs
->icc_ctlr_el1
[GICV3_NS
] & ICC_CTLR_EL1_CBPR
) {
918 value
|= ICC_CTLR_EL3_CBPR_EL1S
;
921 trace_gicv3_icc_ctlr_el3_read(gicv3_redist_affid(cs
), value
);
925 static void icc_ctlr_el3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
928 GICv3CPUState
*cs
= icc_cs_from_env(env
);
931 trace_gicv3_icc_ctlr_el3_write(gicv3_redist_affid(cs
), value
);
933 /* *_EL1NS and *_EL1S bits are aliases into the ICC_CTLR_EL1 bits. */
934 cs
->icc_ctlr_el1
[GICV3_NS
] &= (ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
);
935 if (value
& ICC_CTLR_EL3_EOIMODE_EL1NS
) {
936 cs
->icc_ctlr_el1
[GICV3_NS
] |= ICC_CTLR_EL1_EOIMODE
;
938 if (value
& ICC_CTLR_EL3_CBPR_EL1NS
) {
939 cs
->icc_ctlr_el1
[GICV3_NS
] |= ICC_CTLR_EL1_CBPR
;
942 cs
->icc_ctlr_el1
[GICV3_S
] &= (ICC_CTLR_EL1_CBPR
| ICC_CTLR_EL1_EOIMODE
);
943 if (value
& ICC_CTLR_EL3_EOIMODE_EL1S
) {
944 cs
->icc_ctlr_el1
[GICV3_S
] |= ICC_CTLR_EL1_EOIMODE
;
946 if (value
& ICC_CTLR_EL3_CBPR_EL1S
) {
947 cs
->icc_ctlr_el1
[GICV3_S
] |= ICC_CTLR_EL1_CBPR
;
950 /* The only bit stored in icc_ctlr_el3 which is writeable is EOIMODE_EL3: */
951 mask
= ICC_CTLR_EL3_EOIMODE_EL3
;
953 cs
->icc_ctlr_el3
&= ~mask
;
954 cs
->icc_ctlr_el3
|= (value
& mask
);
955 gicv3_cpuif_update(cs
);
958 static CPAccessResult
gicv3_irqfiq_access(CPUARMState
*env
,
959 const ARMCPRegInfo
*ri
, bool isread
)
961 CPAccessResult r
= CP_ACCESS_OK
;
963 if ((env
->cp15
.scr_el3
& (SCR_FIQ
| SCR_IRQ
)) == (SCR_FIQ
| SCR_IRQ
)) {
964 switch (arm_current_el(env
)) {
966 if (arm_is_secure_below_el3(env
) ||
967 ((env
->cp15
.hcr_el2
& (HCR_IMO
| HCR_FMO
)) == 0)) {
968 r
= CP_ACCESS_TRAP_EL3
;
972 r
= CP_ACCESS_TRAP_EL3
;
975 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
976 r
= CP_ACCESS_TRAP_EL3
;
980 g_assert_not_reached();
984 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
990 static CPAccessResult
gicv3_fiq_access(CPUARMState
*env
,
991 const ARMCPRegInfo
*ri
, bool isread
)
993 CPAccessResult r
= CP_ACCESS_OK
;
995 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
996 switch (arm_current_el(env
)) {
998 if (arm_is_secure_below_el3(env
) ||
999 ((env
->cp15
.hcr_el2
& HCR_FMO
) == 0)) {
1000 r
= CP_ACCESS_TRAP_EL3
;
1004 r
= CP_ACCESS_TRAP_EL3
;
1007 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
1008 r
= CP_ACCESS_TRAP_EL3
;
1012 g_assert_not_reached();
1016 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
1022 static CPAccessResult
gicv3_irq_access(CPUARMState
*env
,
1023 const ARMCPRegInfo
*ri
, bool isread
)
1025 CPAccessResult r
= CP_ACCESS_OK
;
1027 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
1028 switch (arm_current_el(env
)) {
1030 if (arm_is_secure_below_el3(env
) ||
1031 ((env
->cp15
.hcr_el2
& HCR_IMO
) == 0)) {
1032 r
= CP_ACCESS_TRAP_EL3
;
1036 r
= CP_ACCESS_TRAP_EL3
;
1039 if (!is_a64(env
) && !arm_is_el3_or_mon(env
)) {
1040 r
= CP_ACCESS_TRAP_EL3
;
1044 g_assert_not_reached();
1048 if (r
== CP_ACCESS_TRAP_EL3
&& !arm_el_is_aa64(env
, 3)) {
1054 static void icc_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1056 GICv3CPUState
*cs
= icc_cs_from_env(env
);
1058 cs
->icc_ctlr_el1
[GICV3_S
] = ICC_CTLR_EL1_A3V
|
1059 (1 << ICC_CTLR_EL1_IDBITS_SHIFT
) |
1060 (7 << ICC_CTLR_EL1_PRIBITS_SHIFT
);
1061 cs
->icc_ctlr_el1
[GICV3_NS
] = ICC_CTLR_EL1_A3V
|
1062 (1 << ICC_CTLR_EL1_IDBITS_SHIFT
) |
1063 (7 << ICC_CTLR_EL1_PRIBITS_SHIFT
);
1064 cs
->icc_pmr_el1
= 0;
1065 cs
->icc_bpr
[GICV3_G0
] = GIC_MIN_BPR
;
1066 cs
->icc_bpr
[GICV3_G1
] = GIC_MIN_BPR
;
1067 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
1068 cs
->icc_bpr
[GICV3_G1NS
] = GIC_MIN_BPR_NS
;
1070 cs
->icc_bpr
[GICV3_G1NS
] = GIC_MIN_BPR
;
1072 memset(cs
->icc_apr
, 0, sizeof(cs
->icc_apr
));
1073 memset(cs
->icc_igrpen
, 0, sizeof(cs
->icc_igrpen
));
1074 cs
->icc_ctlr_el3
= ICC_CTLR_EL3_NDS
| ICC_CTLR_EL3_A3V
|
1075 (1 << ICC_CTLR_EL3_IDBITS_SHIFT
) |
1076 (7 << ICC_CTLR_EL3_PRIBITS_SHIFT
);
1079 static const ARMCPRegInfo gicv3_cpuif_reginfo
[] = {
1080 { .name
= "ICC_PMR_EL1", .state
= ARM_CP_STATE_BOTH
,
1081 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 6, .opc2
= 0,
1082 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1083 .access
= PL1_RW
, .accessfn
= gicv3_irqfiq_access
,
1084 .readfn
= icc_pmr_read
,
1085 .writefn
= icc_pmr_write
,
1086 /* We hang the whole cpu interface reset routine off here
1087 * rather than parcelling it out into one little function
1090 .resetfn
= icc_reset
,
1092 { .name
= "ICC_IAR0_EL1", .state
= ARM_CP_STATE_BOTH
,
1093 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 0,
1094 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1095 .access
= PL1_R
, .accessfn
= gicv3_fiq_access
,
1096 .readfn
= icc_iar0_read
,
1098 { .name
= "ICC_EOIR0_EL1", .state
= ARM_CP_STATE_BOTH
,
1099 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 1,
1100 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1101 .access
= PL1_W
, .accessfn
= gicv3_fiq_access
,
1102 .writefn
= icc_eoir_write
,
1104 { .name
= "ICC_HPPIR0_EL1", .state
= ARM_CP_STATE_BOTH
,
1105 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 2,
1106 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1107 .access
= PL1_R
, .accessfn
= gicv3_fiq_access
,
1108 .readfn
= icc_hppir0_read
,
1110 { .name
= "ICC_BPR0_EL1", .state
= ARM_CP_STATE_BOTH
,
1111 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 3,
1112 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1113 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
1114 .fieldoffset
= offsetof(GICv3CPUState
, icc_bpr
[GICV3_G0
]),
1115 .writefn
= icc_bpr_write
,
1117 { .name
= "ICC_AP0R0_EL1", .state
= ARM_CP_STATE_BOTH
,
1118 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 4,
1119 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1120 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
1121 .fieldoffset
= offsetof(GICv3CPUState
, icc_apr
[GICV3_G0
][0]),
1122 .writefn
= icc_ap_write
,
1124 { .name
= "ICC_AP0R1_EL1", .state
= ARM_CP_STATE_BOTH
,
1125 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 5,
1126 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1127 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
1128 .fieldoffset
= offsetof(GICv3CPUState
, icc_apr
[GICV3_G0
][1]),
1129 .writefn
= icc_ap_write
,
1131 { .name
= "ICC_AP0R2_EL1", .state
= ARM_CP_STATE_BOTH
,
1132 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 6,
1133 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1134 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
1135 .fieldoffset
= offsetof(GICv3CPUState
, icc_apr
[GICV3_G0
][2]),
1136 .writefn
= icc_ap_write
,
1138 { .name
= "ICC_AP0R3_EL1", .state
= ARM_CP_STATE_BOTH
,
1139 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 8, .opc2
= 7,
1140 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1141 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
1142 .fieldoffset
= offsetof(GICv3CPUState
, icc_apr
[GICV3_G0
][3]),
1143 .writefn
= icc_ap_write
,
1145 /* All the ICC_AP1R*_EL1 registers are banked */
1146 { .name
= "ICC_AP1R0_EL1", .state
= ARM_CP_STATE_BOTH
,
1147 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 0,
1148 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1149 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
1150 .readfn
= icc_ap_read
,
1151 .writefn
= icc_ap_write
,
1153 { .name
= "ICC_AP1R1_EL1", .state
= ARM_CP_STATE_BOTH
,
1154 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 1,
1155 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1156 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
1157 .readfn
= icc_ap_read
,
1158 .writefn
= icc_ap_write
,
1160 { .name
= "ICC_AP1R2_EL1", .state
= ARM_CP_STATE_BOTH
,
1161 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 2,
1162 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1163 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
1164 .readfn
= icc_ap_read
,
1165 .writefn
= icc_ap_write
,
1167 { .name
= "ICC_AP1R3_EL1", .state
= ARM_CP_STATE_BOTH
,
1168 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 9, .opc2
= 3,
1169 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1170 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
1171 .readfn
= icc_ap_read
,
1172 .writefn
= icc_ap_write
,
1174 { .name
= "ICC_DIR_EL1", .state
= ARM_CP_STATE_BOTH
,
1175 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 1,
1176 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1177 .access
= PL1_W
, .accessfn
= gicv3_irqfiq_access
,
1178 .writefn
= icc_dir_write
,
1180 { .name
= "ICC_RPR_EL1", .state
= ARM_CP_STATE_BOTH
,
1181 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 3,
1182 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1183 .access
= PL1_R
, .accessfn
= gicv3_irqfiq_access
,
1184 .readfn
= icc_rpr_read
,
1186 { .name
= "ICC_SGI1R_EL1", .state
= ARM_CP_STATE_AA64
,
1187 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 5,
1188 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1189 .access
= PL1_W
, .accessfn
= gicv3_irqfiq_access
,
1190 .writefn
= icc_sgi1r_write
,
1192 { .name
= "ICC_SGI1R",
1193 .cp
= 15, .opc1
= 0, .crm
= 12,
1194 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
1195 .access
= PL1_W
, .accessfn
= gicv3_irqfiq_access
,
1196 .writefn
= icc_sgi1r_write
,
1198 { .name
= "ICC_ASGI1R_EL1", .state
= ARM_CP_STATE_AA64
,
1199 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 6,
1200 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1201 .access
= PL1_W
, .accessfn
= gicv3_irqfiq_access
,
1202 .writefn
= icc_asgi1r_write
,
1204 { .name
= "ICC_ASGI1R",
1205 .cp
= 15, .opc1
= 1, .crm
= 12,
1206 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
1207 .access
= PL1_W
, .accessfn
= gicv3_irqfiq_access
,
1208 .writefn
= icc_asgi1r_write
,
1210 { .name
= "ICC_SGI0R_EL1", .state
= ARM_CP_STATE_AA64
,
1211 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 11, .opc2
= 7,
1212 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1213 .access
= PL1_W
, .accessfn
= gicv3_irqfiq_access
,
1214 .writefn
= icc_sgi0r_write
,
1216 { .name
= "ICC_SGI0R",
1217 .cp
= 15, .opc1
= 2, .crm
= 12,
1218 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_NO_RAW
,
1219 .access
= PL1_W
, .accessfn
= gicv3_irqfiq_access
,
1220 .writefn
= icc_sgi0r_write
,
1222 { .name
= "ICC_IAR1_EL1", .state
= ARM_CP_STATE_BOTH
,
1223 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 0,
1224 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1225 .access
= PL1_R
, .accessfn
= gicv3_irq_access
,
1226 .readfn
= icc_iar1_read
,
1228 { .name
= "ICC_EOIR1_EL1", .state
= ARM_CP_STATE_BOTH
,
1229 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 1,
1230 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1231 .access
= PL1_W
, .accessfn
= gicv3_irq_access
,
1232 .writefn
= icc_eoir_write
,
1234 { .name
= "ICC_HPPIR1_EL1", .state
= ARM_CP_STATE_BOTH
,
1235 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 2,
1236 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1237 .access
= PL1_R
, .accessfn
= gicv3_irq_access
,
1238 .readfn
= icc_hppir1_read
,
1240 /* This register is banked */
1241 { .name
= "ICC_BPR1_EL1", .state
= ARM_CP_STATE_BOTH
,
1242 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 3,
1243 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1244 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
1245 .readfn
= icc_bpr_read
,
1246 .writefn
= icc_bpr_write
,
1248 /* This register is banked */
1249 { .name
= "ICC_CTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
1250 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 4,
1251 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1252 .access
= PL1_RW
, .accessfn
= gicv3_irqfiq_access
,
1253 .readfn
= icc_ctlr_el1_read
,
1254 .writefn
= icc_ctlr_el1_write
,
1256 { .name
= "ICC_SRE_EL1", .state
= ARM_CP_STATE_BOTH
,
1257 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 5,
1258 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
1260 /* We don't support IRQ/FIQ bypass and system registers are
1261 * always enabled, so all our bits are RAZ/WI or RAO/WI.
1262 * This register is banked but since it's constant we don't
1263 * need to do anything special.
1267 { .name
= "ICC_IGRPEN0_EL1", .state
= ARM_CP_STATE_BOTH
,
1268 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 6,
1269 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1270 .access
= PL1_RW
, .accessfn
= gicv3_fiq_access
,
1271 .fieldoffset
= offsetof(GICv3CPUState
, icc_igrpen
[GICV3_G0
]),
1272 .writefn
= icc_igrpen_write
,
1274 /* This register is banked */
1275 { .name
= "ICC_IGRPEN1_EL1", .state
= ARM_CP_STATE_BOTH
,
1276 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 12, .opc2
= 7,
1277 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1278 .access
= PL1_RW
, .accessfn
= gicv3_irq_access
,
1279 .readfn
= icc_igrpen_read
,
1280 .writefn
= icc_igrpen_write
,
1282 { .name
= "ICC_SRE_EL2", .state
= ARM_CP_STATE_BOTH
,
1283 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 9, .opc2
= 5,
1284 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
1286 /* We don't support IRQ/FIQ bypass and system registers are
1287 * always enabled, so all our bits are RAZ/WI or RAO/WI.
1291 { .name
= "ICC_CTLR_EL3", .state
= ARM_CP_STATE_BOTH
,
1292 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 4,
1293 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1295 .fieldoffset
= offsetof(GICv3CPUState
, icc_ctlr_el3
),
1296 .readfn
= icc_ctlr_el3_read
,
1297 .writefn
= icc_ctlr_el3_write
,
1299 { .name
= "ICC_SRE_EL3", .state
= ARM_CP_STATE_BOTH
,
1300 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 5,
1301 .type
= ARM_CP_NO_RAW
| ARM_CP_CONST
,
1303 /* We don't support IRQ/FIQ bypass and system registers are
1304 * always enabled, so all our bits are RAZ/WI or RAO/WI.
1308 { .name
= "ICC_IGRPEN1_EL3", .state
= ARM_CP_STATE_BOTH
,
1309 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 12, .opc2
= 7,
1310 .type
= ARM_CP_IO
| ARM_CP_NO_RAW
,
1312 .readfn
= icc_igrpen1_el3_read
,
1313 .writefn
= icc_igrpen1_el3_write
,
1318 static void gicv3_cpuif_el_change_hook(ARMCPU
*cpu
, void *opaque
)
1320 GICv3CPUState
*cs
= opaque
;
1322 gicv3_cpuif_update(cs
);
1325 void gicv3_init_cpuif(GICv3State
*s
)
1327 /* Called from the GICv3 realize function; register our system
1328 * registers with the CPU
1332 for (i
= 0; i
< s
->num_cpu
; i
++) {
1333 ARMCPU
*cpu
= ARM_CPU(qemu_get_cpu(i
));
1334 GICv3CPUState
*cs
= &s
->cpu
[i
];
1336 /* Note that we can't just use the GICv3CPUState as an opaque pointer
1337 * in define_arm_cp_regs_with_opaque(), because when we're called back
1338 * it might be with code translated by CPU 0 but run by CPU 1, in
1339 * which case we'd get the wrong value.
1340 * So instead we define the regs with no ri->opaque info, and
1341 * get back to the GICv3CPUState from the ARMCPU by reading back
1342 * the opaque pointer from the el_change_hook, which we're going
1343 * to need to register anyway.
1345 define_arm_cp_regs(cpu
, gicv3_cpuif_reginfo
);
1346 arm_register_el_change_hook(cpu
, gicv3_cpuif_el_change_hook
, cs
);