2 * Copyright (C) 2006-2016 Oracle Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
24 #ifndef __VBOXVIDEO_H__
25 #define __VBOXVIDEO_H__
28 * This should be in sync with monitorCount <xsd:maxInclusive value="64"/> in
29 * src/VBox/Main/xml/VirtualBox-settings-common.xsd
31 #define VBOX_VIDEO_MAX_SCREENS 64
34 * The last 4096 bytes of the guest VRAM contains the generic info for all
35 * DualView chunks: sizes and offsets of chunks. This is filled by miniport.
37 * Last 4096 bytes of each chunk contain chunk specific data: framebuffer info,
38 * etc. This is used exclusively by the corresponding instance of a display
42 * Last 4096 bytes - Adapter information area.
43 * 4096 bytes aligned miniport heap (value specified in the config rouded up).
44 * Slack - what left after dividing the VRAM.
45 * 4096 bytes aligned framebuffers:
46 * last 4096 bytes of each framebuffer is the display information area.
48 * The Virtual Graphics Adapter information in the guest VRAM is stored by the
49 * guest video driver using structures prepended by VBOXVIDEOINFOHDR.
51 * When the guest driver writes dword 0 to the VBE_DISPI_INDEX_VBOX_VIDEO
52 * the host starts to process the info. The first element at the start of
53 * the 4096 bytes region should be normally be a LINK that points to
54 * actual information chain. That way the guest driver can have some
55 * fixed layout of the information memory block and just rewrite
56 * the link to point to relevant memory chain.
58 * The processing stops at the END element.
60 * The host can access the memory only when the port IO is processed.
61 * All data that will be needed later must be copied from these 4096 bytes.
62 * But other VRAM can be used by host until the mode is disabled.
64 * The guest driver writes dword 0xffffffff to the VBE_DISPI_INDEX_VBOX_VIDEO
65 * to disable the mode.
67 * VBE_DISPI_INDEX_VBOX_VIDEO is used to read the configuration information
68 * from the host and issue commands to the host.
70 * The guest writes the VBE_DISPI_INDEX_VBOX_VIDEO index register, the the
71 * following operations with the VBE data register can be performed:
74 * write 16 bit value NOP
75 * read 16 bit value count of monitors
76 * write 32 bit value set the vbox cmd value and the cmd processed by the host
77 * read 32 bit value result of the last vbox command is returned
81 * VBVA command header.
83 * @todo Where does this fit in?
86 /** Coordinates of affected rectangle. */
93 /** @name VBVA ring defines.
95 * The VBVA ring buffer is suitable for transferring large (< 2GB) amount of
96 * data. For example big bitmaps which do not fit to the buffer.
98 * Guest starts writing to the buffer by initializing a record entry in the
99 * records queue. VBVA_F_RECORD_PARTIAL indicates that the record is being
100 * written. As data is written to the ring buffer, the guest increases
103 * The host reads the records on flushes and processes all completed records.
104 * When host encounters situation when only a partial record presents and
105 * len_and_flags & ~VBVA_F_RECORD_PARTIAL >= VBVA_RING_BUFFER_SIZE -
106 * VBVA_RING_BUFFER_THRESHOLD, the host fetched all record data and updates
107 * data_offset. After that on each flush the host continues fetching the data
108 * until the record is completed.
111 #define VBVA_RING_BUFFER_SIZE (4194304 - 1024)
112 #define VBVA_RING_BUFFER_THRESHOLD (4096)
114 #define VBVA_MAX_RECORDS (64)
116 #define VBVA_F_MODE_ENABLED 0x00000001u
117 #define VBVA_F_MODE_VRDP 0x00000002u
118 #define VBVA_F_MODE_VRDP_RESET 0x00000004u
119 #define VBVA_F_MODE_VRDP_ORDER_MASK 0x00000008u
121 #define VBVA_F_STATE_PROCESSING 0x00010000u
123 #define VBVA_F_RECORD_PARTIAL 0x80000000u
129 /** The length of the record. Changed by guest. */
134 * The minimum HGSMI heap size is PAGE_SIZE (4096 bytes) and is a restriction of
135 * the runtime heapsimple API. Use minimum 2 pages here, because the info area
136 * also may contain other data (for example hgsmi_host_flags structure).
138 #define VBVA_ADAPTER_INFORMATION_SIZE 65536
139 #define VBVA_MIN_BUFFER_SIZE 65536
141 /* The value for port IO to let the adapter to interpret the adapter memory. */
142 #define VBOX_VIDEO_DISABLE_ADAPTER_MEMORY 0xFFFFFFFF
144 /* The value for port IO to let the adapter to interpret the adapter memory. */
145 #define VBOX_VIDEO_INTERPRET_ADAPTER_MEMORY 0x00000000
147 /* The value for port IO to let the adapter to interpret the display memory.
148 * The display number is encoded in low 16 bits.
150 #define VBOX_VIDEO_INTERPRET_DISPLAY_MEMORY_BASE 0x00010000
152 struct vbva_host_flags
{
154 u32 supported_orders
;
158 struct vbva_host_flags host_flags
;
160 /* The offset where the data start in the buffer. */
162 /* The offset where next data must be placed in the buffer. */
165 /* The queue of record descriptions. */
166 struct vbva_record records
[VBVA_MAX_RECORDS
];
167 u32 record_first_index
;
168 u32 record_free_index
;
170 /* Space to leave free when large partial records are transferred. */
171 u32 partial_write_tresh
;
174 /* variable size for the rest of the vbva_buffer area in VRAM. */
178 #define VBVA_MAX_RECORD_SIZE (128 * 1024 * 1024)
180 /* guest->host commands */
181 #define VBVA_QUERY_CONF32 1
182 #define VBVA_SET_CONF32 2
183 #define VBVA_INFO_VIEW 3
184 #define VBVA_INFO_HEAP 4
186 #define VBVA_INFO_SCREEN 6
187 #define VBVA_ENABLE 7
188 #define VBVA_MOUSE_POINTER_SHAPE 8
189 /* informs host about HGSMI caps. see vbva_caps below */
190 #define VBVA_INFO_CAPS 12
191 /* configures scanline, see VBVASCANLINECFG below */
192 #define VBVA_SCANLINE_CFG 13
193 /* requests scanline info, see VBVASCANLINEINFO below */
194 #define VBVA_SCANLINE_INFO 14
195 /* inform host about VBVA Command submission */
196 #define VBVA_CMDVBVA_SUBMIT 16
197 /* inform host about VBVA Command submission */
198 #define VBVA_CMDVBVA_FLUSH 17
199 /* G->H DMA command */
200 #define VBVA_CMDVBVA_CTL 18
201 /* Query most recent mode hints sent */
202 #define VBVA_QUERY_MODE_HINTS 19
204 * Report the guest virtual desktop position and size for mapping host and
205 * guest pointer positions.
207 #define VBVA_REPORT_INPUT_MAPPING 20
208 /** Report the guest cursor position and query the host position. */
209 #define VBVA_CURSOR_POSITION 21
211 /* host->guest commands */
212 #define VBVAHG_EVENT 1
213 #define VBVAHG_DISPLAY_CUSTOM 2
215 /* vbva_conf32::index */
216 #define VBOX_VBVA_CONF32_MONITOR_COUNT 0
217 #define VBOX_VBVA_CONF32_HOST_HEAP_SIZE 1
219 * Returns VINF_SUCCESS if the host can report mode hints via VBVA.
220 * Set value to VERR_NOT_SUPPORTED before calling.
222 #define VBOX_VBVA_CONF32_MODE_HINT_REPORTING 2
224 * Returns VINF_SUCCESS if the host can report guest cursor enabled status via
225 * VBVA. Set value to VERR_NOT_SUPPORTED before calling.
227 #define VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING 3
229 * Returns the currently available host cursor capabilities. Available if
230 * vbva_conf32::VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING returns success.
231 * @see VMMDevReqMouseStatus::mouseFeatures.
233 #define VBOX_VBVA_CONF32_CURSOR_CAPABILITIES 4
234 /** Returns the supported flags in vbva_infoscreen::flags. */
235 #define VBOX_VBVA_CONF32_SCREEN_FLAGS 5
236 /** Returns the max size of VBVA record. */
237 #define VBOX_VBVA_CONF32_MAX_RECORD_SIZE 6
244 /** Reserved for historical reasons. */
245 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED0 BIT(0)
247 * Guest cursor capability: can the host show a hardware cursor at the host
250 #define VBOX_VBVA_CURSOR_CAPABILITY_HARDWARE BIT(1)
251 /** Reserved for historical reasons. */
252 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED2 BIT(2)
253 /** Reserved for historical reasons. Must always be unset. */
254 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED3 BIT(3)
255 /** Reserved for historical reasons. */
256 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED4 BIT(4)
257 /** Reserved for historical reasons. */
258 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED5 BIT(5)
260 struct vbva_infoview
{
261 /* Index of the screen, assigned by the guest. */
264 /* The screen offset in VRAM, the framebuffer starts here. */
267 /* The size of the VRAM memory that can be used for the view. */
270 /* The recommended maximum size of the VRAM memory for the screen. */
278 /* vbva_infoscreen::flags */
279 #define VBVA_SCREEN_F_NONE 0x0000
280 #define VBVA_SCREEN_F_ACTIVE 0x0001
282 * The virtual monitor has been disabled by the guest and should be removed
283 * by the host and ignored for purposes of pointer position calculation.
285 #define VBVA_SCREEN_F_DISABLED 0x0002
287 * The virtual monitor has been blanked by the guest and should be blacked
288 * out by the host using width, height, etc values from the vbva_infoscreen
291 #define VBVA_SCREEN_F_BLANK 0x0004
293 * The virtual monitor has been blanked by the guest and should be blacked
294 * out by the host using the previous mode values for width. height, etc.
296 #define VBVA_SCREEN_F_BLANK2 0x0008
298 struct vbva_infoscreen
{
299 /* Which view contains the screen. */
302 /* Physical X origin relative to the primary screen. */
305 /* Physical Y origin relative to the primary screen. */
308 /* Offset of visible framebuffer relative to the framebuffer start. */
311 /* The scan line size in bytes. */
314 /* Width of the screen. */
317 /* Height of the screen. */
323 /* VBVA_SCREEN_F_* */
327 /* vbva_enable::flags */
328 #define VBVA_F_NONE 0x00000000
329 #define VBVA_F_ENABLE 0x00000001
330 #define VBVA_F_DISABLE 0x00000002
331 /* extended VBVA to be used with WDDM */
332 #define VBVA_F_EXTENDED 0x00000004
333 /* vbva offset is absolute VRAM offset */
334 #define VBVA_F_ABSOFFSET 0x00000008
342 struct vbva_enable_ex
{
343 struct vbva_enable base
;
347 struct vbva_mouse_pointer_shape
{
348 /* The host result. */
351 /* VBOX_MOUSE_POINTER_* bit flags. */
354 /* X coordinate of the hot spot. */
357 /* Y coordinate of the hot spot. */
360 /* Width of the pointer in pixels. */
363 /* Height of the pointer in scanlines. */
369 * The data consists of 1 bpp AND mask followed by 32 bpp XOR (color)
372 * For pointers without alpha channel the XOR mask pixels are 32 bit
373 * values: (lsb)BGR0(msb). For pointers with alpha channel the XOR mask
374 * consists of (lsb)BGRA(msb) 32 bit values.
376 * Guest driver must create the AND mask for pointers with alpha chan.,
377 * so if host does not support alpha, the pointer could be displayed as
378 * a normal color pointer. The AND mask can be constructed from alpha
379 * values. For example alpha value >= 0xf0 means bit 0 in the AND mask.
381 * The AND mask is 1 bpp bitmap with byte aligned scanlines. Size of AND
382 * mask, therefore, is and_len = (width + 7) / 8 * height. The padding
383 * bits at the end of any scanline are undefined.
385 * The XOR mask follows the AND mask on the next 4 bytes aligned offset:
386 * u8 *xor = and + (and_len + 3) & ~3
387 * Bytes in the gap between the AND and the XOR mask are undefined.
388 * XOR mask scanlines have no gap between them and size of XOR mask is:
389 * xor_len = width * 4 * height.
392 * Preallocate 4 bytes for accessing actual data as p->data.
398 * @name vbva_mouse_pointer_shape::flags
399 * @note The VBOX_MOUSE_POINTER_* flags are used in the guest video driver,
400 * values must be <= 0x8000 and must not be changed. (try make more sense
405 /** pointer is visible */
406 #define VBOX_MOUSE_POINTER_VISIBLE 0x0001
407 /** pointer has alpha channel */
408 #define VBOX_MOUSE_POINTER_ALPHA 0x0002
409 /** pointerData contains new pointer shape */
410 #define VBOX_MOUSE_POINTER_SHAPE 0x0004
415 * The guest driver can handle asynch guest cmd completion by reading the
416 * command offset from io port.
418 #define VBVACAPS_COMPLETEGCMD_BY_IOREAD 0x00000001
419 /* the guest driver can handle video adapter IRQs */
420 #define VBVACAPS_IRQ 0x00000002
421 /** The guest can read video mode hints sent via VBVA. */
422 #define VBVACAPS_VIDEO_MODE_HINTS 0x00000004
423 /** The guest can switch to a software cursor on demand. */
424 #define VBVACAPS_DISABLE_CURSOR_INTEGRATION 0x00000008
425 /** The guest does not depend on host handling the VBE registers. */
426 #define VBVACAPS_USE_VBVA_ONLY 0x00000010
433 /** Query the most recent mode hints received from the host. */
434 struct vbva_query_mode_hints
{
435 /** The maximum number of screens to return hints for. */
436 u16 hints_queried_count
;
437 /** The size of the mode hint structures directly following this one. */
438 u16 hint_structure_guest_size
;
439 /** Return code for the operation. Initialise to VERR_NOT_SUPPORTED. */
444 * Structure in which a mode hint is returned. The guest allocates an array
445 * of these immediately after the vbva_query_mode_hints structure.
446 * To accommodate future extensions, the vbva_query_mode_hints structure
447 * specifies the size of the vbva_modehint structures allocated by the guest,
448 * and the host only fills out structure elements which fit into that size. The
449 * host should fill any unused members (e.g. dx, dy) or structure space on the
450 * end with ~0. The whole structure can legally be set to ~0 to skip a screen.
452 struct vbva_modehint
{
456 u32 bpp
; /* Which has never been used... */
458 u32 dx
; /**< X offset into the virtual frame-buffer. */
459 u32 dy
; /**< Y offset into the virtual frame-buffer. */
460 u32 enabled
; /* Not flags. Add new members for new flags. */
463 #define VBVAMODEHINT_MAGIC 0x0801add9u
466 * Report the rectangle relative to which absolute pointer events should be
467 * expressed. This information remains valid until the next VBVA resize event
468 * for any screen, at which time it is reset to the bounding rectangle of all
469 * virtual screens and must be re-set.
470 * @see VBVA_REPORT_INPUT_MAPPING.
472 struct vbva_report_input_mapping
{
473 s32 x
; /**< Upper left X co-ordinate relative to the first screen. */
474 s32 y
; /**< Upper left Y co-ordinate relative to the first screen. */
475 u32 cx
; /**< Rectangle width. */
476 u32 cy
; /**< Rectangle height. */
480 * Report the guest cursor position and query the host one. The host may wish
481 * to use the guest information to re-position its own cursor (though this is
482 * currently unlikely).
483 * @see VBVA_CURSOR_POSITION
485 struct vbva_cursor_position
{
486 u32 report_position
; /**< Are we reporting a position? */
487 u32 x
; /**< Guest cursor X position */
488 u32 y
; /**< Guest cursor Y position */