]>
Commit | Line | Data |
---|---|---|
a7bf3034 PF |
1 | /* |
2 | * ARM Generic Interrupt Controller using KVM in-kernel support | |
3 | * | |
4 | * Copyright (c) 2015 Samsung Electronics Co., Ltd. | |
5 | * Written by Pavel Fedin | |
6 | * Based on vGICv2 code by Peter Maydell | |
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 | ||
8ef94f0b | 22 | #include "qemu/osdep.h" |
da34e65c | 23 | #include "qapi/error.h" |
a7bf3034 PF |
24 | #include "hw/intc/arm_gicv3_common.h" |
25 | #include "hw/sysbus.h" | |
26 | #include "sysemu/kvm.h" | |
27 | #include "kvm_arm.h" | |
28 | #include "vgic_common.h" | |
757caeed | 29 | #include "migration/migration.h" |
a7bf3034 PF |
30 | |
31 | #ifdef DEBUG_GICV3_KVM | |
32 | #define DPRINTF(fmt, ...) \ | |
33 | do { fprintf(stderr, "kvm_gicv3: " fmt, ## __VA_ARGS__); } while (0) | |
34 | #else | |
35 | #define DPRINTF(fmt, ...) \ | |
36 | do { } while (0) | |
37 | #endif | |
38 | ||
39 | #define TYPE_KVM_ARM_GICV3 "kvm-arm-gicv3" | |
40 | #define KVM_ARM_GICV3(obj) \ | |
41 | OBJECT_CHECK(GICv3State, (obj), TYPE_KVM_ARM_GICV3) | |
42 | #define KVM_ARM_GICV3_CLASS(klass) \ | |
43 | OBJECT_CLASS_CHECK(KVMARMGICv3Class, (klass), TYPE_KVM_ARM_GICV3) | |
44 | #define KVM_ARM_GICV3_GET_CLASS(obj) \ | |
45 | OBJECT_GET_CLASS(KVMARMGICv3Class, (obj), TYPE_KVM_ARM_GICV3) | |
46 | ||
47 | typedef struct KVMARMGICv3Class { | |
48 | ARMGICv3CommonClass parent_class; | |
49 | DeviceRealize parent_realize; | |
50 | void (*parent_reset)(DeviceState *dev); | |
51 | } KVMARMGICv3Class; | |
52 | ||
53 | static void kvm_arm_gicv3_set_irq(void *opaque, int irq, int level) | |
54 | { | |
55 | GICv3State *s = (GICv3State *)opaque; | |
56 | ||
57 | kvm_arm_gic_set_irq(s->num_irq, irq, level); | |
58 | } | |
59 | ||
60 | static void kvm_arm_gicv3_put(GICv3State *s) | |
61 | { | |
62 | /* TODO */ | |
63 | DPRINTF("Cannot put kernel gic state, no kernel interface\n"); | |
64 | } | |
65 | ||
66 | static void kvm_arm_gicv3_get(GICv3State *s) | |
67 | { | |
68 | /* TODO */ | |
69 | DPRINTF("Cannot get kernel gic state, no kernel interface\n"); | |
70 | } | |
71 | ||
72 | static void kvm_arm_gicv3_reset(DeviceState *dev) | |
73 | { | |
74 | GICv3State *s = ARM_GICV3_COMMON(dev); | |
75 | KVMARMGICv3Class *kgc = KVM_ARM_GICV3_GET_CLASS(s); | |
76 | ||
77 | DPRINTF("Reset\n"); | |
78 | ||
79 | kgc->parent_reset(dev); | |
80 | kvm_arm_gicv3_put(s); | |
81 | } | |
82 | ||
83 | static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp) | |
84 | { | |
85 | GICv3State *s = KVM_ARM_GICV3(dev); | |
86 | KVMARMGICv3Class *kgc = KVM_ARM_GICV3_GET_CLASS(s); | |
87 | Error *local_err = NULL; | |
88 | ||
89 | DPRINTF("kvm_arm_gicv3_realize\n"); | |
90 | ||
91 | kgc->parent_realize(dev, &local_err); | |
92 | if (local_err) { | |
93 | error_propagate(errp, local_err); | |
94 | return; | |
95 | } | |
96 | ||
97 | if (s->security_extn) { | |
98 | error_setg(errp, "the in-kernel VGICv3 does not implement the " | |
99 | "security extensions"); | |
100 | return; | |
101 | } | |
102 | ||
103 | gicv3_init_irqs_and_mmio(s, kvm_arm_gicv3_set_irq, NULL); | |
104 | ||
105 | /* Try to create the device via the device control API */ | |
106 | s->dev_fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_ARM_VGIC_V3, false); | |
107 | if (s->dev_fd < 0) { | |
108 | error_setg_errno(errp, -s->dev_fd, "error creating in-kernel VGIC"); | |
109 | return; | |
110 | } | |
111 | ||
112 | kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS, | |
113 | 0, &s->num_irq, true); | |
114 | ||
115 | /* Tell the kernel to complete VGIC initialization now */ | |
116 | kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL, | |
117 | KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true); | |
118 | ||
119 | kvm_arm_register_device(&s->iomem_dist, -1, KVM_DEV_ARM_VGIC_GRP_ADDR, | |
120 | KVM_VGIC_V3_ADDR_TYPE_DIST, s->dev_fd); | |
121 | kvm_arm_register_device(&s->iomem_redist, -1, KVM_DEV_ARM_VGIC_GRP_ADDR, | |
122 | KVM_VGIC_V3_ADDR_TYPE_REDIST, s->dev_fd); | |
757caeed PF |
123 | |
124 | /* Block migration of a KVM GICv3 device: the API for saving and restoring | |
125 | * the state in the kernel is not yet finalised in the kernel or | |
126 | * implemented in QEMU. | |
127 | */ | |
128 | error_setg(&s->migration_blocker, "vGICv3 migration is not implemented"); | |
129 | migrate_add_blocker(s->migration_blocker); | |
a7bf3034 PF |
130 | } |
131 | ||
132 | static void kvm_arm_gicv3_class_init(ObjectClass *klass, void *data) | |
133 | { | |
134 | DeviceClass *dc = DEVICE_CLASS(klass); | |
135 | ARMGICv3CommonClass *agcc = ARM_GICV3_COMMON_CLASS(klass); | |
136 | KVMARMGICv3Class *kgc = KVM_ARM_GICV3_CLASS(klass); | |
137 | ||
138 | agcc->pre_save = kvm_arm_gicv3_get; | |
139 | agcc->post_load = kvm_arm_gicv3_put; | |
140 | kgc->parent_realize = dc->realize; | |
141 | kgc->parent_reset = dc->reset; | |
142 | dc->realize = kvm_arm_gicv3_realize; | |
143 | dc->reset = kvm_arm_gicv3_reset; | |
144 | } | |
145 | ||
146 | static const TypeInfo kvm_arm_gicv3_info = { | |
147 | .name = TYPE_KVM_ARM_GICV3, | |
148 | .parent = TYPE_ARM_GICV3_COMMON, | |
149 | .instance_size = sizeof(GICv3State), | |
150 | .class_init = kvm_arm_gicv3_class_init, | |
151 | .class_size = sizeof(KVMARMGICv3Class), | |
152 | }; | |
153 | ||
154 | static void kvm_arm_gicv3_register_types(void) | |
155 | { | |
156 | type_register_static(&kvm_arm_gicv3_info); | |
157 | } | |
158 | ||
159 | type_init(kvm_arm_gicv3_register_types) |