Skip to content

SDMA: Fix sound issues caused by SDMA driver #90330

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

Merged
merged 2 commits into from
May 28, 2025

Conversation

dbaluta
Copy link
Collaborator

@dbaluta dbaluta commented May 22, 2025

This patch series:

  • introduces sdma channel states in order to prevent invalid state transitions
  • adds a fix for pause/resume sound issue because computation for total buffer length was wrong.
  • adds a fix for a sound issue caused by a race when updating buffer status

@dbaluta
Copy link
Collaborator Author

dbaluta commented May 23, 2025

@LaurentiuM1234 @iuliana-prodan please review.

iuliana-prodan
iuliana-prodan previously approved these changes May 23, 2025
@dbaluta
Copy link
Collaborator Author

dbaluta commented May 26, 2025

Removed unused states and remove _func_ as per @LaurentiuM1234 review.

LaurentiuM1234
LaurentiuM1234 previously approved these changes May 26, 2025
iuliana-prodan
iuliana-prodan previously approved these changes May 26, 2025
@dbaluta dbaluta dismissed stale reviews from iuliana-prodan and LaurentiuM1234 via 6beedc6 May 27, 2025 10:42
@dbaluta dbaluta changed the title SDMA: Fix sound issues after a pause/resume operation SDMA: Fix sound issues caused by SDMA driver May 27, 2025
iuliana-prodan
iuliana-prodan previously approved these changes May 27, 2025
@@ -347,8 +363,15 @@ static int dma_nxp_sdma_start(const struct device *dev, uint32_t channel)

chan_data = &dev_data->chan[channel];

if (chan_data->state != SDMA_CHAN_STATE_STOPPED &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

repeated start is allowable as is resume from start, but in both cases should likely be a a do nothing request, please make sure that the following bits make sense in that scenario, this seems like it would be -EINVAL which isn't quite matching the expected state machine

https://docs.zephyrproject.org/latest/hardware/peripherals/dma.html#channel-state-machine-expectations

Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

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

Er meant to request changes, the state machine doesn't quite match the documented expectations

dbaluta added 2 commits May 28, 2025 17:55
Each time we configure an SDMA channel we also compute the total
allocated DMA buffer length but we assume is initialized with zero.

This is true each time a channel is requested. But if there are
multiple calls to configure without releasing the channel the buffer
length is not correctly computed.

So, we need to initialize it with zero each time we reconfigure the dma
channel.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
DMA channel stats like pending_length or free is not protected
and can be modified in parallel by a consumer and a producer.

This can result in non-atomic updates which in turn will result
in using stale data.

Fix this by making regions of code accessing dma stats atomic.

Fixes: e94c86f ("drivers: dma: Add initial support for NXP SDMA")
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
@dbaluta
Copy link
Collaborator Author

dbaluta commented May 28, 2025

@teburd I removed the patch that handles the states for now. Lets merge the 2 bugfixes. Will need to study more the DMA state changes diagram.

In the DMA state diagram looks like you cannot call directly dma_stop() while in RUNNING state which is odd.

I will come back the states when implementing PM support for SDMA driver.

image

Copy link

@teburd
Copy link
Collaborator

teburd commented May 28, 2025

@teburd I removed the patch that handles the states for now. Lets merge the 2 bugfixes. Will need to study more the DMA state changes diagram.

In the DMA state diagram looks like you cannot call directly dma_stop() while in RUNNING state which is odd.

I will come back the states when implementing PM support for SDMA driver.

image

It's there, but the diagram is a bit dense for sure. dma_stop() is allowable at any time and will take the state back to a configured state (once configured the dma channel is always configured to the last known configuration is the thinking...)

@kartben kartben merged commit 85b6ff0 into zephyrproject-rtos:main May 28, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DMA Direct Memory Access platform: NXP Drivers NXP Semiconductors, drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants