Skip to content

Commit f9c0e38

Browse files
kv2019iujfalusi
authored andcommitted
ASoC: SOF: ipc4-pcm: fix start offset calculation for chain DMA
Assumption that chain DMA module starts the link DMA when 1ms of data is available from host is not correct. Instead the firmware chain DMA module fills the link DMA with initial buffer of zeroes and the host and link DMAs are started at the same time. This results in a small error in delay calculation. This can become a more severe problem if host DMA has delays that exceed 1ms. This results in negative delay to be calculated and bogus values reported to applications. This can confuse some applications like alsa_conformance_test. Fix the issue by correctly calculating the firmware chain DMA preamble size and initializing the start offset to this value. Fixes: a1d203d ("ASoC: SOF: ipc4-pcm: Enable delay reporting for ChainDMA streams") Signed-off-by: Kai Vehmanen <[email protected]>
1 parent aba6ee4 commit f9c0e38

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

sound/soc/sof/ipc4-pcm.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,18 +1108,24 @@ static int sof_ipc4_get_stream_start_offset(struct snd_sof_dev *sdev,
11081108
return -EINVAL;
11091109
} else if (host_copier->data.gtw_cfg.node_id == SOF_IPC4_CHAIN_DMA_NODE_ID) {
11101110
/*
1111-
* While the firmware does not supports time_info reporting for
1111+
* While the firmware does not support time_info reporting for
11121112
* streams using ChainDMA, it is granted that ChainDMA can only
11131113
* be used on Host+Link pairs where the link position is
11141114
* accessible from the host side.
11151115
*
11161116
* Enable delay calculation in case of ChainDMA via host
11171117
* accessible registers.
11181118
*
1119-
* The ChainDMA uses 2x 1ms ping-pong buffer, dai side starts
1120-
* when 1ms data is available
1119+
* The ChainDMA prefills the link DMA with a preamble
1120+
* of zero samples. Set the stream start offset based
1121+
* on size of the preamble (driver provided fifo size
1122+
* multiplied by 2.5). We add 1ms of margin as the FW
1123+
* will align the buffer size to DMA hardware
1124+
* alignment that is not known to host.
11211125
*/
1122-
time_info->stream_start_offset = substream->runtime->rate / MSEC_PER_SEC;
1126+
int pre_ms = SOF_IPC4_CHAIN_DMA_BUF_SIZE_MS * 5 / 2 + 1;
1127+
1128+
time_info->stream_start_offset = pre_ms * substream->runtime->rate / MSEC_PER_SEC;
11231129
goto out;
11241130
}
11251131

sound/soc/sof/ipc4-topology.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ MODULE_PARM_DESC(ipc4_ignore_cpc,
3333

3434
#define SOF_IPC4_GAIN_PARAM_ID 0
3535
#define SOF_IPC4_TPLG_ABI_SIZE 6
36-
#define SOF_IPC4_CHAIN_DMA_BUF_SIZE_MS 2
3736

3837
static DEFINE_IDA(alh_group_ida);
3938
static DEFINE_IDA(pipeline_ida);

sound/soc/sof/ipc4-topology.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ struct sof_ipc4_dma_stream_ch_map {
263263
#define SOF_IPC4_DMA_METHOD_HDA 1
264264
#define SOF_IPC4_DMA_METHOD_GPDMA 2 /* defined for consistency but not used */
265265

266+
#define SOF_IPC4_CHAIN_DMA_BUF_SIZE_MS 2
267+
266268
/**
267269
* struct sof_ipc4_dma_config: DMA configuration
268270
* @dma_method: HDAudio or GPDMA

0 commit comments

Comments
 (0)