1 // SPDX-License-Identifier: (GPL-2.0-only 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_type);
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)
59 glb = cmd & SOF_GLB_TYPE_MASK;
60 type = cmd & SOF_CMD_TYPE_MASK;
63 case SOF_IPC_GLB_REPLY:
64 str = "GLB_REPLY"; break;
65 case SOF_IPC_GLB_COMPOUND:
66 str = "GLB_COMPOUND"; break;
67 case SOF_IPC_GLB_TPLG_MSG:
70 case SOF_IPC_TPLG_COMP_NEW:
71 str2 = "COMP_NEW"; break;
72 case SOF_IPC_TPLG_COMP_FREE:
73 str2 = "COMP_FREE"; break;
74 case SOF_IPC_TPLG_COMP_CONNECT:
75 str2 = "COMP_CONNECT"; break;
76 case SOF_IPC_TPLG_PIPE_NEW:
77 str2 = "PIPE_NEW"; break;
78 case SOF_IPC_TPLG_PIPE_FREE:
79 str2 = "PIPE_FREE"; break;
80 case SOF_IPC_TPLG_PIPE_CONNECT:
81 str2 = "PIPE_CONNECT"; break;
82 case SOF_IPC_TPLG_PIPE_COMPLETE:
83 str2 = "PIPE_COMPLETE"; break;
84 case SOF_IPC_TPLG_BUFFER_NEW:
85 str2 = "BUFFER_NEW"; break;
86 case SOF_IPC_TPLG_BUFFER_FREE:
87 str2 = "BUFFER_FREE"; break;
89 str2 = "unknown type"; break;
92 case SOF_IPC_GLB_PM_MSG:
95 case SOF_IPC_PM_CTX_SAVE:
96 str2 = "CTX_SAVE"; break;
97 case SOF_IPC_PM_CTX_RESTORE:
98 str2 = "CTX_RESTORE"; break;
99 case SOF_IPC_PM_CTX_SIZE:
100 str2 = "CTX_SIZE"; break;
101 case SOF_IPC_PM_CLK_SET:
102 str2 = "CLK_SET"; break;
103 case SOF_IPC_PM_CLK_GET:
104 str2 = "CLK_GET"; break;
105 case SOF_IPC_PM_CLK_REQ:
106 str2 = "CLK_REQ"; break;
107 case SOF_IPC_PM_CORE_ENABLE:
108 str2 = "CORE_ENABLE"; break;
109 case SOF_IPC_PM_GATE:
110 str2 = "GATE"; break;
112 str2 = "unknown type"; break;
115 case SOF_IPC_GLB_COMP_MSG:
116 str = "GLB_COMP_MSG";
118 case SOF_IPC_COMP_SET_VALUE:
119 str2 = "SET_VALUE"; break;
120 case SOF_IPC_COMP_GET_VALUE:
121 str2 = "GET_VALUE"; break;
122 case SOF_IPC_COMP_SET_DATA:
123 str2 = "SET_DATA"; break;
124 case SOF_IPC_COMP_GET_DATA:
125 str2 = "GET_DATA"; break;
127 str2 = "unknown type"; break;
130 case SOF_IPC_GLB_STREAM_MSG:
131 str = "GLB_STREAM_MSG";
133 case SOF_IPC_STREAM_PCM_PARAMS:
134 str2 = "PCM_PARAMS"; break;
135 case SOF_IPC_STREAM_PCM_PARAMS_REPLY:
136 str2 = "PCM_REPLY"; break;
137 case SOF_IPC_STREAM_PCM_FREE:
138 str2 = "PCM_FREE"; break;
139 case SOF_IPC_STREAM_TRIG_START:
140 str2 = "TRIG_START"; break;
141 case SOF_IPC_STREAM_TRIG_STOP:
142 str2 = "TRIG_STOP"; break;
143 case SOF_IPC_STREAM_TRIG_PAUSE:
144 str2 = "TRIG_PAUSE"; break;
145 case SOF_IPC_STREAM_TRIG_RELEASE:
146 str2 = "TRIG_RELEASE"; break;
147 case SOF_IPC_STREAM_TRIG_DRAIN:
148 str2 = "TRIG_DRAIN"; break;
149 case SOF_IPC_STREAM_TRIG_XRUN:
150 str2 = "TRIG_XRUN"; break;
151 case SOF_IPC_STREAM_POSITION:
153 str2 = "POSITION"; break;
154 case SOF_IPC_STREAM_VORBIS_PARAMS:
155 str2 = "VORBIS_PARAMS"; break;
156 case SOF_IPC_STREAM_VORBIS_FREE:
157 str2 = "VORBIS_FREE"; break;
159 str2 = "unknown type"; break;
162 case SOF_IPC_FW_READY:
163 str = "FW_READY"; break;
164 case SOF_IPC_GLB_DAI_MSG:
167 case SOF_IPC_DAI_CONFIG:
168 str2 = "CONFIG"; break;
169 case SOF_IPC_DAI_LOOPBACK:
170 str2 = "LOOPBACK"; break;
172 str2 = "unknown type"; break;
175 case SOF_IPC_GLB_TRACE_MSG:
176 str = "GLB_TRACE_MSG"; break;
177 case SOF_IPC_GLB_TEST_MSG:
178 str = "GLB_TEST_MSG";
180 case SOF_IPC_TEST_IPC_FLOOD:
181 str2 = "IPC_FLOOD"; break;
183 str2 = "unknown type"; break;
186 case SOF_IPC_GLB_DEBUG:
189 case SOF_IPC_DEBUG_MEM_USAGE:
190 str2 = "MEM_USAGE"; break;
192 str2 = "unknown type"; break;
195 case SOF_IPC_GLB_PROBE:
198 case SOF_IPC_PROBE_INIT:
199 str2 = "INIT"; break;
200 case SOF_IPC_PROBE_DEINIT:
201 str2 = "DEINIT"; break;
202 case SOF_IPC_PROBE_DMA_ADD:
203 str2 = "DMA_ADD"; break;
204 case SOF_IPC_PROBE_DMA_INFO:
205 str2 = "DMA_INFO"; break;
206 case SOF_IPC_PROBE_DMA_REMOVE:
207 str2 = "DMA_REMOVE"; break;
208 case SOF_IPC_PROBE_POINT_ADD:
209 str2 = "POINT_ADD"; break;
210 case SOF_IPC_PROBE_POINT_INFO:
211 str2 = "POINT_INFO"; break;
212 case SOF_IPC_PROBE_POINT_REMOVE:
213 str2 = "POINT_REMOVE"; break;
215 str2 = "unknown type"; break;
219 str = "unknown GLB command"; break;
224 dev_vdbg(dev, "%s: 0x%x: %s: %s\n", text, cmd, str, str2);
226 dev_dbg(dev, "%s: 0x%x: %s: %s\n", text, cmd, str, str2);
228 dev_dbg(dev, "%s: 0x%x: %s\n", text, cmd, str);
232 static inline void ipc_log_header(struct device *dev, u8 *text, u32 cmd)
234 if ((cmd & SOF_GLB_TYPE_MASK) != SOF_IPC_GLB_TRACE_MSG)
235 dev_dbg(dev, "%s: 0x%x\n", text, cmd);
239 /* wait for IPC message reply */
240 static int tx_wait_done(struct snd_sof_ipc *ipc, struct snd_sof_ipc_msg *msg,
243 struct snd_sof_dev *sdev = ipc->sdev;
244 struct sof_ipc_cmd_hdr *hdr = msg->msg_data;
247 /* wait for DSP IPC completion */
248 ret = wait_event_timeout(msg->waitq, msg->ipc_complete,
249 msecs_to_jiffies(sdev->ipc_timeout));
252 dev_err(sdev->dev, "error: ipc timed out for 0x%x size %d\n",
253 hdr->cmd, hdr->size);
254 snd_sof_handle_fw_exception(ipc->sdev);
257 ret = msg->reply_error;
259 dev_err(sdev->dev, "error: ipc error for 0x%x size %zu\n",
260 hdr->cmd, msg->reply_size);
262 ipc_log_header(sdev->dev, "ipc tx succeeded", hdr->cmd);
264 /* copy the data returned from DSP */
265 memcpy(reply_data, msg->reply_data,
273 /* send IPC message from host to DSP */
274 static int sof_ipc_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header,
275 void *msg_data, size_t msg_bytes,
276 void *reply_data, size_t reply_bytes)
278 struct snd_sof_dev *sdev = ipc->sdev;
279 struct snd_sof_ipc_msg *msg;
282 if (ipc->disable_ipc_tx)
286 * The spin-lock is also still needed to protect message objects against
287 * other atomic contexts.
289 spin_lock_irq(&sdev->ipc_lock);
291 /* initialise the message */
294 msg->header = header;
295 msg->msg_size = msg_bytes;
296 msg->reply_size = reply_bytes;
297 msg->reply_error = 0;
299 /* attach any data */
301 memcpy(msg->msg_data, msg_data, msg_bytes);
305 ret = snd_sof_dsp_send_msg(sdev, msg);
306 /* Next reply that we receive will be related to this message */
308 msg->ipc_complete = false;
310 spin_unlock_irq(&sdev->ipc_lock);
313 dev_err_ratelimited(sdev->dev,
314 "error: ipc tx failed with error %d\n",
319 ipc_log_header(sdev->dev, "ipc tx", msg->header);
321 /* now wait for completion */
322 return tx_wait_done(ipc, msg, reply_data);
325 /* send IPC message from host to DSP */
326 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header,
327 void *msg_data, size_t msg_bytes, void *reply_data,
330 const struct sof_dsp_power_state target_state = {
331 .state = SOF_DSP_PM_D0,
335 /* ensure the DSP is in D0 before sending a new IPC */
336 ret = snd_sof_dsp_set_power_state(ipc->sdev, &target_state);
338 dev_err(ipc->sdev->dev, "error: resuming DSP %d\n", ret);
342 return sof_ipc_tx_message_no_pm(ipc, header, msg_data, msg_bytes,
343 reply_data, reply_bytes);
345 EXPORT_SYMBOL(sof_ipc_tx_message);
348 * send IPC message from host to DSP without modifying the DSP state.
349 * This will be used for IPC's that can be handled by the DSP
350 * even in a low-power D0 substate.
352 int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header,
353 void *msg_data, size_t msg_bytes,
354 void *reply_data, size_t reply_bytes)
358 if (msg_bytes > SOF_IPC_MSG_MAX_SIZE ||
359 reply_bytes > SOF_IPC_MSG_MAX_SIZE)
362 /* Serialise IPC TX */
363 mutex_lock(&ipc->tx_mutex);
365 ret = sof_ipc_tx_message_unlocked(ipc, header, msg_data, msg_bytes,
366 reply_data, reply_bytes);
368 mutex_unlock(&ipc->tx_mutex);
372 EXPORT_SYMBOL(sof_ipc_tx_message_no_pm);
374 /* handle reply message from DSP */
375 void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id)
377 struct snd_sof_ipc_msg *msg = &sdev->ipc->msg;
379 if (msg->ipc_complete) {
381 "no reply expected, received 0x%x, will be ignored",
386 /* wake up and return the error if we have waiters on this message ? */
387 msg->ipc_complete = true;
388 wake_up(&msg->waitq);
390 EXPORT_SYMBOL(snd_sof_ipc_reply);
392 static void ipc_comp_notification(struct snd_sof_dev *sdev,
393 struct sof_ipc_cmd_hdr *hdr)
395 u32 msg_type = hdr->cmd & SOF_CMD_TYPE_MASK;
396 struct sof_ipc_ctrl_data *cdata;
399 case SOF_IPC_COMP_GET_VALUE:
400 case SOF_IPC_COMP_GET_DATA:
401 cdata = kmalloc(hdr->size, GFP_KERNEL);
405 /* read back full message */
406 snd_sof_ipc_msg_data(sdev, NULL, cdata, hdr->size);
409 dev_err(sdev->dev, "error: unhandled component message %#x\n", msg_type);
413 snd_sof_control_notify(sdev, cdata);
418 /* DSP firmware has sent host a message */
419 void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
421 struct sof_ipc_cmd_hdr hdr;
425 /* read back header */
426 snd_sof_ipc_msg_data(sdev, NULL, &hdr, sizeof(hdr));
427 ipc_log_header(sdev->dev, "ipc rx", hdr.cmd);
429 cmd = hdr.cmd & SOF_GLB_TYPE_MASK;
430 type = hdr.cmd & SOF_CMD_TYPE_MASK;
432 /* check message type */
434 case SOF_IPC_GLB_REPLY:
435 dev_err(sdev->dev, "error: ipc reply unknown\n");
437 case SOF_IPC_FW_READY:
438 /* check for FW boot completion */
439 if (sdev->fw_state == SOF_FW_BOOT_IN_PROGRESS) {
440 err = sof_ops(sdev)->fw_ready(sdev, cmd);
442 sdev->fw_state = SOF_FW_BOOT_READY_FAILED;
444 sdev->fw_state = SOF_FW_BOOT_COMPLETE;
446 /* wake up firmware loader */
447 wake_up(&sdev->boot_wait);
450 case SOF_IPC_GLB_COMPOUND:
451 case SOF_IPC_GLB_TPLG_MSG:
452 case SOF_IPC_GLB_PM_MSG:
454 case SOF_IPC_GLB_COMP_MSG:
455 ipc_comp_notification(sdev, &hdr);
457 case SOF_IPC_GLB_STREAM_MSG:
458 /* need to pass msg id into the function */
459 ipc_stream_message(sdev, hdr.cmd);
461 case SOF_IPC_GLB_TRACE_MSG:
462 ipc_trace_message(sdev, type);
465 dev_err(sdev->dev, "error: unknown DSP message 0x%x\n", cmd);
469 ipc_log_header(sdev->dev, "ipc rx done", hdr.cmd);
471 EXPORT_SYMBOL(snd_sof_ipc_msgs_rx);
474 * IPC trace mechanism.
477 static void ipc_trace_message(struct snd_sof_dev *sdev, u32 msg_type)
479 struct sof_ipc_dma_trace_posn posn;
482 case SOF_IPC_TRACE_DMA_POSITION:
483 /* read back full message */
484 snd_sof_ipc_msg_data(sdev, NULL, &posn, sizeof(posn));
485 snd_sof_trace_update_pos(sdev, &posn);
488 dev_err(sdev->dev, "error: unhandled trace message %#x\n", msg_type);
494 * IPC stream position.
497 static void ipc_period_elapsed(struct snd_sof_dev *sdev, u32 msg_id)
499 struct snd_soc_component *scomp = sdev->component;
500 struct snd_sof_pcm_stream *stream;
501 struct sof_ipc_stream_posn posn;
502 struct snd_sof_pcm *spcm;
505 spcm = snd_sof_find_spcm_comp(scomp, msg_id, &direction);
508 "error: period elapsed for unknown stream, msg_id %d\n",
513 stream = &spcm->stream[direction];
514 snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn));
516 dev_vdbg(sdev->dev, "posn : host 0x%llx dai 0x%llx wall 0x%llx\n",
517 posn.host_posn, posn.dai_posn, posn.wallclock);
519 memcpy(&stream->posn, &posn, sizeof(posn));
521 /* only inform ALSA for period_wakeup mode */
522 if (!stream->substream->runtime->no_period_wakeup)
523 snd_sof_pcm_period_elapsed(stream->substream);
526 /* DSP notifies host of an XRUN within FW */
527 static void ipc_xrun(struct snd_sof_dev *sdev, u32 msg_id)
529 struct snd_soc_component *scomp = sdev->component;
530 struct snd_sof_pcm_stream *stream;
531 struct sof_ipc_stream_posn posn;
532 struct snd_sof_pcm *spcm;
535 spcm = snd_sof_find_spcm_comp(scomp, msg_id, &direction);
537 dev_err(sdev->dev, "error: XRUN for unknown stream, msg_id %d\n",
542 stream = &spcm->stream[direction];
543 snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn));
545 dev_dbg(sdev->dev, "posn XRUN: host %llx comp %d size %d\n",
546 posn.host_posn, posn.xrun_comp_id, posn.xrun_size);
548 #if defined(CONFIG_SND_SOC_SOF_DEBUG_XRUN_STOP)
549 /* stop PCM on XRUN - used for pipeline debug */
550 memcpy(&stream->posn, &posn, sizeof(posn));
551 snd_pcm_stop_xrun(stream->substream);
555 /* stream notifications from DSP FW */
556 static void ipc_stream_message(struct snd_sof_dev *sdev, u32 msg_cmd)
558 /* get msg cmd type and msd id */
559 u32 msg_type = msg_cmd & SOF_CMD_TYPE_MASK;
560 u32 msg_id = SOF_IPC_MESSAGE_ID(msg_cmd);
563 case SOF_IPC_STREAM_POSITION:
564 ipc_period_elapsed(sdev, msg_id);
566 case SOF_IPC_STREAM_TRIG_XRUN:
567 ipc_xrun(sdev, msg_id);
570 dev_err(sdev->dev, "error: unhandled stream message %#x\n",
576 /* get stream position IPC - use faster MMIO method if available on platform */
577 int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
578 struct snd_sof_pcm *spcm, int direction,
579 struct sof_ipc_stream_posn *posn)
581 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
582 struct sof_ipc_stream stream;
585 /* read position via slower IPC */
586 stream.hdr.size = sizeof(stream);
587 stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_POSITION;
588 stream.comp_id = spcm->stream[direction].comp_id;
590 /* send IPC to the DSP */
591 err = sof_ipc_tx_message(sdev->ipc,
592 stream.hdr.cmd, &stream, sizeof(stream), posn,
595 dev_err(sdev->dev, "error: failed to get stream %d position\n",
602 EXPORT_SYMBOL(snd_sof_ipc_stream_posn);
604 static int sof_get_ctrl_copy_params(enum sof_ipc_ctrl_type ctrl_type,
605 struct sof_ipc_ctrl_data *src,
606 struct sof_ipc_ctrl_data *dst,
607 struct sof_ipc_ctrl_data_params *sparams)
610 case SOF_CTRL_TYPE_VALUE_CHAN_GET:
611 case SOF_CTRL_TYPE_VALUE_CHAN_SET:
612 sparams->src = (u8 *)src->chanv;
613 sparams->dst = (u8 *)dst->chanv;
615 case SOF_CTRL_TYPE_VALUE_COMP_GET:
616 case SOF_CTRL_TYPE_VALUE_COMP_SET:
617 sparams->src = (u8 *)src->compv;
618 sparams->dst = (u8 *)dst->compv;
620 case SOF_CTRL_TYPE_DATA_GET:
621 case SOF_CTRL_TYPE_DATA_SET:
622 sparams->src = (u8 *)src->data->data;
623 sparams->dst = (u8 *)dst->data->data;
629 /* calculate payload size and number of messages */
630 sparams->pl_size = SOF_IPC_MSG_MAX_SIZE - sparams->hdr_bytes;
631 sparams->num_msg = DIV_ROUND_UP(sparams->msg_bytes, sparams->pl_size);
636 static int sof_set_get_large_ctrl_data(struct snd_sof_dev *sdev,
637 struct sof_ipc_ctrl_data *cdata,
638 struct sof_ipc_ctrl_data_params *sparams,
641 struct sof_ipc_ctrl_data *partdata;
649 /* allocate max ipc size because we have at least one */
650 partdata = kzalloc(SOF_IPC_MSG_MAX_SIZE, GFP_KERNEL);
655 err = sof_get_ctrl_copy_params(cdata->type, cdata, partdata,
658 err = sof_get_ctrl_copy_params(cdata->type, partdata, cdata,
665 msg_bytes = sparams->msg_bytes;
666 pl_size = sparams->pl_size;
668 /* copy the header data */
669 memcpy(partdata, cdata, sparams->hdr_bytes);
671 /* Serialise IPC TX */
672 mutex_lock(&sdev->ipc->tx_mutex);
674 /* copy the payload data in a loop */
675 for (i = 0; i < sparams->num_msg; i++) {
676 send_bytes = min(msg_bytes, pl_size);
677 partdata->num_elems = send_bytes;
678 partdata->rhdr.hdr.size = sparams->hdr_bytes + send_bytes;
679 partdata->msg_index = i;
680 msg_bytes -= send_bytes;
681 partdata->elems_remaining = msg_bytes;
684 memcpy(sparams->dst, sparams->src + offset, send_bytes);
686 err = sof_ipc_tx_message_unlocked(sdev->ipc,
687 partdata->rhdr.hdr.cmd,
689 partdata->rhdr.hdr.size,
691 partdata->rhdr.hdr.size);
696 memcpy(sparams->dst + offset, sparams->src, send_bytes);
701 mutex_unlock(&sdev->ipc->tx_mutex);
708 * IPC get()/set() for kcontrols.
710 int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol,
712 enum sof_ipc_ctrl_type ctrl_type,
713 enum sof_ipc_ctrl_cmd ctrl_cmd,
716 struct snd_soc_component *scomp = scontrol->scomp;
717 struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
718 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
719 struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
720 struct sof_ipc_fw_version *v = &ready->version;
721 struct sof_ipc_ctrl_data_params sparams;
725 /* read or write firmware volume */
726 if (scontrol->readback_offset != 0) {
727 /* write/read value header via mmaped region */
728 send_bytes = sizeof(struct sof_ipc_ctrl_value_chan) *
731 err = snd_sof_dsp_block_write(sdev, SOF_FW_BLK_TYPE_IRAM,
732 scontrol->readback_offset,
733 cdata->chanv, send_bytes);
736 err = snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_IRAM,
737 scontrol->readback_offset,
738 cdata->chanv, send_bytes);
741 dev_err_once(sdev->dev, "error: %s TYPE_IRAM failed\n",
742 send ? "write to" : "read from");
746 cdata->rhdr.hdr.cmd = SOF_IPC_GLB_COMP_MSG | ipc_cmd;
747 cdata->cmd = ctrl_cmd;
748 cdata->type = ctrl_type;
749 cdata->comp_id = scontrol->comp_id;
750 cdata->msg_index = 0;
752 /* calculate header and data size */
753 switch (cdata->type) {
754 case SOF_CTRL_TYPE_VALUE_CHAN_GET:
755 case SOF_CTRL_TYPE_VALUE_CHAN_SET:
756 sparams.msg_bytes = scontrol->num_channels *
757 sizeof(struct sof_ipc_ctrl_value_chan);
758 sparams.hdr_bytes = sizeof(struct sof_ipc_ctrl_data);
759 sparams.elems = scontrol->num_channels;
761 case SOF_CTRL_TYPE_VALUE_COMP_GET:
762 case SOF_CTRL_TYPE_VALUE_COMP_SET:
763 sparams.msg_bytes = scontrol->num_channels *
764 sizeof(struct sof_ipc_ctrl_value_comp);
765 sparams.hdr_bytes = sizeof(struct sof_ipc_ctrl_data);
766 sparams.elems = scontrol->num_channels;
768 case SOF_CTRL_TYPE_DATA_GET:
769 case SOF_CTRL_TYPE_DATA_SET:
770 sparams.msg_bytes = cdata->data->size;
771 sparams.hdr_bytes = sizeof(struct sof_ipc_ctrl_data) +
772 sizeof(struct sof_abi_hdr);
773 sparams.elems = cdata->data->size;
779 cdata->rhdr.hdr.size = sparams.msg_bytes + sparams.hdr_bytes;
780 cdata->num_elems = sparams.elems;
781 cdata->elems_remaining = 0;
783 /* send normal size ipc in one part */
784 if (cdata->rhdr.hdr.size <= SOF_IPC_MSG_MAX_SIZE) {
785 err = sof_ipc_tx_message(sdev->ipc, cdata->rhdr.hdr.cmd, cdata,
786 cdata->rhdr.hdr.size, cdata,
787 cdata->rhdr.hdr.size);
790 dev_err(sdev->dev, "error: set/get ctrl ipc comp %d\n",
796 /* data is bigger than max ipc size, chop into smaller pieces */
797 dev_dbg(sdev->dev, "large ipc size %u, control size %u\n",
798 cdata->rhdr.hdr.size, scontrol->size);
800 /* large messages is only supported from ABI 3.3.0 onwards */
801 if (v->abi_version < SOF_ABI_VER(3, 3, 0)) {
802 dev_err(sdev->dev, "error: incompatible FW ABI version\n");
806 err = sof_set_get_large_ctrl_data(sdev, cdata, &sparams, send);
809 dev_err(sdev->dev, "error: set/get large ctrl ipc comp %d\n",
814 EXPORT_SYMBOL(snd_sof_ipc_set_get_comp_data);
816 int snd_sof_ipc_valid(struct snd_sof_dev *sdev)
818 struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
819 struct sof_ipc_fw_version *v = &ready->version;
822 "Firmware info: version %d:%d:%d-%s\n", v->major, v->minor,
825 "Firmware: ABI %d:%d:%d Kernel ABI %d:%d:%d\n",
826 SOF_ABI_VERSION_MAJOR(v->abi_version),
827 SOF_ABI_VERSION_MINOR(v->abi_version),
828 SOF_ABI_VERSION_PATCH(v->abi_version),
829 SOF_ABI_MAJOR, SOF_ABI_MINOR, SOF_ABI_PATCH);
831 if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, v->abi_version)) {
832 dev_err(sdev->dev, "error: incompatible FW ABI version\n");
836 if (SOF_ABI_VERSION_MINOR(v->abi_version) > SOF_ABI_MINOR) {
837 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS)) {
838 dev_warn(sdev->dev, "warn: FW ABI is more recent than kernel\n");
840 dev_err(sdev->dev, "error: FW ABI is more recent than kernel\n");
845 if (ready->flags & SOF_IPC_INFO_BUILD) {
847 "Firmware debug build %d on %s-%s - options:\n"
850 " lock vdebug: %s\n",
851 v->build, v->date, v->time,
852 (ready->flags & SOF_IPC_INFO_GDB) ?
853 "enabled" : "disabled",
854 (ready->flags & SOF_IPC_INFO_LOCKS) ?
855 "enabled" : "disabled",
856 (ready->flags & SOF_IPC_INFO_LOCKSV) ?
857 "enabled" : "disabled");
860 /* copy the fw_version into debugfs at first boot */
861 memcpy(&sdev->fw_version, v, sizeof(*v));
865 EXPORT_SYMBOL(snd_sof_ipc_valid);
867 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev)
869 struct snd_sof_ipc *ipc;
870 struct snd_sof_ipc_msg *msg;
872 ipc = devm_kzalloc(sdev->dev, sizeof(*ipc), GFP_KERNEL);
876 mutex_init(&ipc->tx_mutex);
880 /* indicate that we aren't sending a message ATM */
881 msg->ipc_complete = true;
883 /* pre-allocate message data */
884 msg->msg_data = devm_kzalloc(sdev->dev, SOF_IPC_MSG_MAX_SIZE,
889 msg->reply_data = devm_kzalloc(sdev->dev, SOF_IPC_MSG_MAX_SIZE,
891 if (!msg->reply_data)
894 init_waitqueue_head(&msg->waitq);
898 EXPORT_SYMBOL(snd_sof_ipc_init);
900 void snd_sof_ipc_free(struct snd_sof_dev *sdev)
902 struct snd_sof_ipc *ipc = sdev->ipc;
907 /* disable sending of ipc's */
908 mutex_lock(&ipc->tx_mutex);
909 ipc->disable_ipc_tx = true;
910 mutex_unlock(&ipc->tx_mutex);
912 EXPORT_SYMBOL(snd_sof_ipc_free);