Skip to content

Commit 7730ace

Browse files
committed
audio: host-zephyr: add HOST_DMA_IPC_POSITION_UPDATES Kconfig
Add a built option HOST_DMA_IPC_POSITION_UPDATES to control whether functionality to send IPC stream position updates is enabled or not. Most platforms provide more efficient means for host to monitor DMA state, so this code is in most cases unncessary. The current IPC sending code (from audio context) also assume kernel context, so making this functionality user-space compatible will require extra work. Enable DMA IPC position updates by default for IPC3 as the feature can be controlled by host with sof_ipc_stream_params.no_stream_position IPC interface. Disable the feature by default for IPC4, as there is no host IPC interface to control this and copier_update_params() unconditionally disables IPC updates for IPC4 now, so this code is never used. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent e3246b8 commit 7730ace

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/audio/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ config HOST_DMA_STREAM_SYNCHRONIZATION
4242
for each group, different than the default one determined by the system tick frequency.
4343
This feature will allow host lower power consumption in scenarios with deep buffering.
4444

45+
config HOST_DMA_IPC_POSITION_UPDATES
46+
bool "Support for stream position updates via IPC messages"
47+
depends on IPC_MAJOR_3
48+
default y
49+
help
50+
Support firmware functionality to report stream position updates
51+
by sending an IPC message whenever one period of audio is transferred.
52+
Most platforms provide more efficient ways to query the DMA status.
53+
4554
config COMP_CHAIN_DMA
4655
bool "Chain DMA component"
4756
depends on IPC_MAJOR_4

src/audio/copier/host_copier.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ struct host_data {
7070

7171
/* host position reporting related */
7272
uint32_t host_size; /**< Host buffer size (in bytes) */
73-
uint32_t report_pos; /**< Position in current report period */
7473
uint32_t local_pos; /**< Local position in host buffer */
7574
uint32_t host_period_bytes;
7675
uint16_t stream_tag;
@@ -106,7 +105,10 @@ struct host_data {
106105

107106
/* stream info */
108107
struct sof_ipc_stream_posn posn; /* TODO: update this */
108+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
109+
uint32_t report_pos; /**< Position in current report period */
109110
struct ipc_msg *msg; /**< host notification */
111+
#endif
110112
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
111113
bool xrun_notification_sent;
112114
#endif

src/audio/host-legacy.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t byt
227227
struct comp_buffer *sink;
228228
int ret;
229229
bool update_mailbox = false;
230+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
230231
bool send_ipc = false;
232+
#endif
231233

232234
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
233235
source = hd->dma_buffer;
@@ -272,6 +274,7 @@ void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t byt
272274
if (hd->cont_update_posn)
273275
update_mailbox = true;
274276

277+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
275278
/* Don't send stream position if no_stream_position == 1 */
276279
if (!hd->no_stream_position) {
277280
hd->report_pos += bytes;
@@ -291,13 +294,16 @@ void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t byt
291294
send_ipc = true;
292295
}
293296
}
297+
#endif
294298

295299
if (update_mailbox) {
296300
pipeline_get_timestamp(dev->pipeline, dev, &hd->posn);
297301
mailbox_stream_write(dev->pipeline->posn_offset,
298302
&hd->posn, sizeof(hd->posn));
303+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
299304
if (send_ipc)
300305
ipc_msg_send(hd->msg, &hd->posn, false);
306+
#endif
301307
}
302308
}
303309

@@ -553,12 +559,14 @@ int host_common_new(struct host_data *hd, struct comp_dev *dev,
553559

554560
ipc_build_stream_posn(&hd->posn, SOF_IPC_STREAM_POSITION, config_id);
555561

562+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
556563
hd->msg = ipc_msg_init(hd->posn.rhdr.hdr.cmd, hd->posn.rhdr.hdr.size);
557564
if (!hd->msg) {
558565
comp_err(dev, "ipc_msg_init failed");
559566
dma_put(hd->dma);
560567
return -ENOMEM;
561568
}
569+
#endif
562570
hd->chan = NULL;
563571
hd->copy_type = COMP_COPY_NORMAL;
564572

@@ -614,7 +622,9 @@ void host_common_free(struct host_data *hd)
614622

615623
dma_put(hd->dma);
616624

625+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
617626
ipc_msg_free(hd->msg);
627+
#endif
618628
dma_sg_free(NULL, &hd->config.elem_array);
619629
}
620630

@@ -952,7 +962,9 @@ void host_common_reset(struct host_data *hd, uint16_t state)
952962

953963
/* reset buffer pointers */
954964
hd->local_pos = 0;
965+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
955966
hd->report_pos = 0;
967+
#endif
956968
hd->total_data_processed = 0;
957969

958970
hd->copy_type = COMP_COPY_NORMAL;

src/audio/host-zephyr.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t byt
246246
struct comp_buffer *sink;
247247
int ret;
248248
bool update_mailbox = false;
249+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
249250
bool send_ipc = false;
251+
#endif
250252

251253
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
252254
source = hd->dma_buffer;
@@ -285,6 +287,7 @@ void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t byt
285287
if (hd->cont_update_posn)
286288
update_mailbox = true;
287289

290+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
288291
/* Don't send stream position if no_stream_position == 1 */
289292
if (!hd->no_stream_position) {
290293
hd->report_pos += bytes;
@@ -304,13 +307,16 @@ void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t byt
304307
send_ipc = true;
305308
}
306309
}
310+
#endif
307311

308312
if (update_mailbox) {
309313
pipeline_get_timestamp(dev->pipeline, dev, &hd->posn);
310314
mailbox_stream_write(dev->pipeline->posn_offset,
311315
&hd->posn, sizeof(hd->posn));
316+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
312317
if (send_ipc)
313318
ipc_msg_send(hd->msg, &hd->posn, false);
319+
#endif
314320
}
315321
}
316322

@@ -721,12 +727,14 @@ __cold int host_common_new(struct host_data *hd, struct comp_dev *dev,
721727

722728
ipc_build_stream_posn(&hd->posn, SOF_IPC_STREAM_POSITION, config_id);
723729

730+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
724731
hd->msg = ipc_msg_init(hd->posn.rhdr.hdr.cmd, sizeof(hd->posn));
725732
if (!hd->msg) {
726733
comp_err(dev, "ipc_msg_init failed");
727734
sof_dma_put(hd->dma);
728735
return -ENOMEM;
729736
}
737+
#endif
730738
hd->chan_index = -EINVAL;
731739
hd->copy_type = COMP_COPY_NORMAL;
732740

@@ -808,7 +816,9 @@ __cold void host_common_free(struct host_data *hd)
808816

809817
sof_dma_put(hd->dma);
810818

819+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
811820
ipc_msg_free(hd->msg);
821+
#endif
812822
dma_sg_free(hd->alloc_ctx.heap, &hd->config.elem_array);
813823
}
814824

@@ -1212,7 +1222,9 @@ void host_common_reset(struct host_data *hd, uint16_t state)
12121222

12131223
/* reset buffer pointers */
12141224
hd->local_pos = 0;
1225+
#if CONFIG_HOST_DMA_IPC_POSITION_UPDATES
12151226
hd->report_pos = 0;
1227+
#endif
12161228
hd->total_data_processed = 0;
12171229

12181230
hd->copy_type = COMP_COPY_NORMAL;

0 commit comments

Comments
 (0)