vboxvideo.h 16 KB

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