displif.h 39 KB

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