2 * VBox Host Guest Shared Memory Interface (HGSMI).
3 * OS-independent guest structures.
7 * Copyright (C) 2006-2016 Oracle Corporation
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.
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.
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.
28 #ifndef ___VBox_VBoxVideoGuest_h___
29 #define ___VBox_VBoxVideoGuest_h___
31 #include <VBox/HGSMI/HGSMI.h>
32 #include <VBox/HGSMI/HGSMIChSetup.h>
33 #include <VBox/VBoxVideo.h>
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>
42 # include <iprt/asm-amd64-x86.h>
45 #ifdef VBOX_WDDM_MINIPORT
46 # include "wddm/VBoxMPShgsmi.h"
47 typedef VBOXSHGSMI HGSMIGUESTCMDHEAP
;
48 # define HGSMIGUESTCMDHEAP_GET(_p) (&(_p)->Heap)
50 typedef HGSMIHEAP HGSMIGUESTCMDHEAP
;
51 # define HGSMIGUESTCMDHEAP_GET(_p) (_p)
57 * Structure grouping the context needed for submitting commands to the host
60 typedef struct HGSMIGUESTCOMMANDCONTEXT
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. */
68 } HGSMIGUESTCOMMANDCONTEXT
, *PHGSMIGUESTCOMMANDCONTEXT
;
72 * Structure grouping the context needed for receiving commands from the host
75 typedef struct HGSMIHOSTCOMMANDCONTEXT
77 /** Information about the memory area located in VRAM in which the host
78 * places data structures to be read by the guest. */
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
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). */
95 } HGSMIHOSTCOMMANDCONTEXT
, *PHGSMIHOSTCOMMANDCONTEXT
;
99 * Structure grouping the context needed for sending graphics acceleration
100 * information to the host via VBVA. Each screen has its own VBVA buffer.
102 typedef struct VBVABUFFERCONTEXT
104 /** Offset of the buffer in the VRAM section for the screen */
105 uint32_t offVRAMBuffer
;
106 /** Length of the buffer in bytes */
108 /** This flag is set if we wrote to the buffer faster than the host could
110 bool fHwBufferOverflow
;
111 /** The VBVA record that we are currently preparing for the host, NULL if
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
;
119 /** @name Helper functions
121 /** Write an 8-bit value to an I/O port. */
122 DECLINLINE(void) VBoxVideoCmnPortWriteUchar(RTIOPORT Port
, uint8_t Value
)
124 #ifdef VBOX_XPDM_MINIPORT
125 VideoPortWritePortUchar((PUCHAR
)Port
, Value
);
126 #elif defined VBOX_GUESTR3XORGMOD
128 #else /** @todo make these explicit */
129 ASMOutU8(Port
, Value
);
133 /** Write a 16-bit value to an I/O port. */
134 DECLINLINE(void) VBoxVideoCmnPortWriteUshort(RTIOPORT Port
, uint16_t Value
)
136 #ifdef VBOX_XPDM_MINIPORT
137 VideoPortWritePortUshort((PUSHORT
)Port
,Value
);
138 #elif defined VBOX_GUESTR3XORGMOD
141 ASMOutU16(Port
, Value
);
145 /** Write a 32-bit value to an I/O port. */
146 DECLINLINE(void) VBoxVideoCmnPortWriteUlong(RTIOPORT Port
, uint32_t Value
)
148 #ifdef VBOX_XPDM_MINIPORT
149 VideoPortWritePortUlong((PULONG
)Port
,Value
);
150 #elif defined VBOX_GUESTR3XORGMOD
153 ASMOutU32(Port
, Value
);
157 /** Read an 8-bit value from an I/O port. */
158 DECLINLINE(uint8_t) VBoxVideoCmnPortReadUchar(RTIOPORT Port
)
160 #ifdef VBOX_XPDM_MINIPORT
161 return VideoPortReadPortUchar((PUCHAR
)Port
);
162 #elif defined VBOX_GUESTR3XORGMOD
165 return ASMInU8(Port
);
169 /** Read a 16-bit value from an I/O port. */
170 DECLINLINE(uint16_t) VBoxVideoCmnPortReadUshort(RTIOPORT Port
)
172 #ifdef VBOX_XPDM_MINIPORT
173 return VideoPortReadPortUshort((PUSHORT
)Port
);
174 #elif defined VBOX_GUESTR3XORGMOD
177 return ASMInU16(Port
);
181 /** Read a 32-bit value from an I/O port. */
182 DECLINLINE(uint32_t) VBoxVideoCmnPortReadUlong(RTIOPORT Port
)
184 #ifdef VBOX_XPDM_MINIPORT
185 return VideoPortReadPortUlong((PULONG
)Port
);
186 #elif defined VBOX_GUESTR3XORGMOD
189 return ASMInU32(Port
);
195 /** @name Base HGSMI APIs
198 /** Acknowlege an IRQ. */
199 DECLINLINE(void) VBoxHGSMIClearIrq(PHGSMIHOSTCOMMANDCONTEXT pCtx
)
201 VBoxVideoCmnPortWriteUlong(pCtx
->port
, HGSMIOFFSET_VOID
);
204 DECLHIDDEN(void) VBoxHGSMIHostCmdComplete(PHGSMIHOSTCOMMANDCONTEXT pCtx
,
206 DECLHIDDEN(void) VBoxHGSMIProcessHostQueue(PHGSMIHOSTCOMMANDCONTEXT pCtx
);
207 DECLHIDDEN(bool) VBoxHGSMIIsSupported(void);
208 DECLHIDDEN(void *) VBoxHGSMIBufferAlloc(PHGSMIGUESTCOMMANDCONTEXT pCtx
,
212 DECLHIDDEN(void) VBoxHGSMIBufferFree(PHGSMIGUESTCOMMANDCONTEXT pCtx
,
214 DECLHIDDEN(int) VBoxHGSMIBufferSubmit(PHGSMIGUESTCOMMANDCONTEXT pCtx
,
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
,
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
,
234 uint32_t offVRAMBaseMapping
,
235 uint32_t *poffVRAMHostArea
,
236 uint32_t *pcbHostArea
);
237 DECLHIDDEN(void) VBoxHGSMISetupHostContext(PHGSMIHOSTCOMMANDCONTEXT pCtx
,
239 uint32_t offHostFlags
,
240 void *pvHostAreaMapping
,
241 uint32_t offVRAMHostArea
,
242 uint32_t cbHostArea
);
243 DECLHIDDEN(int) VBoxHGSMISendHostCtxInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx
,
244 HGSMIOFFSET offVRAMFlagsLocation
,
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
,
260 DECLHIDDEN(int) VBoxHGSMICursorPosition(PHGSMIGUESTCOMMANDCONTEXT pCtx
, bool fReportPosition
, uint32_t x
, uint32_t y
,
261 uint32_t *pxHost
, uint32_t *pyHost
);
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
,
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
,
286 /** @name Modesetting APIs
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
);
296 * Callback funtion called from @a VBoxHGSMISendViewInfo to initialise
297 * the @a VBVAINFOVIEW structure for each screen.
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
305 typedef DECLCALLBACK(int) FNHGSMIFILLVIEWINFO(void *pvData
,
306 struct VBVAINFOVIEW
*pInfo
,
308 /** Pointer to a FNHGSMIFILLVIEWINFO callback */
309 typedef FNHGSMIFILLVIEWINFO
*PFNHGSMIFILLVIEWINFO
;
311 DECLHIDDEN(int) VBoxHGSMISendViewInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx
,
313 PFNHGSMIFILLVIEWINFO pfnFill
,
315 DECLHIDDEN(void) VBoxVideoSetModeRegisters(uint16_t cWidth
, uint16_t cHeight
,
316 uint16_t cVirtWidth
, uint16_t cBPP
,
318 uint16_t cx
, uint16_t cy
);
319 DECLHIDDEN(bool) VBoxVideoGetModeRegisters(uint16_t *pcWidth
,
321 uint16_t *pcVirtWidth
,
324 DECLHIDDEN(void) VBoxVideoDisableVBE(void);
325 DECLHIDDEN(void) VBoxHGSMIProcessDisplayInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx
,
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
);