Skip to content

Commit b22db70

Browse files
committed
ipc: rework Zephyr IPC interface
This reworks Zephyr IPC interface to utilize the newly introduced IPC message service, which provides a more generic IPC interface. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
1 parent eb7102b commit b22db70

File tree

4 files changed

+93
-20
lines changed

4 files changed

+93
-20
lines changed

app/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ CONFIG_SCHED_CPU_MASK=y
4949
CONFIG_SYS_CLOCK_TICKS_PER_SEC=15000
5050
CONFIG_DAI=y
5151
CONFIG_HEAP_MEM_POOL_SIZE=2048
52+
53+
# Use the new IPC message service in Zephyr
54+
CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE=n

src/include/sof/ipc/common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,12 @@ void ipc_msg_reply(struct sof_ipc_reply *reply);
243243
*/
244244
void ipc_complete_cmd(struct ipc *ipc);
245245

246+
/**
247+
* \brief Send emergency IPC message.
248+
*
249+
* @param[in] data IPC data to be sent.
250+
* @param[in] ext_data Extended data to be sent.
251+
*/
252+
void ipc_send_message_emergency(uint32_t data, uint32_t ext_data);
253+
246254
#endif /* __SOF_DRIVERS_IPC_H__ */

src/ipc/ipc-zephyr.c

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <autoconf.h>
1313

14-
#include <intel_adsp_ipc.h>
1514
#include <sof/ipc/common.h>
1615

1716
#include <sof/ipc/schedule.h>
@@ -43,6 +42,8 @@
4342
#include <stddef.h>
4443
#include <stdint.h>
4544

45+
#include <zephyr/ipc/backends/ipc_msg_intel_adsp_ipc.h>
46+
4647
SOF_DEFINE_REG_UUID(zipc_task);
4748

4849
LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
@@ -58,23 +59,27 @@ LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
5859
static uint32_t g_last_data, g_last_ext_data;
5960

6061
/**
61-
* @brief cAVS IPC Message Handler Callback function.
62+
* @brief cAVS IPC Message Received Callback function.
6263
*
63-
* See @ref (*intel_adsp_ipc_handler_t) for function signature description.
64-
* @return false so BUSY on the other side will not be cleared immediately but
64+
* @return -1 so BUSY on the other side will not be cleared immediately but
6565
* will remain set until message would have been processed by scheduled task, i.e.
6666
* until ipc_platform_complete_cmd() call.
6767
*/
68-
static bool message_handler(const struct device *dev, void *arg, uint32_t data, uint32_t ext_data)
68+
static int ipc_receive_cb(uint8_t msg_type, const void *msg_data, void *priv)
6969
{
70-
struct ipc *ipc = (struct ipc *)arg;
70+
const struct intel_adsp_ipc_msg *msg = (const struct intel_adsp_ipc_msg *)msg_data;
71+
72+
if (msg_type != INTEL_ADSP_IPC_MSG)
73+
return -EBADMSG;
74+
75+
struct ipc *ipc = (struct ipc *)priv;
7176

7277
k_spinlock_key_t key;
7378

7479
key = k_spin_lock(&ipc->lock);
7580

76-
g_last_data = data;
77-
g_last_ext_data = ext_data;
81+
g_last_data = msg->data;
82+
g_last_ext_data = msg->extdata;
7883

7984
#if CONFIG_DEBUG_IPC_COUNTERS
8085
increment_ipc_received_counter();
@@ -83,7 +88,64 @@ static bool message_handler(const struct device *dev, void *arg, uint32_t data,
8388

8489
k_spin_unlock(&ipc->lock, key);
8590

86-
return false;
91+
return -1;
92+
}
93+
94+
static struct ipc_msg_ept ipc_ept;
95+
static struct ipc_msg_ept_cfg ipc_ept_cfg = {
96+
.name = "sof_ipc",
97+
.cb = {
98+
.received = ipc_receive_cb,
99+
},
100+
};
101+
102+
static void ipc_ept_init(struct ipc *ipc)
103+
{
104+
int ret;
105+
const struct device *ipc_dev = INTEL_ADSP_IPC_HOST_DEV;
106+
107+
ipc_ept_cfg.priv = (void *)ipc;
108+
109+
ret = ipc_msg_service_register_endpoint(ipc_dev, &ipc_ept, &ipc_ept_cfg);
110+
ARG_UNUSED(ret);
111+
}
112+
113+
static void ipc_complete(void)
114+
{
115+
int ret;
116+
117+
ret = ipc_msg_service_send(&ipc_ept, INTEL_ADSP_IPC_MSG_DONE, NULL);
118+
119+
ARG_UNUSED(ret);
120+
}
121+
122+
static bool ipc_is_complete(void)
123+
{
124+
int ret;
125+
126+
ret = ipc_msg_service_query(&ipc_ept, INTEL_ADSP_IPC_QUERY_IS_COMPLETE, NULL, NULL);
127+
128+
return ret == 0;
129+
}
130+
131+
static int ipc_send_message(uint32_t data, uint32_t ext_data)
132+
{
133+
struct intel_adsp_ipc_msg msg = {.data = data, .extdata = ext_data};
134+
int ret;
135+
136+
ret = ipc_msg_service_send(&ipc_ept, INTEL_ADSP_IPC_MSG, &msg);
137+
138+
return ret;
139+
}
140+
141+
void ipc_send_message_emergency(uint32_t data, uint32_t ext_data)
142+
{
143+
struct intel_adsp_ipc_msg_emergency msg = {.data = data, .extdata = ext_data};
144+
int ret;
145+
146+
ret = ipc_msg_service_send(&ipc_ept, INTEL_ADSP_IPC_MSG_EMERGENCY, &msg);
147+
148+
ARG_UNUSED(ret);
87149
}
88150

89151
#ifdef CONFIG_PM_DEVICE
@@ -157,8 +219,8 @@ static int ipc_device_resume_handler(const struct device *dev, void *arg)
157219
ipc->task_mask = 0;
158220
ipc->pm_prepare_D3 = false;
159221

160-
/* attach handlers */
161-
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, message_handler, ipc);
222+
/* initialize IPC endpoint */
223+
ipc_ept_init(ipc);
162224

163225
/* schedule task */
164226
#if CONFIG_TWB_IPC_TASK
@@ -252,7 +314,7 @@ enum task_state ipc_platform_do_cmd(struct ipc *ipc)
252314
void ipc_platform_complete_cmd(struct ipc *ipc)
253315
{
254316
ARG_UNUSED(ipc);
255-
intel_adsp_ipc_complete(INTEL_ADSP_IPC_HOST_DEV);
317+
ipc_complete();
256318

257319
#if CONFIG_DEBUG_IPC_COUNTERS
258320
increment_ipc_processed_counter();
@@ -261,26 +323,26 @@ void ipc_platform_complete_cmd(struct ipc *ipc)
261323

262324
int ipc_platform_send_msg(const struct ipc_msg *msg)
263325
{
264-
if (!intel_adsp_ipc_is_complete(INTEL_ADSP_IPC_HOST_DEV))
326+
if (!ipc_is_complete())
265327
return -EBUSY;
266328

267329
/* prepare the message and copy to mailbox */
268330
struct ipc_cmd_hdr *hdr = ipc_prepare_to_send(msg);
269331

270-
return intel_adsp_ipc_send_message(INTEL_ADSP_IPC_HOST_DEV, hdr->pri, hdr->ext);
332+
return ipc_send_message(hdr->pri, hdr->ext);
271333
}
272334

273335
void ipc_platform_send_msg_direct(const struct ipc_msg *msg)
274336
{
275337
/* prepare the message and copy to mailbox */
276338
struct ipc_cmd_hdr *hdr = ipc_prepare_to_send(msg);
277339

278-
intel_adsp_ipc_send_message_emergency(INTEL_ADSP_IPC_HOST_DEV, hdr->pri, hdr->ext);
340+
ipc_send_message_emergency(hdr->pri, hdr->ext);
279341
}
280342

281343
int ipc_platform_poll_is_host_ready(void)
282344
{
283-
return intel_adsp_ipc_is_complete(INTEL_ADSP_IPC_HOST_DEV);
345+
return ipc_is_complete();
284346
}
285347

286348
int platform_ipc_init(struct ipc *ipc)
@@ -298,8 +360,9 @@ int platform_ipc_init(struct ipc *ipc)
298360
#endif
299361
/* configure interrupt - work is done internally by Zephyr API */
300362

301-
/* attach handlers */
302-
intel_adsp_ipc_set_message_handler(INTEL_ADSP_IPC_HOST_DEV, message_handler, ipc);
363+
/* initialize IPC endpoint */
364+
ipc_ept_init(ipc);
365+
303366
#ifdef CONFIG_PM
304367
intel_adsp_ipc_set_suspend_handler(INTEL_ADSP_IPC_HOST_DEV,
305368
ipc_device_suspend_handler, ipc);

src/platform/intel/ace/lib/watchdog.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ static void watchdog_primary_core_action_on_timeout(void)
3434

3535
/* Send Watchdog Timeout IPC notification */
3636
ipc4_notification_watchdog_init(&notif, cpu_get_id(), true);
37-
intel_adsp_ipc_send_message_emergency(INTEL_ADSP_IPC_HOST_DEV,
38-
notif.primary.dat, notif.extension.dat);
37+
(void)ipc_send_message_emergency(notif.primary.dat, notif.extension.dat);
3938
}
4039

4140
static void watchdog_secondary_core_action_on_timeout(void)

0 commit comments

Comments
 (0)