VirtualBox

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

Last change on this file since 95164 was 95164, checked in by vboxsync, 3 years ago

Devices/Graphics: avoid deadlock on power off.

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