Skip to content

dma: dma_sg: allocate on specific heap#10729

Draft
kv2019i wants to merge 1 commit intothesofproject:mainfrom
kv2019i:202604-dai-zephyr-userll
Draft

dma: dma_sg: allocate on specific heap#10729
kv2019i wants to merge 1 commit intothesofproject:mainfrom
kv2019i:202604-dai-zephyr-userll

Conversation

@kv2019i
Copy link
Copy Markdown
Collaborator

@kv2019i kv2019i commented Apr 28, 2026

Add a heap parameter to DMA scatter-gather allocation interface. This makes it possible to control how allocations are done for the DMA buffers.

Add a heap parameter to DMA scatter-gather allocation interface. This
makes it possible to control how allocations are done for the DMA
buffers.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Copilot AI review requested due to automatic review settings April 28, 2026 09:24
@kv2019i kv2019i requested a review from jsarha April 28, 2026 09:24
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented Apr 28, 2026

For context, this is part of #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 extends the DMA scatter-gather (SG) allocation/free interface to accept an explicit Zephyr heap pointer, enabling callers to control which heap backs SG element allocations.

Changes:

  • Add struct k_heap *heap parameter to dma_sg_alloc() / dma_sg_free() declarations and definitions.
  • Switch SG element allocation/free to sof_heap_alloc() / sof_heap_free() and explicitly zero-initialize the allocated element array.
  • Update all current call sites to pass NULL for the heap (default heap behavior).

Reviewed changes

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

Show a summary per file
File Description
zephyr/include/sof/lib/dma.h Updates SG API prototypes to include a heap parameter.
posix/include/sof/lib/dma.h Mirrors the SG API prototype changes for the POSIX build.
src/lib/dma.c Implements heap-aware SG allocation/free using sof_heap_alloc/free and adds explicit zeroing.
src/trace/dma-trace.c Adjusts SG free call to pass NULL heap.
src/probe/probe.c Adjusts SG alloc/free calls to pass NULL heap.
src/ipc/ipc3/host-page-table.c Adjusts SG free call to pass NULL heap on error path.
src/ipc/ipc3/handler.c Adjusts SG free call to pass NULL heap on error path.
src/audio/host-zephyr.c Adjusts SG alloc/free calls to pass NULL heap.
src/audio/host-legacy.c Adjusts SG alloc/free calls to pass NULL heap.
src/audio/dai-zephyr.c Adjusts SG alloc/free calls to pass NULL heap.
src/audio/dai-legacy.c Adjusts SG alloc/free calls to pass NULL heap.

Comment thread src/lib/dma.c
Comment thread src/lib/dma.c
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 4, 2026

@lyakh @jsarha @lgirdwood ping?

@lyakh
Copy link
Copy Markdown
Collaborator

lyakh commented May 5, 2026

@kv2019i so, now that we've merged vregions for modules - which heap would these dma_sg allocations be done on? If you meant to allocate them on module heap, then I think now you need to pass a struct mod_alloc_ctx * as a parameter instead of struct k_heap *?

@lgirdwood
Copy link
Copy Markdown
Member

lgirdwood commented May 5, 2026

@kv2019i so, now that we've merged vregions for modules - which heap would these dma_sg allocations be done on? If you meant to allocate them on module heap, then I think now you need to pass a struct mod_alloc_ctx * as a parameter instead of struct k_heap *?

@kv2019i if needed dont mind if you want to do this incrementally.

@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 5, 2026

I think @lyakh and @lgirdwood we could do this incrementally. The users of this interface (DAI and host code) is not yet converted to use vregions (e.g. create_local_elems() in host-zephyr.c). So I cannot immediately convert this PR to vregions yet.

@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 5, 2026

Moving to draft until next rebase of #10558 (to see how move to vregions changes, or does not change, this PR).

@kv2019i kv2019i marked this pull request as draft May 5, 2026 13:31
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.

4 participants