-
Notifications
You must be signed in to change notification settings - Fork 318
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
ipc: add cache flushing and invalidation for IPC data #9630
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,9 +72,9 @@ struct ipc4_msg_data { | |
static struct ipc4_msg_data msg_data; | ||
|
||
/* fw sends a fw ipc message to send the status of the last host ipc message */ | ||
static struct ipc_msg msg_reply = {0, 0, 0, 0, LIST_INIT(msg_reply.list)}; | ||
static struct ipc_msg msg_reply = {0, 0, 0, 0, false, LIST_INIT(msg_reply.list)}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are those static structures ever cleaned? If not, once is_shared is set to true it'll never be set to back false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that was a good catch. It seems to me that I managed to cover all cases now. |
||
|
||
static struct ipc_msg msg_notify = {0, 0, 0, 0, LIST_INIT(msg_notify.list)}; | ||
static struct ipc_msg msg_notify = {0, 0, 0, 0, false, LIST_INIT(msg_notify.list)}; | ||
|
||
#if CONFIG_LIBRARY | ||
static inline struct ipc4_message_request *ipc4_get_message_request(void) | ||
|
@@ -1494,14 +1494,25 @@ 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) { | ||
tmleman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* Invalidate cache to ensure we read the latest data from memory. | ||
* The response was prepared on a secondary core but will be sent | ||
* to the host from the primary core. | ||
*/ | ||
if (msg->is_shared) { | ||
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) { | ||
rfree(msg_reply.tx_data); | ||
msg_reply.tx_data = NULL; | ||
msg_reply.tx_size = 0; | ||
msg_reply.is_shared = false; | ||
} | ||
|
||
return &msg_data.msg_out; | ||
|
@@ -1535,6 +1546,7 @@ void ipc_send_panic_notification(void) | |
{ | ||
msg_notify.header = SOF_IPC4_NOTIF_HEADER(SOF_IPC4_EXCEPTION_CAUGHT); | ||
msg_notify.extension = cpu_get_id(); | ||
msg_notify.is_shared = !cpu_is_primary(cpu_get_id()); | ||
msg_notify.tx_size = 0; | ||
msg_notify.tx_data = NULL; | ||
list_init(&msg_notify.list); | ||
|
@@ -1567,6 +1579,7 @@ void ipc_send_buffer_status_notify(void) | |
msg_notify.header = SOF_IPC4_NOTIF_HEADER(SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS); | ||
msg_notify.extension = 0; | ||
msg_notify.tx_size = 0; | ||
msg_notify.is_shared = false; | ||
|
||
tr_dbg(&ipc_tr, "tx-notify\t: %#x|%#x", msg_notify.header, msg_notify.extension); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good catch. I wonder if a better fix would be to just allocate tx_data as uncached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible, but it probably comes with a performance cost. It's hard for me to determine what is better. However, invalidating each message also seems problematic to me, and I considered adding some flag in the structure that would indicate that the payload should be invalidated before copying.