/* SPDX-License-Identifier: MIT */1/******************************************************************************2* sndif.h3*4* Unified sound-device I/O interface for Xen guest OSes.5*6* Copyright (C) 2013-2015 GlobalLogic Inc.7* Copyright (C) 2016-2017 EPAM Systems Inc.8*9* Authors: Oleksandr Andrushchenko <[email protected]>10* Oleksandr Grytsov <[email protected]>11* Oleksandr Dmytryshyn <[email protected]>12* Iurii Konovalenko <[email protected]>13*/1415#ifndef __XEN_PUBLIC_IO_SNDIF_H__16#define __XEN_PUBLIC_IO_SNDIF_H__1718#include "ring.h"19#include "../grant_table.h"2021/*22******************************************************************************23* Protocol version24******************************************************************************25*/26#define XENSND_PROTOCOL_VERSION 22728/*29******************************************************************************30* Feature and Parameter Negotiation31******************************************************************************32*33* Front->back notifications: when enqueuing a new request, sending a34* notification can be made conditional on xensnd_req (i.e., the generic35* hold-off mechanism provided by the ring macros). Backends must set36* xensnd_req appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).37*38* Back->front notifications: when enqueuing a new response, sending a39* notification can be made conditional on xensnd_resp (i.e., the generic40* hold-off mechanism provided by the ring macros). Frontends must set41* xensnd_resp appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).42*43* The two halves of a para-virtual sound card driver utilize nodes within44* XenStore to communicate capabilities and to negotiate operating parameters.45* This section enumerates these nodes which reside in the respective front and46* backend portions of XenStore, following the XenBus convention.47*48* All data in XenStore is stored as strings. Nodes specifying numeric49* values are encoded in decimal. Integer value ranges listed below are50* expressed as fixed sized integer types capable of storing the conversion51* of a properly formated node string, without loss of information.52*53******************************************************************************54* Example configuration55******************************************************************************56*57* Note: depending on the use-case backend can expose more sound cards and58* PCM devices/streams than the underlying HW physically has by employing59* SW mixers, configuring virtual sound streams, channels etc.60*61* This is an example of backend and frontend configuration:62*63*--------------------------------- Backend -----------------------------------64*65* /local/domain/0/backend/vsnd/1/0/frontend-id = "1"66* /local/domain/0/backend/vsnd/1/0/frontend = "/local/domain/1/device/vsnd/0"67* /local/domain/0/backend/vsnd/1/0/state = "4"68* /local/domain/0/backend/vsnd/1/0/versions = "1,2"69*70*--------------------------------- Frontend ----------------------------------71*72* /local/domain/1/device/vsnd/0/backend-id = "0"73* /local/domain/1/device/vsnd/0/backend = "/local/domain/0/backend/vsnd/1/0"74* /local/domain/1/device/vsnd/0/state = "4"75* /local/domain/1/device/vsnd/0/version = "1"76*77*----------------------------- Card configuration ----------------------------78*79* /local/domain/1/device/vsnd/0/short-name = "Card short name"80* /local/domain/1/device/vsnd/0/long-name = "Card long name"81* /local/domain/1/device/vsnd/0/sample-rates = "8000,32000,44100,48000,96000"82* /local/domain/1/device/vsnd/0/sample-formats = "s8,u8,s16_le,s16_be"83* /local/domain/1/device/vsnd/0/buffer-size = "262144"84*85*------------------------------- PCM device 0 --------------------------------86*87* /local/domain/1/device/vsnd/0/0/name = "General analog"88* /local/domain/1/device/vsnd/0/0/channels-max = "5"89*90*----------------------------- Stream 0, playback ----------------------------91*92* /local/domain/1/device/vsnd/0/0/0/type = "p"93* /local/domain/1/device/vsnd/0/0/0/sample-formats = "s8,u8"94* /local/domain/1/device/vsnd/0/0/0/unique-id = "0"95*96* /local/domain/1/device/vsnd/0/0/0/ring-ref = "386"97* /local/domain/1/device/vsnd/0/0/0/event-channel = "15"98* /local/domain/1/device/vsnd/0/0/0/evt-ring-ref = "1386"99* /local/domain/1/device/vsnd/0/0/0/evt-event-channel = "215"100*101*------------------------------ Stream 1, capture ----------------------------102*103* /local/domain/1/device/vsnd/0/0/1/type = "c"104* /local/domain/1/device/vsnd/0/0/1/channels-max = "2"105* /local/domain/1/device/vsnd/0/0/1/unique-id = "1"106*107* /local/domain/1/device/vsnd/0/0/1/ring-ref = "384"108* /local/domain/1/device/vsnd/0/0/1/event-channel = "13"109* /local/domain/1/device/vsnd/0/0/1/evt-ring-ref = "1384"110* /local/domain/1/device/vsnd/0/0/1/evt-event-channel = "213"111*112*------------------------------- PCM device 1 --------------------------------113*114* /local/domain/1/device/vsnd/0/1/name = "HDMI-0"115* /local/domain/1/device/vsnd/0/1/sample-rates = "8000,32000,44100"116*117*------------------------------ Stream 0, capture ----------------------------118*119* /local/domain/1/device/vsnd/0/1/0/type = "c"120* /local/domain/1/device/vsnd/0/1/0/unique-id = "2"121*122* /local/domain/1/device/vsnd/0/1/0/ring-ref = "387"123* /local/domain/1/device/vsnd/0/1/0/event-channel = "151"124* /local/domain/1/device/vsnd/0/1/0/evt-ring-ref = "1387"125* /local/domain/1/device/vsnd/0/1/0/evt-event-channel = "351"126*127*------------------------------- PCM device 2 --------------------------------128*129* /local/domain/1/device/vsnd/0/2/name = "SPDIF"130*131*----------------------------- Stream 0, playback ----------------------------132*133* /local/domain/1/device/vsnd/0/2/0/type = "p"134* /local/domain/1/device/vsnd/0/2/0/unique-id = "3"135*136* /local/domain/1/device/vsnd/0/2/0/ring-ref = "389"137* /local/domain/1/device/vsnd/0/2/0/event-channel = "152"138* /local/domain/1/device/vsnd/0/2/0/evt-ring-ref = "1389"139* /local/domain/1/device/vsnd/0/2/0/evt-event-channel = "452"140*141******************************************************************************142* Backend XenBus Nodes143******************************************************************************144*145*----------------------------- Protocol version ------------------------------146*147* versions148* Values: <string>149*150* List of XENSND_LIST_SEPARATOR separated protocol versions supported151* by the backend. For example "1,2,3".152*153******************************************************************************154* Frontend XenBus Nodes155******************************************************************************156*157*-------------------------------- Addressing ---------------------------------158*159* dom-id160* Values: <uint16_t>161*162* Domain identifier.163*164* dev-id165* Values: <uint16_t>166*167* Device identifier.168*169* pcm-dev-idx170* Values: <uint8_t>171*172* Zero based contigous index of the PCM device.173*174* stream-idx175* Values: <uint8_t>176*177* Zero based contigous index of the stream of the PCM device.178*179* The following pattern is used for addressing:180* /local/domain/<dom-id>/device/vsnd/<dev-id>/<pcm-dev-idx>/<stream-idx>/...181*182*----------------------------- Protocol version ------------------------------183*184* version185* Values: <string>186*187* Protocol version, chosen among the ones supported by the backend.188*189*------------------------------- PCM settings --------------------------------190*191* Every virtualized sound frontend has a set of PCM devices and streams, each192* could be individually configured. Part of the PCM configuration can be193* defined at higher level of the hierarchy and be fully or partially re-used194* by the underlying layers. These configuration values are:195* o number of channels (min/max)196* o supported sample rates197* o supported sample formats.198* E.g. one can define these values for the whole card, device or stream.199* Every underlying layer in turn can re-define some or all of them to better200* fit its needs. For example, card may define number of channels to be201* in [1; 8] range, and some particular stream may be limited to [1; 2] only.202* The rule is that the underlying layer must be a subset of the upper layer203* range.204*205* channels-min206* Values: <uint8_t>207*208* The minimum amount of channels that is supported, [1; channels-max].209* Optional, if not set or omitted a value of 1 is used.210*211* channels-max212* Values: <uint8_t>213*214* The maximum amount of channels that is supported.215* Must be at least <channels-min>.216*217* sample-rates218* Values: <list of uint32_t>219*220* List of supported sample rates separated by XENSND_LIST_SEPARATOR.221* Sample rates are expressed as a list of decimal values w/o any222* ordering requirement.223*224* sample-formats225* Values: <list of XENSND_PCM_FORMAT_XXX_STR>226*227* List of supported sample formats separated by XENSND_LIST_SEPARATOR.228* Items must not exceed XENSND_SAMPLE_FORMAT_MAX_LEN length.229*230* buffer-size231* Values: <uint32_t>232*233* The maximum size in octets of the buffer to allocate per stream.234*235*----------------------- Virtual sound card settings -------------------------236* short-name237* Values: <char[32]>238*239* Short name of the virtual sound card. Optional.240*241* long-name242* Values: <char[80]>243*244* Long name of the virtual sound card. Optional.245*246*----------------------------- Device settings -------------------------------247* name248* Values: <char[80]>249*250* Name of the sound device within the virtual sound card. Optional.251*252*----------------------------- Stream settings -------------------------------253*254* type255* Values: "p", "c"256*257* Stream type: "p" - playback stream, "c" - capture stream258*259* If both capture and playback are needed then two streams need to be260* defined under the same device.261*262* unique-id263* Values: <string>264*265* After stream initialization it is assigned a unique ID, so every266* stream of the frontend can be identified by the backend by this ID.267* This can be UUID or such.268*269*-------------------- Stream Request Transport Parameters --------------------270*271* event-channel272* Values: <uint32_t>273*274* The identifier of the Xen event channel used to signal activity275* in the ring buffer.276*277* ring-ref278* Values: <uint32_t>279*280* The Xen grant reference granting permission for the backend to map281* a sole page in a single page sized ring buffer.282*283*--------------------- Stream Event Transport Parameters ---------------------284*285* This communication path is used to deliver asynchronous events from backend286* to frontend, set up per stream.287*288* evt-event-channel289* Values: <uint32_t>290*291* The identifier of the Xen event channel used to signal activity292* in the ring buffer.293*294* evt-ring-ref295* Values: <uint32_t>296*297* The Xen grant reference granting permission for the backend to map298* a sole page in a single page sized ring buffer.299*300******************************************************************************301* STATE DIAGRAMS302******************************************************************************303*304* Tool stack creates front and back state nodes with initial state305* XenbusStateInitialising.306* Tool stack creates and sets up frontend sound configuration nodes per domain.307*308* Front Back309* ================================= =====================================310* XenbusStateInitialising XenbusStateInitialising311* o Query backend device identification312* data.313* o Open and validate backend device.314* |315* |316* V317* XenbusStateInitWait318*319* o Query frontend configuration320* o Allocate and initialize321* event channels per configured322* playback/capture stream.323* o Publish transport parameters324* that will be in effect during325* this connection.326* |327* |328* V329* XenbusStateInitialised330*331* o Query frontend transport parameters.332* o Connect to the event channels.333* |334* |335* V336* XenbusStateConnected337*338* o Create and initialize OS339* virtual sound device instances340* as per configuration.341* |342* |343* V344* XenbusStateConnected345*346* XenbusStateUnknown347* XenbusStateClosed348* XenbusStateClosing349* o Remove virtual sound device350* o Remove event channels351* |352* |353* V354* XenbusStateClosed355*356*------------------------------- Recovery flow -------------------------------357*358* In case of frontend unrecoverable errors backend handles that as359* if frontend goes into the XenbusStateClosed state.360*361* In case of backend unrecoverable errors frontend tries removing362* the virtualized device. If this is possible at the moment of error,363* then frontend goes into the XenbusStateInitialising state and is ready for364* new connection with backend. If the virtualized device is still in use and365* cannot be removed, then frontend goes into the XenbusStateReconfiguring state366* until either the virtualized device removed or backend initiates a new367* connection. On the virtualized device removal frontend goes into the368* XenbusStateInitialising state.369*370* Note on XenbusStateReconfiguring state of the frontend: if backend has371* unrecoverable errors then frontend cannot send requests to the backend372* and thus cannot provide functionality of the virtualized device anymore.373* After backend is back to normal the virtualized device may still hold some374* state: configuration in use, allocated buffers, client application state etc.375* So, in most cases, this will require frontend to implement complex recovery376* reconnect logic. Instead, by going into XenbusStateReconfiguring state,377* frontend will make sure no new clients of the virtualized device are378* accepted, allow existing client(s) to exit gracefully by signaling error379* state etc.380* Once all the clients are gone frontend can reinitialize the virtualized381* device and get into XenbusStateInitialising state again signaling the382* backend that a new connection can be made.383*384* There are multiple conditions possible under which frontend will go from385* XenbusStateReconfiguring into XenbusStateInitialising, some of them are OS386* specific. For example:387* 1. The underlying OS framework may provide callbacks to signal that the last388* client of the virtualized device has gone and the device can be removed389* 2. Frontend can schedule a deferred work (timer/tasklet/workqueue)390* to periodically check if this is the right time to re-try removal of391* the virtualized device.392* 3. By any other means.393*394******************************************************************************395* PCM FORMATS396******************************************************************************397*398* XENSND_PCM_FORMAT_<format>[_<endian>]399*400* format: <S/U/F><bits> or <name>401* S - signed, U - unsigned, F - float402* bits - 8, 16, 24, 32403* name - MU_LAW, GSM, etc.404*405* endian: <LE/BE>, may be absent406* LE - Little endian, BE - Big endian407*/408#define XENSND_PCM_FORMAT_S8 0409#define XENSND_PCM_FORMAT_U8 1410#define XENSND_PCM_FORMAT_S16_LE 2411#define XENSND_PCM_FORMAT_S16_BE 3412#define XENSND_PCM_FORMAT_U16_LE 4413#define XENSND_PCM_FORMAT_U16_BE 5414#define XENSND_PCM_FORMAT_S24_LE 6415#define XENSND_PCM_FORMAT_S24_BE 7416#define XENSND_PCM_FORMAT_U24_LE 8417#define XENSND_PCM_FORMAT_U24_BE 9418#define XENSND_PCM_FORMAT_S32_LE 10419#define XENSND_PCM_FORMAT_S32_BE 11420#define XENSND_PCM_FORMAT_U32_LE 12421#define XENSND_PCM_FORMAT_U32_BE 13422#define XENSND_PCM_FORMAT_F32_LE 14 /* 4-byte float, IEEE-754 32-bit, */423#define XENSND_PCM_FORMAT_F32_BE 15 /* range -1.0 to 1.0 */424#define XENSND_PCM_FORMAT_F64_LE 16 /* 8-byte float, IEEE-754 64-bit, */425#define XENSND_PCM_FORMAT_F64_BE 17 /* range -1.0 to 1.0 */426#define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE 18427#define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE 19428#define XENSND_PCM_FORMAT_MU_LAW 20429#define XENSND_PCM_FORMAT_A_LAW 21430#define XENSND_PCM_FORMAT_IMA_ADPCM 22431#define XENSND_PCM_FORMAT_MPEG 23432#define XENSND_PCM_FORMAT_GSM 24433434/*435******************************************************************************436* REQUEST CODES437******************************************************************************438*/439#define XENSND_OP_OPEN 0440#define XENSND_OP_CLOSE 1441#define XENSND_OP_READ 2442#define XENSND_OP_WRITE 3443#define XENSND_OP_SET_VOLUME 4444#define XENSND_OP_GET_VOLUME 5445#define XENSND_OP_MUTE 6446#define XENSND_OP_UNMUTE 7447#define XENSND_OP_TRIGGER 8448#define XENSND_OP_HW_PARAM_QUERY 9449450#define XENSND_OP_TRIGGER_START 0451#define XENSND_OP_TRIGGER_PAUSE 1452#define XENSND_OP_TRIGGER_STOP 2453#define XENSND_OP_TRIGGER_RESUME 3454455/*456******************************************************************************457* EVENT CODES458******************************************************************************459*/460#define XENSND_EVT_CUR_POS 0461462/*463******************************************************************************464* XENSTORE FIELD AND PATH NAME STRINGS, HELPERS465******************************************************************************466*/467#define XENSND_DRIVER_NAME "vsnd"468469#define XENSND_LIST_SEPARATOR ","470/* Field names */471#define XENSND_FIELD_BE_VERSIONS "versions"472#define XENSND_FIELD_FE_VERSION "version"473#define XENSND_FIELD_VCARD_SHORT_NAME "short-name"474#define XENSND_FIELD_VCARD_LONG_NAME "long-name"475#define XENSND_FIELD_RING_REF "ring-ref"476#define XENSND_FIELD_EVT_CHNL "event-channel"477#define XENSND_FIELD_EVT_RING_REF "evt-ring-ref"478#define XENSND_FIELD_EVT_EVT_CHNL "evt-event-channel"479#define XENSND_FIELD_DEVICE_NAME "name"480#define XENSND_FIELD_TYPE "type"481#define XENSND_FIELD_STREAM_UNIQUE_ID "unique-id"482#define XENSND_FIELD_CHANNELS_MIN "channels-min"483#define XENSND_FIELD_CHANNELS_MAX "channels-max"484#define XENSND_FIELD_SAMPLE_RATES "sample-rates"485#define XENSND_FIELD_SAMPLE_FORMATS "sample-formats"486#define XENSND_FIELD_BUFFER_SIZE "buffer-size"487488/* Stream type field values. */489#define XENSND_STREAM_TYPE_PLAYBACK "p"490#define XENSND_STREAM_TYPE_CAPTURE "c"491/* Sample rate max string length */492#define XENSND_SAMPLE_RATE_MAX_LEN 11493/* Sample format field values */494#define XENSND_SAMPLE_FORMAT_MAX_LEN 24495496#define XENSND_PCM_FORMAT_S8_STR "s8"497#define XENSND_PCM_FORMAT_U8_STR "u8"498#define XENSND_PCM_FORMAT_S16_LE_STR "s16_le"499#define XENSND_PCM_FORMAT_S16_BE_STR "s16_be"500#define XENSND_PCM_FORMAT_U16_LE_STR "u16_le"501#define XENSND_PCM_FORMAT_U16_BE_STR "u16_be"502#define XENSND_PCM_FORMAT_S24_LE_STR "s24_le"503#define XENSND_PCM_FORMAT_S24_BE_STR "s24_be"504#define XENSND_PCM_FORMAT_U24_LE_STR "u24_le"505#define XENSND_PCM_FORMAT_U24_BE_STR "u24_be"506#define XENSND_PCM_FORMAT_S32_LE_STR "s32_le"507#define XENSND_PCM_FORMAT_S32_BE_STR "s32_be"508#define XENSND_PCM_FORMAT_U32_LE_STR "u32_le"509#define XENSND_PCM_FORMAT_U32_BE_STR "u32_be"510#define XENSND_PCM_FORMAT_F32_LE_STR "float_le"511#define XENSND_PCM_FORMAT_F32_BE_STR "float_be"512#define XENSND_PCM_FORMAT_F64_LE_STR "float64_le"513#define XENSND_PCM_FORMAT_F64_BE_STR "float64_be"514#define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE_STR "iec958_subframe_le"515#define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE_STR "iec958_subframe_be"516#define XENSND_PCM_FORMAT_MU_LAW_STR "mu_law"517#define XENSND_PCM_FORMAT_A_LAW_STR "a_law"518#define XENSND_PCM_FORMAT_IMA_ADPCM_STR "ima_adpcm"519#define XENSND_PCM_FORMAT_MPEG_STR "mpeg"520#define XENSND_PCM_FORMAT_GSM_STR "gsm"521522523/*524******************************************************************************525* STATUS RETURN CODES526******************************************************************************527*528* Status return code is zero on success and -XEN_EXX on failure.529*530******************************************************************************531* Assumptions532******************************************************************************533* o usage of grant reference 0 as invalid grant reference:534* grant reference 0 is valid, but never exposed to a PV driver,535* because of the fact it is already in use/reserved by the PV console.536* o all references in this document to page sizes must be treated537* as pages of size XEN_PAGE_SIZE unless otherwise noted.538*539******************************************************************************540* Description of the protocol between frontend and backend driver541******************************************************************************542*543* The two halves of a Para-virtual sound driver communicate with544* each other using shared pages and event channels.545* Shared page contains a ring with request/response packets.546*547* Packets, used for input/output operations, e.g. read/write, set/get volume,548* etc., provide offset/length fields in order to allow asynchronous protocol549* operation with buffer space sharing: part of the buffer allocated at550* XENSND_OP_OPEN can be used for audio samples and part, for example,551* for volume control.552*553* All reserved fields in the structures below must be 0.554*555*---------------------------------- Requests ---------------------------------556*557* All request packets have the same length (64 octets)558* All request packets have common header:559* 0 1 2 3 octet560* +----------------+----------------+----------------+----------------+561* | id | operation | reserved | 4562* +----------------+----------------+----------------+----------------+563* | reserved | 8564* +----------------+----------------+----------------+----------------+565* id - uint16_t, private guest value, echoed in response566* operation - uint8_t, operation code, XENSND_OP_???567*568* For all packets which use offset and length:569* offset - uint32_t, read or write data offset within the shared buffer,570* passed with XENSND_OP_OPEN request, octets,571* [0; XENSND_OP_OPEN.buffer_sz - 1].572* length - uint32_t, read or write data length, octets573*574* Request open - open a PCM stream for playback or capture:575*576* 0 1 2 3 octet577* +----------------+----------------+----------------+----------------+578* | id | XENSND_OP_OPEN | reserved | 4579* +----------------+----------------+----------------+----------------+580* | reserved | 8581* +----------------+----------------+----------------+----------------+582* | pcm_rate | 12583* +----------------+----------------+----------------+----------------+584* | pcm_format | pcm_channels | reserved | 16585* +----------------+----------------+----------------+----------------+586* | buffer_sz | 20587* +----------------+----------------+----------------+----------------+588* | gref_directory | 24589* +----------------+----------------+----------------+----------------+590* | period_sz | 28591* +----------------+----------------+----------------+----------------+592* | reserved | 32593* +----------------+----------------+----------------+----------------+594* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|595* +----------------+----------------+----------------+----------------+596* | reserved | 64597* +----------------+----------------+----------------+----------------+598*599* pcm_rate - uint32_t, stream data rate, Hz600* pcm_format - uint8_t, XENSND_PCM_FORMAT_XXX value601* pcm_channels - uint8_t, number of channels of this stream,602* [channels-min; channels-max]603* buffer_sz - uint32_t, buffer size to be allocated, octets604* period_sz - uint32_t, event period size, octets605* This is the requested value of the period at which frontend would606* like to receive XENSND_EVT_CUR_POS notifications from the backend when607* stream position advances during playback/capture.608* It shows how many octets are expected to be played/captured before609* sending such an event.610* If set to 0 no XENSND_EVT_CUR_POS events are sent by the backend.611*612* gref_directory - grant_ref_t, a reference to the first shared page613* describing shared buffer references. At least one page exists. If shared614* buffer size (buffer_sz) exceeds what can be addressed by this single page,615* then reference to the next page must be supplied (see gref_dir_next_page616* below)617*/618619struct xensnd_open_req {620uint32_t pcm_rate;621uint8_t pcm_format;622uint8_t pcm_channels;623uint16_t reserved;624uint32_t buffer_sz;625grant_ref_t gref_directory;626uint32_t period_sz;627};628629/*630* Shared page for XENSND_OP_OPEN buffer descriptor (gref_directory in the631* request) employs a list of pages, describing all pages of the shared data632* buffer:633* 0 1 2 3 octet634* +----------------+----------------+----------------+----------------+635* | gref_dir_next_page | 4636* +----------------+----------------+----------------+----------------+637* | gref[0] | 8638* +----------------+----------------+----------------+----------------+639* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|640* +----------------+----------------+----------------+----------------+641* | gref[i] | i*4+8642* +----------------+----------------+----------------+----------------+643* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|644* +----------------+----------------+----------------+----------------+645* | gref[N - 1] | N*4+8646* +----------------+----------------+----------------+----------------+647*648* gref_dir_next_page - grant_ref_t, reference to the next page describing649* page directory. Must be 0 if there are no more pages in the list.650* gref[i] - grant_ref_t, reference to a shared page of the buffer651* allocated at XENSND_OP_OPEN652*653* Number of grant_ref_t entries in the whole page directory is not654* passed, but instead can be calculated as:655* num_grefs_total = (XENSND_OP_OPEN.buffer_sz + XEN_PAGE_SIZE - 1) /656* XEN_PAGE_SIZE657*/658659struct xensnd_page_directory {660grant_ref_t gref_dir_next_page;661grant_ref_t gref[];662};663664/*665* Request close - close an opened pcm stream:666* 0 1 2 3 octet667* +----------------+----------------+----------------+----------------+668* | id | XENSND_OP_CLOSE| reserved | 4669* +----------------+----------------+----------------+----------------+670* | reserved | 8671* +----------------+----------------+----------------+----------------+672* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|673* +----------------+----------------+----------------+----------------+674* | reserved | 64675* +----------------+----------------+----------------+----------------+676*677* Request read/write - used for read (for capture) or write (for playback):678* 0 1 2 3 octet679* +----------------+----------------+----------------+----------------+680* | id | operation | reserved | 4681* +----------------+----------------+----------------+----------------+682* | reserved | 8683* +----------------+----------------+----------------+----------------+684* | offset | 12685* +----------------+----------------+----------------+----------------+686* | length | 16687* +----------------+----------------+----------------+----------------+688* | reserved | 20689* +----------------+----------------+----------------+----------------+690* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|691* +----------------+----------------+----------------+----------------+692* | reserved | 64693* +----------------+----------------+----------------+----------------+694*695* operation - XENSND_OP_READ for read or XENSND_OP_WRITE for write696*/697698struct xensnd_rw_req {699uint32_t offset;700uint32_t length;701};702703/*704* Request set/get volume - set/get channels' volume of the stream given:705* 0 1 2 3 octet706* +----------------+----------------+----------------+----------------+707* | id | operation | reserved | 4708* +----------------+----------------+----------------+----------------+709* | reserved | 8710* +----------------+----------------+----------------+----------------+711* | offset | 12712* +----------------+----------------+----------------+----------------+713* | length | 16714* +----------------+----------------+----------------+----------------+715* | reserved | 20716* +----------------+----------------+----------------+----------------+717* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|718* +----------------+----------------+----------------+----------------+719* | reserved | 64720* +----------------+----------------+----------------+----------------+721*722* operation - XENSND_OP_SET_VOLUME for volume set723* or XENSND_OP_GET_VOLUME for volume get724* Buffer passed with XENSND_OP_OPEN is used to exchange volume725* values:726*727* 0 1 2 3 octet728* +----------------+----------------+----------------+----------------+729* | channel[0] | 4730* +----------------+----------------+----------------+----------------+731* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|732* +----------------+----------------+----------------+----------------+733* | channel[i] | i*4734* +----------------+----------------+----------------+----------------+735* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|736* +----------------+----------------+----------------+----------------+737* | channel[N - 1] | (N-1)*4738* +----------------+----------------+----------------+----------------+739*740* N = XENSND_OP_OPEN.pcm_channels741* i - uint8_t, index of a channel742* channel[i] - sint32_t, volume of i-th channel743* Volume is expressed as a signed value in steps of 0.001 dB,744* while 0 being 0 dB.745*746* Request mute/unmute - mute/unmute stream:747* 0 1 2 3 octet748* +----------------+----------------+----------------+----------------+749* | id | operation | reserved | 4750* +----------------+----------------+----------------+----------------+751* | reserved | 8752* +----------------+----------------+----------------+----------------+753* | offset | 12754* +----------------+----------------+----------------+----------------+755* | length | 16756* +----------------+----------------+----------------+----------------+757* | reserved | 20758* +----------------+----------------+----------------+----------------+759* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|760* +----------------+----------------+----------------+----------------+761* | reserved | 64762* +----------------+----------------+----------------+----------------+763*764* operation - XENSND_OP_MUTE for mute or XENSND_OP_UNMUTE for unmute765* Buffer passed with XENSND_OP_OPEN is used to exchange mute/unmute766* values:767*768* 0 octet769* +----------------+----------------+----------------+----------------+770* | channel[0] | 4771* +----------------+----------------+----------------+----------------+772* +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|773* +----------------+----------------+----------------+----------------+774* | channel[i] | i*4775* +----------------+----------------+----------------+----------------+776* +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|777* +----------------+----------------+----------------+----------------+778* | channel[N - 1] | (N-1)*4779* +----------------+----------------+----------------+----------------+780*781* N = XENSND_OP_OPEN.pcm_channels782* i - uint8_t, index of a channel783* channel[i] - uint8_t, non-zero if i-th channel needs to be muted/unmuted784*785*------------------------------------ N.B. -----------------------------------786*787* The 'struct xensnd_rw_req' is also used for XENSND_OP_SET_VOLUME,788* XENSND_OP_GET_VOLUME, XENSND_OP_MUTE, XENSND_OP_UNMUTE.789*790* Request stream running state change - trigger PCM stream running state791* to start, stop, pause or resume:792*793* 0 1 2 3 octet794* +----------------+----------------+----------------+----------------+795* | id | _OP_TRIGGER | reserved | 4796* +----------------+----------------+----------------+----------------+797* | reserved | 8798* +----------------+----------------+----------------+----------------+799* | type | reserved | 12800* +----------------+----------------+----------------+----------------+801* | reserved | 16802* +----------------+----------------+----------------+----------------+803* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|804* +----------------+----------------+----------------+----------------+805* | reserved | 64806* +----------------+----------------+----------------+----------------+807*808* type - uint8_t, XENSND_OP_TRIGGER_XXX value809*/810811struct xensnd_trigger_req {812uint8_t type;813};814815/*816* Request stream parameter ranges: request intervals and817* masks of supported ranges for stream configuration values.818*819* Sound device configuration for a particular stream is a limited subset820* of the multidimensional configuration available on XenStore, e.g.821* once the frame rate has been selected there is a limited supported range822* for sample rates becomes available (which might be the same set configured823* on XenStore or less). For example, selecting 96kHz sample rate may limit824* number of channels available for such configuration from 4 to 2, etc.825* Thus, each call to XENSND_OP_HW_PARAM_QUERY may reduce configuration826* space making it possible to iteratively get the final stream configuration,827* used in XENSND_OP_OPEN request.828*829* See response format for this request.830*831* 0 1 2 3 octet832* +----------------+----------------+----------------+----------------+833* | id | _HW_PARAM_QUERY| reserved | 4834* +----------------+----------------+----------------+----------------+835* | reserved | 8836* +----------------+----------------+----------------+----------------+837* | formats mask low 32-bit | 12838* +----------------+----------------+----------------+----------------+839* | formats mask high 32-bit | 16840* +----------------+----------------+----------------+----------------+841* | min rate | 20842* +----------------+----------------+----------------+----------------+843* | max rate | 24844* +----------------+----------------+----------------+----------------+845* | min channels | 28846* +----------------+----------------+----------------+----------------+847* | max channels | 32848* +----------------+----------------+----------------+----------------+849* | min buffer frames | 36850* +----------------+----------------+----------------+----------------+851* | max buffer frames | 40852* +----------------+----------------+----------------+----------------+853* | min period frames | 44854* +----------------+----------------+----------------+----------------+855* | max period frames | 48856* +----------------+----------------+----------------+----------------+857* | reserved | 52858* +----------------+----------------+----------------+----------------+859* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|860* +----------------+----------------+----------------+----------------+861* | reserved | 64862* +----------------+----------------+----------------+----------------+863*864* formats - uint64_t, bit mask representing values of the parameter865* made as bitwise OR of (1 << XENSND_PCM_FORMAT_XXX) values866*867* For interval parameters:868* min - uint32_t, minimum value of the parameter869* max - uint32_t, maximum value of the parameter870*871* Frame is defined as a product of the number of channels by the872* number of octets per one sample.873*/874875struct xensnd_query_hw_param {876uint64_t formats;877struct {878uint32_t min;879uint32_t max;880} rates;881struct {882uint32_t min;883uint32_t max;884} channels;885struct {886uint32_t min;887uint32_t max;888} buffer;889struct {890uint32_t min;891uint32_t max;892} period;893};894895/*896*---------------------------------- Responses --------------------------------897*898* All response packets have the same length (64 octets)899*900* All response packets have common header:901* 0 1 2 3 octet902* +----------------+----------------+----------------+----------------+903* | id | operation | reserved | 4904* +----------------+----------------+----------------+----------------+905* | status | 8906* +----------------+----------------+----------------+----------------+907*908* id - uint16_t, copied from the request909* operation - uint8_t, XENSND_OP_* - copied from request910* status - int32_t, response status, zero on success and -XEN_EXX on failure911*912*913* HW parameter query response - response for XENSND_OP_HW_PARAM_QUERY:914* 0 1 2 3 octet915* +----------------+----------------+----------------+----------------+916* | id | operation | reserved | 4917* +----------------+----------------+----------------+----------------+918* | status | 8919* +----------------+----------------+----------------+----------------+920* | formats mask low 32-bit | 12921* +----------------+----------------+----------------+----------------+922* | formats mask high 32-bit | 16923* +----------------+----------------+----------------+----------------+924* | min rate | 20925* +----------------+----------------+----------------+----------------+926* | max rate | 24927* +----------------+----------------+----------------+----------------+928* | min channels | 28929* +----------------+----------------+----------------+----------------+930* | max channels | 32931* +----------------+----------------+----------------+----------------+932* | min buffer frames | 36933* +----------------+----------------+----------------+----------------+934* | max buffer frames | 40935* +----------------+----------------+----------------+----------------+936* | min period frames | 44937* +----------------+----------------+----------------+----------------+938* | max period frames | 48939* +----------------+----------------+----------------+----------------+940* | reserved | 52941* +----------------+----------------+----------------+----------------+942* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|943* +----------------+----------------+----------------+----------------+944* | reserved | 64945* +----------------+----------------+----------------+----------------+946*947* Meaning of the values in this response is the same as for948* XENSND_OP_HW_PARAM_QUERY request.949*/950951/*952*----------------------------------- Events ----------------------------------953*954* Events are sent via shared page allocated by the front and propagated by955* evt-event-channel/evt-ring-ref XenStore entries956* All event packets have the same length (64 octets)957* All event packets have common header:958* 0 1 2 3 octet959* +----------------+----------------+----------------+----------------+960* | id | type | reserved | 4961* +----------------+----------------+----------------+----------------+962* | reserved | 8963* +----------------+----------------+----------------+----------------+964*965* id - uint16_t, event id, may be used by front966* type - uint8_t, type of the event967*968*969* Current stream position - event from back to front when stream's970* playback/capture position has advanced:971* 0 1 2 3 octet972* +----------------+----------------+----------------+----------------+973* | id | _EVT_CUR_POS | reserved | 4974* +----------------+----------------+----------------+----------------+975* | reserved | 8976* +----------------+----------------+----------------+----------------+977* | position low 32-bit | 12978* +----------------+----------------+----------------+----------------+979* | position high 32-bit | 16980* +----------------+----------------+----------------+----------------+981* | reserved | 20982* +----------------+----------------+----------------+----------------+983* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|984* +----------------+----------------+----------------+----------------+985* | reserved | 64986* +----------------+----------------+----------------+----------------+987*988* position - current value of stream's playback/capture position, octets989*990*/991992struct xensnd_cur_pos_evt {993uint64_t position;994};995996struct xensnd_req {997uint16_t id;998uint8_t operation;999uint8_t reserved[5];1000union {1001struct xensnd_open_req open;1002struct xensnd_rw_req rw;1003struct xensnd_trigger_req trigger;1004struct xensnd_query_hw_param hw_param;1005uint8_t reserved[56];1006} op;1007};10081009struct xensnd_resp {1010uint16_t id;1011uint8_t operation;1012uint8_t reserved;1013int32_t status;1014union {1015struct xensnd_query_hw_param hw_param;1016uint8_t reserved1[56];1017} resp;1018};10191020struct xensnd_evt {1021uint16_t id;1022uint8_t type;1023uint8_t reserved[5];1024union {1025struct xensnd_cur_pos_evt cur_pos;1026uint8_t reserved[56];1027} op;1028};10291030DEFINE_RING_TYPES(xen_sndif, struct xensnd_req, struct xensnd_resp);10311032/*1033******************************************************************************1034* Back to front events delivery1035******************************************************************************1036* In order to deliver asynchronous events from back to front a shared page is1037* allocated by front and its granted reference propagated to back via1038* XenStore entries (evt-ring-ref/evt-event-channel).1039* This page has a common header used by both front and back to synchronize1040* access and control event's ring buffer, while back being a producer of the1041* events and front being a consumer. The rest of the page after the header1042* is used for event packets.1043*1044* Upon reception of an event(s) front may confirm its reception1045* for either each event, group of events or none.1046*/10471048struct xensnd_event_page {1049uint32_t in_cons;1050uint32_t in_prod;1051uint8_t reserved[56];1052};10531054#define XENSND_EVENT_PAGE_SIZE XEN_PAGE_SIZE1055#define XENSND_IN_RING_OFFS (sizeof(struct xensnd_event_page))1056#define XENSND_IN_RING_SIZE (XENSND_EVENT_PAGE_SIZE - XENSND_IN_RING_OFFS)1057#define XENSND_IN_RING_LEN (XENSND_IN_RING_SIZE / sizeof(struct xensnd_evt))1058#define XENSND_IN_RING(page) \1059((struct xensnd_evt *)((char *)(page) + XENSND_IN_RING_OFFS))1060#define XENSND_IN_RING_REF(page, idx) \1061(XENSND_IN_RING((page))[(idx) % XENSND_IN_RING_LEN])10621063#endif /* __XEN_PUBLIC_IO_SNDIF_H__ */106410651066