sound/virtio/virtio_pcm_ops.c
Source file repositories/reference/linux-study-clean/sound/virtio/virtio_pcm_ops.c
File Facts
- System
- Linux kernel
- Corpus path
sound/virtio/virtio_pcm_ops.c- Extension
.c- Size
- 15666 bytes
- Lines
- 527
- Domain
- Driver Families
- Bucket
- sound/virtio
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sound/pcm_params.hvirtio_card.h
Detected Declarations
struct virtsnd_a2v_formatstruct virtsnd_a2v_ratefunction virtsnd_pcm_openfunction virtsnd_pcm_closefunction virtsnd_pcm_dev_set_paramsfunction virtsnd_pcm_hw_paramsfunction virtsnd_pcm_hw_freefunction virtsnd_pcm_preparefunction virtsnd_pcm_triggerfunction scoped_guardfunction scoped_guardfunction virtsnd_pcm_sync_stopfunction virtsnd_pcm_pb_pointerfunction virtsnd_pcm_cp_pointerfunction virtsnd_pcm_trans_copyfunction virtsnd_pcm_pb_ackfunction virtsnd_pcm_cp_ack
Annotated Snippet
struct virtsnd_a2v_format {
snd_pcm_format_t alsa_bit;
unsigned int vio_bit;
};
static const struct virtsnd_a2v_format g_a2v_format_map[] = {
{ SNDRV_PCM_FORMAT_IMA_ADPCM, VIRTIO_SND_PCM_FMT_IMA_ADPCM },
{ SNDRV_PCM_FORMAT_MU_LAW, VIRTIO_SND_PCM_FMT_MU_LAW },
{ SNDRV_PCM_FORMAT_A_LAW, VIRTIO_SND_PCM_FMT_A_LAW },
{ SNDRV_PCM_FORMAT_S8, VIRTIO_SND_PCM_FMT_S8 },
{ SNDRV_PCM_FORMAT_U8, VIRTIO_SND_PCM_FMT_U8 },
{ SNDRV_PCM_FORMAT_S16_LE, VIRTIO_SND_PCM_FMT_S16 },
{ SNDRV_PCM_FORMAT_U16_LE, VIRTIO_SND_PCM_FMT_U16 },
{ SNDRV_PCM_FORMAT_S18_3LE, VIRTIO_SND_PCM_FMT_S18_3 },
{ SNDRV_PCM_FORMAT_U18_3LE, VIRTIO_SND_PCM_FMT_U18_3 },
{ SNDRV_PCM_FORMAT_S20_3LE, VIRTIO_SND_PCM_FMT_S20_3 },
{ SNDRV_PCM_FORMAT_U20_3LE, VIRTIO_SND_PCM_FMT_U20_3 },
{ SNDRV_PCM_FORMAT_S24_3LE, VIRTIO_SND_PCM_FMT_S24_3 },
{ SNDRV_PCM_FORMAT_U24_3LE, VIRTIO_SND_PCM_FMT_U24_3 },
{ SNDRV_PCM_FORMAT_S20_LE, VIRTIO_SND_PCM_FMT_S20 },
{ SNDRV_PCM_FORMAT_U20_LE, VIRTIO_SND_PCM_FMT_U20 },
{ SNDRV_PCM_FORMAT_S24_LE, VIRTIO_SND_PCM_FMT_S24 },
{ SNDRV_PCM_FORMAT_U24_LE, VIRTIO_SND_PCM_FMT_U24 },
{ SNDRV_PCM_FORMAT_S32_LE, VIRTIO_SND_PCM_FMT_S32 },
{ SNDRV_PCM_FORMAT_U32_LE, VIRTIO_SND_PCM_FMT_U32 },
{ SNDRV_PCM_FORMAT_FLOAT_LE, VIRTIO_SND_PCM_FMT_FLOAT },
{ SNDRV_PCM_FORMAT_FLOAT64_LE, VIRTIO_SND_PCM_FMT_FLOAT64 },
{ SNDRV_PCM_FORMAT_DSD_U8, VIRTIO_SND_PCM_FMT_DSD_U8 },
{ SNDRV_PCM_FORMAT_DSD_U16_LE, VIRTIO_SND_PCM_FMT_DSD_U16 },
{ SNDRV_PCM_FORMAT_DSD_U32_LE, VIRTIO_SND_PCM_FMT_DSD_U32 },
{ SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE,
VIRTIO_SND_PCM_FMT_IEC958_SUBFRAME }
};
/* Map for converting ALSA frame rate to VirtIO frame rate. */
struct virtsnd_a2v_rate {
unsigned int rate;
unsigned int vio_bit;
};
static const struct virtsnd_a2v_rate g_a2v_rate_map[] = {
{ 5512, VIRTIO_SND_PCM_RATE_5512 },
{ 8000, VIRTIO_SND_PCM_RATE_8000 },
{ 11025, VIRTIO_SND_PCM_RATE_11025 },
{ 16000, VIRTIO_SND_PCM_RATE_16000 },
{ 22050, VIRTIO_SND_PCM_RATE_22050 },
{ 32000, VIRTIO_SND_PCM_RATE_32000 },
{ 44100, VIRTIO_SND_PCM_RATE_44100 },
{ 48000, VIRTIO_SND_PCM_RATE_48000 },
{ 64000, VIRTIO_SND_PCM_RATE_64000 },
{ 88200, VIRTIO_SND_PCM_RATE_88200 },
{ 96000, VIRTIO_SND_PCM_RATE_96000 },
{ 176400, VIRTIO_SND_PCM_RATE_176400 },
{ 192000, VIRTIO_SND_PCM_RATE_192000 },
{ 384000, VIRTIO_SND_PCM_RATE_384000 }
};
static int virtsnd_pcm_sync_stop(struct snd_pcm_substream *substream);
/**
* virtsnd_pcm_open() - Open the PCM substream.
* @substream: Kernel ALSA substream.
*
* Context: Process context.
* Return: 0 on success, -errno on failure.
*/
static int virtsnd_pcm_open(struct snd_pcm_substream *substream)
{
struct virtio_pcm *vpcm = snd_pcm_substream_chip(substream);
struct virtio_pcm_stream *vs = &vpcm->streams[substream->stream];
struct virtio_pcm_substream *vss = vs->substreams[substream->number];
substream->runtime->hw = vss->hw;
substream->private_data = vss;
snd_pcm_hw_constraint_integer(substream->runtime,
SNDRV_PCM_HW_PARAM_PERIODS);
vss->stopped = !!virtsnd_pcm_msg_pending_num(vss);
vss->suspended = false;
/*
* If the substream has already been used, then the I/O queue may be in
* an invalid state. Just in case, we do a check and try to return the
* queue to its original state, if necessary.
*/
return virtsnd_pcm_sync_stop(substream);
}
/**
Annotation
- Immediate include surface: `sound/pcm_params.h`, `virtio_card.h`.
- Detected declarations: `struct virtsnd_a2v_format`, `struct virtsnd_a2v_rate`, `function virtsnd_pcm_open`, `function virtsnd_pcm_close`, `function virtsnd_pcm_dev_set_params`, `function virtsnd_pcm_hw_params`, `function virtsnd_pcm_hw_free`, `function virtsnd_pcm_prepare`, `function virtsnd_pcm_trigger`, `function scoped_guard`.
- Atlas domain: Driver Families / sound/virtio.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.