]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/arch/x86/include/asm/jailhouse_hypercall.h
5e148c81c49d8e669383677cb2a9821e868e22b3
[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 #define JAILHOUSE_CALL_ARG3     "d" (arg3)
25 #define JAILHOUSE_CALL_ARG4     "c" (arg4)
26
27 #ifndef __ASSEMBLY__
28
29 static inline __u32 jailhouse_call0(__u32 num)
30 {
31         __u32 result;
32
33         asm volatile(JAILHOUSE_CALL_INS
34                 : JAILHOUSE_CALL_RESULT
35                 : JAILHOUSE_CALL_NUM
36                 : "memory");
37         return result;
38 }
39
40 static inline __u32 jailhouse_call1(__u32 num, __u32 arg1)
41 {
42         __u32 result;
43
44         asm volatile(JAILHOUSE_CALL_INS
45                 : JAILHOUSE_CALL_RESULT
46                 : JAILHOUSE_CALL_NUM, JAILHOUSE_CALL_ARG1
47                 : "memory");
48         return result;
49 }
50
51 static inline __u32 jailhouse_call2(__u32 num, __u32 arg1, __u32 arg2)
52 {
53         __u32 result;
54
55         asm volatile(JAILHOUSE_CALL_INS
56                 : JAILHOUSE_CALL_RESULT
57                 : JAILHOUSE_CALL_NUM, JAILHOUSE_CALL_ARG1, JAILHOUSE_CALL_ARG2
58                 : "memory");
59         return result;
60 }
61
62 static inline __u32 jailhouse_call3(__u32 num, __u32 arg1, __u32 arg2,
63                                    __u32 arg3)
64 {
65         __u32 result;
66
67         asm volatile(JAILHOUSE_CALL_INS
68                 : JAILHOUSE_CALL_RESULT
69                 : JAILHOUSE_CALL_NUM, JAILHOUSE_CALL_ARG1, JAILHOUSE_CALL_ARG2,
70                   JAILHOUSE_CALL_ARG3
71                 : "memory");
72         return result;
73 }
74
75 static inline __u32 jailhouse_call4(__u32 num, __u32 arg1, __u32 arg2,
76                                    __u32 arg3, __u32 arg4)
77 {
78         __u32 result;
79
80         asm volatile(JAILHOUSE_CALL_INS
81                 : JAILHOUSE_CALL_RESULT
82                 : JAILHOUSE_CALL_NUM, JAILHOUSE_CALL_ARG1, JAILHOUSE_CALL_ARG2,
83                   JAILHOUSE_CALL_ARG3, JAILHOUSE_CALL_ARG4
84                 : "memory");
85         return result;
86 }
87
88 static inline void
89 jailhouse_send_msg_to_cell(struct jailhouse_comm_region *comm_region,
90                            __u32 msg)
91 {
92         comm_region->reply_from_cell = JAILHOUSE_MSG_NONE;
93         /* ensure reply was cleared before sending new message */
94         asm volatile("mfence" : : : "memory");
95         comm_region->msg_to_cell = msg;
96 }
97
98 static inline void
99 jailhouse_send_reply_from_cell(struct jailhouse_comm_region *comm_region,
100                                __u32 reply)
101 {
102         comm_region->msg_to_cell = JAILHOUSE_MSG_NONE;
103         /* ensure message was cleared before sending reply */
104         asm volatile("mfence" : : : "memory");
105         comm_region->reply_from_cell = reply;
106 }
107
108 #endif /* !__ASSEMBLY__ */