| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Intel SST generic IPC Support |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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 | | - * |
|---|
| 15 | 6 | */ |
|---|
| 16 | 7 | |
|---|
| 17 | 8 | #include <linux/types.h> |
|---|
| .. | .. |
|---|
| 52 | 43 | } |
|---|
| 53 | 44 | |
|---|
| 54 | 45 | 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) |
|---|
| 56 | 47 | { |
|---|
| 57 | 48 | unsigned long flags; |
|---|
| 58 | 49 | int ret; |
|---|
| .. | .. |
|---|
| 71 | 62 | } else { |
|---|
| 72 | 63 | |
|---|
| 73 | 64 | /* 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 | + } |
|---|
| 76 | 70 | ret = msg->errno; |
|---|
| 77 | 71 | } |
|---|
| 78 | 72 | |
|---|
| .. | .. |
|---|
| 81 | 75 | return ret; |
|---|
| 82 | 76 | } |
|---|
| 83 | 77 | |
|---|
| 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) |
|---|
| 87 | 81 | { |
|---|
| 88 | 82 | struct ipc_message *msg; |
|---|
| 89 | 83 | unsigned long flags; |
|---|
| .. | .. |
|---|
| 96 | 90 | return -EBUSY; |
|---|
| 97 | 91 | } |
|---|
| 98 | 92 | |
|---|
| 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; |
|---|
| 102 | 97 | msg->wait = wait; |
|---|
| 103 | 98 | msg->errno = 0; |
|---|
| 104 | 99 | msg->pending = false; |
|---|
| 105 | 100 | msg->complete = false; |
|---|
| 106 | 101 | |
|---|
| 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); |
|---|
| 109 | 104 | |
|---|
| 110 | 105 | list_add_tail(&msg->list, &ipc->tx_list); |
|---|
| 111 | 106 | schedule_work(&ipc->kwork); |
|---|
| 112 | 107 | spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); |
|---|
| 113 | 108 | |
|---|
| 114 | 109 | if (wait) |
|---|
| 115 | | - return tx_wait_done(ipc, msg, rx_data); |
|---|
| 110 | + return tx_wait_done(ipc, msg, reply); |
|---|
| 116 | 111 | else |
|---|
| 117 | 112 | return 0; |
|---|
| 118 | 113 | } |
|---|
| .. | .. |
|---|
| 127 | 122 | return -ENOMEM; |
|---|
| 128 | 123 | |
|---|
| 129 | 124 | 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) |
|---|
| 132 | 127 | goto free_mem; |
|---|
| 133 | 128 | |
|---|
| 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); |
|---|
| 137 | 132 | goto free_mem; |
|---|
| 138 | 133 | } |
|---|
| 139 | 134 | |
|---|
| .. | .. |
|---|
| 145 | 140 | |
|---|
| 146 | 141 | free_mem: |
|---|
| 147 | 142 | 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); |
|---|
| 150 | 145 | --i; |
|---|
| 151 | 146 | } |
|---|
| 152 | 147 | kfree(ipc->msg); |
|---|
| .. | .. |
|---|
| 182 | 177 | spin_unlock_irq(&ipc->dsp->spinlock); |
|---|
| 183 | 178 | } |
|---|
| 184 | 179 | |
|---|
| 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) |
|---|
| 187 | 182 | { |
|---|
| 188 | 183 | int ret; |
|---|
| 189 | 184 | |
|---|
| .. | .. |
|---|
| 196 | 191 | if (ipc->ops.check_dsp_lp_on(ipc->dsp, true)) |
|---|
| 197 | 192 | return -EIO; |
|---|
| 198 | 193 | |
|---|
| 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); |
|---|
| 201 | 195 | |
|---|
| 202 | 196 | if (ipc->ops.check_dsp_lp_on) |
|---|
| 203 | 197 | if (ipc->ops.check_dsp_lp_on(ipc->dsp, false)) |
|---|
| .. | .. |
|---|
| 207 | 201 | } |
|---|
| 208 | 202 | EXPORT_SYMBOL_GPL(sst_ipc_tx_message_wait); |
|---|
| 209 | 203 | |
|---|
| 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) |
|---|
| 212 | 206 | { |
|---|
| 213 | | - return ipc_tx_message(ipc, header, tx_data, tx_bytes, |
|---|
| 214 | | - NULL, 0, 0); |
|---|
| 207 | + return ipc_tx_message(ipc, request, NULL, 0); |
|---|
| 215 | 208 | } |
|---|
| 216 | 209 | EXPORT_SYMBOL_GPL(sst_ipc_tx_message_nowait); |
|---|
| 217 | 210 | |
|---|
| 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) |
|---|
| 220 | 213 | { |
|---|
| 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); |
|---|
| 223 | 215 | } |
|---|
| 224 | 216 | EXPORT_SYMBOL_GPL(sst_ipc_tx_message_nopm); |
|---|
| 225 | 217 | |
|---|
| .. | .. |
|---|
| 241 | 233 | } |
|---|
| 242 | 234 | |
|---|
| 243 | 235 | list_for_each_entry(msg, &ipc->rx_list, list) { |
|---|
| 244 | | - if ((msg->header & mask) == header) |
|---|
| 236 | + if ((msg->tx.header & mask) == header) |
|---|
| 245 | 237 | return msg; |
|---|
| 246 | 238 | } |
|---|
| 247 | 239 | |
|---|
| .. | .. |
|---|
| 261 | 253 | wake_up(&msg->waitq); |
|---|
| 262 | 254 | } |
|---|
| 263 | 255 | 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); |
|---|
| 291 | 256 | |
|---|
| 292 | 257 | int sst_ipc_init(struct sst_generic_ipc *ipc) |
|---|
| 293 | 258 | { |
|---|
| .. | .. |
|---|
| 315 | 280 | |
|---|
| 316 | 281 | if (ipc->msg) { |
|---|
| 317 | 282 | 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); |
|---|
| 320 | 285 | } |
|---|
| 321 | 286 | kfree(ipc->msg); |
|---|
| 322 | 287 | } |
|---|