1
- /* Copyright (c) 2022 Intel Corporation
1
+ /*
2
+ * Copyright (c) 2022, 2025 Intel Corporation
3
+ *
2
4
* SPDX-License-Identifier: Apache-2.0
3
5
*/
6
+
4
7
#include <zephyr/kernel.h>
5
8
#include <zephyr/ztest.h>
6
9
#include <intel_adsp_ipc.h>
@@ -11,6 +14,7 @@ static volatile bool done_flag, msg_flag;
11
14
#define RETURN_MSG_SYNC_VAL 0x12345
12
15
#define RETURN_MSG_ASYNC_VAL 0x54321
13
16
17
+ #ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
14
18
static bool ipc_message (const struct device * dev , void * arg ,
15
19
uint32_t data , uint32_t ext_data )
16
20
{
@@ -29,13 +33,103 @@ static bool ipc_done(const struct device *dev, void *arg)
29
33
done_flag = true;
30
34
return false;
31
35
}
36
+ #else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
37
+
38
+ #include <zephyr/ipc/ipc_service.h>
39
+ #include <zephyr/ipc/backends/intel_adsp_host_ipc.h>
40
+
41
+ struct ipc_ept host_ipc_ept ;
42
+
43
+ void ipc_receive_cb (const void * data , size_t len , void * priv )
44
+ {
45
+ struct intel_adsp_ipc_ept_priv_data * priv_data =
46
+ (struct intel_adsp_ipc_ept_priv_data * )priv ;
47
+
48
+ if (len == INTEL_ADSP_IPC_CB_MSG ) {
49
+ const struct intel_adsp_ipc_msg * msg = (const struct intel_adsp_ipc_msg * )data ;
50
+
51
+ zassert_equal (msg -> data , msg -> ext_data , "unequal message data/ext_data" );
52
+ zassert_true (msg -> data == RETURN_MSG_SYNC_VAL ||
53
+ msg -> data == RETURN_MSG_ASYNC_VAL , "unexpected msg data" );
54
+
55
+ msg_flag = true;
56
+
57
+ if (msg -> data == RETURN_MSG_SYNC_VAL ) {
58
+ priv_data -> cb_ret = INTEL_ADSP_IPC_CB_RET_OKAY ;
59
+ } else {
60
+ priv_data -> cb_ret = - EINVAL ;
61
+ }
62
+ } else if (len == INTEL_ADSP_IPC_CB_DONE ) {
63
+ zassert_false (done_flag , "done called unexpectedly" );
64
+
65
+ done_flag = true;
66
+
67
+ priv_data -> cb_ret = INTEL_ADSP_IPC_CB_RET_OKAY ;
68
+ }
69
+ }
70
+
71
+ static struct intel_adsp_ipc_ept_priv_data host_ipc_priv_data ;
72
+
73
+ struct ipc_ept_cfg host_ipc_ept_cfg = {
74
+ .name = "host_ipc_ept" ,
75
+ .cb = {
76
+ .received = ipc_receive_cb ,
77
+ },
78
+ .priv = & host_ipc_priv_data ,
79
+ };
80
+
81
+ static void intel_adsp_ipc_complete (const struct device * dev )
82
+ {
83
+ int ret ;
84
+
85
+ ret = ipc_service_send (& host_ipc_ept , NULL , INTEL_ADSP_IPC_SEND_DONE );
86
+
87
+ ARG_UNUSED (ret );
88
+ }
89
+
90
+ static bool intel_adsp_ipc_is_complete (const struct device * dev )
91
+ {
92
+ int ret ;
93
+
94
+ ret = ipc_service_send (& host_ipc_ept , NULL , INTEL_ADSP_IPC_SEND_IS_COMPLETE );
95
+
96
+ return ret == 0 ;
97
+ }
98
+
99
+ int intel_adsp_ipc_send_message (const struct device * dev , uint32_t data , uint32_t ext_data )
100
+ {
101
+ struct intel_adsp_ipc_msg msg = {.data = data , .ext_data = ext_data };
102
+ int ret ;
103
+
104
+ ret = ipc_service_send (& host_ipc_ept , & msg , INTEL_ADSP_IPC_SEND_MSG );
105
+
106
+ return ret ;
107
+ }
108
+
109
+ static int intel_adsp_ipc_send_message_sync (const struct device * dev , uint32_t data ,
110
+ uint32_t ext_data , k_timeout_t timeout )
111
+ {
112
+ struct intel_adsp_ipc_msg msg = {.data = data , .ext_data = ext_data , .timeout = timeout };
113
+ int ret ;
114
+
115
+ ret = ipc_service_send (& host_ipc_ept , & msg , INTEL_ADSP_IPC_SEND_MSG_SYNC );
116
+
117
+ return ret ;
118
+ }
119
+ #endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
32
120
33
121
ZTEST (intel_adsp , test_host_ipc )
34
122
{
35
123
int ret ;
36
124
125
+ #ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
37
126
intel_adsp_ipc_set_message_handler (INTEL_ADSP_IPC_HOST_DEV , ipc_message , NULL );
38
127
intel_adsp_ipc_set_done_handler (INTEL_ADSP_IPC_HOST_DEV , ipc_done , NULL );
128
+ #else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
129
+ ret = ipc_service_register_endpoint (INTEL_ADSP_IPC_HOST_DEV , & host_ipc_ept ,
130
+ & host_ipc_ept_cfg );
131
+ zassert_equal (ret , 0 , "cannot register IPC endpoint" );
132
+ #endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
39
133
40
134
/* Just send a message and wait for it to complete */
41
135
printk ("Simple message send...\n" );
@@ -97,7 +191,12 @@ ZTEST(intel_adsp, test_host_ipc)
97
191
zassert_true (intel_adsp_ipc_is_complete (INTEL_ADSP_IPC_HOST_DEV ),
98
192
"sync message incomplete" );
99
193
194
+ #ifdef CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE
100
195
/* Clean up. Further tests might want to use IPC */
101
196
intel_adsp_ipc_set_message_handler (INTEL_ADSP_IPC_HOST_DEV , NULL , NULL );
102
197
intel_adsp_ipc_set_done_handler (INTEL_ADSP_IPC_HOST_DEV , NULL , NULL );
198
+ #else /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
199
+ ret = ipc_service_deregister_endpoint (& host_ipc_ept );
200
+ zassert_equal (ret , 0 , "cannot de-register IPC endpoint" );
201
+ #endif /* CONFIG_INTEL_ADSP_IPC_OLD_INTERFACE */
103
202
}
0 commit comments