acrn.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_ACRN_H
  3. #define _ASM_X86_ACRN_H
  4. /*
  5. * This CPUID returns feature bitmaps in EAX.
  6. * Guest VM uses this to detect the appropriate feature bit.
  7. */
  8. #define ACRN_CPUID_FEATURES 0x40000001
  9. /* Bit 0 indicates whether guest VM is privileged */
  10. #define ACRN_FEATURE_PRIVILEGED_VM BIT(0)
  11. /*
  12. * Timing Information.
  13. * This leaf returns the current TSC frequency in kHz.
  14. *
  15. * EAX: (Virtual) TSC frequency in kHz.
  16. * EBX, ECX, EDX: RESERVED (reserved fields are set to zero).
  17. */
  18. #define ACRN_CPUID_TIMING_INFO 0x40000010
  19. void acrn_setup_intr_handler(void (*handler)(void));
  20. void acrn_remove_intr_handler(void);
  21. static inline u32 acrn_cpuid_base(void)
  22. {
  23. if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
  24. return hypervisor_cpuid_base("ACRNACRNACRN", 0);
  25. return 0;
  26. }
  27. static inline unsigned long acrn_get_tsc_khz(void)
  28. {
  29. return cpuid_eax(ACRN_CPUID_TIMING_INFO);
  30. }
  31. /*
  32. * Hypercalls for ACRN
  33. *
  34. * - VMCALL instruction is used to implement ACRN hypercalls.
  35. * - ACRN hypercall ABI:
  36. * - Hypercall number is passed in R8 register.
  37. * - Up to 2 arguments are passed in RDI, RSI.
  38. * - Return value will be placed in RAX.
  39. *
  40. * Because GCC doesn't support R8 register as direct register constraints, use
  41. * supported constraint as input with a explicit MOV to R8 in beginning of asm.
  42. */
  43. static inline long acrn_hypercall0(unsigned long hcall_id)
  44. {
  45. long result;
  46. asm volatile("movl %1, %%r8d\n\t"
  47. "vmcall\n\t"
  48. : "=a" (result)
  49. : "g" (hcall_id)
  50. : "r8", "memory");
  51. return result;
  52. }
  53. static inline long acrn_hypercall1(unsigned long hcall_id,
  54. unsigned long param1)
  55. {
  56. long result;
  57. asm volatile("movl %1, %%r8d\n\t"
  58. "vmcall\n\t"
  59. : "=a" (result)
  60. : "g" (hcall_id), "D" (param1)
  61. : "r8", "memory");
  62. return result;
  63. }
  64. static inline long acrn_hypercall2(unsigned long hcall_id,
  65. unsigned long param1,
  66. unsigned long param2)
  67. {
  68. long result;
  69. asm volatile("movl %1, %%r8d\n\t"
  70. "vmcall\n\t"
  71. : "=a" (result)
  72. : "g" (hcall_id), "D" (param1), "S" (param2)
  73. : "r8", "memory");
  74. return result;
  75. }
  76. #endif /* _ASM_X86_ACRN_H */