Skip to content

Commit

Permalink
ipc: add cache flushing and invalidation for IPC data
Browse files Browse the repository at this point in the history
This patch addresses an issue with incorrect IPC responses due to the
lack of cache flushing and invalidation on secondary cores.

The following changes have been made:

1. Added cache writeback for IPC message data in `ipc_msg_send` when the
   current core is not the primary core.
2. Added cache invalidation for IPC message data in
   `ipc_prepare_to_send` before writing to the mailbox.

These changes ensure that the IPC data is correctly synchronized between
cores.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
  • Loading branch information
tmleman committed Oct 31, 2024
1 parent 2f4efa5 commit a99c314
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/ipc/ipc-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ void ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority)
msg->tx_data != data) {
ret = memcpy_s(msg->tx_data, msg->tx_size, data, msg->tx_size);
assert(!ret);
if (!cpu_is_primary(cpu_get_id()))
dcache_writeback_region((__sparse_force void __sparse_cache *)msg->tx_data,
msg->tx_size);
}

/*
Expand Down
5 changes: 4 additions & 1 deletion src/ipc/ipc4/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1494,8 +1494,11 @@ struct ipc_cmd_hdr *ipc_prepare_to_send(const struct ipc_msg *msg)
msg_data.msg_out.pri = msg->header;
msg_data.msg_out.ext = msg->extension;

if (msg->tx_size)
if (msg->tx_size) {
dcache_invalidate_region((__sparse_force void __sparse_cache *)msg->tx_data,
msg->tx_size);
mailbox_dspbox_write(0, (uint32_t *)msg->tx_data, msg->tx_size);
}

/* free memory for get config function */
if (msg == &msg_reply && msg_reply.tx_size > 0) {
Expand Down

0 comments on commit a99c314

Please sign in to comment.