Skip to content

audio: dai-zephyr: rework calls to DMA driver, remove channel pointer#10767

Draft
kv2019i wants to merge 4 commits into
thesofproject:mainfrom
kv2019i:202605-dai-zephyr-chan-idx
Draft

audio: dai-zephyr: rework calls to DMA driver, remove channel pointer#10767
kv2019i wants to merge 4 commits into
thesofproject:mainfrom
kv2019i:202605-dai-zephyr-chan-idx

Conversation

@kv2019i
Copy link
Copy Markdown
Collaborator

@kv2019i kv2019i commented May 12, 2026

For historical reasons, dai-zephyr has somewhat complicated code to manage the DMA channel instance information. When a DMA channel is allocated, a pointer to the system DMA channel table is acquired and some additional information is stored per channel. This is however redundant as the only piece of information actually needed is the channel index.

Simplify the code by not storing the channel pointer anymore, but rather just store the channel index and use that in all calls to the DMA driver.

Copilot AI review requested due to automatic review settings May 12, 2026 12:48
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 12, 2026

Similar to previously done change for host-zephyr.c in #10721

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies dai-zephyr DMA channel handling by removing the stored DMA channel pointer and keeping only the DMA channel index, then updating DMA driver calls to use that index.

Changes:

  • Replaced struct dai_data::chan with chan_index and updated call sites accordingly.
  • Updated DAI DMA stop/release and position/status queries to use chan_index.
  • Removed per-channel dev_data handling associated with the removed channel pointer.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
src/ipc/ipc4/dai.c Switches IPC4 DAI DMA release/config/position code paths to use chan_index instead of a channel pointer.
src/include/sof/lib/dai-zephyr.h Replaces struct dai_data *chan with int chan_index.
src/audio/dai-zephyr.c Updates DMA config/prepare/trigger/copy/status paths to use chan_index and dd->dma directly.

Comment thread src/audio/dai-zephyr.c
Comment thread src/audio/dai-zephyr.c
Comment thread src/audio/dai-zephyr.c Outdated
Comment thread src/ipc/ipc4/dai.c
Comment thread src/ipc/ipc4/dai.c Outdated
Comment thread src/ipc/ipc4/dai.c Outdated
Comment thread src/ipc/ipc4/dai.c Outdated
@softwarecki
Copy link
Copy Markdown
Collaborator

In my opinion we should treat any negative value as "no channel". This simplifies the code compared to checking against a specific constant, makes it safer for future changes and more consistent. The channel id value comes from sof_dma_request_channel(), and code check < 0 to detect errors, so any negative value mean no assigned channel.

@lgirdwood
Copy link
Copy Markdown
Member

In my opinion we should treat any negative value as "no channel". This simplifies the code compared to checking against a specific constant, makes it safer for future changes and more consistent. The channel id value comes from sof_dma_request_channel(), and code check < 0 to detect errors, so any negative value mean no assigned channel.

Ack - and I think historically 0 is also a valid channel number used in the HW DMA specs so negative better.

Comment thread src/ipc/ipc4/dai.c Outdated
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 13, 2026

@softwarecki wrote:

In my opinion we should treat any negative value as "no channel". This simplifies the code compared to checking against a specific constant, makes it safer for future changes and more consistent. The channel id value comes from sof_dma_request_channel(), and code check < 0 to detect errors, so any negative value mean no assigned channel.

Ack, this was actually @abonislawski 's idea to use Zephyr DMA API error values directly. But makes sense to continue and check for a negative value, will change in V2.

@kv2019i kv2019i force-pushed the 202605-dai-zephyr-chan-idx branch from 97983d0 to b271352 Compare May 13, 2026 14:33
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 13, 2026

V2 pushed:

  • addressed all review comments so far
  • added commit to drop support for non-native drivers and IPC4 (no known users, pretty much everybody has moved to native drivers and those who are not, are using IPC3)
  • add a comment to align host-zephyr.c to feedback from @softwarecki

@lgirdwood
Copy link
Copy Markdown
Member

@kv2019i btw, some build errors:

modules/sof/CMakeFiles/modules_sof.dir/__w/sof/sof/sof/src/ipc/ipc3/dai.c.obj.d -o modules/sof/CMakeFiles/modules_sof.dir/__w/sof/sof/sof/src/ipc/ipc3/dai.c.obj -c /__w/sof/sof/sof/src/ipc/ipc3/dai.c
/__w/sof/sof/sof/src/ipc/ipc3/dai.c: In function 'dai_dma_release':
/__w/sof/sof/sof/src/ipc/ipc3/dai.c:314:15: error: 'struct dai_data' has no member named 'chan'
  314 |         if (dd->chan) {
      |               ^~
/__w/sof/sof/sof/src/ipc/ipc3/dai.c:316:44: error: 'struct dai_data' has no member named 'chan'
  316 |                 notifier_unregister(dev, dd->chan, NOTIFIER_ID_DMA_COPY);
      |                                            ^~
/__w/sof/sof/sof/src/ipc/ipc3/dai.c:318:39: error: 'struct dai_data' has no member named 'chan'
  318 |                 dma_release_channel(dd->chan->dma->z_dev, dd->chan->index);
      |                                       ^~
/__w/sof/sof/sof/src/ipc/ipc3/dai.c:318:61: error: 'struct dai_data' has no member named 'chan'
  318 |                 dma_release_channel(dd->chan->dma->z_dev, dd->chan->index);
      |                                                             ^~
/__w/sof/sof/sof/src/ipc/ipc3/dai.c:322:19: error: 'struct dai_data' has no member named 'chan'
  322 |                 dd->chan->dev_data = NULL;
      |                   ^~
/__w/sof/sof/sof/src/ipc/ipc3/dai.c:323:19: error: 'struct dai_data' has no member named 'chan'
  323 |                 dd->chan = NULL;
      |                   ^~
/__w/sof/sof/sof/src/ipc/ipc3/dai.c: In function 'dai_config':
/__w/sof/sof/sof/src/ipc/ipc3/dai.c:355:23: error: 'struct dai_data' has no member named 'chan'
  355 |                 if (dd->chan) {
      |                       ^~
In file included from /__w/sof/sof/zephyr/include/zephyr/logging/log.h:11,
                 from /__w/sof/sof/sof/zephyr/include/sof/trace/trace.h:10,
                 from /__w/sof/sof/sof/zephyr/include/rtos/alloc.h:12,
                 from /__w/sof/sof/sof/zephyr/include/sof/lib/dma.h:23,
                 from /__w/sof/sof/sof/src/include/sof/audio/audio_stream.h:23,
                 from /__w/sof/sof/sof/src/include/sof/audio/buffer.h:11,
                 from /__w/sof/sof/sof/src/include/sof/audio/component.h:19,
                 from /__w/sof/sof/sof/src/include/sof/audio/component_ext.h:19,
                 from /__w/sof/sof/sof/src/ipc/ipc3/dai.c:8:
/__w/sof/sof/sof/src/ipc/ipc3/dai.c:357:37: error: 'struct dai_data' has no member named 'chan'
  357 |                                   dd->chan->index);

@kv2019i kv2019i marked this pull request as draft May 13, 2026 17:36
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 13, 2026

Back to draft, this needs more work to fix IPC3 builds (dai-zephyr.c is shared and needs to work with both IPC3 and IPC4 dai code).

@kv2019i kv2019i force-pushed the 202605-dai-zephyr-chan-idx branch from b271352 to e6bc02b Compare May 15, 2026 10:44
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 15, 2026

V3 pushed:

  • Fix IPC3 builds. The IPC3 dai code has some code to interface with DMA drivers that was broken by the changes.
  • With IPC3, legacy DMA/DAI drivers are still supported, but for IPC4, native drivers are mandatory.

@kv2019i kv2019i force-pushed the 202605-dai-zephyr-chan-idx branch from e6bc02b to 39e334e Compare May 15, 2026 11:30
kv2019i added 4 commits May 15, 2026 15:49
When SOF is built in library mode, the IPC dai integration can
be left out. It's not currently needed by any library build
users (like testbench), and building the code requires either Zephyr
DAI driver, or old XTOS DAI driver definitions.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Remove old code to support IPC4 use with non-Zephyr DAI and DMA drivers.
This code was used to transition to Zephyr, but now all active users of
IPC4 have moved to native Zephyr drivers, so there are no users for this
code left.

Add a Kconfig dependency to native driver support. Alternatively IPC4
can be built with CONFIG_LIBRARY. In this case the IPC DAI integration
is not part of the library build.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
For historical reasons, dai-zephyr has somewhat complicated code to
manage the DMA channel instance information. When a DMA channel is
allocated, a pointer to the system DMA channel table is acquired and
some additional information is stored per channel. This is however
redundant as the only piece of information actually needed is the
channel index.

Simplify the code by not storing the channel pointer anymore, but rather
just store the channel index and use that in all calls to the DMA
driver.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Align host-zephyr.c with dai-zephry.c and consider any negative
value as an invalid DMA channel.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i kv2019i force-pushed the 202605-dai-zephyr-chan-idx branch from 39e334e to 315508f Compare May 15, 2026 12:50
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 15, 2026

V4 and V5 pushed:

  • This turned out to be more complicated. Some of the SOF library test targets (like testbench and SOF ALSA plugin) rely on the old DAI legacy interface to build SOF IPC4 build without depending on Zephyr. By adding new dependencies to IPC4 builds, this PR broke these test targets.
  • Fortunately the test targets do not actually need IPC DAI integration, so in V5 this is fixed by simply leaving this code out from library builds. Let's see if CI tests verify the solution (local builds already pass).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants