Skip to content

ASoC: SOF: IPC4 message abstraction and API change - #3334

Merged
plbossart merged 6 commits into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/ipc4_msg_01
Jan 20, 2022
Merged

plbossart merged 6 commits into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/ipc4_msg_01

Conversation

@ujfalusi

Copy link
Copy Markdown
Collaborator

Hi,

Create a container struct to encompass the IPC4 message (the header and the optional data part) so that we can simplify the API and make it possible later on to have generic ops among different IPC versions.

Note: I'm not sure about the new msg_bytes/reply_bytes definition for IPC4, I felt that passing 0 as msg_bytes when there is a message (there must be always) but we don't have the optional data, strange, but it can be justified, if it is preferred.

Comment thread sound/soc/sof/ipc4.c Outdated
* The msg_total_size should be passed as msg_bytes for function expecting
* a message size and underlaying code should take this into account.
*/
sdev->ipc->max_payload_size += sizeof(struct sof_ipc4_msg);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have missed the setup of the reply placeholder, this should be added after line 227:

	ipc4_msg = msg->reply_data;
	ipc4_msg->data_ptr = msg->reply_data + sizeof(struct sof_ipc4_msg);

So that the data_ptr points to the memory right after the header.

Or I could have two separate allocations for the message struct then the data section?

@RanderWang RanderWang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Comment thread sound/soc/sof/ipc4.c Outdated
* The msg_total_size should be passed as msg_bytes for function expecting
* a message size and underlaying code should take this into account.
*/
sdev->ipc->max_payload_size += sizeof(struct sof_ipc4_msg);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I dont understand this @ujfalusi . The max payload for me refers to the MAX size of the mailbox. Why would we include the header and extension in it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was exactly my concern.
I guess I can modify things that the msg_bytes is the optional data size which goes via the mailbox, but then the msg_bytes is kind of half backed as we still have the u64 header, which is a message by itself in some cases.

@ujfalusi
ujfalusi force-pushed the peter/sof/pr/ipc4_msg_01 branch from dc6464d to 251f692 Compare December 15, 2021 12:15
@ujfalusi

Copy link
Copy Markdown
Collaborator Author

Changes since v1:

  • the size of struct sof_ipc4_msg is not counted towards the msg/reply_bytes
  • Remove the header and extension members from struct snd_sof_ipc_msg
  • Use the new ipc4 encapsulation for message reception

@ujfalusi
ujfalusi force-pushed the peter/sof/pr/ipc4_msg_01 branch from 251f692 to f03d30a Compare December 17, 2021 21:24
@ujfalusi

Copy link
Copy Markdown
Collaborator Author

Changes since v2:

  • Remove the header parameter from sof_ipc_tx_message() and derivatives
  • Remove the header and extension members from struct snd_sof_ipc_msg

@ranj063 ranj063 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ujfalusi should these patches be fixups? the ipc4 stuff is not upstream yet. Maybe thats why I am not able to appreciate why we're doing this

Comment thread sound/soc/sof/ipc4.c Outdated
static int ipc4_tx_wait_done(struct snd_sof_ipc *ipc, struct snd_sof_ipc_msg *msg,
void *reply_data)
{
struct sof_ipc4_msg *ipc4_msg = msg->reply_data;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ujfalusi I'm not able to appreciate why we need to do this. Maybe I'm missing the point. There's struct sof_ipc_msg that we use to pass the IPC message to be sent. What is the purpose of the sof_ipc4_msg? we dont have a sof_ipc3_msg similar to sof_ipc4_msg isnt it? So why is ipc4 special?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@ranj063, all ipc3 messages start with struct sof_ipc_cmd_hdr followed by the payload, if any. When we receive the reply or notification then the header is behind of the msg->reply_data.
In IPC3 we pass the whole message, including the header via mailbox.

IPC4 on the other hand is a 'split' protocol in this sense. The header is not passed via the mailbox, it is written to registers and the mailbox is only used in case there is additional data for the message.

We could do an asymmetric handling of IPC4, but I don't think it helps the reader by using the struct sof_ipc4_msg for TX and spreading out the reply, notification into struct sof_ipc_msg

Users of the IPC interface should not be using the struct sof_ipc_msg as it is internal to the IPC 'subsystem' of SOF, we should have a simple interface of "send this message and give me the reply here" and on the notification side it should be that, "here, we have received this message".
Ideally only the low level and high level should know how to deal with the pointer, in the middle layer we just pass things.
I consider the ipc4_tx_wait_done() here a low(ish) level functionality as it does error checking, but it should be possible to abstract it away to only wait w/o knowing anything about the content.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I see now.
The RX for notification is handled completely differently than the reply in IPC3. The reply is copied to reply_data while the notification is not, the IPC3 RX function itself reads the message from the mailbox (first the header only, then the whole message when it knows the size).

Hrm, It might be better to rename the reply_data and reply_size to rx_data and rx_size and use it for both reply and notifications/events.
We are serializing things, so while a reply is handled it is guarantied that a notification will not change the rx_data.

That would make it a bit more well defined and we would save on kmalloc() for notifications as a bonus?

Comment thread sound/soc/sof/sof-priv.h Resolved
@ujfalusi
ujfalusi force-pushed the peter/sof/pr/ipc4_msg_01 branch from f03d30a to ddf78b3 Compare January 3, 2022 10:21
@ujfalusi

ujfalusi commented Jan 3, 2022

Copy link
Copy Markdown
Collaborator Author

Changes since v3:

  • Move the struct sof_ipc4_msg definition to global header (include/sound/sof/ipc4/header.h) so it can be used outside of the core (not via sof-priv.h)

@ujfalusi
ujfalusi force-pushed the peter/sof/pr/ipc4_msg_01 branch from ddf78b3 to 81316e8 Compare January 5, 2022 12:48
@ujfalusi

ujfalusi commented Jan 5, 2022

Copy link
Copy Markdown
Collaborator Author

Changes since v4:

  • Fixed the tx error handling to print the tx message's primary and extension.

Comment thread sound/soc/sof/ipc4.c Resolved
Comment thread sound/soc/sof/debug.c Resolved
@ujfalusi
ujfalusi force-pushed the peter/sof/pr/ipc4_msg_01 branch from 81316e8 to 206f032 Compare January 7, 2022 15:35
@ujfalusi

ujfalusi commented Jan 7, 2022

Copy link
Copy Markdown
Collaborator Author

Changes since v5:

  • Fixed the typos in commit messages pointed out by @ranj063

ranj063
ranj063 previously approved these changes Jan 9, 2022
bardliao
bardliao previously approved these changes Jan 10, 2022

@bardliao bardliao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@ujfalusi
ujfalusi marked this pull request as ready for review January 10, 2022 07:31
RanderWang
RanderWang previously approved these changes Jan 10, 2022
kuanhsuncheng
kuanhsuncheng previously approved these changes Jan 10, 2022
@ujfalusi ujfalusi changed the title [RFC] IPC4 message abstraction and API change ASoC: SOF: IPC4 message abstraction and API change Jan 14, 2022
The message and reply size can be checked earlier to fail early in case
the requested size can not be sent due to it's length.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The sof_ipc4_tx_message (and _unlocked) does not have support for async
operations.
There is no need to allocate a buffer and copy each message to it to be
sent to the DSP, we can use the passed message data pointer directly.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The struct sof_ipc4_msg encapsulates an IPC4 message for easier handling.
In IPC4 the header (u64) is treated differently compared to IPC3.
IPC4 gives the option that the header can bypass the mailbox memory where
only the optional data part of the message is sent.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
IPC4 related code must use the struct sof_ipc4_msg to pass the message to
be sent to the firmware.
Similarly on message reception, the platform code must make sure that
the ipc4 message container is updated before calling the handler.

For message sending the msg_data is mandatory and must point to the ipc4
message container while the msg_bytes is the size of the optional data
part of the message (data_bytes == ipc4_msg->data_size).

On message reception, platform code is responsible to update the ipc4
struct's header (primary and extension) before calling the handler.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
The header parameter is not used anymore and now it can be dropped from
the parameter list of tx_message().

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Neither the header or the extension is used by the underlying code, they
can be dropped from the snd_sof_ipc_msg struct.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
@ujfalusi
ujfalusi force-pushed the peter/sof/pr/ipc4_msg_01 branch from 206f032 to 7326973 Compare January 14, 2022 07:39
Comment thread sound/soc/sof/ipc4.c
/* check for FW boot completion */
if (sdev->fw_state == SOF_FW_BOOT_IN_PROGRESS) {
err = sof_ops(sdev)->fw_ready(sdev, msg);
err = sof_ops(sdev)->fw_ready(sdev, ipc4_msg->primary);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you help to add debug log for default case to notify unsupported reply ? thanks!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right, should I add a new patch on top or a new PR? We can only print the primary and extension for now, but we should have similar logging as with IPC3.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@RanderWang, something like this?
ujfalusi@41ebbc9

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

sure

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you can create a new PR if you like

@RanderWang RanderWang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@plbossart
plbossart merged commit 4f79168 into thesofproject:topic/sof-dev Jan 20, 2022
@ujfalusi
ujfalusi deleted the peter/sof/pr/ipc4_msg_01 branch November 18, 2022 07:30
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