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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,9 +1014,11 @@ static int dai_comp_trigger_internal(struct comp_dev *dev, int cmd)
/* only start the DAI if we are not XRUN handling */
if (dd->xrun == 0) {
/* recover valid start position */
ret = dma_stop(dd->chan->dma->z_dev, dd->chan->index);
if (ret < 0)
return ret;
if (dev->state == COMP_STATE_ACTIVE) {
ret = dma_stop(dd->chan->dma->z_dev, dd->chan->index);
if (ret < 0)
return ret;
}

/* dma_config needed after stop */
ret = dma_config(dd->chan->dma->z_dev, dd->chan->index, dd->z_config);
Expand Down Expand Up @@ -1054,12 +1056,23 @@ 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);
tmleman marked this conversation as resolved.
Show resolved Hide resolved
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

} else {
comp_warn(dev, "dma was stopped earlier");
ranj063 marked this conversation as resolved.
Show resolved Hide resolved
ret = 0;
}
#endif
break;
case COMP_TRIGGER_PAUSE:
comp_dbg(dev, "dai_comp_trigger_internal(), PAUSE");
ret = dma_suspend(dd->chan->dma->z_dev, dd->chan->index);
if (dev->state == COMP_STATE_ACTIVE) {
ret = dma_suspend(dd->chan->dma->z_dev, dd->chan->index);
} else {
comp_warn(dev, "dma was stopped earlier");
ret = 0;
}

dai_trigger_op(dd->dai, cmd, dev->direction);
break;
case COMP_TRIGGER_PRE_START:
Expand Down
14 changes: 9 additions & 5 deletions src/audio/host-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,13 @@ static int host_trigger(struct comp_dev *dev, int cmd)
break;
case COMP_TRIGGER_STOP:
case COMP_TRIGGER_XRUN:
ret = dma_stop(hd->chan->dma->z_dev, hd->chan->index);
if (ret < 0)
comp_err(dev, "host_trigger(): dma stop failed: %d",
ret);
if (dev->state == COMP_STATE_ACTIVE) {
ret = dma_stop(hd->chan->dma->z_dev, hd->chan->index);
if (ret < 0)
comp_err(dev, "host_trigger(): dma stop failed: %d",
ret);
}

break;
default:
break;
Expand Down Expand Up @@ -1048,7 +1051,8 @@ static int host_reset(struct comp_dev *dev)
comp_dbg(dev, "host_reset()");

if (hd->chan) {
dma_stop(hd->chan->dma->z_dev, hd->chan->index);
if (dev->state == COMP_STATE_ACTIVE)
ranj063 marked this conversation as resolved.
Show resolved Hide resolved
dma_stop(hd->chan->dma->z_dev, hd->chan->index);

/* remove callback */
notifier_unregister(dev, hd->chan, NOTIFIER_ID_DMA_COPY);
Expand Down
4 changes: 3 additions & 1 deletion src/ipc/ipc4/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ void dai_dma_release(struct comp_dev *dev)
* TODO: refine power management when stream is paused
*/
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
dma_stop(dd->chan->dma->z_dev, dd->chan->index);
/* if reset is after pause dma has already been stopped */
if (dev->state != COMP_STATE_PAUSED)
dma_stop(dd->chan->dma->z_dev, dd->chan->index);

/* remove callback */
notifier_unregister(dev, dd->chan, NOTIFIER_ID_DMA_COPY);
Expand Down