Skip to content

audio: host-zephyr: rework calls to DMA driver, remove channel pointer#10721

Open
kv2019i wants to merge 3 commits intothesofproject:mainfrom
kv2019i:202604-host-zephyr-cleanup
Open

audio: host-zephyr: rework calls to DMA driver, remove channel pointer#10721
kv2019i wants to merge 3 commits intothesofproject:mainfrom
kv2019i:202604-host-zephyr-cleanup

Conversation

@kv2019i
Copy link
Copy Markdown
Collaborator

@kv2019i kv2019i commented Apr 23, 2026

For historical reasons, host-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.

@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented Apr 23, 2026

Tested as part of bigger #10558

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 host-zephyr DMA channel handling by removing the stored DMA channel pointer and tracking only the allocated channel index, using that index for all DMA driver calls.

Changes:

  • Replace hd->chan->dma / hd->chan->index usage with hd->dma / hd->chan_index in host-zephyr DMA operations.
  • Store/initialize/reset DMA channel state via chan_index (using -1 as “not configured”).
  • Update struct host_data (Zephyr native drivers path) to include chan_index instead of a channel pointer.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/audio/host-zephyr.c Switch all DMA config/reload/start/stop/status calls to use hd->chan_index and update lifecycle checks/reset paths accordingly.
src/audio/copier/host_copier.h Adjust struct host_data layout for Zephyr native drivers to store chan_index.

Comment thread src/audio/host-zephyr.c Outdated
Comment thread src/audio/host-zephyr.c
Comment thread src/audio/host-zephyr.c
Comment thread src/audio/host-zephyr.c Outdated
Comment thread src/audio/host-zephyr.c Outdated
Comment thread src/audio/host-zephyr.c Outdated
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented Apr 24, 2026

The quickbuild fails seems to be network infra related " error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500". @lrudyX can you check?

Copy link
Copy Markdown
Collaborator Author

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

The copilot comments are valid, but they are not related to code changes in this PR.

Comment thread src/audio/host-zephyr.c Outdated
Comment thread src/audio/host-zephyr.c
Comment thread src/audio/host-zephyr.c
Comment thread src/audio/host-zephyr.c Outdated
Comment thread src/audio/host-zephyr.c Outdated
Comment thread src/audio/host-zephyr.c
comp_err(dev, "requested channel %d is busy", hda_chan);
return -ENODEV;
}
hd->chan = &hd->dma->chan[channel];
Copy link
Copy Markdown
Contributor

@wjablon1 wjablon1 Apr 24, 2026

Choose a reason for hiding this comment

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

I did not fully analyze this code but at first glance I see this risk:

The previous invalid value (hd->chan == NULL) was also the default value (zero memset) whereas the current invalid value (hd->chan_index == -1) is not the default. Did you make sure the code is secured in that regard?

Also instead of "-1" you could use some predefined error code like -ENXIO

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kv2019i resolved ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ack, should be resolved. The value is now initialized and -EINVAL is used aligned to Zephyr dma.h. Does this look better now @wjablon1 ?

Comment thread src/audio/host-zephyr.c
Comment thread src/audio/host-zephyr.c Outdated
return -ENOMEM;
}
hd->chan = NULL;
hd->chan_index = -1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Zephyr DMA API uses -EINVAL for an invalid channel, so we could follow the same convention.

@kv2019i kv2019i force-pushed the 202604-host-zephyr-cleanup branch from 3d8330c to 746f49e Compare April 27, 2026 09:35
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented Apr 27, 2026

V2 pushed:

  • address comments from @wjablon1 , make sure we initialize DMA channel as invalid
  • use -EINVAL to mark invalid channels (like used in Zephyr dma.h)
  • add a separate commit to address the invalid comp_err() messages

@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented Apr 27, 2026

Two first commits not squashed properly, will fix in V3 soon...

kv2019i added 3 commits April 27, 2026 17:46
For historical reasons, host-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>
Add code to check for a valid DMA channel in host_common_free()
and if a DMA channel is set, stop the channel and free DMA
resources.

Issue found in code review. This should not be hit in normal
use-cases, but this makes the free implementation more robust in
case of errors.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Multiple comp_err() statements refer to incorrect DMA function
call names and/or use "%u" to print integer value.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i kv2019i force-pushed the 202604-host-zephyr-cleanup branch from 746f49e to aa1838d Compare April 27, 2026 14:53
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented Apr 27, 2026

V3 pushed:

  • properly squashed the two first commits, no other changes compared to V2

Copy link
Copy Markdown
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

LGTM, just one open to align.

Comment thread src/audio/host-zephyr.c
comp_err(dev, "requested channel %d is busy", hda_chan);
return -ENODEV;
}
hd->chan = &hd->dma->chan[channel];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kv2019i resolved ?

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.

7 participants