1 // SPDX-License-Identifier: GPL-2.0
3 * ACRN detection support
5 * Copyright (C) 2019 Intel Corporation. All rights reserved.
7 * Jason Chen CJ <jason.cj.chen@intel.com>
8 * Zhao Yakui <yakui.zhao@intel.com>
12 #include <linux/interrupt.h>
16 #include <asm/cpufeatures.h>
18 #include <asm/hypervisor.h>
19 #include <asm/idtentry.h>
20 #include <asm/irq_regs.h>
22 static u32 __init acrn_detect(void)
24 return acrn_cpuid_base();
27 static void __init acrn_init_platform(void)
29 /* Setup the IDT for ACRN hypervisor callback */
30 alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback);
33 static bool acrn_x2apic_available(void)
35 return boot_cpu_has(X86_FEATURE_X2APIC);
38 static void (*acrn_intr_handler)(void);
40 DEFINE_IDTENTRY_SYSVEC(sysvec_acrn_hv_callback)
42 struct pt_regs *old_regs = set_irq_regs(regs);
45 * The hypervisor requires that the APIC EOI should be acked.
46 * If the APIC EOI is not acked, the APIC ISR bit for the
47 * HYPERVISOR_CALLBACK_VECTOR will not be cleared and then it
48 * will block the interrupt whose vector is lower than
49 * HYPERVISOR_CALLBACK_VECTOR.
52 inc_irq_stat(irq_hv_callback_count);
54 if (acrn_intr_handler)
57 set_irq_regs(old_regs);
60 void acrn_setup_intr_handler(void (*handler)(void))
62 acrn_intr_handler = handler;
64 EXPORT_SYMBOL_GPL(acrn_setup_intr_handler);
66 void acrn_remove_intr_handler(void)
68 acrn_intr_handler = NULL;
70 EXPORT_SYMBOL_GPL(acrn_remove_intr_handler);
72 const __initconst struct hypervisor_x86 x86_hyper_acrn = {
74 .detect = acrn_detect,
75 .type = X86_HYPER_ACRN,
76 .init.init_platform = acrn_init_platform,
77 .init.x2apic_available = acrn_x2apic_available,