2 * Copyright (C) 2015, 2016 ARM Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <linux/uaccess.h>
18 #include <linux/interrupt.h>
19 #include <linux/cpu.h>
20 #include <linux/kvm_host.h>
21 #include <kvm/arm_vgic.h>
22 #include <asm/kvm_mmu.h>
27 static void vgic_init_maintenance_interrupt(void *info
)
29 enable_percpu_irq(kvm_vgic_global_state
.maint_irq
, 0);
32 static int vgic_cpu_notify(struct notifier_block
*self
,
33 unsigned long action
, void *cpu
)
37 case CPU_STARTING_FROZEN
:
38 vgic_init_maintenance_interrupt(NULL
);
41 case CPU_DYING_FROZEN
:
42 disable_percpu_irq(kvm_vgic_global_state
.maint_irq
);
49 static struct notifier_block vgic_cpu_nb
= {
50 .notifier_call
= vgic_cpu_notify
,
53 static irqreturn_t
vgic_maintenance_handler(int irq
, void *data
)
56 * We cannot rely on the vgic maintenance interrupt to be
57 * delivered synchronously. This means we can only use it to
58 * exit the VM, and we perform the handling of EOIed
59 * interrupts on the exit path (see vgic_process_maintenance).
65 * kvm_vgic_hyp_init: populates the kvm_vgic_global_state variable
66 * according to the host GIC model. Accordingly calls either
67 * vgic_v2/v3_probe which registers the KVM_DEVICE that can be
68 * instantiated by a guest later on .
70 int kvm_vgic_hyp_init(void)
72 const struct gic_kvm_info
*gic_kvm_info
;
75 gic_kvm_info
= gic_get_kvm_info();
79 if (!gic_kvm_info
->maint_irq
) {
80 kvm_err("No vgic maintenance irq\n");
84 switch (gic_kvm_info
->type
) {
86 ret
= vgic_v2_probe(gic_kvm_info
);
89 ret
= vgic_v3_probe(gic_kvm_info
);
98 kvm_vgic_global_state
.maint_irq
= gic_kvm_info
->maint_irq
;
99 ret
= request_percpu_irq(kvm_vgic_global_state
.maint_irq
,
100 vgic_maintenance_handler
,
101 "vgic", kvm_get_running_vcpus());
103 kvm_err("Cannot register interrupt %d\n",
104 kvm_vgic_global_state
.maint_irq
);
108 ret
= __register_cpu_notifier(&vgic_cpu_nb
);
110 kvm_err("Cannot register vgic CPU notifier\n");
114 on_each_cpu(vgic_init_maintenance_interrupt
, NULL
, 1);
116 kvm_info("vgic interrupt IRQ%d\n", kvm_vgic_global_state
.maint_irq
);
120 free_percpu_irq(kvm_vgic_global_state
.maint_irq
,
121 kvm_get_running_vcpus());