1 /* SPDX-License-Identifier: MIT */ 2 /* Copyright (C) 2006-2016 Oracle Corporation */ 3 4 #ifndef __VBOXVIDEO_H__ 5 #define __VBOXVIDEO_H__ 6 7 #define VBOX_VIDEO_MAX_SCREENS 64 8 9 /* 10 * The last 4096 bytes of the guest VRAM contains the generic info for all 11 * DualView chunks: sizes and offsets of chunks. This is filled by miniport. 12 * 13 * Last 4096 bytes of each chunk contain chunk specific data: framebuffer info, 14 * etc. This is used exclusively by the corresponding instance of a display 15 * driver. 16 * 17 * The VRAM layout: 18 * Last 4096 bytes - Adapter information area. 19 * 4096 bytes aligned miniport heap (value specified in the config rouded up). 20 * Slack - what left after dividing the VRAM. 21 * 4096 bytes aligned framebuffers: 22 * last 4096 bytes of each framebuffer is the display information area. 23 * 24 * The Virtual Graphics Adapter information in the guest VRAM is stored by the 25 * guest video driver using structures prepended by VBOXVIDEOINFOHDR. 26 * 27 * When the guest driver writes dword 0 to the VBE_DISPI_INDEX_VBOX_VIDEO 28 * the host starts to process the info. The first element at the start of 29 * the 4096 bytes region should be normally be a LINK that points to 30 * actual information chain. That way the guest driver can have some 31 * fixed layout of the information memory block and just rewrite 32 * the link to point to relevant memory chain. 33 * 34 * The processing stops at the END element. 35 * 36 * The host can access the memory only when the port IO is processed. 37 * All data that will be needed later must be copied from these 4096 bytes. 38 * But other VRAM can be used by host until the mode is disabled. 39 * 40 * The guest driver writes dword 0xffffffff to the VBE_DISPI_INDEX_VBOX_VIDEO 41 * to disable the mode. 42 * 43 * VBE_DISPI_INDEX_VBOX_VIDEO is used to read the configuration information 44 * from the host and issue commands to the host. 45 * 46 * The guest writes the VBE_DISPI_INDEX_VBOX_VIDEO index register, the the 47 * following operations with the VBE data register can be performed: 48 * 49 * Operation Result 50 * write 16 bit value NOP 51 * read 16 bit value count of monitors 52 * write 32 bit value set the vbox cmd value and the cmd processed by the host 53 * read 32 bit value result of the last vbox command is returned 54 */ 55 56 struct vbva_cmd_hdr { 57 s16 x; 58 s16 y; 59 u16 w; 60 u16 h; 61 } __packed; 62 63 /* 64 * The VBVA ring buffer is suitable for transferring large (< 2GB) amount of 65 * data. For example big bitmaps which do not fit to the buffer. 66 * 67 * Guest starts writing to the buffer by initializing a record entry in the 68 * records queue. VBVA_F_RECORD_PARTIAL indicates that the record is being 69 * written. As data is written to the ring buffer, the guest increases 70 * free_offset. 71 * 72 * The host reads the records on flushes and processes all completed records. 73 * When host encounters situation when only a partial record presents and 74 * len_and_flags & ~VBVA_F_RECORD_PARTIAL >= VBVA_RING_BUFFER_SIZE - 75 * VBVA_RING_BUFFER_THRESHOLD, the host fetched all record data and updates 76 * data_offset. After that on each flush the host continues fetching the data 77 * until the record is completed. 78 */ 79 80 #define VBVA_RING_BUFFER_SIZE (4194304 - 1024) 81 #define VBVA_RING_BUFFER_THRESHOLD (4096) 82 83 #define VBVA_MAX_RECORDS (64) 84 85 #define VBVA_F_MODE_ENABLED 0x00000001u 86 #define VBVA_F_MODE_VRDP 0x00000002u 87 #define VBVA_F_MODE_VRDP_RESET 0x00000004u 88 #define VBVA_F_MODE_VRDP_ORDER_MASK 0x00000008u 89 90 #define VBVA_F_STATE_PROCESSING 0x00010000u 91 92 #define VBVA_F_RECORD_PARTIAL 0x80000000u 93 94 struct vbva_record { 95 u32 len_and_flags; 96 } __packed; 97 98 /* 99 * The minimum HGSMI heap size is PAGE_SIZE (4096 bytes) and is a restriction of 100 * the runtime heapsimple API. Use minimum 2 pages here, because the info area 101 * also may contain other data (for example hgsmi_host_flags structure). 102 */ 103 #define VBVA_ADAPTER_INFORMATION_SIZE 65536 104 #define VBVA_MIN_BUFFER_SIZE 65536 105 106 /* The value for port IO to let the adapter to interpret the adapter memory. */ 107 #define VBOX_VIDEO_DISABLE_ADAPTER_MEMORY 0xFFFFFFFF 108 109 /* The value for port IO to let the adapter to interpret the adapter memory. */ 110 #define VBOX_VIDEO_INTERPRET_ADAPTER_MEMORY 0x00000000 111 112 /* 113 * The value for port IO to let the adapter to interpret the display memory. 114 * The display number is encoded in low 16 bits. 115 */ 116 #define VBOX_VIDEO_INTERPRET_DISPLAY_MEMORY_BASE 0x00010000 117 118 struct vbva_host_flags { 119 u32 host_events; 120 u32 supported_orders; 121 } __packed; 122 123 struct vbva_buffer { 124 struct vbva_host_flags host_flags; 125 126 /* The offset where the data start in the buffer. */ 127 u32 data_offset; 128 /* The offset where next data must be placed in the buffer. */ 129 u32 free_offset; 130 131 /* The queue of record descriptions. */ 132 struct vbva_record records[VBVA_MAX_RECORDS]; 133 u32 record_first_index; 134 u32 record_free_index; 135 136 /* Space to leave free when large partial records are transferred. */ 137 u32 partial_write_tresh; 138 139 u32 data_len; 140 /* variable size for the rest of the vbva_buffer area in VRAM. */ 141 u8 data[0]; 142 } __packed; 143 144 #define VBVA_MAX_RECORD_SIZE (128 * 1024 * 1024) 145 146 /* guest->host commands */ 147 #define VBVA_QUERY_CONF32 1 148 #define VBVA_SET_CONF32 2 149 #define VBVA_INFO_VIEW 3 150 #define VBVA_INFO_HEAP 4 151 #define VBVA_FLUSH 5 152 #define VBVA_INFO_SCREEN 6 153 #define VBVA_ENABLE 7 154 #define VBVA_MOUSE_POINTER_SHAPE 8 155 /* informs host about HGSMI caps. see vbva_caps below */ 156 #define VBVA_INFO_CAPS 12 157 /* configures scanline, see VBVASCANLINECFG below */ 158 #define VBVA_SCANLINE_CFG 13 159 /* requests scanline info, see VBVASCANLINEINFO below */ 160 #define VBVA_SCANLINE_INFO 14 161 /* inform host about VBVA Command submission */ 162 #define VBVA_CMDVBVA_SUBMIT 16 163 /* inform host about VBVA Command submission */ 164 #define VBVA_CMDVBVA_FLUSH 17 165 /* G->H DMA command */ 166 #define VBVA_CMDVBVA_CTL 18 167 /* Query most recent mode hints sent */ 168 #define VBVA_QUERY_MODE_HINTS 19 169 /* 170 * Report the guest virtual desktop position and size for mapping host and 171 * guest pointer positions. 172 */ 173 #define VBVA_REPORT_INPUT_MAPPING 20 174 /* Report the guest cursor position and query the host position. */ 175 #define VBVA_CURSOR_POSITION 21 176 177 /* host->guest commands */ 178 #define VBVAHG_EVENT 1 179 #define VBVAHG_DISPLAY_CUSTOM 2 180 181 /* vbva_conf32::index */ 182 #define VBOX_VBVA_CONF32_MONITOR_COUNT 0 183 #define VBOX_VBVA_CONF32_HOST_HEAP_SIZE 1 184 /* 185 * Returns VINF_SUCCESS if the host can report mode hints via VBVA. 186 * Set value to VERR_NOT_SUPPORTED before calling. 187 */ 188 #define VBOX_VBVA_CONF32_MODE_HINT_REPORTING 2 189 /* 190 * Returns VINF_SUCCESS if the host can report guest cursor enabled status via 191 * VBVA. Set value to VERR_NOT_SUPPORTED before calling. 192 */ 193 #define VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING 3 194 /* 195 * Returns the currently available host cursor capabilities. Available if 196 * VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING returns success. 197 */ 198 #define VBOX_VBVA_CONF32_CURSOR_CAPABILITIES 4 199 /* Returns the supported flags in vbva_infoscreen.flags. */ 200 #define VBOX_VBVA_CONF32_SCREEN_FLAGS 5 201 /* Returns the max size of VBVA record. */ 202 #define VBOX_VBVA_CONF32_MAX_RECORD_SIZE 6 203 204 struct vbva_conf32 { 205 u32 index; 206 u32 value; 207 } __packed; 208 209 /* Reserved for historical reasons. */ 210 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED0 BIT(0) 211 /* 212 * Guest cursor capability: can the host show a hardware cursor at the host 213 * pointer location? 214 */ 215 #define VBOX_VBVA_CURSOR_CAPABILITY_HARDWARE BIT(1) 216 /* Reserved for historical reasons. */ 217 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED2 BIT(2) 218 /* Reserved for historical reasons. Must always be unset. */ 219 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED3 BIT(3) 220 /* Reserved for historical reasons. */ 221 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED4 BIT(4) 222 /* Reserved for historical reasons. */ 223 #define VBOX_VBVA_CURSOR_CAPABILITY_RESERVED5 BIT(5) 224 225 struct vbva_infoview { 226 /* Index of the screen, assigned by the guest. */ 227 u32 view_index; 228 229 /* The screen offset in VRAM, the framebuffer starts here. */ 230 u32 view_offset; 231 232 /* The size of the VRAM memory that can be used for the view. */ 233 u32 view_size; 234 235 /* The recommended maximum size of the VRAM memory for the screen. */ 236 u32 max_screen_size; 237 } __packed; 238 239 struct vbva_flush { 240 u32 reserved; 241 } __packed; 242 243 /* vbva_infoscreen.flags */ 244 #define VBVA_SCREEN_F_NONE 0x0000 245 #define VBVA_SCREEN_F_ACTIVE 0x0001 246 /* 247 * The virtual monitor has been disabled by the guest and should be removed 248 * by the host and ignored for purposes of pointer position calculation. 249 */ 250 #define VBVA_SCREEN_F_DISABLED 0x0002 251 /* 252 * The virtual monitor has been blanked by the guest and should be blacked 253 * out by the host using width, height, etc values from the vbva_infoscreen 254 * request. 255 */ 256 #define VBVA_SCREEN_F_BLANK 0x0004 257 /* 258 * The virtual monitor has been blanked by the guest and should be blacked 259 * out by the host using the previous mode values for width. height, etc. 260 */ 261 #define VBVA_SCREEN_F_BLANK2 0x0008 262 263 struct vbva_infoscreen { 264 /* Which view contains the screen. */ 265 u32 view_index; 266 267 /* Physical X origin relative to the primary screen. */ 268 s32 origin_x; 269 270 /* Physical Y origin relative to the primary screen. */ 271 s32 origin_y; 272 273 /* Offset of visible framebuffer relative to the framebuffer start. */ 274 u32 start_offset; 275 276 /* The scan line size in bytes. */ 277 u32 line_size; 278 279 /* Width of the screen. */ 280 u32 width; 281 282 /* Height of the screen. */ 283 u32 height; 284 285 /* Color depth. */ 286 u16 bits_per_pixel; 287 288 /* VBVA_SCREEN_F_* */ 289 u16 flags; 290 } __packed; 291 292 /* vbva_enable.flags */ 293 #define VBVA_F_NONE 0x00000000 294 #define VBVA_F_ENABLE 0x00000001 295 #define VBVA_F_DISABLE 0x00000002 296 /* extended VBVA to be used with WDDM */ 297 #define VBVA_F_EXTENDED 0x00000004 298 /* vbva offset is absolute VRAM offset */ 299 #define VBVA_F_ABSOFFSET 0x00000008 300 301 struct vbva_enable { 302 u32 flags; 303 u32 offset; 304 s32 result; 305 } __packed; 306 307 struct vbva_enable_ex { 308 struct vbva_enable base; 309 u32 screen_id; 310 } __packed; 311 312 struct vbva_mouse_pointer_shape { 313 /* The host result. */ 314 s32 result; 315 316 /* VBOX_MOUSE_POINTER_* bit flags. */ 317 u32 flags; 318 319 /* X coordinate of the hot spot. */ 320 u32 hot_X; 321 322 /* Y coordinate of the hot spot. */ 323 u32 hot_y; 324 325 /* Width of the pointer in pixels. */ 326 u32 width; 327 328 /* Height of the pointer in scanlines. */ 329 u32 height; 330 331 /* Pointer data. 332 * 333 * The data consists of 1 bpp AND mask followed by 32 bpp XOR (color) 334 * mask. 335 * 336 * For pointers without alpha channel the XOR mask pixels are 32 bit 337 * values: (lsb)BGR0(msb). For pointers with alpha channel the XOR mask 338 * consists of (lsb)BGRA(msb) 32 bit values. 339 * 340 * Guest driver must create the AND mask for pointers with alpha chan., 341 * so if host does not support alpha, the pointer could be displayed as 342 * a normal color pointer. The AND mask can be constructed from alpha 343 * values. For example alpha value >= 0xf0 means bit 0 in the AND mask. 344 * 345 * The AND mask is 1 bpp bitmap with byte aligned scanlines. Size of AND 346 * mask, therefore, is and_len = (width + 7) / 8 * height. The padding 347 * bits at the end of any scanline are undefined. 348 * 349 * The XOR mask follows the AND mask on the next 4 bytes aligned offset: 350 * u8 *xor = and + (and_len + 3) & ~3 351 * Bytes in the gap between the AND and the XOR mask are undefined. 352 * XOR mask scanlines have no gap between them and size of XOR mask is: 353 * xor_len = width * 4 * height. 354 * 355 * Preallocate 4 bytes for accessing actual data as p->data. 356 */ 357 u8 data[4]; 358 } __packed; 359 360 /* pointer is visible */ 361 #define VBOX_MOUSE_POINTER_VISIBLE 0x0001 362 /* pointer has alpha channel */ 363 #define VBOX_MOUSE_POINTER_ALPHA 0x0002 364 /* pointerData contains new pointer shape */ 365 #define VBOX_MOUSE_POINTER_SHAPE 0x0004 366 367 /* 368 * The guest driver can handle asynch guest cmd completion by reading the 369 * command offset from io port. 370 */ 371 #define VBVACAPS_COMPLETEGCMD_BY_IOREAD 0x00000001 372 /* the guest driver can handle video adapter IRQs */ 373 #define VBVACAPS_IRQ 0x00000002 374 /* The guest can read video mode hints sent via VBVA. */ 375 #define VBVACAPS_VIDEO_MODE_HINTS 0x00000004 376 /* The guest can switch to a software cursor on demand. */ 377 #define VBVACAPS_DISABLE_CURSOR_INTEGRATION 0x00000008 378 /* The guest does not depend on host handling the VBE registers. */ 379 #define VBVACAPS_USE_VBVA_ONLY 0x00000010 380 381 struct vbva_caps { 382 s32 rc; 383 u32 caps; 384 } __packed; 385 386 /* Query the most recent mode hints received from the host. */ 387 struct vbva_query_mode_hints { 388 /* The maximum number of screens to return hints for. */ 389 u16 hints_queried_count; 390 /* The size of the mode hint structures directly following this one. */ 391 u16 hint_structure_guest_size; 392 /* Return code for the operation. Initialise to VERR_NOT_SUPPORTED. */ 393 s32 rc; 394 } __packed; 395 396 /* 397 * Structure in which a mode hint is returned. The guest allocates an array 398 * of these immediately after the vbva_query_mode_hints structure. 399 * To accommodate future extensions, the vbva_query_mode_hints structure 400 * specifies the size of the vbva_modehint structures allocated by the guest, 401 * and the host only fills out structure elements which fit into that size. The 402 * host should fill any unused members (e.g. dx, dy) or structure space on the 403 * end with ~0. The whole structure can legally be set to ~0 to skip a screen. 404 */ 405 struct vbva_modehint { 406 u32 magic; 407 u32 cx; 408 u32 cy; 409 u32 bpp; /* Which has never been used... */ 410 u32 display; 411 u32 dx; /* X offset into the virtual frame-buffer. */ 412 u32 dy; /* Y offset into the virtual frame-buffer. */ 413 u32 enabled; /* Not flags. Add new members for new flags. */ 414 } __packed; 415 416 #define VBVAMODEHINT_MAGIC 0x0801add9u 417 418 /* 419 * Report the rectangle relative to which absolute pointer events should be 420 * expressed. This information remains valid until the next VBVA resize event 421 * for any screen, at which time it is reset to the bounding rectangle of all 422 * virtual screens and must be re-set. 423 */ 424 struct vbva_report_input_mapping { 425 s32 x; /* Upper left X co-ordinate relative to the first screen. */ 426 s32 y; /* Upper left Y co-ordinate relative to the first screen. */ 427 u32 cx; /* Rectangle width. */ 428 u32 cy; /* Rectangle height. */ 429 } __packed; 430 431 /* 432 * Report the guest cursor position and query the host one. The host may wish 433 * to use the guest information to re-position its own cursor (though this is 434 * currently unlikely). 435 */ 436 struct vbva_cursor_position { 437 u32 report_position; /* Are we reporting a position? */ 438 u32 x; /* Guest cursor X position */ 439 u32 y; /* Guest cursor Y position */ 440 } __packed; 441 442 #endif