1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
10 // Generic IPC layer that can work over MMIO and SPI/I2C. PHY layer provided
11 // by platform driver code.
14 #include <linux/mutex.h>
15 #include <linux/types.h>
18 #include "sof-audio.h"
21 static void ipc_trace_message(struct snd_sof_dev
*sdev
, u32 msg_id
);
22 static void ipc_stream_message(struct snd_sof_dev
*sdev
, u32 msg_cmd
);
25 * IPC message Tx/Rx message handling.
28 /* SOF generic IPC data */
30 struct snd_sof_dev
*sdev
;
32 /* protects messages and the disable flag */
33 struct mutex tx_mutex
;
34 /* disables further sending of ipc's */
37 struct snd_sof_ipc_msg msg
;
40 struct sof_ipc_ctrl_data_params
{
50 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_VERBOSE_IPC)
51 static void ipc_log_header(struct device
*dev
, u8
*text
, u32 cmd
)
58 glb
= cmd
& SOF_GLB_TYPE_MASK
;
59 type
= cmd
& SOF_CMD_TYPE_MASK
;
62 case SOF_IPC_GLB_REPLY
:
63 str
= "GLB_REPLY"; break;
64 case SOF_IPC_GLB_COMPOUND
:
65 str
= "GLB_COMPOUND"; break;
66 case SOF_IPC_GLB_TPLG_MSG
:
69 case SOF_IPC_TPLG_COMP_NEW
:
70 str2
= "COMP_NEW"; break;
71 case SOF_IPC_TPLG_COMP_FREE
:
72 str2
= "COMP_FREE"; break;
73 case SOF_IPC_TPLG_COMP_CONNECT
:
74 str2
= "COMP_CONNECT"; break;
75 case SOF_IPC_TPLG_PIPE_NEW
:
76 str2
= "PIPE_NEW"; break;
77 case SOF_IPC_TPLG_PIPE_FREE
:
78 str2
= "PIPE_FREE"; break;
79 case SOF_IPC_TPLG_PIPE_CONNECT
:
80 str2
= "PIPE_CONNECT"; break;
81 case SOF_IPC_TPLG_PIPE_COMPLETE
:
82 str2
= "PIPE_COMPLETE"; break;
83 case SOF_IPC_TPLG_BUFFER_NEW
:
84 str2
= "BUFFER_NEW"; break;
85 case SOF_IPC_TPLG_BUFFER_FREE
:
86 str2
= "BUFFER_FREE"; break;
88 str2
= "unknown type"; break;
91 case SOF_IPC_GLB_PM_MSG
:
94 case SOF_IPC_PM_CTX_SAVE
:
95 str2
= "CTX_SAVE"; break;
96 case SOF_IPC_PM_CTX_RESTORE
:
97 str2
= "CTX_RESTORE"; break;
98 case SOF_IPC_PM_CTX_SIZE
:
99 str2
= "CTX_SIZE"; break;
100 case SOF_IPC_PM_CLK_SET
:
101 str2
= "CLK_SET"; break;
102 case SOF_IPC_PM_CLK_GET
:
103 str2
= "CLK_GET"; break;
104 case SOF_IPC_PM_CLK_REQ
:
105 str2
= "CLK_REQ"; break;
106 case SOF_IPC_PM_CORE_ENABLE
:
107 str2
= "CORE_ENABLE"; break;
109 str2
= "unknown type"; break;
112 case SOF_IPC_GLB_COMP_MSG
:
113 str
= "GLB_COMP_MSG";
115 case SOF_IPC_COMP_SET_VALUE
:
116 str2
= "SET_VALUE"; break;
117 case SOF_IPC_COMP_GET_VALUE
:
118 str2
= "GET_VALUE"; break;
119 case SOF_IPC_COMP_SET_DATA
:
120 str2
= "SET_DATA"; break;
121 case SOF_IPC_COMP_GET_DATA
:
122 str2
= "GET_DATA"; break;
124 str2
= "unknown type"; break;
127 case SOF_IPC_GLB_STREAM_MSG
:
128 str
= "GLB_STREAM_MSG";
130 case SOF_IPC_STREAM_PCM_PARAMS
:
131 str2
= "PCM_PARAMS"; break;
132 case SOF_IPC_STREAM_PCM_PARAMS_REPLY
:
133 str2
= "PCM_REPLY"; break;
134 case SOF_IPC_STREAM_PCM_FREE
:
135 str2
= "PCM_FREE"; break;
136 case SOF_IPC_STREAM_TRIG_START
:
137 str2
= "TRIG_START"; break;
138 case SOF_IPC_STREAM_TRIG_STOP
:
139 str2
= "TRIG_STOP"; break;
140 case SOF_IPC_STREAM_TRIG_PAUSE
:
141 str2
= "TRIG_PAUSE"; break;
142 case SOF_IPC_STREAM_TRIG_RELEASE
:
143 str2
= "TRIG_RELEASE"; break;
144 case SOF_IPC_STREAM_TRIG_DRAIN
:
145 str2
= "TRIG_DRAIN"; break;
146 case SOF_IPC_STREAM_TRIG_XRUN
:
147 str2
= "TRIG_XRUN"; break;
148 case SOF_IPC_STREAM_POSITION
:
149 str2
= "POSITION"; break;
150 case SOF_IPC_STREAM_VORBIS_PARAMS
:
151 str2
= "VORBIS_PARAMS"; break;
152 case SOF_IPC_STREAM_VORBIS_FREE
:
153 str2
= "VORBIS_FREE"; break;
155 str2
= "unknown type"; break;
158 case SOF_IPC_FW_READY
:
159 str
= "FW_READY"; break;
160 case SOF_IPC_GLB_DAI_MSG
:
163 case SOF_IPC_DAI_CONFIG
:
164 str2
= "CONFIG"; break;
165 case SOF_IPC_DAI_LOOPBACK
:
166 str2
= "LOOPBACK"; break;
168 str2
= "unknown type"; break;
171 case SOF_IPC_GLB_TRACE_MSG
:
172 str
= "GLB_TRACE_MSG"; break;
173 case SOF_IPC_GLB_TEST_MSG
:
174 str
= "GLB_TEST_MSG";
176 case SOF_IPC_TEST_IPC_FLOOD
:
177 str2
= "IPC_FLOOD"; break;
179 str2
= "unknown type"; break;
183 str
= "unknown GLB command"; break;
187 dev_dbg(dev
, "%s: 0x%x: %s: %s\n", text
, cmd
, str
, str2
);
189 dev_dbg(dev
, "%s: 0x%x: %s\n", text
, cmd
, str
);
192 static inline void ipc_log_header(struct device
*dev
, u8
*text
, u32 cmd
)
194 if ((cmd
& SOF_GLB_TYPE_MASK
) != SOF_IPC_GLB_TRACE_MSG
)
195 dev_dbg(dev
, "%s: 0x%x\n", text
, cmd
);
199 /* wait for IPC message reply */
200 static int tx_wait_done(struct snd_sof_ipc
*ipc
, struct snd_sof_ipc_msg
*msg
,
203 struct snd_sof_dev
*sdev
= ipc
->sdev
;
204 struct sof_ipc_cmd_hdr
*hdr
= msg
->msg_data
;
207 /* wait for DSP IPC completion */
208 ret
= wait_event_timeout(msg
->waitq
, msg
->ipc_complete
,
209 msecs_to_jiffies(sdev
->ipc_timeout
));
212 dev_err(sdev
->dev
, "error: ipc timed out for 0x%x size %d\n",
213 hdr
->cmd
, hdr
->size
);
214 snd_sof_handle_fw_exception(ipc
->sdev
);
217 /* copy the data returned from DSP */
218 ret
= msg
->reply_error
;
220 memcpy(reply_data
, msg
->reply_data
, msg
->reply_size
);
222 dev_err(sdev
->dev
, "error: ipc error for 0x%x size %zu\n",
223 hdr
->cmd
, msg
->reply_size
);
225 ipc_log_header(sdev
->dev
, "ipc tx succeeded", hdr
->cmd
);
231 /* send IPC message from host to DSP */
232 static int sof_ipc_tx_message_unlocked(struct snd_sof_ipc
*ipc
, u32 header
,
233 void *msg_data
, size_t msg_bytes
,
234 void *reply_data
, size_t reply_bytes
)
236 struct snd_sof_dev
*sdev
= ipc
->sdev
;
237 struct snd_sof_ipc_msg
*msg
;
240 if (ipc
->disable_ipc_tx
)
244 * The spin-lock is also still needed to protect message objects against
245 * other atomic contexts.
247 spin_lock_irq(&sdev
->ipc_lock
);
249 /* initialise the message */
252 msg
->header
= header
;
253 msg
->msg_size
= msg_bytes
;
254 msg
->reply_size
= reply_bytes
;
255 msg
->reply_error
= 0;
257 /* attach any data */
259 memcpy(msg
->msg_data
, msg_data
, msg_bytes
);
263 ret
= snd_sof_dsp_send_msg(sdev
, msg
);
264 /* Next reply that we receive will be related to this message */
266 msg
->ipc_complete
= false;
268 spin_unlock_irq(&sdev
->ipc_lock
);
271 /* So far IPC TX never fails, consider making the above void */
272 dev_err_ratelimited(sdev
->dev
,
273 "error: ipc tx failed with error %d\n",
278 ipc_log_header(sdev
->dev
, "ipc tx", msg
->header
);
280 /* now wait for completion */
282 ret
= tx_wait_done(ipc
, msg
, reply_data
);
287 /* send IPC message from host to DSP */
288 int sof_ipc_tx_message(struct snd_sof_ipc
*ipc
, u32 header
,
289 void *msg_data
, size_t msg_bytes
, void *reply_data
,
294 if (msg_bytes
> SOF_IPC_MSG_MAX_SIZE
||
295 reply_bytes
> SOF_IPC_MSG_MAX_SIZE
)
298 /* Serialise IPC TX */
299 mutex_lock(&ipc
->tx_mutex
);
301 ret
= sof_ipc_tx_message_unlocked(ipc
, header
, msg_data
, msg_bytes
,
302 reply_data
, reply_bytes
);
304 mutex_unlock(&ipc
->tx_mutex
);
308 EXPORT_SYMBOL(sof_ipc_tx_message
);
310 /* handle reply message from DSP */
311 int snd_sof_ipc_reply(struct snd_sof_dev
*sdev
, u32 msg_id
)
313 struct snd_sof_ipc_msg
*msg
= &sdev
->ipc
->msg
;
315 if (msg
->ipc_complete
) {
316 dev_err(sdev
->dev
, "error: no reply expected, received 0x%x",
321 /* wake up and return the error if we have waiters on this message ? */
322 msg
->ipc_complete
= true;
323 wake_up(&msg
->waitq
);
327 EXPORT_SYMBOL(snd_sof_ipc_reply
);
329 /* DSP firmware has sent host a message */
330 void snd_sof_ipc_msgs_rx(struct snd_sof_dev
*sdev
)
332 struct sof_ipc_cmd_hdr hdr
;
336 /* read back header */
337 snd_sof_ipc_msg_data(sdev
, NULL
, &hdr
, sizeof(hdr
));
338 ipc_log_header(sdev
->dev
, "ipc rx", hdr
.cmd
);
340 cmd
= hdr
.cmd
& SOF_GLB_TYPE_MASK
;
341 type
= hdr
.cmd
& SOF_CMD_TYPE_MASK
;
343 /* check message type */
345 case SOF_IPC_GLB_REPLY
:
346 dev_err(sdev
->dev
, "error: ipc reply unknown\n");
348 case SOF_IPC_FW_READY
:
349 /* check for FW boot completion */
350 if (sdev
->fw_state
== SOF_FW_BOOT_IN_PROGRESS
) {
351 err
= sof_ops(sdev
)->fw_ready(sdev
, cmd
);
353 sdev
->fw_state
= SOF_FW_BOOT_READY_FAILED
;
355 sdev
->fw_state
= SOF_FW_BOOT_COMPLETE
;
357 /* wake up firmware loader */
358 wake_up(&sdev
->boot_wait
);
361 case SOF_IPC_GLB_COMPOUND
:
362 case SOF_IPC_GLB_TPLG_MSG
:
363 case SOF_IPC_GLB_PM_MSG
:
364 case SOF_IPC_GLB_COMP_MSG
:
366 case SOF_IPC_GLB_STREAM_MSG
:
367 /* need to pass msg id into the function */
368 ipc_stream_message(sdev
, hdr
.cmd
);
370 case SOF_IPC_GLB_TRACE_MSG
:
371 ipc_trace_message(sdev
, type
);
374 dev_err(sdev
->dev
, "error: unknown DSP message 0x%x\n", cmd
);
378 ipc_log_header(sdev
->dev
, "ipc rx done", hdr
.cmd
);
380 EXPORT_SYMBOL(snd_sof_ipc_msgs_rx
);
383 * IPC trace mechanism.
386 static void ipc_trace_message(struct snd_sof_dev
*sdev
, u32 msg_id
)
388 struct sof_ipc_dma_trace_posn posn
;
391 case SOF_IPC_TRACE_DMA_POSITION
:
392 /* read back full message */
393 snd_sof_ipc_msg_data(sdev
, NULL
, &posn
, sizeof(posn
));
394 snd_sof_trace_update_pos(sdev
, &posn
);
397 dev_err(sdev
->dev
, "error: unhandled trace message %x\n",
404 * IPC stream position.
407 static void ipc_period_elapsed(struct snd_sof_dev
*sdev
, u32 msg_id
)
409 struct snd_soc_component
*scomp
= sdev
->component
;
410 struct snd_sof_pcm_stream
*stream
;
411 struct sof_ipc_stream_posn posn
;
412 struct snd_sof_pcm
*spcm
;
415 spcm
= snd_sof_find_spcm_comp(scomp
, msg_id
, &direction
);
418 "error: period elapsed for unknown stream, msg_id %d\n",
423 stream
= &spcm
->stream
[direction
];
424 snd_sof_ipc_msg_data(sdev
, stream
->substream
, &posn
, sizeof(posn
));
426 dev_dbg(sdev
->dev
, "posn : host 0x%llx dai 0x%llx wall 0x%llx\n",
427 posn
.host_posn
, posn
.dai_posn
, posn
.wallclock
);
429 memcpy(&stream
->posn
, &posn
, sizeof(posn
));
431 /* only inform ALSA for period_wakeup mode */
432 if (!stream
->substream
->runtime
->no_period_wakeup
)
433 snd_sof_pcm_period_elapsed(stream
->substream
);
436 /* DSP notifies host of an XRUN within FW */
437 static void ipc_xrun(struct snd_sof_dev
*sdev
, u32 msg_id
)
439 struct snd_soc_component
*scomp
= sdev
->component
;
440 struct snd_sof_pcm_stream
*stream
;
441 struct sof_ipc_stream_posn posn
;
442 struct snd_sof_pcm
*spcm
;
445 spcm
= snd_sof_find_spcm_comp(scomp
, msg_id
, &direction
);
447 dev_err(sdev
->dev
, "error: XRUN for unknown stream, msg_id %d\n",
452 stream
= &spcm
->stream
[direction
];
453 snd_sof_ipc_msg_data(sdev
, stream
->substream
, &posn
, sizeof(posn
));
455 dev_dbg(sdev
->dev
, "posn XRUN: host %llx comp %d size %d\n",
456 posn
.host_posn
, posn
.xrun_comp_id
, posn
.xrun_size
);
458 #if defined(CONFIG_SND_SOC_SOF_DEBUG_XRUN_STOP)
459 /* stop PCM on XRUN - used for pipeline debug */
460 memcpy(&stream
->posn
, &posn
, sizeof(posn
));
461 snd_pcm_stop_xrun(stream
->substream
);
465 /* stream notifications from DSP FW */
466 static void ipc_stream_message(struct snd_sof_dev
*sdev
, u32 msg_cmd
)
468 /* get msg cmd type and msd id */
469 u32 msg_type
= msg_cmd
& SOF_CMD_TYPE_MASK
;
470 u32 msg_id
= SOF_IPC_MESSAGE_ID(msg_cmd
);
473 case SOF_IPC_STREAM_POSITION
:
474 ipc_period_elapsed(sdev
, msg_id
);
476 case SOF_IPC_STREAM_TRIG_XRUN
:
477 ipc_xrun(sdev
, msg_id
);
480 dev_err(sdev
->dev
, "error: unhandled stream message %x\n",
486 /* get stream position IPC - use faster MMIO method if available on platform */
487 int snd_sof_ipc_stream_posn(struct snd_soc_component
*scomp
,
488 struct snd_sof_pcm
*spcm
, int direction
,
489 struct sof_ipc_stream_posn
*posn
)
491 struct snd_sof_dev
*sdev
= snd_soc_component_get_drvdata(scomp
);
492 struct sof_ipc_stream stream
;
495 /* read position via slower IPC */
496 stream
.hdr
.size
= sizeof(stream
);
497 stream
.hdr
.cmd
= SOF_IPC_GLB_STREAM_MSG
| SOF_IPC_STREAM_POSITION
;
498 stream
.comp_id
= spcm
->stream
[direction
].comp_id
;
500 /* send IPC to the DSP */
501 err
= sof_ipc_tx_message(sdev
->ipc
,
502 stream
.hdr
.cmd
, &stream
, sizeof(stream
), &posn
,
505 dev_err(sdev
->dev
, "error: failed to get stream %d position\n",
512 EXPORT_SYMBOL(snd_sof_ipc_stream_posn
);
514 static int sof_get_ctrl_copy_params(enum sof_ipc_ctrl_type ctrl_type
,
515 struct sof_ipc_ctrl_data
*src
,
516 struct sof_ipc_ctrl_data
*dst
,
517 struct sof_ipc_ctrl_data_params
*sparams
)
520 case SOF_CTRL_TYPE_VALUE_CHAN_GET
:
521 case SOF_CTRL_TYPE_VALUE_CHAN_SET
:
522 sparams
->src
= (u8
*)src
->chanv
;
523 sparams
->dst
= (u8
*)dst
->chanv
;
525 case SOF_CTRL_TYPE_VALUE_COMP_GET
:
526 case SOF_CTRL_TYPE_VALUE_COMP_SET
:
527 sparams
->src
= (u8
*)src
->compv
;
528 sparams
->dst
= (u8
*)dst
->compv
;
530 case SOF_CTRL_TYPE_DATA_GET
:
531 case SOF_CTRL_TYPE_DATA_SET
:
532 sparams
->src
= (u8
*)src
->data
->data
;
533 sparams
->dst
= (u8
*)dst
->data
->data
;
539 /* calculate payload size and number of messages */
540 sparams
->pl_size
= SOF_IPC_MSG_MAX_SIZE
- sparams
->hdr_bytes
;
541 sparams
->num_msg
= DIV_ROUND_UP(sparams
->msg_bytes
, sparams
->pl_size
);
546 static int sof_set_get_large_ctrl_data(struct snd_sof_dev
*sdev
,
547 struct sof_ipc_ctrl_data
*cdata
,
548 struct sof_ipc_ctrl_data_params
*sparams
,
551 struct sof_ipc_ctrl_data
*partdata
;
559 /* allocate max ipc size because we have at least one */
560 partdata
= kzalloc(SOF_IPC_MSG_MAX_SIZE
, GFP_KERNEL
);
565 err
= sof_get_ctrl_copy_params(cdata
->type
, cdata
, partdata
,
568 err
= sof_get_ctrl_copy_params(cdata
->type
, partdata
, cdata
,
575 msg_bytes
= sparams
->msg_bytes
;
576 pl_size
= sparams
->pl_size
;
578 /* copy the header data */
579 memcpy(partdata
, cdata
, sparams
->hdr_bytes
);
581 /* Serialise IPC TX */
582 mutex_lock(&sdev
->ipc
->tx_mutex
);
584 /* copy the payload data in a loop */
585 for (i
= 0; i
< sparams
->num_msg
; i
++) {
586 send_bytes
= min(msg_bytes
, pl_size
);
587 partdata
->num_elems
= send_bytes
;
588 partdata
->rhdr
.hdr
.size
= sparams
->hdr_bytes
+ send_bytes
;
589 partdata
->msg_index
= i
;
590 msg_bytes
-= send_bytes
;
591 partdata
->elems_remaining
= msg_bytes
;
594 memcpy(sparams
->dst
, sparams
->src
+ offset
, send_bytes
);
596 err
= sof_ipc_tx_message_unlocked(sdev
->ipc
,
597 partdata
->rhdr
.hdr
.cmd
,
599 partdata
->rhdr
.hdr
.size
,
601 partdata
->rhdr
.hdr
.size
);
606 memcpy(sparams
->dst
+ offset
, sparams
->src
, send_bytes
);
611 mutex_unlock(&sdev
->ipc
->tx_mutex
);
618 * IPC get()/set() for kcontrols.
620 int snd_sof_ipc_set_get_comp_data(struct snd_sof_control
*scontrol
,
622 enum sof_ipc_ctrl_type ctrl_type
,
623 enum sof_ipc_ctrl_cmd ctrl_cmd
,
626 struct snd_soc_component
*scomp
= scontrol
->scomp
;
627 struct sof_ipc_ctrl_data
*cdata
= scontrol
->control_data
;
628 struct snd_sof_dev
*sdev
= snd_soc_component_get_drvdata(scomp
);
629 struct sof_ipc_fw_ready
*ready
= &sdev
->fw_ready
;
630 struct sof_ipc_fw_version
*v
= &ready
->version
;
631 struct sof_ipc_ctrl_data_params sparams
;
635 /* read or write firmware volume */
636 if (scontrol
->readback_offset
!= 0) {
637 /* write/read value header via mmaped region */
638 send_bytes
= sizeof(struct sof_ipc_ctrl_value_chan
) *
641 snd_sof_dsp_block_write(sdev
, sdev
->mmio_bar
,
642 scontrol
->readback_offset
,
643 cdata
->chanv
, send_bytes
);
646 snd_sof_dsp_block_read(sdev
, sdev
->mmio_bar
,
647 scontrol
->readback_offset
,
648 cdata
->chanv
, send_bytes
);
652 cdata
->rhdr
.hdr
.cmd
= SOF_IPC_GLB_COMP_MSG
| ipc_cmd
;
653 cdata
->cmd
= ctrl_cmd
;
654 cdata
->type
= ctrl_type
;
655 cdata
->comp_id
= scontrol
->comp_id
;
656 cdata
->msg_index
= 0;
658 /* calculate header and data size */
659 switch (cdata
->type
) {
660 case SOF_CTRL_TYPE_VALUE_CHAN_GET
:
661 case SOF_CTRL_TYPE_VALUE_CHAN_SET
:
662 sparams
.msg_bytes
= scontrol
->num_channels
*
663 sizeof(struct sof_ipc_ctrl_value_chan
);
664 sparams
.hdr_bytes
= sizeof(struct sof_ipc_ctrl_data
);
665 sparams
.elems
= scontrol
->num_channels
;
667 case SOF_CTRL_TYPE_VALUE_COMP_GET
:
668 case SOF_CTRL_TYPE_VALUE_COMP_SET
:
669 sparams
.msg_bytes
= scontrol
->num_channels
*
670 sizeof(struct sof_ipc_ctrl_value_comp
);
671 sparams
.hdr_bytes
= sizeof(struct sof_ipc_ctrl_data
);
672 sparams
.elems
= scontrol
->num_channels
;
674 case SOF_CTRL_TYPE_DATA_GET
:
675 case SOF_CTRL_TYPE_DATA_SET
:
676 sparams
.msg_bytes
= cdata
->data
->size
;
677 sparams
.hdr_bytes
= sizeof(struct sof_ipc_ctrl_data
) +
678 sizeof(struct sof_abi_hdr
);
679 sparams
.elems
= cdata
->data
->size
;
685 cdata
->rhdr
.hdr
.size
= sparams
.msg_bytes
+ sparams
.hdr_bytes
;
686 cdata
->num_elems
= sparams
.elems
;
687 cdata
->elems_remaining
= 0;
689 /* send normal size ipc in one part */
690 if (cdata
->rhdr
.hdr
.size
<= SOF_IPC_MSG_MAX_SIZE
) {
691 err
= sof_ipc_tx_message(sdev
->ipc
, cdata
->rhdr
.hdr
.cmd
, cdata
,
692 cdata
->rhdr
.hdr
.size
, cdata
,
693 cdata
->rhdr
.hdr
.size
);
696 dev_err(sdev
->dev
, "error: set/get ctrl ipc comp %d\n",
702 /* data is bigger than max ipc size, chop into smaller pieces */
703 dev_dbg(sdev
->dev
, "large ipc size %u, control size %u\n",
704 cdata
->rhdr
.hdr
.size
, scontrol
->size
);
706 /* large messages is only supported from ABI 3.3.0 onwards */
707 if (v
->abi_version
< SOF_ABI_VER(3, 3, 0)) {
708 dev_err(sdev
->dev
, "error: incompatible FW ABI version\n");
712 err
= sof_set_get_large_ctrl_data(sdev
, cdata
, &sparams
, send
);
715 dev_err(sdev
->dev
, "error: set/get large ctrl ipc comp %d\n",
720 EXPORT_SYMBOL(snd_sof_ipc_set_get_comp_data
);
723 * IPC layer enumeration.
726 int snd_sof_dsp_mailbox_init(struct snd_sof_dev
*sdev
, u32 dspbox
,
727 size_t dspbox_size
, u32 hostbox
,
730 sdev
->dsp_box
.offset
= dspbox
;
731 sdev
->dsp_box
.size
= dspbox_size
;
732 sdev
->host_box
.offset
= hostbox
;
733 sdev
->host_box
.size
= hostbox_size
;
736 EXPORT_SYMBOL(snd_sof_dsp_mailbox_init
);
738 int snd_sof_ipc_valid(struct snd_sof_dev
*sdev
)
740 struct sof_ipc_fw_ready
*ready
= &sdev
->fw_ready
;
741 struct sof_ipc_fw_version
*v
= &ready
->version
;
744 "Firmware info: version %d:%d:%d-%s\n", v
->major
, v
->minor
,
747 "Firmware: ABI %d:%d:%d Kernel ABI %d:%d:%d\n",
748 SOF_ABI_VERSION_MAJOR(v
->abi_version
),
749 SOF_ABI_VERSION_MINOR(v
->abi_version
),
750 SOF_ABI_VERSION_PATCH(v
->abi_version
),
751 SOF_ABI_MAJOR
, SOF_ABI_MINOR
, SOF_ABI_PATCH
);
753 if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION
, v
->abi_version
)) {
754 dev_err(sdev
->dev
, "error: incompatible FW ABI version\n");
758 if (v
->abi_version
> SOF_ABI_VERSION
) {
759 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS
)) {
760 dev_warn(sdev
->dev
, "warn: FW ABI is more recent than kernel\n");
762 dev_err(sdev
->dev
, "error: FW ABI is more recent than kernel\n");
767 if (ready
->flags
& SOF_IPC_INFO_BUILD
) {
769 "Firmware debug build %d on %s-%s - options:\n"
772 " lock vdebug: %s\n",
773 v
->build
, v
->date
, v
->time
,
774 (ready
->flags
& SOF_IPC_INFO_GDB
) ?
775 "enabled" : "disabled",
776 (ready
->flags
& SOF_IPC_INFO_LOCKS
) ?
777 "enabled" : "disabled",
778 (ready
->flags
& SOF_IPC_INFO_LOCKSV
) ?
779 "enabled" : "disabled");
782 /* copy the fw_version into debugfs at first boot */
783 memcpy(&sdev
->fw_version
, v
, sizeof(*v
));
787 EXPORT_SYMBOL(snd_sof_ipc_valid
);
789 struct snd_sof_ipc
*snd_sof_ipc_init(struct snd_sof_dev
*sdev
)
791 struct snd_sof_ipc
*ipc
;
792 struct snd_sof_ipc_msg
*msg
;
794 ipc
= devm_kzalloc(sdev
->dev
, sizeof(*ipc
), GFP_KERNEL
);
798 mutex_init(&ipc
->tx_mutex
);
802 /* indicate that we aren't sending a message ATM */
803 msg
->ipc_complete
= true;
805 /* pre-allocate message data */
806 msg
->msg_data
= devm_kzalloc(sdev
->dev
, SOF_IPC_MSG_MAX_SIZE
,
811 msg
->reply_data
= devm_kzalloc(sdev
->dev
, SOF_IPC_MSG_MAX_SIZE
,
813 if (!msg
->reply_data
)
816 init_waitqueue_head(&msg
->waitq
);
820 EXPORT_SYMBOL(snd_sof_ipc_init
);
822 void snd_sof_ipc_free(struct snd_sof_dev
*sdev
)
824 struct snd_sof_ipc
*ipc
= sdev
->ipc
;
829 /* disable sending of ipc's */
830 mutex_lock(&ipc
->tx_mutex
);
831 ipc
->disable_ipc_tx
= true;
832 mutex_unlock(&ipc
->tx_mutex
);
834 EXPORT_SYMBOL(snd_sof_ipc_free
);