]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - ubuntu/vbox/include/VBox/VBoxVideoGuest.h
UBUNTU: ubuntu: vbox -- update to 5.1.28-dfsg-1
[mirror_ubuntu-bionic-kernel.git] / ubuntu / vbox / include / VBox / VBoxVideoGuest.h
1 /** @file
2 * VBox Host Guest Shared Memory Interface (HGSMI).
3 * OS-independent guest structures.
4 */
5
6 /*
7 * Copyright (C) 2006-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28 #ifndef ___VBox_VBoxVideoGuest_h___
29 #define ___VBox_VBoxVideoGuest_h___
30
31 #include <VBox/HGSMI/HGSMI.h>
32 #include <VBox/HGSMI/HGSMIChSetup.h>
33 #include <VBox/VBoxVideo.h>
34
35 #ifdef VBOX_XPDM_MINIPORT
36 # include <iprt/nt/miniport.h>
37 # include <ntddvdeo.h> /* sdk, clean */
38 # include <iprt/nt/Video.h>
39 #elif defined VBOX_GUESTR3XORGMOD
40 # include <compiler.h>
41 #else
42 # include <iprt/asm-amd64-x86.h>
43 #endif
44
45 #ifdef VBOX_WDDM_MINIPORT
46 # include "wddm/VBoxMPShgsmi.h"
47 typedef VBOXSHGSMI HGSMIGUESTCMDHEAP;
48 # define HGSMIGUESTCMDHEAP_GET(_p) (&(_p)->Heap)
49 #else
50 typedef HGSMIHEAP HGSMIGUESTCMDHEAP;
51 # define HGSMIGUESTCMDHEAP_GET(_p) (_p)
52 #endif
53
54 RT_C_DECLS_BEGIN
55
56 /**
57 * Structure grouping the context needed for submitting commands to the host
58 * via HGSMI
59 */
60 typedef struct HGSMIGUESTCOMMANDCONTEXT
61 {
62 /** Information about the memory heap located in VRAM from which data
63 * structures to be sent to the host are allocated. */
64 HGSMIGUESTCMDHEAP heapCtx;
65 /** The I/O port used for submitting commands to the host by writing their
66 * offsets into the heap. */
67 RTIOPORT port;
68 } HGSMIGUESTCOMMANDCONTEXT, *PHGSMIGUESTCOMMANDCONTEXT;
69
70
71 /**
72 * Structure grouping the context needed for receiving commands from the host
73 * via HGSMI
74 */
75 typedef struct HGSMIHOSTCOMMANDCONTEXT
76 {
77 /** Information about the memory area located in VRAM in which the host
78 * places data structures to be read by the guest. */
79 HGSMIAREA areaCtx;
80 /** Convenience structure used for matching host commands to handlers. */
81 /** @todo handlers are registered individually in code rather than just
82 * passing a static structure in order to gain extra flexibility. There is
83 * currently no expected usage case for this though. Is the additional
84 * complexity really justified? */
85 HGSMICHANNELINFO channels;
86 /** Flag to indicate that one thread is currently processing the command
87 * queue. */
88 volatile bool fHostCmdProcessing;
89 /* Pointer to the VRAM location where the HGSMI host flags are kept. */
90 volatile HGSMIHOSTFLAGS *pfHostFlags;
91 /** The I/O port used for receiving commands from the host as offsets into
92 * the memory area and sending back confirmations (command completion,
93 * IRQ acknowlegement). */
94 RTIOPORT port;
95 } HGSMIHOSTCOMMANDCONTEXT, *PHGSMIHOSTCOMMANDCONTEXT;
96
97
98 /**
99 * Structure grouping the context needed for sending graphics acceleration
100 * information to the host via VBVA. Each screen has its own VBVA buffer.
101 */
102 typedef struct VBVABUFFERCONTEXT
103 {
104 /** Offset of the buffer in the VRAM section for the screen */
105 uint32_t offVRAMBuffer;
106 /** Length of the buffer in bytes */
107 uint32_t cbBuffer;
108 /** This flag is set if we wrote to the buffer faster than the host could
109 * read it. */
110 bool fHwBufferOverflow;
111 /** The VBVA record that we are currently preparing for the host, NULL if
112 * none. */
113 struct VBVARECORD *pRecord;
114 /** Pointer to the VBVA buffer mapped into the current address space. Will
115 * be NULL if VBVA is not enabled. */
116 struct VBVABUFFER *pVBVA;
117 } VBVABUFFERCONTEXT, *PVBVABUFFERCONTEXT;
118
119 /** @name Helper functions
120 * @{ */
121 /** Write an 8-bit value to an I/O port. */
122 DECLINLINE(void) VBoxVideoCmnPortWriteUchar(RTIOPORT Port, uint8_t Value)
123 {
124 #ifdef VBOX_XPDM_MINIPORT
125 VideoPortWritePortUchar((PUCHAR)Port, Value);
126 #elif defined VBOX_GUESTR3XORGMOD
127 outb(Port, Value);
128 #else /** @todo make these explicit */
129 ASMOutU8(Port, Value);
130 #endif
131 }
132
133 /** Write a 16-bit value to an I/O port. */
134 DECLINLINE(void) VBoxVideoCmnPortWriteUshort(RTIOPORT Port, uint16_t Value)
135 {
136 #ifdef VBOX_XPDM_MINIPORT
137 VideoPortWritePortUshort((PUSHORT)Port,Value);
138 #elif defined VBOX_GUESTR3XORGMOD
139 outw(Port, Value);
140 #else
141 ASMOutU16(Port, Value);
142 #endif
143 }
144
145 /** Write a 32-bit value to an I/O port. */
146 DECLINLINE(void) VBoxVideoCmnPortWriteUlong(RTIOPORT Port, uint32_t Value)
147 {
148 #ifdef VBOX_XPDM_MINIPORT
149 VideoPortWritePortUlong((PULONG)Port,Value);
150 #elif defined VBOX_GUESTR3XORGMOD
151 outl(Port, Value);
152 #else
153 ASMOutU32(Port, Value);
154 #endif
155 }
156
157 /** Read an 8-bit value from an I/O port. */
158 DECLINLINE(uint8_t) VBoxVideoCmnPortReadUchar(RTIOPORT Port)
159 {
160 #ifdef VBOX_XPDM_MINIPORT
161 return VideoPortReadPortUchar((PUCHAR)Port);
162 #elif defined VBOX_GUESTR3XORGMOD
163 return inb(Port);
164 #else
165 return ASMInU8(Port);
166 #endif
167 }
168
169 /** Read a 16-bit value from an I/O port. */
170 DECLINLINE(uint16_t) VBoxVideoCmnPortReadUshort(RTIOPORT Port)
171 {
172 #ifdef VBOX_XPDM_MINIPORT
173 return VideoPortReadPortUshort((PUSHORT)Port);
174 #elif defined VBOX_GUESTR3XORGMOD
175 return inw(Port);
176 #else
177 return ASMInU16(Port);
178 #endif
179 }
180
181 /** Read a 32-bit value from an I/O port. */
182 DECLINLINE(uint32_t) VBoxVideoCmnPortReadUlong(RTIOPORT Port)
183 {
184 #ifdef VBOX_XPDM_MINIPORT
185 return VideoPortReadPortUlong((PULONG)Port);
186 #elif defined VBOX_GUESTR3XORGMOD
187 return inl(Port);
188 #else
189 return ASMInU32(Port);
190 #endif
191 }
192
193 /** @} */
194
195 /** @name Base HGSMI APIs
196 * @{ */
197
198 /** Acknowlege an IRQ. */
199 DECLINLINE(void) VBoxHGSMIClearIrq(PHGSMIHOSTCOMMANDCONTEXT pCtx)
200 {
201 VBoxVideoCmnPortWriteUlong(pCtx->port, HGSMIOFFSET_VOID);
202 }
203
204 DECLHIDDEN(void) VBoxHGSMIHostCmdComplete(PHGSMIHOSTCOMMANDCONTEXT pCtx,
205 void *pvMem);
206 DECLHIDDEN(void) VBoxHGSMIProcessHostQueue(PHGSMIHOSTCOMMANDCONTEXT pCtx);
207 DECLHIDDEN(bool) VBoxHGSMIIsSupported(void);
208 DECLHIDDEN(void *) VBoxHGSMIBufferAlloc(PHGSMIGUESTCOMMANDCONTEXT pCtx,
209 HGSMISIZE cbData,
210 uint8_t u8Ch,
211 uint16_t u16Op);
212 DECLHIDDEN(void) VBoxHGSMIBufferFree(PHGSMIGUESTCOMMANDCONTEXT pCtx,
213 void *pvBuffer);
214 DECLHIDDEN(int) VBoxHGSMIBufferSubmit(PHGSMIGUESTCOMMANDCONTEXT pCtx,
215 void *pvBuffer);
216 DECLHIDDEN(void) VBoxHGSMIGetBaseMappingInfo(uint32_t cbVRAM,
217 uint32_t *poffVRAMBaseMapping,
218 uint32_t *pcbMapping,
219 uint32_t *poffGuestHeapMemory,
220 uint32_t *pcbGuestHeapMemory,
221 uint32_t *poffHostFlags);
222 DECLHIDDEN(int) VBoxHGSMIReportFlagsLocation(PHGSMIGUESTCOMMANDCONTEXT pCtx,
223 HGSMIOFFSET offLocation);
224 DECLHIDDEN(int) VBoxHGSMISendCapsInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
225 uint32_t fCaps);
226 /** @todo we should provide a cleanup function too as part of the API */
227 DECLHIDDEN(int) VBoxHGSMISetupGuestContext(PHGSMIGUESTCOMMANDCONTEXT pCtx,
228 void *pvGuestHeapMemory,
229 uint32_t cbGuestHeapMemory,
230 uint32_t offVRAMGuestHeapMemory,
231 const HGSMIENV *pEnv);
232 DECLHIDDEN(void) VBoxHGSMIGetHostAreaMapping(PHGSMIGUESTCOMMANDCONTEXT pCtx,
233 uint32_t cbVRAM,
234 uint32_t offVRAMBaseMapping,
235 uint32_t *poffVRAMHostArea,
236 uint32_t *pcbHostArea);
237 DECLHIDDEN(void) VBoxHGSMISetupHostContext(PHGSMIHOSTCOMMANDCONTEXT pCtx,
238 void *pvBaseMapping,
239 uint32_t offHostFlags,
240 void *pvHostAreaMapping,
241 uint32_t offVRAMHostArea,
242 uint32_t cbHostArea);
243 DECLHIDDEN(int) VBoxHGSMISendHostCtxInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
244 HGSMIOFFSET offVRAMFlagsLocation,
245 uint32_t fCaps,
246 uint32_t offVRAMHostArea,
247 uint32_t cbHostArea);
248 DECLHIDDEN(int) VBoxQueryConfHGSMI(PHGSMIGUESTCOMMANDCONTEXT pCtx,
249 uint32_t u32Index, uint32_t *pulValue);
250 DECLHIDDEN(int) VBoxQueryConfHGSMIDef(PHGSMIGUESTCOMMANDCONTEXT pCtx,
251 uint32_t u32Index, uint32_t u32DefValue, uint32_t *pulValue);
252 DECLHIDDEN(int) VBoxHGSMIUpdatePointerShape(PHGSMIGUESTCOMMANDCONTEXT pCtx,
253 uint32_t fFlags,
254 uint32_t cHotX,
255 uint32_t cHotY,
256 uint32_t cWidth,
257 uint32_t cHeight,
258 uint8_t *pPixels,
259 uint32_t cbLength);
260 DECLHIDDEN(int) VBoxHGSMICursorPosition(PHGSMIGUESTCOMMANDCONTEXT pCtx, bool fReportPosition, uint32_t x, uint32_t y,
261 uint32_t *pxHost, uint32_t *pyHost);
262
263 /** @} */
264
265 /** @name VBVA APIs
266 * @{ */
267 DECLHIDDEN(bool) VBoxVBVAEnable(PVBVABUFFERCONTEXT pCtx,
268 PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
269 struct VBVABUFFER *pVBVA, int32_t cScreen);
270 DECLHIDDEN(void) VBoxVBVADisable(PVBVABUFFERCONTEXT pCtx,
271 PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
272 int32_t cScreen);
273 DECLHIDDEN(bool) VBoxVBVABufferBeginUpdate(PVBVABUFFERCONTEXT pCtx,
274 PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx);
275 DECLHIDDEN(void) VBoxVBVABufferEndUpdate(PVBVABUFFERCONTEXT pCtx);
276 DECLHIDDEN(bool) VBoxVBVAWrite(PVBVABUFFERCONTEXT pCtx,
277 PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
278 const void *pv, uint32_t cb);
279 DECLHIDDEN(bool) VBoxVBVAOrderSupported(PVBVABUFFERCONTEXT pCtx, unsigned code);
280 DECLHIDDEN(void) VBoxVBVASetupBufferContext(PVBVABUFFERCONTEXT pCtx,
281 uint32_t offVRAMBuffer,
282 uint32_t cbBuffer);
283
284 /** @} */
285
286 /** @name Modesetting APIs
287 * @{ */
288
289 DECLHIDDEN(uint32_t) VBoxHGSMIGetMonitorCount(PHGSMIGUESTCOMMANDCONTEXT pCtx);
290 DECLHIDDEN(uint32_t) VBoxVideoGetVRAMSize(void);
291 DECLHIDDEN(bool) VBoxVideoAnyWidthAllowed(void);
292 DECLHIDDEN(uint16_t) VBoxHGSMIGetScreenFlags(PHGSMIGUESTCOMMANDCONTEXT pCtx);
293
294 struct VBVAINFOVIEW;
295 /**
296 * Callback funtion called from @a VBoxHGSMISendViewInfo to initialise
297 * the @a VBVAINFOVIEW structure for each screen.
298 *
299 * @returns iprt status code
300 * @param pvData context data for the callback, passed to @a
301 * VBoxHGSMISendViewInfo along with the callback
302 * @param pInfo array of @a VBVAINFOVIEW structures to be filled in
303 * @todo explicitly pass the array size
304 */
305 typedef DECLCALLBACK(int) FNHGSMIFILLVIEWINFO(void *pvData,
306 struct VBVAINFOVIEW *pInfo,
307 uint32_t cViews);
308 /** Pointer to a FNHGSMIFILLVIEWINFO callback */
309 typedef FNHGSMIFILLVIEWINFO *PFNHGSMIFILLVIEWINFO;
310
311 DECLHIDDEN(int) VBoxHGSMISendViewInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
312 uint32_t u32Count,
313 PFNHGSMIFILLVIEWINFO pfnFill,
314 void *pvData);
315 DECLHIDDEN(void) VBoxVideoSetModeRegisters(uint16_t cWidth, uint16_t cHeight,
316 uint16_t cVirtWidth, uint16_t cBPP,
317 uint16_t fFlags,
318 uint16_t cx, uint16_t cy);
319 DECLHIDDEN(bool) VBoxVideoGetModeRegisters(uint16_t *pcWidth,
320 uint16_t *pcHeight,
321 uint16_t *pcVirtWidth,
322 uint16_t *pcBPP,
323 uint16_t *pfFlags);
324 DECLHIDDEN(void) VBoxVideoDisableVBE(void);
325 DECLHIDDEN(void) VBoxHGSMIProcessDisplayInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
326 uint32_t cDisplay,
327 int32_t cOriginX,
328 int32_t cOriginY,
329 uint32_t offStart,
330 uint32_t cbPitch,
331 uint32_t cWidth,
332 uint32_t cHeight,
333 uint16_t cBPP,
334 uint16_t fFlags);
335 DECLHIDDEN(int) VBoxHGSMIUpdateInputMapping(PHGSMIGUESTCOMMANDCONTEXT pCtx, int32_t cOriginX, int32_t cOriginY,
336 uint32_t cWidth, uint32_t cHeight);
337 DECLHIDDEN(int) VBoxHGSMIGetModeHints(PHGSMIGUESTCOMMANDCONTEXT pCtx,
338 unsigned cScreens, VBVAMODEHINT *paHints);
339
340 /** @} */
341
342 RT_C_DECLS_END
343
344 #endif
345