Skip to content
Closed
Show file tree
Hide file tree
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."
#endif
#define IPC4_EARLY_ACK 1 /* ack with DONE immediately */
#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);
#endif

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.

It is a test. I prefer to do it in ipc4/handler.c without ifdef.

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 Not sure I follow. This is writing to IPC hw registers and it thus should be done in the driver, not the protocol code in ipc4/handler.c. Right? The ifdef is needed as same driver is used for IPC3 and there the semantics are different ACK/REPLY are the same thing, so the proper place to do is later.

/* perform command */
ipc_cmd(hdr);

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
3 changes: 3 additions & 0 deletions src/include/sof/ipc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ struct ipc {
/* processing task */
struct task ipc_task;

/* task for flushing outbound messages */

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.

to the commit message: "the platform driver returns -EBUSY?"

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, fixed in #6243

struct task ipc_tx_task;

void *private;
};

Expand Down
26 changes: 26 additions & 0 deletions src/ipc/ipc-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <sof/ipc/common.h>
#include <sof/ipc/msg.h>
#include <sof/ipc/driver.h>
#include <sof/schedule/ll_schedule.h>
#include <sof/ipc/schedule.h>
#include <sof/lib/alloc.h>
#include <sof/lib/cache.h>
Expand Down Expand Up @@ -168,6 +169,9 @@ void ipc_send_queued_msg(void)

key = k_spin_lock(&ipc->lock);

if (ipc->pm_prepare_D3)
goto out;

/* any messages to send ? */
if (list_is_empty(&ipc->msg_list))
goto out;
Expand All @@ -186,6 +190,7 @@ void ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority)
{
struct ipc *ipc = ipc_get();
k_spinlock_key_t key;
bool resched = false;
int ret;

key = k_spin_lock(&ipc->lock);
Expand All @@ -209,17 +214,34 @@ void ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority)
list_item_prepend(&msg->list, &ipc->msg_list);
else
list_item_append(&msg->list, &ipc->msg_list);

resched = true;
}

out:
k_spin_unlock(&ipc->lock, key);

if (resched)
schedule_task(&ipc->ipc_tx_task, IPC_PERIOD_USEC, IPC_PERIOD_USEC);
}

void ipc_schedule_process(struct ipc *ipc)
{
schedule_task(&ipc->ipc_task, 0, IPC_PERIOD_USEC);
}

static enum task_state ipc_tx_task_run(void *data)
{
struct ipc *ipc = data;

ipc_send_queued_msg();

if (!list_is_empty(&ipc->msg_list))
return SOF_TASK_STATE_RESCHEDULE;

return SOF_TASK_STATE_COMPLETED;
}

int ipc_init(struct sof *sof)
{
tr_info(&ipc_tr, "ipc_init()");
Expand All @@ -233,6 +255,10 @@ int ipc_init(struct sof *sof)
list_init(&sof->ipc->msg_list);
list_init(&sof->ipc->comp_list);

schedule_task_init_ll(&sof->ipc->ipc_tx_task, SOF_UUID(ipc_uuid),
SOF_SCHEDULE_LL_TIMER, SOF_TASK_PRI_MED,
ipc_tx_task_run, sof->ipc, 0, 0);

return platform_ipc_init(sof->ipc);
}

Expand Down
36 changes: 36 additions & 0 deletions src/ipc/ipc4/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,13 +981,48 @@ void ipc_boot_complete_msg(struct ipc_cmd_hdr *header, uint32_t data)
}

#ifdef CONFIG_LOG_BACKEND_ADSP_MTRACE

static bool is_notification_queued(void)
{
struct ipc *ipc = ipc_get();
struct list_item *slist;
struct ipc_msg *msg;
k_spinlock_key_t key;
bool queued = false;

key = k_spin_lock(&ipc->lock);
if (list_is_empty(&ipc->msg_list))
goto out;

list_for_item(slist, &ipc->msg_list) {
msg = container_of(slist, struct ipc_msg, list);

if (msg == &msg_notify) {
queued = true;
break;
}
}

out:
k_spin_unlock(&ipc->lock, key);

return queued;
}

void ipc_send_buffer_status_notify(void)
{
/* a single msg_notify object is used */
if (is_notification_queued())
return;

msg_notify.header = SOF_IPC4_NOTIF_HEADER(SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS);
msg_notify.extension = 0;
msg_notify.tx_size = 0;
list_init(&msg_notify.list);

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 see that it affects the test in ipc_msg_send() but why is that test needed at all? Why is it possible to call that function for a message, that is already queued?..

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.

Is it OK to list_init() every time?
The problem is that we have single, local msg_notify and msg_reply.
If for example the notify got delayed, put to the list and you will have another notification: you change that message which was queued, list_init it again and things will be in an interesting state, no?

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.

@lyakh We might have contention between FW->HOST replies and FW->HOST notifications. Kernel needs to ack both and until kernel ack is received, ipc_msg_send() will return EBUSY.

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.

@kv2019i Just for the record - you probably mean ipc_platform_msg_send(). Ok, so apparently either there's no waiting for the host response or the wait can be preempted.


ipc_msg_send(&msg_notify, NULL, true);

return;
}
#endif

Expand All @@ -1014,6 +1049,7 @@ void ipc_cmd(struct ipc_cmd_hdr *_hdr)
msg_reply.tx_size = 0;
msg_reply.header = in->primary.dat;
msg_reply.extension = in->extension.dat;
list_init(&msg_reply.list);

target = in->primary.r.msg_tgt;

Expand Down
6 changes: 0 additions & 6 deletions src/schedule/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,10 @@ static uint64_t task_main_deadline(void *data)

enum task_state task_main_primary_core(void *data)
{
struct ipc *ipc = ipc_get();

/* main audio processing loop */
while (1) {
/* sleep until next IPC or DMA */
wait_for_interrupt(0);

if (!ipc->pm_prepare_D3)
ipc_send_queued_msg();

}

return SOF_TASK_STATE_COMPLETED;
Expand Down