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