]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/arch/x86/include/asm/jailhouse_hypercall.h
core: Add support for per-CPU statistics
[jailhouse.git] / hypervisor / arch / x86 / include / asm / jailhouse_hypercall.h
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2013
5  *
6  * Authors:
7  *  Jan Kiszka <jan.kiszka@siemens.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #ifndef __x86_64__
14 #error 64-bit kernel required!
15 #endif
16
17 #define JAILHOUSE_BASE          0xfffffffff0000000
18
19 #define JAILHOUSE_CALL_INS      "vmcall"
20 #define JAILHOUSE_CALL_RESULT   "=a" (result)
21 #define JAILHOUSE_CALL_NUM      "a" (num)
22 #define JAILHOUSE_CALL_ARG1     "D" (arg1)
23 #define JAILHOUSE_CALL_ARG2     "S" (arg2)
24
25 /* CPU statistics */
26 #define JAILHOUSE_CPU_STAT_VMEXITS_PIO          JAILHOUSE_GENERIC_CPU_STATS
27 #define JAILHOUSE_CPU_STAT_VMEXITS_XAPIC        JAILHOUSE_GENERIC_CPU_STATS + 1
28 #define JAILHOUSE_CPU_STAT_VMEXITS_CR           JAILHOUSE_GENERIC_CPU_STATS + 2
29 #define JAILHOUSE_CPU_STAT_VMEXITS_MSR          JAILHOUSE_GENERIC_CPU_STATS + 3
30 #define JAILHOUSE_CPU_STAT_VMEXITS_CPUID        JAILHOUSE_GENERIC_CPU_STATS + 4
31 #define JAILHOUSE_CPU_STAT_VMEXITS_XSETBV       JAILHOUSE_GENERIC_CPU_STATS + 5
32 #define JAILHOUSE_NUM_CPU_STATS                 JAILHOUSE_GENERIC_CPU_STATS + 6
33
34 #ifndef __ASSEMBLY__
35
36 static inline __u32 jailhouse_call(__u32 num)
37 {
38         __u32 result;
39
40         asm volatile(JAILHOUSE_CALL_INS
41                 : JAILHOUSE_CALL_RESULT
42                 : JAILHOUSE_CALL_NUM
43                 : "memory");
44         return result;
45 }
46
47 static inline __u32 jailhouse_call_arg1(__u32 num, __u32 arg1)
48 {
49         __u32 result;
50
51         asm volatile(JAILHOUSE_CALL_INS
52                 : JAILHOUSE_CALL_RESULT
53                 : JAILHOUSE_CALL_NUM, JAILHOUSE_CALL_ARG1
54                 : "memory");
55         return result;
56 }
57
58 static inline __u32 jailhouse_call_arg2(__u32 num, __u32 arg1, __u32 arg2)
59 {
60         __u32 result;
61
62         asm volatile(JAILHOUSE_CALL_INS
63                 : JAILHOUSE_CALL_RESULT
64                 : JAILHOUSE_CALL_NUM, JAILHOUSE_CALL_ARG1, JAILHOUSE_CALL_ARG2
65                 : "memory");
66         return result;
67 }
68
69 static inline void
70 jailhouse_send_msg_to_cell(struct jailhouse_comm_region *comm_region,
71                            __u32 msg)
72 {
73         comm_region->reply_from_cell = JAILHOUSE_MSG_NONE;
74         /* ensure reply was cleared before sending new message */
75         asm volatile("mfence" : : : "memory");
76         comm_region->msg_to_cell = msg;
77 }
78
79 static inline void
80 jailhouse_send_reply_from_cell(struct jailhouse_comm_region *comm_region,
81                                __u32 reply)
82 {
83         comm_region->msg_to_cell = JAILHOUSE_MSG_NONE;
84         /* ensure message was cleared before sending reply */
85         asm volatile("mfence" : : : "memory");
86         comm_region->reply_from_cell = reply;
87 }
88
89 #endif /* !__ASSEMBLY__ */