displif.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. /* SPDX-License-Identifier: MIT */
  2. /******************************************************************************
  3. * displif.h
  4. *
  5. * Unified display device I/O interface for Xen guest OSes.
  6. *
  7. * Copyright (C) 2016-2017 EPAM Systems Inc.
  8. *
  9. * Authors: Oleksandr Andrushchenko <[email protected]>
  10. * Oleksandr Grytsov <[email protected]>
  11. */
  12. #ifndef __XEN_PUBLIC_IO_DISPLIF_H__
  13. #define __XEN_PUBLIC_IO_DISPLIF_H__
  14. #include "ring.h"
  15. #include "../grant_table.h"
  16. /*
  17. ******************************************************************************
  18. * Protocol version
  19. ******************************************************************************
  20. */
  21. #define XENDISPL_PROTOCOL_VERSION "2"
  22. #define XENDISPL_PROTOCOL_VERSION_INT 2
  23. /*
  24. ******************************************************************************
  25. * Main features provided by the protocol
  26. ******************************************************************************
  27. * This protocol aims to provide a unified protocol which fits more
  28. * sophisticated use-cases than a framebuffer device can handle. At the
  29. * moment basic functionality is supported with the intention to be extended:
  30. * o multiple dynamically allocated/destroyed framebuffers
  31. * o buffers of arbitrary sizes
  32. * o buffer allocation at either back or front end
  33. * o better configuration options including multiple display support
  34. *
  35. * Note: existing fbif can be used together with displif running at the
  36. * same time, e.g. on Linux one provides framebuffer and another DRM/KMS
  37. *
  38. * Note: display resolution (XenStore's "resolution" property) defines
  39. * visible area of the virtual display. At the same time resolution of
  40. * the display and frame buffers may differ: buffers can be smaller, equal
  41. * or bigger than the visible area. This is to enable use-cases, where backend
  42. * may do some post-processing of the display and frame buffers supplied,
  43. * e.g. those buffers can be just a part of the final composition.
  44. *
  45. ******************************************************************************
  46. * Direction of improvements
  47. ******************************************************************************
  48. * Future extensions to the existing protocol may include:
  49. * o display/connector cloning
  50. * o allocation of objects other than display buffers
  51. * o plane/overlay support
  52. * o scaling support
  53. * o rotation support
  54. *
  55. ******************************************************************************
  56. * Feature and Parameter Negotiation
  57. ******************************************************************************
  58. *
  59. * Front->back notifications: when enqueuing a new request, sending a
  60. * notification can be made conditional on xendispl_req (i.e., the generic
  61. * hold-off mechanism provided by the ring macros). Backends must set
  62. * xendispl_req appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
  63. *
  64. * Back->front notifications: when enqueuing a new response, sending a
  65. * notification can be made conditional on xendispl_resp (i.e., the generic
  66. * hold-off mechanism provided by the ring macros). Frontends must set
  67. * xendispl_resp appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
  68. *
  69. * The two halves of a para-virtual display driver utilize nodes within
  70. * XenStore to communicate capabilities and to negotiate operating parameters.
  71. * This section enumerates these nodes which reside in the respective front and
  72. * backend portions of XenStore, following the XenBus convention.
  73. *
  74. * All data in XenStore is stored as strings. Nodes specifying numeric
  75. * values are encoded in decimal. Integer value ranges listed below are
  76. * expressed as fixed sized integer types capable of storing the conversion
  77. * of a properly formated node string, without loss of information.
  78. *
  79. ******************************************************************************
  80. * Example configuration
  81. ******************************************************************************
  82. *
  83. * Note: depending on the use-case backend can expose more display connectors
  84. * than the underlying HW physically has by employing SW graphics compositors
  85. *
  86. * This is an example of backend and frontend configuration:
  87. *
  88. *--------------------------------- Backend -----------------------------------
  89. *
  90. * /local/domain/0/backend/vdispl/1/0/frontend-id = "1"
  91. * /local/domain/0/backend/vdispl/1/0/frontend = "/local/domain/1/device/vdispl/0"
  92. * /local/domain/0/backend/vdispl/1/0/state = "4"
  93. * /local/domain/0/backend/vdispl/1/0/versions = "1,2"
  94. *
  95. *--------------------------------- Frontend ----------------------------------
  96. *
  97. * /local/domain/1/device/vdispl/0/backend-id = "0"
  98. * /local/domain/1/device/vdispl/0/backend = "/local/domain/0/backend/vdispl/1/0"
  99. * /local/domain/1/device/vdispl/0/state = "4"
  100. * /local/domain/1/device/vdispl/0/version = "1"
  101. * /local/domain/1/device/vdispl/0/be-alloc = "1"
  102. *
  103. *-------------------------- Connector 0 configuration ------------------------
  104. *
  105. * /local/domain/1/device/vdispl/0/0/resolution = "1920x1080"
  106. * /local/domain/1/device/vdispl/0/0/req-ring-ref = "2832"
  107. * /local/domain/1/device/vdispl/0/0/req-event-channel = "15"
  108. * /local/domain/1/device/vdispl/0/0/evt-ring-ref = "387"
  109. * /local/domain/1/device/vdispl/0/0/evt-event-channel = "16"
  110. *
  111. *-------------------------- Connector 1 configuration ------------------------
  112. *
  113. * /local/domain/1/device/vdispl/0/1/resolution = "800x600"
  114. * /local/domain/1/device/vdispl/0/1/req-ring-ref = "2833"
  115. * /local/domain/1/device/vdispl/0/1/req-event-channel = "17"
  116. * /local/domain/1/device/vdispl/0/1/evt-ring-ref = "388"
  117. * /local/domain/1/device/vdispl/0/1/evt-event-channel = "18"
  118. *
  119. ******************************************************************************
  120. * Backend XenBus Nodes
  121. ******************************************************************************
  122. *
  123. *----------------------------- Protocol version ------------------------------
  124. *
  125. * versions
  126. * Values: <string>
  127. *
  128. * List of XENDISPL_LIST_SEPARATOR separated protocol versions supported
  129. * by the backend. For example "1,2,3".
  130. *
  131. ******************************************************************************
  132. * Frontend XenBus Nodes
  133. ******************************************************************************
  134. *
  135. *-------------------------------- Addressing ---------------------------------
  136. *
  137. * dom-id
  138. * Values: <uint16_t>
  139. *
  140. * Domain identifier.
  141. *
  142. * dev-id
  143. * Values: <uint16_t>
  144. *
  145. * Device identifier.
  146. *
  147. * conn-idx
  148. * Values: <uint8_t>
  149. *
  150. * Zero based contigous index of the connector.
  151. * /local/domain/<dom-id>/device/vdispl/<dev-id>/<conn-idx>/...
  152. *
  153. *----------------------------- Protocol version ------------------------------
  154. *
  155. * version
  156. * Values: <string>
  157. *
  158. * Protocol version, chosen among the ones supported by the backend.
  159. *
  160. *------------------------- Backend buffer allocation -------------------------
  161. *
  162. * be-alloc
  163. * Values: "0", "1"
  164. *
  165. * If value is set to "1", then backend can be a buffer provider/allocator
  166. * for this domain during XENDISPL_OP_DBUF_CREATE operation (see below
  167. * for negotiation).
  168. * If value is not "1" or omitted frontend must allocate buffers itself.
  169. *
  170. *----------------------------- Connector settings ----------------------------
  171. *
  172. * unique-id
  173. * Values: <string>
  174. *
  175. * After device instance initialization each connector is assigned a
  176. * unique ID, so it can be identified by the backend by this ID.
  177. * This can be UUID or such.
  178. *
  179. * resolution
  180. * Values: <width, uint32_t>x<height, uint32_t>
  181. *
  182. * Width and height of the connector in pixels separated by
  183. * XENDISPL_RESOLUTION_SEPARATOR. This defines visible area of the
  184. * display.
  185. * If backend provides extended display identification data (EDID) with
  186. * XENDISPL_OP_GET_EDID request then EDID values must take precedence
  187. * over the resolutions defined here.
  188. *
  189. *------------------ Connector Request Transport Parameters -------------------
  190. *
  191. * This communication path is used to deliver requests from frontend to backend
  192. * and get the corresponding responses from backend to frontend,
  193. * set up per connector.
  194. *
  195. * req-event-channel
  196. * Values: <uint32_t>
  197. *
  198. * The identifier of the Xen connector's control event channel
  199. * used to signal activity in the ring buffer.
  200. *
  201. * req-ring-ref
  202. * Values: <uint32_t>
  203. *
  204. * The Xen grant reference granting permission for the backend to map
  205. * a sole page of connector's control ring buffer.
  206. *
  207. *------------------- Connector Event Transport Parameters --------------------
  208. *
  209. * This communication path is used to deliver asynchronous events from backend
  210. * to frontend, set up per connector.
  211. *
  212. * evt-event-channel
  213. * Values: <uint32_t>
  214. *
  215. * The identifier of the Xen connector's event channel
  216. * used to signal activity in the ring buffer.
  217. *
  218. * evt-ring-ref
  219. * Values: <uint32_t>
  220. *
  221. * The Xen grant reference granting permission for the backend to map
  222. * a sole page of connector's event ring buffer.
  223. */
  224. /*
  225. ******************************************************************************
  226. * STATE DIAGRAMS
  227. ******************************************************************************
  228. *
  229. * Tool stack creates front and back state nodes with initial state
  230. * XenbusStateInitialising.
  231. * Tool stack creates and sets up frontend display configuration
  232. * nodes per domain.
  233. *
  234. *-------------------------------- Normal flow --------------------------------
  235. *
  236. * Front Back
  237. * ================================= =====================================
  238. * XenbusStateInitialising XenbusStateInitialising
  239. * o Query backend device identification
  240. * data.
  241. * o Open and validate backend device.
  242. * |
  243. * |
  244. * V
  245. * XenbusStateInitWait
  246. *
  247. * o Query frontend configuration
  248. * o Allocate and initialize
  249. * event channels per configured
  250. * connector.
  251. * o Publish transport parameters
  252. * that will be in effect during
  253. * this connection.
  254. * |
  255. * |
  256. * V
  257. * XenbusStateInitialised
  258. *
  259. * o Query frontend transport parameters.
  260. * o Connect to the event channels.
  261. * |
  262. * |
  263. * V
  264. * XenbusStateConnected
  265. *
  266. * o Create and initialize OS
  267. * virtual display connectors
  268. * as per configuration.
  269. * |
  270. * |
  271. * V
  272. * XenbusStateConnected
  273. *
  274. * XenbusStateUnknown
  275. * XenbusStateClosed
  276. * XenbusStateClosing
  277. * o Remove virtual display device
  278. * o Remove event channels
  279. * |
  280. * |
  281. * V
  282. * XenbusStateClosed
  283. *
  284. *------------------------------- Recovery flow -------------------------------
  285. *
  286. * In case of frontend unrecoverable errors backend handles that as
  287. * if frontend goes into the XenbusStateClosed state.
  288. *
  289. * In case of backend unrecoverable errors frontend tries removing
  290. * the virtualized device. If this is possible at the moment of error,
  291. * then frontend goes into the XenbusStateInitialising state and is ready for
  292. * new connection with backend. If the virtualized device is still in use and
  293. * cannot be removed, then frontend goes into the XenbusStateReconfiguring state
  294. * until either the virtualized device is removed or backend initiates a new
  295. * connection. On the virtualized device removal frontend goes into the
  296. * XenbusStateInitialising state.
  297. *
  298. * Note on XenbusStateReconfiguring state of the frontend: if backend has
  299. * unrecoverable errors then frontend cannot send requests to the backend
  300. * and thus cannot provide functionality of the virtualized device anymore.
  301. * After backend is back to normal the virtualized device may still hold some
  302. * state: configuration in use, allocated buffers, client application state etc.
  303. * In most cases, this will require frontend to implement complex recovery
  304. * reconnect logic. Instead, by going into XenbusStateReconfiguring state,
  305. * frontend will make sure no new clients of the virtualized device are
  306. * accepted, allow existing client(s) to exit gracefully by signaling error
  307. * state etc.
  308. * Once all the clients are gone frontend can reinitialize the virtualized
  309. * device and get into XenbusStateInitialising state again signaling the
  310. * backend that a new connection can be made.
  311. *
  312. * There are multiple conditions possible under which frontend will go from
  313. * XenbusStateReconfiguring into XenbusStateInitialising, some of them are OS
  314. * specific. For example:
  315. * 1. The underlying OS framework may provide callbacks to signal that the last
  316. * client of the virtualized device has gone and the device can be removed
  317. * 2. Frontend can schedule a deferred work (timer/tasklet/workqueue)
  318. * to periodically check if this is the right time to re-try removal of
  319. * the virtualized device.
  320. * 3. By any other means.
  321. *
  322. ******************************************************************************
  323. * REQUEST CODES
  324. ******************************************************************************
  325. * Request codes [0; 15] are reserved and must not be used
  326. */
  327. #define XENDISPL_OP_DBUF_CREATE 0x10
  328. #define XENDISPL_OP_DBUF_DESTROY 0x11
  329. #define XENDISPL_OP_FB_ATTACH 0x12
  330. #define XENDISPL_OP_FB_DETACH 0x13
  331. #define XENDISPL_OP_SET_CONFIG 0x14
  332. #define XENDISPL_OP_PG_FLIP 0x15
  333. /* The below command is available in protocol version 2 and above. */
  334. #define XENDISPL_OP_GET_EDID 0x16
  335. /*
  336. ******************************************************************************
  337. * EVENT CODES
  338. ******************************************************************************
  339. */
  340. #define XENDISPL_EVT_PG_FLIP 0x00
  341. /*
  342. ******************************************************************************
  343. * XENSTORE FIELD AND PATH NAME STRINGS, HELPERS
  344. ******************************************************************************
  345. */
  346. #define XENDISPL_DRIVER_NAME "vdispl"
  347. #define XENDISPL_LIST_SEPARATOR ","
  348. #define XENDISPL_RESOLUTION_SEPARATOR "x"
  349. #define XENDISPL_FIELD_BE_VERSIONS "versions"
  350. #define XENDISPL_FIELD_FE_VERSION "version"
  351. #define XENDISPL_FIELD_REQ_RING_REF "req-ring-ref"
  352. #define XENDISPL_FIELD_REQ_CHANNEL "req-event-channel"
  353. #define XENDISPL_FIELD_EVT_RING_REF "evt-ring-ref"
  354. #define XENDISPL_FIELD_EVT_CHANNEL "evt-event-channel"
  355. #define XENDISPL_FIELD_RESOLUTION "resolution"
  356. #define XENDISPL_FIELD_BE_ALLOC "be-alloc"
  357. #define XENDISPL_FIELD_UNIQUE_ID "unique-id"
  358. #define XENDISPL_EDID_BLOCK_SIZE 128
  359. #define XENDISPL_EDID_BLOCK_COUNT 256
  360. #define XENDISPL_EDID_MAX_SIZE (XENDISPL_EDID_BLOCK_SIZE * XENDISPL_EDID_BLOCK_COUNT)
  361. /*
  362. ******************************************************************************
  363. * STATUS RETURN CODES
  364. ******************************************************************************
  365. *
  366. * Status return code is zero on success and -XEN_EXX on failure.
  367. *
  368. ******************************************************************************
  369. * Assumptions
  370. ******************************************************************************
  371. * o usage of grant reference 0 as invalid grant reference:
  372. * grant reference 0 is valid, but never exposed to a PV driver,
  373. * because of the fact it is already in use/reserved by the PV console.
  374. * o all references in this document to page sizes must be treated
  375. * as pages of size XEN_PAGE_SIZE unless otherwise noted.
  376. *
  377. ******************************************************************************
  378. * Description of the protocol between frontend and backend driver
  379. ******************************************************************************
  380. *
  381. * The two halves of a Para-virtual display driver communicate with
  382. * each other using shared pages and event channels.
  383. * Shared page contains a ring with request/response packets.
  384. *
  385. * All reserved fields in the structures below must be 0.
  386. * Display buffers's cookie of value 0 is treated as invalid.
  387. * Framebuffer's cookie of value 0 is treated as invalid.
  388. *
  389. * For all request/response/event packets that use cookies:
  390. * dbuf_cookie - uint64_t, unique to guest domain value used by the backend
  391. * to map remote display buffer to its local one
  392. * fb_cookie - uint64_t, unique to guest domain value used by the backend
  393. * to map remote framebuffer to its local one
  394. *
  395. *---------------------------------- Requests ---------------------------------
  396. *
  397. * All requests/responses, which are not connector specific, must be sent over
  398. * control ring of the connector which has the index value of 0:
  399. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  400. *
  401. * All request packets have the same length (64 octets)
  402. * All request packets have common header:
  403. * 0 1 2 3 octet
  404. * +----------------+----------------+----------------+----------------+
  405. * | id | operation | reserved | 4
  406. * +----------------+----------------+----------------+----------------+
  407. * | reserved | 8
  408. * +----------------+----------------+----------------+----------------+
  409. * id - uint16_t, private guest value, echoed in response
  410. * operation - uint8_t, operation code, XENDISPL_OP_???
  411. *
  412. * Request dbuf creation - request creation of a display buffer.
  413. * 0 1 2 3 octet
  414. * +----------------+----------------+----------------+----------------+
  415. * | id |_OP_DBUF_CREATE | reserved | 4
  416. * +----------------+----------------+----------------+----------------+
  417. * | reserved | 8
  418. * +----------------+----------------+----------------+----------------+
  419. * | dbuf_cookie low 32-bit | 12
  420. * +----------------+----------------+----------------+----------------+
  421. * | dbuf_cookie high 32-bit | 16
  422. * +----------------+----------------+----------------+----------------+
  423. * | width | 20
  424. * +----------------+----------------+----------------+----------------+
  425. * | height | 24
  426. * +----------------+----------------+----------------+----------------+
  427. * | bpp | 28
  428. * +----------------+----------------+----------------+----------------+
  429. * | buffer_sz | 32
  430. * +----------------+----------------+----------------+----------------+
  431. * | flags | 36
  432. * +----------------+----------------+----------------+----------------+
  433. * | gref_directory | 40
  434. * +----------------+----------------+----------------+----------------+
  435. * | data_ofs | 44
  436. * +----------------+----------------+----------------+----------------+
  437. * | reserved | 48
  438. * +----------------+----------------+----------------+----------------+
  439. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  440. * +----------------+----------------+----------------+----------------+
  441. * | reserved | 64
  442. * +----------------+----------------+----------------+----------------+
  443. *
  444. * Must be sent over control ring of the connector which has the index
  445. * value of 0:
  446. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  447. * All unused bits in flags field must be set to 0.
  448. *
  449. * An attempt to create multiple display buffers with the same dbuf_cookie is
  450. * an error. dbuf_cookie can be re-used after destroying the corresponding
  451. * display buffer.
  452. *
  453. * Width and height of the display buffers can be smaller, equal or bigger
  454. * than the connector's resolution. Depth/pixel format of the individual
  455. * buffers can differ as well.
  456. *
  457. * width - uint32_t, width in pixels
  458. * height - uint32_t, height in pixels
  459. * bpp - uint32_t, bits per pixel
  460. * buffer_sz - uint32_t, buffer size to be allocated, octets
  461. * flags - uint32_t, flags of the operation
  462. * o XENDISPL_DBUF_FLG_REQ_ALLOC - if set, then backend is requested
  463. * to allocate the buffer with the parameters provided in this request.
  464. * Page directory is handled as follows:
  465. * Frontend on request:
  466. * o allocates pages for the directory (gref_directory,
  467. * gref_dir_next_page(s)
  468. * o grants permissions for the pages of the directory to the backend
  469. * o sets gref_dir_next_page fields
  470. * Backend on response:
  471. * o grants permissions for the pages of the buffer allocated to
  472. * the frontend
  473. * o fills in page directory with grant references
  474. * (gref[] in struct xendispl_page_directory)
  475. * gref_directory - grant_ref_t, a reference to the first shared page
  476. * describing shared buffer references. At least one page exists. If shared
  477. * buffer size (buffer_sz) exceeds what can be addressed by this single page,
  478. * then reference to the next page must be supplied (see gref_dir_next_page
  479. * below)
  480. * data_ofs - uint32_t, offset of the data in the buffer, octets
  481. */
  482. #define XENDISPL_DBUF_FLG_REQ_ALLOC (1 << 0)
  483. struct xendispl_dbuf_create_req {
  484. uint64_t dbuf_cookie;
  485. uint32_t width;
  486. uint32_t height;
  487. uint32_t bpp;
  488. uint32_t buffer_sz;
  489. uint32_t flags;
  490. grant_ref_t gref_directory;
  491. uint32_t data_ofs;
  492. };
  493. /*
  494. * Shared page for XENDISPL_OP_DBUF_CREATE buffer descriptor (gref_directory in
  495. * the request) employs a list of pages, describing all pages of the shared
  496. * data buffer:
  497. * 0 1 2 3 octet
  498. * +----------------+----------------+----------------+----------------+
  499. * | gref_dir_next_page | 4
  500. * +----------------+----------------+----------------+----------------+
  501. * | gref[0] | 8
  502. * +----------------+----------------+----------------+----------------+
  503. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  504. * +----------------+----------------+----------------+----------------+
  505. * | gref[i] | i*4+8
  506. * +----------------+----------------+----------------+----------------+
  507. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  508. * +----------------+----------------+----------------+----------------+
  509. * | gref[N - 1] | N*4+8
  510. * +----------------+----------------+----------------+----------------+
  511. *
  512. * gref_dir_next_page - grant_ref_t, reference to the next page describing
  513. * page directory. Must be 0 if there are no more pages in the list.
  514. * gref[i] - grant_ref_t, reference to a shared page of the buffer
  515. * allocated at XENDISPL_OP_DBUF_CREATE
  516. *
  517. * Number of grant_ref_t entries in the whole page directory is not
  518. * passed, but instead can be calculated as:
  519. * num_grefs_total = (XENDISPL_OP_DBUF_CREATE.buffer_sz + XEN_PAGE_SIZE - 1) /
  520. * XEN_PAGE_SIZE
  521. */
  522. struct xendispl_page_directory {
  523. grant_ref_t gref_dir_next_page;
  524. grant_ref_t gref[1]; /* Variable length */
  525. };
  526. /*
  527. * Request dbuf destruction - destroy a previously allocated display buffer:
  528. * 0 1 2 3 octet
  529. * +----------------+----------------+----------------+----------------+
  530. * | id |_OP_DBUF_DESTROY| reserved | 4
  531. * +----------------+----------------+----------------+----------------+
  532. * | reserved | 8
  533. * +----------------+----------------+----------------+----------------+
  534. * | dbuf_cookie low 32-bit | 12
  535. * +----------------+----------------+----------------+----------------+
  536. * | dbuf_cookie high 32-bit | 16
  537. * +----------------+----------------+----------------+----------------+
  538. * | reserved | 20
  539. * +----------------+----------------+----------------+----------------+
  540. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  541. * +----------------+----------------+----------------+----------------+
  542. * | reserved | 64
  543. * +----------------+----------------+----------------+----------------+
  544. *
  545. * Must be sent over control ring of the connector which has the index
  546. * value of 0:
  547. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  548. */
  549. struct xendispl_dbuf_destroy_req {
  550. uint64_t dbuf_cookie;
  551. };
  552. /*
  553. * Request framebuffer attachment - request attachment of a framebuffer to
  554. * previously created display buffer.
  555. * 0 1 2 3 octet
  556. * +----------------+----------------+----------------+----------------+
  557. * | id | _OP_FB_ATTACH | reserved | 4
  558. * +----------------+----------------+----------------+----------------+
  559. * | reserved | 8
  560. * +----------------+----------------+----------------+----------------+
  561. * | dbuf_cookie low 32-bit | 12
  562. * +----------------+----------------+----------------+----------------+
  563. * | dbuf_cookie high 32-bit | 16
  564. * +----------------+----------------+----------------+----------------+
  565. * | fb_cookie low 32-bit | 20
  566. * +----------------+----------------+----------------+----------------+
  567. * | fb_cookie high 32-bit | 24
  568. * +----------------+----------------+----------------+----------------+
  569. * | width | 28
  570. * +----------------+----------------+----------------+----------------+
  571. * | height | 32
  572. * +----------------+----------------+----------------+----------------+
  573. * | pixel_format | 36
  574. * +----------------+----------------+----------------+----------------+
  575. * | reserved | 40
  576. * +----------------+----------------+----------------+----------------+
  577. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  578. * +----------------+----------------+----------------+----------------+
  579. * | reserved | 64
  580. * +----------------+----------------+----------------+----------------+
  581. *
  582. * Must be sent over control ring of the connector which has the index
  583. * value of 0:
  584. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  585. * Width and height can be smaller, equal or bigger than the connector's
  586. * resolution.
  587. *
  588. * An attempt to create multiple frame buffers with the same fb_cookie is
  589. * an error. fb_cookie can be re-used after destroying the corresponding
  590. * frame buffer.
  591. *
  592. * width - uint32_t, width in pixels
  593. * height - uint32_t, height in pixels
  594. * pixel_format - uint32_t, pixel format of the framebuffer, FOURCC code
  595. */
  596. struct xendispl_fb_attach_req {
  597. uint64_t dbuf_cookie;
  598. uint64_t fb_cookie;
  599. uint32_t width;
  600. uint32_t height;
  601. uint32_t pixel_format;
  602. };
  603. /*
  604. * Request framebuffer detach - detach a previously
  605. * attached framebuffer from the display buffer in request:
  606. * 0 1 2 3 octet
  607. * +----------------+----------------+----------------+----------------+
  608. * | id | _OP_FB_DETACH | reserved | 4
  609. * +----------------+----------------+----------------+----------------+
  610. * | reserved | 8
  611. * +----------------+----------------+----------------+----------------+
  612. * | fb_cookie low 32-bit | 12
  613. * +----------------+----------------+----------------+----------------+
  614. * | fb_cookie high 32-bit | 16
  615. * +----------------+----------------+----------------+----------------+
  616. * | reserved | 20
  617. * +----------------+----------------+----------------+----------------+
  618. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  619. * +----------------+----------------+----------------+----------------+
  620. * | reserved | 64
  621. * +----------------+----------------+----------------+----------------+
  622. *
  623. * Must be sent over control ring of the connector which has the index
  624. * value of 0:
  625. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  626. */
  627. struct xendispl_fb_detach_req {
  628. uint64_t fb_cookie;
  629. };
  630. /*
  631. * Request configuration set/reset - request to set or reset
  632. * the configuration/mode of the display:
  633. * 0 1 2 3 octet
  634. * +----------------+----------------+----------------+----------------+
  635. * | id | _OP_SET_CONFIG | reserved | 4
  636. * +----------------+----------------+----------------+----------------+
  637. * | reserved | 8
  638. * +----------------+----------------+----------------+----------------+
  639. * | fb_cookie low 32-bit | 12
  640. * +----------------+----------------+----------------+----------------+
  641. * | fb_cookie high 32-bit | 16
  642. * +----------------+----------------+----------------+----------------+
  643. * | x | 20
  644. * +----------------+----------------+----------------+----------------+
  645. * | y | 24
  646. * +----------------+----------------+----------------+----------------+
  647. * | width | 28
  648. * +----------------+----------------+----------------+----------------+
  649. * | height | 32
  650. * +----------------+----------------+----------------+----------------+
  651. * | bpp | 40
  652. * +----------------+----------------+----------------+----------------+
  653. * | reserved | 44
  654. * +----------------+----------------+----------------+----------------+
  655. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  656. * +----------------+----------------+----------------+----------------+
  657. * | reserved | 64
  658. * +----------------+----------------+----------------+----------------+
  659. *
  660. * Pass all zeros to reset, otherwise command is treated as
  661. * configuration set.
  662. * Framebuffer's cookie defines which framebuffer/dbuf must be
  663. * displayed while enabling display (applying configuration).
  664. * x, y, width and height are bound by the connector's resolution and must not
  665. * exceed it.
  666. *
  667. * x - uint32_t, starting position in pixels by X axis
  668. * y - uint32_t, starting position in pixels by Y axis
  669. * width - uint32_t, width in pixels
  670. * height - uint32_t, height in pixels
  671. * bpp - uint32_t, bits per pixel
  672. */
  673. struct xendispl_set_config_req {
  674. uint64_t fb_cookie;
  675. uint32_t x;
  676. uint32_t y;
  677. uint32_t width;
  678. uint32_t height;
  679. uint32_t bpp;
  680. };
  681. /*
  682. * Request page flip - request to flip a page identified by the framebuffer
  683. * cookie:
  684. * 0 1 2 3 octet
  685. * +----------------+----------------+----------------+----------------+
  686. * | id | _OP_PG_FLIP | reserved | 4
  687. * +----------------+----------------+----------------+----------------+
  688. * | reserved | 8
  689. * +----------------+----------------+----------------+----------------+
  690. * | fb_cookie low 32-bit | 12
  691. * +----------------+----------------+----------------+----------------+
  692. * | fb_cookie high 32-bit | 16
  693. * +----------------+----------------+----------------+----------------+
  694. * | reserved | 20
  695. * +----------------+----------------+----------------+----------------+
  696. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  697. * +----------------+----------------+----------------+----------------+
  698. * | reserved | 64
  699. * +----------------+----------------+----------------+----------------+
  700. */
  701. struct xendispl_page_flip_req {
  702. uint64_t fb_cookie;
  703. };
  704. /*
  705. * Request EDID - request EDID describing current connector:
  706. * 0 1 2 3 octet
  707. * +----------------+----------------+----------------+----------------+
  708. * | id | _OP_GET_EDID | reserved | 4
  709. * +----------------+----------------+----------------+----------------+
  710. * | buffer_sz | 8
  711. * +----------------+----------------+----------------+----------------+
  712. * | gref_directory | 12
  713. * +----------------+----------------+----------------+----------------+
  714. * | reserved | 16
  715. * +----------------+----------------+----------------+----------------+
  716. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  717. * +----------------+----------------+----------------+----------------+
  718. * | reserved | 64
  719. * +----------------+----------------+----------------+----------------+
  720. *
  721. * Notes:
  722. * - This command is not available in protocol version 1 and should be
  723. * ignored.
  724. * - This request is optional and if not supported then visible area
  725. * is defined by the relevant XenStore's "resolution" property.
  726. * - Shared buffer, allocated for EDID storage, must not be less then
  727. * XENDISPL_EDID_MAX_SIZE octets.
  728. *
  729. * buffer_sz - uint32_t, buffer size to be allocated, octets
  730. * gref_directory - grant_ref_t, a reference to the first shared page
  731. * describing EDID buffer references. See XENDISPL_OP_DBUF_CREATE for
  732. * grant page directory structure (struct xendispl_page_directory).
  733. *
  734. * See response format for this request.
  735. */
  736. struct xendispl_get_edid_req {
  737. uint32_t buffer_sz;
  738. grant_ref_t gref_directory;
  739. };
  740. /*
  741. *---------------------------------- Responses --------------------------------
  742. *
  743. * All response packets have the same length (64 octets)
  744. *
  745. * All response packets have common header:
  746. * 0 1 2 3 octet
  747. * +----------------+----------------+----------------+----------------+
  748. * | id | reserved | 4
  749. * +----------------+----------------+----------------+----------------+
  750. * | status | 8
  751. * +----------------+----------------+----------------+----------------+
  752. * | reserved | 12
  753. * +----------------+----------------+----------------+----------------+
  754. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  755. * +----------------+----------------+----------------+----------------+
  756. * | reserved | 64
  757. * +----------------+----------------+----------------+----------------+
  758. *
  759. * id - uint16_t, private guest value, echoed from request
  760. * status - int32_t, response status, zero on success and -XEN_EXX on failure
  761. *
  762. *
  763. * Get EDID response - response for XENDISPL_OP_GET_EDID:
  764. * 0 1 2 3 octet
  765. * +----------------+----------------+----------------+----------------+
  766. * | id | operation | reserved | 4
  767. * +----------------+----------------+----------------+----------------+
  768. * | status | 8
  769. * +----------------+----------------+----------------+----------------+
  770. * | edid_sz | 12
  771. * +----------------+----------------+----------------+----------------+
  772. * | reserved | 16
  773. * +----------------+----------------+----------------+----------------+
  774. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  775. * +----------------+----------------+----------------+----------------+
  776. * | reserved | 64
  777. * +----------------+----------------+----------------+----------------+
  778. *
  779. * Notes:
  780. * - This response is not available in protocol version 1 and should be
  781. * ignored.
  782. *
  783. * edid_sz - uint32_t, size of the EDID, octets
  784. */
  785. struct xendispl_get_edid_resp {
  786. uint32_t edid_sz;
  787. };
  788. /*
  789. *----------------------------------- Events ----------------------------------
  790. *
  791. * Events are sent via a shared page allocated by the front and propagated by
  792. * evt-event-channel/evt-ring-ref XenStore entries
  793. * All event packets have the same length (64 octets)
  794. * All event packets have common header:
  795. * 0 1 2 3 octet
  796. * +----------------+----------------+----------------+----------------+
  797. * | id | type | reserved | 4
  798. * +----------------+----------------+----------------+----------------+
  799. * | reserved | 8
  800. * +----------------+----------------+----------------+----------------+
  801. *
  802. * id - uint16_t, event id, may be used by front
  803. * type - uint8_t, type of the event
  804. *
  805. *
  806. * Page flip complete event - event from back to front on page flip completed:
  807. * 0 1 2 3 octet
  808. * +----------------+----------------+----------------+----------------+
  809. * | id | _EVT_PG_FLIP | reserved | 4
  810. * +----------------+----------------+----------------+----------------+
  811. * | reserved | 8
  812. * +----------------+----------------+----------------+----------------+
  813. * | fb_cookie low 32-bit | 12
  814. * +----------------+----------------+----------------+----------------+
  815. * | fb_cookie high 32-bit | 16
  816. * +----------------+----------------+----------------+----------------+
  817. * | reserved | 20
  818. * +----------------+----------------+----------------+----------------+
  819. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  820. * +----------------+----------------+----------------+----------------+
  821. * | reserved | 64
  822. * +----------------+----------------+----------------+----------------+
  823. */
  824. struct xendispl_pg_flip_evt {
  825. uint64_t fb_cookie;
  826. };
  827. struct xendispl_req {
  828. uint16_t id;
  829. uint8_t operation;
  830. uint8_t reserved[5];
  831. union {
  832. struct xendispl_dbuf_create_req dbuf_create;
  833. struct xendispl_dbuf_destroy_req dbuf_destroy;
  834. struct xendispl_fb_attach_req fb_attach;
  835. struct xendispl_fb_detach_req fb_detach;
  836. struct xendispl_set_config_req set_config;
  837. struct xendispl_page_flip_req pg_flip;
  838. struct xendispl_get_edid_req get_edid;
  839. uint8_t reserved[56];
  840. } op;
  841. };
  842. struct xendispl_resp {
  843. uint16_t id;
  844. uint8_t operation;
  845. uint8_t reserved;
  846. int32_t status;
  847. union {
  848. struct xendispl_get_edid_resp get_edid;
  849. uint8_t reserved1[56];
  850. } op;
  851. };
  852. struct xendispl_evt {
  853. uint16_t id;
  854. uint8_t type;
  855. uint8_t reserved[5];
  856. union {
  857. struct xendispl_pg_flip_evt pg_flip;
  858. uint8_t reserved[56];
  859. } op;
  860. };
  861. DEFINE_RING_TYPES(xen_displif, struct xendispl_req, struct xendispl_resp);
  862. /*
  863. ******************************************************************************
  864. * Back to front events delivery
  865. ******************************************************************************
  866. * In order to deliver asynchronous events from back to front a shared page is
  867. * allocated by front and its granted reference propagated to back via
  868. * XenStore entries (evt-ring-ref/evt-event-channel).
  869. * This page has a common header used by both front and back to synchronize
  870. * access and control event's ring buffer, while back being a producer of the
  871. * events and front being a consumer. The rest of the page after the header
  872. * is used for event packets.
  873. *
  874. * Upon reception of an event(s) front may confirm its reception
  875. * for either each event, group of events or none.
  876. */
  877. struct xendispl_event_page {
  878. uint32_t in_cons;
  879. uint32_t in_prod;
  880. uint8_t reserved[56];
  881. };
  882. #define XENDISPL_EVENT_PAGE_SIZE XEN_PAGE_SIZE
  883. #define XENDISPL_IN_RING_OFFS (sizeof(struct xendispl_event_page))
  884. #define XENDISPL_IN_RING_SIZE (XENDISPL_EVENT_PAGE_SIZE - XENDISPL_IN_RING_OFFS)
  885. #define XENDISPL_IN_RING_LEN (XENDISPL_IN_RING_SIZE / sizeof(struct xendispl_evt))
  886. #define XENDISPL_IN_RING(page) \
  887. ((struct xendispl_evt *)((char *)(page) + XENDISPL_IN_RING_OFFS))
  888. #define XENDISPL_IN_RING_REF(page, idx) \
  889. (XENDISPL_IN_RING((page))[(idx) % XENDISPL_IN_RING_LEN])
  890. #endif /* __XEN_PUBLIC_IO_DISPLIF_H__ */