xref: /linux/arch/x86/kernel/cpu/acrn.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
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 
14 #include <asm/acrn.h>
15 #include <asm/apic.h>
16 #include <asm/cpufeatures.h>
17 #include <asm/desc.h>
18 #include <asm/hypervisor.h>
19 #include <asm/idtentry.h>
20 #include <asm/irq_regs.h>
21 
acrn_detect(void)22 static u32 __init acrn_detect(void)
23 {
24 	return acrn_cpuid_base();
25 }
26 
acrn_init_platform(void)27 static void __init acrn_init_platform(void)
28 {
29 	/* Install system interrupt handler for ACRN hypervisor callback */
30 	sysvec_install(HYPERVISOR_CALLBACK_VECTOR, sysvec_acrn_hv_callback);
31 
32 	x86_platform.calibrate_tsc = acrn_get_tsc_khz;
33 	x86_platform.calibrate_cpu = acrn_get_tsc_khz;
34 }
35 
acrn_x2apic_available(void)36 static bool acrn_x2apic_available(void)
37 {
38 	return boot_cpu_has(X86_FEATURE_X2APIC);
39 }
40 
41 static void (*acrn_intr_handler)(void);
42 
DEFINE_IDTENTRY_SYSVEC(sysvec_acrn_hv_callback)43 DEFINE_IDTENTRY_SYSVEC(sysvec_acrn_hv_callback)
44 {
45 	struct pt_regs *old_regs = set_irq_regs(regs);
46 
47 	/*
48 	 * The hypervisor requires that the APIC EOI should be acked.
49 	 * If the APIC EOI is not acked, the APIC ISR bit for the
50 	 * HYPERVISOR_CALLBACK_VECTOR will not be cleared and then it
51 	 * will block the interrupt whose vector is lower than
52 	 * HYPERVISOR_CALLBACK_VECTOR.
53 	 */
54 	apic_eoi();
55 	inc_irq_stat(irq_hv_callback_count);
56 
57 	if (acrn_intr_handler)
58 		acrn_intr_handler();
59 
60 	set_irq_regs(old_regs);
61 }
62 
acrn_setup_intr_handler(void (* handler)(void))63 void acrn_setup_intr_handler(void (*handler)(void))
64 {
65 	acrn_intr_handler = handler;
66 }
67 EXPORT_SYMBOL_GPL(acrn_setup_intr_handler);
68 
acrn_remove_intr_handler(void)69 void acrn_remove_intr_handler(void)
70 {
71 	acrn_intr_handler = NULL;
72 }
73 EXPORT_SYMBOL_GPL(acrn_remove_intr_handler);
74 
75 const __initconst struct hypervisor_x86 x86_hyper_acrn = {
76 	.name                   = "ACRN",
77 	.detect                 = acrn_detect,
78 	.type			= X86_HYPER_ACRN,
79 	.init.init_platform     = acrn_init_platform,
80 	.init.x2apic_available  = acrn_x2apic_available,
81 };
82