sndif.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. /******************************************************************************
  2. * sndif.h
  3. *
  4. * Unified sound-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) 2013-2015 GlobalLogic Inc.
  25. * Copyright (C) 2016-2017 EPAM Systems Inc.
  26. *
  27. * Authors: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
  28. * Oleksandr Grytsov <oleksandr_grytsov@epam.com>
  29. * Oleksandr Dmytryshyn <oleksandr.dmytryshyn@globallogic.com>
  30. * Iurii Konovalenko <iurii.konovalenko@globallogic.com>
  31. */
  32. #ifndef __XEN_PUBLIC_IO_SNDIF_H__
  33. #define __XEN_PUBLIC_IO_SNDIF_H__
  34. #include "ring.h"
  35. #include "../grant_table.h"
  36. /*
  37. ******************************************************************************
  38. * Protocol version
  39. ******************************************************************************
  40. */
  41. #define XENSND_PROTOCOL_VERSION 2
  42. /*
  43. ******************************************************************************
  44. * Feature and Parameter Negotiation
  45. ******************************************************************************
  46. *
  47. * Front->back notifications: when enqueuing a new request, sending a
  48. * notification can be made conditional on xensnd_req (i.e., the generic
  49. * hold-off mechanism provided by the ring macros). Backends must set
  50. * xensnd_req appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
  51. *
  52. * Back->front notifications: when enqueuing a new response, sending a
  53. * notification can be made conditional on xensnd_resp (i.e., the generic
  54. * hold-off mechanism provided by the ring macros). Frontends must set
  55. * xensnd_resp appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
  56. *
  57. * The two halves of a para-virtual sound card driver utilize nodes within
  58. * XenStore to communicate capabilities and to negotiate operating parameters.
  59. * This section enumerates these nodes which reside in the respective front and
  60. * backend portions of XenStore, following the XenBus convention.
  61. *
  62. * All data in XenStore is stored as strings. Nodes specifying numeric
  63. * values are encoded in decimal. Integer value ranges listed below are
  64. * expressed as fixed sized integer types capable of storing the conversion
  65. * of a properly formated node string, without loss of information.
  66. *
  67. ******************************************************************************
  68. * Example configuration
  69. ******************************************************************************
  70. *
  71. * Note: depending on the use-case backend can expose more sound cards and
  72. * PCM devices/streams than the underlying HW physically has by employing
  73. * SW mixers, configuring virtual sound streams, channels etc.
  74. *
  75. * This is an example of backend and frontend configuration:
  76. *
  77. *--------------------------------- Backend -----------------------------------
  78. *
  79. * /local/domain/0/backend/vsnd/1/0/frontend-id = "1"
  80. * /local/domain/0/backend/vsnd/1/0/frontend = "/local/domain/1/device/vsnd/0"
  81. * /local/domain/0/backend/vsnd/1/0/state = "4"
  82. * /local/domain/0/backend/vsnd/1/0/versions = "1,2"
  83. *
  84. *--------------------------------- Frontend ----------------------------------
  85. *
  86. * /local/domain/1/device/vsnd/0/backend-id = "0"
  87. * /local/domain/1/device/vsnd/0/backend = "/local/domain/0/backend/vsnd/1/0"
  88. * /local/domain/1/device/vsnd/0/state = "4"
  89. * /local/domain/1/device/vsnd/0/version = "1"
  90. *
  91. *----------------------------- Card configuration ----------------------------
  92. *
  93. * /local/domain/1/device/vsnd/0/short-name = "Card short name"
  94. * /local/domain/1/device/vsnd/0/long-name = "Card long name"
  95. * /local/domain/1/device/vsnd/0/sample-rates = "8000,32000,44100,48000,96000"
  96. * /local/domain/1/device/vsnd/0/sample-formats = "s8,u8,s16_le,s16_be"
  97. * /local/domain/1/device/vsnd/0/buffer-size = "262144"
  98. *
  99. *------------------------------- PCM device 0 --------------------------------
  100. *
  101. * /local/domain/1/device/vsnd/0/0/name = "General analog"
  102. * /local/domain/1/device/vsnd/0/0/channels-max = "5"
  103. *
  104. *----------------------------- Stream 0, playback ----------------------------
  105. *
  106. * /local/domain/1/device/vsnd/0/0/0/type = "p"
  107. * /local/domain/1/device/vsnd/0/0/0/sample-formats = "s8,u8"
  108. * /local/domain/1/device/vsnd/0/0/0/unique-id = "0"
  109. *
  110. * /local/domain/1/device/vsnd/0/0/0/ring-ref = "386"
  111. * /local/domain/1/device/vsnd/0/0/0/event-channel = "15"
  112. * /local/domain/1/device/vsnd/0/0/0/evt-ring-ref = "1386"
  113. * /local/domain/1/device/vsnd/0/0/0/evt-event-channel = "215"
  114. *
  115. *------------------------------ Stream 1, capture ----------------------------
  116. *
  117. * /local/domain/1/device/vsnd/0/0/1/type = "c"
  118. * /local/domain/1/device/vsnd/0/0/1/channels-max = "2"
  119. * /local/domain/1/device/vsnd/0/0/1/unique-id = "1"
  120. *
  121. * /local/domain/1/device/vsnd/0/0/1/ring-ref = "384"
  122. * /local/domain/1/device/vsnd/0/0/1/event-channel = "13"
  123. * /local/domain/1/device/vsnd/0/0/1/evt-ring-ref = "1384"
  124. * /local/domain/1/device/vsnd/0/0/1/evt-event-channel = "213"
  125. *
  126. *------------------------------- PCM device 1 --------------------------------
  127. *
  128. * /local/domain/1/device/vsnd/0/1/name = "HDMI-0"
  129. * /local/domain/1/device/vsnd/0/1/sample-rates = "8000,32000,44100"
  130. *
  131. *------------------------------ Stream 0, capture ----------------------------
  132. *
  133. * /local/domain/1/device/vsnd/0/1/0/type = "c"
  134. * /local/domain/1/device/vsnd/0/1/0/unique-id = "2"
  135. *
  136. * /local/domain/1/device/vsnd/0/1/0/ring-ref = "387"
  137. * /local/domain/1/device/vsnd/0/1/0/event-channel = "151"
  138. * /local/domain/1/device/vsnd/0/1/0/evt-ring-ref = "1387"
  139. * /local/domain/1/device/vsnd/0/1/0/evt-event-channel = "351"
  140. *
  141. *------------------------------- PCM device 2 --------------------------------
  142. *
  143. * /local/domain/1/device/vsnd/0/2/name = "SPDIF"
  144. *
  145. *----------------------------- Stream 0, playback ----------------------------
  146. *
  147. * /local/domain/1/device/vsnd/0/2/0/type = "p"
  148. * /local/domain/1/device/vsnd/0/2/0/unique-id = "3"
  149. *
  150. * /local/domain/1/device/vsnd/0/2/0/ring-ref = "389"
  151. * /local/domain/1/device/vsnd/0/2/0/event-channel = "152"
  152. * /local/domain/1/device/vsnd/0/2/0/evt-ring-ref = "1389"
  153. * /local/domain/1/device/vsnd/0/2/0/evt-event-channel = "452"
  154. *
  155. ******************************************************************************
  156. * Backend XenBus Nodes
  157. ******************************************************************************
  158. *
  159. *----------------------------- Protocol version ------------------------------
  160. *
  161. * versions
  162. * Values: <string>
  163. *
  164. * List of XENSND_LIST_SEPARATOR separated protocol versions supported
  165. * by the backend. For example "1,2,3".
  166. *
  167. ******************************************************************************
  168. * Frontend XenBus Nodes
  169. ******************************************************************************
  170. *
  171. *-------------------------------- Addressing ---------------------------------
  172. *
  173. * dom-id
  174. * Values: <uint16_t>
  175. *
  176. * Domain identifier.
  177. *
  178. * dev-id
  179. * Values: <uint16_t>
  180. *
  181. * Device identifier.
  182. *
  183. * pcm-dev-idx
  184. * Values: <uint8_t>
  185. *
  186. * Zero based contigous index of the PCM device.
  187. *
  188. * stream-idx
  189. * Values: <uint8_t>
  190. *
  191. * Zero based contigous index of the stream of the PCM device.
  192. *
  193. * The following pattern is used for addressing:
  194. * /local/domain/<dom-id>/device/vsnd/<dev-id>/<pcm-dev-idx>/<stream-idx>/...
  195. *
  196. *----------------------------- Protocol version ------------------------------
  197. *
  198. * version
  199. * Values: <string>
  200. *
  201. * Protocol version, chosen among the ones supported by the backend.
  202. *
  203. *------------------------------- PCM settings --------------------------------
  204. *
  205. * Every virtualized sound frontend has a set of PCM devices and streams, each
  206. * could be individually configured. Part of the PCM configuration can be
  207. * defined at higher level of the hierarchy and be fully or partially re-used
  208. * by the underlying layers. These configuration values are:
  209. * o number of channels (min/max)
  210. * o supported sample rates
  211. * o supported sample formats.
  212. * E.g. one can define these values for the whole card, device or stream.
  213. * Every underlying layer in turn can re-define some or all of them to better
  214. * fit its needs. For example, card may define number of channels to be
  215. * in [1; 8] range, and some particular stream may be limited to [1; 2] only.
  216. * The rule is that the underlying layer must be a subset of the upper layer
  217. * range.
  218. *
  219. * channels-min
  220. * Values: <uint8_t>
  221. *
  222. * The minimum amount of channels that is supported, [1; channels-max].
  223. * Optional, if not set or omitted a value of 1 is used.
  224. *
  225. * channels-max
  226. * Values: <uint8_t>
  227. *
  228. * The maximum amount of channels that is supported.
  229. * Must be at least <channels-min>.
  230. *
  231. * sample-rates
  232. * Values: <list of uint32_t>
  233. *
  234. * List of supported sample rates separated by XENSND_LIST_SEPARATOR.
  235. * Sample rates are expressed as a list of decimal values w/o any
  236. * ordering requirement.
  237. *
  238. * sample-formats
  239. * Values: <list of XENSND_PCM_FORMAT_XXX_STR>
  240. *
  241. * List of supported sample formats separated by XENSND_LIST_SEPARATOR.
  242. * Items must not exceed XENSND_SAMPLE_FORMAT_MAX_LEN length.
  243. *
  244. * buffer-size
  245. * Values: <uint32_t>
  246. *
  247. * The maximum size in octets of the buffer to allocate per stream.
  248. *
  249. *----------------------- Virtual sound card settings -------------------------
  250. * short-name
  251. * Values: <char[32]>
  252. *
  253. * Short name of the virtual sound card. Optional.
  254. *
  255. * long-name
  256. * Values: <char[80]>
  257. *
  258. * Long name of the virtual sound card. Optional.
  259. *
  260. *----------------------------- Device settings -------------------------------
  261. * name
  262. * Values: <char[80]>
  263. *
  264. * Name of the sound device within the virtual sound card. Optional.
  265. *
  266. *----------------------------- Stream settings -------------------------------
  267. *
  268. * type
  269. * Values: "p", "c"
  270. *
  271. * Stream type: "p" - playback stream, "c" - capture stream
  272. *
  273. * If both capture and playback are needed then two streams need to be
  274. * defined under the same device.
  275. *
  276. * unique-id
  277. * Values: <uint32_t>
  278. *
  279. * After stream initialization it is assigned a unique ID (within the front
  280. * driver), so every stream of the frontend can be identified by the
  281. * backend by this ID. This is not equal to stream-idx as the later is
  282. * zero based within the device, but this index is contigous within the
  283. * driver.
  284. *
  285. *-------------------- Stream Request Transport Parameters --------------------
  286. *
  287. * event-channel
  288. * Values: <uint32_t>
  289. *
  290. * The identifier of the Xen event channel used to signal activity
  291. * in the ring buffer.
  292. *
  293. * ring-ref
  294. * Values: <uint32_t>
  295. *
  296. * The Xen grant reference granting permission for the backend to map
  297. * a sole page in a single page sized ring buffer.
  298. *
  299. *--------------------- Stream Event Transport Parameters ---------------------
  300. *
  301. * This communication path is used to deliver asynchronous events from backend
  302. * to frontend, set up per stream.
  303. *
  304. * evt-event-channel
  305. * Values: <uint32_t>
  306. *
  307. * The identifier of the Xen event channel used to signal activity
  308. * in the ring buffer.
  309. *
  310. * evt-ring-ref
  311. * Values: <uint32_t>
  312. *
  313. * The Xen grant reference granting permission for the backend to map
  314. * a sole page in a single page sized ring buffer.
  315. *
  316. ******************************************************************************
  317. * STATE DIAGRAMS
  318. ******************************************************************************
  319. *
  320. * Tool stack creates front and back state nodes with initial state
  321. * XenbusStateInitialising.
  322. * Tool stack creates and sets up frontend sound configuration nodes per domain.
  323. *
  324. * Front Back
  325. * ================================= =====================================
  326. * XenbusStateInitialising XenbusStateInitialising
  327. * o Query backend device identification
  328. * data.
  329. * o Open and validate backend device.
  330. * |
  331. * |
  332. * V
  333. * XenbusStateInitWait
  334. *
  335. * o Query frontend configuration
  336. * o Allocate and initialize
  337. * event channels per configured
  338. * playback/capture stream.
  339. * o Publish transport parameters
  340. * that will be in effect during
  341. * this connection.
  342. * |
  343. * |
  344. * V
  345. * XenbusStateInitialised
  346. *
  347. * o Query frontend transport parameters.
  348. * o Connect to the event channels.
  349. * |
  350. * |
  351. * V
  352. * XenbusStateConnected
  353. *
  354. * o Create and initialize OS
  355. * virtual sound device instances
  356. * as per configuration.
  357. * |
  358. * |
  359. * V
  360. * XenbusStateConnected
  361. *
  362. * XenbusStateUnknown
  363. * XenbusStateClosed
  364. * XenbusStateClosing
  365. * o Remove virtual sound device
  366. * o Remove event channels
  367. * |
  368. * |
  369. * V
  370. * XenbusStateClosed
  371. *
  372. *------------------------------- Recovery flow -------------------------------
  373. *
  374. * In case of frontend unrecoverable errors backend handles that as
  375. * if frontend goes into the XenbusStateClosed state.
  376. *
  377. * In case of backend unrecoverable errors frontend tries removing
  378. * the virtualized device. If this is possible at the moment of error,
  379. * then frontend goes into the XenbusStateInitialising state and is ready for
  380. * new connection with backend. If the virtualized device is still in use and
  381. * cannot be removed, then frontend goes into the XenbusStateReconfiguring state
  382. * until either the virtualized device removed or backend initiates a new
  383. * connection. On the virtualized device removal frontend goes into the
  384. * XenbusStateInitialising state.
  385. *
  386. * Note on XenbusStateReconfiguring state of the frontend: if backend has
  387. * unrecoverable errors then frontend cannot send requests to the backend
  388. * and thus cannot provide functionality of the virtualized device anymore.
  389. * After backend is back to normal the virtualized device may still hold some
  390. * state: configuration in use, allocated buffers, client application state etc.
  391. * So, in most cases, this will require frontend to implement complex recovery
  392. * reconnect logic. Instead, by going into XenbusStateReconfiguring state,
  393. * frontend will make sure no new clients of the virtualized device are
  394. * accepted, allow existing client(s) to exit gracefully by signaling error
  395. * state etc.
  396. * Once all the clients are gone frontend can reinitialize the virtualized
  397. * device and get into XenbusStateInitialising state again signaling the
  398. * backend that a new connection can be made.
  399. *
  400. * There are multiple conditions possible under which frontend will go from
  401. * XenbusStateReconfiguring into XenbusStateInitialising, some of them are OS
  402. * specific. For example:
  403. * 1. The underlying OS framework may provide callbacks to signal that the last
  404. * client of the virtualized device has gone and the device can be removed
  405. * 2. Frontend can schedule a deferred work (timer/tasklet/workqueue)
  406. * to periodically check if this is the right time to re-try removal of
  407. * the virtualized device.
  408. * 3. By any other means.
  409. *
  410. ******************************************************************************
  411. * PCM FORMATS
  412. ******************************************************************************
  413. *
  414. * XENSND_PCM_FORMAT_<format>[_<endian>]
  415. *
  416. * format: <S/U/F><bits> or <name>
  417. * S - signed, U - unsigned, F - float
  418. * bits - 8, 16, 24, 32
  419. * name - MU_LAW, GSM, etc.
  420. *
  421. * endian: <LE/BE>, may be absent
  422. * LE - Little endian, BE - Big endian
  423. */
  424. #define XENSND_PCM_FORMAT_S8 0
  425. #define XENSND_PCM_FORMAT_U8 1
  426. #define XENSND_PCM_FORMAT_S16_LE 2
  427. #define XENSND_PCM_FORMAT_S16_BE 3
  428. #define XENSND_PCM_FORMAT_U16_LE 4
  429. #define XENSND_PCM_FORMAT_U16_BE 5
  430. #define XENSND_PCM_FORMAT_S24_LE 6
  431. #define XENSND_PCM_FORMAT_S24_BE 7
  432. #define XENSND_PCM_FORMAT_U24_LE 8
  433. #define XENSND_PCM_FORMAT_U24_BE 9
  434. #define XENSND_PCM_FORMAT_S32_LE 10
  435. #define XENSND_PCM_FORMAT_S32_BE 11
  436. #define XENSND_PCM_FORMAT_U32_LE 12
  437. #define XENSND_PCM_FORMAT_U32_BE 13
  438. #define XENSND_PCM_FORMAT_F32_LE 14 /* 4-byte float, IEEE-754 32-bit, */
  439. #define XENSND_PCM_FORMAT_F32_BE 15 /* range -1.0 to 1.0 */
  440. #define XENSND_PCM_FORMAT_F64_LE 16 /* 8-byte float, IEEE-754 64-bit, */
  441. #define XENSND_PCM_FORMAT_F64_BE 17 /* range -1.0 to 1.0 */
  442. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE 18
  443. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE 19
  444. #define XENSND_PCM_FORMAT_MU_LAW 20
  445. #define XENSND_PCM_FORMAT_A_LAW 21
  446. #define XENSND_PCM_FORMAT_IMA_ADPCM 22
  447. #define XENSND_PCM_FORMAT_MPEG 23
  448. #define XENSND_PCM_FORMAT_GSM 24
  449. /*
  450. ******************************************************************************
  451. * REQUEST CODES
  452. ******************************************************************************
  453. */
  454. #define XENSND_OP_OPEN 0
  455. #define XENSND_OP_CLOSE 1
  456. #define XENSND_OP_READ 2
  457. #define XENSND_OP_WRITE 3
  458. #define XENSND_OP_SET_VOLUME 4
  459. #define XENSND_OP_GET_VOLUME 5
  460. #define XENSND_OP_MUTE 6
  461. #define XENSND_OP_UNMUTE 7
  462. #define XENSND_OP_TRIGGER 8
  463. #define XENSND_OP_HW_PARAM_QUERY 9
  464. #define XENSND_OP_TRIGGER_START 0
  465. #define XENSND_OP_TRIGGER_PAUSE 1
  466. #define XENSND_OP_TRIGGER_STOP 2
  467. #define XENSND_OP_TRIGGER_RESUME 3
  468. /*
  469. ******************************************************************************
  470. * EVENT CODES
  471. ******************************************************************************
  472. */
  473. #define XENSND_EVT_CUR_POS 0
  474. /*
  475. ******************************************************************************
  476. * XENSTORE FIELD AND PATH NAME STRINGS, HELPERS
  477. ******************************************************************************
  478. */
  479. #define XENSND_DRIVER_NAME "vsnd"
  480. #define XENSND_LIST_SEPARATOR ","
  481. /* Field names */
  482. #define XENSND_FIELD_BE_VERSIONS "versions"
  483. #define XENSND_FIELD_FE_VERSION "version"
  484. #define XENSND_FIELD_VCARD_SHORT_NAME "short-name"
  485. #define XENSND_FIELD_VCARD_LONG_NAME "long-name"
  486. #define XENSND_FIELD_RING_REF "ring-ref"
  487. #define XENSND_FIELD_EVT_CHNL "event-channel"
  488. #define XENSND_FIELD_EVT_RING_REF "evt-ring-ref"
  489. #define XENSND_FIELD_EVT_EVT_CHNL "evt-event-channel"
  490. #define XENSND_FIELD_DEVICE_NAME "name"
  491. #define XENSND_FIELD_TYPE "type"
  492. #define XENSND_FIELD_STREAM_UNIQUE_ID "unique-id"
  493. #define XENSND_FIELD_CHANNELS_MIN "channels-min"
  494. #define XENSND_FIELD_CHANNELS_MAX "channels-max"
  495. #define XENSND_FIELD_SAMPLE_RATES "sample-rates"
  496. #define XENSND_FIELD_SAMPLE_FORMATS "sample-formats"
  497. #define XENSND_FIELD_BUFFER_SIZE "buffer-size"
  498. /* Stream type field values. */
  499. #define XENSND_STREAM_TYPE_PLAYBACK "p"
  500. #define XENSND_STREAM_TYPE_CAPTURE "c"
  501. /* Sample rate max string length */
  502. #define XENSND_SAMPLE_RATE_MAX_LEN 11
  503. /* Sample format field values */
  504. #define XENSND_SAMPLE_FORMAT_MAX_LEN 24
  505. #define XENSND_PCM_FORMAT_S8_STR "s8"
  506. #define XENSND_PCM_FORMAT_U8_STR "u8"
  507. #define XENSND_PCM_FORMAT_S16_LE_STR "s16_le"
  508. #define XENSND_PCM_FORMAT_S16_BE_STR "s16_be"
  509. #define XENSND_PCM_FORMAT_U16_LE_STR "u16_le"
  510. #define XENSND_PCM_FORMAT_U16_BE_STR "u16_be"
  511. #define XENSND_PCM_FORMAT_S24_LE_STR "s24_le"
  512. #define XENSND_PCM_FORMAT_S24_BE_STR "s24_be"
  513. #define XENSND_PCM_FORMAT_U24_LE_STR "u24_le"
  514. #define XENSND_PCM_FORMAT_U24_BE_STR "u24_be"
  515. #define XENSND_PCM_FORMAT_S32_LE_STR "s32_le"
  516. #define XENSND_PCM_FORMAT_S32_BE_STR "s32_be"
  517. #define XENSND_PCM_FORMAT_U32_LE_STR "u32_le"
  518. #define XENSND_PCM_FORMAT_U32_BE_STR "u32_be"
  519. #define XENSND_PCM_FORMAT_F32_LE_STR "float_le"
  520. #define XENSND_PCM_FORMAT_F32_BE_STR "float_be"
  521. #define XENSND_PCM_FORMAT_F64_LE_STR "float64_le"
  522. #define XENSND_PCM_FORMAT_F64_BE_STR "float64_be"
  523. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE_STR "iec958_subframe_le"
  524. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE_STR "iec958_subframe_be"
  525. #define XENSND_PCM_FORMAT_MU_LAW_STR "mu_law"
  526. #define XENSND_PCM_FORMAT_A_LAW_STR "a_law"
  527. #define XENSND_PCM_FORMAT_IMA_ADPCM_STR "ima_adpcm"
  528. #define XENSND_PCM_FORMAT_MPEG_STR "mpeg"
  529. #define XENSND_PCM_FORMAT_GSM_STR "gsm"
  530. /*
  531. ******************************************************************************
  532. * STATUS RETURN CODES
  533. ******************************************************************************
  534. *
  535. * Status return code is zero on success and -XEN_EXX on failure.
  536. *
  537. ******************************************************************************
  538. * Assumptions
  539. ******************************************************************************
  540. * o usage of grant reference 0 as invalid grant reference:
  541. * grant reference 0 is valid, but never exposed to a PV driver,
  542. * because of the fact it is already in use/reserved by the PV console.
  543. * o all references in this document to page sizes must be treated
  544. * as pages of size XEN_PAGE_SIZE unless otherwise noted.
  545. *
  546. ******************************************************************************
  547. * Description of the protocol between frontend and backend driver
  548. ******************************************************************************
  549. *
  550. * The two halves of a Para-virtual sound driver communicate with
  551. * each other using shared pages and event channels.
  552. * Shared page contains a ring with request/response packets.
  553. *
  554. * Packets, used for input/output operations, e.g. read/write, set/get volume,
  555. * etc., provide offset/length fields in order to allow asynchronous protocol
  556. * operation with buffer space sharing: part of the buffer allocated at
  557. * XENSND_OP_OPEN can be used for audio samples and part, for example,
  558. * for volume control.
  559. *
  560. * All reserved fields in the structures below must be 0.
  561. *
  562. *---------------------------------- Requests ---------------------------------
  563. *
  564. * All request packets have the same length (64 octets)
  565. * All request packets have common header:
  566. * 0 1 2 3 octet
  567. * +----------------+----------------+----------------+----------------+
  568. * | id | operation | reserved | 4
  569. * +----------------+----------------+----------------+----------------+
  570. * | reserved | 8
  571. * +----------------+----------------+----------------+----------------+
  572. * id - uint16_t, private guest value, echoed in response
  573. * operation - uint8_t, operation code, XENSND_OP_???
  574. *
  575. * For all packets which use offset and length:
  576. * offset - uint32_t, read or write data offset within the shared buffer,
  577. * passed with XENSND_OP_OPEN request, octets,
  578. * [0; XENSND_OP_OPEN.buffer_sz - 1].
  579. * length - uint32_t, read or write data length, octets
  580. *
  581. * Request open - open a PCM stream for playback or capture:
  582. *
  583. * 0 1 2 3 octet
  584. * +----------------+----------------+----------------+----------------+
  585. * | id | XENSND_OP_OPEN | reserved | 4
  586. * +----------------+----------------+----------------+----------------+
  587. * | reserved | 8
  588. * +----------------+----------------+----------------+----------------+
  589. * | pcm_rate | 12
  590. * +----------------+----------------+----------------+----------------+
  591. * | pcm_format | pcm_channels | reserved | 16
  592. * +----------------+----------------+----------------+----------------+
  593. * | buffer_sz | 20
  594. * +----------------+----------------+----------------+----------------+
  595. * | gref_directory | 24
  596. * +----------------+----------------+----------------+----------------+
  597. * | period_sz | 28
  598. * +----------------+----------------+----------------+----------------+
  599. * | reserved | 32
  600. * +----------------+----------------+----------------+----------------+
  601. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  602. * +----------------+----------------+----------------+----------------+
  603. * | reserved | 64
  604. * +----------------+----------------+----------------+----------------+
  605. *
  606. * pcm_rate - uint32_t, stream data rate, Hz
  607. * pcm_format - uint8_t, XENSND_PCM_FORMAT_XXX value
  608. * pcm_channels - uint8_t, number of channels of this stream,
  609. * [channels-min; channels-max]
  610. * buffer_sz - uint32_t, buffer size to be allocated, octets
  611. * period_sz - uint32_t, event period size, octets
  612. * This is the requested value of the period at which frontend would
  613. * like to receive XENSND_EVT_CUR_POS notifications from the backend when
  614. * stream position advances during playback/capture.
  615. * It shows how many octets are expected to be played/captured before
  616. * sending such an event.
  617. * If set to 0 no XENSND_EVT_CUR_POS events are sent by the backend.
  618. *
  619. * gref_directory - grant_ref_t, a reference to the first shared page
  620. * describing shared buffer references. At least one page exists. If shared
  621. * buffer size (buffer_sz) exceeds what can be addressed by this single page,
  622. * then reference to the next page must be supplied (see gref_dir_next_page
  623. * below)
  624. */
  625. struct xensnd_open_req {
  626. uint32_t pcm_rate;
  627. uint8_t pcm_format;
  628. uint8_t pcm_channels;
  629. uint16_t reserved;
  630. uint32_t buffer_sz;
  631. grant_ref_t gref_directory;
  632. uint32_t period_sz;
  633. };
  634. /*
  635. * Shared page for XENSND_OP_OPEN buffer descriptor (gref_directory in the
  636. * request) employs a list of pages, describing all pages of the shared data
  637. * buffer:
  638. * 0 1 2 3 octet
  639. * +----------------+----------------+----------------+----------------+
  640. * | gref_dir_next_page | 4
  641. * +----------------+----------------+----------------+----------------+
  642. * | gref[0] | 8
  643. * +----------------+----------------+----------------+----------------+
  644. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  645. * +----------------+----------------+----------------+----------------+
  646. * | gref[i] | i*4+8
  647. * +----------------+----------------+----------------+----------------+
  648. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  649. * +----------------+----------------+----------------+----------------+
  650. * | gref[N - 1] | N*4+8
  651. * +----------------+----------------+----------------+----------------+
  652. *
  653. * gref_dir_next_page - grant_ref_t, reference to the next page describing
  654. * page directory. Must be 0 if there are no more pages in the list.
  655. * gref[i] - grant_ref_t, reference to a shared page of the buffer
  656. * allocated at XENSND_OP_OPEN
  657. *
  658. * Number of grant_ref_t entries in the whole page directory is not
  659. * passed, but instead can be calculated as:
  660. * num_grefs_total = (XENSND_OP_OPEN.buffer_sz + XEN_PAGE_SIZE - 1) /
  661. * XEN_PAGE_SIZE
  662. */
  663. struct xensnd_page_directory {
  664. grant_ref_t gref_dir_next_page;
  665. grant_ref_t gref[1]; /* Variable length */
  666. };
  667. /*
  668. * Request close - close an opened pcm stream:
  669. * 0 1 2 3 octet
  670. * +----------------+----------------+----------------+----------------+
  671. * | id | XENSND_OP_CLOSE| reserved | 4
  672. * +----------------+----------------+----------------+----------------+
  673. * | reserved | 8
  674. * +----------------+----------------+----------------+----------------+
  675. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  676. * +----------------+----------------+----------------+----------------+
  677. * | reserved | 64
  678. * +----------------+----------------+----------------+----------------+
  679. *
  680. * Request read/write - used for read (for capture) or write (for playback):
  681. * 0 1 2 3 octet
  682. * +----------------+----------------+----------------+----------------+
  683. * | id | operation | reserved | 4
  684. * +----------------+----------------+----------------+----------------+
  685. * | reserved | 8
  686. * +----------------+----------------+----------------+----------------+
  687. * | offset | 12
  688. * +----------------+----------------+----------------+----------------+
  689. * | length | 16
  690. * +----------------+----------------+----------------+----------------+
  691. * | reserved | 20
  692. * +----------------+----------------+----------------+----------------+
  693. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  694. * +----------------+----------------+----------------+----------------+
  695. * | reserved | 64
  696. * +----------------+----------------+----------------+----------------+
  697. *
  698. * operation - XENSND_OP_READ for read or XENSND_OP_WRITE for write
  699. */
  700. struct xensnd_rw_req {
  701. uint32_t offset;
  702. uint32_t length;
  703. };
  704. /*
  705. * Request set/get volume - set/get channels' volume of the stream given:
  706. * 0 1 2 3 octet
  707. * +----------------+----------------+----------------+----------------+
  708. * | id | operation | reserved | 4
  709. * +----------------+----------------+----------------+----------------+
  710. * | reserved | 8
  711. * +----------------+----------------+----------------+----------------+
  712. * | offset | 12
  713. * +----------------+----------------+----------------+----------------+
  714. * | length | 16
  715. * +----------------+----------------+----------------+----------------+
  716. * | reserved | 20
  717. * +----------------+----------------+----------------+----------------+
  718. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  719. * +----------------+----------------+----------------+----------------+
  720. * | reserved | 64
  721. * +----------------+----------------+----------------+----------------+
  722. *
  723. * operation - XENSND_OP_SET_VOLUME for volume set
  724. * or XENSND_OP_GET_VOLUME for volume get
  725. * Buffer passed with XENSND_OP_OPEN is used to exchange volume
  726. * values:
  727. *
  728. * 0 1 2 3 octet
  729. * +----------------+----------------+----------------+----------------+
  730. * | channel[0] | 4
  731. * +----------------+----------------+----------------+----------------+
  732. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  733. * +----------------+----------------+----------------+----------------+
  734. * | channel[i] | i*4
  735. * +----------------+----------------+----------------+----------------+
  736. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  737. * +----------------+----------------+----------------+----------------+
  738. * | channel[N - 1] | (N-1)*4
  739. * +----------------+----------------+----------------+----------------+
  740. *
  741. * N = XENSND_OP_OPEN.pcm_channels
  742. * i - uint8_t, index of a channel
  743. * channel[i] - sint32_t, volume of i-th channel
  744. * Volume is expressed as a signed value in steps of 0.001 dB,
  745. * while 0 being 0 dB.
  746. *
  747. * Request mute/unmute - mute/unmute stream:
  748. * 0 1 2 3 octet
  749. * +----------------+----------------+----------------+----------------+
  750. * | id | operation | reserved | 4
  751. * +----------------+----------------+----------------+----------------+
  752. * | reserved | 8
  753. * +----------------+----------------+----------------+----------------+
  754. * | offset | 12
  755. * +----------------+----------------+----------------+----------------+
  756. * | length | 16
  757. * +----------------+----------------+----------------+----------------+
  758. * | reserved | 20
  759. * +----------------+----------------+----------------+----------------+
  760. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  761. * +----------------+----------------+----------------+----------------+
  762. * | reserved | 64
  763. * +----------------+----------------+----------------+----------------+
  764. *
  765. * operation - XENSND_OP_MUTE for mute or XENSND_OP_UNMUTE for unmute
  766. * Buffer passed with XENSND_OP_OPEN is used to exchange mute/unmute
  767. * values:
  768. *
  769. * 0 octet
  770. * +----------------+----------------+----------------+----------------+
  771. * | channel[0] | 4
  772. * +----------------+----------------+----------------+----------------+
  773. * +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  774. * +----------------+----------------+----------------+----------------+
  775. * | channel[i] | i*4
  776. * +----------------+----------------+----------------+----------------+
  777. * +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  778. * +----------------+----------------+----------------+----------------+
  779. * | channel[N - 1] | (N-1)*4
  780. * +----------------+----------------+----------------+----------------+
  781. *
  782. * N = XENSND_OP_OPEN.pcm_channels
  783. * i - uint8_t, index of a channel
  784. * channel[i] - uint8_t, non-zero if i-th channel needs to be muted/unmuted
  785. *
  786. *------------------------------------ N.B. -----------------------------------
  787. *
  788. * The 'struct xensnd_rw_req' is also used for XENSND_OP_SET_VOLUME,
  789. * XENSND_OP_GET_VOLUME, XENSND_OP_MUTE, XENSND_OP_UNMUTE.
  790. *
  791. * Request stream running state change - trigger PCM stream running state
  792. * to start, stop, pause or resume:
  793. *
  794. * 0 1 2 3 octet
  795. * +----------------+----------------+----------------+----------------+
  796. * | id | _OP_TRIGGER | reserved | 4
  797. * +----------------+----------------+----------------+----------------+
  798. * | reserved | 8
  799. * +----------------+----------------+----------------+----------------+
  800. * | type | reserved | 12
  801. * +----------------+----------------+----------------+----------------+
  802. * | reserved | 16
  803. * +----------------+----------------+----------------+----------------+
  804. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  805. * +----------------+----------------+----------------+----------------+
  806. * | reserved | 64
  807. * +----------------+----------------+----------------+----------------+
  808. *
  809. * type - uint8_t, XENSND_OP_TRIGGER_XXX value
  810. */
  811. struct xensnd_trigger_req {
  812. uint8_t type;
  813. };
  814. /*
  815. * Request stream parameter ranges: request intervals and
  816. * masks of supported ranges for stream configuration values.
  817. *
  818. * Sound device configuration for a particular stream is a limited subset
  819. * of the multidimensional configuration available on XenStore, e.g.
  820. * once the frame rate has been selected there is a limited supported range
  821. * for sample rates becomes available (which might be the same set configured
  822. * on XenStore or less). For example, selecting 96kHz sample rate may limit
  823. * number of channels available for such configuration from 4 to 2, etc.
  824. * Thus, each call to XENSND_OP_HW_PARAM_QUERY may reduce configuration
  825. * space making it possible to iteratively get the final stream configuration,
  826. * used in XENSND_OP_OPEN request.
  827. *
  828. * See response format for this request.
  829. *
  830. * 0 1 2 3 octet
  831. * +----------------+----------------+----------------+----------------+
  832. * | id | _HW_PARAM_QUERY| reserved | 4
  833. * +----------------+----------------+----------------+----------------+
  834. * | reserved | 8
  835. * +----------------+----------------+----------------+----------------+
  836. * | formats mask low 32-bit | 12
  837. * +----------------+----------------+----------------+----------------+
  838. * | formats mask high 32-bit | 16
  839. * +----------------+----------------+----------------+----------------+
  840. * | min rate | 20
  841. * +----------------+----------------+----------------+----------------+
  842. * | max rate | 24
  843. * +----------------+----------------+----------------+----------------+
  844. * | min channels | 28
  845. * +----------------+----------------+----------------+----------------+
  846. * | max channels | 32
  847. * +----------------+----------------+----------------+----------------+
  848. * | min buffer frames | 36
  849. * +----------------+----------------+----------------+----------------+
  850. * | max buffer frames | 40
  851. * +----------------+----------------+----------------+----------------+
  852. * | min period frames | 44
  853. * +----------------+----------------+----------------+----------------+
  854. * | max period frames | 48
  855. * +----------------+----------------+----------------+----------------+
  856. * | reserved | 52
  857. * +----------------+----------------+----------------+----------------+
  858. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  859. * +----------------+----------------+----------------+----------------+
  860. * | reserved | 64
  861. * +----------------+----------------+----------------+----------------+
  862. *
  863. * formats - uint64_t, bit mask representing values of the parameter
  864. * made as bitwise OR of (1 << XENSND_PCM_FORMAT_XXX) values
  865. *
  866. * For interval parameters:
  867. * min - uint32_t, minimum value of the parameter
  868. * max - uint32_t, maximum value of the parameter
  869. *
  870. * Frame is defined as a product of the number of channels by the
  871. * number of octets per one sample.
  872. */
  873. struct xensnd_query_hw_param {
  874. uint64_t formats;
  875. struct {
  876. uint32_t min;
  877. uint32_t max;
  878. } rates;
  879. struct {
  880. uint32_t min;
  881. uint32_t max;
  882. } channels;
  883. struct {
  884. uint32_t min;
  885. uint32_t max;
  886. } buffer;
  887. struct {
  888. uint32_t min;
  889. uint32_t max;
  890. } period;
  891. };
  892. /*
  893. *---------------------------------- Responses --------------------------------
  894. *
  895. * All response packets have the same length (64 octets)
  896. *
  897. * All response packets have common header:
  898. * 0 1 2 3 octet
  899. * +----------------+----------------+----------------+----------------+
  900. * | id | operation | reserved | 4
  901. * +----------------+----------------+----------------+----------------+
  902. * | status | 8
  903. * +----------------+----------------+----------------+----------------+
  904. *
  905. * id - uint16_t, copied from the request
  906. * operation - uint8_t, XENSND_OP_* - copied from request
  907. * status - int32_t, response status, zero on success and -XEN_EXX on failure
  908. *
  909. *
  910. * HW parameter query response - response for XENSND_OP_HW_PARAM_QUERY:
  911. * 0 1 2 3 octet
  912. * +----------------+----------------+----------------+----------------+
  913. * | id | operation | reserved | 4
  914. * +----------------+----------------+----------------+----------------+
  915. * | status | 8
  916. * +----------------+----------------+----------------+----------------+
  917. * | formats mask low 32-bit | 12
  918. * +----------------+----------------+----------------+----------------+
  919. * | formats mask high 32-bit | 16
  920. * +----------------+----------------+----------------+----------------+
  921. * | min rate | 20
  922. * +----------------+----------------+----------------+----------------+
  923. * | max rate | 24
  924. * +----------------+----------------+----------------+----------------+
  925. * | min channels | 28
  926. * +----------------+----------------+----------------+----------------+
  927. * | max channels | 32
  928. * +----------------+----------------+----------------+----------------+
  929. * | min buffer frames | 36
  930. * +----------------+----------------+----------------+----------------+
  931. * | max buffer frames | 40
  932. * +----------------+----------------+----------------+----------------+
  933. * | min period frames | 44
  934. * +----------------+----------------+----------------+----------------+
  935. * | max period frames | 48
  936. * +----------------+----------------+----------------+----------------+
  937. * | reserved | 52
  938. * +----------------+----------------+----------------+----------------+
  939. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  940. * +----------------+----------------+----------------+----------------+
  941. * | reserved | 64
  942. * +----------------+----------------+----------------+----------------+
  943. *
  944. * Meaning of the values in this response is the same as for
  945. * XENSND_OP_HW_PARAM_QUERY request.
  946. */
  947. /*
  948. *----------------------------------- Events ----------------------------------
  949. *
  950. * Events are sent via shared page allocated by the front and propagated by
  951. * evt-event-channel/evt-ring-ref XenStore entries
  952. * All event packets have the same length (64 octets)
  953. * All event packets have common header:
  954. * 0 1 2 3 octet
  955. * +----------------+----------------+----------------+----------------+
  956. * | id | type | reserved | 4
  957. * +----------------+----------------+----------------+----------------+
  958. * | reserved | 8
  959. * +----------------+----------------+----------------+----------------+
  960. *
  961. * id - uint16_t, event id, may be used by front
  962. * type - uint8_t, type of the event
  963. *
  964. *
  965. * Current stream position - event from back to front when stream's
  966. * playback/capture position has advanced:
  967. * 0 1 2 3 octet
  968. * +----------------+----------------+----------------+----------------+
  969. * | id | _EVT_CUR_POS | reserved | 4
  970. * +----------------+----------------+----------------+----------------+
  971. * | reserved | 8
  972. * +----------------+----------------+----------------+----------------+
  973. * | position low 32-bit | 12
  974. * +----------------+----------------+----------------+----------------+
  975. * | position high 32-bit | 16
  976. * +----------------+----------------+----------------+----------------+
  977. * | reserved | 20
  978. * +----------------+----------------+----------------+----------------+
  979. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  980. * +----------------+----------------+----------------+----------------+
  981. * | reserved | 64
  982. * +----------------+----------------+----------------+----------------+
  983. *
  984. * position - current value of stream's playback/capture position, octets
  985. *
  986. */
  987. struct xensnd_cur_pos_evt {
  988. uint64_t position;
  989. };
  990. struct xensnd_req {
  991. uint16_t id;
  992. uint8_t operation;
  993. uint8_t reserved[5];
  994. union {
  995. struct xensnd_open_req open;
  996. struct xensnd_rw_req rw;
  997. struct xensnd_trigger_req trigger;
  998. struct xensnd_query_hw_param hw_param;
  999. uint8_t reserved[56];
  1000. } op;
  1001. };
  1002. struct xensnd_resp {
  1003. uint16_t id;
  1004. uint8_t operation;
  1005. uint8_t reserved;
  1006. int32_t status;
  1007. union {
  1008. struct xensnd_query_hw_param hw_param;
  1009. uint8_t reserved1[56];
  1010. } resp;
  1011. };
  1012. struct xensnd_evt {
  1013. uint16_t id;
  1014. uint8_t type;
  1015. uint8_t reserved[5];
  1016. union {
  1017. struct xensnd_cur_pos_evt cur_pos;
  1018. uint8_t reserved[56];
  1019. } op;
  1020. };
  1021. DEFINE_RING_TYPES(xen_sndif, struct xensnd_req, struct xensnd_resp);
  1022. /*
  1023. ******************************************************************************
  1024. * Back to front events delivery
  1025. ******************************************************************************
  1026. * In order to deliver asynchronous events from back to front a shared page is
  1027. * allocated by front and its granted reference propagated to back via
  1028. * XenStore entries (evt-ring-ref/evt-event-channel).
  1029. * This page has a common header used by both front and back to synchronize
  1030. * access and control event's ring buffer, while back being a producer of the
  1031. * events and front being a consumer. The rest of the page after the header
  1032. * is used for event packets.
  1033. *
  1034. * Upon reception of an event(s) front may confirm its reception
  1035. * for either each event, group of events or none.
  1036. */
  1037. struct xensnd_event_page {
  1038. uint32_t in_cons;
  1039. uint32_t in_prod;
  1040. uint8_t reserved[56];
  1041. };
  1042. #define XENSND_EVENT_PAGE_SIZE XEN_PAGE_SIZE
  1043. #define XENSND_IN_RING_OFFS (sizeof(struct xensnd_event_page))
  1044. #define XENSND_IN_RING_SIZE (XENSND_EVENT_PAGE_SIZE - XENSND_IN_RING_OFFS)
  1045. #define XENSND_IN_RING_LEN (XENSND_IN_RING_SIZE / sizeof(struct xensnd_evt))
  1046. #define XENSND_IN_RING(page) \
  1047. ((struct xensnd_evt *)((char *)(page) + XENSND_IN_RING_OFFS))
  1048. #define XENSND_IN_RING_REF(page, idx) \
  1049. (XENSND_IN_RING((page))[(idx) % XENSND_IN_RING_LEN])
  1050. #endif /* __XEN_PUBLIC_IO_SNDIF_H__ */