Skip to content

imx6ull-sdma: make BD_DONE handing optional#660

Open
xvuko wants to merge 8 commits into
masterfrom
xvuko/msh-36-sdma
Open

imx6ull-sdma: make BD_DONE handing optional#660
xvuko wants to merge 8 commits into
masterfrom
xvuko/msh-36-sdma

Conversation

@xvuko

@xvuko xvuko commented May 12, 2026

Copy link
Copy Markdown
Contributor

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the i.MX6ULL SDMA driver by introducing an 'auto BD done' configuration option, refactoring the interrupt handler for better readability, and improving the main loop's locking mechanism. It also updates the data write API for const-correctness and adds a FAQ to the documentation. Key review feedback identified a bug where the new option constant was defined as zero, making it impossible to enable. Other suggestions include adding alignment checks for memory transfers and addressing the safety of const-casting in the library implementation.

Comment thread dma/imx6ull-sdma/sdma-api.h Outdated
Comment thread dma/imx6ull-sdma/imx6ull-sdma.c
dev_ctl.mem.len = size;

return sdma_dev_ctl(s, &dev_ctl, data, size);
return sdma_dev_ctl(s, &dev_ctl, (void *)data, size);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Casting away const from the data pointer when calling sdma_dev_ctl is potentially unsafe. Although sdma_data_mem_write is a write operation (where the buffer is only read), the sdma_dev_ctl function takes a non-const void * and could potentially modify the buffer if the implementation changes or if the function is misused in other contexts. Ideally, the underlying sdma_dev_ctl API should be updated to be const-correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is required as msg_t uses non const pointer.

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.

But this data is o->data (pointer to output data). This is not how it supposed to work!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added comment for now. Doing this properly requires more changes (ie splitting devctl type) and needs to be tested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And now this comment is actually pushed to this issue

@xvuko xvuko force-pushed the xvuko/msh-36-sdma branch from b5f4e4f to 07ddaeb Compare May 12, 2026 19:03
@github-actions

github-actions Bot commented May 12, 2026

Copy link
Copy Markdown

Unit Test Results

10 860 tests  +275   10 190 ✅ +275   53m 7s ⏱️ +4s
   670 suites + 21      670 💤 ±  0 
     1 files   ±  0        0 ❌ ±  0 

Results for commit 8f35865. ± Comparison against base commit a9f6ccd.

This pull request removes 3 and adds 278 tests. Note that renamed tests count towards both.
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit
phoenix-rtos-tests/libcache/unit ‑ armv7m7-imxrt106x-evk:phoenix-rtos-tests/libcache/unit
phoenix-rtos-tests/libcache/unit ‑ armv7m7-imxrt117x-evk:phoenix-rtos-tests/libcache/unit
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_cleanCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_flushCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_read_readCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_write_readCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_write_writeCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_clean.cache_clean_addrOutOfScope
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_clean.cache_clean_addrPartiallyInScope
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_clean.cache_clean_badAddrRange
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_clean.cache_clean_lines
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_deinit.cache_deinit_initalizedCache
…

♻️ This comment has been updated with latest results.

@xvuko xvuko force-pushed the xvuko/msh-36-sdma branch from 07ddaeb to 5e02458 Compare May 13, 2026 09:21
@xvuko xvuko requested a review from anglov May 13, 2026 09:24
@xvuko xvuko marked this pull request as ready for review May 13, 2026 09:24
@xvuko xvuko force-pushed the xvuko/msh-36-sdma branch from 5e02458 to f10ba83 Compare May 13, 2026 09:26

@anglov anglov left a comment

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.

If I would nitpicking you greatly I would say that

imx6ull-sdma: remove noop write to reserved register

is indeed probably noop but register is described in docs and 1 value on each bits is quite-well defined.

It would be great if you could provide some context – why you introduce this feature, how it's supposed to use.

I think you should check your changes if not introduce any issues in DTR project.

dev_ctl.mem.len = size;

return sdma_dev_ctl(s, &dev_ctl, data, size);
return sdma_dev_ctl(s, &dev_ctl, (void *)data, size);

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.

But this data is o->data (pointer to output data). This is not how it supposed to work!

@xvuko xvuko force-pushed the xvuko/msh-36-sdma branch 2 times, most recently from fd06027 to 63d2ca3 Compare June 2, 2026 18:52
@xvuko

xvuko commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

is indeed probably noop but register is described in docs and 1 value on each bits is quite-well defined.

Added more context to commit message:

    imx6ull-sdma: remove noop write to reserved register
    
    There is no need to `DSPOVR`o register. IMX6 does not have DSP core. It
    is set to 0xffffffff after reset and there is no need for any explicit
    writes from driver. Line `DSPOVR |= 1 << channel_id` looks like it might
    do something important. It does not. It makes `sdma_init_core` harder
    to understand without any benefit.

@xvuko

xvuko commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

It would be great if you could provide some context – why you introduce this feature, how it's supposed to use.

Added more context to commit message:

    !imx6ull-sdma: make BD_DONE handing optional
    
    BD_DONE flags indicate that SDMA "owns" buffer described in BD and can
    write into it. When SDMA returns ownership to processor/driver buffer
    content should be read *before* setting BD_DONE flag. This ensures data
    integrity (no read / write collisions). This description assumes RX
    transfer, but same applies to TX with read / writes swapped.
    
    Automatic BD_DONE set can still be useful in some cases like sending
    fixed buffer repeatedaly (like read requests from ADC).
    
    Backwards incompatible.
    Use `channelCfg.options = sdma_chOption__auto_bd_done` to keep old
    behaviour.

@xvuko xvuko force-pushed the xvuko/msh-36-sdma branch from 63d2ca3 to 2b42f56 Compare June 2, 2026 19:36
xvuko added 8 commits June 9, 2026 17:44
TASK: MSH-36
SDMA commands GET_DM and SET_DM take size in 32 bit words.

TASK: MSH-36
Lock is always released inside condWait

TASK: MSH-36
There is no need to `DSPOVR`o register. IMX6 does not have DSP core. It
is set to 0xffffffff after reset and there is no need for any explicit
writes from driver. Line `DSPOVR |= 1 << channel_id` looks like it might
do something important. It does not. It makes `sdma_init_core` harder
to understand without any benefit.

TASK: MSH-36
BD_DONE flags indicate that SDMA "owns" buffer described in BD and can
write into it. When SDMA returns ownership to processor/driver buffer
content should be read *before* setting BD_DONE flag. This ensures data
integrity (no read / write collisions). This description assumes RX
transfer, but same applies to TX with read / writes swapped.

Automatic BD_DONE set can still be useful in some cases like sending
fixed buffer repeatedaly (like read requests from ADC).

Backwards incompatible.
Use `channelCfg.options = sdma_chOption__auto_bd_done` to keep old
behaviour.

TASK: MSH-36
@xvuko xvuko force-pushed the xvuko/msh-36-sdma branch from 2b42f56 to 8f35865 Compare June 9, 2026 15:45
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.

2 participants