xref: /qemu/hw/intc/arm_gic_kvm.c (revision db1015e92e04835c9eb50c29625fe566d1202dbd)
1 /*
2  * ARM Generic Interrupt Controller using KVM in-kernel support
3  *
4  * Copyright (c) 2012 Linaro Limited
5  * Written by Peter Maydell
6  * Save/Restore logic added by Christoffer Dall.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "qemu/osdep.h"
23 #include "qapi/error.h"
24 #include "qemu/module.h"
25 #include "cpu.h"
26 #include "hw/sysbus.h"
27 #include "migration/blocker.h"
28 #include "sysemu/kvm.h"
29 #include "kvm_arm.h"
30 #include "gic_internal.h"
31 #include "vgic_common.h"
32 #include "qom/object.h"
33 
34 #define TYPE_KVM_ARM_GIC "kvm-arm-gic"
35 typedef struct KVMARMGICClass KVMARMGICClass;
36 #define KVM_ARM_GIC(obj) \
37      OBJECT_CHECK(GICState, (obj), TYPE_KVM_ARM_GIC)
38 #define KVM_ARM_GIC_CLASS(klass) \
39      OBJECT_CLASS_CHECK(KVMARMGICClass, (klass), TYPE_KVM_ARM_GIC)
40 #define KVM_ARM_GIC_GET_CLASS(obj) \
41      OBJECT_GET_CLASS(KVMARMGICClass, (obj), TYPE_KVM_ARM_GIC)
42 
43 struct KVMARMGICClass {
44     ARMGICCommonClass parent_class;
45     DeviceRealize parent_realize;
46     void (*parent_reset)(DeviceState *dev);
47 };
48 
49 void kvm_arm_gic_set_irq(uint32_t num_irq, int irq, int level)
50 {
51     /* Meaning of the 'irq' parameter:
52      *  [0..N-1] : external interrupts
53      *  [N..N+31] : PPI (internal) interrupts for CPU 0
54      *  [N+32..N+63] : PPI (internal interrupts for CPU 1
55      *  ...
56      * Convert this to the kernel's desired encoding, which
57      * has separate fields in the irq number for type,
58      * CPU number and interrupt number.
59      */
60     int irqtype, cpu;
61 
62     if (irq < (num_irq - GIC_INTERNAL)) {
63         /* External interrupt. The kernel numbers these like the GIC
64          * hardware, with external interrupt IDs starting after the
65          * internal ones.
66          */
67         irqtype = KVM_ARM_IRQ_TYPE_SPI;
68         cpu = 0;
69         irq += GIC_INTERNAL;
70     } else {
71         /* Internal interrupt: decode into (cpu, interrupt id) */
72         irqtype = KVM_ARM_IRQ_TYPE_PPI;
73         irq -= (num_irq - GIC_INTERNAL);
74         cpu = irq / GIC_INTERNAL;
75         irq %= GIC_INTERNAL;
76     }
77     kvm_arm_set_irq(cpu, irqtype, irq, !!level);
78 }
79 
80 static void kvm_arm_gicv2_set_irq(void *opaque, int irq, int level)
81 {
82     GICState *s = (GICState *)opaque;
83 
84     kvm_arm_gic_set_irq(s->num_irq, irq, level);
85 }
86 
87 static bool kvm_arm_gic_can_save_restore(GICState *s)
88 {
89     return s->dev_fd >= 0;
90 }
91 
92 #define KVM_VGIC_ATTR(offset, cpu) \
93     ((((uint64_t)(cpu) << KVM_DEV_ARM_VGIC_CPUID_SHIFT) & \
94       KVM_DEV_ARM_VGIC_CPUID_MASK) | \
95      (((uint64_t)(offset) << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) & \
96       KVM_DEV_ARM_VGIC_OFFSET_MASK))
97 
98 static void kvm_gicd_access(GICState *s, int offset, int cpu,
99                             uint32_t *val, bool write)
100 {
101     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
102                       KVM_VGIC_ATTR(offset, cpu), val, write, &error_abort);
103 }
104 
105 static void kvm_gicc_access(GICState *s, int offset, int cpu,
106                             uint32_t *val, bool write)
107 {
108     kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_REGS,
109                       KVM_VGIC_ATTR(offset, cpu), val, write, &error_abort);
110 }
111 
112 #define for_each_irq_reg(_ctr, _max_irq, _field_width) \
113     for (_ctr = 0; _ctr < ((_max_irq) / (32 / (_field_width))); _ctr++)
114 
115 /*
116  * Translate from the in-kernel field for an IRQ value to/from the qemu
117  * representation.
118  */
119 typedef void (*vgic_translate_fn)(GICState *s, int irq, int cpu,
120                                   uint32_t *field, bool to_kernel);
121 
122 /* synthetic translate function used for clear/set registers to completely
123  * clear a setting using a clear-register before setting the remaining bits
124  * using a set-register */
125 static void translate_clear(GICState *s, int irq, int cpu,
126                             uint32_t *field, bool to_kernel)
127 {
128     if (to_kernel) {
129         *field = ~0;
130     } else {
131         /* does not make sense: qemu model doesn't use set/clear regs */
132         abort();
133     }
134 }
135 
136 static void translate_group(GICState *s, int irq, int cpu,
137                             uint32_t *field, bool to_kernel)
138 {
139     int cm = (irq < GIC_INTERNAL) ? (1 << cpu) : ALL_CPU_MASK;
140 
141     if (to_kernel) {
142         *field = GIC_DIST_TEST_GROUP(irq, cm);
143     } else {
144         if (*field & 1) {
145             GIC_DIST_SET_GROUP(irq, cm);
146         }
147     }
148 }
149 
150 static void translate_enabled(GICState *s, int irq, int cpu,
151                               uint32_t *field, bool to_kernel)
152 {
153     int cm = (irq < GIC_INTERNAL) ? (1 << cpu) : ALL_CPU_MASK;
154 
155     if (to_kernel) {
156         *field = GIC_DIST_TEST_ENABLED(irq, cm);
157     } else {
158         if (*field & 1) {
159             GIC_DIST_SET_ENABLED(irq, cm);
160         }
161     }
162 }
163 
164 static void translate_pending(GICState *s, int irq, int cpu,
165                               uint32_t *field, bool to_kernel)
166 {
167     int cm = (irq < GIC_INTERNAL) ? (1 << cpu) : ALL_CPU_MASK;
168 
169     if (to_kernel) {
170         *field = gic_test_pending(s, irq, cm);
171     } else {
172         if (*field & 1) {
173             GIC_DIST_SET_PENDING(irq, cm);
174             /* TODO: Capture is level-line is held high in the kernel */
175         }
176     }
177 }
178 
179 static void translate_active(GICState *s, int irq, int cpu,
180                              uint32_t *field, bool to_kernel)
181 {
182     int cm = (irq < GIC_INTERNAL) ? (1 << cpu) : ALL_CPU_MASK;
183 
184     if (to_kernel) {
185         *field = GIC_DIST_TEST_ACTIVE(irq, cm);
186     } else {
187         if (*field & 1) {
188             GIC_DIST_SET_ACTIVE(irq, cm);
189         }
190     }
191 }
192 
193 static void translate_trigger(GICState *s, int irq, int cpu,
194                               uint32_t *field, bool to_kernel)
195 {
196     if (to_kernel) {
197         *field = (GIC_DIST_TEST_EDGE_TRIGGER(irq)) ? 0x2 : 0x0;
198     } else {
199         if (*field & 0x2) {
200             GIC_DIST_SET_EDGE_TRIGGER(irq);
201         }
202     }
203 }
204 
205 static void translate_priority(GICState *s, int irq, int cpu,
206                                uint32_t *field, bool to_kernel)
207 {
208     if (to_kernel) {
209         *field = GIC_DIST_GET_PRIORITY(irq, cpu) & 0xff;
210     } else {
211         gic_dist_set_priority(s, cpu, irq,
212                               *field & 0xff, MEMTXATTRS_UNSPECIFIED);
213     }
214 }
215 
216 static void translate_targets(GICState *s, int irq, int cpu,
217                               uint32_t *field, bool to_kernel)
218 {
219     if (to_kernel) {
220         *field = s->irq_target[irq] & 0xff;
221     } else {
222         s->irq_target[irq] = *field & 0xff;
223     }
224 }
225 
226 static void translate_sgisource(GICState *s, int irq, int cpu,
227                                 uint32_t *field, bool to_kernel)
228 {
229     if (to_kernel) {
230         *field = s->sgi_pending[irq][cpu] & 0xff;
231     } else {
232         s->sgi_pending[irq][cpu] = *field & 0xff;
233     }
234 }
235 
236 /* Read a register group from the kernel VGIC */
237 static void kvm_dist_get(GICState *s, uint32_t offset, int width,
238                          int maxirq, vgic_translate_fn translate_fn)
239 {
240     uint32_t reg;
241     int i;
242     int j;
243     int irq;
244     int cpu;
245     int regsz = 32 / width; /* irqs per kernel register */
246     uint32_t field;
247 
248     for_each_irq_reg(i, maxirq, width) {
249         irq = i * regsz;
250         cpu = 0;
251         while ((cpu < s->num_cpu && irq < GIC_INTERNAL) || cpu == 0) {
252             kvm_gicd_access(s, offset, cpu, &reg, false);
253             for (j = 0; j < regsz; j++) {
254                 field = extract32(reg, j * width, width);
255                 translate_fn(s, irq + j, cpu, &field, false);
256             }
257 
258             cpu++;
259         }
260         offset += 4;
261     }
262 }
263 
264 /* Write a register group to the kernel VGIC */
265 static void kvm_dist_put(GICState *s, uint32_t offset, int width,
266                          int maxirq, vgic_translate_fn translate_fn)
267 {
268     uint32_t reg;
269     int i;
270     int j;
271     int irq;
272     int cpu;
273     int regsz = 32 / width; /* irqs per kernel register */
274     uint32_t field;
275 
276     for_each_irq_reg(i, maxirq, width) {
277         irq = i * regsz;
278         cpu = 0;
279         while ((cpu < s->num_cpu && irq < GIC_INTERNAL) || cpu == 0) {
280             reg = 0;
281             for (j = 0; j < regsz; j++) {
282                 translate_fn(s, irq + j, cpu, &field, true);
283                 reg = deposit32(reg, j * width, width, field);
284             }
285             kvm_gicd_access(s, offset, cpu, &reg, true);
286 
287             cpu++;
288         }
289         offset += 4;
290     }
291 }
292 
293 static void kvm_arm_gic_put(GICState *s)
294 {
295     uint32_t reg;
296     int i;
297     int cpu;
298     int num_cpu;
299     int num_irq;
300 
301     /* Note: We do the restore in a slightly different order than the save
302      * (where the order doesn't matter and is simply ordered according to the
303      * register offset values */
304 
305     /*****************************************************************
306      * Distributor State
307      */
308 
309     /* s->ctlr -> GICD_CTLR */
310     reg = s->ctlr;
311     kvm_gicd_access(s, 0x0, 0, &reg, true);
312 
313     /* Sanity checking on GICD_TYPER and s->num_irq, s->num_cpu */
314     kvm_gicd_access(s, 0x4, 0, &reg, false);
315     num_irq = ((reg & 0x1f) + 1) * 32;
316     num_cpu = ((reg & 0xe0) >> 5) + 1;
317 
318     if (num_irq < s->num_irq) {
319             fprintf(stderr, "Restoring %u IRQs, but kernel supports max %d\n",
320                     s->num_irq, num_irq);
321             abort();
322     } else if (num_cpu != s->num_cpu) {
323             fprintf(stderr, "Restoring %u CPU interfaces, kernel only has %d\n",
324                     s->num_cpu, num_cpu);
325             /* Did we not create the VCPUs in the kernel yet? */
326             abort();
327     }
328 
329     /* TODO: Consider checking compatibility with the IIDR ? */
330 
331     /* irq_state[n].enabled -> GICD_ISENABLERn */
332     kvm_dist_put(s, 0x180, 1, s->num_irq, translate_clear);
333     kvm_dist_put(s, 0x100, 1, s->num_irq, translate_enabled);
334 
335     /* irq_state[n].group -> GICD_IGROUPRn */
336     kvm_dist_put(s, 0x80, 1, s->num_irq, translate_group);
337 
338     /* s->irq_target[irq] -> GICD_ITARGETSRn
339      * (restore targets before pending to ensure the pending state is set on
340      * the appropriate CPU interfaces in the kernel) */
341     kvm_dist_put(s, 0x800, 8, s->num_irq, translate_targets);
342 
343     /* irq_state[n].trigger -> GICD_ICFGRn
344      * (restore configuration registers before pending IRQs so we treat
345      * level/edge correctly) */
346     kvm_dist_put(s, 0xc00, 2, s->num_irq, translate_trigger);
347 
348     /* irq_state[n].pending + irq_state[n].level -> GICD_ISPENDRn */
349     kvm_dist_put(s, 0x280, 1, s->num_irq, translate_clear);
350     kvm_dist_put(s, 0x200, 1, s->num_irq, translate_pending);
351 
352     /* irq_state[n].active -> GICD_ISACTIVERn */
353     kvm_dist_put(s, 0x380, 1, s->num_irq, translate_clear);
354     kvm_dist_put(s, 0x300, 1, s->num_irq, translate_active);
355 
356 
357     /* s->priorityX[irq] -> ICD_IPRIORITYRn */
358     kvm_dist_put(s, 0x400, 8, s->num_irq, translate_priority);
359 
360     /* s->sgi_pending -> ICD_CPENDSGIRn */
361     kvm_dist_put(s, 0xf10, 8, GIC_NR_SGIS, translate_clear);
362     kvm_dist_put(s, 0xf20, 8, GIC_NR_SGIS, translate_sgisource);
363 
364 
365     /*****************************************************************
366      * CPU Interface(s) State
367      */
368 
369     for (cpu = 0; cpu < s->num_cpu; cpu++) {
370         /* s->cpu_ctlr[cpu] -> GICC_CTLR */
371         reg = s->cpu_ctlr[cpu];
372         kvm_gicc_access(s, 0x00, cpu, &reg, true);
373 
374         /* s->priority_mask[cpu] -> GICC_PMR */
375         reg = (s->priority_mask[cpu] & 0xff);
376         kvm_gicc_access(s, 0x04, cpu, &reg, true);
377 
378         /* s->bpr[cpu] -> GICC_BPR */
379         reg = (s->bpr[cpu] & 0x7);
380         kvm_gicc_access(s, 0x08, cpu, &reg, true);
381 
382         /* s->abpr[cpu] -> GICC_ABPR */
383         reg = (s->abpr[cpu] & 0x7);
384         kvm_gicc_access(s, 0x1c, cpu, &reg, true);
385 
386         /* s->apr[n][cpu] -> GICC_APRn */
387         for (i = 0; i < 4; i++) {
388             reg = s->apr[i][cpu];
389             kvm_gicc_access(s, 0xd0 + i * 4, cpu, &reg, true);
390         }
391     }
392 }
393 
394 static void kvm_arm_gic_get(GICState *s)
395 {
396     uint32_t reg;
397     int i;
398     int cpu;
399 
400     /*****************************************************************
401      * Distributor State
402      */
403 
404     /* GICD_CTLR -> s->ctlr */
405     kvm_gicd_access(s, 0x0, 0, &reg, false);
406     s->ctlr = reg;
407 
408     /* Sanity checking on GICD_TYPER -> s->num_irq, s->num_cpu */
409     kvm_gicd_access(s, 0x4, 0, &reg, false);
410     s->num_irq = ((reg & 0x1f) + 1) * 32;
411     s->num_cpu = ((reg & 0xe0) >> 5) + 1;
412 
413     if (s->num_irq > GIC_MAXIRQ) {
414             fprintf(stderr, "Too many IRQs reported from the kernel: %d\n",
415                     s->num_irq);
416             abort();
417     }
418 
419     /* GICD_IIDR -> ? */
420     kvm_gicd_access(s, 0x8, 0, &reg, false);
421 
422     /* Clear all the IRQ settings */
423     for (i = 0; i < s->num_irq; i++) {
424         memset(&s->irq_state[i], 0, sizeof(s->irq_state[0]));
425     }
426 
427     /* GICD_IGROUPRn -> irq_state[n].group */
428     kvm_dist_get(s, 0x80, 1, s->num_irq, translate_group);
429 
430     /* GICD_ISENABLERn -> irq_state[n].enabled */
431     kvm_dist_get(s, 0x100, 1, s->num_irq, translate_enabled);
432 
433     /* GICD_ISPENDRn -> irq_state[n].pending + irq_state[n].level */
434     kvm_dist_get(s, 0x200, 1, s->num_irq, translate_pending);
435 
436     /* GICD_ISACTIVERn -> irq_state[n].active */
437     kvm_dist_get(s, 0x300, 1, s->num_irq, translate_active);
438 
439     /* GICD_ICFRn -> irq_state[n].trigger */
440     kvm_dist_get(s, 0xc00, 2, s->num_irq, translate_trigger);
441 
442     /* GICD_IPRIORITYRn -> s->priorityX[irq] */
443     kvm_dist_get(s, 0x400, 8, s->num_irq, translate_priority);
444 
445     /* GICD_ITARGETSRn -> s->irq_target[irq] */
446     kvm_dist_get(s, 0x800, 8, s->num_irq, translate_targets);
447 
448     /* GICD_CPENDSGIRn -> s->sgi_pending */
449     kvm_dist_get(s, 0xf10, 8, GIC_NR_SGIS, translate_sgisource);
450 
451 
452     /*****************************************************************
453      * CPU Interface(s) State
454      */
455 
456     for (cpu = 0; cpu < s->num_cpu; cpu++) {
457         /* GICC_CTLR -> s->cpu_ctlr[cpu] */
458         kvm_gicc_access(s, 0x00, cpu, &reg, false);
459         s->cpu_ctlr[cpu] = reg;
460 
461         /* GICC_PMR -> s->priority_mask[cpu] */
462         kvm_gicc_access(s, 0x04, cpu, &reg, false);
463         s->priority_mask[cpu] = (reg & 0xff);
464 
465         /* GICC_BPR -> s->bpr[cpu] */
466         kvm_gicc_access(s, 0x08, cpu, &reg, false);
467         s->bpr[cpu] = (reg & 0x7);
468 
469         /* GICC_ABPR -> s->abpr[cpu] */
470         kvm_gicc_access(s, 0x1c, cpu, &reg, false);
471         s->abpr[cpu] = (reg & 0x7);
472 
473         /* GICC_APRn -> s->apr[n][cpu] */
474         for (i = 0; i < 4; i++) {
475             kvm_gicc_access(s, 0xd0 + i * 4, cpu, &reg, false);
476             s->apr[i][cpu] = reg;
477         }
478     }
479 }
480 
481 static void kvm_arm_gic_reset(DeviceState *dev)
482 {
483     GICState *s = ARM_GIC_COMMON(dev);
484     KVMARMGICClass *kgc = KVM_ARM_GIC_GET_CLASS(s);
485 
486     kgc->parent_reset(dev);
487 
488     if (kvm_arm_gic_can_save_restore(s)) {
489         kvm_arm_gic_put(s);
490     }
491 }
492 
493 static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)
494 {
495     int i;
496     GICState *s = KVM_ARM_GIC(dev);
497     KVMARMGICClass *kgc = KVM_ARM_GIC_GET_CLASS(s);
498     Error *local_err = NULL;
499     int ret;
500 
501     kgc->parent_realize(dev, &local_err);
502     if (local_err) {
503         error_propagate(errp, local_err);
504         return;
505     }
506 
507     if (s->security_extn) {
508         error_setg(errp, "the in-kernel VGIC does not implement the "
509                    "security extensions");
510         return;
511     }
512 
513     if (s->virt_extn) {
514         error_setg(errp, "the in-kernel VGIC does not implement the "
515                    "virtualization extensions");
516         return;
517     }
518 
519     if (!kvm_arm_gic_can_save_restore(s)) {
520         error_setg(&s->migration_blocker, "This operating system kernel does "
521                                           "not support vGICv2 migration");
522         if (migrate_add_blocker(s->migration_blocker, errp) < 0) {
523             error_free(s->migration_blocker);
524             return;
525         }
526     }
527 
528     gic_init_irqs_and_mmio(s, kvm_arm_gicv2_set_irq, NULL, NULL);
529 
530     for (i = 0; i < s->num_irq - GIC_INTERNAL; i++) {
531         qemu_irq irq = qdev_get_gpio_in(dev, i);
532         kvm_irqchip_set_qemuirq_gsi(kvm_state, irq, i);
533     }
534 
535     /* Try to create the device via the device control API */
536     s->dev_fd = -1;
537     ret = kvm_create_device(kvm_state, KVM_DEV_TYPE_ARM_VGIC_V2, false);
538     if (ret >= 0) {
539         s->dev_fd = ret;
540 
541         /* Newstyle API is used, we may have attributes */
542         if (kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS, 0)) {
543             uint32_t numirqs = s->num_irq;
544             kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS, 0,
545                               &numirqs, true, &error_abort);
546         }
547         /* Tell the kernel to complete VGIC initialization now */
548         if (kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
549                                   KVM_DEV_ARM_VGIC_CTRL_INIT)) {
550             kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
551                               KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true,
552                               &error_abort);
553         }
554     } else if (kvm_check_extension(kvm_state, KVM_CAP_DEVICE_CTRL)) {
555         error_setg_errno(errp, -ret, "error creating in-kernel VGIC");
556         error_append_hint(errp,
557                           "Perhaps the host CPU does not support GICv2?\n");
558     } else if (ret != -ENODEV && ret != -ENOTSUP) {
559         /*
560          * Very ancient kernel without KVM_CAP_DEVICE_CTRL: assume that
561          * ENODEV or ENOTSUP mean "can't create GICv2 with KVM_CREATE_DEVICE",
562          * and that we will get a GICv2 via KVM_CREATE_IRQCHIP.
563          */
564         error_setg_errno(errp, -ret, "error creating in-kernel VGIC");
565         return;
566     }
567 
568     /* Distributor */
569     kvm_arm_register_device(&s->iomem,
570                             (KVM_ARM_DEVICE_VGIC_V2 << KVM_ARM_DEVICE_ID_SHIFT)
571                             | KVM_VGIC_V2_ADDR_TYPE_DIST,
572                             KVM_DEV_ARM_VGIC_GRP_ADDR,
573                             KVM_VGIC_V2_ADDR_TYPE_DIST,
574                             s->dev_fd, 0);
575     /* CPU interface for current core. Unlike arm_gic, we don't
576      * provide the "interface for core #N" memory regions, because
577      * cores with a VGIC don't have those.
578      */
579     kvm_arm_register_device(&s->cpuiomem[0],
580                             (KVM_ARM_DEVICE_VGIC_V2 << KVM_ARM_DEVICE_ID_SHIFT)
581                             | KVM_VGIC_V2_ADDR_TYPE_CPU,
582                             KVM_DEV_ARM_VGIC_GRP_ADDR,
583                             KVM_VGIC_V2_ADDR_TYPE_CPU,
584                             s->dev_fd, 0);
585 
586     if (kvm_has_gsi_routing()) {
587         /* set up irq routing */
588         for (i = 0; i < s->num_irq - GIC_INTERNAL; ++i) {
589             kvm_irqchip_add_irq_route(kvm_state, i, 0, i);
590         }
591 
592         kvm_gsi_routing_allowed = true;
593 
594         kvm_irqchip_commit_routes(kvm_state);
595     }
596 }
597 
598 static void kvm_arm_gic_class_init(ObjectClass *klass, void *data)
599 {
600     DeviceClass *dc = DEVICE_CLASS(klass);
601     ARMGICCommonClass *agcc = ARM_GIC_COMMON_CLASS(klass);
602     KVMARMGICClass *kgc = KVM_ARM_GIC_CLASS(klass);
603 
604     agcc->pre_save = kvm_arm_gic_get;
605     agcc->post_load = kvm_arm_gic_put;
606     device_class_set_parent_realize(dc, kvm_arm_gic_realize,
607                                     &kgc->parent_realize);
608     device_class_set_parent_reset(dc, kvm_arm_gic_reset, &kgc->parent_reset);
609 }
610 
611 static const TypeInfo kvm_arm_gic_info = {
612     .name = TYPE_KVM_ARM_GIC,
613     .parent = TYPE_ARM_GIC_COMMON,
614     .instance_size = sizeof(GICState),
615     .class_init = kvm_arm_gic_class_init,
616     .class_size = sizeof(KVMARMGICClass),
617 };
618 
619 static void kvm_arm_gic_register_types(void)
620 {
621     type_register_static(&kvm_arm_gic_info);
622 }
623 
624 type_init(kvm_arm_gic_register_types)
625