sound/core/pcm_lib.c
Source file repositories/reference/linux-study-clean/sound/core/pcm_lib.c
File Facts
- System
- Linux kernel
- Corpus path
sound/core/pcm_lib.c- Extension
.c- Size
- 74641 bytes
- Lines
- 2636
- Domain
- Driver Families
- Bucket
- sound/core
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/sched/signal.hlinux/time.hlinux/math64.hlinux/export.hsound/core.hsound/control.hsound/tlv.hsound/info.hsound/pcm.hsound/pcm_params.hsound/timer.hpcm_local.hpcm_trace.h
Detected Declarations
function update_silence_varsfunction snd_pcm_playback_silencefunction snd_pcm_debug_namefunction __snd_pcm_xrunfunction snd_pcm_update_statefunction update_audio_tstampfunction snd_pcm_update_hw_ptr0function snd_pcm_update_hw_ptrfunction snd_pcm_set_opsfunction sourcefunction div32function div_downfunction div_upfunction mulfunction muldiv32function statusfunction snd_interval_refine_firstfunction snd_interval_refine_lastfunction snd_interval_mulfunction snd_interval_divfunction snd_interval_muldivkfunction snd_interval_mulkdivfunction snd_interval_ratnumfunction snd_interval_ratdenfunction snd_interval_listfunction snd_interval_rangesfunction snd_interval_stepfunction snd_pcm_hw_rule_addfunction snd_pcm_hw_constraint_maskfunction snd_pcm_hw_constraint_mask64function snd_pcm_hw_constraint_integerfunction snd_pcm_hw_constraint_minmaxfunction snd_pcm_hw_rule_listfunction snd_pcm_hw_constraint_listfunction snd_pcm_hw_rule_rangesfunction snd_pcm_hw_constraint_rangesfunction snd_pcm_hw_rule_ratnumsfunction snd_pcm_hw_constraint_ratnumsfunction snd_pcm_hw_rule_ratdensfunction snd_pcm_hw_constraint_ratdensfunction snd_pcm_hw_rule_msbitsfunction bitsfunction snd_pcm_hw_rule_stepfunction snd_pcm_hw_constraint_stepfunction snd_pcm_hw_rule_pow2function snd_pcm_hw_constraint_pow2function snd_pcm_hw_rule_noresample_funcfunction snd_pcm_hw_rule_noresample
Annotated Snippet
if (new_hw_ptr == ULONG_MAX) {
/*
* Initialization, fill the whole unused buffer with silence.
*
* Usually, this is entered while stopped, before data is queued,
* so both pointers are expected to be zero.
*/
snd_pcm_sframes_t avail = runtime->control->appl_ptr - hw_ptr;
if (avail < 0)
avail += runtime->boundary;
/*
* In free-running mode, appl_ptr will be zero even while running,
* so we end up with a huge number. There is no useful way to
* handle this, so we just clear the whole buffer.
*/
runtime->silence_filled = avail > runtime->buffer_size ? 0 : avail;
runtime->silence_start = hw_ptr;
} else {
/* Silence the just played area immediately */
update_silence_vars(runtime, hw_ptr, new_hw_ptr);
}
/*
* In this mode, silence_filled actually includes the valid
* sample data from the user.
*/
frames = runtime->buffer_size - runtime->silence_filled;
}
if (snd_BUG_ON(frames > runtime->buffer_size))
return;
if (frames == 0)
return;
ofs = (runtime->silence_start + runtime->silence_filled) % runtime->buffer_size;
do {
transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames;
err = fill_silence_frames(substream, ofs, transfer);
snd_BUG_ON(err < 0);
runtime->silence_filled += transfer;
frames -= transfer;
ofs = 0;
} while (frames > 0);
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
}
#ifdef CONFIG_SND_DEBUG
void snd_pcm_debug_name(struct snd_pcm_substream *substream,
char *name, size_t len)
{
snprintf(name, len, "pcmC%dD%d%c:%d",
substream->pcm->card->number,
substream->pcm->device,
substream->stream ? 'c' : 'p',
substream->number);
}
EXPORT_SYMBOL(snd_pcm_debug_name);
#endif
#define XRUN_DEBUG_BASIC (1<<0)
#define XRUN_DEBUG_STACK (1<<1) /* dump also stack */
#define XRUN_DEBUG_JIFFIESCHECK (1<<2) /* do jiffies check */
#ifdef CONFIG_SND_PCM_XRUN_DEBUG
#define xrun_debug(substream, mask) \
((substream)->pstr->xrun_debug & (mask))
#else
#define xrun_debug(substream, mask) 0
#endif
#define dump_stack_on_xrun(substream) do { \
if (xrun_debug(substream, XRUN_DEBUG_STACK)) \
dump_stack(); \
} while (0)
/* call with stream lock held */
void __snd_pcm_xrun(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
trace_xrun(substream);
if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
struct timespec64 tstamp;
snd_pcm_gettime(runtime, &tstamp);
runtime->status->tstamp.tv_sec = tstamp.tv_sec;
runtime->status->tstamp.tv_nsec = tstamp.tv_nsec;
}
snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
if (xrun_debug(substream, XRUN_DEBUG_BASIC)) {
char name[16];
snd_pcm_debug_name(substream, name, sizeof(name));
Annotation
- Immediate include surface: `linux/slab.h`, `linux/sched/signal.h`, `linux/time.h`, `linux/math64.h`, `linux/export.h`, `sound/core.h`, `sound/control.h`, `sound/tlv.h`.
- Detected declarations: `function update_silence_vars`, `function snd_pcm_playback_silence`, `function snd_pcm_debug_name`, `function __snd_pcm_xrun`, `function snd_pcm_update_state`, `function update_audio_tstamp`, `function snd_pcm_update_hw_ptr0`, `function snd_pcm_update_hw_ptr`, `function snd_pcm_set_ops`, `function source`.
- Atlas domain: Driver Families / sound/core.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.