18c2ecf20Sopenharmony_ci/******************************************************************************
28c2ecf20Sopenharmony_ci * sndif.h
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Unified sound-device I/O interface for Xen guest OSes.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
78c2ecf20Sopenharmony_ci * of this software and associated documentation files (the "Software"), to
88c2ecf20Sopenharmony_ci * deal in the Software without restriction, including without limitation the
98c2ecf20Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
108c2ecf20Sopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is
118c2ecf20Sopenharmony_ci * furnished to do so, subject to the following conditions:
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
148c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
178c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
188c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
198c2ecf20Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
208c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
218c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
228c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * Copyright (C) 2013-2015 GlobalLogic Inc.
258c2ecf20Sopenharmony_ci * Copyright (C) 2016-2017 EPAM Systems Inc.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * Authors: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
288c2ecf20Sopenharmony_ci *          Oleksandr Grytsov <oleksandr_grytsov@epam.com>
298c2ecf20Sopenharmony_ci *          Oleksandr Dmytryshyn <oleksandr.dmytryshyn@globallogic.com>
308c2ecf20Sopenharmony_ci *          Iurii Konovalenko <iurii.konovalenko@globallogic.com>
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#ifndef __XEN_PUBLIC_IO_SNDIF_H__
348c2ecf20Sopenharmony_ci#define __XEN_PUBLIC_IO_SNDIF_H__
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include "ring.h"
378c2ecf20Sopenharmony_ci#include "../grant_table.h"
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/*
408c2ecf20Sopenharmony_ci ******************************************************************************
418c2ecf20Sopenharmony_ci *                           Protocol version
428c2ecf20Sopenharmony_ci ******************************************************************************
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_ci#define XENSND_PROTOCOL_VERSION	2
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/*
478c2ecf20Sopenharmony_ci ******************************************************************************
488c2ecf20Sopenharmony_ci *                  Feature and Parameter Negotiation
498c2ecf20Sopenharmony_ci ******************************************************************************
508c2ecf20Sopenharmony_ci *
518c2ecf20Sopenharmony_ci * Front->back notifications: when enqueuing a new request, sending a
528c2ecf20Sopenharmony_ci * notification can be made conditional on xensnd_req (i.e., the generic
538c2ecf20Sopenharmony_ci * hold-off mechanism provided by the ring macros). Backends must set
548c2ecf20Sopenharmony_ci * xensnd_req appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
558c2ecf20Sopenharmony_ci *
568c2ecf20Sopenharmony_ci * Back->front notifications: when enqueuing a new response, sending a
578c2ecf20Sopenharmony_ci * notification can be made conditional on xensnd_resp (i.e., the generic
588c2ecf20Sopenharmony_ci * hold-off mechanism provided by the ring macros). Frontends must set
598c2ecf20Sopenharmony_ci * xensnd_resp appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
608c2ecf20Sopenharmony_ci *
618c2ecf20Sopenharmony_ci * The two halves of a para-virtual sound card driver utilize nodes within
628c2ecf20Sopenharmony_ci * XenStore to communicate capabilities and to negotiate operating parameters.
638c2ecf20Sopenharmony_ci * This section enumerates these nodes which reside in the respective front and
648c2ecf20Sopenharmony_ci * backend portions of XenStore, following the XenBus convention.
658c2ecf20Sopenharmony_ci *
668c2ecf20Sopenharmony_ci * All data in XenStore is stored as strings. Nodes specifying numeric
678c2ecf20Sopenharmony_ci * values are encoded in decimal. Integer value ranges listed below are
688c2ecf20Sopenharmony_ci * expressed as fixed sized integer types capable of storing the conversion
698c2ecf20Sopenharmony_ci * of a properly formated node string, without loss of information.
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci ******************************************************************************
728c2ecf20Sopenharmony_ci *                        Example configuration
738c2ecf20Sopenharmony_ci ******************************************************************************
748c2ecf20Sopenharmony_ci *
758c2ecf20Sopenharmony_ci * Note: depending on the use-case backend can expose more sound cards and
768c2ecf20Sopenharmony_ci * PCM devices/streams than the underlying HW physically has by employing
778c2ecf20Sopenharmony_ci * SW mixers, configuring virtual sound streams, channels etc.
788c2ecf20Sopenharmony_ci *
798c2ecf20Sopenharmony_ci * This is an example of backend and frontend configuration:
808c2ecf20Sopenharmony_ci *
818c2ecf20Sopenharmony_ci *--------------------------------- Backend -----------------------------------
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci * /local/domain/0/backend/vsnd/1/0/frontend-id = "1"
848c2ecf20Sopenharmony_ci * /local/domain/0/backend/vsnd/1/0/frontend = "/local/domain/1/device/vsnd/0"
858c2ecf20Sopenharmony_ci * /local/domain/0/backend/vsnd/1/0/state = "4"
868c2ecf20Sopenharmony_ci * /local/domain/0/backend/vsnd/1/0/versions = "1,2"
878c2ecf20Sopenharmony_ci *
888c2ecf20Sopenharmony_ci *--------------------------------- Frontend ----------------------------------
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/backend-id = "0"
918c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/backend = "/local/domain/0/backend/vsnd/1/0"
928c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/state = "4"
938c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/version = "1"
948c2ecf20Sopenharmony_ci *
958c2ecf20Sopenharmony_ci *----------------------------- Card configuration ----------------------------
968c2ecf20Sopenharmony_ci *
978c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/short-name = "Card short name"
988c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/long-name = "Card long name"
998c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/sample-rates = "8000,32000,44100,48000,96000"
1008c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/sample-formats = "s8,u8,s16_le,s16_be"
1018c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/buffer-size = "262144"
1028c2ecf20Sopenharmony_ci *
1038c2ecf20Sopenharmony_ci *------------------------------- PCM device 0 --------------------------------
1048c2ecf20Sopenharmony_ci *
1058c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/name = "General analog"
1068c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/channels-max = "5"
1078c2ecf20Sopenharmony_ci *
1088c2ecf20Sopenharmony_ci *----------------------------- Stream 0, playback ----------------------------
1098c2ecf20Sopenharmony_ci *
1108c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/0/type = "p"
1118c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/0/sample-formats = "s8,u8"
1128c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/0/unique-id = "0"
1138c2ecf20Sopenharmony_ci *
1148c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/0/ring-ref = "386"
1158c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/0/event-channel = "15"
1168c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/0/evt-ring-ref = "1386"
1178c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/0/evt-event-channel = "215"
1188c2ecf20Sopenharmony_ci *
1198c2ecf20Sopenharmony_ci *------------------------------ Stream 1, capture ----------------------------
1208c2ecf20Sopenharmony_ci *
1218c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/1/type = "c"
1228c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/1/channels-max = "2"
1238c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/1/unique-id = "1"
1248c2ecf20Sopenharmony_ci *
1258c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/1/ring-ref = "384"
1268c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/1/event-channel = "13"
1278c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/1/evt-ring-ref = "1384"
1288c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/0/1/evt-event-channel = "213"
1298c2ecf20Sopenharmony_ci *
1308c2ecf20Sopenharmony_ci *------------------------------- PCM device 1 --------------------------------
1318c2ecf20Sopenharmony_ci *
1328c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/1/name = "HDMI-0"
1338c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/1/sample-rates = "8000,32000,44100"
1348c2ecf20Sopenharmony_ci *
1358c2ecf20Sopenharmony_ci *------------------------------ Stream 0, capture ----------------------------
1368c2ecf20Sopenharmony_ci *
1378c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/1/0/type = "c"
1388c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/1/0/unique-id = "2"
1398c2ecf20Sopenharmony_ci *
1408c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/1/0/ring-ref = "387"
1418c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/1/0/event-channel = "151"
1428c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/1/0/evt-ring-ref = "1387"
1438c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/1/0/evt-event-channel = "351"
1448c2ecf20Sopenharmony_ci *
1458c2ecf20Sopenharmony_ci *------------------------------- PCM device 2 --------------------------------
1468c2ecf20Sopenharmony_ci *
1478c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/2/name = "SPDIF"
1488c2ecf20Sopenharmony_ci *
1498c2ecf20Sopenharmony_ci *----------------------------- Stream 0, playback ----------------------------
1508c2ecf20Sopenharmony_ci *
1518c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/2/0/type = "p"
1528c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/2/0/unique-id = "3"
1538c2ecf20Sopenharmony_ci *
1548c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/2/0/ring-ref = "389"
1558c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/2/0/event-channel = "152"
1568c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/2/0/evt-ring-ref = "1389"
1578c2ecf20Sopenharmony_ci * /local/domain/1/device/vsnd/0/2/0/evt-event-channel = "452"
1588c2ecf20Sopenharmony_ci *
1598c2ecf20Sopenharmony_ci ******************************************************************************
1608c2ecf20Sopenharmony_ci *                            Backend XenBus Nodes
1618c2ecf20Sopenharmony_ci ******************************************************************************
1628c2ecf20Sopenharmony_ci *
1638c2ecf20Sopenharmony_ci *----------------------------- Protocol version ------------------------------
1648c2ecf20Sopenharmony_ci *
1658c2ecf20Sopenharmony_ci * versions
1668c2ecf20Sopenharmony_ci *      Values:         <string>
1678c2ecf20Sopenharmony_ci *
1688c2ecf20Sopenharmony_ci *      List of XENSND_LIST_SEPARATOR separated protocol versions supported
1698c2ecf20Sopenharmony_ci *      by the backend. For example "1,2,3".
1708c2ecf20Sopenharmony_ci *
1718c2ecf20Sopenharmony_ci ******************************************************************************
1728c2ecf20Sopenharmony_ci *                            Frontend XenBus Nodes
1738c2ecf20Sopenharmony_ci ******************************************************************************
1748c2ecf20Sopenharmony_ci *
1758c2ecf20Sopenharmony_ci *-------------------------------- Addressing ---------------------------------
1768c2ecf20Sopenharmony_ci *
1778c2ecf20Sopenharmony_ci * dom-id
1788c2ecf20Sopenharmony_ci *      Values:         <uint16_t>
1798c2ecf20Sopenharmony_ci *
1808c2ecf20Sopenharmony_ci *      Domain identifier.
1818c2ecf20Sopenharmony_ci *
1828c2ecf20Sopenharmony_ci * dev-id
1838c2ecf20Sopenharmony_ci *      Values:         <uint16_t>
1848c2ecf20Sopenharmony_ci *
1858c2ecf20Sopenharmony_ci *      Device identifier.
1868c2ecf20Sopenharmony_ci *
1878c2ecf20Sopenharmony_ci * pcm-dev-idx
1888c2ecf20Sopenharmony_ci *      Values:         <uint8_t>
1898c2ecf20Sopenharmony_ci *
1908c2ecf20Sopenharmony_ci *      Zero based contigous index of the PCM device.
1918c2ecf20Sopenharmony_ci *
1928c2ecf20Sopenharmony_ci * stream-idx
1938c2ecf20Sopenharmony_ci *      Values:         <uint8_t>
1948c2ecf20Sopenharmony_ci *
1958c2ecf20Sopenharmony_ci *      Zero based contigous index of the stream of the PCM device.
1968c2ecf20Sopenharmony_ci *
1978c2ecf20Sopenharmony_ci * The following pattern is used for addressing:
1988c2ecf20Sopenharmony_ci *   /local/domain/<dom-id>/device/vsnd/<dev-id>/<pcm-dev-idx>/<stream-idx>/...
1998c2ecf20Sopenharmony_ci *
2008c2ecf20Sopenharmony_ci *----------------------------- Protocol version ------------------------------
2018c2ecf20Sopenharmony_ci *
2028c2ecf20Sopenharmony_ci * version
2038c2ecf20Sopenharmony_ci *      Values:         <string>
2048c2ecf20Sopenharmony_ci *
2058c2ecf20Sopenharmony_ci *      Protocol version, chosen among the ones supported by the backend.
2068c2ecf20Sopenharmony_ci *
2078c2ecf20Sopenharmony_ci *------------------------------- PCM settings --------------------------------
2088c2ecf20Sopenharmony_ci *
2098c2ecf20Sopenharmony_ci * Every virtualized sound frontend has a set of PCM devices and streams, each
2108c2ecf20Sopenharmony_ci * could be individually configured. Part of the PCM configuration can be
2118c2ecf20Sopenharmony_ci * defined at higher level of the hierarchy and be fully or partially re-used
2128c2ecf20Sopenharmony_ci * by the underlying layers. These configuration values are:
2138c2ecf20Sopenharmony_ci *  o number of channels (min/max)
2148c2ecf20Sopenharmony_ci *  o supported sample rates
2158c2ecf20Sopenharmony_ci *  o supported sample formats.
2168c2ecf20Sopenharmony_ci * E.g. one can define these values for the whole card, device or stream.
2178c2ecf20Sopenharmony_ci * Every underlying layer in turn can re-define some or all of them to better
2188c2ecf20Sopenharmony_ci * fit its needs. For example, card may define number of channels to be
2198c2ecf20Sopenharmony_ci * in [1; 8] range, and some particular stream may be limited to [1; 2] only.
2208c2ecf20Sopenharmony_ci * The rule is that the underlying layer must be a subset of the upper layer
2218c2ecf20Sopenharmony_ci * range.
2228c2ecf20Sopenharmony_ci *
2238c2ecf20Sopenharmony_ci * channels-min
2248c2ecf20Sopenharmony_ci *      Values:         <uint8_t>
2258c2ecf20Sopenharmony_ci *
2268c2ecf20Sopenharmony_ci *      The minimum amount of channels that is supported, [1; channels-max].
2278c2ecf20Sopenharmony_ci *      Optional, if not set or omitted a value of 1 is used.
2288c2ecf20Sopenharmony_ci *
2298c2ecf20Sopenharmony_ci * channels-max
2308c2ecf20Sopenharmony_ci *      Values:         <uint8_t>
2318c2ecf20Sopenharmony_ci *
2328c2ecf20Sopenharmony_ci *      The maximum amount of channels that is supported.
2338c2ecf20Sopenharmony_ci *      Must be at least <channels-min>.
2348c2ecf20Sopenharmony_ci *
2358c2ecf20Sopenharmony_ci * sample-rates
2368c2ecf20Sopenharmony_ci *      Values:         <list of uint32_t>
2378c2ecf20Sopenharmony_ci *
2388c2ecf20Sopenharmony_ci *      List of supported sample rates separated by XENSND_LIST_SEPARATOR.
2398c2ecf20Sopenharmony_ci *      Sample rates are expressed as a list of decimal values w/o any
2408c2ecf20Sopenharmony_ci *      ordering requirement.
2418c2ecf20Sopenharmony_ci *
2428c2ecf20Sopenharmony_ci * sample-formats
2438c2ecf20Sopenharmony_ci *      Values:         <list of XENSND_PCM_FORMAT_XXX_STR>
2448c2ecf20Sopenharmony_ci *
2458c2ecf20Sopenharmony_ci *      List of supported sample formats separated by XENSND_LIST_SEPARATOR.
2468c2ecf20Sopenharmony_ci *      Items must not exceed XENSND_SAMPLE_FORMAT_MAX_LEN length.
2478c2ecf20Sopenharmony_ci *
2488c2ecf20Sopenharmony_ci * buffer-size
2498c2ecf20Sopenharmony_ci *      Values:         <uint32_t>
2508c2ecf20Sopenharmony_ci *
2518c2ecf20Sopenharmony_ci *      The maximum size in octets of the buffer to allocate per stream.
2528c2ecf20Sopenharmony_ci *
2538c2ecf20Sopenharmony_ci *----------------------- Virtual sound card settings -------------------------
2548c2ecf20Sopenharmony_ci * short-name
2558c2ecf20Sopenharmony_ci *      Values:         <char[32]>
2568c2ecf20Sopenharmony_ci *
2578c2ecf20Sopenharmony_ci *      Short name of the virtual sound card. Optional.
2588c2ecf20Sopenharmony_ci *
2598c2ecf20Sopenharmony_ci * long-name
2608c2ecf20Sopenharmony_ci *      Values:         <char[80]>
2618c2ecf20Sopenharmony_ci *
2628c2ecf20Sopenharmony_ci *      Long name of the virtual sound card. Optional.
2638c2ecf20Sopenharmony_ci *
2648c2ecf20Sopenharmony_ci *----------------------------- Device settings -------------------------------
2658c2ecf20Sopenharmony_ci * name
2668c2ecf20Sopenharmony_ci *      Values:         <char[80]>
2678c2ecf20Sopenharmony_ci *
2688c2ecf20Sopenharmony_ci *      Name of the sound device within the virtual sound card. Optional.
2698c2ecf20Sopenharmony_ci *
2708c2ecf20Sopenharmony_ci *----------------------------- Stream settings -------------------------------
2718c2ecf20Sopenharmony_ci *
2728c2ecf20Sopenharmony_ci * type
2738c2ecf20Sopenharmony_ci *      Values:         "p", "c"
2748c2ecf20Sopenharmony_ci *
2758c2ecf20Sopenharmony_ci *      Stream type: "p" - playback stream, "c" - capture stream
2768c2ecf20Sopenharmony_ci *
2778c2ecf20Sopenharmony_ci *      If both capture and playback are needed then two streams need to be
2788c2ecf20Sopenharmony_ci *      defined under the same device.
2798c2ecf20Sopenharmony_ci *
2808c2ecf20Sopenharmony_ci * unique-id
2818c2ecf20Sopenharmony_ci *      Values:         <string>
2828c2ecf20Sopenharmony_ci *
2838c2ecf20Sopenharmony_ci *      After stream initialization it is assigned a unique ID, so every
2848c2ecf20Sopenharmony_ci *      stream of the frontend can be identified by the backend by this ID.
2858c2ecf20Sopenharmony_ci *      This can be UUID or such.
2868c2ecf20Sopenharmony_ci *
2878c2ecf20Sopenharmony_ci *-------------------- Stream Request Transport Parameters --------------------
2888c2ecf20Sopenharmony_ci *
2898c2ecf20Sopenharmony_ci * event-channel
2908c2ecf20Sopenharmony_ci *      Values:         <uint32_t>
2918c2ecf20Sopenharmony_ci *
2928c2ecf20Sopenharmony_ci *      The identifier of the Xen event channel used to signal activity
2938c2ecf20Sopenharmony_ci *      in the ring buffer.
2948c2ecf20Sopenharmony_ci *
2958c2ecf20Sopenharmony_ci * ring-ref
2968c2ecf20Sopenharmony_ci *      Values:         <uint32_t>
2978c2ecf20Sopenharmony_ci *
2988c2ecf20Sopenharmony_ci *      The Xen grant reference granting permission for the backend to map
2998c2ecf20Sopenharmony_ci *      a sole page in a single page sized ring buffer.
3008c2ecf20Sopenharmony_ci *
3018c2ecf20Sopenharmony_ci *--------------------- Stream Event Transport Parameters ---------------------
3028c2ecf20Sopenharmony_ci *
3038c2ecf20Sopenharmony_ci * This communication path is used to deliver asynchronous events from backend
3048c2ecf20Sopenharmony_ci * to frontend, set up per stream.
3058c2ecf20Sopenharmony_ci *
3068c2ecf20Sopenharmony_ci * evt-event-channel
3078c2ecf20Sopenharmony_ci *      Values:         <uint32_t>
3088c2ecf20Sopenharmony_ci *
3098c2ecf20Sopenharmony_ci *      The identifier of the Xen event channel used to signal activity
3108c2ecf20Sopenharmony_ci *      in the ring buffer.
3118c2ecf20Sopenharmony_ci *
3128c2ecf20Sopenharmony_ci * evt-ring-ref
3138c2ecf20Sopenharmony_ci *      Values:         <uint32_t>
3148c2ecf20Sopenharmony_ci *
3158c2ecf20Sopenharmony_ci *      The Xen grant reference granting permission for the backend to map
3168c2ecf20Sopenharmony_ci *      a sole page in a single page sized ring buffer.
3178c2ecf20Sopenharmony_ci *
3188c2ecf20Sopenharmony_ci ******************************************************************************
3198c2ecf20Sopenharmony_ci *                               STATE DIAGRAMS
3208c2ecf20Sopenharmony_ci ******************************************************************************
3218c2ecf20Sopenharmony_ci *
3228c2ecf20Sopenharmony_ci * Tool stack creates front and back state nodes with initial state
3238c2ecf20Sopenharmony_ci * XenbusStateInitialising.
3248c2ecf20Sopenharmony_ci * Tool stack creates and sets up frontend sound configuration nodes per domain.
3258c2ecf20Sopenharmony_ci *
3268c2ecf20Sopenharmony_ci * Front                                Back
3278c2ecf20Sopenharmony_ci * =================================    =====================================
3288c2ecf20Sopenharmony_ci * XenbusStateInitialising              XenbusStateInitialising
3298c2ecf20Sopenharmony_ci *                                       o Query backend device identification
3308c2ecf20Sopenharmony_ci *                                         data.
3318c2ecf20Sopenharmony_ci *                                       o Open and validate backend device.
3328c2ecf20Sopenharmony_ci *                                                      |
3338c2ecf20Sopenharmony_ci *                                                      |
3348c2ecf20Sopenharmony_ci *                                                      V
3358c2ecf20Sopenharmony_ci *                                      XenbusStateInitWait
3368c2ecf20Sopenharmony_ci *
3378c2ecf20Sopenharmony_ci * o Query frontend configuration
3388c2ecf20Sopenharmony_ci * o Allocate and initialize
3398c2ecf20Sopenharmony_ci *   event channels per configured
3408c2ecf20Sopenharmony_ci *   playback/capture stream.
3418c2ecf20Sopenharmony_ci * o Publish transport parameters
3428c2ecf20Sopenharmony_ci *   that will be in effect during
3438c2ecf20Sopenharmony_ci *   this connection.
3448c2ecf20Sopenharmony_ci *              |
3458c2ecf20Sopenharmony_ci *              |
3468c2ecf20Sopenharmony_ci *              V
3478c2ecf20Sopenharmony_ci * XenbusStateInitialised
3488c2ecf20Sopenharmony_ci *
3498c2ecf20Sopenharmony_ci *                                       o Query frontend transport parameters.
3508c2ecf20Sopenharmony_ci *                                       o Connect to the event channels.
3518c2ecf20Sopenharmony_ci *                                                      |
3528c2ecf20Sopenharmony_ci *                                                      |
3538c2ecf20Sopenharmony_ci *                                                      V
3548c2ecf20Sopenharmony_ci *                                      XenbusStateConnected
3558c2ecf20Sopenharmony_ci *
3568c2ecf20Sopenharmony_ci *  o Create and initialize OS
3578c2ecf20Sopenharmony_ci *    virtual sound device instances
3588c2ecf20Sopenharmony_ci *    as per configuration.
3598c2ecf20Sopenharmony_ci *              |
3608c2ecf20Sopenharmony_ci *              |
3618c2ecf20Sopenharmony_ci *              V
3628c2ecf20Sopenharmony_ci * XenbusStateConnected
3638c2ecf20Sopenharmony_ci *
3648c2ecf20Sopenharmony_ci *                                      XenbusStateUnknown
3658c2ecf20Sopenharmony_ci *                                      XenbusStateClosed
3668c2ecf20Sopenharmony_ci *                                      XenbusStateClosing
3678c2ecf20Sopenharmony_ci * o Remove virtual sound device
3688c2ecf20Sopenharmony_ci * o Remove event channels
3698c2ecf20Sopenharmony_ci *              |
3708c2ecf20Sopenharmony_ci *              |
3718c2ecf20Sopenharmony_ci *              V
3728c2ecf20Sopenharmony_ci * XenbusStateClosed
3738c2ecf20Sopenharmony_ci *
3748c2ecf20Sopenharmony_ci *------------------------------- Recovery flow -------------------------------
3758c2ecf20Sopenharmony_ci *
3768c2ecf20Sopenharmony_ci * In case of frontend unrecoverable errors backend handles that as
3778c2ecf20Sopenharmony_ci * if frontend goes into the XenbusStateClosed state.
3788c2ecf20Sopenharmony_ci *
3798c2ecf20Sopenharmony_ci * In case of backend unrecoverable errors frontend tries removing
3808c2ecf20Sopenharmony_ci * the virtualized device. If this is possible at the moment of error,
3818c2ecf20Sopenharmony_ci * then frontend goes into the XenbusStateInitialising state and is ready for
3828c2ecf20Sopenharmony_ci * new connection with backend. If the virtualized device is still in use and
3838c2ecf20Sopenharmony_ci * cannot be removed, then frontend goes into the XenbusStateReconfiguring state
3848c2ecf20Sopenharmony_ci * until either the virtualized device removed or backend initiates a new
3858c2ecf20Sopenharmony_ci * connection. On the virtualized device removal frontend goes into the
3868c2ecf20Sopenharmony_ci * XenbusStateInitialising state.
3878c2ecf20Sopenharmony_ci *
3888c2ecf20Sopenharmony_ci * Note on XenbusStateReconfiguring state of the frontend: if backend has
3898c2ecf20Sopenharmony_ci * unrecoverable errors then frontend cannot send requests to the backend
3908c2ecf20Sopenharmony_ci * and thus cannot provide functionality of the virtualized device anymore.
3918c2ecf20Sopenharmony_ci * After backend is back to normal the virtualized device may still hold some
3928c2ecf20Sopenharmony_ci * state: configuration in use, allocated buffers, client application state etc.
3938c2ecf20Sopenharmony_ci * So, in most cases, this will require frontend to implement complex recovery
3948c2ecf20Sopenharmony_ci * reconnect logic. Instead, by going into XenbusStateReconfiguring state,
3958c2ecf20Sopenharmony_ci * frontend will make sure no new clients of the virtualized device are
3968c2ecf20Sopenharmony_ci * accepted, allow existing client(s) to exit gracefully by signaling error
3978c2ecf20Sopenharmony_ci * state etc.
3988c2ecf20Sopenharmony_ci * Once all the clients are gone frontend can reinitialize the virtualized
3998c2ecf20Sopenharmony_ci * device and get into XenbusStateInitialising state again signaling the
4008c2ecf20Sopenharmony_ci * backend that a new connection can be made.
4018c2ecf20Sopenharmony_ci *
4028c2ecf20Sopenharmony_ci * There are multiple conditions possible under which frontend will go from
4038c2ecf20Sopenharmony_ci * XenbusStateReconfiguring into XenbusStateInitialising, some of them are OS
4048c2ecf20Sopenharmony_ci * specific. For example:
4058c2ecf20Sopenharmony_ci * 1. The underlying OS framework may provide callbacks to signal that the last
4068c2ecf20Sopenharmony_ci *    client of the virtualized device has gone and the device can be removed
4078c2ecf20Sopenharmony_ci * 2. Frontend can schedule a deferred work (timer/tasklet/workqueue)
4088c2ecf20Sopenharmony_ci *    to periodically check if this is the right time to re-try removal of
4098c2ecf20Sopenharmony_ci *    the virtualized device.
4108c2ecf20Sopenharmony_ci * 3. By any other means.
4118c2ecf20Sopenharmony_ci *
4128c2ecf20Sopenharmony_ci ******************************************************************************
4138c2ecf20Sopenharmony_ci *                             PCM FORMATS
4148c2ecf20Sopenharmony_ci ******************************************************************************
4158c2ecf20Sopenharmony_ci *
4168c2ecf20Sopenharmony_ci * XENSND_PCM_FORMAT_<format>[_<endian>]
4178c2ecf20Sopenharmony_ci *
4188c2ecf20Sopenharmony_ci * format: <S/U/F><bits> or <name>
4198c2ecf20Sopenharmony_ci *     S - signed, U - unsigned, F - float
4208c2ecf20Sopenharmony_ci *     bits - 8, 16, 24, 32
4218c2ecf20Sopenharmony_ci *     name - MU_LAW, GSM, etc.
4228c2ecf20Sopenharmony_ci *
4238c2ecf20Sopenharmony_ci * endian: <LE/BE>, may be absent
4248c2ecf20Sopenharmony_ci *     LE - Little endian, BE - Big endian
4258c2ecf20Sopenharmony_ci */
4268c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S8		0
4278c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U8		1
4288c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S16_LE	2
4298c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S16_BE	3
4308c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U16_LE	4
4318c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U16_BE	5
4328c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S24_LE	6
4338c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S24_BE	7
4348c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U24_LE	8
4358c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U24_BE	9
4368c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S32_LE	10
4378c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S32_BE	11
4388c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U32_LE	12
4398c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U32_BE	13
4408c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_F32_LE	14 /* 4-byte float, IEEE-754 32-bit, */
4418c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_F32_BE	15 /* range -1.0 to 1.0              */
4428c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_F64_LE	16 /* 8-byte float, IEEE-754 64-bit, */
4438c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_F64_BE	17 /* range -1.0 to 1.0              */
4448c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE 18
4458c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE 19
4468c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_MU_LAW	20
4478c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_A_LAW		21
4488c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_IMA_ADPCM	22
4498c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_MPEG		23
4508c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_GSM		24
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci/*
4538c2ecf20Sopenharmony_ci ******************************************************************************
4548c2ecf20Sopenharmony_ci *                             REQUEST CODES
4558c2ecf20Sopenharmony_ci ******************************************************************************
4568c2ecf20Sopenharmony_ci */
4578c2ecf20Sopenharmony_ci#define XENSND_OP_OPEN			0
4588c2ecf20Sopenharmony_ci#define XENSND_OP_CLOSE			1
4598c2ecf20Sopenharmony_ci#define XENSND_OP_READ			2
4608c2ecf20Sopenharmony_ci#define XENSND_OP_WRITE			3
4618c2ecf20Sopenharmony_ci#define XENSND_OP_SET_VOLUME		4
4628c2ecf20Sopenharmony_ci#define XENSND_OP_GET_VOLUME		5
4638c2ecf20Sopenharmony_ci#define XENSND_OP_MUTE			6
4648c2ecf20Sopenharmony_ci#define XENSND_OP_UNMUTE		7
4658c2ecf20Sopenharmony_ci#define XENSND_OP_TRIGGER		8
4668c2ecf20Sopenharmony_ci#define XENSND_OP_HW_PARAM_QUERY	9
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci#define XENSND_OP_TRIGGER_START		0
4698c2ecf20Sopenharmony_ci#define XENSND_OP_TRIGGER_PAUSE		1
4708c2ecf20Sopenharmony_ci#define XENSND_OP_TRIGGER_STOP		2
4718c2ecf20Sopenharmony_ci#define XENSND_OP_TRIGGER_RESUME	3
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci/*
4748c2ecf20Sopenharmony_ci ******************************************************************************
4758c2ecf20Sopenharmony_ci *                                 EVENT CODES
4768c2ecf20Sopenharmony_ci ******************************************************************************
4778c2ecf20Sopenharmony_ci */
4788c2ecf20Sopenharmony_ci#define XENSND_EVT_CUR_POS		0
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci/*
4818c2ecf20Sopenharmony_ci ******************************************************************************
4828c2ecf20Sopenharmony_ci *               XENSTORE FIELD AND PATH NAME STRINGS, HELPERS
4838c2ecf20Sopenharmony_ci ******************************************************************************
4848c2ecf20Sopenharmony_ci */
4858c2ecf20Sopenharmony_ci#define XENSND_DRIVER_NAME		"vsnd"
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci#define XENSND_LIST_SEPARATOR		","
4888c2ecf20Sopenharmony_ci/* Field names */
4898c2ecf20Sopenharmony_ci#define XENSND_FIELD_BE_VERSIONS	"versions"
4908c2ecf20Sopenharmony_ci#define XENSND_FIELD_FE_VERSION		"version"
4918c2ecf20Sopenharmony_ci#define XENSND_FIELD_VCARD_SHORT_NAME	"short-name"
4928c2ecf20Sopenharmony_ci#define XENSND_FIELD_VCARD_LONG_NAME	"long-name"
4938c2ecf20Sopenharmony_ci#define XENSND_FIELD_RING_REF		"ring-ref"
4948c2ecf20Sopenharmony_ci#define XENSND_FIELD_EVT_CHNL		"event-channel"
4958c2ecf20Sopenharmony_ci#define XENSND_FIELD_EVT_RING_REF	"evt-ring-ref"
4968c2ecf20Sopenharmony_ci#define XENSND_FIELD_EVT_EVT_CHNL	"evt-event-channel"
4978c2ecf20Sopenharmony_ci#define XENSND_FIELD_DEVICE_NAME	"name"
4988c2ecf20Sopenharmony_ci#define XENSND_FIELD_TYPE		"type"
4998c2ecf20Sopenharmony_ci#define XENSND_FIELD_STREAM_UNIQUE_ID	"unique-id"
5008c2ecf20Sopenharmony_ci#define XENSND_FIELD_CHANNELS_MIN	"channels-min"
5018c2ecf20Sopenharmony_ci#define XENSND_FIELD_CHANNELS_MAX	"channels-max"
5028c2ecf20Sopenharmony_ci#define XENSND_FIELD_SAMPLE_RATES	"sample-rates"
5038c2ecf20Sopenharmony_ci#define XENSND_FIELD_SAMPLE_FORMATS	"sample-formats"
5048c2ecf20Sopenharmony_ci#define XENSND_FIELD_BUFFER_SIZE	"buffer-size"
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci/* Stream type field values. */
5078c2ecf20Sopenharmony_ci#define XENSND_STREAM_TYPE_PLAYBACK	"p"
5088c2ecf20Sopenharmony_ci#define XENSND_STREAM_TYPE_CAPTURE	"c"
5098c2ecf20Sopenharmony_ci/* Sample rate max string length */
5108c2ecf20Sopenharmony_ci#define XENSND_SAMPLE_RATE_MAX_LEN	11
5118c2ecf20Sopenharmony_ci/* Sample format field values */
5128c2ecf20Sopenharmony_ci#define XENSND_SAMPLE_FORMAT_MAX_LEN	24
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S8_STR	"s8"
5158c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U8_STR	"u8"
5168c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S16_LE_STR	"s16_le"
5178c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S16_BE_STR	"s16_be"
5188c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U16_LE_STR	"u16_le"
5198c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U16_BE_STR	"u16_be"
5208c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S24_LE_STR	"s24_le"
5218c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S24_BE_STR	"s24_be"
5228c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U24_LE_STR	"u24_le"
5238c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U24_BE_STR	"u24_be"
5248c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S32_LE_STR	"s32_le"
5258c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_S32_BE_STR	"s32_be"
5268c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U32_LE_STR	"u32_le"
5278c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_U32_BE_STR	"u32_be"
5288c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_F32_LE_STR	"float_le"
5298c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_F32_BE_STR	"float_be"
5308c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_F64_LE_STR	"float64_le"
5318c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_F64_BE_STR	"float64_be"
5328c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_IEC958_SUBFRAME_LE_STR "iec958_subframe_le"
5338c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_IEC958_SUBFRAME_BE_STR "iec958_subframe_be"
5348c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_MU_LAW_STR	"mu_law"
5358c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_A_LAW_STR	"a_law"
5368c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_IMA_ADPCM_STR	"ima_adpcm"
5378c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_MPEG_STR	"mpeg"
5388c2ecf20Sopenharmony_ci#define XENSND_PCM_FORMAT_GSM_STR	"gsm"
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci/*
5428c2ecf20Sopenharmony_ci ******************************************************************************
5438c2ecf20Sopenharmony_ci *                          STATUS RETURN CODES
5448c2ecf20Sopenharmony_ci ******************************************************************************
5458c2ecf20Sopenharmony_ci *
5468c2ecf20Sopenharmony_ci * Status return code is zero on success and -XEN_EXX on failure.
5478c2ecf20Sopenharmony_ci *
5488c2ecf20Sopenharmony_ci ******************************************************************************
5498c2ecf20Sopenharmony_ci *                              Assumptions
5508c2ecf20Sopenharmony_ci ******************************************************************************
5518c2ecf20Sopenharmony_ci * o usage of grant reference 0 as invalid grant reference:
5528c2ecf20Sopenharmony_ci *   grant reference 0 is valid, but never exposed to a PV driver,
5538c2ecf20Sopenharmony_ci *   because of the fact it is already in use/reserved by the PV console.
5548c2ecf20Sopenharmony_ci * o all references in this document to page sizes must be treated
5558c2ecf20Sopenharmony_ci *   as pages of size XEN_PAGE_SIZE unless otherwise noted.
5568c2ecf20Sopenharmony_ci *
5578c2ecf20Sopenharmony_ci ******************************************************************************
5588c2ecf20Sopenharmony_ci *       Description of the protocol between frontend and backend driver
5598c2ecf20Sopenharmony_ci ******************************************************************************
5608c2ecf20Sopenharmony_ci *
5618c2ecf20Sopenharmony_ci * The two halves of a Para-virtual sound driver communicate with
5628c2ecf20Sopenharmony_ci * each other using shared pages and event channels.
5638c2ecf20Sopenharmony_ci * Shared page contains a ring with request/response packets.
5648c2ecf20Sopenharmony_ci *
5658c2ecf20Sopenharmony_ci * Packets, used for input/output operations, e.g. read/write, set/get volume,
5668c2ecf20Sopenharmony_ci * etc., provide offset/length fields in order to allow asynchronous protocol
5678c2ecf20Sopenharmony_ci * operation with buffer space sharing: part of the buffer allocated at
5688c2ecf20Sopenharmony_ci * XENSND_OP_OPEN can be used for audio samples and part, for example,
5698c2ecf20Sopenharmony_ci * for volume control.
5708c2ecf20Sopenharmony_ci *
5718c2ecf20Sopenharmony_ci * All reserved fields in the structures below must be 0.
5728c2ecf20Sopenharmony_ci *
5738c2ecf20Sopenharmony_ci *---------------------------------- Requests ---------------------------------
5748c2ecf20Sopenharmony_ci *
5758c2ecf20Sopenharmony_ci * All request packets have the same length (64 octets)
5768c2ecf20Sopenharmony_ci * All request packets have common header:
5778c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
5788c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
5798c2ecf20Sopenharmony_ci * |               id                |    operation   |    reserved    | 4
5808c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
5818c2ecf20Sopenharmony_ci * |                             reserved                              | 8
5828c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
5838c2ecf20Sopenharmony_ci *   id - uint16_t, private guest value, echoed in response
5848c2ecf20Sopenharmony_ci *   operation - uint8_t, operation code, XENSND_OP_???
5858c2ecf20Sopenharmony_ci *
5868c2ecf20Sopenharmony_ci * For all packets which use offset and length:
5878c2ecf20Sopenharmony_ci *   offset - uint32_t, read or write data offset within the shared buffer,
5888c2ecf20Sopenharmony_ci *     passed with XENSND_OP_OPEN request, octets,
5898c2ecf20Sopenharmony_ci *     [0; XENSND_OP_OPEN.buffer_sz - 1].
5908c2ecf20Sopenharmony_ci *   length - uint32_t, read or write data length, octets
5918c2ecf20Sopenharmony_ci *
5928c2ecf20Sopenharmony_ci * Request open - open a PCM stream for playback or capture:
5938c2ecf20Sopenharmony_ci *
5948c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
5958c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
5968c2ecf20Sopenharmony_ci * |               id                | XENSND_OP_OPEN |    reserved    | 4
5978c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
5988c2ecf20Sopenharmony_ci * |                             reserved                              | 8
5998c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6008c2ecf20Sopenharmony_ci * |                             pcm_rate                              | 12
6018c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6028c2ecf20Sopenharmony_ci * |  pcm_format    |  pcm_channels  |             reserved            | 16
6038c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6048c2ecf20Sopenharmony_ci * |                             buffer_sz                             | 20
6058c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6068c2ecf20Sopenharmony_ci * |                           gref_directory                          | 24
6078c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6088c2ecf20Sopenharmony_ci * |                             period_sz                             | 28
6098c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6108c2ecf20Sopenharmony_ci * |                             reserved                              | 32
6118c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6128c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
6138c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6148c2ecf20Sopenharmony_ci * |                             reserved                              | 64
6158c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6168c2ecf20Sopenharmony_ci *
6178c2ecf20Sopenharmony_ci * pcm_rate - uint32_t, stream data rate, Hz
6188c2ecf20Sopenharmony_ci * pcm_format - uint8_t, XENSND_PCM_FORMAT_XXX value
6198c2ecf20Sopenharmony_ci * pcm_channels - uint8_t, number of channels of this stream,
6208c2ecf20Sopenharmony_ci *   [channels-min; channels-max]
6218c2ecf20Sopenharmony_ci * buffer_sz - uint32_t, buffer size to be allocated, octets
6228c2ecf20Sopenharmony_ci * period_sz - uint32_t, event period size, octets
6238c2ecf20Sopenharmony_ci *   This is the requested value of the period at which frontend would
6248c2ecf20Sopenharmony_ci *   like to receive XENSND_EVT_CUR_POS notifications from the backend when
6258c2ecf20Sopenharmony_ci *   stream position advances during playback/capture.
6268c2ecf20Sopenharmony_ci *   It shows how many octets are expected to be played/captured before
6278c2ecf20Sopenharmony_ci *   sending such an event.
6288c2ecf20Sopenharmony_ci *   If set to 0 no XENSND_EVT_CUR_POS events are sent by the backend.
6298c2ecf20Sopenharmony_ci *
6308c2ecf20Sopenharmony_ci * gref_directory - grant_ref_t, a reference to the first shared page
6318c2ecf20Sopenharmony_ci *   describing shared buffer references. At least one page exists. If shared
6328c2ecf20Sopenharmony_ci *   buffer size  (buffer_sz) exceeds what can be addressed by this single page,
6338c2ecf20Sopenharmony_ci *   then reference to the next page must be supplied (see gref_dir_next_page
6348c2ecf20Sopenharmony_ci *   below)
6358c2ecf20Sopenharmony_ci */
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_cistruct xensnd_open_req {
6388c2ecf20Sopenharmony_ci	uint32_t pcm_rate;
6398c2ecf20Sopenharmony_ci	uint8_t pcm_format;
6408c2ecf20Sopenharmony_ci	uint8_t pcm_channels;
6418c2ecf20Sopenharmony_ci	uint16_t reserved;
6428c2ecf20Sopenharmony_ci	uint32_t buffer_sz;
6438c2ecf20Sopenharmony_ci	grant_ref_t gref_directory;
6448c2ecf20Sopenharmony_ci	uint32_t period_sz;
6458c2ecf20Sopenharmony_ci};
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci/*
6488c2ecf20Sopenharmony_ci * Shared page for XENSND_OP_OPEN buffer descriptor (gref_directory in the
6498c2ecf20Sopenharmony_ci *   request) employs a list of pages, describing all pages of the shared data
6508c2ecf20Sopenharmony_ci *   buffer:
6518c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
6528c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6538c2ecf20Sopenharmony_ci * |                        gref_dir_next_page                         | 4
6548c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6558c2ecf20Sopenharmony_ci * |                              gref[0]                              | 8
6568c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6578c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
6588c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6598c2ecf20Sopenharmony_ci * |                              gref[i]                              | i*4+8
6608c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6618c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
6628c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6638c2ecf20Sopenharmony_ci * |                             gref[N - 1]                           | N*4+8
6648c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6658c2ecf20Sopenharmony_ci *
6668c2ecf20Sopenharmony_ci * gref_dir_next_page - grant_ref_t, reference to the next page describing
6678c2ecf20Sopenharmony_ci *   page directory. Must be 0 if there are no more pages in the list.
6688c2ecf20Sopenharmony_ci * gref[i] - grant_ref_t, reference to a shared page of the buffer
6698c2ecf20Sopenharmony_ci *   allocated at XENSND_OP_OPEN
6708c2ecf20Sopenharmony_ci *
6718c2ecf20Sopenharmony_ci * Number of grant_ref_t entries in the whole page directory is not
6728c2ecf20Sopenharmony_ci * passed, but instead can be calculated as:
6738c2ecf20Sopenharmony_ci *   num_grefs_total = (XENSND_OP_OPEN.buffer_sz + XEN_PAGE_SIZE - 1) /
6748c2ecf20Sopenharmony_ci *       XEN_PAGE_SIZE
6758c2ecf20Sopenharmony_ci */
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_cistruct xensnd_page_directory {
6788c2ecf20Sopenharmony_ci	grant_ref_t gref_dir_next_page;
6798c2ecf20Sopenharmony_ci	grant_ref_t gref[1]; /* Variable length */
6808c2ecf20Sopenharmony_ci};
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci/*
6838c2ecf20Sopenharmony_ci *  Request close - close an opened pcm stream:
6848c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
6858c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6868c2ecf20Sopenharmony_ci * |               id                | XENSND_OP_CLOSE|    reserved    | 4
6878c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6888c2ecf20Sopenharmony_ci * |                             reserved                              | 8
6898c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6908c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
6918c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6928c2ecf20Sopenharmony_ci * |                             reserved                              | 64
6938c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6948c2ecf20Sopenharmony_ci *
6958c2ecf20Sopenharmony_ci * Request read/write - used for read (for capture) or write (for playback):
6968c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
6978c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
6988c2ecf20Sopenharmony_ci * |               id                |   operation    |    reserved    | 4
6998c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7008c2ecf20Sopenharmony_ci * |                             reserved                              | 8
7018c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7028c2ecf20Sopenharmony_ci * |                              offset                               | 12
7038c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7048c2ecf20Sopenharmony_ci * |                              length                               | 16
7058c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7068c2ecf20Sopenharmony_ci * |                             reserved                              | 20
7078c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7088c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
7098c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7108c2ecf20Sopenharmony_ci * |                             reserved                              | 64
7118c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7128c2ecf20Sopenharmony_ci *
7138c2ecf20Sopenharmony_ci * operation - XENSND_OP_READ for read or XENSND_OP_WRITE for write
7148c2ecf20Sopenharmony_ci */
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_cistruct xensnd_rw_req {
7178c2ecf20Sopenharmony_ci	uint32_t offset;
7188c2ecf20Sopenharmony_ci	uint32_t length;
7198c2ecf20Sopenharmony_ci};
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci/*
7228c2ecf20Sopenharmony_ci * Request set/get volume - set/get channels' volume of the stream given:
7238c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
7248c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7258c2ecf20Sopenharmony_ci * |               id                |   operation    |    reserved    | 4
7268c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7278c2ecf20Sopenharmony_ci * |                             reserved                              | 8
7288c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7298c2ecf20Sopenharmony_ci * |                              offset                               | 12
7308c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7318c2ecf20Sopenharmony_ci * |                              length                               | 16
7328c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7338c2ecf20Sopenharmony_ci * |                             reserved                              | 20
7348c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7358c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
7368c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7378c2ecf20Sopenharmony_ci * |                             reserved                              | 64
7388c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7398c2ecf20Sopenharmony_ci *
7408c2ecf20Sopenharmony_ci * operation - XENSND_OP_SET_VOLUME for volume set
7418c2ecf20Sopenharmony_ci *   or XENSND_OP_GET_VOLUME for volume get
7428c2ecf20Sopenharmony_ci * Buffer passed with XENSND_OP_OPEN is used to exchange volume
7438c2ecf20Sopenharmony_ci * values:
7448c2ecf20Sopenharmony_ci *
7458c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
7468c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7478c2ecf20Sopenharmony_ci * |                             channel[0]                            | 4
7488c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7498c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
7508c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7518c2ecf20Sopenharmony_ci * |                             channel[i]                            | i*4
7528c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7538c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
7548c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7558c2ecf20Sopenharmony_ci * |                           channel[N - 1]                          | (N-1)*4
7568c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7578c2ecf20Sopenharmony_ci *
7588c2ecf20Sopenharmony_ci * N = XENSND_OP_OPEN.pcm_channels
7598c2ecf20Sopenharmony_ci * i - uint8_t, index of a channel
7608c2ecf20Sopenharmony_ci * channel[i] - sint32_t, volume of i-th channel
7618c2ecf20Sopenharmony_ci * Volume is expressed as a signed value in steps of 0.001 dB,
7628c2ecf20Sopenharmony_ci * while 0 being 0 dB.
7638c2ecf20Sopenharmony_ci *
7648c2ecf20Sopenharmony_ci * Request mute/unmute - mute/unmute stream:
7658c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
7668c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7678c2ecf20Sopenharmony_ci * |               id                |   operation    |    reserved    | 4
7688c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7698c2ecf20Sopenharmony_ci * |                             reserved                              | 8
7708c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7718c2ecf20Sopenharmony_ci * |                              offset                               | 12
7728c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7738c2ecf20Sopenharmony_ci * |                              length                               | 16
7748c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7758c2ecf20Sopenharmony_ci * |                             reserved                              | 20
7768c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7778c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
7788c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7798c2ecf20Sopenharmony_ci * |                             reserved                              | 64
7808c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7818c2ecf20Sopenharmony_ci *
7828c2ecf20Sopenharmony_ci * operation - XENSND_OP_MUTE for mute or XENSND_OP_UNMUTE for unmute
7838c2ecf20Sopenharmony_ci * Buffer passed with XENSND_OP_OPEN is used to exchange mute/unmute
7848c2ecf20Sopenharmony_ci * values:
7858c2ecf20Sopenharmony_ci *
7868c2ecf20Sopenharmony_ci *                                   0                                 octet
7878c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7888c2ecf20Sopenharmony_ci * |                             channel[0]                            | 4
7898c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7908c2ecf20Sopenharmony_ci * +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
7918c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7928c2ecf20Sopenharmony_ci * |                             channel[i]                            | i*4
7938c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7948c2ecf20Sopenharmony_ci * +/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
7958c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7968c2ecf20Sopenharmony_ci * |                           channel[N - 1]                          | (N-1)*4
7978c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
7988c2ecf20Sopenharmony_ci *
7998c2ecf20Sopenharmony_ci * N = XENSND_OP_OPEN.pcm_channels
8008c2ecf20Sopenharmony_ci * i - uint8_t, index of a channel
8018c2ecf20Sopenharmony_ci * channel[i] - uint8_t, non-zero if i-th channel needs to be muted/unmuted
8028c2ecf20Sopenharmony_ci *
8038c2ecf20Sopenharmony_ci *------------------------------------ N.B. -----------------------------------
8048c2ecf20Sopenharmony_ci *
8058c2ecf20Sopenharmony_ci * The 'struct xensnd_rw_req' is also used for XENSND_OP_SET_VOLUME,
8068c2ecf20Sopenharmony_ci * XENSND_OP_GET_VOLUME, XENSND_OP_MUTE, XENSND_OP_UNMUTE.
8078c2ecf20Sopenharmony_ci *
8088c2ecf20Sopenharmony_ci * Request stream running state change - trigger PCM stream running state
8098c2ecf20Sopenharmony_ci * to start, stop, pause or resume:
8108c2ecf20Sopenharmony_ci *
8118c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
8128c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8138c2ecf20Sopenharmony_ci * |               id                |   _OP_TRIGGER  |    reserved    | 4
8148c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8158c2ecf20Sopenharmony_ci * |                             reserved                              | 8
8168c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8178c2ecf20Sopenharmony_ci * |      type      |                     reserved                     | 12
8188c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8198c2ecf20Sopenharmony_ci * |                             reserved                              | 16
8208c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8218c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
8228c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8238c2ecf20Sopenharmony_ci * |                             reserved                              | 64
8248c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8258c2ecf20Sopenharmony_ci *
8268c2ecf20Sopenharmony_ci * type - uint8_t, XENSND_OP_TRIGGER_XXX value
8278c2ecf20Sopenharmony_ci */
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_cistruct xensnd_trigger_req {
8308c2ecf20Sopenharmony_ci	uint8_t type;
8318c2ecf20Sopenharmony_ci};
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_ci/*
8348c2ecf20Sopenharmony_ci * Request stream parameter ranges: request intervals and
8358c2ecf20Sopenharmony_ci *   masks of supported ranges for stream configuration values.
8368c2ecf20Sopenharmony_ci *
8378c2ecf20Sopenharmony_ci *   Sound device configuration for a particular stream is a limited subset
8388c2ecf20Sopenharmony_ci *   of the multidimensional configuration available on XenStore, e.g.
8398c2ecf20Sopenharmony_ci *   once the frame rate has been selected there is a limited supported range
8408c2ecf20Sopenharmony_ci *   for sample rates becomes available (which might be the same set configured
8418c2ecf20Sopenharmony_ci *   on XenStore or less). For example, selecting 96kHz sample rate may limit
8428c2ecf20Sopenharmony_ci *   number of channels available for such configuration from 4 to 2, etc.
8438c2ecf20Sopenharmony_ci *   Thus, each call to XENSND_OP_HW_PARAM_QUERY may reduce configuration
8448c2ecf20Sopenharmony_ci *   space making it possible to iteratively get the final stream configuration,
8458c2ecf20Sopenharmony_ci *   used in XENSND_OP_OPEN request.
8468c2ecf20Sopenharmony_ci *
8478c2ecf20Sopenharmony_ci *   See response format for this request.
8488c2ecf20Sopenharmony_ci *
8498c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
8508c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8518c2ecf20Sopenharmony_ci * |               id                | _HW_PARAM_QUERY|    reserved    | 4
8528c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8538c2ecf20Sopenharmony_ci * |                             reserved                              | 8
8548c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8558c2ecf20Sopenharmony_ci * |                     formats mask low 32-bit                       | 12
8568c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8578c2ecf20Sopenharmony_ci * |                     formats mask high 32-bit                      | 16
8588c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8598c2ecf20Sopenharmony_ci * |                              min rate                             | 20
8608c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8618c2ecf20Sopenharmony_ci * |                              max rate                             | 24
8628c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8638c2ecf20Sopenharmony_ci * |                            min channels                           | 28
8648c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8658c2ecf20Sopenharmony_ci * |                            max channels                           | 32
8668c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8678c2ecf20Sopenharmony_ci * |                         min buffer frames                         | 36
8688c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8698c2ecf20Sopenharmony_ci * |                         max buffer frames                         | 40
8708c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8718c2ecf20Sopenharmony_ci * |                         min period frames                         | 44
8728c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8738c2ecf20Sopenharmony_ci * |                         max period frames                         | 48
8748c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8758c2ecf20Sopenharmony_ci * |                             reserved                              | 52
8768c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8778c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
8788c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8798c2ecf20Sopenharmony_ci * |                             reserved                              | 64
8808c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
8818c2ecf20Sopenharmony_ci *
8828c2ecf20Sopenharmony_ci * formats - uint64_t, bit mask representing values of the parameter
8838c2ecf20Sopenharmony_ci *     made as bitwise OR of (1 << XENSND_PCM_FORMAT_XXX) values
8848c2ecf20Sopenharmony_ci *
8858c2ecf20Sopenharmony_ci * For interval parameters:
8868c2ecf20Sopenharmony_ci *   min - uint32_t, minimum value of the parameter
8878c2ecf20Sopenharmony_ci *   max - uint32_t, maximum value of the parameter
8888c2ecf20Sopenharmony_ci *
8898c2ecf20Sopenharmony_ci * Frame is defined as a product of the number of channels by the
8908c2ecf20Sopenharmony_ci * number of octets per one sample.
8918c2ecf20Sopenharmony_ci */
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_cistruct xensnd_query_hw_param {
8948c2ecf20Sopenharmony_ci	uint64_t formats;
8958c2ecf20Sopenharmony_ci	struct {
8968c2ecf20Sopenharmony_ci		uint32_t min;
8978c2ecf20Sopenharmony_ci		uint32_t max;
8988c2ecf20Sopenharmony_ci	} rates;
8998c2ecf20Sopenharmony_ci	struct {
9008c2ecf20Sopenharmony_ci		uint32_t min;
9018c2ecf20Sopenharmony_ci		uint32_t max;
9028c2ecf20Sopenharmony_ci	} channels;
9038c2ecf20Sopenharmony_ci	struct {
9048c2ecf20Sopenharmony_ci		uint32_t min;
9058c2ecf20Sopenharmony_ci		uint32_t max;
9068c2ecf20Sopenharmony_ci	} buffer;
9078c2ecf20Sopenharmony_ci	struct {
9088c2ecf20Sopenharmony_ci		uint32_t min;
9098c2ecf20Sopenharmony_ci		uint32_t max;
9108c2ecf20Sopenharmony_ci	} period;
9118c2ecf20Sopenharmony_ci};
9128c2ecf20Sopenharmony_ci
9138c2ecf20Sopenharmony_ci/*
9148c2ecf20Sopenharmony_ci *---------------------------------- Responses --------------------------------
9158c2ecf20Sopenharmony_ci *
9168c2ecf20Sopenharmony_ci * All response packets have the same length (64 octets)
9178c2ecf20Sopenharmony_ci *
9188c2ecf20Sopenharmony_ci * All response packets have common header:
9198c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
9208c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9218c2ecf20Sopenharmony_ci * |               id                |    operation   |    reserved    | 4
9228c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9238c2ecf20Sopenharmony_ci * |                              status                               | 8
9248c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9258c2ecf20Sopenharmony_ci *
9268c2ecf20Sopenharmony_ci * id - uint16_t, copied from the request
9278c2ecf20Sopenharmony_ci * operation - uint8_t, XENSND_OP_* - copied from request
9288c2ecf20Sopenharmony_ci * status - int32_t, response status, zero on success and -XEN_EXX on failure
9298c2ecf20Sopenharmony_ci *
9308c2ecf20Sopenharmony_ci *
9318c2ecf20Sopenharmony_ci * HW parameter query response - response for XENSND_OP_HW_PARAM_QUERY:
9328c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
9338c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9348c2ecf20Sopenharmony_ci * |               id                |    operation   |    reserved    | 4
9358c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9368c2ecf20Sopenharmony_ci * |                              status                               | 8
9378c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9388c2ecf20Sopenharmony_ci * |                     formats mask low 32-bit                       | 12
9398c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9408c2ecf20Sopenharmony_ci * |                     formats mask high 32-bit                      | 16
9418c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9428c2ecf20Sopenharmony_ci * |                              min rate                             | 20
9438c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9448c2ecf20Sopenharmony_ci * |                              max rate                             | 24
9458c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9468c2ecf20Sopenharmony_ci * |                            min channels                           | 28
9478c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9488c2ecf20Sopenharmony_ci * |                            max channels                           | 32
9498c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9508c2ecf20Sopenharmony_ci * |                         min buffer frames                         | 36
9518c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9528c2ecf20Sopenharmony_ci * |                         max buffer frames                         | 40
9538c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9548c2ecf20Sopenharmony_ci * |                         min period frames                         | 44
9558c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9568c2ecf20Sopenharmony_ci * |                         max period frames                         | 48
9578c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9588c2ecf20Sopenharmony_ci * |                             reserved                              | 52
9598c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9608c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
9618c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9628c2ecf20Sopenharmony_ci * |                             reserved                              | 64
9638c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9648c2ecf20Sopenharmony_ci *
9658c2ecf20Sopenharmony_ci * Meaning of the values in this response is the same as for
9668c2ecf20Sopenharmony_ci * XENSND_OP_HW_PARAM_QUERY request.
9678c2ecf20Sopenharmony_ci */
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci/*
9708c2ecf20Sopenharmony_ci *----------------------------------- Events ----------------------------------
9718c2ecf20Sopenharmony_ci *
9728c2ecf20Sopenharmony_ci * Events are sent via shared page allocated by the front and propagated by
9738c2ecf20Sopenharmony_ci *   evt-event-channel/evt-ring-ref XenStore entries
9748c2ecf20Sopenharmony_ci * All event packets have the same length (64 octets)
9758c2ecf20Sopenharmony_ci * All event packets have common header:
9768c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
9778c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9788c2ecf20Sopenharmony_ci * |               id                |      type      |   reserved     | 4
9798c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9808c2ecf20Sopenharmony_ci * |                             reserved                              | 8
9818c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9828c2ecf20Sopenharmony_ci *
9838c2ecf20Sopenharmony_ci * id - uint16_t, event id, may be used by front
9848c2ecf20Sopenharmony_ci * type - uint8_t, type of the event
9858c2ecf20Sopenharmony_ci *
9868c2ecf20Sopenharmony_ci *
9878c2ecf20Sopenharmony_ci * Current stream position - event from back to front when stream's
9888c2ecf20Sopenharmony_ci *   playback/capture position has advanced:
9898c2ecf20Sopenharmony_ci *         0                1                 2               3        octet
9908c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9918c2ecf20Sopenharmony_ci * |               id                |   _EVT_CUR_POS |   reserved     | 4
9928c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9938c2ecf20Sopenharmony_ci * |                             reserved                              | 8
9948c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9958c2ecf20Sopenharmony_ci * |                         position low 32-bit                       | 12
9968c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9978c2ecf20Sopenharmony_ci * |                         position high 32-bit                      | 16
9988c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
9998c2ecf20Sopenharmony_ci * |                             reserved                              | 20
10008c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
10018c2ecf20Sopenharmony_ci * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
10028c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
10038c2ecf20Sopenharmony_ci * |                             reserved                              | 64
10048c2ecf20Sopenharmony_ci * +----------------+----------------+----------------+----------------+
10058c2ecf20Sopenharmony_ci *
10068c2ecf20Sopenharmony_ci * position - current value of stream's playback/capture position, octets
10078c2ecf20Sopenharmony_ci *
10088c2ecf20Sopenharmony_ci */
10098c2ecf20Sopenharmony_ci
10108c2ecf20Sopenharmony_cistruct xensnd_cur_pos_evt {
10118c2ecf20Sopenharmony_ci	uint64_t position;
10128c2ecf20Sopenharmony_ci};
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_cistruct xensnd_req {
10158c2ecf20Sopenharmony_ci	uint16_t id;
10168c2ecf20Sopenharmony_ci	uint8_t operation;
10178c2ecf20Sopenharmony_ci	uint8_t reserved[5];
10188c2ecf20Sopenharmony_ci	union {
10198c2ecf20Sopenharmony_ci		struct xensnd_open_req open;
10208c2ecf20Sopenharmony_ci		struct xensnd_rw_req rw;
10218c2ecf20Sopenharmony_ci		struct xensnd_trigger_req trigger;
10228c2ecf20Sopenharmony_ci		struct xensnd_query_hw_param hw_param;
10238c2ecf20Sopenharmony_ci		uint8_t reserved[56];
10248c2ecf20Sopenharmony_ci	} op;
10258c2ecf20Sopenharmony_ci};
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_cistruct xensnd_resp {
10288c2ecf20Sopenharmony_ci	uint16_t id;
10298c2ecf20Sopenharmony_ci	uint8_t operation;
10308c2ecf20Sopenharmony_ci	uint8_t reserved;
10318c2ecf20Sopenharmony_ci	int32_t status;
10328c2ecf20Sopenharmony_ci	union {
10338c2ecf20Sopenharmony_ci		struct xensnd_query_hw_param hw_param;
10348c2ecf20Sopenharmony_ci		uint8_t reserved1[56];
10358c2ecf20Sopenharmony_ci	} resp;
10368c2ecf20Sopenharmony_ci};
10378c2ecf20Sopenharmony_ci
10388c2ecf20Sopenharmony_cistruct xensnd_evt {
10398c2ecf20Sopenharmony_ci	uint16_t id;
10408c2ecf20Sopenharmony_ci	uint8_t type;
10418c2ecf20Sopenharmony_ci	uint8_t reserved[5];
10428c2ecf20Sopenharmony_ci	union {
10438c2ecf20Sopenharmony_ci		struct xensnd_cur_pos_evt cur_pos;
10448c2ecf20Sopenharmony_ci		uint8_t reserved[56];
10458c2ecf20Sopenharmony_ci	} op;
10468c2ecf20Sopenharmony_ci};
10478c2ecf20Sopenharmony_ci
10488c2ecf20Sopenharmony_ciDEFINE_RING_TYPES(xen_sndif, struct xensnd_req, struct xensnd_resp);
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci/*
10518c2ecf20Sopenharmony_ci ******************************************************************************
10528c2ecf20Sopenharmony_ci *                        Back to front events delivery
10538c2ecf20Sopenharmony_ci ******************************************************************************
10548c2ecf20Sopenharmony_ci * In order to deliver asynchronous events from back to front a shared page is
10558c2ecf20Sopenharmony_ci * allocated by front and its granted reference propagated to back via
10568c2ecf20Sopenharmony_ci * XenStore entries (evt-ring-ref/evt-event-channel).
10578c2ecf20Sopenharmony_ci * This page has a common header used by both front and back to synchronize
10588c2ecf20Sopenharmony_ci * access and control event's ring buffer, while back being a producer of the
10598c2ecf20Sopenharmony_ci * events and front being a consumer. The rest of the page after the header
10608c2ecf20Sopenharmony_ci * is used for event packets.
10618c2ecf20Sopenharmony_ci *
10628c2ecf20Sopenharmony_ci * Upon reception of an event(s) front may confirm its reception
10638c2ecf20Sopenharmony_ci * for either each event, group of events or none.
10648c2ecf20Sopenharmony_ci */
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_cistruct xensnd_event_page {
10678c2ecf20Sopenharmony_ci	uint32_t in_cons;
10688c2ecf20Sopenharmony_ci	uint32_t in_prod;
10698c2ecf20Sopenharmony_ci	uint8_t reserved[56];
10708c2ecf20Sopenharmony_ci};
10718c2ecf20Sopenharmony_ci
10728c2ecf20Sopenharmony_ci#define XENSND_EVENT_PAGE_SIZE XEN_PAGE_SIZE
10738c2ecf20Sopenharmony_ci#define XENSND_IN_RING_OFFS (sizeof(struct xensnd_event_page))
10748c2ecf20Sopenharmony_ci#define XENSND_IN_RING_SIZE (XENSND_EVENT_PAGE_SIZE - XENSND_IN_RING_OFFS)
10758c2ecf20Sopenharmony_ci#define XENSND_IN_RING_LEN (XENSND_IN_RING_SIZE / sizeof(struct xensnd_evt))
10768c2ecf20Sopenharmony_ci#define XENSND_IN_RING(page) \
10778c2ecf20Sopenharmony_ci	((struct xensnd_evt *)((char *)(page) + XENSND_IN_RING_OFFS))
10788c2ecf20Sopenharmony_ci#define XENSND_IN_RING_REF(page, idx) \
10798c2ecf20Sopenharmony_ci	(XENSND_IN_RING((page))[(idx) % XENSND_IN_RING_LEN])
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci#endif /* __XEN_PUBLIC_IO_SNDIF_H__ */
1082