Skip to content

soundwire/ASoC: add fake BRA frame to align Intel DMA buffer size#5512

Merged
bardliao merged 7 commits intothesofproject:topic/sof-devfrom
bardliao:fix_bra_buf_alignment
Sep 23, 2025
Merged

soundwire/ASoC: add fake BRA frame to align Intel DMA buffer size#5512
bardliao merged 7 commits intothesofproject:topic/sof-devfrom
bardliao:fix_bra_buf_alignment

Conversation

@bardliao
Copy link
Collaborator

There is a constraint on Intel DMA buffer size that needs to be a multiple of data block size. This series adds some fake BRA frames to add some extra buffer size to meet the constraint .

The existing code uses i as the frame index which is 0 based. And
"bad frame %d/%d", i, num_frames where num_frames is 1 based. Change the
frame index to i + 1 to align with num_frames and more readable.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
DP0 is only for BPT stream. We should not compute and update the port
params of the normal audio streams.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Copy link
Member

@plbossart plbossart left a comment

Choose a reason for hiding this comment

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

Interesting that there are DMA restrictions, they were not known to me :-)

}

/* Add fack frame */
header[0] &= ~GENMASK(7, 6); /* Mark inactive to the fack frame */
Copy link
Member

Choose a reason for hiding this comment

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

you should explain what a 'fake frame' is, looks like you are using a flag in the BPT header.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently, I just make it inactive. Hope it is good enough for the codec to ignore the frame.

Copy link
Member

Choose a reason for hiding this comment

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

suggested edit: change comment to say "set inactive flag in BPT/BRA frame header".

* Add at most 3 fake frames for read command to make the pdi0_buffer_size a
* mutiple of rx alignment and pdi1_buffer_size a mutiple of TX_BUF_ALIGNMENT.
*/
for (i = 1; i < data_per_frame * 3; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

this looks suspect, looks like you are mixing frame counter and data counter. You may want to use a better index name than 'i'...

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 is the fake data size and I need to set a maximum number which is currently 3 frames. But I am not quite sure if at most 3 fake frames is reasonable or not.

Copy link
Member

Choose a reason for hiding this comment

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

looks like you'd need something like a LCM to find out how many invalid/inactive BRA/BTP frames to add. An iterative loop could fail to find the right amount, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it would be better if I calculate the required frames instead of finding it with a loop.

data_per_frame will be used for preparing the TX buffer and we may add
some fake frames to ensure the data in the buffer will be flushed.
So that it should indicate the the frame capability even if the required
data bytes are less than the frame capability.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Currently, we calculate the required bandwidth after the PDI buffer size
is calculated. However as we need to add some fake frame to align the
data block size, the final PDI size and the frame number will change.
Besides, we need the required bandwidth to decide the DMA channel number
and the channel number will be used to calculate the data block size.
Therefore, we calculate the required bandwidth and export a helper for
the caller to get the required bandwidth.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
@bardliao bardliao force-pushed the fix_bra_buf_alignment branch from 8e3a8f0 to e720e51 Compare September 3, 2025 08:00
@bardliao bardliao force-pushed the fix_bra_buf_alignment branch from e720e51 to 97fd645 Compare September 11, 2025 05:10
The dma buffer need to be a multiple of data block size and
the fifo size. Export a function to return the LCM of data
block size and the fifo size.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
…e_read_dma_buffer

We may need to add few fake frames to fit the aligned read dma buffer
size. Add a fake_size parameter to allow the caller to set the fake data
size.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Intel DMA buffer size need to be a mutiple of data block size.
Find the minimal fake data size and extra buffer size to meet the
requirement.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
@bardliao bardliao force-pushed the fix_bra_buf_alignment branch from 97fd645 to 8707df5 Compare September 11, 2025 06:06
@bardliao
Copy link
Collaborator Author

@plbossart Are you good with this PR?

Copy link

@shumingfan shumingfan left a comment

Choose a reason for hiding this comment

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

Tested-by: Shuming Fan shumingf@realtek.com

@bardliao
Copy link
Collaborator Author

SOFCI TEST

@bardliao bardliao merged commit 57782be into thesofproject:topic/sof-dev Sep 23, 2025
7 of 16 checks passed
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.

4 participants