1 | /* $Id: DevVGA-SVGA-internal.h 86855 2020-11-11 01:03:54Z 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 | /** Tracks how much time we waste reading SVGA_REG_BUSY with a busy FIFO. */
|
---|
192 | STAMPROFILE StatBusyDelayEmts;
|
---|
193 |
|
---|
194 | STAMPROFILE StatR3Cmd3dPresentProf;
|
---|
195 | STAMPROFILE StatR3Cmd3dDrawPrimitivesProf;
|
---|
196 | STAMPROFILE StatR3Cmd3dSurfaceDmaProf;
|
---|
197 | STAMPROFILE StatR3Cmd3dBlitSurfaceToScreenProf;
|
---|
198 | STAMCOUNTER StatR3CmdDefineGmr2;
|
---|
199 | STAMCOUNTER StatR3CmdDefineGmr2Free;
|
---|
200 | STAMCOUNTER StatR3CmdDefineGmr2Modify;
|
---|
201 | STAMCOUNTER StatR3CmdRemapGmr2;
|
---|
202 | STAMCOUNTER StatR3CmdRemapGmr2Modify;
|
---|
203 | STAMCOUNTER StatR3CmdInvalidCmd;
|
---|
204 | STAMCOUNTER StatR3CmdFence;
|
---|
205 | STAMCOUNTER StatR3CmdUpdate;
|
---|
206 | STAMCOUNTER StatR3CmdUpdateVerbose;
|
---|
207 | STAMCOUNTER StatR3CmdDefineCursor;
|
---|
208 | STAMCOUNTER StatR3CmdDefineAlphaCursor;
|
---|
209 | STAMCOUNTER StatR3CmdMoveCursor;
|
---|
210 | STAMCOUNTER StatR3CmdDisplayCursor;
|
---|
211 | STAMCOUNTER StatR3CmdRectFill;
|
---|
212 | STAMCOUNTER StatR3CmdRectCopy;
|
---|
213 | STAMCOUNTER StatR3CmdRectRopCopy;
|
---|
214 | STAMCOUNTER StatR3CmdEscape;
|
---|
215 | STAMCOUNTER StatR3CmdDefineScreen;
|
---|
216 | STAMCOUNTER StatR3CmdDestroyScreen;
|
---|
217 | STAMCOUNTER StatR3CmdDefineGmrFb;
|
---|
218 | STAMCOUNTER StatR3CmdBlitGmrFbToScreen;
|
---|
219 | STAMCOUNTER StatR3CmdBlitScreentoGmrFb;
|
---|
220 | STAMCOUNTER StatR3CmdAnnotationFill;
|
---|
221 | STAMCOUNTER StatR3CmdAnnotationCopy;
|
---|
222 | STAMCOUNTER StatR3Cmd3dSurfaceDefine;
|
---|
223 | STAMCOUNTER StatR3Cmd3dSurfaceDefineV2;
|
---|
224 | STAMCOUNTER StatR3Cmd3dSurfaceDestroy;
|
---|
225 | STAMCOUNTER StatR3Cmd3dSurfaceCopy;
|
---|
226 | STAMCOUNTER StatR3Cmd3dSurfaceStretchBlt;
|
---|
227 | STAMCOUNTER StatR3Cmd3dSurfaceDma;
|
---|
228 | STAMCOUNTER StatR3Cmd3dSurfaceScreen;
|
---|
229 | STAMCOUNTER StatR3Cmd3dContextDefine;
|
---|
230 | STAMCOUNTER StatR3Cmd3dContextDestroy;
|
---|
231 | STAMCOUNTER StatR3Cmd3dSetTransform;
|
---|
232 | STAMCOUNTER StatR3Cmd3dSetZRange;
|
---|
233 | STAMCOUNTER StatR3Cmd3dSetRenderState;
|
---|
234 | STAMCOUNTER StatR3Cmd3dSetRenderTarget;
|
---|
235 | STAMCOUNTER StatR3Cmd3dSetTextureState;
|
---|
236 | STAMCOUNTER StatR3Cmd3dSetMaterial;
|
---|
237 | STAMCOUNTER StatR3Cmd3dSetLightData;
|
---|
238 | STAMCOUNTER StatR3Cmd3dSetLightEnable;
|
---|
239 | STAMCOUNTER StatR3Cmd3dSetViewPort;
|
---|
240 | STAMCOUNTER StatR3Cmd3dSetClipPlane;
|
---|
241 | STAMCOUNTER StatR3Cmd3dClear;
|
---|
242 | STAMCOUNTER StatR3Cmd3dPresent;
|
---|
243 | STAMCOUNTER StatR3Cmd3dPresentReadBack;
|
---|
244 | STAMCOUNTER StatR3Cmd3dShaderDefine;
|
---|
245 | STAMCOUNTER StatR3Cmd3dShaderDestroy;
|
---|
246 | STAMCOUNTER StatR3Cmd3dSetShader;
|
---|
247 | STAMCOUNTER StatR3Cmd3dSetShaderConst;
|
---|
248 | STAMCOUNTER StatR3Cmd3dDrawPrimitives;
|
---|
249 | STAMCOUNTER StatR3Cmd3dSetScissorRect;
|
---|
250 | STAMCOUNTER StatR3Cmd3dBeginQuery;
|
---|
251 | STAMCOUNTER StatR3Cmd3dEndQuery;
|
---|
252 | STAMCOUNTER StatR3Cmd3dWaitForQuery;
|
---|
253 | STAMCOUNTER StatR3Cmd3dGenerateMipmaps;
|
---|
254 | STAMCOUNTER StatR3Cmd3dActivateSurface;
|
---|
255 | STAMCOUNTER StatR3Cmd3dDeactivateSurface;
|
---|
256 |
|
---|
257 | STAMCOUNTER StatR3RegConfigDoneWr;
|
---|
258 | STAMCOUNTER StatR3RegGmrDescriptorWr;
|
---|
259 | STAMCOUNTER StatR3RegGmrDescriptorWrErrors;
|
---|
260 | STAMCOUNTER StatR3RegGmrDescriptorWrFree;
|
---|
261 |
|
---|
262 | STAMCOUNTER StatFifoCommands;
|
---|
263 | STAMCOUNTER StatFifoErrors;
|
---|
264 | STAMCOUNTER StatFifoUnkCmds;
|
---|
265 | STAMCOUNTER StatFifoTodoTimeout;
|
---|
266 | STAMCOUNTER StatFifoTodoWoken;
|
---|
267 | STAMPROFILE StatFifoStalls;
|
---|
268 | STAMPROFILE StatFifoExtendedSleep;
|
---|
269 | # ifdef VMSVGA_USE_FIFO_ACCESS_HANDLER
|
---|
270 | STAMCOUNTER StatFifoAccessHandler;
|
---|
271 | # endif
|
---|
272 | STAMCOUNTER StatFifoCursorFetchAgain;
|
---|
273 | STAMCOUNTER StatFifoCursorNoChange;
|
---|
274 | STAMCOUNTER StatFifoCursorPosition;
|
---|
275 | STAMCOUNTER StatFifoCursorVisiblity;
|
---|
276 | STAMCOUNTER StatFifoWatchdogWakeUps;
|
---|
277 | } VMSVGAR3STATE, *PVMSVGAR3STATE;
|
---|
278 |
|
---|
279 |
|
---|
280 | /*********************************************************************************************************************************
|
---|
281 | * Functions *
|
---|
282 | *********************************************************************************************************************************/
|
---|
283 | #ifdef DEBUG_GMR_ACCESS
|
---|
284 | DECLCALLBACK(int) vmsvgaR3ResetGmrHandlers(PVGASTATE pThis);
|
---|
285 | DECLCALLBACK(int) vmsvgaR3DeregisterGmr(PPDMDEVINS pDevIns, uint32_t gmrId);
|
---|
286 | #endif
|
---|
287 |
|
---|
288 | DECLCALLBACK(VBOXSTRICTRC) vmsvgaR3GboAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
|
---|
289 | PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser);
|
---|
290 |
|
---|
291 | void vmsvgaR3ResetScreens(PVGASTATE pThis, PVGASTATECC pThisCC);
|
---|
292 |
|
---|
293 | int vmsvgaR3ChangeMode(PVGASTATE pThis, PVGASTATECC pThisCC);
|
---|
294 | int vmsvgaR3UpdateScreen(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen, int x, int y, int w, int h);
|
---|
295 |
|
---|
296 | int vmsvgaR3GmrTransfer(PVGASTATE pThis, PVGASTATECC pThisCC, const SVGA3dTransferType enmTransferType,
|
---|
297 | uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
|
---|
298 | SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
|
---|
299 | uint32_t cbWidth, uint32_t cHeight);
|
---|
300 | void vmsvgaR3GmrFree(PVGASTATECC pThisCC, uint32_t idGMR);
|
---|
301 |
|
---|
302 | void vmsvgaR3CmdUpdate(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdate const *pCmd);
|
---|
303 | void vmsvgaR3CmdUpdateVerbose(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdUpdateVerbose const *pCmd);
|
---|
304 | void vmsvgaR3CmdRectFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectFill const *pCmd);
|
---|
305 | void vmsvgaR3CmdRectCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectCopy const *pCmd);
|
---|
306 | void vmsvgaR3CmdRectRopCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRectRopCopy const *pCmd);
|
---|
307 | void vmsvgaR3CmdDisplayCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDisplayCursor const *pCmd);
|
---|
308 | void vmsvgaR3CmdMoveCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdMoveCursor const *pCmd);
|
---|
309 | void vmsvgaR3CmdDefineCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineCursor const *pCmd);
|
---|
310 | void vmsvgaR3CmdDefineAlphaCursor(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineAlphaCursor const *pCmd);
|
---|
311 | void vmsvgaR3CmdEscape(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdEscape const *pCmd);
|
---|
312 | void vmsvgaR3CmdDefineScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineScreen const *pCmd);
|
---|
313 | void vmsvgaR3CmdDestroyScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDestroyScreen const *pCmd);
|
---|
314 | void vmsvgaR3CmdDefineGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMRFB const *pCmd);
|
---|
315 | void vmsvgaR3CmdBlitGMRFBToScreen(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitGMRFBToScreen const *pCmd);
|
---|
316 | void vmsvgaR3CmdBlitScreenToGMRFB(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdBlitScreenToGMRFB const *pCmd);
|
---|
317 | void vmsvgaR3CmdAnnotationFill(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationFill const *pCmd);
|
---|
318 | void vmsvgaR3CmdAnnotationCopy(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdAnnotationCopy const *pCmd);
|
---|
319 |
|
---|
320 | #ifdef VBOX_WITH_VMSVGA3D
|
---|
321 | void vmsvgaR3CmdDefineGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdDefineGMR2 const *pCmd);
|
---|
322 | void vmsvgaR3CmdRemapGMR2(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifoCmdRemapGMR2 const *pCmd);
|
---|
323 | int vmsvgaR3Process3dCmd(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAFifo3dCmdId enmCmdId, uint32_t cbCmd, void const *pvCmd);
|
---|
324 | #endif
|
---|
325 |
|
---|
326 | #if defined(LOG_ENABLED) || defined(VBOX_STRICT)
|
---|
327 | const char *vmsvgaR3FifoCmdToString(uint32_t u32Cmd);
|
---|
328 | #endif
|
---|
329 |
|
---|
330 |
|
---|
331 | #endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA_internal_h */
|
---|