summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/vmwgfx/vmwgfx_msg.h
blob: 557a033fb610f1dfcb3568aceebd5592c97b3c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * Copyright (C) 2016, VMware, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
 * NON INFRINGEMENT.  See the GNU General Public License for more
 * details.
 *
 * Based on code from vmware.c and vmmouse.c.
 * Author:
 *   Sinclair Yeh <syeh@vmware.com>
 */
#ifndef _VMWGFX_MSG_H
#define _VMWGFX_MSG_H


/**
 * Hypervisor-specific bi-directional communication channel.  Should never
 * execute on bare metal hardware.  The caller must make sure to check for
 * supported hypervisor before using these macros.
 *
 * The last two parameters are both input and output and must be initialized.
 *
 * @cmd: [IN] Message Cmd
 * @in_ebx: [IN] Message Len, through EBX
 * @in_si: [IN] Input argument through SI, set to 0 if not used
 * @in_di: [IN] Input argument through DI, set ot 0 if not used
 * @port_num: [IN] port number + [channel id]
 * @magic: [IN] hypervisor magic value
 * @eax: [OUT] value of EAX register
 * @ebx: [OUT] e.g. status from an HB message status command
 * @ecx: [OUT] e.g. status from a non-HB message status command
 * @edx: [OUT] e.g. channel id
 * @si:  [OUT]
 * @di:  [OUT]
 */
#define VMW_PORT(cmd, in_ebx, in_si, in_di,	\
		 port_num, magic,		\
		 eax, ebx, ecx, edx, si, di)	\
({						\
	asm volatile ("inl %%dx, %%eax;" :	\
		"=a"(eax),			\
		"=b"(ebx),			\
		"=c"(ecx),			\
		"=d"(edx),			\
		"=S"(si),			\
		"=D"(di) :			\
		"a"(magic),			\
		"b"(in_ebx),			\
		"c"(cmd),			\
		"d"(port_num),			\
		"S"(in_si),			\
		"D"(in_di) :			\
		"memory");			\
})


/**
 * Hypervisor-specific bi-directional communication channel.  Should never
 * execute on bare metal hardware.  The caller must make sure to check for
 * supported hypervisor before using these macros.
 *
 * The last 3 parameters are both input and output and must be initialized.
 *
 * @cmd: [IN] Message Cmd
 * @in_ecx: [IN] Message Len, through ECX
 * @in_si: [IN] Input argument through SI, set to 0 if not used
 * @in_di: [IN] Input argument through DI, set to 0 if not used
 * @port_num: [IN] port number + [channel id]
 * @magic: [IN] hypervisor magic value
 * @bp:  [IN]
 * @eax: [OUT] value of EAX register
 * @ebx: [OUT] e.g. status from an HB message status command
 * @ecx: [OUT] e.g. status from a non-HB message status command
 * @edx: [OUT] e.g. channel id
 * @si:  [OUT]
 * @di:  [OUT]
 */
#ifdef __x86_64__

#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di,	\
			port_num, magic, bp,		\
			eax, ebx, ecx, edx, si, di)	\
({							\
	asm volatile ("push %%rbp;"			\
		"mov %12, %%rbp;"			\
		"rep outsb;"				\
		"pop %%rbp;" :				\
		"=a"(eax),				\
		"=b"(ebx),				\
		"=c"(ecx),				\
		"=d"(edx),				\
		"=S"(si),				\
		"=D"(di) :				\
		"a"(magic),				\
		"b"(cmd),				\
		"c"(in_ecx),				\
		"d"(port_num),				\
		"S"(in_si),				\
		"D"(in_di),				\
		"r"(bp) :				\
		"memory", "cc");			\
})


#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di,	\
		       port_num, magic, bp,		\
		       eax, ebx, ecx, edx, si, di)	\
({							\
	asm volatile ("push %%rbp;"			\
		"mov %12, %%rbp;"			\
		"rep insb;"				\
		"pop %%rbp" :				\
		"=a"(eax),				\
		"=b"(ebx),				\
		"=c"(ecx),				\
		"=d"(edx),				\
		"=S"(si),				\
		"=D"(di) :				\
		"a"(magic),				\
		"b"(cmd),				\
		"c"(in_ecx),				\
		"d"(port_num),				\
		"S"(in_si),				\
		"D"(in_di),				\
		"r"(bp) :				\
		"memory", "cc");			\
})

#else

/* In the 32-bit version of this macro, we use "m" because there is no
 * more register left for bp
 */
#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di,	\
			port_num, magic, bp,		\
			eax, ebx, ecx, edx, si, di)	\
({							\
	asm volatile ("push %%ebp;"			\
		"mov %12, %%ebp;"			\
		"rep outsb;"				\
		"pop %%ebp;" :				\
		"=a"(eax),				\
		"=b"(ebx),				\
		"=c"(ecx),				\
		"=d"(edx),				\
		"=S"(si),				\
		"=D"(di) :				\
		"a"(magic),				\
		"b"(cmd),				\
		"c"(in_ecx),				\
		"d"(port_num),				\
		"S"(in_si),				\
		"D"(in_di),				\
		"m"(bp) :				\
		"memory", "cc");			\
})


#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di,	\
		       port_num, magic, bp,		\
		       eax, ebx, ecx, edx, si, di)	\
({							\
	asm volatile ("push %%ebp;"			\
		"mov %12, %%ebp;"			\
		"rep insb;"				\
		"pop %%ebp" :				\
		"=a"(eax),				\
		"=b"(ebx),				\
		"=c"(ecx),				\
		"=d"(edx),				\
		"=S"(si),				\
		"=D"(di) :				\
		"a"(magic),				\
		"b"(cmd),				\
		"c"(in_ecx),				\
		"d"(port_num),				\
		"S"(in_si),				\
		"D"(in_di),				\
		"m"(bp) :				\
		"memory", "cc");			\
})
#endif /* #if __x86_64__ */

#endif