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