sound/firewire/amdtp-stream.c
Source file repositories/reference/linux-study-clean/sound/firewire/amdtp-stream.c
File Facts
- System
- Linux kernel
- Corpus path
sound/firewire/amdtp-stream.c- Extension
.c- Size
- 62477 bytes
- Lines
- 2149
- Domain
- Driver Families
- Bucket
- sound/firewire
- 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.
- 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/device.hlinux/err.hlinux/firewire.hlinux/firewire-constants.hlinux/module.hlinux/slab.hsound/pcm.hsound/pcm_params.hamdtp-stream.hamdtp-stream-trace.h
Detected Declarations
function amdtp_stream_initfunction amdtp_stream_destroyfunction apply_constraint_to_sizefunction amdtp_stream_add_pcm_hw_constraintsfunction amdtp_stream_set_parametersfunction amdtp_stream_get_max_ctx_payload_sizefunction amdtp_stream_set_parametersfunction amdtp_stream_pcm_preparefunction pool_blocking_data_blocksfunction pool_ideal_nonblocking_data_blocksfunction calculate_syt_offsetfunction pool_ideal_syt_offsetsfunction compute_syt_offsetfunction calculate_cached_cycle_countfunction cache_seqfunction pool_ideal_seq_descsfunction pool_replayed_seqfunction pool_seq_descsfunction update_pcm_pointersfunction pcm_period_workfunction queue_packetfunction queue_out_packetfunction queue_in_packetfunction generate_cip_headerfunction build_it_pkt_headerfunction check_cip_headerfunction parse_ir_ctx_headerfunction compute_ohci_iso_ctx_cycle_countfunction compute_ohci_cycle_countfunction increment_ohci_cycle_countfunction decrement_ohci_cycle_countfunction compare_ohci_cycle_countfunction compute_ohci_it_cyclefunction generate_tx_packet_descsfunction compute_sytfunction generate_rx_packet_descsfunction cancel_streamfunction compute_pcm_extra_delayfunction process_ctx_payloadsfunction process_rx_packetsfunction skip_rx_packetsfunction process_rx_packets_intermediatelyfunction process_tx_packetsfunction drop_tx_packetsfunction process_tx_packets_intermediatelyfunction drop_tx_packets_initiallyfunction list_for_each_entryfunction list_for_each_entry
Annotated Snippet
if (!cip_sfc_is_base_44100(sfc)) {
// Sample_rate / 8000 is an integer, and precomputed.
desc->data_blocks = state;
} else {
unsigned int phase = state;
/*
* This calculates the number of data blocks per packet so that
* 1) the overall rate is correct and exactly synchronized to
* the bus clock, and
* 2) packets with a rounded-up number of blocks occur as early
* as possible in the sequence (to prevent underruns of the
* device's buffer).
*/
if (sfc == CIP_SFC_44100)
/* 6 6 5 6 5 6 5 ... */
desc->data_blocks = 5 + ((phase & 1) ^ (phase == 0 || phase >= 40));
else
/* 12 11 11 11 11 ... or 23 22 22 22 22 ... */
desc->data_blocks = 11 * (sfc >> 1) + (phase == 0);
if (++phase >= (80 >> (sfc >> 1)))
phase = 0;
state = phase;
}
pos = (pos + 1) % size;
}
s->ctx_data.rx.data_block_state = state;
}
static unsigned int calculate_syt_offset(unsigned int *last_syt_offset,
unsigned int *syt_offset_state, enum cip_sfc sfc)
{
unsigned int syt_offset;
if (*last_syt_offset < TICKS_PER_CYCLE) {
if (!cip_sfc_is_base_44100(sfc))
syt_offset = *last_syt_offset + *syt_offset_state;
else {
/*
* The time, in ticks, of the n'th SYT_INTERVAL sample is:
* n * SYT_INTERVAL * 24576000 / sample_rate
* Modulo TICKS_PER_CYCLE, the difference between successive
* elements is about 1386.23. Rounding the results of this
* formula to the SYT precision results in a sequence of
* differences that begins with:
* 1386 1386 1387 1386 1386 1386 1387 1386 1386 1386 1387 ...
* This code generates _exactly_ the same sequence.
*/
unsigned int phase = *syt_offset_state;
unsigned int index = phase % 13;
syt_offset = *last_syt_offset;
syt_offset += 1386 + ((index && !(index & 3)) ||
phase == 146);
if (++phase >= 147)
phase = 0;
*syt_offset_state = phase;
}
} else
syt_offset = *last_syt_offset - TICKS_PER_CYCLE;
*last_syt_offset = syt_offset;
if (syt_offset >= TICKS_PER_CYCLE)
syt_offset = CIP_SYT_NO_INFO;
return syt_offset;
}
static void pool_ideal_syt_offsets(struct amdtp_stream *s, struct seq_desc *descs,
unsigned int size, unsigned int pos, unsigned int count)
{
const enum cip_sfc sfc = s->sfc;
unsigned int last = s->ctx_data.rx.last_syt_offset;
unsigned int state = s->ctx_data.rx.syt_offset_state;
int i;
for (i = 0; i < count; ++i) {
struct seq_desc *desc = descs + pos;
desc->syt_offset = calculate_syt_offset(&last, &state, sfc);
pos = (pos + 1) % size;
}
s->ctx_data.rx.last_syt_offset = last;
s->ctx_data.rx.syt_offset_state = state;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/firewire.h`, `linux/firewire-constants.h`, `linux/module.h`, `linux/slab.h`, `sound/pcm.h`, `sound/pcm_params.h`.
- Detected declarations: `function amdtp_stream_init`, `function amdtp_stream_destroy`, `function apply_constraint_to_size`, `function amdtp_stream_add_pcm_hw_constraints`, `function amdtp_stream_set_parameters`, `function amdtp_stream_get_max_ctx_payload_size`, `function amdtp_stream_set_parameters`, `function amdtp_stream_pcm_prepare`, `function pool_blocking_data_blocks`, `function pool_ideal_nonblocking_data_blocks`.
- Atlas domain: Driver Families / sound/firewire.
- Implementation status: integration 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.