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

ASoC: SOF: Intel/ipc4: Add support for two staged library loading #4521

Conversation

ujfalusi
Copy link
Collaborator

Hi,

It was determined that the existing library loading flow cannot follow the hardware programming sequence for the DMA, which is:
DSP side sets buffer and sets the GEN bit
Host side sets the RUN bit

With the single message the current flow is:
Host sets the RUN bit
Host sends LOAD_LIBRARY
DSP side sets buffer and sets the GEN bit

The agreed solution is that we will add a new LOAD_LIBRARY_PREPARE message and by using it in host and firmware side we can have correct programming flow:
host sends LOAD_LIBRARY_PREPARE
DSP side sets it's buffer and sets the GEN bit
Host sets the RUN bit
Host sends LOAD_LIBRARY
DSP recceives the library data.

In case the firmware does not implement this new message (returns with not supported message) then we will proceed and send only the LOAD_LIBRARY message as it was defined by legacy and to maintain backwards compatibility.

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.

a couple of cosmetic/nit-picks and a more fundamental question on ABI and definition of "legacy".

sound/soc/sof/ipc4.c Show resolved Hide resolved
@@ -108,6 +108,11 @@ enum sof_ipc4_global_msg {

/* Loads library (using Code Load or HD/A Host Output DMA) */
SOF_IPC4_GLB_LOAD_LIBRARY,
/*
* Prepare the host DMA channel for library loading, must be followed by
* a SOF_IPC4_GLB_LOAD_LIBRARY message as the library loading step
Copy link
Member

Choose a reason for hiding this comment

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

extra space after 'a'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok

include/sound/sof/ipc4/header.h Show resolved Hide resolved
include/sound/sof/ipc4/header.h Show resolved Hide resolved
* message with valid dma_id and invalid (0) lib_id
* if the firmware does not have support for the message, we will
* receive -EOPNOTSUPP. In this case we assume legacy, single step library
* loading support and proceed to send the LOAD_LIBRARY message.
Copy link
Member

Choose a reason for hiding this comment

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

this goes with my question on ABI. Do we even want to support those 'legacy' firmware and why?

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 supporting firmware which does not implement this mode of library loading can be useful and only developers will encounter them.


/*
* 1st stage: SOF_IPC4_GLB_LOAD_LIBRARY_PREPARE
* message with valid dma_id and invalid (0) lib_id
Copy link
Member

Choose a reason for hiding this comment

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

why do you even need to pass an invalid lib_id here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, we only send the dma_id.

Copy link

@lyakh lyakh left a comment

Choose a reason for hiding this comment

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

subject to addressing Pierre's comments - LGTM otherwise

@ujfalusi ujfalusi force-pushed the peter/sof/pr/two_stage_library_loading_02 branch from 9a23d47 to 6d78705 Compare August 15, 2023 08:54
@ujfalusi
Copy link
Collaborator Author

Changes since v1:

  • commit messages updated
  • removed the note about message id 25 being reserved (as we are using it)
  • clarify and cleanup the library loading flow, drop the lib_id reference from LOAD_LIBRARY_PREPARE message for example

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.

Approved but commit messages can be improved for grammar and clarity, see below.

include/sound/sof/ipc4/header.h Show resolved Hide resolved
include/sound/sof/ipc4/header.h Show resolved Hide resolved
jsarha
jsarha previously approved these changes Aug 15, 2023
Copy link

@jsarha jsarha left a comment

Choose a reason for hiding this comment

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

Code-wise I see nothing wrong. For commit messages, the message in the 3rd commit is a bit hard to follow and mostly redundant, as 4th commit message explains the same thing. Maybe remove most of the 3rd commit message, and just tell that a new message is needed. The explanation comes in the 4th message. From the 4rd I'd just drop "There is" from the beginning. These are only suggestions, so approved.

@ujfalusi ujfalusi force-pushed the peter/sof/pr/two_stage_library_loading_02 branch from 6d78705 to 3d89465 Compare August 16, 2023 12:31
@ujfalusi
Copy link
Collaborator Author

Changes since v2:

  • commit message rewritten for the new message type introduction (SOF_IPC4_GLB_LOAD_LIBRARY_PREPARE)

plbossart
plbossart previously approved these changes Aug 16, 2023
status,
(status & SOF_HDA_SD_FIFOSIZE_FIFOS_MASK),
HDA_DSP_REG_POLL_INTERVAL_US,
HDA_DSP_BASEFW_TIMEOUT_US);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ujfalusi is this just a paranoia check or is it really required to check the FIFO value?

Copy link
Member

Choose a reason for hiding this comment

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

ping @ujfalusi, if we want this in 6.6 we don't have much time left

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is paranoia check, but I feel more comfortable doing this, The firmware will set the GEN bit before it sends the reply.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, the FIFO value check? It is paranoia and also to make sure that we only set the RUN bit after the GEN was set. It should be, but I do feel that this a good practice and provides additional point if the loading fails (like the firmware have bug and not set the GEN bit and returns with success)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ping @ujfalusi, if we want this in 6.6 we don't have much time left

I missed the comment, sorry.

@plbossart plbossart requested a review from lyakh August 17, 2023 20:58
ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR,
sd_offset + SOF_HDA_ADSP_REG_SD_FIFOSIZE,
status,
(status & SOF_HDA_SD_FIFOSIZE_FIFOS_MASK),
Copy link

Choose a reason for hiding this comment

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

superfluous parentheses

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, fixing it, for some reason checkpatch was fine with it.

Copy link

Choose a reason for hiding this comment

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

oh, checkpatch is perfectly happy to swallow as many parentheses as you want to throw at it x = (((((0)))));

@ujfalusi ujfalusi dismissed stale reviews from plbossart and jsarha via b0a7d2b August 18, 2023 08:06
@ujfalusi ujfalusi force-pushed the peter/sof/pr/two_stage_library_loading_02 branch from 3d89465 to b0a7d2b Compare August 18, 2023 08:06
The status code 2 and 15 can be translated to -EOPNOTSUPP, so convert them
to a meaningful error number.

Signed-off-by: Peter Ujfalusi <[email protected]>
The FIFOS (FIFO Size) field is in bit 0-15 of the register.
Use the defined mask instead of a magic number for the FIFOS value
masking in hda_dsp_stream_hw_params().

Signed-off-by: Peter Ujfalusi <[email protected]>
On Intel platforms there is a strict order requirement for the DMA
programming:
DSP side configures the buffer and sets the GEN bit
Host side sets the RUN bit.

In order to follow this flow, a new global message type has been added to
prepare the DSP side of the DMA:

host sends LOAD_LIBRARY_PREPARE with the dma_id
DSP side sets its buffer and sets the GEN bit
Host sets the RUN bit
Host sends LOAD_LIBRARY with dma_id and lib_id
DSP receives the library data.

It is up to the platform code to use the new prepare stage message and how
to handle the reply to it from the firmware, which can indicate that the
message type is not supported/handled.
In this case the kernel should proceed to the LOAD_LIBRARY stage assuming
a single stage library loading:

host sends LOAD_LIBRARY_PREPARE with the dma_id
DSP replies that the message type is not supported/handled
Host acknowledges the return code and sets the RUN bit
Host sends LOAD_LIBRARY with dma_id and lib_id
DSP receives the library data.

Signed-off-by: Peter Ujfalusi <[email protected]>
There is a certain sequence needs to be followed when configuring the HDA
DMA in host and DSP.
The firmware provides a way to handle this two stage sequencing by
splitting the library loading into two stage:
1st stage: LOAD_LIBRARY_PREPARE message
           the lib_id is 0, used to configure the DMA on DSP side
2nd stage: LOAD_LIBRARY message
           both dma_id and lib_id is valid, used for the actual transfer of
           the library

In case a firmware without support for this two stage loading is used then
the second stage message will trigger the loading and the first stage will
return with error, which is ignored by the kernel.

Signed-off-by: Peter Ujfalusi <[email protected]>
@ujfalusi
Copy link
Collaborator Author

Changes since v3:

  • remove unneeded parenthesis in snd_sof_dsp_read_poll_timeout() call

@mengdonglin
Copy link
Collaborator

This is kernel part for loading a module library. The FW part has been merged thesofproject/sof#7986

@ujfalusi
Copy link
Collaborator Author

This is kernel part for loading a module library. The FW part has been merged thesofproject/sof#7986

@mengdonglin, that PR was the cleanup and fixes, the two staged one is not yet submitted.

@plbossart
Copy link
Member

@ranj063 can you review this one please?

@ranj063
Copy link
Collaborator

ranj063 commented Aug 21, 2023

@ujfalusi there's a genuine checkpatch warning. Maybe you can submit a fixup?

@ujfalusi
Copy link
Collaborator Author

@ujfalusi there's a genuine checkpatch warning. Maybe you can submit a fixup?

There are two warnings, one is for 'hda' (misspelled had?) the other is alignment, but that I cannot fix unless we prefer long line warning. Almost all uses of snd_sof_dsp_read_poll_timeout() are like this.

@aiChaoSONG
Copy link
Collaborator

@ujfalusi there's a genuine checkpatch warning. Maybe you can submit a fixup?

There are two warnings, one is for 'hda' (misspelled had?) the other is alignment, but that I cannot fix unless we prefer long line warning. Almost all uses of snd_sof_dsp_read_poll_timeout() are like this.

Guess what, the checkpatch issue could be fixed without the long line warning.

@plbossart plbossart merged commit 1083fe3 into thesofproject:topic/sof-dev Aug 22, 2023
@ujfalusi ujfalusi deleted the peter/sof/pr/two_stage_library_loading_02 branch November 30, 2023 06:38
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.

7 participants