VirtualBox

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

Last change on this file since 74944 was 73328, checked in by vboxsync, 6 years ago

DevVGA-SVGA: SVGA_CMD_BLIT_GMRFB_TO_SCREEN and SVGA_CMD_BLIT_SCREEN_TO_GMRFB updates

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