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