xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/svga/include/svga_reg.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (c) 1998-2024 Broadcom. All Rights Reserved.
3  * The term “Broadcom” refers to Broadcom Inc.
4  * and/or its subsidiaries.
5  * SPDX-License-Identifier: GPL-2.0 OR MIT
6  */
7 
8 /*
9  * svga_reg.h --
10  *
11  *    Virtual hardware definitions for the VMware SVGA II device.
12  */
13 
14 #ifndef _SVGA_REG_H_
15 #define _SVGA_REG_H_
16 
17 #include "svga_types.h"
18 
19 /*
20  * SVGA_REG_ENABLE bit definitions.
21  */
22 typedef enum {
23    SVGA_REG_ENABLE_DISABLE = 0,
24    SVGA_REG_ENABLE_ENABLE = (1 << 0),
25    SVGA_REG_ENABLE_HIDE = (1 << 1),
26 } SvgaRegEnable;
27 
28 typedef uint32 SVGAMobId;
29 
30 /*
31  * Arbitrary and meaningless limits. Please ignore these when writing
32  * new drivers.
33  */
34 #define SVGA_MAX_WIDTH                  2560
35 #define SVGA_MAX_HEIGHT                 1600
36 #define SVGA_MAX_BITS_PER_PIXEL         32
37 #define SVGA_MAX_DEPTH                  24
38 #define SVGA_MAX_DISPLAYS               10
39 
40 /*
41  * Legal values for the SVGA_REG_CURSOR_ON register in old-fashioned
42  * cursor bypass mode. This is still supported, but no new guest
43  * drivers should use it.
44  */
45 #define SVGA_CURSOR_ON_HIDE            0x0   /* Must be 0 to maintain backward compatibility */
46 #define SVGA_CURSOR_ON_SHOW            0x1   /* Must be 1 to maintain backward compatibility */
47 #define SVGA_CURSOR_ON_REMOVE_FROM_FB  0x2   /* Remove the cursor from the framebuffer because we need to see what's under it */
48 #define SVGA_CURSOR_ON_RESTORE_TO_FB   0x3   /* Put the cursor back in the framebuffer so the user can see it */
49 
50 /*
51  * The maximum framebuffer size that can traced for e.g. guests in VESA mode.
52  * The changeMap in the monitor is proportional to this number. Therefore, we'd
53  * like to keep it as small as possible to reduce monitor overhead (using
54  * SVGA_VRAM_MAX_SIZE for this increases the size of the shared area by over
55  * 4k!).
56  *
57  * NB: For compatibility reasons, this value must be greater than 0xff0000.
58  *     See bug 335072.
59  */
60 #define SVGA_FB_MAX_TRACEABLE_SIZE      0x1000000
61 
62 #define SVGA_MAX_PSEUDOCOLOR_DEPTH      8
63 #define SVGA_MAX_PSEUDOCOLORS           (1 << SVGA_MAX_PSEUDOCOLOR_DEPTH)
64 #define SVGA_NUM_PALETTE_REGS           (3 * SVGA_MAX_PSEUDOCOLORS)
65 
66 #define SVGA_MAGIC         0x900000UL
67 #define SVGA_MAKE_ID(ver)  (SVGA_MAGIC << 8 | (ver))
68 
69 /* Version 2 let the address of the frame buffer be unsigned on Win32 */
70 #define SVGA_VERSION_2     2
71 #define SVGA_ID_2          SVGA_MAKE_ID(SVGA_VERSION_2)
72 
73 /* Version 1 has new registers starting with SVGA_REG_CAPABILITIES so
74    PALETTE_BASE has moved */
75 #define SVGA_VERSION_1     1
76 #define SVGA_ID_1          SVGA_MAKE_ID(SVGA_VERSION_1)
77 
78 /* Version 0 is the initial version */
79 #define SVGA_VERSION_0     0
80 #define SVGA_ID_0          SVGA_MAKE_ID(SVGA_VERSION_0)
81 
82 /* "Invalid" value for all SVGA IDs. (Version ID, screen object ID, surface ID...) */
83 #define SVGA_ID_INVALID    0xFFFFFFFF
84 
85 /* Port offsets, relative to BAR0 */
86 #define SVGA_INDEX_PORT         0x0
87 #define SVGA_VALUE_PORT         0x1
88 #define SVGA_BIOS_PORT          0x2
89 #define SVGA_IRQSTATUS_PORT     0x8
90 
91 /*
92  * Interrupt source flags for IRQSTATUS_PORT and IRQMASK.
93  *
94  * Interrupts are only supported when the
95  * SVGA_CAP_IRQMASK capability is present.
96  */
97 #define SVGA_IRQFLAG_ANY_FENCE            0x1    /* Any fence was passed */
98 #define SVGA_IRQFLAG_FIFO_PROGRESS        0x2    /* Made forward progress in the FIFO */
99 #define SVGA_IRQFLAG_FENCE_GOAL           0x4    /* SVGA_FIFO_FENCE_GOAL reached */
100 #define SVGA_IRQFLAG_COMMAND_BUFFER       0x8    /* Command buffer completed */
101 #define SVGA_IRQFLAG_ERROR                0x10   /* Error while processing commands */
102 
103 /*
104  * Registers
105  */
106 
107 enum {
108    SVGA_REG_ID = 0,
109    SVGA_REG_ENABLE = 1,
110    SVGA_REG_WIDTH = 2,
111    SVGA_REG_HEIGHT = 3,
112    SVGA_REG_MAX_WIDTH = 4,
113    SVGA_REG_MAX_HEIGHT = 5,
114    SVGA_REG_DEPTH = 6,
115    SVGA_REG_BITS_PER_PIXEL = 7,       /* Current bpp in the guest */
116    SVGA_REG_PSEUDOCOLOR = 8,
117    SVGA_REG_RED_MASK = 9,
118    SVGA_REG_GREEN_MASK = 10,
119    SVGA_REG_BLUE_MASK = 11,
120    SVGA_REG_BYTES_PER_LINE = 12,
121    SVGA_REG_FB_START = 13,            /* (Deprecated) */
122    SVGA_REG_FB_OFFSET = 14,
123    SVGA_REG_VRAM_SIZE = 15,
124    SVGA_REG_FB_SIZE = 16,
125 
126    /* ID 0 implementation only had the above registers, then the palette */
127    SVGA_REG_ID_0_TOP = 17,
128 
129    SVGA_REG_CAPABILITIES = 17,
130    SVGA_REG_MEM_START = 18,           /* (Deprecated) */
131    SVGA_REG_MEM_SIZE = 19,
132    SVGA_REG_CONFIG_DONE = 20,         /* Set when memory area configured */
133    SVGA_REG_SYNC = 21,                /* See "FIFO Synchronization Registers" */
134    SVGA_REG_BUSY = 22,                /* See "FIFO Synchronization Registers" */
135    SVGA_REG_GUEST_ID = 23,            /* Set guest OS identifier */
136    SVGA_REG_CURSOR_ID = 24,           /* (Deprecated) */
137    SVGA_REG_CURSOR_X = 25,            /* (Deprecated) */
138    SVGA_REG_CURSOR_Y = 26,            /* (Deprecated) */
139    SVGA_REG_CURSOR_ON = 27,           /* (Deprecated) */
140    SVGA_REG_HOST_BITS_PER_PIXEL = 28, /* (Deprecated) */
141    SVGA_REG_SCRATCH_SIZE = 29,        /* Number of scratch registers */
142    SVGA_REG_MEM_REGS = 30,            /* Number of FIFO registers */
143    SVGA_REG_NUM_DISPLAYS = 31,        /* (Deprecated) */
144    SVGA_REG_PITCHLOCK = 32,           /* Fixed pitch for all modes */
145    SVGA_REG_IRQMASK = 33,             /* Interrupt mask */
146 
147    /* Legacy multi-monitor support */
148    SVGA_REG_NUM_GUEST_DISPLAYS = 34,/* Number of guest displays in X/Y direction */
149    SVGA_REG_DISPLAY_ID = 35,        /* Display ID for the following display attributes */
150    SVGA_REG_DISPLAY_IS_PRIMARY = 36,/* Whether this is a primary display */
151    SVGA_REG_DISPLAY_POSITION_X = 37,/* The display position x */
152    SVGA_REG_DISPLAY_POSITION_Y = 38,/* The display position y */
153    SVGA_REG_DISPLAY_WIDTH = 39,     /* The display's width */
154    SVGA_REG_DISPLAY_HEIGHT = 40,    /* The display's height */
155 
156    /* See "Guest memory regions" below. */
157    SVGA_REG_GMR_ID = 41,
158    SVGA_REG_GMR_DESCRIPTOR = 42,
159    SVGA_REG_GMR_MAX_IDS = 43,
160    SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH = 44,
161 
162    SVGA_REG_TRACES = 45,            /* Enable trace-based updates even when FIFO is on */
163    SVGA_REG_GMRS_MAX_PAGES = 46,    /* Maximum number of 4KB pages for all GMRs */
164    SVGA_REG_MEMORY_SIZE = 47,       /* Total dedicated device memory excluding FIFO */
165    SVGA_REG_COMMAND_LOW = 48,       /* Lower 32 bits and submits commands */
166    SVGA_REG_COMMAND_HIGH = 49,      /* Upper 32 bits of command buffer PA */
167    SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM = 50,   /* Max primary memory */
168    SVGA_REG_SUGGESTED_GBOBJECT_MEM_SIZE_KB = 51, /* Suggested limit on mob mem */
169    SVGA_REG_DEV_CAP = 52,           /* Write dev cap index, read value */
170    SVGA_REG_CMD_PREPEND_LOW = 53,
171    SVGA_REG_iCMD_PREPEND_HIGH = 54,
172    SVGA_REG_SCREENTARGET_MAX_WIDTH = 55,
173    SVGA_REG_SCREENTARGET_MAX_HEIGHT = 56,
174    SVGA_REG_MOB_MAX_SIZE = 57,
175    SVGA_REG_BLANK_SCREEN_TARGETS = 58,
176    SVGA_REG_CAP2 = 59,
177    SVGA_REG_TOP = 60,               /* Must be 1 more than the last register */
178 
179    SVGA_PALETTE_BASE = 1024,        /* Base of SVGA color map */
180    /* Next 768 (== 256*3) registers exist for colormap */
181    SVGA_SCRATCH_BASE = SVGA_PALETTE_BASE + SVGA_NUM_PALETTE_REGS
182                                     /* Base of scratch registers */
183    /* Next reg[SVGA_REG_SCRATCH_SIZE] registers exist for scratch usage:
184       First 4 are reserved for VESA BIOS Extension; any remaining are for
185       the use of the current SVGA driver. */
186 };
187 
188 /*
189  * Guest memory regions (GMRs):
190  *
191  * This is a new memory mapping feature available in SVGA devices
192  * which have the SVGA_CAP_GMR bit set. Previously, there were two
193  * fixed memory regions available with which to share data between the
194  * device and the driver: the FIFO ('MEM') and the framebuffer. GMRs
195  * are our name for an extensible way of providing arbitrary DMA
196  * buffers for use between the driver and the SVGA device. They are a
197  * new alternative to framebuffer memory, usable for both 2D and 3D
198  * graphics operations.
199  *
200  * Since GMR mapping must be done synchronously with guest CPU
201  * execution, we use a new pair of SVGA registers:
202  *
203  *   SVGA_REG_GMR_ID --
204  *
205  *     Read/write.
206  *     This register holds the 32-bit ID (a small positive integer)
207  *     of a GMR to create, delete, or redefine. Writing this register
208  *     has no side-effects.
209  *
210  *   SVGA_REG_GMR_DESCRIPTOR --
211  *
212  *     Write-only.
213  *     Writing this register will create, delete, or redefine the GMR
214  *     specified by the above ID register. If this register is zero,
215  *     the GMR is deleted. Any pointers into this GMR (including those
216  *     currently being processed by FIFO commands) will be
217  *     synchronously invalidated.
218  *
219  *     If this register is nonzero, it must be the physical page
220  *     number (PPN) of a data structure which describes the physical
221  *     layout of the memory region this GMR should describe. The
222  *     descriptor structure will be read synchronously by the SVGA
223  *     device when this register is written. The descriptor need not
224  *     remain allocated for the lifetime of the GMR.
225  *
226  *     The guest driver should write SVGA_REG_GMR_ID first, then
227  *     SVGA_REG_GMR_DESCRIPTOR.
228  *
229  *   SVGA_REG_GMR_MAX_IDS --
230  *
231  *     Read-only.
232  *     The SVGA device may choose to support a maximum number of
233  *     user-defined GMR IDs. This register holds the number of supported
234  *     IDs. (The maximum supported ID plus 1)
235  *
236  *   SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH --
237  *
238  *     Read-only.
239  *     The SVGA device may choose to put a limit on the total number
240  *     of SVGAGuestMemDescriptor structures it will read when defining
241  *     a single GMR.
242  *
243  * The descriptor structure is an array of SVGAGuestMemDescriptor
244  * structures. Each structure may do one of three things:
245  *
246  *   - Terminate the GMR descriptor list.
247  *     (ppn==0, numPages==0)
248  *
249  *   - Add a PPN or range of PPNs to the GMR's virtual address space.
250  *     (ppn != 0, numPages != 0)
251  *
252  *   - Provide the PPN of the next SVGAGuestMemDescriptor, in order to
253  *     support multi-page GMR descriptor tables without forcing the
254  *     driver to allocate physically contiguous memory.
255  *     (ppn != 0, numPages == 0)
256  *
257  * Note that each physical page of SVGAGuestMemDescriptor structures
258  * can describe at least 2MB of guest memory. If the driver needs to
259  * use more than one page of descriptor structures, it must use one of
260  * its SVGAGuestMemDescriptors to point to an additional page.  The
261  * device will never automatically cross a page boundary.
262  *
263  * Once the driver has described a GMR, it is immediately available
264  * for use via any FIFO command that uses an SVGAGuestPtr structure.
265  * These pointers include a GMR identifier plus an offset into that
266  * GMR.
267  *
268  * The driver must check the SVGA_CAP_GMR bit before using the GMR
269  * registers.
270  */
271 
272 /*
273  * Special GMR IDs, allowing SVGAGuestPtrs to point to framebuffer
274  * memory as well.  In the future, these IDs could even be used to
275  * allow legacy memory regions to be redefined by the guest as GMRs.
276  *
277  * Using the guest framebuffer (GFB) at BAR1 for general purpose DMA
278  * is being phased out. Please try to use user-defined GMRs whenever
279  * possible.
280  */
281 #define SVGA_GMR_NULL         ((uint32) -1)
282 #define SVGA_GMR_FRAMEBUFFER  ((uint32) -2)  // Guest Framebuffer (GFB)
283 
284 typedef
285 struct SVGAGuestMemDescriptor {
286    uint32 ppn;
287    uint32 numPages;
288 } SVGAGuestMemDescriptor;
289 
290 typedef
291 struct SVGAGuestPtr {
292    uint32 gmrId;
293    uint32 offset;
294 } SVGAGuestPtr;
295 
296 /*
297  * Register based command buffers --
298  *
299  * Provide an SVGA device interface that allows the guest to submit
300  * command buffers to the SVGA device through an SVGA device register.
301  * The metadata for each command buffer is contained in the
302  * SVGACBHeader structure along with the return status codes.
303  *
304  * The SVGA device supports command buffers if
305  * SVGA_CAP_COMMAND_BUFFERS is set in the device caps register.  The
306  * fifo must be enabled for command buffers to be submitted.
307  *
308  * Command buffers are submitted when the guest writing the 64 byte
309  * aligned physical address into the SVGA_REG_COMMAND_LOW and
310  * SVGA_REG_COMMAND_HIGH.  SVGA_REG_COMMAND_HIGH contains the upper 32
311  * bits of the physical address.  SVGA_REG_COMMAND_LOW contains the
312  * lower 32 bits of the physical address, since the command buffer
313  * headers are required to be 64 byte aligned the lower 6 bits are
314  * used for the SVGACBContext value.  Writing to SVGA_REG_COMMAND_LOW
315  * submits the command buffer to the device and queues it for
316  * execution.  The SVGA device supports at least
317  * SVGA_CB_MAX_QUEUED_PER_CONTEXT command buffers that can be queued
318  * per context and if that limit is reached the device will write the
319  * status SVGA_CB_STATUS_QUEUE_FULL to the status value of the command
320  * buffer header synchronously and not raise any IRQs.
321  *
322  * It is invalid to submit a command buffer without a valid physical
323  * address and results are undefined.
324  *
325  * The device guarantees that command buffers of size SVGA_CB_MAX_SIZE
326  * will be supported.  If a larger command buffer is submitted results
327  * are unspecified and the device will either complete the command
328  * buffer or return an error.
329  *
330  * The device guarantees that any individual command in a command
331  * buffer can be up to SVGA_CB_MAX_COMMAND_SIZE in size which is
332  * enough to fit a 64x64 color-cursor definition.  If the command is
333  * too large the device is allowed to process the command or return an
334  * error.
335  *
336  * The device context is a special SVGACBContext that allows for
337  * synchronous register like accesses with the flexibility of
338  * commands.  There is a different command set defined by
339  * SVGADeviceContextCmdId.  The commands in each command buffer is not
340  * allowed to straddle physical pages.
341  */
342 
343 #define SVGA_CB_MAX_SIZE (512 * 1024)  // 512 KB
344 #define SVGA_CB_MAX_QUEUED_PER_CONTEXT 32
345 #define SVGA_CB_MAX_COMMAND_SIZE (32 * 1024) // 32 KB
346 
347 #define SVGA_CB_CONTEXT_MASK 0x3f
348 typedef enum {
349    SVGA_CB_CONTEXT_DEVICE = 0x3f,
350    SVGA_CB_CONTEXT_0      = 0x0,
351    SVGA_CB_CONTEXT_MAX    = 0x1,
352 } SVGACBContext;
353 
354 
355 typedef enum {
356    /*
357     * The guest is supposed to write SVGA_CB_STATUS_NONE to the status
358     * field before submitting the command buffer header, the host will
359     * change the value when it is done with the command buffer.
360     */
361    SVGA_CB_STATUS_NONE             = 0,
362 
363    /*
364     * Written by the host when a command buffer completes successfully.
365     * The device raises an IRQ with SVGA_IRQFLAG_COMMAND_BUFFER unless
366     * the SVGA_CB_FLAG_NO_IRQ flag is set.
367     */
368    SVGA_CB_STATUS_COMPLETED        = 1,
369 
370    /*
371     * Written by the host synchronously with the command buffer
372     * submission to indicate the command buffer was not submitted.  No
373     * IRQ is raised.
374     */
375    SVGA_CB_STATUS_QUEUE_FULL       = 2,
376 
377    /*
378     * Written by the host when an error was detected parsing a command
379     * in the command buffer, errorOffset is written to contain the
380     * offset to the first byte of the failing command.  The device
381     * raises the IRQ with both SVGA_IRQFLAG_ERROR and
382     * SVGA_IRQFLAG_COMMAND_BUFFER.  Some of the commands may have been
383     * processed.
384     */
385    SVGA_CB_STATUS_COMMAND_ERROR    = 3,
386 
387    /*
388     * Written by the host if there is an error parsing the command
389     * buffer header.  The device raises the IRQ with both
390     * SVGA_IRQFLAG_ERROR and SVGA_IRQFLAG_COMMAND_BUFFER.  The device
391     * did not processes any of the command buffer.
392     */
393    SVGA_CB_STATUS_CB_HEADER_ERROR  = 4,
394 
395    /*
396     * Written by the host if the guest requested the host to preempt
397     * the command buffer.  The device will not raise any IRQs and the
398     * command buffer was not processed.
399     */
400    SVGA_CB_STATUS_PREEMPTED        = 5,
401 } SVGACBStatus;
402 
403 typedef enum {
404    SVGA_CB_FLAG_NONE     = 0,
405    SVGA_CB_FLAG_NO_IRQ   = 1 << 0,
406 } SVGACBFlags;
407 
408 typedef
409 struct {
410    volatile SVGACBStatus status;
411    volatile uint32 errorOffset;
412    uint64 id;
413    SVGACBFlags flags;
414    uint32 length;
415    union {
416       PA pa;
417    } ptr;
418    uint32 mustBeZero[8];
419 } SVGACBHeader;
420 
421 typedef enum {
422    SVGA_DC_CMD_NOP                   = 0,
423    SVGA_DC_CMD_START_STOP_CONTEXT    = 1,
424    SVGA_DC_CMD_PREEMPT               = 2,
425    SVGA_DC_CMD_MAX                   = 3,
426    SVGA_DC_CMD_FORCE_UINT            = MAX_UINT32,
427 } SVGADeviceContextCmdId;
428 
429 typedef struct {
430    uint32 enable;
431    SVGACBContext context;
432 } SVGADCCmdStartStop;
433 
434 /*
435  * SVGADCCmdPreempt --
436  *
437  * This command allows the guest to request that all command buffers
438  * on the specified context be preempted that can be.  After execution
439  * of this command all command buffers that were preempted will
440  * already have SVGA_CB_STATUS_PREEMPTED written into the status
441  * field.  The device might still be processing a command buffer,
442  * assuming execution of it started before the preemption request was
443  * received.  Specifying the ignoreIDZero flag to TRUE will cause the
444  * device to not preempt command buffers with the id field in the
445  * command buffer header set to zero.
446  */
447 
448 typedef struct {
449    SVGACBContext context;
450    uint32 ignoreIDZero;
451 } SVGADCCmdPreempt;
452 
453 
454 /*
455  * SVGAGMRImageFormat --
456  *
457  *    This is a packed representation of the source 2D image format
458  *    for a GMR-to-screen blit. Currently it is defined as an encoding
459  *    of the screen's color depth and bits-per-pixel, however, 16 bits
460  *    are reserved for future use to identify other encodings (such as
461  *    RGBA or higher-precision images).
462  *
463  *    Currently supported formats:
464  *
465  *       bpp depth  Format Name
466  *       --- -----  -----------
467  *        32    24  32-bit BGRX
468  *        24    24  24-bit BGR
469  *        16    16  RGB 5-6-5
470  *        16    15  RGB 5-5-5
471  *
472  */
473 
474 typedef struct SVGAGMRImageFormat {
475    union {
476       struct {
477          uint32 bitsPerPixel : 8;
478          uint32 colorDepth   : 8;
479 	 uint32 reserved     : 16;  /* Must be zero */
480       };
481 
482       uint32 value;
483    };
484 } SVGAGMRImageFormat;
485 
486 typedef
487 struct SVGAGuestImage {
488    SVGAGuestPtr         ptr;
489 
490    /*
491     * A note on interpretation of pitch: This value of pitch is the
492     * number of bytes between vertically adjacent image
493     * blocks. Normally this is the number of bytes between the first
494     * pixel of two adjacent scanlines. With compressed textures,
495     * however, this may represent the number of bytes between
496     * compression blocks rather than between rows of pixels.
497     *
498     * XXX: Compressed textures currently must be tightly packed in guest memory.
499     *
500     * If the image is 1-dimensional, pitch is ignored.
501     *
502     * If 'pitch' is zero, the SVGA3D device calculates a pitch value
503     * assuming each row of blocks is tightly packed.
504     */
505    uint32 pitch;
506 } SVGAGuestImage;
507 
508 /*
509  * SVGAColorBGRX --
510  *
511  *    A 24-bit color format (BGRX), which does not depend on the
512  *    format of the legacy guest framebuffer (GFB) or the current
513  *    GMRFB state.
514  */
515 
516 typedef struct SVGAColorBGRX {
517    union {
518       struct {
519          uint32 b : 8;
520          uint32 g : 8;
521          uint32 r : 8;
522 	     uint32 x : 8;  /* Unused */
523       };
524 
525       uint32 value;
526    };
527 } SVGAColorBGRX;
528 
529 
530 /*
531  * SVGASignedRect --
532  * SVGASignedPoint --
533  *
534  *    Signed rectangle and point primitives. These are used by the new
535  *    2D primitives for drawing to Screen Objects, which can occupy a
536  *    signed virtual coordinate space.
537  *
538  *    SVGASignedRect specifies a half-open interval: the (left, top)
539  *    pixel is part of the rectangle, but the (right, bottom) pixel is
540  *    not.
541  */
542 
543 typedef
544 struct {
545    int32  left;
546    int32  top;
547    int32  right;
548    int32  bottom;
549 } SVGASignedRect;
550 
551 typedef
552 struct {
553    int32  x;
554    int32  y;
555 } SVGASignedPoint;
556 
557 
558 /*
559  * SVGA Device Capabilities
560  *
561  * Note the holes in the bitfield. Missing bits have been deprecated,
562  * and must not be reused. Those capabilities will never be reported
563  * by new versions of the SVGA device.
564  *
565  * XXX: Add longer descriptions for each capability, including a list
566  *      of the new features that each capability provides.
567  *
568  * SVGA_CAP_IRQMASK --
569  *    Provides device interrupts.  Adds device register SVGA_REG_IRQMASK
570  *    to set interrupt mask and direct I/O port SVGA_IRQSTATUS_PORT to
571  *    set/clear pending interrupts.
572  *
573  * SVGA_CAP_GMR --
574  *    Provides synchronous mapping of guest memory regions (GMR).
575  *    Adds device registers SVGA_REG_GMR_ID, SVGA_REG_GMR_DESCRIPTOR,
576  *    SVGA_REG_GMR_MAX_IDS, and SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH.
577  *
578  * SVGA_CAP_TRACES --
579  *    Allows framebuffer trace-based updates even when FIFO is enabled.
580  *    Adds device register SVGA_REG_TRACES.
581  *
582  * SVGA_CAP_GMR2 --
583  *    Provides asynchronous commands to define and remap guest memory
584  *    regions.  Adds device registers SVGA_REG_GMRS_MAX_PAGES and
585  *    SVGA_REG_MEMORY_SIZE.
586  *
587  * SVGA_CAP_SCREEN_OBJECT_2 --
588  *    Allow screen object support, and require backing stores from the
589  *    guest for each screen object.
590  *
591  * SVGA_CAP_COMMAND_BUFFERS --
592  *    Enable register based command buffer submission.
593  *
594  * SVGA_CAP_DEAD1 --
595  *    This cap was incorrectly used by old drivers and should not be
596  *    reused.
597  *
598  * SVGA_CAP_CMD_BUFFERS_2 --
599  *    Enable support for the prepend command buffer submission
600  *    registers.  SVGA_REG_CMD_PREPEND_LOW and
601  *    SVGA_REG_CMD_PREPEND_HIGH.
602  *
603  * SVGA_CAP_GBOBJECTS --
604  *    Enable guest-backed objects and surfaces.
605  *
606  * SVGA_CAP_CMD_BUFFERS_3 --
607  *    Enable support for command buffers in a mob.
608  */
609 
610 #define SVGA_CAP_NONE               0x00000000
611 #define SVGA_CAP_RECT_COPY          0x00000002
612 #define SVGA_CAP_CURSOR             0x00000020
613 #define SVGA_CAP_CURSOR_BYPASS      0x00000040
614 #define SVGA_CAP_CURSOR_BYPASS_2    0x00000080
615 #define SVGA_CAP_8BIT_EMULATION     0x00000100
616 #define SVGA_CAP_ALPHA_CURSOR       0x00000200
617 #define SVGA_CAP_3D                 0x00004000
618 #define SVGA_CAP_EXTENDED_FIFO      0x00008000
619 #define SVGA_CAP_MULTIMON           0x00010000
620 #define SVGA_CAP_PITCHLOCK          0x00020000
621 #define SVGA_CAP_IRQMASK            0x00040000
622 #define SVGA_CAP_DISPLAY_TOPOLOGY   0x00080000
623 #define SVGA_CAP_GMR                0x00100000
624 #define SVGA_CAP_TRACES             0x00200000
625 #define SVGA_CAP_GMR2               0x00400000
626 #define SVGA_CAP_SCREEN_OBJECT_2    0x00800000
627 #define SVGA_CAP_COMMAND_BUFFERS    0x01000000
628 #define SVGA_CAP_DEAD1              0x02000000
629 #define SVGA_CAP_CMD_BUFFERS_2      0x04000000
630 #define SVGA_CAP_GBOBJECTS          0x08000000
631 #define SVGA_CAP_CMD_BUFFERS_3      0x10000000
632 
633 #define SVGA_CAP_CAP2_REGISTER      0x80000000
634 
635 
636 /*
637  * The SVGA_REG_CAP2 register is an additional set of SVGA capability bits.
638  *
639  * SVGA_CAP2_GROW_OTABLE --
640  *      Allow the GrowOTable/DXGrowCOTable commands.
641  *
642  * SVGA_CAP2_INTRA_SURFACE_COPY --
643  *      Allow the IntraSurfaceCopy command.
644  *
645  * SVGA_CAP2_RESERVED --
646  *      Reserve the last bit for extending the SVGA capabilities to some
647  *      future mechanisms.
648  */
649 #define SVGA_CAP2_NONE               0x00000000
650 #define SVGA_CAP2_GROW_OTABLE        0x00000001
651 #define SVGA_CAP2_INTRA_SURFACE_COPY 0x00000002
652 #define SVGA_CAP2_RESERVED           0x80000000
653 
654 /*
655  * The Guest can optionally read some SVGA device capabilities through
656  * the backdoor with command BDOOR_CMD_GET_SVGA_CAPABILITIES before
657  * the SVGA device is initialized.  The type of capability the guest
658  * is requesting from the SVGABackdoorCapType enum should be placed in
659  * the upper 16 bits of the backdoor command id (ECX).  On success the
660  * the value of EBX will be set to BDOOR_MAGIC and EAX will be set to
661  * the requested capability.  If the command is not supported then EBX
662  * will be left unchanged and EAX will be set to -1.  Because it is
663  * possible that -1 is the value of the requested cap the correct way
664  * to check if the command was successful is to check if EBX was changed
665  * to BDOOR_MAGIC making sure to initialize the register to something
666  * else first.
667  */
668 
669 typedef enum {
670    SVGABackdoorCapDeviceCaps = 0,
671    SVGABackdoorCapFifoCaps = 1,
672    SVGABackdoorCap3dHWVersion = 2,
673    SVGABackdoorCapMax = 3,
674 } SVGABackdoorCapType;
675 
676 
677 /*
678  * FIFO register indices.
679  *
680  * The FIFO is a chunk of device memory mapped into guest physmem.  It
681  * is always treated as 32-bit words.
682  *
683  * The guest driver gets to decide how to partition it between
684  * - FIFO registers (there are always at least 4, specifying where the
685  *   following data area is and how much data it contains; there may be
686  *   more registers following these, depending on the FIFO protocol
687  *   version in use)
688  * - FIFO data, written by the guest and slurped out by the VMX.
689  * These indices are 32-bit word offsets into the FIFO.
690  */
691 
692 enum {
693    /*
694     * Block 1 (basic registers): The originally defined FIFO registers.
695     * These exist and are valid for all versions of the FIFO protocol.
696     */
697 
698    SVGA_FIFO_MIN = 0,
699    SVGA_FIFO_MAX,       /* The distance from MIN to MAX must be at least 10K */
700    SVGA_FIFO_NEXT_CMD,
701    SVGA_FIFO_STOP,
702 
703    /*
704     * Block 2 (extended registers): Mandatory registers for the extended
705     * FIFO.  These exist if the SVGA caps register includes
706     * SVGA_CAP_EXTENDED_FIFO; some of them are valid only if their
707     * associated capability bit is enabled.
708     *
709     * Note that when originally defined, SVGA_CAP_EXTENDED_FIFO implied
710     * support only for (FIFO registers) CAPABILITIES, FLAGS, and FENCE.
711     * This means that the guest has to test individually (in most cases
712     * using FIFO caps) for the presence of registers after this; the VMX
713     * can define "extended FIFO" to mean whatever it wants, and currently
714     * won't enable it unless there's room for that set and much more.
715     */
716 
717    SVGA_FIFO_CAPABILITIES = 4,
718    SVGA_FIFO_FLAGS,
719    /* Valid with SVGA_FIFO_CAP_FENCE: */
720    SVGA_FIFO_FENCE,
721 
722    /*
723     * Block 3a (optional extended registers): Additional registers for the
724     * extended FIFO, whose presence isn't actually implied by
725     * SVGA_CAP_EXTENDED_FIFO; these exist if SVGA_FIFO_MIN is high enough to
726     * leave room for them.
727     *
728     * These in block 3a, the VMX currently considers mandatory for the
729     * extended FIFO.
730     */
731 
732    /* Valid if exists (i.e. if extended FIFO enabled): */
733    SVGA_FIFO_3D_HWVERSION,       /* See SVGA3dHardwareVersion in svga3d_reg.h */
734    /* Valid with SVGA_FIFO_CAP_PITCHLOCK: */
735    SVGA_FIFO_PITCHLOCK,
736 
737    /* Valid with SVGA_FIFO_CAP_CURSOR_BYPASS_3: */
738    SVGA_FIFO_CURSOR_ON,          /* Cursor bypass 3 show/hide register */
739    SVGA_FIFO_CURSOR_X,           /* Cursor bypass 3 x register */
740    SVGA_FIFO_CURSOR_Y,           /* Cursor bypass 3 y register */
741    SVGA_FIFO_CURSOR_COUNT,       /* Incremented when any of the other 3 change */
742    SVGA_FIFO_CURSOR_LAST_UPDATED,/* Last time the host updated the cursor */
743 
744    /* Valid with SVGA_FIFO_CAP_RESERVE: */
745    SVGA_FIFO_RESERVED,           /* Bytes past NEXT_CMD with real contents */
746 
747    /*
748     * Valid with SVGA_FIFO_CAP_SCREEN_OBJECT or SVGA_FIFO_CAP_SCREEN_OBJECT_2:
749     *
750     * By default this is SVGA_ID_INVALID, to indicate that the cursor
751     * coordinates are specified relative to the virtual root. If this
752     * is set to a specific screen ID, cursor position is reinterpreted
753     * as a signed offset relative to that screen's origin.
754     */
755    SVGA_FIFO_CURSOR_SCREEN_ID,
756 
757    /*
758     * Valid with SVGA_FIFO_CAP_DEAD
759     *
760     * An arbitrary value written by the host, drivers should not use it.
761     */
762    SVGA_FIFO_DEAD,
763 
764    /*
765     * Valid with SVGA_FIFO_CAP_3D_HWVERSION_REVISED:
766     *
767     * Contains 3D HWVERSION (see SVGA3dHardwareVersion in svga3d_reg.h)
768     * on platforms that can enforce graphics resource limits.
769     */
770    SVGA_FIFO_3D_HWVERSION_REVISED,
771 
772    /*
773     * XXX: The gap here, up until SVGA_FIFO_3D_CAPS, can be used for new
774     * registers, but this must be done carefully and with judicious use of
775     * capability bits, since comparisons based on SVGA_FIFO_MIN aren't
776     * enough to tell you whether the register exists: we've shipped drivers
777     * and products that used SVGA_FIFO_3D_CAPS but didn't know about some of
778     * the earlier ones.  The actual order of introduction was:
779     * - PITCHLOCK
780     * - 3D_CAPS
781     * - CURSOR_* (cursor bypass 3)
782     * - RESERVED
783     * So, code that wants to know whether it can use any of the
784     * aforementioned registers, or anything else added after PITCHLOCK and
785     * before 3D_CAPS, needs to reason about something other than
786     * SVGA_FIFO_MIN.
787     */
788 
789    /*
790     * 3D caps block space; valid with 3D hardware version >=
791     * SVGA3D_HWVERSION_WS6_B1.
792     */
793    SVGA_FIFO_3D_CAPS      = 32,
794    SVGA_FIFO_3D_CAPS_LAST = 32 + 255,
795 
796    /*
797     * End of VMX's current definition of "extended-FIFO registers".
798     * Registers before here are always enabled/disabled as a block; either
799     * the extended FIFO is enabled and includes all preceding registers, or
800     * it's disabled entirely.
801     *
802     * Block 3b (truly optional extended registers): Additional registers for
803     * the extended FIFO, which the VMX already knows how to enable and
804     * disable with correct granularity.
805     *
806     * Registers after here exist if and only if the guest SVGA driver
807     * sets SVGA_FIFO_MIN high enough to leave room for them.
808     */
809 
810    /* Valid if register exists: */
811    SVGA_FIFO_GUEST_3D_HWVERSION, /* Guest driver's 3D version */
812    SVGA_FIFO_FENCE_GOAL,         /* Matching target for SVGA_IRQFLAG_FENCE_GOAL */
813    SVGA_FIFO_BUSY,               /* See "FIFO Synchronization Registers" */
814 
815    /*
816     * Always keep this last.  This defines the maximum number of
817     * registers we know about.  At power-on, this value is placed in
818     * the SVGA_REG_MEM_REGS register, and we expect the guest driver
819     * to allocate this much space in FIFO memory for registers.
820     */
821     SVGA_FIFO_NUM_REGS
822 };
823 
824 
825 /*
826  * Definition of registers included in extended FIFO support.
827  *
828  * The guest SVGA driver gets to allocate the FIFO between registers
829  * and data.  It must always allocate at least 4 registers, but old
830  * drivers stopped there.
831  *
832  * The VMX will enable extended FIFO support if and only if the guest
833  * left enough room for all registers defined as part of the mandatory
834  * set for the extended FIFO.
835  *
836  * Note that the guest drivers typically allocate the FIFO only at
837  * initialization time, not at mode switches, so it's likely that the
838  * number of FIFO registers won't change without a reboot.
839  *
840  * All registers less than this value are guaranteed to be present if
841  * svgaUser->fifo.extended is set. Any later registers must be tested
842  * individually for compatibility at each use (in the VMX).
843  *
844  * This value is used only by the VMX, so it can change without
845  * affecting driver compatibility; keep it that way?
846  */
847 #define SVGA_FIFO_EXTENDED_MANDATORY_REGS  (SVGA_FIFO_3D_CAPS_LAST + 1)
848 
849 
850 /*
851  * FIFO Synchronization Registers
852  *
853  *  This explains the relationship between the various FIFO
854  *  sync-related registers in IOSpace and in FIFO space.
855  *
856  *  SVGA_REG_SYNC --
857  *
858  *       The SYNC register can be used in two different ways by the guest:
859  *
860  *         1. If the guest wishes to fully sync (drain) the FIFO,
861  *            it will write once to SYNC then poll on the BUSY
862  *            register. The FIFO is synced once BUSY is zero.
863  *
864  *         2. If the guest wants to asynchronously wake up the host,
865  *            it will write once to SYNC without polling on BUSY.
866  *            Ideally it will do this after some new commands have
867  *            been placed in the FIFO, and after reading a zero
868  *            from SVGA_FIFO_BUSY.
869  *
870  *       (1) is the original behaviour that SYNC was designed to
871  *       support.  Originally, a write to SYNC would implicitly
872  *       trigger a read from BUSY. This causes us to synchronously
873  *       process the FIFO.
874  *
875  *       This behaviour has since been changed so that writing SYNC
876  *       will *not* implicitly cause a read from BUSY. Instead, it
877  *       makes a channel call which asynchronously wakes up the MKS
878  *       thread.
879  *
880  *       New guests can use this new behaviour to implement (2)
881  *       efficiently. This lets guests get the host's attention
882  *       without waiting for the MKS to poll, which gives us much
883  *       better CPU utilization on SMP hosts and on UP hosts while
884  *       we're blocked on the host GPU.
885  *
886  *       Old guests shouldn't notice the behaviour change. SYNC was
887  *       never guaranteed to process the entire FIFO, since it was
888  *       bounded to a particular number of CPU cycles. Old guests will
889  *       still loop on the BUSY register until the FIFO is empty.
890  *
891  *       Writing to SYNC currently has the following side-effects:
892  *
893  *         - Sets SVGA_REG_BUSY to TRUE (in the monitor)
894  *         - Asynchronously wakes up the MKS thread for FIFO processing
895  *         - The value written to SYNC is recorded as a "reason", for
896  *           stats purposes.
897  *
898  *       If SVGA_FIFO_BUSY is available, drivers are advised to only
899  *       write to SYNC if SVGA_FIFO_BUSY is FALSE. Drivers should set
900  *       SVGA_FIFO_BUSY to TRUE after writing to SYNC. The MKS will
901  *       eventually set SVGA_FIFO_BUSY on its own, but this approach
902  *       lets the driver avoid sending multiple asynchronous wakeup
903  *       messages to the MKS thread.
904  *
905  *  SVGA_REG_BUSY --
906  *
907  *       This register is set to TRUE when SVGA_REG_SYNC is written,
908  *       and it reads as FALSE when the FIFO has been completely
909  *       drained.
910  *
911  *       Every read from this register causes us to synchronously
912  *       process FIFO commands. There is no guarantee as to how many
913  *       commands each read will process.
914  *
915  *       CPU time spent processing FIFO commands will be billed to
916  *       the guest.
917  *
918  *       New drivers should avoid using this register unless they
919  *       need to guarantee that the FIFO is completely drained. It
920  *       is overkill for performing a sync-to-fence. Older drivers
921  *       will use this register for any type of synchronization.
922  *
923  *  SVGA_FIFO_BUSY --
924  *
925  *       This register is a fast way for the guest driver to check
926  *       whether the FIFO is already being processed. It reads and
927  *       writes at normal RAM speeds, with no monitor intervention.
928  *
929  *       If this register reads as TRUE, the host is guaranteeing that
930  *       any new commands written into the FIFO will be noticed before
931  *       the MKS goes back to sleep.
932  *
933  *       If this register reads as FALSE, no such guarantee can be
934  *       made.
935  *
936  *       The guest should use this register to quickly determine
937  *       whether or not it needs to wake up the host. If the guest
938  *       just wrote a command or group of commands that it would like
939  *       the host to begin processing, it should:
940  *
941  *         1. Read SVGA_FIFO_BUSY. If it reads as TRUE, no further
942  *            action is necessary.
943  *
944  *         2. Write TRUE to SVGA_FIFO_BUSY. This informs future guest
945  *            code that we've already sent a SYNC to the host and we
946  *            don't need to send a duplicate.
947  *
948  *         3. Write a reason to SVGA_REG_SYNC. This will send an
949  *            asynchronous wakeup to the MKS thread.
950  */
951 
952 
953 /*
954  * FIFO Capabilities
955  *
956  *      Fence -- Fence register and command are supported
957  *      Accel Front -- Front buffer only commands are supported
958  *      Pitch Lock -- Pitch lock register is supported
959  *      Video -- SVGA Video overlay units are supported
960  *      Escape -- Escape command is supported
961  *
962  * XXX: Add longer descriptions for each capability, including a list
963  *      of the new features that each capability provides.
964  *
965  * SVGA_FIFO_CAP_SCREEN_OBJECT --
966  *
967  *    Provides dynamic multi-screen rendering, for improved Unity and
968  *    multi-monitor modes. With Screen Object, the guest can
969  *    dynamically create and destroy 'screens', which can represent
970  *    Unity windows or virtual monitors. Screen Object also provides
971  *    strong guarantees that DMA operations happen only when
972  *    guest-initiated. Screen Object deprecates the BAR1 guest
973  *    framebuffer (GFB) and all commands that work only with the GFB.
974  *
975  *    New registers:
976  *       FIFO_CURSOR_SCREEN_ID, VIDEO_DATA_GMRID, VIDEO_DST_SCREEN_ID
977  *
978  *    New 2D commands:
979  *       DEFINE_SCREEN, DESTROY_SCREEN, DEFINE_GMRFB, BLIT_GMRFB_TO_SCREEN,
980  *       BLIT_SCREEN_TO_GMRFB, ANNOTATION_FILL, ANNOTATION_COPY
981  *
982  *    New 3D commands:
983  *       BLIT_SURFACE_TO_SCREEN
984  *
985  *    New guarantees:
986  *
987  *       - The host will not read or write guest memory, including the GFB,
988  *         except when explicitly initiated by a DMA command.
989  *
990  *       - All DMA, including legacy DMA like UPDATE and PRESENT_READBACK,
991  *         is guaranteed to complete before any subsequent FENCEs.
992  *
993  *       - All legacy commands which affect a Screen (UPDATE, PRESENT,
994  *         PRESENT_READBACK) as well as new Screen blit commands will
995  *         all behave consistently as blits, and memory will be read
996  *         or written in FIFO order.
997  *
998  *         For example, if you PRESENT from one SVGA3D surface to multiple
999  *         places on the screen, the data copied will always be from the
1000  *         SVGA3D surface at the time the PRESENT was issued in the FIFO.
1001  *         This was not necessarily true on devices without Screen Object.
1002  *
1003  *         This means that on devices that support Screen Object, the
1004  *         PRESENT_READBACK command should not be necessary unless you
1005  *         actually want to read back the results of 3D rendering into
1006  *         system memory. (And for that, the BLIT_SCREEN_TO_GMRFB
1007  *         command provides a strict superset of functionality.)
1008  *
1009  *       - When a screen is resized, either using Screen Object commands or
1010  *         legacy multimon registers, its contents are preserved.
1011  *
1012  * SVGA_FIFO_CAP_GMR2 --
1013  *
1014  *    Provides new commands to define and remap guest memory regions (GMR).
1015  *
1016  *    New 2D commands:
1017  *       DEFINE_GMR2, REMAP_GMR2.
1018  *
1019  * SVGA_FIFO_CAP_3D_HWVERSION_REVISED --
1020  *
1021  *    Indicates new register SVGA_FIFO_3D_HWVERSION_REVISED exists.
1022  *    This register may replace SVGA_FIFO_3D_HWVERSION on platforms
1023  *    that enforce graphics resource limits.  This allows the platform
1024  *    to clear SVGA_FIFO_3D_HWVERSION and disable 3D in legacy guest
1025  *    drivers that do not limit their resources.
1026  *
1027  *    Note this is an alias to SVGA_FIFO_CAP_GMR2 because these indicators
1028  *    are codependent (and thus we use a single capability bit).
1029  *
1030  * SVGA_FIFO_CAP_SCREEN_OBJECT_2 --
1031  *
1032  *    Modifies the DEFINE_SCREEN command to include a guest provided
1033  *    backing store in GMR memory and the bytesPerLine for the backing
1034  *    store.  This capability requires the use of a backing store when
1035  *    creating screen objects.  However if SVGA_FIFO_CAP_SCREEN_OBJECT
1036  *    is present then backing stores are optional.
1037  *
1038  * SVGA_FIFO_CAP_DEAD --
1039  *
1040  *    Drivers should not use this cap bit.  This cap bit can not be
1041  *    reused since some hosts already expose it.
1042  */
1043 
1044 #define SVGA_FIFO_CAP_NONE                  0
1045 #define SVGA_FIFO_CAP_FENCE             (1<<0)
1046 #define SVGA_FIFO_CAP_ACCELFRONT        (1<<1)
1047 #define SVGA_FIFO_CAP_PITCHLOCK         (1<<2)
1048 #define SVGA_FIFO_CAP_VIDEO             (1<<3)
1049 #define SVGA_FIFO_CAP_CURSOR_BYPASS_3   (1<<4)
1050 #define SVGA_FIFO_CAP_ESCAPE            (1<<5)
1051 #define SVGA_FIFO_CAP_RESERVE           (1<<6)
1052 #define SVGA_FIFO_CAP_SCREEN_OBJECT     (1<<7)
1053 #define SVGA_FIFO_CAP_GMR2              (1<<8)
1054 #define SVGA_FIFO_CAP_3D_HWVERSION_REVISED  SVGA_FIFO_CAP_GMR2
1055 #define SVGA_FIFO_CAP_SCREEN_OBJECT_2   (1<<9)
1056 #define SVGA_FIFO_CAP_DEAD              (1<<10)
1057 
1058 
1059 /*
1060  * FIFO Flags
1061  *
1062  *      Accel Front -- Driver should use front buffer only commands
1063  */
1064 
1065 #define SVGA_FIFO_FLAG_NONE                 0
1066 #define SVGA_FIFO_FLAG_ACCELFRONT       (1<<0)
1067 #define SVGA_FIFO_FLAG_RESERVED        (1<<31) /* Internal use only */
1068 
1069 /*
1070  * FIFO reservation sentinel value
1071  */
1072 
1073 #define SVGA_FIFO_RESERVED_UNKNOWN      0xffffffff
1074 
1075 
1076 /*
1077  * Video overlay support
1078  */
1079 
1080 #define SVGA_NUM_OVERLAY_UNITS 32
1081 
1082 
1083 /*
1084  * Video capabilities that the guest is currently using
1085  */
1086 
1087 #define SVGA_VIDEO_FLAG_COLORKEY        0x0001
1088 
1089 
1090 /*
1091  * Offsets for the video overlay registers
1092  */
1093 
1094 enum {
1095    SVGA_VIDEO_ENABLED = 0,
1096    SVGA_VIDEO_FLAGS,
1097    SVGA_VIDEO_DATA_OFFSET,
1098    SVGA_VIDEO_FORMAT,
1099    SVGA_VIDEO_COLORKEY,
1100    SVGA_VIDEO_SIZE,          /* Deprecated */
1101    SVGA_VIDEO_WIDTH,
1102    SVGA_VIDEO_HEIGHT,
1103    SVGA_VIDEO_SRC_X,
1104    SVGA_VIDEO_SRC_Y,
1105    SVGA_VIDEO_SRC_WIDTH,
1106    SVGA_VIDEO_SRC_HEIGHT,
1107    SVGA_VIDEO_DST_X,         /* Signed int32 */
1108    SVGA_VIDEO_DST_Y,         /* Signed int32 */
1109    SVGA_VIDEO_DST_WIDTH,
1110    SVGA_VIDEO_DST_HEIGHT,
1111    SVGA_VIDEO_PITCH_1,
1112    SVGA_VIDEO_PITCH_2,
1113    SVGA_VIDEO_PITCH_3,
1114    SVGA_VIDEO_DATA_GMRID,    /* Optional, defaults to SVGA_GMR_FRAMEBUFFER */
1115    SVGA_VIDEO_DST_SCREEN_ID, /* Optional, defaults to virtual coords */
1116                              /* (SVGA_ID_INVALID) */
1117    SVGA_VIDEO_NUM_REGS
1118 };
1119 
1120 
1121 /*
1122  * SVGA Overlay Units
1123  *
1124  *      width and height relate to the entire source video frame.
1125  *      srcX, srcY, srcWidth and srcHeight represent subset of the source
1126  *      video frame to be displayed.
1127  */
1128 
1129 typedef struct SVGAOverlayUnit {
1130    uint32 enabled;
1131    uint32 flags;
1132    uint32 dataOffset;
1133    uint32 format;
1134    uint32 colorKey;
1135    uint32 size;
1136    uint32 width;
1137    uint32 height;
1138    uint32 srcX;
1139    uint32 srcY;
1140    uint32 srcWidth;
1141    uint32 srcHeight;
1142    int32  dstX;
1143    int32  dstY;
1144    uint32 dstWidth;
1145    uint32 dstHeight;
1146    uint32 pitches[3];
1147    uint32 dataGMRId;
1148    uint32 dstScreenId;
1149 } SVGAOverlayUnit;
1150 
1151 
1152 /*
1153  * Guest display topology
1154  *
1155  * XXX: This structure is not part of the SVGA device's interface, and
1156  * doesn't really belong here.
1157  */
1158 #define SVGA_INVALID_DISPLAY_ID ((uint32)-1)
1159 
1160 typedef struct SVGADisplayTopology {
1161    uint16 displayId;
1162    uint16 isPrimary;
1163    uint32 width;
1164    uint32 height;
1165    uint32 positionX;
1166    uint32 positionY;
1167 } SVGADisplayTopology;
1168 
1169 
1170 /*
1171  * SVGAScreenObject --
1172  *
1173  *    This is a new way to represent a guest's multi-monitor screen or
1174  *    Unity window. Screen objects are only supported if the
1175  *    SVGA_FIFO_CAP_SCREEN_OBJECT capability bit is set.
1176  *
1177  *    If Screen Objects are supported, they can be used to fully
1178  *    replace the functionality provided by the framebuffer registers
1179  *    (SVGA_REG_WIDTH, HEIGHT, etc.) and by SVGA_CAP_DISPLAY_TOPOLOGY.
1180  *
1181  *    The screen object is a struct with guaranteed binary
1182  *    compatibility. New flags can be added, and the struct may grow,
1183  *    but existing fields must retain their meaning.
1184  *
1185  *    Added with SVGA_FIFO_CAP_SCREEN_OBJECT_2 are required fields of
1186  *    a SVGAGuestPtr that is used to back the screen contents.  This
1187  *    memory must come from the GFB.  The guest is not allowed to
1188  *    access the memory and doing so will have undefined results.  The
1189  *    backing store is required to be page aligned and the size is
1190  *    padded to the next page boundary.  The number of pages is:
1191  *       (bytesPerLine * size.width * 4 + PAGE_SIZE - 1) / PAGE_SIZE
1192  *
1193  *    The pitch in the backingStore is required to be at least large
1194  *    enough to hold a 32bbp scanline.  It is recommended that the
1195  *    driver pad bytesPerLine for a potential performance win.
1196  *
1197  *    The cloneCount field is treated as a hint from the guest that
1198  *    the user wants this display to be cloned, countCount times.  A
1199  *    value of zero means no cloning should happen.
1200  */
1201 
1202 #define SVGA_SCREEN_MUST_BE_SET     (1 << 0)
1203 #define SVGA_SCREEN_HAS_ROOT SVGA_SCREEN_MUST_BE_SET /* Deprecated */
1204 #define SVGA_SCREEN_IS_PRIMARY      (1 << 1)
1205 #define SVGA_SCREEN_FULLSCREEN_HINT (1 << 2)
1206 
1207 /*
1208  * Added with SVGA_FIFO_CAP_SCREEN_OBJECT_2.  When the screen is
1209  * deactivated the base layer is defined to lose all contents and
1210  * become black.  When a screen is deactivated the backing store is
1211  * optional.  When set backingPtr and bytesPerLine will be ignored.
1212  */
1213 #define SVGA_SCREEN_DEACTIVATE  (1 << 3)
1214 
1215 /*
1216  * Added with SVGA_FIFO_CAP_SCREEN_OBJECT_2.  When this flag is set
1217  * the screen contents will be outputted as all black to the user
1218  * though the base layer contents is preserved.  The screen base layer
1219  * can still be read and written to like normal though the no visible
1220  * effect will be seen by the user.  When the flag is changed the
1221  * screen will be blanked or redrawn to the current contents as needed
1222  * without any extra commands from the driver.  This flag only has an
1223  * effect when the screen is not deactivated.
1224  */
1225 #define SVGA_SCREEN_BLANKING (1 << 4)
1226 
1227 typedef
1228 struct {
1229    uint32 structSize;   /* sizeof(SVGAScreenObject) */
1230    uint32 id;
1231    uint32 flags;
1232    struct {
1233       uint32 width;
1234       uint32 height;
1235    } size;
1236    struct {
1237       int32 x;
1238       int32 y;
1239    } root;
1240 
1241    /*
1242     * Added and required by SVGA_FIFO_CAP_SCREEN_OBJECT_2, optional
1243     * with SVGA_FIFO_CAP_SCREEN_OBJECT.
1244     */
1245    SVGAGuestImage backingStore;
1246 
1247    /*
1248     * The cloneCount field is treated as a hint from the guest that
1249     * the user wants this display to be cloned, cloneCount times.
1250     *
1251     * A value of zero means no cloning should happen.
1252     */
1253    uint32 cloneCount;
1254 } SVGAScreenObject;
1255 
1256 
1257 /*
1258  *  Commands in the command FIFO:
1259  *
1260  *  Command IDs defined below are used for the traditional 2D FIFO
1261  *  communication (not all commands are available for all versions of the
1262  *  SVGA FIFO protocol).
1263  *
1264  *  Note the holes in the command ID numbers: These commands have been
1265  *  deprecated, and the old IDs must not be reused.
1266  *
1267  *  Command IDs from 1000 to 2999 are reserved for use by the SVGA3D
1268  *  protocol.
1269  *
1270  *  Each command's parameters are described by the comments and
1271  *  structs below.
1272  */
1273 
1274 typedef enum {
1275    SVGA_CMD_INVALID_CMD           = 0,
1276    SVGA_CMD_UPDATE                = 1,
1277    SVGA_CMD_RECT_COPY             = 3,
1278    SVGA_CMD_RECT_ROP_COPY         = 14,
1279    SVGA_CMD_DEFINE_CURSOR         = 19,
1280    SVGA_CMD_DEFINE_ALPHA_CURSOR   = 22,
1281    SVGA_CMD_UPDATE_VERBOSE        = 25,
1282    SVGA_CMD_FRONT_ROP_FILL        = 29,
1283    SVGA_CMD_FENCE                 = 30,
1284    SVGA_CMD_ESCAPE                = 33,
1285    SVGA_CMD_DEFINE_SCREEN         = 34,
1286    SVGA_CMD_DESTROY_SCREEN        = 35,
1287    SVGA_CMD_DEFINE_GMRFB          = 36,
1288    SVGA_CMD_BLIT_GMRFB_TO_SCREEN  = 37,
1289    SVGA_CMD_BLIT_SCREEN_TO_GMRFB  = 38,
1290    SVGA_CMD_ANNOTATION_FILL       = 39,
1291    SVGA_CMD_ANNOTATION_COPY       = 40,
1292    SVGA_CMD_DEFINE_GMR2           = 41,
1293    SVGA_CMD_REMAP_GMR2            = 42,
1294    SVGA_CMD_DEAD                  = 43,
1295    SVGA_CMD_DEAD_2                = 44,
1296    SVGA_CMD_NOP                   = 45,
1297    SVGA_CMD_NOP_ERROR             = 46,
1298    SVGA_CMD_MAX
1299 } SVGAFifoCmdId;
1300 
1301 #define SVGA_CMD_MAX_DATASIZE       (256 * 1024)
1302 #define SVGA_CMD_MAX_ARGS           64
1303 #define SVGA_CB_MAX_COMMAND_SIZE (32 * 1024) // 32 KB
1304 
1305 
1306 /*
1307  * SVGA_CMD_UPDATE --
1308  *
1309  *    This is a DMA transfer which copies from the Guest Framebuffer
1310  *    (GFB) at BAR1 + SVGA_REG_FB_OFFSET to any screens which
1311  *    intersect with the provided virtual rectangle.
1312  *
1313  *    This command does not support using arbitrary guest memory as a
1314  *    data source- it only works with the pre-defined GFB memory.
1315  *    This command also does not support signed virtual coordinates.
1316  *    If you have defined screens (using SVGA_CMD_DEFINE_SCREEN) with
1317  *    negative root x/y coordinates, the negative portion of those
1318  *    screens will not be reachable by this command.
1319  *
1320  *    This command is not necessary when using framebuffer
1321  *    traces. Traces are automatically enabled if the SVGA FIFO is
1322  *    disabled, and you may explicitly enable/disable traces using
1323  *    SVGA_REG_TRACES. With traces enabled, any write to the GFB will
1324  *    automatically act as if a subsequent SVGA_CMD_UPDATE was issued.
1325  *
1326  *    Traces and SVGA_CMD_UPDATE are the only supported ways to render
1327  *    pseudocolor screen updates. The newer Screen Object commands
1328  *    only support true color formats.
1329  *
1330  * Availability:
1331  *    Always available.
1332  */
1333 
1334 typedef
1335 struct {
1336    uint32 x;
1337    uint32 y;
1338    uint32 width;
1339    uint32 height;
1340 } SVGAFifoCmdUpdate;
1341 
1342 
1343 /*
1344  * SVGA_CMD_RECT_COPY --
1345  *
1346  *    Perform a rectangular DMA transfer from one area of the GFB to
1347  *    another, and copy the result to any screens which intersect it.
1348  *
1349  * Availability:
1350  *    SVGA_CAP_RECT_COPY
1351  */
1352 
1353 typedef
1354 struct {
1355    uint32 srcX;
1356    uint32 srcY;
1357    uint32 destX;
1358    uint32 destY;
1359    uint32 width;
1360    uint32 height;
1361 } SVGAFifoCmdRectCopy;
1362 
1363 
1364 /*
1365  * SVGA_CMD_RECT_ROP_COPY --
1366  *
1367  *    Perform a rectangular DMA transfer from one area of the GFB to
1368  *    another, and copy the result to any screens which intersect it.
1369  *    The value of ROP may only be SVGA_ROP_COPY, and this command is
1370  *    only supported for backwards compatibility reasons.
1371  *
1372  * Availability:
1373  *    SVGA_CAP_RECT_COPY
1374  */
1375 
1376 typedef
1377 struct {
1378    uint32 srcX;
1379    uint32 srcY;
1380    uint32 destX;
1381    uint32 destY;
1382    uint32 width;
1383    uint32 height;
1384    uint32 rop;
1385 } SVGAFifoCmdRectRopCopy;
1386 
1387 
1388 /*
1389  * SVGA_CMD_DEFINE_CURSOR --
1390  *
1391  *    Provide a new cursor image, as an AND/XOR mask.
1392  *
1393  *    The recommended way to position the cursor overlay is by using
1394  *    the SVGA_FIFO_CURSOR_* registers, supported by the
1395  *    SVGA_FIFO_CAP_CURSOR_BYPASS_3 capability.
1396  *
1397  * Availability:
1398  *    SVGA_CAP_CURSOR
1399  */
1400 
1401 typedef
1402 struct {
1403    uint32 id;             /* Reserved, must be zero. */
1404    uint32 hotspotX;
1405    uint32 hotspotY;
1406    uint32 width;
1407    uint32 height;
1408    uint32 andMaskDepth;   /* Value must be 1 or equal to BITS_PER_PIXEL */
1409    uint32 xorMaskDepth;   /* Value must be 1 or equal to BITS_PER_PIXEL */
1410    /*
1411     * Followed by scanline data for AND mask, then XOR mask.
1412     * Each scanline is padded to a 32-bit boundary.
1413    */
1414 } SVGAFifoCmdDefineCursor;
1415 
1416 
1417 /*
1418  * SVGA_CMD_DEFINE_ALPHA_CURSOR --
1419  *
1420  *    Provide a new cursor image, in 32-bit BGRA format.
1421  *
1422  *    The recommended way to position the cursor overlay is by using
1423  *    the SVGA_FIFO_CURSOR_* registers, supported by the
1424  *    SVGA_FIFO_CAP_CURSOR_BYPASS_3 capability.
1425  *
1426  * Availability:
1427  *    SVGA_CAP_ALPHA_CURSOR
1428  */
1429 
1430 typedef
1431 struct {
1432    uint32 id;             /* Reserved, must be zero. */
1433    uint32 hotspotX;
1434    uint32 hotspotY;
1435    uint32 width;
1436    uint32 height;
1437    /* Followed by scanline data */
1438 } SVGAFifoCmdDefineAlphaCursor;
1439 
1440 
1441 /*
1442  * SVGA_CMD_UPDATE_VERBOSE --
1443  *
1444  *    Just like SVGA_CMD_UPDATE, but also provide a per-rectangle
1445  *    'reason' value, an opaque cookie which is used by internal
1446  *    debugging tools. Third party drivers should not use this
1447  *    command.
1448  *
1449  * Availability:
1450  *    SVGA_CAP_EXTENDED_FIFO
1451  */
1452 
1453 typedef
1454 struct {
1455    uint32 x;
1456    uint32 y;
1457    uint32 width;
1458    uint32 height;
1459    uint32 reason;
1460 } SVGAFifoCmdUpdateVerbose;
1461 
1462 
1463 /*
1464  * SVGA_CMD_FRONT_ROP_FILL --
1465  *
1466  *    This is a hint which tells the SVGA device that the driver has
1467  *    just filled a rectangular region of the GFB with a solid
1468  *    color. Instead of reading these pixels from the GFB, the device
1469  *    can assume that they all equal 'color'. This is primarily used
1470  *    for remote desktop protocols.
1471  *
1472  * Availability:
1473  *    SVGA_FIFO_CAP_ACCELFRONT
1474  */
1475 
1476 #define  SVGA_ROP_COPY                    0x03
1477 
1478 typedef
1479 struct {
1480    uint32 color;     /* In the same format as the GFB */
1481    uint32 x;
1482    uint32 y;
1483    uint32 width;
1484    uint32 height;
1485    uint32 rop;       /* Must be SVGA_ROP_COPY */
1486 } SVGAFifoCmdFrontRopFill;
1487 
1488 
1489 /*
1490  * SVGA_CMD_FENCE --
1491  *
1492  *    Insert a synchronization fence.  When the SVGA device reaches
1493  *    this command, it will copy the 'fence' value into the
1494  *    SVGA_FIFO_FENCE register. It will also compare the fence against
1495  *    SVGA_FIFO_FENCE_GOAL. If the fence matches the goal and the
1496  *    SVGA_IRQFLAG_FENCE_GOAL interrupt is enabled, the device will
1497  *    raise this interrupt.
1498  *
1499  * Availability:
1500  *    SVGA_FIFO_FENCE for this command,
1501  *    SVGA_CAP_IRQMASK for SVGA_FIFO_FENCE_GOAL.
1502  */
1503 
1504 typedef
1505 struct {
1506    uint32 fence;
1507 } SVGAFifoCmdFence;
1508 
1509 
1510 /*
1511  * SVGA_CMD_ESCAPE --
1512  *
1513  *    Send an extended or vendor-specific variable length command.
1514  *    This is used for video overlay, third party plugins, and
1515  *    internal debugging tools. See svga_escape.h
1516  *
1517  * Availability:
1518  *    SVGA_FIFO_CAP_ESCAPE
1519  */
1520 
1521 typedef
1522 struct {
1523    uint32 nsid;
1524    uint32 size;
1525    /* followed by 'size' bytes of data */
1526 } SVGAFifoCmdEscape;
1527 
1528 
1529 /*
1530  * SVGA_CMD_DEFINE_SCREEN --
1531  *
1532  *    Define or redefine an SVGAScreenObject. See the description of
1533  *    SVGAScreenObject above.  The video driver is responsible for
1534  *    generating new screen IDs. They should be small positive
1535  *    integers. The virtual device will have an implementation
1536  *    specific upper limit on the number of screen IDs
1537  *    supported. Drivers are responsible for recycling IDs. The first
1538  *    valid ID is zero.
1539  *
1540  *    - Interaction with other registers:
1541  *
1542  *    For backwards compatibility, when the GFB mode registers (WIDTH,
1543  *    HEIGHT, PITCHLOCK, BITS_PER_PIXEL) are modified, the SVGA device
1544  *    deletes all screens other than screen #0, and redefines screen
1545  *    #0 according to the specified mode. Drivers that use
1546  *    SVGA_CMD_DEFINE_SCREEN should destroy or redefine screen #0.
1547  *
1548  *    If you use screen objects, do not use the legacy multi-mon
1549  *    registers (SVGA_REG_NUM_GUEST_DISPLAYS, SVGA_REG_DISPLAY_*).
1550  *
1551  * Availability:
1552  *    SVGA_FIFO_CAP_SCREEN_OBJECT or SVGA_FIFO_CAP_SCREEN_OBJECT_2
1553  */
1554 
1555 typedef
1556 struct {
1557    SVGAScreenObject screen;   /* Variable-length according to version */
1558 } SVGAFifoCmdDefineScreen;
1559 
1560 
1561 /*
1562  * SVGA_CMD_DESTROY_SCREEN --
1563  *
1564  *    Destroy an SVGAScreenObject. Its ID is immediately available for
1565  *    re-use.
1566  *
1567  * Availability:
1568  *    SVGA_FIFO_CAP_SCREEN_OBJECT or SVGA_FIFO_CAP_SCREEN_OBJECT_2
1569  */
1570 
1571 typedef
1572 struct {
1573    uint32 screenId;
1574 } SVGAFifoCmdDestroyScreen;
1575 
1576 
1577 /*
1578  * SVGA_CMD_DEFINE_GMRFB --
1579  *
1580  *    This command sets a piece of SVGA device state called the
1581  *    Guest Memory Region Framebuffer, or GMRFB. The GMRFB is a
1582  *    piece of light-weight state which identifies the location and
1583  *    format of an image in guest memory or in BAR1. The GMRFB has
1584  *    an arbitrary size, and it doesn't need to match the geometry
1585  *    of the GFB or any screen object.
1586  *
1587  *    The GMRFB can be redefined as often as you like. You could
1588  *    always use the same GMRFB, you could redefine it before
1589  *    rendering from a different guest screen, or you could even
1590  *    redefine it before every blit.
1591  *
1592  *    There are multiple ways to use this command. The simplest way is
1593  *    to use it to move the framebuffer either to elsewhere in the GFB
1594  *    (BAR1) memory region, or to a user-defined GMR. This lets a
1595  *    driver use a framebuffer allocated entirely out of normal system
1596  *    memory, which we encourage.
1597  *
1598  *    Another way to use this command is to set up a ring buffer of
1599  *    updates in GFB memory. If a driver wants to ensure that no
1600  *    frames are skipped by the SVGA device, it is important that the
1601  *    driver not modify the source data for a blit until the device is
1602  *    done processing the command. One efficient way to accomplish
1603  *    this is to use a ring of small DMA buffers. Each buffer is used
1604  *    for one blit, then we move on to the next buffer in the
1605  *    ring. The FENCE mechanism is used to protect each buffer from
1606  *    re-use until the device is finished with that buffer's
1607  *    corresponding blit.
1608  *
1609  *    This command does not affect the meaning of SVGA_CMD_UPDATE.
1610  *    UPDATEs always occur from the legacy GFB memory area. This
1611  *    command has no support for pseudocolor GMRFBs. Currently only
1612  *    true-color 15, 16, and 24-bit depths are supported. Future
1613  *    devices may expose capabilities for additional framebuffer
1614  *    formats.
1615  *
1616  *    The default GMRFB value is undefined. Drivers must always send
1617  *    this command at least once before performing any blit from the
1618  *    GMRFB.
1619  *
1620  * Availability:
1621  *    SVGA_FIFO_CAP_SCREEN_OBJECT or SVGA_FIFO_CAP_SCREEN_OBJECT_2
1622  */
1623 
1624 typedef
1625 struct {
1626    SVGAGuestPtr        ptr;
1627    uint32              bytesPerLine;
1628    SVGAGMRImageFormat  format;
1629 } SVGAFifoCmdDefineGMRFB;
1630 
1631 
1632 /*
1633  * SVGA_CMD_BLIT_GMRFB_TO_SCREEN --
1634  *
1635  *    This is a guest-to-host blit. It performs a DMA operation to
1636  *    copy a rectangular region of pixels from the current GMRFB to
1637  *    one or more Screen Objects.
1638  *
1639  *    The destination coordinate may be specified relative to a
1640  *    screen's origin (if a screen ID is specified) or relative to the
1641  *    virtual coordinate system's origin (if the screen ID is
1642  *    SVGA_ID_INVALID). The actual destination may span zero or more
1643  *    screens, in the case of a virtual destination rect or a rect
1644  *    which extends off the edge of the specified screen.
1645  *
1646  *    This command writes to the screen's "base layer": the underlying
1647  *    framebuffer which exists below any cursor or video overlays. No
1648  *    action is necessary to explicitly hide or update any overlays
1649  *    which exist on top of the updated region.
1650  *
1651  *    The SVGA device is guaranteed to finish reading from the GMRFB
1652  *    by the time any subsequent FENCE commands are reached.
1653  *
1654  *    This command consumes an annotation. See the
1655  *    SVGA_CMD_ANNOTATION_* commands for details.
1656  *
1657  * Availability:
1658  *    SVGA_FIFO_CAP_SCREEN_OBJECT or SVGA_FIFO_CAP_SCREEN_OBJECT_2
1659  */
1660 
1661 typedef
1662 struct {
1663    SVGASignedPoint  srcOrigin;
1664    SVGASignedRect   destRect;
1665    uint32           destScreenId;
1666 } SVGAFifoCmdBlitGMRFBToScreen;
1667 
1668 
1669 /*
1670  * SVGA_CMD_BLIT_SCREEN_TO_GMRFB --
1671  *
1672  *    This is a host-to-guest blit. It performs a DMA operation to
1673  *    copy a rectangular region of pixels from a single Screen Object
1674  *    back to the current GMRFB.
1675  *
1676  *    Usage note: This command should be used rarely. It will
1677  *    typically be inefficient, but it is necessary for some types of
1678  *    synchronization between 3D (GPU) and 2D (CPU) rendering into
1679  *    overlapping areas of a screen.
1680  *
1681  *    The source coordinate is specified relative to a screen's
1682  *    origin. The provided screen ID must be valid. If any parameters
1683  *    are invalid, the resulting pixel values are undefined.
1684  *
1685  *    This command reads the screen's "base layer". Overlays like
1686  *    video and cursor are not included, but any data which was sent
1687  *    using a blit-to-screen primitive will be available, no matter
1688  *    whether the data's original source was the GMRFB or the 3D
1689  *    acceleration hardware.
1690  *
1691  *    Note that our guest-to-host blits and host-to-guest blits aren't
1692  *    symmetric in their current implementation. While the parameters
1693  *    are identical, host-to-guest blits are a lot less featureful.
1694  *    They do not support clipping: If the source parameters don't
1695  *    fully fit within a screen, the blit fails. They must originate
1696  *    from exactly one screen. Virtual coordinates are not directly
1697  *    supported.
1698  *
1699  *    Host-to-guest blits do support the same set of GMRFB formats
1700  *    offered by guest-to-host blits.
1701  *
1702  *    The SVGA device is guaranteed to finish writing to the GMRFB by
1703  *    the time any subsequent FENCE commands are reached.
1704  *
1705  * Availability:
1706  *    SVGA_FIFO_CAP_SCREEN_OBJECT or SVGA_FIFO_CAP_SCREEN_OBJECT_2
1707  */
1708 
1709 typedef
1710 struct {
1711    SVGASignedPoint  destOrigin;
1712    SVGASignedRect   srcRect;
1713    uint32           srcScreenId;
1714 } SVGAFifoCmdBlitScreenToGMRFB;
1715 
1716 
1717 /*
1718  * SVGA_CMD_ANNOTATION_FILL --
1719  *
1720  *    This is a blit annotation. This command stores a small piece of
1721  *    device state which is consumed by the next blit-to-screen
1722  *    command. The state is only cleared by commands which are
1723  *    specifically documented as consuming an annotation. Other
1724  *    commands (such as ESCAPEs for debugging) may intervene between
1725  *    the annotation and its associated blit.
1726  *
1727  *    This annotation is a promise about the contents of the next
1728  *    blit: The video driver is guaranteeing that all pixels in that
1729  *    blit will have the same value, specified here as a color in
1730  *    SVGAColorBGRX format.
1731  *
1732  *    The SVGA device can still render the blit correctly even if it
1733  *    ignores this annotation, but the annotation may allow it to
1734  *    perform the blit more efficiently, for example by ignoring the
1735  *    source data and performing a fill in hardware.
1736  *
1737  *    This annotation is most important for performance when the
1738  *    user's display is being remoted over a network connection.
1739  *
1740  * Availability:
1741  *    SVGA_FIFO_CAP_SCREEN_OBJECT or SVGA_FIFO_CAP_SCREEN_OBJECT_2
1742  */
1743 
1744 typedef
1745 struct {
1746    SVGAColorBGRX  color;
1747 } SVGAFifoCmdAnnotationFill;
1748 
1749 
1750 /*
1751  * SVGA_CMD_ANNOTATION_COPY --
1752  *
1753  *    This is a blit annotation. See SVGA_CMD_ANNOTATION_FILL for more
1754  *    information about annotations.
1755  *
1756  *    This annotation is a promise about the contents of the next
1757  *    blit: The video driver is guaranteeing that all pixels in that
1758  *    blit will have the same value as those which already exist at an
1759  *    identically-sized region on the same or a different screen.
1760  *
1761  *    Note that the source pixels for the COPY in this annotation are
1762  *    sampled before applying the annotation's associated blit. They
1763  *    are allowed to overlap with the blit's destination pixels.
1764  *
1765  *    The copy source rectangle is specified the same way as the blit
1766  *    destination: it can be a rectangle which spans zero or more
1767  *    screens, specified relative to either a screen or to the virtual
1768  *    coordinate system's origin. If the source rectangle includes
1769  *    pixels which are not from exactly one screen, the results are
1770  *    undefined.
1771  *
1772  * Availability:
1773  *    SVGA_FIFO_CAP_SCREEN_OBJECT or SVGA_FIFO_CAP_SCREEN_OBJECT_2
1774  */
1775 
1776 typedef
1777 struct {
1778    SVGASignedPoint  srcOrigin;
1779    uint32           srcScreenId;
1780 } SVGAFifoCmdAnnotationCopy;
1781 
1782 
1783 /*
1784  * SVGA_CMD_DEFINE_GMR2 --
1785  *
1786  *    Define guest memory region v2.  See the description of GMRs above.
1787  *
1788  * Availability:
1789  *    SVGA_CAP_GMR2
1790  */
1791 
1792 typedef
1793 struct {
1794    uint32 gmrId;
1795    uint32 numPages;
1796 } SVGAFifoCmdDefineGMR2;
1797 
1798 
1799 /*
1800  * SVGA_CMD_REMAP_GMR2 --
1801  *
1802  *    Remap guest memory region v2.  See the description of GMRs above.
1803  *
1804  *    This command allows guest to modify a portion of an existing GMR by
1805  *    invalidating it or reassigning it to different guest physical pages.
1806  *    The pages are identified by physical page number (PPN).  The pages
1807  *    are assumed to be pinned and valid for DMA operations.
1808  *
1809  *    Description of command flags:
1810  *
1811  *    SVGA_REMAP_GMR2_VIA_GMR: If enabled, references a PPN list in a GMR.
1812  *       The PPN list must not overlap with the remap region (this can be
1813  *       handled trivially by referencing a separate GMR).  If flag is
1814  *       disabled, PPN list is appended to SVGARemapGMR command.
1815  *
1816  *    SVGA_REMAP_GMR2_PPN64: If set, PPN list is in PPN64 format, otherwise
1817  *       it is in PPN32 format.
1818  *
1819  *    SVGA_REMAP_GMR2_SINGLE_PPN: If set, PPN list contains a single entry.
1820  *       A single PPN can be used to invalidate a portion of a GMR or
1821  *       map it to to a single guest scratch page.
1822  *
1823  * Availability:
1824  *    SVGA_CAP_GMR2
1825  */
1826 
1827 typedef enum {
1828    SVGA_REMAP_GMR2_PPN32         = 0,
1829    SVGA_REMAP_GMR2_VIA_GMR       = (1 << 0),
1830    SVGA_REMAP_GMR2_PPN64         = (1 << 1),
1831    SVGA_REMAP_GMR2_SINGLE_PPN    = (1 << 2),
1832 } SVGARemapGMR2Flags;
1833 
1834 typedef
1835 struct {
1836    uint32 gmrId;
1837    SVGARemapGMR2Flags flags;
1838    uint32 offsetPages; /* offset in pages to begin remap */
1839    uint32 numPages; /* number of pages to remap */
1840    /*
1841     * Followed by additional data depending on SVGARemapGMR2Flags.
1842     *
1843     * If flag SVGA_REMAP_GMR2_VIA_GMR is set, single SVGAGuestPtr follows.
1844     * Otherwise an array of page descriptors in PPN32 or PPN64 format
1845     * (according to flag SVGA_REMAP_GMR2_PPN64) follows.  If flag
1846     * SVGA_REMAP_GMR2_SINGLE_PPN is set, array contains a single entry.
1847     */
1848 } SVGAFifoCmdRemapGMR2;
1849 
1850 
1851 /*
1852  * Size of SVGA device memory such as frame buffer and FIFO.
1853  */
1854 #define SVGA_VRAM_MIN_SIZE             (4 * 640 * 480) /* bytes */
1855 #define SVGA_VRAM_MIN_SIZE_3D       (16 * 1024 * 1024)
1856 #define SVGA_VRAM_MAX_SIZE         (128 * 1024 * 1024)
1857 #define SVGA_MEMORY_SIZE_MAX      (1024 * 1024 * 1024)
1858 #define SVGA_FIFO_SIZE_MAX           (2 * 1024 * 1024)
1859 #define SVGA_GRAPHICS_MEMORY_KB_MIN       (32 * 1024)
1860 #define SVGA_GRAPHICS_MEMORY_KB_MAX       (2 * 1024 * 1024)
1861 #define SVGA_GRAPHICS_MEMORY_KB_DEFAULT   (256 * 1024)
1862 
1863 #define SVGA_VRAM_SIZE_W2K          (64 * 1024 * 1024) /* 64 MB */
1864 
1865 /*
1866  * To simplify autoDetect display configuration, support a minimum of
1867  * two 1920x1200 monitors, 32bpp, side-by-side, optionally rotated:
1868  *   numDisplays = 2
1869  *   maxWidth = numDisplay * 1920 = 3840
1870  *   maxHeight = rotated width of single monitor = 1920
1871  *   vramSize = maxWidth * maxHeight * 4 = 29491200
1872  */
1873 #define SVGA_VRAM_SIZE_AUTODETECT   (32 * 1024 * 1024)
1874 
1875 #if defined(VMX86_SERVER)
1876 #define SVGA_VRAM_SIZE               (4 * 1024 * 1024)
1877 #define SVGA_VRAM_SIZE_3D           (64 * 1024 * 1024)
1878 #define SVGA_FIFO_SIZE                    (256 * 1024)
1879 #define SVGA_FIFO_SIZE_3D                 (516 * 1024)
1880 #define SVGA_MEMORY_SIZE_DEFAULT   (160 * 1024 * 1024)
1881 #define SVGA_AUTODETECT_DEFAULT                  FALSE
1882 #else
1883 #define SVGA_VRAM_SIZE              (16 * 1024 * 1024)
1884 #define SVGA_VRAM_SIZE_3D           SVGA_VRAM_MAX_SIZE
1885 #define SVGA_FIFO_SIZE               (2 * 1024 * 1024)
1886 #define SVGA_FIFO_SIZE_3D               SVGA_FIFO_SIZE
1887 #define SVGA_MEMORY_SIZE_DEFAULT   (768 * 1024 * 1024)
1888 #define SVGA_AUTODETECT_DEFAULT                   TRUE
1889 #endif
1890 
1891 #endif
1892