11
11
12
12
#include <autoconf.h>
13
13
14
- #include <intel_adsp_ipc.h>
15
14
#include <sof/ipc/common.h>
16
15
17
16
#include <sof/ipc/schedule.h>
43
42
#include <stddef.h>
44
43
#include <stdint.h>
45
44
45
+ #include <zephyr/ipc/backends/ipc_msg_intel_adsp_ipc.h>
46
+
46
47
SOF_DEFINE_REG_UUID (zipc_task );
47
48
48
49
LOG_MODULE_DECLARE (ipc , CONFIG_SOF_LOG_LEVEL );
@@ -58,23 +59,27 @@ LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
58
59
static uint32_t g_last_data , g_last_ext_data ;
59
60
60
61
/**
61
- * @brief cAVS IPC Message Handler Callback function.
62
+ * @brief cAVS IPC Message Received Callback function.
62
63
*
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
65
65
* will remain set until message would have been processed by scheduled task, i.e.
66
66
* until ipc_platform_complete_cmd() call.
67
67
*/
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 )
69
69
{
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 ;
71
76
72
77
k_spinlock_key_t key ;
73
78
74
79
key = k_spin_lock (& ipc -> lock );
75
80
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 ;
78
83
79
84
#if CONFIG_DEBUG_IPC_COUNTERS
80
85
increment_ipc_received_counter ();
@@ -83,7 +88,64 @@ static bool message_handler(const struct device *dev, void *arg, uint32_t data,
83
88
84
89
k_spin_unlock (& ipc -> lock , key );
85
90
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 );
87
149
}
88
150
89
151
#ifdef CONFIG_PM_DEVICE
@@ -157,8 +219,8 @@ static int ipc_device_resume_handler(const struct device *dev, void *arg)
157
219
ipc -> task_mask = 0 ;
158
220
ipc -> pm_prepare_D3 = false;
159
221
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 );
162
224
163
225
/* schedule task */
164
226
#if CONFIG_TWB_IPC_TASK
@@ -252,7 +314,7 @@ enum task_state ipc_platform_do_cmd(struct ipc *ipc)
252
314
void ipc_platform_complete_cmd (struct ipc * ipc )
253
315
{
254
316
ARG_UNUSED (ipc );
255
- intel_adsp_ipc_complete ( INTEL_ADSP_IPC_HOST_DEV );
317
+ ipc_complete ( );
256
318
257
319
#if CONFIG_DEBUG_IPC_COUNTERS
258
320
increment_ipc_processed_counter ();
@@ -261,26 +323,26 @@ void ipc_platform_complete_cmd(struct ipc *ipc)
261
323
262
324
int ipc_platform_send_msg (const struct ipc_msg * msg )
263
325
{
264
- if (!intel_adsp_ipc_is_complete ( INTEL_ADSP_IPC_HOST_DEV ))
326
+ if (!ipc_is_complete ( ))
265
327
return - EBUSY ;
266
328
267
329
/* prepare the message and copy to mailbox */
268
330
struct ipc_cmd_hdr * hdr = ipc_prepare_to_send (msg );
269
331
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 );
271
333
}
272
334
273
335
void ipc_platform_send_msg_direct (const struct ipc_msg * msg )
274
336
{
275
337
/* prepare the message and copy to mailbox */
276
338
struct ipc_cmd_hdr * hdr = ipc_prepare_to_send (msg );
277
339
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 );
279
341
}
280
342
281
343
int ipc_platform_poll_is_host_ready (void )
282
344
{
283
- return intel_adsp_ipc_is_complete ( INTEL_ADSP_IPC_HOST_DEV );
345
+ return ipc_is_complete ( );
284
346
}
285
347
286
348
int platform_ipc_init (struct ipc * ipc )
@@ -298,8 +360,9 @@ int platform_ipc_init(struct ipc *ipc)
298
360
#endif
299
361
/* configure interrupt - work is done internally by Zephyr API */
300
362
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
+
303
366
#ifdef CONFIG_PM
304
367
intel_adsp_ipc_set_suspend_handler (INTEL_ADSP_IPC_HOST_DEV ,
305
368
ipc_device_suspend_handler , ipc );
0 commit comments