VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.h@ 85054

Last change on this file since 85054 was 84802, checked in by vboxsync, 5 years ago

Devices/Graphics: experimental GLX graphics output: reset screens on power off

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.2 KB
Line 
1/* $Id: DevVGA-SVGA.h 84802 2020-06-11 22:44:48Z vboxsync $ */
2/** @file
3 * VMware SVGA device
4 */
5/*
6 * Copyright (C) 2013-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA_h
18#define VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA_h
19#ifndef RT_WITHOUT_PRAGMA_ONCE
20# pragma once
21#endif
22
23#ifndef VBOX_WITH_VMSVGA
24# error "VBOX_WITH_VMSVGA is not defined"
25#endif
26
27#include <VBox/vmm/pdmthread.h>
28
29#include "vmsvga/svga3d_reg.h"
30
31/** Default FIFO size. */
32#define VMSVGA_FIFO_SIZE _2M
33/** The old FIFO size. */
34#define VMSVGA_FIFO_SIZE_OLD _128K
35
36/** Default scratch region size. */
37#define VMSVGA_SCRATCH_SIZE 0x100
38/** Surface memory available to the guest. */
39#define VMSVGA_SURFACE_SIZE (512*1024*1024)
40/** Maximum GMR pages. */
41#define VMSVGA_MAX_GMR_PAGES 0x100000
42/** Maximum nr of GMR ids. */
43#define VMSVGA_MAX_GMR_IDS _8K
44/** Maximum number of GMR descriptors. */
45#define VMSVGA_MAX_GMR_DESC_LOOP_COUNT VMSVGA_MAX_GMR_PAGES
46
47#define VMSVGA_VAL_UNINITIALIZED (unsigned)-1
48
49/** For validating X and width values.
50 * The code assumes it's at least an order of magnitude less than UINT32_MAX. */
51#define VMSVGA_MAX_X _1M
52/** For validating Y and height values.
53 * The code assumes it's at least an order of magnitude less than UINT32_MAX. */
54#define VMSVGA_MAX_Y _1M
55
56/* u32ActionFlags */
57#define VMSVGA_ACTION_CHANGEMODE_BIT 0
58#define VMSVGA_ACTION_CHANGEMODE RT_BIT(VMSVGA_ACTION_CHANGEMODE_BIT)
59
60
61#ifdef DEBUG
62/* Enable to log FIFO register accesses. */
63//# define DEBUG_FIFO_ACCESS
64/* Enable to log GMR page accesses. */
65//# define DEBUG_GMR_ACCESS
66#endif
67
68#define VMSVGA_FIFO_EXTCMD_NONE 0
69#define VMSVGA_FIFO_EXTCMD_TERMINATE 1
70#define VMSVGA_FIFO_EXTCMD_SAVESTATE 2
71#define VMSVGA_FIFO_EXTCMD_LOADSTATE 3
72#define VMSVGA_FIFO_EXTCMD_RESET 4
73#define VMSVGA_FIFO_EXTCMD_UPDATE_SURFACE_HEAP_BUFFERS 5
74#define VMSVGA_FIFO_EXTCMD_POWEROFF 6
75
76/** Size of the region to backup when switching into svga mode. */
77#define VMSVGA_VGA_FB_BACKUP_SIZE _512K
78
79/** @def VMSVGA_WITH_VGA_FB_BACKUP
80 * Enables correct VGA MMIO read/write handling when VMSVGA is enabled. It
81 * is SLOW and probably not entirely right, but it helps with getting 3dmark
82 * output and other stuff. */
83#define VMSVGA_WITH_VGA_FB_BACKUP 1
84
85/** @def VMSVGA_WITH_VGA_FB_BACKUP_AND_IN_RING3
86 * defined(VMSVGA_WITH_VGA_FB_BACKUP) && defined(IN_RING3) */
87#if (defined(VMSVGA_WITH_VGA_FB_BACKUP) && defined(IN_RING3)) || defined(DOXYGEN_RUNNING)
88# define VMSVGA_WITH_VGA_FB_BACKUP_AND_IN_RING3 1
89#else
90# undef VMSVGA_WITH_VGA_FB_BACKUP_AND_IN_RING3
91#endif
92
93/** @def VMSVGA_WITH_VGA_FB_BACKUP_AND_IN_RZ
94 * defined(VMSVGA_WITH_VGA_FB_BACKUP) && !defined(IN_RING3) */
95#if (defined(VMSVGA_WITH_VGA_FB_BACKUP) && !defined(IN_RING3)) || defined(DOXYGEN_RUNNING)
96# define VMSVGA_WITH_VGA_FB_BACKUP_AND_IN_RZ 1
97#else
98# undef VMSVGA_WITH_VGA_FB_BACKUP_AND_IN_RZ
99#endif
100
101
102typedef struct
103{
104 PSSMHANDLE pSSM;
105 uint32_t uVersion;
106 uint32_t uPass;
107} VMSVGA_STATE_LOAD;
108typedef VMSVGA_STATE_LOAD *PVMSVGA_STATE_LOAD;
109
110/** Host screen viewport.
111 * (4th quadrant with negated Y values - usual Windows and X11 world view.) */
112typedef struct VMSVGAVIEWPORT
113{
114 uint32_t x; /**< x coordinate (left). */
115 uint32_t y; /**< y coordinate (top). */
116 uint32_t cx; /**< width. */
117 uint32_t cy; /**< height. */
118 /** Right side coordinate (exclusive). Same as x + cx. */
119 uint32_t xRight;
120 /** First quadrant low y coordinate.
121 * Same as y + cy - 1 in window coordinates. */
122 uint32_t yLowWC;
123 /** First quadrant high y coordinate (exclusive) - yLowWC + cy.
124 * Same as y - 1 in window coordinates. */
125 uint32_t yHighWC;
126 /** Alignment padding. */
127 uint32_t uAlignment;
128} VMSVGAVIEWPORT;
129
130#ifdef VBOX_WITH_VMSVGA3D
131typedef struct VMSVGAHWSCREEN *PVMSVGAHWSCREEN;
132#endif
133
134/**
135 * Screen object state.
136 */
137typedef struct VMSVGASCREENOBJECT
138{
139 /** SVGA_SCREEN_* flags. */
140 uint32_t fuScreen;
141 /** The screen object id. */
142 uint32_t idScreen;
143 /** The screen dimensions. */
144 int32_t xOrigin;
145 int32_t yOrigin;
146 uint32_t cWidth;
147 uint32_t cHeight;
148 /** Offset of the screen buffer in the guest VRAM. */
149 uint32_t offVRAM;
150 /** Scanline pitch. */
151 uint32_t cbPitch;
152 /** Bits per pixel. */
153 uint32_t cBpp;
154 bool fDefined;
155 bool fModified;
156#ifdef VBOX_WITH_VMSVGA3D
157 /** Pointer to the HW accelerated (3D) screen data. */
158 R3PTRTYPE(PVMSVGAHWSCREEN) pHwScreen;
159#endif
160} VMSVGASCREENOBJECT;
161
162/** Pointer to the private VMSVGA ring-3 state structure.
163 * @todo Still not entirely satisfired with the type name, but better than
164 * the previous lower/upper case only distinction. */
165typedef struct VMSVGAR3STATE *PVMSVGAR3STATE;
166/** Pointer to the private (implementation specific) VMSVGA3d state. */
167typedef struct VMSVGA3DSTATE *PVMSVGA3DSTATE;
168
169
170/**
171 * The VMSVGA device state.
172 *
173 * This instantatiated as VGASTATE::svga.
174 */
175typedef struct VMSVGAState
176{
177 /** Guest physical address of the FIFO memory range. */
178 RTGCPHYS GCPhysFIFO;
179 /** Size in bytes of the FIFO memory range.
180 * This may be smaller than cbFIFOConfig after restoring an old VM state. */
181 uint32_t cbFIFO;
182 /** The configured FIFO size. */
183 uint32_t cbFIFOConfig;
184 /** SVGA id. */
185 uint32_t u32SVGAId;
186 /** SVGA extensions enabled or not. */
187 uint32_t fEnabled;
188 /** SVGA memory area configured status. */
189 uint32_t fConfigured;
190 /** Device is busy handling FIFO requests (VMSVGA_BUSY_F_FIFO,
191 * VMSVGA_BUSY_F_EMT_FORCE). */
192 uint32_t volatile fBusy;
193#define VMSVGA_BUSY_F_FIFO RT_BIT_32(0) /**< The normal true/false busy FIFO bit. */
194#define VMSVGA_BUSY_F_EMT_FORCE RT_BIT_32(1) /**< Bit preventing race status flickering when EMT kicks the FIFO thread. */
195 /** Traces (dirty page detection) enabled or not. */
196 uint32_t fTraces;
197 /** Guest OS identifier. */
198 uint32_t u32GuestId;
199 /** Scratch region size (VMSVGAState::au32ScratchRegion). */
200 uint32_t cScratchRegion;
201 /** Irq status. */
202 uint32_t u32IrqStatus;
203 /** Irq mask. */
204 uint32_t u32IrqMask;
205 /** Pitch lock. */
206 uint32_t u32PitchLock;
207 /** Current GMR id. (SVGA_REG_GMR_ID) */
208 uint32_t u32CurrentGMRId;
209 /** Register caps. */
210 uint32_t u32RegCaps;
211 uint32_t Padding0; /* Used to be I/O port base address. */
212 /** Port io index register. */
213 uint32_t u32IndexReg;
214 /** FIFO request semaphore. */
215 SUPSEMEVENT hFIFORequestSem;
216 /** The last seen SVGA_FIFO_CURSOR_COUNT value.
217 * Used by the FIFO thread and its watchdog. */
218 uint32_t uLastCursorUpdateCount;
219 /** Indicates that the FIFO thread is sleeping and might need waking up. */
220 bool volatile fFIFOThreadSleeping;
221 /** The legacy GFB mode registers. If used, they correspond to screen 0. */
222 /** True when the guest modifies the GFB mode registers. */
223 bool fGFBRegisters;
224 bool afPadding[6];
225 uint32_t uWidth;
226 uint32_t uHeight;
227 uint32_t uBpp;
228 uint32_t cbScanline;
229 uint32_t uHostBpp;
230 /** Maximum width supported. */
231 uint32_t u32MaxWidth;
232 /** Maximum height supported. */
233 uint32_t u32MaxHeight;
234 /** Viewport rectangle, i.e. what's currently visible of the target host
235 * window. This is usually (0,0)(uWidth,uHeight), but if the window is
236 * shrunk and scrolling applied, both the origin and size may differ. */
237 VMSVGAVIEWPORT viewport;
238 /** Action flags */
239 uint32_t u32ActionFlags;
240 /** SVGA 3d extensions enabled or not. */
241 bool f3DEnabled;
242 /** VRAM page monitoring enabled or not. */
243 bool fVRAMTracking;
244 /** External command to be executed in the FIFO thread. */
245 uint8_t volatile u8FIFOExtCommand;
246 /** Set by vmsvgaR3RunExtCmdOnFifoThread when it temporarily resumes the FIFO
247 * thread and does not want it do anything but the command. */
248 bool volatile fFifoExtCommandWakeup;
249#ifdef DEBUG_GMR_ACCESS
250 /** GMR debug access handler type handle. */
251 PGMPHYSHANDLERTYPE hGmrAccessHandlerType;
252#endif
253#if defined(VMSVGA_USE_FIFO_ACCESS_HANDLER) || defined(DEBUG_FIFO_ACCESS)
254 /** FIFO debug access handler type handle. */
255 PGMPHYSHANDLERTYPE hFifoAccessHandlerType;
256#elif defined(DEBUG_GMR_ACCESS)
257 uint32_t uPadding1;
258#endif
259 /** Number of GMRs. */
260 uint32_t cGMR;
261 uint32_t uScreenOffset; /* Used only for loading older saved states. */
262
263 /** Legacy cursor state. */
264 uint32_t uCursorX;
265 uint32_t uCursorY;
266 uint32_t uCursorID;
267 uint32_t uCursorOn;
268
269 /** Scratch array.
270 * Putting this at the end since it's big it probably not . */
271 uint32_t au32ScratchRegion[VMSVGA_SCRATCH_SIZE];
272
273 STAMCOUNTER StatRegBitsPerPixelWr;
274 STAMCOUNTER StatRegBusyWr;
275 STAMCOUNTER StatRegCursorXWr;
276 STAMCOUNTER StatRegCursorYWr;
277 STAMCOUNTER StatRegCursorIdWr;
278 STAMCOUNTER StatRegCursorOnWr;
279 STAMCOUNTER StatRegDepthWr;
280 STAMCOUNTER StatRegDisplayHeightWr;
281 STAMCOUNTER StatRegDisplayIdWr;
282 STAMCOUNTER StatRegDisplayIsPrimaryWr;
283 STAMCOUNTER StatRegDisplayPositionXWr;
284 STAMCOUNTER StatRegDisplayPositionYWr;
285 STAMCOUNTER StatRegDisplayWidthWr;
286 STAMCOUNTER StatRegEnableWr;
287 STAMCOUNTER StatRegGmrIdWr;
288 STAMCOUNTER StatRegGuestIdWr;
289 STAMCOUNTER StatRegHeightWr;
290 STAMCOUNTER StatRegIdWr;
291 STAMCOUNTER StatRegIrqMaskWr;
292 STAMCOUNTER StatRegNumDisplaysWr;
293 STAMCOUNTER StatRegNumGuestDisplaysWr;
294 STAMCOUNTER StatRegPaletteWr;
295 STAMCOUNTER StatRegPitchLockWr;
296 STAMCOUNTER StatRegPseudoColorWr;
297 STAMCOUNTER StatRegReadOnlyWr;
298 STAMCOUNTER StatRegScratchWr;
299 STAMCOUNTER StatRegSyncWr;
300 STAMCOUNTER StatRegTopWr;
301 STAMCOUNTER StatRegTracesWr;
302 STAMCOUNTER StatRegUnknownWr;
303 STAMCOUNTER StatRegWidthWr;
304
305 STAMCOUNTER StatRegBitsPerPixelRd;
306 STAMCOUNTER StatRegBlueMaskRd;
307 STAMCOUNTER StatRegBusyRd;
308 STAMCOUNTER StatRegBytesPerLineRd;
309 STAMCOUNTER StatRegCapabilitesRd;
310 STAMCOUNTER StatRegConfigDoneRd;
311 STAMCOUNTER StatRegCursorXRd;
312 STAMCOUNTER StatRegCursorYRd;
313 STAMCOUNTER StatRegCursorIdRd;
314 STAMCOUNTER StatRegCursorOnRd;
315 STAMCOUNTER StatRegDepthRd;
316 STAMCOUNTER StatRegDisplayHeightRd;
317 STAMCOUNTER StatRegDisplayIdRd;
318 STAMCOUNTER StatRegDisplayIsPrimaryRd;
319 STAMCOUNTER StatRegDisplayPositionXRd;
320 STAMCOUNTER StatRegDisplayPositionYRd;
321 STAMCOUNTER StatRegDisplayWidthRd;
322 STAMCOUNTER StatRegEnableRd;
323 STAMCOUNTER StatRegFbOffsetRd;
324 STAMCOUNTER StatRegFbSizeRd;
325 STAMCOUNTER StatRegFbStartRd;
326 STAMCOUNTER StatRegGmrIdRd;
327 STAMCOUNTER StatRegGmrMaxDescriptorLengthRd;
328 STAMCOUNTER StatRegGmrMaxIdsRd;
329 STAMCOUNTER StatRegGmrsMaxPagesRd;
330 STAMCOUNTER StatRegGreenMaskRd;
331 STAMCOUNTER StatRegGuestIdRd;
332 STAMCOUNTER StatRegHeightRd;
333 STAMCOUNTER StatRegHostBitsPerPixelRd;
334 STAMCOUNTER StatRegIdRd;
335 STAMCOUNTER StatRegIrqMaskRd;
336 STAMCOUNTER StatRegMaxHeightRd;
337 STAMCOUNTER StatRegMaxWidthRd;
338 STAMCOUNTER StatRegMemorySizeRd;
339 STAMCOUNTER StatRegMemRegsRd;
340 STAMCOUNTER StatRegMemSizeRd;
341 STAMCOUNTER StatRegMemStartRd;
342 STAMCOUNTER StatRegNumDisplaysRd;
343 STAMCOUNTER StatRegNumGuestDisplaysRd;
344 STAMCOUNTER StatRegPaletteRd;
345 STAMCOUNTER StatRegPitchLockRd;
346 STAMCOUNTER StatRegPsuedoColorRd;
347 STAMCOUNTER StatRegRedMaskRd;
348 STAMCOUNTER StatRegScratchRd;
349 STAMCOUNTER StatRegScratchSizeRd;
350 STAMCOUNTER StatRegSyncRd;
351 STAMCOUNTER StatRegTopRd;
352 STAMCOUNTER StatRegTracesRd;
353 STAMCOUNTER StatRegUnknownRd;
354 STAMCOUNTER StatRegVramSizeRd;
355 STAMCOUNTER StatRegWidthRd;
356 STAMCOUNTER StatRegWriteOnlyRd;
357} VMSVGAState, VMSVGASTATE;
358
359
360/**
361 * The VMSVGA device state for ring-3
362 *
363 * This instantatiated as VGASTATER3::svga.
364 */
365typedef struct VMSVGASTATER3
366{
367 /** The R3 FIFO pointer. */
368 R3PTRTYPE(uint32_t *) pau32FIFO;
369 /** R3 Opaque pointer to svga state. */
370 R3PTRTYPE(PVMSVGAR3STATE) pSvgaR3State;
371 /** R3 Opaque pointer to 3d state. */
372 R3PTRTYPE(PVMSVGA3DSTATE) p3dState;
373 /** The separate VGA frame buffer in svga mode.
374 * Unlike the the boch-based VGA device implementation, VMSVGA seems to have a
375 * separate frame buffer for VGA and allows concurrent use of both. The SVGA
376 * SDK is making use of this to do VGA text output while testing other things in
377 * SVGA mode, displaying the result by switching back to VGA text mode. So,
378 * when entering SVGA mode we copy the first part of the frame buffer here and
379 * direct VGA accesses here instead. It is copied back when leaving SVGA mode. */
380 R3PTRTYPE(uint8_t *) pbVgaFrameBufferR3;
381 /** R3 Opaque pointer to an external fifo cmd parameter. */
382 R3PTRTYPE(void * volatile) pvFIFOExtCmdParam;
383
384 /** FIFO external command semaphore. */
385 R3PTRTYPE(RTSEMEVENT) hFIFOExtCmdSem;
386 /** FIFO IO Thread. */
387 R3PTRTYPE(PPDMTHREAD) pFIFOIOThread;
388} VMSVGASTATER3;
389
390
391/**
392 * The VMSVGA device state for ring-0
393 *
394 * This instantatiated as VGASTATER0::svga.
395 */
396typedef struct VMSVGASTATER0
397{
398 /** The R0 FIFO pointer.
399 * @note This only points to the _first_ _page_ of the FIFO! */
400 R0PTRTYPE(uint32_t *) pau32FIFO;
401} VMSVGASTATER0;
402
403
404typedef struct VGAState *PVGASTATE;
405typedef struct VGASTATER3 *PVGASTATER3;
406typedef struct VGASTATER0 *PVGASTATER0;
407typedef struct VGASTATERC *PVGASTATERC;
408typedef CTX_SUFF(PVGASTATE) PVGASTATECC;
409
410DECLCALLBACK(int) vmsvgaR3PciIORegionFifoMapUnmap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
411 RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType);
412DECLCALLBACK(VBOXSTRICTRC) vmsvgaIORead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb);
413DECLCALLBACK(VBOXSTRICTRC) vmsvgaIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb);
414
415DECLCALLBACK(void) vmsvgaR3PortSetViewport(PPDMIDISPLAYPORT pInterface, uint32_t uScreenId,
416 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
417DECLCALLBACK(void) vmsvgaR3PortReportMonitorPositions(PPDMIDISPLAYPORT pInterface, uint32_t cPositions, PCRTPOINT paPositions);
418
419int vmsvgaR3Init(PPDMDEVINS pDevIns);
420int vmsvgaR3Reset(PPDMDEVINS pDevIns);
421int vmsvgaR3Destruct(PPDMDEVINS pDevIns);
422int vmsvgaR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
423int vmsvgaR3LoadDone(PPDMDEVINS pDevIns);
424int vmsvgaR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
425DECLCALLBACK(void) vmsvgaR3PowerOn(PPDMDEVINS pDevIns);
426DECLCALLBACK(void) vmsvgaR3PowerOff(PPDMDEVINS pDevIns);
427void vmsvgaR3FifoWatchdogTimer(PPDMDEVINS pDevIns, PVGASTATE pThis, PVGASTATECC pThisCC);
428
429#ifdef IN_RING3
430VMSVGASCREENOBJECT *vmsvgaR3GetScreenObject(PVGASTATECC pThisCC, uint32_t idScreen);
431int vmsvgaR3UpdateScreen(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen, int x, int y, int w, int h);
432#endif
433
434int vmsvgaR3GmrTransfer(PVGASTATE pThis, PVGASTATECC pThisCC, const SVGA3dTransferType enmTransferType,
435 uint8_t *pbHstBuf, uint32_t cbHstBuf, uint32_t offHst, int32_t cbHstPitch,
436 SVGAGuestPtr gstPtr, uint32_t offGst, int32_t cbGstPitch,
437 uint32_t cbWidth, uint32_t cHeight);
438
439void vmsvgaR3ClipCopyBox(const SVGA3dSize *pSizeSrc, const SVGA3dSize *pSizeDest, SVGA3dCopyBox *pBox);
440void vmsvgaR3ClipBox(const SVGA3dSize *pSize, SVGA3dBox *pBox);
441void vmsvgaR3ClipRect(SVGASignedRect const *pBound, SVGASignedRect *pRect);
442
443#endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA_h */
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