Loading...
1/* SPDX-License-Identifier: GPL-2.0+ OR MIT */
2/**************************************************************************
3 *
4 * Copyright 2016 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_H
33#define _VMWGFX_MSG_H
34
35#include <asm/vmware.h>
36
37/**
38 * Hypervisor-specific bi-directional communication channel. Should never
39 * execute on bare metal hardware. The caller must make sure to check for
40 * supported hypervisor before using these macros.
41 *
42 * The last two parameters are both input and output and must be initialized.
43 *
44 * @cmd: [IN] Message Cmd
45 * @in_ebx: [IN] Message Len, through EBX
46 * @in_si: [IN] Input argument through SI, set to 0 if not used
47 * @in_di: [IN] Input argument through DI, set ot 0 if not used
48 * @flags: [IN] hypercall flags + [channel id]
49 * @magic: [IN] hypervisor magic value
50 * @eax: [OUT] value of EAX register
51 * @ebx: [OUT] e.g. status from an HB message status command
52 * @ecx: [OUT] e.g. status from a non-HB message status command
53 * @edx: [OUT] e.g. channel id
54 * @si: [OUT]
55 * @di: [OUT]
56 */
57#define VMW_PORT(cmd, in_ebx, in_si, in_di, \
58 flags, magic, \
59 eax, ebx, ecx, edx, si, di) \
60({ \
61 asm volatile (VMWARE_HYPERCALL : \
62 "=a"(eax), \
63 "=b"(ebx), \
64 "=c"(ecx), \
65 "=d"(edx), \
66 "=S"(si), \
67 "=D"(di) : \
68 "a"(magic), \
69 "b"(in_ebx), \
70 "c"(cmd), \
71 "d"(flags), \
72 "S"(in_si), \
73 "D"(in_di) : \
74 "memory"); \
75})
76
77
78/**
79 * Hypervisor-specific bi-directional communication channel. Should never
80 * execute on bare metal hardware. The caller must make sure to check for
81 * supported hypervisor before using these macros.
82 *
83 * The last 3 parameters are both input and output and must be initialized.
84 *
85 * @cmd: [IN] Message Cmd
86 * @in_ecx: [IN] Message Len, through ECX
87 * @in_si: [IN] Input argument through SI, set to 0 if not used
88 * @in_di: [IN] Input argument through DI, set to 0 if not used
89 * @flags: [IN] hypercall flags + [channel id]
90 * @magic: [IN] hypervisor magic value
91 * @bp: [IN]
92 * @eax: [OUT] value of EAX register
93 * @ebx: [OUT] e.g. status from an HB message status command
94 * @ecx: [OUT] e.g. status from a non-HB message status command
95 * @edx: [OUT] e.g. channel id
96 * @si: [OUT]
97 * @di: [OUT]
98 */
99#ifdef __x86_64__
100
101#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
102 flags, magic, bp, \
103 eax, ebx, ecx, edx, si, di) \
104({ \
105 asm volatile ("push %%rbp;" \
106 "mov %12, %%rbp;" \
107 VMWARE_HYPERCALL_HB_OUT \
108 "pop %%rbp;" : \
109 "=a"(eax), \
110 "=b"(ebx), \
111 "=c"(ecx), \
112 "=d"(edx), \
113 "=S"(si), \
114 "=D"(di) : \
115 "a"(magic), \
116 "b"(cmd), \
117 "c"(in_ecx), \
118 "d"(flags), \
119 "S"(in_si), \
120 "D"(in_di), \
121 "r"(bp) : \
122 "memory", "cc"); \
123})
124
125
126#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
127 flags, magic, bp, \
128 eax, ebx, ecx, edx, si, di) \
129({ \
130 asm volatile ("push %%rbp;" \
131 "mov %12, %%rbp;" \
132 VMWARE_HYPERCALL_HB_IN \
133 "pop %%rbp" : \
134 "=a"(eax), \
135 "=b"(ebx), \
136 "=c"(ecx), \
137 "=d"(edx), \
138 "=S"(si), \
139 "=D"(di) : \
140 "a"(magic), \
141 "b"(cmd), \
142 "c"(in_ecx), \
143 "d"(flags), \
144 "S"(in_si), \
145 "D"(in_di), \
146 "r"(bp) : \
147 "memory", "cc"); \
148})
149
150#else
151
152/*
153 * In the 32-bit version of this macro, we store bp in a memory location
154 * because we've ran out of registers.
155 * Now we can't reference that memory location while we've modified
156 * %esp or %ebp, so we first push it on the stack, just before we push
157 * %ebp, and then when we need it we read it from the stack where we
158 * just pushed it.
159 */
160#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
161 flags, magic, bp, \
162 eax, ebx, ecx, edx, si, di) \
163({ \
164 asm volatile ("push %12;" \
165 "push %%ebp;" \
166 "mov 0x04(%%esp), %%ebp;" \
167 VMWARE_HYPERCALL_HB_OUT \
168 "pop %%ebp;" \
169 "add $0x04, %%esp;" : \
170 "=a"(eax), \
171 "=b"(ebx), \
172 "=c"(ecx), \
173 "=d"(edx), \
174 "=S"(si), \
175 "=D"(di) : \
176 "a"(magic), \
177 "b"(cmd), \
178 "c"(in_ecx), \
179 "d"(flags), \
180 "S"(in_si), \
181 "D"(in_di), \
182 "m"(bp) : \
183 "memory", "cc"); \
184})
185
186
187#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
188 flags, magic, bp, \
189 eax, ebx, ecx, edx, si, di) \
190({ \
191 asm volatile ("push %12;" \
192 "push %%ebp;" \
193 "mov 0x04(%%esp), %%ebp;" \
194 VMWARE_HYPERCALL_HB_IN \
195 "pop %%ebp;" \
196 "add $0x04, %%esp;" : \
197 "=a"(eax), \
198 "=b"(ebx), \
199 "=c"(ecx), \
200 "=d"(edx), \
201 "=S"(si), \
202 "=D"(di) : \
203 "a"(magic), \
204 "b"(cmd), \
205 "c"(in_ecx), \
206 "d"(flags), \
207 "S"(in_si), \
208 "D"(in_di), \
209 "m"(bp) : \
210 "memory", "cc"); \
211})
212#endif /* #if __x86_64__ */
213
214#endif
1/*
2 * Copyright (C) 2016, VMware, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 *
15 * Based on code from vmware.c and vmmouse.c.
16 * Author:
17 * Sinclair Yeh <syeh@vmware.com>
18 */
19#ifndef _VMWGFX_MSG_H
20#define _VMWGFX_MSG_H
21
22
23/**
24 * Hypervisor-specific bi-directional communication channel. Should never
25 * execute on bare metal hardware. The caller must make sure to check for
26 * supported hypervisor before using these macros.
27 *
28 * The last two parameters are both input and output and must be initialized.
29 *
30 * @cmd: [IN] Message Cmd
31 * @in_ebx: [IN] Message Len, through EBX
32 * @in_si: [IN] Input argument through SI, set to 0 if not used
33 * @in_di: [IN] Input argument through DI, set ot 0 if not used
34 * @port_num: [IN] port number + [channel id]
35 * @magic: [IN] hypervisor magic value
36 * @eax: [OUT] value of EAX register
37 * @ebx: [OUT] e.g. status from an HB message status command
38 * @ecx: [OUT] e.g. status from a non-HB message status command
39 * @edx: [OUT] e.g. channel id
40 * @si: [OUT]
41 * @di: [OUT]
42 */
43#define VMW_PORT(cmd, in_ebx, in_si, in_di, \
44 port_num, magic, \
45 eax, ebx, ecx, edx, si, di) \
46({ \
47 asm volatile ("inl %%dx, %%eax;" : \
48 "=a"(eax), \
49 "=b"(ebx), \
50 "=c"(ecx), \
51 "=d"(edx), \
52 "=S"(si), \
53 "=D"(di) : \
54 "a"(magic), \
55 "b"(in_ebx), \
56 "c"(cmd), \
57 "d"(port_num), \
58 "S"(in_si), \
59 "D"(in_di) : \
60 "memory"); \
61})
62
63
64/**
65 * Hypervisor-specific bi-directional communication channel. Should never
66 * execute on bare metal hardware. The caller must make sure to check for
67 * supported hypervisor before using these macros.
68 *
69 * The last 3 parameters are both input and output and must be initialized.
70 *
71 * @cmd: [IN] Message Cmd
72 * @in_ecx: [IN] Message Len, through ECX
73 * @in_si: [IN] Input argument through SI, set to 0 if not used
74 * @in_di: [IN] Input argument through DI, set to 0 if not used
75 * @port_num: [IN] port number + [channel id]
76 * @magic: [IN] hypervisor magic value
77 * @bp: [IN]
78 * @eax: [OUT] value of EAX register
79 * @ebx: [OUT] e.g. status from an HB message status command
80 * @ecx: [OUT] e.g. status from a non-HB message status command
81 * @edx: [OUT] e.g. channel id
82 * @si: [OUT]
83 * @di: [OUT]
84 */
85#ifdef __x86_64__
86
87#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
88 port_num, magic, bp, \
89 eax, ebx, ecx, edx, si, di) \
90({ \
91 asm volatile ("push %%rbp;" \
92 "mov %12, %%rbp;" \
93 "rep outsb;" \
94 "pop %%rbp;" : \
95 "=a"(eax), \
96 "=b"(ebx), \
97 "=c"(ecx), \
98 "=d"(edx), \
99 "=S"(si), \
100 "=D"(di) : \
101 "a"(magic), \
102 "b"(cmd), \
103 "c"(in_ecx), \
104 "d"(port_num), \
105 "S"(in_si), \
106 "D"(in_di), \
107 "r"(bp) : \
108 "memory", "cc"); \
109})
110
111
112#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
113 port_num, magic, bp, \
114 eax, ebx, ecx, edx, si, di) \
115({ \
116 asm volatile ("push %%rbp;" \
117 "mov %12, %%rbp;" \
118 "rep insb;" \
119 "pop %%rbp" : \
120 "=a"(eax), \
121 "=b"(ebx), \
122 "=c"(ecx), \
123 "=d"(edx), \
124 "=S"(si), \
125 "=D"(di) : \
126 "a"(magic), \
127 "b"(cmd), \
128 "c"(in_ecx), \
129 "d"(port_num), \
130 "S"(in_si), \
131 "D"(in_di), \
132 "r"(bp) : \
133 "memory", "cc"); \
134})
135
136#else
137
138/* In the 32-bit version of this macro, we use "m" because there is no
139 * more register left for bp
140 */
141#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
142 port_num, magic, bp, \
143 eax, ebx, ecx, edx, si, di) \
144({ \
145 asm volatile ("push %%ebp;" \
146 "mov %12, %%ebp;" \
147 "rep outsb;" \
148 "pop %%ebp;" : \
149 "=a"(eax), \
150 "=b"(ebx), \
151 "=c"(ecx), \
152 "=d"(edx), \
153 "=S"(si), \
154 "=D"(di) : \
155 "a"(magic), \
156 "b"(cmd), \
157 "c"(in_ecx), \
158 "d"(port_num), \
159 "S"(in_si), \
160 "D"(in_di), \
161 "m"(bp) : \
162 "memory", "cc"); \
163})
164
165
166#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
167 port_num, magic, bp, \
168 eax, ebx, ecx, edx, si, di) \
169({ \
170 asm volatile ("push %%ebp;" \
171 "mov %12, %%ebp;" \
172 "rep insb;" \
173 "pop %%ebp" : \
174 "=a"(eax), \
175 "=b"(ebx), \
176 "=c"(ecx), \
177 "=d"(edx), \
178 "=S"(si), \
179 "=D"(di) : \
180 "a"(magic), \
181 "b"(cmd), \
182 "c"(in_ecx), \
183 "d"(port_num), \
184 "S"(in_si), \
185 "D"(in_di), \
186 "m"(bp) : \
187 "memory", "cc"); \
188})
189#endif /* #if __x86_64__ */
190
191#endif