xref: /qemu/hw/intc/arm_gicv3_kvm.c (revision 06b40d250ecfa1633209c2e431a7a38acfd03a98)
1a7bf3034SPavel Fedin /*
2a7bf3034SPavel Fedin  * ARM Generic Interrupt Controller using KVM in-kernel support
3a7bf3034SPavel Fedin  *
4a7bf3034SPavel Fedin  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5a7bf3034SPavel Fedin  * Written by Pavel Fedin
6a7bf3034SPavel Fedin  * Based on vGICv2 code by Peter Maydell
7a7bf3034SPavel Fedin  *
8a7bf3034SPavel Fedin  * This program is free software; you can redistribute it and/or modify
9a7bf3034SPavel Fedin  * it under the terms of the GNU General Public License as published by
10a7bf3034SPavel Fedin  * the Free Software Foundation, either version 2 of the License, or
11a7bf3034SPavel Fedin  * (at your option) any later version.
12a7bf3034SPavel Fedin  *
13a7bf3034SPavel Fedin  * This program is distributed in the hope that it will be useful,
14a7bf3034SPavel Fedin  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15a7bf3034SPavel Fedin  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16a7bf3034SPavel Fedin  * GNU General Public License for more details.
17a7bf3034SPavel Fedin  *
18a7bf3034SPavel Fedin  * You should have received a copy of the GNU General Public License along
19a7bf3034SPavel Fedin  * with this program; if not, see <http://www.gnu.org/licenses/>.
20a7bf3034SPavel Fedin  */
21a7bf3034SPavel Fedin 
228ef94f0bSPeter Maydell #include "qemu/osdep.h"
23da34e65cSMarkus Armbruster #include "qapi/error.h"
24a7bf3034SPavel Fedin #include "hw/intc/arm_gicv3_common.h"
25367b9f52SVijaya Kumar K #include "qemu/error-report.h"
260b8fa32fSMarkus Armbruster #include "qemu/module.h"
2732cad1ffSPhilippe Mathieu-Daudé #include "system/kvm.h"
2832cad1ffSPhilippe Mathieu-Daudé #include "system/runstate.h"
29a7bf3034SPavel Fedin #include "kvm_arm.h"
30367b9f52SVijaya Kumar K #include "gicv3_internal.h"
31a7bf3034SPavel Fedin #include "vgic_common.h"
32795c40b8SJuan Quintela #include "migration/blocker.h"
33db1015e9SEduardo Habkost #include "qom/object.h"
34cf7c6d10SRichard Henderson #include "target/arm/cpregs.h"
35cf7c6d10SRichard Henderson 
36a7bf3034SPavel Fedin 
37a7bf3034SPavel Fedin #ifdef DEBUG_GICV3_KVM
38a7bf3034SPavel Fedin #define DPRINTF(fmt, ...) \
39a7bf3034SPavel Fedin     do { fprintf(stderr, "kvm_gicv3: " fmt, ## __VA_ARGS__); } while (0)
40a7bf3034SPavel Fedin #else
41a7bf3034SPavel Fedin #define DPRINTF(fmt, ...) \
42a7bf3034SPavel Fedin     do { } while (0)
43a7bf3034SPavel Fedin #endif
44a7bf3034SPavel Fedin 
45a7bf3034SPavel Fedin #define TYPE_KVM_ARM_GICV3 "kvm-arm-gicv3"
46db1015e9SEduardo Habkost typedef struct KVMARMGICv3Class KVMARMGICv3Class;
47fa34a3c5SEduardo Habkost /* This is reusing the GICv3State typedef from ARM_GICV3_ITS_COMMON */
48fa34a3c5SEduardo Habkost DECLARE_OBJ_CHECKERS(GICv3State, KVMARMGICv3Class,
49fa34a3c5SEduardo Habkost                      KVM_ARM_GICV3, TYPE_KVM_ARM_GICV3)
50a7bf3034SPavel Fedin 
51367b9f52SVijaya Kumar K #define   KVM_DEV_ARM_VGIC_SYSREG(op0, op1, crn, crm, op2)         \
52367b9f52SVijaya Kumar K                              (ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \
53367b9f52SVijaya Kumar K                               ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \
54367b9f52SVijaya Kumar K                               ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \
55367b9f52SVijaya Kumar K                               ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \
56367b9f52SVijaya Kumar K                               ARM64_SYS_REG_SHIFT_MASK(op2, OP2))
57367b9f52SVijaya Kumar K 
58367b9f52SVijaya Kumar K #define ICC_PMR_EL1     \
59367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 4, 6, 0)
60367b9f52SVijaya Kumar K #define ICC_BPR0_EL1    \
61367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 8, 3)
62367b9f52SVijaya Kumar K #define ICC_AP0R_EL1(n) \
63367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 8, 4 | n)
64367b9f52SVijaya Kumar K #define ICC_AP1R_EL1(n) \
65367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 9, n)
66367b9f52SVijaya Kumar K #define ICC_BPR1_EL1    \
67367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 3)
68367b9f52SVijaya Kumar K #define ICC_CTLR_EL1    \
69367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 4)
70367b9f52SVijaya Kumar K #define ICC_SRE_EL1 \
71367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 5)
72367b9f52SVijaya Kumar K #define ICC_IGRPEN0_EL1 \
73367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 6)
74367b9f52SVijaya Kumar K #define ICC_IGRPEN1_EL1 \
75367b9f52SVijaya Kumar K     KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 7)
76367b9f52SVijaya Kumar K 
77db1015e9SEduardo Habkost struct KVMARMGICv3Class {
78a7bf3034SPavel Fedin     ARMGICv3CommonClass parent_class;
79a7bf3034SPavel Fedin     DeviceRealize parent_realize;
80823300f0SPeter Maydell     ResettablePhases parent_phases;
81db1015e9SEduardo Habkost };
82a7bf3034SPavel Fedin 
kvm_arm_gicv3_set_irq(void * opaque,int irq,int level)83a7bf3034SPavel Fedin static void kvm_arm_gicv3_set_irq(void *opaque, int irq, int level)
84a7bf3034SPavel Fedin {
85a7bf3034SPavel Fedin     GICv3State *s = (GICv3State *)opaque;
86a7bf3034SPavel Fedin 
87a7bf3034SPavel Fedin     kvm_arm_gic_set_irq(s->num_irq, irq, level);
88a7bf3034SPavel Fedin }
89a7bf3034SPavel Fedin 
90367b9f52SVijaya Kumar K #define KVM_VGIC_ATTR(reg, typer) \
91367b9f52SVijaya Kumar K     ((typer & KVM_DEV_ARM_VGIC_V3_MPIDR_MASK) | (reg))
92367b9f52SVijaya Kumar K 
kvm_gicd_access(GICv3State * s,int offset,uint32_t * val,bool write)93367b9f52SVijaya Kumar K static inline void kvm_gicd_access(GICv3State *s, int offset,
94367b9f52SVijaya Kumar K                                    uint32_t *val, bool write)
95367b9f52SVijaya Kumar K {
96367b9f52SVijaya Kumar K     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
97367b9f52SVijaya Kumar K                       KVM_VGIC_ATTR(offset, 0),
98556969e9SEric Auger                       val, write, &error_abort);
99367b9f52SVijaya Kumar K }
100367b9f52SVijaya Kumar K 
kvm_gicr_access(GICv3State * s,int offset,int cpu,uint32_t * val,bool write)101367b9f52SVijaya Kumar K static inline void kvm_gicr_access(GICv3State *s, int offset, int cpu,
102367b9f52SVijaya Kumar K                                    uint32_t *val, bool write)
103367b9f52SVijaya Kumar K {
104367b9f52SVijaya Kumar K     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_REDIST_REGS,
105367b9f52SVijaya Kumar K                       KVM_VGIC_ATTR(offset, s->cpu[cpu].gicr_typer),
106556969e9SEric Auger                       val, write, &error_abort);
107367b9f52SVijaya Kumar K }
108367b9f52SVijaya Kumar K 
kvm_gicc_access(GICv3State * s,uint64_t reg,int cpu,uint64_t * val,bool write)109367b9f52SVijaya Kumar K static inline void kvm_gicc_access(GICv3State *s, uint64_t reg, int cpu,
110367b9f52SVijaya Kumar K                                    uint64_t *val, bool write)
111367b9f52SVijaya Kumar K {
112367b9f52SVijaya Kumar K     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS,
113367b9f52SVijaya Kumar K                       KVM_VGIC_ATTR(reg, s->cpu[cpu].gicr_typer),
114556969e9SEric Auger                       val, write, &error_abort);
115367b9f52SVijaya Kumar K }
116367b9f52SVijaya Kumar K 
kvm_gic_line_level_access(GICv3State * s,int irq,int cpu,uint32_t * val,bool write)117367b9f52SVijaya Kumar K static inline void kvm_gic_line_level_access(GICv3State *s, int irq, int cpu,
118367b9f52SVijaya Kumar K                                              uint32_t *val, bool write)
119367b9f52SVijaya Kumar K {
120367b9f52SVijaya Kumar K     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO,
121367b9f52SVijaya Kumar K                       KVM_VGIC_ATTR(irq, s->cpu[cpu].gicr_typer) |
122367b9f52SVijaya Kumar K                       (VGIC_LEVEL_INFO_LINE_LEVEL <<
123367b9f52SVijaya Kumar K                        KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT),
124556969e9SEric Auger                       val, write, &error_abort);
125367b9f52SVijaya Kumar K }
126367b9f52SVijaya Kumar K 
127367b9f52SVijaya Kumar K /* Loop through each distributor IRQ related register; since bits
128367b9f52SVijaya Kumar K  * corresponding to SPIs and PPIs are RAZ/WI when affinity routing
129367b9f52SVijaya Kumar K  * is enabled, we skip those.
130367b9f52SVijaya Kumar K  */
131367b9f52SVijaya Kumar K #define for_each_dist_irq_reg(_irq, _max, _field_width) \
132367b9f52SVijaya Kumar K     for (_irq = GIC_INTERNAL; _irq < _max; _irq += (32 / _field_width))
133367b9f52SVijaya Kumar K 
kvm_dist_get_priority(GICv3State * s,uint32_t offset,uint8_t * bmp)134367b9f52SVijaya Kumar K static void kvm_dist_get_priority(GICv3State *s, uint32_t offset, uint8_t *bmp)
135367b9f52SVijaya Kumar K {
136367b9f52SVijaya Kumar K     uint32_t reg, *field;
137367b9f52SVijaya Kumar K     int irq;
138367b9f52SVijaya Kumar K 
1391dcf3675SShannon Zhao     /* For the KVM GICv3, affinity routing is always enabled, and the first 8
1401dcf3675SShannon Zhao      * GICD_IPRIORITYR<n> registers are always RAZ/WI. The corresponding
1411dcf3675SShannon Zhao      * functionality is replaced by GICR_IPRIORITYR<n>. It doesn't need to
1421dcf3675SShannon Zhao      * sync them. So it needs to skip the field of GIC_INTERNAL irqs in bmp and
1431dcf3675SShannon Zhao      * offset.
1441dcf3675SShannon Zhao      */
1451dcf3675SShannon Zhao     field = (uint32_t *)(bmp + GIC_INTERNAL);
1461dcf3675SShannon Zhao     offset += (GIC_INTERNAL * 8) / 8;
147367b9f52SVijaya Kumar K     for_each_dist_irq_reg(irq, s->num_irq, 8) {
148367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &reg, false);
149367b9f52SVijaya Kumar K         *field = reg;
150367b9f52SVijaya Kumar K         offset += 4;
151367b9f52SVijaya Kumar K         field++;
152367b9f52SVijaya Kumar K     }
153367b9f52SVijaya Kumar K }
154367b9f52SVijaya Kumar K 
kvm_dist_put_priority(GICv3State * s,uint32_t offset,uint8_t * bmp)155367b9f52SVijaya Kumar K static void kvm_dist_put_priority(GICv3State *s, uint32_t offset, uint8_t *bmp)
156367b9f52SVijaya Kumar K {
157367b9f52SVijaya Kumar K     uint32_t reg, *field;
158367b9f52SVijaya Kumar K     int irq;
159367b9f52SVijaya Kumar K 
1601dcf3675SShannon Zhao     /* For the KVM GICv3, affinity routing is always enabled, and the first 8
1611dcf3675SShannon Zhao      * GICD_IPRIORITYR<n> registers are always RAZ/WI. The corresponding
1621dcf3675SShannon Zhao      * functionality is replaced by GICR_IPRIORITYR<n>. It doesn't need to
1631dcf3675SShannon Zhao      * sync them. So it needs to skip the field of GIC_INTERNAL irqs in bmp and
1641dcf3675SShannon Zhao      * offset.
1651dcf3675SShannon Zhao      */
1661dcf3675SShannon Zhao     field = (uint32_t *)(bmp + GIC_INTERNAL);
1671dcf3675SShannon Zhao     offset += (GIC_INTERNAL * 8) / 8;
168367b9f52SVijaya Kumar K     for_each_dist_irq_reg(irq, s->num_irq, 8) {
169367b9f52SVijaya Kumar K         reg = *field;
170367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &reg, true);
171367b9f52SVijaya Kumar K         offset += 4;
172367b9f52SVijaya Kumar K         field++;
173367b9f52SVijaya Kumar K     }
174367b9f52SVijaya Kumar K }
175367b9f52SVijaya Kumar K 
kvm_dist_get_edge_trigger(GICv3State * s,uint32_t offset,uint32_t * bmp)176367b9f52SVijaya Kumar K static void kvm_dist_get_edge_trigger(GICv3State *s, uint32_t offset,
177367b9f52SVijaya Kumar K                                       uint32_t *bmp)
178367b9f52SVijaya Kumar K {
179367b9f52SVijaya Kumar K     uint32_t reg;
180367b9f52SVijaya Kumar K     int irq;
181367b9f52SVijaya Kumar K 
182910e2048SShannon Zhao     /* For the KVM GICv3, affinity routing is always enabled, and the first 2
183910e2048SShannon Zhao      * GICD_ICFGR<n> registers are always RAZ/WI. The corresponding
184910e2048SShannon Zhao      * functionality is replaced by GICR_ICFGR<n>. It doesn't need to sync
185910e2048SShannon Zhao      * them. So it should increase the offset to skip GIC_INTERNAL irqs.
186910e2048SShannon Zhao      * This matches the for_each_dist_irq_reg() macro which also skips the
187910e2048SShannon Zhao      * first GIC_INTERNAL irqs.
188910e2048SShannon Zhao      */
189910e2048SShannon Zhao     offset += (GIC_INTERNAL * 2) / 8;
190367b9f52SVijaya Kumar K     for_each_dist_irq_reg(irq, s->num_irq, 2) {
191367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &reg, false);
192367b9f52SVijaya Kumar K         reg = half_unshuffle32(reg >> 1);
193367b9f52SVijaya Kumar K         if (irq % 32 != 0) {
194367b9f52SVijaya Kumar K             reg = (reg << 16);
195367b9f52SVijaya Kumar K         }
196367b9f52SVijaya Kumar K         *gic_bmp_ptr32(bmp, irq) |=  reg;
197367b9f52SVijaya Kumar K         offset += 4;
198367b9f52SVijaya Kumar K     }
199367b9f52SVijaya Kumar K }
200367b9f52SVijaya Kumar K 
kvm_dist_put_edge_trigger(GICv3State * s,uint32_t offset,uint32_t * bmp)201367b9f52SVijaya Kumar K static void kvm_dist_put_edge_trigger(GICv3State *s, uint32_t offset,
202367b9f52SVijaya Kumar K                                       uint32_t *bmp)
203367b9f52SVijaya Kumar K {
204367b9f52SVijaya Kumar K     uint32_t reg;
205367b9f52SVijaya Kumar K     int irq;
206367b9f52SVijaya Kumar K 
207910e2048SShannon Zhao     /* For the KVM GICv3, affinity routing is always enabled, and the first 2
208910e2048SShannon Zhao      * GICD_ICFGR<n> registers are always RAZ/WI. The corresponding
209910e2048SShannon Zhao      * functionality is replaced by GICR_ICFGR<n>. It doesn't need to sync
210910e2048SShannon Zhao      * them. So it should increase the offset to skip GIC_INTERNAL irqs.
211910e2048SShannon Zhao      * This matches the for_each_dist_irq_reg() macro which also skips the
212910e2048SShannon Zhao      * first GIC_INTERNAL irqs.
213910e2048SShannon Zhao      */
214910e2048SShannon Zhao     offset += (GIC_INTERNAL * 2) / 8;
215367b9f52SVijaya Kumar K     for_each_dist_irq_reg(irq, s->num_irq, 2) {
216367b9f52SVijaya Kumar K         reg = *gic_bmp_ptr32(bmp, irq);
217367b9f52SVijaya Kumar K         if (irq % 32 != 0) {
218367b9f52SVijaya Kumar K             reg = (reg & 0xffff0000) >> 16;
219367b9f52SVijaya Kumar K         } else {
220367b9f52SVijaya Kumar K             reg = reg & 0xffff;
221367b9f52SVijaya Kumar K         }
222367b9f52SVijaya Kumar K         reg = half_shuffle32(reg) << 1;
223367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &reg, true);
224367b9f52SVijaya Kumar K         offset += 4;
225367b9f52SVijaya Kumar K     }
226367b9f52SVijaya Kumar K }
227367b9f52SVijaya Kumar K 
kvm_gic_get_line_level_bmp(GICv3State * s,uint32_t * bmp)228367b9f52SVijaya Kumar K static void kvm_gic_get_line_level_bmp(GICv3State *s, uint32_t *bmp)
229367b9f52SVijaya Kumar K {
230367b9f52SVijaya Kumar K     uint32_t reg;
231367b9f52SVijaya Kumar K     int irq;
232367b9f52SVijaya Kumar K 
233367b9f52SVijaya Kumar K     for_each_dist_irq_reg(irq, s->num_irq, 1) {
234367b9f52SVijaya Kumar K         kvm_gic_line_level_access(s, irq, 0, &reg, false);
235367b9f52SVijaya Kumar K         *gic_bmp_ptr32(bmp, irq) = reg;
236367b9f52SVijaya Kumar K     }
237367b9f52SVijaya Kumar K }
238367b9f52SVijaya Kumar K 
kvm_gic_put_line_level_bmp(GICv3State * s,uint32_t * bmp)239367b9f52SVijaya Kumar K static void kvm_gic_put_line_level_bmp(GICv3State *s, uint32_t *bmp)
240367b9f52SVijaya Kumar K {
241367b9f52SVijaya Kumar K     uint32_t reg;
242367b9f52SVijaya Kumar K     int irq;
243367b9f52SVijaya Kumar K 
244367b9f52SVijaya Kumar K     for_each_dist_irq_reg(irq, s->num_irq, 1) {
245367b9f52SVijaya Kumar K         reg = *gic_bmp_ptr32(bmp, irq);
246367b9f52SVijaya Kumar K         kvm_gic_line_level_access(s, irq, 0, &reg, true);
247367b9f52SVijaya Kumar K     }
248367b9f52SVijaya Kumar K }
249367b9f52SVijaya Kumar K 
250367b9f52SVijaya Kumar K /* Read a bitmap register group from the kernel VGIC. */
kvm_dist_getbmp(GICv3State * s,uint32_t offset,uint32_t * bmp)251367b9f52SVijaya Kumar K static void kvm_dist_getbmp(GICv3State *s, uint32_t offset, uint32_t *bmp)
252367b9f52SVijaya Kumar K {
253367b9f52SVijaya Kumar K     uint32_t reg;
254367b9f52SVijaya Kumar K     int irq;
255367b9f52SVijaya Kumar K 
256910e2048SShannon Zhao     /* For the KVM GICv3, affinity routing is always enabled, and the
257910e2048SShannon Zhao      * GICD_IGROUPR0/GICD_IGRPMODR0/GICD_ISENABLER0/GICD_ISPENDR0/
258910e2048SShannon Zhao      * GICD_ISACTIVER0 registers are always RAZ/WI. The corresponding
259910e2048SShannon Zhao      * functionality is replaced by the GICR registers. It doesn't need to sync
260910e2048SShannon Zhao      * them. So it should increase the offset to skip GIC_INTERNAL irqs.
261910e2048SShannon Zhao      * This matches the for_each_dist_irq_reg() macro which also skips the
262910e2048SShannon Zhao      * first GIC_INTERNAL irqs.
263910e2048SShannon Zhao      */
264910e2048SShannon Zhao     offset += (GIC_INTERNAL * 1) / 8;
265367b9f52SVijaya Kumar K     for_each_dist_irq_reg(irq, s->num_irq, 1) {
266367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &reg, false);
267367b9f52SVijaya Kumar K         *gic_bmp_ptr32(bmp, irq) = reg;
268367b9f52SVijaya Kumar K         offset += 4;
269367b9f52SVijaya Kumar K     }
270367b9f52SVijaya Kumar K }
271367b9f52SVijaya Kumar K 
kvm_dist_putbmp(GICv3State * s,uint32_t offset,uint32_t clroffset,uint32_t * bmp)272367b9f52SVijaya Kumar K static void kvm_dist_putbmp(GICv3State *s, uint32_t offset,
273367b9f52SVijaya Kumar K                             uint32_t clroffset, uint32_t *bmp)
274367b9f52SVijaya Kumar K {
275367b9f52SVijaya Kumar K     uint32_t reg;
276367b9f52SVijaya Kumar K     int irq;
277367b9f52SVijaya Kumar K 
278910e2048SShannon Zhao     /* For the KVM GICv3, affinity routing is always enabled, and the
279910e2048SShannon Zhao      * GICD_IGROUPR0/GICD_IGRPMODR0/GICD_ISENABLER0/GICD_ISPENDR0/
280910e2048SShannon Zhao      * GICD_ISACTIVER0 registers are always RAZ/WI. The corresponding
281910e2048SShannon Zhao      * functionality is replaced by the GICR registers. It doesn't need to sync
282910e2048SShannon Zhao      * them. So it should increase the offset and clroffset to skip GIC_INTERNAL
283910e2048SShannon Zhao      * irqs. This matches the for_each_dist_irq_reg() macro which also skips the
284910e2048SShannon Zhao      * first GIC_INTERNAL irqs.
285910e2048SShannon Zhao      */
286910e2048SShannon Zhao     offset += (GIC_INTERNAL * 1) / 8;
287910e2048SShannon Zhao     if (clroffset != 0) {
288910e2048SShannon Zhao         clroffset += (GIC_INTERNAL * 1) / 8;
289910e2048SShannon Zhao     }
290910e2048SShannon Zhao 
291367b9f52SVijaya Kumar K     for_each_dist_irq_reg(irq, s->num_irq, 1) {
292367b9f52SVijaya Kumar K         /* If this bitmap is a set/clear register pair, first write to the
293367b9f52SVijaya Kumar K          * clear-reg to clear all bits before using the set-reg to write
294367b9f52SVijaya Kumar K          * the 1 bits.
295367b9f52SVijaya Kumar K          */
296367b9f52SVijaya Kumar K         if (clroffset != 0) {
297367b9f52SVijaya Kumar K             reg = 0;
298367b9f52SVijaya Kumar K             kvm_gicd_access(s, clroffset, &reg, true);
29934ffacaeSShannon Zhao             clroffset += 4;
300367b9f52SVijaya Kumar K         }
301367b9f52SVijaya Kumar K         reg = *gic_bmp_ptr32(bmp, irq);
302367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &reg, true);
303367b9f52SVijaya Kumar K         offset += 4;
304367b9f52SVijaya Kumar K     }
305367b9f52SVijaya Kumar K }
306367b9f52SVijaya Kumar K 
kvm_arm_gicv3_check(GICv3State * s)307367b9f52SVijaya Kumar K static void kvm_arm_gicv3_check(GICv3State *s)
308367b9f52SVijaya Kumar K {
309367b9f52SVijaya Kumar K     uint32_t reg;
310367b9f52SVijaya Kumar K     uint32_t num_irq;
311367b9f52SVijaya Kumar K 
312367b9f52SVijaya Kumar K     /* Sanity checking s->num_irq */
313367b9f52SVijaya Kumar K     kvm_gicd_access(s, GICD_TYPER, &reg, false);
314367b9f52SVijaya Kumar K     num_irq = ((reg & 0x1f) + 1) * 32;
315367b9f52SVijaya Kumar K 
316367b9f52SVijaya Kumar K     if (num_irq < s->num_irq) {
317367b9f52SVijaya Kumar K         error_report("Model requests %u IRQs, but kernel supports max %u",
318367b9f52SVijaya Kumar K                      s->num_irq, num_irq);
319367b9f52SVijaya Kumar K         abort();
320367b9f52SVijaya Kumar K     }
321367b9f52SVijaya Kumar K }
322367b9f52SVijaya Kumar K 
kvm_arm_gicv3_put(GICv3State * s)323a7bf3034SPavel Fedin static void kvm_arm_gicv3_put(GICv3State *s)
324a7bf3034SPavel Fedin {
325367b9f52SVijaya Kumar K     uint32_t regl, regh, reg;
326367b9f52SVijaya Kumar K     uint64_t reg64, redist_typer;
327367b9f52SVijaya Kumar K     int ncpu, i;
328367b9f52SVijaya Kumar K 
329367b9f52SVijaya Kumar K     kvm_arm_gicv3_check(s);
330367b9f52SVijaya Kumar K 
331367b9f52SVijaya Kumar K     kvm_gicr_access(s, GICR_TYPER, 0, &regl, false);
332367b9f52SVijaya Kumar K     kvm_gicr_access(s, GICR_TYPER + 4, 0, &regh, false);
333367b9f52SVijaya Kumar K     redist_typer = ((uint64_t)regh << 32) | regl;
334367b9f52SVijaya Kumar K 
335367b9f52SVijaya Kumar K     reg = s->gicd_ctlr;
336367b9f52SVijaya Kumar K     kvm_gicd_access(s, GICD_CTLR, &reg, true);
337367b9f52SVijaya Kumar K 
338367b9f52SVijaya Kumar K     if (redist_typer & GICR_TYPER_PLPIS) {
339618bacabSZenghui Yu         /*
340618bacabSZenghui Yu          * Restore base addresses before LPIs are potentially enabled by
341618bacabSZenghui Yu          * GICR_CTLR write
342618bacabSZenghui Yu          */
343367b9f52SVijaya Kumar K         for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
344367b9f52SVijaya Kumar K             GICv3CPUState *c = &s->cpu[ncpu];
345367b9f52SVijaya Kumar K 
346367b9f52SVijaya Kumar K             reg64 = c->gicr_propbaser;
347367b9f52SVijaya Kumar K             regl = (uint32_t)reg64;
348367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_PROPBASER, ncpu, &regl, true);
349367b9f52SVijaya Kumar K             regh = (uint32_t)(reg64 >> 32);
350367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_PROPBASER + 4, ncpu, &regh, true);
351367b9f52SVijaya Kumar K 
352367b9f52SVijaya Kumar K             reg64 = c->gicr_pendbaser;
353367b9f52SVijaya Kumar K             regl = (uint32_t)reg64;
354367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_PENDBASER, ncpu, &regl, true);
355367b9f52SVijaya Kumar K             regh = (uint32_t)(reg64 >> 32);
356367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_PENDBASER + 4, ncpu, &regh, true);
357367b9f52SVijaya Kumar K         }
358367b9f52SVijaya Kumar K     }
359367b9f52SVijaya Kumar K 
360367b9f52SVijaya Kumar K     /* Redistributor state (one per CPU) */
361367b9f52SVijaya Kumar K 
362367b9f52SVijaya Kumar K     for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
363367b9f52SVijaya Kumar K         GICv3CPUState *c = &s->cpu[ncpu];
364367b9f52SVijaya Kumar K 
365367b9f52SVijaya Kumar K         reg = c->gicr_ctlr;
366367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_CTLR, ncpu, &reg, true);
367367b9f52SVijaya Kumar K 
368367b9f52SVijaya Kumar K         reg = c->gicr_statusr[GICV3_NS];
369367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_STATUSR, ncpu, &reg, true);
370367b9f52SVijaya Kumar K 
371367b9f52SVijaya Kumar K         reg = c->gicr_waker;
372367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_WAKER, ncpu, &reg, true);
373367b9f52SVijaya Kumar K 
374367b9f52SVijaya Kumar K         reg = c->gicr_igroupr0;
375367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_IGROUPR0, ncpu, &reg, true);
376367b9f52SVijaya Kumar K 
377367b9f52SVijaya Kumar K         reg = ~0;
378367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ICENABLER0, ncpu, &reg, true);
379367b9f52SVijaya Kumar K         reg = c->gicr_ienabler0;
380367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ISENABLER0, ncpu, &reg, true);
381367b9f52SVijaya Kumar K 
382367b9f52SVijaya Kumar K         /* Restore config before pending so we treat level/edge correctly */
383367b9f52SVijaya Kumar K         reg = half_shuffle32(c->edge_trigger >> 16) << 1;
384367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ICFGR1, ncpu, &reg, true);
385367b9f52SVijaya Kumar K 
386367b9f52SVijaya Kumar K         reg = c->level;
387367b9f52SVijaya Kumar K         kvm_gic_line_level_access(s, 0, ncpu, &reg, true);
388367b9f52SVijaya Kumar K 
389367b9f52SVijaya Kumar K         reg = ~0;
390367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ICPENDR0, ncpu, &reg, true);
391367b9f52SVijaya Kumar K         reg = c->gicr_ipendr0;
392367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ISPENDR0, ncpu, &reg, true);
393367b9f52SVijaya Kumar K 
394367b9f52SVijaya Kumar K         reg = ~0;
395367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ICACTIVER0, ncpu, &reg, true);
396367b9f52SVijaya Kumar K         reg = c->gicr_iactiver0;
397367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ISACTIVER0, ncpu, &reg, true);
398367b9f52SVijaya Kumar K 
399367b9f52SVijaya Kumar K         for (i = 0; i < GIC_INTERNAL; i += 4) {
400367b9f52SVijaya Kumar K             reg = c->gicr_ipriorityr[i] |
401367b9f52SVijaya Kumar K                 (c->gicr_ipriorityr[i + 1] << 8) |
402367b9f52SVijaya Kumar K                 (c->gicr_ipriorityr[i + 2] << 16) |
403367b9f52SVijaya Kumar K                 (c->gicr_ipriorityr[i + 3] << 24);
404367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_IPRIORITYR + i, ncpu, &reg, true);
405367b9f52SVijaya Kumar K         }
406367b9f52SVijaya Kumar K     }
407367b9f52SVijaya Kumar K 
408367b9f52SVijaya Kumar K     /* Distributor state (shared between all CPUs */
409367b9f52SVijaya Kumar K     reg = s->gicd_statusr[GICV3_NS];
410367b9f52SVijaya Kumar K     kvm_gicd_access(s, GICD_STATUSR, &reg, true);
411367b9f52SVijaya Kumar K 
412367b9f52SVijaya Kumar K     /* s->enable bitmap -> GICD_ISENABLERn */
413367b9f52SVijaya Kumar K     kvm_dist_putbmp(s, GICD_ISENABLER, GICD_ICENABLER, s->enabled);
414367b9f52SVijaya Kumar K 
415367b9f52SVijaya Kumar K     /* s->group bitmap -> GICD_IGROUPRn */
416367b9f52SVijaya Kumar K     kvm_dist_putbmp(s, GICD_IGROUPR, 0, s->group);
417367b9f52SVijaya Kumar K 
418367b9f52SVijaya Kumar K     /* Restore targets before pending to ensure the pending state is set on
419367b9f52SVijaya Kumar K      * the appropriate CPU interfaces in the kernel
420367b9f52SVijaya Kumar K      */
421367b9f52SVijaya Kumar K 
422367b9f52SVijaya Kumar K     /* s->gicd_irouter[irq] -> GICD_IROUTERn
423367b9f52SVijaya Kumar K      * We can't use kvm_dist_put() here because the registers are 64-bit
424367b9f52SVijaya Kumar K      */
425367b9f52SVijaya Kumar K     for (i = GIC_INTERNAL; i < s->num_irq; i++) {
426367b9f52SVijaya Kumar K         uint32_t offset;
427367b9f52SVijaya Kumar K 
428367b9f52SVijaya Kumar K         offset = GICD_IROUTER + (sizeof(uint32_t) * i);
429367b9f52SVijaya Kumar K         reg = (uint32_t)s->gicd_irouter[i];
430367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &reg, true);
431367b9f52SVijaya Kumar K 
432367b9f52SVijaya Kumar K         offset = GICD_IROUTER + (sizeof(uint32_t) * i) + 4;
433367b9f52SVijaya Kumar K         reg = (uint32_t)(s->gicd_irouter[i] >> 32);
434367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &reg, true);
435367b9f52SVijaya Kumar K     }
436367b9f52SVijaya Kumar K 
437367b9f52SVijaya Kumar K     /* s->trigger bitmap -> GICD_ICFGRn
438367b9f52SVijaya Kumar K      * (restore configuration registers before pending IRQs so we treat
439367b9f52SVijaya Kumar K      * level/edge correctly)
440367b9f52SVijaya Kumar K      */
441367b9f52SVijaya Kumar K     kvm_dist_put_edge_trigger(s, GICD_ICFGR, s->edge_trigger);
442367b9f52SVijaya Kumar K 
443367b9f52SVijaya Kumar K     /* s->level bitmap ->  line_level */
444367b9f52SVijaya Kumar K     kvm_gic_put_line_level_bmp(s, s->level);
445367b9f52SVijaya Kumar K 
446367b9f52SVijaya Kumar K     /* s->pending bitmap -> GICD_ISPENDRn */
447367b9f52SVijaya Kumar K     kvm_dist_putbmp(s, GICD_ISPENDR, GICD_ICPENDR, s->pending);
448367b9f52SVijaya Kumar K 
449367b9f52SVijaya Kumar K     /* s->active bitmap -> GICD_ISACTIVERn */
450367b9f52SVijaya Kumar K     kvm_dist_putbmp(s, GICD_ISACTIVER, GICD_ICACTIVER, s->active);
451367b9f52SVijaya Kumar K 
452367b9f52SVijaya Kumar K     /* s->gicd_ipriority[] -> GICD_IPRIORITYRn */
453367b9f52SVijaya Kumar K     kvm_dist_put_priority(s, GICD_IPRIORITYR, s->gicd_ipriority);
454367b9f52SVijaya Kumar K 
455367b9f52SVijaya Kumar K     /* CPU Interface state (one per CPU) */
456367b9f52SVijaya Kumar K 
457367b9f52SVijaya Kumar K     for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
458367b9f52SVijaya Kumar K         GICv3CPUState *c = &s->cpu[ncpu];
459367b9f52SVijaya Kumar K         int num_pri_bits;
460367b9f52SVijaya Kumar K 
461367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_SRE_EL1, ncpu, &c->icc_sre_el1, true);
462367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_CTLR_EL1, ncpu,
463367b9f52SVijaya Kumar K                         &c->icc_ctlr_el1[GICV3_NS], true);
464367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_IGRPEN0_EL1, ncpu,
465367b9f52SVijaya Kumar K                         &c->icc_igrpen[GICV3_G0], true);
466367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_IGRPEN1_EL1, ncpu,
467367b9f52SVijaya Kumar K                         &c->icc_igrpen[GICV3_G1NS], true);
468367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_PMR_EL1, ncpu, &c->icc_pmr_el1, true);
469367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_BPR0_EL1, ncpu, &c->icc_bpr[GICV3_G0], true);
470367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_BPR1_EL1, ncpu, &c->icc_bpr[GICV3_G1NS], true);
471367b9f52SVijaya Kumar K 
472367b9f52SVijaya Kumar K         num_pri_bits = ((c->icc_ctlr_el1[GICV3_NS] &
473367b9f52SVijaya Kumar K                         ICC_CTLR_EL1_PRIBITS_MASK) >>
474367b9f52SVijaya Kumar K                         ICC_CTLR_EL1_PRIBITS_SHIFT) + 1;
475367b9f52SVijaya Kumar K 
476367b9f52SVijaya Kumar K         switch (num_pri_bits) {
477367b9f52SVijaya Kumar K         case 7:
478367b9f52SVijaya Kumar K             reg64 = c->icc_apr[GICV3_G0][3];
479367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP0R_EL1(3), ncpu, &reg64, true);
480367b9f52SVijaya Kumar K             reg64 = c->icc_apr[GICV3_G0][2];
481367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP0R_EL1(2), ncpu, &reg64, true);
482d85afd1eSChen Qun             /* fall through */
483367b9f52SVijaya Kumar K         case 6:
484367b9f52SVijaya Kumar K             reg64 = c->icc_apr[GICV3_G0][1];
485367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP0R_EL1(1), ncpu, &reg64, true);
486d85afd1eSChen Qun             /* fall through */
487367b9f52SVijaya Kumar K         default:
488367b9f52SVijaya Kumar K             reg64 = c->icc_apr[GICV3_G0][0];
489367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP0R_EL1(0), ncpu, &reg64, true);
490367b9f52SVijaya Kumar K         }
491367b9f52SVijaya Kumar K 
492367b9f52SVijaya Kumar K         switch (num_pri_bits) {
493367b9f52SVijaya Kumar K         case 7:
494367b9f52SVijaya Kumar K             reg64 = c->icc_apr[GICV3_G1NS][3];
495367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP1R_EL1(3), ncpu, &reg64, true);
496367b9f52SVijaya Kumar K             reg64 = c->icc_apr[GICV3_G1NS][2];
497367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP1R_EL1(2), ncpu, &reg64, true);
498d85afd1eSChen Qun             /* fall through */
499367b9f52SVijaya Kumar K         case 6:
500367b9f52SVijaya Kumar K             reg64 = c->icc_apr[GICV3_G1NS][1];
501367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP1R_EL1(1), ncpu, &reg64, true);
502d85afd1eSChen Qun             /* fall through */
503367b9f52SVijaya Kumar K         default:
504367b9f52SVijaya Kumar K             reg64 = c->icc_apr[GICV3_G1NS][0];
505367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP1R_EL1(0), ncpu, &reg64, true);
506367b9f52SVijaya Kumar K         }
507367b9f52SVijaya Kumar K     }
508a7bf3034SPavel Fedin }
509a7bf3034SPavel Fedin 
kvm_arm_gicv3_get(GICv3State * s)510a7bf3034SPavel Fedin static void kvm_arm_gicv3_get(GICv3State *s)
511a7bf3034SPavel Fedin {
512367b9f52SVijaya Kumar K     uint32_t regl, regh, reg;
513367b9f52SVijaya Kumar K     uint64_t reg64, redist_typer;
514367b9f52SVijaya Kumar K     int ncpu, i;
515367b9f52SVijaya Kumar K 
516367b9f52SVijaya Kumar K     kvm_arm_gicv3_check(s);
517367b9f52SVijaya Kumar K 
518367b9f52SVijaya Kumar K     kvm_gicr_access(s, GICR_TYPER, 0, &regl, false);
519367b9f52SVijaya Kumar K     kvm_gicr_access(s, GICR_TYPER + 4, 0, &regh, false);
520367b9f52SVijaya Kumar K     redist_typer = ((uint64_t)regh << 32) | regl;
521367b9f52SVijaya Kumar K 
522367b9f52SVijaya Kumar K     kvm_gicd_access(s, GICD_CTLR, &reg, false);
523367b9f52SVijaya Kumar K     s->gicd_ctlr = reg;
524367b9f52SVijaya Kumar K 
525367b9f52SVijaya Kumar K     /* Redistributor state (one per CPU) */
526367b9f52SVijaya Kumar K 
527367b9f52SVijaya Kumar K     for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
528367b9f52SVijaya Kumar K         GICv3CPUState *c = &s->cpu[ncpu];
529367b9f52SVijaya Kumar K 
530367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_CTLR, ncpu, &reg, false);
531367b9f52SVijaya Kumar K         c->gicr_ctlr = reg;
532367b9f52SVijaya Kumar K 
533367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_STATUSR, ncpu, &reg, false);
534367b9f52SVijaya Kumar K         c->gicr_statusr[GICV3_NS] = reg;
535367b9f52SVijaya Kumar K 
536367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_WAKER, ncpu, &reg, false);
537367b9f52SVijaya Kumar K         c->gicr_waker = reg;
538367b9f52SVijaya Kumar K 
539367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_IGROUPR0, ncpu, &reg, false);
540367b9f52SVijaya Kumar K         c->gicr_igroupr0 = reg;
541367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ISENABLER0, ncpu, &reg, false);
542367b9f52SVijaya Kumar K         c->gicr_ienabler0 = reg;
543367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ICFGR1, ncpu, &reg, false);
544367b9f52SVijaya Kumar K         c->edge_trigger = half_unshuffle32(reg >> 1) << 16;
545367b9f52SVijaya Kumar K         kvm_gic_line_level_access(s, 0, ncpu, &reg, false);
546367b9f52SVijaya Kumar K         c->level = reg;
547367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ISPENDR0, ncpu, &reg, false);
548367b9f52SVijaya Kumar K         c->gicr_ipendr0 = reg;
549367b9f52SVijaya Kumar K         kvm_gicr_access(s, GICR_ISACTIVER0, ncpu, &reg, false);
550367b9f52SVijaya Kumar K         c->gicr_iactiver0 = reg;
551367b9f52SVijaya Kumar K 
552367b9f52SVijaya Kumar K         for (i = 0; i < GIC_INTERNAL; i += 4) {
553367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_IPRIORITYR + i, ncpu, &reg, false);
554367b9f52SVijaya Kumar K             c->gicr_ipriorityr[i] = extract32(reg, 0, 8);
555367b9f52SVijaya Kumar K             c->gicr_ipriorityr[i + 1] = extract32(reg, 8, 8);
556367b9f52SVijaya Kumar K             c->gicr_ipriorityr[i + 2] = extract32(reg, 16, 8);
557367b9f52SVijaya Kumar K             c->gicr_ipriorityr[i + 3] = extract32(reg, 24, 8);
558367b9f52SVijaya Kumar K         }
559367b9f52SVijaya Kumar K     }
560367b9f52SVijaya Kumar K 
561367b9f52SVijaya Kumar K     if (redist_typer & GICR_TYPER_PLPIS) {
562367b9f52SVijaya Kumar K         for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
563367b9f52SVijaya Kumar K             GICv3CPUState *c = &s->cpu[ncpu];
564367b9f52SVijaya Kumar K 
565367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_PROPBASER, ncpu, &regl, false);
566367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_PROPBASER + 4, ncpu, &regh, false);
567367b9f52SVijaya Kumar K             c->gicr_propbaser = ((uint64_t)regh << 32) | regl;
568367b9f52SVijaya Kumar K 
569367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_PENDBASER, ncpu, &regl, false);
570367b9f52SVijaya Kumar K             kvm_gicr_access(s, GICR_PENDBASER + 4, ncpu, &regh, false);
571367b9f52SVijaya Kumar K             c->gicr_pendbaser = ((uint64_t)regh << 32) | regl;
572367b9f52SVijaya Kumar K         }
573367b9f52SVijaya Kumar K     }
574367b9f52SVijaya Kumar K 
575367b9f52SVijaya Kumar K     /* Distributor state (shared between all CPUs */
576367b9f52SVijaya Kumar K 
577367b9f52SVijaya Kumar K     kvm_gicd_access(s, GICD_STATUSR, &reg, false);
578367b9f52SVijaya Kumar K     s->gicd_statusr[GICV3_NS] = reg;
579367b9f52SVijaya Kumar K 
580367b9f52SVijaya Kumar K     /* GICD_IGROUPRn -> s->group bitmap */
581367b9f52SVijaya Kumar K     kvm_dist_getbmp(s, GICD_IGROUPR, s->group);
582367b9f52SVijaya Kumar K 
583367b9f52SVijaya Kumar K     /* GICD_ISENABLERn -> s->enabled bitmap */
584367b9f52SVijaya Kumar K     kvm_dist_getbmp(s, GICD_ISENABLER, s->enabled);
585367b9f52SVijaya Kumar K 
586367b9f52SVijaya Kumar K     /* Line level of irq */
587367b9f52SVijaya Kumar K     kvm_gic_get_line_level_bmp(s, s->level);
588367b9f52SVijaya Kumar K     /* GICD_ISPENDRn -> s->pending bitmap */
589367b9f52SVijaya Kumar K     kvm_dist_getbmp(s, GICD_ISPENDR, s->pending);
590367b9f52SVijaya Kumar K 
591367b9f52SVijaya Kumar K     /* GICD_ISACTIVERn -> s->active bitmap */
592367b9f52SVijaya Kumar K     kvm_dist_getbmp(s, GICD_ISACTIVER, s->active);
593367b9f52SVijaya Kumar K 
594367b9f52SVijaya Kumar K     /* GICD_ICFGRn -> s->trigger bitmap */
595367b9f52SVijaya Kumar K     kvm_dist_get_edge_trigger(s, GICD_ICFGR, s->edge_trigger);
596367b9f52SVijaya Kumar K 
597367b9f52SVijaya Kumar K     /* GICD_IPRIORITYRn -> s->gicd_ipriority[] */
598367b9f52SVijaya Kumar K     kvm_dist_get_priority(s, GICD_IPRIORITYR, s->gicd_ipriority);
599367b9f52SVijaya Kumar K 
600367b9f52SVijaya Kumar K     /* GICD_IROUTERn -> s->gicd_irouter[irq] */
601367b9f52SVijaya Kumar K     for (i = GIC_INTERNAL; i < s->num_irq; i++) {
602367b9f52SVijaya Kumar K         uint32_t offset;
603367b9f52SVijaya Kumar K 
604367b9f52SVijaya Kumar K         offset = GICD_IROUTER + (sizeof(uint32_t) * i);
605367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &regl, false);
606367b9f52SVijaya Kumar K         offset = GICD_IROUTER + (sizeof(uint32_t) * i) + 4;
607367b9f52SVijaya Kumar K         kvm_gicd_access(s, offset, &regh, false);
608367b9f52SVijaya Kumar K         s->gicd_irouter[i] = ((uint64_t)regh << 32) | regl;
609367b9f52SVijaya Kumar K     }
610367b9f52SVijaya Kumar K 
611367b9f52SVijaya Kumar K     /*****************************************************************
612367b9f52SVijaya Kumar K      * CPU Interface(s) State
613367b9f52SVijaya Kumar K      */
614367b9f52SVijaya Kumar K 
615367b9f52SVijaya Kumar K     for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
616367b9f52SVijaya Kumar K         GICv3CPUState *c = &s->cpu[ncpu];
617367b9f52SVijaya Kumar K         int num_pri_bits;
618367b9f52SVijaya Kumar K 
619367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_SRE_EL1, ncpu, &c->icc_sre_el1, false);
620367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_CTLR_EL1, ncpu,
621367b9f52SVijaya Kumar K                         &c->icc_ctlr_el1[GICV3_NS], false);
622367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_IGRPEN0_EL1, ncpu,
623367b9f52SVijaya Kumar K                         &c->icc_igrpen[GICV3_G0], false);
624367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_IGRPEN1_EL1, ncpu,
625367b9f52SVijaya Kumar K                         &c->icc_igrpen[GICV3_G1NS], false);
626367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_PMR_EL1, ncpu, &c->icc_pmr_el1, false);
627367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_BPR0_EL1, ncpu, &c->icc_bpr[GICV3_G0], false);
628367b9f52SVijaya Kumar K         kvm_gicc_access(s, ICC_BPR1_EL1, ncpu, &c->icc_bpr[GICV3_G1NS], false);
629367b9f52SVijaya Kumar K         num_pri_bits = ((c->icc_ctlr_el1[GICV3_NS] &
630367b9f52SVijaya Kumar K                         ICC_CTLR_EL1_PRIBITS_MASK) >>
631367b9f52SVijaya Kumar K                         ICC_CTLR_EL1_PRIBITS_SHIFT) + 1;
632367b9f52SVijaya Kumar K 
633367b9f52SVijaya Kumar K         switch (num_pri_bits) {
634367b9f52SVijaya Kumar K         case 7:
635367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP0R_EL1(3), ncpu, &reg64, false);
636367b9f52SVijaya Kumar K             c->icc_apr[GICV3_G0][3] = reg64;
637367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP0R_EL1(2), ncpu, &reg64, false);
638367b9f52SVijaya Kumar K             c->icc_apr[GICV3_G0][2] = reg64;
639d85afd1eSChen Qun             /* fall through */
640367b9f52SVijaya Kumar K         case 6:
641367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP0R_EL1(1), ncpu, &reg64, false);
642367b9f52SVijaya Kumar K             c->icc_apr[GICV3_G0][1] = reg64;
643d85afd1eSChen Qun             /* fall through */
644367b9f52SVijaya Kumar K         default:
645367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP0R_EL1(0), ncpu, &reg64, false);
646367b9f52SVijaya Kumar K             c->icc_apr[GICV3_G0][0] = reg64;
647367b9f52SVijaya Kumar K         }
648367b9f52SVijaya Kumar K 
649367b9f52SVijaya Kumar K         switch (num_pri_bits) {
650367b9f52SVijaya Kumar K         case 7:
651367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP1R_EL1(3), ncpu, &reg64, false);
652367b9f52SVijaya Kumar K             c->icc_apr[GICV3_G1NS][3] = reg64;
653367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP1R_EL1(2), ncpu, &reg64, false);
654367b9f52SVijaya Kumar K             c->icc_apr[GICV3_G1NS][2] = reg64;
655d85afd1eSChen Qun             /* fall through */
656367b9f52SVijaya Kumar K         case 6:
657367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP1R_EL1(1), ncpu, &reg64, false);
658367b9f52SVijaya Kumar K             c->icc_apr[GICV3_G1NS][1] = reg64;
659d85afd1eSChen Qun             /* fall through */
660367b9f52SVijaya Kumar K         default:
661367b9f52SVijaya Kumar K             kvm_gicc_access(s, ICC_AP1R_EL1(0), ncpu, &reg64, false);
662367b9f52SVijaya Kumar K             c->icc_apr[GICV3_G1NS][0] = reg64;
663367b9f52SVijaya Kumar K         }
664367b9f52SVijaya Kumar K     }
665a7bf3034SPavel Fedin }
666a7bf3034SPavel Fedin 
arm_gicv3_icc_reset(CPUARMState * env,const ARMCPRegInfo * ri)66707a5628cSVijaya Kumar K static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri)
66807a5628cSVijaya Kumar K {
66907a5628cSVijaya Kumar K     GICv3State *s;
67007a5628cSVijaya Kumar K     GICv3CPUState *c;
67107a5628cSVijaya Kumar K 
67207a5628cSVijaya Kumar K     c = (GICv3CPUState *)env->gicv3state;
67307a5628cSVijaya Kumar K     s = c->gic;
67407a5628cSVijaya Kumar K 
67507a5628cSVijaya Kumar K     c->icc_pmr_el1 = 0;
6769774c0f7SPeter Maydell     /*
6779774c0f7SPeter Maydell      * Architecturally the reset value of the ICC_BPR registers
6789774c0f7SPeter Maydell      * is UNKNOWN. We set them all to 0 here; when the kernel
6799774c0f7SPeter Maydell      * uses these values to program the ICH_VMCR_EL2 fields that
6809774c0f7SPeter Maydell      * determine the guest-visible ICC_BPR register values, the
6819774c0f7SPeter Maydell      * hardware's "writing a value less than the minimum sets
6829774c0f7SPeter Maydell      * the field to the minimum value" behaviour will result in
6839774c0f7SPeter Maydell      * them effectively resetting to the correct minimum value
6849774c0f7SPeter Maydell      * for the host GIC.
6859774c0f7SPeter Maydell      */
6869774c0f7SPeter Maydell     c->icc_bpr[GICV3_G0] = 0;
6879774c0f7SPeter Maydell     c->icc_bpr[GICV3_G1] = 0;
6889774c0f7SPeter Maydell     c->icc_bpr[GICV3_G1NS] = 0;
68907a5628cSVijaya Kumar K 
69007a5628cSVijaya Kumar K     c->icc_sre_el1 = 0x7;
69107a5628cSVijaya Kumar K     memset(c->icc_apr, 0, sizeof(c->icc_apr));
69207a5628cSVijaya Kumar K     memset(c->icc_igrpen, 0, sizeof(c->icc_igrpen));
693e7d54416SEric Auger 
694e7d54416SEric Auger     if (s->migration_blocker) {
695e7d54416SEric Auger         return;
696e7d54416SEric Auger     }
697e7d54416SEric Auger 
698e7d54416SEric Auger     /* Initialize to actual HW supported configuration */
699e7d54416SEric Auger     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS,
7001e11a139SKeqian Zhu                       KVM_VGIC_ATTR(ICC_CTLR_EL1, c->gicr_typer),
701556969e9SEric Auger                       &c->icc_ctlr_el1[GICV3_NS], false, &error_abort);
702e7d54416SEric Auger 
703e7d54416SEric Auger     c->icc_ctlr_el1[GICV3_S] = c->icc_ctlr_el1[GICV3_NS];
70407a5628cSVijaya Kumar K }
70507a5628cSVijaya Kumar K 
kvm_arm_gicv3_reset_hold(Object * obj,ResetType type)706ad80e367SPeter Maydell static void kvm_arm_gicv3_reset_hold(Object *obj, ResetType type)
707a7bf3034SPavel Fedin {
708823300f0SPeter Maydell     GICv3State *s = ARM_GICV3_COMMON(obj);
709a7bf3034SPavel Fedin     KVMARMGICv3Class *kgc = KVM_ARM_GICV3_GET_CLASS(s);
710a7bf3034SPavel Fedin 
711a7bf3034SPavel Fedin     DPRINTF("Reset\n");
712a7bf3034SPavel Fedin 
713823300f0SPeter Maydell     if (kgc->parent_phases.hold) {
714ad80e367SPeter Maydell         kgc->parent_phases.hold(obj, type);
715823300f0SPeter Maydell     }
716367b9f52SVijaya Kumar K 
717367b9f52SVijaya Kumar K     if (s->migration_blocker) {
718367b9f52SVijaya Kumar K         DPRINTF("Cannot put kernel gic state, no kernel interface\n");
719367b9f52SVijaya Kumar K         return;
720367b9f52SVijaya Kumar K     }
721367b9f52SVijaya Kumar K 
722a7bf3034SPavel Fedin     kvm_arm_gicv3_put(s);
723a7bf3034SPavel Fedin }
724a7bf3034SPavel Fedin 
72507a5628cSVijaya Kumar K /*
72607a5628cSVijaya Kumar K  * CPU interface registers of GIC needs to be reset on CPU reset.
72707a5628cSVijaya Kumar K  * For the calling arm_gicv3_icc_reset() on CPU reset, we register
72807a5628cSVijaya Kumar K  * below ARMCPRegInfo. As we reset the whole cpu interface under single
72907a5628cSVijaya Kumar K  * register reset, we define only one register of CPU interface instead
73007a5628cSVijaya Kumar K  * of defining all the registers.
73107a5628cSVijaya Kumar K  */
73207a5628cSVijaya Kumar K static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
73307a5628cSVijaya Kumar K     { .name = "ICC_CTLR_EL1", .state = ARM_CP_STATE_BOTH,
73407a5628cSVijaya Kumar K       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 4,
73507a5628cSVijaya Kumar K       /*
73607a5628cSVijaya Kumar K        * If ARM_CP_NOP is used, resetfn is not called,
73707a5628cSVijaya Kumar K        * So ARM_CP_NO_RAW is appropriate type.
73807a5628cSVijaya Kumar K        */
73907a5628cSVijaya Kumar K       .type = ARM_CP_NO_RAW,
74007a5628cSVijaya Kumar K       .access = PL1_RW,
74107a5628cSVijaya Kumar K       .readfn = arm_cp_read_zero,
74207a5628cSVijaya Kumar K       .writefn = arm_cp_write_ignore,
74307a5628cSVijaya Kumar K       /*
74407a5628cSVijaya Kumar K        * We hang the whole cpu interface reset routine off here
74507a5628cSVijaya Kumar K        * rather than parcelling it out into one little function
74607a5628cSVijaya Kumar K        * per register
74707a5628cSVijaya Kumar K        */
74807a5628cSVijaya Kumar K       .resetfn = arm_gicv3_icc_reset,
74907a5628cSVijaya Kumar K     },
75007a5628cSVijaya Kumar K };
75107a5628cSVijaya Kumar K 
752d5aa0c22SEric Auger /**
753d5aa0c22SEric Auger  * vm_change_state_handler - VM change state callback aiming at flushing
754d5aa0c22SEric Auger  * RDIST pending tables into guest RAM
755d5aa0c22SEric Auger  *
756d5aa0c22SEric Auger  * The tables get flushed to guest RAM whenever the VM gets stopped.
757d5aa0c22SEric Auger  */
vm_change_state_handler(void * opaque,bool running,RunState state)758538f0497SPhilippe Mathieu-Daudé static void vm_change_state_handler(void *opaque, bool running,
759d5aa0c22SEric Auger                                     RunState state)
760d5aa0c22SEric Auger {
761d5aa0c22SEric Auger     GICv3State *s = (GICv3State *)opaque;
762d5aa0c22SEric Auger     Error *err = NULL;
763d5aa0c22SEric Auger     int ret;
764d5aa0c22SEric Auger 
765d5aa0c22SEric Auger     if (running) {
766d5aa0c22SEric Auger         return;
767d5aa0c22SEric Auger     }
768d5aa0c22SEric Auger 
769d5aa0c22SEric Auger     ret = kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
770d5aa0c22SEric Auger                            KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES,
771d5aa0c22SEric Auger                            NULL, true, &err);
772d5aa0c22SEric Auger     if (err) {
773d5aa0c22SEric Auger         error_report_err(err);
774d5aa0c22SEric Auger     }
775d5aa0c22SEric Auger     if (ret < 0 && ret != -EFAULT) {
776d5aa0c22SEric Auger         abort();
777d5aa0c22SEric Auger     }
778d5aa0c22SEric Auger }
779d5aa0c22SEric Auger 
780d5aa0c22SEric Auger 
kvm_arm_gicv3_realize(DeviceState * dev,Error ** errp)781a7bf3034SPavel Fedin static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
782a7bf3034SPavel Fedin {
783a7bf3034SPavel Fedin     GICv3State *s = KVM_ARM_GICV3(dev);
784a7bf3034SPavel Fedin     KVMARMGICv3Class *kgc = KVM_ARM_GICV3_GET_CLASS(s);
78580d67333SEric Auger     bool multiple_redist_region_allowed;
786a7bf3034SPavel Fedin     Error *local_err = NULL;
787d19a4d4eSEric Auger     int i;
788a7bf3034SPavel Fedin 
789a7bf3034SPavel Fedin     DPRINTF("kvm_arm_gicv3_realize\n");
790a7bf3034SPavel Fedin 
791a7bf3034SPavel Fedin     kgc->parent_realize(dev, &local_err);
792a7bf3034SPavel Fedin     if (local_err) {
793a7bf3034SPavel Fedin         error_propagate(errp, local_err);
794a7bf3034SPavel Fedin         return;
795a7bf3034SPavel Fedin     }
796a7bf3034SPavel Fedin 
797445d5825SPeter Maydell     if (s->revision != 3) {
798445d5825SPeter Maydell         error_setg(errp, "unsupported GIC revision %d for in-kernel GIC",
799445d5825SPeter Maydell                    s->revision);
800445d5825SPeter Maydell     }
801445d5825SPeter Maydell 
802a7bf3034SPavel Fedin     if (s->security_extn) {
803a7bf3034SPavel Fedin         error_setg(errp, "the in-kernel VGICv3 does not implement the "
804a7bf3034SPavel Fedin                    "security extensions");
805a7bf3034SPavel Fedin         return;
806a7bf3034SPavel Fedin     }
807a7bf3034SPavel Fedin 
80867d74e4cSJinjie Ruan     if (s->nmi_support) {
80967d74e4cSJinjie Ruan         error_setg(errp, "NMI is not supported with the in-kernel GIC");
81067d74e4cSJinjie Ruan         return;
81167d74e4cSJinjie Ruan     }
81267d74e4cSJinjie Ruan 
81301b5ab8cSPeter Maydell     gicv3_init_irqs_and_mmio(s, kvm_arm_gicv3_set_irq, NULL);
814a7bf3034SPavel Fedin 
81507a5628cSVijaya Kumar K     for (i = 0; i < s->num_cpu; i++) {
81607a5628cSVijaya Kumar K         ARMCPU *cpu = ARM_CPU(qemu_get_cpu(i));
81707a5628cSVijaya Kumar K 
81807a5628cSVijaya Kumar K         define_arm_cp_regs(cpu, gicv3_cpuif_reginfo);
81907a5628cSVijaya Kumar K     }
82007a5628cSVijaya Kumar K 
821a7bf3034SPavel Fedin     /* Try to create the device via the device control API */
822a7bf3034SPavel Fedin     s->dev_fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_ARM_VGIC_V3, false);
823a7bf3034SPavel Fedin     if (s->dev_fd < 0) {
824a7bf3034SPavel Fedin         error_setg_errno(errp, -s->dev_fd, "error creating in-kernel VGIC");
825a7bf3034SPavel Fedin         return;
826a7bf3034SPavel Fedin     }
827a7bf3034SPavel Fedin 
82880d67333SEric Auger     multiple_redist_region_allowed =
82980d67333SEric Auger         kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
83080d67333SEric Auger                               KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION);
83180d67333SEric Auger 
83280d67333SEric Auger     if (!multiple_redist_region_allowed && s->nb_redist_regions > 1) {
83380d67333SEric Auger         error_setg(errp, "Multiple VGICv3 redistributor regions are not "
83480d67333SEric Auger                    "supported by this host kernel");
83580d67333SEric Auger         error_append_hint(errp, "A maximum of %d VCPUs can be used",
83680d67333SEric Auger                           s->redist_region_count[0]);
83780d67333SEric Auger         return;
83880d67333SEric Auger     }
83980d67333SEric Auger 
840a7bf3034SPavel Fedin     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS,
841556969e9SEric Auger                       0, &s->num_irq, true, &error_abort);
842a7bf3034SPavel Fedin 
843a7bf3034SPavel Fedin     /* Tell the kernel to complete VGIC initialization now */
844a7bf3034SPavel Fedin     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
845556969e9SEric Auger                       KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true, &error_abort);
846a7bf3034SPavel Fedin 
847a7bf3034SPavel Fedin     kvm_arm_register_device(&s->iomem_dist, -1, KVM_DEV_ARM_VGIC_GRP_ADDR,
84819d1bd0bSEric Auger                             KVM_VGIC_V3_ADDR_TYPE_DIST, s->dev_fd, 0);
84980d67333SEric Auger 
85080d67333SEric Auger     if (!multiple_redist_region_allowed) {
851e5cba10eSPeter Maydell         kvm_arm_register_device(&s->redist_regions[0].iomem, -1,
8521e575b66SEric Auger                                 KVM_DEV_ARM_VGIC_GRP_ADDR,
85319d1bd0bSEric Auger                                 KVM_VGIC_V3_ADDR_TYPE_REDIST, s->dev_fd, 0);
85480d67333SEric Auger     } else {
85580d67333SEric Auger         /* we register regions in reverse order as "devices" are inserted at
85680d67333SEric Auger          * the head of a QSLIST and the list is then popped from the head
85780d67333SEric Auger          * onwards by kvm_arm_machine_init_done()
85880d67333SEric Auger          */
85980d67333SEric Auger         for (i = s->nb_redist_regions - 1; i >= 0; i--) {
86080d67333SEric Auger             /* Address mask made of the rdist region index and count */
86180d67333SEric Auger             uint64_t addr_ormask =
86280d67333SEric Auger                         i | ((uint64_t)s->redist_region_count[i] << 52);
86380d67333SEric Auger 
864e5cba10eSPeter Maydell             kvm_arm_register_device(&s->redist_regions[i].iomem, -1,
86580d67333SEric Auger                                     KVM_DEV_ARM_VGIC_GRP_ADDR,
86680d67333SEric Auger                                     KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION,
86780d67333SEric Auger                                     s->dev_fd, addr_ormask);
86880d67333SEric Auger         }
86980d67333SEric Auger     }
870757caeedSPavel Fedin 
871d19a4d4eSEric Auger     if (kvm_has_gsi_routing()) {
872d19a4d4eSEric Auger         /* set up irq routing */
873d19a4d4eSEric Auger         for (i = 0; i < s->num_irq - GIC_INTERNAL; ++i) {
874d19a4d4eSEric Auger             kvm_irqchip_add_irq_route(kvm_state, i, 0, i);
875d19a4d4eSEric Auger         }
876d19a4d4eSEric Auger 
877d19a4d4eSEric Auger         kvm_gsi_routing_allowed = true;
878d19a4d4eSEric Auger 
879d19a4d4eSEric Auger         kvm_irqchip_commit_routes(kvm_state);
880d19a4d4eSEric Auger     }
881367b9f52SVijaya Kumar K 
882367b9f52SVijaya Kumar K     if (!kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
883367b9f52SVijaya Kumar K                                GICD_CTLR)) {
884367b9f52SVijaya Kumar K         error_setg(&s->migration_blocker, "This operating system kernel does "
885367b9f52SVijaya Kumar K                                           "not support vGICv3 migration");
886c8a7fc51SSteve Sistare         if (migrate_add_blocker(&s->migration_blocker, errp) < 0) {
887367b9f52SVijaya Kumar K             return;
888367b9f52SVijaya Kumar K         }
889367b9f52SVijaya Kumar K     }
890d5aa0c22SEric Auger     if (kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
891d5aa0c22SEric Auger                               KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES)) {
892d5aa0c22SEric Auger         qemu_add_vm_change_state_handler(vm_change_state_handler, s);
893d5aa0c22SEric Auger     }
894a7bf3034SPavel Fedin }
895a7bf3034SPavel Fedin 
kvm_arm_gicv3_class_init(ObjectClass * klass,const void * data)896*12d1a768SPhilippe Mathieu-Daudé static void kvm_arm_gicv3_class_init(ObjectClass *klass, const void *data)
897a7bf3034SPavel Fedin {
898a7bf3034SPavel Fedin     DeviceClass *dc = DEVICE_CLASS(klass);
899823300f0SPeter Maydell     ResettableClass *rc = RESETTABLE_CLASS(klass);
900a7bf3034SPavel Fedin     ARMGICv3CommonClass *agcc = ARM_GICV3_COMMON_CLASS(klass);
901a7bf3034SPavel Fedin     KVMARMGICv3Class *kgc = KVM_ARM_GICV3_CLASS(klass);
902a7bf3034SPavel Fedin 
903a7bf3034SPavel Fedin     agcc->pre_save = kvm_arm_gicv3_get;
904a7bf3034SPavel Fedin     agcc->post_load = kvm_arm_gicv3_put;
905bf853881SPhilippe Mathieu-Daudé     device_class_set_parent_realize(dc, kvm_arm_gicv3_realize,
906bf853881SPhilippe Mathieu-Daudé                                     &kgc->parent_realize);
907823300f0SPeter Maydell     resettable_class_set_parent_phases(rc, NULL, kvm_arm_gicv3_reset_hold, NULL,
908823300f0SPeter Maydell                                        &kgc->parent_phases);
909a7bf3034SPavel Fedin }
910a7bf3034SPavel Fedin 
911a7bf3034SPavel Fedin static const TypeInfo kvm_arm_gicv3_info = {
912a7bf3034SPavel Fedin     .name = TYPE_KVM_ARM_GICV3,
913a7bf3034SPavel Fedin     .parent = TYPE_ARM_GICV3_COMMON,
914a7bf3034SPavel Fedin     .instance_size = sizeof(GICv3State),
915a7bf3034SPavel Fedin     .class_init = kvm_arm_gicv3_class_init,
916a7bf3034SPavel Fedin     .class_size = sizeof(KVMARMGICv3Class),
917a7bf3034SPavel Fedin };
918a7bf3034SPavel Fedin 
kvm_arm_gicv3_register_types(void)919a7bf3034SPavel Fedin static void kvm_arm_gicv3_register_types(void)
920a7bf3034SPavel Fedin {
921a7bf3034SPavel Fedin     type_register_static(&kvm_arm_gicv3_info);
922a7bf3034SPavel Fedin }
923a7bf3034SPavel Fedin 
924a7bf3034SPavel Fedin type_init(kvm_arm_gicv3_register_types)
925