mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2025-12-28 16:29:45 +00:00
Merge pull request #1 from dorindabassey/d_sound
virtio_sound.rs: Added device configuration and common definitions
This commit is contained in:
commit
c3e2f6a4bc
@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
|
||||
#![allow(dead_code)] //TODO: remove
|
||||
|
||||
use vm_memory::{ByteValued, Le32};
|
||||
use vm_memory::{ByteValued, Le32, Le64};
|
||||
|
||||
// virtqueues
|
||||
|
||||
@ -51,6 +51,106 @@ pub const VIRTIO_SND_S_IO_ERR: u32 = 0x8003;
|
||||
pub const VIRTIO_SND_D_OUTPUT: u32 = 0;
|
||||
pub const VIRTIO_SND_D_INPUT: u32 = 1;
|
||||
|
||||
// supported jack features
|
||||
|
||||
pub const VIRTIO_SND_JACK_F_REMAP: u32 = 0;
|
||||
|
||||
// supported PCM stream features
|
||||
|
||||
pub const VIRTIO_SND_PCM_F_SHMEM_HOST: u8 = 0;
|
||||
pub const VIRTIO_SND_PCM_F_SHMEM_GUEST: u8 = 1;
|
||||
pub const VIRTIO_SND_PCM_F_MSG_POLLING: u8 = 2;
|
||||
pub const VIRTIO_SND_PCM_F_EVT_SHMEM_PERIODS: u8 = 3;
|
||||
pub const VIRTIO_SND_PCM_F_EVT_XRUNS: u8 = 4;
|
||||
|
||||
// supported PCM sample formats
|
||||
|
||||
pub const VIRTIO_SND_PCM_FMT_IMA_ADPCM: u8 = 0;
|
||||
pub const VIRTIO_SND_PCM_FMT_MU_LAW: u8 = 1;
|
||||
pub const VIRTIO_SND_PCM_FMT_A_LAW: u8 = 2;
|
||||
pub const VIRTIO_SND_PCM_FMT_S8: u8 = 3;
|
||||
pub const VIRTIO_SND_PCM_FMT_U8: u8 = 4;
|
||||
pub const VIRTIO_SND_PCM_FMT_S16: u8 = 5;
|
||||
pub const VIRTIO_SND_PCM_FMT_U16: u8 = 6;
|
||||
pub const VIRTIO_SND_PCM_FMT_S18_3: u8 = 7;
|
||||
pub const VIRTIO_SND_PCM_FMT_U18_3: u8 = 8;
|
||||
pub const VIRTIO_SND_PCM_FMT_S20_3: u8 = 9;
|
||||
pub const VIRTIO_SND_PCM_FMT_U20_3: u8 = 10;
|
||||
pub const VIRTIO_SND_PCM_FMT_S24_3: u8 = 11;
|
||||
pub const VIRTIO_SND_PCM_FMT_U24_3: u8 = 12;
|
||||
pub const VIRTIO_SND_PCM_FMT_S20: u8 = 13;
|
||||
pub const VIRTIO_SND_PCM_FMT_U20: u8 = 14;
|
||||
pub const VIRTIO_SND_PCM_FMT_S24: u8 = 15;
|
||||
pub const VIRTIO_SND_PCM_FMT_U24: u8 = 16;
|
||||
pub const VIRTIO_SND_PCM_FMT_S32: u8 = 17;
|
||||
pub const VIRTIO_SND_PCM_FMT_U32: u8 = 18;
|
||||
pub const VIRTIO_SND_PCM_FMT_FLOAT: u8 = 19;
|
||||
pub const VIRTIO_SND_PCM_FMT_FLOAT64: u8 = 20;
|
||||
// digital formats (width / physical width)
|
||||
pub const VIRTIO_SND_PCM_FMT_DSD_U8: u8 = 21;
|
||||
pub const VIRTIO_SND_PCM_FMT_DSD_U16: u8 = 22;
|
||||
pub const VIRTIO_SND_PCM_FMT_DSD_U32: u8 = 23;
|
||||
pub const VIRTIO_SND_PCM_FMT_IEC958_SUBFRAME: u8 = 24;
|
||||
|
||||
// supported PCM frame rates
|
||||
|
||||
pub const VIRTIO_SND_PCM_RATE_5512: u8 = 0;
|
||||
pub const VIRTIO_SND_PCM_RATE_8000: u8 = 1;
|
||||
pub const VIRTIO_SND_PCM_RATE_11025: u8 = 2;
|
||||
pub const VIRTIO_SND_PCM_RATE_16000: u8 = 3;
|
||||
pub const VIRTIO_SND_PCM_RATE_22050: u8 = 4;
|
||||
pub const VIRTIO_SND_PCM_RATE_32000: u8 = 5;
|
||||
pub const VIRTIO_SND_PCM_RATE_44100: u8 = 6;
|
||||
pub const VIRTIO_SND_PCM_RATE_48000: u8 = 7;
|
||||
pub const VIRTIO_SND_PCM_RATE_64000: u8 = 8;
|
||||
pub const VIRTIO_SND_PCM_RATE_88200: u8 = 9;
|
||||
pub const VIRTIO_SND_PCM_RATE_96000: u8 = 10;
|
||||
pub const VIRTIO_SND_PCM_RATE_176400: u8 = 11;
|
||||
pub const VIRTIO_SND_PCM_RATE_192000: u8 = 12;
|
||||
pub const VIRTIO_SND_PCM_RATE_384000: u8 = 13;
|
||||
|
||||
// standard channel position definition
|
||||
|
||||
pub const VIRTIO_SND_CHMAP_NONE: u8 = 0; /* undefined */
|
||||
pub const VIRTIO_SND_CHMAP_NA: u8 = 1; /* silent */
|
||||
pub const VIRTIO_SND_CHMAP_MONO: u8 = 2; /* mono stream */
|
||||
pub const VIRTIO_SND_CHMAP_FL: u8 = 3; /* front left */
|
||||
pub const VIRTIO_SND_CHMAP_FR: u8 = 4; /* front right */
|
||||
pub const VIRTIO_SND_CHMAP_RL: u8 = 5; /* rear left */
|
||||
pub const VIRTIO_SND_CHMAP_RR: u8 = 6; /* rear right */
|
||||
pub const VIRTIO_SND_CHMAP_FC: u8 = 7; /* front center */
|
||||
pub const VIRTIO_SND_CHMAP_LFE: u8 = 8; /* low frequency (LFE) */
|
||||
pub const VIRTIO_SND_CHMAP_SL: u8 = 9; /* side left */
|
||||
pub const VIRTIO_SND_CHMAP_SR: u8 = 10; /* side right */
|
||||
pub const VIRTIO_SND_CHMAP_RC: u8 = 11; /* rear center */
|
||||
pub const VIRTIO_SND_CHMAP_FLC: u8 = 12; /* front left center */
|
||||
pub const VIRTIO_SND_CHMAP_FRC: u8 = 13; /* front right center */
|
||||
pub const VIRTIO_SND_CHMAP_RLC: u8 = 14; /* rear left center */
|
||||
pub const VIRTIO_SND_CHMAP_RRC: u8 = 15; /* rear right center */
|
||||
pub const VIRTIO_SND_CHMAP_FLW: u8 = 16; /* front left wide */
|
||||
pub const VIRTIO_SND_CHMAP_FRW: u8 = 17; /* front right wide */
|
||||
pub const VIRTIO_SND_CHMAP_FLH: u8 = 18; /* front left high */
|
||||
pub const VIRTIO_SND_CHMAP_FCH: u8 = 19; /* front center high */
|
||||
pub const VIRTIO_SND_CHMAP_FRH: u8 = 20; /* front right high */
|
||||
pub const VIRTIO_SND_CHMAP_TC: u8 = 21; /* top center */
|
||||
pub const VIRTIO_SND_CHMAP_TFL: u8 = 22; /* top front left */
|
||||
pub const VIRTIO_SND_CHMAP_TFR: u8 = 23; /* top front right */
|
||||
pub const VIRTIO_SND_CHMAP_TFC: u8 = 24; /* top front center */
|
||||
pub const VIRTIO_SND_CHMAP_TRL: u8 = 25; /* top rear left */
|
||||
pub const VIRTIO_SND_CHMAP_TRR: u8 = 26; /* top rear right */
|
||||
pub const VIRTIO_SND_CHMAP_TRC: u8 = 27; /* top rear center */
|
||||
pub const VIRTIO_SND_CHMAP_TFLC: u8 = 28; /* top front left center */
|
||||
pub const VIRTIO_SND_CHMAP_TFRC: u8 = 29; /* top front right center */
|
||||
pub const VIRTIO_SND_CHMAP_TSL: u8 = 34; /* top side left */
|
||||
pub const VIRTIO_SND_CHMAP_TSR: u8 = 35; /* top side right */
|
||||
pub const VIRTIO_SND_CHMAP_LLFE: u8 = 36; /* left LFE */
|
||||
pub const VIRTIO_SND_CHMAP_RLFE: u8 = 37; /* right LFE */
|
||||
pub const VIRTIO_SND_CHMAP_BC: u8 = 38; /* bottom center */
|
||||
pub const VIRTIO_SND_CHMAP_BLC: u8 = 39; /* bottom left center */
|
||||
pub const VIRTIO_SND_CHMAP_BRC: u8 = 40; /* bottom right center */
|
||||
// maximum possible number of channels
|
||||
pub const VIRTIO_SND_CHMAP_MAX_SIZE: usize = 18;
|
||||
|
||||
/// Virtio Sound Configuration
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
@ -99,7 +199,7 @@ pub struct VirtioSoundQueryInfo {
|
||||
/// starting identifier for the item
|
||||
pub start_id: Le32,
|
||||
/// number of items for which information is requested
|
||||
pub cound: Le32,
|
||||
pub count: Le32,
|
||||
/// size of the structure containing information for one item
|
||||
pub size: Le32,
|
||||
}
|
||||
@ -117,3 +217,129 @@ pub struct VirtioSoundInfo {
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundInfo {}
|
||||
|
||||
/// Jack control request / Jack common header
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSoundJackHeader {
|
||||
/// jack request type (VIRTIO_SND_R_JACK_*)
|
||||
pub hdr: VirtioSoundHeader,
|
||||
/// jack identifier
|
||||
pub jack_id: Le32,
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundJackHeader {}
|
||||
|
||||
/// Jack response information about available jacks
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSoundJackInfo {
|
||||
/// jack response header type
|
||||
pub hdr: VirtioSoundInfo,
|
||||
/// supported feature bit map (VIRTIO_SND_JACK_F_XXX)
|
||||
pub feature: Le32,
|
||||
/// pin default configuration value
|
||||
pub hda_reg_defconf: Le32,
|
||||
/// pin capabilities value
|
||||
pub hda_reg_caps: Le32,
|
||||
/// current jack connection status
|
||||
pub connected: u8,
|
||||
pub padding: [u8; 7],
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundJackInfo {}
|
||||
|
||||
///If the VIRTIO_SND_JACK_F_REMAP feature bit is set in the jack information
|
||||
/// Remap control request
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSoundJackRemap {
|
||||
pub hdr: VirtioSoundJackHeader, /* .code = VIRTIO_SND_R_JACK_REMAP */
|
||||
pub association: Le32,
|
||||
pub sequence: Le32,
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundJackRemap {}
|
||||
|
||||
/// PCM control request / PCM common header
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSoundPcmHeader {
|
||||
pub hdr: VirtioSoundHeader,
|
||||
pub stream_id: Le32,
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundPcmHeader {}
|
||||
|
||||
/// PCM response information
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSoundPcmInfo {
|
||||
pub hdr: VirtioSoundInfo,
|
||||
pub features: Le32, /* 1 << VIRTIO_SND_PCM_F_XXX */
|
||||
pub formats: Le64, /* 1 << VIRTIO_SND_PCM_FMT_XXX */
|
||||
pub rates: Le64, /* 1 << VIRTIO_SND_PCM_RATE_XXX */
|
||||
pub direction: u8,
|
||||
pub channels_min: u8,
|
||||
pub channels_max: u8,
|
||||
|
||||
pub padding: [u8; 5],
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundPcmInfo {}
|
||||
|
||||
/// Set selected stream parameters for the specified stream ID
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSndPcmSetParams {
|
||||
pub hdr: VirtioSoundPcmHeader,
|
||||
pub buffer_bytes: Le32,
|
||||
pub period_bytes: Le32,
|
||||
pub features: Le32, /* 1 << VIRTIO_SND_PCM_F_XXX */
|
||||
pub channels: u8,
|
||||
pub format: u8,
|
||||
pub rate: u8,
|
||||
pub padding: u8,
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSndPcmSetParams {}
|
||||
|
||||
/// PCM I/O header
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSoundPcmXfer {
|
||||
pub stream_id: Le32,
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundPcmXfer {}
|
||||
|
||||
/// PCM I/O status
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSoundPcmStatus {
|
||||
pub status: Le32,
|
||||
pub latency_bytes: Le32,
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundPcmStatus {}
|
||||
|
||||
/// channel maps response information
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioSoundChmapInfo {
|
||||
pub hdr: VirtioSoundInfo,
|
||||
pub direction: u8,
|
||||
pub channels: u8,
|
||||
pub positions: [u8; VIRTIO_SND_CHMAP_MAX_SIZE],
|
||||
}
|
||||
// SAFETY: The layout of the structure is fixed and can be initialized by
|
||||
// reading its content from byte array.
|
||||
unsafe impl ByteValued for VirtioSoundChmapInfo {}
|
||||
Loading…
Reference in New Issue
Block a user