hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/soc/intel/common/sst-ipc.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Intel SST generic IPC Support
34 *
45 * Copyright (C) 2015, Intel Corporation. All rights reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License version
8
- * 2 as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
156 */
167
178 #include <linux/types.h>
....@@ -52,7 +43,7 @@
5243 }
5344
5445 static int tx_wait_done(struct sst_generic_ipc *ipc,
55
- struct ipc_message *msg, void *rx_data)
46
+ struct ipc_message *msg, struct sst_ipc_message *reply)
5647 {
5748 unsigned long flags;
5849 int ret;
....@@ -71,8 +62,11 @@
7162 } else {
7263
7364 /* copy the data returned from DSP */
74
- if (msg->rx_size)
75
- memcpy(rx_data, msg->rx_data, msg->rx_size);
65
+ if (reply) {
66
+ reply->header = msg->rx.header;
67
+ if (reply->data)
68
+ memcpy(reply->data, msg->rx.data, msg->rx.size);
69
+ }
7670 ret = msg->errno;
7771 }
7872
....@@ -81,9 +75,9 @@
8175 return ret;
8276 }
8377
84
-static int ipc_tx_message(struct sst_generic_ipc *ipc, u64 header,
85
- void *tx_data, size_t tx_bytes, void *rx_data,
86
- size_t rx_bytes, int wait)
78
+static int ipc_tx_message(struct sst_generic_ipc *ipc,
79
+ struct sst_ipc_message request,
80
+ struct sst_ipc_message *reply, int wait)
8781 {
8882 struct ipc_message *msg;
8983 unsigned long flags;
....@@ -96,23 +90,24 @@
9690 return -EBUSY;
9791 }
9892
99
- msg->header = header;
100
- msg->tx_size = tx_bytes;
101
- msg->rx_size = rx_bytes;
93
+ msg->tx.header = request.header;
94
+ msg->tx.size = request.size;
95
+ msg->rx.header = 0;
96
+ msg->rx.size = reply ? reply->size : 0;
10297 msg->wait = wait;
10398 msg->errno = 0;
10499 msg->pending = false;
105100 msg->complete = false;
106101
107
- if ((tx_bytes) && (ipc->ops.tx_data_copy != NULL))
108
- ipc->ops.tx_data_copy(msg, tx_data, tx_bytes);
102
+ if ((request.size) && (ipc->ops.tx_data_copy != NULL))
103
+ ipc->ops.tx_data_copy(msg, request.data, request.size);
109104
110105 list_add_tail(&msg->list, &ipc->tx_list);
111106 schedule_work(&ipc->kwork);
112107 spin_unlock_irqrestore(&ipc->dsp->spinlock, flags);
113108
114109 if (wait)
115
- return tx_wait_done(ipc, msg, rx_data);
110
+ return tx_wait_done(ipc, msg, reply);
116111 else
117112 return 0;
118113 }
....@@ -127,13 +122,13 @@
127122 return -ENOMEM;
128123
129124 for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) {
130
- ipc->msg[i].tx_data = kzalloc(ipc->tx_data_max_size, GFP_KERNEL);
131
- if (ipc->msg[i].tx_data == NULL)
125
+ ipc->msg[i].tx.data = kzalloc(ipc->tx_data_max_size, GFP_KERNEL);
126
+ if (ipc->msg[i].tx.data == NULL)
132127 goto free_mem;
133128
134
- ipc->msg[i].rx_data = kzalloc(ipc->rx_data_max_size, GFP_KERNEL);
135
- if (ipc->msg[i].rx_data == NULL) {
136
- kfree(ipc->msg[i].tx_data);
129
+ ipc->msg[i].rx.data = kzalloc(ipc->rx_data_max_size, GFP_KERNEL);
130
+ if (ipc->msg[i].rx.data == NULL) {
131
+ kfree(ipc->msg[i].tx.data);
137132 goto free_mem;
138133 }
139134
....@@ -145,8 +140,8 @@
145140
146141 free_mem:
147142 while (i > 0) {
148
- kfree(ipc->msg[i-1].tx_data);
149
- kfree(ipc->msg[i-1].rx_data);
143
+ kfree(ipc->msg[i-1].tx.data);
144
+ kfree(ipc->msg[i-1].rx.data);
150145 --i;
151146 }
152147 kfree(ipc->msg);
....@@ -182,8 +177,8 @@
182177 spin_unlock_irq(&ipc->dsp->spinlock);
183178 }
184179
185
-int sst_ipc_tx_message_wait(struct sst_generic_ipc *ipc, u64 header,
186
- void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes)
180
+int sst_ipc_tx_message_wait(struct sst_generic_ipc *ipc,
181
+ struct sst_ipc_message request, struct sst_ipc_message *reply)
187182 {
188183 int ret;
189184
....@@ -196,8 +191,7 @@
196191 if (ipc->ops.check_dsp_lp_on(ipc->dsp, true))
197192 return -EIO;
198193
199
- ret = ipc_tx_message(ipc, header, tx_data, tx_bytes,
200
- rx_data, rx_bytes, 1);
194
+ ret = ipc_tx_message(ipc, request, reply, 1);
201195
202196 if (ipc->ops.check_dsp_lp_on)
203197 if (ipc->ops.check_dsp_lp_on(ipc->dsp, false))
....@@ -207,19 +201,17 @@
207201 }
208202 EXPORT_SYMBOL_GPL(sst_ipc_tx_message_wait);
209203
210
-int sst_ipc_tx_message_nowait(struct sst_generic_ipc *ipc, u64 header,
211
- void *tx_data, size_t tx_bytes)
204
+int sst_ipc_tx_message_nowait(struct sst_generic_ipc *ipc,
205
+ struct sst_ipc_message request)
212206 {
213
- return ipc_tx_message(ipc, header, tx_data, tx_bytes,
214
- NULL, 0, 0);
207
+ return ipc_tx_message(ipc, request, NULL, 0);
215208 }
216209 EXPORT_SYMBOL_GPL(sst_ipc_tx_message_nowait);
217210
218
-int sst_ipc_tx_message_nopm(struct sst_generic_ipc *ipc, u64 header,
219
- void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes)
211
+int sst_ipc_tx_message_nopm(struct sst_generic_ipc *ipc,
212
+ struct sst_ipc_message request, struct sst_ipc_message *reply)
220213 {
221
- return ipc_tx_message(ipc, header, tx_data, tx_bytes,
222
- rx_data, rx_bytes, 1);
214
+ return ipc_tx_message(ipc, request, reply, 1);
223215 }
224216 EXPORT_SYMBOL_GPL(sst_ipc_tx_message_nopm);
225217
....@@ -241,7 +233,7 @@
241233 }
242234
243235 list_for_each_entry(msg, &ipc->rx_list, list) {
244
- if ((msg->header & mask) == header)
236
+ if ((msg->tx.header & mask) == header)
245237 return msg;
246238 }
247239
....@@ -261,33 +253,6 @@
261253 wake_up(&msg->waitq);
262254 }
263255 EXPORT_SYMBOL_GPL(sst_ipc_tx_msg_reply_complete);
264
-
265
-void sst_ipc_drop_all(struct sst_generic_ipc *ipc)
266
-{
267
- struct ipc_message *msg, *tmp;
268
- unsigned long flags;
269
- int tx_drop_cnt = 0, rx_drop_cnt = 0;
270
-
271
- /* drop all TX and Rx messages before we stall + reset DSP */
272
- spin_lock_irqsave(&ipc->dsp->spinlock, flags);
273
-
274
- list_for_each_entry_safe(msg, tmp, &ipc->tx_list, list) {
275
- list_move(&msg->list, &ipc->empty_list);
276
- tx_drop_cnt++;
277
- }
278
-
279
- list_for_each_entry_safe(msg, tmp, &ipc->rx_list, list) {
280
- list_move(&msg->list, &ipc->empty_list);
281
- rx_drop_cnt++;
282
- }
283
-
284
- spin_unlock_irqrestore(&ipc->dsp->spinlock, flags);
285
-
286
- if (tx_drop_cnt || rx_drop_cnt)
287
- dev_err(ipc->dev, "dropped IPC msg RX=%d, TX=%d\n",
288
- tx_drop_cnt, rx_drop_cnt);
289
-}
290
-EXPORT_SYMBOL_GPL(sst_ipc_drop_all);
291256
292257 int sst_ipc_init(struct sst_generic_ipc *ipc)
293258 {
....@@ -315,8 +280,8 @@
315280
316281 if (ipc->msg) {
317282 for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) {
318
- kfree(ipc->msg[i].tx_data);
319
- kfree(ipc->msg[i].rx_data);
283
+ kfree(ipc->msg[i].tx.data);
284
+ kfree(ipc->msg[i].rx.data);
320285 }
321286 kfree(ipc->msg);
322287 }