xref: /openbmc/linux/arch/x86/kernel/cpu/acrn.c (revision 0b26ca68)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * ACRN detection support
4  *
5  * Copyright (C) 2019 Intel Corporation. All rights reserved.
6  *
7  * Jason Chen CJ <jason.cj.chen@intel.com>
8  * Zhao Yakui <yakui.zhao@intel.com>
9  *
10  */
11 
12 #include <linux/interrupt.h>
13 #include <asm/apic.h>
14 #include <asm/cpufeatures.h>
15 #include <asm/desc.h>
16 #include <asm/hypervisor.h>
17 #include <asm/idtentry.h>
18 #include <asm/irq_regs.h>
19 
20 static u32 __init acrn_detect(void)
21 {
22 	return hypervisor_cpuid_base("ACRNACRNACRN", 0);
23 }
24 
25 static void __init acrn_init_platform(void)
26 {
27 	/* Setup the IDT for ACRN hypervisor callback */
28 	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback);
29 }
30 
31 static bool acrn_x2apic_available(void)
32 {
33 	return boot_cpu_has(X86_FEATURE_X2APIC);
34 }
35 
36 static void (*acrn_intr_handler)(void);
37 
38 DEFINE_IDTENTRY_SYSVEC(sysvec_acrn_hv_callback)
39 {
40 	struct pt_regs *old_regs = set_irq_regs(regs);
41 
42 	/*
43 	 * The hypervisor requires that the APIC EOI should be acked.
44 	 * If the APIC EOI is not acked, the APIC ISR bit for the
45 	 * HYPERVISOR_CALLBACK_VECTOR will not be cleared and then it
46 	 * will block the interrupt whose vector is lower than
47 	 * HYPERVISOR_CALLBACK_VECTOR.
48 	 */
49 	ack_APIC_irq();
50 	inc_irq_stat(irq_hv_callback_count);
51 
52 	if (acrn_intr_handler)
53 		acrn_intr_handler();
54 
55 	set_irq_regs(old_regs);
56 }
57 
58 const __initconst struct hypervisor_x86 x86_hyper_acrn = {
59 	.name                   = "ACRN",
60 	.detect                 = acrn_detect,
61 	.type			= X86_HYPER_ACRN,
62 	.init.init_platform     = acrn_init_platform,
63 	.init.x2apic_available  = acrn_x2apic_available,
64 };
65