STRUCT VIRTIO_PCM_SUBSTREAM(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– struct virtio_pcm_substream(9) πŸ’–

okay so real quick before we dive in: this is a page from the Kernel API Manual and it's all about struct virtio_pcm_substream β€” yes bestie, the VirtIO PCM substream itself, the main character of the sound subsystem. buckle up πŸŽ€


✨ NAME ✨

struct virtio_pcm_substream β€” VirtIO PCM substream. that's it, that's the vibe. πŸ’…


🌸 SYNOPSIS 🌸

here's the whole struct, copied exactly because we do not paraphrase code in this house 🫢

struct virtio_pcm_substream {
    struct virtio_snd *snd;
    u32 nid;
    u32 sid;
    u32 direction;
    u32 features;
    struct snd_pcm_substream *substream;
    struct snd_pcm_indirect pcm_indirect;
    struct snd_pcm_hardware hw;
    struct work_struct elapsed_period;
    spinlock_t lock;
    size_t buffer_bytes;
    size_t hw_ptr;
    bool xfer_enabled;
    bool xfer_xrun;
    bool stopped;
    bool suspended;
    struct virtio_pcm_msg **msgs;
    unsigned int nmsgs;
    unsigned int msg_count;
    wait_queue_head_t msg_empty;
 };

πŸ’… Members πŸ’…

every single field, no skips, no cap. let's go field by field πŸ”₯

  • snd β€” the VirtIO sound device. the whole reason we're here tbh πŸ‘‘
  • nid β€” function group node identifier.
  • sid β€” stream identifier.
  • direction β€” which way the stream data flows, (SNDRV_PCM_STREAM_XXX). pick a lane bestie πŸ¦‹
  • features β€” the stream's VirtIO feature bit map, written as (1 << VIRTIO_SND_PCM_F_XXX).
  • substream β€” the kernel ALSA substream. iconic struct adjacent ✨
  • pcm_indirect β€” the kernel indirect pcm structure.
  • hw β€” the kernel ALSA substream hardware descriptor.
  • elapsed_period β€” kernel work that handles the elapsed period state. lowkey busy little worker bee 🐝
  • lock β€” spinlock that protects fields shared by interrupt handlers and substream operators. very much the bouncer at the club πŸšͺπŸ’€
  • buffer_bytes β€” current buffer size in bytes.
  • hw_ptr β€” substream hardware pointer value in bytes, and its range is literally [0 ... buffer_bytes) β€” note that the top end is exclusive, so don't come for me 🌈
  • xfer_enabled β€” data transfer state (0 - off, 1 - on).
  • xfer_xrun β€” data underflow/overflow state (0 - no xrun, 1 - xrun). if this is 1 we're having a bad time 😭
  • stopped β€” True if the substream is stopped and must be released on the device side.
  • suspended β€” True if the substream is suspended and must be reconfigured on the device side at resume.
  • msgs β€” allocated I/O messages.
  • nmsgs β€” number of allocated I/O messages.
  • msg_count β€” number of pending I/O messages in the virtqueue.
  • msg_empty β€” the thing that notifies when msg_count is zero. the "we're empty, come thru" signal 🫢

⭐ SEE ALSO ⭐

go read these next, iykyk:

  • Kernel file ./sound/virtio/virtio_pcm.h
  • struct virtio_pcm_stream(9)
  • struct virtio_pcm(9)

ok that's the whole page, every field accounted for, nothing dropped πŸ’– now go make some sound drivers slay πŸ’…

and finally, mwah, this little writeup lives in ./sound/virtio and it's dated October 2026 β€” signing off, struct virtio_pcm_substream(9), no notes, periodt πŸŽ€βœ¨

πŸ“¦ where this page comes from