displif.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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. * unique-id
  189. * Values: <string>
  190. *
  191. * After device instance initialization each connector is assigned a
  192. * unique ID, so it can be identified by the backend by this ID.
  193. * This can be UUID or such.
  194. *
  195. * resolution
  196. * Values: <width, uint32_t>x<height, uint32_t>
  197. *
  198. * Width and height of the connector in pixels separated by
  199. * XENDISPL_RESOLUTION_SEPARATOR. This defines visible area of the
  200. * display.
  201. *
  202. *------------------ Connector Request Transport Parameters -------------------
  203. *
  204. * This communication path is used to deliver requests from frontend to backend
  205. * and get the corresponding responses from backend to frontend,
  206. * set up per connector.
  207. *
  208. * req-event-channel
  209. * Values: <uint32_t>
  210. *
  211. * The identifier of the Xen connector's control event channel
  212. * used to signal activity in the ring buffer.
  213. *
  214. * req-ring-ref
  215. * Values: <uint32_t>
  216. *
  217. * The Xen grant reference granting permission for the backend to map
  218. * a sole page of connector's control ring buffer.
  219. *
  220. *------------------- Connector Event Transport Parameters --------------------
  221. *
  222. * This communication path is used to deliver asynchronous events from backend
  223. * to frontend, set up per connector.
  224. *
  225. * evt-event-channel
  226. * Values: <uint32_t>
  227. *
  228. * The identifier of the Xen connector's event channel
  229. * used to signal activity in the ring buffer.
  230. *
  231. * evt-ring-ref
  232. * Values: <uint32_t>
  233. *
  234. * The Xen grant reference granting permission for the backend to map
  235. * a sole page of connector's event ring buffer.
  236. */
  237. /*
  238. ******************************************************************************
  239. * STATE DIAGRAMS
  240. ******************************************************************************
  241. *
  242. * Tool stack creates front and back state nodes with initial state
  243. * XenbusStateInitialising.
  244. * Tool stack creates and sets up frontend display configuration
  245. * nodes per domain.
  246. *
  247. *-------------------------------- Normal flow --------------------------------
  248. *
  249. * Front Back
  250. * ================================= =====================================
  251. * XenbusStateInitialising XenbusStateInitialising
  252. * o Query backend device identification
  253. * data.
  254. * o Open and validate backend device.
  255. * |
  256. * |
  257. * V
  258. * XenbusStateInitWait
  259. *
  260. * o Query frontend configuration
  261. * o Allocate and initialize
  262. * event channels per configured
  263. * connector.
  264. * o Publish transport parameters
  265. * that will be in effect during
  266. * this connection.
  267. * |
  268. * |
  269. * V
  270. * XenbusStateInitialised
  271. *
  272. * o Query frontend transport parameters.
  273. * o Connect to the event channels.
  274. * |
  275. * |
  276. * V
  277. * XenbusStateConnected
  278. *
  279. * o Create and initialize OS
  280. * virtual display connectors
  281. * as per configuration.
  282. * |
  283. * |
  284. * V
  285. * XenbusStateConnected
  286. *
  287. * XenbusStateUnknown
  288. * XenbusStateClosed
  289. * XenbusStateClosing
  290. * o Remove virtual display device
  291. * o Remove event channels
  292. * |
  293. * |
  294. * V
  295. * XenbusStateClosed
  296. *
  297. *------------------------------- Recovery flow -------------------------------
  298. *
  299. * In case of frontend unrecoverable errors backend handles that as
  300. * if frontend goes into the XenbusStateClosed state.
  301. *
  302. * In case of backend unrecoverable errors frontend tries removing
  303. * the virtualized device. If this is possible at the moment of error,
  304. * then frontend goes into the XenbusStateInitialising state and is ready for
  305. * new connection with backend. If the virtualized device is still in use and
  306. * cannot be removed, then frontend goes into the XenbusStateReconfiguring state
  307. * until either the virtualized device is removed or backend initiates a new
  308. * connection. On the virtualized device removal frontend goes into the
  309. * XenbusStateInitialising state.
  310. *
  311. * Note on XenbusStateReconfiguring state of the frontend: if backend has
  312. * unrecoverable errors then frontend cannot send requests to the backend
  313. * and thus cannot provide functionality of the virtualized device anymore.
  314. * After backend is back to normal the virtualized device may still hold some
  315. * state: configuration in use, allocated buffers, client application state etc.
  316. * In most cases, this will require frontend to implement complex recovery
  317. * reconnect logic. Instead, by going into XenbusStateReconfiguring state,
  318. * frontend will make sure no new clients of the virtualized device are
  319. * accepted, allow existing client(s) to exit gracefully by signaling error
  320. * state etc.
  321. * Once all the clients are gone frontend can reinitialize the virtualized
  322. * device and get into XenbusStateInitialising state again signaling the
  323. * backend that a new connection can be made.
  324. *
  325. * There are multiple conditions possible under which frontend will go from
  326. * XenbusStateReconfiguring into XenbusStateInitialising, some of them are OS
  327. * specific. For example:
  328. * 1. The underlying OS framework may provide callbacks to signal that the last
  329. * client of the virtualized device has gone and the device can be removed
  330. * 2. Frontend can schedule a deferred work (timer/tasklet/workqueue)
  331. * to periodically check if this is the right time to re-try removal of
  332. * the virtualized device.
  333. * 3. By any other means.
  334. *
  335. ******************************************************************************
  336. * REQUEST CODES
  337. ******************************************************************************
  338. * Request codes [0; 15] are reserved and must not be used
  339. */
  340. #define XENDISPL_OP_DBUF_CREATE 0x10
  341. #define XENDISPL_OP_DBUF_DESTROY 0x11
  342. #define XENDISPL_OP_FB_ATTACH 0x12
  343. #define XENDISPL_OP_FB_DETACH 0x13
  344. #define XENDISPL_OP_SET_CONFIG 0x14
  345. #define XENDISPL_OP_PG_FLIP 0x15
  346. /*
  347. ******************************************************************************
  348. * EVENT CODES
  349. ******************************************************************************
  350. */
  351. #define XENDISPL_EVT_PG_FLIP 0x00
  352. /*
  353. ******************************************************************************
  354. * XENSTORE FIELD AND PATH NAME STRINGS, HELPERS
  355. ******************************************************************************
  356. */
  357. #define XENDISPL_DRIVER_NAME "vdispl"
  358. #define XENDISPL_LIST_SEPARATOR ","
  359. #define XENDISPL_RESOLUTION_SEPARATOR "x"
  360. #define XENDISPL_FIELD_BE_VERSIONS "versions"
  361. #define XENDISPL_FIELD_FE_VERSION "version"
  362. #define XENDISPL_FIELD_REQ_RING_REF "req-ring-ref"
  363. #define XENDISPL_FIELD_REQ_CHANNEL "req-event-channel"
  364. #define XENDISPL_FIELD_EVT_RING_REF "evt-ring-ref"
  365. #define XENDISPL_FIELD_EVT_CHANNEL "evt-event-channel"
  366. #define XENDISPL_FIELD_RESOLUTION "resolution"
  367. #define XENDISPL_FIELD_BE_ALLOC "be-alloc"
  368. #define XENDISPL_FIELD_UNIQUE_ID "unique-id"
  369. /*
  370. ******************************************************************************
  371. * STATUS RETURN CODES
  372. ******************************************************************************
  373. *
  374. * Status return code is zero on success and -XEN_EXX on failure.
  375. *
  376. ******************************************************************************
  377. * Assumptions
  378. ******************************************************************************
  379. * o usage of grant reference 0 as invalid grant reference:
  380. * grant reference 0 is valid, but never exposed to a PV driver,
  381. * because of the fact it is already in use/reserved by the PV console.
  382. * o all references in this document to page sizes must be treated
  383. * as pages of size XEN_PAGE_SIZE unless otherwise noted.
  384. *
  385. ******************************************************************************
  386. * Description of the protocol between frontend and backend driver
  387. ******************************************************************************
  388. *
  389. * The two halves of a Para-virtual display driver communicate with
  390. * each other using shared pages and event channels.
  391. * Shared page contains a ring with request/response packets.
  392. *
  393. * All reserved fields in the structures below must be 0.
  394. * Display buffers's cookie of value 0 is treated as invalid.
  395. * Framebuffer's cookie of value 0 is treated as invalid.
  396. *
  397. * For all request/response/event packets that use cookies:
  398. * dbuf_cookie - uint64_t, unique to guest domain value used by the backend
  399. * to map remote display buffer to its local one
  400. * fb_cookie - uint64_t, unique to guest domain value used by the backend
  401. * to map remote framebuffer to its local one
  402. *
  403. *---------------------------------- Requests ---------------------------------
  404. *
  405. * All requests/responses, which are not connector specific, must be sent over
  406. * control ring of the connector which has the index value of 0:
  407. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  408. *
  409. * All request packets have the same length (64 octets)
  410. * All request packets have common header:
  411. * 0 1 2 3 octet
  412. * +----------------+----------------+----------------+----------------+
  413. * | id | operation | reserved | 4
  414. * +----------------+----------------+----------------+----------------+
  415. * | reserved | 8
  416. * +----------------+----------------+----------------+----------------+
  417. * id - uint16_t, private guest value, echoed in response
  418. * operation - uint8_t, operation code, XENDISPL_OP_???
  419. *
  420. * Request dbuf creation - request creation of a display buffer.
  421. * 0 1 2 3 octet
  422. * +----------------+----------------+----------------+----------------+
  423. * | id |_OP_DBUF_CREATE | reserved | 4
  424. * +----------------+----------------+----------------+----------------+
  425. * | reserved | 8
  426. * +----------------+----------------+----------------+----------------+
  427. * | dbuf_cookie low 32-bit | 12
  428. * +----------------+----------------+----------------+----------------+
  429. * | dbuf_cookie high 32-bit | 16
  430. * +----------------+----------------+----------------+----------------+
  431. * | width | 20
  432. * +----------------+----------------+----------------+----------------+
  433. * | height | 24
  434. * +----------------+----------------+----------------+----------------+
  435. * | bpp | 28
  436. * +----------------+----------------+----------------+----------------+
  437. * | buffer_sz | 32
  438. * +----------------+----------------+----------------+----------------+
  439. * | flags | 36
  440. * +----------------+----------------+----------------+----------------+
  441. * | gref_directory | 40
  442. * +----------------+----------------+----------------+----------------+
  443. * | reserved | 44
  444. * +----------------+----------------+----------------+----------------+
  445. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  446. * +----------------+----------------+----------------+----------------+
  447. * | reserved | 64
  448. * +----------------+----------------+----------------+----------------+
  449. *
  450. * Must be sent over control ring of the connector which has the index
  451. * value of 0:
  452. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  453. * All unused bits in flags field must be set to 0.
  454. *
  455. * An attempt to create multiple display buffers with the same dbuf_cookie is
  456. * an error. dbuf_cookie can be re-used after destroying the corresponding
  457. * display buffer.
  458. *
  459. * Width and height of the display buffers can be smaller, equal or bigger
  460. * than the connector's resolution. Depth/pixel format of the individual
  461. * buffers can differ as well.
  462. *
  463. * width - uint32_t, width in pixels
  464. * height - uint32_t, height in pixels
  465. * bpp - uint32_t, bits per pixel
  466. * buffer_sz - uint32_t, buffer size to be allocated, octets
  467. * flags - uint32_t, flags of the operation
  468. * o XENDISPL_DBUF_FLG_REQ_ALLOC - if set, then backend is requested
  469. * to allocate the buffer with the parameters provided in this request.
  470. * Page directory is handled as follows:
  471. * Frontend on request:
  472. * o allocates pages for the directory (gref_directory,
  473. * gref_dir_next_page(s)
  474. * o grants permissions for the pages of the directory to the backend
  475. * o sets gref_dir_next_page fields
  476. * Backend on response:
  477. * o grants permissions for the pages of the buffer allocated to
  478. * the frontend
  479. * o fills in page directory with grant references
  480. * (gref[] in struct xendispl_page_directory)
  481. * gref_directory - grant_ref_t, a reference to the first shared page
  482. * describing shared buffer references. At least one page exists. If shared
  483. * buffer size (buffer_sz) exceeds what can be addressed by this single page,
  484. * then reference to the next page must be supplied (see gref_dir_next_page
  485. * below)
  486. */
  487. #define XENDISPL_DBUF_FLG_REQ_ALLOC (1 << 0)
  488. struct xendispl_dbuf_create_req {
  489. uint64_t dbuf_cookie;
  490. uint32_t width;
  491. uint32_t height;
  492. uint32_t bpp;
  493. uint32_t buffer_sz;
  494. uint32_t flags;
  495. grant_ref_t gref_directory;
  496. };
  497. /*
  498. * Shared page for XENDISPL_OP_DBUF_CREATE buffer descriptor (gref_directory in
  499. * the request) employs a list of pages, describing all pages of the shared
  500. * data buffer:
  501. * 0 1 2 3 octet
  502. * +----------------+----------------+----------------+----------------+
  503. * | gref_dir_next_page | 4
  504. * +----------------+----------------+----------------+----------------+
  505. * | gref[0] | 8
  506. * +----------------+----------------+----------------+----------------+
  507. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  508. * +----------------+----------------+----------------+----------------+
  509. * | gref[i] | i*4+8
  510. * +----------------+----------------+----------------+----------------+
  511. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  512. * +----------------+----------------+----------------+----------------+
  513. * | gref[N - 1] | N*4+8
  514. * +----------------+----------------+----------------+----------------+
  515. *
  516. * gref_dir_next_page - grant_ref_t, reference to the next page describing
  517. * page directory. Must be 0 if there are no more pages in the list.
  518. * gref[i] - grant_ref_t, reference to a shared page of the buffer
  519. * allocated at XENDISPL_OP_DBUF_CREATE
  520. *
  521. * Number of grant_ref_t entries in the whole page directory is not
  522. * passed, but instead can be calculated as:
  523. * num_grefs_total = (XENDISPL_OP_DBUF_CREATE.buffer_sz + XEN_PAGE_SIZE - 1) /
  524. * XEN_PAGE_SIZE
  525. */
  526. struct xendispl_page_directory {
  527. grant_ref_t gref_dir_next_page;
  528. grant_ref_t gref[1]; /* Variable length */
  529. };
  530. /*
  531. * Request dbuf destruction - destroy a previously allocated display buffer:
  532. * 0 1 2 3 octet
  533. * +----------------+----------------+----------------+----------------+
  534. * | id |_OP_DBUF_DESTROY| reserved | 4
  535. * +----------------+----------------+----------------+----------------+
  536. * | reserved | 8
  537. * +----------------+----------------+----------------+----------------+
  538. * | dbuf_cookie low 32-bit | 12
  539. * +----------------+----------------+----------------+----------------+
  540. * | dbuf_cookie high 32-bit | 16
  541. * +----------------+----------------+----------------+----------------+
  542. * | reserved | 20
  543. * +----------------+----------------+----------------+----------------+
  544. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  545. * +----------------+----------------+----------------+----------------+
  546. * | reserved | 64
  547. * +----------------+----------------+----------------+----------------+
  548. *
  549. * Must be sent over control ring of the connector which has the index
  550. * value of 0:
  551. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  552. */
  553. struct xendispl_dbuf_destroy_req {
  554. uint64_t dbuf_cookie;
  555. };
  556. /*
  557. * Request framebuffer attachment - request attachment of a framebuffer to
  558. * previously created display buffer.
  559. * 0 1 2 3 octet
  560. * +----------------+----------------+----------------+----------------+
  561. * | id | _OP_FB_ATTACH | reserved | 4
  562. * +----------------+----------------+----------------+----------------+
  563. * | reserved | 8
  564. * +----------------+----------------+----------------+----------------+
  565. * | dbuf_cookie low 32-bit | 12
  566. * +----------------+----------------+----------------+----------------+
  567. * | dbuf_cookie high 32-bit | 16
  568. * +----------------+----------------+----------------+----------------+
  569. * | fb_cookie low 32-bit | 20
  570. * +----------------+----------------+----------------+----------------+
  571. * | fb_cookie high 32-bit | 24
  572. * +----------------+----------------+----------------+----------------+
  573. * | width | 28
  574. * +----------------+----------------+----------------+----------------+
  575. * | height | 32
  576. * +----------------+----------------+----------------+----------------+
  577. * | pixel_format | 36
  578. * +----------------+----------------+----------------+----------------+
  579. * | reserved | 40
  580. * +----------------+----------------+----------------+----------------+
  581. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  582. * +----------------+----------------+----------------+----------------+
  583. * | reserved | 64
  584. * +----------------+----------------+----------------+----------------+
  585. *
  586. * Must be sent over control ring of the connector which has the index
  587. * value of 0:
  588. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  589. * Width and height can be smaller, equal or bigger than the connector's
  590. * resolution.
  591. *
  592. * An attempt to create multiple frame buffers with the same fb_cookie is
  593. * an error. fb_cookie can be re-used after destroying the corresponding
  594. * frame buffer.
  595. *
  596. * width - uint32_t, width in pixels
  597. * height - uint32_t, height in pixels
  598. * pixel_format - uint32_t, pixel format of the framebuffer, FOURCC code
  599. */
  600. struct xendispl_fb_attach_req {
  601. uint64_t dbuf_cookie;
  602. uint64_t fb_cookie;
  603. uint32_t width;
  604. uint32_t height;
  605. uint32_t pixel_format;
  606. };
  607. /*
  608. * Request framebuffer detach - detach a previously
  609. * attached framebuffer from the display buffer in request:
  610. * 0 1 2 3 octet
  611. * +----------------+----------------+----------------+----------------+
  612. * | id | _OP_FB_DETACH | reserved | 4
  613. * +----------------+----------------+----------------+----------------+
  614. * | reserved | 8
  615. * +----------------+----------------+----------------+----------------+
  616. * | fb_cookie low 32-bit | 12
  617. * +----------------+----------------+----------------+----------------+
  618. * | fb_cookie high 32-bit | 16
  619. * +----------------+----------------+----------------+----------------+
  620. * | reserved | 20
  621. * +----------------+----------------+----------------+----------------+
  622. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  623. * +----------------+----------------+----------------+----------------+
  624. * | reserved | 64
  625. * +----------------+----------------+----------------+----------------+
  626. *
  627. * Must be sent over control ring of the connector which has the index
  628. * value of 0:
  629. * /local/domain/<dom-id>/device/vdispl/<dev-id>/0/req-ring-ref
  630. */
  631. struct xendispl_fb_detach_req {
  632. uint64_t fb_cookie;
  633. };
  634. /*
  635. * Request configuration set/reset - request to set or reset
  636. * the configuration/mode of the display:
  637. * 0 1 2 3 octet
  638. * +----------------+----------------+----------------+----------------+
  639. * | id | _OP_SET_CONFIG | reserved | 4
  640. * +----------------+----------------+----------------+----------------+
  641. * | reserved | 8
  642. * +----------------+----------------+----------------+----------------+
  643. * | fb_cookie low 32-bit | 12
  644. * +----------------+----------------+----------------+----------------+
  645. * | fb_cookie high 32-bit | 16
  646. * +----------------+----------------+----------------+----------------+
  647. * | x | 20
  648. * +----------------+----------------+----------------+----------------+
  649. * | y | 24
  650. * +----------------+----------------+----------------+----------------+
  651. * | width | 28
  652. * +----------------+----------------+----------------+----------------+
  653. * | height | 32
  654. * +----------------+----------------+----------------+----------------+
  655. * | bpp | 40
  656. * +----------------+----------------+----------------+----------------+
  657. * | reserved | 44
  658. * +----------------+----------------+----------------+----------------+
  659. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  660. * +----------------+----------------+----------------+----------------+
  661. * | reserved | 64
  662. * +----------------+----------------+----------------+----------------+
  663. *
  664. * Pass all zeros to reset, otherwise command is treated as
  665. * configuration set.
  666. * Framebuffer's cookie defines which framebuffer/dbuf must be
  667. * displayed while enabling display (applying configuration).
  668. * x, y, width and height are bound by the connector's resolution and must not
  669. * exceed it.
  670. *
  671. * x - uint32_t, starting position in pixels by X axis
  672. * y - uint32_t, starting position in pixels by Y axis
  673. * width - uint32_t, width in pixels
  674. * height - uint32_t, height in pixels
  675. * bpp - uint32_t, bits per pixel
  676. */
  677. struct xendispl_set_config_req {
  678. uint64_t fb_cookie;
  679. uint32_t x;
  680. uint32_t y;
  681. uint32_t width;
  682. uint32_t height;
  683. uint32_t bpp;
  684. };
  685. /*
  686. * Request page flip - request to flip a page identified by the framebuffer
  687. * cookie:
  688. * 0 1 2 3 octet
  689. * +----------------+----------------+----------------+----------------+
  690. * | id | _OP_PG_FLIP | reserved | 4
  691. * +----------------+----------------+----------------+----------------+
  692. * | reserved | 8
  693. * +----------------+----------------+----------------+----------------+
  694. * | fb_cookie low 32-bit | 12
  695. * +----------------+----------------+----------------+----------------+
  696. * | fb_cookie high 32-bit | 16
  697. * +----------------+----------------+----------------+----------------+
  698. * | reserved | 20
  699. * +----------------+----------------+----------------+----------------+
  700. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  701. * +----------------+----------------+----------------+----------------+
  702. * | reserved | 64
  703. * +----------------+----------------+----------------+----------------+
  704. */
  705. struct xendispl_page_flip_req {
  706. uint64_t fb_cookie;
  707. };
  708. /*
  709. *---------------------------------- Responses --------------------------------
  710. *
  711. * All response packets have the same length (64 octets)
  712. *
  713. * All response packets have common header:
  714. * 0 1 2 3 octet
  715. * +----------------+----------------+----------------+----------------+
  716. * | id | reserved | 4
  717. * +----------------+----------------+----------------+----------------+
  718. * | status | 8
  719. * +----------------+----------------+----------------+----------------+
  720. * | reserved | 12
  721. * +----------------+----------------+----------------+----------------+
  722. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  723. * +----------------+----------------+----------------+----------------+
  724. * | reserved | 64
  725. * +----------------+----------------+----------------+----------------+
  726. *
  727. * id - uint16_t, private guest value, echoed from request
  728. * status - int32_t, response status, zero on success and -XEN_EXX on failure
  729. *
  730. *----------------------------------- Events ----------------------------------
  731. *
  732. * Events are sent via a shared page allocated by the front and propagated by
  733. * evt-event-channel/evt-ring-ref XenStore entries
  734. * All event packets have the same length (64 octets)
  735. * All event packets have common header:
  736. * 0 1 2 3 octet
  737. * +----------------+----------------+----------------+----------------+
  738. * | id | type | reserved | 4
  739. * +----------------+----------------+----------------+----------------+
  740. * | reserved | 8
  741. * +----------------+----------------+----------------+----------------+
  742. *
  743. * id - uint16_t, event id, may be used by front
  744. * type - uint8_t, type of the event
  745. *
  746. *
  747. * Page flip complete event - event from back to front on page flip completed:
  748. * 0 1 2 3 octet
  749. * +----------------+----------------+----------------+----------------+
  750. * | id | _EVT_PG_FLIP | reserved | 4
  751. * +----------------+----------------+----------------+----------------+
  752. * | reserved | 8
  753. * +----------------+----------------+----------------+----------------+
  754. * | fb_cookie low 32-bit | 12
  755. * +----------------+----------------+----------------+----------------+
  756. * | fb_cookie high 32-bit | 16
  757. * +----------------+----------------+----------------+----------------+
  758. * | reserved | 20
  759. * +----------------+----------------+----------------+----------------+
  760. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  761. * +----------------+----------------+----------------+----------------+
  762. * | reserved | 64
  763. * +----------------+----------------+----------------+----------------+
  764. */
  765. struct xendispl_pg_flip_evt {
  766. uint64_t fb_cookie;
  767. };
  768. struct xendispl_req {
  769. uint16_t id;
  770. uint8_t operation;
  771. uint8_t reserved[5];
  772. union {
  773. struct xendispl_dbuf_create_req dbuf_create;
  774. struct xendispl_dbuf_destroy_req dbuf_destroy;
  775. struct xendispl_fb_attach_req fb_attach;
  776. struct xendispl_fb_detach_req fb_detach;
  777. struct xendispl_set_config_req set_config;
  778. struct xendispl_page_flip_req pg_flip;
  779. uint8_t reserved[56];
  780. } op;
  781. };
  782. struct xendispl_resp {
  783. uint16_t id;
  784. uint8_t operation;
  785. uint8_t reserved;
  786. int32_t status;
  787. uint8_t reserved1[56];
  788. };
  789. struct xendispl_evt {
  790. uint16_t id;
  791. uint8_t type;
  792. uint8_t reserved[5];
  793. union {
  794. struct xendispl_pg_flip_evt pg_flip;
  795. uint8_t reserved[56];
  796. } op;
  797. };
  798. DEFINE_RING_TYPES(xen_displif, struct xendispl_req, struct xendispl_resp);
  799. /*
  800. ******************************************************************************
  801. * Back to front events delivery
  802. ******************************************************************************
  803. * In order to deliver asynchronous events from back to front a shared page is
  804. * allocated by front and its granted reference propagated to back via
  805. * XenStore entries (evt-ring-ref/evt-event-channel).
  806. * This page has a common header used by both front and back to synchronize
  807. * access and control event's ring buffer, while back being a producer of the
  808. * events and front being a consumer. The rest of the page after the header
  809. * is used for event packets.
  810. *
  811. * Upon reception of an event(s) front may confirm its reception
  812. * for either each event, group of events or none.
  813. */
  814. struct xendispl_event_page {
  815. uint32_t in_cons;
  816. uint32_t in_prod;
  817. uint8_t reserved[56];
  818. };
  819. #define XENDISPL_EVENT_PAGE_SIZE XEN_PAGE_SIZE
  820. #define XENDISPL_IN_RING_OFFS (sizeof(struct xendispl_event_page))
  821. #define XENDISPL_IN_RING_SIZE (XENDISPL_EVENT_PAGE_SIZE - XENDISPL_IN_RING_OFFS)
  822. #define XENDISPL_IN_RING_LEN (XENDISPL_IN_RING_SIZE / sizeof(struct xendispl_evt))
  823. #define XENDISPL_IN_RING(page) \
  824. ((struct xendispl_evt *)((char *)(page) + XENDISPL_IN_RING_OFFS))
  825. #define XENDISPL_IN_RING_REF(page, idx) \
  826. (XENDISPL_IN_RING((page))[(idx) % XENDISPL_IN_RING_LEN])
  827. #endif /* __XEN_PUBLIC_IO_DISPLIF_H__ */