Skip to content
Closed
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
20 changes: 20 additions & 0 deletions src/drivers/intel/cavs/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ DECLARE_SOF_UUID("ipc-task", ipc_task_uuid, 0x8fa1d42f, 0xbc6f, 0x464b,

/* No private data for IPC */


#if CONFIG_IPC_MAJOR_4
#if CAVS_VERSION < CAVS_VERSION_1_8
#error "Invalid configuration for IPC4."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you sure about this? If yes, then it should be a separate patch deprecating CAVS_VERSION_1_5 ?
In current code we only have checks:

#if CAVS_VERSION == CAVS_VERSION_1_5
...
#else
...
#endif 

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.

Probably not, if this approach is ok, maybe we need to keep the 1.5 support around for IPC4.

#endif
#define IPC4_EARLY_ACK 1 /* ack with DONE immediately */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Basically with this you made sure that IPC4_EARLY_ACK is only defined in case CONFIG_IPC_MAJOR_4 and when CONFIG_IPC_MAJOR_4 is set the IPC4_EARLY_ACK is also. You can just use the CONFIG_IPC_MAJOR_4 in place of IPC4_EARLY_ACK

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.

True, but I kind of prefer to have more meaning in the ifdefs. It makes the code body more readable. Well, avoiding ifdefs to begin with would be even better, but if you have to do it, having some semantics seems helpful. But yeah, style issue.

#endif


#if CONFIG_DEBUG_IPC_COUNTERS
static inline void increment_ipc_received_counter(void)
{
Expand Down Expand Up @@ -185,6 +194,15 @@ enum task_state ipc_platform_do_cmd(struct ipc *ipc)
hdr = mailbox_validate();
#endif

#ifdef IPC4_EARLY_ACK
/*
* notify host that we have received the message and
* do this before we send the response
*/
ipc_write(IPC_DIPCTDR, ipc_read(IPC_DIPCTDR) | IPC_DIPCTDR_BUSY);
ipc_write(IPC_DIPCTDA, ipc_read(IPC_DIPCTDA) | IPC_DIPCTDA_DONE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to cAVS 2.5 HW Arch Spec, IPC flow should be implemented as follows:

  1. DSP receives the interrupt, reads message from DIPCTDR, DIPCTDD and L2 local memory
  2. DSP clears BUSY by writing 1 to DIPCTDR
  3. DSP process the message
  4. DSP set DONE by writing DIPCTDA

Replacing 3. and 4. will violate the architecture flow.
Note: in closed-source cAVS, BUSY is cleared together with set DONE, after processing the message, so moment of clearing BUSY seems to not to be critical.

At present cAVS closed-source solution, BUSY and DONE are triggered after processing message from host and before writing response. It seems to be the best way.

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.

Thanks @pblaszko ! Indeed, this is what @ujfalusi also commented in last Friday in #6239 (comment) . And yes, this seems to be the correct thing.

The key seems to be whether busy+done clearance is done before or after the response is sent. We are err'ing towards the direction that host/kernel should handle even the case where busy+done is cleared only at the end (i.e. the original sequence).

#endif

/* perform command */
ipc_cmd(hdr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, I see. the reply is sent as a new message within ipc_cmd() at the end of the handling.
In theory host software could rely on the BUSY to decide to send a new message or not, so if we clear it before we processed the message from the registers and mailbox then there is a chance that the host changes the content under our feet...

One way to be safer is to add a flag to struct ipc_msg, something like bool reply_message. If it is true then do the ack before sending the reply message itself. The flag is ignored for IPC3.


Expand All @@ -204,9 +222,11 @@ void ipc_platform_complete_cmd(struct ipc *ipc)
#if CAVS_VERSION == CAVS_VERSION_1_5
ipc_write(IPC_DIPCT, ipc_read(IPC_DIPCT) | IPC_DIPCT_BUSY);
#else
#ifndef IPC4_EARLY_ACK
ipc_write(IPC_DIPCTDR, ipc_read(IPC_DIPCTDR) | IPC_DIPCTDR_BUSY);
ipc_write(IPC_DIPCTDA, ipc_read(IPC_DIPCTDA) | IPC_DIPCTDA_DONE);
#endif
#endif

#if CONFIG_DEBUG_IPC_COUNTERS
increment_ipc_processed_counter();
Expand Down