VirtualBox

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

Last change on this file since 54158 was 54158, checked in by vboxsync, 10 years ago

svga3d: log 3d capabilities.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 171.7 KB
Line 
1/* $Id: DevVGA-SVGA.cpp 54158 2015-02-11 18:57:02Z 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-2014 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/*******************************************************************************
27* Header Files *
28*******************************************************************************/
29#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
30#define VMSVGA_USE_EMT_HALT_CODE
31#include <VBox/vmm/pdmdev.h>
32#include <VBox/version.h>
33#include <VBox/err.h>
34#include <VBox/log.h>
35#include <VBox/vmm/pgm.h>
36#ifdef VMSVGA_USE_EMT_HALT_CODE
37# include <VBox/vmm/vmapi.h>
38# include <VBox/vmm/vmcpuset.h>
39#endif
40#include <VBox/sup.h>
41
42#include <iprt/assert.h>
43#include <iprt/semaphore.h>
44#include <iprt/uuid.h>
45#ifdef IN_RING3
46# include <iprt/mem.h>
47#endif
48
49#include <VBox/VMMDev.h>
50#include <VBox/VBoxVideo.h>
51#include <VBox/bioslogo.h>
52
53/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
54#include "DevVGA.h"
55
56#ifdef DEBUG
57/* Enable to log FIFO register accesses. */
58//# define DEBUG_FIFO_ACCESS
59/* Enable to log GMR page accesses. */
60//# define DEBUG_GMR_ACCESS
61#endif
62
63#include "DevVGA-SVGA.h"
64#include "vmsvga/svga_reg.h"
65#include "vmsvga/svga_escape.h"
66#include "vmsvga/svga_overlay.h"
67#include "vmsvga/svga3d_reg.h"
68#include "vmsvga/svga3d_caps.h"
69#ifdef VBOX_WITH_VMSVGA3D
70# include "DevVGA-SVGA3d.h"
71#endif
72
73/*******************************************************************************
74* Defined Constants And Macros *
75*******************************************************************************/
76/**
77 * Macro for checking if a fixed FIFO register is valid according to the
78 * current FIFO configuration.
79 *
80 * @returns true / false.
81 * @param a_iIndex The fifo register index (like SVGA_FIFO_CAPABILITIES).
82 * @param a_offFifoMin A valid SVGA_FIFO_MIN value.
83 */
84#define VMSVGA_IS_VALID_FIFO_REG(a_iIndex, a_offFifoMin) ( ((a_iIndex) + 1) * sizeof(uint32_t) <= (a_offFifoMin) )
85
86
87/*******************************************************************************
88* Structures and Typedefs *
89*******************************************************************************/
90/* 64-bit GMR descriptor */
91typedef struct
92{
93 RTGCPHYS GCPhys;
94 uint64_t numPages;
95} VMSVGAGMRDESCRIPTOR, *PVMSVGAGMRDESCRIPTOR;
96
97/* GMR slot */
98typedef struct
99{
100 uint32_t cMaxPages;
101 uint32_t cbTotal;
102 uint32_t numDescriptors;
103 PVMSVGAGMRDESCRIPTOR paDesc;
104} GMR, *PGMR;
105
106/* Internal SVGA state. */
107typedef struct
108{
109 GMR aGMR[VMSVGA_MAX_GMR_IDS];
110 struct
111 {
112 SVGAGuestPtr ptr;
113 uint32_t bytesPerLine;
114 SVGAGMRImageFormat format;
115 } GMRFB;
116 struct
117 {
118 bool fActive;
119 uint32_t xHotspot;
120 uint32_t yHotspot;
121 uint32_t width;
122 uint32_t height;
123 uint32_t cbData;
124 void *pData;
125 } Cursor;
126 SVGAColorBGRX colorAnnotation;
127
128#ifdef VMSVGA_USE_EMT_HALT_CODE
129 /** Number of EMTs in BusyDelayedEmts (quicker than scanning the set). */
130 uint32_t volatile cBusyDelayedEmts;
131 /** Set of EMTs that are */
132 VMCPUSET BusyDelayedEmts;
133#else
134 /** Number of EMTs waiting on hBusyDelayedEmts. */
135 uint32_t volatile cBusyDelayedEmts;
136 /** Semaphore that EMTs wait on when reading SVGA_REG_BUSY and the FIFO is
137 * busy (ugly). */
138 RTSEMEVENTMULTI hBusyDelayedEmts;
139#endif
140 /** Tracks how much time we waste reading SVGA_REG_BUSY with a busy FIFO. */
141 STAMPROFILE StatBusyDelayEmts;
142
143 STAMPROFILE StatR3CmdPresent;
144 STAMPROFILE StatR3CmdDrawPrimitive;
145 STAMPROFILE StatR3CmdSurfaceDMA;
146
147 STAMCOUNTER StatFifoCommands;
148 STAMCOUNTER StatFifoErrors;
149 STAMCOUNTER StatFifoUnkCmds;
150 STAMCOUNTER StatFifoTodoTimeout;
151 STAMCOUNTER StatFifoTodoWoken;
152 STAMPROFILE StatFifoStalls;
153
154} VMSVGASTATE, *PVMSVGASTATE;
155
156#ifdef IN_RING3
157
158/**
159 * SSM descriptor table for the VMSVGAGMRDESCRIPTOR structure.
160 */
161static SSMFIELD const g_aVMSVGAGMRDESCRIPTORFields[] =
162{
163 SSMFIELD_ENTRY_GCPHYS( VMSVGAGMRDESCRIPTOR, GCPhys),
164 SSMFIELD_ENTRY( VMSVGAGMRDESCRIPTOR, numPages),
165 SSMFIELD_ENTRY_TERM()
166};
167
168/**
169 * SSM descriptor table for the GMR structure.
170 */
171static SSMFIELD const g_aGMRFields[] =
172{
173 SSMFIELD_ENTRY( GMR, cMaxPages),
174 SSMFIELD_ENTRY( GMR, cbTotal),
175 SSMFIELD_ENTRY( GMR, numDescriptors),
176 SSMFIELD_ENTRY_IGN_HCPTR( GMR, paDesc),
177 SSMFIELD_ENTRY_TERM()
178};
179
180/**
181 * SSM descriptor table for the VMSVGASTATE structure.
182 */
183static SSMFIELD const g_aVMSVGASTATEFields[] =
184{
185 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, aGMR),
186 SSMFIELD_ENTRY( VMSVGASTATE, GMRFB),
187 SSMFIELD_ENTRY( VMSVGASTATE, Cursor.fActive),
188 SSMFIELD_ENTRY( VMSVGASTATE, Cursor.xHotspot),
189 SSMFIELD_ENTRY( VMSVGASTATE, Cursor.yHotspot),
190 SSMFIELD_ENTRY( VMSVGASTATE, Cursor.width),
191 SSMFIELD_ENTRY( VMSVGASTATE, Cursor.height),
192 SSMFIELD_ENTRY( VMSVGASTATE, Cursor.cbData),
193 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGASTATE, Cursor.pData),
194 SSMFIELD_ENTRY( VMSVGASTATE, colorAnnotation),
195 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, cBusyDelayedEmts),
196#ifdef VMSVGA_USE_EMT_HALT_CODE
197 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, BusyDelayedEmts),
198#else
199 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, hBusyDelayedEmts),
200#endif
201 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatBusyDelayEmts),
202 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatR3CmdPresent),
203 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatR3CmdDrawPrimitive),
204 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatR3CmdSurfaceDMA),
205 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatFifoCommands),
206 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatFifoErrors),
207 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatFifoUnkCmds),
208 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatFifoTodoTimeout),
209 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatFifoTodoWoken),
210 SSMFIELD_ENTRY_IGNORE( VMSVGASTATE, StatFifoStalls),
211 SSMFIELD_ENTRY_TERM()
212};
213
214/**
215 * SSM descriptor table for the VGAState.svga structure.
216 */
217static SSMFIELD const g_aVGAStateSVGAFields[] =
218{
219 SSMFIELD_ENTRY_IGNORE( VMSVGAState, u64HostWindowId),
220 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pFIFOR3),
221 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pFIFOR0),
222 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pSVGAState),
223 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, p3dState),
224 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pFrameBufferBackup),
225 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pFIFOExtCmdParam),
226 SSMFIELD_ENTRY_IGN_GCPHYS( VMSVGAState, GCPhysFIFO),
227 SSMFIELD_ENTRY_IGNORE( VMSVGAState, cbFIFO),
228 SSMFIELD_ENTRY( VMSVGAState, u32SVGAId),
229 SSMFIELD_ENTRY( VMSVGAState, fEnabled),
230 SSMFIELD_ENTRY( VMSVGAState, fConfigured),
231 SSMFIELD_ENTRY( VMSVGAState, fBusy),
232 SSMFIELD_ENTRY( VMSVGAState, fTraces),
233 SSMFIELD_ENTRY( VMSVGAState, u32GuestId),
234 SSMFIELD_ENTRY( VMSVGAState, cScratchRegion),
235 SSMFIELD_ENTRY( VMSVGAState, au32ScratchRegion),
236 SSMFIELD_ENTRY( VMSVGAState, u32IrqStatus),
237 SSMFIELD_ENTRY( VMSVGAState, u32IrqMask),
238 SSMFIELD_ENTRY( VMSVGAState, u32PitchLock),
239 SSMFIELD_ENTRY( VMSVGAState, u32CurrentGMRId),
240 SSMFIELD_ENTRY( VMSVGAState, u32RegCaps),
241 SSMFIELD_ENTRY_IGNORE( VMSVGAState, BasePort),
242 SSMFIELD_ENTRY( VMSVGAState, u32IndexReg),
243 SSMFIELD_ENTRY_IGNORE( VMSVGAState, pSupDrvSession),
244 SSMFIELD_ENTRY_IGNORE( VMSVGAState, FIFORequestSem),
245 SSMFIELD_ENTRY_IGNORE( VMSVGAState, FIFOExtCmdSem),
246 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGAState, pFIFOIOThread),
247 SSMFIELD_ENTRY( VMSVGAState, uWidth),
248 SSMFIELD_ENTRY( VMSVGAState, uHeight),
249 SSMFIELD_ENTRY( VMSVGAState, uBpp),
250 SSMFIELD_ENTRY( VMSVGAState, cbScanline),
251 SSMFIELD_ENTRY( VMSVGAState, u32MaxWidth),
252 SSMFIELD_ENTRY( VMSVGAState, u32MaxHeight),
253 SSMFIELD_ENTRY( VMSVGAState, u32ActionFlags),
254 SSMFIELD_ENTRY( VMSVGAState, f3DEnabled),
255 SSMFIELD_ENTRY( VMSVGAState, fVRAMTracking),
256 SSMFIELD_ENTRY_IGNORE( VMSVGAState, u8FIFOExtCommand),
257 SSMFIELD_ENTRY_TERM()
258};
259
260static void vmsvgaSetTraces(PVGASTATE pThis, bool fTraces);
261
262#endif /* IN_RING3 */
263
264
265#ifdef LOG_ENABLED
266/**
267 * Index register string name lookup
268 *
269 * @returns Index register string or "UNKNOWN"
270 * @param pThis VMSVGA State
271 */
272static const char *vmsvgaIndexToString(PVGASTATE pThis)
273{
274 switch (pThis->svga.u32IndexReg)
275 {
276 case SVGA_REG_ID:
277 return "SVGA_REG_ID";
278 case SVGA_REG_ENABLE:
279 return "SVGA_REG_ENABLE";
280 case SVGA_REG_WIDTH:
281 return "SVGA_REG_WIDTH";
282 case SVGA_REG_HEIGHT:
283 return "SVGA_REG_HEIGHT";
284 case SVGA_REG_MAX_WIDTH:
285 return "SVGA_REG_MAX_WIDTH";
286 case SVGA_REG_MAX_HEIGHT:
287 return "SVGA_REG_MAX_HEIGHT";
288 case SVGA_REG_DEPTH:
289 return "SVGA_REG_DEPTH";
290 case SVGA_REG_BITS_PER_PIXEL: /* Current bpp in the guest */
291 return "SVGA_REG_BITS_PER_PIXEL";
292 case SVGA_REG_HOST_BITS_PER_PIXEL: /* (Deprecated) */
293 return "SVGA_REG_HOST_BITS_PER_PIXEL";
294 case SVGA_REG_PSEUDOCOLOR:
295 return "SVGA_REG_PSEUDOCOLOR";
296 case SVGA_REG_RED_MASK:
297 return "SVGA_REG_RED_MASK";
298 case SVGA_REG_GREEN_MASK:
299 return "SVGA_REG_GREEN_MASK";
300 case SVGA_REG_BLUE_MASK:
301 return "SVGA_REG_BLUE_MASK";
302 case SVGA_REG_BYTES_PER_LINE:
303 return "SVGA_REG_BYTES_PER_LINE";
304 case SVGA_REG_VRAM_SIZE: /* VRAM size */
305 return "SVGA_REG_VRAM_SIZE";
306 case SVGA_REG_FB_START: /* Frame buffer physical address. */
307 return "SVGA_REG_FB_START";
308 case SVGA_REG_FB_OFFSET: /* Offset of the frame buffer in VRAM */
309 return "SVGA_REG_FB_OFFSET";
310 case SVGA_REG_FB_SIZE: /* Frame buffer size */
311 return "SVGA_REG_FB_SIZE";
312 case SVGA_REG_CAPABILITIES:
313 return "SVGA_REG_CAPABILITIES";
314 case SVGA_REG_MEM_START: /* FIFO start */
315 return "SVGA_REG_MEM_START";
316 case SVGA_REG_MEM_SIZE: /* FIFO size */
317 return "SVGA_REG_MEM_SIZE";
318 case SVGA_REG_CONFIG_DONE: /* Set when memory area configured */
319 return "SVGA_REG_CONFIG_DONE";
320 case SVGA_REG_SYNC: /* See "FIFO Synchronization Registers" */
321 return "SVGA_REG_SYNC";
322 case SVGA_REG_BUSY: /* See "FIFO Synchronization Registers" */
323 return "SVGA_REG_BUSY";
324 case SVGA_REG_GUEST_ID: /* Set guest OS identifier */
325 return "SVGA_REG_GUEST_ID";
326 case SVGA_REG_SCRATCH_SIZE: /* Number of scratch registers */
327 return "SVGA_REG_SCRATCH_SIZE";
328 case SVGA_REG_MEM_REGS: /* Number of FIFO registers */
329 return "SVGA_REG_MEM_REGS";
330 case SVGA_REG_PITCHLOCK: /* Fixed pitch for all modes */
331 return "SVGA_REG_PITCHLOCK";
332 case SVGA_REG_IRQMASK: /* Interrupt mask */
333 return "SVGA_REG_IRQMASK";
334 case SVGA_REG_GMR_ID:
335 return "SVGA_REG_GMR_ID";
336 case SVGA_REG_GMR_DESCRIPTOR:
337 return "SVGA_REG_GMR_DESCRIPTOR";
338 case SVGA_REG_GMR_MAX_IDS:
339 return "SVGA_REG_GMR_MAX_IDS";
340 case SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH:
341 return "SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH";
342 case SVGA_REG_TRACES: /* Enable trace-based updates even when FIFO is on */
343 return "SVGA_REG_TRACES";
344 case SVGA_REG_GMRS_MAX_PAGES: /* Maximum number of 4KB pages for all GMRs */
345 return "SVGA_REG_GMRS_MAX_PAGES";
346 case SVGA_REG_MEMORY_SIZE: /* Total dedicated device memory excluding FIFO */
347 return "SVGA_REG_MEMORY_SIZE";
348 case SVGA_REG_TOP: /* Must be 1 more than the last register */
349 return "SVGA_REG_TOP";
350 case SVGA_PALETTE_BASE: /* Base of SVGA color map */
351 return "SVGA_PALETTE_BASE";
352 case SVGA_REG_CURSOR_ID:
353 return "SVGA_REG_CURSOR_ID";
354 case SVGA_REG_CURSOR_X:
355 return "SVGA_REG_CURSOR_X";
356 case SVGA_REG_CURSOR_Y:
357 return "SVGA_REG_CURSOR_Y";
358 case SVGA_REG_CURSOR_ON:
359 return "SVGA_REG_CURSOR_ON";
360 case SVGA_REG_NUM_GUEST_DISPLAYS:/* Number of guest displays in X/Y direction */
361 return "SVGA_REG_NUM_GUEST_DISPLAYS";
362 case SVGA_REG_DISPLAY_ID: /* Display ID for the following display attributes */
363 return "SVGA_REG_DISPLAY_ID";
364 case SVGA_REG_DISPLAY_IS_PRIMARY:/* Whether this is a primary display */
365 return "SVGA_REG_DISPLAY_IS_PRIMARY";
366 case SVGA_REG_DISPLAY_POSITION_X:/* The display position x */
367 return "SVGA_REG_DISPLAY_POSITION_X";
368 case SVGA_REG_DISPLAY_POSITION_Y:/* The display position y */
369 return "SVGA_REG_DISPLAY_POSITION_Y";
370 case SVGA_REG_DISPLAY_WIDTH: /* The display's width */
371 return "SVGA_REG_DISPLAY_WIDTH";
372 case SVGA_REG_DISPLAY_HEIGHT: /* The display's height */
373 return "SVGA_REG_DISPLAY_HEIGHT";
374 case SVGA_REG_NUM_DISPLAYS: /* (Deprecated) */
375 return "SVGA_REG_NUM_DISPLAYS";
376
377 default:
378 if (pThis->svga.u32IndexReg - (uint32_t)SVGA_SCRATCH_BASE < pThis->svga.cScratchRegion)
379 return "SVGA_SCRATCH_BASE reg";
380 if (pThis->svga.u32IndexReg - (uint32_t)SVGA_PALETTE_BASE < (uint32_t)SVGA_NUM_PALETTE_REGS)
381 return "SVGA_PALETTE_BASE reg";
382 return "UNKNOWN";
383 }
384}
385
386/**
387 * FIFO command name lookup
388 *
389 * @returns FIFO command string or "UNKNOWN"
390 * @param u32Cmd FIFO command
391 */
392static const char *vmsvgaFIFOCmdToString(uint32_t u32Cmd)
393{
394 switch (u32Cmd)
395 {
396 case SVGA_CMD_INVALID_CMD:
397 return "SVGA_CMD_INVALID_CMD";
398 case SVGA_CMD_UPDATE:
399 return "SVGA_CMD_UPDATE";
400 case SVGA_CMD_RECT_COPY:
401 return "SVGA_CMD_RECT_COPY";
402 case SVGA_CMD_DEFINE_CURSOR:
403 return "SVGA_CMD_DEFINE_CURSOR";
404 case SVGA_CMD_DEFINE_ALPHA_CURSOR:
405 return "SVGA_CMD_DEFINE_ALPHA_CURSOR";
406 case SVGA_CMD_UPDATE_VERBOSE:
407 return "SVGA_CMD_UPDATE_VERBOSE";
408 case SVGA_CMD_FRONT_ROP_FILL:
409 return "SVGA_CMD_FRONT_ROP_FILL";
410 case SVGA_CMD_FENCE:
411 return "SVGA_CMD_FENCE";
412 case SVGA_CMD_ESCAPE:
413 return "SVGA_CMD_ESCAPE";
414 case SVGA_CMD_DEFINE_SCREEN:
415 return "SVGA_CMD_DEFINE_SCREEN";
416 case SVGA_CMD_DESTROY_SCREEN:
417 return "SVGA_CMD_DESTROY_SCREEN";
418 case SVGA_CMD_DEFINE_GMRFB:
419 return "SVGA_CMD_DEFINE_GMRFB";
420 case SVGA_CMD_BLIT_GMRFB_TO_SCREEN:
421 return "SVGA_CMD_BLIT_GMRFB_TO_SCREEN";
422 case SVGA_CMD_BLIT_SCREEN_TO_GMRFB:
423 return "SVGA_CMD_BLIT_SCREEN_TO_GMRFB";
424 case SVGA_CMD_ANNOTATION_FILL:
425 return "SVGA_CMD_ANNOTATION_FILL";
426 case SVGA_CMD_ANNOTATION_COPY:
427 return "SVGA_CMD_ANNOTATION_COPY";
428 case SVGA_CMD_DEFINE_GMR2:
429 return "SVGA_CMD_DEFINE_GMR2";
430 case SVGA_CMD_REMAP_GMR2:
431 return "SVGA_CMD_REMAP_GMR2";
432 case SVGA_3D_CMD_SURFACE_DEFINE:
433 return "SVGA_3D_CMD_SURFACE_DEFINE";
434 case SVGA_3D_CMD_SURFACE_DESTROY:
435 return "SVGA_3D_CMD_SURFACE_DESTROY";
436 case SVGA_3D_CMD_SURFACE_COPY:
437 return "SVGA_3D_CMD_SURFACE_COPY";
438 case SVGA_3D_CMD_SURFACE_STRETCHBLT:
439 return "SVGA_3D_CMD_SURFACE_STRETCHBLT";
440 case SVGA_3D_CMD_SURFACE_DMA:
441 return "SVGA_3D_CMD_SURFACE_DMA";
442 case SVGA_3D_CMD_CONTEXT_DEFINE:
443 return "SVGA_3D_CMD_CONTEXT_DEFINE";
444 case SVGA_3D_CMD_CONTEXT_DESTROY:
445 return "SVGA_3D_CMD_CONTEXT_DESTROY";
446 case SVGA_3D_CMD_SETTRANSFORM:
447 return "SVGA_3D_CMD_SETTRANSFORM";
448 case SVGA_3D_CMD_SETZRANGE:
449 return "SVGA_3D_CMD_SETZRANGE";
450 case SVGA_3D_CMD_SETRENDERSTATE:
451 return "SVGA_3D_CMD_SETRENDERSTATE";
452 case SVGA_3D_CMD_SETRENDERTARGET:
453 return "SVGA_3D_CMD_SETRENDERTARGET";
454 case SVGA_3D_CMD_SETTEXTURESTATE:
455 return "SVGA_3D_CMD_SETTEXTURESTATE";
456 case SVGA_3D_CMD_SETMATERIAL:
457 return "SVGA_3D_CMD_SETMATERIAL";
458 case SVGA_3D_CMD_SETLIGHTDATA:
459 return "SVGA_3D_CMD_SETLIGHTDATA";
460 case SVGA_3D_CMD_SETLIGHTENABLED:
461 return "SVGA_3D_CMD_SETLIGHTENABLED";
462 case SVGA_3D_CMD_SETVIEWPORT:
463 return "SVGA_3D_CMD_SETVIEWPORT";
464 case SVGA_3D_CMD_SETCLIPPLANE:
465 return "SVGA_3D_CMD_SETCLIPPLANE";
466 case SVGA_3D_CMD_CLEAR:
467 return "SVGA_3D_CMD_CLEAR";
468 case SVGA_3D_CMD_PRESENT:
469 return "SVGA_3D_CMD_PRESENT";
470 case SVGA_3D_CMD_SHADER_DEFINE:
471 return "SVGA_3D_CMD_SHADER_DEFINE";
472 case SVGA_3D_CMD_SHADER_DESTROY:
473 return "SVGA_3D_CMD_SHADER_DESTROY";
474 case SVGA_3D_CMD_SET_SHADER:
475 return "SVGA_3D_CMD_SET_SHADER";
476 case SVGA_3D_CMD_SET_SHADER_CONST:
477 return "SVGA_3D_CMD_SET_SHADER_CONST";
478 case SVGA_3D_CMD_DRAW_PRIMITIVES:
479 return "SVGA_3D_CMD_DRAW_PRIMITIVES";
480 case SVGA_3D_CMD_SETSCISSORRECT:
481 return "SVGA_3D_CMD_SETSCISSORRECT";
482 case SVGA_3D_CMD_BEGIN_QUERY:
483 return "SVGA_3D_CMD_BEGIN_QUERY";
484 case SVGA_3D_CMD_END_QUERY:
485 return "SVGA_3D_CMD_END_QUERY";
486 case SVGA_3D_CMD_WAIT_FOR_QUERY:
487 return "SVGA_3D_CMD_WAIT_FOR_QUERY";
488 case SVGA_3D_CMD_PRESENT_READBACK:
489 return "SVGA_3D_CMD_PRESENT_READBACK";
490 case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN:
491 return "SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN";
492 case SVGA_3D_CMD_SURFACE_DEFINE_V2:
493 return "SVGA_3D_CMD_SURFACE_DEFINE_V2";
494 case SVGA_3D_CMD_GENERATE_MIPMAPS:
495 return "SVGA_3D_CMD_GENERATE_MIPMAPS";
496 case SVGA_3D_CMD_ACTIVATE_SURFACE:
497 return "SVGA_3D_CMD_ACTIVATE_SURFACE";
498 case SVGA_3D_CMD_DEACTIVATE_SURFACE:
499 return "SVGA_3D_CMD_DEACTIVATE_SURFACE";
500 default:
501 return "UNKNOWN";
502 }
503}
504#endif
505
506/**
507 * Inform the VGA device of viewport changes (as a result of e.g. scrolling)
508 *
509 * @param pInterface Pointer to this interface.
510 * @param
511 * @param uScreenId The screen updates are for.
512 * @param x The upper left corner x coordinate of the new viewport rectangle
513 * @param y The upper left corner y coordinate of the new viewport rectangle
514 * @param cx The width of the new viewport rectangle
515 * @param cy The height of the new viewport rectangle
516 * @thread The emulation thread.
517 */
518DECLCALLBACK(void) vmsvgaPortSetViewPort(PPDMIDISPLAYPORT pInterface, uint32_t uScreenId, uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
519{
520 PVGASTATE pThis = RT_FROM_MEMBER(pInterface, VGASTATE, IPort);
521
522 Log(("vmsvgaPortSetViewPort: screen %d (%d,%d)(%d,%d)\n", uScreenId, x, y, cx, cy));
523
524 pThis->svga.viewport.x = x;
525 pThis->svga.viewport.y = y;
526 pThis->svga.viewport.cx = RT_MIN(cx, (uint32_t)pThis->svga.uWidth);
527 pThis->svga.viewport.cy = RT_MIN(cy, (uint32_t)pThis->svga.uHeight);
528 return;
529}
530
531/**
532 * Read port register
533 *
534 * @returns VBox status code.
535 * @param pThis VMSVGA State
536 * @param pu32 Where to store the read value
537 */
538PDMBOTHCBDECL(int) vmsvgaReadPort(PVGASTATE pThis, uint32_t *pu32)
539{
540 int rc = VINF_SUCCESS;
541
542 *pu32 = 0;
543 switch (pThis->svga.u32IndexReg)
544 {
545 case SVGA_REG_ID:
546 *pu32 = pThis->svga.u32SVGAId;
547 break;
548
549 case SVGA_REG_ENABLE:
550 *pu32 = pThis->svga.fEnabled;
551 break;
552
553 case SVGA_REG_WIDTH:
554 {
555 if ( pThis->svga.fEnabled
556 && pThis->svga.uWidth != VMSVGA_VAL_UNINITIALIZED)
557 {
558 *pu32 = pThis->svga.uWidth;
559 }
560 else
561 {
562#ifndef IN_RING3
563 rc = VINF_IOM_R3_IOPORT_READ;
564#else
565 *pu32 = pThis->pDrv->cx;
566#endif
567 }
568 break;
569 }
570
571 case SVGA_REG_HEIGHT:
572 {
573 if ( pThis->svga.fEnabled
574 && pThis->svga.uHeight != VMSVGA_VAL_UNINITIALIZED)
575 {
576 *pu32 = pThis->svga.uHeight;
577 }
578 else
579 {
580#ifndef IN_RING3
581 rc = VINF_IOM_R3_IOPORT_READ;
582#else
583 *pu32 = pThis->pDrv->cy;
584#endif
585 }
586 break;
587 }
588
589 case SVGA_REG_MAX_WIDTH:
590 *pu32 = pThis->svga.u32MaxWidth;
591 break;
592
593 case SVGA_REG_MAX_HEIGHT:
594 *pu32 = pThis->svga.u32MaxHeight;
595 break;
596
597 case SVGA_REG_DEPTH:
598 /* This returns the color depth of the current mode. */
599 switch (pThis->svga.uBpp)
600 {
601 case 15:
602 case 16:
603 case 24:
604 *pu32 = pThis->svga.uBpp;
605 break;
606
607 default:
608 case 32:
609 *pu32 = 24; /* The upper 8 bits are either alpha bits or not used. */
610 break;
611 }
612 break;
613
614 case SVGA_REG_HOST_BITS_PER_PIXEL: /* (Deprecated) */
615 if ( pThis->svga.fEnabled
616 && pThis->svga.uBpp != VMSVGA_VAL_UNINITIALIZED)
617 {
618 *pu32 = pThis->svga.uBpp;
619 }
620 else
621 {
622#ifndef IN_RING3
623 rc = VINF_IOM_R3_IOPORT_READ;
624#else
625 *pu32 = pThis->pDrv->cBits;
626#endif
627 }
628 break;
629
630 case SVGA_REG_BITS_PER_PIXEL: /* Current bpp in the guest */
631 if ( pThis->svga.fEnabled
632 && pThis->svga.uBpp != VMSVGA_VAL_UNINITIALIZED)
633 {
634 *pu32 = (pThis->svga.uBpp + 7) & ~7;
635 }
636 else
637 {
638#ifndef IN_RING3
639 rc = VINF_IOM_R3_IOPORT_READ;
640#else
641 *pu32 = (pThis->pDrv->cBits + 7) & ~7;
642#endif
643 }
644 break;
645
646 case SVGA_REG_PSEUDOCOLOR:
647 *pu32 = 0;
648 break;
649
650 case SVGA_REG_RED_MASK:
651 case SVGA_REG_GREEN_MASK:
652 case SVGA_REG_BLUE_MASK:
653 {
654 uint32_t uBpp;
655
656 if ( pThis->svga.fEnabled
657 && pThis->svga.uBpp != VMSVGA_VAL_UNINITIALIZED)
658 {
659 uBpp = pThis->svga.uBpp;
660 }
661 else
662 {
663#ifndef IN_RING3
664 rc = VINF_IOM_R3_IOPORT_READ;
665 break;
666#else
667 uBpp = pThis->pDrv->cBits;
668#endif
669 }
670 uint32_t u32RedMask, u32GreenMask, u32BlueMask;
671 switch (uBpp)
672 {
673 case 8:
674 u32RedMask = 0x07;
675 u32GreenMask = 0x38;
676 u32BlueMask = 0xc0;
677 break;
678
679 case 15:
680 u32RedMask = 0x0000001f;
681 u32GreenMask = 0x000003e0;
682 u32BlueMask = 0x00007c00;
683 break;
684
685 case 16:
686 u32RedMask = 0x0000001f;
687 u32GreenMask = 0x000007e0;
688 u32BlueMask = 0x0000f800;
689 break;
690
691 case 24:
692 case 32:
693 default:
694 u32RedMask = 0x00ff0000;
695 u32GreenMask = 0x0000ff00;
696 u32BlueMask = 0x000000ff;
697 break;
698 }
699 switch (pThis->svga.u32IndexReg)
700 {
701 case SVGA_REG_RED_MASK:
702 *pu32 = u32RedMask;
703 break;
704
705 case SVGA_REG_GREEN_MASK:
706 *pu32 = u32GreenMask;
707 break;
708
709 case SVGA_REG_BLUE_MASK:
710 *pu32 = u32BlueMask;
711 break;
712 }
713 break;
714 }
715
716 case SVGA_REG_BYTES_PER_LINE:
717 {
718 if ( pThis->svga.fEnabled
719 && pThis->svga.cbScanline)
720 {
721 *pu32 = pThis->svga.cbScanline;
722 }
723 else
724 {
725#ifndef IN_RING3
726 rc = VINF_IOM_R3_IOPORT_READ;
727#else
728 *pu32 = pThis->pDrv->cbScanline;
729#endif
730 }
731 break;
732 }
733
734 case SVGA_REG_VRAM_SIZE: /* VRAM size */
735 *pu32 = pThis->vram_size;
736 break;
737
738 case SVGA_REG_FB_START: /* Frame buffer physical address. */
739 Assert(pThis->GCPhysVRAM <= 0xffffffff);
740 *pu32 = pThis->GCPhysVRAM;
741 break;
742
743 case SVGA_REG_FB_OFFSET: /* Offset of the frame buffer in VRAM */
744 /* Always zero in our case. */
745 *pu32 = 0;
746 break;
747
748 case SVGA_REG_FB_SIZE: /* Frame buffer size */
749 {
750#ifndef IN_RING3
751 rc = VINF_IOM_R3_IOPORT_READ;
752#else
753 /* VMWare testcases want at least 4 MB in case the hardware is disabled. */
754 if ( pThis->svga.fEnabled
755 && pThis->svga.uHeight != VMSVGA_VAL_UNINITIALIZED)
756 {
757 /* Hardware enabled; return real framebuffer size .*/
758 *pu32 = (uint32_t)pThis->svga.uHeight * pThis->svga.cbScanline;
759 }
760 else
761 *pu32 = RT_MAX(0x100000, (uint32_t)pThis->pDrv->cy * pThis->pDrv->cbScanline);
762
763 *pu32 = RT_MIN(pThis->vram_size, *pu32);
764 Log(("h=%d w=%d bpp=%d\n", pThis->pDrv->cy, pThis->pDrv->cx, pThis->pDrv->cBits));
765#endif
766 break;
767 }
768
769 case SVGA_REG_CAPABILITIES:
770 *pu32 = pThis->svga.u32RegCaps;
771 break;
772
773 case SVGA_REG_MEM_START: /* FIFO start */
774 Assert(pThis->svga.GCPhysFIFO <= 0xffffffff);
775 *pu32 = pThis->svga.GCPhysFIFO;
776 break;
777
778 case SVGA_REG_MEM_SIZE: /* FIFO size */
779 *pu32 = pThis->svga.cbFIFO;
780 break;
781
782 case SVGA_REG_CONFIG_DONE: /* Set when memory area configured */
783 *pu32 = pThis->svga.fConfigured;
784 break;
785
786 case SVGA_REG_SYNC: /* See "FIFO Synchronization Registers" */
787 *pu32 = 0;
788 break;
789
790 case SVGA_REG_BUSY: /* See "FIFO Synchronization Registers" */
791 if (pThis->svga.fBusy)
792 {
793#ifndef IN_RING3
794 /* Go to ring-3 and halt the CPU. */
795 rc = VINF_IOM_R3_IOPORT_READ;
796 break;
797#elif defined(VMSVGA_USE_EMT_HALT_CODE)
798 /* The guest is basically doing a HLT via the device here, but with
799 a special wake up condition on FIFO completion. */
800 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
801 STAM_REL_PROFILE_START(&pSVGAState->StatBusyDelayEmts, EmtDelay);
802 PVM pVM = PDMDevHlpGetVM(pThis->pDevInsR3);
803 VMCPUID idCpu = PDMDevHlpGetCurrentCpuId(pThis->pDevInsR3);
804 VMCPUSET_ATOMIC_ADD(&pSVGAState->BusyDelayedEmts, idCpu);
805 ASMAtomicIncU32(&pSVGAState->cBusyDelayedEmts);
806 if (pThis->svga.fBusy)
807 rc = VMR3WaitForDeviceReady(pVM, idCpu);
808 ASMAtomicDecU32(&pSVGAState->cBusyDelayedEmts);
809 VMCPUSET_ATOMIC_DEL(&pSVGAState->BusyDelayedEmts, idCpu);
810#else
811
812 /* Delay the EMT a bit so the FIFO and others can get some work done.
813 This used to be a crude 50 ms sleep. The current code tries to be
814 more efficient, but the consept is still very crude. */
815 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
816 STAM_REL_PROFILE_START(&pSVGAState->StatBusyDelayEmts, EmtDelay);
817 RTThreadYield();
818 if (pThis->svga.fBusy)
819 {
820 uint32_t cRefs = ASMAtomicIncU32(&pSVGAState->cBusyDelayedEmts);
821
822 if (pThis->svga.fBusy && cRefs == 1)
823 RTSemEventMultiReset(pSVGAState->hBusyDelayedEmts);
824 if (pThis->svga.fBusy)
825 {
826 /** @todo If this code is going to stay, we need to call into the halt/wait
827 * code in VMEmt.cpp here, otherwise all kind of EMT interaction will
828 * suffer when the guest is polling on a busy FIFO. */
829 uint64_t cNsMaxWait = TMVirtualSyncGetNsToDeadline(PDMDevHlpGetVM(pThis->pDevInsR3));
830 if (cNsMaxWait >= RT_NS_100US)
831 RTSemEventMultiWaitEx(pSVGAState->hBusyDelayedEmts,
832 RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NORESUME,
833 RT_MIN(cNsMaxWait, RT_NS_10MS));
834 }
835
836 ASMAtomicDecU32(&pSVGAState->cBusyDelayedEmts);
837 }
838 STAM_REL_PROFILE_STOP(&pSVGAState->StatBusyDelayEmts, EmtDelay);
839#endif
840 *pu32 = pThis->svga.fBusy != 0;
841 }
842 else
843 *pu32 = false;
844 break;
845
846 case SVGA_REG_GUEST_ID: /* Set guest OS identifier */
847 *pu32 = pThis->svga.u32GuestId;
848 break;
849
850 case SVGA_REG_SCRATCH_SIZE: /* Number of scratch registers */
851 *pu32 = pThis->svga.cScratchRegion;
852 break;
853
854 case SVGA_REG_MEM_REGS: /* Number of FIFO registers */
855 *pu32 = SVGA_FIFO_NUM_REGS;
856 break;
857
858 case SVGA_REG_PITCHLOCK: /* Fixed pitch for all modes */
859 *pu32 = pThis->svga.u32PitchLock;
860 break;
861
862 case SVGA_REG_IRQMASK: /* Interrupt mask */
863 *pu32 = pThis->svga.u32IrqMask;
864 break;
865
866 /* See "Guest memory regions" below. */
867 case SVGA_REG_GMR_ID:
868 *pu32 = pThis->svga.u32CurrentGMRId;
869 break;
870
871 case SVGA_REG_GMR_DESCRIPTOR:
872 /* Write only */
873 *pu32 = 0;
874 break;
875
876 case SVGA_REG_GMR_MAX_IDS:
877 *pu32 = VMSVGA_MAX_GMR_IDS;
878 break;
879
880 case SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH:
881 *pu32 = VMSVGA_MAX_GMR_PAGES;
882 break;
883
884 case SVGA_REG_TRACES: /* Enable trace-based updates even when FIFO is on */
885 *pu32 = pThis->svga.fTraces;
886 break;
887
888 case SVGA_REG_GMRS_MAX_PAGES: /* Maximum number of 4KB pages for all GMRs */
889 *pu32 = VMSVGA_MAX_GMR_PAGES;
890 break;
891
892 case SVGA_REG_MEMORY_SIZE: /* Total dedicated device memory excluding FIFO */
893 *pu32 = VMSVGA_SURFACE_SIZE;
894 break;
895
896 case SVGA_REG_TOP: /* Must be 1 more than the last register */
897 break;
898
899 case SVGA_PALETTE_BASE: /* Base of SVGA color map */
900 break;
901 /* Next 768 (== 256*3) registers exist for colormap */
902
903 /* Mouse cursor support. */
904 case SVGA_REG_CURSOR_ID:
905 case SVGA_REG_CURSOR_X:
906 case SVGA_REG_CURSOR_Y:
907 case SVGA_REG_CURSOR_ON:
908 break;
909
910 /* Legacy multi-monitor support */
911 case SVGA_REG_NUM_GUEST_DISPLAYS:/* Number of guest displays in X/Y direction */
912 *pu32 = 1;
913 break;
914
915 case SVGA_REG_DISPLAY_ID: /* Display ID for the following display attributes */
916 case SVGA_REG_DISPLAY_IS_PRIMARY:/* Whether this is a primary display */
917 case SVGA_REG_DISPLAY_POSITION_X:/* The display position x */
918 case SVGA_REG_DISPLAY_POSITION_Y:/* The display position y */
919 *pu32 = 0;
920 break;
921
922 case SVGA_REG_DISPLAY_WIDTH: /* The display's width */
923 *pu32 = pThis->svga.uWidth;
924 break;
925
926 case SVGA_REG_DISPLAY_HEIGHT: /* The display's height */
927 *pu32 = pThis->svga.uHeight;
928 break;
929
930 case SVGA_REG_NUM_DISPLAYS: /* (Deprecated) */
931 *pu32 = 1; /* Must return something sensible here otherwise the Linux driver will take a legacy code path without 3d support. */
932 break;
933
934 default:
935 if ( pThis->svga.u32IndexReg >= SVGA_SCRATCH_BASE
936 && pThis->svga.u32IndexReg < SVGA_SCRATCH_BASE + pThis->svga.cScratchRegion)
937 {
938 *pu32 = pThis->svga.au32ScratchRegion[pThis->svga.u32IndexReg - SVGA_SCRATCH_BASE];
939 }
940 break;
941 }
942 Log(("vmsvgaReadPort index=%s (%d) val=%#x rc=%x\n", vmsvgaIndexToString(pThis), pThis->svga.u32IndexReg, *pu32, rc));
943 return rc;
944}
945
946#ifdef IN_RING3
947/**
948 * Apply the current resolution settings to change the video mode.
949 *
950 * @returns VBox status code.
951 * @param pThis VMSVGA State
952 */
953int vmsvgaChangeMode(PVGASTATE pThis)
954{
955 int rc;
956
957 if ( pThis->svga.uWidth == VMSVGA_VAL_UNINITIALIZED
958 || pThis->svga.uHeight == VMSVGA_VAL_UNINITIALIZED
959 || pThis->svga.uBpp == VMSVGA_VAL_UNINITIALIZED)
960 {
961 /* Mode change in progress; wait for all values to be set. */
962 Log(("vmsvgaChangeMode: BOGUS sEnable LFB mode and resize to (%d,%d) bpp=%d\n", pThis->svga.uWidth, pThis->svga.uHeight, pThis->svga.uBpp));
963 return VINF_SUCCESS;
964 }
965
966 if ( pThis->svga.uWidth == 0
967 || pThis->svga.uHeight == 0
968 || pThis->svga.uBpp == 0)
969 {
970 /* Invalid mode change. */
971 Log(("vmsvgaChangeMode: BOGUS sEnable LFB mode and resize to (%d,%d) bpp=%d\n", pThis->svga.uWidth, pThis->svga.uHeight, pThis->svga.uBpp));
972 return VINF_SUCCESS;
973 }
974
975 if ( pThis->last_bpp == (unsigned)pThis->svga.uBpp
976 && pThis->last_scr_width == (unsigned)pThis->svga.uWidth
977 && pThis->last_scr_height == (unsigned)pThis->svga.uHeight
978 && pThis->last_width == (unsigned)pThis->svga.uWidth
979 && pThis->last_height == (unsigned)pThis->svga.uHeight
980 )
981 {
982 /* Nothing to do. */
983 Log(("vmsvgaChangeMode: nothing changed; ignore\n"));
984 return VINF_SUCCESS;
985 }
986
987 Log(("vmsvgaChangeMode: sEnable LFB mode and resize to (%d,%d) bpp=%d\n", pThis->svga.uWidth, pThis->svga.uHeight, pThis->svga.uBpp));
988 pThis->svga.cbScanline = ((pThis->svga.uWidth * pThis->svga.uBpp + 7) & ~7) / 8;
989
990 pThis->pDrv->pfnLFBModeChange(pThis->pDrv, true);
991 rc = pThis->pDrv->pfnResize(pThis->pDrv, pThis->svga.uBpp, pThis->CTX_SUFF(vram_ptr), pThis->svga.cbScanline, pThis->svga.uWidth, pThis->svga.uHeight);
992 AssertRC(rc);
993 AssertReturn(rc == VINF_SUCCESS || rc == VINF_VGA_RESIZE_IN_PROGRESS, rc);
994
995 /* last stuff */
996 pThis->last_bpp = pThis->svga.uBpp;
997 pThis->last_scr_width = pThis->svga.uWidth;
998 pThis->last_scr_height = pThis->svga.uHeight;
999 pThis->last_width = pThis->svga.uWidth;
1000 pThis->last_height = pThis->svga.uHeight;
1001
1002 ASMAtomicOrU32(&pThis->svga.u32ActionFlags, VMSVGA_ACTION_CHANGEMODE);
1003
1004 /* vmsvgaPortSetViewPort not called after state load; set sensible defaults. */
1005 if ( pThis->svga.viewport.cx == 0
1006 && pThis->svga.viewport.cy == 0)
1007 {
1008 pThis->svga.viewport.cx = pThis->svga.uWidth;
1009 pThis->svga.viewport.cy = pThis->svga.uHeight;
1010 }
1011 return VINF_SUCCESS;
1012}
1013#endif /* IN_RING3 */
1014
1015#if defined(IN_RING0) || defined(IN_RING3)
1016/**
1017 * Safely updates the SVGA_FIFO_BUSY register (in shared memory).
1018 *
1019 * @param pThis The VMSVGA state.
1020 * @param fState The busy state.
1021 */
1022DECLINLINE(void) vmsvgaSafeFifoBusyRegUpdate(PVGASTATE pThis, bool fState)
1023{
1024 ASMAtomicWriteU32(&pThis->svga.CTX_SUFF(pFIFO)[SVGA_FIFO_BUSY], fState);
1025
1026 if (RT_UNLIKELY(fState != (pThis->svga.fBusy != 0)))
1027 {
1028 /* Race / unfortunately scheduling. Highly unlikly. */
1029 uint32_t cLoops = 64;
1030 do
1031 {
1032 ASMNopPause();
1033 fState = (pThis->svga.fBusy != 0);
1034 ASMAtomicWriteU32(&pThis->svga.CTX_SUFF(pFIFO)[SVGA_FIFO_BUSY], fState != 0);
1035 } while (cLoops-- > 0 && fState != (pThis->svga.fBusy != 0));
1036 }
1037}
1038#endif
1039
1040/**
1041 * Write port register
1042 *
1043 * @returns VBox status code.
1044 * @param pThis VMSVGA State
1045 * @param u32 Value to write
1046 */
1047PDMBOTHCBDECL(int) vmsvgaWritePort(PVGASTATE pThis, uint32_t u32)
1048{
1049 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
1050 int rc = VINF_SUCCESS;
1051
1052 Log(("vmsvgaWritePort index=%s (%d) val=%#x\n", vmsvgaIndexToString(pThis), pThis->svga.u32IndexReg, u32));
1053 switch (pThis->svga.u32IndexReg)
1054 {
1055 case SVGA_REG_ID:
1056 if ( u32 == SVGA_ID_0
1057 || u32 == SVGA_ID_1
1058 || u32 == SVGA_ID_2)
1059 pThis->svga.u32SVGAId = u32;
1060 break;
1061
1062 case SVGA_REG_ENABLE:
1063 if ( pThis->svga.fEnabled == u32
1064 && pThis->last_bpp == (unsigned)pThis->svga.uBpp
1065 && pThis->last_scr_width == (unsigned)pThis->svga.uWidth
1066 && pThis->last_scr_height == (unsigned)pThis->svga.uHeight
1067 && pThis->last_width == (unsigned)pThis->svga.uWidth
1068 && pThis->last_height == (unsigned)pThis->svga.uHeight
1069 )
1070 /* Nothing to do. */
1071 break;
1072
1073#ifdef IN_RING3
1074 if ( u32 == 1
1075 && pThis->svga.fEnabled == false)
1076 {
1077 /* Make a backup copy of the first 32k in order to save font data etc. */
1078 memcpy(pThis->svga.pFrameBufferBackup, pThis->vram_ptrR3, VMSVGA_FRAMEBUFFER_BACKUP_SIZE);
1079 }
1080
1081 pThis->svga.fEnabled = u32;
1082 if (pThis->svga.fEnabled)
1083 {
1084 if ( pThis->svga.uWidth == VMSVGA_VAL_UNINITIALIZED
1085 && pThis->svga.uHeight == VMSVGA_VAL_UNINITIALIZED
1086 && pThis->svga.uBpp == VMSVGA_VAL_UNINITIALIZED)
1087 {
1088 /* Keep the current mode. */
1089 pThis->svga.uWidth = pThis->pDrv->cx;
1090 pThis->svga.uHeight = pThis->pDrv->cy;
1091 pThis->svga.uBpp = (pThis->pDrv->cBits + 7) & ~7;
1092 }
1093
1094 if ( pThis->svga.uWidth != VMSVGA_VAL_UNINITIALIZED
1095 && pThis->svga.uHeight != VMSVGA_VAL_UNINITIALIZED
1096 && pThis->svga.uBpp != VMSVGA_VAL_UNINITIALIZED)
1097 {
1098 rc = vmsvgaChangeMode(pThis);
1099 AssertRCReturn(rc, rc);
1100 }
1101 Log(("configured=%d busy=%d\n", pThis->svga.fConfigured, pThis->svga.pFIFOR3[SVGA_FIFO_BUSY]));
1102 uint32_t *pFIFO = pThis->svga.pFIFOR3;
1103 Log(("next %x stop %x\n", pFIFO[SVGA_FIFO_NEXT_CMD], pFIFO[SVGA_FIFO_STOP]));
1104
1105 /* Disable or enable dirty page tracking according to the current fTraces value. */
1106 vmsvgaSetTraces(pThis, !!pThis->svga.fTraces);
1107 }
1108 else
1109 {
1110 /* Restore the text mode backup. */
1111 memcpy(pThis->vram_ptrR3, pThis->svga.pFrameBufferBackup, VMSVGA_FRAMEBUFFER_BACKUP_SIZE);
1112
1113/* pThis->svga.uHeight = -1;
1114 pThis->svga.uWidth = -1;
1115 pThis->svga.uBpp = -1;
1116 pThis->svga.cbScanline = 0; */
1117 pThis->pDrv->pfnLFBModeChange(pThis->pDrv, false);
1118
1119 /* Enable dirty page tracking again when going into legacy mode. */
1120 vmsvgaSetTraces(pThis, true);
1121 }
1122#else
1123 rc = VINF_IOM_R3_IOPORT_WRITE;
1124#endif
1125 break;
1126
1127 case SVGA_REG_WIDTH:
1128 if (pThis->svga.uWidth != u32)
1129 {
1130 if (pThis->svga.fEnabled)
1131 {
1132#ifdef IN_RING3
1133 pThis->svga.uWidth = u32;
1134 rc = vmsvgaChangeMode(pThis);
1135 AssertRCReturn(rc, rc);
1136#else
1137 rc = VINF_IOM_R3_IOPORT_WRITE;
1138#endif
1139 }
1140 else
1141 pThis->svga.uWidth = u32;
1142 }
1143 /* else: nop */
1144 break;
1145
1146 case SVGA_REG_HEIGHT:
1147 if (pThis->svga.uHeight != u32)
1148 {
1149 if (pThis->svga.fEnabled)
1150 {
1151#ifdef IN_RING3
1152 pThis->svga.uHeight = u32;
1153 rc = vmsvgaChangeMode(pThis);
1154 AssertRCReturn(rc, rc);
1155#else
1156 rc = VINF_IOM_R3_IOPORT_WRITE;
1157#endif
1158 }
1159 else
1160 pThis->svga.uHeight = u32;
1161 }
1162 /* else: nop */
1163 break;
1164
1165 case SVGA_REG_DEPTH:
1166 /** @todo read-only?? */
1167 break;
1168
1169 case SVGA_REG_BITS_PER_PIXEL: /* Current bpp in the guest */
1170 if (pThis->svga.uBpp != u32)
1171 {
1172 if (pThis->svga.fEnabled)
1173 {
1174#ifdef IN_RING3
1175 pThis->svga.uBpp = u32;
1176 rc = vmsvgaChangeMode(pThis);
1177 AssertRCReturn(rc, rc);
1178#else
1179 rc = VINF_IOM_R3_IOPORT_WRITE;
1180#endif
1181 }
1182 else
1183 pThis->svga.uBpp = u32;
1184 }
1185 /* else: nop */
1186 break;
1187
1188 case SVGA_REG_PSEUDOCOLOR:
1189 break;
1190
1191 case SVGA_REG_CONFIG_DONE: /* Set when memory area configured */
1192#ifdef IN_RING3
1193 pThis->svga.fConfigured = u32;
1194 /* Disabling the FIFO enables tracing (dirty page detection) by default. */
1195 if (!pThis->svga.fConfigured)
1196 {
1197 pThis->svga.fTraces = true;
1198 }
1199 vmsvgaSetTraces(pThis, !!pThis->svga.fTraces);
1200#else
1201 rc = VINF_IOM_R3_IOPORT_WRITE;
1202#endif
1203 break;
1204
1205 case SVGA_REG_SYNC: /* See "FIFO Synchronization Registers" */
1206 if ( pThis->svga.fEnabled
1207 && pThis->svga.fConfigured)
1208 {
1209#if defined(IN_RING3) || defined(IN_RING0)
1210 Log(("SVGA_REG_SYNC: SVGA_FIFO_BUSY=%d\n", pThis->svga.CTX_SUFF(pFIFO)[SVGA_FIFO_BUSY]));
1211 ASMAtomicWriteU32(&pThis->svga.fBusy, VMSVGA_BUSY_F_EMT_FORCE | VMSVGA_BUSY_F_FIFO);
1212 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_BUSY, pThis->svga.CTX_SUFF(pFIFO)[SVGA_FIFO_MIN]))
1213 vmsvgaSafeFifoBusyRegUpdate(pThis, true);
1214
1215 /* Kick the FIFO thread to start processing commands again. */
1216 SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
1217#else
1218 rc = VINF_IOM_R3_IOPORT_WRITE;
1219#endif
1220 }
1221 /* else nothing to do. */
1222 else
1223 Log(("Sync ignored enabled=%d configured=%d\n", pThis->svga.fEnabled, pThis->svga.fConfigured));
1224
1225 break;
1226
1227 case SVGA_REG_BUSY: /* See "FIFO Synchronization Registers" (read-only) */
1228 break;
1229
1230 case SVGA_REG_GUEST_ID: /* Set guest OS identifier */
1231 pThis->svga.u32GuestId = u32;
1232 break;
1233
1234 case SVGA_REG_PITCHLOCK: /* Fixed pitch for all modes */
1235 pThis->svga.u32PitchLock = u32;
1236 break;
1237
1238 case SVGA_REG_IRQMASK: /* Interrupt mask */
1239 pThis->svga.u32IrqMask = u32;
1240
1241 /* Irq pending after the above change? */
1242 if (pThis->svga.u32IrqMask & pThis->svga.u32IrqStatus)
1243 {
1244 Log(("SVGA_REG_IRQMASK: Trigger interrupt with status %x\n", pThis->svga.u32IrqStatus));
1245 PDMDevHlpPCISetIrqNoWait(pThis->CTX_SUFF(pDevIns), 0, 1);
1246 }
1247 else
1248 PDMDevHlpPCISetIrqNoWait(pThis->CTX_SUFF(pDevIns), 0, 0);
1249 break;
1250
1251 /* Mouse cursor support */
1252 case SVGA_REG_CURSOR_ID:
1253 case SVGA_REG_CURSOR_X:
1254 case SVGA_REG_CURSOR_Y:
1255 case SVGA_REG_CURSOR_ON:
1256 break;
1257
1258 /* Legacy multi-monitor support */
1259 case SVGA_REG_NUM_GUEST_DISPLAYS:/* Number of guest displays in X/Y direction */
1260 break;
1261 case SVGA_REG_DISPLAY_ID: /* Display ID for the following display attributes */
1262 break;
1263 case SVGA_REG_DISPLAY_IS_PRIMARY:/* Whether this is a primary display */
1264 break;
1265 case SVGA_REG_DISPLAY_POSITION_X:/* The display position x */
1266 break;
1267 case SVGA_REG_DISPLAY_POSITION_Y:/* The display position y */
1268 break;
1269 case SVGA_REG_DISPLAY_WIDTH: /* The display's width */
1270 break;
1271 case SVGA_REG_DISPLAY_HEIGHT: /* The display's height */
1272 break;
1273#ifdef VBOX_WITH_VMSVGA3D
1274 /* See "Guest memory regions" below. */
1275 case SVGA_REG_GMR_ID:
1276 pThis->svga.u32CurrentGMRId = u32;
1277 break;
1278
1279 case SVGA_REG_GMR_DESCRIPTOR:
1280# ifndef IN_RING3
1281 rc = VINF_IOM_R3_IOPORT_WRITE;
1282 break;
1283# else /* IN_RING3 */
1284 {
1285 SVGAGuestMemDescriptor desc;
1286 RTGCPHYS GCPhys = (RTGCPHYS)u32 << PAGE_SHIFT;
1287 RTGCPHYS GCPhysBase = GCPhys;
1288 uint32_t idGMR = pThis->svga.u32CurrentGMRId;
1289 uint32_t cDescriptorsAllocated = 16;
1290 uint32_t iDescriptor = 0;
1291
1292 /* Validate current GMR id. */
1293 AssertBreak(idGMR < VMSVGA_MAX_GMR_IDS);
1294
1295 /* Free the old GMR if present. */
1296 vmsvgaGMRFree(pThis, idGMR);
1297
1298 /* Just undefine the GMR? */
1299 if (GCPhys == 0)
1300 break;
1301
1302 pSVGAState->aGMR[idGMR].paDesc = (PVMSVGAGMRDESCRIPTOR)RTMemAllocZ(cDescriptorsAllocated * sizeof(VMSVGAGMRDESCRIPTOR));
1303 AssertReturn(pSVGAState->aGMR[idGMR].paDesc, VERR_NO_MEMORY);
1304
1305 /* Never cross a page boundary automatically. */
1306 while (PHYS_PAGE_ADDRESS(GCPhys) == PHYS_PAGE_ADDRESS(GCPhysBase))
1307 {
1308 /* Read descriptor. */
1309 rc = PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCPhys, &desc, sizeof(desc));
1310 AssertRCBreak(rc);
1311
1312 if ( desc.ppn == 0
1313 && desc.numPages == 0)
1314 break; /* terminator */
1315
1316 if ( desc.ppn != 0
1317 && desc.numPages == 0)
1318 {
1319 /* Pointer to the next physical page of descriptors. */
1320 GCPhys = GCPhysBase = desc.ppn << PAGE_SHIFT;
1321 }
1322 else
1323 {
1324 if (iDescriptor == cDescriptorsAllocated)
1325 {
1326 cDescriptorsAllocated += 16;
1327 pSVGAState->aGMR[idGMR].paDesc = (PVMSVGAGMRDESCRIPTOR)RTMemRealloc(pSVGAState->aGMR[idGMR].paDesc, cDescriptorsAllocated * sizeof(VMSVGAGMRDESCRIPTOR));
1328 AssertReturn(pSVGAState->aGMR[idGMR].paDesc, VERR_NO_MEMORY);
1329 }
1330
1331 pSVGAState->aGMR[idGMR].paDesc[iDescriptor].GCPhys = desc.ppn << PAGE_SHIFT;
1332 pSVGAState->aGMR[idGMR].paDesc[iDescriptor++].numPages = desc.numPages;
1333 pSVGAState->aGMR[idGMR].cbTotal += desc.numPages * PAGE_SIZE;
1334
1335 /* Continue with the next descriptor. */
1336 GCPhys += sizeof(desc);
1337 }
1338 }
1339 pSVGAState->aGMR[idGMR].numDescriptors = iDescriptor;
1340 Log(("Defined new gmr %x numDescriptors=%d cbTotal=%x\n", idGMR, iDescriptor, pSVGAState->aGMR[idGMR].cbTotal));
1341
1342 if (!pSVGAState->aGMR[idGMR].numDescriptors)
1343 {
1344 AssertFailed();
1345 RTMemFree(pSVGAState->aGMR[idGMR].paDesc);
1346 pSVGAState->aGMR[idGMR].paDesc = NULL;
1347 }
1348 AssertRC(rc);
1349 break;
1350 }
1351# endif /* IN_RING3 */
1352#endif // VBOX_WITH_VMSVGA3D
1353
1354 case SVGA_REG_TRACES: /* Enable trace-based updates even when FIFO is on */
1355 if (pThis->svga.fTraces == u32)
1356 break; /* nothing to do */
1357
1358#ifdef IN_RING3
1359 vmsvgaSetTraces(pThis, !!u32);
1360#else
1361 rc = VINF_IOM_R3_IOPORT_WRITE;
1362#endif
1363 break;
1364
1365 case SVGA_REG_TOP: /* Must be 1 more than the last register */
1366 break;
1367
1368 case SVGA_PALETTE_BASE: /* Base of SVGA color map */
1369 break;
1370 /* Next 768 (== 256*3) registers exist for colormap */
1371
1372 case SVGA_REG_NUM_DISPLAYS: /* (Deprecated) */
1373 Log(("Write to deprecated register %x - val %x ignored\n", pThis->svga.u32IndexReg, u32));
1374 break;
1375
1376 case SVGA_REG_FB_START:
1377 case SVGA_REG_MEM_START:
1378 case SVGA_REG_HOST_BITS_PER_PIXEL:
1379 case SVGA_REG_MAX_WIDTH:
1380 case SVGA_REG_MAX_HEIGHT:
1381 case SVGA_REG_VRAM_SIZE:
1382 case SVGA_REG_FB_SIZE:
1383 case SVGA_REG_CAPABILITIES:
1384 case SVGA_REG_MEM_SIZE:
1385 case SVGA_REG_SCRATCH_SIZE: /* Number of scratch registers */
1386 case SVGA_REG_MEM_REGS: /* Number of FIFO registers */
1387 case SVGA_REG_BYTES_PER_LINE:
1388 case SVGA_REG_FB_OFFSET:
1389 case SVGA_REG_RED_MASK:
1390 case SVGA_REG_GREEN_MASK:
1391 case SVGA_REG_BLUE_MASK:
1392 case SVGA_REG_GMRS_MAX_PAGES: /* Maximum number of 4KB pages for all GMRs */
1393 case SVGA_REG_MEMORY_SIZE: /* Total dedicated device memory excluding FIFO */
1394 case SVGA_REG_GMR_MAX_IDS:
1395 case SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH:
1396 /* Read only - ignore. */
1397 Log(("Write to R/O register %x - val %x ignored\n", pThis->svga.u32IndexReg, u32));
1398 break;
1399
1400 default:
1401 if ( pThis->svga.u32IndexReg >= SVGA_SCRATCH_BASE
1402 && pThis->svga.u32IndexReg < SVGA_SCRATCH_BASE + pThis->svga.cScratchRegion)
1403 {
1404 pThis->svga.au32ScratchRegion[pThis->svga.u32IndexReg - SVGA_SCRATCH_BASE] = u32;
1405 }
1406 break;
1407 }
1408 return rc;
1409}
1410
1411/**
1412 * Port I/O Handler for IN operations.
1413 *
1414 * @returns VINF_SUCCESS or VINF_EM_*.
1415 * @returns VERR_IOM_IOPORT_UNUSED if the port is really unused and a ~0 value should be returned.
1416 *
1417 * @param pDevIns The device instance.
1418 * @param pvUser User argument.
1419 * @param uPort Port number used for the IN operation.
1420 * @param pu32 Where to store the result. This is always a 32-bit
1421 * variable regardless of what @a cb might say.
1422 * @param cb Number of bytes read.
1423 */
1424PDMBOTHCBDECL(int) vmsvgaIORead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
1425{
1426 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
1427 int rc = VINF_SUCCESS;
1428
1429 /* Ignore non-dword accesses. */
1430 if (cb != 4)
1431 {
1432 Log(("Ignoring non-dword read at %x cb=%d\n", Port, cb));
1433 *pu32 = ~0;
1434 return VINF_SUCCESS;
1435 }
1436
1437 switch (Port - pThis->svga.BasePort)
1438 {
1439 case SVGA_INDEX_PORT:
1440 *pu32 = pThis->svga.u32IndexReg;
1441 break;
1442
1443 case SVGA_VALUE_PORT:
1444 return vmsvgaReadPort(pThis, pu32);
1445
1446 case SVGA_BIOS_PORT:
1447 Log(("Ignoring BIOS port read\n"));
1448 *pu32 = 0;
1449 break;
1450
1451 case SVGA_IRQSTATUS_PORT:
1452 LogFlow(("vmsvgaIORead: SVGA_IRQSTATUS_PORT %x\n", pThis->svga.u32IrqStatus));
1453 *pu32 = pThis->svga.u32IrqStatus;
1454 break;
1455 }
1456 return rc;
1457}
1458
1459/**
1460 * Port I/O Handler for OUT operations.
1461 *
1462 * @returns VINF_SUCCESS or VINF_EM_*.
1463 *
1464 * @param pDevIns The device instance.
1465 * @param pvUser User argument.
1466 * @param uPort Port number used for the OUT operation.
1467 * @param u32 The value to output.
1468 * @param cb The value size in bytes.
1469 */
1470PDMBOTHCBDECL(int) vmsvgaIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
1471{
1472 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
1473 int rc = VINF_SUCCESS;
1474
1475 /* Ignore non-dword accesses. */
1476 if (cb != 4)
1477 {
1478 Log(("Ignoring non-dword write at %x val=%x cb=%d\n", Port, u32, cb));
1479 return VINF_SUCCESS;
1480 }
1481
1482 switch (Port - pThis->svga.BasePort)
1483 {
1484 case SVGA_INDEX_PORT:
1485 pThis->svga.u32IndexReg = u32;
1486 break;
1487
1488 case SVGA_VALUE_PORT:
1489 return vmsvgaWritePort(pThis, u32);
1490
1491 case SVGA_BIOS_PORT:
1492 Log(("Ignoring BIOS port write (val=%x)\n", u32));
1493 break;
1494
1495 case SVGA_IRQSTATUS_PORT:
1496 Log(("vmsvgaIOWrite SVGA_IRQSTATUS_PORT %x: status %x -> %x\n", u32, pThis->svga.u32IrqStatus, pThis->svga.u32IrqStatus & ~u32));
1497 ASMAtomicAndU32(&pThis->svga.u32IrqStatus, ~u32);
1498 /* Clear the irq in case all events have been cleared. */
1499 if (!(pThis->svga.u32IrqStatus & pThis->svga.u32IrqMask))
1500 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
1501 break;
1502 }
1503 return rc;
1504}
1505
1506#ifdef DEBUG_FIFO_ACCESS
1507
1508# ifdef IN_RING3
1509/**
1510 * Handle LFB access.
1511 * @returns VBox status code.
1512 * @param pVM VM handle.
1513 * @param pThis VGA device instance data.
1514 * @param GCPhys The access physical address.
1515 * @param fWriteAccess Read or write access
1516 */
1517static int vmsvgaFIFOAccess(PVM pVM, PVGASTATE pThis, RTGCPHYS GCPhys, bool fWriteAccess)
1518{
1519 RTGCPHYS GCPhysOffset = GCPhys - pThis->svga.GCPhysFIFO;
1520 uint32_t *pFIFO = pThis->svga.pFIFOR3;
1521
1522 switch (GCPhysOffset >> 2)
1523 {
1524 case SVGA_FIFO_MIN:
1525 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_MIN = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1526 break;
1527 case SVGA_FIFO_MAX:
1528 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_MAX = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1529 break;
1530 case SVGA_FIFO_NEXT_CMD:
1531 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_NEXT_CMD = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1532 break;
1533 case SVGA_FIFO_STOP:
1534 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_STOP = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1535 break;
1536 case SVGA_FIFO_CAPABILITIES:
1537 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CAPABILITIES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1538 break;
1539 case SVGA_FIFO_FLAGS:
1540 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_FLAGS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1541 break;
1542 case SVGA_FIFO_FENCE:
1543 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_FENCE = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1544 break;
1545 case SVGA_FIFO_3D_HWVERSION:
1546 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_HWVERSION = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1547 break;
1548 case SVGA_FIFO_PITCHLOCK:
1549 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_PITCHLOCK = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1550 break;
1551 case SVGA_FIFO_CURSOR_ON:
1552 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_ON = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1553 break;
1554 case SVGA_FIFO_CURSOR_X:
1555 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_X = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1556 break;
1557 case SVGA_FIFO_CURSOR_Y:
1558 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_Y = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1559 break;
1560 case SVGA_FIFO_CURSOR_COUNT:
1561 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_COUNT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1562 break;
1563 case SVGA_FIFO_CURSOR_LAST_UPDATED:
1564 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_LAST_UPDATED = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1565 break;
1566 case SVGA_FIFO_RESERVED:
1567 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_RESERVED = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1568 break;
1569 case SVGA_FIFO_CURSOR_SCREEN_ID:
1570 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_CURSOR_SCREEN_ID = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1571 break;
1572 case SVGA_FIFO_DEAD:
1573 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_DEAD = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1574 break;
1575 case SVGA_FIFO_3D_HWVERSION_REVISED:
1576 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_HWVERSION_REVISED = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1577 break;
1578 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_3D:
1579 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_3D = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1580 break;
1581 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_LIGHTS:
1582 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_LIGHTS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1583 break;
1584 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURES:
1585 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1586 break;
1587 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_CLIP_PLANES:
1588 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_CLIP_PLANES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1589 break;
1590 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_VERTEX_SHADER_VERSION:
1591 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_VERTEX_SHADER_VERSION = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1592 break;
1593 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_VERTEX_SHADER:
1594 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_VERTEX_SHADER = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1595 break;
1596 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION:
1597 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1598 break;
1599 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_FRAGMENT_SHADER:
1600 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_FRAGMENT_SHADER = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1601 break;
1602 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_RENDER_TARGETS:
1603 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_RENDER_TARGETS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1604 break;
1605 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_S23E8_TEXTURES:
1606 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_S23E8_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1607 break;
1608 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_S10E5_TEXTURES:
1609 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_S10E5_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1610 break;
1611 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND:
1612 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1613 break;
1614 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_D16_BUFFER_FORMAT:
1615 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_D16_BUFFER_FORMAT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1616 break;
1617 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT:
1618 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1619 break;
1620 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT:
1621 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1622 break;
1623 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_QUERY_TYPES:
1624 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_QUERY_TYPES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1625 break;
1626 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING:
1627 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1628 break;
1629 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_POINT_SIZE:
1630 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_POINT_SIZE = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1631 break;
1632 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_SHADER_TEXTURES:
1633 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_SHADER_TEXTURES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1634 break;
1635 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH:
1636 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1637 break;
1638 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT:
1639 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1640 break;
1641 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VOLUME_EXTENT:
1642 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_VOLUME_EXTENT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1643 break;
1644 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT:
1645 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1646 break;
1647 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO:
1648 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]));
1649 break;
1650 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY:
1651 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1652 break;
1653 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT:
1654 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1655 break;
1656 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VERTEX_INDEX:
1657 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_VERTEX_INDEX = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1658 break;
1659 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS:
1660 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]));
1661 break;
1662 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS:
1663 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]));
1664 break;
1665 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS:
1666 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]));
1667 break;
1668 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS:
1669 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]));
1670 break;
1671 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_TEXTURE_OPS:
1672 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_TEXTURE_OPS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1673 break;
1674 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8:
1675 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1676 break;
1677 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8:
1678 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1679 break;
1680 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10:
1681 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1682 break;
1683 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5:
1684 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1685 break;
1686 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5:
1687 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1688 break;
1689 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4:
1690 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1691 break;
1692 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_R5G6B5:
1693 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_R5G6B5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1694 break;
1695 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16:
1696 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1697 break;
1698 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8:
1699 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1700 break;
1701 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_ALPHA8:
1702 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_ALPHA8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1703 break;
1704 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8:
1705 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1706 break;
1707 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_D16:
1708 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_D16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1709 break;
1710 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8:
1711 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1712 break;
1713 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8:
1714 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1715 break;
1716 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT1:
1717 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT1 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1718 break;
1719 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT2:
1720 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT2 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1721 break;
1722 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT3:
1723 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT3 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1724 break;
1725 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT4:
1726 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT4 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1727 break;
1728 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_DXT5:
1729 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_DXT5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1730 break;
1731 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8:
1732 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1733 break;
1734 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10:
1735 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1736 break;
1737 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8:
1738 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1739 break;
1740 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8:
1741 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1742 break;
1743 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_CxV8U8:
1744 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_CxV8U8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1745 break;
1746 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_R_S10E5:
1747 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_R_S10E5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1748 break;
1749 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_R_S23E8:
1750 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_R_S23E8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1751 break;
1752 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5:
1753 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1754 break;
1755 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8:
1756 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1757 break;
1758 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5:
1759 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1760 break;
1761 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8:
1762 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1763 break;
1764 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES:
1765 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]));
1766 break;
1767 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS:
1768 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]));
1769 break;
1770 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_V16U16:
1771 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_V16U16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1772 break;
1773 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_G16R16:
1774 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_G16R16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1775 break;
1776 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16:
1777 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1778 break;
1779 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_UYVY:
1780 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_UYVY = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1781 break;
1782 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_YUY2:
1783 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_YUY2 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1784 break;
1785 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES:
1786 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1787 break;
1788 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES:
1789 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1790 break;
1791 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_ALPHATOCOVERAGE:
1792 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_ALPHATOCOVERAGE = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1793 break;
1794 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SUPERSAMPLE:
1795 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SUPERSAMPLE = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1796 break;
1797 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_AUTOGENMIPMAPS:
1798 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_AUTOGENMIPMAPS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1799 break;
1800 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_NV12:
1801 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_NV12 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1802 break;
1803 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_AYUV:
1804 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_AYUV = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1805 break;
1806 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_CONTEXT_IDS:
1807 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_CONTEXT_IDS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1808 break;
1809 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_MAX_SURFACE_IDS:
1810 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_MAX_SURFACE_IDS = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1811 break;
1812 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_DF16:
1813 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_DF16 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1814 break;
1815 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_DF24:
1816 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_Z_DF24 = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1817 break;
1818 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT:
1819 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]));
1820 break;
1821 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM:
1822 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1823 break;
1824 case SVGA_FIFO_3D_CAPS + SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM:
1825 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1826 break;
1827 case SVGA_FIFO_3D_CAPS_LAST:
1828 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_3D_CAPS_LAST = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1829 break;
1830 case SVGA_FIFO_GUEST_3D_HWVERSION:
1831 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_GUEST_3D_HWVERSION = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1832 break;
1833 case SVGA_FIFO_FENCE_GOAL:
1834 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_FENCE_GOAL = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1835 break;
1836 case SVGA_FIFO_BUSY:
1837 Log(("vmsvgaFIFOAccess [0x%x]: %s SVGA_FIFO_BUSY = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", pFIFO[GCPhysOffset >> 2]));
1838 break;
1839 default:
1840 Log(("vmsvgaFIFOAccess [0x%x]: %s access at offset %x = %x\n", GCPhysOffset >> 2, (fWriteAccess) ? "WRITE" : "READ", GCPhysOffset, pFIFO[GCPhysOffset >> 2]));
1841 break;
1842 }
1843
1844 return VINF_EM_RAW_EMULATE_INSTR;
1845}
1846
1847/**
1848 * HC access handler for the FIFO.
1849 *
1850 * @returns VINF_SUCCESS if the handler have carried out the operation.
1851 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
1852 * @param pVM VM Handle.
1853 * @param GCPhys The physical address the guest is writing to.
1854 * @param pvPhys The HC mapping of that address.
1855 * @param pvBuf What the guest is reading/writing.
1856 * @param cbBuf How much it's reading/writing.
1857 * @param enmAccessType The access type.
1858 * @param pvUser User argument.
1859 */
1860static DECLCALLBACK(int) vmsvgaR3FIFOAccessHandler(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser)
1861{
1862 PVGASTATE pThis = (PVGASTATE)pvUser;
1863 int rc;
1864 Assert(pThis);
1865 Assert(GCPhys >= pThis->GCPhysVRAM);
1866 NOREF(pvPhys); NOREF(pvBuf); NOREF(cbBuf);
1867
1868 rc = vmsvgaFIFOAccess(pVM, pThis, GCPhys, enmAccessType == PGMACCESSTYPE_WRITE);
1869 if (RT_SUCCESS(rc))
1870 return VINF_PGM_HANDLER_DO_DEFAULT;
1871 AssertMsg(rc <= VINF_SUCCESS, ("rc=%Rrc\n", rc));
1872 return rc;
1873}
1874
1875# endif /* IN_RING3 */
1876#endif /* DEBUG_FIFO_ACCESS */
1877
1878#ifdef DEBUG_GMR_ACCESS
1879/**
1880 * HC access handler for the FIFO.
1881 *
1882 * @returns VINF_SUCCESS if the handler have carried out the operation.
1883 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
1884 * @param pVM VM Handle.
1885 * @param GCPhys The physical address the guest is writing to.
1886 * @param pvPhys The HC mapping of that address.
1887 * @param pvBuf What the guest is reading/writing.
1888 * @param cbBuf How much it's reading/writing.
1889 * @param enmAccessType The access type.
1890 * @param pvUser User argument.
1891 */
1892static DECLCALLBACK(int) vmsvgaR3GMRAccessHandler(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser)
1893{
1894 PVGASTATE pThis = (PVGASTATE)pvUser;
1895 Assert(pThis);
1896 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
1897 NOREF(pvPhys); NOREF(pvBuf); NOREF(cbBuf);
1898
1899 Log(("vmsvgaR3GMRAccessHandler: GMR access to page %RGp\n", GCPhys));
1900
1901 for (uint32_t i = 0; i < RT_ELEMENTS(pSVGAState->aGMR); i++)
1902 {
1903 PGMR pGMR = &pSVGAState->aGMR[i];
1904
1905 if (pGMR->numDescriptors)
1906 {
1907 for (uint32_t j = 0; j < pGMR->numDescriptors; j++)
1908 {
1909 if ( GCPhys >= pGMR->paDesc[j].GCPhys
1910 && GCPhys < pGMR->paDesc[j].GCPhys + pGMR->paDesc[j].numPages * PAGE_SIZE)
1911 {
1912 /*
1913 * Turn off the write handler for this particular page and make it R/W.
1914 * Then return telling the caller to restart the guest instruction.
1915 */
1916 int rc = PGMHandlerPhysicalPageTempOff(pVM, pGMR->paDesc[j].GCPhys, GCPhys);
1917 goto end;
1918 }
1919 }
1920 }
1921 }
1922end:
1923 return VINF_PGM_HANDLER_DO_DEFAULT;
1924}
1925
1926# ifdef IN_RING3
1927
1928/* Callback handler for VMR3ReqCallWait */
1929static DECLCALLBACK(int) vmsvgaRegisterGMR(PPDMDEVINS pDevIns, uint32_t gmrId)
1930{
1931 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
1932 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
1933 PGMR pGMR = &pSVGAState->aGMR[gmrId];
1934 int rc;
1935
1936 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
1937 {
1938 rc = PGMR3HandlerPhysicalRegister(PDMDevHlpGetVM(pThis->pDevInsR3),
1939 PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
1940 pGMR->paDesc[i].GCPhys, pGMR->paDesc[i].GCPhys + pGMR->paDesc[i].numPages * PAGE_SIZE - 1,
1941 vmsvgaR3GMRAccessHandler, pThis,
1942 NULL, NULL, NULL,
1943 NULL, NULL, NULL,
1944 "VMSVGA GMR");
1945 AssertRC(rc);
1946 }
1947 return VINF_SUCCESS;
1948}
1949
1950/* Callback handler for VMR3ReqCallWait */
1951static DECLCALLBACK(int) vmsvgaUnregisterGMR(PPDMDEVINS pDevIns, uint32_t gmrId)
1952{
1953 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
1954 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
1955 PGMR pGMR = &pSVGAState->aGMR[gmrId];
1956
1957 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
1958 {
1959 int rc = PGMHandlerPhysicalDeregister(PDMDevHlpGetVM(pThis->pDevInsR3), pGMR->paDesc[i].GCPhys);
1960 AssertRC(rc);
1961 }
1962 return VINF_SUCCESS;
1963}
1964
1965/* Callback handler for VMR3ReqCallWait */
1966static DECLCALLBACK(int) vmsvgaResetGMRHandlers(PVGASTATE pThis)
1967{
1968 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
1969
1970 for (uint32_t i = 0; i < RT_ELEMENTS(pSVGAState->aGMR); i++)
1971 {
1972 PGMR pGMR = &pSVGAState->aGMR[i];
1973
1974 if (pGMR->numDescriptors)
1975 {
1976 for (uint32_t j = 0; j < pGMR->numDescriptors; j++)
1977 {
1978 int rc = PGMHandlerPhysicalReset(PDMDevHlpGetVM(pThis->pDevInsR3), pGMR->paDesc[j].GCPhys);
1979 AssertRC(rc);
1980 }
1981 }
1982 }
1983 return VINF_SUCCESS;
1984}
1985
1986# endif /* IN_RING3 */
1987#endif /* DEBUG_GMR_ACCESS */
1988
1989/* -=-=-=-=-=- Ring 3 -=-=-=-=-=- */
1990
1991#ifdef IN_RING3
1992
1993/**
1994 * Marks the FIFO non-busy, notifying any waiting EMTs.
1995 *
1996 * @param pThis The VGA state.
1997 * @param pSVGAState Pointer to the ring-3 only SVGA state data.
1998 * @param offFifoMin The start byte offset of the command FIFO.
1999 */
2000static void vmsvgaFifoSetNotBusy(PVGASTATE pThis, PVMSVGASTATE pSVGAState, uint32_t offFifoMin)
2001{
2002 ASMAtomicAndU32(&pThis->svga.fBusy, ~VMSVGA_BUSY_F_FIFO);
2003 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_BUSY, offFifoMin))
2004 vmsvgaSafeFifoBusyRegUpdate(pThis, pThis->svga.fBusy != 0);
2005
2006 /* Wake up any waiting EMTs. */
2007 if (pSVGAState->cBusyDelayedEmts > 0)
2008 {
2009#ifdef VMSVGA_USE_EMT_HALT_CODE
2010 PVM pVM = PDMDevHlpGetVM(pThis->pDevInsR3);
2011 VMCPUID idCpu = VMCpuSetFindLastPresentInternal(&pSVGAState->BusyDelayedEmts);
2012 if (idCpu != NIL_VMCPUID)
2013 {
2014 VMR3NotifyCpuDeviceReady(pVM, idCpu);
2015 while (idCpu-- > 0)
2016 if (VMCPUSET_IS_PRESENT(&pSVGAState->BusyDelayedEmts, idCpu))
2017 VMR3NotifyCpuDeviceReady(pVM, idCpu);
2018 }
2019#else
2020 int rc2 = RTSemEventMultiSignal(pSVGAState->hBusyDelayedEmts);
2021 AssertRC(rc2);
2022#endif
2023 }
2024}
2025
2026/**
2027 * Reads (more) payload into the command buffer.
2028 *
2029 * @returns pbBounceBuf on success
2030 * @retval (void *)1 if the thread was requested to stop.
2031 * @retval NULL on FIFO error.
2032 *
2033 * @param cbPayloadReq The number of bytes of payload requested.
2034 * @param pFIFO The FIFO.
2035 * @param offCurrentCmd The FIFO byte offset of the current command.
2036 * @param offFifoMin The start byte offset of the command FIFO.
2037 * @param offFifoMax The end byte offset of the command FIFO.
2038 * @param pbBounceBuf The bounch buffer. Same size as the entire FIFO, so
2039 * always sufficient size.
2040 * @param pcbAlreadyRead How much payload we've already read into the bounce
2041 * buffer. (We will NEVER re-read anything.)
2042 * @param pThread The calling PDM thread handle.
2043 * @param pThis The VGA state.
2044 * @param pSVGAState Pointer to the ring-3 only SVGA state data. For
2045 * statistics collection.
2046 */
2047static void *vmsvgaFIFOGetCmdPayload(uint32_t cbPayloadReq, uint32_t volatile *pFIFO,
2048 uint32_t offCurrentCmd, uint32_t offFifoMin, uint32_t offFifoMax,
2049 uint8_t *pbBounceBuf, uint32_t *pcbAlreadyRead,
2050 PPDMTHREAD pThread, PVGASTATE pThis, PVMSVGASTATE pSVGAState)
2051{
2052 Assert(pbBounceBuf);
2053 Assert(pcbAlreadyRead);
2054 Assert(offFifoMin < offFifoMax);
2055 Assert(offCurrentCmd >= offFifoMin && offCurrentCmd < offFifoMax);
2056 Assert(offFifoMax <= VMSVGA_FIFO_SIZE);
2057
2058 /*
2059 * Check if the requested payload size has already been satisfied .
2060 * .
2061 * When called to read more, the caller is responsible for making sure the .
2062 * new command size (cbRequsted) never is smaller than what has already .
2063 * been read.
2064 */
2065 uint32_t cbAlreadyRead = *pcbAlreadyRead;
2066 if (cbPayloadReq <= cbAlreadyRead)
2067 {
2068 AssertLogRelReturn(cbPayloadReq == cbAlreadyRead, NULL);
2069 return pbBounceBuf;
2070 }
2071
2072 /*
2073 * Commands bigger than the fifo buffer are invalid.
2074 */
2075 uint32_t const cbFifoCmd = offFifoMax - offFifoMin;
2076 AssertMsgReturnStmt(cbPayloadReq <= cbFifoCmd, ("cbPayloadReq=%#x cbFifoCmd=%#x\n", cbPayloadReq, cbFifoCmd),
2077 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors),
2078 NULL);
2079
2080 /*
2081 * Move offCurrentCmd past the command dword.
2082 */
2083 offCurrentCmd += sizeof(uint32_t);
2084 if (offCurrentCmd >= offFifoMax)
2085 offCurrentCmd = offFifoMin;
2086
2087 /*
2088 * Do we have sufficient payload data available already?
2089 */
2090 uint32_t cbAfter, cbBefore;
2091 uint32_t offNextCmd = pFIFO[SVGA_FIFO_NEXT_CMD];
2092 if (offNextCmd > offCurrentCmd)
2093 {
2094 if (RT_LIKELY(offNextCmd < offFifoMax))
2095 cbAfter = offNextCmd - offCurrentCmd;
2096 else
2097 {
2098 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors);
2099 LogRelMax(16, ("vmsvgaFIFOGetCmdPayload: Invalid offNextCmd=%#x (offFifoMin=%#x offFifoMax=%#x)\n",
2100 offNextCmd, offFifoMin, offFifoMax));
2101 /** @todo release counter. */
2102 cbAfter = offFifoMax - offCurrentCmd;
2103 }
2104 cbBefore = 0;
2105 }
2106 else
2107 {
2108 cbAfter = offFifoMax - offCurrentCmd;
2109 if (offNextCmd >= offFifoMin)
2110 cbBefore = offNextCmd - offFifoMin;
2111 else
2112 {
2113 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors);
2114 LogRelMax(16, ("vmsvgaFIFOGetCmdPayload: Invalid offNextCmd=%#x (offFifoMin=%#x offFifoMax=%#x)\n",
2115 offNextCmd, offFifoMin, offFifoMax));
2116 /** @todo release counter. */
2117 cbBefore = 0;
2118 }
2119 }
2120 if (cbAfter + cbBefore < cbPayloadReq)
2121 {
2122 /*
2123 * Insufficient, must wait for it to arrive.
2124 */
2125 STAM_REL_PROFILE_START(&pSVGAState->StatFifoStalls, Stall);
2126 for (uint32_t i = 0;; i++)
2127 {
2128 if (pThread->enmState != PDMTHREADSTATE_RUNNING)
2129 {
2130 STAM_REL_PROFILE_STOP(&pSVGAState->StatFifoStalls, Stall);
2131 return (void *)(uintptr_t)1;
2132 }
2133 Log(("Guest still copying (%x vs %x) current %x next %x stop %x loop %u; sleep a bit\n",
2134 cbPayloadReq, cbAfter + cbBefore, offCurrentCmd, offNextCmd, pFIFO[SVGA_FIFO_STOP], i));
2135
2136 SUPSemEventWaitNoResume(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem, i < 16 ? 1 : 2);
2137
2138 offNextCmd = pFIFO[SVGA_FIFO_NEXT_CMD];
2139 if (offNextCmd > offCurrentCmd)
2140 {
2141 cbAfter = RT_MIN(offNextCmd, offFifoMax) - offCurrentCmd;
2142 cbBefore = 0;
2143 }
2144 else
2145 {
2146 cbAfter = offFifoMax - offCurrentCmd;
2147 cbBefore = RT_MAX(offNextCmd, offFifoMin) - offFifoMin;
2148 }
2149
2150 if (cbAfter + cbBefore >= cbPayloadReq)
2151 break;
2152 }
2153 STAM_REL_PROFILE_STOP(&pSVGAState->StatFifoStalls, Stall);
2154 }
2155
2156 /*
2157 * Copy out the memory and update what pcbAlreadyRead points to.
2158 */
2159 if (cbAfter >= cbPayloadReq)
2160 memcpy(pbBounceBuf + cbAlreadyRead,
2161 (uint8_t *)pFIFO + offCurrentCmd + cbAlreadyRead,
2162 cbPayloadReq - cbAlreadyRead);
2163 else
2164 {
2165 LogFlow(("Split data buffer at %x (%u-%u)\n", offCurrentCmd, cbAfter, cbBefore));
2166 if (cbAlreadyRead < cbAfter)
2167 {
2168 memcpy(pbBounceBuf + cbAlreadyRead,
2169 (uint8_t *)pFIFO + offCurrentCmd + cbAlreadyRead,
2170 cbAfter - cbAlreadyRead);
2171 cbAlreadyRead += cbAfter - cbAlreadyRead;
2172 }
2173 memcpy(pbBounceBuf + cbAlreadyRead,
2174 (uint8_t *)pFIFO + offFifoMin + cbAlreadyRead - cbAfter,
2175 cbPayloadReq - cbAlreadyRead);
2176 }
2177 *pcbAlreadyRead = cbPayloadReq;
2178 return pbBounceBuf;
2179}
2180
2181/* The async FIFO handling thread. */
2182static DECLCALLBACK(int) vmsvgaFIFOLoop(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
2183{
2184 PVGASTATE pThis = (PVGASTATE)pThread->pvUser;
2185 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
2186 int rc;
2187
2188 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
2189 return VINF_SUCCESS;
2190
2191 /*
2192 * Signal the semaphore to make sure we don't wait for 250 after a
2193 * suspend & resume scenario (see vmsvgaFIFOGetCmdPayload).
2194 */
2195 SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
2196
2197 /*
2198 * Allocate a bounce buffer for command we get from the FIFO.
2199 * (All code must return via the end of the function to free this buffer.)
2200 */
2201 uint8_t *pbBounceBuf = (uint8_t *)RTMemAllocZ(VMSVGA_FIFO_SIZE);
2202 AssertReturn(pbBounceBuf, VERR_NO_MEMORY);
2203
2204 LogFlow(("vmsvgaFIFOLoop: started loop\n"));
2205 uint32_t volatile * const pFIFO = pThis->svga.pFIFOR3;
2206 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
2207 {
2208
2209 /*
2210 * Wait for at most 250 ms to start polling.
2211 */
2212 rc = SUPSemEventWaitNoResume(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem, 250);
2213 AssertBreak(RT_SUCCESS(rc) || rc == VERR_TIMEOUT || rc == VERR_INTERRUPTED);
2214 if (pThread->enmState != PDMTHREADSTATE_RUNNING)
2215 {
2216 LogFlow(("vmsvgaFIFOLoop: thread state %x\n", pThread->enmState));
2217 break;
2218 }
2219 if (rc == VERR_TIMEOUT)
2220 {
2221 if (pFIFO[SVGA_FIFO_NEXT_CMD] == pFIFO[SVGA_FIFO_STOP])
2222 continue;
2223 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoTodoTimeout);
2224
2225 Log(("vmsvgaFIFOLoop: timeout\n"));
2226 }
2227 else if (pFIFO[SVGA_FIFO_NEXT_CMD] != pFIFO[SVGA_FIFO_STOP])
2228 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoTodoWoken);
2229
2230 Log(("vmsvgaFIFOLoop: enabled=%d configured=%d busy=%d\n", pThis->svga.fEnabled, pThis->svga.fConfigured, pThis->svga.pFIFOR3[SVGA_FIFO_BUSY]));
2231 Log(("vmsvgaFIFOLoop: min %x max %x\n", pFIFO[SVGA_FIFO_MIN], pFIFO[SVGA_FIFO_MAX]));
2232 Log(("vmsvgaFIFOLoop: next %x stop %x\n", pFIFO[SVGA_FIFO_NEXT_CMD], pFIFO[SVGA_FIFO_STOP]));
2233
2234 /*
2235 * Handle external commands.
2236 */
2237 if (pThis->svga.u8FIFOExtCommand != VMSVGA_FIFO_EXTCMD_NONE)
2238 {
2239 switch (pThis->svga.u8FIFOExtCommand)
2240 {
2241 case VMSVGA_FIFO_EXTCMD_RESET:
2242 Log(("vmsvgaFIFOLoop: reset the fifo thread.\n"));
2243# ifdef VBOX_WITH_VMSVGA3D
2244 if (pThis->svga.f3DEnabled)
2245 {
2246 /* The 3d subsystem must be reset from the fifo thread. */
2247 vmsvga3dReset(pThis);
2248 }
2249# endif
2250 break;
2251
2252 case VMSVGA_FIFO_EXTCMD_TERMINATE:
2253 Log(("vmsvgaFIFOLoop: terminate the fifo thread.\n"));
2254# ifdef VBOX_WITH_VMSVGA3D
2255 if (pThis->svga.f3DEnabled)
2256 {
2257 /* The 3d subsystem must be shut down from the fifo thread. */
2258 vmsvga3dTerminate(pThis);
2259 }
2260# endif
2261 break;
2262
2263 case VMSVGA_FIFO_EXTCMD_SAVESTATE:
2264 Log(("vmsvgaFIFOLoop: VMSVGA_FIFO_EXTCMD_SAVESTATE.\n"));
2265# ifdef VBOX_WITH_VMSVGA3D
2266 vmsvga3dSaveExec(pThis, (PSSMHANDLE)pThis->svga.pFIFOExtCmdParam);
2267# endif
2268 break;
2269
2270 case VMSVGA_FIFO_EXTCMD_LOADSTATE:
2271 {
2272 Log(("vmsvgaFIFOLoop: VMSVGA_FIFO_EXTCMD_LOADSTATE.\n"));
2273# ifdef VBOX_WITH_VMSVGA3D
2274 PVMSVGA_STATE_LOAD pLoadState = (PVMSVGA_STATE_LOAD)pThis->svga.pFIFOExtCmdParam;
2275 vmsvga3dLoadExec(pThis, pLoadState->pSSM, pLoadState->uVersion, pLoadState->uPass);
2276# endif
2277 break;
2278 }
2279 }
2280
2281 pThis->svga.u8FIFOExtCommand = VMSVGA_FIFO_EXTCMD_NONE;
2282
2283 /* Signal the end of the external command. */
2284 RTSemEventSignal(pThis->svga.FIFOExtCmdSem);
2285 continue;
2286 }
2287
2288 if ( !pThis->svga.fEnabled
2289 || !pThis->svga.fConfigured)
2290 {
2291 vmsvgaFifoSetNotBusy(pThis, pSVGAState, pFIFO[SVGA_FIFO_MIN]);
2292 continue; /* device not enabled. */
2293 }
2294
2295 /*
2296 * Get and check the min/max values. We ASSUME that they will remain
2297 * unchanged while we process requests. A further ASSUMPTION is that
2298 * the guest won't mess with SVGA_FIFO_NEXT_CMD while we're busy, so
2299 * we don't read it back while in the loop.
2300 */
2301 uint32_t const offFifoMin = pFIFO[SVGA_FIFO_MIN];
2302 uint32_t const offFifoMax = pFIFO[SVGA_FIFO_MAX];
2303 uint32_t offCurrentCmd = pFIFO[SVGA_FIFO_STOP];
2304 if (RT_UNLIKELY( !VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_STOP, offFifoMin)
2305 || offFifoMax <= offFifoMin
2306 || offFifoMax > VMSVGA_FIFO_SIZE
2307 || (offFifoMax & 3) != 0
2308 || (offFifoMin & 3) != 0
2309 || offCurrentCmd < offFifoMin
2310 || offCurrentCmd > offFifoMax))
2311 {
2312 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors);
2313 LogRelMax(8, ("vmsvgaFIFOLoop: Bad fifo: min=%#x stop=%#x max=%#x\n", offFifoMin, offCurrentCmd, offFifoMax));
2314 vmsvgaFifoSetNotBusy(pThis, pSVGAState, offFifoMin);
2315 continue;
2316 }
2317 if (RT_UNLIKELY(offCurrentCmd & 3))
2318 {
2319 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoErrors);
2320 LogRelMax(8, ("vmsvgaFIFOLoop: Misaligned offCurrentCmd=%#x?\n", offCurrentCmd));
2321 offCurrentCmd = ~UINT32_C(3);
2322 }
2323
2324/**
2325 * Macro for shortening calls to vmsvgaFIFOGetCmdPayload.
2326 *
2327 * Will break out of the switch on failure.
2328 * Will restart and quit the loop if the thread was requested to stop.
2329 *
2330 * @param a_cbPayloadReq How much payload to fetch.
2331 * @remarks Access a bunch of variables in the current scope!
2332 */
2333# define VMSVGAFIFO_GET_CMD_BUFFER_BREAK(a_PtrVar, a_Type, a_cbPayloadReq) \
2334 if (1) { \
2335 (a_PtrVar) = (a_Type *)vmsvgaFIFOGetCmdPayload((a_cbPayloadReq), pFIFO, offCurrentCmd, offFifoMin, offFifoMax, \
2336 pbBounceBuf, &cbPayload, pThread, pThis, pSVGAState); \
2337 if (RT_UNLIKELY((uintptr_t)(a_PtrVar) < 2)) { if ((uintptr_t)(a_PtrVar) == 1) continue; break; } \
2338 } else do {} while (0)
2339/**
2340 * Macro for shortening calls to vmsvgaFIFOGetCmdPayload for refetching the
2341 * buffer after figuring out the actual command size.
2342 * Will break out of the switch on failure.
2343 * @param a_cbPayloadReq How much payload to fetch.
2344 * @remarks Access a bunch of variables in the current scope!
2345 */
2346# define VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(a_PtrVar, a_Type, a_cbPayloadReq) \
2347 if (1) { \
2348 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(a_PtrVar, a_Type, a_cbPayloadReq); \
2349 } else do {} while (0)
2350
2351 /*
2352 * Mark the FIFO as busy.
2353 */
2354 ASMAtomicWriteU32(&pThis->svga.fBusy, VMSVGA_BUSY_F_FIFO);
2355 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_BUSY, offFifoMin))
2356 ASMAtomicWriteU32(&pFIFO[SVGA_FIFO_BUSY], true);
2357
2358 /*
2359 * Execute all queued FIFO commands.
2360 * Quit if pending external command or changes in the thread state.
2361 */
2362 bool fDone = false;
2363 while ( !(fDone = pFIFO[SVGA_FIFO_NEXT_CMD] == offCurrentCmd)
2364 && pThread->enmState == PDMTHREADSTATE_RUNNING)
2365 {
2366 uint32_t cbPayload = 0;
2367 uint32_t u32IrqStatus = 0;
2368 bool fTriggerIrq = false;
2369
2370 Assert(offCurrentCmd < offFifoMax && offCurrentCmd >= offFifoMin);
2371
2372 /* First check any pending actions. */
2373 if (ASMBitTestAndClear(&pThis->svga.u32ActionFlags, VMSVGA_ACTION_CHANGEMODE_BIT))
2374# ifdef VBOX_WITH_VMSVGA3D
2375 vmsvga3dChangeMode(pThis);
2376# else
2377 {/*nothing*/}
2378# endif
2379 /* Check for pending external commands. */
2380 if (pThis->svga.u8FIFOExtCommand != VMSVGA_FIFO_EXTCMD_NONE)
2381 break;
2382
2383 /*
2384 * Process the command.
2385 */
2386 SVGAFifoCmdId const enmCmdId = (SVGAFifoCmdId)pFIFO[offCurrentCmd / sizeof(uint32_t)];
2387 LogFlow(("vmsvgaFIFOLoop: FIFO command (iCmd=0x%x) %s 0x%x\n",
2388 offCurrentCmd / sizeof(uint32_t), vmsvgaFIFOCmdToString(enmCmdId), enmCmdId));
2389 switch (enmCmdId)
2390 {
2391 case SVGA_CMD_INVALID_CMD:
2392 /* Nothing to do. */
2393 break;
2394
2395 case SVGA_CMD_FENCE:
2396 {
2397 SVGAFifoCmdFence *pCmdFence;
2398 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmdFence, SVGAFifoCmdFence, sizeof(*pCmdFence));
2399 if (VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_FENCE, offFifoMin))
2400 {
2401 Log(("vmsvgaFIFOLoop: SVGA_CMD_FENCE %x\n", pCmdFence->fence));
2402 pFIFO[SVGA_FIFO_FENCE] = pCmdFence->fence;
2403
2404 if (pThis->svga.u32IrqMask & SVGA_IRQFLAG_ANY_FENCE)
2405 {
2406 Log(("vmsvgaFIFOLoop: any fence irq\n"));
2407 u32IrqStatus |= SVGA_IRQFLAG_ANY_FENCE;
2408 }
2409 else
2410 if ( VMSVGA_IS_VALID_FIFO_REG(SVGA_FIFO_FENCE_GOAL, offFifoMin)
2411 && (pThis->svga.u32IrqMask & SVGA_IRQFLAG_FENCE_GOAL)
2412 && pFIFO[SVGA_FIFO_FENCE_GOAL] == pCmdFence->fence)
2413 {
2414 Log(("vmsvgaFIFOLoop: fence goal reached irq (fence=%x)\n", pCmdFence->fence));
2415 u32IrqStatus |= SVGA_IRQFLAG_FENCE_GOAL;
2416 }
2417 }
2418 else
2419 Log(("SVGA_CMD_FENCE is bogus when offFifoMin is %#x!\n", offFifoMin));
2420 break;
2421 }
2422 case SVGA_CMD_UPDATE:
2423 case SVGA_CMD_UPDATE_VERBOSE:
2424 {
2425 SVGAFifoCmdUpdate *pUpdate;
2426 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pUpdate, SVGAFifoCmdUpdate, sizeof(*pUpdate));
2427 Log(("vmsvgaFIFOLoop: UPDATE (%d,%d)(%d,%d)\n", pUpdate->x, pUpdate->y, pUpdate->width, pUpdate->height));
2428 vgaR3UpdateDisplay(pThis, pUpdate->x, pUpdate->y, pUpdate->width, pUpdate->height);
2429 break;
2430 }
2431
2432 case SVGA_CMD_DEFINE_CURSOR:
2433 {
2434 /* Followed by bitmap data. */
2435 SVGAFifoCmdDefineCursor *pCursor;
2436 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCursor, SVGAFifoCmdDefineCursor, sizeof(*pCursor));
2437 AssertFailed(); /** @todo implement when necessary. */
2438 break;
2439 }
2440
2441 case SVGA_CMD_DEFINE_ALPHA_CURSOR:
2442 {
2443 /* Followed by bitmap data. */
2444 uint32_t cbCursorShape, cbAndMask;
2445 uint8_t *pCursorCopy;
2446 uint32_t cbCmd;
2447
2448 SVGAFifoCmdDefineAlphaCursor *pCursor;
2449 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCursor, SVGAFifoCmdDefineAlphaCursor, sizeof(*pCursor));
2450
2451 Log(("vmsvgaFIFOLoop: ALPHA_CURSOR id=%d size (%d,%d) hotspot (%d,%d)\n", pCursor->id, pCursor->width, pCursor->height, pCursor->hotspotX, pCursor->hotspotY));
2452
2453 /* Check against a reasonable upper limit to prevent integer overflows in the sanity checks below. */
2454 AssertBreak(pCursor->height < 2048 && pCursor->width < 2048);
2455
2456 /* Refetch the bitmap data as well. */
2457 cbCmd = sizeof(SVGAFifoCmdDefineAlphaCursor) + pCursor->width * pCursor->height * sizeof(uint32_t) /* 32-bit BRGA format */;
2458 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pCursor, SVGAFifoCmdDefineAlphaCursor, cbCmd);
2459 /** @todo Would be more efficient to copy the data straight into pCursorCopy (memcpy below). */
2460
2461 /* The mouse pointer interface always expects an AND mask followed by the color data (XOR mask). */
2462 cbAndMask = (pCursor->width + 7) / 8 * pCursor->height; /* size of the AND mask */
2463 cbAndMask = ((cbAndMask + 3) & ~3); /* + gap for alignment */
2464 cbCursorShape = cbAndMask + pCursor->width * sizeof(uint32_t) * pCursor->height; /* + size of the XOR mask (32-bit BRGA format) */
2465
2466 pCursorCopy = (uint8_t *)RTMemAlloc(cbCursorShape);
2467 AssertBreak(pCursorCopy);
2468
2469 Log2(("Cursor data:\n%.*Rhxd\n", pCursor->width * pCursor->height * sizeof(uint32_t), pCursor+1));
2470
2471 /* Transparency is defined by the alpha bytes, so make the whole bitmap visible. */
2472 memset(pCursorCopy, 0xff, cbAndMask);
2473 /* Colour data */
2474 memcpy(pCursorCopy + cbAndMask, (pCursor + 1), pCursor->width * pCursor->height * sizeof(uint32_t));
2475
2476 rc = pThis->pDrv->pfnVBVAMousePointerShape (pThis->pDrv,
2477 true,
2478 true,
2479 pCursor->hotspotX,
2480 pCursor->hotspotY,
2481 pCursor->width,
2482 pCursor->height,
2483 pCursorCopy);
2484 AssertRC(rc);
2485
2486 if (pSVGAState->Cursor.fActive)
2487 RTMemFree(pSVGAState->Cursor.pData);
2488
2489 pSVGAState->Cursor.fActive = true;
2490 pSVGAState->Cursor.xHotspot = pCursor->hotspotX;
2491 pSVGAState->Cursor.yHotspot = pCursor->hotspotY;
2492 pSVGAState->Cursor.width = pCursor->width;
2493 pSVGAState->Cursor.height = pCursor->height;
2494 pSVGAState->Cursor.cbData = cbCursorShape;
2495 pSVGAState->Cursor.pData = pCursorCopy;
2496 break;
2497 }
2498
2499 case SVGA_CMD_ESCAPE:
2500 {
2501 /* Followed by nsize bytes of data. */
2502 SVGAFifoCmdEscape *pEscape;
2503 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pEscape, SVGAFifoCmdEscape, sizeof(*pEscape));
2504
2505 /* Refetch the command buffer with the variable data; undo size increase (ugly) */
2506 AssertBreak(pEscape->size < VMSVGA_FIFO_SIZE);
2507 uint32_t cbCmd = sizeof(SVGAFifoCmdEscape) + pEscape->size;
2508 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pEscape, SVGAFifoCmdEscape, cbCmd);
2509
2510 if (pEscape->nsid == SVGA_ESCAPE_NSID_VMWARE)
2511 {
2512 AssertBreak(pEscape->size >= sizeof(uint32_t));
2513 uint32_t cmd = *(uint32_t *)(pEscape + 1);
2514 Log(("vmsvgaFIFOLoop: ESCAPE (%x %x) VMWARE cmd=%x\n", pEscape->nsid, pEscape->size, cmd));
2515
2516 switch (cmd)
2517 {
2518 case SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS:
2519 {
2520 SVGAEscapeVideoSetRegs *pVideoCmd = (SVGAEscapeVideoSetRegs *)(pEscape + 1);
2521 AssertBreak(pEscape->size >= sizeof(pVideoCmd->header));
2522 uint32_t cRegs = (pEscape->size - sizeof(pVideoCmd->header)) / sizeof(pVideoCmd->items[0]);
2523
2524 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: stream %x\n", pVideoCmd->header.streamId));
2525 for (uint32_t iReg = 0; iReg < cRegs; iReg++)
2526 {
2527 Log(("SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS: reg %x val %x\n", pVideoCmd->items[iReg].registerId, pVideoCmd->items[iReg].value));
2528 }
2529 break;
2530 }
2531
2532 case SVGA_ESCAPE_VMWARE_VIDEO_FLUSH:
2533 SVGAEscapeVideoFlush *pVideoCmd = (SVGAEscapeVideoFlush *)(pEscape + 1);
2534 AssertBreak(pEscape->size >= sizeof(*pVideoCmd));
2535 Log(("SVGA_ESCAPE_VMWARE_VIDEO_FLUSH: stream %x\n", pVideoCmd->streamId));
2536 break;
2537 }
2538 }
2539 else
2540 Log(("vmsvgaFIFOLoop: ESCAPE %x %x\n", pEscape->nsid, pEscape->size));
2541
2542 break;
2543 }
2544# ifdef VBOX_WITH_VMSVGA3D
2545 case SVGA_CMD_DEFINE_GMR2:
2546 {
2547 SVGAFifoCmdDefineGMR2 *pCmd;
2548 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDefineGMR2, sizeof(*pCmd));
2549 Log(("vmsvgaFIFOLoop: SVGA_CMD_DEFINE_GMR2 id=%x %x pages\n", pCmd->gmrId, pCmd->numPages));
2550
2551 /* Validate current GMR id. */
2552 AssertBreak(pCmd->gmrId < VMSVGA_MAX_GMR_IDS);
2553 AssertBreak(pCmd->numPages <= VMSVGA_MAX_GMR_PAGES);
2554
2555 if (!pCmd->numPages)
2556 {
2557 vmsvgaGMRFree(pThis, pCmd->gmrId);
2558 }
2559 else
2560 {
2561 PGMR pGMR = &pSVGAState->aGMR[pCmd->gmrId];
2562 pGMR->cMaxPages = pCmd->numPages;
2563 }
2564 /* everything done in remap */
2565 break;
2566 }
2567
2568 case SVGA_CMD_REMAP_GMR2:
2569 {
2570 /* Followed by page descriptors or guest ptr. */
2571 SVGAFifoCmdRemapGMR2 *pCmd;
2572 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdRemapGMR2, sizeof(*pCmd));
2573 uint32_t cbPageDesc = (pCmd->flags & SVGA_REMAP_GMR2_PPN64) ? sizeof(uint64_t) : sizeof(uint32_t);
2574 uint32_t cbCmd;
2575 uint64_t *paNewPage64 = NULL;
2576
2577 Log(("vmsvgaFIFOLoop: SVGA_CMD_REMAP_GMR2 id=%x flags=%x offset=%x npages=%x\n", pCmd->gmrId, pCmd->flags, pCmd->offsetPages, pCmd->numPages));
2578 AssertBreak(pCmd->gmrId < VMSVGA_MAX_GMR_IDS);
2579
2580 /* Calculate the size of what comes after next and fetch it. */
2581 cbCmd = sizeof(SVGAFifoCmdRemapGMR2);
2582 if (pCmd->flags & SVGA_REMAP_GMR2_VIA_GMR)
2583 cbCmd += sizeof(SVGAGuestPtr);
2584 else
2585 if (pCmd->flags & SVGA_REMAP_GMR2_SINGLE_PPN)
2586 {
2587 cbCmd += cbPageDesc;
2588 pCmd->numPages = 1;
2589 }
2590 else
2591 {
2592 AssertBreak(pCmd->numPages <= VMSVGA_FIFO_SIZE);
2593 cbCmd += cbPageDesc * pCmd->numPages;
2594 }
2595 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdRemapGMR2, cbCmd);
2596
2597 /* Validate current GMR id. */
2598 AssertBreak(pCmd->gmrId < VMSVGA_MAX_GMR_IDS);
2599 PGMR pGMR = &pSVGAState->aGMR[pCmd->gmrId];
2600 AssertBreak(pCmd->offsetPages + pCmd->numPages <= pGMR->cMaxPages);
2601 AssertBreak(!pCmd->offsetPages || pGMR->paDesc); /** @todo */
2602
2603 /* Save the old page descriptors as an array of page addresses (>> PAGE_SHIFT) */
2604 if (pGMR->paDesc)
2605 {
2606 uint32_t idxPage = 0;
2607 paNewPage64 = (uint64_t *)RTMemAllocZ(pGMR->cMaxPages * sizeof(uint64_t));
2608 AssertBreak(paNewPage64);
2609
2610 for (uint32_t i = 0; i < pGMR->numDescriptors; i++)
2611 {
2612 for (uint32_t j = 0; j < pGMR->paDesc[i].numPages; j++)
2613 {
2614 paNewPage64[idxPage++] = (pGMR->paDesc[i].GCPhys + j * PAGE_SIZE) >> PAGE_SHIFT;
2615 }
2616 }
2617 AssertBreak(idxPage == pGMR->cbTotal >> PAGE_SHIFT);
2618 }
2619
2620 /* Free the old GMR if present. */
2621 if (pGMR->paDesc)
2622 RTMemFree(pGMR->paDesc);
2623
2624 /* Allocate the maximum amount possible (everything non-continuous) */
2625 pGMR->paDesc = (PVMSVGAGMRDESCRIPTOR)RTMemAllocZ(pGMR->cMaxPages * sizeof(VMSVGAGMRDESCRIPTOR));
2626 AssertBreak(pGMR->paDesc);
2627
2628 if (pCmd->flags & SVGA_REMAP_GMR2_VIA_GMR)
2629 {
2630 /** @todo */
2631 AssertFailed();
2632 }
2633 else
2634 {
2635 uint32_t *pPage32 = (uint32_t *)(pCmd + 1);
2636 uint64_t *pPage64 = (uint64_t *)(pCmd + 1);
2637 uint32_t iDescriptor = 0;
2638 RTGCPHYS GCPhys;
2639 PVMSVGAGMRDESCRIPTOR paDescOld = NULL;
2640 bool fGCPhys64 = !!(pCmd->flags & SVGA_REMAP_GMR2_PPN64);
2641
2642 if (paNewPage64)
2643 {
2644 /* Overwrite the old page array with the new page values. */
2645 for (uint32_t i = pCmd->offsetPages; i < pCmd->offsetPages + pCmd->numPages; i++)
2646 {
2647 if (pCmd->flags & SVGA_REMAP_GMR2_PPN64)
2648 paNewPage64[i] = pPage64[i - pCmd->offsetPages];
2649 else
2650 paNewPage64[i] = pPage32[i - pCmd->offsetPages];
2651 }
2652 /* Use the updated page array instead of the command data. */
2653 fGCPhys64 = true;
2654 pPage64 = paNewPage64;
2655 pCmd->numPages = pGMR->cbTotal >> PAGE_SHIFT;
2656 }
2657
2658 if (fGCPhys64)
2659 GCPhys = (pPage64[0] << PAGE_SHIFT) & 0x00000FFFFFFFFFFFULL; /* seeing rubbish in the top bits with certain linux guests*/
2660 else
2661 GCPhys = pPage32[0] << PAGE_SHIFT;
2662
2663 pGMR->paDesc[0].GCPhys = GCPhys;
2664 pGMR->paDesc[0].numPages = 1;
2665 pGMR->cbTotal = PAGE_SIZE;
2666
2667 for (uint32_t i = 1; i < pCmd->numPages; i++)
2668 {
2669 if (pCmd->flags & SVGA_REMAP_GMR2_PPN64)
2670 GCPhys = (pPage64[i] << PAGE_SHIFT) & 0x00000FFFFFFFFFFFULL; /* seeing rubbish in the top bits with certain linux guests*/
2671 else
2672 GCPhys = pPage32[i] << PAGE_SHIFT;
2673
2674 /* Continuous physical memory? */
2675 if (GCPhys == pGMR->paDesc[iDescriptor].GCPhys + pGMR->paDesc[iDescriptor].numPages * PAGE_SIZE)
2676 {
2677 Assert(pGMR->paDesc[iDescriptor].numPages);
2678 pGMR->paDesc[iDescriptor].numPages++;
2679 LogFlow(("Page %x GCPhys=%RGp successor\n", i, GCPhys));
2680 }
2681 else
2682 {
2683 iDescriptor++;
2684 pGMR->paDesc[iDescriptor].GCPhys = GCPhys;
2685 pGMR->paDesc[iDescriptor].numPages = 1;
2686 LogFlow(("Page %x GCPhys=%RGp\n", i, pGMR->paDesc[iDescriptor].GCPhys));
2687 }
2688
2689 pGMR->cbTotal += PAGE_SIZE;
2690 }
2691 LogFlow(("Nr of descriptors %x\n", iDescriptor + 1));
2692 pGMR->numDescriptors = iDescriptor + 1;
2693 }
2694
2695 if (paNewPage64)
2696 RTMemFree(paNewPage64);
2697
2698# ifdef DEBUG_GMR_ACCESS
2699 VMR3ReqCallWait(PDMDevHlpGetVM(pThis->pDevInsR3), VMCPUID_ANY, (PFNRT)vmsvgaRegisterGMR, 2, pThis->pDevInsR3, pCmd->gmrId);
2700# endif
2701 break;
2702 }
2703# endif // VBOX_WITH_VMSVGA3D
2704 case SVGA_CMD_DEFINE_SCREEN:
2705 {
2706 /* Note! The size of this command is specified by the guest and depends on capabilities. */
2707 Assert(!(pThis->svga.pFIFOR3[SVGA_FIFO_CAPABILITIES] & SVGA_FIFO_CAP_SCREEN_OBJECT));
2708 SVGAFifoCmdDefineScreen *pCmd;
2709 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDefineScreen, sizeof(pCmd->screen.structSize));
2710 RT_BZERO(&pCmd->screen.id, sizeof(*pCmd) - RT_OFFSETOF(SVGAFifoCmdDefineScreen, screen.structSize));
2711 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDefineScreen, RT_MAX(sizeof(pCmd->screen.structSize), pCmd->screen.structSize));
2712
2713 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));
2714 if (pCmd->screen.flags & SVGA_SCREEN_HAS_ROOT)
2715 Log(("vmsvgaFIFOLoop: SVGA_CMD_DEFINE_SCREEN flags SVGA_SCREEN_HAS_ROOT\n"));
2716 if (pCmd->screen.flags & SVGA_SCREEN_IS_PRIMARY)
2717 Log(("vmsvgaFIFOLoop: SVGA_CMD_DEFINE_SCREEN flags SVGA_SCREEN_IS_PRIMARY\n"));
2718 if (pCmd->screen.flags & SVGA_SCREEN_FULLSCREEN_HINT)
2719 Log(("vmsvgaFIFOLoop: SVGA_CMD_DEFINE_SCREEN flags SVGA_SCREEN_FULLSCREEN_HINT\n"));
2720 if (pCmd->screen.flags & SVGA_SCREEN_DEACTIVATE )
2721 Log(("vmsvgaFIFOLoop: SVGA_CMD_DEFINE_SCREEN flags SVGA_SCREEN_DEACTIVATE \n"));
2722 if (pCmd->screen.flags & SVGA_SCREEN_BLANKING)
2723 Log(("vmsvgaFIFOLoop: SVGA_CMD_DEFINE_SCREEN flags SVGA_SCREEN_BLANKING\n"));
2724
2725 /** @todo multi monitor support and screen object capabilities. */
2726 pThis->svga.uWidth = pCmd->screen.size.width;
2727 pThis->svga.uHeight = pCmd->screen.size.height;
2728 vmsvgaChangeMode(pThis);
2729 break;
2730 }
2731
2732 case SVGA_CMD_DESTROY_SCREEN:
2733 {
2734 SVGAFifoCmdDestroyScreen *pCmd;
2735 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDestroyScreen, sizeof(*pCmd));
2736
2737 Log(("vmsvgaFIFOLoop: SVGA_CMD_DESTROY_SCREEN id=%x\n", pCmd->screenId));
2738 break;
2739 }
2740# ifdef VBOX_WITH_VMSVGA3D
2741 case SVGA_CMD_DEFINE_GMRFB:
2742 {
2743 SVGAFifoCmdDefineGMRFB *pCmd;
2744 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdDefineGMRFB, sizeof(*pCmd));
2745
2746 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));
2747 pSVGAState->GMRFB.ptr = pCmd->ptr;
2748 pSVGAState->GMRFB.bytesPerLine = pCmd->bytesPerLine;
2749 pSVGAState->GMRFB.format = pCmd->format;
2750 break;
2751 }
2752
2753 case SVGA_CMD_BLIT_GMRFB_TO_SCREEN:
2754 {
2755 uint32_t width, height;
2756 SVGAFifoCmdBlitGMRFBToScreen *pCmd;
2757 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdBlitGMRFBToScreen, sizeof(*pCmd));
2758
2759 Log(("vmsvgaFIFOLoop: SVGA_CMD_BLIT_GMRFB_TO_SCREEN src=(%d,%d) dest id=%d (%d,%d)(%d,%d)\n", pCmd->srcOrigin.x, pCmd->srcOrigin.y, pCmd->destScreenId, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right, pCmd->destRect.bottom));
2760
2761 /** @todo Support GMRFB.format.s.bitsPerPixel != pThis->svga.uBpp */
2762 AssertBreak(pSVGAState->GMRFB.format.s.bitsPerPixel == pThis->svga.uBpp);
2763 AssertBreak(pCmd->destScreenId == 0);
2764
2765 if (pCmd->destRect.left < 0)
2766 pCmd->destRect.left = 0;
2767 if (pCmd->destRect.top < 0)
2768 pCmd->destRect.top = 0;
2769 if (pCmd->destRect.right < 0)
2770 pCmd->destRect.right = 0;
2771 if (pCmd->destRect.bottom < 0)
2772 pCmd->destRect.bottom = 0;
2773
2774 width = pCmd->destRect.right - pCmd->destRect.left;
2775 height = pCmd->destRect.bottom - pCmd->destRect.top;
2776
2777 if ( width == 0
2778 || height == 0)
2779 break; /* Nothing to do. */
2780
2781 /* Clip to screen dimensions. */
2782 if (width > pThis->svga.uWidth)
2783 width = pThis->svga.uWidth;
2784 if (height > pThis->svga.uHeight)
2785 height = pThis->svga.uHeight;
2786
2787 unsigned offsetSource = (pCmd->srcOrigin.x * pSVGAState->GMRFB.format.s.bitsPerPixel) / 8 + pSVGAState->GMRFB.bytesPerLine * pCmd->srcOrigin.y;
2788 unsigned offsetDest = (pCmd->destRect.left * RT_ALIGN(pThis->svga.uBpp, 8)) / 8 + pThis->svga.cbScanline * pCmd->destRect.top;
2789 unsigned cbCopyWidth = (width * RT_ALIGN(pThis->svga.uBpp, 8)) / 8;
2790
2791 AssertBreak(offsetDest < pThis->vram_size);
2792
2793 rc = vmsvgaGMRTransfer(pThis, SVGA3D_WRITE_HOST_VRAM, pThis->CTX_SUFF(vram_ptr) + offsetDest, pThis->svga.cbScanline, pSVGAState->GMRFB.ptr, offsetSource, pSVGAState->GMRFB.bytesPerLine, cbCopyWidth, height);
2794 AssertRC(rc);
2795 vgaR3UpdateDisplay(pThis, pCmd->destRect.left, pCmd->destRect.top, pCmd->destRect.right - pCmd->destRect.left, pCmd->destRect.bottom - pCmd->destRect.top);
2796 break;
2797 }
2798
2799 case SVGA_CMD_BLIT_SCREEN_TO_GMRFB:
2800 {
2801 SVGAFifoCmdBlitScreenToGMRFB *pCmd;
2802 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdBlitScreenToGMRFB, sizeof(*pCmd));
2803
2804 /* Note! This can fetch 3d render results as well!! */
2805 Log(("vmsvgaFIFOLoop: SVGA_CMD_BLIT_SCREEN_TO_GMRFB dest=(%d,%d) src id=%d (%d,%d)(%d,%d)\n", pCmd->destOrigin.x, pCmd->destOrigin.y, pCmd->srcScreenId, pCmd->srcRect.left, pCmd->srcRect.top, pCmd->srcRect.right, pCmd->srcRect.bottom));
2806 AssertFailed();
2807 break;
2808 }
2809# endif // VBOX_WITH_VMSVGA3D
2810 case SVGA_CMD_ANNOTATION_FILL:
2811 {
2812 SVGAFifoCmdAnnotationFill *pCmd;
2813 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdAnnotationFill, sizeof(*pCmd));
2814
2815 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));
2816 pSVGAState->colorAnnotation = pCmd->color;
2817 break;
2818 }
2819
2820 case SVGA_CMD_ANNOTATION_COPY:
2821 {
2822 SVGAFifoCmdAnnotationCopy *pCmd;
2823 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pCmd, SVGAFifoCmdAnnotationCopy, sizeof(*pCmd));
2824
2825 Log(("vmsvgaFIFOLoop: SVGA_CMD_ANNOTATION_COPY\n"));
2826 AssertFailed();
2827 break;
2828 }
2829
2830 /** @todo SVGA_CMD_RECT_COPY - see with ubuntu */
2831
2832 default:
2833# ifdef VBOX_WITH_VMSVGA3D
2834 if ( enmCmdId >= SVGA_3D_CMD_BASE
2835 && enmCmdId < SVGA_3D_CMD_MAX)
2836 {
2837 /* All 3d commands start with a common header, which defines the size of the command. */
2838 SVGA3dCmdHeader *pHdr;
2839 VMSVGAFIFO_GET_CMD_BUFFER_BREAK(pHdr, SVGA3dCmdHeader, sizeof(*pHdr));
2840 AssertBreak(pHdr->size < VMSVGA_FIFO_SIZE);
2841 uint32_t cbCmd = sizeof(SVGA3dCmdHeader) + pHdr->size;
2842 VMSVGAFIFO_GET_MORE_CMD_BUFFER_BREAK(pHdr, SVGA3dCmdHeader, cbCmd);
2843
2844/**
2845 * Check that the 3D command has at least a_cbMin of payload bytes after the
2846 * header. Will break out of the switch if it doesn't.
2847 */
2848# define VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(a_cbMin) \
2849 AssertMsgBreak((a_cbMin) <= pHdr->size, ("size=%#x a_cbMin=%#zx\n", pHdr->size, (size_t)(a_cbMin)))
2850 switch ((int)enmCmdId)
2851 {
2852 case SVGA_3D_CMD_SURFACE_DEFINE:
2853 {
2854 uint32_t cMipLevels;
2855 SVGA3dCmdDefineSurface *pCmd = (SVGA3dCmdDefineSurface *)(pHdr + 1);
2856 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2857
2858 cMipLevels = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dSize);
2859 rc = vmsvga3dSurfaceDefine(pThis, pCmd->sid, (uint32_t)pCmd->surfaceFlags, pCmd->format, pCmd->face, 0, SVGA3D_TEX_FILTER_NONE, cMipLevels, (SVGA3dSize *)(pCmd + 1));
2860# ifdef DEBUG_GMR_ACCESS
2861 VMR3ReqCallWait(PDMDevHlpGetVM(pThis->pDevInsR3), VMCPUID_ANY, (PFNRT)vmsvgaResetGMRHandlers, 1, pThis);
2862# endif
2863 break;
2864 }
2865
2866 case SVGA_3D_CMD_SURFACE_DEFINE_V2:
2867 {
2868 uint32_t cMipLevels;
2869 SVGA3dCmdDefineSurface_v2 *pCmd = (SVGA3dCmdDefineSurface_v2 *)(pHdr + 1);
2870 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2871
2872 cMipLevels = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dSize);
2873 rc = vmsvga3dSurfaceDefine(pThis, pCmd->sid, pCmd->surfaceFlags, pCmd->format, pCmd->face, pCmd->multisampleCount, pCmd->autogenFilter, cMipLevels, (SVGA3dSize *)(pCmd + 1));
2874 break;
2875 }
2876
2877 case SVGA_3D_CMD_SURFACE_DESTROY:
2878 {
2879 SVGA3dCmdDestroySurface *pCmd = (SVGA3dCmdDestroySurface *)(pHdr + 1);
2880 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2881 rc = vmsvga3dSurfaceDestroy(pThis, pCmd->sid);
2882 break;
2883 }
2884
2885 case SVGA_3D_CMD_SURFACE_COPY:
2886 {
2887 uint32_t cCopyBoxes;
2888 SVGA3dCmdSurfaceCopy *pCmd = (SVGA3dCmdSurfaceCopy *)(pHdr + 1);
2889 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2890
2891 cCopyBoxes = (pHdr->size - sizeof(pCmd)) / sizeof(SVGA3dCopyBox);
2892 rc = vmsvga3dSurfaceCopy(pThis, pCmd->dest, pCmd->src, cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
2893 break;
2894 }
2895
2896 case SVGA_3D_CMD_SURFACE_STRETCHBLT:
2897 {
2898 SVGA3dCmdSurfaceStretchBlt *pCmd = (SVGA3dCmdSurfaceStretchBlt *)(pHdr + 1);
2899 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2900
2901 rc = vmsvga3dSurfaceStretchBlt(pThis, pCmd->dest, pCmd->boxDest, pCmd->src, pCmd->boxSrc, pCmd->mode);
2902 break;
2903 }
2904
2905 case SVGA_3D_CMD_SURFACE_DMA:
2906 {
2907 uint32_t cCopyBoxes;
2908 SVGA3dCmdSurfaceDMA *pCmd = (SVGA3dCmdSurfaceDMA *)(pHdr + 1);
2909 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2910
2911 cCopyBoxes = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dCopyBox);
2912 STAM_PROFILE_START(&pSVGAState->StatR3CmdSurfaceDMA, a);
2913 rc = vmsvga3dSurfaceDMA(pThis, pCmd->guest, pCmd->host, pCmd->transfer, cCopyBoxes, (SVGA3dCopyBox *)(pCmd + 1));
2914 STAM_PROFILE_STOP(&pSVGAState->StatR3CmdSurfaceDMA, a);
2915 break;
2916 }
2917
2918 case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN:
2919 {
2920 uint32_t cRects;
2921 SVGA3dCmdBlitSurfaceToScreen *pCmd = (SVGA3dCmdBlitSurfaceToScreen *)(pHdr + 1);
2922 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2923
2924 cRects = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGASignedRect);
2925 rc = vmsvga3dSurfaceBlitToScreen(pThis, pCmd->destScreenId, pCmd->destRect, pCmd->srcImage, pCmd->srcRect, cRects, (SVGASignedRect *)(pCmd + 1));
2926 break;
2927 }
2928
2929 case SVGA_3D_CMD_CONTEXT_DEFINE:
2930 {
2931 SVGA3dCmdDefineContext *pCmd = (SVGA3dCmdDefineContext *)(pHdr + 1);
2932 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2933
2934 rc = vmsvga3dContextDefine(pThis, pCmd->cid, false /*fOtherProfile*/);
2935 break;
2936 }
2937
2938 case SVGA_3D_CMD_CONTEXT_DESTROY:
2939 {
2940 SVGA3dCmdDestroyContext *pCmd = (SVGA3dCmdDestroyContext *)(pHdr + 1);
2941 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2942
2943 rc = vmsvga3dContextDestroy(pThis, pCmd->cid);
2944 break;
2945 }
2946
2947 case SVGA_3D_CMD_SETTRANSFORM:
2948 {
2949 SVGA3dCmdSetTransform *pCmd = (SVGA3dCmdSetTransform *)(pHdr + 1);
2950 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2951
2952 rc = vmsvga3dSetTransform(pThis, pCmd->cid, pCmd->type, pCmd->matrix);
2953 break;
2954 }
2955
2956 case SVGA_3D_CMD_SETZRANGE:
2957 {
2958 SVGA3dCmdSetZRange *pCmd = (SVGA3dCmdSetZRange *)(pHdr + 1);
2959 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2960
2961 rc = vmsvga3dSetZRange(pThis, pCmd->cid, pCmd->zRange);
2962 break;
2963 }
2964
2965 case SVGA_3D_CMD_SETRENDERSTATE:
2966 {
2967 uint32_t cRenderStates;
2968 SVGA3dCmdSetRenderState *pCmd = (SVGA3dCmdSetRenderState *)(pHdr + 1);
2969 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2970
2971 cRenderStates = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dRenderState);
2972 rc = vmsvga3dSetRenderState(pThis, pCmd->cid, cRenderStates, (SVGA3dRenderState *)(pCmd + 1));
2973 break;
2974 }
2975
2976 case SVGA_3D_CMD_SETRENDERTARGET:
2977 {
2978 SVGA3dCmdSetRenderTarget *pCmd = (SVGA3dCmdSetRenderTarget *)(pHdr + 1);
2979 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2980
2981 rc = vmsvga3dSetRenderTarget(pThis, pCmd->cid, pCmd->type, pCmd->target);
2982 break;
2983 }
2984
2985 case SVGA_3D_CMD_SETTEXTURESTATE:
2986 {
2987 uint32_t cTextureStates;
2988 SVGA3dCmdSetTextureState *pCmd = (SVGA3dCmdSetTextureState *)(pHdr + 1);
2989 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
2990
2991 cTextureStates = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dTextureState);
2992 rc = vmsvga3dSetTextureState(pThis, pCmd->cid, cTextureStates, (SVGA3dTextureState *)(pCmd + 1));
2993 break;
2994 }
2995
2996 case SVGA_3D_CMD_SETMATERIAL:
2997 {
2998 SVGA3dCmdSetMaterial *pCmd = (SVGA3dCmdSetMaterial *)(pHdr + 1);
2999 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3000
3001 rc = vmsvga3dSetMaterial(pThis, pCmd->cid, pCmd->face, &pCmd->material);
3002 break;
3003 }
3004
3005 case SVGA_3D_CMD_SETLIGHTDATA:
3006 {
3007 SVGA3dCmdSetLightData *pCmd = (SVGA3dCmdSetLightData *)(pHdr + 1);
3008 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3009
3010 rc = vmsvga3dSetLightData(pThis, pCmd->cid, pCmd->index, &pCmd->data);
3011 break;
3012 }
3013
3014 case SVGA_3D_CMD_SETLIGHTENABLED:
3015 {
3016 SVGA3dCmdSetLightEnabled *pCmd = (SVGA3dCmdSetLightEnabled *)(pHdr + 1);
3017 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3018
3019 rc = vmsvga3dSetLightEnabled(pThis, pCmd->cid, pCmd->index, pCmd->enabled);
3020 break;
3021 }
3022
3023 case SVGA_3D_CMD_SETVIEWPORT:
3024 {
3025 SVGA3dCmdSetViewport *pCmd = (SVGA3dCmdSetViewport *)(pHdr + 1);
3026 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3027
3028 rc = vmsvga3dSetViewPort(pThis, pCmd->cid, &pCmd->rect);
3029 break;
3030 }
3031
3032 case SVGA_3D_CMD_SETCLIPPLANE:
3033 {
3034 SVGA3dCmdSetClipPlane *pCmd = (SVGA3dCmdSetClipPlane *)(pHdr + 1);
3035 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3036
3037 rc = vmsvga3dSetClipPlane(pThis, pCmd->cid, pCmd->index, pCmd->plane);
3038 break;
3039 }
3040
3041 case SVGA_3D_CMD_CLEAR:
3042 {
3043 SVGA3dCmdClear *pCmd = (SVGA3dCmdClear *)(pHdr + 1);
3044 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3045 uint32_t cRects;
3046
3047 cRects = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dRect);
3048 rc = vmsvga3dCommandClear(pThis, pCmd->cid, pCmd->clearFlag, pCmd->color, pCmd->depth, pCmd->stencil, cRects, (SVGA3dRect *)(pCmd + 1));
3049 break;
3050 }
3051
3052 case SVGA_3D_CMD_PRESENT:
3053 {
3054 SVGA3dCmdPresent *pCmd = (SVGA3dCmdPresent *)(pHdr + 1);
3055 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3056 uint32_t cRects;
3057
3058 cRects = (pHdr->size - sizeof(*pCmd)) / sizeof(SVGA3dCopyRect);
3059
3060 STAM_PROFILE_START(&pSVGAState->StatR3CmdPresent, a);
3061 rc = vmsvga3dCommandPresent(pThis, pCmd->sid, cRects, (SVGA3dCopyRect *)(pCmd + 1));
3062 STAM_PROFILE_STOP(&pSVGAState->StatR3CmdPresent, a);
3063 break;
3064 }
3065
3066 case SVGA_3D_CMD_SHADER_DEFINE:
3067 {
3068 SVGA3dCmdDefineShader *pCmd = (SVGA3dCmdDefineShader *)(pHdr + 1);
3069 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3070 uint32_t cbData;
3071
3072 cbData = (pHdr->size - sizeof(*pCmd));
3073 rc = vmsvga3dShaderDefine(pThis, pCmd->cid, pCmd->shid, pCmd->type, cbData, (uint32_t *)(pCmd + 1));
3074 break;
3075 }
3076
3077 case SVGA_3D_CMD_SHADER_DESTROY:
3078 {
3079 SVGA3dCmdDestroyShader *pCmd = (SVGA3dCmdDestroyShader *)(pHdr + 1);
3080 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3081
3082 rc = vmsvga3dShaderDestroy(pThis, pCmd->cid, pCmd->shid, pCmd->type);
3083 break;
3084 }
3085
3086 case SVGA_3D_CMD_SET_SHADER:
3087 {
3088 SVGA3dCmdSetShader *pCmd = (SVGA3dCmdSetShader *)(pHdr + 1);
3089 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3090
3091 rc = vmsvga3dShaderSet(pThis, pCmd->cid, pCmd->type, pCmd->shid);
3092 break;
3093 }
3094
3095 case SVGA_3D_CMD_SET_SHADER_CONST:
3096 {
3097 SVGA3dCmdSetShaderConst *pCmd = (SVGA3dCmdSetShaderConst *)(pHdr + 1);
3098 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3099
3100 uint32_t cRegisters = (pHdr->size - sizeof(*pCmd)) / sizeof(pCmd->values) + 1;
3101 rc = vmsvga3dShaderSetConst(pThis, pCmd->cid, pCmd->reg, pCmd->type, pCmd->ctype, cRegisters, pCmd->values);
3102 break;
3103 }
3104
3105 case SVGA_3D_CMD_DRAW_PRIMITIVES:
3106 {
3107 SVGA3dCmdDrawPrimitives *pCmd = (SVGA3dCmdDrawPrimitives *)(pHdr + 1);
3108 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3109 uint32_t cVertexDivisor;
3110
3111 cVertexDivisor = (pHdr->size - sizeof(*pCmd) - sizeof(SVGA3dVertexDecl) * pCmd->numVertexDecls - sizeof(SVGA3dPrimitiveRange) * pCmd->numRanges);
3112 Assert(pCmd->numRanges <= SVGA3D_MAX_DRAW_PRIMITIVE_RANGES);
3113 Assert(pCmd->numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS);
3114 Assert(!cVertexDivisor || cVertexDivisor == pCmd->numVertexDecls);
3115
3116 SVGA3dVertexDecl *pVertexDecl = (SVGA3dVertexDecl *)(pCmd + 1);
3117 SVGA3dPrimitiveRange *pNumRange = (SVGA3dPrimitiveRange *) (&pVertexDecl[pCmd->numVertexDecls]);
3118 SVGA3dVertexDivisor *pVertexDivisor = (cVertexDivisor) ? (SVGA3dVertexDivisor *)(&pNumRange[pCmd->numRanges]) : NULL;
3119
3120 STAM_PROFILE_START(&pSVGAState->StatR3CmdDrawPrimitive, a);
3121 rc = vmsvga3dDrawPrimitives(pThis, pCmd->cid, pCmd->numVertexDecls, pVertexDecl, pCmd->numRanges, pNumRange, cVertexDivisor, pVertexDivisor);
3122 STAM_PROFILE_STOP(&pSVGAState->StatR3CmdDrawPrimitive, a);
3123 break;
3124 }
3125
3126 case SVGA_3D_CMD_SETSCISSORRECT:
3127 {
3128 SVGA3dCmdSetScissorRect *pCmd = (SVGA3dCmdSetScissorRect *)(pHdr + 1);
3129 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3130
3131 rc = vmsvga3dSetScissorRect(pThis, pCmd->cid, &pCmd->rect);
3132 break;
3133 }
3134
3135 case SVGA_3D_CMD_BEGIN_QUERY:
3136 {
3137 SVGA3dCmdBeginQuery *pCmd = (SVGA3dCmdBeginQuery *)(pHdr + 1);
3138 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3139
3140 rc = vmsvga3dQueryBegin(pThis, pCmd->cid, pCmd->type);
3141 break;
3142 }
3143
3144 case SVGA_3D_CMD_END_QUERY:
3145 {
3146 SVGA3dCmdEndQuery *pCmd = (SVGA3dCmdEndQuery *)(pHdr + 1);
3147 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3148
3149 rc = vmsvga3dQueryEnd(pThis, pCmd->cid, pCmd->type, pCmd->guestResult);
3150 break;
3151 }
3152
3153 case SVGA_3D_CMD_WAIT_FOR_QUERY:
3154 {
3155 SVGA3dCmdWaitForQuery *pCmd = (SVGA3dCmdWaitForQuery *)(pHdr + 1);
3156 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3157
3158 rc = vmsvga3dQueryWait(pThis, pCmd->cid, pCmd->type, pCmd->guestResult);
3159 break;
3160 }
3161
3162 case SVGA_3D_CMD_GENERATE_MIPMAPS:
3163 {
3164 SVGA3dCmdGenerateMipmaps *pCmd = (SVGA3dCmdGenerateMipmaps *)(pHdr + 1);
3165 VMSVGAFIFO_CHECK_3D_CMD_MIN_SIZE_BREAK(sizeof(*pCmd));
3166
3167 rc = vmsvga3dGenerateMipmaps(pThis, pCmd->sid, pCmd->filter);
3168 break;
3169 }
3170
3171 case SVGA_3D_CMD_ACTIVATE_SURFACE:
3172 case SVGA_3D_CMD_DEACTIVATE_SURFACE:
3173 /* context id + surface id? */
3174 break;
3175
3176 default:
3177 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoUnkCmds);
3178 AssertFailed();
3179 break;
3180 }
3181 }
3182 else
3183# endif // VBOX_WITH_VMSVGA3D
3184 {
3185 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoUnkCmds);
3186 AssertFailed();
3187 }
3188 }
3189
3190 /* Go to the next slot */
3191 Assert(cbPayload + sizeof(uint32_t) <= offFifoMax - offFifoMin);
3192 offCurrentCmd += RT_ALIGN_32(cbPayload + sizeof(uint32_t), sizeof(uint32_t));
3193 if (offCurrentCmd >= offFifoMax)
3194 {
3195 offCurrentCmd -= offFifoMax - offFifoMin;
3196 Assert(offCurrentCmd >= offFifoMin);
3197 Assert(offCurrentCmd < offFifoMax);
3198 }
3199 ASMAtomicWriteU32(&pFIFO[SVGA_FIFO_STOP], offCurrentCmd);
3200 STAM_REL_COUNTER_INC(&pSVGAState->StatFifoCommands);
3201
3202 /* FIFO progress might trigger an interrupt. */
3203 if (pThis->svga.u32IrqMask & SVGA_IRQFLAG_FIFO_PROGRESS)
3204 {
3205 Log(("vmsvgaFIFOLoop: fifo progress irq\n"));
3206 u32IrqStatus |= SVGA_IRQFLAG_FIFO_PROGRESS;
3207 }
3208
3209 /* Irq pending? */
3210 if (pThis->svga.u32IrqMask & u32IrqStatus)
3211 {
3212 Log(("vmsvgaFIFOLoop: Trigger interrupt with status %x\n", u32IrqStatus));
3213 ASMAtomicOrU32(&pThis->svga.u32IrqStatus, u32IrqStatus);
3214 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 1);
3215 }
3216 }
3217
3218 /* If really done, clear the busy flag. */
3219 if (fDone)
3220 {
3221 Log(("vmsvgaFIFOLoop: emptied the FIFO next=%x stop=%x\n", pFIFO[SVGA_FIFO_NEXT_CMD], offCurrentCmd));
3222 vmsvgaFifoSetNotBusy(pThis, pSVGAState, offFifoMin);
3223 }
3224 }
3225
3226 /*
3227 * Free the bounce buffer. (There are no returns above!)
3228 */
3229 RTMemFree(pbBounceBuf);
3230
3231 return VINF_SUCCESS;
3232}
3233
3234/**
3235 * Free the specified GMR
3236 *
3237 * @param pThis VGA device instance data.
3238 * @param idGMR GMR id
3239 */
3240void vmsvgaGMRFree(PVGASTATE pThis, uint32_t idGMR)
3241{
3242 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
3243
3244 /* Free the old descriptor if present. */
3245 if (pSVGAState->aGMR[idGMR].numDescriptors)
3246 {
3247 PGMR pGMR = &pSVGAState->aGMR[idGMR];
3248# ifdef DEBUG_GMR_ACCESS
3249 VMR3ReqCallWait(PDMDevHlpGetVM(pThis->pDevInsR3), VMCPUID_ANY, (PFNRT)vmsvgaUnregisterGMR, 2, pThis->pDevInsR3, idGMR);
3250# endif
3251
3252 Assert(pGMR->paDesc);
3253 RTMemFree(pGMR->paDesc);
3254 pGMR->paDesc = NULL;
3255 pGMR->numDescriptors = 0;
3256 pGMR->cbTotal = 0;
3257 pGMR->cMaxPages = 0;
3258 }
3259 Assert(!pSVGAState->aGMR[idGMR].cbTotal);
3260}
3261
3262/**
3263 * Copy from a GMR to host memory or vice versa
3264 *
3265 * @returns VBox status code.
3266 * @param pThis VGA device instance data.
3267 * @param enmTransferType Transfer type (read/write)
3268 * @param pbDst Host destination pointer
3269 * @param cbDestPitch Destination buffer pitch
3270 * @param src GMR description
3271 * @param offSrc Source buffer offset
3272 * @param cbSrcPitch Source buffer pitch
3273 * @param cbWidth Source width in bytes
3274 * @param cHeight Source height
3275 */
3276int vmsvgaGMRTransfer(PVGASTATE pThis, const SVGA3dTransferType enmTransferType, uint8_t *pbDst, int32_t cbDestPitch,
3277 SVGAGuestPtr src, uint32_t offSrc, int32_t cbSrcPitch, uint32_t cbWidth, uint32_t cHeight)
3278{
3279 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
3280 PGMR pGMR;
3281 int rc;
3282 PVMSVGAGMRDESCRIPTOR pDesc;
3283 unsigned offDesc = 0;
3284
3285 Log(("vmsvgaGMRTransfer: gmr=%x offset=%x pitch=%d cbWidth=%d cHeight=%d; src offset=%d src pitch=%d\n",
3286 src.gmrId, src.offset, cbDestPitch, cbWidth, cHeight, offSrc, cbSrcPitch));
3287 Assert(cbWidth && cHeight);
3288
3289 /* Shortcut for the framebuffer. */
3290 if (src.gmrId == SVGA_GMR_FRAMEBUFFER)
3291 {
3292 offSrc += src.offset;
3293 AssertMsgReturn(src.offset < pThis->vram_size,
3294 ("src.offset=%#x offSrc=%#x cbSrcPitch=%#x cHeight=%#x cbWidth=%#x cbTotal=%#x vram_size=%#x\n",
3295 src.offset, offSrc, cbSrcPitch, cHeight, cbWidth, pThis->vram_size),
3296 VERR_INVALID_PARAMETER);
3297 AssertMsgReturn(offSrc + cbSrcPitch * (cHeight - 1) + cbWidth <= pThis->vram_size,
3298 ("src.offset=%#x offSrc=%#x cbSrcPitch=%#x cHeight=%#x cbWidth=%#x cbTotal=%#x vram_size=%#x\n",
3299 src.offset, offSrc, cbSrcPitch, cHeight, cbWidth, pThis->vram_size),
3300 VERR_INVALID_PARAMETER);
3301
3302 uint8_t *pSrc = pThis->CTX_SUFF(vram_ptr) + offSrc;
3303
3304 if (enmTransferType == SVGA3D_READ_HOST_VRAM)
3305 {
3306 /* switch src & dest */
3307 uint8_t *pTemp = pbDst;
3308 int32_t cbTempPitch = cbDestPitch;
3309
3310 pbDst = pSrc;
3311 pSrc = pTemp;
3312
3313 cbDestPitch = cbSrcPitch;
3314 cbSrcPitch = cbTempPitch;
3315 }
3316
3317 if ( pThis->svga.cbScanline == (uint32_t)cbDestPitch
3318 && cbWidth == (uint32_t)cbDestPitch
3319 && cbSrcPitch == cbDestPitch)
3320 {
3321 memcpy(pbDst, pSrc, cbWidth * cHeight);
3322 }
3323 else
3324 {
3325 for(uint32_t i = 0; i < cHeight; i++)
3326 {
3327 memcpy(pbDst, pSrc, cbWidth);
3328
3329 pbDst += cbDestPitch;
3330 pSrc += cbSrcPitch;
3331 }
3332 }
3333 return VINF_SUCCESS;
3334 }
3335
3336 AssertReturn(src.gmrId < VMSVGA_MAX_GMR_IDS, VERR_INVALID_PARAMETER);
3337 pGMR = &pSVGAState->aGMR[src.gmrId];
3338 pDesc = pGMR->paDesc;
3339
3340 offSrc += src.offset;
3341 AssertMsgReturn(src.offset < pGMR->cbTotal,
3342 ("src.gmrId=%#x src.offset=%#x offSrc=%#x cbSrcPitch=%#x cHeight=%#x cbWidth=%#x cbTotal=%#x\n",
3343 src.gmrId, src.offset, offSrc, cbSrcPitch, cHeight, cbWidth, pGMR->cbTotal),
3344 VERR_INVALID_PARAMETER);
3345 AssertMsgReturn(offSrc + cbSrcPitch * (cHeight - 1) + cbWidth <= pGMR->cbTotal,
3346 ("src.gmrId=%#x src.offset=%#x offSrc=%#x cbSrcPitch=%#x cHeight=%#x cbWidth=%#x cbTotal=%#x\n",
3347 src.gmrId, src.offset, offSrc, cbSrcPitch, cHeight, cbWidth, pGMR->cbTotal),
3348 VERR_INVALID_PARAMETER);
3349
3350 for (uint32_t i = 0; i < cHeight; i++)
3351 {
3352 uint32_t cbCurrentWidth = cbWidth;
3353 uint32_t offCurrent = offSrc;
3354 uint8_t *pCurrentDest = pbDst;
3355
3356 /* Find the right descriptor */
3357 while (offDesc + pDesc->numPages * PAGE_SIZE <= offCurrent)
3358 {
3359 offDesc += pDesc->numPages * PAGE_SIZE;
3360 AssertReturn(offDesc < pGMR->cbTotal, VERR_INTERNAL_ERROR); /* overflow protection */
3361 pDesc++;
3362 }
3363
3364 while (cbCurrentWidth)
3365 {
3366 uint32_t cbToCopy;
3367
3368 if (offCurrent + cbCurrentWidth <= offDesc + pDesc->numPages * PAGE_SIZE)
3369 {
3370 cbToCopy = cbCurrentWidth;
3371 }
3372 else
3373 {
3374 cbToCopy = (offDesc + pDesc->numPages * PAGE_SIZE - offCurrent);
3375 AssertReturn(cbToCopy <= cbCurrentWidth, VERR_INVALID_PARAMETER);
3376 }
3377
3378 LogFlow(("vmsvgaGMRTransfer: %s phys=%RGp\n", (enmTransferType == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", pDesc->GCPhys + offCurrent - offDesc));
3379
3380 if (enmTransferType == SVGA3D_WRITE_HOST_VRAM)
3381 rc = PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), pDesc->GCPhys + offCurrent - offDesc, pCurrentDest, cbToCopy);
3382 else
3383 rc = PDMDevHlpPhysWrite(pThis->CTX_SUFF(pDevIns), pDesc->GCPhys + offCurrent - offDesc, pCurrentDest, cbToCopy);
3384 AssertRCBreak(rc);
3385
3386 cbCurrentWidth -= cbToCopy;
3387 offCurrent += cbToCopy;
3388 pCurrentDest += cbToCopy;
3389
3390 /* Go to the next descriptor if there's anything left. */
3391 if (cbCurrentWidth)
3392 {
3393 offDesc += pDesc->numPages * PAGE_SIZE;
3394 pDesc++;
3395 }
3396 }
3397
3398 offSrc += cbSrcPitch;
3399 pbDst += cbDestPitch;
3400 }
3401
3402 return VINF_SUCCESS;
3403}
3404
3405/**
3406 * Unblock the FIFO I/O thread so it can respond to a state change.
3407 *
3408 * @returns VBox status code.
3409 * @param pDevIns The VGA device instance.
3410 * @param pThread The send thread.
3411 */
3412static DECLCALLBACK(int) vmsvgaFIFOLoopWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
3413{
3414 PVGASTATE pThis = (PVGASTATE)pThread->pvUser;
3415 Log(("vmsvgaFIFOLoopWakeUp\n"));
3416 return SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3417}
3418
3419/**
3420 * Enables or disables dirty page tracking for the framebuffer
3421 *
3422 * @param pThis VGA device instance data.
3423 * @param fTraces Enable/disable traces
3424 */
3425static void vmsvgaSetTraces(PVGASTATE pThis, bool fTraces)
3426{
3427 if ( (!pThis->svga.fConfigured || !pThis->svga.fEnabled)
3428 && !fTraces)
3429 {
3430 //Assert(pThis->svga.fTraces);
3431 Log(("vmsvgaSetTraces: *not* allowed to disable dirty page tracking when the device is in legacy mode.\n"));
3432 return;
3433 }
3434
3435 pThis->svga.fTraces = fTraces;
3436 if (pThis->svga.fTraces)
3437 {
3438 unsigned cbFrameBuffer = pThis->vram_size;
3439
3440 Log(("vmsvgaSetTraces: enable dirty page handling for the frame buffer only (%x bytes)\n", 0));
3441 if (pThis->svga.uHeight != VMSVGA_VAL_UNINITIALIZED)
3442 {
3443 Assert(pThis->svga.cbScanline);
3444 /* Hardware enabled; return real framebuffer size .*/
3445 cbFrameBuffer = (uint32_t)pThis->svga.uHeight * pThis->svga.cbScanline;
3446 cbFrameBuffer = RT_ALIGN(cbFrameBuffer, PAGE_SIZE);
3447 }
3448
3449 if (!pThis->svga.fVRAMTracking)
3450 {
3451 Log(("vmsvgaSetTraces: enable frame buffer dirty page tracking. (%x bytes; vram %x)\n", cbFrameBuffer, pThis->vram_size));
3452 vgaR3RegisterVRAMHandler(pThis, cbFrameBuffer);
3453 pThis->svga.fVRAMTracking = true;
3454 }
3455 }
3456 else
3457 {
3458 if (pThis->svga.fVRAMTracking)
3459 {
3460 Log(("vmsvgaSetTraces: disable frame buffer dirty page tracking\n"));
3461 vgaR3UnregisterVRAMHandler(pThis);
3462 pThis->svga.fVRAMTracking = false;
3463 }
3464 }
3465}
3466
3467/**
3468 * Callback function for mapping a PCI I/O region.
3469 *
3470 * @return VBox status code.
3471 * @param pPciDev Pointer to PCI device.
3472 * Use pPciDev->pDevIns to get the device instance.
3473 * @param iRegion The region number.
3474 * @param GCPhysAddress Physical address of the region.
3475 * If iType is PCI_ADDRESS_SPACE_IO, this is an
3476 * I/O port, else it's a physical address.
3477 * This address is *NOT* relative
3478 * to pci_mem_base like earlier!
3479 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
3480 */
3481DECLCALLBACK(int) vmsvgaR3IORegionMap(PPCIDEVICE pPciDev, int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
3482{
3483 int rc;
3484 PPDMDEVINS pDevIns = pPciDev->pDevIns;
3485 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
3486
3487 Log(("vgasvgaR3IORegionMap: iRegion=%d GCPhysAddress=%RGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
3488 if (enmType == PCI_ADDRESS_SPACE_IO)
3489 {
3490 AssertReturn(iRegion == 0, VERR_INTERNAL_ERROR);
3491 rc = PDMDevHlpIOPortRegister(pDevIns, (RTIOPORT)GCPhysAddress, cb, 0,
3492 vmsvgaIOWrite, vmsvgaIORead, NULL /* OutStr */, NULL /* InStr */, "VMSVGA");
3493 if (RT_FAILURE(rc))
3494 return rc;
3495 if (pThis->fR0Enabled)
3496 {
3497 rc = PDMDevHlpIOPortRegisterR0(pDevIns, (RTIOPORT)GCPhysAddress, cb, 0,
3498 "vmsvgaIOWrite", "vmsvgaIORead", NULL, NULL, "VMSVGA");
3499 if (RT_FAILURE(rc))
3500 return rc;
3501 }
3502 if (pThis->fGCEnabled)
3503 {
3504 rc = PDMDevHlpIOPortRegisterRC(pDevIns, (RTIOPORT)GCPhysAddress, cb, 0,
3505 "vmsvgaIOWrite", "vmsvgaIORead", NULL, NULL, "VMSVGA");
3506 if (RT_FAILURE(rc))
3507 return rc;
3508 }
3509
3510 pThis->svga.BasePort = GCPhysAddress;
3511 Log(("vmsvgaR3IORegionMap: base port = %x\n", pThis->svga.BasePort));
3512 }
3513 else
3514 {
3515 AssertReturn(iRegion == 2 && enmType == PCI_ADDRESS_SPACE_MEM, VERR_INTERNAL_ERROR);
3516 if (GCPhysAddress != NIL_RTGCPHYS)
3517 {
3518 /*
3519 * Mapping the FIFO RAM.
3520 */
3521 rc = PDMDevHlpMMIO2Map(pDevIns, iRegion, GCPhysAddress);
3522 AssertRC(rc);
3523
3524# ifdef DEBUG_FIFO_ACCESS
3525 if (RT_SUCCESS(rc))
3526 {
3527 rc = PGMR3HandlerPhysicalRegister(PDMDevHlpGetVM(pDevIns),
3528 PGMPHYSHANDLERTYPE_PHYSICAL_ALL,
3529 GCPhysAddress, GCPhysAddress + (VMSVGA_FIFO_SIZE - 1),
3530 vmsvgaR3FIFOAccessHandler, pThis,
3531 NULL, NULL, NULL,
3532 NULL, NULL, NULL,
3533 "VMSVGA FIFO");
3534 AssertRC(rc);
3535 }
3536# endif
3537 if (RT_SUCCESS(rc))
3538 {
3539 pThis->svga.GCPhysFIFO = GCPhysAddress;
3540 Log(("vmsvgaR3IORegionMap: FIFO address = %RGp\n", GCPhysAddress));
3541 }
3542 }
3543 else
3544 {
3545 Assert(pThis->svga.GCPhysFIFO);
3546# ifdef DEBUG_FIFO_ACCESS
3547 rc = PGMHandlerPhysicalDeregister(PDMDevHlpGetVM(pDevIns), pThis->svga.GCPhysFIFO);
3548 AssertRC(rc);
3549# endif
3550 pThis->svga.GCPhysFIFO = 0;
3551 }
3552
3553 }
3554 return VINF_SUCCESS;
3555}
3556
3557
3558/**
3559 * @copydoc FNSSMDEVLOADEXEC
3560 */
3561int vmsvgaLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
3562{
3563 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
3564 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
3565 int rc;
3566
3567 /* Load our part of the VGAState */
3568 rc = SSMR3GetStructEx(pSSM, &pThis->svga, sizeof(pThis->svga), 0, g_aVGAStateSVGAFields, NULL);
3569 AssertRCReturn(rc, rc);
3570
3571 /* Load the framebuffer backup. */
3572 rc = SSMR3GetMem(pSSM, pThis->svga.pFrameBufferBackup, VMSVGA_FRAMEBUFFER_BACKUP_SIZE);
3573 AssertRCReturn(rc, rc);
3574
3575 /* Load the VMSVGA state. */
3576 rc = SSMR3GetStructEx(pSSM, pSVGAState, sizeof(*pSVGAState), 0, g_aVMSVGASTATEFields, NULL);
3577 AssertRCReturn(rc, rc);
3578
3579 /* Load the active cursor bitmaps. */
3580 if (pSVGAState->Cursor.fActive)
3581 {
3582 pSVGAState->Cursor.pData = RTMemAlloc(pSVGAState->Cursor.cbData);
3583 AssertReturn(pSVGAState->Cursor.pData, VERR_NO_MEMORY);
3584
3585 rc = SSMR3GetMem(pSSM, pSVGAState->Cursor.pData, pSVGAState->Cursor.cbData);
3586 AssertRCReturn(rc, rc);
3587 }
3588
3589 /* Load the GMR state */
3590 for (uint32_t i = 0; i < RT_ELEMENTS(pSVGAState->aGMR); i++)
3591 {
3592 PGMR pGMR = &pSVGAState->aGMR[i];
3593
3594 rc = SSMR3GetStructEx(pSSM, pGMR, sizeof(*pGMR), 0, g_aGMRFields, NULL);
3595 AssertRCReturn(rc, rc);
3596
3597 if (pGMR->numDescriptors)
3598 {
3599 /* Allocate the maximum amount possible (everything non-continuous) */
3600 Assert(pGMR->cMaxPages || pGMR->cbTotal);
3601 pGMR->paDesc = (PVMSVGAGMRDESCRIPTOR)RTMemAllocZ((pGMR->cMaxPages) ? pGMR->cMaxPages : (pGMR->cbTotal >> PAGE_SHIFT) * sizeof(VMSVGAGMRDESCRIPTOR));
3602 AssertReturn(pGMR->paDesc, VERR_NO_MEMORY);
3603
3604 for (uint32_t j = 0; j < pGMR->numDescriptors; j++)
3605 {
3606 rc = SSMR3GetStructEx(pSSM, &pGMR->paDesc[j], sizeof(pGMR->paDesc[j]), 0, g_aVMSVGAGMRDESCRIPTORFields, NULL);
3607 AssertRCReturn(rc, rc);
3608 }
3609 }
3610 }
3611
3612# ifdef VBOX_WITH_VMSVGA3D
3613 if (pThis->svga.f3DEnabled)
3614 {
3615 VMSVGA_STATE_LOAD loadstate;
3616
3617 loadstate.pSSM = pSSM;
3618 loadstate.uVersion = uVersion;
3619 loadstate.uPass = uPass;
3620
3621 /* Save the 3d state in the FIFO thread. */
3622 pThis->svga.u8FIFOExtCommand = VMSVGA_FIFO_EXTCMD_LOADSTATE;
3623 pThis->svga.pFIFOExtCmdParam = (void *)&loadstate;
3624 /* Hack alert: resume the IO thread as it has been suspended before the destruct callback.
3625 * The PowerOff notification isn't working, so not an option in this case.
3626 */
3627 PDMR3ThreadResume(pThis->svga.pFIFOIOThread);
3628 SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3629 /* Wait for the end of the command. */
3630 rc = RTSemEventWait(pThis->svga.FIFOExtCmdSem, RT_INDEFINITE_WAIT);
3631 AssertRC(rc);
3632 PDMR3ThreadSuspend(pThis->svga.pFIFOIOThread);
3633 }
3634# endif
3635
3636 return VINF_SUCCESS;
3637}
3638
3639/**
3640 * Reinit the video mode after the state has been loaded.
3641 */
3642int vmsvgaLoadDone(PPDMDEVINS pDevIns)
3643{
3644 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
3645 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
3646
3647 pThis->last_bpp = VMSVGA_VAL_UNINITIALIZED; /* force mode reset */
3648 vmsvgaChangeMode(pThis);
3649
3650 /* Set the active cursor. */
3651 if (pSVGAState->Cursor.fActive)
3652 {
3653 int rc;
3654
3655 rc = pThis->pDrv->pfnVBVAMousePointerShape (pThis->pDrv,
3656 true,
3657 true,
3658 pSVGAState->Cursor.xHotspot,
3659 pSVGAState->Cursor.yHotspot,
3660 pSVGAState->Cursor.width,
3661 pSVGAState->Cursor.height,
3662 pSVGAState->Cursor.pData);
3663 AssertRC(rc);
3664 }
3665 return VINF_SUCCESS;
3666}
3667
3668/**
3669 * @copydoc FNSSMDEVSAVEEXEC
3670 */
3671int vmsvgaSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
3672{
3673 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
3674 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
3675 int rc;
3676
3677 /* Save our part of the VGAState */
3678 rc = SSMR3PutStructEx(pSSM, &pThis->svga, sizeof(pThis->svga), 0, g_aVGAStateSVGAFields, NULL);
3679 AssertRCReturn(rc, rc);
3680
3681 /* Save the framebuffer backup. */
3682 rc = SSMR3PutMem(pSSM, pThis->svga.pFrameBufferBackup, VMSVGA_FRAMEBUFFER_BACKUP_SIZE);
3683 AssertRCReturn(rc, rc);
3684
3685 /* Save the VMSVGA state. */
3686 rc = SSMR3PutStructEx(pSSM, pSVGAState, sizeof(*pSVGAState), 0, g_aVMSVGASTATEFields, NULL);
3687 AssertRCReturn(rc, rc);
3688
3689 /* Save the active cursor bitmaps. */
3690 if (pSVGAState->Cursor.fActive)
3691 {
3692 rc = SSMR3PutMem(pSSM, pSVGAState->Cursor.pData, pSVGAState->Cursor.cbData);
3693 AssertRCReturn(rc, rc);
3694 }
3695
3696 /* Save the GMR state */
3697 for (uint32_t i = 0; i < RT_ELEMENTS(pSVGAState->aGMR); i++)
3698 {
3699 rc = SSMR3PutStructEx(pSSM, &pSVGAState->aGMR[i], sizeof(pSVGAState->aGMR[i]), 0, g_aGMRFields, NULL);
3700 AssertRCReturn(rc, rc);
3701
3702 for (uint32_t j = 0; j < pSVGAState->aGMR[i].numDescriptors; j++)
3703 {
3704 rc = SSMR3PutStructEx(pSSM, &pSVGAState->aGMR[i].paDesc[j], sizeof(pSVGAState->aGMR[i].paDesc[j]), 0, g_aVMSVGAGMRDESCRIPTORFields, NULL);
3705 AssertRCReturn(rc, rc);
3706 }
3707 }
3708
3709# ifdef VBOX_WITH_VMSVGA3D
3710 if (pThis->svga.f3DEnabled)
3711 {
3712 /* Save the 3d state in the FIFO thread. */
3713 pThis->svga.u8FIFOExtCommand = VMSVGA_FIFO_EXTCMD_SAVESTATE;
3714 pThis->svga.pFIFOExtCmdParam = (void *)pSSM;
3715 /* Hack alert: resume the IO thread as it has been suspended before the destruct callback.
3716 * The PowerOff notification isn't working, so not an option in this case.
3717 */
3718 PDMR3ThreadResume(pThis->svga.pFIFOIOThread);
3719 SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3720 /* Wait for the end of the external command. */
3721 rc = RTSemEventWait(pThis->svga.FIFOExtCmdSem, RT_INDEFINITE_WAIT);
3722 AssertRC(rc);
3723 PDMR3ThreadSuspend(pThis->svga.pFIFOIOThread);
3724 }
3725# endif
3726 return VINF_SUCCESS;
3727}
3728
3729/**
3730 * Resets the SVGA hardware state
3731 *
3732 * @returns VBox status code.
3733 * @param pDevIns The device instance.
3734 */
3735int vmsvgaReset(PPDMDEVINS pDevIns)
3736{
3737 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
3738 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
3739
3740 /* Reset before init? */
3741 if (!pSVGAState)
3742 return VINF_SUCCESS;
3743
3744 Log(("vmsvgaReset\n"));
3745
3746 pThis->svga.pFIFOR3[SVGA_FIFO_NEXT_CMD] = pThis->svga.pFIFOR3[SVGA_FIFO_STOP] = 0;
3747
3748 /* Reset the FIFO thread. */
3749 pThis->svga.u8FIFOExtCommand = VMSVGA_FIFO_EXTCMD_RESET;
3750 SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3751 /* Wait for the end of the termination sequence. */
3752 int rc = RTSemEventWait(pThis->svga.FIFOExtCmdSem, 10000);
3753 AssertRC(rc);
3754
3755 pThis->svga.cScratchRegion = VMSVGA_SCRATCH_SIZE;
3756 memset(pThis->svga.au32ScratchRegion, 0, sizeof(pThis->svga.au32ScratchRegion));
3757 memset(pThis->svga.pSVGAState, 0, sizeof(VMSVGASTATE));
3758 memset(pThis->svga.pFrameBufferBackup, 0, VMSVGA_FRAMEBUFFER_BACKUP_SIZE);
3759
3760 /* Register caps. */
3761 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;
3762# ifdef VBOX_WITH_VMSVGA3D
3763 pThis->svga.u32RegCaps |= SVGA_CAP_3D;
3764# endif
3765
3766 /* Setup FIFO capabilities. */
3767 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;
3768
3769 /* Valid with SVGA_FIFO_CAP_SCREEN_OBJECT_2 */
3770 pThis->svga.pFIFOR3[SVGA_FIFO_CURSOR_SCREEN_ID] = SVGA_ID_INVALID;
3771
3772 /* VRAM tracking is enabled by default during bootup. */
3773 pThis->svga.fVRAMTracking = true;
3774 pThis->svga.fEnabled = false;
3775
3776 /* Invalidate current settings. */
3777 pThis->svga.uWidth = VMSVGA_VAL_UNINITIALIZED;
3778 pThis->svga.uHeight = VMSVGA_VAL_UNINITIALIZED;
3779 pThis->svga.uBpp = VMSVGA_VAL_UNINITIALIZED;
3780 pThis->svga.cbScanline = 0;
3781
3782 return rc;
3783}
3784
3785/**
3786 * Cleans up the SVGA hardware state
3787 *
3788 * @returns VBox status code.
3789 * @param pDevIns The device instance.
3790 */
3791int vmsvgaDestruct(PPDMDEVINS pDevIns)
3792{
3793 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
3794 PVMSVGASTATE pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
3795 int rc;
3796
3797 /* Stop the FIFO thread. */
3798 pThis->svga.u8FIFOExtCommand = VMSVGA_FIFO_EXTCMD_TERMINATE;
3799 /* Hack alert: resume the IO thread as it has been suspended before the destruct callback.
3800 * The PowerOff notification isn't working, so not an option in this case.
3801 */
3802 PDMR3ThreadResume(pThis->svga.pFIFOIOThread);
3803 SUPSemEventSignal(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3804
3805 /* Wait for the end of the termination sequence. */
3806 rc = RTSemEventWait(pThis->svga.FIFOExtCmdSem, 10000);
3807 AssertRC(rc);
3808 PDMR3ThreadSuspend(pThis->svga.pFIFOIOThread);
3809
3810 if (pSVGAState)
3811 {
3812# ifndef VMSVGA_USE_EMT_HALT_CODE
3813 if (pSVGAState->hBusyDelayedEmts != NIL_RTSEMEVENTMULTI)
3814 {
3815 RTSemEventMultiDestroy(pSVGAState->hBusyDelayedEmts);
3816 pSVGAState->hBusyDelayedEmts = NIL_RTSEMEVENT;
3817 }
3818# endif
3819 if (pSVGAState->Cursor.fActive)
3820 RTMemFree(pSVGAState->Cursor.pData);
3821
3822 for (unsigned i = 0; i < RT_ELEMENTS(pSVGAState->aGMR); i++)
3823 {
3824 if (pSVGAState->aGMR[i].paDesc)
3825 RTMemFree(pSVGAState->aGMR[i].paDesc);
3826 }
3827 RTMemFree(pSVGAState);
3828 }
3829 if (pThis->svga.pFrameBufferBackup)
3830 RTMemFree(pThis->svga.pFrameBufferBackup);
3831 if (pThis->svga.FIFOExtCmdSem != NIL_RTSEMEVENT)
3832 {
3833 RTSemEventDestroy(pThis->svga.FIFOExtCmdSem);
3834 pThis->svga.FIFOExtCmdSem = NIL_RTSEMEVENT;
3835 }
3836 if (pThis->svga.FIFORequestSem != NIL_SUPSEMEVENT)
3837 {
3838 SUPSemEventClose(pThis->svga.pSupDrvSession, pThis->svga.FIFORequestSem);
3839 pThis->svga.FIFORequestSem = NIL_SUPSEMEVENT;
3840 }
3841
3842 return VINF_SUCCESS;
3843}
3844
3845/**
3846 * Initialize the SVGA hardware state
3847 *
3848 * @returns VBox status code.
3849 * @param pDevIns The device instance.
3850 */
3851int vmsvgaInit(PPDMDEVINS pDevIns)
3852{
3853 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
3854 PVMSVGASTATE pSVGAState;
3855 PVM pVM = PDMDevHlpGetVM(pDevIns);
3856 int rc;
3857
3858 pThis->svga.cScratchRegion = VMSVGA_SCRATCH_SIZE;
3859 memset(pThis->svga.au32ScratchRegion, 0, sizeof(pThis->svga.au32ScratchRegion));
3860
3861 pThis->svga.pSVGAState = RTMemAllocZ(sizeof(VMSVGASTATE));
3862 AssertReturn(pThis->svga.pSVGAState, VERR_NO_MEMORY);
3863 pSVGAState = (PVMSVGASTATE)pThis->svga.pSVGAState;
3864
3865 /* Necessary for creating a backup of the text mode frame buffer when switching into svga mode. */
3866 pThis->svga.pFrameBufferBackup = RTMemAllocZ(VMSVGA_FRAMEBUFFER_BACKUP_SIZE);
3867 AssertReturn(pThis->svga.pFrameBufferBackup, VERR_NO_MEMORY);
3868
3869 /* Create event semaphore. */
3870 pThis->svga.pSupDrvSession = PDMDevHlpGetSupDrvSession(pDevIns);
3871
3872 rc = SUPSemEventCreate(pThis->svga.pSupDrvSession, &pThis->svga.FIFORequestSem);
3873 if (RT_FAILURE(rc))
3874 {
3875 Log(("%s: Failed to create event semaphore for FIFO handling.\n", __FUNCTION__));
3876 return rc;
3877 }
3878
3879 /* Create event semaphore. */
3880 rc = RTSemEventCreate(&pThis->svga.FIFOExtCmdSem);
3881 if (RT_FAILURE(rc))
3882 {
3883 Log(("%s: Failed to create event semaphore for external fifo cmd handling.\n", __FUNCTION__));
3884 return rc;
3885 }
3886
3887# ifndef VMSVGA_USE_EMT_HALT_CODE
3888 /* Create semaphore for delaying EMTs wait for the FIFO to stop being busy. */
3889 rc = RTSemEventMultiCreate(&pSVGAState->hBusyDelayedEmts);
3890 AssertRCReturn(rc, rc);
3891# endif
3892
3893 /* Register caps. */
3894 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;
3895# ifdef VBOX_WITH_VMSVGA3D
3896 pThis->svga.u32RegCaps |= SVGA_CAP_3D;
3897# endif
3898
3899 /* Setup FIFO capabilities. */
3900 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;
3901
3902 /* Valid with SVGA_FIFO_CAP_SCREEN_OBJECT_2 */
3903 pThis->svga.pFIFOR3[SVGA_FIFO_CURSOR_SCREEN_ID] = SVGA_ID_INVALID;
3904
3905 pThis->svga.pFIFOR3[SVGA_FIFO_3D_HWVERSION] = pThis->svga.pFIFOR3[SVGA_FIFO_3D_HWVERSION_REVISED] = 0; /* no 3d available. */
3906# ifdef VBOX_WITH_VMSVGA3D
3907 if (pThis->svga.f3DEnabled)
3908 {
3909 rc = vmsvga3dInit(pThis);
3910 if (RT_FAILURE(rc))
3911 {
3912 LogRel(("VMSVGA3d: 3D support disabled! (vmsvga3dInit -> %Rrc)\n", rc));
3913 pThis->svga.f3DEnabled = false;
3914 }
3915 }
3916# endif
3917 /* VRAM tracking is enabled by default during bootup. */
3918 pThis->svga.fVRAMTracking = true;
3919
3920 /* Invalidate current settings. */
3921 pThis->svga.uWidth = VMSVGA_VAL_UNINITIALIZED;
3922 pThis->svga.uHeight = VMSVGA_VAL_UNINITIALIZED;
3923 pThis->svga.uBpp = VMSVGA_VAL_UNINITIALIZED;
3924 pThis->svga.cbScanline = 0;
3925
3926 pThis->svga.u32MaxWidth = VBE_DISPI_MAX_YRES;
3927 pThis->svga.u32MaxHeight = VBE_DISPI_MAX_XRES;
3928 while (pThis->svga.u32MaxWidth * pThis->svga.u32MaxHeight * 4 /* 32 bpp */ > pThis->vram_size)
3929 {
3930 pThis->svga.u32MaxWidth -= 256;
3931 pThis->svga.u32MaxHeight -= 256;
3932 }
3933 Log(("VMSVGA: Maximum size (%d,%d)\n", pThis->svga.u32MaxWidth, pThis->svga.u32MaxHeight));
3934
3935 /* Create the async IO thread. */
3936 rc = PDMDevHlpThreadCreate(pDevIns, &pThis->svga.pFIFOIOThread, pThis, vmsvgaFIFOLoop, vmsvgaFIFOLoopWakeUp, 0,
3937 RTTHREADTYPE_IO, "VMSVGA FIFO");
3938 if (RT_FAILURE(rc))
3939 {
3940 AssertMsgFailed(("%s: Async IO Thread creation for FIFO handling failed rc=%d\n", __FUNCTION__, rc));
3941 return rc;
3942 }
3943
3944 /*
3945 * Statistics.
3946 */
3947 STAM_REG(pVM, &pSVGAState->StatR3CmdPresent, STAMTYPE_PROFILE, "/Devices/VMSVGA/3d/Cmd/Present", STAMUNIT_TICKS_PER_CALL, "Profiling of Present.");
3948 STAM_REG(pVM, &pSVGAState->StatR3CmdDrawPrimitive, STAMTYPE_PROFILE, "/Devices/VMSVGA/3d/Cmd/DrawPrimitive", STAMUNIT_TICKS_PER_CALL, "Profiling of DrawPrimitive.");
3949 STAM_REG(pVM, &pSVGAState->StatR3CmdSurfaceDMA, STAMTYPE_PROFILE, "/Devices/VMSVGA/3d/Cmd/SurfaceDMA", STAMUNIT_TICKS_PER_CALL, "Profiling of SurfaceDMA.");
3950 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.");
3951 STAM_REL_REG(pVM, &pSVGAState->StatFifoCommands, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoCommands", STAMUNIT_OCCURENCES, "FIFO command counter.");
3952 STAM_REL_REG(pVM, &pSVGAState->StatFifoErrors, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoErrors", STAMUNIT_OCCURENCES, "FIFO error counter.");
3953 STAM_REL_REG(pVM, &pSVGAState->StatFifoUnkCmds, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoUnknownCommands", STAMUNIT_OCCURENCES, "FIFO unknown command counter.");
3954 STAM_REL_REG(pVM, &pSVGAState->StatFifoTodoTimeout, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoTodoTimeout", STAMUNIT_OCCURENCES, "Number of times we discovered pending work after a wait timeout.");
3955 STAM_REL_REG(pVM, &pSVGAState->StatFifoTodoWoken, STAMTYPE_COUNTER, "/Devices/VMSVGA/FifoTodoWoken", STAMUNIT_OCCURENCES, "Number of times we discovered pending work after being woken up.");
3956 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).");
3957
3958 return VINF_SUCCESS;
3959}
3960
3961# ifdef VBOX_WITH_VMSVGA3D
3962/** Names for the vmsvga 3d capabilities, prefixed with format type hint char. */
3963static const char * const g_apszVmSvgaDevCapNames[] =
3964{
3965 "x3D", /* = 0 */
3966 "xMAX_LIGHTS",
3967 "xMAX_TEXTURES",
3968 "xMAX_CLIP_PLANES",
3969 "xVERTEX_SHADER_VERSION",
3970 "xVERTEX_SHADER",
3971 "xFRAGMENT_SHADER_VERSION",
3972 "xFRAGMENT_SHADER",
3973 "xMAX_RENDER_TARGETS",
3974 "xS23E8_TEXTURES",
3975 "xS10E5_TEXTURES",
3976 "xMAX_FIXED_VERTEXBLEND",
3977 "xD16_BUFFER_FORMAT",
3978 "xD24S8_BUFFER_FORMAT",
3979 "xD24X8_BUFFER_FORMAT",
3980 "xQUERY_TYPES",
3981 "xTEXTURE_GRADIENT_SAMPLING",
3982 "rMAX_POINT_SIZE",
3983 "xMAX_SHADER_TEXTURES",
3984 "xMAX_TEXTURE_WIDTH",
3985 "xMAX_TEXTURE_HEIGHT",
3986 "xMAX_VOLUME_EXTENT",
3987 "xMAX_TEXTURE_REPEAT",
3988 "xMAX_TEXTURE_ASPECT_RATIO",
3989 "xMAX_TEXTURE_ANISOTROPY",
3990 "xMAX_PRIMITIVE_COUNT",
3991 "xMAX_VERTEX_INDEX",
3992 "xMAX_VERTEX_SHADER_INSTRUCTIONS",
3993 "xMAX_FRAGMENT_SHADER_INSTRUCTIONS",
3994 "xMAX_VERTEX_SHADER_TEMPS",
3995 "xMAX_FRAGMENT_SHADER_TEMPS",
3996 "xTEXTURE_OPS",
3997 "xSURFACEFMT_X8R8G8B8",
3998 "xSURFACEFMT_A8R8G8B8",
3999 "xSURFACEFMT_A2R10G10B10",
4000 "xSURFACEFMT_X1R5G5B5",
4001 "xSURFACEFMT_A1R5G5B5",
4002 "xSURFACEFMT_A4R4G4B4",
4003 "xSURFACEFMT_R5G6B5",
4004 "xSURFACEFMT_LUMINANCE16",
4005 "xSURFACEFMT_LUMINANCE8_ALPHA8",
4006 "xSURFACEFMT_ALPHA8",
4007 "xSURFACEFMT_LUMINANCE8",
4008 "xSURFACEFMT_Z_D16",
4009 "xSURFACEFMT_Z_D24S8",
4010 "xSURFACEFMT_Z_D24X8",
4011 "xSURFACEFMT_DXT1",
4012 "xSURFACEFMT_DXT2",
4013 "xSURFACEFMT_DXT3",
4014 "xSURFACEFMT_DXT4",
4015 "xSURFACEFMT_DXT5",
4016 "xSURFACEFMT_BUMPX8L8V8U8",
4017 "xSURFACEFMT_A2W10V10U10",
4018 "xSURFACEFMT_BUMPU8V8",
4019 "xSURFACEFMT_Q8W8V8U8",
4020 "xSURFACEFMT_CxV8U8",
4021 "xSURFACEFMT_R_S10E5",
4022 "xSURFACEFMT_R_S23E8",
4023 "xSURFACEFMT_RG_S10E5",
4024 "xSURFACEFMT_RG_S23E8",
4025 "xSURFACEFMT_ARGB_S10E5",
4026 "xSURFACEFMT_ARGB_S23E8",
4027 "xMISSING62",
4028 "xMAX_VERTEX_SHADER_TEXTURES",
4029 "xMAX_SIMULTANEOUS_RENDER_TARGETS",
4030 "xSURFACEFMT_V16U16",
4031 "xSURFACEFMT_G16R16",
4032 "xSURFACEFMT_A16B16G16R16",
4033 "xSURFACEFMT_UYVY",
4034 "xSURFACEFMT_YUY2",
4035 "xMULTISAMPLE_NONMASKABLESAMPLES",
4036 "xMULTISAMPLE_MASKABLESAMPLES",
4037 "xALPHATOCOVERAGE",
4038 "xSUPERSAMPLE",
4039 "xAUTOGENMIPMAPS",
4040 "xSURFACEFMT_NV12",
4041 "xSURFACEFMT_AYUV",
4042 "xMAX_CONTEXT_IDS",
4043 "xMAX_SURFACE_IDS",
4044 "xSURFACEFMT_Z_DF16",
4045 "xSURFACEFMT_Z_DF24",
4046 "xSURFACEFMT_Z_D24S8_INT",
4047 "xSURFACEFMT_BC4_UNORM",
4048 "xSURFACEFMT_BC5_UNORM", /* 83 */
4049};
4050# endif
4051
4052
4053/**
4054 * Power On notification.
4055 *
4056 * @returns VBox status.
4057 * @param pDevIns The device instance data.
4058 *
4059 * @remarks Caller enters the device critical section.
4060 */
4061DECLCALLBACK(void) vmsvgaR3PowerOn(PPDMDEVINS pDevIns)
4062{
4063 PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
4064 int rc;
4065
4066# ifdef VBOX_WITH_VMSVGA3D
4067 if (pThis->svga.f3DEnabled)
4068 {
4069 rc = vmsvga3dPowerOn(pThis);
4070
4071 if (RT_SUCCESS(rc))
4072 {
4073 bool fSavedBuffering = RTLogRelSetBuffering(true);
4074 SVGA3dCapsRecord *pCaps;
4075 SVGA3dCapPair *pData;
4076 uint32_t idxCap = 0;
4077
4078 /* 3d hardware version; latest and greatest */
4079 pThis->svga.pFIFOR3[SVGA_FIFO_3D_HWVERSION_REVISED] = SVGA3D_HWVERSION_CURRENT;
4080 pThis->svga.pFIFOR3[SVGA_FIFO_3D_HWVERSION] = SVGA3D_HWVERSION_CURRENT;
4081
4082 pCaps = (SVGA3dCapsRecord *)&pThis->svga.pFIFOR3[SVGA_FIFO_3D_CAPS];
4083 pCaps->header.type = SVGA3DCAPS_RECORD_DEVCAPS;
4084 pData = (SVGA3dCapPair *)&pCaps->data;
4085
4086 /* Fill out all 3d capabilities. */
4087 for (unsigned i = 0; i < SVGA3D_DEVCAP_MAX; i++)
4088 {
4089 uint32_t val = 0;
4090
4091 rc = vmsvga3dQueryCaps(pThis, i, &val);
4092 if (RT_SUCCESS(rc))
4093 {
4094 pData[idxCap][0] = i;
4095 pData[idxCap][1] = val;
4096 idxCap++;
4097 if (g_apszVmSvgaDevCapNames[i][0] == 'x')
4098 LogRel(("VMSVGA3d: cap[%u]=%#010x {%s}\n", i, val, &g_apszVmSvgaDevCapNames[i][1]));
4099 else
4100 LogRel(("VMSVGA3d: cap[%u]=%d.%04u {%s}\n", i, (int)(float)val, (unsigned)((float)val * 10000) % 10000,
4101 &g_apszVmSvgaDevCapNames[i][1]));
4102 }
4103 else
4104 LogRel(("VMSVGA3d: cap[%u]=failed rc=%Rrc! {%s}\n", i, rc, &g_apszVmSvgaDevCapNames[i][1]));
4105 }
4106 pCaps->header.length = (sizeof(pCaps->header) + idxCap * sizeof(SVGA3dCapPair)) / sizeof(uint32_t);
4107 pCaps = (SVGA3dCapsRecord *)((uint32_t *)pCaps + pCaps->header.length);
4108
4109 /* Mark end of record array. */
4110 pCaps->header.length = 0;
4111
4112 RTLogRelSetBuffering(fSavedBuffering);
4113 }
4114 }
4115# endif // VBOX_WITH_VMSVGA3D
4116}
4117
4118#endif /* IN_RING3 */
4119
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