cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

audio-v2.h (14356B)


      1// SPDX-License-Identifier: GPL-2.0
      2/*
      3 * Copyright (c) 2010 Daniel Mack <daniel@caiaq.de>
      4 *
      5 * This software is distributed under the terms of the GNU General Public
      6 * License ("GPL") version 2, as published by the Free Software Foundation.
      7 *
      8 * This file holds USB constants and structures defined
      9 * by the USB Device Class Definition for Audio Devices in version 2.0.
     10 * Comments below reference relevant sections of the documents contained
     11 * in http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
     12 */
     13
     14#ifndef __LINUX_USB_AUDIO_V2_H
     15#define __LINUX_USB_AUDIO_V2_H
     16
     17#include <linux/types.h>
     18
     19/* v1.0 and v2.0 of this standard have many things in common. For the rest
     20 * of the definitions, please refer to audio.h */
     21
     22/*
     23 * bmControl field decoders
     24 *
     25 * From the USB Audio spec v2.0:
     26 *
     27 *   bmaControls() is a (ch+1)-element array of 4-byte bitmaps,
     28 *   each containing a set of bit pairs. If a Control is present,
     29 *   it must be Host readable. If a certain Control is not
     30 *   present then the bit pair must be set to 0b00.
     31 *   If a Control is present but read-only, the bit pair must be
     32 *   set to 0b01. If a Control is also Host programmable, the bit
     33 *   pair must be set to 0b11. The value 0b10 is not allowed.
     34 *
     35 */
     36
     37static inline bool uac_v2v3_control_is_readable(u32 bmControls, u8 control)
     38{
     39	return (bmControls >> ((control - 1) * 2)) & 0x1;
     40}
     41
     42static inline bool uac_v2v3_control_is_writeable(u32 bmControls, u8 control)
     43{
     44	return (bmControls >> ((control - 1) * 2)) & 0x2;
     45}
     46
     47/* 4.7.2 Class-Specific AC Interface Descriptor */
     48struct uac2_ac_header_descriptor {
     49	__u8  bLength;			/* 9 */
     50	__u8  bDescriptorType;		/* USB_DT_CS_INTERFACE */
     51	__u8  bDescriptorSubtype;	/* UAC_MS_HEADER */
     52	__le16 bcdADC;			/* 0x0200 */
     53	__u8  bCategory;
     54	__le16 wTotalLength;		/* includes Unit and Terminal desc. */
     55	__u8  bmControls;
     56} __packed;
     57
     58/* 2.3.1.6 Type I Format Type Descriptor (Frmts20 final.pdf)*/
     59struct uac2_format_type_i_descriptor {
     60	__u8  bLength;			/* in bytes: 6 */
     61	__u8  bDescriptorType;		/* USB_DT_CS_INTERFACE */
     62	__u8  bDescriptorSubtype;	/* FORMAT_TYPE */
     63	__u8  bFormatType;		/* FORMAT_TYPE_1 */
     64	__u8  bSubslotSize;		/* {1,2,3,4} */
     65	__u8  bBitResolution;
     66} __packed;
     67
     68/* 4.7.2.1 Clock Source Descriptor */
     69
     70struct uac_clock_source_descriptor {
     71	__u8 bLength;
     72	__u8 bDescriptorType;
     73	__u8 bDescriptorSubtype;
     74	__u8 bClockID;
     75	__u8 bmAttributes;
     76	__u8 bmControls;
     77	__u8 bAssocTerminal;
     78	__u8 iClockSource;
     79} __attribute__((packed));
     80
     81/* bmAttribute fields */
     82#define UAC_CLOCK_SOURCE_TYPE_EXT	0x0
     83#define UAC_CLOCK_SOURCE_TYPE_INT_FIXED	0x1
     84#define UAC_CLOCK_SOURCE_TYPE_INT_VAR	0x2
     85#define UAC_CLOCK_SOURCE_TYPE_INT_PROG	0x3
     86#define UAC_CLOCK_SOURCE_SYNCED_TO_SOF	(1 << 2)
     87
     88/* 4.7.2.2 Clock Source Descriptor */
     89
     90struct uac_clock_selector_descriptor {
     91	__u8 bLength;
     92	__u8 bDescriptorType;
     93	__u8 bDescriptorSubtype;
     94	__u8 bClockID;
     95	__u8 bNrInPins;
     96	__u8 baCSourceID[];
     97	/* bmControls and iClockSource omitted */
     98} __attribute__((packed));
     99
    100/* 4.7.2.3 Clock Multiplier Descriptor */
    101
    102struct uac_clock_multiplier_descriptor {
    103	__u8 bLength;
    104	__u8 bDescriptorType;
    105	__u8 bDescriptorSubtype;
    106	__u8 bClockID;
    107	__u8 bCSourceID;
    108	__u8 bmControls;
    109	__u8 iClockMultiplier;
    110} __attribute__((packed));
    111
    112/* 4.7.2.4 Input terminal descriptor */
    113
    114struct uac2_input_terminal_descriptor {
    115	__u8 bLength;
    116	__u8 bDescriptorType;
    117	__u8 bDescriptorSubtype;
    118	__u8 bTerminalID;
    119	__le16 wTerminalType;
    120	__u8 bAssocTerminal;
    121	__u8 bCSourceID;
    122	__u8 bNrChannels;
    123	__le32 bmChannelConfig;
    124	__u8 iChannelNames;
    125	__le16 bmControls;
    126	__u8 iTerminal;
    127} __attribute__((packed));
    128
    129/* 4.7.2.5 Output terminal descriptor */
    130
    131struct uac2_output_terminal_descriptor {
    132	__u8 bLength;
    133	__u8 bDescriptorType;
    134	__u8 bDescriptorSubtype;
    135	__u8 bTerminalID;
    136	__le16 wTerminalType;
    137	__u8 bAssocTerminal;
    138	__u8 bSourceID;
    139	__u8 bCSourceID;
    140	__le16 bmControls;
    141	__u8 iTerminal;
    142} __attribute__((packed));
    143
    144
    145
    146/* 4.7.2.8 Feature Unit Descriptor */
    147
    148struct uac2_feature_unit_descriptor {
    149	__u8 bLength;
    150	__u8 bDescriptorType;
    151	__u8 bDescriptorSubtype;
    152	__u8 bUnitID;
    153	__u8 bSourceID;
    154	/* bmaControls is actually u32,
    155	 * but u8 is needed for the hybrid parser */
    156	__u8 bmaControls[]; /* variable length */
    157} __attribute__((packed));
    158
    159#define UAC2_DT_FEATURE_UNIT_SIZE(ch)		(6 + ((ch) + 1) * 4)
    160
    161/* As above, but more useful for defining your own descriptors: */
    162#define DECLARE_UAC2_FEATURE_UNIT_DESCRIPTOR(ch)		\
    163struct uac2_feature_unit_descriptor_##ch {			\
    164	__u8  bLength;						\
    165	__u8  bDescriptorType;					\
    166	__u8  bDescriptorSubtype;				\
    167	__u8  bUnitID;						\
    168	__u8  bSourceID;					\
    169	__le32 bmaControls[ch + 1];				\
    170	__u8  iFeature;						\
    171} __packed
    172
    173/* 4.7.2.10 Effect Unit Descriptor */
    174
    175struct uac2_effect_unit_descriptor {
    176	__u8 bLength;
    177	__u8 bDescriptorType;
    178	__u8 bDescriptorSubtype;
    179	__u8 bUnitID;
    180	__le16 wEffectType;
    181	__u8 bSourceID;
    182	__u8 bmaControls[]; /* variable length */
    183} __attribute__((packed));
    184
    185/* 4.9.2 Class-Specific AS Interface Descriptor */
    186
    187struct uac2_as_header_descriptor {
    188	__u8 bLength;
    189	__u8 bDescriptorType;
    190	__u8 bDescriptorSubtype;
    191	__u8 bTerminalLink;
    192	__u8 bmControls;
    193	__u8 bFormatType;
    194	__le32 bmFormats;
    195	__u8 bNrChannels;
    196	__le32 bmChannelConfig;
    197	__u8 iChannelNames;
    198} __attribute__((packed));
    199
    200#define UAC2_FORMAT_TYPE_I_RAW_DATA	(1 << 31)
    201
    202/* 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor */
    203
    204struct uac2_iso_endpoint_descriptor {
    205	__u8  bLength;			/* in bytes: 8 */
    206	__u8  bDescriptorType;		/* USB_DT_CS_ENDPOINT */
    207	__u8  bDescriptorSubtype;	/* EP_GENERAL */
    208	__u8  bmAttributes;
    209	__u8  bmControls;
    210	__u8  bLockDelayUnits;
    211	__le16 wLockDelay;
    212} __attribute__((packed));
    213
    214#define UAC2_CONTROL_PITCH		(3 << 0)
    215#define UAC2_CONTROL_DATA_OVERRUN	(3 << 2)
    216#define UAC2_CONTROL_DATA_UNDERRUN	(3 << 4)
    217
    218/* 5.2.5.4.2 Connector Control Parameter Block */
    219struct uac2_connectors_ctl_blk {
    220	__u8 bNrChannels;
    221	__le32 bmChannelConfig;
    222	__u8 iChannelNames;
    223} __attribute__((packed));
    224
    225/* 6.1 Interrupt Data Message */
    226
    227#define UAC2_INTERRUPT_DATA_MSG_VENDOR	(1 << 0)
    228#define UAC2_INTERRUPT_DATA_MSG_EP	(1 << 1)
    229
    230struct uac2_interrupt_data_msg {
    231	__u8 bInfo;
    232	__u8 bAttribute;
    233	__le16 wValue;
    234	__le16 wIndex;
    235} __attribute__((packed));
    236
    237/* A.7 Audio Function Category Codes */
    238#define UAC2_FUNCTION_SUBCLASS_UNDEFINED	0x00
    239#define UAC2_FUNCTION_DESKTOP_SPEAKER		0x01
    240#define UAC2_FUNCTION_HOME_THEATER		0x02
    241#define UAC2_FUNCTION_MICROPHONE		0x03
    242#define UAC2_FUNCTION_HEADSET			0x04
    243#define UAC2_FUNCTION_TELEPHONE			0x05
    244#define UAC2_FUNCTION_CONVERTER			0x06
    245#define UAC2_FUNCTION_SOUND_RECORDER		0x07
    246#define UAC2_FUNCTION_IO_BOX			0x08
    247#define UAC2_FUNCTION_MUSICAL_INSTRUMENT	0x09
    248#define UAC2_FUNCTION_PRO_AUDIO			0x0a
    249#define UAC2_FUNCTION_AUDIO_VIDEO		0x0b
    250#define UAC2_FUNCTION_CONTROL_PANEL		0x0c
    251#define UAC2_FUNCTION_OTHER			0xff
    252
    253/* A.9 Audio Class-Specific AC Interface Descriptor Subtypes */
    254/* see audio.h for the rest, which is identical to v1 */
    255#define UAC2_EFFECT_UNIT			0x07
    256#define UAC2_PROCESSING_UNIT_V2		0x08
    257#define UAC2_EXTENSION_UNIT_V2		0x09
    258#define UAC2_CLOCK_SOURCE		0x0a
    259#define UAC2_CLOCK_SELECTOR		0x0b
    260#define UAC2_CLOCK_MULTIPLIER		0x0c
    261#define UAC2_SAMPLE_RATE_CONVERTER	0x0d
    262
    263/* A.10 Audio Class-Specific AS Interface Descriptor Subtypes */
    264/* see audio.h for the rest, which is identical to v1 */
    265#define UAC2_ENCODER			0x03
    266#define UAC2_DECODER			0x04
    267
    268/* A.11 Effect Unit Effect Types */
    269#define UAC2_EFFECT_UNDEFINED		0x00
    270#define UAC2_EFFECT_PARAM_EQ		0x01
    271#define UAC2_EFFECT_REVERB		0x02
    272#define UAC2_EFFECT_MOD_DELAY		0x03
    273#define UAC2_EFFECT_DYN_RANGE_COMP	0x04
    274
    275/* A.12 Processing Unit Process Types */
    276#define UAC2_PROCESS_UNDEFINED		0x00
    277#define UAC2_PROCESS_UP_DOWNMIX		0x01
    278#define UAC2_PROCESS_DOLBY_PROLOCIC	0x02
    279#define UAC2_PROCESS_STEREO_EXTENDER	0x03
    280
    281/* A.14 Audio Class-Specific Request Codes */
    282#define UAC2_CS_CUR			0x01
    283#define UAC2_CS_RANGE			0x02
    284#define UAC2_CS_MEM			0x03
    285
    286/* A.15 Encoder Type Codes */
    287#define UAC2_ENCODER_UNDEFINED		0x00
    288#define UAC2_ENCODER_OTHER		0x01
    289#define UAC2_ENCODER_MPEG		0x02
    290#define UAC2_ENCODER_AC3		0x03
    291#define UAC2_ENCODER_WMA		0x04
    292#define UAC2_ENCODER_DTS		0x05
    293
    294/* A.16 Decoder Type Codes */
    295#define UAC2_DECODER_UNDEFINED		0x00
    296#define UAC2_DECODER_OTHER		0x01
    297#define UAC2_DECODER_MPEG		0x02
    298#define UAC2_DECODER_AC3		0x03
    299#define UAC2_DECODER_WMA		0x04
    300#define UAC2_DECODER_DTS		0x05
    301
    302/* A.17.1 Clock Source Control Selectors */
    303#define UAC2_CS_UNDEFINED		0x00
    304#define UAC2_CS_CONTROL_SAM_FREQ	0x01
    305#define UAC2_CS_CONTROL_CLOCK_VALID	0x02
    306
    307/* A.17.2 Clock Selector Control Selectors */
    308#define UAC2_CX_UNDEFINED		0x00
    309#define UAC2_CX_CLOCK_SELECTOR		0x01
    310
    311/* A.17.3 Clock Multiplier Control Selectors */
    312#define UAC2_CM_UNDEFINED		0x00
    313#define UAC2_CM_NUMERATOR		0x01
    314#define UAC2_CM_DENOMINTATOR		0x02
    315
    316/* A.17.4 Terminal Control Selectors */
    317#define UAC2_TE_UNDEFINED		0x00
    318#define UAC2_TE_COPY_PROTECT		0x01
    319#define UAC2_TE_CONNECTOR		0x02
    320#define UAC2_TE_OVERLOAD		0x03
    321#define UAC2_TE_CLUSTER			0x04
    322#define UAC2_TE_UNDERFLOW		0x05
    323#define UAC2_TE_OVERFLOW		0x06
    324#define UAC2_TE_LATENCY			0x07
    325
    326/* A.17.5 Mixer Control Selectors */
    327#define UAC2_MU_UNDEFINED		0x00
    328#define UAC2_MU_MIXER			0x01
    329#define UAC2_MU_CLUSTER			0x02
    330#define UAC2_MU_UNDERFLOW		0x03
    331#define UAC2_MU_OVERFLOW		0x04
    332#define UAC2_MU_LATENCY			0x05
    333
    334/* A.17.6 Selector Control Selectors */
    335#define UAC2_SU_UNDEFINED		0x00
    336#define UAC2_SU_SELECTOR		0x01
    337#define UAC2_SU_LATENCY			0x02
    338
    339/* A.17.7 Feature Unit Control Selectors */
    340/* see audio.h for the rest, which is identical to v1 */
    341#define UAC2_FU_INPUT_GAIN		0x0b
    342#define UAC2_FU_INPUT_GAIN_PAD		0x0c
    343#define UAC2_FU_PHASE_INVERTER		0x0d
    344#define UAC2_FU_UNDERFLOW		0x0e
    345#define UAC2_FU_OVERFLOW		0x0f
    346#define UAC2_FU_LATENCY			0x10
    347
    348/* A.17.8.1 Parametric Equalizer Section Effect Unit Control Selectors */
    349#define UAC2_PE_UNDEFINED		0x00
    350#define UAC2_PE_ENABLE			0x01
    351#define UAC2_PE_CENTERFREQ		0x02
    352#define UAC2_PE_QFACTOR			0x03
    353#define UAC2_PE_GAIN			0x04
    354#define UAC2_PE_UNDERFLOW		0x05
    355#define UAC2_PE_OVERFLOW		0x06
    356#define UAC2_PE_LATENCY			0x07
    357
    358/* A.17.8.2 Reverberation Effect Unit Control Selectors */
    359#define UAC2_RV_UNDEFINED		0x00
    360#define UAC2_RV_ENABLE			0x01
    361#define UAC2_RV_TYPE			0x02
    362#define UAC2_RV_LEVEL			0x03
    363#define UAC2_RV_TIME			0x04
    364#define UAC2_RV_FEEDBACK		0x05
    365#define UAC2_RV_PREDELAY		0x06
    366#define UAC2_RV_DENSITY			0x07
    367#define UAC2_RV_HIFREQ_ROLLOFF		0x08
    368#define UAC2_RV_UNDERFLOW		0x09
    369#define UAC2_RV_OVERFLOW		0x0a
    370#define UAC2_RV_LATENCY			0x0b
    371
    372/* A.17.8.3 Modulation Delay Effect Control Selectors */
    373#define UAC2_MD_UNDEFINED		0x00
    374#define UAC2_MD_ENABLE			0x01
    375#define UAC2_MD_BALANCE			0x02
    376#define UAC2_MD_RATE			0x03
    377#define UAC2_MD_DEPTH			0x04
    378#define UAC2_MD_TIME			0x05
    379#define UAC2_MD_FEEDBACK		0x06
    380#define UAC2_MD_UNDERFLOW		0x07
    381#define UAC2_MD_OVERFLOW		0x08
    382#define UAC2_MD_LATENCY			0x09
    383
    384/* A.17.8.4 Dynamic Range Compressor Effect Unit Control Selectors */
    385#define UAC2_DR_UNDEFINED		0x00
    386#define UAC2_DR_ENABLE			0x01
    387#define UAC2_DR_COMPRESSION_RATE	0x02
    388#define UAC2_DR_MAXAMPL			0x03
    389#define UAC2_DR_THRESHOLD		0x04
    390#define UAC2_DR_ATTACK_TIME		0x05
    391#define UAC2_DR_RELEASE_TIME		0x06
    392#define UAC2_DR_UNDEFLOW		0x07
    393#define UAC2_DR_OVERFLOW		0x08
    394#define UAC2_DR_LATENCY			0x09
    395
    396/* A.17.9.1 Up/Down-mix Processing Unit Control Selectors */
    397#define UAC2_UD_UNDEFINED		0x00
    398#define UAC2_UD_ENABLE			0x01
    399#define UAC2_UD_MODE_SELECT		0x02
    400#define UAC2_UD_CLUSTER			0x03
    401#define UAC2_UD_UNDERFLOW		0x04
    402#define UAC2_UD_OVERFLOW		0x05
    403#define UAC2_UD_LATENCY			0x06
    404
    405/* A.17.9.2 Dolby Prologic[tm] Processing Unit Control Selectors */
    406#define UAC2_DP_UNDEFINED		0x00
    407#define UAC2_DP_ENABLE			0x01
    408#define UAC2_DP_MODE_SELECT		0x02
    409#define UAC2_DP_CLUSTER			0x03
    410#define UAC2_DP_UNDERFFLOW		0x04
    411#define UAC2_DP_OVERFLOW		0x05
    412#define UAC2_DP_LATENCY			0x06
    413
    414/* A.17.9.3 Stereo Expander Processing Unit Control Selectors */
    415#define UAC2_ST_EXT_UNDEFINED		0x00
    416#define UAC2_ST_EXT_ENABLE		0x01
    417#define UAC2_ST_EXT_WIDTH		0x02
    418#define UAC2_ST_EXT_UNDEFLOW		0x03
    419#define UAC2_ST_EXT_OVERFLOW		0x04
    420#define UAC2_ST_EXT_LATENCY		0x05
    421
    422/* A.17.10 Extension Unit Control Selectors */
    423#define UAC2_XU_UNDEFINED		0x00
    424#define UAC2_XU_ENABLE			0x01
    425#define UAC2_XU_CLUSTER			0x02
    426#define UAC2_XU_UNDERFLOW		0x03
    427#define UAC2_XU_OVERFLOW		0x04
    428#define UAC2_XU_LATENCY			0x05
    429
    430/* A.17.11 AudioStreaming Interface Control Selectors */
    431#define UAC2_AS_UNDEFINED		0x00
    432#define UAC2_AS_ACT_ALT_SETTING		0x01
    433#define UAC2_AS_VAL_ALT_SETTINGS	0x02
    434#define UAC2_AS_AUDIO_DATA_FORMAT	0x03
    435
    436/* A.17.12 Encoder Control Selectors */
    437#define UAC2_EN_UNDEFINED		0x00
    438#define UAC2_EN_BIT_RATE		0x01
    439#define UAC2_EN_QUALITY			0x02
    440#define UAC2_EN_VBR			0x03
    441#define UAC2_EN_TYPE			0x04
    442#define UAC2_EN_UNDERFLOW		0x05
    443#define UAC2_EN_OVERFLOW		0x06
    444#define UAC2_EN_ENCODER_ERROR		0x07
    445#define UAC2_EN_PARAM1			0x08
    446#define UAC2_EN_PARAM2			0x09
    447#define UAC2_EN_PARAM3			0x0a
    448#define UAC2_EN_PARAM4			0x0b
    449#define UAC2_EN_PARAM5			0x0c
    450#define UAC2_EN_PARAM6			0x0d
    451#define UAC2_EN_PARAM7			0x0e
    452#define UAC2_EN_PARAM8			0x0f
    453
    454/* A.17.13.1 MPEG Decoder Control Selectors */
    455#define UAC2_MPEG_UNDEFINED		0x00
    456#define UAC2_MPEG_DUAL_CHANNEL		0x01
    457#define UAC2_MPEG_SECOND_STEREO		0x02
    458#define UAC2_MPEG_MULTILINGUAL		0x03
    459#define UAC2_MPEG_DYN_RANGE		0x04
    460#define UAC2_MPEG_SCALING		0x05
    461#define UAC2_MPEG_HILO_SCALING		0x06
    462#define UAC2_MPEG_UNDERFLOW		0x07
    463#define UAC2_MPEG_OVERFLOW		0x08
    464#define UAC2_MPEG_DECODER_ERROR		0x09
    465
    466/* A17.13.2 AC3 Decoder Control Selectors */
    467#define UAC2_AC3_UNDEFINED		0x00
    468#define UAC2_AC3_MODE			0x01
    469#define UAC2_AC3_DYN_RANGE		0x02
    470#define UAC2_AC3_SCALING		0x03
    471#define UAC2_AC3_HILO_SCALING		0x04
    472#define UAC2_AC3_UNDERFLOW		0x05
    473#define UAC2_AC3_OVERFLOW		0x06
    474#define UAC2_AC3_DECODER_ERROR		0x07
    475
    476/* A17.13.3 WMA Decoder Control Selectors */
    477#define UAC2_WMA_UNDEFINED		0x00
    478#define UAC2_WMA_UNDERFLOW		0x01
    479#define UAC2_WMA_OVERFLOW		0x02
    480#define UAC2_WMA_DECODER_ERROR		0x03
    481
    482/* A17.13.4 DTS Decoder Control Selectors */
    483#define UAC2_DTS_UNDEFINED		0x00
    484#define UAC2_DTS_UNDERFLOW		0x01
    485#define UAC2_DTS_OVERFLOW		0x02
    486#define UAC2_DTS_DECODER_ERROR		0x03
    487
    488/* A17.14 Endpoint Control Selectors */
    489#define UAC2_EP_CS_UNDEFINED		0x00
    490#define UAC2_EP_CS_PITCH		0x01
    491#define UAC2_EP_CS_DATA_OVERRUN		0x02
    492#define UAC2_EP_CS_DATA_UNDERRUN	0x03
    493
    494#endif /* __LINUX_USB_AUDIO_V2_H */
    495