vboxvideo.h 14 KB

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