Skip to content

Commit c04d3f1

Browse files
ursus161lgirdwood
authored andcommitted
probe: IPC3+Zephyr: extract to a host ring through the i.MX host DMA
IPC3 PROBE_INIT carries no host buffer address: on Intel the kernel programs the destination into the HDA stream, so the firmware never needs one. On i.MX the host DMA (nxp_sof_host_dma) is configured by the firmware itself and was never given a destination, so the extraction channel had nowhere to deliver to and dma_reload() never moved any probe data. Have the kernel pass the bus address of a coherent host buffer in the PROBE_INIT stream_tag field. The buffer is a header page followed by a ring whose size is a power of two of at least the local probe ring. Before every transfer point the host DMA block at the bytes about to go out, at the offset given by the write counter, then let the common dma_reload() path copy them, exactly as on the other Zephyr-native platforms. The transfer size is already clamped at the end of the local ring and the host ring is a multiple of it, so the transfer never has to wrap in the host ring either. The host DMA reports no position, so after each transfer publish the write counter in the first word of the header page for the kernel to poll. Use channel 0 in probe_dma_init() under CONFIG_PROBE_IMX_HOST_DMA, since stream_tag carries an address there, not a channel index; every other IPC3 platform (e.g. AMD ACP, MediaTek) keeps its previous channel selection unchanged. Add the CONFIG_PROBE_IMX_HOST_DMA Kconfig option for this path and enable it, together with CONFIG_PROBE=y and CONFIG_PROBE_POINTS_MAX=16, for the i.MX8MP EVK ADSP board. Look up IPC3 probe points with ipc_get_buffer_by_id() on this path, as on AMD. Signed-off-by: Stefan Ghetu <stefan.ghetu@nxp.com>
1 parent b6830b8 commit c04d3f1

3 files changed

Lines changed: 122 additions & 12 deletions

File tree

‎app/boards/imx8mp_evk_mimx8ml8_adsp.conf‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ CONFIG_KPB_FORCE_COPY_TYPE_NORMAL=n
55
CONFIG_DMA=y
66
CONFIG_DMA_NXP_SDMA=y
77
CONFIG_DAI_NXP_MICFIL=y
8+
CONFIG_PROBE=y
9+
CONFIG_PROBE_POINTS_MAX=16
10+
CONFIG_PROBE_IMX_HOST_DMA=y
811
CONFIG_SHARED_INTERRUPTS=y
912
CONFIG_ZEPHYR_NATIVE_DRIVERS=y
1013
CONFIG_SAI_HAS_MCLK_CONFIG_OPTION=y

‎src/kernel/probe/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ config PROBE_DMA_MAX
2727
help
2828
Define maximum number of injection DMAs.
2929

30+
config PROBE_IMX_HOST_DMA
31+
bool "Extract probe data to a host ring through the i.MX host DMA"
32+
depends on PROBE && IMX && IPC_MAJOR_3 && ZEPHYR_NATIVE_DRIVERS
33+
help
34+
On i.MX IPC3 platforms the host DMA is configured by the firmware,
35+
so the kernel passes the host ring address in the PROBE_INIT
36+
stream_tag and the DSP writes extraction data directly into it.
37+
The firmware publishes a write counter in the ring header for the
38+
kernel to poll, since the host DMA reports no position.
39+
3040
endif
3141

3242
endmenu

‎src/kernel/probe/probe.c‎

Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ LOG_MODULE_REGISTER(probe, CONFIG_SOF_LOG_LEVEL);
5151
#define PROBE_POINT_INVALID 0xFFFFFFFF
5252

5353
#define PROBE_BUFFER_LOCAL_SIZE 8192
54+
/* host buffer layout: u32 write counter in the first bytes, ring data after the header */
55+
#define PROBE_HOST_HDR_SIZE 4096
5456
#define DMA_ELEM_SIZE 32
5557

5658
/**
@@ -74,6 +76,11 @@ struct probe_dma_ext {
7476
struct dma_sg_config config; /**< DMA SG config */
7577
struct probe_dma_buf dmapb; /**< DMA buffer pointer */
7678
struct dma_copy dc; /**< DMA copy */
79+
#if CONFIG_PROBE_IMX_HOST_DMA
80+
uintptr_t host_base; /**< host buffer: header + ring (IPC3) */
81+
uint32_t host_size; /**< host ring size in bytes (IPC3) */
82+
uint32_t host_wr; /**< total bytes written to host ring (IPC3) */
83+
#endif
7784
};
7885

7986
/**
@@ -201,7 +208,12 @@ __cold static int probe_dma_init(struct probe_dma_ext *dma, uint32_t direction)
201208

202209
assert_can_be_cold();
203210

211+
#if CONFIG_PROBE_IMX_HOST_DMA
212+
/* i.MX: stream_tag carries the host buffer address; use host DMA channel 0 */
213+
channel = 0;
214+
#else
204215
channel = ((union ipc4_connector_node_id)dma->stream_tag).f.v_index;
216+
#endif
205217

206218
/* request DMA in the dir LMEM->HMEM with shared access */
207219
dma->dc.dmac = sof_dma_get(direction, 0, SOF_DMA_DEV_HOST,
@@ -259,6 +271,10 @@ __cold static int probe_dma_init(struct probe_dma_ext *dma, uint32_t direction)
259271
case SOF_DMA_DIR_LMEM_TO_HMEM:
260272
dma_cfg.channel_direction = MEMORY_TO_HOST;
261273
dma_block_cfg.source_address = (uint32_t)dma->dmapb.addr;
274+
#if CONFIG_PROBE_IMX_HOST_DMA
275+
/* re-pointed before every transfer, see probe_host_reconfig() */
276+
dma_block_cfg.dest_address = (uint32_t)(dma->host_base + PROBE_HOST_HDR_SIZE);
277+
#endif
262278
break;
263279
case SOF_DMA_DIR_HMEM_TO_LMEM:
264280
dma_cfg.channel_direction = HOST_TO_MEMORY;
@@ -320,6 +336,58 @@ __cold static int probe_dma_deinit(struct probe_dma_ext *dma)
320336
return 0;
321337
}
322338

339+
#if CONFIG_PROBE_IMX_HOST_DMA
340+
/**
341+
* \brief Point the i.MX host DMA at the bytes about to be transferred.
342+
*
343+
* The host DMA copies the block it was last configured with, so the block
344+
* is updated before every transfer. The transfer never has to wrap in the
345+
* host ring: probe_task() already clamps it at the end of the local ring,
346+
* and the host ring is a multiple of the local ring, so every host ring
347+
* boundary falls on a local one.
348+
*
349+
* \param[in] dma extraction DMA.
350+
* \param[in] bytes size of the next transfer.
351+
* \return 0 on success, error code otherwise.
352+
*/
353+
static int probe_host_reconfig(struct probe_dma_ext *dma, uint32_t bytes)
354+
{
355+
uint32_t off = dma->host_wr % dma->host_size;
356+
struct dma_block_config blk = {
357+
.source_address = (uint32_t)dma->dmapb.r_ptr,
358+
.dest_address = (uint32_t)(dma->host_base + PROBE_HOST_HDR_SIZE + off),
359+
.block_size = bytes,
360+
};
361+
struct dma_config cfg = {
362+
.channel_direction = MEMORY_TO_HOST,
363+
.source_data_size = sizeof(uint32_t),
364+
.dest_data_size = sizeof(uint32_t),
365+
.block_count = 1,
366+
.head_block = &blk,
367+
};
368+
369+
return dma_config(dma->dc.dmac->z_dev, dma->dc.chan->index, &cfg);
370+
}
371+
372+
/**
373+
* \brief Publish the host ring write counter after a transfer.
374+
*
375+
* The data itself was already flushed by the host DMA, so the counter is
376+
* only ever visible to the host once the bytes it covers are.
377+
*
378+
* \param[in] dma extraction DMA.
379+
* \param[in] bytes size of the transfer just completed.
380+
*/
381+
static void probe_host_publish(struct probe_dma_ext *dma, uint32_t bytes)
382+
{
383+
/* host_wr wraps at 2^32; kernel side casts its counter to u32 before subtracting */
384+
dma->host_wr += bytes;
385+
*(volatile uint32_t *)dma->host_base = dma->host_wr;
386+
dcache_writeback_region((__sparse_force void __sparse_cache *)dma->host_base,
387+
sizeof(uint32_t));
388+
}
389+
#endif
390+
323391
/*
324392
* \brief Probe task for extraction.
325393
*
@@ -350,24 +418,34 @@ static enum task_state probe_task(void *data)
350418
if (avail + _probe->ext_dma.dmapb.r_ptr >= _probe->ext_dma.dmapb.end_addr)
351419
avail = _probe->ext_dma.dmapb.end_addr - _probe->ext_dma.dmapb.r_ptr;
352420

353-
if (avail > 0)
421+
if (!avail)
422+
return SOF_TASK_STATE_RESCHEDULE;
423+
424+
#if CONFIG_PROBE_IMX_HOST_DMA
425+
err = probe_host_reconfig(&_probe->ext_dma, avail);
426+
if (err < 0) {
427+
tr_err(&pr_tr, "host dma reconfig failed.");
428+
return SOF_TASK_STATE_COMPLETED;
429+
}
430+
#endif
354431
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
355-
err = dma_reload(_probe->ext_dma.dc.dmac->z_dev,
356-
_probe->ext_dma.dc.chan->index, 0, 0, avail);
432+
err = dma_reload(_probe->ext_dma.dc.dmac->z_dev,
433+
_probe->ext_dma.dc.chan->index, 0, 0, avail);
357434
#else
358-
err = dma_copy_to_host_nowait(&_probe->ext_dma.dc,
359-
&_probe->ext_dma.config, 0,
360-
(void *)_probe->ext_dma.dmapb.r_ptr,
361-
avail);
435+
err = dma_copy_to_host_nowait(&_probe->ext_dma.dc,
436+
&_probe->ext_dma.config, 0,
437+
(void *)_probe->ext_dma.dmapb.r_ptr,
438+
avail);
362439
#endif
363-
else
364-
return SOF_TASK_STATE_RESCHEDULE;
365-
366440
if (err < 0) {
367441
tr_err(&pr_tr, "dma_copy_to_host() failed.");
368442
return err;
369443
}
370444

445+
#if CONFIG_PROBE_IMX_HOST_DMA
446+
probe_host_publish(&_probe->ext_dma, avail);
447+
#endif
448+
371449
/* buffer data sent, set read pointer and clear avail bytes */
372450
_probe->ext_dma.dmapb.r_ptr += avail;
373451
if (_probe->ext_dma.dmapb.r_ptr >= _probe->ext_dma.dmapb.end_addr)
@@ -417,6 +495,19 @@ __cold int probe_init(const struct probe_dma *probe_dma)
417495
return -EINVAL;
418496
}
419497

498+
#if CONFIG_PROBE_IMX_HOST_DMA
499+
/*
500+
* a power of two of at least the local ring size: a multiple of the
501+
* local ring keeps transfers from wrapping in the host ring, a power
502+
* of two keeps the write counter consistent across its 2^32 wrap
503+
*/
504+
if (probe_dma && (probe_dma->dma_buffer_size < PROBE_BUFFER_LOCAL_SIZE ||
505+
(probe_dma->dma_buffer_size & (probe_dma->dma_buffer_size - 1)))) {
506+
tr_err(&pr_tr, "bad host ring size %u", probe_dma->dma_buffer_size);
507+
return -EINVAL;
508+
}
509+
#endif
510+
420511
/* alloc probes main struct */
421512
sof_get()->probe = rzalloc(SOF_MEM_FLAG_USER,
422513
sizeof(*_probe));
@@ -446,6 +537,12 @@ __cold int probe_init(const struct probe_dma *probe_dma)
446537

447538
_probe->ext_dma.stream_tag = probe_dma->stream_tag;
448539
_probe->ext_dma.dma_buffer_size = probe_dma->dma_buffer_size;
540+
#if CONFIG_PROBE_IMX_HOST_DMA
541+
/* i.MX: stream_tag holds the physical address of the host ring buffer */
542+
_probe->ext_dma.host_base = probe_dma->stream_tag;
543+
_probe->ext_dma.host_size = probe_dma->dma_buffer_size;
544+
_probe->ext_dma.host_wr = 0;
545+
#endif
449546

450547
err = probe_dma_init(&_probe->ext_dma, SOF_DMA_DIR_LMEM_TO_HMEM);
451548
if (err < 0) {
@@ -1246,7 +1343,7 @@ __cold int probe_point_add(uint32_t count, const struct probe_point *probe)
12461343
dev = ipc_get_comp_by_id(ipc_get(),
12471344
IPC4_COMP_ID(buf_id->fields.module_id,
12481345
buf_id->fields.instance_id));
1249-
#elif CONFIG_AMD_ACP_HOST_DMA_PROBE
1346+
#elif CONFIG_AMD_ACP_HOST_DMA_PROBE || CONFIG_PROBE_IMX_HOST_DMA
12501347
dev = ipc_get_buffer_by_id(ipc_get(), buf_id->full_id);
12511348
#else
12521349
dev = ipc_get_comp_by_id(ipc_get(), buf_id->full_id);
@@ -1509,7 +1606,7 @@ __cold int probe_point_remove(uint32_t count, const uint32_t *buffer_id)
15091606
}
15101607
}
15111608
#else
1512-
#if CONFIG_AMD_ACP_HOST_DMA_PROBE
1609+
#if CONFIG_AMD_ACP_HOST_DMA_PROBE || CONFIG_PROBE_IMX_HOST_DMA
15131610
dev = ipc_get_buffer_by_id(ipc_get(), buffer_id[i]);
15141611
#else
15151612
dev = ipc_get_comp_by_id(ipc_get(), buffer_id[i]);

0 commit comments

Comments
 (0)