Repository navigation
probe: IPC3 firmware probe fixes and direct host-ring extraction for i.MX8MP #11399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,8 +51,17 @@ LOG_MODULE_REGISTER(probe, CONFIG_SOF_LOG_LEVEL); | |
| #define PROBE_POINT_INVALID 0xFFFFFFFF | ||
|
|
||
| #define PROBE_BUFFER_LOCAL_SIZE 8192 | ||
| /* host buffer layout: u32 write counter in the first bytes, ring data after the header */ | ||
| #define PROBE_HOST_HDR_SIZE 4096 | ||
| #define DMA_ELEM_SIZE 32 | ||
|
|
||
| /* i.MX IPC3: the DSP writes extraction data straight into the host ring */ | ||
| #if CONFIG_IPC_MAJOR_3 && CONFIG_ZEPHYR_NATIVE_DRIVERS && CONFIG_IMX | ||
| #define PROBE_HOST_RING 1 | ||
| #else | ||
| #define PROBE_HOST_RING 0 | ||
| #endif | ||
|
|
||
| /** | ||
| * DMA buffer | ||
| */ | ||
|
|
@@ -74,6 +83,11 @@ struct probe_dma_ext { | |
| struct dma_sg_config config; /**< DMA SG config */ | ||
| struct probe_dma_buf dmapb; /**< DMA buffer pointer */ | ||
| struct dma_copy dc; /**< DMA copy */ | ||
| #if PROBE_HOST_RING | ||
| uintptr_t host_base; /**< host buffer: header + ring (IPC3) */ | ||
| uint32_t host_size; /**< host ring size in bytes (IPC3) */ | ||
| uint32_t host_wr; /**< total bytes written to host ring (IPC3) */ | ||
| #endif | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -195,13 +209,18 @@ __cold static int probe_dma_init(struct probe_dma_ext *dma, uint32_t direction) | |
| { | ||
|
ursus161 marked this conversation as resolved.
Resolved
|
||
| uint32_t addr_align; | ||
| uint32_t channel; | ||
| struct dma_config dma_cfg; | ||
| struct dma_block_config dma_block_cfg; | ||
| struct dma_config dma_cfg = {0}; | ||
| struct dma_block_config dma_block_cfg = {0}; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bugfix and should be place din a separate patch even you can send this as a separate PR so we can merge it faster.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I will send this as a separate PR. |
||
| int err = 0; | ||
|
|
||
| assert_can_be_cold(); | ||
|
|
||
| #if PROBE_HOST_RING | ||
| /* i.MX: stream_tag carries the host buffer address; use host DMA channel 0 */ | ||
| channel = 0; | ||
| #else | ||
| channel = ((union ipc4_connector_node_id)dma->stream_tag).f.v_index; | ||
| #endif | ||
|
|
||
| /* request DMA in the dir LMEM->HMEM with shared access */ | ||
| dma->dc.dmac = sof_dma_get(direction, 0, SOF_DMA_DEV_HOST, | ||
|
|
@@ -259,6 +278,10 @@ __cold static int probe_dma_init(struct probe_dma_ext *dma, uint32_t direction) | |
| case SOF_DMA_DIR_LMEM_TO_HMEM: | ||
| dma_cfg.channel_direction = MEMORY_TO_HOST; | ||
| dma_block_cfg.source_address = (uint32_t)dma->dmapb.addr; | ||
| #if PROBE_HOST_RING | ||
| /* re-pointed before every transfer, see probe_host_reconfig() */ | ||
| dma_block_cfg.dest_address = (uint32_t)(dma->host_base + PROBE_HOST_HDR_SIZE); | ||
| #endif | ||
| break; | ||
| case SOF_DMA_DIR_HMEM_TO_LMEM: | ||
| dma_cfg.channel_direction = HOST_TO_MEMORY; | ||
|
|
@@ -320,6 +343,58 @@ __cold static int probe_dma_deinit(struct probe_dma_ext *dma) | |
| return 0; | ||
| } | ||
|
|
||
| #if PROBE_HOST_RING | ||
| /** | ||
| * \brief Point the i.MX host DMA at the bytes about to be transferred. | ||
| * | ||
| * The host DMA copies the block it was last configured with, so the block | ||
| * is updated before every transfer. The transfer never has to wrap in the | ||
| * host ring: probe_task() already clamps it at the end of the local ring, | ||
| * and the host ring is a multiple of the local ring, so every host ring | ||
| * boundary falls on a local one. | ||
| * | ||
| * \param[in] dma extraction DMA. | ||
| * \param[in] bytes size of the next transfer. | ||
| * \return 0 on success, error code otherwise. | ||
| */ | ||
| static int probe_host_reconfig(struct probe_dma_ext *dma, uint32_t bytes) | ||
| { | ||
| uint32_t off = dma->host_wr % dma->host_size; | ||
| struct dma_block_config blk = { | ||
| .source_address = (uint32_t)dma->dmapb.r_ptr, | ||
| .dest_address = (uint32_t)(dma->host_base + PROBE_HOST_HDR_SIZE + off), | ||
| .block_size = bytes, | ||
| }; | ||
| struct dma_config cfg = { | ||
| .channel_direction = MEMORY_TO_HOST, | ||
| .source_data_size = sizeof(uint32_t), | ||
| .dest_data_size = sizeof(uint32_t), | ||
| .block_count = 1, | ||
| .head_block = &blk, | ||
| }; | ||
|
|
||
| return dma_config(dma->dc.dmac->z_dev, dma->dc.chan->index, &cfg); | ||
| } | ||
|
|
||
| /** | ||
| * \brief Publish the host ring write counter after a transfer. | ||
| * | ||
| * The data itself was already flushed by the host DMA, so the counter is | ||
| * only ever visible to the host once the bytes it covers are. | ||
| * | ||
| * \param[in] dma extraction DMA. | ||
| * \param[in] bytes size of the transfer just completed. | ||
| */ | ||
| static void probe_host_publish(struct probe_dma_ext *dma, uint32_t bytes) | ||
| { | ||
| /* host_wr wraps at 2^32; kernel side casts its counter to u32 before subtracting */ | ||
| dma->host_wr += bytes; | ||
| *(volatile uint32_t *)dma->host_base = dma->host_wr; | ||
| dcache_writeback_region((__sparse_force void __sparse_cache *)dma->host_base, | ||
| sizeof(uint32_t)); | ||
| } | ||
| #endif | ||
|
|
||
| /* | ||
| * \brief Probe task for extraction. | ||
| * | ||
|
|
@@ -350,24 +425,34 @@ static enum task_state probe_task(void *data) | |
| if (avail + _probe->ext_dma.dmapb.r_ptr >= _probe->ext_dma.dmapb.end_addr) | ||
| avail = _probe->ext_dma.dmapb.end_addr - _probe->ext_dma.dmapb.r_ptr; | ||
|
|
||
| if (avail > 0) | ||
| if (!avail) | ||
| return SOF_TASK_STATE_RESCHEDULE; | ||
|
|
||
| #if PROBE_HOST_RING | ||
| err = probe_host_reconfig(&_probe->ext_dma, avail); | ||
| if (err < 0) { | ||
| tr_err(&pr_tr, "host dma reconfig failed."); | ||
| return SOF_TASK_STATE_COMPLETED; | ||
| } | ||
| #endif | ||
| #if CONFIG_ZEPHYR_NATIVE_DRIVERS | ||
| err = dma_reload(_probe->ext_dma.dc.dmac->z_dev, | ||
| _probe->ext_dma.dc.chan->index, 0, 0, avail); | ||
| err = dma_reload(_probe->ext_dma.dc.dmac->z_dev, | ||
| _probe->ext_dma.dc.chan->index, 0, 0, avail); | ||
| #else | ||
| err = dma_copy_to_host_nowait(&_probe->ext_dma.dc, | ||
| &_probe->ext_dma.config, 0, | ||
| (void *)_probe->ext_dma.dmapb.r_ptr, | ||
| avail); | ||
| err = dma_copy_to_host_nowait(&_probe->ext_dma.dc, | ||
| &_probe->ext_dma.config, 0, | ||
| (void *)_probe->ext_dma.dmapb.r_ptr, | ||
| avail); | ||
| #endif | ||
| else | ||
| return SOF_TASK_STATE_RESCHEDULE; | ||
|
|
||
| if (err < 0) { | ||
| tr_err(&pr_tr, "dma_copy_to_host() failed."); | ||
| return err; | ||
| } | ||
|
|
||
| #if PROBE_HOST_RING | ||
| probe_host_publish(&_probe->ext_dma, avail); | ||
| #endif | ||
|
|
||
| /* buffer data sent, set read pointer and clear avail bytes */ | ||
| _probe->ext_dma.dmapb.r_ptr += avail; | ||
| if (_probe->ext_dma.dmapb.r_ptr >= _probe->ext_dma.dmapb.end_addr) | ||
|
|
@@ -417,6 +502,19 @@ __cold int probe_init(const struct probe_dma *probe_dma) | |
| return -EINVAL; | ||
| } | ||
|
|
||
| #if PROBE_HOST_RING | ||
| /* | ||
| * a power of two of at least the local ring size: a multiple of the | ||
| * local ring keeps transfers from wrapping in the host ring, a power | ||
| * of two keeps the write counter consistent across its 2^32 wrap | ||
| */ | ||
| if (probe_dma && (probe_dma->dma_buffer_size < PROBE_BUFFER_LOCAL_SIZE || | ||
| (probe_dma->dma_buffer_size & (probe_dma->dma_buffer_size - 1)))) { | ||
| tr_err(&pr_tr, "bad host ring size %u", probe_dma->dma_buffer_size); | ||
| return -EINVAL; | ||
| } | ||
| #endif | ||
|
|
||
| /* alloc probes main struct */ | ||
| sof_get()->probe = rzalloc(SOF_MEM_FLAG_USER, | ||
| sizeof(*_probe)); | ||
|
|
@@ -446,6 +544,12 @@ __cold int probe_init(const struct probe_dma *probe_dma) | |
|
|
||
| _probe->ext_dma.stream_tag = probe_dma->stream_tag; | ||
| _probe->ext_dma.dma_buffer_size = probe_dma->dma_buffer_size; | ||
| #if PROBE_HOST_RING | ||
| /* i.MX: stream_tag holds the physical address of the host ring buffer */ | ||
| _probe->ext_dma.host_base = probe_dma->stream_tag; | ||
| _probe->ext_dma.host_size = probe_dma->dma_buffer_size; | ||
| _probe->ext_dma.host_wr = 0; | ||
| #endif | ||
|
|
||
| err = probe_dma_init(&_probe->ext_dma, SOF_DMA_DIR_LMEM_TO_HMEM); | ||
| if (err < 0) { | ||
|
|
@@ -1249,7 +1353,7 @@ __cold int probe_point_add(uint32_t count, const struct probe_point *probe) | |
| #elif CONFIG_AMD_ACP_HOST_DMA_PROBE | ||
| dev = ipc_get_buffer_by_id(ipc_get(), buf_id->full_id); | ||
| #else | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please try to use AMD path for this? |
||
| dev = ipc_get_comp_by_id(ipc_get(), buf_id->full_id); | ||
| dev = ipc_get_comp_dev(ipc_get(), COMP_TYPE_ANY, buf_id->full_id); | ||
| #endif | ||
| /* check if buffer exists */ | ||
| if (!dev) { | ||
|
|
@@ -1512,7 +1616,7 @@ __cold int probe_point_remove(uint32_t count, const uint32_t *buffer_id) | |
| #if CONFIG_AMD_ACP_HOST_DMA_PROBE | ||
| dev = ipc_get_buffer_by_id(ipc_get(), buffer_id[i]); | ||
| #else | ||
| dev = ipc_get_comp_by_id(ipc_get(), buffer_id[i]); | ||
| dev = ipc_get_comp_dev(ipc_get(), COMP_TYPE_ANY, buffer_id[i]); | ||
| #endif | ||
| if (dev) { | ||
| struct comp_buffer *probe_buf = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the zephyr/drivers/dma have a look at dma_nxp_sof_host_dma.c. This should provide you a way to "DMA" data into RAM seen by Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, switched this to go through nxp_sof_host_dma instead of memcpy'ing myself.
Turns out the real bug was probe_dma_init() never set a dest_address (PROBE_INIT has no host addr field in IPC3), so dma_reload() had nowhere to write to. not that the driver can't reach host RAM. now the kernel passes the ring's bus addr via stream_tag and the driver gets a real destination.
Extraction now does dma_config() to point the block at the next chunk, then the same dma_reload() AMD/Intel use. old probe_host_write() + wrap logic is gone.
Heads up: the driver ignores, or looks a lot like it, reload()'s own args and just replays the last configured block, so this reconfigures every tick (same as host_copy_one_shot() already does in host-zephyr.c). could follow up with a zephyr patch to give it a real cursor so it behaves like an actual host DMA, happy to do that separately if useful.
Testing on the imx8mp-evk shortly, will report back. thanks a lot for the input.
The changes are here for testing: ursus161@d03474a