acrn.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 <[email protected]>
  8. * Zhao Yakui <[email protected]>
  9. *
  10. */
  11. #include <linux/interrupt.h>
  12. #include <asm/acrn.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. static u32 __init acrn_detect(void)
  20. {
  21. return acrn_cpuid_base();
  22. }
  23. static void __init acrn_init_platform(void)
  24. {
  25. /* Setup the IDT for ACRN hypervisor callback */
  26. alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback);
  27. x86_platform.calibrate_tsc = acrn_get_tsc_khz;
  28. x86_platform.calibrate_cpu = acrn_get_tsc_khz;
  29. }
  30. static bool acrn_x2apic_available(void)
  31. {
  32. return boot_cpu_has(X86_FEATURE_X2APIC);
  33. }
  34. static void (*acrn_intr_handler)(void);
  35. DEFINE_IDTENTRY_SYSVEC(sysvec_acrn_hv_callback)
  36. {
  37. struct pt_regs *old_regs = set_irq_regs(regs);
  38. /*
  39. * The hypervisor requires that the APIC EOI should be acked.
  40. * If the APIC EOI is not acked, the APIC ISR bit for the
  41. * HYPERVISOR_CALLBACK_VECTOR will not be cleared and then it
  42. * will block the interrupt whose vector is lower than
  43. * HYPERVISOR_CALLBACK_VECTOR.
  44. */
  45. ack_APIC_irq();
  46. inc_irq_stat(irq_hv_callback_count);
  47. if (acrn_intr_handler)
  48. acrn_intr_handler();
  49. set_irq_regs(old_regs);
  50. }
  51. void acrn_setup_intr_handler(void (*handler)(void))
  52. {
  53. acrn_intr_handler = handler;
  54. }
  55. EXPORT_SYMBOL_GPL(acrn_setup_intr_handler);
  56. void acrn_remove_intr_handler(void)
  57. {
  58. acrn_intr_handler = NULL;
  59. }
  60. EXPORT_SYMBOL_GPL(acrn_remove_intr_handler);
  61. const __initconst struct hypervisor_x86 x86_hyper_acrn = {
  62. .name = "ACRN",
  63. .detect = acrn_detect,
  64. .type = X86_HYPER_ACRN,
  65. .init.init_platform = acrn_init_platform,
  66. .init.x2apic_available = acrn_x2apic_available,
  67. };