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>
4342#include <stddef.h>
4443#include <stdint.h>
4544
45+ #include <zephyr/ipc/backends/ipc_msg_intel_adsp_ipc.h>
46+
4647SOF_DEFINE_REG_UUID (zipc_task );
4748
4849LOG_MODULE_DECLARE (ipc , CONFIG_SOF_LOG_LEVEL );
@@ -58,23 +59,27 @@ LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
5859static 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)
252314void 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
262324int 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
273335void 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
281343int 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
286348int 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 );
0 commit comments