1 | /* $Id: DevVGA-SVGA-internal.h 86886 2020-11-14 02:30:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMWare SVGA device - internal header for DevVGA-SVGA* source files.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2020 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 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA_internal_h
|
---|
19 | #define VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA_internal_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * Assert sane compilation environment.
|
---|
26 | */
|
---|
27 | #ifndef IN_RING3
|
---|
28 | # error "DevVGA-SVGA-internal.h is only for ring-3 code"
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #include <iprt/avl.h>
|
---|
32 | #include <iprt/list.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /*********************************************************************************************************************************
|
---|
36 | * Structures and Typedefs *
|
---|
37 | *********************************************************************************************************************************/
|
---|
38 | /**
|
---|
39 | * 64-bit GMR descriptor.
|
---|
40 | */
|
---|
41 | typedef struct
|
---|
42 | {
|
---|
43 | RTGCPHYS GCPhys;
|
---|
44 | uint64_t numPages;
|
---|
45 | } VMSVGAGMRDESCRIPTOR, *PVMSVGAGMRDESCRIPTOR;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * GMR slot
|
---|
49 | */
|
---|
50 | typedef struct
|
---|
51 | {
|
---|
52 | uint32_t cMaxPages;
|
---|
53 | uint32_t cbTotal;
|
---|
54 | uint32_t numDescriptors;
|
---|
55 | PVMSVGAGMRDESCRIPTOR paDesc;
|
---|
56 | } GMR, *PGMR;
|
---|
57 |
|
---|
58 | /*
|
---|
59 | * GBO (Guest Backed Object).
|
---|
60 | * A GBO is a list of the guest pages. GBOs are used for VMSVGA MOBs (Memory OBjects)
|
---|
61 | * and Object Tables which the guest shares with the host.
|
---|
62 | *
|
---|
63 | * A GBO is similar to a GMR. Nevertheless I'll create a new code for GBOs in order
|
---|
64 | * to avoid tweaking and possibly breaking existing code. Moreover it will be probably possible to
|
---|
65 | * map the guest pages into the host R3 memory and access them directly.
|
---|
66 | */
|
---|
67 |
|
---|
68 | /* GBO descriptor. */
|
---|
69 | typedef struct VMSVGAGBODESCRIPTOR
|
---|
70 | {
|
---|
71 | RTGCPHYS GCPhys;
|
---|
72 | uint64_t cPages;
|
---|
73 | } VMSVGAGBODESCRIPTOR, *PVMSVGAGBODESCRIPTOR;
|
---|
74 | typedef VMSVGAGBODESCRIPTOR const *PCVMSVGAGBODESCRIPTOR;
|
---|
75 |
|
---|
76 | /* GBO.
|
---|
77 | */
|
---|
78 | typedef struct VMSVGAGBO
|
---|
79 | {
|
---|
80 | uint32_t fGboFlags;
|
---|
81 | uint32_t cTotalPages;
|
---|
82 | uint32_t cbTotal;
|
---|
83 | uint32_t cDescriptors;
|
---|
84 | PVMSVGAGBODESCRIPTOR paDescriptors;
|
---|
85 | } VMSVGAGBO, *PVMSVGAGBO;
|
---|
86 | typedef VMSVGAGBO const *PCVMSVGAGBO;
|
---|
87 |
|
---|
88 | #define VMSVGAGBO_F_WRITE_PROTECTED 1
|
---|
89 |
|
---|
90 | #define VMSVGA_IS_GBO_CREATED(a_Gbo) ((a_Gbo)->paDescriptors != NULL)
|
---|
91 |
|
---|
92 | /* MOB is also a GBO.
|
---|
93 | */
|
---|
94 | typedef struct VMSVGAMOB
|
---|
95 | {
|
---|
96 | AVLU32NODECORE Core; /* Key is the mobid. */
|
---|
97 | RTLISTNODE nodeLRU;
|
---|
98 | VMSVGAGBO Gbo;
|
---|
99 | } VMSVGAMOB, *PVMSVGAMOB;
|
---|
100 | typedef VMSVGAMOB const *PCVMSVGAMOB;
|
---|
101 |
|
---|
102 |
|
---|
103 | typedef struct VMSVGACMDBUF *PVMSVGACMDBUF;
|
---|
104 | typedef struct VMSVGACMDBUFCTX *PVMSVGACMDBUFCTX;
|
---|
105 |
|
---|
106 | /* Command buffer. */
|
---|
107 | typedef struct VMSVGACMDBUF
|
---|
108 | {
|
---|
109 | RTLISTNODE nodeBuffer;
|
---|
110 | /* Context of the buffer. */
|
---|
111 | PVMSVGACMDBUFCTX pCmdBufCtx;
|
---|
112 | /* PA of the buffer. */
|
---|
113 | RTGCPHYS GCPhysCB;
|
---|
114 | /* A copy of the buffer header. */
|
---|
115 | SVGACBHeader hdr;
|
---|
116 | /* A copy of the commands. Size of the memory buffer is hdr.length */
|
---|
117 | void *pvCommands;
|
---|
118 | } VMSVGACMDBUF;
|
---|
119 |
|
---|
120 | /* Command buffer context. */
|
---|
121 | typedef struct VMSVGACMDBUFCTX
|
---|
122 | {
|
---|
123 | /* Buffers submitted to processing for the FIFO thread. */
|
---|
124 | RTLISTANCHOR listSubmitted;
|
---|
125 | /* How many buffers in the queue. */
|
---|
126 | uint32_t cSubmitted;
|
---|
127 | } VMSVGACMDBUFCTX;
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Internal SVGA ring-3 only state.
|
---|
131 | */
|
---|
132 | typedef struct VMSVGAR3STATE
|
---|
133 | {
|
---|
134 | PPDMDEVINS pDevIns; /* Stored here to use with PDMDevHlp* */
|
---|
135 | GMR *paGMR; // [VMSVGAState::cGMR]
|
---|
136 | struct
|
---|
137 | {
|
---|
138 | SVGAGuestPtr RT_UNTRUSTED_GUEST ptr;
|
---|
139 | uint32_t RT_UNTRUSTED_GUEST bytesPerLine;
|
---|
140 | SVGAGMRImageFormat RT_UNTRUSTED_GUEST format;
|
---|
141 | } GMRFB;
|
---|
142 | struct
|
---|
143 | {
|
---|
144 | bool fActive;
|
---|
145 | uint32_t xHotspot;
|
---|
146 | uint32_t yHotspot;
|
---|
147 | uint32_t width;
|
---|
148 | uint32_t height;
|
---|
149 | uint32_t cbData;
|
---|
150 | void *pData;
|
---|
151 | } Cursor;
|
---|
152 | SVGAColorBGRX colorAnnotation;
|
---|
153 |
|
---|
154 | # ifdef VMSVGA_USE_EMT_HALT_CODE
|
---|
155 | /** Number of EMTs in BusyDelayedEmts (quicker than scanning the set). */
|
---|
156 | uint32_t volatile cBusyDelayedEmts;
|
---|
157 | /** Set of EMTs that are */
|
---|
158 | VMCPUSET BusyDelayedEmts;
|
---|
159 | # else
|
---|
160 | /** Number of EMTs waiting on hBusyDelayedEmts. */
|
---|
161 | uint32_t volatile cBusyDelayedEmts;
|
---|
162 | /** Semaphore that EMTs wait on when reading SVGA_REG_BUSY and the FIFO is
|
---|
163 | * busy (ugly). */
|
---|
164 | RTSEMEVENTMULTI hBusyDelayedEmts;
|
---|
165 | # endif
|
---|
166 |
|
---|
167 | /** Information about screens. */
|
---|
168 | VMSVGASCREENOBJECT aScreens[64];
|
---|
169 |
|
---|
170 | /** Command buffer contexts. */
|
---|
171 | PVMSVGACMDBUFCTX apCmdBufCtxs[SVGA_CB_CONTEXT_MAX];
|
---|
172 | /** The special Device Context for synchronous commands. */
|
---|
173 | VMSVGACMDBUFCTX CmdBufCtxDC;
|
---|
174 | /** Flag which indicates that there are buffers to be processed. */
|
---|
175 | uint32_t volatile fCmdBuf;
|
---|
176 | /** Critical section for accessing the command buffer data. */
|
---|
177 | RTCRITSECT CritSectCmdBuf;
|
---|
178 |
|
---|
179 | /** Write protected GBOs (OTables) access handler type handle. */
|
---|
180 | PGMPHYSHANDLERTYPE hGboAccessHandlerType;
|
---|
181 |
|
---|
182 | /** */
|
---|
183 | VMSVGAGBO aGboOTables[SVGA_OTABLE_MAX];
|
---|
184 |
|
---|
185 | /** Tree of guest's Memory OBjects. Key is mobid. */
|
---|
186 | AVLU32TREE MOBTree;
|
---|
187 | /** Least Recently Used list of MOBs.
|
---|
188 | * To unmap older MOBs when the guest exceeds SVGA_REG_SUGGESTED_GBOBJECT_MEM_SIZE_KB (SVGA_REG_GBOBJECT_MEM_SIZE_KB) value. */
|
---|
189 | RTLISTANCHOR MOBLRUList;
|
---|
190 |
|
---|
191 | # ifdef VBOX_WITH_VMSVGA3D
|
---|
192 | VMSVGA3DBACKENDFUNCSMAP *pFuncsMap;
|
---|
193 | VMSVGA3DBACKENDFUNCSGBO *pFuncsGBO;
|
---|
194 | VMSVGA3DBACKENDFUNCSDX *pFuncsDX;
|
---|
195 | # endif
|
---|
196 |
|
---|
197 | /** Tracks how much time we waste reading SVGA_REG_BUSY with a busy FIFO. */
|
---|
198 | STAMPROFILE StatBusyDelayEmts;
|
---|
199 |
|
---|
200 | STAMPROFILE StatR3Cmd3dPresentProf;
|
---|
201 | STAMPROFILE StatR3Cmd3dDrawPrimitivesProf;
|
---|
202 | STAMPROFILE StatR3Cmd3dSurfaceDmaProf;
|
---|
203 | STAMPROFILE StatR3Cmd3dBlitSurfaceToScreenProf;
|
---|
204 | STAMCOUNTER StatR3CmdDefineGmr2;
|
---|
205 | STAMCOUNTER StatR3CmdDefineGmr2Free;
|
---|
206 | STAMCOUNTER StatR3CmdDefineGmr2Modify;
|
---|
207 | STAMCOUNTER StatR3CmdRemapGmr2;
|
---|
208 | STAMCOUNTER StatR3CmdRemapGmr2Modify;
|
---|
209 | STAMCOUNTER StatR3CmdInvalidCmd;
|
---|
210 | STAMCOUNTER StatR3CmdFence;
|
---|
211 | STAMCOUNTER StatR3CmdUpdate;
|
---|
212 | STAMCOUNTER StatR3CmdUpdateVerbose;
|
---|
213 | STAMCOUNTER StatR3CmdDefineCursor;
|
---|
214 | STAMCOUNTER StatR3CmdDefineAlphaCursor;
|
---|
215 | STAMCOUNTER StatR3CmdMoveCursor;
|
---|
216 | STAMCOUNTER StatR3CmdDisplayCursor;
|
---|
217 | STAMCOUNTER StatR3CmdRectFill;
|
---|
218 | STAMCOUNTER StatR3CmdRectCopy;
|
---|
219 | STAMCOUNTER StatR3CmdRectRopCopy;
|
---|
220 | STAMCOUNTER StatR3CmdEscape;
|
---|
221 | STAMCOUNTER StatR3CmdDefineScreen;
|
---|
222 | STAMCOUNTER StatR3CmdDestroyScreen;
|
---|
223 | STAMCOUNTER StatR3CmdDefineGmrFb;
|
---|
224 | STAMCOUNTER StatR3CmdBlitGmrFbToScreen;
|
---|
225 | STAMCOUNTER StatR3CmdBlitScreentoGmrFb;
|
---|
226 | STAMCOUNTER StatR3CmdAnnotationFill;
|
---|
227 | STAMCOUNTER StatR3CmdAnnotationCopy;
|
---|
228 | STAMCOUNTER StatR3Cmd3dSurfaceDefine;
|
---|
229 | STAMCOUNTER StatR3Cmd3dSurfaceDefineV2;
|
---|
230 | STAMCOUNTER StatR3Cmd3dSurfaceDestroy;
|
---|
231 | STAMCOUNTER StatR3Cmd3dSurfaceCopy;
|
---|
232 | STAMCOUNTER StatR3Cmd3dSurfaceStretchBlt;
|
---|
233 | STAMCOUNTER StatR3Cmd3dSurfaceDma;
|
---|
234 | STAMCOUNTER StatR3Cmd3dSurfaceScreen;
|
---|
235 | STAMCOUNTER StatR3Cmd3dContextDefine;
|
---|
236 | STAMCOUNTER StatR3Cmd3dContextDestroy;
|
---|
237 | STAMCOUNTER StatR3Cmd3dSetTransform;
|
---|
238 | STAMCOUNTER StatR3Cmd3dSetZRange;
|
---|
239 | STAMCOUNTER StatR3Cmd3dSetRenderState;
|
---|
240 | STAMCOUNTER StatR3Cmd3dSetRenderTarget;
|
---|
241 | STAMCOUNTER StatR3Cmd3dSetTextureState;
|
---|
242 | STAMCOUNTER StatR3Cmd3dSetMaterial;
|
---|
243 | STAMCOUNTER StatR3Cmd3dSetLightData;
|
---|
244 | STAMCOUNTER StatR3Cmd3dSetLightEnable;
|
---|
245 | STAMCOUNTER StatR3Cmd3dSetViewPort;
|
---|
246 | STAMCOUNTER StatR3Cmd3dSetClipPlane;
|
---|
247 | STAMCOUNTER StatR3Cmd3dClear;
|
---|
248 | STAMCOUNTER StatR3Cmd3dPresent;
|
---|
249 | STAMCOUNTER StatR3Cmd3dPresentReadBack;
|
---|
250 | STAMCOUNTER StatR3Cmd3dShaderDefine;
|
---|
251 | STAMCOUNTER StatR3Cmd3dShaderDestroy;
|
---|
252 | STAMCOUNTER StatR3Cmd3dSetShader;
|
---|
253 | STAMCOUNTER StatR3Cmd3dSetShaderConst;
|
---|
254 | STAMCOUNTER StatR3Cmd3dDrawPrimitives;
|
---|
255 | STAMCOUNTER StatR3Cmd3dSetScissorRect;
|
---|
256 | STAMCOUNTER StatR3Cmd3dBeginQuery;
|
---|
257 | STAMCOUNTER StatR3Cmd3dEndQuery;
|
---|
258 | STAMCOUNTER StatR3Cmd3dWaitForQuery;
|
---|
259 | STAMCOUNTER StatR3Cmd3dGenerateMipmaps;
|
---|
260 | STAMCOUNTER StatR3Cmd3dActivateSurface;
|
---|
261 | STAMCOUNTER StatR3Cmd3dDeactivateSurface;
|
---|
262 |
|
---|
263 | STAMCOUNTER StatR3RegConfigDoneWr;
|
---|
264 | STAMCOUNTER StatR3RegGmrDescriptorWr;
|
---|
265 | STAMCOUNTER StatR3RegGmrDescriptorWrErrors;
|
---|
266 | STAMCOUNTER StatR3RegGmrDescriptorWrFree;
|
---|
267 |
|
---|
268 | STAMCOUNTER StatFifoCommands;
|
---|
269 | STAMCOUNTER StatFifoErrors;
|
---|
270 | STAMCOUNTER StatFifoUnkCmds;
|
---|
271 | STAMCOUNTER StatFifoTodoTimeout;
|
---|
272 | STAMCOUNTER StatFifoTodoWoken;
|
---|
273 | STAMPROFILE StatFifoStalls;
|
---|
274 | STAMPROFILE StatFifoExtendedSleep;
|
---|
275 | # ifdef VMSVGA_USE_FIFO_ACCESS_HANDLER
|
---|
276 | STAMCOUNTER StatFifoAccessHandler;
|
---|
277 | # endif
|
---|
278 | STAMCOUNTER StatFifoCursorFetchAgain;
|
---|
279 | STAMCOUNTER StatFifoCursorNoChange;
|
---|
280 | STAMCOUNTER StatFifoCursorPosition;
|
---|
281 | STAMCOUNTER StatFifoCursorVisiblity;
|
---|
282 | STAMCOUNTER StatFifoWatchdogWakeUps;
|
---|
283 | } VMSVGAR3STATE, *PVMSVGAR3STATE;
|
---|
284 |
|
---|
285 |
|
---|
286 | /*********************************************************************************************************************************
|
---|
287 | * Functions *
|
---|
288 | *********************************************************************************************************************************/
|
---|
289 | #ifdef DEBUG_GMR_ACCESS
|
---|
290 | DECLCALLBACK(int) vmsvgaR3ResetGmrHandlers(PVGASTATE pThis);
|
---|
291 | DECLCALLBACK(int) vmsvgaR3DeregisterGmr(PPDMDEVINS pDevIns, uint32_t gmrId);
|
---|
292 | #endif
|
---|
293 |
|
---|
294 | DECLCALLBACK(VBOXSTRICTRC) vmsvgaR3GboAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
|
---|
295 | PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser);
|
---|
296 |
|
---|
297 | void vmsvgaR3ResetScreens(PVGASTATE pThis, PVGASTATECC pThisCC);
|
---|
298 |
|
---|
299 | int vmsvgaR3ChangeMode(PVGASTATE pThis, PVGASTATECC pThisCC);
|
---|
300 | int vmsvgaR3UpdateScreen(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen, int x, int y, int w, int h);
|
---|
301 |
|
---|
302 | int vmsvgaR3GmrTransfer(PVGASTATE pThis, PVGASTATECC pThisCC, const SVGA3dTransferType enmTransferType,
|
---|
303 | uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
|
---|
304 | SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
|
---|
305 | uint32_t cbWidth, uint32_t cHeight);
|
---|
306 | void vmsvgaR3GmrFree(PVGASTATECC pThisCC, uint32_t idGMR);
|
---|
307 |
|
---|
308 | void vmsvgaR3CmdUpdate(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdate const *pCmd);
|
---|
309 | void vmsvgaR3CmdUpdateVerbose(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdateVerbose const *pCmd);
|
---|
310 | void vmsvgaR3CmdRectFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectFill const *pCmd);
|
---|
311 | void vmsvgaR3CmdRectCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectCopy const *pCmd);
|
---|
312 | void vmsvgaR3CmdRectRopCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectRopCopy const *pCmd);
|
---|
313 | void vmsvgaR3CmdDisplayCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDisplayCursor const *pCmd);
|
---|
314 | void vmsvgaR3CmdMoveCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdMoveCursor const *pCmd);
|
---|
315 | void vmsvgaR3CmdDefineCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineCursor const *pCmd);
|
---|
316 | void vmsvgaR3CmdDefineAlphaCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineAlphaCursor const *pCmd);
|
---|
317 | void vmsvgaR3CmdEscape(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdEscape const *pCmd);
|
---|
318 | void vmsvgaR3CmdDefineScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineScreen const *pCmd);
|
---|
319 | void vmsvgaR3CmdDestroyScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDestroyScreen const *pCmd);
|
---|
320 | void vmsvgaR3CmdDefineGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMRFB const *pCmd);
|
---|
321 | void vmsvgaR3CmdBlitGMRFBToScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitGMRFBToScreen const *pCmd);
|
---|
322 | void vmsvgaR3CmdBlitScreenToGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitScreenToGMRFB const *pCmd);
|
---|
323 | void vmsvgaR3CmdAnnotationFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationFill const *pCmd);
|
---|
324 | void vmsvgaR3CmdAnnotationCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationCopy const *pCmd);
|
---|
325 |
|
---|
326 | #ifdef VBOX_WITH_VMSVGA3D
|
---|
327 | void vmsvgaR3CmdDefineGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMR2 const *pCmd);
|
---|
328 | void vmsvgaR3CmdRemapGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRemapGMR2 const *pCmd);
|
---|
329 | int vmsvgaR3Process3dCmd(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifo3dCmdId enmCmdId, uint32_t cbCmd, void const *pvCmd);
|
---|
330 | #endif
|
---|
331 |
|
---|
332 | #if defined(LOG_ENABLED) || defined(VBOX_STRICT)
|
---|
333 | const char *vmsvgaR3FifoCmdToString(uint32_t u32Cmd);
|
---|
334 | #endif
|
---|
335 |
|
---|
336 |
|
---|
337 | #endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA_internal_h */
|
---|