Linux Audio

Check our new training course

Loading...
v5.4
 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/acrn.h>
14#include <asm/apic.h>
 
15#include <asm/desc.h>
16#include <asm/hypervisor.h>
 
17#include <asm/irq_regs.h>
18
19static uint32_t __init acrn_detect(void)
20{
21	return hypervisor_cpuid_base("ACRNACRNACRN\0\0", 0);
22}
23
24static void __init acrn_init_platform(void)
25{
26	/* Setup the IDT for ACRN hypervisor callback */
27	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, acrn_hv_callback_vector);
 
 
 
28}
29
30static bool acrn_x2apic_available(void)
31{
32	/*
33	 * x2apic is not supported for now. Future enablement will have to check
34	 * X86_FEATURE_X2APIC to determine whether x2apic is supported in the
35	 * guest.
36	 */
37	return false;
38}
39
40static void (*acrn_intr_handler)(void);
41
42__visible void __irq_entry acrn_hv_vector_handler(struct pt_regs *regs)
43{
44	struct pt_regs *old_regs = set_irq_regs(regs);
45
46	/*
47	 * The hypervisor requires that the APIC EOI should be acked.
48	 * If the APIC EOI is not acked, the APIC ISR bit for the
49	 * HYPERVISOR_CALLBACK_VECTOR will not be cleared and then it
50	 * will block the interrupt whose vector is lower than
51	 * HYPERVISOR_CALLBACK_VECTOR.
52	 */
53	entering_ack_irq();
54	inc_irq_stat(irq_hv_callback_count);
55
56	if (acrn_intr_handler)
57		acrn_intr_handler();
58
59	exiting_irq();
60	set_irq_regs(old_regs);
61}
 
 
 
 
 
 
 
 
 
 
 
 
62
63const __initconst struct hypervisor_x86 x86_hyper_acrn = {
64	.name                   = "ACRN",
65	.detect                 = acrn_detect,
66	.type			= X86_HYPER_ACRN,
67	.init.init_platform     = acrn_init_platform,
68	.init.x2apic_available  = acrn_x2apic_available,
69};
v6.8
 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
22static u32 __init acrn_detect(void)
23{
24	return acrn_cpuid_base();
25}
26
27static void __init acrn_init_platform(void)
28{
29	/* Setup the IDT for ACRN hypervisor callback */
30	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_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
36static bool acrn_x2apic_available(void)
37{
38	return boot_cpu_has(X86_FEATURE_X2APIC);
 
 
 
 
 
39}
40
41static void (*acrn_intr_handler)(void);
42
43DEFINE_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
63void acrn_setup_intr_handler(void (*handler)(void))
64{
65	acrn_intr_handler = handler;
66}
67EXPORT_SYMBOL_GPL(acrn_setup_intr_handler);
68
69void acrn_remove_intr_handler(void)
70{
71	acrn_intr_handler = NULL;
72}
73EXPORT_SYMBOL_GPL(acrn_remove_intr_handler);
74
75const __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};