1 | /* SPDX-License-Identifier: GPL-2.0+ OR MIT */ |
2 | /************************************************************************** |
3 | * |
4 | * Copyright 2016-2021 VMware, Inc., Palo Alto, CA., USA |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the |
8 | * "Software"), to deal in the Software without restriction, including |
9 | * without limitation the rights to use, copy, modify, merge, publish, |
10 | * distribute, sub license, and/or sell copies of the Software, and to |
11 | * permit persons to whom the Software is furnished to do so, subject to |
12 | * the following conditions: |
13 | * |
14 | * The above copyright notice and this permission notice (including the |
15 | * next paragraph) shall be included in all copies or substantial portions |
16 | * of the Software. |
17 | * |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
25 | * |
26 | ************************************************************************** |
27 | * |
28 | * Based on code from vmware.c and vmmouse.c. |
29 | * Author: |
30 | * Sinclair Yeh <syeh@vmware.com> |
31 | */ |
32 | #ifndef _VMWGFX_MSG_X86_H |
33 | #define _VMWGFX_MSG_X86_H |
34 | |
35 | |
36 | #if defined(__i386__) || defined(__x86_64__) |
37 | |
38 | #include <asm/vmware.h> |
39 | |
40 | /** |
41 | * Hypervisor-specific bi-directional communication channel. Should never |
42 | * execute on bare metal hardware. The caller must make sure to check for |
43 | * supported hypervisor before using these macros. |
44 | * |
45 | * The last two parameters are both input and output and must be initialized. |
46 | * |
47 | * @cmd: [IN] Message Cmd |
48 | * @in_ebx: [IN] Message Len, through EBX |
49 | * @in_si: [IN] Input argument through SI, set to 0 if not used |
50 | * @in_di: [IN] Input argument through DI, set ot 0 if not used |
51 | * @flags: [IN] hypercall flags + [channel id] |
52 | * @magic: [IN] hypervisor magic value |
53 | * @eax: [OUT] value of EAX register |
54 | * @ebx: [OUT] e.g. status from an HB message status command |
55 | * @ecx: [OUT] e.g. status from a non-HB message status command |
56 | * @edx: [OUT] e.g. channel id |
57 | * @si: [OUT] |
58 | * @di: [OUT] |
59 | */ |
60 | #define VMW_PORT(cmd, in_ebx, in_si, in_di, \ |
61 | flags, magic, \ |
62 | eax, ebx, ecx, edx, si, di) \ |
63 | ({ \ |
64 | asm volatile (VMWARE_HYPERCALL : \ |
65 | "=a"(eax), \ |
66 | "=b"(ebx), \ |
67 | "=c"(ecx), \ |
68 | "=d"(edx), \ |
69 | "=S"(si), \ |
70 | "=D"(di) : \ |
71 | "a"(magic), \ |
72 | "b"(in_ebx), \ |
73 | "c"(cmd), \ |
74 | "d"(flags), \ |
75 | "S"(in_si), \ |
76 | "D"(in_di) : \ |
77 | "memory"); \ |
78 | }) |
79 | |
80 | |
81 | /** |
82 | * Hypervisor-specific bi-directional communication channel. Should never |
83 | * execute on bare metal hardware. The caller must make sure to check for |
84 | * supported hypervisor before using these macros. |
85 | * |
86 | * The last 3 parameters are both input and output and must be initialized. |
87 | * |
88 | * @cmd: [IN] Message Cmd |
89 | * @in_ecx: [IN] Message Len, through ECX |
90 | * @in_si: [IN] Input argument through SI, set to 0 if not used |
91 | * @in_di: [IN] Input argument through DI, set to 0 if not used |
92 | * @flags: [IN] hypercall flags + [channel id] |
93 | * @magic: [IN] hypervisor magic value |
94 | * @bp: [IN] |
95 | * @eax: [OUT] value of EAX register |
96 | * @ebx: [OUT] e.g. status from an HB message status command |
97 | * @ecx: [OUT] e.g. status from a non-HB message status command |
98 | * @edx: [OUT] e.g. channel id |
99 | * @si: [OUT] |
100 | * @di: [OUT] |
101 | */ |
102 | #ifdef __x86_64__ |
103 | |
104 | #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \ |
105 | flags, magic, bp, \ |
106 | eax, ebx, ecx, edx, si, di) \ |
107 | ({ \ |
108 | asm volatile ( \ |
109 | UNWIND_HINT_SAVE \ |
110 | "push %%rbp;" \ |
111 | UNWIND_HINT_UNDEFINED \ |
112 | "mov %12, %%rbp;" \ |
113 | VMWARE_HYPERCALL_HB_OUT \ |
114 | "pop %%rbp;" \ |
115 | UNWIND_HINT_RESTORE : \ |
116 | "=a"(eax), \ |
117 | "=b"(ebx), \ |
118 | "=c"(ecx), \ |
119 | "=d"(edx), \ |
120 | "=S"(si), \ |
121 | "=D"(di) : \ |
122 | "a"(magic), \ |
123 | "b"(cmd), \ |
124 | "c"(in_ecx), \ |
125 | "d"(flags), \ |
126 | "S"(in_si), \ |
127 | "D"(in_di), \ |
128 | "r"(bp) : \ |
129 | "memory", "cc"); \ |
130 | }) |
131 | |
132 | |
133 | #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \ |
134 | flags, magic, bp, \ |
135 | eax, ebx, ecx, edx, si, di) \ |
136 | ({ \ |
137 | asm volatile ( \ |
138 | UNWIND_HINT_SAVE \ |
139 | "push %%rbp;" \ |
140 | UNWIND_HINT_UNDEFINED \ |
141 | "mov %12, %%rbp;" \ |
142 | VMWARE_HYPERCALL_HB_IN \ |
143 | "pop %%rbp;" \ |
144 | UNWIND_HINT_RESTORE : \ |
145 | "=a"(eax), \ |
146 | "=b"(ebx), \ |
147 | "=c"(ecx), \ |
148 | "=d"(edx), \ |
149 | "=S"(si), \ |
150 | "=D"(di) : \ |
151 | "a"(magic), \ |
152 | "b"(cmd), \ |
153 | "c"(in_ecx), \ |
154 | "d"(flags), \ |
155 | "S"(in_si), \ |
156 | "D"(in_di), \ |
157 | "r"(bp) : \ |
158 | "memory", "cc"); \ |
159 | }) |
160 | |
161 | #elif defined(__i386__) |
162 | |
163 | /* |
164 | * In the 32-bit version of this macro, we store bp in a memory location |
165 | * because we've ran out of registers. |
166 | * Now we can't reference that memory location while we've modified |
167 | * %esp or %ebp, so we first push it on the stack, just before we push |
168 | * %ebp, and then when we need it we read it from the stack where we |
169 | * just pushed it. |
170 | */ |
171 | #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \ |
172 | flags, magic, bp, \ |
173 | eax, ebx, ecx, edx, si, di) \ |
174 | ({ \ |
175 | asm volatile ("push %12;" \ |
176 | "push %%ebp;" \ |
177 | "mov 0x04(%%esp), %%ebp;" \ |
178 | VMWARE_HYPERCALL_HB_OUT \ |
179 | "pop %%ebp;" \ |
180 | "add $0x04, %%esp;" : \ |
181 | "=a"(eax), \ |
182 | "=b"(ebx), \ |
183 | "=c"(ecx), \ |
184 | "=d"(edx), \ |
185 | "=S"(si), \ |
186 | "=D"(di) : \ |
187 | "a"(magic), \ |
188 | "b"(cmd), \ |
189 | "c"(in_ecx), \ |
190 | "d"(flags), \ |
191 | "S"(in_si), \ |
192 | "D"(in_di), \ |
193 | "m"(bp) : \ |
194 | "memory", "cc"); \ |
195 | }) |
196 | |
197 | |
198 | #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \ |
199 | flags, magic, bp, \ |
200 | eax, ebx, ecx, edx, si, di) \ |
201 | ({ \ |
202 | asm volatile ("push %12;" \ |
203 | "push %%ebp;" \ |
204 | "mov 0x04(%%esp), %%ebp;" \ |
205 | VMWARE_HYPERCALL_HB_IN \ |
206 | "pop %%ebp;" \ |
207 | "add $0x04, %%esp;" : \ |
208 | "=a"(eax), \ |
209 | "=b"(ebx), \ |
210 | "=c"(ecx), \ |
211 | "=d"(edx), \ |
212 | "=S"(si), \ |
213 | "=D"(di) : \ |
214 | "a"(magic), \ |
215 | "b"(cmd), \ |
216 | "c"(in_ecx), \ |
217 | "d"(flags), \ |
218 | "S"(in_si), \ |
219 | "D"(in_di), \ |
220 | "m"(bp) : \ |
221 | "memory", "cc"); \ |
222 | }) |
223 | #endif /* defined(__i386__) */ |
224 | |
225 | #endif /* defined(__i386__) || defined(__x86_64__) */ |
226 | |
227 | #endif /* _VMWGFX_MSG_X86_H */ |
228 | |