VirtualBox

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

Last change on this file since 76276 was 76249, checked in by vboxsync, 6 years ago

DevVGA-SVGA: removed obsolete HostWindowId

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