sndif.h 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  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: <string>
  278. *
  279. * After stream initialization it is assigned a unique ID, so every
  280. * stream of the frontend can be identified by the backend by this ID.
  281. * This can be UUID or such.
  282. *
  283. *-------------------- Stream Request Transport Parameters --------------------
  284. *
  285. * event-channel
  286. * Values: <uint32_t>
  287. *
  288. * The identifier of the Xen event channel used to signal activity
  289. * in the ring buffer.
  290. *
  291. * ring-ref
  292. * Values: <uint32_t>
  293. *
  294. * The Xen grant reference granting permission for the backend to map
  295. * a sole page in a single page sized ring buffer.
  296. *
  297. *--------------------- Stream Event Transport Parameters ---------------------
  298. *
  299. * This communication path is used to deliver asynchronous events from backend
  300. * to frontend, set up per stream.
  301. *
  302. * evt-event-channel
  303. * Values: <uint32_t>
  304. *
  305. * The identifier of the Xen event channel used to signal activity
  306. * in the ring buffer.
  307. *
  308. * evt-ring-ref
  309. * Values: <uint32_t>
  310. *
  311. * The Xen grant reference granting permission for the backend to map
  312. * a sole page in a single page sized ring buffer.
  313. *
  314. ******************************************************************************
  315. * STATE DIAGRAMS
  316. ******************************************************************************
  317. *
  318. * Tool stack creates front and back state nodes with initial state
  319. * XenbusStateInitialising.
  320. * Tool stack creates and sets up frontend sound configuration nodes per domain.
  321. *
  322. * Front Back
  323. * ================================= =====================================
  324. * XenbusStateInitialising XenbusStateInitialising
  325. * o Query backend device identification
  326. * data.
  327. * o Open and validate backend device.
  328. * |
  329. * |
  330. * V
  331. * XenbusStateInitWait
  332. *
  333. * o Query frontend configuration
  334. * o Allocate and initialize
  335. * event channels per configured
  336. * playback/capture stream.
  337. * o Publish transport parameters
  338. * that will be in effect during
  339. * this connection.
  340. * |
  341. * |
  342. * V
  343. * XenbusStateInitialised
  344. *
  345. * o Query frontend transport parameters.
  346. * o Connect to the event channels.
  347. * |
  348. * |
  349. * V
  350. * XenbusStateConnected
  351. *
  352. * o Create and initialize OS
  353. * virtual sound device instances
  354. * as per configuration.
  355. * |
  356. * |
  357. * V
  358. * XenbusStateConnected
  359. *
  360. * XenbusStateUnknown
  361. * XenbusStateClosed
  362. * XenbusStateClosing
  363. * o Remove virtual sound device
  364. * o Remove event channels
  365. * |
  366. * |
  367. * V
  368. * XenbusStateClosed
  369. *
  370. *------------------------------- Recovery flow -------------------------------
  371. *
  372. * In case of frontend unrecoverable errors backend handles that as
  373. * if frontend goes into the XenbusStateClosed state.
  374. *
  375. * In case of backend unrecoverable errors frontend tries removing
  376. * the virtualized device. If this is possible at the moment of error,
  377. * then frontend goes into the XenbusStateInitialising state and is ready for
  378. * new connection with backend. If the virtualized device is still in use and
  379. * cannot be removed, then frontend goes into the XenbusStateReconfiguring state
  380. * until either the virtualized device removed or backend initiates a new
  381. * connection. On the virtualized device removal frontend goes into the
  382. * XenbusStateInitialising state.
  383. *
  384. * Note on XenbusStateReconfiguring state of the frontend: if backend has
  385. * unrecoverable errors then frontend cannot send requests to the backend
  386. * and thus cannot provide functionality of the virtualized device anymore.
  387. * After backend is back to normal the virtualized device may still hold some
  388. * state: configuration in use, allocated buffers, client application state etc.
  389. * So, in most cases, this will require frontend to implement complex recovery
  390. * reconnect logic. Instead, by going into XenbusStateReconfiguring state,
  391. * frontend will make sure no new clients of the virtualized device are
  392. * accepted, allow existing client(s) to exit gracefully by signaling error
  393. * state etc.
  394. * Once all the clients are gone frontend can reinitialize the virtualized
  395. * device and get into XenbusStateInitialising state again signaling the
  396. * backend that a new connection can be made.
  397. *
  398. * There are multiple conditions possible under which frontend will go from
  399. * XenbusStateReconfiguring into XenbusStateInitialising, some of them are OS
  400. * specific. For example:
  401. * 1. The underlying OS framework may provide callbacks to signal that the last
  402. * client of the virtualized device has gone and the device can be removed
  403. * 2. Frontend can schedule a deferred work (timer/tasklet/workqueue)
  404. * to periodically check if this is the right time to re-try removal of
  405. * the virtualized device.
  406. * 3. By any other means.
  407. *
  408. ******************************************************************************
  409. * PCM FORMATS
  410. ******************************************************************************
  411. *
  412. * XENSND_PCM_FORMAT_<format>[_<endian>]
  413. *
  414. * format: <S/U/F><bits> or <name>
  415. * S - signed, U - unsigned, F - float
  416. * bits - 8, 16, 24, 32
  417. * name - MU_LAW, GSM, etc.
  418. *
  419. * endian: <LE/BE>, may be absent
  420. * LE - Little endian, BE - Big endian
  421. */
  422. #define XENSND_PCM_FORMAT_S8 0
  423. #define XENSND_PCM_FORMAT_U8 1
  424. #define XENSND_PCM_FORMAT_S16_LE 2
  425. #define XENSND_PCM_FORMAT_S16_BE 3
  426. #define XENSND_PCM_FORMAT_U16_LE 4
  427. #define XENSND_PCM_FORMAT_U16_BE 5
  428. #define XENSND_PCM_FORMAT_S24_LE 6
  429. #define XENSND_PCM_FORMAT_S24_BE 7
  430. #define XENSND_PCM_FORMAT_U24_LE 8
  431. #define XENSND_PCM_FORMAT_U24_BE 9
  432. #define XENSND_PCM_FORMAT_S32_LE 10
  433. #define XENSND_PCM_FORMAT_S32_BE 11
  434. #define XENSND_PCM_FORMAT_U32_LE 12
  435. #define XENSND_PCM_FORMAT_U32_BE 13
  436. #define XENSND_PCM_FORMAT_F32_LE 14 /* 4-byte float, IEEE-754 32-bit, */
  437. #define XENSND_PCM_FORMAT_F32_BE 15 /* range -1.0 to 1.0 */
  438. #define XENSND_PCM_FORMAT_F64_LE 16 /* 8-byte float, IEEE-754 64-bit, */
  439. #define XENSND_PCM_FORMAT_F64_BE 17 /* range -1.0 to 1.0 */
  440. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE 18
  441. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE 19
  442. #define XENSND_PCM_FORMAT_MU_LAW 20
  443. #define XENSND_PCM_FORMAT_A_LAW 21
  444. #define XENSND_PCM_FORMAT_IMA_ADPCM 22
  445. #define XENSND_PCM_FORMAT_MPEG 23
  446. #define XENSND_PCM_FORMAT_GSM 24
  447. /*
  448. ******************************************************************************
  449. * REQUEST CODES
  450. ******************************************************************************
  451. */
  452. #define XENSND_OP_OPEN 0
  453. #define XENSND_OP_CLOSE 1
  454. #define XENSND_OP_READ 2
  455. #define XENSND_OP_WRITE 3
  456. #define XENSND_OP_SET_VOLUME 4
  457. #define XENSND_OP_GET_VOLUME 5
  458. #define XENSND_OP_MUTE 6
  459. #define XENSND_OP_UNMUTE 7
  460. #define XENSND_OP_TRIGGER 8
  461. #define XENSND_OP_HW_PARAM_QUERY 9
  462. #define XENSND_OP_TRIGGER_START 0
  463. #define XENSND_OP_TRIGGER_PAUSE 1
  464. #define XENSND_OP_TRIGGER_STOP 2
  465. #define XENSND_OP_TRIGGER_RESUME 3
  466. /*
  467. ******************************************************************************
  468. * EVENT CODES
  469. ******************************************************************************
  470. */
  471. #define XENSND_EVT_CUR_POS 0
  472. /*
  473. ******************************************************************************
  474. * XENSTORE FIELD AND PATH NAME STRINGS, HELPERS
  475. ******************************************************************************
  476. */
  477. #define XENSND_DRIVER_NAME "vsnd"
  478. #define XENSND_LIST_SEPARATOR ","
  479. /* Field names */
  480. #define XENSND_FIELD_BE_VERSIONS "versions"
  481. #define XENSND_FIELD_FE_VERSION "version"
  482. #define XENSND_FIELD_VCARD_SHORT_NAME "short-name"
  483. #define XENSND_FIELD_VCARD_LONG_NAME "long-name"
  484. #define XENSND_FIELD_RING_REF "ring-ref"
  485. #define XENSND_FIELD_EVT_CHNL "event-channel"
  486. #define XENSND_FIELD_EVT_RING_REF "evt-ring-ref"
  487. #define XENSND_FIELD_EVT_EVT_CHNL "evt-event-channel"
  488. #define XENSND_FIELD_DEVICE_NAME "name"
  489. #define XENSND_FIELD_TYPE "type"
  490. #define XENSND_FIELD_STREAM_UNIQUE_ID "unique-id"
  491. #define XENSND_FIELD_CHANNELS_MIN "channels-min"
  492. #define XENSND_FIELD_CHANNELS_MAX "channels-max"
  493. #define XENSND_FIELD_SAMPLE_RATES "sample-rates"
  494. #define XENSND_FIELD_SAMPLE_FORMATS "sample-formats"
  495. #define XENSND_FIELD_BUFFER_SIZE "buffer-size"
  496. /* Stream type field values. */
  497. #define XENSND_STREAM_TYPE_PLAYBACK "p"
  498. #define XENSND_STREAM_TYPE_CAPTURE "c"
  499. /* Sample rate max string length */
  500. #define XENSND_SAMPLE_RATE_MAX_LEN 11
  501. /* Sample format field values */
  502. #define XENSND_SAMPLE_FORMAT_MAX_LEN 24
  503. #define XENSND_PCM_FORMAT_S8_STR "s8"
  504. #define XENSND_PCM_FORMAT_U8_STR "u8"
  505. #define XENSND_PCM_FORMAT_S16_LE_STR "s16_le"
  506. #define XENSND_PCM_FORMAT_S16_BE_STR "s16_be"
  507. #define XENSND_PCM_FORMAT_U16_LE_STR "u16_le"
  508. #define XENSND_PCM_FORMAT_U16_BE_STR "u16_be"
  509. #define XENSND_PCM_FORMAT_S24_LE_STR "s24_le"
  510. #define XENSND_PCM_FORMAT_S24_BE_STR "s24_be"
  511. #define XENSND_PCM_FORMAT_U24_LE_STR "u24_le"
  512. #define XENSND_PCM_FORMAT_U24_BE_STR "u24_be"
  513. #define XENSND_PCM_FORMAT_S32_LE_STR "s32_le"
  514. #define XENSND_PCM_FORMAT_S32_BE_STR "s32_be"
  515. #define XENSND_PCM_FORMAT_U32_LE_STR "u32_le"
  516. #define XENSND_PCM_FORMAT_U32_BE_STR "u32_be"
  517. #define XENSND_PCM_FORMAT_F32_LE_STR "float_le"
  518. #define XENSND_PCM_FORMAT_F32_BE_STR "float_be"
  519. #define XENSND_PCM_FORMAT_F64_LE_STR "float64_le"
  520. #define XENSND_PCM_FORMAT_F64_BE_STR "float64_be"
  521. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE_STR "iec958_subframe_le"
  522. #define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE_STR "iec958_subframe_be"
  523. #define XENSND_PCM_FORMAT_MU_LAW_STR "mu_law"
  524. #define XENSND_PCM_FORMAT_A_LAW_STR "a_law"
  525. #define XENSND_PCM_FORMAT_IMA_ADPCM_STR "ima_adpcm"
  526. #define XENSND_PCM_FORMAT_MPEG_STR "mpeg"
  527. #define XENSND_PCM_FORMAT_GSM_STR "gsm"
  528. /*
  529. ******************************************************************************
  530. * STATUS RETURN CODES
  531. ******************************************************************************
  532. *
  533. * Status return code is zero on success and -XEN_EXX on failure.
  534. *
  535. ******************************************************************************
  536. * Assumptions
  537. ******************************************************************************
  538. * o usage of grant reference 0 as invalid grant reference:
  539. * grant reference 0 is valid, but never exposed to a PV driver,
  540. * because of the fact it is already in use/reserved by the PV console.
  541. * o all references in this document to page sizes must be treated
  542. * as pages of size XEN_PAGE_SIZE unless otherwise noted.
  543. *
  544. ******************************************************************************
  545. * Description of the protocol between frontend and backend driver
  546. ******************************************************************************
  547. *
  548. * The two halves of a Para-virtual sound driver communicate with
  549. * each other using shared pages and event channels.
  550. * Shared page contains a ring with request/response packets.
  551. *
  552. * Packets, used for input/output operations, e.g. read/write, set/get volume,
  553. * etc., provide offset/length fields in order to allow asynchronous protocol
  554. * operation with buffer space sharing: part of the buffer allocated at
  555. * XENSND_OP_OPEN can be used for audio samples and part, for example,
  556. * for volume control.
  557. *
  558. * All reserved fields in the structures below must be 0.
  559. *
  560. *---------------------------------- Requests ---------------------------------
  561. *
  562. * All request packets have the same length (64 octets)
  563. * All request packets have common header:
  564. * 0 1 2 3 octet
  565. * +----------------+----------------+----------------+----------------+
  566. * | id | operation | reserved | 4
  567. * +----------------+----------------+----------------+----------------+
  568. * | reserved | 8
  569. * +----------------+----------------+----------------+----------------+
  570. * id - uint16_t, private guest value, echoed in response
  571. * operation - uint8_t, operation code, XENSND_OP_???
  572. *
  573. * For all packets which use offset and length:
  574. * offset - uint32_t, read or write data offset within the shared buffer,
  575. * passed with XENSND_OP_OPEN request, octets,
  576. * [0; XENSND_OP_OPEN.buffer_sz - 1].
  577. * length - uint32_t, read or write data length, octets
  578. *
  579. * Request open - open a PCM stream for playback or capture:
  580. *
  581. * 0 1 2 3 octet
  582. * +----------------+----------------+----------------+----------------+
  583. * | id | XENSND_OP_OPEN | reserved | 4
  584. * +----------------+----------------+----------------+----------------+
  585. * | reserved | 8
  586. * +----------------+----------------+----------------+----------------+
  587. * | pcm_rate | 12
  588. * +----------------+----------------+----------------+----------------+
  589. * | pcm_format | pcm_channels | reserved | 16
  590. * +----------------+----------------+----------------+----------------+
  591. * | buffer_sz | 20
  592. * +----------------+----------------+----------------+----------------+
  593. * | gref_directory | 24
  594. * +----------------+----------------+----------------+----------------+
  595. * | period_sz | 28
  596. * +----------------+----------------+----------------+----------------+
  597. * | reserved | 32
  598. * +----------------+----------------+----------------+----------------+
  599. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  600. * +----------------+----------------+----------------+----------------+
  601. * | reserved | 64
  602. * +----------------+----------------+----------------+----------------+
  603. *
  604. * pcm_rate - uint32_t, stream data rate, Hz
  605. * pcm_format - uint8_t, XENSND_PCM_FORMAT_XXX value
  606. * pcm_channels - uint8_t, number of channels of this stream,
  607. * [channels-min; channels-max]
  608. * buffer_sz - uint32_t, buffer size to be allocated, octets
  609. * period_sz - uint32_t, event period size, octets
  610. * This is the requested value of the period at which frontend would
  611. * like to receive XENSND_EVT_CUR_POS notifications from the backend when
  612. * stream position advances during playback/capture.
  613. * It shows how many octets are expected to be played/captured before
  614. * sending such an event.
  615. * If set to 0 no XENSND_EVT_CUR_POS events are sent by the backend.
  616. *
  617. * gref_directory - grant_ref_t, a reference to the first shared page
  618. * describing shared buffer references. At least one page exists. If shared
  619. * buffer size (buffer_sz) exceeds what can be addressed by this single page,
  620. * then reference to the next page must be supplied (see gref_dir_next_page
  621. * below)
  622. */
  623. struct xensnd_open_req {
  624. uint32_t pcm_rate;
  625. uint8_t pcm_format;
  626. uint8_t pcm_channels;
  627. uint16_t reserved;
  628. uint32_t buffer_sz;
  629. grant_ref_t gref_directory;
  630. uint32_t period_sz;
  631. };
  632. /*
  633. * Shared page for XENSND_OP_OPEN buffer descriptor (gref_directory in the
  634. * request) employs a list of pages, describing all pages of the shared data
  635. * buffer:
  636. * 0 1 2 3 octet
  637. * +----------------+----------------+----------------+----------------+
  638. * | gref_dir_next_page | 4
  639. * +----------------+----------------+----------------+----------------+
  640. * | gref[0] | 8
  641. * +----------------+----------------+----------------+----------------+
  642. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  643. * +----------------+----------------+----------------+----------------+
  644. * | gref[i] | i*4+8
  645. * +----------------+----------------+----------------+----------------+
  646. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  647. * +----------------+----------------+----------------+----------------+
  648. * | gref[N - 1] | N*4+8
  649. * +----------------+----------------+----------------+----------------+
  650. *
  651. * gref_dir_next_page - grant_ref_t, reference to the next page describing
  652. * page directory. Must be 0 if there are no more pages in the list.
  653. * gref[i] - grant_ref_t, reference to a shared page of the buffer
  654. * allocated at XENSND_OP_OPEN
  655. *
  656. * Number of grant_ref_t entries in the whole page directory is not
  657. * passed, but instead can be calculated as:
  658. * num_grefs_total = (XENSND_OP_OPEN.buffer_sz + XEN_PAGE_SIZE - 1) /
  659. * XEN_PAGE_SIZE
  660. */
  661. struct xensnd_page_directory {
  662. grant_ref_t gref_dir_next_page;
  663. grant_ref_t gref[1]; /* Variable length */
  664. };
  665. /*
  666. * Request close - close an opened pcm stream:
  667. * 0 1 2 3 octet
  668. * +----------------+----------------+----------------+----------------+
  669. * | id | XENSND_OP_CLOSE| reserved | 4
  670. * +----------------+----------------+----------------+----------------+
  671. * | reserved | 8
  672. * +----------------+----------------+----------------+----------------+
  673. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  674. * +----------------+----------------+----------------+----------------+
  675. * | reserved | 64
  676. * +----------------+----------------+----------------+----------------+
  677. *
  678. * Request read/write - used for read (for capture) or write (for playback):
  679. * 0 1 2 3 octet
  680. * +----------------+----------------+----------------+----------------+
  681. * | id | operation | reserved | 4
  682. * +----------------+----------------+----------------+----------------+
  683. * | reserved | 8
  684. * +----------------+----------------+----------------+----------------+
  685. * | offset | 12
  686. * +----------------+----------------+----------------+----------------+
  687. * | length | 16
  688. * +----------------+----------------+----------------+----------------+
  689. * | reserved | 20
  690. * +----------------+----------------+----------------+----------------+
  691. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  692. * +----------------+----------------+----------------+----------------+
  693. * | reserved | 64
  694. * +----------------+----------------+----------------+----------------+
  695. *
  696. * operation - XENSND_OP_READ for read or XENSND_OP_WRITE for write
  697. */
  698. struct xensnd_rw_req {
  699. uint32_t offset;
  700. uint32_t length;
  701. };
  702. /*
  703. * Request set/get volume - set/get channels' volume of the stream given:
  704. * 0 1 2 3 octet
  705. * +----------------+----------------+----------------+----------------+
  706. * | id | operation | reserved | 4
  707. * +----------------+----------------+----------------+----------------+
  708. * | reserved | 8
  709. * +----------------+----------------+----------------+----------------+
  710. * | offset | 12
  711. * +----------------+----------------+----------------+----------------+
  712. * | length | 16
  713. * +----------------+----------------+----------------+----------------+
  714. * | reserved | 20
  715. * +----------------+----------------+----------------+----------------+
  716. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  717. * +----------------+----------------+----------------+----------------+
  718. * | reserved | 64
  719. * +----------------+----------------+----------------+----------------+
  720. *
  721. * operation - XENSND_OP_SET_VOLUME for volume set
  722. * or XENSND_OP_GET_VOLUME for volume get
  723. * Buffer passed with XENSND_OP_OPEN is used to exchange volume
  724. * values:
  725. *
  726. * 0 1 2 3 octet
  727. * +----------------+----------------+----------------+----------------+
  728. * | channel[0] | 4
  729. * +----------------+----------------+----------------+----------------+
  730. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  731. * +----------------+----------------+----------------+----------------+
  732. * | channel[i] | i*4
  733. * +----------------+----------------+----------------+----------------+
  734. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  735. * +----------------+----------------+----------------+----------------+
  736. * | channel[N - 1] | (N-1)*4
  737. * +----------------+----------------+----------------+----------------+
  738. *
  739. * N = XENSND_OP_OPEN.pcm_channels
  740. * i - uint8_t, index of a channel
  741. * channel[i] - sint32_t, volume of i-th channel
  742. * Volume is expressed as a signed value in steps of 0.001 dB,
  743. * while 0 being 0 dB.
  744. *
  745. * Request mute/unmute - mute/unmute stream:
  746. * 0 1 2 3 octet
  747. * +----------------+----------------+----------------+----------------+
  748. * | id | operation | reserved | 4
  749. * +----------------+----------------+----------------+----------------+
  750. * | reserved | 8
  751. * +----------------+----------------+----------------+----------------+
  752. * | offset | 12
  753. * +----------------+----------------+----------------+----------------+
  754. * | length | 16
  755. * +----------------+----------------+----------------+----------------+
  756. * | reserved | 20
  757. * +----------------+----------------+----------------+----------------+
  758. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  759. * +----------------+----------------+----------------+----------------+
  760. * | reserved | 64
  761. * +----------------+----------------+----------------+----------------+
  762. *
  763. * operation - XENSND_OP_MUTE for mute or XENSND_OP_UNMUTE for unmute
  764. * Buffer passed with XENSND_OP_OPEN is used to exchange mute/unmute
  765. * values:
  766. *
  767. * 0 octet
  768. * +----------------+----------------+----------------+----------------+
  769. * | channel[0] | 4
  770. * +----------------+----------------+----------------+----------------+
  771. * +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  772. * +----------------+----------------+----------------+----------------+
  773. * | channel[i] | i*4
  774. * +----------------+----------------+----------------+----------------+
  775. * +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  776. * +----------------+----------------+----------------+----------------+
  777. * | channel[N - 1] | (N-1)*4
  778. * +----------------+----------------+----------------+----------------+
  779. *
  780. * N = XENSND_OP_OPEN.pcm_channels
  781. * i - uint8_t, index of a channel
  782. * channel[i] - uint8_t, non-zero if i-th channel needs to be muted/unmuted
  783. *
  784. *------------------------------------ N.B. -----------------------------------
  785. *
  786. * The 'struct xensnd_rw_req' is also used for XENSND_OP_SET_VOLUME,
  787. * XENSND_OP_GET_VOLUME, XENSND_OP_MUTE, XENSND_OP_UNMUTE.
  788. *
  789. * Request stream running state change - trigger PCM stream running state
  790. * to start, stop, pause or resume:
  791. *
  792. * 0 1 2 3 octet
  793. * +----------------+----------------+----------------+----------------+
  794. * | id | _OP_TRIGGER | reserved | 4
  795. * +----------------+----------------+----------------+----------------+
  796. * | reserved | 8
  797. * +----------------+----------------+----------------+----------------+
  798. * | type | reserved | 12
  799. * +----------------+----------------+----------------+----------------+
  800. * | reserved | 16
  801. * +----------------+----------------+----------------+----------------+
  802. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  803. * +----------------+----------------+----------------+----------------+
  804. * | reserved | 64
  805. * +----------------+----------------+----------------+----------------+
  806. *
  807. * type - uint8_t, XENSND_OP_TRIGGER_XXX value
  808. */
  809. struct xensnd_trigger_req {
  810. uint8_t type;
  811. };
  812. /*
  813. * Request stream parameter ranges: request intervals and
  814. * masks of supported ranges for stream configuration values.
  815. *
  816. * Sound device configuration for a particular stream is a limited subset
  817. * of the multidimensional configuration available on XenStore, e.g.
  818. * once the frame rate has been selected there is a limited supported range
  819. * for sample rates becomes available (which might be the same set configured
  820. * on XenStore or less). For example, selecting 96kHz sample rate may limit
  821. * number of channels available for such configuration from 4 to 2, etc.
  822. * Thus, each call to XENSND_OP_HW_PARAM_QUERY may reduce configuration
  823. * space making it possible to iteratively get the final stream configuration,
  824. * used in XENSND_OP_OPEN request.
  825. *
  826. * See response format for this request.
  827. *
  828. * 0 1 2 3 octet
  829. * +----------------+----------------+----------------+----------------+
  830. * | id | _HW_PARAM_QUERY| reserved | 4
  831. * +----------------+----------------+----------------+----------------+
  832. * | reserved | 8
  833. * +----------------+----------------+----------------+----------------+
  834. * | formats mask low 32-bit | 12
  835. * +----------------+----------------+----------------+----------------+
  836. * | formats mask high 32-bit | 16
  837. * +----------------+----------------+----------------+----------------+
  838. * | min rate | 20
  839. * +----------------+----------------+----------------+----------------+
  840. * | max rate | 24
  841. * +----------------+----------------+----------------+----------------+
  842. * | min channels | 28
  843. * +----------------+----------------+----------------+----------------+
  844. * | max channels | 32
  845. * +----------------+----------------+----------------+----------------+
  846. * | min buffer frames | 36
  847. * +----------------+----------------+----------------+----------------+
  848. * | max buffer frames | 40
  849. * +----------------+----------------+----------------+----------------+
  850. * | min period frames | 44
  851. * +----------------+----------------+----------------+----------------+
  852. * | max period frames | 48
  853. * +----------------+----------------+----------------+----------------+
  854. * | reserved | 52
  855. * +----------------+----------------+----------------+----------------+
  856. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  857. * +----------------+----------------+----------------+----------------+
  858. * | reserved | 64
  859. * +----------------+----------------+----------------+----------------+
  860. *
  861. * formats - uint64_t, bit mask representing values of the parameter
  862. * made as bitwise OR of (1 << XENSND_PCM_FORMAT_XXX) values
  863. *
  864. * For interval parameters:
  865. * min - uint32_t, minimum value of the parameter
  866. * max - uint32_t, maximum value of the parameter
  867. *
  868. * Frame is defined as a product of the number of channels by the
  869. * number of octets per one sample.
  870. */
  871. struct xensnd_query_hw_param {
  872. uint64_t formats;
  873. struct {
  874. uint32_t min;
  875. uint32_t max;
  876. } rates;
  877. struct {
  878. uint32_t min;
  879. uint32_t max;
  880. } channels;
  881. struct {
  882. uint32_t min;
  883. uint32_t max;
  884. } buffer;
  885. struct {
  886. uint32_t min;
  887. uint32_t max;
  888. } period;
  889. };
  890. /*
  891. *---------------------------------- Responses --------------------------------
  892. *
  893. * All response packets have the same length (64 octets)
  894. *
  895. * All response packets have common header:
  896. * 0 1 2 3 octet
  897. * +----------------+----------------+----------------+----------------+
  898. * | id | operation | reserved | 4
  899. * +----------------+----------------+----------------+----------------+
  900. * | status | 8
  901. * +----------------+----------------+----------------+----------------+
  902. *
  903. * id - uint16_t, copied from the request
  904. * operation - uint8_t, XENSND_OP_* - copied from request
  905. * status - int32_t, response status, zero on success and -XEN_EXX on failure
  906. *
  907. *
  908. * HW parameter query response - response for XENSND_OP_HW_PARAM_QUERY:
  909. * 0 1 2 3 octet
  910. * +----------------+----------------+----------------+----------------+
  911. * | id | operation | reserved | 4
  912. * +----------------+----------------+----------------+----------------+
  913. * | status | 8
  914. * +----------------+----------------+----------------+----------------+
  915. * | formats mask low 32-bit | 12
  916. * +----------------+----------------+----------------+----------------+
  917. * | formats mask high 32-bit | 16
  918. * +----------------+----------------+----------------+----------------+
  919. * | min rate | 20
  920. * +----------------+----------------+----------------+----------------+
  921. * | max rate | 24
  922. * +----------------+----------------+----------------+----------------+
  923. * | min channels | 28
  924. * +----------------+----------------+----------------+----------------+
  925. * | max channels | 32
  926. * +----------------+----------------+----------------+----------------+
  927. * | min buffer frames | 36
  928. * +----------------+----------------+----------------+----------------+
  929. * | max buffer frames | 40
  930. * +----------------+----------------+----------------+----------------+
  931. * | min period frames | 44
  932. * +----------------+----------------+----------------+----------------+
  933. * | max period frames | 48
  934. * +----------------+----------------+----------------+----------------+
  935. * | reserved | 52
  936. * +----------------+----------------+----------------+----------------+
  937. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  938. * +----------------+----------------+----------------+----------------+
  939. * | reserved | 64
  940. * +----------------+----------------+----------------+----------------+
  941. *
  942. * Meaning of the values in this response is the same as for
  943. * XENSND_OP_HW_PARAM_QUERY request.
  944. */
  945. /*
  946. *----------------------------------- Events ----------------------------------
  947. *
  948. * Events are sent via shared page allocated by the front and propagated by
  949. * evt-event-channel/evt-ring-ref XenStore entries
  950. * All event packets have the same length (64 octets)
  951. * All event packets have common header:
  952. * 0 1 2 3 octet
  953. * +----------------+----------------+----------------+----------------+
  954. * | id | type | reserved | 4
  955. * +----------------+----------------+----------------+----------------+
  956. * | reserved | 8
  957. * +----------------+----------------+----------------+----------------+
  958. *
  959. * id - uint16_t, event id, may be used by front
  960. * type - uint8_t, type of the event
  961. *
  962. *
  963. * Current stream position - event from back to front when stream's
  964. * playback/capture position has advanced:
  965. * 0 1 2 3 octet
  966. * +----------------+----------------+----------------+----------------+
  967. * | id | _EVT_CUR_POS | reserved | 4
  968. * +----------------+----------------+----------------+----------------+
  969. * | reserved | 8
  970. * +----------------+----------------+----------------+----------------+
  971. * | position low 32-bit | 12
  972. * +----------------+----------------+----------------+----------------+
  973. * | position high 32-bit | 16
  974. * +----------------+----------------+----------------+----------------+
  975. * | reserved | 20
  976. * +----------------+----------------+----------------+----------------+
  977. * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  978. * +----------------+----------------+----------------+----------------+
  979. * | reserved | 64
  980. * +----------------+----------------+----------------+----------------+
  981. *
  982. * position - current value of stream's playback/capture position, octets
  983. *
  984. */
  985. struct xensnd_cur_pos_evt {
  986. uint64_t position;
  987. };
  988. struct xensnd_req {
  989. uint16_t id;
  990. uint8_t operation;
  991. uint8_t reserved[5];
  992. union {
  993. struct xensnd_open_req open;
  994. struct xensnd_rw_req rw;
  995. struct xensnd_trigger_req trigger;
  996. struct xensnd_query_hw_param hw_param;
  997. uint8_t reserved[56];
  998. } op;
  999. };
  1000. struct xensnd_resp {
  1001. uint16_t id;
  1002. uint8_t operation;
  1003. uint8_t reserved;
  1004. int32_t status;
  1005. union {
  1006. struct xensnd_query_hw_param hw_param;
  1007. uint8_t reserved1[56];
  1008. } resp;
  1009. };
  1010. struct xensnd_evt {
  1011. uint16_t id;
  1012. uint8_t type;
  1013. uint8_t reserved[5];
  1014. union {
  1015. struct xensnd_cur_pos_evt cur_pos;
  1016. uint8_t reserved[56];
  1017. } op;
  1018. };
  1019. DEFINE_RING_TYPES(xen_sndif, struct xensnd_req, struct xensnd_resp);
  1020. /*
  1021. ******************************************************************************
  1022. * Back to front events delivery
  1023. ******************************************************************************
  1024. * In order to deliver asynchronous events from back to front a shared page is
  1025. * allocated by front and its granted reference propagated to back via
  1026. * XenStore entries (evt-ring-ref/evt-event-channel).
  1027. * This page has a common header used by both front and back to synchronize
  1028. * access and control event's ring buffer, while back being a producer of the
  1029. * events and front being a consumer. The rest of the page after the header
  1030. * is used for event packets.
  1031. *
  1032. * Upon reception of an event(s) front may confirm its reception
  1033. * for either each event, group of events or none.
  1034. */
  1035. struct xensnd_event_page {
  1036. uint32_t in_cons;
  1037. uint32_t in_prod;
  1038. uint8_t reserved[56];
  1039. };
  1040. #define XENSND_EVENT_PAGE_SIZE XEN_PAGE_SIZE
  1041. #define XENSND_IN_RING_OFFS (sizeof(struct xensnd_event_page))
  1042. #define XENSND_IN_RING_SIZE (XENSND_EVENT_PAGE_SIZE - XENSND_IN_RING_OFFS)
  1043. #define XENSND_IN_RING_LEN (XENSND_IN_RING_SIZE / sizeof(struct xensnd_evt))
  1044. #define XENSND_IN_RING(page) \
  1045. ((struct xensnd_evt *)((char *)(page) + XENSND_IN_RING_OFFS))
  1046. #define XENSND_IN_RING_REF(page, idx) \
  1047. (XENSND_IN_RING((page))[(idx) % XENSND_IN_RING_LEN])
  1048. #endif /* __XEN_PUBLIC_IO_SNDIF_H__ */