Skip to content

Conversation

@bardliao
Copy link
Collaborator

Currently, the BPT stream will not run with other streams. So there is no issue we don't mark bpt_stream->link_locked. But we will support the BRA and audio streams run simultaneously. Therefore, marking link_locked is required to prevent the link being used by different streams.

@bardliao bardliao requested a review from kv2019i July 31, 2025 07:30
@plbossart
Copy link
Member

@bardliao the design assumptions was that all the frame was allocated to BPT or audio, I don't think it's possible to mix the two, nor why we would need this capability.

@bardliao
Copy link
Collaborator Author

@plbossart The request is from Cirrus. One scenario is that one codec and one amp are on the same SDW link. We may want to write the AMP firmware while the codec is playing. @charleskeepax @stuhenderson Do you have any comment?

kv2019i
kv2019i previously approved these changes Sep 8, 2025
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.

Hmm, even if we end up not supporting concurrent use, this would seem a safe thing to align bpt assignement with the flow in hda_link_stream_assign() and mark the link as locked as done here.

@bardliao bardliao marked this pull request as ready for review September 8, 2025 12:41
return PTR_ERR(bpt_stream);
}
/* Mark the HDA stream link is used */
bpt_stream->link_locked = 1;
Copy link
Collaborator

@ranj063 ranj063 Sep 12, 2025

Choose a reason for hiding this comment

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

@bardliao IMO this may not be enough to meet the requirement for concurrent BPT and regular streams. I think we;d be oversimplifying it by assuming that the link DMA is always available when picking the host DMA channel isnt it? What if the link is already taken?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think the BPT stream will use a stream that bpt_stream->link_locked = 1. Both BTP and regular stream use hda_dsp_stream_get/put with the opened flag to manage the hdac_stream. So that BTP stream should not get a hdac_stream that is opened. But hda_link_stream_assign checked hext_stream->link_locked and that is why we need to set link_locked as regular streams.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@bardliao I think you should squash the 2 patches and do the link_locked set/clear in the stream_get/put functions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bardliao I think you should squash the 2 patches and do the link_locked set/clear in the stream_get/put functions

Updated.

ranj063
ranj063 previously approved these changes Sep 30, 2025
@bardliao bardliao requested a review from kv2019i October 1, 2025 01:43
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.

I'm afraid V2 raised some new questions, please see inline.


if (use_link_dma)
snd_hdac_ext_stream_release(link_stream, HDAC_EXT_STREAM_TYPE_LINK);

Copy link
Collaborator

Choose a reason for hiding this comment

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

And do we really need to remember to pass "use_link_dma" to put? Shouldn't this be recorded in get and we allocated a linked link dma, we release it in put?

Copy link
Collaborator

Choose a reason for hiding this comment

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

IOW, @ujfalusi is adding automatic re-coupling in #5525

Not sure how we book-keep the case where we'd have multiple link DMAs per one host DMA, but shouldn't we have some state to track which case this is so the put() can do the right thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And do we really need to remember to pass "use_link_dma" to put? Shouldn't this be recorded in get and we allocated a linked link dma, we release it in put?

I thought about that, but I can't find a place to record the link_locked is set by hda_dsp_stream_get(). That's why originally, I set link_locked and call snd_hdac_ext_stream_release in hda_sdw_bpt_dma_prepare and hda_sdw_bpt_dma_deprepare where the stream is used/released.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ack @bardliao . If you took look at the options, then I'm ok. @ujfalusi can you also take a look that this does not conflict with your thinking in #5525 ?

int ret;

hext_stream = hda_dsp_stream_get(sdev, direction, 0);
hext_stream = hda_dsp_stream_get(sdev, direction, 0, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a fan of these true/false parameters. Can we add a enum or define for this?

hext_stream = hda_dsp_stream_get(sdev, direction, 0, HDA_STREAM_USE_LINK_DMA);

is much more readable. I know we have many true/false interfaces in existing code, so if you @bardliao @ranj063 @ujfalusi are ok, I'm not going to block, but I do find these hard to read (in the calling code).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not a fan of these true/false parameters. Can we add a enum or define for this?

hext_stream = hda_dsp_stream_get(sdev, direction, 0, HDA_STREAM_USE_LINK_DMA);

is much more readable. I know we have many true/false interfaces in existing code, so if you @bardliao @ranj063 @ujfalusi are ok, I'm not going to block, but I do find these hard to read (in the calling code).

Updated

Currently, we get host and link DMA streams separately by
hda_dsp_stream_get() and hda_link_stream_assign(). However, in some
cases like SoundWire BPT, we use hda_dsp_stream_get() to get the HDA
stream and use the same HDA stream for both host and link DMAs.
Add a use_link_dma flag to handle the case.

Signed-off-by: Bard Liao <[email protected]>
int ret;

hext_stream = hda_dsp_stream_get(sdev, direction, 0);
hext_stream = hda_dsp_stream_get(sdev, direction, 0, HDA_STREAM_USE_HOST_LINK_DMA);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would you need LinkDMA for Code Loader? It only needs hostDMA.

Copy link
Collaborator Author

@bardliao bardliao Oct 20, 2025

Choose a reason for hiding this comment

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

hda_cl_prepare() is called by hda_sdw_bpt_dma_prepare(). Maybe we should reconsider my first proposal which set link_locked in hda_sdw_bpt_dma_prepare and clear it in hda_sdw_bpt_dma_deprepare c79e2c5
What do you think? @ranj063

enum sof_hda_stream_type {
HDA_STREAM_USE_HOST_DMA,
HDA_STREAM_USE_HOST_LINK_DMA,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is a bool reserve_dma_pair sort of thing at the end, no?

What would happen if BRA would use hda_link_stream_assign() to grab the Link channel or is it mandatory that we must use the host/link with the same index?

Say, you use a wrapper in BR to get the two channels, host via hda_dsp_stream_get() and link via hda_link_stream_assign()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or for BRA we need to allocate the pairs like for platforms that have the PROCEN_FMT_QUIRK set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not mandatory, but we set the same ID for host and link.

	msg.primary |=  SOF_IPC4_GLB_CHAIN_DMA_HOST_ID(dma_id);
	msg.primary |=  SOF_IPC4_GLB_CHAIN_DMA_LINK_ID(dma_id);

https://github.com/thesofproject/linux/blob/topic/sof-dev/sound/soc/sof/intel/hda-sdw-bpt.c#L73

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is a bool reserve_dma_pair sort of thing at the end, no?

To me, yes. Using enum is an ask from @kv2019i to make the code more readable.

What would happen if BRA would use hda_link_stream_assign() to grab the Link channel or is it mandatory that we must use the host/link with the same index?

Say, you use a wrapper in BR to get the two channels, host via hda_dsp_stream_get() and link via hda_link_stream_assign()

I thought about this. However, it will be more complicated. Besides, we can always use the same index for both host and link. Just have to use unused host/link.

@bardliao bardliao closed this Oct 23, 2025
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.

5 participants