VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.cpp@ 81428

Last change on this file since 81428 was 81194, checked in by vboxsync, 5 years ago

Devices/Graphics/DevVGA-SVGA.cpp: Improve check, bugref:9535

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 293.0 KB
Line 
1/* $Id: DevVGA-SVGA.cpp 81194 2019-10-09 19:47:36Z vboxsync $ */
2/** @file
3 * VMware SVGA device.
4 *
5 * Logging levels guidelines for this and related files:
6 * - Log() for normal bits.
7 * - LogFlow() for more info.
8 * - Log2 for hex dump of cursor data.
9 * - Log3 for hex dump of shader code.
10 * - Log4 for hex dumps of 3D data.
11 */
12
13/*
14 * Copyright (C) 2013-2019 Oracle Corporation
15 *
16 * This file is part of VirtualBox Open Source Edition (OSE), as
17 * available from http://www.virtualbox.org. This file is free software;
18 * you can redistribute it and/or modify it under the terms of the GNU
19 * General Public License (GPL) as published by the Free Software
20 * Foundation, in version 2 as it comes in the "COPYING" file of the
21 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
22 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
23 */
24
25
26/** @page pg_dev_vmsvga VMSVGA - VMware SVGA II Device Emulation
27 *
28 * This device emulation was contributed by trivirt AG. It offers an
29 * alternative to our Bochs based VGA graphics and 3d emulations. This is
30 * valuable for Xorg based guests, as there is driver support shipping with Xorg
31 * since it forked from XFree86.
32 *
33 *
34 * @section sec_dev_vmsvga_sdk The VMware SDK
35 *
36 * This is officially deprecated now, however it's still quite useful,
37 * especially for getting the old features working:
38 * http://vmware-svga.sourceforge.net/
39 *
40 * They currently point developers at the following resources.
41 * - http://cgit.freedesktop.org/xorg/driver/xf86-video-vmware/
42 * - http://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/svga/
43 * - http://cgit.freedesktop.org/mesa/vmwgfx/
44 *
45 * @subsection subsec_dev_vmsvga_sdk_results Test results
46 *
47 * Test results:
48 * - 2dmark.img:
49 * + todo
50 * - backdoor-tclo.img:
51 * + todo
52 * - blit-cube.img:
53 * + todo
54 * - bunnies.img:
55 * + todo
56 * - cube.img:
57 * + todo
58 * - cubemark.img:
59 * + todo
60 * - dynamic-vertex-stress.img:
61 * + todo
62 * - dynamic-vertex.img:
63 * + todo
64 * - fence-stress.img:
65 * + todo
66 * - gmr-test.img:
67 * + todo
68 * - half-float-test.img:
69 * + todo
70 * - noscreen-cursor.img:
71 * - The CURSOR I/O and FIFO registers are not implemented, so the mouse
72 * cursor doesn't show. (Hacking the GUI a little, would make the cursor
73 * visible though.)
74 * - Cursor animation via the palette doesn't work.
75 * - During debugging, it turns out that the framebuffer content seems to
76 * be halfways ignore or something (memset(fb, 0xcc, lots)).
77 * - Trouble with way to small FIFO and the 256x256 cursor fails. Need to
78 * grow it 0x10 fold (128KB -> 2MB like in WS10).
79 * - null.img:
80 * + todo
81 * - pong.img:
82 * + todo
83 * - presentReadback.img:
84 * + todo
85 * - resolution-set.img:
86 * + todo
87 * - rt-gamma-test.img:
88 * + todo
89 * - screen-annotation.img:
90 * + todo
91 * - screen-cursor.img:
92 * + todo
93 * - screen-dma-coalesce.img:
94 * + todo
95 * - screen-gmr-discontig.img:
96 * + todo
97 * - screen-gmr-remap.img:
98 * + todo
99 * - screen-multimon.img:
100 * + todo
101 * - screen-present-clip.img:
102 * + todo
103 * - screen-render-test.img:
104 * + todo
105 * - screen-simple.img:
106 * + todo
107 * - screen-text.img:
108 * + todo
109 * - simple-shaders.img:
110 * + todo
111 * - simple_blit.img:
112 * + todo
113 * - tiny-2d-updates.img:
114 * + todo
115 * - video-formats.img:
116 * + todo
117 * - video-sync.img:
118 * + todo
119 *
120 */
121
122
123/*********************************************************************************************************************************
124* Header Files *
125*********************************************************************************************************************************/
126#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
127#define VMSVGA_USE_EMT_HALT_CODE
128#include <VBox/vmm/pdmdev.h>
129#include <VBox/version.h>
130#include <VBox/err.h>
131#include <VBox/log.h>
132#include <VBox/vmm/pgm.h>
133#ifdef VMSVGA_USE_EMT_HALT_CODE
134# include <VBox/vmm/vmapi.h>
135# include <VBox/vmm/vmcpuset.h>
136#endif
137#include <VBox/sup.h>
138
139#include <iprt/assert.h>
140#include <iprt/semaphore.h>
141#include <iprt/uuid.h>
142#ifdef IN_RING3
143# include <iprt/ctype.h>
144# include <iprt/mem.h>
145# ifdef VBOX_STRICT
146# include <iprt/time.h>
147# endif
148#endif
149
150#include <VBox/AssertGuest.h>
151#include <VBox/VMMDev.h>
152#include <VBoxVideo.h>
153#include <VBox/bioslogo.h>
154
155/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
156#include "DevVGA.h"
157
158#include "DevVGA-SVGA.h"
159#include "vmsvga/svga_escape.h"
160#include "vmsvga/svga_overlay.h"
161#include "vmsvga/svga3d_caps.h"
162#ifdef VBOX_WITH_VMSVGA3D
163# include "DevVGA-SVGA3d.h"
164# ifdef RT_OS_DARWIN
165# include "DevVGA-SVGA3d-cocoa.h"
166# endif
167#endif
168
169
170/*********************************************************************************************************************************
171* Defined Constants And Macros *
172*********************************************************************************************************************************/
173/**
174 * Macro for checking if a fixed FIFO register is valid according to the
175 * current FIFO configuration.
176 *
177 * @returns true / false.
178 * @param a_iIndex The fifo register index (like SVGA_FIFO_CAPABILITIES).
179 * @param a_offFifoMin A valid SVGA_FIFO_MIN value.
180 */
181#define VMSVGA_IS_VALID_FIFO_REG(a_iIndex, a_offFifoMin) ( ((a_iIndex) + 1) * sizeof(uint32_t) <= (a_offFifoMin) )
182
183
184/*********************************************************************************************************************************
185* Structures and Typedefs *
186*********************************************************************************************************************************/
187/**
188 * 64-bit GMR descriptor.
189 */
190typedef struct
191{
192 RTGCPHYS GCPhys;
193 uint64_t numPages;
194} VMSVGAGMRDESCRIPTOR, *PVMSVGAGMRDESCRIPTOR;
195
196/**
197 * GMR slot
198 */
199typedef struct
200{
201 uint32_t cMaxPages;
202 uint32_t cbTotal;
203 uint32_t numDescriptors;
204 PVMSVGAGMRDESCRIPTOR paDesc;
205} GMR, *PGMR;
206
207#ifdef IN_RING3
208/**
209 * Internal SVGA ring-3 only state.
210 */
211typedef struct VMSVGAR3STATE
212{
213 GMR *paGMR; // [VMSVGAState::cGMR]
214 struct
215 {
216 SVGAGuestPtr RT_UNTRUSTED_GUEST ptr;
217 uint32_t RT_UNTRUSTED_GUEST bytesPerLine;
218 SVGAGMRImageFormat RT_UNTRUSTED_GUEST format;
219 } GMRFB;
220 struct
221 {
222 bool fActive;
223 uint32_t xHotspot;
224 uint32_t yHotspot;
225 uint32_t width;
226 uint32_t height;
227 uint32_t cbData;
228 void *pData;
229 } Cursor;
230 SVGAColorBGRX colorAnnotation;
231
232# ifdef VMSVGA_USE_EMT_HALT_CODE
233 /** Number of EMTs in BusyDelayedEmts (quicker than scanning the set). */
234 uint32_t volatile cBusyDelayedEmts;
235 /** Set of EMTs that are */
236 VMCPUSET BusyDelayedEmts;
237# else
238 /** Number of EMTs waiting on hBusyDelayedEmts. */
239 uint32_t volatile cBusyDelayedEmts;
240 /** Semaphore that EMTs wait on when reading SVGA_REG_BUSY and the FIFO is
241 * busy (ugly). */
242 RTSEMEVENTMULTI hBusyDelayedEmts;
243# endif
244
245 /** Information obout screens. */
246 VMSVGASCREENOBJECT aScreens[64];
247
248 /** Tracks how much time we waste reading SVGA_REG_BUSY with a busy FIFO. */
249 STAMPROFILE StatBusyDelayEmts;
250
251 STAMPROFILE StatR3Cmd3dPresentProf;
252 STAMPROFILE StatR3Cmd3dDrawPrimitivesProf;
253 STAMPROFILE StatR3Cmd3dSurfaceDmaProf;
254 STAMCOUNTER StatR3CmdDefineGmr2;
255 STAMCOUNTER StatR3CmdDefineGmr2Free;
256 STAMCOUNTER StatR3CmdDefineGmr2Modify;
257 STAMCOUNTER StatR3CmdRemapGmr2;
258 STAMCOUNTER StatR3CmdRemapGmr2Modify;
259 STAMCOUNTER StatR3CmdInvalidCmd;
260 STAMCOUNTER StatR3CmdFence;
261 STAMCOUNTER StatR3CmdUpdate;
262 STAMCOUNTER StatR3CmdUpdateVerbose;
263 STAMCOUNTER StatR3CmdDefineCursor;
264 STAMCOUNTER StatR3CmdDefineAlphaCursor;
265 STAMCOUNTER StatR3CmdEscape;
266 STAMCOUNTER StatR3CmdDefineScreen;
267 STAMCOUNTER StatR3CmdDestroyScreen;
268 STAMCOUNTER StatR3CmdDefineGmrFb;
269 STAMCOUNTER StatR3CmdBlitGmrFbToScreen;
270 STAMCOUNTER StatR3CmdBlitScreentoGmrFb;
271 STAMCOUNTER StatR3CmdAnnotationFill;
272 STAMCOUNTER StatR3CmdAnnotationCopy;
273 STAMCOUNTER StatR3Cmd3dSurfaceDefine;
274 STAMCOUNTER StatR3Cmd3dSurfaceDefineV2;
275 STAMCOUNTER StatR3Cmd3dSurfaceDestroy;
276 STAMCOUNTER StatR3Cmd3dSurfaceCopy;
277 STAMCOUNTER StatR3Cmd3dSurfaceStretchBlt;
278 STAMCOUNTER StatR3Cmd3dSurfaceDma;
279 STAMCOUNTER StatR3Cmd3dSurfaceScreen;
280 STAMCOUNTER StatR3Cmd3dContextDefine;
281 STAMCOUNTER StatR3Cmd3dContextDestroy;
282 STAMCOUNTER StatR3Cmd3dSetTransform;
283 STAMCOUNTER StatR3Cmd3dSetZRange;
284 STAMCOUNTER StatR3Cmd3dSetRenderState;
285 STAMCOUNTER StatR3Cmd3dSetRenderTarget;
286 STAMCOUNTER StatR3Cmd3dSetTextureState;
287 STAMCOUNTER StatR3Cmd3dSetMaterial;
288 STAMCOUNTER StatR3Cmd3dSetLightData;
289 STAMCOUNTER StatR3Cmd3dSetLightEnable;
290 STAMCOUNTER StatR3Cmd3dSetViewPort;
291 STAMCOUNTER StatR3Cmd3dSetClipPlane;
292 STAMCOUNTER StatR3Cmd3dClear;
293 STAMCOUNTER StatR3Cmd3dPresent;
294 STAMCOUNTER StatR3Cmd3dPresentReadBack;
295 STAMCOUNTER StatR3Cmd3dShaderDefine;
296 STAMCOUNTER StatR3Cmd3dShaderDestroy;
297 STAMCOUNTER StatR3Cmd3dSetShader;
298 STAMCOUNTER StatR3Cmd3dSetShaderConst;
299 STAMCOUNTER StatR3Cmd3dDrawPrimitives;
300 STAMCOUNTER StatR3Cmd3dSetScissorRect;
301 STAMCOUNTER StatR3Cmd3dBeginQuery;
302 STAMCOUNTER StatR3Cmd3dEndQuery;
303 STAMCOUNTER StatR3Cmd3dWaitForQuery;
304 STAMCOUNTER StatR3Cmd3dGenerateMipmaps;
305 STAMCOUNTER StatR3Cmd3dActivateSurface;
306 STAMCOUNTER StatR3Cmd3dDeactivateSurface;
307
308 STAMCOUNTER StatR3RegConfigDoneWr;
309 STAMCOUNTER StatR3RegGmrDescriptorWr;
310 STAMCOUNTER StatR3RegGmrDescriptorWrErrors;
311 STAMCOUNTER StatR3RegGmrDescriptorWrFree;
312
313 STAMCOUNTER StatFifoCommands;
314 STAMCOUNTER StatFifoErrors;
315 STAMCOUNTER StatFifoUnkCmds;
316 STAMCOUNTER StatFifoTodoTimeout;
317 STAMCOUNTER StatFifoTodoWoken;
318 STAMPROFILE StatFifoStalls;
319 STAMPROFILE StatFifoExtendedSleep;
320# ifdef VMSVGA_USE_FIFO_ACCESS_HANDLER
321 STAMCOUNTER StatFifoAccessHandler;
322# endif
323 STAMCOUNTER StatFifoCursorFetchAgain;
324 STAMCOUNTER StatFifoCursorNoChange;
325 STAMCOUNTER StatFifoCursorPosition;
326 STAMCOUNTER StatFifoCursorVisiblity;
327 STAMCOUNTER StatFifoWatchdogWakeUps;
328} VMSVGAR3STATE, *PVMSVGAR3STATE;
329#endif /* IN_RING3 */
330
331
332/*********************************************************************************************************************************
333* Internal Functions *
334*********************************************************************************************************************************/
335#ifdef IN_RING3
336# if defined(VMSVGA_USE_FIFO_ACCESS_HANDLER) || defined(DEBUG_FIFO_ACCESS)
337static FNPGMPHYSHANDLER vmsvgaR3FIFOAccessHandler;
338# endif
339# ifdef DEBUG_GMR_ACCESS
340static FNPGMPHYSHANDLER vmsvgaR3GMRAccessHandler;
341# endif
342#endif
343
344
345/*********************************************************************************************************************************
346* Global Variables *
347*********************************************************************************************************************************/
348#ifdef IN_RING3
349
350/**
351 * SSM descriptor table for the VMSVGAGMRDESCRIPTOR structure.
352 */
353static SSMFIELD const g_aVMSVGAGMRDESCRIPTORFields[] =
354{
355 SSMFIELD_ENTRY_GCPHYS( VMSVGAGMRDESCRIPTOR, GCPhys),
356 SSMFIELD_ENTRY( VMSVGAGMRDESCRIPTOR, numPages),
357 SSMFIELD_ENTRY_TERM()
358};
359
360/**
361 * SSM descriptor table for the GMR structure.
362 */
363static SSMFIELD const g_aGMRFields[] =
364{
365 SSMFIELD_ENTRY( GMR, cMaxPages),
366 SSMFIELD_ENTRY( GMR, cbTotal),
367 SSMFIELD_ENTRY( GMR, numDescriptors),
368 SSMFIELD_ENTRY_IGN_HCPTR( GMR, paDesc),
369 SSMFIELD_ENTRY_TERM()
370};
371
372/**
373 * SSM descriptor table for the VMSVGASCREENOBJECT structure.
374 */
375static SSMFIELD const g_aVMSVGASCREENOBJECTFields[] =
376{
377 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, fuScreen),
378 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, idScreen),
379 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, xOrigin),
380 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, yOrigin),
381 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, cWidth),
382 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, cHeight),
383 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, offVRAM),
384 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, cbPitch),
385 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, cBpp),
386 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, fDefined),
387 SSMFIELD_ENTRY( VMSVGASCREENOBJECT, fModified),
388 SSMFIELD_ENTRY_TERM()
389};
390
391/**
392 * SSM descriptor table for the VMSVGAR3STATE structure.
393 */
394static SSMFIELD const g_aVMSVGAR3STATEFields[] =
395{
396 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, paGMR),
397 SSMFIELD_ENTRY( VMSVGAR3STATE, GMRFB),
398 SSMFIELD_ENTRY( VMSVGAR3STATE, Cursor.fActive),
399 SSMFIELD_ENTRY( VMSVGAR3STATE, Cursor.xHotspot),
400 SSMFIELD_ENTRY( VMSVGAR3STATE, Cursor.yHotspot),
401 SSMFIELD_ENTRY( VMSVGAR3STATE, Cursor.width),
402 SSMFIELD_ENTRY( VMSVGAR3STATE, Cursor.height),
403 SSMFIELD_ENTRY( VMSVGAR3STATE, Cursor.cbData),
404 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAR3STATE, Cursor.pData),
405 SSMFIELD_ENTRY( VMSVGAR3STATE, colorAnnotation),
406 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, cBusyDelayedEmts),
407#ifdef VMSVGA_USE_EMT_HALT_CODE
408 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, BusyDelayedEmts),
409#else
410 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, hBusyDelayedEmts),
411#endif
412 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatBusyDelayEmts),
413 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dPresentProf),
414 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dDrawPrimitivesProf),
415 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSurfaceDmaProf),
416 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdDefineGmr2),
417 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdDefineGmr2Free),
418 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdDefineGmr2Modify),
419 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdRemapGmr2),
420 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdRemapGmr2Modify),
421 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdInvalidCmd),
422 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdFence),
423 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdUpdate),
424 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdUpdateVerbose),
425 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdDefineCursor),
426 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdDefineAlphaCursor),
427 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdEscape),
428 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdDefineScreen),
429 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdDestroyScreen),
430 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdDefineGmrFb),
431 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdBlitGmrFbToScreen),
432 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdBlitScreentoGmrFb),
433 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdAnnotationFill),
434 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3CmdAnnotationCopy),
435 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSurfaceDefine),
436 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSurfaceDefineV2),
437 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSurfaceDestroy),
438 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSurfaceCopy),
439 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSurfaceStretchBlt),
440 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSurfaceDma),
441 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSurfaceScreen),
442 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dContextDefine),
443 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dContextDestroy),
444 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetTransform),
445 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetZRange),
446 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetRenderState),
447 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetRenderTarget),
448 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetTextureState),
449 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetMaterial),
450 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetLightData),
451 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetLightEnable),
452 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetViewPort),
453 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetClipPlane),
454 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dClear),
455 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dPresent),
456 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dPresentReadBack),
457 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dShaderDefine),
458 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dShaderDestroy),
459 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetShader),
460 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetShaderConst),
461 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dDrawPrimitives),
462 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dSetScissorRect),
463 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dBeginQuery),
464 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dEndQuery),
465 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dWaitForQuery),
466 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dGenerateMipmaps),
467 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dActivateSurface),
468 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3Cmd3dDeactivateSurface),
469
470 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3RegConfigDoneWr),
471 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3RegGmrDescriptorWr),
472 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3RegGmrDescriptorWrErrors),
473 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatR3RegGmrDescriptorWrFree),
474
475 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoCommands),
476 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoErrors),
477 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoUnkCmds),
478 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoTodoTimeout),
479 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoTodoWoken),
480 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoStalls),
481 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoExtendedSleep),
482# if defined(VMSVGA_USE_FIFO_ACCESS_HANDLER) || defined(DEBUG_FIFO_ACCESS)
483 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoAccessHandler),
484# endif
485 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoCursorFetchAgain),
486 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoCursorNoChange),
487 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoCursorPosition),
488 SSMFIELD_ENTRY_IGNORE( VMSVGAR3STATE, StatFifoCursorVisiblity),
489
490 SSMFIELD_ENTRY_TERM()
491};
492
493/**
494 * SSM descriptor table for the VGAState.svga structure.
495 */
496static SSMFIELD const g_aVGAStateSVGAFields[] =
497{
498 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pFIFOR3),
499 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pFIFOR0),
500 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pSvgaR3State),
501 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, p3dState),
502 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pbVgaFrameBufferR3),
503 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pvFIFOExtCmdParam),
504 SSMFIELD_ENTRY_IGN_GCPHYS( VMSVGAState, GCPhysFIFO),
505 SSMFIELD_ENTRY_IGNORE( VMSVGAState, cbFIFO),
506 SSMFIELD_ENTRY_IGNORE( VMSVGAState, cbFIFOConfig),
507 SSMFIELD_ENTRY( VMSVGAState, u32SVGAId),
508 SSMFIELD_ENTRY( VMSVGAState, fEnabled),
509 SSMFIELD_ENTRY( VMSVGAState, fConfigured),
510 SSMFIELD_ENTRY( VMSVGAState, fBusy),
511 SSMFIELD_ENTRY( VMSVGAState, fTraces),
512 SSMFIELD_ENTRY( VMSVGAState, u32GuestId),
513 SSMFIELD_ENTRY( VMSVGAState, cScratchRegion),
514 SSMFIELD_ENTRY( VMSVGAState, au32ScratchRegion),
515 SSMFIELD_ENTRY( VMSVGAState, u32IrqStatus),
516 SSMFIELD_ENTRY( VMSVGAState, u32IrqMask),
517 SSMFIELD_ENTRY( VMSVGAState, u32PitchLock),
518 SSMFIELD_ENTRY( VMSVGAState, u32CurrentGMRId),
519 SSMFIELD_ENTRY( VMSVGAState, u32RegCaps),
520 SSMFIELD_ENTRY_IGNORE( VMSVGAState, BasePort),
521 SSMFIELD_ENTRY( VMSVGAState, u32IndexReg),
522 SSMFIELD_ENTRY_IGNORE( VMSVGAState, pSupDrvSession),
523 SSMFIELD_ENTRY_IGNORE( VMSVGAState, FIFORequestSem),
524 SSMFIELD_ENTRY_IGNORE( VMSVGAState, FIFOExtCmdSem),
525 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pFIFOIOThread),
526 SSMFIELD_ENTRY_IGNORE( VMSVGAState, uLastCursorUpdateCount),
527 SSMFIELD_ENTRY_IGNORE( VMSVGAState, fFIFOThreadSleeping),
528 SSMFIELD_ENTRY_VER( VMSVGAState, fGFBRegisters, VGA_SAVEDSTATE_VERSION_VMSVGA_SCREENS),
529 SSMFIELD_ENTRY( VMSVGAState, uWidth),
530 SSMFIELD_ENTRY( VMSVGAState, uHeight),
531 SSMFIELD_ENTRY( VMSVGAState, uBpp),
532 SSMFIELD_ENTRY( VMSVGAState, cbScanline),
533 SSMFIELD_ENTRY_VER( VMSVGAState, uScreenOffset, VGA_SAVEDSTATE_VERSION_VMSVGA),
534 SSMFIELD_ENTRY( VMSVGAState, u32MaxWidth),
535 SSMFIELD_ENTRY( VMSVGAState, u32MaxHeight),
536 SSMFIELD_ENTRY( VMSVGAState, u32ActionFlags),
537 SSMFIELD_ENTRY( VMSVGAState, f3DEnabled),
538 SSMFIELD_ENTRY( VMSVGAState, fVRAMTracking),
539 SSMFIELD_ENTRY_IGNORE( VMSVGAState, u8FIFOExtCommand),
540 SSMFIELD_ENTRY_IGNORE( VMSVGAState, fFifoExtCommandWakeup),
541 SSMFIELD_ENTRY_IGNORE( VMSVGAState, cGMR),
542 SSMFIELD_ENTRY_TERM()
543};
544
545static void vmsvgaSetTraces(PVGASTATE pThis, bool fTraces);
546static int vmsvgaLoadExecFifo(PVGASTATE pThis, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
547static int vmsvgaSaveExecFifo(PVGASTATE pThis, PSSMHANDLE pSSM);
548
549VMSVGASCREENOBJECT *vmsvgaGetScreenObject(PVGASTATE pThis, uint32_t idScreen)
550{
551 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
552 if ( idScreen < (uint32_t)RT_ELEMENTS(pSVGAState->aScreens)
553 && pSVGAState
554 && pSVGAState->aScreens[idScreen].fDefined)
555 {
556 return &pSVGAState->aScreens[idScreen];
557 }
558 return NULL;
559}
560
561#endif /* IN_RING3 */
562
563#ifdef LOG_ENABLED
564
565/**
566 * Index register string name lookup
567 *
568 * @returns Index register string or "UNKNOWN"
569 * @param pThis VMSVGA State
570 * @param idxReg The index register.
571 */
572static const char *vmsvgaIndexToString(PVGASTATE pThis, uint32_t idxReg)
573{
574 switch (idxReg)
575 {
576 case SVGA_REG_ID: return "SVGA_REG_ID";
577 case SVGA_REG_ENABLE: return "SVGA_REG_ENABLE";
578 case SVGA_REG_WIDTH: return "SVGA_REG_WIDTH";
579 case SVGA_REG_HEIGHT: return "SVGA_REG_HEIGHT";
580 case SVGA_REG_MAX_WIDTH: return "SVGA_REG_MAX_WIDTH";
581 case SVGA_REG_MAX_HEIGHT: return "SVGA_REG_MAX_HEIGHT";
582 case SVGA_REG_DEPTH: return "SVGA_REG_DEPTH";
583 case SVGA_REG_BITS_PER_PIXEL: return "SVGA_REG_BITS_PER_PIXEL"; /* Current bpp in the guest */
584 case SVGA_REG_HOST_BITS_PER_PIXEL: return "SVGA_REG_HOST_BITS_PER_PIXEL"; /* (Deprecated) */
585 case SVGA_REG_PSEUDOCOLOR: return "SVGA_REG_PSEUDOCOLOR";
586 case SVGA_REG_RED_MASK: return "SVGA_REG_RED_MASK";
587 case SVGA_REG_GREEN_MASK: return "SVGA_REG_GREEN_MASK";
588 case SVGA_REG_BLUE_MASK: return "SVGA_REG_BLUE_MASK";
589 case SVGA_REG_BYTES_PER_LINE: return "SVGA_REG_BYTES_PER_LINE";
590 case SVGA_REG_VRAM_SIZE: return "SVGA_REG_VRAM_SIZE"; /* VRAM size */
591 case SVGA_REG_FB_START: return "SVGA_REG_FB_START"; /* Frame buffer physical address. */
592 case SVGA_REG_FB_OFFSET: return "SVGA_REG_FB_OFFSET"; /* Offset of the frame buffer in VRAM */
593 case SVGA_REG_FB_SIZE: return "SVGA_REG_FB_SIZE"; /* Frame buffer size */
594 case SVGA_REG_CAPABILITIES: return "SVGA_REG_CAPABILITIES";
595 case SVGA_REG_MEM_START: return "SVGA_REG_MEM_START"; /* FIFO start */
596 case SVGA_REG_MEM_SIZE: return "SVGA_REG_MEM_SIZE"; /* FIFO size */
597 case SVGA_REG_CONFIG_DONE: return "SVGA_REG_CONFIG_DONE"; /* Set when memory area configured */
598 case SVGA_REG_SYNC: return "SVGA_REG_SYNC"; /* See "FIFO Synchronization Registers" */
599 case SVGA_REG_BUSY: return "SVGA_REG_BUSY"; /* See "FIFO Synchronization Registers" */
600 case SVGA_REG_GUEST_ID: return "SVGA_REG_GUEST_ID"; /* Set guest OS identifier */
601 case SVGA_REG_SCRATCH_SIZE: return "SVGA_REG_SCRATCH_SIZE"; /* Number of scratch registers */
602 case SVGA_REG_MEM_REGS: return "SVGA_REG_MEM_REGS"; /* Number of FIFO registers */
603 case SVGA_REG_PITCHLOCK: return "SVGA_REG_PITCHLOCK"; /* Fixed pitch for all modes */
604 case SVGA_REG_IRQMASK: return "SVGA_REG_IRQMASK"; /* Interrupt mask */
605 case SVGA_REG_GMR_ID: return "SVGA_REG_GMR_ID";
606 case SVGA_REG_GMR_DESCRIPTOR: return "SVGA_REG_GMR_DESCRIPTOR";
607 case SVGA_REG_GMR_MAX_IDS: return "SVGA_REG_GMR_MAX_IDS";
608 case SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH:return "SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH";
609 case SVGA_REG_TRACES: return "SVGA_REG_TRACES"; /* Enable trace-based updates even when FIFO is on */
610 case SVGA_REG_GMRS_MAX_PAGES: return "SVGA_REG_GMRS_MAX_PAGES"; /* Maximum number of 4KB pages for all GMRs */
611 case SVGA_REG_MEMORY_SIZE: return "SVGA_REG_MEMORY_SIZE"; /* Total dedicated device memory excluding FIFO */
612 case SVGA_REG_TOP: return "SVGA_REG_TOP"; /* Must be 1 more than the last register */
613 case SVGA_PALETTE_BASE: return "SVGA_PALETTE_BASE"; /* Base of SVGA color map */
614 case SVGA_REG_CURSOR_ID: return "SVGA_REG_CURSOR_ID";
615 case SVGA_REG_CURSOR_X: return "SVGA_REG_CURSOR_X";
616 case SVGA_REG_CURSOR_Y: return "SVGA_REG_CURSOR_Y";
617 case SVGA_REG_CURSOR_ON: return "SVGA_REG_CURSOR_ON";
618 case SVGA_REG_NUM_GUEST_DISPLAYS: return "SVGA_REG_NUM_GUEST_DISPLAYS"; /* Number of guest displays in X/Y direction */
619 case SVGA_REG_DISPLAY_ID: return "SVGA_REG_DISPLAY_ID"; /* Display ID for the following display attributes */
620 case SVGA_REG_DISPLAY_IS_PRIMARY: return "SVGA_REG_DISPLAY_IS_PRIMARY"; /* Whether this is a primary display */
621 case SVGA_REG_DISPLAY_POSITION_X: return "SVGA_REG_DISPLAY_POSITION_X"; /* The display position x */
622 case SVGA_REG_DISPLAY_POSITION_Y: return "SVGA_REG_DISPLAY_POSITION_Y"; /* The display position y */
623 case SVGA_REG_DISPLAY_WIDTH: return "SVGA_REG_DISPLAY_WIDTH"; /* The display's width */
624 case SVGA_REG_DISPLAY_HEIGHT: return "SVGA_REG_DISPLAY_HEIGHT"; /* The display's height */
625 case SVGA_REG_NUM_DISPLAYS: return "SVGA_REG_NUM_DISPLAYS"; /* (Deprecated) */
626
627 default:
628 if (idxReg - (uint32_t)SVGA_SCRATCH_BASE < pThis->svga.cScratchRegion)
629 return "SVGA_SCRATCH_BASE reg";
630 if (idxReg - (uint32_t)SVGA_PALETTE_BASE < (uint32_t)SVGA_NUM_PALETTE_REGS)
631 return "SVGA_PALETTE_BASE reg";
632 return "UNKNOWN";
633 }
634}
635
636#ifdef IN_RING3
637/**
638 * FIFO command name lookup
639 *
640 * @returns FIFO command string or "UNKNOWN"
641 * @param u32Cmd FIFO command
642 */
643static const char *vmsvgaFIFOCmdToString(uint32_t u32Cmd)
644{
645 switch (u32Cmd)
646 {
647 case SVGA_CMD_INVALID_CMD: return "SVGA_CMD_INVALID_CMD";
648 case SVGA_CMD_UPDATE: return "SVGA_CMD_UPDATE";
649 case SVGA_CMD_RECT_COPY: return "SVGA_CMD_RECT_COPY";
650 case SVGA_CMD_DEFINE_CURSOR: return "SVGA_CMD_DEFINE_CURSOR";
651 case SVGA_CMD_DEFINE_ALPHA_CURSOR: return "SVGA_CMD_DEFINE_ALPHA_CURSOR";
652 case SVGA_CMD_UPDATE_VERBOSE: return "SVGA_CMD_UPDATE_VERBOSE";
653 case SVGA_CMD_FRONT_ROP_FILL: return "SVGA_CMD_FRONT_ROP_FILL";
654 case SVGA_CMD_FENCE: return "SVGA_CMD_FENCE";
655 case SVGA_CMD_ESCAPE: return "SVGA_CMD_ESCAPE";
656 case SVGA_CMD_DEFINE_SCREEN: return "SVGA_CMD_DEFINE_SCREEN";
657 case SVGA_CMD_DESTROY_SCREEN: return "SVGA_CMD_DESTROY_SCREEN";
658 case SVGA_CMD_DEFINE_GMRFB: return "SVGA_CMD_DEFINE_GMRFB";
659 case SVGA_CMD_BLIT_GMRFB_TO_SCREEN: return "SVGA_CMD_BLIT_GMRFB_TO_SCREEN";
660 case SVGA_CMD_BLIT_SCREEN_TO_GMRFB: return "SVGA_CMD_BLIT_SCREEN_TO_GMRFB";
661 case SVGA_CMD_ANNOTATION_FILL: return "SVGA_CMD_ANNOTATION_FILL";
662 case SVGA_CMD_ANNOTATION_COPY: return "SVGA_CMD_ANNOTATION_COPY";
663 case SVGA_CMD_DEFINE_GMR2: return "SVGA_CMD_DEFINE_GMR2";
664 case SVGA_CMD_REMAP_GMR2: return "SVGA_CMD_REMAP_GMR2";
665 case SVGA_3D_CMD_SURFACE_DEFINE: return "SVGA_3D_CMD_SURFACE_DEFINE";
666 case SVGA_3D_CMD_SURFACE_DESTROY: return "SVGA_3D_CMD_SURFACE_DESTROY";
667 case SVGA_3D_CMD_SURFACE_COPY: return "SVGA_3D_CMD_SURFACE_COPY";
668 case SVGA_3D_CMD_SURFACE_STRETCHBLT: return "SVGA_3D_CMD_SURFACE_STRETCHBLT";
669 case SVGA_3D_CMD_SURFACE_DMA: return "SVGA_3D_CMD_SURFACE_DMA";
670 case SVGA_3D_CMD_CONTEXT_DEFINE: return "SVGA_3D_CMD_CONTEXT_DEFINE";
671 case SVGA_3D_CMD_CONTEXT_DESTROY: return "SVGA_3D_CMD_CONTEXT_DESTROY";
672 case SVGA_3D_CMD_SETTRANSFORM: return "SVGA_3D_CMD_SETTRANSFORM";
673 case SVGA_3D_CMD_SETZRANGE: return "SVGA_3D_CMD_SETZRANGE";
674 case SVGA_3D_CMD_SETRENDERSTATE: return "SVGA_3D_CMD_SETRENDERSTATE";
675 case SVGA_3D_CMD_SETRENDERTARGET: return "SVGA_3D_CMD_SETRENDERTARGET";
676 case SVGA_3D_CMD_SETTEXTURESTATE: return "SVGA_3D_CMD_SETTEXTURESTATE";
677 case SVGA_3D_CMD_SETMATERIAL: return "SVGA_3D_CMD_SETMATERIAL";
678 case SVGA_3D_CMD_SETLIGHTDATA: return "SVGA_3D_CMD_SETLIGHTDATA";
679 case SVGA_3D_CMD_SETLIGHTENABLED: return "SVGA_3D_CMD_SETLIGHTENABLED";
680 case SVGA_3D_CMD_SETVIEWPORT: return "SVGA_3D_CMD_SETVIEWPORT";
681 case SVGA_3D_CMD_SETCLIPPLANE: return "SVGA_3D_CMD_SETCLIPPLANE";
682 case SVGA_3D_CMD_CLEAR: return "SVGA_3D_CMD_CLEAR";
683 case SVGA_3D_CMD_PRESENT: return "SVGA_3D_CMD_PRESENT";
684 case SVGA_3D_CMD_SHADER_DEFINE: return "SVGA_3D_CMD_SHADER_DEFINE";
685 case SVGA_3D_CMD_SHADER_DESTROY: return "SVGA_3D_CMD_SHADER_DESTROY";
686 case SVGA_3D_CMD_SET_SHADER: return "SVGA_3D_CMD_SET_SHADER";
687 case SVGA_3D_CMD_SET_SHADER_CONST: return "SVGA_3D_CMD_SET_SHADER_CONST";
688 case SVGA_3D_CMD_DRAW_PRIMITIVES: return "SVGA_3D_CMD_DRAW_PRIMITIVES";
689 case SVGA_3D_CMD_SETSCISSORRECT: return "SVGA_3D_CMD_SETSCISSORRECT";
690 case SVGA_3D_CMD_BEGIN_QUERY: return "SVGA_3D_CMD_BEGIN_QUERY";
691 case SVGA_3D_CMD_END_QUERY: return "SVGA_3D_CMD_END_QUERY";
692 case SVGA_3D_CMD_WAIT_FOR_QUERY: return "SVGA_3D_CMD_WAIT_FOR_QUERY";
693 case SVGA_3D_CMD_PRESENT_READBACK: return "SVGA_3D_CMD_PRESENT_READBACK";
694 case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN:return "SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN";
695 case SVGA_3D_CMD_SURFACE_DEFINE_V2: return "SVGA_3D_CMD_SURFACE_DEFINE_V2";
696 case SVGA_3D_CMD_GENERATE_MIPMAPS: return "SVGA_3D_CMD_GENERATE_MIPMAPS";
697 case SVGA_3D_CMD_ACTIVATE_SURFACE: return "SVGA_3D_CMD_ACTIVATE_SURFACE";
698 case SVGA_3D_CMD_DEACTIVATE_SURFACE: return "SVGA_3D_CMD_DEACTIVATE_SURFACE";
699 default: return "UNKNOWN";
700 }
701}
702# endif /* IN_RING3 */
703
704#endif /* LOG_ENABLED */
705
706#ifdef IN_RING3
707/**
708 * @interface_method_impl{PDMIDISPLAYPORT,pfnSetViewport}
709 */
710DECLCALLBACK(void) vmsvgaPortSetViewport(PPDMIDISPLAYPORT pInterface, uint32_t idScreen, uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
711{
712 PVGASTATE pThis = RT_FROM_MEMBER(pInterface, VGASTATE, IPort);
713
714 Log(("vmsvgaPortSetViewPort: screen %d (%d,%d)(%d,%d)\n", idScreen, x, y, cx, cy));
715 VMSVGAVIEWPORT const OldViewport = pThis->svga.viewport;
716
717 /** @todo Test how it interacts with multiple screen objects. */
718 VMSVGASCREENOBJECT *pScreen = vmsvgaGetScreenObject(pThis, idScreen);
719 uint32_t const uWidth = pScreen ? pScreen->cWidth : 0;
720 uint32_t const uHeight = pScreen ? pScreen->cHeight : 0;
721
722 if (x < uWidth)
723 {
724 pThis->svga.viewport.x = x;
725 pThis->svga.viewport.cx = RT_MIN(cx, uWidth - x);
726 pThis->svga.viewport.xRight = x + pThis->svga.viewport.cx;
727 }
728 else
729 {
730 pThis->svga.viewport.x = uWidth;
731 pThis->svga.viewport.cx = 0;
732 pThis->svga.viewport.xRight = uWidth;
733 }
734 if (y < uHeight)
735 {
736 pThis->svga.viewport.y = y;
737 pThis->svga.viewport.cy = RT_MIN(cy, uHeight - y);
738 pThis->svga.viewport.yLowWC = uHeight - y - pThis->svga.viewport.cy;
739 pThis->svga.viewport.yHighWC = uHeight - y;
740 }
741 else
742 {
743 pThis->svga.viewport.y = uHeight;
744 pThis->svga.viewport.cy = 0;
745 pThis->svga.viewport.yLowWC = 0;
746 pThis->svga.viewport.yHighWC = 0;
747 }
748
749# ifdef VBOX_WITH_VMSVGA3D
750 /*
751 * Now inform the 3D backend.
752 */
753 if (pThis->svga.f3DEnabled)
754 vmsvga3dUpdateHostScreenViewport(pThis, idScreen, &OldViewport);
755# else
756 RT_NOREF(OldViewport);
757# endif
758}
759#endif /* IN_RING3 */
760
761/**
762 * Read port register
763 *
764 * @returns VBox status code.
765 * @param pThis VMSVGA State
766 * @param pu32 Where to store the read value
767 */
768PDMBOTHCBDECL(int) vmsvgaReadPort(PVGASTATE pThis, uint32_t *pu32)
769{
770 int rc = VINF_SUCCESS;
771 *pu32 = 0;
772
773 /* Rough index register validation. */
774 uint32_t idxReg = pThis->svga.u32IndexReg;
775#if !defined(IN_RING3) && defined(VBOX_STRICT)
776 ASSERT_GUEST_MSG_RETURN(idxReg < SVGA_SCRATCH_BASE + pThis->svga.cScratchRegion, ("idxReg=%#x\n", idxReg),
777 VINF_IOM_R3_IOPORT_READ);
778#else
779 ASSERT_GUEST_MSG_STMT_RETURN(idxReg < SVGA_SCRATCH_BASE + pThis->svga.cScratchRegion, ("idxReg=%#x\n", idxReg),
780 STAM_REL_COUNTER_INC(&pThis->svga.StatRegUnknownRd),
781 VINF_SUCCESS);
782#endif
783 RT_UNTRUSTED_VALIDATED_FENCE();
784
785 /* We must adjust the register number if we're in SVGA_ID_0 mode because the PALETTE range moved. */
786 if ( idxReg >= SVGA_REG_CAPABILITIES
787 && pThis->svga.u32SVGAId == SVGA_ID_0)
788 {
789 idxReg += SVGA_PALETTE_BASE - SVGA_REG_CAPABILITIES;
790 Log(("vmsvgaWritePort: SVGA_ID_0 reg adj %#x -> %#x\n", pThis->svga.u32IndexReg, idxReg));
791 }
792
793 switch (idxReg)
794 {
795 case SVGA_REG_ID:
796 STAM_REL_COUNTER_INC(&pThis->svga.StatRegIdRd);
797 *pu32 = pThis->svga.u32SVGAId;
798 break;
799
800 case SVGA_REG_ENABLE:
801 STAM_REL_COUNTER_INC(&pThis->svga.StatRegEnableRd);
802 *pu32 = pThis->svga.fEnabled;
803 break;
804
805 case SVGA_REG_WIDTH:
806 {
807 STAM_REL_COUNTER_INC(&pThis->svga.StatRegWidthRd);
808 if ( pThis->svga.fEnabled
809 && pThis->svga.uWidth != VMSVGA_VAL_UNINITIALIZED)
810 {
811 *pu32 = pThis->svga.uWidth;
812 }
813 else
814 {
815#ifndef IN_RING3
816 rc = VINF_IOM_R3_IOPORT_READ;
817#else
818 *pu32 = pThis->pDrv->cx;
819#endif
820 }
821 break;
822 }
823
824 case SVGA_REG_HEIGHT:
825 {
826 STAM_REL_COUNTER_INC(&pThis->svga.StatRegHeightRd);
827 if ( pThis->svga.fEnabled
828 && pThis->svga.uHeight != VMSVGA_VAL_UNINITIALIZED)
829 {
830 *pu32 = pThis->svga.uHeight;
831 }
832 else
833 {
834#ifndef IN_RING3
835 rc = VINF_IOM_R3_IOPORT_READ;
836#else
837 *pu32 = pThis->pDrv->cy;
838#endif
839 }
840 break;
841 }
842
843 case SVGA_REG_MAX_WIDTH:
844 STAM_REL_COUNTER_INC(&pThis->svga.StatRegMaxWidthRd);
845 *pu32 = pThis->svga.u32MaxWidth;
846 break;
847
848 case SVGA_REG_MAX_HEIGHT:
849 STAM_REL_COUNTER_INC(&pThis->svga.StatRegMaxHeightRd);
850 *pu32 = pThis->svga.u32MaxHeight;
851 break;
852
853 case SVGA_REG_DEPTH:
854 /* This returns the color depth of the current mode. */
855 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDepthRd);
856 switch (pThis->svga.uBpp)
857 {
858 case 15:
859 case 16:
860 case 24:
861 *pu32 = pThis->svga.uBpp;
862 break;
863
864 default:
865 case 32:
866 *pu32 = 24; /* The upper 8 bits are either alpha bits or not used. */
867 break;
868 }
869 break;
870
871 case SVGA_REG_HOST_BITS_PER_PIXEL: /* (Deprecated) */
872 STAM_REL_COUNTER_INC(&pThis->svga.StatRegHostBitsPerPixelRd);
873 if ( pThis->svga.fEnabled
874 && pThis->svga.uBpp != VMSVGA_VAL_UNINITIALIZED)
875 {
876 *pu32 = pThis->svga.uBpp;
877 }
878 else
879 {
880#ifndef IN_RING3
881 rc = VINF_IOM_R3_IOPORT_READ;
882#else
883 *pu32 = pThis->pDrv->cBits;
884#endif
885 }
886 break;
887
888 case SVGA_REG_BITS_PER_PIXEL: /* Current bpp in the guest */
889 STAM_REL_COUNTER_INC(&pThis->svga.StatRegBitsPerPixelRd);
890 if ( pThis->svga.fEnabled
891 && pThis->svga.uBpp != VMSVGA_VAL_UNINITIALIZED)
892 {
893 *pu32 = (pThis->svga.uBpp + 7) & ~7;
894 }
895 else
896 {
897#ifndef IN_RING3
898 rc = VINF_IOM_R3_IOPORT_READ;
899#else
900 *pu32 = (pThis->pDrv->cBits + 7) & ~7;
901#endif
902 }
903 break;
904
905 case SVGA_REG_PSEUDOCOLOR:
906 STAM_REL_COUNTER_INC(&pThis->svga.StatRegPsuedoColorRd);
907 *pu32 = pThis->svga.uBpp == 8; /* See section 6 "Pseudocolor" in svga_interface.txt. */
908 break;
909
910 case SVGA_REG_RED_MASK:
911 case SVGA_REG_GREEN_MASK:
912 case SVGA_REG_BLUE_MASK:
913 {
914 uint32_t uBpp;
915
916 if ( pThis->svga.fEnabled
917 && pThis->svga.uBpp != VMSVGA_VAL_UNINITIALIZED)
918 {
919 uBpp = pThis->svga.uBpp;
920 }
921 else
922 {
923#ifndef IN_RING3
924 rc = VINF_IOM_R3_IOPORT_READ;
925 break;
926#else
927 uBpp = pThis->pDrv->cBits;
928#endif
929 }
930 uint32_t u32RedMask, u32GreenMask, u32BlueMask;
931 switch (uBpp)
932 {
933 case 8:
934 u32RedMask = 0x07;
935 u32GreenMask = 0x38;
936 u32BlueMask = 0xc0;
937 break;
938
939 case 15:
940 u32RedMask = 0x0000001f;
941 u32GreenMask = 0x000003e0;
942 u32BlueMask = 0x00007c00;
943 break;
944
945 case 16:
946 u32RedMask = 0x0000001f;
947 u32GreenMask = 0x000007e0;
948 u32BlueMask = 0x0000f800;
949 break;
950
951 case 24:
952 case 32:
953 default:
954 u32RedMask = 0x00ff0000;
955 u32GreenMask = 0x0000ff00;
956 u32BlueMask = 0x000000ff;
957 break;
958 }
959 switch (idxReg)
960 {
961 case SVGA_REG_RED_MASK:
962 STAM_REL_COUNTER_INC(&pThis->svga.StatRegRedMaskRd);
963 *pu32 = u32RedMask;
964 break;
965
966 case SVGA_REG_GREEN_MASK:
967 STAM_REL_COUNTER_INC(&pThis->svga.StatRegGreenMaskRd);
968 *pu32 = u32GreenMask;
969 break;
970
971 case SVGA_REG_BLUE_MASK:
972 STAM_REL_COUNTER_INC(&pThis->svga.StatRegBlueMaskRd);
973 *pu32 = u32BlueMask;
974 break;
975 }
976 break;
977 }
978
979 case SVGA_REG_BYTES_PER_LINE:
980 {
981 STAM_REL_COUNTER_INC(&pThis->svga.StatRegBytesPerLineRd);
982 if ( pThis->svga.fEnabled
983 && pThis->svga.cbScanline)
984 {
985 *pu32 = pThis->svga.cbScanline;
986 }
987 else
988 {
989#ifndef IN_RING3
990 rc = VINF_IOM_R3_IOPORT_READ;
991#else
992 *pu32 = pThis->pDrv->cbScanline;
993#endif
994 }
995 break;
996 }
997
998 case SVGA_REG_VRAM_SIZE: /* VRAM size */
999 STAM_REL_COUNTER_INC(&pThis->svga.StatRegVramSizeRd);
1000 *pu32 = pThis->vram_size;
1001 break;
1002
1003 case SVGA_REG_FB_START: /* Frame buffer physical address. */
1004 STAM_REL_COUNTER_INC(&pThis->svga.StatRegFbStartRd);
1005 Assert(pThis->GCPhysVRAM <= 0xffffffff);
1006 *pu32 = pThis->GCPhysVRAM;
1007 break;
1008
1009 case SVGA_REG_FB_OFFSET: /* Offset of the frame buffer in VRAM */
1010 STAM_REL_COUNTER_INC(&pThis->svga.StatRegFbOffsetRd);
1011 /* Always zero in our case. */
1012 *pu32 = 0;
1013 break;
1014
1015 case SVGA_REG_FB_SIZE: /* Frame buffer size */
1016 {
1017#ifndef IN_RING3
1018 rc = VINF_IOM_R3_IOPORT_READ;
1019#else
1020 STAM_REL_COUNTER_INC(&pThis->svga.StatRegFbSizeRd);
1021
1022 /* VMWare testcases want at least 4 MB in case the hardware is disabled. */
1023 if ( pThis->svga.fEnabled
1024 && pThis->svga.uHeight != VMSVGA_VAL_UNINITIALIZED)
1025 {
1026 /* Hardware enabled; return real framebuffer size .*/
1027 *pu32 = (uint32_t)pThis->svga.uHeight * pThis->svga.cbScanline;
1028 }
1029 else
1030 *pu32 = RT_MAX(0x100000, (uint32_t)pThis->pDrv->cy * pThis->pDrv->cbScanline);
1031
1032 *pu32 = RT_MIN(pThis->vram_size, *pu32);
1033 Log(("h=%d w=%d bpp=%d\n", pThis->pDrv->cy, pThis->pDrv->cx, pThis->pDrv->cBits));
1034#endif
1035 break;
1036 }
1037
1038 case SVGA_REG_CAPABILITIES:
1039 STAM_REL_COUNTER_INC(&pThis->svga.StatRegCapabilitesRd);
1040 *pu32 = pThis->svga.u32RegCaps;
1041 break;
1042
1043 case SVGA_REG_MEM_START: /* FIFO start */
1044 STAM_REL_COUNTER_INC(&pThis->svga.StatRegMemStartRd);
1045 Assert(pThis->svga.GCPhysFIFO <= 0xffffffff);
1046 *pu32 = pThis->svga.GCPhysFIFO;
1047 break;
1048
1049 case SVGA_REG_MEM_SIZE: /* FIFO size */
1050 STAM_REL_COUNTER_INC(&pThis->svga.StatRegMemSizeRd);
1051 *pu32 = pThis->svga.cbFIFO;
1052 break;
1053
1054 case SVGA_REG_CONFIG_DONE: /* Set when memory area configured */
1055 STAM_REL_COUNTER_INC(&pThis->svga.StatRegConfigDoneRd);
1056 *pu32 = pThis->svga.fConfigured;
1057 break;
1058
1059 case SVGA_REG_SYNC: /* See "FIFO Synchronization Registers" */
1060 STAM_REL_COUNTER_INC(&pThis->svga.StatRegSyncRd);
1061 *pu32 = 0;
1062 break;
1063
1064 case SVGA_REG_BUSY: /* See "FIFO Synchronization Registers" */
1065 STAM_REL_COUNTER_INC(&pThis->svga.StatRegBusyRd);
1066 if (pThis->svga.fBusy)
1067 {
1068#ifndef IN_RING3
1069 /* Go to ring-3 and halt the CPU. */
1070 rc = VINF_IOM_R3_IOPORT_READ;
1071 break;
1072#else
1073# if defined(VMSVGA_USE_EMT_HALT_CODE)
1074 /* The guest is basically doing a HLT via the device here, but with
1075 a special wake up condition on FIFO completion. */
1076 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
1077 STAM_REL_PROFILE_START(&pSVGAState->StatBusyDelayEmts, EmtDelay);
1078 PVM pVM = PDMDevHlpGetVM(pThis->pDevInsR3);
1079 VMCPUID idCpu = PDMDevHlpGetCurrentCpuId(pThis->pDevInsR3);
1080 VMCPUSET_ATOMIC_ADD(&pSVGAState->BusyDelayedEmts, idCpu);
1081 ASMAtomicIncU32(&pSVGAState->cBusyDelayedEmts);
1082 if (pThis->svga.fBusy)
1083 {
1084 PDMCritSectLeave(&pThis->CritSect); /* hack around lock order issue. */
1085 rc = VMR3WaitForDeviceReady(pVM, idCpu);
1086 PDMCritSectEnter(&pThis->CritSect, VERR_IGNORED);
1087 }
1088 ASMAtomicDecU32(&pSVGAState->cBusyDelayedEmts);
1089 VMCPUSET_ATOMIC_DEL(&pSVGAState->BusyDelayedEmts, idCpu);
1090# else
1091
1092 /* Delay the EMT a bit so the FIFO and others can get some work done.
1093 This used to be a crude 50 ms sleep. The current code tries to be
1094 more efficient, but the consept is still very crude. */
1095 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
1096 STAM_REL_PROFILE_START(&pSVGAState->StatBusyDelayEmts, EmtDelay);
1097 RTThreadYield();
1098 if (pThis->svga.fBusy)
1099 {
1100 uint32_t cRefs = ASMAtomicIncU32(&pSVGAState->cBusyDelayedEmts);
1101
1102 if (pThis->svga.fBusy && cRefs == 1)
1103 RTSemEventMultiReset(pSVGAState->hBusyDelayedEmts);
1104 if (pThis->svga.fBusy)
1105 {
1106 /** @todo If this code is going to stay, we need to call into the halt/wait
1107 * code in VMEmt.cpp here, otherwise all kind of EMT interaction will
1108 * suffer when the guest is polling on a busy FIFO. */
1109 uint64_t cNsMaxWait = TMVirtualSyncGetNsToDeadline(PDMDevHlpGetVM(pThis->pDevInsR3));
1110 if (cNsMaxWait >= RT_NS_100US)
1111 RTSemEventMultiWaitEx(pSVGAState->hBusyDelayedEmts,
1112 RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NORESUME,
1113 RT_MIN(cNsMaxWait, RT_NS_10MS));
1114 }
1115
1116 ASMAtomicDecU32(&pSVGAState->cBusyDelayedEmts);
1117 }
1118 STAM_REL_PROFILE_STOP(&pSVGAState->StatBusyDelayEmts, EmtDelay);
1119# endif
1120 *pu32 = pThis->svga.fBusy != 0;
1121#endif
1122 }
1123 else
1124 *pu32 = false;
1125 break;
1126
1127 case SVGA_REG_GUEST_ID: /* Set guest OS identifier */
1128 STAM_REL_COUNTER_INC(&pThis->svga.StatRegGuestIdRd);
1129 *pu32 = pThis->svga.u32GuestId;
1130 break;
1131
1132 case SVGA_REG_SCRATCH_SIZE: /* Number of scratch registers */
1133 STAM_REL_COUNTER_INC(&pThis->svga.StatRegScratchSizeRd);
1134 *pu32 = pThis->svga.cScratchRegion;
1135 break;
1136
1137 case SVGA_REG_MEM_REGS: /* Number of FIFO registers */
1138 STAM_REL_COUNTER_INC(&pThis->svga.StatRegMemRegsRd);
1139 *pu32 = SVGA_FIFO_NUM_REGS;
1140 break;
1141
1142 case SVGA_REG_PITCHLOCK: /* Fixed pitch for all modes */
1143 STAM_REL_COUNTER_INC(&pThis->svga.StatRegPitchLockRd);
1144 *pu32 = pThis->svga.u32PitchLock;
1145 break;
1146
1147 case SVGA_REG_IRQMASK: /* Interrupt mask */
1148 STAM_REL_COUNTER_INC(&pThis->svga.StatRegIrqMaskRd);
1149 *pu32 = pThis->svga.u32IrqMask;
1150 break;
1151
1152 /* See "Guest memory regions" below. */
1153 case SVGA_REG_GMR_ID:
1154 STAM_REL_COUNTER_INC(&pThis->svga.StatRegGmrIdRd);
1155 *pu32 = pThis->svga.u32CurrentGMRId;
1156 break;
1157
1158 case SVGA_REG_GMR_DESCRIPTOR:
1159 STAM_REL_COUNTER_INC(&pThis->svga.StatRegWriteOnlyRd);
1160 /* Write only */
1161 *pu32 = 0;
1162 break;
1163
1164 case SVGA_REG_GMR_MAX_IDS:
1165 STAM_REL_COUNTER_INC(&pThis->svga.StatRegGmrMaxIdsRd);
1166 *pu32 = pThis->svga.cGMR;
1167 break;
1168
1169 case SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH:
1170 STAM_REL_COUNTER_INC(&pThis->svga.StatRegGmrMaxDescriptorLengthRd);
1171 *pu32 = VMSVGA_MAX_GMR_PAGES;
1172 break;
1173
1174 case SVGA_REG_TRACES: /* Enable trace-based updates even when FIFO is on */
1175 STAM_REL_COUNTER_INC(&pThis->svga.StatRegTracesRd);
1176 *pu32 = pThis->svga.fTraces;
1177 break;
1178
1179 case SVGA_REG_GMRS_MAX_PAGES: /* Maximum number of 4KB pages for all GMRs */
1180 STAM_REL_COUNTER_INC(&pThis->svga.StatRegGmrsMaxPagesRd);
1181 *pu32 = VMSVGA_MAX_GMR_PAGES;
1182 break;
1183
1184 case SVGA_REG_MEMORY_SIZE: /* Total dedicated device memory excluding FIFO */
1185 STAM_REL_COUNTER_INC(&pThis->svga.StatRegMemorySizeRd);
1186 *pu32 = VMSVGA_SURFACE_SIZE;
1187 break;
1188
1189 case SVGA_REG_TOP: /* Must be 1 more than the last register */
1190 STAM_REL_COUNTER_INC(&pThis->svga.StatRegTopRd);
1191 break;
1192
1193 /* Mouse cursor support. */
1194 case SVGA_REG_CURSOR_ID:
1195 case SVGA_REG_CURSOR_X:
1196 case SVGA_REG_CURSOR_Y:
1197 case SVGA_REG_CURSOR_ON:
1198 STAM_REL_COUNTER_INC(&pThis->svga.StatRegCursorXxxxRd);
1199 break;
1200
1201 /* Legacy multi-monitor support */
1202 case SVGA_REG_NUM_GUEST_DISPLAYS:/* Number of guest displays in X/Y direction */
1203 STAM_REL_COUNTER_INC(&pThis->svga.StatRegNumGuestDisplaysRd);
1204 *pu32 = 1;
1205 break;
1206
1207 case SVGA_REG_DISPLAY_ID: /* Display ID for the following display attributes */
1208 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayIdRd);
1209 *pu32 = 0;
1210 break;
1211
1212 case SVGA_REG_DISPLAY_IS_PRIMARY:/* Whether this is a primary display */
1213 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayIsPrimaryRd);
1214 *pu32 = 0;
1215 break;
1216
1217 case SVGA_REG_DISPLAY_POSITION_X:/* The display position x */
1218 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayPositionXRd);
1219 *pu32 = 0;
1220 break;
1221
1222 case SVGA_REG_DISPLAY_POSITION_Y:/* The display position y */
1223 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayPositionYRd);
1224 *pu32 = 0;
1225 break;
1226
1227 case SVGA_REG_DISPLAY_WIDTH: /* The display's width */
1228 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayWidthRd);
1229 *pu32 = pThis->svga.uWidth;
1230 break;
1231
1232 case SVGA_REG_DISPLAY_HEIGHT: /* The display's height */
1233 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayHeightRd);
1234 *pu32 = pThis->svga.uHeight;
1235 break;
1236
1237 case SVGA_REG_NUM_DISPLAYS: /* (Deprecated) */
1238 STAM_REL_COUNTER_INC(&pThis->svga.StatRegNumDisplaysRd);
1239 /* We must return something sensible here otherwise the Linux driver
1240 will take a legacy code path without 3d support. This number also
1241 limits how many screens Linux guests will allow. */
1242 *pu32 = pThis->cMonitors;
1243 break;
1244
1245 default:
1246 {
1247 uint32_t offReg;
1248 if ((offReg = idxReg - SVGA_SCRATCH_BASE) < pThis->svga.cScratchRegion)
1249 {
1250 RT_UNTRUSTED_VALIDATED_FENCE();
1251 *pu32 = pThis->svga.au32ScratchRegion[offReg];
1252 STAM_REL_COUNTER_INC(&pThis->svga.StatRegScratchRd);
1253 }
1254 else if ((offReg = idxReg - SVGA_PALETTE_BASE) < (uint32_t)SVGA_NUM_PALETTE_REGS)
1255 {
1256 /* Note! Using last_palette rather than palette here to preserve the VGA one. */
1257 STAM_REL_COUNTER_INC(&pThis->svga.StatRegPaletteRd);
1258 RT_UNTRUSTED_VALIDATED_FENCE();
1259 uint32_t u32 = pThis->last_palette[offReg / 3];
1260 switch (offReg % 3)
1261 {
1262 case 0: *pu32 = (u32 >> 16) & 0xff; break; /* red */
1263 case 1: *pu32 = (u32 >> 8) & 0xff; break; /* green */
1264 case 2: *pu32 = u32 & 0xff; break; /* blue */
1265 }
1266 }
1267 else
1268 {
1269#if !defined(IN_RING3) && defined(VBOX_STRICT)
1270 rc = VINF_IOM_R3_IOPORT_READ;
1271#else
1272 STAM_REL_COUNTER_INC(&pThis->svga.StatRegUnknownRd);
1273
1274 /* Do not assert. The guest might be reading all registers. */
1275 LogFunc(("Unknown reg=%#x\n", idxReg));
1276#endif
1277 }
1278 break;
1279 }
1280 }
1281 Log(("vmsvgaReadPort index=%s (%d) val=%#x rc=%x\n", vmsvgaIndexToString(pThis, idxReg), idxReg, *pu32, rc));
1282 return rc;
1283}
1284
1285#ifdef IN_RING3
1286/**
1287 * Apply the current resolution settings to change the video mode.
1288 *
1289 * @returns VBox status code.
1290 * @param pThis VMSVGA State
1291 */
1292static int vmsvgaChangeMode(PVGASTATE pThis)
1293{
1294 int rc;
1295
1296 /* Always do changemode on FIFO thread. */
1297 Assert(RTThreadSelf() == pThis->svga.pFIFOIOThread->Thread);
1298
1299 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
1300
1301 pThis->pDrv->pfnLFBModeChange(pThis->pDrv, true);
1302
1303 if (pThis->svga.fGFBRegisters)
1304 {
1305 /* "For backwards compatibility, when the GFB mode registers (WIDTH,
1306 * HEIGHT, PITCHLOCK, BITS_PER_PIXEL) are modified, the SVGA device
1307 * deletes all screens other than screen #0, and redefines screen
1308 * #0 according to the specified mode. Drivers that use
1309 * SVGA_CMD_DEFINE_SCREEN should destroy or redefine screen #0."
1310 */
1311
1312 VMSVGASCREENOBJECT *pScreen = &pSVGAState->aScreens[0];
1313 pScreen->fDefined = true;
1314 pScreen->fModified = true;
1315 pScreen->fuScreen = SVGA_SCREEN_MUST_BE_SET | SVGA_SCREEN_IS_PRIMARY;
1316 pScreen->idScreen = 0;
1317 pScreen->xOrigin = 0;
1318 pScreen->yOrigin = 0;
1319 pScreen->offVRAM = 0;
1320 pScreen->cbPitch = pThis->svga.cbScanline;
1321 pScreen->cWidth = pThis->svga.uWidth;
1322 pScreen->cHeight = pThis->svga.uHeight;
1323 pScreen->cBpp = pThis->svga.uBpp;
1324
1325 for (unsigned iScreen = 1; iScreen < RT_ELEMENTS(pSVGAState->aScreens); ++iScreen)
1326 {
1327 /* Delete screen. */
1328 pScreen = &pSVGAState->aScreens[iScreen];
1329 if (pScreen->fDefined)
1330 {
1331 pScreen->fModified = true;
1332 pScreen->fDefined = false;
1333 }
1334 }
1335 }
1336 else
1337 {
1338 /* "If Screen Objects are supported, they can be used to fully
1339 * replace the functionality provided by the framebuffer registers
1340 * (SVGA_REG_WIDTH, HEIGHT, etc.) and by SVGA_CAP_DISPLAY_TOPOLOGY."
1341 */
1342 pThis->svga.uWidth = VMSVGA_VAL_UNINITIALIZED;
1343 pThis->svga.uHeight = VMSVGA_VAL_UNINITIALIZED;
1344 pThis->svga.uBpp = VMSVGA_VAL_UNINITIALIZED;
1345 }
1346
1347 for (unsigned iScreen = 0; iScreen < RT_ELEMENTS(pSVGAState->aScreens); ++iScreen)
1348 {
1349 VMSVGASCREENOBJECT *pScreen = &pSVGAState->aScreens[iScreen];
1350 if (!pScreen->fModified)
1351 continue;
1352
1353 pScreen->fModified = false;
1354
1355 VBVAINFOVIEW view;
1356 RT_ZERO(view);
1357 view.u32ViewIndex = pScreen->idScreen;
1358 // view.u32ViewOffset = 0;
1359 view.u32ViewSize = pThis->vram_size;
1360 view.u32MaxScreenSize = pThis->vram_size;
1361
1362 VBVAINFOSCREEN screen;
1363 RT_ZERO(screen);
1364 screen.u32ViewIndex = pScreen->idScreen;
1365
1366 if (pScreen->fDefined)
1367 {
1368 if ( pScreen->cWidth == VMSVGA_VAL_UNINITIALIZED
1369 || pScreen->cHeight == VMSVGA_VAL_UNINITIALIZED
1370 || pScreen->cBpp == VMSVGA_VAL_UNINITIALIZED)
1371 {
1372 Assert(pThis->svga.fGFBRegisters);
1373 continue;
1374 }
1375
1376 screen.i32OriginX = pScreen->xOrigin;
1377 screen.i32OriginY = pScreen->yOrigin;
1378 screen.u32StartOffset = pScreen->offVRAM;
1379 screen.u32LineSize = pScreen->cbPitch;
1380 screen.u32Width = pScreen->cWidth;
1381 screen.u32Height = pScreen->cHeight;
1382 screen.u16BitsPerPixel = pScreen->cBpp;
1383 if (!(pScreen->fuScreen & SVGA_SCREEN_DEACTIVATE))
1384 screen.u16Flags = VBVA_SCREEN_F_ACTIVE;
1385 if (pScreen->fuScreen & SVGA_SCREEN_BLANKING)
1386 screen.u16Flags |= VBVA_SCREEN_F_BLANK2;
1387 }
1388 else
1389 {
1390 /* Screen is destroyed. */
1391 screen.u16Flags = VBVA_SCREEN_F_DISABLED;
1392 }
1393
1394 rc = pThis->pDrv->pfnVBVAResize(pThis->pDrv, &view, &screen, pThis->CTX_SUFF(vram_ptr), /*fResetInputMapping=*/ true);
1395 AssertRC(rc);
1396 }
1397
1398 /* Last stuff. For the VGA device screenshot. */
1399 pThis->last_bpp = pSVGAState->aScreens[0].cBpp;
1400 pThis->last_scr_width = pSVGAState->aScreens[0].cWidth;
1401 pThis->last_scr_height = pSVGAState->aScreens[0].cHeight;
1402 pThis->last_width = pSVGAState->aScreens[0].cWidth;
1403 pThis->last_height = pSVGAState->aScreens[0].cHeight;
1404
1405 /* vmsvgaPortSetViewPort not called after state load; set sensible defaults. */
1406 if ( pThis->svga.viewport.cx == 0
1407 && pThis->svga.viewport.cy == 0)
1408 {
1409 pThis->svga.viewport.cx = pSVGAState->aScreens[0].cWidth;
1410 pThis->svga.viewport.xRight = pSVGAState->aScreens[0].cWidth;
1411 pThis->svga.viewport.cy = pSVGAState->aScreens[0].cHeight;
1412 pThis->svga.viewport.yHighWC = pSVGAState->aScreens[0].cHeight;
1413 pThis->svga.viewport.yLowWC = 0;
1414 }
1415
1416 return VINF_SUCCESS;
1417}
1418
1419int vmsvgaUpdateScreen(PVGASTATE pThis, VMSVGASCREENOBJECT *pScreen, int x, int y, int w, int h)
1420{
1421 VBVACMDHDR cmd;
1422 cmd.x = (int16_t)(pScreen->xOrigin + x);
1423 cmd.y = (int16_t)(pScreen->yOrigin + y);
1424 cmd.w = (uint16_t)w;
1425 cmd.h = (uint16_t)h;
1426
1427 pThis->pDrv->pfnVBVAUpdateBegin(pThis->pDrv, pScreen->idScreen);
1428 pThis->pDrv->pfnVBVAUpdateProcess(pThis->pDrv, pScreen->idScreen, &cmd, sizeof(cmd));
1429 pThis->pDrv->pfnVBVAUpdateEnd(pThis->pDrv, pScreen->idScreen,
1430 pScreen->xOrigin + x, pScreen->yOrigin + y, w, h);
1431
1432 return VINF_SUCCESS;
1433}
1434
1435#endif /* IN_RING3 */
1436
1437#if defined(IN_RING0) || defined(IN_RING3)
1438/**
1439 * Safely updates the SVGA_FIFO_BUSY register (in shared memory).
1440 *
1441 * @param pThis The VMSVGA state.
1442 * @param fState The busy state.
1443 */
1444DECLINLINE(void) vmsvgaSafeFifoBusyRegUpdate(PVGASTATE pThis, bool fState)
1445{
1446 ASMAtomicWriteU32(&pThis->svga.CTX_SUFF(pFIFO)[SVGA_FIFO_BUSY], fState);
1447
1448 if (RT_UNLIKELY(fState != (pThis->svga.fBusy != 0)))
1449 {
1450 /* Race / unfortunately scheduling. Highly unlikly. */
1451 uint32_t cLoops = 64;
1452 do
1453 {
1454 ASMNopPause();
1455 fState = (pThis->svga.fBusy != 0);
1456 ASMAtomicWriteU32(&pThis->svga.CTX_SUFF(pFIFO)[SVGA_FIFO_BUSY], fState != 0);
1457 } while (cLoops-- > 0 && fState != (pThis->svga.fBusy != 0));
1458 }
1459}
1460
1461
1462/**
1463 * Update the scanline pitch in response to the guest changing mode
1464 * width/bpp.
1465 *
1466 * @param pThis VMSVGA State
1467 */
1468DECLINLINE(void) vmsvgaUpdatePitch(PVGASTATE pThis)
1469{
1470 uint32_t RT_UNTRUSTED_VOLATILE_GUEST *pFIFO = pThis->svga.CTX_SUFF(pFIFO);
1471 uint32_t uFifoPitchLock = pFIFO[SVGA_FIFO_PITCHLOCK];
1472 uint32_t uRegPitchLock = pThis->svga.u32PitchLock;
1473 uint32_t uFifoMin = pFIFO[SVGA_FIFO_MIN];
1474
1475 /* The SVGA_FIFO_PITCHLOCK register is only valid if SVGA_FIFO_MIN points past
1476 * it. If SVGA_FIFO_MIN is small, there may well be data at the SVGA_FIFO_PITCHLOCK
1477 * location but it has a different meaning.
1478 */
1479 if ((uFifoMin / sizeof(uint32_t)) <= SVGA_FIFO_PITCHLOCK)
1480 uFifoPitchLock = 0;
1481
1482 /* Sanitize values. */
1483 if ((uFifoPitchLock < 200) || (uFifoPitchLock > 32768))
1484 uFifoPitchLock = 0;
1485 if ((uRegPitchLock < 200) || (uRegPitchLock > 32768))
1486 uRegPitchLock = 0;
1487
1488 /* Prefer the register value to the FIFO value.*/
1489 if (uRegPitchLock)
1490 pThis->svga.cbScanline = uRegPitchLock;
1491 else if (uFifoPitchLock)
1492 pThis->svga.cbScanline = uFifoPitchLock;
1493 else
1494 pThis->svga.cbScanline = pThis->svga.uWidth * (RT_ALIGN(pThis->svga.uBpp, 8) / 8);
1495
1496 if ((uFifoMin / sizeof(uint32_t)) <= SVGA_FIFO_PITCHLOCK)
1497 pThis->svga.u32PitchLock = pThis->svga.cbScanline;
1498}
1499#endif
1500
1501
1502/**
1503 * Write port register
1504 *
1505 * @returns VBox status code.
1506 * @param pThis VMSVGA State
1507 * @param u32 Value to write
1508 */
1509PDMBOTHCBDECL(int) vmsvgaWritePort(PVGASTATE pThis, uint32_t u32)
1510{
1511#ifdef IN_RING3
1512 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
1513#endif
1514 int rc = VINF_SUCCESS;
1515
1516 /* Rough index register validation. */
1517 uint32_t idxReg = pThis->svga.u32IndexReg;
1518#if !defined(IN_RING3) && defined(VBOX_STRICT)
1519 ASSERT_GUEST_MSG_RETURN(idxReg < SVGA_SCRATCH_BASE + pThis->svga.cScratchRegion, ("idxReg=%#x\n", idxReg),
1520 VINF_IOM_R3_IOPORT_WRITE);
1521#else
1522 ASSERT_GUEST_MSG_STMT_RETURN(idxReg < SVGA_SCRATCH_BASE + pThis->svga.cScratchRegion, ("idxReg=%#x\n", idxReg),
1523 STAM_REL_COUNTER_INC(&pThis->svga.StatRegUnknownWr),
1524 VINF_SUCCESS);
1525#endif
1526 RT_UNTRUSTED_VALIDATED_FENCE();
1527
1528 /* We must adjust the register number if we're in SVGA_ID_0 mode because the PALETTE range moved. */
1529 if ( idxReg >= SVGA_REG_CAPABILITIES
1530 && pThis->svga.u32SVGAId == SVGA_ID_0)
1531 {
1532 idxReg += SVGA_PALETTE_BASE - SVGA_REG_CAPABILITIES;
1533 Log(("vmsvgaWritePort: SVGA_ID_0 reg adj %#x -> %#x\n", pThis->svga.u32IndexReg, idxReg));
1534 }
1535 Log(("vmsvgaWritePort index=%s (%d) val=%#x\n", vmsvgaIndexToString(pThis, idxReg), idxReg, u32));
1536 /* Check if the guest uses legacy registers. See vmsvgaChangeMode */
1537 switch (idxReg)
1538 {
1539 case SVGA_REG_WIDTH:
1540 case SVGA_REG_HEIGHT:
1541 case SVGA_REG_PITCHLOCK:
1542 case SVGA_REG_BITS_PER_PIXEL:
1543 pThis->svga.fGFBRegisters = true;
1544 break;
1545 default:
1546 break;
1547 }
1548
1549 switch (idxReg)
1550 {
1551 case SVGA_REG_ID:
1552 STAM_REL_COUNTER_INC(&pThis->svga.StatRegIdWr);
1553 if ( u32 == SVGA_ID_0
1554 || u32 == SVGA_ID_1
1555 || u32 == SVGA_ID_2)
1556 pThis->svga.u32SVGAId = u32;
1557 else
1558 PDMDevHlpDBGFStop(pThis->CTX_SUFF(pDevIns), RT_SRC_POS, "Trying to set SVGA_REG_ID to %#x (%d)\n", u32, u32);
1559 break;
1560
1561 case SVGA_REG_ENABLE:
1562 STAM_REL_COUNTER_INC(&pThis->svga.StatRegEnableWr);
1563#ifdef IN_RING3
1564 if ( (u32 & SVGA_REG_ENABLE_ENABLE)
1565 && pThis->svga.fEnabled == false)
1566 {
1567 /* Make a backup copy of the first 512kb in order to save font data etc. */
1568 /** @todo should probably swap here, rather than copy + zero */
1569 memcpy(pThis->svga.pbVgaFrameBufferR3, pThis->vram_ptrR3, VMSVGA_VGA_FB_BACKUP_SIZE);
1570 memset(pThis->vram_ptrR3, 0, VMSVGA_VGA_FB_BACKUP_SIZE);
1571 }
1572
1573 pThis->svga.fEnabled = u32;
1574 if (pThis->svga.fEnabled)
1575 {
1576 if ( pThis->svga.uWidth == VMSVGA_VAL_UNINITIALIZED
1577 && pThis->svga.uHeight == VMSVGA_VAL_UNINITIALIZED
1578 && pThis->svga.uBpp == VMSVGA_VAL_UNINITIALIZED)
1579 {
1580 /* Keep the current mode. */
1581 pThis->svga.uWidth = pThis->pDrv->cx;
1582 pThis->svga.uHeight = pThis->pDrv->cy;
1583 pThis->svga.uBpp = (pThis->pDrv->cBits + 7) & ~7;
1584 }
1585
1586 if ( pThis->svga.uWidth != VMSVGA_VAL_UNINITIALIZED
1587 && pThis->svga.uHeight != VMSVGA_VAL_UNINITIALIZED
1588 && pThis->svga.uBpp != VMSVGA_VAL_UNINITIALIZED)
1589 {
1590 ASMAtomicOrU32(&pThis->svga.u32ActionFlags, VMSVGA_ACTION_CHANGEMODE);
1591 }
1592# ifdef LOG_ENABLED
1593 uint32_t *pFIFO = pThis->svga.pFIFOR3;
1594 Log(("configured=%d busy=%d\n", pThis->svga.fConfigured, pFIFO[SVGA_FIFO_BUSY]));
1595 Log(("next %x stop %x\n", pFIFO[SVGA_FIFO_NEXT_CMD], pFIFO[SVGA_FIFO_STOP]));
1596# endif
1597
1598 /* Disable or enable dirty page tracking according to the current fTraces value. */
1599 vmsvgaSetTraces(pThis, !!pThis->svga.fTraces);
1600
1601 /* bird: Whatever this is was added to make screenshot work, ask sunlover should explain... */
1602 for (uint32_t idScreen = 0; idScreen < pThis->cMonitors; ++idScreen)
1603 pThis->pDrv->pfnVBVAEnable(pThis->pDrv, idScreen, NULL /*pHostFlags*/);
1604 }
1605 else
1606 {
1607 /* Restore the text mode backup. */
1608 memcpy(pThis->vram_ptrR3, pThis->svga.pbVgaFrameBufferR3, VMSVGA_VGA_FB_BACKUP_SIZE);
1609
1610 pThis->pDrv->pfnLFBModeChange(pThis->pDrv, false);
1611
1612 /* Enable dirty page tracking again when going into legacy mode. */
1613 vmsvgaSetTraces(pThis, true);
1614
1615 /* bird: Whatever this is was added to make screenshot work, ask sunlover should explain... */
1616 for (uint32_t idScreen = 0; idScreen < pThis->cMonitors; ++idScreen)
1617 pThis->pDrv->pfnVBVADisable(pThis->pDrv, idScreen);
1618
1619 /* Clear the pitch lock. */
1620 pThis->svga.u32PitchLock = 0;
1621 }
1622#else /* !IN_RING3 */
1623 rc = VINF_IOM_R3_IOPORT_WRITE;
1624#endif /* !IN_RING3 */
1625 break;
1626
1627 case SVGA_REG_WIDTH:
1628 STAM_REL_COUNTER_INC(&pThis->svga.StatRegWidthWr);
1629 if (pThis->svga.uWidth != u32)
1630 {
1631#if defined(IN_RING3) || defined(IN_RING0)
1632 pThis->svga.uWidth = u32;
1633 vmsvgaUpdatePitch(pThis);
1634 if (pThis->svga.fEnabled)
1635 {
1636 ASMAtomicOrU32(&pThis->svga.u32ActionFlags, VMSVGA_ACTION_CHANGEMODE);
1637 }
1638#else
1639 rc = VINF_IOM_R3_IOPORT_WRITE;
1640#endif
1641 }
1642 /* else: nop */
1643 break;
1644
1645 case SVGA_REG_HEIGHT:
1646 STAM_REL_COUNTER_INC(&pThis->svga.StatRegHeightWr);
1647 if (pThis->svga.uHeight != u32)
1648 {
1649 pThis->svga.uHeight = u32;
1650 if (pThis->svga.fEnabled)
1651 {
1652 ASMAtomicOrU32(&pThis->svga.u32ActionFlags, VMSVGA_ACTION_CHANGEMODE);
1653 }
1654 }
1655 /* else: nop */
1656 break;
1657
1658 case SVGA_REG_DEPTH:
1659 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDepthWr);
1660 /** @todo read-only?? */
1661 break;
1662
1663 case SVGA_REG_BITS_PER_PIXEL: /* Current bpp in the guest */
1664 STAM_REL_COUNTER_INC(&pThis->svga.StatRegBitsPerPixelWr);
1665 if (pThis->svga.uBpp != u32)
1666 {
1667#if defined(IN_RING3) || defined(IN_RING0)
1668 pThis->svga.uBpp = u32;
1669 vmsvgaUpdatePitch(pThis);
1670 if (pThis->svga.fEnabled)
1671 {
1672 ASMAtomicOrU32(&pThis->svga.u32ActionFlags, VMSVGA_ACTION_CHANGEMODE);
1673 }
1674#else
1675 rc = VINF_IOM_R3_IOPORT_WRITE;
1676#endif
1677 }
1678 /* else: nop */
1679 break;
1680
1681 case SVGA_REG_PSEUDOCOLOR:
1682 STAM_REL_COUNTER_INC(&pThis->svga.StatRegPseudoColorWr);
1683 break;
1684
1685 case SVGA_REG_CONFIG_DONE: /* Set when memory area configured */
1686#ifdef IN_RING3
1687 STAM_REL_COUNTER_INC(&pSVGAState->StatR3RegConfigDoneWr);
1688 pThis->svga.fConfigured = u32;
1689 /* Disabling the FIFO enables tracing (dirty page detection) by default. */
1690 if (!pThis->svga.fConfigured)
1691 {
1692 pThis->svga.fTraces = true;
1693 }
1694 vmsvgaSetTraces(pThis, !!pThis->svga.fTraces);
1695#else
1696 rc = VINF_IOM_R3_IOPORT_WRITE;
1697#endif
1698 break;
1699
1700 case SVGA_REG_SYNC: /* See "FIFO Synchronization Registers" */
1701 STAM_REL_COUNTER_INC(&pThis->svga.StatRegSyncWr);
1702 if ( pThis->svga.fEnabled
1703 && pThis->svga.fConfigured)
1704 {
1705#if defined(IN_RING3) || defined(IN_RING0)
1706 Log(("SVGA_REG_SYNC: SVGA_FIFO_BUSY=%d\n", pThis->svga.CTX_SUFF(pFIFO)[SVGA_FIFO_BUSY]));
1707 ASMAtomicWriteU32(&pThis->svga.fBusy, VMSVGA_BUSY_F_EMT_FORCE | VMSVGA_BUSY_F_FIFO);
1708 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_BUSY, pThis->svga.CTX_SUFF(pFIFO)[SVGA_FIFO_MIN]))
1709 vmsvgaSafeFifoBusyRegUpdate(pThis, true);
1710
1711 /* Kick the FIFO thread to start processing commands again. */
1712 SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
1713#else
1714 rc = VINF_IOM_R3_IOPORT_WRITE;
1715#endif
1716 }
1717 /* else nothing to do. */
1718 else
1719 Log(("Sync ignored enabled=%d configured=%d\n", pThis->svga.fEnabled, pThis->svga.fConfigured));
1720
1721 break;
1722
1723 case SVGA_REG_BUSY: /* See "FIFO Synchronization Registers" (read-only) */
1724 STAM_REL_COUNTER_INC(&pThis->svga.StatRegBusyWr);
1725 break;
1726
1727 case SVGA_REG_GUEST_ID: /* Set guest OS identifier */
1728 STAM_REL_COUNTER_INC(&pThis->svga.StatRegGuestIdWr);
1729 pThis->svga.u32GuestId = u32;
1730 break;
1731
1732 case SVGA_REG_PITCHLOCK: /* Fixed pitch for all modes */
1733 STAM_REL_COUNTER_INC(&pThis->svga.StatRegPitchLockWr);
1734 pThis->svga.u32PitchLock = u32;
1735 /* Should this also update the FIFO pitch lock? Unclear. */
1736 break;
1737
1738 case SVGA_REG_IRQMASK: /* Interrupt mask */
1739 STAM_REL_COUNTER_INC(&pThis->svga.StatRegIrqMaskWr);
1740 pThis->svga.u32IrqMask = u32;
1741
1742 /* Irq pending after the above change? */
1743 if (pThis->svga.u32IrqStatus & u32)
1744 {
1745 Log(("SVGA_REG_IRQMASK: Trigger interrupt with status %x\n", pThis->svga.u32IrqStatus));
1746 PDMDevHlpPCISetIrqNoWait(pThis->CTX_SUFF(pDevIns), 0, 1);
1747 }
1748 else
1749 PDMDevHlpPCISetIrqNoWait(pThis->CTX_SUFF(pDevIns), 0, 0);
1750 break;
1751
1752 /* Mouse cursor support */
1753 case SVGA_REG_CURSOR_ID:
1754 case SVGA_REG_CURSOR_X:
1755 case SVGA_REG_CURSOR_Y:
1756 case SVGA_REG_CURSOR_ON:
1757 STAM_REL_COUNTER_INC(&pThis->svga.StatRegCursorXxxxWr);
1758 break;
1759
1760 /* Legacy multi-monitor support */
1761 case SVGA_REG_NUM_GUEST_DISPLAYS:/* Number of guest displays in X/Y direction */
1762 STAM_REL_COUNTER_INC(&pThis->svga.StatRegNumGuestDisplaysWr);
1763 break;
1764 case SVGA_REG_DISPLAY_ID: /* Display ID for the following display attributes */
1765 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayIdWr);
1766 break;
1767 case SVGA_REG_DISPLAY_IS_PRIMARY:/* Whether this is a primary display */
1768 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayIsPrimaryWr);
1769 break;
1770 case SVGA_REG_DISPLAY_POSITION_X:/* The display position x */
1771 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayPositionXWr);
1772 break;
1773 case SVGA_REG_DISPLAY_POSITION_Y:/* The display position y */
1774 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayPositionYWr);
1775 break;
1776 case SVGA_REG_DISPLAY_WIDTH: /* The display's width */
1777 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayWidthWr);
1778 break;
1779 case SVGA_REG_DISPLAY_HEIGHT: /* The display's height */
1780 STAM_REL_COUNTER_INC(&pThis->svga.StatRegDisplayHeightWr);
1781 break;
1782#ifdef VBOX_WITH_VMSVGA3D
1783 /* See "Guest memory regions" below. */
1784 case SVGA_REG_GMR_ID:
1785 STAM_REL_COUNTER_INC(&pThis->svga.StatRegGmrIdWr);
1786 pThis->svga.u32CurrentGMRId = u32;
1787 break;
1788
1789 case SVGA_REG_GMR_DESCRIPTOR:
1790# ifndef IN_RING3
1791 rc = VINF_IOM_R3_IOPORT_WRITE;
1792 break;
1793# else /* IN_RING3 */
1794 {
1795 STAM_REL_COUNTER_INC(&pSVGAState->StatR3RegGmrDescriptorWr);
1796
1797 /* Validate current GMR id. */
1798 uint32_t idGMR = pThis->svga.u32CurrentGMRId;
1799 AssertBreak(idGMR < pThis->svga.cGMR);
1800 RT_UNTRUSTED_VALIDATED_FENCE();
1801
1802 /* Free the old GMR if present. */
1803 vmsvgaGMRFree(pThis, idGMR);
1804
1805 /* Just undefine the GMR? */
1806 RTGCPHYS GCPhys = (RTGCPHYS)u32 << PAGE_SHIFT;
1807 if (GCPhys == 0)
1808 {
1809 STAM_REL_COUNTER_INC(&pSVGAState->StatR3RegGmrDescriptorWrFree);
1810 break;
1811 }
1812
1813
1814 /* Never cross a page boundary automatically. */
1815 const uint32_t cMaxPages = RT_MIN(VMSVGA_MAX_GMR_PAGES, UINT32_MAX / X86_PAGE_SIZE);
1816 uint32_t cPagesTotal = 0;
1817 uint32_t iDesc = 0;
1818 PVMSVGAGMRDESCRIPTOR paDescs = NULL;
1819 uint32_t cLoops = 0;
1820 RTGCPHYS GCPhysBase = GCPhys;
1821 while (PHYS_PAGE_ADDRESS(GCPhys) == PHYS_PAGE_ADDRESS(GCPhysBase))
1822 {
1823 /* Read descriptor. */
1824 SVGAGuestMemDescriptor desc;
1825 rc = PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCPhys, &desc, sizeof(desc));
1826 AssertRCBreak(rc);
1827
1828 if (desc.numPages != 0)
1829 {
1830 AssertBreakStmt(desc.numPages <= cMaxPages, rc = VERR_OUT_OF_RANGE);
1831 cPagesTotal += desc.numPages;
1832 AssertBreakStmt(cPagesTotal <= cMaxPages, rc = VERR_OUT_OF_RANGE);
1833
1834 if ((iDesc & 15) == 0)
1835 {
1836 void *pvNew = RTMemRealloc(paDescs, (iDesc + 16) * sizeof(VMSVGAGMRDESCRIPTOR));
1837 AssertBreakStmt(pvNew, rc = VERR_NO_MEMORY);
1838 paDescs = (PVMSVGAGMRDESCRIPTOR)pvNew;
1839 }
1840
1841 paDescs[iDesc].GCPhys = (RTGCPHYS)desc.ppn << PAGE_SHIFT;
1842 paDescs[iDesc++].numPages = desc.numPages;
1843
1844 /* Continue with the next descriptor. */
1845 GCPhys += sizeof(desc);
1846 }
1847 else if (desc.ppn == 0)
1848 break; /* terminator */
1849 else /* Pointer to the next physical page of descriptors. */
1850 GCPhys = GCPhysBase = (RTGCPHYS)desc.ppn << PAGE_SHIFT;
1851
1852 cLoops++;
1853 AssertBreakStmt(cLoops < VMSVGA_MAX_GMR_DESC_LOOP_COUNT, rc = VERR_OUT_OF_RANGE);
1854 }
1855
1856 AssertStmt(iDesc > 0 || RT_FAILURE_NP(rc), rc = VERR_OUT_OF_RANGE);
1857 if (RT_SUCCESS(rc))
1858 {
1859 /* Commit the GMR. */
1860 pSVGAState->paGMR[idGMR].paDesc = paDescs;
1861 pSVGAState->paGMR[idGMR].numDescriptors = iDesc;
1862 pSVGAState->paGMR[idGMR].cMaxPages = cPagesTotal;
1863 pSVGAState->paGMR[idGMR].cbTotal = cPagesTotal * PAGE_SIZE;
1864 Assert((pSVGAState->paGMR[idGMR].cbTotal >> PAGE_SHIFT) == cPagesTotal);
1865 Log(("Defined new gmr %x numDescriptors=%d cbTotal=%x (%#x pages)\n",
1866 idGMR, iDesc, pSVGAState->paGMR[idGMR].cbTotal, cPagesTotal));
1867 }
1868 else
1869 {
1870 RTMemFree(paDescs);
1871 STAM_REL_COUNTER_INC(&pSVGAState->StatR3RegGmrDescriptorWrErrors);
1872 }
1873 break;
1874 }
1875# endif /* IN_RING3 */
1876#endif // VBOX_WITH_VMSVGA3D
1877
1878 case SVGA_REG_TRACES: /* Enable trace-based updates even when FIFO is on */
1879 STAM_REL_COUNTER_INC(&pThis->svga.StatRegTracesWr);
1880 if (pThis->svga.fTraces == u32)
1881 break; /* nothing to do */
1882
1883#ifdef IN_RING3
1884 vmsvgaSetTraces(pThis, !!u32);
1885#else
1886 rc = VINF_IOM_R3_IOPORT_WRITE;
1887#endif
1888 break;
1889
1890 case SVGA_REG_TOP: /* Must be 1 more than the last register */
1891 STAM_REL_COUNTER_INC(&pThis->svga.StatRegTopWr);
1892 break;
1893
1894 case SVGA_REG_NUM_DISPLAYS: /* (Deprecated) */
1895 STAM_REL_COUNTER_INC(&pThis->svga.StatRegNumDisplaysWr);
1896 Log(("Write to deprecated register %x - val %x ignored\n", idxReg, u32));
1897 break;
1898
1899 case SVGA_REG_FB_START:
1900 case SVGA_REG_MEM_START:
1901 case SVGA_REG_HOST_BITS_PER_PIXEL:
1902 case SVGA_REG_MAX_WIDTH:
1903 case SVGA_REG_MAX_HEIGHT:
1904 case SVGA_REG_VRAM_SIZE:
1905 case SVGA_REG_FB_SIZE:
1906 case SVGA_REG_CAPABILITIES:
1907 case SVGA_REG_MEM_SIZE:
1908 case SVGA_REG_SCRATCH_SIZE: /* Number of scratch registers */
1909 case SVGA_REG_MEM_REGS: /* Number of FIFO registers */
1910 case SVGA_REG_BYTES_PER_LINE:
1911 case SVGA_REG_FB_OFFSET:
1912 case SVGA_REG_RED_MASK:
1913 case SVGA_REG_GREEN_MASK:
1914 case SVGA_REG_BLUE_MASK:
1915 case SVGA_REG_GMRS_MAX_PAGES: /* Maximum number of 4KB pages for all GMRs */
1916 case SVGA_REG_MEMORY_SIZE: /* Total dedicated device memory excluding FIFO */
1917 case SVGA_REG_GMR_MAX_IDS:
1918 case SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH:
1919 /* Read only - ignore. */
1920 Log(("Write to R/O register %x - val %x ignored\n", idxReg, u32));
1921 STAM_REL_COUNTER_INC(&pThis->svga.StatRegReadOnlyWr);
1922 break;
1923
1924 default:
1925 {
1926 uint32_t offReg;
1927 if ((offReg = idxReg - SVGA_SCRATCH_BASE) < pThis->svga.cScratchRegion)
1928 {
1929 RT_UNTRUSTED_VALIDATED_FENCE();
1930 pThis->svga.au32ScratchRegion[offReg] = u32;
1931 STAM_REL_COUNTER_INC(&pThis->svga.StatRegScratchWr);
1932 }
1933 else if ((offReg = idxReg - SVGA_PALETTE_BASE) < (uint32_t)SVGA_NUM_PALETTE_REGS)
1934 {
1935 /* Note! Using last_palette rather than palette here to preserve the VGA one.
1936 Btw, see rgb_to_pixel32. */
1937 STAM_REL_COUNTER_INC(&pThis->svga.StatRegPaletteWr);
1938 u32 &= 0xff;
1939 RT_UNTRUSTED_VALIDATED_FENCE();
1940 uint32_t uRgb = pThis->last_palette[offReg / 3];
1941 switch (offReg % 3)
1942 {
1943 case 0: uRgb = (uRgb & UINT32_C(0x0000ffff)) | (u32 << 16); break; /* red */
1944 case 1: uRgb = (uRgb & UINT32_C(0x00ff00ff)) | (u32 << 8); break; /* green */
1945 case 2: uRgb = (uRgb & UINT32_C(0x00ffff00)) | u32 ; break; /* blue */
1946 }
1947 pThis->last_palette[offReg / 3] = uRgb;
1948 }
1949 else
1950 {
1951#if !defined(IN_RING3) && defined(VBOX_STRICT)
1952 rc = VINF_IOM_R3_IOPORT_WRITE;
1953#else
1954 STAM_REL_COUNTER_INC(&pThis->svga.StatRegUnknownWr);
1955 AssertMsgFailed(("reg=%#x u32=%#x\n", idxReg, u32));
1956#endif
1957 }
1958 break;
1959 }
1960 }
1961 return rc;
1962}
1963
1964/**
1965 * Port I/O Handler for IN operations.
1966 *
1967 * @returns VINF_SUCCESS or VINF_EM_*.
1968 * @returns VERR_IOM_IOPORT_UNUSED if the port is really unused and a ~0 value should be returned.
1969 *
1970 * @param pDevIns The device instance.
1971 * @param pvUser User argument.
1972 * @param uPort Port number used for the IN operation.
1973 * @param pu32 Where to store the result. This is always a 32-bit
1974 * variable regardless of what @a cb might say.
1975 * @param cb Number of bytes read.
1976 */
1977PDMBOTHCBDECL(int) vmsvgaIORead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t *pu32, unsigned cb)
1978{
1979 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
1980 RT_NOREF_PV(pvUser);
1981
1982 /* Ignore non-dword accesses. */
1983 if (cb != 4)
1984 {
1985 Log(("Ignoring non-dword read at %x cb=%d\n", uPort, cb));
1986 *pu32 = UINT32_MAX;
1987 return VINF_SUCCESS;
1988 }
1989
1990 switch (uPort - pThis->svga.BasePort)
1991 {
1992 case SVGA_INDEX_PORT:
1993 *pu32 = pThis->svga.u32IndexReg;
1994 break;
1995
1996 case SVGA_VALUE_PORT:
1997 return vmsvgaReadPort(pThis, pu32);
1998
1999 case SVGA_BIOS_PORT:
2000 Log(("Ignoring BIOS port read\n"));
2001 *pu32 = 0;
2002 break;
2003
2004 case SVGA_IRQSTATUS_PORT:
2005 LogFlow(("vmsvgaIORead: SVGA_IRQSTATUS_PORT %x\n", pThis->svga.u32IrqStatus));
2006 *pu32 = pThis->svga.u32IrqStatus;
2007 break;
2008
2009 default:
2010 ASSERT_GUEST_MSG_FAILED(("vmsvgaIORead: Unknown register %u (%#x) was read from.\n", uPort - pThis->svga.BasePort, uPort));
2011 *pu32 = UINT32_MAX;
2012 break;
2013 }
2014
2015 return VINF_SUCCESS;
2016}
2017
2018/**
2019 * Port I/O Handler for OUT operations.
2020 *
2021 * @returns VINF_SUCCESS or VINF_EM_*.
2022 *
2023 * @param pDevIns The device instance.
2024 * @param pvUser User argument.
2025 * @param uPort Port number used for the OUT operation.
2026 * @param u32 The value to output.
2027 * @param cb The value size in bytes.
2028 */
2029PDMBOTHCBDECL(int) vmsvgaIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t u32, unsigned cb)
2030{
2031 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
2032 RT_NOREF_PV(pvUser);
2033
2034 /* Ignore non-dword accesses. */
2035 if (cb != 4)
2036 {
2037 Log(("Ignoring non-dword write at %x val=%x cb=%d\n", uPort, u32, cb));
2038 return VINF_SUCCESS;
2039 }
2040
2041 switch (uPort - pThis->svga.BasePort)
2042 {
2043 case SVGA_INDEX_PORT:
2044 pThis->svga.u32IndexReg = u32;
2045 break;
2046
2047 case SVGA_VALUE_PORT:
2048 return vmsvgaWritePort(pThis, u32);
2049
2050 case SVGA_BIOS_PORT:
2051 Log(("Ignoring BIOS port write (val=%x)\n", u32));
2052 break;
2053
2054 case SVGA_IRQSTATUS_PORT:
2055 Log(("vmsvgaIOWrite SVGA_IRQSTATUS_PORT %x: status %x -> %x\n", u32, pThis->svga.u32IrqStatus, pThis->svga.u32IrqStatus & ~u32));
2056 ASMAtomicAndU32(&pThis->svga.u32IrqStatus, ~u32);
2057 /* Clear the irq in case all events have been cleared. */
2058 if (!(pThis->svga.u32IrqStatus & pThis->svga.u32IrqMask))
2059 {
2060 Log(("vmsvgaIOWrite SVGA_IRQSTATUS_PORT: clearing IRQ\n"));
2061 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
2062 }
2063 break;
2064
2065 default:
2066 ASSERT_GUEST_MSG_FAILED(("vmsvgaIOWrite: Unknown register %u (%#x) was written to, value %#x LB %u.\n",
2067 uPort - pThis->svga.BasePort, uPort, u32, cb));
2068 break;
2069 }
2070 return VINF_SUCCESS;
2071}
2072
2073#ifdef IN_RING3
2074
2075# ifdef DEBUG_FIFO_ACCESS
2076/**
2077 * Handle FIFO memory access.
2078 * @returns VBox status code.
2079 * @param pVM VM handle.
2080 * @param pThis VGA device instance data.
2081 * @param GCPhys The access physical address.
2082 * @param fWriteAccess Read or write access
2083 */
2084static int vmsvgaDebugFIFOAccess(PVM pVM, PVGASTATE pThis, RTGCPHYS GCPhys, bool fWriteAccess)
2085{
2086 RT_NOREF(pVM);
2087 RTGCPHYS GCPhysOffset = GCPhys - pThis->svga.GCPhysFIFO;
2088 uint32_t *pFIFO = pThis->svga.pFIFOR3;
2089
2090 switch (GCPhysOffset >> 2)
2091 {
2092 case SVGA_FIFO_MIN:
2093 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_MIN = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2094 break;
2095 case SVGA_FIFO_MAX:
2096 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_MAX = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2097 break;
2098 case SVGA_FIFO_NEXT_CMD:
2099 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_NEXT_CMD = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2100 break;
2101 case SVGA_FIFO_STOP:
2102 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_STOP = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2103 break;
2104 case SVGA_FIFO_CAPABILITIES:
2105 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CAPABILITIES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2106 break;
2107 case SVGA_FIFO_FLAGS:
2108 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_FLAGS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2109 break;
2110 case SVGA_FIFO_FENCE:
2111 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_FENCE = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2112 break;
2113 case SVGA_FIFO_3D_HWVERSION:
2114 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_HWVERSION = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2115 break;
2116 case SVGA_FIFO_PITCHLOCK:
2117 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_PITCHLOCK = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2118 break;
2119 case SVGA_FIFO_CURSOR_ON:
2120 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_ON = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2121 break;
2122 case SVGA_FIFO_CURSOR_X:
2123 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_X = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2124 break;
2125 case SVGA_FIFO_CURSOR_Y:
2126 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_Y = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2127 break;
2128 case SVGA_FIFO_CURSOR_COUNT:
2129 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_COUNT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2130 break;
2131 case SVGA_FIFO_CURSOR_LAST_UPDATED:
2132 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_LAST_UPDATED = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2133 break;
2134 case SVGA_FIFO_RESERVED:
2135 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_RESERVED = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2136 break;
2137 case SVGA_FIFO_CURSOR_SCREEN_ID:
2138 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_SCREEN_ID = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2139 break;
2140 case SVGA_FIFO_DEAD:
2141 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_DEAD = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2142 break;
2143 case SVGA_FIFO_3D_HWVERSION_REVISED:
2144 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_HWVERSION_REVISED = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2145 break;
2146 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_3D:
2147 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_3D = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2148 break;
2149 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_LIGHTS:
2150 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_LIGHTS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2151 break;
2152 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURES:
2153 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2154 break;
2155 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_CLIP_PLANES:
2156 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_CLIP_PLANES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2157 break;
2158 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_VERTEX_SHADER_VERSION:
2159 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_VERTEX_SHADER_VERSION = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2160 break;
2161 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_VERTEX_SHADER:
2162 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_VERTEX_SHADER = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2163 break;
2164 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION:
2165 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2166 break;
2167 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_FRAGMENT_SHADER:
2168 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_FRAGMENT_SHADER = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2169 break;
2170 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_RENDER_TARGETS:
2171 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_RENDER_TARGETS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2172 break;
2173 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_S23E8_TEXTURES:
2174 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_S23E8_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2175 break;
2176 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_S10E5_TEXTURES:
2177 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_S10E5_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2178 break;
2179 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND:
2180 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2181 break;
2182 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_D16_BUFFER_FORMAT:
2183 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_D16_BUFFER_FORMAT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2184 break;
2185 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT:
2186 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2187 break;
2188 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT:
2189 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2190 break;
2191 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_QUERY_TYPES:
2192 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_QUERY_TYPES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2193 break;
2194 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING:
2195 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2196 break;
2197 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_POINT_SIZE:
2198 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_POINT_SIZE = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2199 break;
2200 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_SHADER_TEXTURES:
2201 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_SHADER_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2202 break;
2203 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH:
2204 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2205 break;
2206 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT:
2207 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2208 break;
2209 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VOLUME_EXTENT:
2210 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_VOLUME_EXTENT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2211 break;
2212 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT:
2213 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2214 break;
2215 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO:
2216 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2217 break;
2218 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY:
2219 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2220 break;
2221 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT:
2222 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2223 break;
2224 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VERTEX_INDEX:
2225 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_VERTEX_INDEX = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2226 break;
2227 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS:
2228 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2229 break;
2230 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS:
2231 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2232 break;
2233 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS:
2234 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2235 break;
2236 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS:
2237 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2238 break;
2239 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_TEXTURE_OPS:
2240 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_TEXTURE_OPS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2241 break;
2242 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8:
2243 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2244 break;
2245 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8:
2246 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2247 break;
2248 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10:
2249 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2250 break;
2251 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5:
2252 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2253 break;
2254 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5:
2255 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2256 break;
2257 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4:
2258 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2259 break;
2260 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_R5G6B5:
2261 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_R5G6B5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2262 break;
2263 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16:
2264 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2265 break;
2266 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8:
2267 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2268 break;
2269 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_ALPHA8:
2270 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_ALPHA8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2271 break;
2272 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8:
2273 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2274 break;
2275 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_D16:
2276 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_D16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2277 break;
2278 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8:
2279 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2280 break;
2281 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8:
2282 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2283 break;
2284 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT1:
2285 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT1 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2286 break;
2287 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT2:
2288 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT2 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2289 break;
2290 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT3:
2291 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT3 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2292 break;
2293 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT4:
2294 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT4 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2295 break;
2296 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT5:
2297 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2298 break;
2299 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8:
2300 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2301 break;
2302 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10:
2303 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2304 break;
2305 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8:
2306 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2307 break;
2308 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8:
2309 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2310 break;
2311 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_CxV8U8:
2312 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_CxV8U8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2313 break;
2314 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_R_S10E5:
2315 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_R_S10E5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2316 break;
2317 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_R_S23E8:
2318 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_R_S23E8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2319 break;
2320 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5:
2321 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2322 break;
2323 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8:
2324 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2325 break;
2326 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5:
2327 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2328 break;
2329 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8:
2330 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2331 break;
2332 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES:
2333 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2334 break;
2335 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS:
2336 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2337 break;
2338 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_V16U16:
2339 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_V16U16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2340 break;
2341 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_G16R16:
2342 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_G16R16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2343 break;
2344 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16:
2345 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2346 break;
2347 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_UYVY:
2348 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_UYVY = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2349 break;
2350 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_YUY2:
2351 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_YUY2 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2352 break;
2353 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES:
2354 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2355 break;
2356 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES:
2357 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2358 break;
2359 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_ALPHATOCOVERAGE:
2360 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_ALPHATOCOVERAGE = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2361 break;
2362 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SUPERSAMPLE:
2363 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SUPERSAMPLE = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2364 break;
2365 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_AUTOGENMIPMAPS:
2366 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_AUTOGENMIPMAPS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2367 break;
2368 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_NV12:
2369 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_NV12 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2370 break;
2371 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_AYUV:
2372 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_AYUV = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2373 break;
2374 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_CONTEXT_IDS:
2375 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_CONTEXT_IDS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2376 break;
2377 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_SURFACE_IDS:
2378 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_SURFACE_IDS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2379 break;
2380 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_DF16:
2381 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_DF16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2382 break;
2383 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_DF24:
2384 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_DF24 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2385 break;
2386 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT:
2387 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2388 break;
2389 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM:
2390 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2391 break;
2392 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM:
2393 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2394 break;
2395 case SVGA_FIFO_3D_CAPS_LAST:
2396 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS_LAST = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2397 break;
2398 case SVGA_FIFO_GUEST_3D_HWVERSION:
2399 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_GUEST_3D_HWVERSION = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2400 break;
2401 case SVGA_FIFO_FENCE_GOAL:
2402 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_FENCE_GOAL = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2403 break;
2404 case SVGA_FIFO_BUSY:
2405 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_BUSY = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
2406 break;
2407 default:
2408 Log(("vmsvgaFIFOAccess [0x%x]: %s access at offset %x = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", GCPhysOffset, pFIFO[GCPhysOffset >> 2]));
2409 break;
2410 }
2411
2412 return VINF_EM_RAW_EMULATE_INSTR;
2413}
2414# endif /* DEBUG_FIFO_ACCESS */
2415
2416# if defined(VMSVGA_USE_FIFO_ACCESS_HANDLER) || defined(DEBUG_FIFO_ACCESS)
2417/**
2418 * HC access handler for the FIFO.
2419 *
2420 * @returns VINF_SUCCESS if the handler have carried out the operation.
2421 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
2422 * @param pVM VM Handle.
2423 * @param pVCpu The cross context CPU structure for the calling EMT.
2424 * @param GCPhys The physical address the guest is writing to.
2425 * @param pvPhys The HC mapping of that address.
2426 * @param pvBuf What the guest is reading/writing.
2427 * @param cbBuf How much it's reading/writing.
2428 * @param enmAccessType The access type.
2429 * @param enmOrigin Who is making the access.
2430 * @param pvUser User argument.
2431 */
2432static DECLCALLBACK(VBOXSTRICTRC)
2433vmsvgaR3FIFOAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
2434 PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser)
2435{
2436 NOREF(pVCpu); NOREF(pvPhys); NOREF(pvBuf); NOREF(cbBuf); NOREF(enmOrigin); NOREF(enmAccessType); NOREF(GCPhys);
2437 PVGASTATE pThis = (PVGASTATE)pvUser;
2438 AssertPtr(pThis);
2439
2440# ifdef VMSVGA_USE_FIFO_ACCESS_HANDLER
2441 /*
2442 * Wake up the FIFO thread as it might have work to do now.
2443 */
2444 int rc = SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
2445 AssertLogRelRC(rc);
2446# endif
2447
2448# ifdef DEBUG_FIFO_ACCESS
2449 /*
2450 * When in debug-fifo-access mode, we do not disable the access handler,
2451 * but leave it on as we wish to catch all access.
2452 */
2453 Assert(GCPhys >= pThis->svga.GCPhysFIFO);
2454 rc = vmsvgaDebugFIFOAccess(pVM, pThis, GCPhys, enmAccessType == PGMACCESSTYPE_WRITE);
2455# elif defined(VMSVGA_USE_FIFO_ACCESS_HANDLER)
2456 /*
2457 * Temporarily disable the access handler now that we've kicked the FIFO thread.
2458 */
2459 STAM_REL_COUNTER_INC(&pThis->svga.pSvgaR3State->StatFifoAccessHandler);
2460 rc = PGMHandlerPhysicalPageTempOff(pVM, pThis->svga.GCPhysFIFO, pThis->svga.GCPhysFIFO);
2461# endif
2462 if (RT_SUCCESS(rc))
2463 return VINF_PGM_HANDLER_DO_DEFAULT;
2464 AssertMsg(rc <= VINF_SUCCESS, ("rc=%Rrc\n", rc));
2465 return rc;
2466}
2467# endif /* VMSVGA_USE_FIFO_ACCESS_HANDLER || DEBUG_FIFO_ACCESS */
2468
2469#endif /* IN_RING3 */
2470
2471#ifdef DEBUG_GMR_ACCESS
2472# ifdef IN_RING3
2473
2474/**
2475 * HC access handler for the FIFO.
2476 *
2477 * @returns VINF_SUCCESS if the handler have carried out the operation.
2478 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
2479 * @param pVM VM Handle.
2480 * @param pVCpu The cross context CPU structure for the calling EMT.
2481 * @param GCPhys The physical address the guest is writing to.
2482 * @param pvPhys The HC mapping of that address.
2483 * @param pvBuf What the guest is reading/writing.
2484 * @param cbBuf How much it's reading/writing.
2485 * @param enmAccessType The access type.
2486 * @param enmOrigin Who is making the access.
2487 * @param pvUser User argument.
2488 */
2489static DECLCALLBACK(VBOXSTRICTRC)
2490vmsvgaR3GMRAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
2491 PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser)
2492{
2493 PVGASTATE pThis = (PVGASTATE)pvUser;
2494 Assert(pThis);
2495 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
2496 NOREF(pVCpu); NOREF(pvPhys); NOREF(pvBuf); NOREF(cbBuf); NOREF(enmAccessType); NOREF(enmOrigin);
2497
2498 Log(("vmsvgaR3GMRAccessHandler: GMR access to page %RGp\n", GCPhys));
2499
2500 for (uint32_t i = 0; i < pThis->svga.cGMR; ++i)
2501 {
2502 PGMR pGMR = &pSVGAState->paGMR[i];
2503
2504 if (pGMR->numDescriptors)
2505 {
2506 for (uint32_t j = 0; j < pGMR->numDescriptors; j++)
2507 {
2508 if ( GCPhys >= pGMR->paDesc[j].GCPhys
2509 && GCPhys < pGMR->paDesc[j].GCPhys + pGMR->paDesc[j].numPages * PAGE_SIZE)
2510 {
2511 /*
2512 * Turn off the write handler for this particular page and make it R/W.
2513 * Then return telling the caller to restart the guest instruction.
2514 */
2515 int rc = PGMHandlerPhysicalPageTempOff(pVM, pGMR->paDesc[j].GCPhys, GCPhys);
2516 AssertRC(rc);
2517 goto end;
2518 }
2519 }
2520 }
2521 }
2522end:
2523 return VINF_PGM_HANDLER_DO_DEFAULT;
2524}
2525
2526/* Callback handler for VMR3ReqCallWaitU */
2527static DECLCALLBACK(int) vmsvgaRegisterGMR(PPDMDEVINS pDevIns, uint32_t gmrId)
2528{
2529 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
2530 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
2531 PGMR pGMR = &pSVGAState->paGMR[gmrId];
2532 int rc;
2533
2534 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
2535 {
2536 rc = PGMHandlerPhysicalRegister(PDMDevHlpGetVM(pThis->pDevInsR3),
2537 pGMR->paDesc[i].GCPhys, pGMR->paDesc[i].GCPhys + pGMR->paDesc[i].numPages * PAGE_SIZE - 1,
2538 pThis->svga.hGmrAccessHandlerType, pThis, NIL_RTR0PTR, NIL_RTRCPTR, "VMSVGA GMR");
2539 AssertRC(rc);
2540 }
2541 return VINF_SUCCESS;
2542}
2543
2544/* Callback handler for VMR3ReqCallWaitU */
2545static DECLCALLBACK(int) vmsvgaDeregisterGMR(PPDMDEVINS pDevIns, uint32_t gmrId)
2546{
2547 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
2548 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
2549 PGMR pGMR = &pSVGAState->paGMR[gmrId];
2550
2551 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
2552 {
2553 int rc = PGMHandlerPhysicalDeregister(PDMDevHlpGetVM(pThis->pDevInsR3), pGMR->paDesc[i].GCPhys);
2554 AssertRC(rc);
2555 }
2556 return VINF_SUCCESS;
2557}
2558
2559/* Callback handler for VMR3ReqCallWaitU */
2560static DECLCALLBACK(int) vmsvgaResetGMRHandlers(PVGASTATE pThis)
2561{
2562 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
2563
2564 for (uint32_t i = 0; i < pThis->svga.cGMR; ++i)
2565 {
2566 PGMR pGMR = &pSVGAState->paGMR[i];
2567
2568 if (pGMR->numDescriptors)
2569 {
2570 for (uint32_t j = 0; j < pGMR->numDescriptors; j++)
2571 {
2572 int rc = PGMHandlerPhysicalReset(PDMDevHlpGetVM(pThis->pDevInsR3), pGMR->paDesc[j].GCPhys);
2573 AssertRC(rc);
2574 }
2575 }
2576 }
2577 return VINF_SUCCESS;
2578}
2579
2580# endif /* IN_RING3 */
2581#endif /* DEBUG_GMR_ACCESS */
2582
2583/* -=-=-=-=-=- Ring 3 -=-=-=-=-=- */
2584
2585#ifdef IN_RING3
2586
2587
2588/**
2589 * Common worker for changing the pointer shape.
2590 *
2591 * @param pThis The VGA instance data.
2592 * @param pSVGAState The VMSVGA ring-3 instance data.
2593 * @param fAlpha Whether there is alpha or not.
2594 * @param xHot Hotspot x coordinate.
2595 * @param yHot Hotspot y coordinate.
2596 * @param cx Width.
2597 * @param cy Height.
2598 * @param pbData Heap copy of the cursor data. Consumed.
2599 * @param cbData The size of the data.
2600 */
2601static void vmsvgaR3InstallNewCursor(PVGASTATE pThis, PVMSVGAR3STATE pSVGAState, bool fAlpha,
2602 uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, uint8_t *pbData, uint32_t cbData)
2603{
2604 Log(("vmsvgaR3InstallNewCursor: cx=%d cy=%d xHot=%d yHot=%d fAlpha=%d cbData=%#x\n", cx, cy, xHot, yHot, fAlpha, cbData));
2605#ifdef LOG_ENABLED
2606 if (LogIs2Enabled())
2607 {
2608 uint32_t cbAndLine = RT_ALIGN(cx, 8) / 8;
2609 if (!fAlpha)
2610 {
2611 Log2(("VMSVGA Cursor AND mask (%d,%d):\n", cx, cy));
2612 for (uint32_t y = 0; y < cy; y++)
2613 {
2614 Log2(("%3u:", y));
2615 uint8_t const *pbLine = &pbData[y * cbAndLine];
2616 for (uint32_t x = 0; x < cx; x += 8)
2617 {
2618 uint8_t b = pbLine[x / 8];
2619 char szByte[12];
2620 szByte[0] = b & 0x80 ? '*' : ' '; /* most significant bit first */
2621 szByte[1] = b & 0x40 ? '*' : ' ';
2622 szByte[2] = b & 0x20 ? '*' : ' ';
2623 szByte[3] = b & 0x10 ? '*' : ' ';
2624 szByte[4] = b & 0x08 ? '*' : ' ';
2625 szByte[5] = b & 0x04 ? '*' : ' ';
2626 szByte[6] = b & 0x02 ? '*' : ' ';
2627 szByte[7] = b & 0x01 ? '*' : ' ';
2628 szByte[8] = '\0';
2629 Log2(("%s", szByte));
2630 }
2631 Log2(("\n"));
2632 }
2633 }
2634
2635 Log2(("VMSVGA Cursor XOR mask (%d,%d):\n", cx, cy));
2636 uint32_t const *pu32Xor = (uint32_t const *)&pbData[RT_ALIGN_32(cbAndLine * cy, 4)];
2637 for (uint32_t y = 0; y < cy; y++)
2638 {
2639 Log2(("%3u:", y));
2640 uint32_t const *pu32Line = &pu32Xor[y * cx];
2641 for (uint32_t x = 0; x < cx; x++)
2642 Log2((" %08x", pu32Line[x]));
2643 Log2(("\n"));
2644 }
2645 }
2646#endif
2647
2648 int rc = pThis->pDrv->pfnVBVAMousePointerShape(pThis->pDrv, true /*fVisible*/, fAlpha, xHot, yHot, cx, cy, pbData);
2649 AssertRC(rc);
2650
2651 if (pSVGAState->Cursor.fActive)
2652 RTMemFree(pSVGAState->Cursor.pData);
2653
2654 pSVGAState->Cursor.fActive = true;
2655 pSVGAState->Cursor.xHotspot = xHot;
2656 pSVGAState->Cursor.yHotspot = yHot;
2657 pSVGAState->Cursor.width = cx;
2658 pSVGAState->Cursor.height = cy;
2659 pSVGAState->Cursor.cbData = cbData;
2660 pSVGAState->Cursor.pData = pbData;
2661}
2662
2663
2664/**
2665 * Handles the SVGA_CMD_DEFINE_CURSOR command.
2666 *
2667 * @param pThis The VGA instance data.
2668 * @param pSVGAState The VMSVGA ring-3 instance data.
2669 * @param pCursor The cursor.
2670 * @param pbSrcAndMask The AND mask.
2671 * @param cbSrcAndLine The scanline length of the AND mask.
2672 * @param pbSrcXorMask The XOR mask.
2673 * @param cbSrcXorLine The scanline length of the XOR mask.
2674 */
2675static void vmsvgaR3CmdDefineCursor(PVGASTATE pThis, PVMSVGAR3STATE pSVGAState, SVGAFifoCmdDefineCursor const *pCursor,
2676 uint8_t const *pbSrcAndMask, uint32_t cbSrcAndLine,
2677 uint8_t const *pbSrcXorMask, uint32_t cbSrcXorLine)
2678{
2679 uint32_t const cx = pCursor->width;
2680 uint32_t const cy = pCursor->height;
2681
2682 /*
2683 * Convert the input to 1-bit AND mask and a 32-bit BRGA XOR mask.
2684 * The AND data uses 8-bit aligned scanlines.
2685 * The XOR data must be starting on a 32-bit boundrary.
2686 */
2687 uint32_t cbDstAndLine = RT_ALIGN_32(cx, 8) / 8;
2688 uint32_t cbDstAndMask = cbDstAndLine * cy;
2689 uint32_t cbDstXorMask = cx * sizeof(uint32_t) * cy;
2690 uint32_t cbCopy = RT_ALIGN_32(cbDstAndMask, 4) + cbDstXorMask;
2691
2692 uint8_t *pbCopy = (uint8_t *)RTMemAlloc(cbCopy);
2693 AssertReturnVoid(pbCopy);
2694
2695 /* Convert the AND mask. */
2696 uint8_t *pbDst = pbCopy;
2697 uint8_t const *pbSrc = pbSrcAndMask;
2698 switch (pCursor->andMaskDepth)
2699 {
2700 case 1:
2701 if (cbSrcAndLine == cbDstAndLine)
2702 memcpy(pbDst, pbSrc, cbSrcAndLine * cy);
2703 else
2704 {
2705 Assert(cbSrcAndLine > cbDstAndLine); /* lines are dword alined in source, but only byte in destination. */
2706 for (uint32_t y = 0; y < cy; y++)
2707 {
2708 memcpy(pbDst, pbSrc, cbDstAndLine);
2709 pbDst += cbDstAndLine;
2710 pbSrc += cbSrcAndLine;
2711 }
2712 }
2713 break;
2714 /* Should take the XOR mask into account for the multi-bit AND mask. */
2715 case 8:
2716 for (uint32_t y = 0; y < cy; y++)
2717 {
2718 for (uint32_t x = 0; x < cx; )
2719 {
2720 uint8_t bDst = 0;
2721 uint8_t fBit = 1;
2722 do
2723 {
2724 uintptr_t const idxPal = pbSrc[x] * 3;
2725 if ((( pThis->last_palette[idxPal]
2726 | (pThis->last_palette[idxPal] >> 8)
2727 | (pThis->last_palette[idxPal] >> 16)) & 0xff) > 0xfc)
2728 bDst |= fBit;
2729 fBit <<= 1;
2730 x++;
2731 } while (x < cx && (x & 7));
2732 pbDst[(x - 1) / 8] = bDst;
2733 }
2734 pbDst += cbDstAndLine;
2735 pbSrc += cbSrcAndLine;
2736 }
2737 break;
2738 case 15:
2739 for (uint32_t y = 0; y < cy; y++)
2740 {
2741 for (uint32_t x = 0; x < cx; )
2742 {
2743 uint8_t bDst = 0;
2744 uint8_t fBit = 1;
2745 do
2746 {
2747 if ((pbSrc[x * 2] | (pbSrc[x * 2 + 1] & 0x7f)) >= 0xfc)
2748 bDst |= fBit;
2749 fBit <<= 1;
2750 x++;
2751 } while (x < cx && (x & 7));
2752 pbDst[(x - 1) / 8] = bDst;
2753 }
2754 pbDst += cbDstAndLine;
2755 pbSrc += cbSrcAndLine;
2756 }
2757 break;
2758 case 16:
2759 for (uint32_t y = 0; y < cy; y++)
2760 {
2761 for (uint32_t x = 0; x < cx; )
2762 {
2763 uint8_t bDst = 0;
2764 uint8_t fBit = 1;
2765 do
2766 {
2767 if ((pbSrc[x * 2] | pbSrc[x * 2 + 1]) >= 0xfc)
2768 bDst |= fBit;
2769 fBit <<= 1;
2770 x++;
2771 } while (x < cx && (x & 7));
2772 pbDst[(x - 1) / 8] = bDst;
2773 }
2774 pbDst += cbDstAndLine;
2775 pbSrc += cbSrcAndLine;
2776 }
2777 break;
2778 case 24:
2779 for (uint32_t y = 0; y < cy; y++)
2780 {
2781 for (uint32_t x = 0; x < cx; )
2782 {
2783 uint8_t bDst = 0;
2784 uint8_t fBit = 1;
2785 do
2786 {
2787 if ((pbSrc[x * 3] | pbSrc[x * 3 + 1] | pbSrc[x * 3 + 2]) >= 0xfc)
2788 bDst |= fBit;
2789 fBit <<= 1;
2790 x++;
2791 } while (x < cx && (x & 7));
2792 pbDst[(x - 1) / 8] = bDst;
2793 }
2794 pbDst += cbDstAndLine;
2795 pbSrc += cbSrcAndLine;
2796 }
2797 break;
2798 case 32:
2799 for (uint32_t y = 0; y < cy; y++)
2800 {
2801 for (uint32_t x = 0; x < cx; )
2802 {
2803 uint8_t bDst = 0;
2804 uint8_t fBit = 1;
2805 do
2806 {
2807 if ((pbSrc[x * 4] | pbSrc[x * 4 + 1] | pbSrc[x * 4 + 2] | pbSrc[x * 4 + 3]) >= 0xfc)
2808 bDst |= fBit;
2809 fBit <<= 1;
2810 x++;
2811 } while (x < cx && (x & 7));
2812 pbDst[(x - 1) / 8] = bDst;
2813 }
2814 pbDst += cbDstAndLine;
2815 pbSrc += cbSrcAndLine;
2816 }
2817 break;
2818 default:
2819 RTMemFree(pbCopy);
2820 AssertFailedReturnVoid();
2821 }
2822
2823 /* Convert the XOR mask. */
2824 uint32_t *pu32Dst = (uint32_t *)(pbCopy + cbDstAndMask);
2825 pbSrc = pbSrcXorMask;
2826 switch (pCursor->xorMaskDepth)
2827 {
2828 case 1:
2829 for (uint32_t y = 0; y < cy; y++)
2830 {
2831 for (uint32_t x = 0; x < cx; )
2832 {
2833 /* most significant bit is the left most one. */
2834 uint8_t bSrc = pbSrc[x / 8];
2835 do
2836 {
2837 *pu32Dst++ = bSrc & 0x80 ? UINT32_C(0x00ffffff) : 0;
2838 bSrc <<= 1;
2839 x++;
2840 } while ((x & 7) && x < cx);
2841 }
2842 pbSrc += cbSrcXorLine;
2843 }
2844 break;
2845 case 8:
2846 for (uint32_t y = 0; y < cy; y++)
2847 {
2848 for (uint32_t x = 0; x < cx; x++)
2849 {
2850 uint32_t u = pThis->last_palette[pbSrc[x]];
2851 *pu32Dst++ = u;//RT_MAKE_U32_FROM_U8(RT_BYTE1(u), RT_BYTE2(u), RT_BYTE3(u), 0);
2852 }
2853 pbSrc += cbSrcXorLine;
2854 }
2855 break;
2856 case 15: /* Src: RGB-5-5-5 */
2857 for (uint32_t y = 0; y < cy; y++)
2858 {
2859 for (uint32_t x = 0; x < cx; x++)
2860 {
2861 uint32_t const uValue = RT_MAKE_U16(pbSrc[x * 2], pbSrc[x * 2 + 1]);
2862 *pu32Dst++ = RT_MAKE_U32_FROM_U8(( uValue & 0x1f) << 3,
2863 ((uValue >> 5) & 0x1f) << 3,
2864 ((uValue >> 10) & 0x1f) << 3, 0);
2865 }
2866 pbSrc += cbSrcXorLine;
2867 }
2868 break;
2869 case 16: /* Src: RGB-5-6-5 */
2870 for (uint32_t y = 0; y < cy; y++)
2871 {
2872 for (uint32_t x = 0; x < cx; x++)
2873 {
2874 uint32_t const uValue = RT_MAKE_U16(pbSrc[x * 2], pbSrc[x * 2 + 1]);
2875 *pu32Dst++ = RT_MAKE_U32_FROM_U8(( uValue & 0x1f) << 3,
2876 ((uValue >> 5) & 0x3f) << 2,
2877 ((uValue >> 11) & 0x1f) << 3, 0);
2878 }
2879 pbSrc += cbSrcXorLine;
2880 }
2881 break;
2882 case 24:
2883 for (uint32_t y = 0; y < cy; y++)
2884 {
2885 for (uint32_t x = 0; x < cx; x++)
2886 *pu32Dst++ = RT_MAKE_U32_FROM_U8(pbSrc[x*3], pbSrc[x*3 + 1], pbSrc[x*3 + 2], 0);
2887 pbSrc += cbSrcXorLine;
2888 }
2889 break;
2890 case 32:
2891 for (uint32_t y = 0; y < cy; y++)
2892 {
2893 for (uint32_t x = 0; x < cx; x++)
2894 *pu32Dst++ = RT_MAKE_U32_FROM_U8(pbSrc[x*4], pbSrc[x*4 + 1], pbSrc[x*4 + 2], 0);
2895 pbSrc += cbSrcXorLine;
2896 }
2897 break;
2898 default:
2899 RTMemFree(pbCopy);
2900 AssertFailedReturnVoid();
2901 }
2902
2903 /*
2904 * Pass it to the frontend/whatever.
2905 */
2906 vmsvgaR3InstallNewCursor(pThis, pSVGAState, false /*fAlpha*/, pCursor->hotspotX, pCursor->hotspotY, cx, cy, pbCopy, cbCopy);
2907}
2908
2909
2910/**
2911 * Worker for vmsvgaR3FifoThread that handles an external command.
2912 *
2913 * @param pThis VGA device instance data.
2914 */
2915static void vmsvgaR3FifoHandleExtCmd(PVGASTATE pThis)
2916{
2917 uint8_t uExtCmd = pThis->svga.u8FIFOExtCommand;
2918 switch (pThis->svga.u8FIFOExtCommand)
2919 {
2920 case VMSVGA_FIFO_EXTCMD_RESET:
2921 Log(("vmsvgaFIFOLoop: reset the fifo thread.\n"));
2922 Assert(pThis->svga.pvFIFOExtCmdParam == NULL);
2923# ifdef VBOX_WITH_VMSVGA3D
2924 if (pThis->svga.f3DEnabled)
2925 {
2926 /* The 3d subsystem must be reset from the fifo thread. */
2927 vmsvga3dReset(pThis);
2928 }
2929# endif
2930 break;
2931
2932 case VMSVGA_FIFO_EXTCMD_TERMINATE:
2933 Log(("vmsvgaFIFOLoop: terminate the fifo thread.\n"));
2934 Assert(pThis->svga.pvFIFOExtCmdParam == NULL);
2935# ifdef VBOX_WITH_VMSVGA3D
2936 if (pThis->svga.f3DEnabled)
2937 {
2938 /* The 3d subsystem must be shut down from the fifo thread. */
2939 vmsvga3dTerminate(pThis);
2940 }
2941# endif
2942 break;
2943
2944 case VMSVGA_FIFO_EXTCMD_SAVESTATE:
2945 {
2946 Log(("vmsvgaFIFOLoop: VMSVGA_FIFO_EXTCMD_SAVESTATE.\n"));
2947 PSSMHANDLE pSSM = (PSSMHANDLE)pThis->svga.pvFIFOExtCmdParam;
2948 AssertLogRelMsgBreak(RT_VALID_PTR(pSSM), ("pSSM=%p\n", pSSM));
2949 vmsvgaSaveExecFifo(pThis, pSSM);
2950# ifdef VBOX_WITH_VMSVGA3D
2951 if (pThis->svga.f3DEnabled)
2952 vmsvga3dSaveExec(pThis, pSSM);
2953# endif
2954 break;
2955 }
2956
2957 case VMSVGA_FIFO_EXTCMD_LOADSTATE:
2958 {
2959 Log(("vmsvgaFIFOLoop: VMSVGA_FIFO_EXTCMD_LOADSTATE.\n"));
2960 PVMSVGA_STATE_LOAD pLoadState = (PVMSVGA_STATE_LOAD)pThis->svga.pvFIFOExtCmdParam;
2961 AssertLogRelMsgBreak(RT_VALID_PTR(pLoadState), ("pLoadState=%p\n", pLoadState));
2962 vmsvgaLoadExecFifo(pThis, pLoadState->pSSM, pLoadState->uVersion, pLoadState->uPass);
2963# ifdef VBOX_WITH_VMSVGA3D
2964 if (pThis->svga.f3DEnabled)
2965 vmsvga3dLoadExec(pThis, pLoadState->pSSM, pLoadState->uVersion, pLoadState->uPass);
2966# endif
2967 break;
2968 }
2969
2970 case VMSVGA_FIFO_EXTCMD_UPDATE_SURFACE_HEAP_BUFFERS:
2971 {
2972# ifdef VBOX_WITH_VMSVGA3D
2973 uint32_t sid = (uint32_t)(uintptr_t)pThis->svga.pvFIFOExtCmdParam;
2974 Log(("vmsvgaFIFOLoop: VMSVGA_FIFO_EXTCMD_UPDATE_SURFACE_HEAP_BUFFERS sid=%#x\n", sid));
2975 vmsvga3dUpdateHeapBuffersForSurfaces(pThis, sid);
2976# endif
2977 break;
2978 }
2979
2980
2981 default:
2982 AssertLogRelMsgFailed(("uExtCmd=%#x pvFIFOExtCmdParam=%p\n", uExtCmd, pThis->svga.pvFIFOExtCmdParam));
2983 break;
2984 }
2985
2986 /*
2987 * Signal the end of the external command.
2988 */
2989 pThis->svga.pvFIFOExtCmdParam = NULL;
2990 pThis->svga.u8FIFOExtCommand = VMSVGA_FIFO_EXTCMD_NONE;
2991 ASMMemoryFence(); /* paranoia^2 */
2992 int rc = RTSemEventSignal(pThis->svga.FIFOExtCmdSem);
2993 AssertLogRelRC(rc);
2994}
2995
2996/**
2997 * Worker for vmsvgaR3Destruct, vmsvgaR3Reset, vmsvgaR3Save and vmsvgaR3Load for
2998 * doing a job on the FIFO thread (even when it's officially suspended).
2999 *
3000 * @returns VBox status code (fully asserted).
3001 * @param pThis VGA device instance data.
3002 * @param uExtCmd The command to execute on the FIFO thread.
3003 * @param pvParam Pointer to command parameters.
3004 * @param cMsWait The time to wait for the command, given in
3005 * milliseconds.
3006 */
3007static int vmsvgaR3RunExtCmdOnFifoThread(PVGASTATE pThis, uint8_t uExtCmd, void *pvParam, RTMSINTERVAL cMsWait)
3008{
3009 Assert(cMsWait >= RT_MS_1SEC * 5);
3010 AssertLogRelMsg(pThis->svga.u8FIFOExtCommand == VMSVGA_FIFO_EXTCMD_NONE,
3011 ("old=%d new=%d\n", pThis->svga.u8FIFOExtCommand, uExtCmd));
3012
3013 int rc;
3014 PPDMTHREAD pThread = pThis->svga.pFIFOIOThread;
3015 PDMTHREADSTATE enmState = pThread->enmState;
3016 if (enmState == PDMTHREADSTATE_SUSPENDED)
3017 {
3018 /*
3019 * The thread is suspended, we have to temporarily wake it up so it can
3020 * perform the task.
3021 * (We ASSUME not racing code here, both wrt thread state and ext commands.)
3022 */
3023 Log(("vmsvgaR3RunExtCmdOnFifoThread: uExtCmd=%d enmState=SUSPENDED\n", uExtCmd));
3024 /* Post the request. */
3025 pThis->svga.fFifoExtCommandWakeup = true;
3026 pThis->svga.pvFIFOExtCmdParam = pvParam;
3027 pThis->svga.u8FIFOExtCommand = uExtCmd;
3028 ASMMemoryFence(); /* paranoia^3 */
3029
3030 /* Resume the thread. */
3031 rc = PDMR3ThreadResume(pThread);
3032 AssertLogRelRC(rc);
3033 if (RT_SUCCESS(rc))
3034 {
3035 /* Wait. Take care in case the semaphore was already posted (same as below). */
3036 rc = RTSemEventWait(pThis->svga.FIFOExtCmdSem, cMsWait);
3037 if ( rc == VINF_SUCCESS
3038 && pThis->svga.u8FIFOExtCommand == uExtCmd)
3039 rc = RTSemEventWait(pThis->svga.FIFOExtCmdSem, cMsWait);
3040 AssertLogRelMsg(pThis->svga.u8FIFOExtCommand != uExtCmd || RT_FAILURE_NP(rc),
3041 ("%#x %Rrc\n", pThis->svga.u8FIFOExtCommand, rc));
3042
3043 /* suspend the thread */
3044 pThis->svga.fFifoExtCommandWakeup = false;
3045 int rc2 = PDMR3ThreadSuspend(pThread);
3046 AssertLogRelRC(rc2);
3047 if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
3048 rc = rc2;
3049 }
3050 pThis->svga.fFifoExtCommandWakeup = false;
3051 pThis->svga.pvFIFOExtCmdParam = NULL;
3052 }
3053 else if (enmState == PDMTHREADSTATE_RUNNING)
3054 {
3055 /*
3056 * The thread is running, should only happen during reset and vmsvga3dsfc.
3057 * We ASSUME not racing code here, both wrt thread state and ext commands.
3058 */
3059 Log(("vmsvgaR3RunExtCmdOnFifoThread: uExtCmd=%d enmState=RUNNING\n", uExtCmd));
3060 Assert(uExtCmd == VMSVGA_FIFO_EXTCMD_RESET || uExtCmd == VMSVGA_FIFO_EXTCMD_UPDATE_SURFACE_HEAP_BUFFERS);
3061
3062 /* Post the request. */
3063 pThis->svga.pvFIFOExtCmdParam = pvParam;
3064 pThis->svga.u8FIFOExtCommand = uExtCmd;
3065 ASMMemoryFence(); /* paranoia^2 */
3066 rc = SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3067 AssertLogRelRC(rc);
3068
3069 /* Wait. Take care in case the semaphore was already posted (same as above). */
3070 rc = RTSemEventWait(pThis->svga.FIFOExtCmdSem, cMsWait);
3071 if ( rc == VINF_SUCCESS
3072 && pThis->svga.u8FIFOExtCommand == uExtCmd)
3073 rc = RTSemEventWait(pThis->svga.FIFOExtCmdSem, cMsWait); /* it was already posted, retry the wait. */
3074 AssertLogRelMsg(pThis->svga.u8FIFOExtCommand != uExtCmd || RT_FAILURE_NP(rc),
3075 ("%#x %Rrc\n", pThis->svga.u8FIFOExtCommand, rc));
3076
3077 pThis->svga.pvFIFOExtCmdParam = NULL;
3078 }
3079 else
3080 {
3081 /*
3082 * Something is wrong with the thread!
3083 */
3084 AssertLogRelMsgFailed(("uExtCmd=%d enmState=%d\n", uExtCmd, enmState));
3085 rc = VERR_INVALID_STATE;
3086 }
3087 return rc;
3088}
3089
3090
3091/**
3092 * Marks the FIFO non-busy, notifying any waiting EMTs.
3093 *
3094 * @param pThis The VGA state.
3095 * @param pSVGAState Pointer to the ring-3 only SVGA state data.
3096 * @param offFifoMin The start byte offset of the command FIFO.
3097 */
3098static void vmsvgaFifoSetNotBusy(PVGASTATE pThis, PVMSVGAR3STATE pSVGAState, uint32_t offFifoMin)
3099{
3100 ASMAtomicAndU32(&pThis->svga.fBusy, ~VMSVGA_BUSY_F_FIFO);
3101 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_BUSY, offFifoMin))
3102 vmsvgaSafeFifoBusyRegUpdate(pThis, pThis->svga.fBusy != 0);
3103
3104 /* Wake up any waiting EMTs. */
3105 if (pSVGAState->cBusyDelayedEmts > 0)
3106 {
3107#ifdef VMSVGA_USE_EMT_HALT_CODE
3108 PVM pVM = PDMDevHlpGetVM(pThis->pDevInsR3);
3109 VMCPUID idCpu = VMCpuSetFindLastPresentInternal(&pSVGAState->BusyDelayedEmts);
3110 if (idCpu != NIL_VMCPUID)
3111 {
3112 VMR3NotifyCpuDeviceReady(pVM, idCpu);
3113 while (idCpu-- > 0)
3114 if (VMCPUSET_IS_PRESENT(&pSVGAState->BusyDelayedEmts, idCpu))
3115 VMR3NotifyCpuDeviceReady(pVM, idCpu);
3116 }
3117#else
3118 int rc2 = RTSemEventMultiSignal(pSVGAState->hBusyDelayedEmts);
3119 AssertRC(rc2);
3120#endif
3121 }
3122}
3123
3124/**
3125 * Reads (more) payload into the command buffer.
3126 *
3127 * @returns pbBounceBuf on success
3128 * @retval (void *)1 if the thread was requested to stop.
3129 * @retval NULL on FIFO error.
3130 *
3131 * @param cbPayloadReq The number of bytes of payload requested.
3132 * @param pFIFO The FIFO.
3133 * @param offCurrentCmd The FIFO byte offset of the current command.
3134 * @param offFifoMin The start byte offset of the command FIFO.
3135 * @param offFifoMax The end byte offset of the command FIFO.
3136 * @param pbBounceBuf The bounch buffer. Same size as the entire FIFO, so
3137 * always sufficient size.
3138 * @param pcbAlreadyRead How much payload we've already read into the bounce
3139 * buffer. (We will NEVER re-read anything.)
3140 * @param pThread The calling PDM thread handle.
3141 * @param pThis The VGA state.
3142 * @param pSVGAState Pointer to the ring-3 only SVGA state data. For
3143 * statistics collection.
3144 */
3145static void *vmsvgaFIFOGetCmdPayload(uint32_t cbPayloadReq, uint32_t RT_UNTRUSTED_VOLATILE_GUEST *pFIFO,
3146 uint32_t offCurrentCmd, uint32_t offFifoMin, uint32_t offFifoMax,
3147 uint8_t *pbBounceBuf, uint32_t *pcbAlreadyRead,
3148 PPDMTHREAD pThread, PVGASTATE pThis, PVMSVGAR3STATE pSVGAState)
3149{
3150 Assert(pbBounceBuf);
3151 Assert(pcbAlreadyRead);
3152 Assert(offFifoMin < offFifoMax);
3153 Assert(offCurrentCmd >= offFifoMin && offCurrentCmd < offFifoMax);
3154 Assert(offFifoMax <= pThis->svga.cbFIFO);
3155
3156 /*
3157 * Check if the requested payload size has already been satisfied .
3158 * .
3159 * When called to read more, the caller is responsible for making sure the .
3160 * new command size (cbRequsted) never is smaller than what has already .
3161 * been read.
3162 */
3163 uint32_t cbAlreadyRead = *pcbAlreadyRead;
3164 if (cbPayloadReq <= cbAlreadyRead)
3165 {
3166 AssertLogRelReturn(cbPayloadReq == cbAlreadyRead, NULL);
3167 return pbBounceBuf;
3168 }
3169
3170 /*
3171 * Commands bigger than the fifo buffer are invalid.
3172 */
3173 uint32_t const cbFifoCmd = offFifoMax - offFifoMin;
3174 AssertMsgReturnStmt(cbPayloadReq <= cbFifoCmd, ("cbPayloadReq=%#x cbFifoCmd=%#x\n", cbPayloadReq, cbFifoCmd),
3175 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors),
3176 NULL);
3177
3178 /*
3179 * Move offCurrentCmd past the command dword.
3180 */
3181 offCurrentCmd += sizeof(uint32_t);
3182 if (offCurrentCmd >= offFifoMax)
3183 offCurrentCmd = offFifoMin;
3184
3185 /*
3186 * Do we have sufficient payload data available already?
3187 * The host should not read beyond [SVGA_FIFO_NEXT_CMD], therefore '>=' in the condition below.
3188 */
3189 uint32_t cbAfter, cbBefore;
3190 uint32_t offNextCmd = pFIFO[SVGA_FIFO_NEXT_CMD];
3191 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
3192 if (offNextCmd >= offCurrentCmd)
3193 {
3194 if (RT_LIKELY(offNextCmd < offFifoMax))
3195 cbAfter = offNextCmd - offCurrentCmd;
3196 else
3197 {
3198 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors);
3199 LogRelMax(16, ("vmsvgaFIFOGetCmdPayload: Invalid offNextCmd=%#x (offFifoMin=%#x offFifoMax=%#x)\n",
3200 offNextCmd, offFifoMin, offFifoMax));
3201 cbAfter = offFifoMax - offCurrentCmd;
3202 }
3203 cbBefore = 0;
3204 }
3205 else
3206 {
3207 cbAfter = offFifoMax - offCurrentCmd;
3208 if (offNextCmd >= offFifoMin)
3209 cbBefore = offNextCmd - offFifoMin;
3210 else
3211 {
3212 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors);
3213 LogRelMax(16, ("vmsvgaFIFOGetCmdPayload: Invalid offNextCmd=%#x (offFifoMin=%#x offFifoMax=%#x)\n",
3214 offNextCmd, offFifoMin, offFifoMax));
3215 cbBefore = 0;
3216 }
3217 }
3218 if (cbAfter + cbBefore < cbPayloadReq)
3219 {
3220 /*
3221 * Insufficient, must wait for it to arrive.
3222 */
3223/** @todo Should clear the busy flag here to maybe encourage the guest to wake us up. */
3224 STAM_REL_PROFILE_START(&pSVGAState->StatFifoStalls, Stall);
3225 for (uint32_t i = 0;; i++)
3226 {
3227 if (pThread->enmState != PDMTHREADSTATE_RUNNING)
3228 {
3229 STAM_REL_PROFILE_STOP(&pSVGAState->StatFifoStalls, Stall);
3230 return (void *)(uintptr_t)1;
3231 }
3232 Log(("Guest still copying (%x vs %x) current %x next %x stop %x loop %u; sleep a bit\n",
3233 cbPayloadReq, cbAfter + cbBefore, offCurrentCmd, offNextCmd, pFIFO[SVGA_FIFO_STOP], i));
3234
3235 SUPSemEventWaitNoResume(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem, i < 16 ? 1 : 2);
3236
3237 offNextCmd = pFIFO[SVGA_FIFO_NEXT_CMD];
3238 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
3239 if (offNextCmd >= offCurrentCmd)
3240 {
3241 cbAfter = RT_MIN(offNextCmd, offFifoMax) - offCurrentCmd;
3242 cbBefore = 0;
3243 }
3244 else
3245 {
3246 cbAfter = offFifoMax - offCurrentCmd;
3247 cbBefore = RT_MAX(offNextCmd, offFifoMin) - offFifoMin;
3248 }
3249
3250 if (cbAfter + cbBefore >= cbPayloadReq)
3251 break;
3252 }
3253 STAM_REL_PROFILE_STOP(&pSVGAState->StatFifoStalls, Stall);
3254 }
3255
3256 /*
3257 * Copy out the memory and update what pcbAlreadyRead points to.
3258 */
3259 if (cbAfter >= cbPayloadReq)
3260 memcpy(pbBounceBuf + cbAlreadyRead,
3261 (uint8_t *)pFIFO + offCurrentCmd + cbAlreadyRead,
3262 cbPayloadReq - cbAlreadyRead);
3263 else
3264 {
3265 LogFlow(("Split data buffer at %x (%u-%u)\n", offCurrentCmd, cbAfter, cbBefore));
3266 if (cbAlreadyRead < cbAfter)
3267 {
3268 memcpy(pbBounceBuf + cbAlreadyRead,
3269 (uint8_t *)pFIFO + offCurrentCmd + cbAlreadyRead,
3270 cbAfter - cbAlreadyRead);
3271 cbAlreadyRead = cbAfter;
3272 }
3273 memcpy(pbBounceBuf + cbAlreadyRead,
3274 (uint8_t *)pFIFO + offFifoMin + cbAlreadyRead - cbAfter,
3275 cbPayloadReq - cbAlreadyRead);
3276 }
3277 *pcbAlreadyRead = cbPayloadReq;
3278 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
3279 return pbBounceBuf;
3280}
3281
3282
3283/**
3284 * Sends cursor position and visibility information from the FIFO to the front-end.
3285 * @returns SVGA_FIFO_CURSOR_COUNT value used.
3286 */
3287static uint32_t
3288vmsvgaFIFOUpdateCursor(PVGASTATE pVGAState, PVMSVGAR3STATE pSVGAState, uint32_t RT_UNTRUSTED_VOLATILE_GUEST *pFIFO,
3289 uint32_t offFifoMin, uint32_t uCursorUpdateCount,
3290 uint32_t *pxLast, uint32_t *pyLast, uint32_t *pfLastVisible)
3291{
3292 /*
3293 * Check if the cursor update counter has changed and try get a stable
3294 * set of values if it has. This is race-prone, especially consindering
3295 * the screen ID, but little we can do about that.
3296 */
3297 uint32_t x, y, fVisible, idScreen;
3298 for (uint32_t i = 0; ; i++)
3299 {
3300 x = pFIFO[SVGA_FIFO_CURSOR_X];
3301 y = pFIFO[SVGA_FIFO_CURSOR_Y];
3302 fVisible = pFIFO[SVGA_FIFO_CURSOR_ON];
3303 idScreen = VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_CURSOR_SCREEN_ID, offFifoMin)
3304 ? pFIFO[SVGA_FIFO_CURSOR_SCREEN_ID] : SVGA_ID_INVALID;
3305 if ( uCursorUpdateCount == pFIFO[SVGA_FIFO_CURSOR_COUNT]
3306 || i > 3)
3307 break;
3308 if (i == 0)
3309 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoCursorFetchAgain);
3310 ASMNopPause();
3311 uCursorUpdateCount = pFIFO[SVGA_FIFO_CURSOR_COUNT];
3312 }
3313
3314 /*
3315 * Check if anything has changed, as calling into pDrv is not light-weight.
3316 */
3317 if ( *pxLast == x
3318 && *pyLast == y
3319 && (idScreen != SVGA_ID_INVALID || *pfLastVisible == fVisible))
3320 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoCursorNoChange);
3321 else
3322 {
3323 /*
3324 * Detected changes.
3325 *
3326 * We handle global, not per-screen visibility information by sending
3327 * pfnVBVAMousePointerShape without shape data.
3328 */
3329 *pxLast = x;
3330 *pyLast = y;
3331 uint32_t fFlags = VBVA_CURSOR_VALID_DATA;
3332 if (idScreen != SVGA_ID_INVALID)
3333 fFlags |= VBVA_CURSOR_SCREEN_RELATIVE;
3334 else if (*pfLastVisible != fVisible)
3335 {
3336 *pfLastVisible = fVisible;
3337 pVGAState->pDrv->pfnVBVAMousePointerShape(pVGAState->pDrv, RT_BOOL(fVisible), false, 0, 0, 0, 0, NULL);
3338 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoCursorVisiblity);
3339 }
3340 pVGAState->pDrv->pfnVBVAReportCursorPosition(pVGAState->pDrv, fFlags, idScreen, x, y);
3341 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoCursorPosition);
3342 }
3343
3344 /*
3345 * Update done. Signal this to the guest.
3346 */
3347 pFIFO[SVGA_FIFO_CURSOR_LAST_UPDATED] = uCursorUpdateCount;
3348
3349 return uCursorUpdateCount;
3350}
3351
3352
3353/**
3354 * Checks if there is work to be done, either cursor updating or FIFO commands.
3355 *
3356 * @returns true if pending work, false if not.
3357 * @param pFIFO The FIFO to examine.
3358 * @param uLastCursorCount The last cursor update counter value.
3359 */
3360DECLINLINE(bool) vmsvgaFIFOHasWork(uint32_t RT_UNTRUSTED_VOLATILE_GUEST * const pFIFO, uint32_t uLastCursorCount)
3361{
3362 if (pFIFO[SVGA_FIFO_NEXT_CMD] != pFIFO[SVGA_FIFO_STOP])
3363 return true;
3364
3365 if ( uLastCursorCount != pFIFO[SVGA_FIFO_CURSOR_COUNT]
3366 && VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_CURSOR_LAST_UPDATED, pFIFO[SVGA_FIFO_MIN]))
3367 return true;
3368
3369 return false;
3370}
3371
3372
3373/**
3374 * Called by the VGA refresh timer to wake up the FIFO thread when needed.
3375 *
3376 * @param pThis The VGA state.
3377 */
3378void vmsvgaFIFOWatchdogTimer(PVGASTATE pThis)
3379{
3380 /* Caller already checked pThis->svga.fFIFOThreadSleeping, so we only have
3381 to recheck it before doing the signalling. */
3382 uint32_t RT_UNTRUSTED_VOLATILE_GUEST * const pFIFO = pThis->svga.pFIFOR3;
3383 AssertReturnVoid(pFIFO);
3384 if ( vmsvgaFIFOHasWork(pFIFO, ASMAtomicReadU32(&pThis->svga.uLastCursorUpdateCount))
3385 && pThis->svga.fFIFOThreadSleeping)
3386 {
3387 int rc = SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3388 AssertRC(rc);
3389 STAM_REL_COUNTER_INC(&pThis->svga.pSvgaR3State->StatFifoWatchdogWakeUps);
3390 }
3391}
3392
3393
3394/* The async FIFO handling thread. */
3395static DECLCALLBACK(int) vmsvgaFIFOLoop(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
3396{
3397 PVGASTATE pThis = (PVGASTATE)pThread->pvUser;
3398 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
3399 int rc;
3400
3401 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
3402 return VINF_SUCCESS;
3403
3404 /*
3405 * Special mode where we only execute an external command and the go back
3406 * to being suspended. Currently, all ext cmds ends up here, with the reset
3407 * one also being eligble for runtime execution further down as well.
3408 */
3409 if (pThis->svga.fFifoExtCommandWakeup)
3410 {
3411 vmsvgaR3FifoHandleExtCmd(pThis);
3412 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
3413 if (pThis->svga.u8FIFOExtCommand == VMSVGA_FIFO_EXTCMD_NONE)
3414 SUPSemEventWaitNoResume(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem, RT_MS_1MIN);
3415 else
3416 vmsvgaR3FifoHandleExtCmd(pThis);
3417 return VINF_SUCCESS;
3418 }
3419
3420
3421 /*
3422 * Signal the semaphore to make sure we don't wait for 250ms after a
3423 * suspend & resume scenario (see vmsvgaFIFOGetCmdPayload).
3424 */
3425 SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3426
3427 /*
3428 * Allocate a bounce buffer for command we get from the FIFO.
3429 * (All code must return via the end of the function to free this buffer.)
3430 */
3431 uint8_t *pbBounceBuf = (uint8_t *)RTMemAllocZ(pThis->svga.cbFIFO);
3432 AssertReturn(pbBounceBuf, VERR_NO_MEMORY);
3433
3434 /*
3435 * Polling/sleep interval config.
3436 *
3437 * We wait for an a short interval if the guest has recently given us work
3438 * to do, but the interval increases the longer we're kept idle. Once we've
3439 * reached the refresh timer interval, we'll switch to extended waits,
3440 * depending on it or the guest to kick us into action when needed.
3441 *
3442 * Should the refresh time go fishing, we'll just continue increasing the
3443 * sleep length till we reaches the 250 ms max after about 16 seconds.
3444 */
3445 RTMSINTERVAL const cMsMinSleep = 16;
3446 RTMSINTERVAL const cMsIncSleep = 2;
3447 RTMSINTERVAL const cMsMaxSleep = 250;
3448 RTMSINTERVAL const cMsExtendedSleep = 15 * RT_MS_1SEC; /* Regular paranoia dictates that this cannot be indefinite. */
3449 RTMSINTERVAL cMsSleep = cMsMaxSleep;
3450
3451 /*
3452 * Cursor update state (SVGA_FIFO_CAP_CURSOR_BYPASS_3).
3453 *
3454 * Initialize with values that will detect an update from the guest.
3455 * Make sure that if the guest never updates the cursor position, then the device does not report it.
3456 * The guest has to change the value of uLastCursorUpdateCount, when the cursor position is actually updated.
3457 * xLastCursor, yLastCursor and fLastCursorVisible are set to report the first update.
3458 */
3459 uint32_t RT_UNTRUSTED_VOLATILE_GUEST * const pFIFO = pThis->svga.pFIFOR3;
3460 pThis->svga.uLastCursorUpdateCount = pFIFO[SVGA_FIFO_CURSOR_COUNT];
3461 uint32_t xLastCursor = ~pFIFO[SVGA_FIFO_CURSOR_X];
3462 uint32_t yLastCursor = ~pFIFO[SVGA_FIFO_CURSOR_Y];
3463 uint32_t fLastCursorVisible = ~pFIFO[SVGA_FIFO_CURSOR_ON];
3464
3465 /*
3466 * The FIFO loop.
3467 */
3468 LogFlow(("vmsvgaFIFOLoop: started loop\n"));
3469 bool fBadOrDisabledFifo = false;
3470 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
3471 {
3472# if defined(RT_OS_DARWIN) && defined(VBOX_WITH_VMSVGA3D)
3473 /*
3474 * Should service the run loop every so often.
3475 */
3476 if (pThis->svga.f3DEnabled)
3477 vmsvga3dCocoaServiceRunLoop();
3478# endif
3479
3480 /*
3481 * Unless there's already work pending, go to sleep for a short while.
3482 * (See polling/sleep interval config above.)
3483 */
3484 if ( fBadOrDisabledFifo
3485 || !vmsvgaFIFOHasWork(pFIFO, pThis->svga.uLastCursorUpdateCount))
3486 {
3487 ASMAtomicWriteBool(&pThis->svga.fFIFOThreadSleeping, true);
3488 Assert(pThis->cMilliesRefreshInterval > 0);
3489 if (cMsSleep < pThis->cMilliesRefreshInterval)
3490 rc = SUPSemEventWaitNoResume(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem, cMsSleep);
3491 else
3492 {
3493# ifdef VMSVGA_USE_FIFO_ACCESS_HANDLER
3494 int rc2 = PGMHandlerPhysicalReset(PDMDevHlpGetVM(pDevIns), pThis->svga.GCPhysFIFO);
3495 AssertRC(rc2); /* No break. Racing EMTs unmapping and remapping the region. */
3496# endif
3497 if ( !fBadOrDisabledFifo
3498 && vmsvgaFIFOHasWork(pFIFO, pThis->svga.uLastCursorUpdateCount))
3499 rc = VINF_SUCCESS;
3500 else
3501 {
3502 STAM_REL_PROFILE_START(&pSVGAState->StatFifoExtendedSleep, Acc);
3503 rc = SUPSemEventWaitNoResume(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem, cMsExtendedSleep);
3504 STAM_REL_PROFILE_STOP(&pSVGAState->StatFifoExtendedSleep, Acc);
3505 }
3506 }
3507 ASMAtomicWriteBool(&pThis->svga.fFIFOThreadSleeping, false);
3508 AssertBreak(RT_SUCCESS(rc) || rc == VERR_TIMEOUT || rc == VERR_INTERRUPTED);
3509 if (pThread->enmState != PDMTHREADSTATE_RUNNING)
3510 {
3511 LogFlow(("vmsvgaFIFOLoop: thread state %x\n", pThread->enmState));
3512 break;
3513 }
3514 }
3515 else
3516 rc = VINF_SUCCESS;
3517 fBadOrDisabledFifo = false;
3518 if (rc == VERR_TIMEOUT)
3519 {
3520 if (!vmsvgaFIFOHasWork(pFIFO, pThis->svga.uLastCursorUpdateCount))
3521 {
3522 cMsSleep = RT_MIN(cMsSleep + cMsIncSleep, cMsMaxSleep);
3523 continue;
3524 }
3525 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoTodoTimeout);
3526
3527 Log(("vmsvgaFIFOLoop: timeout\n"));
3528 }
3529 else if (vmsvgaFIFOHasWork(pFIFO, pThis->svga.uLastCursorUpdateCount))
3530 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoTodoWoken);
3531 cMsSleep = cMsMinSleep;
3532
3533 Log(("vmsvgaFIFOLoop: enabled=%d configured=%d busy=%d\n", pThis->svga.fEnabled, pThis->svga.fConfigured, pFIFO[SVGA_FIFO_BUSY]));
3534 Log(("vmsvgaFIFOLoop: min %x max %x\n", pFIFO[SVGA_FIFO_MIN], pFIFO[SVGA_FIFO_MAX]));
3535 Log(("vmsvgaFIFOLoop: next %x stop %x\n", pFIFO[SVGA_FIFO_NEXT_CMD], pFIFO[SVGA_FIFO_STOP]));
3536
3537 /*
3538 * Handle external commands (currently only reset).
3539 */
3540 if (pThis->svga.u8FIFOExtCommand != VMSVGA_FIFO_EXTCMD_NONE)
3541 {
3542 vmsvgaR3FifoHandleExtCmd(pThis);
3543 continue;
3544 }
3545
3546 /*
3547 * The device must be enabled and configured.
3548 */
3549 if ( !pThis->svga.fEnabled
3550 || !pThis->svga.fConfigured)
3551 {
3552 vmsvgaFifoSetNotBusy(pThis, pSVGAState, pFIFO[SVGA_FIFO_MIN]);
3553 fBadOrDisabledFifo = true;
3554 cMsSleep = cMsMaxSleep; /* cheat */
3555 continue;
3556 }
3557
3558 /*
3559 * Get and check the min/max values. We ASSUME that they will remain
3560 * unchanged while we process requests. A further ASSUMPTION is that
3561 * the guest won't mess with SVGA_FIFO_NEXT_CMD while we're busy, so
3562 * we don't read it back while in the loop.
3563 */
3564 uint32_t const offFifoMin = pFIFO[SVGA_FIFO_MIN];
3565 uint32_t const offFifoMax = pFIFO[SVGA_FIFO_MAX];
3566 uint32_t offCurrentCmd = pFIFO[SVGA_FIFO_STOP];
3567 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
3568 if (RT_UNLIKELY( !VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_STOP, offFifoMin)
3569 || offFifoMax <= offFifoMin
3570 || offFifoMax > pThis->svga.cbFIFO
3571 || (offFifoMax & 3) != 0
3572 || (offFifoMin & 3) != 0
3573 || offCurrentCmd < offFifoMin
3574 || offCurrentCmd > offFifoMax))
3575 {
3576 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors);
3577 LogRelMax(8, ("vmsvgaFIFOLoop: Bad fifo: min=%#x stop=%#x max=%#x\n", offFifoMin, offCurrentCmd, offFifoMax));
3578 vmsvgaFifoSetNotBusy(pThis, pSVGAState, offFifoMin);
3579 fBadOrDisabledFifo = true;
3580 continue;
3581 }
3582 RT_UNTRUSTED_VALIDATED_FENCE();
3583 if (RT_UNLIKELY(offCurrentCmd & 3))
3584 {
3585 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors);
3586 LogRelMax(8, ("vmsvgaFIFOLoop: Misaligned offCurrentCmd=%#x?\n", offCurrentCmd));
3587 offCurrentCmd &= ~UINT32_C(3);
3588 }
3589
3590 /*
3591 * Update the cursor position before we start on the FIFO commands.
3592 */
3593 /** @todo do we need to check whether the guest disabled the SVGA_FIFO_CAP_CURSOR_BYPASS_3 capability here? */
3594 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_CURSOR_LAST_UPDATED, offFifoMin))
3595 {
3596 uint32_t const uCursorUpdateCount = pFIFO[SVGA_FIFO_CURSOR_COUNT];
3597 if (uCursorUpdateCount == pThis->svga.uLastCursorUpdateCount)
3598 { /* halfways likely */ }
3599 else
3600 {
3601 uint32_t const uLastCursorCount = vmsvgaFIFOUpdateCursor(pThis, pSVGAState, pFIFO, offFifoMin, uCursorUpdateCount,
3602 &xLastCursor, &yLastCursor, &fLastCursorVisible);
3603 ASMAtomicWriteU32(&pThis->svga.uLastCursorUpdateCount, uLastCursorCount);
3604 }
3605 }
3606
3607/** @def VMSVGAFIFO_GET_CMD_BUFFER_BREAK
3608 * Macro for shortening calls to vmsvgaFIFOGetCmdPayload.
3609 *
3610 * Will break out of the switch on failure.
3611 * Will restart and quit the loop if the thread was requested to stop.
3612 *
3613 * @param a_PtrVar Request variable pointer.
3614 * @param a_Type Request typedef (not pointer) for casting.
3615 * @param a_cbPayloadReq How much payload to fetch.
3616 * @remarks Accesses a bunch of variables in the current scope!
3617 */
3618# define VMSVGAFIFO_GET_CMD_BUFFER_BREAK(a_PtrVar, a_Type, a_cbPayloadReq) \
3619 if (1) { \
3620 (a_PtrVar) = (a_Type *)vmsvgaFIFOGetCmdPayload((a_cbPayloadReq), pFIFO, offCurrentCmd, offFifoMin, offFifoMax, \
3621 pbBounceBuf, &cbPayload, pThread, pThis, pSVGAState); \
3622 if (RT_UNLIKELY((uintptr_t)(a_PtrVar) < 2)) { if ((uintptr_t)(a_PtrVar) == 1) continue; break; } \
3623 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE(); \
3624 } else do {} while (0)
3625/** @def VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK
3626 * Macro for shortening calls to vmsvgaFIFOGetCmdPayload for refetching the
3627 * buffer after figuring out the actual command size.
3628 *
3629 * Will break out of the switch on failure.
3630 *
3631 * @param a_PtrVar Request variable pointer.
3632 * @param a_Type Request typedef (not pointer) for casting.
3633 * @param a_cbPayloadReq How much payload to fetch.
3634 * @remarks Accesses a bunch of variables in the current scope!
3635 */
3636# define VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(a_PtrVar, a_Type, a_cbPayloadReq) \
3637 if (1) { \
3638 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(a_PtrVar, a_Type, a_cbPayloadReq); \
3639 } else do {} while (0)
3640
3641 /*
3642 * Mark the FIFO as busy.
3643 */
3644 ASMAtomicWriteU32(&pThis->svga.fBusy, VMSVGA_BUSY_F_FIFO);
3645 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_BUSY, offFifoMin))
3646 ASMAtomicWriteU32(&pFIFO[SVGA_FIFO_BUSY], true);
3647
3648 /*
3649 * Execute all queued FIFO commands.
3650 * Quit if pending external command or changes in the thread state.
3651 */
3652 bool fDone = false;
3653 while ( !(fDone = (pFIFO[SVGA_FIFO_NEXT_CMD] == offCurrentCmd))
3654 && pThread->enmState == PDMTHREADSTATE_RUNNING)
3655 {
3656 uint32_t cbPayload = 0;
3657 uint32_t u32IrqStatus = 0;
3658
3659 Assert(offCurrentCmd < offFifoMax && offCurrentCmd >= offFifoMin);
3660
3661 /* First check any pending actions. */
3662 if (ASMBitTestAndClear(&pThis->svga.u32ActionFlags, VMSVGA_ACTION_CHANGEMODE_BIT))
3663 {
3664 vmsvgaChangeMode(pThis);
3665# ifdef VBOX_WITH_VMSVGA3D
3666 if (pThis->svga.p3dState != NULL)
3667 vmsvga3dChangeMode(pThis);
3668# endif
3669 }
3670
3671 /* Check for pending external commands (reset). */
3672 if (pThis->svga.u8FIFOExtCommand != VMSVGA_FIFO_EXTCMD_NONE)
3673 break;
3674
3675 /*
3676 * Process the command.
3677 */
3678 SVGAFifoCmdId const enmCmdId = (SVGAFifoCmdId)pFIFO[offCurrentCmd / sizeof(uint32_t)];
3679 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
3680 LogFlow(("vmsvgaFIFOLoop: FIFO command (iCmd=0x%x) %s 0x%x\n",
3681 offCurrentCmd / sizeof(uint32_t), vmsvgaFIFOCmdToString(enmCmdId), enmCmdId));
3682 switch (enmCmdId)
3683 {
3684 case SVGA_CMD_INVALID_CMD:
3685 /* Nothing to do. */
3686 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdInvalidCmd);
3687 break;
3688
3689 case SVGA_CMD_FENCE:
3690 {
3691 SVGAFifoCmdFence *pCmdFence;
3692 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmdFence, SVGAFifoCmdFence, sizeof(*pCmdFence));
3693 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdFence);
3694 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_FENCE, offFifoMin))
3695 {
3696 Log(("vmsvgaFIFOLoop: SVGA_CMD_FENCE %x\n", pCmdFence->fence));
3697 pFIFO[SVGA_FIFO_FENCE] = pCmdFence->fence;
3698
3699 if (pThis->svga.u32IrqMask & SVGA_IRQFLAG_ANY_FENCE)
3700 {
3701 Log(("vmsvgaFIFOLoop: any fence irq\n"));
3702 u32IrqStatus |= SVGA_IRQFLAG_ANY_FENCE;
3703 }
3704 else
3705 if ( VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_FENCE_GOAL, offFifoMin)
3706 && (pThis->svga.u32IrqMask & SVGA_IRQFLAG_FENCE_GOAL)
3707 && pFIFO[SVGA_FIFO_FENCE_GOAL] == pCmdFence->fence)
3708 {
3709 Log(("vmsvgaFIFOLoop: fence goal reached irq (fence=%x)\n", pCmdFence->fence));
3710 u32IrqStatus |= SVGA_IRQFLAG_FENCE_GOAL;
3711 }
3712 }
3713 else
3714 Log(("SVGA_CMD_FENCE is bogus when offFifoMin is %#x!\n", offFifoMin));
3715 break;
3716 }
3717 case SVGA_CMD_UPDATE:
3718 case SVGA_CMD_UPDATE_VERBOSE:
3719 {
3720 SVGAFifoCmdUpdate *pUpdate;
3721 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pUpdate, SVGAFifoCmdUpdate, sizeof(*pUpdate));
3722 if (enmCmdId == SVGA_CMD_UPDATE)
3723 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdUpdate);
3724 else
3725 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdUpdateVerbose);
3726 Log(("vmsvgaFIFOLoop: UPDATE (%d,%d)(%d,%d)\n", pUpdate->x, pUpdate->y, pUpdate->width, pUpdate->height));
3727 /** @todo Multiple screens? */
3728 VMSVGASCREENOBJECT *pScreen = vmsvgaGetScreenObject(pThis, 0);
3729 AssertBreak(pScreen);
3730 vmsvgaUpdateScreen(pThis, pScreen, pUpdate->x, pUpdate->y, pUpdate->width, pUpdate->height);
3731 break;
3732 }
3733
3734 case SVGA_CMD_DEFINE_CURSOR:
3735 {
3736 /* Followed by bitmap data. */
3737 SVGAFifoCmdDefineCursor *pCursor;
3738 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCursor, SVGAFifoCmdDefineCursor, sizeof(*pCursor));
3739 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdDefineCursor);
3740
3741 Log(("vmsvgaFIFOLoop: CURSOR id=%d size (%d,%d) hotspot (%d,%d) andMaskDepth=%d xorMaskDepth=%d\n",
3742 pCursor->id, pCursor->width, pCursor->height, pCursor->hotspotX, pCursor->hotspotY,
3743 pCursor->andMaskDepth, pCursor->xorMaskDepth));
3744 AssertBreak(pCursor->height < 2048 && pCursor->width < 2048);
3745 AssertBreak(pCursor->andMaskDepth <= 32);
3746 AssertBreak(pCursor->xorMaskDepth <= 32);
3747 RT_UNTRUSTED_VALIDATED_FENCE();
3748
3749 uint32_t cbAndLine = RT_ALIGN_32(pCursor->width * (pCursor->andMaskDepth + (pCursor->andMaskDepth == 15)), 32) / 8;
3750 uint32_t cbAndMask = cbAndLine * pCursor->height;
3751 uint32_t cbXorLine = RT_ALIGN_32(pCursor->width * (pCursor->xorMaskDepth + (pCursor->xorMaskDepth == 15)), 32) / 8;
3752 uint32_t cbXorMask = cbXorLine * pCursor->height;
3753 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pCursor, SVGAFifoCmdDefineCursor, sizeof(*pCursor) + cbAndMask + cbXorMask);
3754
3755 vmsvgaR3CmdDefineCursor(pThis, pSVGAState, pCursor, (uint8_t const *)(pCursor + 1), cbAndLine,
3756 (uint8_t const *)(pCursor + 1) + cbAndMask, cbXorLine);
3757 break;
3758 }
3759
3760 case SVGA_CMD_DEFINE_ALPHA_CURSOR:
3761 {
3762 /* Followed by bitmap data. */
3763 uint32_t cbCursorShape, cbAndMask;
3764 uint8_t *pCursorCopy;
3765 uint32_t cbCmd;
3766
3767 SVGAFifoCmdDefineAlphaCursor *pCursor;
3768 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCursor, SVGAFifoCmdDefineAlphaCursor, sizeof(*pCursor));
3769 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdDefineAlphaCursor);
3770
3771 Log(("vmsvgaFIFOLoop: ALPHA_CURSOR id=%d size (%d,%d) hotspot (%d,%d)\n", pCursor->id, pCursor->width, pCursor->height, pCursor->hotspotX, pCursor->hotspotY));
3772
3773 /* Check against a reasonable upper limit to prevent integer overflows in the sanity checks below. */
3774 AssertBreak(pCursor->height < 2048 && pCursor->width < 2048);
3775 RT_UNTRUSTED_VALIDATED_FENCE();
3776
3777 /* Refetch the bitmap data as well. */
3778 cbCmd = sizeof(SVGAFifoCmdDefineAlphaCursor) + pCursor->width * pCursor->height * sizeof(uint32_t) /* 32-bit BRGA format */;
3779 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pCursor, SVGAFifoCmdDefineAlphaCursor, cbCmd);
3780 /** @todo Would be more efficient to copy the data straight into pCursorCopy (memcpy below). */
3781
3782 /* The mouse pointer interface always expects an AND mask followed by the color data (XOR mask). */
3783 cbAndMask = (pCursor->width + 7) / 8 * pCursor->height; /* size of the AND mask */
3784 cbAndMask = ((cbAndMask + 3) & ~3); /* + gap for alignment */
3785 cbCursorShape = cbAndMask + pCursor->width * sizeof(uint32_t) * pCursor->height; /* + size of the XOR mask (32-bit BRGA format) */
3786
3787 pCursorCopy = (uint8_t *)RTMemAlloc(cbCursorShape);
3788 AssertBreak(pCursorCopy);
3789
3790 /* Transparency is defined by the alpha bytes, so make the whole bitmap visible. */
3791 memset(pCursorCopy, 0xff, cbAndMask);
3792 /* Colour data */
3793 memcpy(pCursorCopy + cbAndMask, (pCursor + 1), pCursor->width * pCursor->height * sizeof(uint32_t));
3794
3795 vmsvgaR3InstallNewCursor(pThis, pSVGAState, true /*fAlpha*/, pCursor->hotspotX, pCursor->hotspotY,
3796 pCursor->width, pCursor->height, pCursorCopy, cbCursorShape);
3797 break;
3798 }
3799
3800 case SVGA_CMD_ESCAPE:
3801 {
3802 /* Followed by nsize bytes of data. */
3803 SVGAFifoCmdEscape *pEscape;
3804 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pEscape, SVGAFifoCmdEscape, sizeof(*pEscape));
3805 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdEscape);
3806
3807 /* Refetch the command buffer with the variable data; undo size increase (ugly) */
3808 AssertBreak(pEscape->size < pThis->svga.cbFIFO);
3809 RT_UNTRUSTED_VALIDATED_FENCE();
3810 uint32_t cbCmd = sizeof(SVGAFifoCmdEscape) + pEscape->size;
3811 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pEscape, SVGAFifoCmdEscape, cbCmd);
3812
3813 if (pEscape->nsid == SVGA_ESCAPE_NSID_VMWARE)
3814 {
3815 AssertBreak(pEscape->size >= sizeof(uint32_t));
3816 RT_UNTRUSTED_VALIDATED_FENCE();
3817 uint32_t cmd = *(uint32_t *)(pEscape + 1);
3818 Log(("vmsvgaFIFOLoop: ESCAPE (%x %x) VMWARE cmd=%x\n", pEscape->nsid, pEscape->size, cmd));
3819
3820 switch (cmd)
3821 {
3822 case SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS:
3823 {
3824 SVGAEscapeVideoSetRegs *pVideoCmd = (SVGAEscapeVideoSetRegs *)(pEscape + 1);
3825 AssertBreak(pEscape->size >= sizeof(pVideoCmd->header));
3826 uint32_t cRegs = (pEscape->size - sizeof(pVideoCmd->header)) / sizeof(pVideoCmd->items[0]);
3827
3828 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: stream %x\n", pVideoCmd->header.streamId));
3829 for (uint32_t iReg = 0; iReg < cRegs; iReg++)
3830 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: reg %x val %x\n", pVideoCmd->items[iReg].registerId, pVideoCmd->items[iReg].value));
3831
3832 RT_NOREF_PV(pVideoCmd);
3833 break;
3834
3835 }
3836
3837 case SVGA_ESCAPE_VMWARE_VIDEO_FLUSH:
3838 {
3839 SVGAEscapeVideoFlush *pVideoCmd = (SVGAEscapeVideoFlush *)(pEscape + 1);
3840 AssertBreak(pEscape->size >= sizeof(*pVideoCmd));
3841 Log(("SVGA_ESCAPE_VMWARE_VIDEO_FLUSH: stream %x\n", pVideoCmd->streamId));
3842 RT_NOREF_PV(pVideoCmd);
3843 break;
3844 }
3845
3846 default:
3847 Log(("SVGA_CMD_ESCAPE: Unknown vmware escape: %x\n", cmd));
3848 break;
3849 }
3850 }
3851 else
3852 Log(("vmsvgaFIFOLoop: ESCAPE %x %x\n", pEscape->nsid, pEscape->size));
3853
3854 break;
3855 }
3856# ifdef VBOX_WITH_VMSVGA3D
3857 case SVGA_CMD_DEFINE_GMR2:
3858 {
3859 SVGAFifoCmdDefineGMR2 *pCmd;
3860 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDefineGMR2, sizeof(*pCmd));
3861 Log(("vmsvgaFIFOLoop: SVGA_CMD_DEFINE_GMR2 id=%x %x pages\n", pCmd->gmrId, pCmd->numPages));
3862 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdDefineGmr2);
3863
3864 /* Validate current GMR id. */
3865 AssertBreak(pCmd->gmrId < pThis->svga.cGMR);
3866 AssertBreak(pCmd->numPages <= VMSVGA_MAX_GMR_PAGES);
3867 RT_UNTRUSTED_VALIDATED_FENCE();
3868
3869 if (!pCmd->numPages)
3870 {
3871 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdDefineGmr2Free);
3872 vmsvgaGMRFree(pThis, pCmd->gmrId);
3873 }
3874 else
3875 {
3876 PGMR pGMR = &pSVGAState->paGMR[pCmd->gmrId];
3877 if (pGMR->cMaxPages)
3878 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdDefineGmr2Modify);
3879
3880 /* Not sure if we should always free the descriptor, but for simplicity
3881 we do so if the new size is smaller than the current. */
3882 /** @todo always free the descriptor in SVGA_CMD_DEFINE_GMR2? */
3883 if (pGMR->cbTotal / X86_PAGE_SIZE > pGMR->cMaxPages)
3884 vmsvgaGMRFree(pThis, pCmd->gmrId);
3885
3886 pGMR->cMaxPages = pCmd->numPages;
3887 /* The rest is done by the REMAP_GMR2 command. */
3888 }
3889 break;
3890 }
3891
3892 case SVGA_CMD_REMAP_GMR2:
3893 {
3894 /* Followed by page descriptors or guest ptr. */
3895 SVGAFifoCmdRemapGMR2 *pCmd;
3896 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdRemapGMR2, sizeof(*pCmd));
3897 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdRemapGmr2);
3898
3899 Log(("vmsvgaFIFOLoop: SVGA_CMD_REMAP_GMR2 id=%x flags=%x offset=%x npages=%x\n", pCmd->gmrId, pCmd->flags, pCmd->offsetPages, pCmd->numPages));
3900 AssertBreak(pCmd->gmrId < pThis->svga.cGMR);
3901 RT_UNTRUSTED_VALIDATED_FENCE();
3902
3903 /* Calculate the size of what comes after next and fetch it. */
3904 uint32_t cbCmd = sizeof(SVGAFifoCmdRemapGMR2);
3905 if (pCmd->flags & SVGA_REMAP_GMR2_VIA_GMR)
3906 cbCmd += sizeof(SVGAGuestPtr);
3907 else
3908 {
3909 uint32_t const cbPageDesc = (pCmd->flags & SVGA_REMAP_GMR2_PPN64) ? sizeof(uint64_t) : sizeof(uint32_t);
3910 if (pCmd->flags & SVGA_REMAP_GMR2_SINGLE_PPN)
3911 {
3912 cbCmd += cbPageDesc;
3913 pCmd->numPages = 1;
3914 }
3915 else
3916 {
3917 AssertBreak(pCmd->numPages <= pThis->svga.cbFIFO / cbPageDesc);
3918 cbCmd += cbPageDesc * pCmd->numPages;
3919 }
3920 }
3921 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdRemapGMR2, cbCmd);
3922
3923 /* Validate current GMR id and size. */
3924 AssertBreak(pCmd->gmrId < pThis->svga.cGMR);
3925 RT_UNTRUSTED_VALIDATED_FENCE();
3926 PGMR pGMR = &pSVGAState->paGMR[pCmd->gmrId];
3927 AssertBreak( (uint64_t)pCmd->offsetPages + pCmd->numPages
3928 <= RT_MIN(pGMR->cMaxPages, RT_MIN(VMSVGA_MAX_GMR_PAGES, UINT32_MAX / X86_PAGE_SIZE)));
3929 AssertBreak(!pCmd->offsetPages || pGMR->paDesc); /** @todo */
3930
3931 if (pCmd->numPages == 0)
3932 break;
3933
3934 /* Calc new total page count so we can use it instead of cMaxPages for allocations below. */
3935 uint32_t const cNewTotalPages = RT_MAX(pGMR->cbTotal >> X86_PAGE_SHIFT, pCmd->offsetPages + pCmd->numPages);
3936
3937 /*
3938 * We flatten the existing descriptors into a page array, overwrite the
3939 * pages specified in this command and then recompress the descriptor.
3940 */
3941 /** @todo Optimize the GMR remap algorithm! */
3942
3943 /* Save the old page descriptors as an array of page frame numbers (address >> X86_PAGE_SHIFT) */
3944 uint64_t *paNewPage64 = NULL;
3945 if (pGMR->paDesc)
3946 {
3947 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdRemapGmr2Modify);
3948
3949 paNewPage64 = (uint64_t *)RTMemAllocZ(cNewTotalPages * sizeof(uint64_t));
3950 AssertBreak(paNewPage64);
3951
3952 uint32_t idxPage = 0;
3953 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
3954 for (uint32_t j = 0; j < pGMR->paDesc[i].numPages; j++)
3955 paNewPage64[idxPage++] = (pGMR->paDesc[i].GCPhys + j * X86_PAGE_SIZE) >> X86_PAGE_SHIFT;
3956 AssertBreakStmt(idxPage == pGMR->cbTotal >> X86_PAGE_SHIFT, RTMemFree(paNewPage64));
3957 RT_UNTRUSTED_VALIDATED_FENCE();
3958 }
3959
3960 /* Free the old GMR if present. */
3961 if (pGMR->paDesc)
3962 RTMemFree(pGMR->paDesc);
3963
3964 /* Allocate the maximum amount possible (everything non-continuous) */
3965 PVMSVGAGMRDESCRIPTOR paDescs;
3966 pGMR->paDesc = paDescs = (PVMSVGAGMRDESCRIPTOR)RTMemAllocZ(cNewTotalPages * sizeof(VMSVGAGMRDESCRIPTOR));
3967 AssertBreakStmt(paDescs, RTMemFree(paNewPage64));
3968
3969 if (pCmd->flags & SVGA_REMAP_GMR2_VIA_GMR)
3970 {
3971 /** @todo */
3972 AssertFailed();
3973 pGMR->numDescriptors = 0;
3974 }
3975 else
3976 {
3977 uint32_t *paPages32 = (uint32_t *)(pCmd + 1);
3978 uint64_t *paPages64 = (uint64_t *)(pCmd + 1);
3979 bool fGCPhys64 = RT_BOOL(pCmd->flags & SVGA_REMAP_GMR2_PPN64);
3980
3981 if (paNewPage64)
3982 {
3983 /* Overwrite the old page array with the new page values. */
3984 if (fGCPhys64)
3985 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
3986 paNewPage64[i] = paPages64[i - pCmd->offsetPages];
3987 else
3988 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
3989 paNewPage64[i] = paPages32[i - pCmd->offsetPages];
3990
3991 /* Use the updated page array instead of the command data. */
3992 fGCPhys64 = true;
3993 paPages64 = paNewPage64;
3994 pCmd->numPages = cNewTotalPages;
3995 }
3996
3997 /* The first page. */
3998 /** @todo The 0x00000FFFFFFFFFFF mask limits to 44 bits and should not be
3999 * applied to paNewPage64. */
4000 RTGCPHYS GCPhys;
4001 if (fGCPhys64)
4002 GCPhys = (paPages64[0] << X86_PAGE_SHIFT) & UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
4003 else
4004 GCPhys = (RTGCPHYS)paPages32[0] << PAGE_SHIFT;
4005 paDescs[0].GCPhys = GCPhys;
4006 paDescs[0].numPages = 1;
4007
4008 /* Subsequent pages. */
4009 uint32_t iDescriptor = 0;
4010 for (uint32_t i = 1; i < pCmd->numPages; i++)
4011 {
4012 if (pCmd->flags & SVGA_REMAP_GMR2_PPN64)
4013 GCPhys = (paPages64[i] << X86_PAGE_SHIFT) & UINT64_C(0x00000FFFFFFFFFFF); /* Seeing rubbish in the top bits with certain linux guests. */
4014 else
4015 GCPhys = (RTGCPHYS)paPages32[i] << X86_PAGE_SHIFT;
4016
4017 /* Continuous physical memory? */
4018 if (GCPhys == paDescs[iDescriptor].GCPhys + paDescs[iDescriptor].numPages * X86_PAGE_SIZE)
4019 {
4020 Assert(paDescs[iDescriptor].numPages);
4021 paDescs[iDescriptor].numPages++;
4022 LogFlow(("Page %x GCPhys=%RGp successor\n", i, GCPhys));
4023 }
4024 else
4025 {
4026 iDescriptor++;
4027 paDescs[iDescriptor].GCPhys = GCPhys;
4028 paDescs[iDescriptor].numPages = 1;
4029 LogFlow(("Page %x GCPhys=%RGp\n", i, paDescs[iDescriptor].GCPhys));
4030 }
4031 }
4032
4033 pGMR->cbTotal = cNewTotalPages << X86_PAGE_SHIFT;
4034 LogFlow(("Nr of descriptors %x; cbTotal=%#x\n", iDescriptor + 1, cNewTotalPages));
4035 pGMR->numDescriptors = iDescriptor + 1;
4036 }
4037
4038 if (paNewPage64)
4039 RTMemFree(paNewPage64);
4040
4041# ifdef DEBUG_GMR_ACCESS
4042 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pThis->pDevInsR3), VMCPUID_ANY, (PFNRT)vmsvgaRegisterGMR, 2, pThis->pDevInsR3, pCmd->gmrId);
4043# endif
4044 break;
4045 }
4046# endif // VBOX_WITH_VMSVGA3D
4047 case SVGA_CMD_DEFINE_SCREEN:
4048 {
4049 /* The size of this command is specified by the guest and depends on capabilities. */
4050 Assert(pFIFO[SVGA_FIFO_CAPABILITIES] & SVGA_FIFO_CAP_SCREEN_OBJECT_2);
4051
4052 SVGAFifoCmdDefineScreen *pCmd;
4053 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDefineScreen, sizeof(pCmd->screen.structSize));
4054 AssertBreak(pCmd->screen.structSize < pThis->svga.cbFIFO);
4055 RT_UNTRUSTED_VALIDATED_FENCE();
4056
4057 RT_BZERO(&pCmd->screen.id, sizeof(*pCmd) - RT_OFFSETOF(SVGAFifoCmdDefineScreen, screen.id));
4058 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDefineScreen, RT_MAX(sizeof(pCmd->screen.structSize), pCmd->screen.structSize));
4059 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdDefineScreen);
4060
4061 LogFunc(("SVGA_CMD_DEFINE_SCREEN id=%x flags=%x size=(%d,%d) root=(%d,%d) %d:0x%x 0x%x\n",
4062 pCmd->screen.id, pCmd->screen.flags, pCmd->screen.size.width, pCmd->screen.size.height, pCmd->screen.root.x, pCmd->screen.root.y,
4063 pCmd->screen.backingStore.ptr.gmrId, pCmd->screen.backingStore.ptr.offset, pCmd->screen.backingStore.pitch));
4064
4065 uint32_t const idScreen = pCmd->screen.id;
4066 AssertBreak(idScreen < RT_ELEMENTS(pThis->svga.pSvgaR3State->aScreens));
4067
4068 uint32_t const uWidth = pCmd->screen.size.width;
4069 AssertBreak(uWidth <= pThis->svga.u32MaxWidth);
4070
4071 uint32_t const uHeight = pCmd->screen.size.height;
4072 AssertBreak(uHeight <= pThis->svga.u32MaxHeight);
4073
4074 uint32_t const cbWidth = uWidth * ((32 + 7) / 8); /** @todo 32? */
4075 uint32_t const cbPitch = pCmd->screen.backingStore.pitch ? pCmd->screen.backingStore.pitch : cbWidth;
4076 AssertBreak(cbWidth <= cbPitch);
4077
4078 uint32_t const uScreenOffset = pCmd->screen.backingStore.ptr.offset;
4079 AssertBreak(uScreenOffset < pThis->vram_size);
4080
4081 uint32_t const cbVram = pThis->vram_size - uScreenOffset;
4082 /* If we have a not zero pitch, then height can't exceed the available VRAM. */
4083 AssertBreak( (uHeight == 0 && cbPitch == 0)
4084 || (cbPitch > 0 && uHeight <= cbVram / cbPitch));
4085 RT_UNTRUSTED_VALIDATED_FENCE();
4086
4087 VMSVGASCREENOBJECT *pScreen = &pThis->svga.pSvgaR3State->aScreens[idScreen];
4088
4089 bool const fBlank = RT_BOOL(pCmd->screen.flags & (SVGA_SCREEN_DEACTIVATE | SVGA_SCREEN_BLANKING));
4090
4091 pScreen->fDefined = true;
4092 pScreen->fModified = true;
4093 pScreen->fuScreen = pCmd->screen.flags;
4094 pScreen->idScreen = idScreen;
4095 if (!fBlank)
4096 {
4097 AssertBreak(uWidth > 0 && uHeight > 0);
4098
4099 pScreen->xOrigin = pCmd->screen.root.x;
4100 pScreen->yOrigin = pCmd->screen.root.y;
4101 pScreen->cWidth = uWidth;
4102 pScreen->cHeight = uHeight;
4103 pScreen->offVRAM = uScreenOffset;
4104 pScreen->cbPitch = cbPitch;
4105 pScreen->cBpp = 32;
4106 }
4107 else
4108 {
4109 /* Keep old values. */
4110 }
4111
4112 pThis->svga.fGFBRegisters = false;
4113 vmsvgaChangeMode(pThis);
4114 break;
4115 }
4116
4117 case SVGA_CMD_DESTROY_SCREEN:
4118 {
4119 SVGAFifoCmdDestroyScreen *pCmd;
4120 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDestroyScreen, sizeof(*pCmd));
4121 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdDestroyScreen);
4122
4123 Log(("vmsvgaFIFOLoop: SVGA_CMD_DESTROY_SCREEN id=%x\n", pCmd->screenId));
4124
4125 uint32_t const idScreen = pCmd->screenId;
4126 AssertBreak(idScreen < RT_ELEMENTS(pThis->svga.pSvgaR3State->aScreens));
4127 RT_UNTRUSTED_VALIDATED_FENCE();
4128
4129 VMSVGASCREENOBJECT *pScreen = &pThis->svga.pSvgaR3State->aScreens[idScreen];
4130 pScreen->fModified = true;
4131 pScreen->fDefined = false;
4132 pScreen->idScreen = idScreen;
4133
4134 vmsvgaChangeMode(pThis);
4135 break;
4136 }
4137
4138 case SVGA_CMD_DEFINE_GMRFB:
4139 {
4140 SVGAFifoCmdDefineGMRFB *pCmd;
4141 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDefineGMRFB, sizeof(*pCmd));
4142 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdDefineGmrFb);
4143
4144 Log(("vmsvgaFIFOLoop: SVGA_CMD_DEFINE_GMRFB gmr=%x offset=%x bytesPerLine=%x bpp=%d color depth=%d\n", pCmd->ptr.gmrId, pCmd->ptr.offset, pCmd->bytesPerLine, pCmd->format.s.bitsPerPixel, pCmd->format.s.colorDepth));
4145 pSVGAState->GMRFB.ptr = pCmd->ptr;
4146 pSVGAState->GMRFB.bytesPerLine = pCmd->bytesPerLine;
4147 pSVGAState->GMRFB.format = pCmd->format;
4148 break;
4149 }
4150
4151 case SVGA_CMD_BLIT_GMRFB_TO_SCREEN:
4152 {
4153 SVGAFifoCmdBlitGMRFBToScreen *pCmd;
4154 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdBlitGMRFBToScreen, sizeof(*pCmd));
4155 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdBlitGmrFbToScreen);
4156
4157 LogFunc(("SVGA_CMD_BLIT_GMRFB_TO_SCREEN src=(%d,%d) dest id=%d (%d,%d)(%d,%d)\n",
4158 pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->destScreenId, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right, pCmd->destRect.bottom));
4159
4160 AssertBreak(pCmd->destScreenId < RT_ELEMENTS(pThis->svga.pSvgaR3State->aScreens));
4161 RT_UNTRUSTED_VALIDATED_FENCE();
4162
4163 VMSVGASCREENOBJECT *pScreen = vmsvgaGetScreenObject(pThis, pCmd->destScreenId);
4164 AssertBreak(pScreen);
4165
4166 /** @todo Support GMRFB.format.s.bitsPerPixel != pThis->svga.uBpp */
4167 AssertBreak(pSVGAState->GMRFB.format.s.bitsPerPixel == pScreen->cBpp);
4168
4169 /* Clip destRect to the screen dimensions. */
4170 SVGASignedRect screenRect;
4171 screenRect.left = 0;
4172 screenRect.top = 0;
4173 screenRect.right = pScreen->cWidth;
4174 screenRect.bottom = pScreen->cHeight;
4175 SVGASignedRect clipRect = pCmd->destRect;
4176 vmsvgaClipRect(&screenRect, &clipRect);
4177 RT_UNTRUSTED_VALIDATED_FENCE();
4178
4179 uint32_t const width = clipRect.right - clipRect.left;
4180 uint32_t const height = clipRect.bottom - clipRect.top;
4181
4182 if ( width == 0
4183 || height == 0)
4184 break; /* Nothing to do. */
4185
4186 int32_t const srcx = pCmd->srcOrigin.x + (clipRect.left - pCmd->destRect.left);
4187 int32_t const srcy = pCmd->srcOrigin.y + (clipRect.top - pCmd->destRect.top);
4188
4189 /* Copy the defined by GMRFB image to the screen 0 VRAM area.
4190 * Prepare parameters for vmsvgaGMRTransfer.
4191 */
4192 AssertBreak(pScreen->offVRAM < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
4193
4194 /* Destination: host buffer which describes the screen 0 VRAM.
4195 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaGMRTransfer.
4196 */
4197 uint8_t * const pbHstBuf = (uint8_t *)pThis->CTX_SUFF(vram_ptr) + pScreen->offVRAM;
4198 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch :
4199 width * (RT_ALIGN(pScreen->cBpp, 8) / 8);
4200 uint32_t cbHstBuf = cbScanline * pScreen->cHeight;
4201 if (cbHstBuf > pThis->vram_size - pScreen->offVRAM)
4202 cbHstBuf = pThis->vram_size - pScreen->offVRAM; /* Paranoia. */
4203 uint32_t const offHst = (clipRect.left * RT_ALIGN(pScreen->cBpp, 8)) / 8
4204 + cbScanline * clipRect.top;
4205 int32_t const cbHstPitch = cbScanline;
4206
4207 /* Source: GMRFB. vmsvgaGMRTransfer ensures that no memory outside the GMR is read. */
4208 SVGAGuestPtr const gstPtr = pSVGAState->GMRFB.ptr;
4209 uint32_t const offGst = (srcx * RT_ALIGN(pSVGAState->GMRFB.format.s.bitsPerPixel, 8)) / 8
4210 + pSVGAState->GMRFB.bytesPerLine * srcy;
4211 int32_t const cbGstPitch = pSVGAState->GMRFB.bytesPerLine;
4212
4213 rc = vmsvgaGMRTransfer(pThis, SVGA3D_WRITE_HOST_VRAM,
4214 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
4215 gstPtr, offGst, cbGstPitch,
4216 (width * RT_ALIGN(pScreen->cBpp, 8)) / 8, height);
4217 AssertRC(rc);
4218 vmsvgaUpdateScreen(pThis, pScreen, clipRect.left, clipRect.top, width, height);
4219 break;
4220 }
4221
4222 case SVGA_CMD_BLIT_SCREEN_TO_GMRFB:
4223 {
4224 SVGAFifoCmdBlitScreenToGMRFB *pCmd;
4225 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdBlitScreenToGMRFB, sizeof(*pCmd));
4226 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdBlitScreentoGmrFb);
4227
4228 /* Note! This can fetch 3d render results as well!! */
4229 LogFunc(("SVGA_CMD_BLIT_SCREEN_TO_GMRFB dest=(%d,%d) src id=%d (%d,%d)(%d,%d)\n",
4230 pCmd->destOrigin.x, pCmd->destOrigin.y, pCmd->srcScreenId, pCmd->srcRect.left, pCmd->srcRect.top, pCmd->srcRect.right, pCmd->srcRect.bottom));
4231
4232 AssertBreak(pCmd->srcScreenId < RT_ELEMENTS(pThis->svga.pSvgaR3State->aScreens));
4233 RT_UNTRUSTED_VALIDATED_FENCE();
4234
4235 VMSVGASCREENOBJECT *pScreen = vmsvgaGetScreenObject(pThis, pCmd->srcScreenId);
4236 AssertBreak(pScreen);
4237
4238 /** @todo Support GMRFB.format.s.bitsPerPixel != pThis->svga.uBpp? */
4239 AssertBreak(pSVGAState->GMRFB.format.s.bitsPerPixel == pScreen->cBpp);
4240
4241 /* Clip destRect to the screen dimensions. */
4242 SVGASignedRect screenRect;
4243 screenRect.left = 0;
4244 screenRect.top = 0;
4245 screenRect.right = pScreen->cWidth;
4246 screenRect.bottom = pScreen->cHeight;
4247 SVGASignedRect clipRect = pCmd->srcRect;
4248 vmsvgaClipRect(&screenRect, &clipRect);
4249 RT_UNTRUSTED_VALIDATED_FENCE();
4250
4251 uint32_t const width = clipRect.right - clipRect.left;
4252 uint32_t const height = clipRect.bottom - clipRect.top;
4253
4254 if ( width == 0
4255 || height == 0)
4256 break; /* Nothing to do. */
4257
4258 int32_t const dstx = pCmd->destOrigin.x + (clipRect.left - pCmd->srcRect.left);
4259 int32_t const dsty = pCmd->destOrigin.y + (clipRect.top - pCmd->srcRect.top);
4260
4261 /* Copy the defined by GMRFB image to the screen 0 VRAM area.
4262 * Prepare parameters for vmsvgaGMRTransfer.
4263 */
4264 AssertBreak(pScreen->offVRAM < pThis->vram_size); /* Paranoia. Ensured by SVGA_CMD_DEFINE_SCREEN. */
4265
4266 /* Source: host buffer which describes the screen 0 VRAM.
4267 * Important are pbHstBuf and cbHstBuf. offHst and cbHstPitch are verified by vmsvgaGMRTransfer.
4268 */
4269 uint8_t * const pbHstBuf = (uint8_t *)pThis->CTX_SUFF(vram_ptr) + pScreen->offVRAM;
4270 uint32_t const cbScanline = pScreen->cbPitch ? pScreen->cbPitch :
4271 width * (RT_ALIGN(pScreen->cBpp, 8) / 8);
4272 uint32_t cbHstBuf = cbScanline * pScreen->cHeight;
4273 if (cbHstBuf > pThis->vram_size - pScreen->offVRAM)
4274 cbHstBuf = pThis->vram_size - pScreen->offVRAM; /* Paranoia. */
4275 uint32_t const offHst = (clipRect.left * RT_ALIGN(pScreen->cBpp, 8)) / 8
4276 + cbScanline * clipRect.top;
4277 int32_t const cbHstPitch = cbScanline;
4278
4279 /* Destination: GMRFB. vmsvgaGMRTransfer ensures that no memory outside the GMR is read. */
4280 SVGAGuestPtr const gstPtr = pSVGAState->GMRFB.ptr;
4281 uint32_t const offGst = (dstx * RT_ALIGN(pSVGAState->GMRFB.format.s.bitsPerPixel, 8)) / 8
4282 + pSVGAState->GMRFB.bytesPerLine * dsty;
4283 int32_t const cbGstPitch = pSVGAState->GMRFB.bytesPerLine;
4284
4285 rc = vmsvgaGMRTransfer(pThis, SVGA3D_READ_HOST_VRAM,
4286 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
4287 gstPtr, offGst, cbGstPitch,
4288 (width * RT_ALIGN(pScreen->cBpp, 8)) / 8, height);
4289 AssertRC(rc);
4290 break;
4291 }
4292
4293 case SVGA_CMD_ANNOTATION_FILL:
4294 {
4295 SVGAFifoCmdAnnotationFill *pCmd;
4296 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdAnnotationFill, sizeof(*pCmd));
4297 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdAnnotationFill);
4298
4299 Log(("vmsvgaFIFOLoop: SVGA_CMD_ANNOTATION_FILL red=%x green=%x blue=%x\n", pCmd->color.s.r, pCmd->color.s.g, pCmd->color.s.b));
4300 pSVGAState->colorAnnotation = pCmd->color;
4301 break;
4302 }
4303
4304 case SVGA_CMD_ANNOTATION_COPY:
4305 {
4306 SVGAFifoCmdAnnotationCopy *pCmd;
4307 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdAnnotationCopy, sizeof(*pCmd));
4308 STAM_REL_COUNTER_INC(&pSVGAState->StatR3CmdAnnotationCopy);
4309
4310 Log(("vmsvgaFIFOLoop: SVGA_CMD_ANNOTATION_COPY\n"));
4311 AssertFailed();
4312 break;
4313 }
4314
4315 /** @todo SVGA_CMD_RECT_COPY - see with ubuntu */
4316
4317 default:
4318# ifdef VBOX_WITH_VMSVGA3D
4319 if ( (int)enmCmdId >= SVGA_3D_CMD_BASE
4320 && (int)enmCmdId < SVGA_3D_CMD_MAX)
4321 {
4322 RT_UNTRUSTED_VALIDATED_FENCE();
4323
4324 /* All 3d commands start with a common header, which defines the size of the command. */
4325 SVGA3dCmdHeader *pHdr;
4326 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pHdr, SVGA3dCmdHeader, sizeof(*pHdr));
4327 AssertBreak(pHdr->size < pThis->svga.cbFIFO);
4328 uint32_t cbCmd = sizeof(SVGA3dCmdHeader) + pHdr->size;
4329 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pHdr, SVGA3dCmdHeader, cbCmd);
4330
4331 if (RT_LIKELY(pThis->svga.f3DEnabled))
4332 { /* likely */ }
4333 else
4334 {
4335 LogRelMax(8, ("VMSVGA3d: 3D disabled, command %d skipped\n", enmCmdId));
4336 break;
4337 }
4338
4339/**
4340 * Check that the 3D command has at least a_cbMin of payload bytes after the
4341 * header. Will break out of the switch if it doesn't.
4342 */
4343# define VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(a_cbMin) \
4344 if (1) { \
4345 AssertMsgBreak(pHdr->size >= (a_cbMin), ("size=%#x a_cbMin=%#zx\n", pHdr->size, (size_t)(a_cbMin))); \
4346 RT_UNTRUSTED_VALIDATED_FENCE(); \
4347 } else do {} while (0)
4348 switch ((int)enmCmdId)
4349 {
4350 case SVGA_3D_CMD_SURFACE_DEFINE:
4351 {
4352 uint32_t cMipLevels;
4353 SVGA3dCmdDefineSurface *pCmd = (SVGA3dCmdDefineSurface *)(pHdr + 1);
4354 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4355 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSurfaceDefine);
4356
4357 cMipLevels = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dSize);
4358 rc = vmsvga3dSurfaceDefine(pThis, pCmd->sid, (uint32_t)pCmd->surfaceFlags, pCmd->format, pCmd->face, 0,
4359 SVGA3D_TEX_FILTER_NONE, cMipLevels, (SVGA3dSize *)(pCmd + 1));
4360# ifdef DEBUG_GMR_ACCESS
4361 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pThis->pDevInsR3), VMCPUID_ANY, (PFNRT)vmsvgaResetGMRHandlers, 1, pThis);
4362# endif
4363 break;
4364 }
4365
4366 case SVGA_3D_CMD_SURFACE_DEFINE_V2:
4367 {
4368 uint32_t cMipLevels;
4369 SVGA3dCmdDefineSurface_v2 *pCmd = (SVGA3dCmdDefineSurface_v2 *)(pHdr + 1);
4370 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4371 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSurfaceDefineV2);
4372
4373 cMipLevels = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dSize);
4374 rc = vmsvga3dSurfaceDefine(pThis, pCmd->sid, pCmd->surfaceFlags, pCmd->format, pCmd->face,
4375 pCmd->multisampleCount, pCmd->autogenFilter,
4376 cMipLevels, (SVGA3dSize *)(pCmd + 1));
4377 break;
4378 }
4379
4380 case SVGA_3D_CMD_SURFACE_DESTROY:
4381 {
4382 SVGA3dCmdDestroySurface *pCmd = (SVGA3dCmdDestroySurface *)(pHdr + 1);
4383 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4384 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSurfaceDestroy);
4385 rc = vmsvga3dSurfaceDestroy(pThis, pCmd->sid);
4386 break;
4387 }
4388
4389 case SVGA_3D_CMD_SURFACE_COPY:
4390 {
4391 uint32_t cCopyBoxes;
4392 SVGA3dCmdSurfaceCopy *pCmd = (SVGA3dCmdSurfaceCopy *)(pHdr + 1);
4393 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4394 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSurfaceCopy);
4395
4396 cCopyBoxes = (pHdr->size - sizeof(pCmd)) / sizeof(SVGA3dCopyBox);
4397 rc = vmsvga3dSurfaceCopy(pThis, pCmd->dest, pCmd->src, cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
4398 break;
4399 }
4400
4401 case SVGA_3D_CMD_SURFACE_STRETCHBLT:
4402 {
4403 SVGA3dCmdSurfaceStretchBlt *pCmd = (SVGA3dCmdSurfaceStretchBlt *)(pHdr + 1);
4404 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4405 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSurfaceStretchBlt);
4406
4407 rc = vmsvga3dSurfaceStretchBlt(pThis, &pCmd->dest, &pCmd->boxDest, &pCmd->src, &pCmd->boxSrc, pCmd->mode);
4408 break;
4409 }
4410
4411 case SVGA_3D_CMD_SURFACE_DMA:
4412 {
4413 uint32_t cCopyBoxes;
4414 SVGA3dCmdSurfaceDMA *pCmd = (SVGA3dCmdSurfaceDMA *)(pHdr + 1);
4415 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4416 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSurfaceDma);
4417
4418 cCopyBoxes = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dCopyBox);
4419 STAM_PROFILE_START(&pSVGAState->StatR3Cmd3dSurfaceDmaProf, a);
4420 rc = vmsvga3dSurfaceDMA(pThis, pCmd->guest, pCmd->host, pCmd->transfer, cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
4421 STAM_PROFILE_STOP(&pSVGAState->StatR3Cmd3dSurfaceDmaProf, a);
4422 break;
4423 }
4424
4425 case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN:
4426 {
4427 uint32_t cRects;
4428 SVGA3dCmdBlitSurfaceToScreen *pCmd = (SVGA3dCmdBlitSurfaceToScreen *)(pHdr + 1);
4429 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4430 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSurfaceScreen);
4431
4432 cRects = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGASignedRect);
4433 rc = vmsvga3dSurfaceBlitToScreen(pThis, pCmd->destScreenId, pCmd->destRect, pCmd->srcImage, pCmd->srcRect, cRects, (SVGASignedRect *)(pCmd + 1));
4434 break;
4435 }
4436
4437 case SVGA_3D_CMD_CONTEXT_DEFINE:
4438 {
4439 SVGA3dCmdDefineContext *pCmd = (SVGA3dCmdDefineContext *)(pHdr + 1);
4440 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4441 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dContextDefine);
4442
4443 rc = vmsvga3dContextDefine(pThis, pCmd->cid);
4444 break;
4445 }
4446
4447 case SVGA_3D_CMD_CONTEXT_DESTROY:
4448 {
4449 SVGA3dCmdDestroyContext *pCmd = (SVGA3dCmdDestroyContext *)(pHdr + 1);
4450 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4451 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dContextDestroy);
4452
4453 rc = vmsvga3dContextDestroy(pThis, pCmd->cid);
4454 break;
4455 }
4456
4457 case SVGA_3D_CMD_SETTRANSFORM:
4458 {
4459 SVGA3dCmdSetTransform *pCmd = (SVGA3dCmdSetTransform *)(pHdr + 1);
4460 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4461 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetTransform);
4462
4463 rc = vmsvga3dSetTransform(pThis, pCmd->cid, pCmd->type, pCmd->matrix);
4464 break;
4465 }
4466
4467 case SVGA_3D_CMD_SETZRANGE:
4468 {
4469 SVGA3dCmdSetZRange *pCmd = (SVGA3dCmdSetZRange *)(pHdr + 1);
4470 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4471 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetZRange);
4472
4473 rc = vmsvga3dSetZRange(pThis, pCmd->cid, pCmd->zRange);
4474 break;
4475 }
4476
4477 case SVGA_3D_CMD_SETRENDERSTATE:
4478 {
4479 uint32_t cRenderStates;
4480 SVGA3dCmdSetRenderState *pCmd = (SVGA3dCmdSetRenderState *)(pHdr + 1);
4481 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4482 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetRenderState);
4483
4484 cRenderStates = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dRenderState);
4485 rc = vmsvga3dSetRenderState(pThis, pCmd->cid, cRenderStates, (SVGA3dRenderState *)(pCmd + 1));
4486 break;
4487 }
4488
4489 case SVGA_3D_CMD_SETRENDERTARGET:
4490 {
4491 SVGA3dCmdSetRenderTarget *pCmd = (SVGA3dCmdSetRenderTarget *)(pHdr + 1);
4492 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4493 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetRenderTarget);
4494
4495 rc = vmsvga3dSetRenderTarget(pThis, pCmd->cid, pCmd->type, pCmd->target);
4496 break;
4497 }
4498
4499 case SVGA_3D_CMD_SETTEXTURESTATE:
4500 {
4501 uint32_t cTextureStates;
4502 SVGA3dCmdSetTextureState *pCmd = (SVGA3dCmdSetTextureState *)(pHdr + 1);
4503 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4504 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetTextureState);
4505
4506 cTextureStates = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dTextureState);
4507 rc = vmsvga3dSetTextureState(pThis, pCmd->cid, cTextureStates, (SVGA3dTextureState *)(pCmd + 1));
4508 break;
4509 }
4510
4511 case SVGA_3D_CMD_SETMATERIAL:
4512 {
4513 SVGA3dCmdSetMaterial *pCmd = (SVGA3dCmdSetMaterial *)(pHdr + 1);
4514 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4515 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetMaterial);
4516
4517 rc = vmsvga3dSetMaterial(pThis, pCmd->cid, pCmd->face, &pCmd->material);
4518 break;
4519 }
4520
4521 case SVGA_3D_CMD_SETLIGHTDATA:
4522 {
4523 SVGA3dCmdSetLightData *pCmd = (SVGA3dCmdSetLightData *)(pHdr + 1);
4524 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4525 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetLightData);
4526
4527 rc = vmsvga3dSetLightData(pThis, pCmd->cid, pCmd->index, &pCmd->data);
4528 break;
4529 }
4530
4531 case SVGA_3D_CMD_SETLIGHTENABLED:
4532 {
4533 SVGA3dCmdSetLightEnabled *pCmd = (SVGA3dCmdSetLightEnabled *)(pHdr + 1);
4534 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4535 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetLightEnable);
4536
4537 rc = vmsvga3dSetLightEnabled(pThis, pCmd->cid, pCmd->index, pCmd->enabled);
4538 break;
4539 }
4540
4541 case SVGA_3D_CMD_SETVIEWPORT:
4542 {
4543 SVGA3dCmdSetViewport *pCmd = (SVGA3dCmdSetViewport *)(pHdr + 1);
4544 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4545 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetViewPort);
4546
4547 rc = vmsvga3dSetViewPort(pThis, pCmd->cid, &pCmd->rect);
4548 break;
4549 }
4550
4551 case SVGA_3D_CMD_SETCLIPPLANE:
4552 {
4553 SVGA3dCmdSetClipPlane *pCmd = (SVGA3dCmdSetClipPlane *)(pHdr + 1);
4554 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4555 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetClipPlane);
4556
4557 rc = vmsvga3dSetClipPlane(pThis, pCmd->cid, pCmd->index, pCmd->plane);
4558 break;
4559 }
4560
4561 case SVGA_3D_CMD_CLEAR:
4562 {
4563 SVGA3dCmdClear *pCmd = (SVGA3dCmdClear *)(pHdr + 1);
4564 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4565 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dClear);
4566
4567 uint32_t cRects = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dRect);
4568 rc = vmsvga3dCommandClear(pThis, pCmd->cid, pCmd->clearFlag, pCmd->color, pCmd->depth, pCmd->stencil, cRects, (SVGA3dRect *)(pCmd + 1));
4569 break;
4570 }
4571
4572 case SVGA_3D_CMD_PRESENT:
4573 case SVGA_3D_CMD_PRESENT_READBACK: /** @todo SVGA_3D_CMD_PRESENT_READBACK isn't quite the same as present... */
4574 {
4575 SVGA3dCmdPresent *pCmd = (SVGA3dCmdPresent *)(pHdr + 1);
4576 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4577 if ((unsigned)enmCmdId == SVGA_3D_CMD_PRESENT)
4578 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dPresent);
4579 else
4580 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dPresentReadBack);
4581
4582 uint32_t cRects = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dCopyRect);
4583
4584 STAM_PROFILE_START(&pSVGAState->StatR3Cmd3dPresentProf, a);
4585 rc = vmsvga3dCommandPresent(pThis, pCmd->sid, cRects, (SVGA3dCopyRect *)(pCmd + 1));
4586 STAM_PROFILE_STOP(&pSVGAState->StatR3Cmd3dPresentProf, a);
4587 break;
4588 }
4589
4590 case SVGA_3D_CMD_SHADER_DEFINE:
4591 {
4592 SVGA3dCmdDefineShader *pCmd = (SVGA3dCmdDefineShader *)(pHdr + 1);
4593 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4594 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dShaderDefine);
4595
4596 uint32_t cbData = (pHdr->size - sizeof(*pCmd));
4597 rc = vmsvga3dShaderDefine(pThis, pCmd->cid, pCmd->shid, pCmd->type, cbData, (uint32_t *)(pCmd + 1));
4598 break;
4599 }
4600
4601 case SVGA_3D_CMD_SHADER_DESTROY:
4602 {
4603 SVGA3dCmdDestroyShader *pCmd = (SVGA3dCmdDestroyShader *)(pHdr + 1);
4604 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4605 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dShaderDestroy);
4606
4607 rc = vmsvga3dShaderDestroy(pThis, pCmd->cid, pCmd->shid, pCmd->type);
4608 break;
4609 }
4610
4611 case SVGA_3D_CMD_SET_SHADER:
4612 {
4613 SVGA3dCmdSetShader *pCmd = (SVGA3dCmdSetShader *)(pHdr + 1);
4614 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4615 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetShader);
4616
4617 rc = vmsvga3dShaderSet(pThis, NULL, pCmd->cid, pCmd->type, pCmd->shid);
4618 break;
4619 }
4620
4621 case SVGA_3D_CMD_SET_SHADER_CONST:
4622 {
4623 SVGA3dCmdSetShaderConst *pCmd = (SVGA3dCmdSetShaderConst *)(pHdr + 1);
4624 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4625 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetShaderConst);
4626
4627 uint32_t cRegisters = (pHdr->size - sizeof(*pCmd)) / sizeof(pCmd->values) + 1;
4628 rc = vmsvga3dShaderSetConst(pThis, pCmd->cid, pCmd->reg, pCmd->type, pCmd->ctype, cRegisters, pCmd->values);
4629 break;
4630 }
4631
4632 case SVGA_3D_CMD_DRAW_PRIMITIVES:
4633 {
4634 SVGA3dCmdDrawPrimitives *pCmd = (SVGA3dCmdDrawPrimitives *)(pHdr + 1);
4635 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4636 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dDrawPrimitives);
4637
4638 AssertBreak(pCmd->numRanges <= SVGA3D_MAX_DRAW_PRIMITIVE_RANGES);
4639 AssertBreak(pCmd->numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS);
4640 uint32_t const cbRangesAndVertexDecls = pCmd->numVertexDecls * sizeof(SVGA3dVertexDecl)
4641 + pCmd->numRanges * sizeof(SVGA3dPrimitiveRange);
4642 ASSERT_GUEST_BREAK(cbRangesAndVertexDecls <= pHdr->size - sizeof(*pCmd));
4643
4644 uint32_t cVertexDivisor = (pHdr->size - sizeof(*pCmd) - cbRangesAndVertexDecls) / sizeof(uint32_t);
4645 AssertBreak(!cVertexDivisor || cVertexDivisor == pCmd->numVertexDecls);
4646
4647 RT_UNTRUSTED_VALIDATED_FENCE();
4648
4649 SVGA3dVertexDecl *pVertexDecl = (SVGA3dVertexDecl *)(pCmd + 1);
4650 SVGA3dPrimitiveRange *pNumRange = (SVGA3dPrimitiveRange *)&pVertexDecl[pCmd->numVertexDecls];
4651 SVGA3dVertexDivisor *pVertexDivisor = cVertexDivisor ? (SVGA3dVertexDivisor *)&pNumRange[pCmd->numRanges] : NULL;
4652
4653 STAM_PROFILE_START(&pSVGAState->StatR3Cmd3dDrawPrimitivesProf, a);
4654 rc = vmsvga3dDrawPrimitives(pThis, pCmd->cid, pCmd->numVertexDecls, pVertexDecl, pCmd->numRanges,
4655 pNumRange, cVertexDivisor, pVertexDivisor);
4656 STAM_PROFILE_STOP(&pSVGAState->StatR3Cmd3dDrawPrimitivesProf, a);
4657 break;
4658 }
4659
4660 case SVGA_3D_CMD_SETSCISSORRECT:
4661 {
4662 SVGA3dCmdSetScissorRect *pCmd = (SVGA3dCmdSetScissorRect *)(pHdr + 1);
4663 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4664 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dSetScissorRect);
4665
4666 rc = vmsvga3dSetScissorRect(pThis, pCmd->cid, &pCmd->rect);
4667 break;
4668 }
4669
4670 case SVGA_3D_CMD_BEGIN_QUERY:
4671 {
4672 SVGA3dCmdBeginQuery *pCmd = (SVGA3dCmdBeginQuery *)(pHdr + 1);
4673 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4674 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dBeginQuery);
4675
4676 rc = vmsvga3dQueryBegin(pThis, pCmd->cid, pCmd->type);
4677 break;
4678 }
4679
4680 case SVGA_3D_CMD_END_QUERY:
4681 {
4682 SVGA3dCmdEndQuery *pCmd = (SVGA3dCmdEndQuery *)(pHdr + 1);
4683 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4684 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dEndQuery);
4685
4686 rc = vmsvga3dQueryEnd(pThis, pCmd->cid, pCmd->type, pCmd->guestResult);
4687 break;
4688 }
4689
4690 case SVGA_3D_CMD_WAIT_FOR_QUERY:
4691 {
4692 SVGA3dCmdWaitForQuery *pCmd = (SVGA3dCmdWaitForQuery *)(pHdr + 1);
4693 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4694 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dWaitForQuery);
4695
4696 rc = vmsvga3dQueryWait(pThis, pCmd->cid, pCmd->type, pCmd->guestResult);
4697 break;
4698 }
4699
4700 case SVGA_3D_CMD_GENERATE_MIPMAPS:
4701 {
4702 SVGA3dCmdGenerateMipmaps *pCmd = (SVGA3dCmdGenerateMipmaps *)(pHdr + 1);
4703 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
4704 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dGenerateMipmaps);
4705
4706 rc = vmsvga3dGenerateMipmaps(pThis, pCmd->sid, pCmd->filter);
4707 break;
4708 }
4709
4710 case SVGA_3D_CMD_ACTIVATE_SURFACE:
4711 /* context id + surface id? */
4712 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dActivateSurface);
4713 break;
4714 case SVGA_3D_CMD_DEACTIVATE_SURFACE:
4715 /* context id + surface id? */
4716 STAM_REL_COUNTER_INC(&pSVGAState->StatR3Cmd3dDeactivateSurface);
4717 break;
4718
4719 default:
4720 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoUnkCmds);
4721 AssertMsgFailed(("enmCmdId=%d\n", enmCmdId));
4722 break;
4723 }
4724 }
4725 else
4726# endif // VBOX_WITH_VMSVGA3D
4727 {
4728 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoUnkCmds);
4729 AssertMsgFailed(("enmCmdId=%d\n", enmCmdId));
4730 }
4731 }
4732
4733 /* Go to the next slot */
4734 Assert(cbPayload + sizeof(uint32_t) <= offFifoMax - offFifoMin);
4735 offCurrentCmd += RT_ALIGN_32(cbPayload + sizeof(uint32_t), sizeof(uint32_t));
4736 if (offCurrentCmd >= offFifoMax)
4737 {
4738 offCurrentCmd -= offFifoMax - offFifoMin;
4739 Assert(offCurrentCmd >= offFifoMin);
4740 Assert(offCurrentCmd < offFifoMax);
4741 }
4742 ASMAtomicWriteU32(&pFIFO[SVGA_FIFO_STOP], offCurrentCmd);
4743 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoCommands);
4744
4745 /*
4746 * Raise IRQ if required. Must enter the critical section here
4747 * before making final decisions here, otherwise cubebench and
4748 * others may end up waiting forever.
4749 */
4750 if ( u32IrqStatus
4751 || (pThis->svga.u32IrqMask & SVGA_IRQFLAG_FIFO_PROGRESS))
4752 {
4753 int rc2 = PDMCritSectEnter(&pThis->CritSect, VERR_IGNORED);
4754 AssertRC(rc2);
4755
4756 /* FIFO progress might trigger an interrupt. */
4757 if (pThis->svga.u32IrqMask & SVGA_IRQFLAG_FIFO_PROGRESS)
4758 {
4759 Log(("vmsvgaFIFOLoop: fifo progress irq\n"));
4760 u32IrqStatus |= SVGA_IRQFLAG_FIFO_PROGRESS;
4761 }
4762
4763 /* Unmasked IRQ pending? */
4764 if (pThis->svga.u32IrqMask & u32IrqStatus)
4765 {
4766 Log(("vmsvgaFIFOLoop: Trigger interrupt with status %x\n", u32IrqStatus));
4767 ASMAtomicOrU32(&pThis->svga.u32IrqStatus, u32IrqStatus);
4768 PDMDevHlpPCISetIrq(pDevIns, 0, 1);
4769 }
4770
4771 PDMCritSectLeave(&pThis->CritSect);
4772 }
4773 }
4774
4775 /* If really done, clear the busy flag. */
4776 if (fDone)
4777 {
4778 Log(("vmsvgaFIFOLoop: emptied the FIFO next=%x stop=%x\n", pFIFO[SVGA_FIFO_NEXT_CMD], offCurrentCmd));
4779 vmsvgaFifoSetNotBusy(pThis, pSVGAState, offFifoMin);
4780 }
4781 }
4782
4783 /*
4784 * Free the bounce buffer. (There are no returns above!)
4785 */
4786 RTMemFree(pbBounceBuf);
4787
4788 return VINF_SUCCESS;
4789}
4790
4791/**
4792 * Free the specified GMR
4793 *
4794 * @param pThis VGA device instance data.
4795 * @param idGMR GMR id
4796 */
4797void vmsvgaGMRFree(PVGASTATE pThis, uint32_t idGMR)
4798{
4799 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
4800
4801 /* Free the old descriptor if present. */
4802 PGMR pGMR = &pSVGAState->paGMR[idGMR];
4803 if ( pGMR->numDescriptors
4804 || pGMR->paDesc /* needed till we implement SVGA_REMAP_GMR2_VIA_GMR */)
4805 {
4806# ifdef DEBUG_GMR_ACCESS
4807 VMR3ReqCallWaitU(PDMDevHlpGetUVM(pThis->pDevInsR3), VMCPUID_ANY, (PFNRT)vmsvgaDeregisterGMR, 2, pThis->pDevInsR3, idGMR);
4808# endif
4809
4810 Assert(pGMR->paDesc);
4811 RTMemFree(pGMR->paDesc);
4812 pGMR->paDesc = NULL;
4813 pGMR->numDescriptors = 0;
4814 pGMR->cbTotal = 0;
4815 pGMR->cMaxPages = 0;
4816 }
4817 Assert(!pGMR->cMaxPages);
4818 Assert(!pGMR->cbTotal);
4819}
4820
4821/**
4822 * Copy between a GMR and a host memory buffer.
4823 *
4824 * @returns VBox status code.
4825 * @param pThis VGA device instance data.
4826 * @param enmTransferType Transfer type (read/write)
4827 * @param pbHstBuf Host buffer pointer (valid)
4828 * @param cbHstBuf Size of host buffer (valid)
4829 * @param offHst Host buffer offset of the first scanline
4830 * @param cbHstPitch Destination buffer pitch
4831 * @param gstPtr GMR description
4832 * @param offGst Guest buffer offset of the first scanline
4833 * @param cbGstPitch Guest buffer pitch
4834 * @param cbWidth Width in bytes to copy
4835 * @param cHeight Number of scanllines to copy
4836 */
4837int vmsvgaGMRTransfer(PVGASTATE pThis, const SVGA3dTransferType enmTransferType,
4838 uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
4839 SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
4840 uint32_t cbWidth, uint32_t cHeight)
4841{
4842 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
4843 int rc;
4844
4845 LogFunc(("%s host %p size=%d offset %d pitch=%d; guest gmr=%#x:%#x offset=%d pitch=%d cbWidth=%d cHeight=%d\n",
4846 enmTransferType == SVGA3D_READ_HOST_VRAM ? "WRITE" : "READ", /* GMR op: READ host VRAM means WRITE GMR */
4847 pbHstBuf, cbHstBuf, offHst, cbHstPitch,
4848 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cbWidth, cHeight));
4849 AssertReturn(cbWidth && cHeight, VERR_INVALID_PARAMETER);
4850
4851 PGMR pGMR;
4852 uint32_t cbGmr; /* The GMR size in bytes. */
4853 if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
4854 {
4855 pGMR = NULL;
4856 cbGmr = pThis->vram_size;
4857 }
4858 else
4859 {
4860 AssertReturn(gstPtr.gmrId < pThis->svga.cGMR, VERR_INVALID_PARAMETER);
4861 RT_UNTRUSTED_VALIDATED_FENCE();
4862 pGMR = &pSVGAState->paGMR[gstPtr.gmrId];
4863 cbGmr = pGMR->cbTotal;
4864 }
4865
4866 /*
4867 * GMR
4868 */
4869 /* Calculate GMR offset of the data to be copied. */
4870 AssertMsgReturn(gstPtr.offset < cbGmr,
4871 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
4872 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
4873 VERR_INVALID_PARAMETER);
4874 RT_UNTRUSTED_VALIDATED_FENCE();
4875 AssertMsgReturn(offGst < cbGmr - gstPtr.offset,
4876 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
4877 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
4878 VERR_INVALID_PARAMETER);
4879 RT_UNTRUSTED_VALIDATED_FENCE();
4880 uint32_t const offGmr = offGst + gstPtr.offset; /* Offset in the GMR, where the first scanline is located. */
4881
4882 /* Verify that cbWidth is less than scanline and fits into the GMR. */
4883 uint32_t const cbGmrScanline = cbGstPitch > 0 ? cbGstPitch : -cbGstPitch;
4884 AssertMsgReturn(cbGmrScanline != 0,
4885 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
4886 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
4887 VERR_INVALID_PARAMETER);
4888 RT_UNTRUSTED_VALIDATED_FENCE();
4889 AssertMsgReturn(cbWidth <= cbGmrScanline,
4890 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
4891 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
4892 VERR_INVALID_PARAMETER);
4893 AssertMsgReturn(cbWidth <= cbGmr - offGmr,
4894 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
4895 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
4896 VERR_INVALID_PARAMETER);
4897 RT_UNTRUSTED_VALIDATED_FENCE();
4898
4899 /* How many bytes are available for the data in the GMR. */
4900 uint32_t const cbGmrLeft = cbGstPitch > 0 ? cbGmr - offGmr : offGmr + cbWidth;
4901
4902 /* How many scanlines would fit into the available data. */
4903 uint32_t cGmrScanlines = cbGmrLeft / cbGmrScanline;
4904 uint32_t const cbGmrLastScanline = cbGmrLeft - cGmrScanlines * cbGmrScanline; /* Slack space. */
4905 if (cbWidth <= cbGmrLastScanline)
4906 ++cGmrScanlines;
4907
4908 if (cHeight > cGmrScanlines)
4909 cHeight = cGmrScanlines;
4910
4911 AssertMsgReturn(cHeight > 0,
4912 ("gmr=%#x:%#x offGst=%#x cbGstPitch=%#x cHeight=%#x cbWidth=%#x cbGmr=%#x\n",
4913 gstPtr.gmrId, gstPtr.offset, offGst, cbGstPitch, cHeight, cbWidth, cbGmr),
4914 VERR_INVALID_PARAMETER);
4915 RT_UNTRUSTED_VALIDATED_FENCE();
4916
4917 /*
4918 * Host buffer.
4919 */
4920 AssertMsgReturn(offHst < cbHstBuf,
4921 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
4922 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
4923 VERR_INVALID_PARAMETER);
4924
4925 /* Verify that cbWidth is less than scanline and fits into the buffer. */
4926 uint32_t const cbHstScanline = cbHstPitch > 0 ? cbHstPitch : -cbHstPitch;
4927 AssertMsgReturn(cbHstScanline != 0,
4928 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
4929 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
4930 VERR_INVALID_PARAMETER);
4931 AssertMsgReturn(cbWidth <= cbHstScanline,
4932 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
4933 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
4934 VERR_INVALID_PARAMETER);
4935 AssertMsgReturn(cbWidth <= cbHstBuf - offHst,
4936 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
4937 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
4938 VERR_INVALID_PARAMETER);
4939
4940 /* How many bytes are available for the data in the buffer. */
4941 uint32_t const cbHstLeft = cbHstPitch > 0 ? cbHstBuf - offHst : offHst + cbWidth;
4942
4943 /* How many scanlines would fit into the available data. */
4944 uint32_t cHstScanlines = cbHstLeft / cbHstScanline;
4945 uint32_t const cbHstLastScanline = cbHstLeft - cHstScanlines * cbHstScanline; /* Slack space. */
4946 if (cbWidth <= cbHstLastScanline)
4947 ++cHstScanlines;
4948
4949 if (cHeight > cHstScanlines)
4950 cHeight = cHstScanlines;
4951
4952 AssertMsgReturn(cHeight > 0,
4953 ("buffer=%p size %d offHst=%d cbHstPitch=%d cHeight=%d cbWidth=%d\n",
4954 pbHstBuf, cbHstBuf, offHst, cbHstPitch, cHeight, cbWidth),
4955 VERR_INVALID_PARAMETER);
4956
4957 uint8_t *pbHst = pbHstBuf + offHst;
4958
4959 /* Shortcut for the framebuffer. */
4960 if (gstPtr.gmrId == SVGA_GMR_FRAMEBUFFER)
4961 {
4962 uint8_t *pbGst = pThis->CTX_SUFF(vram_ptr) + offGmr;
4963
4964 uint8_t const *pbSrc;
4965 int32_t cbSrcPitch;
4966 uint8_t *pbDst;
4967 int32_t cbDstPitch;
4968
4969 if (enmTransferType == SVGA3D_READ_HOST_VRAM)
4970 {
4971 pbSrc = pbHst;
4972 cbSrcPitch = cbHstPitch;
4973 pbDst = pbGst;
4974 cbDstPitch = cbGstPitch;
4975 }
4976 else
4977 {
4978 pbSrc = pbGst;
4979 cbSrcPitch = cbGstPitch;
4980 pbDst = pbHst;
4981 cbDstPitch = cbHstPitch;
4982 }
4983
4984 if ( cbWidth == (uint32_t)cbGstPitch
4985 && cbGstPitch == cbHstPitch)
4986 {
4987 /* Entire scanlines, positive pitch. */
4988 memcpy(pbDst, pbSrc, cbWidth * cHeight);
4989 }
4990 else
4991 {
4992 for (uint32_t i = 0; i < cHeight; ++i)
4993 {
4994 memcpy(pbDst, pbSrc, cbWidth);
4995
4996 pbDst += cbDstPitch;
4997 pbSrc += cbSrcPitch;
4998 }
4999 }
5000 return VINF_SUCCESS;
5001 }
5002
5003 AssertPtrReturn(pGMR, VERR_INVALID_PARAMETER);
5004 AssertReturn(pGMR->numDescriptors > 0, VERR_INVALID_PARAMETER);
5005
5006 PVMSVGAGMRDESCRIPTOR const paDesc = pGMR->paDesc; /* Local copy of the pointer. */
5007 uint32_t iDesc = 0; /* Index in the descriptor array. */
5008 uint32_t offDesc = 0; /* GMR offset of the current descriptor. */
5009 uint32_t offGmrScanline = offGmr; /* GMR offset of the scanline which is being copied. */
5010 uint8_t *pbHstScanline = pbHst; /* Host address of the scanline which is being copied. */
5011 for (uint32_t i = 0; i < cHeight; ++i)
5012 {
5013 uint32_t cbCurrentWidth = cbWidth;
5014 uint32_t offGmrCurrent = offGmrScanline;
5015 uint8_t *pbCurrentHost = pbHstScanline;
5016
5017 /* Find the right descriptor */
5018 while (offDesc + paDesc[iDesc].numPages * PAGE_SIZE <= offGmrCurrent)
5019 {
5020 offDesc += paDesc[iDesc].numPages * PAGE_SIZE;
5021 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR); /* overflow protection */
5022 ++iDesc;
5023 AssertReturn(iDesc < pGMR->numDescriptors, VERR_INTERNAL_ERROR);
5024 }
5025
5026 while (cbCurrentWidth)
5027 {
5028 uint32_t cbToCopy;
5029
5030 if (offGmrCurrent + cbCurrentWidth <= offDesc + paDesc[iDesc].numPages * PAGE_SIZE)
5031 {
5032 cbToCopy = cbCurrentWidth;
5033 }
5034 else
5035 {
5036 cbToCopy = (offDesc + paDesc[iDesc].numPages * PAGE_SIZE - offGmrCurrent);
5037 AssertReturn(cbToCopy <= cbCurrentWidth, VERR_INVALID_PARAMETER);
5038 }
5039
5040 RTGCPHYS const GCPhys = paDesc[iDesc].GCPhys + offGmrCurrent - offDesc;
5041
5042 LogFlowFunc(("%s phys=%RGp\n", (enmTransferType == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", GCPhys));
5043
5044 if (enmTransferType == SVGA3D_WRITE_HOST_VRAM)
5045 rc = PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCPhys, pbCurrentHost, cbToCopy);
5046 else
5047 rc = PDMDevHlpPhysWrite(pThis->CTX_SUFF(pDevIns), GCPhys, pbCurrentHost, cbToCopy);
5048 AssertRCBreak(rc);
5049
5050 cbCurrentWidth -= cbToCopy;
5051 offGmrCurrent += cbToCopy;
5052 pbCurrentHost += cbToCopy;
5053
5054 /* Go to the next descriptor if there's anything left. */
5055 if (cbCurrentWidth)
5056 {
5057 offDesc += paDesc[iDesc].numPages * PAGE_SIZE;
5058 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR);
5059 ++iDesc;
5060 AssertReturn(iDesc < pGMR->numDescriptors, VERR_INTERNAL_ERROR);
5061 }
5062 }
5063
5064 offGmrScanline += cbGstPitch;
5065 pbHstScanline += cbHstPitch;
5066 }
5067
5068 return VINF_SUCCESS;
5069}
5070
5071
5072/**
5073 * Unsigned coordinates in pBox. Clip to [0; pSizeSrc), [0; pSizeDest).
5074 *
5075 * @param pSizeSrc Source surface dimensions.
5076 * @param pSizeDest Destination surface dimensions.
5077 * @param pBox Coordinates to be clipped.
5078 */
5079void vmsvgaClipCopyBox(const SVGA3dSize *pSizeSrc,
5080 const SVGA3dSize *pSizeDest,
5081 SVGA3dCopyBox *pBox)
5082{
5083 /* Src x, w */
5084 if (pBox->srcx > pSizeSrc->width)
5085 pBox->srcx = pSizeSrc->width;
5086 if (pBox->w > pSizeSrc->width - pBox->srcx)
5087 pBox->w = pSizeSrc->width - pBox->srcx;
5088
5089 /* Src y, h */
5090 if (pBox->srcy > pSizeSrc->height)
5091 pBox->srcy = pSizeSrc->height;
5092 if (pBox->h > pSizeSrc->height - pBox->srcy)
5093 pBox->h = pSizeSrc->height - pBox->srcy;
5094
5095 /* Src z, d */
5096 if (pBox->srcz > pSizeSrc->depth)
5097 pBox->srcz = pSizeSrc->depth;
5098 if (pBox->d > pSizeSrc->depth - pBox->srcz)
5099 pBox->d = pSizeSrc->depth - pBox->srcz;
5100
5101 /* Dest x, w */
5102 if (pBox->x > pSizeDest->width)
5103 pBox->x = pSizeDest->width;
5104 if (pBox->w > pSizeDest->width - pBox->x)
5105 pBox->w = pSizeDest->width - pBox->x;
5106
5107 /* Dest y, h */
5108 if (pBox->y > pSizeDest->height)
5109 pBox->y = pSizeDest->height;
5110 if (pBox->h > pSizeDest->height - pBox->y)
5111 pBox->h = pSizeDest->height - pBox->y;
5112
5113 /* Dest z, d */
5114 if (pBox->z > pSizeDest->depth)
5115 pBox->z = pSizeDest->depth;
5116 if (pBox->d > pSizeDest->depth - pBox->z)
5117 pBox->d = pSizeDest->depth - pBox->z;
5118}
5119
5120/**
5121 * Unsigned coordinates in pBox. Clip to [0; pSize).
5122 *
5123 * @param pSize Source surface dimensions.
5124 * @param pBox Coordinates to be clipped.
5125 */
5126void vmsvgaClipBox(const SVGA3dSize *pSize,
5127 SVGA3dBox *pBox)
5128{
5129 /* x, w */
5130 if (pBox->x > pSize->width)
5131 pBox->x = pSize->width;
5132 if (pBox->w > pSize->width - pBox->x)
5133 pBox->w = pSize->width - pBox->x;
5134
5135 /* y, h */
5136 if (pBox->y > pSize->height)
5137 pBox->y = pSize->height;
5138 if (pBox->h > pSize->height - pBox->y)
5139 pBox->h = pSize->height - pBox->y;
5140
5141 /* z, d */
5142 if (pBox->z > pSize->depth)
5143 pBox->z = pSize->depth;
5144 if (pBox->d > pSize->depth - pBox->z)
5145 pBox->d = pSize->depth - pBox->z;
5146}
5147
5148/**
5149 * Clip.
5150 *
5151 * @param pBound Bounding rectangle.
5152 * @param pRect Rectangle to be clipped.
5153 */
5154void vmsvgaClipRect(SVGASignedRect const *pBound,
5155 SVGASignedRect *pRect)
5156{
5157 int32_t left;
5158 int32_t top;
5159 int32_t right;
5160 int32_t bottom;
5161
5162 /* Right order. */
5163 Assert(pBound->left <= pBound->right && pBound->top <= pBound->bottom);
5164 if (pRect->left < pRect->right)
5165 {
5166 left = pRect->left;
5167 right = pRect->right;
5168 }
5169 else
5170 {
5171 left = pRect->right;
5172 right = pRect->left;
5173 }
5174 if (pRect->top < pRect->bottom)
5175 {
5176 top = pRect->top;
5177 bottom = pRect->bottom;
5178 }
5179 else
5180 {
5181 top = pRect->bottom;
5182 bottom = pRect->top;
5183 }
5184
5185 if (left < pBound->left)
5186 left = pBound->left;
5187 if (right < pBound->left)
5188 right = pBound->left;
5189
5190 if (left > pBound->right)
5191 left = pBound->right;
5192 if (right > pBound->right)
5193 right = pBound->right;
5194
5195 if (top < pBound->top)
5196 top = pBound->top;
5197 if (bottom < pBound->top)
5198 bottom = pBound->top;
5199
5200 if (top > pBound->bottom)
5201 top = pBound->bottom;
5202 if (bottom > pBound->bottom)
5203 bottom = pBound->bottom;
5204
5205 pRect->left = left;
5206 pRect->right = right;
5207 pRect->top = top;
5208 pRect->bottom = bottom;
5209}
5210
5211/**
5212 * Unblock the FIFO I/O thread so it can respond to a state change.
5213 *
5214 * @returns VBox status code.
5215 * @param pDevIns The VGA device instance.
5216 * @param pThread The send thread.
5217 */
5218static DECLCALLBACK(int) vmsvgaFIFOLoopWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
5219{
5220 RT_NOREF(pDevIns);
5221 PVGASTATE pThis = (PVGASTATE)pThread->pvUser;
5222 Log(("vmsvgaFIFOLoopWakeUp\n"));
5223 return SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
5224}
5225
5226/**
5227 * Enables or disables dirty page tracking for the framebuffer
5228 *
5229 * @param pThis VGA device instance data.
5230 * @param fTraces Enable/disable traces
5231 */
5232static void vmsvgaSetTraces(PVGASTATE pThis, bool fTraces)
5233{
5234 if ( (!pThis->svga.fConfigured || !pThis->svga.fEnabled)
5235 && !fTraces)
5236 {
5237 //Assert(pThis->svga.fTraces);
5238 Log(("vmsvgaSetTraces: *not* allowed to disable dirty page tracking when the device is in legacy mode.\n"));
5239 return;
5240 }
5241
5242 pThis->svga.fTraces = fTraces;
5243 if (pThis->svga.fTraces)
5244 {
5245 unsigned cbFrameBuffer = pThis->vram_size;
5246
5247 Log(("vmsvgaSetTraces: enable dirty page handling for the frame buffer only (%x bytes)\n", 0));
5248 /** @todo How does this work with screens? */
5249 if (pThis->svga.uHeight != VMSVGA_VAL_UNINITIALIZED)
5250 {
5251#ifndef DEBUG_bird /* BB-10.3.1 triggers this as it initializes everything to zero. Better just ignore it. */
5252 Assert(pThis->svga.cbScanline);
5253#endif
5254 /* Hardware enabled; return real framebuffer size .*/
5255 cbFrameBuffer = (uint32_t)pThis->svga.uHeight * pThis->svga.cbScanline;
5256 cbFrameBuffer = RT_ALIGN(cbFrameBuffer, PAGE_SIZE);
5257 }
5258
5259 if (!pThis->svga.fVRAMTracking)
5260 {
5261 Log(("vmsvgaSetTraces: enable frame buffer dirty page tracking. (%x bytes; vram %x)\n", cbFrameBuffer, pThis->vram_size));
5262 vgaR3RegisterVRAMHandler(pThis, cbFrameBuffer);
5263 pThis->svga.fVRAMTracking = true;
5264 }
5265 }
5266 else
5267 {
5268 if (pThis->svga.fVRAMTracking)
5269 {
5270 Log(("vmsvgaSetTraces: disable frame buffer dirty page tracking\n"));
5271 vgaR3UnregisterVRAMHandler(pThis);
5272 pThis->svga.fVRAMTracking = false;
5273 }
5274 }
5275}
5276
5277/**
5278 * @callback_method_impl{FNPCIIOREGIONMAP}
5279 */
5280DECLCALLBACK(int) vmsvgaR3IORegionMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
5281 RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
5282{
5283 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
5284 int rc;
5285 RT_NOREF(pPciDev);
5286 Assert(pPciDev == pDevIns->apPciDevs[0]);
5287
5288 Log(("vgasvgaR3IORegionMap: iRegion=%d GCPhysAddress=%RGp cb=%RGp enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
5289 if (enmType == PCI_ADDRESS_SPACE_IO)
5290 {
5291 AssertReturn(iRegion == pThis->pciRegions.iIO, VERR_INTERNAL_ERROR);
5292 rc = PDMDevHlpIOPortRegister(pDevIns, (RTIOPORT)GCPhysAddress, cb, 0,
5293 vmsvgaIOWrite, vmsvgaIORead, NULL /* OutStr */, NULL /* InStr */, "VMSVGA");
5294 if (RT_FAILURE(rc))
5295 return rc;
5296 if (pThis->fR0Enabled)
5297 {
5298 rc = PDMDevHlpIOPortRegisterR0(pDevIns, (RTIOPORT)GCPhysAddress, cb, 0,
5299 "vmsvgaIOWrite", "vmsvgaIORead", NULL, NULL, "VMSVGA");
5300 if (RT_FAILURE(rc))
5301 return rc;
5302 }
5303 if (pThis->fGCEnabled)
5304 {
5305 rc = PDMDevHlpIOPortRegisterRC(pDevIns, (RTIOPORT)GCPhysAddress, cb, 0,
5306 "vmsvgaIOWrite", "vmsvgaIORead", NULL, NULL, "VMSVGA");
5307 if (RT_FAILURE(rc))
5308 return rc;
5309 }
5310
5311 pThis->svga.BasePort = GCPhysAddress;
5312 Log(("vmsvgaR3IORegionMap: base port = %x\n", pThis->svga.BasePort));
5313 }
5314 else
5315 {
5316 AssertReturn(iRegion == pThis->pciRegions.iFIFO && enmType == PCI_ADDRESS_SPACE_MEM, VERR_INTERNAL_ERROR);
5317 if (GCPhysAddress != NIL_RTGCPHYS)
5318 {
5319 /*
5320 * Mapping the FIFO RAM.
5321 */
5322 AssertLogRelMsg(cb == pThis->svga.cbFIFO, ("cb=%#RGp cbFIFO=%#x\n", cb, pThis->svga.cbFIFO));
5323 rc = PDMDevHlpMMIOExMap(pDevIns, pPciDev, iRegion, GCPhysAddress);
5324 AssertRC(rc);
5325
5326# if defined(VMSVGA_USE_FIFO_ACCESS_HANDLER) || defined(DEBUG_FIFO_ACCESS)
5327 if (RT_SUCCESS(rc))
5328 {
5329 rc = PGMHandlerPhysicalRegister(PDMDevHlpGetVM(pDevIns), GCPhysAddress,
5330# ifdef DEBUG_FIFO_ACCESS
5331 GCPhysAddress + (pThis->svga.cbFIFO - 1),
5332# else
5333 GCPhysAddress + PAGE_SIZE - 1,
5334# endif
5335 pThis->svga.hFifoAccessHandlerType, pThis, NIL_RTR0PTR, NIL_RTRCPTR,
5336 "VMSVGA FIFO");
5337 AssertRC(rc);
5338 }
5339# endif
5340 if (RT_SUCCESS(rc))
5341 {
5342 pThis->svga.GCPhysFIFO = GCPhysAddress;
5343 Log(("vmsvgaR3IORegionMap: GCPhysFIFO=%RGp cbFIFO=%#x\n", GCPhysAddress, pThis->svga.cbFIFO));
5344 }
5345 }
5346 else
5347 {
5348 Assert(pThis->svga.GCPhysFIFO);
5349# if defined(VMSVGA_USE_FIFO_ACCESS_HANDLER) || defined(DEBUG_FIFO_ACCESS)
5350 rc = PGMHandlerPhysicalDeregister(PDMDevHlpGetVM(pDevIns), pThis->svga.GCPhysFIFO);
5351 AssertRC(rc);
5352# endif
5353 pThis->svga.GCPhysFIFO = 0;
5354 }
5355 }
5356 return VINF_SUCCESS;
5357}
5358
5359# ifdef VBOX_WITH_VMSVGA3D
5360
5361/**
5362 * Used by vmsvga3dInfoSurfaceWorker to make the FIFO thread to save one or all
5363 * surfaces to VMSVGA3DMIPMAPLEVEL::pSurfaceData heap buffers.
5364 *
5365 * @param pThis The VGA device instance data.
5366 * @param sid Either UINT32_MAX or the ID of a specific
5367 * surface. If UINT32_MAX is used, all surfaces
5368 * are processed.
5369 */
5370void vmsvga3dSurfaceUpdateHeapBuffersOnFifoThread(PVGASTATE pThis, uint32_t sid)
5371{
5372 vmsvgaR3RunExtCmdOnFifoThread(pThis, VMSVGA_FIFO_EXTCMD_UPDATE_SURFACE_HEAP_BUFFERS, (void *)(uintptr_t)sid,
5373 sid == UINT32_MAX ? 10 * RT_MS_1SEC : RT_MS_1MIN);
5374}
5375
5376
5377/**
5378 * @callback_method_impl{FNDBGFHANDLERDEV, "vmsvga3dsfc"}
5379 */
5380DECLCALLBACK(void) vmsvgaR3Info3dSurface(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
5381{
5382 /* There might be a specific surface ID at the start of the
5383 arguments, if not show all surfaces. */
5384 uint32_t sid = UINT32_MAX;
5385 if (pszArgs)
5386 pszArgs = RTStrStripL(pszArgs);
5387 if (pszArgs && RT_C_IS_DIGIT(*pszArgs))
5388 sid = RTStrToUInt32(pszArgs);
5389
5390 /* Verbose or terse display, we default to verbose. */
5391 bool fVerbose = true;
5392 if (RTStrIStr(pszArgs, "terse"))
5393 fVerbose = false;
5394
5395 /* The size of the ascii art (x direction, y is 3/4 of x). */
5396 uint32_t cxAscii = 80;
5397 if (RTStrIStr(pszArgs, "gigantic"))
5398 cxAscii = 300;
5399 else if (RTStrIStr(pszArgs, "huge"))
5400 cxAscii = 180;
5401 else if (RTStrIStr(pszArgs, "big"))
5402 cxAscii = 132;
5403 else if (RTStrIStr(pszArgs, "normal"))
5404 cxAscii = 80;
5405 else if (RTStrIStr(pszArgs, "medium"))
5406 cxAscii = 64;
5407 else if (RTStrIStr(pszArgs, "small"))
5408 cxAscii = 48;
5409 else if (RTStrIStr(pszArgs, "tiny"))
5410 cxAscii = 24;
5411
5412 /* Y invert the image when producing the ASCII art. */
5413 bool fInvY = false;
5414 if (RTStrIStr(pszArgs, "invy"))
5415 fInvY = true;
5416
5417 vmsvga3dInfoSurfaceWorker(PDMINS_2_DATA(pDevIns, PVGASTATE), pHlp, sid, fVerbose, cxAscii, fInvY, NULL);
5418}
5419
5420
5421/**
5422 * @callback_method_impl{FNDBGFHANDLERDEV, "vmsvga3dsurf"}
5423 */
5424DECLCALLBACK(void) vmsvgaR3Info3dSurfaceBmp(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
5425{
5426 /* pszArg = "sid[>dir]"
5427 * Writes %dir%/info-S-sidI.bmp, where S - sequential bitmap number, I - decimal surface id.
5428 */
5429 char *pszBitmapPath = NULL;
5430 uint32_t sid = UINT32_MAX;
5431 if (pszArgs)
5432 pszArgs = RTStrStripL(pszArgs);
5433 if (pszArgs && RT_C_IS_DIGIT(*pszArgs))
5434 RTStrToUInt32Ex(pszArgs, &pszBitmapPath, 0, &sid);
5435 if ( pszBitmapPath
5436 && *pszBitmapPath == '>')
5437 ++pszBitmapPath;
5438
5439 const bool fVerbose = true;
5440 const uint32_t cxAscii = 0; /* No ASCII */
5441 const bool fInvY = false; /* Do not invert. */
5442 vmsvga3dInfoSurfaceWorker(PDMINS_2_DATA(pDevIns, PVGASTATE), pHlp, sid, fVerbose, cxAscii, fInvY, pszBitmapPath);
5443}
5444
5445
5446/**
5447 * @callback_method_impl{FNDBGFHANDLERDEV, "vmsvga3dctx"}
5448 */
5449DECLCALLBACK(void) vmsvgaR3Info3dContext(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
5450{
5451 /* There might be a specific surface ID at the start of the
5452 arguments, if not show all contexts. */
5453 uint32_t sid = UINT32_MAX;
5454 if (pszArgs)
5455 pszArgs = RTStrStripL(pszArgs);
5456 if (pszArgs && RT_C_IS_DIGIT(*pszArgs))
5457 sid = RTStrToUInt32(pszArgs);
5458
5459 /* Verbose or terse display, we default to verbose. */
5460 bool fVerbose = true;
5461 if (RTStrIStr(pszArgs, "terse"))
5462 fVerbose = false;
5463
5464 vmsvga3dInfoContextWorker(PDMINS_2_DATA(pDevIns, PVGASTATE), pHlp, sid, fVerbose);
5465}
5466
5467# endif /* VBOX_WITH_VMSVGA3D */
5468
5469/**
5470 * @callback_method_impl{FNDBGFHANDLERDEV, "vmsvga"}
5471 */
5472static DECLCALLBACK(void) vmsvgaR3Info(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
5473{
5474 RT_NOREF(pszArgs);
5475 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
5476 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
5477 uint32_t RT_UNTRUSTED_VOLATILE_GUEST *pFIFO = pThis->svga.pFIFOR3;
5478
5479 pHlp->pfnPrintf(pHlp, "Extension enabled: %RTbool\n", pThis->svga.fEnabled);
5480 pHlp->pfnPrintf(pHlp, "Configured: %RTbool\n", pThis->svga.fConfigured);
5481 pHlp->pfnPrintf(pHlp, "Base I/O port: %#x\n", pThis->svga.BasePort);
5482 pHlp->pfnPrintf(pHlp, "FIFO address: %RGp\n", pThis->svga.GCPhysFIFO);
5483 pHlp->pfnPrintf(pHlp, "FIFO size: %u (%#x)\n", pThis->svga.cbFIFO, pThis->svga.cbFIFO);
5484 pHlp->pfnPrintf(pHlp, "FIFO external cmd: %#x\n", pThis->svga.u8FIFOExtCommand);
5485 pHlp->pfnPrintf(pHlp, "FIFO extcmd wakeup: %u\n", pThis->svga.fFifoExtCommandWakeup);
5486 pHlp->pfnPrintf(pHlp, "FIFO min/max: %u/%u\n", pFIFO[SVGA_FIFO_MIN], pFIFO[SVGA_FIFO_MAX]);
5487 pHlp->pfnPrintf(pHlp, "Busy: %#x\n", pThis->svga.fBusy);
5488 pHlp->pfnPrintf(pHlp, "Traces: %RTbool (effective: %RTbool)\n", pThis->svga.fTraces, pThis->svga.fVRAMTracking);
5489 pHlp->pfnPrintf(pHlp, "Guest ID: %#x (%d)\n", pThis->svga.u32GuestId, pThis->svga.u32GuestId);
5490 pHlp->pfnPrintf(pHlp, "IRQ status: %#x\n", pThis->svga.u32IrqStatus);
5491 pHlp->pfnPrintf(pHlp, "IRQ mask: %#x\n", pThis->svga.u32IrqMask);
5492 pHlp->pfnPrintf(pHlp, "Pitch lock: %#x (FIFO:%#x)\n", pThis->svga.u32PitchLock, pFIFO[SVGA_FIFO_PITCHLOCK]);
5493 pHlp->pfnPrintf(pHlp, "Current GMR ID: %#x\n", pThis->svga.u32CurrentGMRId);
5494 pHlp->pfnPrintf(pHlp, "Capabilites reg: %#x\n", pThis->svga.u32RegCaps);
5495 pHlp->pfnPrintf(pHlp, "Index reg: %#x\n", pThis->svga.u32IndexReg);
5496 pHlp->pfnPrintf(pHlp, "Action flags: %#x\n", pThis->svga.u32ActionFlags);
5497 pHlp->pfnPrintf(pHlp, "Max display size: %ux%u\n", pThis->svga.u32MaxWidth, pThis->svga.u32MaxHeight);
5498 pHlp->pfnPrintf(pHlp, "Display size: %ux%u %ubpp\n", pThis->svga.uWidth, pThis->svga.uHeight, pThis->svga.uBpp);
5499 pHlp->pfnPrintf(pHlp, "Scanline: %u (%#x)\n", pThis->svga.cbScanline, pThis->svga.cbScanline);
5500 pHlp->pfnPrintf(pHlp, "Viewport position: %ux%u\n", pThis->svga.viewport.x, pThis->svga.viewport.y);
5501 pHlp->pfnPrintf(pHlp, "Viewport size: %ux%u\n", pThis->svga.viewport.cx, pThis->svga.viewport.cy);
5502
5503 pHlp->pfnPrintf(pHlp, "Cursor active: %RTbool\n", pSVGAState->Cursor.fActive);
5504 pHlp->pfnPrintf(pHlp, "Cursor hotspot: %ux%u\n", pSVGAState->Cursor.xHotspot, pSVGAState->Cursor.yHotspot);
5505 pHlp->pfnPrintf(pHlp, "Cursor size: %ux%u\n", pSVGAState->Cursor.width, pSVGAState->Cursor.height);
5506 pHlp->pfnPrintf(pHlp, "Cursor byte size: %u (%#x)\n", pSVGAState->Cursor.cbData, pSVGAState->Cursor.cbData);
5507
5508# ifdef VBOX_WITH_VMSVGA3D
5509 pHlp->pfnPrintf(pHlp, "3D enabled: %RTbool\n", pThis->svga.f3DEnabled);
5510# endif
5511 if (pThis->pDrv)
5512 {
5513 pHlp->pfnPrintf(pHlp, "Driver mode: %ux%u %ubpp\n", pThis->pDrv->cx, pThis->pDrv->cy, pThis->pDrv->cBits);
5514 pHlp->pfnPrintf(pHlp, "Driver pitch: %u (%#x)\n", pThis->pDrv->cbScanline, pThis->pDrv->cbScanline);
5515 }
5516}
5517
5518/** Portion of VMSVGA state which must be loaded oin the FIFO thread.
5519 */
5520static int vmsvgaLoadExecFifo(PVGASTATE pThis, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
5521{
5522 RT_NOREF(uPass);
5523
5524 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
5525 int rc;
5526
5527 if (uVersion >= VGA_SAVEDSTATE_VERSION_VMSVGA_SCREENS)
5528 {
5529 uint32_t cScreens = 0;
5530 rc = SSMR3GetU32(pSSM, &cScreens);
5531 AssertRCReturn(rc, rc);
5532 AssertLogRelMsgReturn(cScreens <= _64K, /* big enough */
5533 ("cScreens=%#x\n", cScreens),
5534 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
5535
5536 for (uint32_t i = 0; i < cScreens; ++i)
5537 {
5538 VMSVGASCREENOBJECT screen;
5539 RT_ZERO(screen);
5540
5541 rc = SSMR3GetStructEx(pSSM, &screen, sizeof(screen), 0, g_aVMSVGASCREENOBJECTFields, NULL);
5542 AssertLogRelRCReturn(rc, rc);
5543
5544 if (screen.idScreen < RT_ELEMENTS(pSVGAState->aScreens))
5545 {
5546 VMSVGASCREENOBJECT *pScreen = &pSVGAState->aScreens[screen.idScreen];
5547 *pScreen = screen;
5548 pScreen->fModified = true;
5549 }
5550 else
5551 {
5552 LogRel(("VGA: ignored screen object %d\n", screen.idScreen));
5553 }
5554 }
5555 }
5556 else
5557 {
5558 /* Try to setup at least the first screen. */
5559 VMSVGASCREENOBJECT *pScreen = &pSVGAState->aScreens[0];
5560 pScreen->fDefined = true;
5561 pScreen->fModified = true;
5562 pScreen->fuScreen = SVGA_SCREEN_MUST_BE_SET | SVGA_SCREEN_IS_PRIMARY;
5563 pScreen->idScreen = 0;
5564 pScreen->xOrigin = 0;
5565 pScreen->yOrigin = 0;
5566 pScreen->offVRAM = pThis->svga.uScreenOffset;
5567 pScreen->cbPitch = pThis->svga.cbScanline;
5568 pScreen->cWidth = pThis->svga.uWidth;
5569 pScreen->cHeight = pThis->svga.uHeight;
5570 pScreen->cBpp = pThis->svga.uBpp;
5571 }
5572
5573 return VINF_SUCCESS;
5574}
5575
5576/**
5577 * @copydoc FNSSMDEVLOADEXEC
5578 */
5579int vmsvgaLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
5580{
5581 RT_NOREF(uPass);
5582 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
5583 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
5584 int rc;
5585
5586 /* Load our part of the VGAState */
5587 rc = SSMR3GetStructEx(pSSM, &pThis->svga, sizeof(pThis->svga), 0, g_aVGAStateSVGAFields, NULL);
5588 AssertRCReturn(rc, rc);
5589
5590 /* Load the VGA framebuffer. */
5591 AssertCompile(VMSVGA_VGA_FB_BACKUP_SIZE >= _32K);
5592 uint32_t cbVgaFramebuffer = _32K;
5593 if (uVersion >= VGA_SAVEDSTATE_VERSION_VMSVGA_VGA_FB_FIX)
5594 {
5595 rc = SSMR3GetU32(pSSM, &cbVgaFramebuffer);
5596 AssertRCReturn(rc, rc);
5597 AssertLogRelMsgReturn(cbVgaFramebuffer <= _4M && cbVgaFramebuffer >= _32K && RT_IS_POWER_OF_TWO(cbVgaFramebuffer),
5598 ("cbVgaFramebuffer=%#x - expected 32KB..4MB, power of two\n", cbVgaFramebuffer),
5599 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
5600 AssertCompile(VMSVGA_VGA_FB_BACKUP_SIZE <= _4M);
5601 AssertCompile(RT_IS_POWER_OF_TWO(VMSVGA_VGA_FB_BACKUP_SIZE));
5602 }
5603 rc = SSMR3GetMem(pSSM, pThis->svga.pbVgaFrameBufferR3, RT_MIN(cbVgaFramebuffer, VMSVGA_VGA_FB_BACKUP_SIZE));
5604 AssertRCReturn(rc, rc);
5605 if (cbVgaFramebuffer > VMSVGA_VGA_FB_BACKUP_SIZE)
5606 SSMR3Skip(pSSM, cbVgaFramebuffer - VMSVGA_VGA_FB_BACKUP_SIZE);
5607 else if (cbVgaFramebuffer < VMSVGA_VGA_FB_BACKUP_SIZE)
5608 RT_BZERO(&pThis->svga.pbVgaFrameBufferR3[cbVgaFramebuffer], VMSVGA_VGA_FB_BACKUP_SIZE - cbVgaFramebuffer);
5609
5610 /* Load the VMSVGA state. */
5611 rc = SSMR3GetStructEx(pSSM, pSVGAState, sizeof(*pSVGAState), 0, g_aVMSVGAR3STATEFields, NULL);
5612 AssertRCReturn(rc, rc);
5613
5614 /* Load the active cursor bitmaps. */
5615 if (pSVGAState->Cursor.fActive)
5616 {
5617 pSVGAState->Cursor.pData = RTMemAlloc(pSVGAState->Cursor.cbData);
5618 AssertReturn(pSVGAState->Cursor.pData, VERR_NO_MEMORY);
5619
5620 rc = SSMR3GetMem(pSSM, pSVGAState->Cursor.pData, pSVGAState->Cursor.cbData);
5621 AssertRCReturn(rc, rc);
5622 }
5623
5624 /* Load the GMR state. */
5625 uint32_t cGMR = 256; /* Hardcoded in previous saved state versions. */
5626 if (uVersion >= VGA_SAVEDSTATE_VERSION_VMSVGA_GMR_COUNT)
5627 {
5628 rc = SSMR3GetU32(pSSM, &cGMR);
5629 AssertRCReturn(rc, rc);
5630 /* Numbers of GMRs was never less than 256. 1MB is a large arbitrary limit. */
5631 AssertLogRelMsgReturn(cGMR <= _1M && cGMR >= 256,
5632 ("cGMR=%#x - expected 256B..1MB\n", cGMR),
5633 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
5634 }
5635
5636 if (pThis->svga.cGMR != cGMR)
5637 {
5638 /* Reallocate GMR array. */
5639 Assert(pSVGAState->paGMR != NULL);
5640 RTMemFree(pSVGAState->paGMR);
5641 pSVGAState->paGMR = (PGMR)RTMemAllocZ(cGMR * sizeof(GMR));
5642 AssertReturn(pSVGAState->paGMR, VERR_NO_MEMORY);
5643 pThis->svga.cGMR = cGMR;
5644 }
5645
5646 for (uint32_t i = 0; i < cGMR; ++i)
5647 {
5648 PGMR pGMR = &pSVGAState->paGMR[i];
5649
5650 rc = SSMR3GetStructEx(pSSM, pGMR, sizeof(*pGMR), 0, g_aGMRFields, NULL);
5651 AssertRCReturn(rc, rc);
5652
5653 if (pGMR->numDescriptors)
5654 {
5655 Assert(pGMR->cMaxPages || pGMR->cbTotal);
5656 pGMR->paDesc = (PVMSVGAGMRDESCRIPTOR)RTMemAllocZ(pGMR->numDescriptors * sizeof(VMSVGAGMRDESCRIPTOR));
5657 AssertReturn(pGMR->paDesc, VERR_NO_MEMORY);
5658
5659 for (uint32_t j = 0; j < pGMR->numDescriptors; ++j)
5660 {
5661 rc = SSMR3GetStructEx(pSSM, &pGMR->paDesc[j], sizeof(pGMR->paDesc[j]), 0, g_aVMSVGAGMRDESCRIPTORFields, NULL);
5662 AssertRCReturn(rc, rc);
5663 }
5664 }
5665 }
5666
5667# ifdef RT_OS_DARWIN /** @todo r=bird: this is normally done on the EMT, so for DARWIN we do that when loading saved state too now. See DevVGA-SVGA3d-shared.h. */
5668 vmsvga3dPowerOn(pThis);
5669# endif
5670
5671 VMSVGA_STATE_LOAD LoadState;
5672 LoadState.pSSM = pSSM;
5673 LoadState.uVersion = uVersion;
5674 LoadState.uPass = uPass;
5675 rc = vmsvgaR3RunExtCmdOnFifoThread(pThis, VMSVGA_FIFO_EXTCMD_LOADSTATE, &LoadState, RT_INDEFINITE_WAIT);
5676 AssertLogRelRCReturn(rc, rc);
5677
5678 return VINF_SUCCESS;
5679}
5680
5681/**
5682 * Reinit the video mode after the state has been loaded.
5683 */
5684int vmsvgaLoadDone(PPDMDEVINS pDevIns)
5685{
5686 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
5687 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
5688
5689 ASMAtomicOrU32(&pThis->svga.u32ActionFlags, VMSVGA_ACTION_CHANGEMODE);
5690
5691 /* Set the active cursor. */
5692 if (pSVGAState->Cursor.fActive)
5693 {
5694 int rc;
5695
5696 rc = pThis->pDrv->pfnVBVAMousePointerShape(pThis->pDrv,
5697 true,
5698 true,
5699 pSVGAState->Cursor.xHotspot,
5700 pSVGAState->Cursor.yHotspot,
5701 pSVGAState->Cursor.width,
5702 pSVGAState->Cursor.height,
5703 pSVGAState->Cursor.pData);
5704 AssertRC(rc);
5705 }
5706 return VINF_SUCCESS;
5707}
5708
5709/**
5710 * Portion of SVGA state which must be saved in the FIFO thread.
5711 */
5712static int vmsvgaSaveExecFifo(PVGASTATE pThis, PSSMHANDLE pSSM)
5713{
5714 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
5715 int rc;
5716
5717 /* Save the screen objects. */
5718 /* Count defined screen object. */
5719 uint32_t cScreens = 0;
5720 for (uint32_t i = 0; i < RT_ELEMENTS(pSVGAState->aScreens); ++i)
5721 {
5722 if (pSVGAState->aScreens[i].fDefined)
5723 ++cScreens;
5724 }
5725
5726 rc = SSMR3PutU32(pSSM, cScreens);
5727 AssertLogRelRCReturn(rc, rc);
5728
5729 for (uint32_t i = 0; i < cScreens; ++i)
5730 {
5731 VMSVGASCREENOBJECT *pScreen = &pSVGAState->aScreens[i];
5732
5733 rc = SSMR3PutStructEx(pSSM, pScreen, sizeof(*pScreen), 0, g_aVMSVGASCREENOBJECTFields, NULL);
5734 AssertLogRelRCReturn(rc, rc);
5735 }
5736 return VINF_SUCCESS;
5737}
5738
5739/**
5740 * @copydoc FNSSMDEVSAVEEXEC
5741 */
5742int vmsvgaSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
5743{
5744 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
5745 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
5746 int rc;
5747
5748 /* Save our part of the VGAState */
5749 rc = SSMR3PutStructEx(pSSM, &pThis->svga, sizeof(pThis->svga), 0, g_aVGAStateSVGAFields, NULL);
5750 AssertLogRelRCReturn(rc, rc);
5751
5752 /* Save the framebuffer backup. */
5753 rc = SSMR3PutU32(pSSM, VMSVGA_VGA_FB_BACKUP_SIZE);
5754 rc = SSMR3PutMem(pSSM, pThis->svga.pbVgaFrameBufferR3, VMSVGA_VGA_FB_BACKUP_SIZE);
5755 AssertLogRelRCReturn(rc, rc);
5756
5757 /* Save the VMSVGA state. */
5758 rc = SSMR3PutStructEx(pSSM, pSVGAState, sizeof(*pSVGAState), 0, g_aVMSVGAR3STATEFields, NULL);
5759 AssertLogRelRCReturn(rc, rc);
5760
5761 /* Save the active cursor bitmaps. */
5762 if (pSVGAState->Cursor.fActive)
5763 {
5764 rc = SSMR3PutMem(pSSM, pSVGAState->Cursor.pData, pSVGAState->Cursor.cbData);
5765 AssertLogRelRCReturn(rc, rc);
5766 }
5767
5768 /* Save the GMR state */
5769 rc = SSMR3PutU32(pSSM, pThis->svga.cGMR);
5770 AssertLogRelRCReturn(rc, rc);
5771 for (uint32_t i = 0; i < pThis->svga.cGMR; ++i)
5772 {
5773 PGMR pGMR = &pSVGAState->paGMR[i];
5774
5775 rc = SSMR3PutStructEx(pSSM, pGMR, sizeof(*pGMR), 0, g_aGMRFields, NULL);
5776 AssertLogRelRCReturn(rc, rc);
5777
5778 for (uint32_t j = 0; j < pGMR->numDescriptors; ++j)
5779 {
5780 rc = SSMR3PutStructEx(pSSM, &pGMR->paDesc[j], sizeof(pGMR->paDesc[j]), 0, g_aVMSVGAGMRDESCRIPTORFields, NULL);
5781 AssertLogRelRCReturn(rc, rc);
5782 }
5783 }
5784
5785 /*
5786 * Must save some state (3D in particular) in the FIFO thread.
5787 */
5788 rc = vmsvgaR3RunExtCmdOnFifoThread(pThis, VMSVGA_FIFO_EXTCMD_SAVESTATE, pSSM, RT_INDEFINITE_WAIT);
5789 AssertLogRelRCReturn(rc, rc);
5790
5791 return VINF_SUCCESS;
5792}
5793
5794/**
5795 * Destructor for PVMSVGAR3STATE structure.
5796 *
5797 * @param pThis The VGA instance.
5798 * @param pSVGAState Pointer to the structure. It is not deallocated.
5799 */
5800static void vmsvgaR3StateTerm(PVGASTATE pThis, PVMSVGAR3STATE pSVGAState)
5801{
5802#ifndef VMSVGA_USE_EMT_HALT_CODE
5803 if (pSVGAState->hBusyDelayedEmts != NIL_RTSEMEVENTMULTI)
5804 {
5805 RTSemEventMultiDestroy(pSVGAState->hBusyDelayedEmts);
5806 pSVGAState->hBusyDelayedEmts = NIL_RTSEMEVENT;
5807 }
5808#endif
5809
5810 if (pSVGAState->Cursor.fActive)
5811 {
5812 RTMemFree(pSVGAState->Cursor.pData);
5813 pSVGAState->Cursor.pData = NULL;
5814 pSVGAState->Cursor.fActive = false;
5815 }
5816
5817 if (pSVGAState->paGMR)
5818 {
5819 for (unsigned i = 0; i < pThis->svga.cGMR; ++i)
5820 if (pSVGAState->paGMR[i].paDesc)
5821 RTMemFree(pSVGAState->paGMR[i].paDesc);
5822
5823 RTMemFree(pSVGAState->paGMR);
5824 pSVGAState->paGMR = NULL;
5825 }
5826}
5827
5828/**
5829 * Constructor for PVMSVGAR3STATE structure.
5830 *
5831 * @returns VBox status code.
5832 * @param pThis The VGA instance.
5833 * @param pSVGAState Pointer to the structure. It is already allocated.
5834 */
5835static int vmsvgaR3StateInit(PVGASTATE pThis, PVMSVGAR3STATE pSVGAState)
5836{
5837 int rc = VINF_SUCCESS;
5838 RT_ZERO(*pSVGAState);
5839
5840 pSVGAState->paGMR = (PGMR)RTMemAllocZ(pThis->svga.cGMR * sizeof(GMR));
5841 AssertReturn(pSVGAState->paGMR, VERR_NO_MEMORY);
5842
5843#ifndef VMSVGA_USE_EMT_HALT_CODE
5844 /* Create semaphore for delaying EMTs wait for the FIFO to stop being busy. */
5845 rc = RTSemEventMultiCreate(&pSVGAState->hBusyDelayedEmts);
5846 AssertRCReturn(rc, rc);
5847#endif
5848
5849 return rc;
5850}
5851
5852/**
5853 * Initializes the host capabilities: registers and FIFO.
5854 *
5855 * @returns VBox status code.
5856 * @param pThis The VGA instance.
5857 */
5858static void vmsvgaInitCaps(PVGASTATE pThis)
5859{
5860 /* Register caps. */
5861 pThis->svga.u32RegCaps = SVGA_CAP_GMR
5862 | SVGA_CAP_GMR2
5863 | SVGA_CAP_CURSOR
5864 | SVGA_CAP_CURSOR_BYPASS_2
5865 | SVGA_CAP_EXTENDED_FIFO
5866 | SVGA_CAP_IRQMASK
5867 | SVGA_CAP_PITCHLOCK
5868 | SVGA_CAP_TRACES
5869 | SVGA_CAP_SCREEN_OBJECT_2
5870 | SVGA_CAP_ALPHA_CURSOR;
5871# ifdef VBOX_WITH_VMSVGA3D
5872 pThis->svga.u32RegCaps |= SVGA_CAP_3D;
5873# endif
5874
5875 /* Clear the FIFO. */
5876 RT_BZERO(pThis->svga.pFIFOR3, pThis->svga.cbFIFO);
5877
5878 /* Setup FIFO capabilities. */
5879 pThis->svga.pFIFOR3[SVGA_FIFO_CAPABILITIES] = SVGA_FIFO_CAP_FENCE
5880 | SVGA_FIFO_CAP_CURSOR_BYPASS_3
5881 | SVGA_FIFO_CAP_GMR2
5882 | SVGA_FIFO_CAP_3D_HWVERSION_REVISED
5883 | SVGA_FIFO_CAP_SCREEN_OBJECT_2
5884 | SVGA_FIFO_CAP_RESERVE
5885 | SVGA_FIFO_CAP_PITCHLOCK;
5886
5887 /* Valid with SVGA_FIFO_CAP_SCREEN_OBJECT_2 */
5888 pThis->svga.pFIFOR3[SVGA_FIFO_CURSOR_SCREEN_ID] = SVGA_ID_INVALID;
5889}
5890
5891# ifdef VBOX_WITH_VMSVGA3D
5892/** Names for the vmsvga 3d capabilities, prefixed with format type hint char. */
5893static const char * const g_apszVmSvgaDevCapNames[] =
5894{
5895 "x3D", /* = 0 */
5896 "xMAX_LIGHTS",
5897 "xMAX_TEXTURES",
5898 "xMAX_CLIP_PLANES",
5899 "xVERTEX_SHADER_VERSION",
5900 "xVERTEX_SHADER",
5901 "xFRAGMENT_SHADER_VERSION",
5902 "xFRAGMENT_SHADER",
5903 "xMAX_RENDER_TARGETS",
5904 "xS23E8_TEXTURES",
5905 "xS10E5_TEXTURES",
5906 "xMAX_FIXED_VERTEXBLEND",
5907 "xD16_BUFFER_FORMAT",
5908 "xD24S8_BUFFER_FORMAT",
5909 "xD24X8_BUFFER_FORMAT",
5910 "xQUERY_TYPES",
5911 "xTEXTURE_GRADIENT_SAMPLING",
5912 "rMAX_POINT_SIZE",
5913 "xMAX_SHADER_TEXTURES",
5914 "xMAX_TEXTURE_WIDTH",
5915 "xMAX_TEXTURE_HEIGHT",
5916 "xMAX_VOLUME_EXTENT",
5917 "xMAX_TEXTURE_REPEAT",
5918 "xMAX_TEXTURE_ASPECT_RATIO",
5919 "xMAX_TEXTURE_ANISOTROPY",
5920 "xMAX_PRIMITIVE_COUNT",
5921 "xMAX_VERTEX_INDEX",
5922 "xMAX_VERTEX_SHADER_INSTRUCTIONS",
5923 "xMAX_FRAGMENT_SHADER_INSTRUCTIONS",
5924 "xMAX_VERTEX_SHADER_TEMPS",
5925 "xMAX_FRAGMENT_SHADER_TEMPS",
5926 "xTEXTURE_OPS",
5927 "xSURFACEFMT_X8R8G8B8",
5928 "xSURFACEFMT_A8R8G8B8",
5929 "xSURFACEFMT_A2R10G10B10",
5930 "xSURFACEFMT_X1R5G5B5",
5931 "xSURFACEFMT_A1R5G5B5",
5932 "xSURFACEFMT_A4R4G4B4",
5933 "xSURFACEFMT_R5G6B5",
5934 "xSURFACEFMT_LUMINANCE16",
5935 "xSURFACEFMT_LUMINANCE8_ALPHA8",
5936 "xSURFACEFMT_ALPHA8",
5937 "xSURFACEFMT_LUMINANCE8",
5938 "xSURFACEFMT_Z_D16",
5939 "xSURFACEFMT_Z_D24S8",
5940 "xSURFACEFMT_Z_D24X8",
5941 "xSURFACEFMT_DXT1",
5942 "xSURFACEFMT_DXT2",
5943 "xSURFACEFMT_DXT3",
5944 "xSURFACEFMT_DXT4",
5945 "xSURFACEFMT_DXT5",
5946 "xSURFACEFMT_BUMPX8L8V8U8",
5947 "xSURFACEFMT_A2W10V10U10",
5948 "xSURFACEFMT_BUMPU8V8",
5949 "xSURFACEFMT_Q8W8V8U8",
5950 "xSURFACEFMT_CxV8U8",
5951 "xSURFACEFMT_R_S10E5",
5952 "xSURFACEFMT_R_S23E8",
5953 "xSURFACEFMT_RG_S10E5",
5954 "xSURFACEFMT_RG_S23E8",
5955 "xSURFACEFMT_ARGB_S10E5",
5956 "xSURFACEFMT_ARGB_S23E8",
5957 "xMISSING62",
5958 "xMAX_VERTEX_SHADER_TEXTURES",
5959 "xMAX_SIMULTANEOUS_RENDER_TARGETS",
5960 "xSURFACEFMT_V16U16",
5961 "xSURFACEFMT_G16R16",
5962 "xSURFACEFMT_A16B16G16R16",
5963 "xSURFACEFMT_UYVY",
5964 "xSURFACEFMT_YUY2",
5965 "xMULTISAMPLE_NONMASKABLESAMPLES",
5966 "xMULTISAMPLE_MASKABLESAMPLES",
5967 "xALPHATOCOVERAGE",
5968 "xSUPERSAMPLE",
5969 "xAUTOGENMIPMAPS",
5970 "xSURFACEFMT_NV12",
5971 "xSURFACEFMT_AYUV",
5972 "xMAX_CONTEXT_IDS",
5973 "xMAX_SURFACE_IDS",
5974 "xSURFACEFMT_Z_DF16",
5975 "xSURFACEFMT_Z_DF24",
5976 "xSURFACEFMT_Z_D24S8_INT",
5977 "xSURFACEFMT_BC4_UNORM",
5978 "xSURFACEFMT_BC5_UNORM", /* 83 */
5979};
5980
5981/**
5982 * Initializes the host 3D capabilities in FIFO.
5983 *
5984 * @returns VBox status code.
5985 * @param pThis The VGA instance.
5986 */
5987static void vmsvgaInitFifo3DCaps(PVGASTATE pThis)
5988{
5989 /** @todo Probably query the capabilities once and cache in a memory buffer. */
5990 bool fSavedBuffering = RTLogRelSetBuffering(true);
5991 SVGA3dCapsRecord *pCaps;
5992 SVGA3dCapPair *pData;
5993 uint32_t idxCap = 0;
5994
5995 /* 3d hardware version; latest and greatest */
5996 pThis->svga.pFIFOR3[SVGA_FIFO_3D_HWVERSION_REVISED] = SVGA3D_HWVERSION_CURRENT;
5997 pThis->svga.pFIFOR3[SVGA_FIFO_3D_HWVERSION] = SVGA3D_HWVERSION_CURRENT;
5998
5999 pCaps = (SVGA3dCapsRecord *)&pThis->svga.pFIFOR3[SVGA_FIFO_3D_CAPS];
6000 pCaps->header.type = SVGA3DCAPS_RECORD_DEVCAPS;
6001 pData = (SVGA3dCapPair *)&pCaps->data;
6002
6003 /* Fill out all 3d capabilities. */
6004 for (unsigned i = 0; i < SVGA3D_DEVCAP_MAX; i++)
6005 {
6006 uint32_t val = 0;
6007
6008 int rc = vmsvga3dQueryCaps(pThis, i, &val);
6009 if (RT_SUCCESS(rc))
6010 {
6011 pData[idxCap][0] = i;
6012 pData[idxCap][1] = val;
6013 idxCap++;
6014 if (g_apszVmSvgaDevCapNames[i][0] == 'x')
6015 LogRel(("VMSVGA3d: cap[%u]=%#010x {%s}\n", i, val, &g_apszVmSvgaDevCapNames[i][1]));
6016 else
6017 LogRel(("VMSVGA3d: cap[%u]=%d.%04u {%s}\n", i, (int)*(float *)&val, (unsigned)(*(float *)&val * 10000) % 10000,
6018 &g_apszVmSvgaDevCapNames[i][1]));
6019 }
6020 else
6021 LogRel(("VMSVGA3d: cap[%u]=failed rc=%Rrc! {%s}\n", i, rc, &g_apszVmSvgaDevCapNames[i][1]));
6022 }
6023 pCaps->header.length = (sizeof(pCaps->header) + idxCap * sizeof(SVGA3dCapPair)) / sizeof(uint32_t);
6024 pCaps = (SVGA3dCapsRecord *)((uint32_t *)pCaps + pCaps->header.length);
6025
6026 /* Mark end of record array. */
6027 pCaps->header.length = 0;
6028
6029 RTLogRelSetBuffering(fSavedBuffering);
6030}
6031
6032# endif
6033
6034/**
6035 * Resets the SVGA hardware state
6036 *
6037 * @returns VBox status code.
6038 * @param pDevIns The device instance.
6039 */
6040int vmsvgaReset(PPDMDEVINS pDevIns)
6041{
6042 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
6043 PVMSVGAR3STATE pSVGAState = pThis->svga.pSvgaR3State;
6044
6045 /* Reset before init? */
6046 if (!pSVGAState)
6047 return VINF_SUCCESS;
6048
6049 Log(("vmsvgaReset\n"));
6050
6051 /* Reset the FIFO processing as well as the 3d state (if we have one). */
6052 pThis->svga.pFIFOR3[SVGA_FIFO_NEXT_CMD] = pThis->svga.pFIFOR3[SVGA_FIFO_STOP] = 0; /** @todo should probably let the FIFO thread do this ... */
6053 int rc = vmsvgaR3RunExtCmdOnFifoThread(pThis, VMSVGA_FIFO_EXTCMD_RESET, NULL /*pvParam*/, 10000 /*ms*/);
6054
6055 /* Reset other stuff. */
6056 pThis->svga.cScratchRegion = VMSVGA_SCRATCH_SIZE;
6057 RT_ZERO(pThis->svga.au32ScratchRegion);
6058
6059 vmsvgaR3StateTerm(pThis, pThis->svga.pSvgaR3State);
6060 vmsvgaR3StateInit(pThis, pThis->svga.pSvgaR3State);
6061
6062 RT_BZERO(pThis->svga.pbVgaFrameBufferR3, VMSVGA_VGA_FB_BACKUP_SIZE);
6063
6064 /* Initialize FIFO and register capabilities. */
6065 vmsvgaInitCaps(pThis);
6066
6067# ifdef VBOX_WITH_VMSVGA3D
6068 if (pThis->svga.f3DEnabled)
6069 vmsvgaInitFifo3DCaps(pThis);
6070# endif
6071
6072 /* VRAM tracking is enabled by default during bootup. */
6073 pThis->svga.fVRAMTracking = true;
6074 pThis->svga.fEnabled = false;
6075
6076 /* Invalidate current settings. */
6077 pThis->svga.uWidth = VMSVGA_VAL_UNINITIALIZED;
6078 pThis->svga.uHeight = VMSVGA_VAL_UNINITIALIZED;
6079 pThis->svga.uBpp = VMSVGA_VAL_UNINITIALIZED;
6080 pThis->svga.cbScanline = 0;
6081 pThis->svga.u32PitchLock = 0;
6082
6083 return rc;
6084}
6085
6086/**
6087 * Cleans up the SVGA hardware state
6088 *
6089 * @returns VBox status code.
6090 * @param pDevIns The device instance.
6091 */
6092int vmsvgaDestruct(PPDMDEVINS pDevIns)
6093{
6094 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
6095
6096 /*
6097 * Ask the FIFO thread to terminate the 3d state and then terminate it.
6098 */
6099 if (pThis->svga.pFIFOIOThread)
6100 {
6101 int rc = vmsvgaR3RunExtCmdOnFifoThread(pThis, VMSVGA_FIFO_EXTCMD_TERMINATE, NULL /*pvParam*/, 30000 /*ms*/);
6102 AssertLogRelRC(rc);
6103
6104 rc = PDMR3ThreadDestroy(pThis->svga.pFIFOIOThread, NULL);
6105 AssertLogRelRC(rc);
6106 pThis->svga.pFIFOIOThread = NULL;
6107 }
6108
6109 /*
6110 * Destroy the special SVGA state.
6111 */
6112 if (pThis->svga.pSvgaR3State)
6113 {
6114 vmsvgaR3StateTerm(pThis, pThis->svga.pSvgaR3State);
6115
6116 RTMemFree(pThis->svga.pSvgaR3State);
6117 pThis->svga.pSvgaR3State = NULL;
6118 }
6119
6120 /*
6121 * Free our resources residing in the VGA state.
6122 */
6123 if (pThis->svga.pbVgaFrameBufferR3)
6124 {
6125 RTMemFree(pThis->svga.pbVgaFrameBufferR3);
6126 pThis->svga.pbVgaFrameBufferR3 = NULL;
6127 }
6128 if (pThis->svga.FIFOExtCmdSem != NIL_RTSEMEVENT)
6129 {
6130 RTSemEventDestroy(pThis->svga.FIFOExtCmdSem);
6131 pThis->svga.FIFOExtCmdSem = NIL_RTSEMEVENT;
6132 }
6133 if (pThis->svga.FIFORequestSem != NIL_SUPSEMEVENT)
6134 {
6135 SUPSemEventClose(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
6136 pThis->svga.FIFORequestSem = NIL_SUPSEMEVENT;
6137 }
6138
6139 return VINF_SUCCESS;
6140}
6141
6142/**
6143 * Initialize the SVGA hardware state
6144 *
6145 * @returns VBox status code.
6146 * @param pDevIns The device instance.
6147 */
6148int vmsvgaInit(PPDMDEVINS pDevIns)
6149{
6150 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
6151 PVMSVGAR3STATE pSVGAState;
6152 PVM pVM = PDMDevHlpGetVM(pDevIns);
6153 int rc;
6154
6155 pThis->svga.cScratchRegion = VMSVGA_SCRATCH_SIZE;
6156 memset(pThis->svga.au32ScratchRegion, 0, sizeof(pThis->svga.au32ScratchRegion));
6157
6158 pThis->svga.cGMR = VMSVGA_MAX_GMR_IDS;
6159
6160 /* Necessary for creating a backup of the text mode frame buffer when switching into svga mode. */
6161 pThis->svga.pbVgaFrameBufferR3 = (uint8_t *)RTMemAllocZ(VMSVGA_VGA_FB_BACKUP_SIZE);
6162 AssertReturn(pThis->svga.pbVgaFrameBufferR3, VERR_NO_MEMORY);
6163
6164 /* Create event semaphore. */
6165 pThis->svga.pSupDrvSession = PDMDevHlpGetSupDrvSession(pDevIns);
6166
6167 rc = SUPSemEventCreate(pThis->svga.pSupDrvSession, &pThis->svga.FIFORequestSem);
6168 if (RT_FAILURE(rc))
6169 {
6170 Log(("%s: Failed to create event semaphore for FIFO handling.\n", __FUNCTION__));
6171 return rc;
6172 }
6173
6174 /* Create event semaphore. */
6175 rc = RTSemEventCreate(&pThis->svga.FIFOExtCmdSem);
6176 if (RT_FAILURE(rc))
6177 {
6178 Log(("%s: Failed to create event semaphore for external fifo cmd handling.\n", __FUNCTION__));
6179 return rc;
6180 }
6181
6182 pThis->svga.pSvgaR3State = (PVMSVGAR3STATE)RTMemAlloc(sizeof(VMSVGAR3STATE));
6183 AssertReturn(pThis->svga.pSvgaR3State, VERR_NO_MEMORY);
6184
6185 rc = vmsvgaR3StateInit(pThis, pThis->svga.pSvgaR3State);
6186 AssertMsgRCReturn(rc, ("Failed to create pSvgaR3State.\n"), rc);
6187
6188 pSVGAState = pThis->svga.pSvgaR3State;
6189
6190 /* Initialize FIFO and register capabilities. */
6191 vmsvgaInitCaps(pThis);
6192
6193# ifdef VBOX_WITH_VMSVGA3D
6194 if (pThis->svga.f3DEnabled)
6195 {
6196 rc = vmsvga3dInit(pThis);
6197 if (RT_FAILURE(rc))
6198 {
6199 LogRel(("VMSVGA3d: 3D support disabled! (vmsvga3dInit -> %Rrc)\n", rc));
6200 pThis->svga.f3DEnabled = false;
6201 }
6202 }
6203# endif
6204 /* VRAM tracking is enabled by default during bootup. */
6205 pThis->svga.fVRAMTracking = true;
6206
6207 /* Invalidate current settings. */
6208 pThis->svga.uWidth = VMSVGA_VAL_UNINITIALIZED;
6209 pThis->svga.uHeight = VMSVGA_VAL_UNINITIALIZED;
6210 pThis->svga.uBpp = VMSVGA_VAL_UNINITIALIZED;
6211 pThis->svga.cbScanline = 0;
6212
6213 pThis->svga.u32MaxWidth = VBE_DISPI_MAX_YRES;
6214 pThis->svga.u32MaxHeight = VBE_DISPI_MAX_XRES;
6215 while (pThis->svga.u32MaxWidth * pThis->svga.u32MaxHeight * 4 /* 32 bpp */ > pThis->vram_size)
6216 {
6217 pThis->svga.u32MaxWidth -= 256;
6218 pThis->svga.u32MaxHeight -= 256;
6219 }
6220 Log(("VMSVGA: Maximum size (%d,%d)\n", pThis->svga.u32MaxWidth, pThis->svga.u32MaxHeight));
6221
6222# ifdef DEBUG_GMR_ACCESS
6223 /* Register the GMR access handler type. */
6224 rc = PGMR3HandlerPhysicalTypeRegister(PDMDevHlpGetVM(pThis->pDevInsR3), PGMPHYSHANDLERKIND_WRITE,
6225 vmsvgaR3GMRAccessHandler,
6226 NULL, NULL, NULL,
6227 NULL, NULL, NULL,
6228 "VMSVGA GMR", &pThis->svga.hGmrAccessHandlerType);
6229 AssertRCReturn(rc, rc);
6230# endif
6231
6232# if defined(VMSVGA_USE_FIFO_ACCESS_HANDLER) || defined(DEBUG_FIFO_ACCESS)
6233 /* Register the FIFO access handler type. In addition to
6234 debugging FIFO access, this is also used to facilitate
6235 extended fifo thread sleeps. */
6236 rc = PGMR3HandlerPhysicalTypeRegister(PDMDevHlpGetVM(pThis->pDevInsR3),
6237# ifdef DEBUG_FIFO_ACCESS
6238 PGMPHYSHANDLERKIND_ALL,
6239# else
6240 PGMPHYSHANDLERKIND_WRITE,
6241# endif
6242 vmsvgaR3FIFOAccessHandler,
6243 NULL, NULL, NULL,
6244 NULL, NULL, NULL,
6245 "VMSVGA FIFO", &pThis->svga.hFifoAccessHandlerType);
6246 AssertRCReturn(rc, rc);
6247# endif
6248
6249 /* Create the async IO thread. */
6250 rc = PDMDevHlpThreadCreate(pDevIns, &pThis->svga.pFIFOIOThread, pThis, vmsvgaFIFOLoop, vmsvgaFIFOLoopWakeUp, 0,
6251 RTTHREADTYPE_IO, "VMSVGA FIFO");
6252 if (RT_FAILURE(rc))
6253 {
6254 AssertMsgFailed(("%s: Async IO Thread creation for FIFO handling failed rc=%d\n", __FUNCTION__, rc));
6255 return rc;
6256 }
6257
6258 /*
6259 * Statistics.
6260 */
6261 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dActivateSurface, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dActivateSurface", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_ACTIVATE_SURFACE");
6262 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dBeginQuery, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dBeginQuery", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_BEGIN_QUERY");
6263 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dClear, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dClear", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_CLEAR");
6264 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dContextDefine, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dContextDefine", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_CONTEXT_DEFINE");
6265 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dContextDestroy, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dContextDestroy", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_CONTEXT_DESTROY");
6266 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dDeactivateSurface, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dDeactivateSurface", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_DEACTIVATE_SURFACE");
6267 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dDrawPrimitives, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dDrawPrimitives", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_DRAW_PRIMITIVES");
6268 STAM_REG(pVM, &pSVGAState->StatR3Cmd3dDrawPrimitivesProf, STAMTYPE_PROFILE, "/Devices/VMSVGA/Cmd/3dDrawPrimitivesProf", STAMUNIT_TICKS_PER_CALL, "Profiling of SVGA_3D_CMD_DRAW_PRIMITIVES.");
6269 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dEndQuery, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dEndQuery", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_END_QUERY");
6270 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dGenerateMipmaps, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dGenerateMipmaps", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_GENERATE_MIPMAPS");
6271 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dPresent, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dPresent", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_PRESENT");
6272 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dPresentReadBack, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dPresentReadBack", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_PRESENT_READBACK");
6273 STAM_REG(pVM, &pSVGAState->StatR3Cmd3dPresentProf, STAMTYPE_PROFILE, "/Devices/VMSVGA/Cmd/3dPresentProfBoth", STAMUNIT_TICKS_PER_CALL, "Profiling of SVGA_3D_CMD_PRESENT and SVGA_3D_CMD_PRESENT_READBACK.");
6274 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetClipPlane, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetClipPlane", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETCLIPPLANE");
6275 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetLightData, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetLightData", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETLIGHTDATA");
6276 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetLightEnable, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetLightEnable", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETLIGHTENABLE");
6277 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetMaterial, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetMaterial", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETMATERIAL");
6278 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetRenderState, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetRenderState", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETRENDERSTATE");
6279 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetRenderTarget, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetRenderTarget", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETRENDERTARGET");
6280 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetScissorRect, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetScissorRect", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETSCISSORRECT");
6281 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetShader, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetShader", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SET_SHADER");
6282 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetShaderConst, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetShaderConst", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SET_SHADER_CONST");
6283 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetTextureState, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetTextureState", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETTEXTURESTATE");
6284 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetTransform, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetTransform", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETTRANSFORM");
6285 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetViewPort, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetViewPort", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETVIEWPORT");
6286 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSetZRange, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSetZRange", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SETZRANGE");
6287 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dShaderDefine, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dShaderDefine", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SHADER_DEFINE");
6288 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dShaderDestroy, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dShaderDestroy", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SHADER_DESTROY");
6289 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSurfaceCopy, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSurfaceCopy", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SURFACE_COPY");
6290 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSurfaceDefine, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSurfaceDefine", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SURFACE_DEFINE");
6291 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSurfaceDefineV2, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSurfaceDefineV2", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SURFACE_DEFINE_V2");
6292 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSurfaceDestroy, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSurfaceDestroy", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SURFACE_DESTROY");
6293 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSurfaceDma, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSurfaceDma", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SURFACE_DMA");
6294 STAM_REG(pVM, &pSVGAState->StatR3Cmd3dSurfaceDmaProf, STAMTYPE_PROFILE, "/Devices/VMSVGA/Cmd/3dSurfaceDmaProf", STAMUNIT_TICKS_PER_CALL, "Profiling of SVGA_3D_CMD_SURFACE_DMA.");
6295 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSurfaceScreen, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSurfaceScreen", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SURFACE_SCREEN");
6296 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dSurfaceStretchBlt, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dSurfaceStretchBlt", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_SURFACE_STRETCHBLT");
6297 STAM_REL_REG(pVM, &pSVGAState->StatR3Cmd3dWaitForQuery, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/3dWaitForQuery", STAMUNIT_OCCURENCES, "SVGA_3D_CMD_WAIT_FOR_QUERY");
6298 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdAnnotationCopy, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/AnnotationCopy", STAMUNIT_OCCURENCES, "SVGA_CMD_ANNOTATION_COPY");
6299 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdAnnotationFill, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/AnnotationFill", STAMUNIT_OCCURENCES, "SVGA_CMD_ANNOTATION_FILL");
6300 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdBlitGmrFbToScreen, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/BlitGmrFbToScreen", STAMUNIT_OCCURENCES, "SVGA_CMD_BLIT_GMRFB_TO_SCREEN");
6301 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdBlitScreentoGmrFb, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/BlitScreentoGmrFb", STAMUNIT_OCCURENCES, "SVGA_CMD_BLIT_SCREEN_TO_GMRFB");
6302 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdDefineAlphaCursor, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/DefineAlphaCursor", STAMUNIT_OCCURENCES, "SVGA_CMD_DEFINE_ALPHA_CURSOR");
6303 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdDefineCursor, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/DefineCursor", STAMUNIT_OCCURENCES, "SVGA_CMD_DEFINE_CURSOR");
6304 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdDefineGmr2, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/DefineGmr2", STAMUNIT_OCCURENCES, "SVGA_CMD_DEFINE_GMR2");
6305 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdDefineGmr2Free, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/DefineGmr2/Free", STAMUNIT_OCCURENCES, "Number of SVGA_CMD_DEFINE_GMR2 commands that only frees.");
6306 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdDefineGmr2Modify, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/DefineGmr2/Modify", STAMUNIT_OCCURENCES, "Number of SVGA_CMD_DEFINE_GMR2 commands that redefines a non-free GMR.");
6307 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdDefineGmrFb, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/DefineGmrFb", STAMUNIT_OCCURENCES, "SVGA_CMD_DEFINE_GMRFB");
6308 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdDefineScreen, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/DefineScreen", STAMUNIT_OCCURENCES, "SVGA_CMD_DEFINE_SCREEN");
6309 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdDestroyScreen, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/DestroyScreen", STAMUNIT_OCCURENCES, "SVGA_CMD_DESTROY_SCREEN");
6310 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdEscape, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/Escape", STAMUNIT_OCCURENCES, "SVGA_CMD_ESCAPE");
6311 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdFence, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/Fence", STAMUNIT_OCCURENCES, "SVGA_CMD_FENCE");
6312 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdInvalidCmd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/InvalidCmd", STAMUNIT_OCCURENCES, "SVGA_CMD_INVALID_CMD");
6313 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdRemapGmr2, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/RemapGmr2", STAMUNIT_OCCURENCES, "SVGA_CMD_REMAP_GMR2");
6314 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdRemapGmr2Modify, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/RemapGmr2/Modify", STAMUNIT_OCCURENCES, "Number of SVGA_CMD_REMAP_GMR2 commands that modifies rather than complete the definition of a GMR.");
6315 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdUpdate, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/Update", STAMUNIT_OCCURENCES, "SVGA_CMD_UPDATE");
6316 STAM_REL_REG(pVM, &pSVGAState->StatR3CmdUpdateVerbose, STAMTYPE_COUNTER, "/Devices/VMSVGA/Cmd/UpdateVerbose", STAMUNIT_OCCURENCES, "SVGA_CMD_UPDATE_VERBOSE");
6317
6318 STAM_REL_REG(pVM, &pSVGAState->StatR3RegConfigDoneWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/ConfigDoneWrite", STAMUNIT_OCCURENCES, "SVGA_REG_CONFIG_DONE writes");
6319 STAM_REL_REG(pVM, &pSVGAState->StatR3RegGmrDescriptorWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GmrDescriptorWrite", STAMUNIT_OCCURENCES, "SVGA_REG_GMR_DESCRIPTOR writes");
6320 STAM_REL_REG(pVM, &pSVGAState->StatR3RegGmrDescriptorWrErrors, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GmrDescriptorWrite/Errors", STAMUNIT_OCCURENCES, "Number of erroneous SVGA_REG_GMR_DESCRIPTOR commands.");
6321 STAM_REL_REG(pVM, &pSVGAState->StatR3RegGmrDescriptorWrFree, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GmrDescriptorWrite/Free", STAMUNIT_OCCURENCES, "Number of SVGA_REG_GMR_DESCRIPTOR commands only freeing the GMR.");
6322 STAM_REL_REG(pVM, &pThis->svga.StatRegBitsPerPixelWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/BitsPerPixelWrite", STAMUNIT_OCCURENCES, "SVGA_REG_BITS_PER_PIXEL writes.");
6323 STAM_REL_REG(pVM, &pThis->svga.StatRegBusyWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/BusyWrite", STAMUNIT_OCCURENCES, "SVGA_REG_BUSY writes.");
6324 STAM_REL_REG(pVM, &pThis->svga.StatRegCursorXxxxWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/CursorXxxxWrite", STAMUNIT_OCCURENCES, "SVGA_REG_CURSOR_XXXX writes.");
6325 STAM_REL_REG(pVM, &pThis->svga.StatRegDepthWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DepthWrite", STAMUNIT_OCCURENCES, "SVGA_REG_DEPTH writes.");
6326 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayHeightWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayHeightWrite", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_HEIGHT writes.");
6327 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayIdWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayIdWrite", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_ID writes.");
6328 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayIsPrimaryWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayIsPrimaryWrite", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_IS_PRIMARY writes.");
6329 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayPositionXWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayPositionXWrite", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_POSITION_X writes.");
6330 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayPositionYWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayPositionYWrite", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_POSITION_Y writes.");
6331 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayWidthWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayWidthWrite", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_WIDTH writes.");
6332 STAM_REL_REG(pVM, &pThis->svga.StatRegEnableWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/EnableWrite", STAMUNIT_OCCURENCES, "SVGA_REG_ENABLE writes.");
6333 STAM_REL_REG(pVM, &pThis->svga.StatRegGmrIdWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GmrIdWrite", STAMUNIT_OCCURENCES, "SVGA_REG_GMR_ID writes.");
6334 STAM_REL_REG(pVM, &pThis->svga.StatRegGuestIdWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GuestIdWrite", STAMUNIT_OCCURENCES, "SVGA_REG_GUEST_ID writes.");
6335 STAM_REL_REG(pVM, &pThis->svga.StatRegHeightWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/HeightWrite", STAMUNIT_OCCURENCES, "SVGA_REG_HEIGHT writes.");
6336 STAM_REL_REG(pVM, &pThis->svga.StatRegIdWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/IdWrite", STAMUNIT_OCCURENCES, "SVGA_REG_ID writes.");
6337 STAM_REL_REG(pVM, &pThis->svga.StatRegIrqMaskWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/IrqMaskWrite", STAMUNIT_OCCURENCES, "SVGA_REG_IRQMASK writes.");
6338 STAM_REL_REG(pVM, &pThis->svga.StatRegNumDisplaysWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/NumDisplaysWrite", STAMUNIT_OCCURENCES, "SVGA_REG_NUM_DISPLAYS writes.");
6339 STAM_REL_REG(pVM, &pThis->svga.StatRegNumGuestDisplaysWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/NumGuestDisplaysWrite", STAMUNIT_OCCURENCES, "SVGA_REG_NUM_GUEST_DISPLAYS writes.");
6340 STAM_REL_REG(pVM, &pThis->svga.StatRegPaletteWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/PaletteWrite", STAMUNIT_OCCURENCES, "SVGA_PALETTE_XXXX writes.");
6341 STAM_REL_REG(pVM, &pThis->svga.StatRegPitchLockWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/PitchLockWrite", STAMUNIT_OCCURENCES, "SVGA_REG_PITCHLOCK writes.");
6342 STAM_REL_REG(pVM, &pThis->svga.StatRegPseudoColorWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/PseudoColorWrite", STAMUNIT_OCCURENCES, "SVGA_REG_PSEUDOCOLOR writes.");
6343 STAM_REL_REG(pVM, &pThis->svga.StatRegReadOnlyWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/ReadOnlyWrite", STAMUNIT_OCCURENCES, "Read-only SVGA_REG_XXXX writes.");
6344 STAM_REL_REG(pVM, &pThis->svga.StatRegScratchWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/ScratchWrite", STAMUNIT_OCCURENCES, "SVGA_REG_SCRATCH_XXXX writes.");
6345 STAM_REL_REG(pVM, &pThis->svga.StatRegSyncWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/SyncWrite", STAMUNIT_OCCURENCES, "SVGA_REG_SYNC writes.");
6346 STAM_REL_REG(pVM, &pThis->svga.StatRegTopWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/TopWrite", STAMUNIT_OCCURENCES, "SVGA_REG_TOP writes.");
6347 STAM_REL_REG(pVM, &pThis->svga.StatRegTracesWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/TracesWrite", STAMUNIT_OCCURENCES, "SVGA_REG_TRACES writes.");
6348 STAM_REL_REG(pVM, &pThis->svga.StatRegUnknownWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/UnknownWrite", STAMUNIT_OCCURENCES, "Writes to unknown register.");
6349 STAM_REL_REG(pVM, &pThis->svga.StatRegWidthWr, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/WidthWrite", STAMUNIT_OCCURENCES, "SVGA_REG_WIDTH writes.");
6350
6351 STAM_REL_REG(pVM, &pThis->svga.StatRegBitsPerPixelRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/BitsPerPixelRead", STAMUNIT_OCCURENCES, "SVGA_REG_BITS_PER_PIXEL reads.");
6352 STAM_REL_REG(pVM, &pThis->svga.StatRegBlueMaskRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/BlueMaskRead", STAMUNIT_OCCURENCES, "SVGA_REG_BLUE_MASK reads.");
6353 STAM_REL_REG(pVM, &pThis->svga.StatRegBusyRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/BusyRead", STAMUNIT_OCCURENCES, "SVGA_REG_BUSY reads.");
6354 STAM_REL_REG(pVM, &pThis->svga.StatRegBytesPerLineRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/BytesPerLineRead", STAMUNIT_OCCURENCES, "SVGA_REG_BYTES_PER_LINE reads.");
6355 STAM_REL_REG(pVM, &pThis->svga.StatRegCapabilitesRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/CapabilitesRead", STAMUNIT_OCCURENCES, "SVGA_REG_CAPABILITIES reads.");
6356 STAM_REL_REG(pVM, &pThis->svga.StatRegConfigDoneRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/ConfigDoneRead", STAMUNIT_OCCURENCES, "SVGA_REG_CONFIG_DONE reads.");
6357 STAM_REL_REG(pVM, &pThis->svga.StatRegCursorXxxxRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/CursorXxxxRead", STAMUNIT_OCCURENCES, "SVGA_REG_CURSOR_XXXX reads.");
6358 STAM_REL_REG(pVM, &pThis->svga.StatRegDepthRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DepthRead", STAMUNIT_OCCURENCES, "SVGA_REG_DEPTH reads.");
6359 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayHeightRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayHeightRead", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_HEIGHT reads.");
6360 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayIdRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayIdRead", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_ID reads.");
6361 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayIsPrimaryRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayIsPrimaryRead", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_IS_PRIMARY reads.");
6362 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayPositionXRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayPositionXRead", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_POSITION_X reads.");
6363 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayPositionYRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayPositionYRead", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_POSITION_Y reads.");
6364 STAM_REL_REG(pVM, &pThis->svga.StatRegDisplayWidthRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/DisplayWidthRead", STAMUNIT_OCCURENCES, "SVGA_REG_DISPLAY_WIDTH reads.");
6365 STAM_REL_REG(pVM, &pThis->svga.StatRegEnableRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/EnableRead", STAMUNIT_OCCURENCES, "SVGA_REG_ENABLE reads.");
6366 STAM_REL_REG(pVM, &pThis->svga.StatRegFbOffsetRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/FbOffsetRead", STAMUNIT_OCCURENCES, "SVGA_REG_FB_OFFSET reads.");
6367 STAM_REL_REG(pVM, &pThis->svga.StatRegFbSizeRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/FbSizeRead", STAMUNIT_OCCURENCES, "SVGA_REG_FB_SIZE reads.");
6368 STAM_REL_REG(pVM, &pThis->svga.StatRegFbStartRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/FbStartRead", STAMUNIT_OCCURENCES, "SVGA_REG_FB_START reads.");
6369 STAM_REL_REG(pVM, &pThis->svga.StatRegGmrIdRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GmrIdRead", STAMUNIT_OCCURENCES, "SVGA_REG_GMR_ID reads.");
6370 STAM_REL_REG(pVM, &pThis->svga.StatRegGmrMaxDescriptorLengthRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GmrMaxDescriptorLengthRead", STAMUNIT_OCCURENCES, "SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH reads.");
6371 STAM_REL_REG(pVM, &pThis->svga.StatRegGmrMaxIdsRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GmrMaxIdsRead", STAMUNIT_OCCURENCES, "SVGA_REG_GMR_MAX_IDS reads.");
6372 STAM_REL_REG(pVM, &pThis->svga.StatRegGmrsMaxPagesRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GmrsMaxPagesRead", STAMUNIT_OCCURENCES, "SVGA_REG_GMRS_MAX_PAGES reads.");
6373 STAM_REL_REG(pVM, &pThis->svga.StatRegGreenMaskRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GreenMaskRead", STAMUNIT_OCCURENCES, "SVGA_REG_GREEN_MASK reads.");
6374 STAM_REL_REG(pVM, &pThis->svga.StatRegGuestIdRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/GuestIdRead", STAMUNIT_OCCURENCES, "SVGA_REG_GUEST_ID reads.");
6375 STAM_REL_REG(pVM, &pThis->svga.StatRegHeightRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/HeightRead", STAMUNIT_OCCURENCES, "SVGA_REG_HEIGHT reads.");
6376 STAM_REL_REG(pVM, &pThis->svga.StatRegHostBitsPerPixelRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/HostBitsPerPixelRead", STAMUNIT_OCCURENCES, "SVGA_REG_HOST_BITS_PER_PIXEL reads.");
6377 STAM_REL_REG(pVM, &pThis->svga.StatRegIdRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/IdRead", STAMUNIT_OCCURENCES, "SVGA_REG_ID reads.");
6378 STAM_REL_REG(pVM, &pThis->svga.StatRegIrqMaskRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/IrqMaskRead", STAMUNIT_OCCURENCES, "SVGA_REG_IRQ_MASK reads.");
6379 STAM_REL_REG(pVM, &pThis->svga.StatRegMaxHeightRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/MaxHeightRead", STAMUNIT_OCCURENCES, "SVGA_REG_MAX_HEIGHT reads.");
6380 STAM_REL_REG(pVM, &pThis->svga.StatRegMaxWidthRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/MaxWidthRead", STAMUNIT_OCCURENCES, "SVGA_REG_MAX_WIDTH reads.");
6381 STAM_REL_REG(pVM, &pThis->svga.StatRegMemorySizeRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/MemorySizeRead", STAMUNIT_OCCURENCES, "SVGA_REG_MEMORY_SIZE reads.");
6382 STAM_REL_REG(pVM, &pThis->svga.StatRegMemRegsRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/MemRegsRead", STAMUNIT_OCCURENCES, "SVGA_REG_MEM_REGS reads.");
6383 STAM_REL_REG(pVM, &pThis->svga.StatRegMemSizeRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/MemSizeRead", STAMUNIT_OCCURENCES, "SVGA_REG_MEM_SIZE reads.");
6384 STAM_REL_REG(pVM, &pThis->svga.StatRegMemStartRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/MemStartRead", STAMUNIT_OCCURENCES, "SVGA_REG_MEM_START reads.");
6385 STAM_REL_REG(pVM, &pThis->svga.StatRegNumDisplaysRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/NumDisplaysRead", STAMUNIT_OCCURENCES, "SVGA_REG_NUM_DISPLAYS reads.");
6386 STAM_REL_REG(pVM, &pThis->svga.StatRegNumGuestDisplaysRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/NumGuestDisplaysRead", STAMUNIT_OCCURENCES, "SVGA_REG_NUM_GUEST_DISPLAYS reads.");
6387 STAM_REL_REG(pVM, &pThis->svga.StatRegPaletteRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/PaletteRead", STAMUNIT_OCCURENCES, "SVGA_REG_PLAETTE_XXXX reads.");
6388 STAM_REL_REG(pVM, &pThis->svga.StatRegPitchLockRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/PitchLockRead", STAMUNIT_OCCURENCES, "SVGA_REG_PITCHLOCK reads.");
6389 STAM_REL_REG(pVM, &pThis->svga.StatRegPsuedoColorRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/PsuedoColorRead", STAMUNIT_OCCURENCES, "SVGA_REG_PSEUDOCOLOR reads.");
6390 STAM_REL_REG(pVM, &pThis->svga.StatRegRedMaskRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/RedMaskRead", STAMUNIT_OCCURENCES, "SVGA_REG_RED_MASK reads.");
6391 STAM_REL_REG(pVM, &pThis->svga.StatRegScratchRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/ScratchRead", STAMUNIT_OCCURENCES, "SVGA_REG_SCRATCH reads.");
6392 STAM_REL_REG(pVM, &pThis->svga.StatRegScratchSizeRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/ScratchSizeRead", STAMUNIT_OCCURENCES, "SVGA_REG_SCRATCH_SIZE reads.");
6393 STAM_REL_REG(pVM, &pThis->svga.StatRegSyncRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/SyncRead", STAMUNIT_OCCURENCES, "SVGA_REG_SYNC reads.");
6394 STAM_REL_REG(pVM, &pThis->svga.StatRegTopRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/TopRead", STAMUNIT_OCCURENCES, "SVGA_REG_TOP reads.");
6395 STAM_REL_REG(pVM, &pThis->svga.StatRegTracesRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/TracesRead", STAMUNIT_OCCURENCES, "SVGA_REG_TRACES reads.");
6396 STAM_REL_REG(pVM, &pThis->svga.StatRegUnknownRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/UnknownRead", STAMUNIT_OCCURENCES, "SVGA_REG_UNKNOWN reads.");
6397 STAM_REL_REG(pVM, &pThis->svga.StatRegVramSizeRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/VramSizeRead", STAMUNIT_OCCURENCES, "SVGA_REG_VRAM_SIZE reads.");
6398 STAM_REL_REG(pVM, &pThis->svga.StatRegWidthRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/WidthRead", STAMUNIT_OCCURENCES, "SVGA_REG_WIDTH reads.");
6399 STAM_REL_REG(pVM, &pThis->svga.StatRegWriteOnlyRd, STAMTYPE_COUNTER, "/Devices/VMSVGA/Reg/WriteOnlyRead", STAMUNIT_OCCURENCES, "Write-only SVGA_REG_XXXX reads.");
6400
6401 STAM_REL_REG(pVM, &pSVGAState->StatBusyDelayEmts, STAMTYPE_PROFILE, "/Devices/VMSVGA/EmtDelayOnBusyFifo", STAMUNIT_TICKS_PER_CALL, "Time we've delayed EMTs because of busy FIFO thread.");
6402 STAM_REL_REG(pVM, &pSVGAState->StatFifoCommands, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoCommands", STAMUNIT_OCCURENCES, "FIFO command counter.");
6403 STAM_REL_REG(pVM, &pSVGAState->StatFifoErrors, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoErrors", STAMUNIT_OCCURENCES, "FIFO error counter.");
6404 STAM_REL_REG(pVM, &pSVGAState->StatFifoUnkCmds, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoUnknownCommands", STAMUNIT_OCCURENCES, "FIFO unknown command counter.");
6405 STAM_REL_REG(pVM, &pSVGAState->StatFifoTodoTimeout, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoTodoTimeout", STAMUNIT_OCCURENCES, "Number of times we discovered pending work after a wait timeout.");
6406 STAM_REL_REG(pVM, &pSVGAState->StatFifoTodoWoken, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoTodoWoken", STAMUNIT_OCCURENCES, "Number of times we discovered pending work after being woken up.");
6407 STAM_REL_REG(pVM, &pSVGAState->StatFifoStalls, STAMTYPE_PROFILE, "/Devices/VMSVGA/FifoStalls", STAMUNIT_TICKS_PER_CALL, "Profiling of FIFO stalls (waiting for guest to finish copying data).");
6408 STAM_REL_REG(pVM, &pSVGAState->StatFifoExtendedSleep, STAMTYPE_PROFILE, "/Devices/VMSVGA/FifoExtendedSleep", STAMUNIT_TICKS_PER_CALL, "Profiling FIFO sleeps relying on the refresh timer and/or access handler.");
6409# if defined(VMSVGA_USE_FIFO_ACCESS_HANDLER) || defined(DEBUG_FIFO_ACCESS)
6410 STAM_REL_REG(pVM, &pSVGAState->StatFifoAccessHandler, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoAccessHandler", STAMUNIT_OCCURENCES, "Number of times the FIFO access handler triggered.");
6411# endif
6412 STAM_REL_REG(pVM, &pSVGAState->StatFifoCursorFetchAgain, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoCursorFetchAgain", STAMUNIT_OCCURENCES, "Times the cursor update counter changed while reading.");
6413 STAM_REL_REG(pVM, &pSVGAState->StatFifoCursorNoChange, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoCursorNoChange", STAMUNIT_OCCURENCES, "No cursor position change event though the update counter was modified.");
6414 STAM_REL_REG(pVM, &pSVGAState->StatFifoCursorPosition, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoCursorPosition", STAMUNIT_OCCURENCES, "Cursor position and visibility changes.");
6415 STAM_REL_REG(pVM, &pSVGAState->StatFifoCursorVisiblity, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoCursorVisiblity", STAMUNIT_OCCURENCES, "Cursor visibility changes.");
6416 STAM_REL_REG(pVM, &pSVGAState->StatFifoWatchdogWakeUps, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoWatchdogWakeUps", STAMUNIT_OCCURENCES, "Number of times the FIFO refresh poller/watchdog woke up the FIFO thread.");
6417
6418 /*
6419 * Info handlers.
6420 */
6421 PDMDevHlpDBGFInfoRegister(pDevIns, "vmsvga", "Basic VMSVGA device state details", vmsvgaR3Info);
6422# ifdef VBOX_WITH_VMSVGA3D
6423 PDMDevHlpDBGFInfoRegister(pDevIns, "vmsvga3dctx", "VMSVGA 3d context details. Accepts 'terse'.", vmsvgaR3Info3dContext);
6424 PDMDevHlpDBGFInfoRegister(pDevIns, "vmsvga3dsfc",
6425 "VMSVGA 3d surface details. "
6426 "Accepts 'terse', 'invy', and one of 'tiny', 'medium', 'normal', 'big', 'huge', or 'gigantic'.",
6427 vmsvgaR3Info3dSurface);
6428 PDMDevHlpDBGFInfoRegister(pDevIns, "vmsvga3dsurf",
6429 "VMSVGA 3d surface details and bitmap: "
6430 "sid[>dir]",
6431 vmsvgaR3Info3dSurfaceBmp);
6432# endif
6433
6434 return VINF_SUCCESS;
6435}
6436
6437/**
6438 * Power On notification.
6439 *
6440 * @returns VBox status code.
6441 * @param pDevIns The device instance data.
6442 *
6443 * @remarks Caller enters the device critical section.
6444 */
6445DECLCALLBACK(void) vmsvgaR3PowerOn(PPDMDEVINS pDevIns)
6446{
6447# ifdef VBOX_WITH_VMSVGA3D
6448 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
6449 if (pThis->svga.f3DEnabled)
6450 {
6451 int rc = vmsvga3dPowerOn(pThis);
6452
6453 if (RT_SUCCESS(rc))
6454 {
6455 /* Initialize FIFO 3D capabilities. */
6456 vmsvgaInitFifo3DCaps(pThis);
6457 }
6458 }
6459# else /* !VBOX_WITH_VMSVGA3D */
6460 RT_NOREF(pDevIns);
6461# endif /* !VBOX_WITH_VMSVGA3D */
6462}
6463
6464#endif /* IN_RING3 */
6465
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette