David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 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> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13 | #include <asm/apic.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 14 | #include <asm/cpufeatures.h> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15 | #include <asm/desc.h> |
| 16 | #include <asm/hypervisor.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 17 | #include <asm/idtentry.h> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 18 | #include <asm/irq_regs.h> |
| 19 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 20 | static u32 __init acrn_detect(void) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 21 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 22 | return hypervisor_cpuid_base("ACRNACRNACRN", 0); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | static void __init acrn_init_platform(void) |
| 26 | { |
| 27 | /* Setup the IDT for ACRN hypervisor callback */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 28 | alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static bool acrn_x2apic_available(void) |
| 32 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 33 | return boot_cpu_has(X86_FEATURE_X2APIC); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static void (*acrn_intr_handler)(void); |
| 37 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 38 | DEFINE_IDTENTRY_SYSVEC(sysvec_acrn_hv_callback) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 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 | */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 49 | ack_APIC_irq(); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 50 | inc_irq_stat(irq_hv_callback_count); |
| 51 | |
| 52 | if (acrn_intr_handler) |
| 53 | acrn_intr_handler(); |
| 54 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 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 | }; |