Skip to content
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

audio: dai-zephyr/host-zephyr: stop dma only once #6849

Conversation

tmleman
Copy link
Contributor

@tmleman tmleman commented Dec 19, 2022

Until now, one dma channel could be stopped multiple times without any problems. From commit af6d827b64 on zephyr it is required that the start and stop calls be perfectly balanced.

Zephyr device power manager stores an internal counter. Counter is incremented if device is used and decremented on device release. In this case when we call dma_start() and dma_stop().

If dma_stop() is called more times than dma_start() power manager will reaport a error -EALREADY.

Signed-off-by: Tomasz Leman tomasz.m.leman@intel.com

src/audio/dai-zephyr.c Show resolved Hide resolved
src/audio/dai-zephyr.c Show resolved Hide resolved
src/audio/host-zephyr.c Show resolved Hide resolved
Copy link
Collaborator

@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.

Thanks @tmleman ! I bit reluctant approval on this one. I think we have to make this change and I couldn't figure out a better way. Still, this seems to add brittleness that might bite us later. If anyone has better suggestions, please chime in.

@@ -1054,7 +1054,12 @@ static int dai_comp_trigger_internal(struct comp_dev *dev, int cmd)
dai_trigger_op(dd->dai, cmd, dev->direction);
#else
dai_trigger_op(dd->dai, cmd, dev->direction);
ret = dma_stop(dd->chan->dma->z_dev, dd->chan->index);
if (dev->state == COMP_STATE_ACTIVE) {
ret = dma_stop(dd->chan->dma->z_dev, dd->chan->index);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we have to do this now. I'm a bit worried about coupling device state and DMA state this way. This opens a problem if some state is set to not ACTIVE in some other piece of code. Then dma_stop() is never called. Probably this is ok now, but it's actually pretty hard to verify this is the case by reading current dai-zephyr.c code.

OTOH, it seems there are no calls to get dma channel status with the public API. Right @teburd @juimonen ? dma_get_status() does not seem fit to gate calls to dma_stop().

Copy link
Member

Choose a reason for hiding this comment

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

This will work but the best way would be to balance this in zephyr driver, in gpdma we already have channel internal state so calling dma_stop several times will not result in unbalanced pm state.

	/* Validate the channel state */
	if (chan_data->state != DW_DMA_ACTIVE &&
	    chan_data->state != DW_DMA_SUSPENDED) {
		ret = -EINVAL;
		goto out;
	}

but there is no such internal state check in HDA zephyr driver so we need to take care of this in SOF (this PR) or track device state in Zephyr (HDA driver)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@abonislawski But as SOF code should work with any Zephyr driver, just fixing HDA is not enough, we'd need to have this as a guarantee at Zephyr dma.h level.

Copy link
Member

@abonislawski abonislawski Dec 20, 2022

Choose a reason for hiding this comment

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

at dma.h level we can only expose current state

@tmleman tmleman force-pushed the topic/upstream/pr/zephyr/pm/dma/start_stop_balance branch 2 times, most recently from 7d71a9f to 214fdec Compare December 19, 2022 20:01
@tmleman tmleman changed the title zephyr: dma: stop dma only once audio: dai-zephyr/host-zephyr: stop dma only once Dec 20, 2022
@tmleman tmleman force-pushed the topic/upstream/pr/zephyr/pm/dma/start_stop_balance branch from 214fdec to 7029d46 Compare December 20, 2022 08:43
@kv2019i
Copy link
Collaborator

kv2019i commented Dec 20, 2022

@abonislawski Ok to merge this? We can't proceed with #6828 without this....

Until now, one dma channel could be stopped multiple times without any
problems. From commit af6d827b64 on zephyr it is required that the start
and stop calls be perfectly balanced.

Zephyr device power manager stores an internal counter. Counter is
incremented if device is used and decremented on device release. In this
case when we call dma_start() and dma_stop().

If dma_stop() is called more times than dma_start() power manager will
reaport a error -EALREADY.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
@tmleman tmleman force-pushed the topic/upstream/pr/zephyr/pm/dma/start_stop_balance branch from 7029d46 to e6489e9 Compare December 20, 2022 13:34
@tmleman
Copy link
Contributor Author

tmleman commented Dec 20, 2022

@kv2019i @abonislawski @ranj063 I had to make additional changes, I encourage you to take a look again.

Here you can check how it behave with updated zephyr kernel #6853

@abonislawski
Copy link
Member

@abonislawski Ok to merge this? We can't proceed with #6828 without this....

Im ok but please wait for CI

@lgirdwood lgirdwood merged commit fa0456e into thesofproject:main Dec 21, 2022
@tmleman tmleman deleted the topic/upstream/pr/zephyr/pm/dma/start_stop_balance branch May 23, 2024 11:18
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.

6 participants