sndif.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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. * Feature and Parameter Negotiation
  39. ******************************************************************************
  40. *
  41. * Front->back notifications: when enqueuing a new request, sending a
  42. * notification can be made conditional on xensnd_req (i.e., the generic
  43. * hold-off mechanism provided by the ring macros). Backends must set
  44. * xensnd_req appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
  45. *
  46. * Back->front notifications: when enqueuing a new response, sending a
  47. * notification can be made conditional on xensnd_resp (i.e., the generic
  48. * hold-off mechanism provided by the ring macros). Frontends must set
  49. * xensnd_resp appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
  50. *
  51. * The two halves of a para-virtual sound card driver utilize nodes within
  52. * XenStore to communicate capabilities and to negotiate operating parameters.
  53. * This section enumerates these nodes which reside in the respective front and
  54. * backend portions of XenStore, following the XenBus convention.
  55. *
  56. * All data in XenStore is stored as strings. Nodes specifying numeric
  57. * values are encoded in decimal. Integer value ranges listed below are
  58. * expressed as fixed sized integer types capable of storing the conversion
  59. * of a properly formated node string, without loss of information.
  60. *
  61. ******************************************************************************
  62. * Example configuration
  63. ******************************************************************************
  64. *
  65. * Note: depending on the use-case backend can expose more sound cards and
  66. * PCM devices/streams than the underlying HW physically has by employing
  67. * SW mixers, configuring virtual sound streams, channels etc.
  68. *
  69. * This is an example of backend and frontend configuration:
  70. *
  71. *--------------------------------- Backend -----------------------------------
  72. *
  73. * /local/domain/0/backend/vsnd/1/0/frontend-id = "1"
  74. * /local/domain/0/backend/vsnd/1/0/frontend = "/local/domain/1/device/vsnd/0"
  75. * /local/domain/0/backend/vsnd/1/0/state = "4"
  76. * /local/domain/0/backend/vsnd/1/0/versions = "1,2"
  77. *
  78. *--------------------------------- Frontend ----------------------------------
  79. *
  80. * /local/domain/1/device/vsnd/0/backend-id = "0"
  81. * /local/domain/1/device/vsnd/0/backend = "/local/domain/0/backend/vsnd/1/0"
  82. * /local/domain/1/device/vsnd/0/state = "4"
  83. * /local/domain/1/device/vsnd/0/version = "1"
  84. *
  85. *----------------------------- Card configuration ----------------------------
  86. *
  87. * /local/domain/1/device/vsnd/0/short-name = "Card short name"
  88. * /local/domain/1/device/vsnd/0/long-name = "Card long name"
  89. * /local/domain/1/device/vsnd/0/sample-rates = "8000,32000,44100,48000,96000"
  90. * /local/domain/1/device/vsnd/0/sample-formats = "s8,u8,s16_le,s16_be"
  91. * /local/domain/1/device/vsnd/0/buffer-size = "262144"
  92. *
  93. *------------------------------- PCM device 0 --------------------------------
  94. *
  95. * /local/domain/1/device/vsnd/0/0/name = "General analog"
  96. * /local/domain/1/device/vsnd/0/0/channels-max = "5"
  97. *
  98. *----------------------------- Stream 0, playback ----------------------------
  99. *
  100. * /local/domain/1/device/vsnd/0/0/0/type = "p"
  101. * /local/domain/1/device/vsnd/0/0/0/sample-formats = "s8,u8"
  102. * /local/domain/1/device/vsnd/0/0/0/unique-id = "0"
  103. *
  104. * /local/domain/1/device/vsnd/0/0/0/ring-ref = "386"
  105. * /local/domain/1/device/vsnd/0/0/0/event-channel = "15"
  106. *
  107. *------------------------------ Stream 1, capture ----------------------------
  108. *
  109. * /local/domain/1/device/vsnd/0/0/1/type = "c"
  110. * /local/domain/1/device/vsnd/0/0/1/channels-max = "2"
  111. * /local/domain/1/device/vsnd/0/0/1/unique-id = "1"
  112. *
  113. * /local/domain/1/device/vsnd/0/0/1/ring-ref = "384"
  114. * /local/domain/1/device/vsnd/0/0/1/event-channel = "13"
  115. *
  116. *------------------------------- PCM device 1 --------------------------------
  117. *
  118. * /local/domain/1/device/vsnd/0/1/name = "HDMI-0"
  119. * /local/domain/1/device/vsnd/0/1/sample-rates = "8000,32000,44100"
  120. *
  121. *------------------------------ Stream 0, capture ----------------------------
  122. *
  123. * /local/domain/1/device/vsnd/0/1/0/type = "c"
  124. * /local/domain/1/device/vsnd/0/1/0/unique-id = "2"
  125. *
  126. * /local/domain/1/device/vsnd/0/1/0/ring-ref = "387"
  127. * /local/domain/1/device/vsnd/0/1/0/event-channel = "151"
  128. *
  129. *------------------------------- PCM device 2 --------------------------------
  130. *
  131. * /local/domain/1/device/vsnd/0/2/name = "SPDIF"
  132. *
  133. *----------------------------- Stream 0, playback ----------------------------
  134. *
  135. * /local/domain/1/device/vsnd/0/2/0/type = "p"
  136. * /local/domain/1/device/vsnd/0/2/0/unique-id = "3"
  137. *
  138. * /local/domain/1/device/vsnd/0/2/0/ring-ref = "389"
  139. * /local/domain/1/device/vsnd/0/2/0/event-channel = "152"
  140. *
  141. ******************************************************************************
  142. * Backend XenBus Nodes
  143. ******************************************************************************
  144. *
  145. *----------------------------- Protocol version ------------------------------
  146. *
  147. * versions
  148. * Values: <string>
  149. *
  150. * List of XENSND_LIST_SEPARATOR separated protocol versions supported
  151. * by the backend. For example "1,2,3".
  152. *
  153. ******************************************************************************
  154. * Frontend XenBus Nodes
  155. ******************************************************************************
  156. *
  157. *-------------------------------- Addressing ---------------------------------
  158. *
  159. * dom-id
  160. * Values: <uint16_t>
  161. *
  162. * Domain identifier.
  163. *
  164. * dev-id
  165. * Values: <uint16_t>
  166. *
  167. * Device identifier.
  168. *
  169. * pcm-dev-idx
  170. * Values: <uint8_t>
  171. *
  172. * Zero based contigous index of the PCM device.
  173. *
  174. * stream-idx
  175. * Values: <uint8_t>
  176. *
  177. * Zero based contigous index of the stream of the PCM device.
  178. *
  179. * The following pattern is used for addressing:
  180. * /local/domain/<dom-id>/device/vsnd/<dev-id>/<pcm-dev-idx>/<stream-idx>/...
  181. *
  182. *----------------------------- Protocol version ------------------------------
  183. *
  184. * version
  185. * Values: <string>
  186. *
  187. * Protocol version, chosen among the ones supported by the backend.
  188. *
  189. *------------------------------- PCM settings --------------------------------
  190. *
  191. * Every virtualized sound frontend has a set of PCM devices and streams, each
  192. * could be individually configured. Part of the PCM configuration can be
  193. * defined at higher level of the hierarchy and be fully or partially re-used
  194. * by the underlying layers. These configuration values are:
  195. * o number of channels (min/max)
  196. * o supported sample rates
  197. * o supported sample formats.
  198. * E.g. one can define these values for the whole card, device or stream.
  199. * Every underlying layer in turn can re-define some or all of them to better
  200. * fit its needs. For example, card may define number of channels to be
  201. * in [1; 8] range, and some particular stream may be limited to [1; 2] only.
  202. * The rule is that the underlying layer must be a subset of the upper layer
  203. * range.
  204. *
  205. * channels-min
  206. * Values: <uint8_t>
  207. *
  208. * The minimum amount of channels that is supported, [1; channels-max].
  209. * Optional, if not set or omitted a value of 1 is used.
  210. *
  211. * channels-max
  212. * Values: <uint8_t>
  213. *
  214. * The maximum amount of channels that is supported.
  215. * Must be at least <channels-min>.
  216. *
  217. * sample-rates
  218. * Values: <list of uint32_t>
  219. *
  220. * List of supported sample rates separated by XENSND_LIST_SEPARATOR.
  221. * Sample rates are expressed as a list of decimal values w/o any
  222. * ordering requirement.
  223. *
  224. * sample-formats
  225. * Values: <list of XENSND_PCM_FORMAT_XXX_STR>
  226. *
  227. * List of supported sample formats separated by XENSND_LIST_SEPARATOR.
  228. * Items must not exceed XENSND_SAMPLE_FORMAT_MAX_LEN length.
  229. *
  230. * buffer-size
  231. * Values: <uint32_t>
  232. *
  233. * The maximum size in octets of the buffer to allocate per stream.
  234. *
  235. *----------------------- Virtual sound card settings -------------------------
  236. * short-name
  237. * Values: <char[32]>
  238. *
  239. * Short name of the virtual sound card. Optional.
  240. *
  241. * long-name
  242. * Values: <char[80]>
  243. *
  244. * Long name of the virtual sound card. Optional.
  245. *
  246. *----------------------------- Device settings -------------------------------
  247. * name
  248. * Values: <char[80]>
  249. *
  250. * Name of the sound device within the virtual sound card. Optional.
  251. *
  252. *----------------------------- Stream settings -------------------------------
  253. *
  254. * type
  255. * Values: "p", "c"
  256. *
  257. * Stream type: "p" - playback stream, "c" - capture stream
  258. *
  259. * If both capture and playback are needed then two streams need to be
  260. * defined under the same device.
  261. *
  262. * unique-id
  263. * Values: <uint32_t>
  264. *
  265. * After stream initialization it is assigned a unique ID (within the front
  266. * driver), so every stream of the frontend can be identified by the
  267. * backend by this ID. This is not equal to stream-idx as the later is
  268. * zero based within the device, but this index is contigous within the
  269. * driver.
  270. *
  271. *-------------------- Stream Request Transport Parameters --------------------
  272. *
  273. * event-channel
  274. * Values: <uint32_t>
  275. *
  276. * The identifier of the Xen event channel used to signal activity
  277. * in the ring buffer.
  278. *
  279. * ring-ref
  280. * Values: <uint32_t>
  281. *
  282. * The Xen grant reference granting permission for the backend to map
  283. * a sole page in a single page sized ring buffer.
  284. *
  285. ******************************************************************************
  286. * STATE DIAGRAMS
  287. ******************************************************************************
  288. *
  289. * Tool stack creates front and back state nodes with initial state
  290. * XenbusStateInitialising.
  291. * Tool stack creates and sets up frontend sound configuration nodes per domain.
  292. *
  293. * Front Back
  294. * ================================= =====================================
  295. * XenbusStateInitialising XenbusStateInitialising
  296. * o Query backend device identification
  297. * data.
  298. * o Open and validate backend device.
  299. * |
  300. * |
  301. * V
  302. * XenbusStateInitWait
  303. *
  304. * o Query frontend configuration
  305. * o Allocate and initialize
  306. * event channels per configured
  307. * playback/capture stream.
  308. * o Publish transport parameters
  309. * that will be in effect during
  310. * this connection.
  311. * |
  312. * |
  313. * V
  314. * XenbusStateInitialised
  315. *
  316. * o Query frontend transport parameters.
  317. * o Connect to the event channels.
  318. * |
  319. * |
  320. * V
  321. * XenbusStateConnected
  322. *
  323. * o Create and initialize OS
  324. * virtual sound device instances
  325. * as per configuration.
  326. * |
  327. * |
  328. * V
  329. * XenbusStateConnected
  330. *
  331. * XenbusStateUnknown
  332. * XenbusStateClosed
  333. * XenbusStateClosing
  334. * o Remove virtual sound device
  335. * o Remove event channels
  336. * |
  337. * |
  338. * V
  339. * XenbusStateClosed
  340. *
  341. *------------------------------- Recovery flow -------------------------------
  342. *
  343. * In case of frontend unrecoverable errors backend handles that as
  344. * if frontend goes into the XenbusStateClosed state.
  345. *
  346. * In case of backend unrecoverable errors frontend tries removing
  347. * the virtualized device. If this is possible at the moment of error,
  348. * then frontend goes into the XenbusStateInitialising state and is ready for
  349. * new connection with backend. If the virtualized device is still in use and
  350. * cannot be removed, then frontend goes into the XenbusStateReconfiguring state
  351. * until either the virtualized device removed or backend initiates a new
  352. * connection. On the virtualized device removal frontend goes into the
  353. * XenbusStateInitialising state.
  354. *
  355. * Note on XenbusStateReconfiguring state of the frontend: if backend has
  356. * unrecoverable errors then frontend cannot send requests to the backend
  357. * and thus cannot provide functionality of the virtualized device anymore.
  358. * After backend is back to normal the virtualized device may still hold some
  359. * state: configuration in use, allocated buffers, client application state etc.
  360. * So, in most cases, this will require frontend to implement complex recovery
  361. * reconnect logic. Instead, by going into XenbusStateReconfiguring state,
  362. * frontend will make sure no new clients of the virtualized device are
  363. * accepted, allow existing client(s) to exit gracefully by signaling error
  364. * state etc.
  365. * Once all the clients are gone frontend can reinitialize the virtualized
  366. * device and get into XenbusStateInitialising state again signaling the
  367. * backend that a new connection can be made.
  368. *
  369. * There are multiple conditions possible under which frontend will go from
  370. * XenbusStateReconfiguring into XenbusStateInitialising, some of them are OS
  371. * specific. For example:
  372. * 1. The underlying OS framework may provide callbacks to signal that the last
  373. * client of the virtualized device has gone and the device can be removed
  374. * 2. Frontend can schedule a deferred work (timer/tasklet/workqueue)
  375. * to periodically check if this is the right time to re-try removal of
  376. * the virtualized device.
  377. * 3. By any other means.
  378. *
  379. ******************************************************************************
  380. * PCM FORMATS
  381. ******************************************************************************
  382. *
  383. * XENSND_PCM_FORMAT_<format>[_<endian>]
  384. *
  385. * format: <S/U/F><bits> or <name>
  386. * S - signed, U - unsigned, F - float
  387. * bits - 8, 16, 24, 32
  388. * name - MU_LAW, GSM, etc.
  389. *
  390. * endian: <LE/BE>, may be absent
  391. * LE - Little endian, BE - Big endian
  392. */
  393. #define XENSND_PCM_FORMAT_S8 0
  394. #define XENSND_PCM_FORMAT_U8 1
  395. #define XENSND_PCM_FORMAT_S16_LE 2
  396. #define XENSND_PCM_FORMAT_S16_BE 3
  397. #define XENSND_PCM_FORMAT_U16_LE 4
  398. #define XENSND_PCM_FORMAT_U16_BE 5
  399. #define XENSND_PCM_FORMAT_S24_LE 6
  400. #define XENSND_PCM_FORMAT_S24_BE 7
  401. #define XENSND_PCM_FORMAT_U24_LE 8
  402. #define XENSND_PCM_FORMAT_U24_BE 9
  403. #define XENSND_PCM_FORMAT_S32_LE 10
  404. #define XENSND_PCM_FORMAT_S32_BE 11
  405. #define XENSND_PCM_FORMAT_U32_LE 12
  406. #define XENSND_PCM_FORMAT_U32_BE 13
  407. #define XENSND_PCM_FORMAT_F32_LE 14 /* 4-byte float, IEEE-754 32-bit, */
  408. #define XENSND_PCM_FORMAT_F32_BE 15 /* range -1.0 to 1.0 */
  409. #define XENSND_PCM_FORMAT_F64_LE 16 /* 8-byte float, IEEE-754 64-bit, */
  410. #define XENSND_PCM_FORMAT_F64_BE 17 /* range -1.0 to 1.0 */
  411. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE 18
  412. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE 19
  413. #define XENSND_PCM_FORMAT_MU_LAW 20
  414. #define XENSND_PCM_FORMAT_A_LAW 21
  415. #define XENSND_PCM_FORMAT_IMA_ADPCM 22
  416. #define XENSND_PCM_FORMAT_MPEG 23
  417. #define XENSND_PCM_FORMAT_GSM 24
  418. /*
  419. ******************************************************************************
  420. * REQUEST CODES
  421. ******************************************************************************
  422. */
  423. #define XENSND_OP_OPEN 0
  424. #define XENSND_OP_CLOSE 1
  425. #define XENSND_OP_READ 2
  426. #define XENSND_OP_WRITE 3
  427. #define XENSND_OP_SET_VOLUME 4
  428. #define XENSND_OP_GET_VOLUME 5
  429. #define XENSND_OP_MUTE 6
  430. #define XENSND_OP_UNMUTE 7
  431. /*
  432. ******************************************************************************
  433. * XENSTORE FIELD AND PATH NAME STRINGS, HELPERS
  434. ******************************************************************************
  435. */
  436. #define XENSND_DRIVER_NAME "vsnd"
  437. #define XENSND_LIST_SEPARATOR ","
  438. /* Field names */
  439. #define XENSND_FIELD_BE_VERSIONS "versions"
  440. #define XENSND_FIELD_FE_VERSION "version"
  441. #define XENSND_FIELD_VCARD_SHORT_NAME "short-name"
  442. #define XENSND_FIELD_VCARD_LONG_NAME "long-name"
  443. #define XENSND_FIELD_RING_REF "ring-ref"
  444. #define XENSND_FIELD_EVT_CHNL "event-channel"
  445. #define XENSND_FIELD_DEVICE_NAME "name"
  446. #define XENSND_FIELD_TYPE "type"
  447. #define XENSND_FIELD_STREAM_UNIQUE_ID "unique-id"
  448. #define XENSND_FIELD_CHANNELS_MIN "channels-min"
  449. #define XENSND_FIELD_CHANNELS_MAX "channels-max"
  450. #define XENSND_FIELD_SAMPLE_RATES "sample-rates"
  451. #define XENSND_FIELD_SAMPLE_FORMATS "sample-formats"
  452. #define XENSND_FIELD_BUFFER_SIZE "buffer-size"
  453. /* Stream type field values. */
  454. #define XENSND_STREAM_TYPE_PLAYBACK "p"
  455. #define XENSND_STREAM_TYPE_CAPTURE "c"
  456. /* Sample rate max string length */
  457. #define XENSND_SAMPLE_RATE_MAX_LEN 11
  458. /* Sample format field values */
  459. #define XENSND_SAMPLE_FORMAT_MAX_LEN 24
  460. #define XENSND_PCM_FORMAT_S8_STR "s8"
  461. #define XENSND_PCM_FORMAT_U8_STR "u8"
  462. #define XENSND_PCM_FORMAT_S16_LE_STR "s16_le"
  463. #define XENSND_PCM_FORMAT_S16_BE_STR "s16_be"
  464. #define XENSND_PCM_FORMAT_U16_LE_STR "u16_le"
  465. #define XENSND_PCM_FORMAT_U16_BE_STR "u16_be"
  466. #define XENSND_PCM_FORMAT_S24_LE_STR "s24_le"
  467. #define XENSND_PCM_FORMAT_S24_BE_STR "s24_be"
  468. #define XENSND_PCM_FORMAT_U24_LE_STR "u24_le"
  469. #define XENSND_PCM_FORMAT_U24_BE_STR "u24_be"
  470. #define XENSND_PCM_FORMAT_S32_LE_STR "s32_le"
  471. #define XENSND_PCM_FORMAT_S32_BE_STR "s32_be"
  472. #define XENSND_PCM_FORMAT_U32_LE_STR "u32_le"
  473. #define XENSND_PCM_FORMAT_U32_BE_STR "u32_be"
  474. #define XENSND_PCM_FORMAT_F32_LE_STR "float_le"
  475. #define XENSND_PCM_FORMAT_F32_BE_STR "float_be"
  476. #define XENSND_PCM_FORMAT_F64_LE_STR "float64_le"
  477. #define XENSND_PCM_FORMAT_F64_BE_STR "float64_be"
  478. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE_STR "iec958_subframe_le"
  479. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE_STR "iec958_subframe_be"
  480. #define XENSND_PCM_FORMAT_MU_LAW_STR "mu_law"
  481. #define XENSND_PCM_FORMAT_A_LAW_STR "a_law"
  482. #define XENSND_PCM_FORMAT_IMA_ADPCM_STR "ima_adpcm"
  483. #define XENSND_PCM_FORMAT_MPEG_STR "mpeg"
  484. #define XENSND_PCM_FORMAT_GSM_STR "gsm"
  485. /*
  486. ******************************************************************************
  487. * STATUS RETURN CODES
  488. ******************************************************************************
  489. *
  490. * Status return code is zero on success and -XEN_EXX on failure.
  491. *
  492. ******************************************************************************
  493. * Assumptions
  494. ******************************************************************************
  495. * o usage of grant reference 0 as invalid grant reference:
  496. * grant reference 0 is valid, but never exposed to a PV driver,
  497. * because of the fact it is already in use/reserved by the PV console.
  498. * o all references in this document to page sizes must be treated
  499. * as pages of size XEN_PAGE_SIZE unless otherwise noted.
  500. *
  501. ******************************************************************************
  502. * Description of the protocol between frontend and backend driver
  503. ******************************************************************************
  504. *
  505. * The two halves of a Para-virtual sound driver communicate with
  506. * each other using shared pages and event channels.
  507. * Shared page contains a ring with request/response packets.
  508. *
  509. * Packets, used for input/output operations, e.g. read/write, set/get volume,
  510. * etc., provide offset/length fields in order to allow asynchronous protocol
  511. * operation with buffer space sharing: part of the buffer allocated at
  512. * XENSND_OP_OPEN can be used for audio samples and part, for example,
  513. * for volume control.
  514. *
  515. * All reserved fields in the structures below must be 0.
  516. *
  517. *---------------------------------- Requests ---------------------------------
  518. *
  519. * All request packets have the same length (32 octets)
  520. * All request packets have common header:
  521. * 0 1 2 3 octet
  522. * +----------------+----------------+----------------+----------------+
  523. * | id | operation | reserved | 4
  524. * +----------------+----------------+----------------+----------------+
  525. * | reserved | 8
  526. * +----------------+----------------+----------------+----------------+
  527. * id - uint16_t, private guest value, echoed in response
  528. * operation - uint8_t, operation code, XENSND_OP_???
  529. *
  530. * For all packets which use offset and length:
  531. * offset - uint32_t, read or write data offset within the shared buffer,
  532. * passed with XENSND_OP_OPEN request, octets,
  533. * [0; XENSND_OP_OPEN.buffer_sz - 1].
  534. * length - uint32_t, read or write data length, octets
  535. *
  536. * Request open - open a PCM stream for playback or capture:
  537. *
  538. * 0 1 2 3 octet
  539. * +----------------+----------------+----------------+----------------+
  540. * | id | XENSND_OP_OPEN | reserved | 4
  541. * +----------------+----------------+----------------+----------------+
  542. * | reserved | 8
  543. * +----------------+----------------+----------------+----------------+
  544. * | pcm_rate | 12
  545. * +----------------+----------------+----------------+----------------+
  546. * | pcm_format | pcm_channels | reserved | 16
  547. * +----------------+----------------+----------------+----------------+
  548. * | buffer_sz | 20
  549. * +----------------+----------------+----------------+----------------+
  550. * | gref_directory | 24
  551. * +----------------+----------------+----------------+----------------+
  552. * | reserved | 28
  553. * +----------------+----------------+----------------+----------------+
  554. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  555. * +----------------+----------------+----------------+----------------+
  556. * | reserved | 32
  557. * +----------------+----------------+----------------+----------------+
  558. *
  559. * pcm_rate - uint32_t, stream data rate, Hz
  560. * pcm_format - uint8_t, XENSND_PCM_FORMAT_XXX value
  561. * pcm_channels - uint8_t, number of channels of this stream,
  562. * [channels-min; channels-max]
  563. * buffer_sz - uint32_t, buffer size to be allocated, octets
  564. * gref_directory - grant_ref_t, a reference to the first shared page
  565. * describing shared buffer references. At least one page exists. If shared
  566. * buffer size (buffer_sz) exceeds what can be addressed by this single page,
  567. * then reference to the next page must be supplied (see gref_dir_next_page
  568. * below)
  569. */
  570. struct xensnd_open_req {
  571. uint32_t pcm_rate;
  572. uint8_t pcm_format;
  573. uint8_t pcm_channels;
  574. uint16_t reserved;
  575. uint32_t buffer_sz;
  576. grant_ref_t gref_directory;
  577. };
  578. /*
  579. * Shared page for XENSND_OP_OPEN buffer descriptor (gref_directory in the
  580. * request) employs a list of pages, describing all pages of the shared data
  581. * buffer:
  582. * 0 1 2 3 octet
  583. * +----------------+----------------+----------------+----------------+
  584. * | gref_dir_next_page | 4
  585. * +----------------+----------------+----------------+----------------+
  586. * | gref[0] | 8
  587. * +----------------+----------------+----------------+----------------+
  588. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  589. * +----------------+----------------+----------------+----------------+
  590. * | gref[i] | i*4+8
  591. * +----------------+----------------+----------------+----------------+
  592. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  593. * +----------------+----------------+----------------+----------------+
  594. * | gref[N - 1] | N*4+8
  595. * +----------------+----------------+----------------+----------------+
  596. *
  597. * gref_dir_next_page - grant_ref_t, reference to the next page describing
  598. * page directory. Must be 0 if there are no more pages in the list.
  599. * gref[i] - grant_ref_t, reference to a shared page of the buffer
  600. * allocated at XENSND_OP_OPEN
  601. *
  602. * Number of grant_ref_t entries in the whole page directory is not
  603. * passed, but instead can be calculated as:
  604. * num_grefs_total = (XENSND_OP_OPEN.buffer_sz + XEN_PAGE_SIZE - 1) /
  605. * XEN_PAGE_SIZE
  606. */
  607. struct xensnd_page_directory {
  608. grant_ref_t gref_dir_next_page;
  609. grant_ref_t gref[1]; /* Variable length */
  610. };
  611. /*
  612. * Request close - close an opened pcm stream:
  613. * 0 1 2 3 octet
  614. * +----------------+----------------+----------------+----------------+
  615. * | id | XENSND_OP_CLOSE| reserved | 4
  616. * +----------------+----------------+----------------+----------------+
  617. * | reserved | 8
  618. * +----------------+----------------+----------------+----------------+
  619. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  620. * +----------------+----------------+----------------+----------------+
  621. * | reserved | 32
  622. * +----------------+----------------+----------------+----------------+
  623. *
  624. * Request read/write - used for read (for capture) or write (for playback):
  625. * 0 1 2 3 octet
  626. * +----------------+----------------+----------------+----------------+
  627. * | id | operation | reserved | 4
  628. * +----------------+----------------+----------------+----------------+
  629. * | reserved | 8
  630. * +----------------+----------------+----------------+----------------+
  631. * | offset | 12
  632. * +----------------+----------------+----------------+----------------+
  633. * | length | 16
  634. * +----------------+----------------+----------------+----------------+
  635. * | reserved | 20
  636. * +----------------+----------------+----------------+----------------+
  637. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  638. * +----------------+----------------+----------------+----------------+
  639. * | reserved | 32
  640. * +----------------+----------------+----------------+----------------+
  641. *
  642. * operation - XENSND_OP_READ for read or XENSND_OP_WRITE for write
  643. */
  644. struct xensnd_rw_req {
  645. uint32_t offset;
  646. uint32_t length;
  647. };
  648. /*
  649. * Request set/get volume - set/get channels' volume of the stream given:
  650. * 0 1 2 3 octet
  651. * +----------------+----------------+----------------+----------------+
  652. * | id | operation | reserved | 4
  653. * +----------------+----------------+----------------+----------------+
  654. * | reserved | 8
  655. * +----------------+----------------+----------------+----------------+
  656. * | offset | 12
  657. * +----------------+----------------+----------------+----------------+
  658. * | length | 16
  659. * +----------------+----------------+----------------+----------------+
  660. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  661. * +----------------+----------------+----------------+----------------+
  662. * | reserved | 32
  663. * +----------------+----------------+----------------+----------------+
  664. *
  665. * operation - XENSND_OP_SET_VOLUME for volume set
  666. * or XENSND_OP_GET_VOLUME for volume get
  667. * Buffer passed with XENSND_OP_OPEN is used to exchange volume
  668. * values:
  669. *
  670. * 0 1 2 3 octet
  671. * +----------------+----------------+----------------+----------------+
  672. * | channel[0] | 4
  673. * +----------------+----------------+----------------+----------------+
  674. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  675. * +----------------+----------------+----------------+----------------+
  676. * | channel[i] | i*4
  677. * +----------------+----------------+----------------+----------------+
  678. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  679. * +----------------+----------------+----------------+----------------+
  680. * | channel[N - 1] | (N-1)*4
  681. * +----------------+----------------+----------------+----------------+
  682. *
  683. * N = XENSND_OP_OPEN.pcm_channels
  684. * i - uint8_t, index of a channel
  685. * channel[i] - sint32_t, volume of i-th channel
  686. * Volume is expressed as a signed value in steps of 0.001 dB,
  687. * while 0 being 0 dB.
  688. *
  689. * Request mute/unmute - mute/unmute stream:
  690. * 0 1 2 3 octet
  691. * +----------------+----------------+----------------+----------------+
  692. * | id | operation | reserved | 4
  693. * +----------------+----------------+----------------+----------------+
  694. * | reserved | 8
  695. * +----------------+----------------+----------------+----------------+
  696. * | offset | 12
  697. * +----------------+----------------+----------------+----------------+
  698. * | length | 16
  699. * +----------------+----------------+----------------+----------------+
  700. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  701. * +----------------+----------------+----------------+----------------+
  702. * | reserved | 32
  703. * +----------------+----------------+----------------+----------------+
  704. *
  705. * operation - XENSND_OP_MUTE for mute or XENSND_OP_UNMUTE for unmute
  706. * Buffer passed with XENSND_OP_OPEN is used to exchange mute/unmute
  707. * values:
  708. *
  709. * 0 octet
  710. * +----------------+----------------+----------------+----------------+
  711. * | channel[0] | 4
  712. * +----------------+----------------+----------------+----------------+
  713. * +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  714. * +----------------+----------------+----------------+----------------+
  715. * | channel[i] | i*4
  716. * +----------------+----------------+----------------+----------------+
  717. * +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  718. * +----------------+----------------+----------------+----------------+
  719. * | channel[N - 1] | (N-1)*4
  720. * +----------------+----------------+----------------+----------------+
  721. *
  722. * N = XENSND_OP_OPEN.pcm_channels
  723. * i - uint8_t, index of a channel
  724. * channel[i] - uint8_t, non-zero if i-th channel needs to be muted/unmuted
  725. *
  726. *------------------------------------ N.B. -----------------------------------
  727. *
  728. * The 'struct xensnd_rw_req' is also used for XENSND_OP_SET_VOLUME,
  729. * XENSND_OP_GET_VOLUME, XENSND_OP_MUTE, XENSND_OP_UNMUTE.
  730. */
  731. /*
  732. *---------------------------------- Responses --------------------------------
  733. *
  734. * All response packets have the same length (32 octets)
  735. *
  736. * Response for all requests:
  737. * 0 1 2 3 octet
  738. * +----------------+----------------+----------------+----------------+
  739. * | id | operation | reserved | 4
  740. * +----------------+----------------+----------------+----------------+
  741. * | status | 8
  742. * +----------------+----------------+----------------+----------------+
  743. * | reserved | 12
  744. * +----------------+----------------+----------------+----------------+
  745. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  746. * +----------------+----------------+----------------+----------------+
  747. * | reserved | 32
  748. * +----------------+----------------+----------------+----------------+
  749. *
  750. * id - uint16_t, copied from the request
  751. * operation - uint8_t, XENSND_OP_* - copied from request
  752. * status - int32_t, response status, zero on success and -XEN_EXX on failure
  753. */
  754. struct xensnd_req {
  755. uint16_t id;
  756. uint8_t operation;
  757. uint8_t reserved[5];
  758. union {
  759. struct xensnd_open_req open;
  760. struct xensnd_rw_req rw;
  761. uint8_t reserved[24];
  762. } op;
  763. };
  764. struct xensnd_resp {
  765. uint16_t id;
  766. uint8_t operation;
  767. uint8_t reserved;
  768. int32_t status;
  769. uint8_t reserved1[24];
  770. };
  771. DEFINE_RING_TYPES(xen_sndif, struct xensnd_req, struct xensnd_resp);
  772. #endif /* __XEN_PUBLIC_IO_SNDIF_H__ */