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;
400 case SOF_IPC_COMP_GET_VALUE:
401 case SOF_IPC_COMP_GET_DATA:
402 cdata = kmalloc(hdr->size, GFP_KERNEL);
406 /* read back full message */
407 ret = snd_sof_ipc_msg_data(sdev, NULL, cdata, hdr->size);
410 "error: failed to read component event: %d\n", ret);
415 dev_err(sdev->dev, "error: unhandled component message %#x\n", msg_type);
419 snd_sof_control_notify(sdev, cdata);
425 /* DSP firmware has sent host a message */
426 void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
428 struct sof_ipc_cmd_hdr hdr;
432 /* read back header */
433 err = snd_sof_ipc_msg_data(sdev, NULL, &hdr, sizeof(hdr));
435 dev_warn(sdev->dev, "failed to read IPC header: %d\n", err);
438 ipc_log_header(sdev->dev, "ipc rx", hdr.cmd);
440 cmd = hdr.cmd & SOF_GLB_TYPE_MASK;
441 type = hdr.cmd & SOF_CMD_TYPE_MASK;
443 /* check message type */
445 case SOF_IPC_GLB_REPLY:
446 dev_err(sdev->dev, "error: ipc reply unknown\n");
448 case SOF_IPC_FW_READY:
449 /* check for FW boot completion */
450 if (sdev->fw_state == SOF_FW_BOOT_IN_PROGRESS) {
451 err = sof_ops(sdev)->fw_ready(sdev, cmd);
453 sdev->fw_state = SOF_FW_BOOT_READY_FAILED;
455 sdev->fw_state = SOF_FW_BOOT_COMPLETE;
457 /* wake up firmware loader */
458 wake_up(&sdev->boot_wait);
461 case SOF_IPC_GLB_COMPOUND:
462 case SOF_IPC_GLB_TPLG_MSG:
463 case SOF_IPC_GLB_PM_MSG:
465 case SOF_IPC_GLB_COMP_MSG:
466 ipc_comp_notification(sdev, &hdr);
468 case SOF_IPC_GLB_STREAM_MSG:
469 /* need to pass msg id into the function */
470 ipc_stream_message(sdev, hdr.cmd);
472 case SOF_IPC_GLB_TRACE_MSG:
473 ipc_trace_message(sdev, type);
476 dev_err(sdev->dev, "error: unknown DSP message 0x%x\n", cmd);
480 ipc_log_header(sdev->dev, "ipc rx done", hdr.cmd);
482 EXPORT_SYMBOL(snd_sof_ipc_msgs_rx);
485 * IPC trace mechanism.
488 static void ipc_trace_message(struct snd_sof_dev *sdev, u32 msg_type)
490 struct sof_ipc_dma_trace_posn posn;
494 case SOF_IPC_TRACE_DMA_POSITION:
495 /* read back full message */
496 ret = snd_sof_ipc_msg_data(sdev, NULL, &posn, sizeof(posn));
498 dev_warn(sdev->dev, "failed to read trace position: %d\n", ret);
500 snd_sof_trace_update_pos(sdev, &posn);
503 dev_err(sdev->dev, "error: unhandled trace message %#x\n", msg_type);
509 * IPC stream position.
512 static void ipc_period_elapsed(struct snd_sof_dev *sdev, u32 msg_id)
514 struct snd_soc_component *scomp = sdev->component;
515 struct snd_sof_pcm_stream *stream;
516 struct sof_ipc_stream_posn posn;
517 struct snd_sof_pcm *spcm;
520 spcm = snd_sof_find_spcm_comp(scomp, msg_id, &direction);
523 "error: period elapsed for unknown stream, msg_id %d\n",
528 stream = &spcm->stream[direction];
529 ret = snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn));
531 dev_warn(sdev->dev, "failed to read stream position: %d\n", ret);
535 dev_vdbg(sdev->dev, "posn : host 0x%llx dai 0x%llx wall 0x%llx\n",
536 posn.host_posn, posn.dai_posn, posn.wallclock);
538 memcpy(&stream->posn, &posn, sizeof(posn));
540 /* only inform ALSA for period_wakeup mode */
541 if (!stream->substream->runtime->no_period_wakeup)
542 snd_sof_pcm_period_elapsed(stream->substream);
545 /* DSP notifies host of an XRUN within FW */
546 static void ipc_xrun(struct snd_sof_dev *sdev, u32 msg_id)
548 struct snd_soc_component *scomp = sdev->component;
549 struct snd_sof_pcm_stream *stream;
550 struct sof_ipc_stream_posn posn;
551 struct snd_sof_pcm *spcm;
554 spcm = snd_sof_find_spcm_comp(scomp, msg_id, &direction);
556 dev_err(sdev->dev, "error: XRUN for unknown stream, msg_id %d\n",
561 stream = &spcm->stream[direction];
562 ret = snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn));
564 dev_warn(sdev->dev, "failed to read overrun position: %d\n", ret);
568 dev_dbg(sdev->dev, "posn XRUN: host %llx comp %d size %d\n",
569 posn.host_posn, posn.xrun_comp_id, posn.xrun_size);
571 #if defined(CONFIG_SND_SOC_SOF_DEBUG_XRUN_STOP)
572 /* stop PCM on XRUN - used for pipeline debug */
573 memcpy(&stream->posn, &posn, sizeof(posn));
574 snd_pcm_stop_xrun(stream->substream);
578 /* stream notifications from DSP FW */
579 static void ipc_stream_message(struct snd_sof_dev *sdev, u32 msg_cmd)
581 /* get msg cmd type and msd id */
582 u32 msg_type = msg_cmd & SOF_CMD_TYPE_MASK;
583 u32 msg_id = SOF_IPC_MESSAGE_ID(msg_cmd);
586 case SOF_IPC_STREAM_POSITION:
587 ipc_period_elapsed(sdev, msg_id);
589 case SOF_IPC_STREAM_TRIG_XRUN:
590 ipc_xrun(sdev, msg_id);
593 dev_err(sdev->dev, "error: unhandled stream message %#x\n",
599 /* get stream position IPC - use faster MMIO method if available on platform */
600 int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
601 struct snd_sof_pcm *spcm, int direction,
602 struct sof_ipc_stream_posn *posn)
604 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
605 struct sof_ipc_stream stream;
608 /* read position via slower IPC */
609 stream.hdr.size = sizeof(stream);
610 stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_POSITION;
611 stream.comp_id = spcm->stream[direction].comp_id;
613 /* send IPC to the DSP */
614 err = sof_ipc_tx_message(sdev->ipc,
615 stream.hdr.cmd, &stream, sizeof(stream), posn,
618 dev_err(sdev->dev, "error: failed to get stream %d position\n",
625 EXPORT_SYMBOL(snd_sof_ipc_stream_posn);
627 static int sof_get_ctrl_copy_params(enum sof_ipc_ctrl_type ctrl_type,
628 struct sof_ipc_ctrl_data *src,
629 struct sof_ipc_ctrl_data *dst,
630 struct sof_ipc_ctrl_data_params *sparams)
633 case SOF_CTRL_TYPE_VALUE_CHAN_GET:
634 case SOF_CTRL_TYPE_VALUE_CHAN_SET:
635 sparams->src = (u8 *)src->chanv;
636 sparams->dst = (u8 *)dst->chanv;
638 case SOF_CTRL_TYPE_VALUE_COMP_GET:
639 case SOF_CTRL_TYPE_VALUE_COMP_SET:
640 sparams->src = (u8 *)src->compv;
641 sparams->dst = (u8 *)dst->compv;
643 case SOF_CTRL_TYPE_DATA_GET:
644 case SOF_CTRL_TYPE_DATA_SET:
645 sparams->src = (u8 *)src->data->data;
646 sparams->dst = (u8 *)dst->data->data;
652 /* calculate payload size and number of messages */
653 sparams->pl_size = SOF_IPC_MSG_MAX_SIZE - sparams->hdr_bytes;
654 sparams->num_msg = DIV_ROUND_UP(sparams->msg_bytes, sparams->pl_size);
659 static int sof_set_get_large_ctrl_data(struct snd_sof_dev *sdev,
660 struct sof_ipc_ctrl_data *cdata,
661 struct sof_ipc_ctrl_data_params *sparams,
664 struct sof_ipc_ctrl_data *partdata;
672 /* allocate max ipc size because we have at least one */
673 partdata = kzalloc(SOF_IPC_MSG_MAX_SIZE, GFP_KERNEL);
678 err = sof_get_ctrl_copy_params(cdata->type, cdata, partdata,
681 err = sof_get_ctrl_copy_params(cdata->type, partdata, cdata,
688 msg_bytes = sparams->msg_bytes;
689 pl_size = sparams->pl_size;
691 /* copy the header data */
692 memcpy(partdata, cdata, sparams->hdr_bytes);
694 /* Serialise IPC TX */
695 mutex_lock(&sdev->ipc->tx_mutex);
697 /* copy the payload data in a loop */
698 for (i = 0; i < sparams->num_msg; i++) {
699 send_bytes = min(msg_bytes, pl_size);
700 partdata->num_elems = send_bytes;
701 partdata->rhdr.hdr.size = sparams->hdr_bytes + send_bytes;
702 partdata->msg_index = i;
703 msg_bytes -= send_bytes;
704 partdata->elems_remaining = msg_bytes;
707 memcpy(sparams->dst, sparams->src + offset, send_bytes);
709 err = sof_ipc_tx_message_unlocked(sdev->ipc,
710 partdata->rhdr.hdr.cmd,
712 partdata->rhdr.hdr.size,
714 partdata->rhdr.hdr.size);
719 memcpy(sparams->dst + offset, sparams->src, send_bytes);
724 mutex_unlock(&sdev->ipc->tx_mutex);
731 * IPC get()/set() for kcontrols.
733 int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol,
735 enum sof_ipc_ctrl_type ctrl_type,
736 enum sof_ipc_ctrl_cmd ctrl_cmd,
739 struct snd_soc_component *scomp = scontrol->scomp;
740 struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
741 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
742 struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
743 struct sof_ipc_fw_version *v = &ready->version;
744 struct sof_ipc_ctrl_data_params sparams;
748 /* read or write firmware volume */
749 if (scontrol->readback_offset != 0) {
750 /* write/read value header via mmaped region */
751 send_bytes = sizeof(struct sof_ipc_ctrl_value_chan) *
754 err = snd_sof_dsp_block_write(sdev, SOF_FW_BLK_TYPE_IRAM,
755 scontrol->readback_offset,
756 cdata->chanv, send_bytes);
759 err = snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_IRAM,
760 scontrol->readback_offset,
761 cdata->chanv, send_bytes);
764 dev_err_once(sdev->dev, "error: %s TYPE_IRAM failed\n",
765 send ? "write to" : "read from");
769 cdata->rhdr.hdr.cmd = SOF_IPC_GLB_COMP_MSG | ipc_cmd;
770 cdata->cmd = ctrl_cmd;
771 cdata->type = ctrl_type;
772 cdata->comp_id = scontrol->comp_id;
773 cdata->msg_index = 0;
775 /* calculate header and data size */
776 switch (cdata->type) {
777 case SOF_CTRL_TYPE_VALUE_CHAN_GET:
778 case SOF_CTRL_TYPE_VALUE_CHAN_SET:
779 sparams.msg_bytes = scontrol->num_channels *
780 sizeof(struct sof_ipc_ctrl_value_chan);
781 sparams.hdr_bytes = sizeof(struct sof_ipc_ctrl_data);
782 sparams.elems = scontrol->num_channels;
784 case SOF_CTRL_TYPE_VALUE_COMP_GET:
785 case SOF_CTRL_TYPE_VALUE_COMP_SET:
786 sparams.msg_bytes = scontrol->num_channels *
787 sizeof(struct sof_ipc_ctrl_value_comp);
788 sparams.hdr_bytes = sizeof(struct sof_ipc_ctrl_data);
789 sparams.elems = scontrol->num_channels;
791 case SOF_CTRL_TYPE_DATA_GET:
792 case SOF_CTRL_TYPE_DATA_SET:
793 sparams.msg_bytes = cdata->data->size;
794 sparams.hdr_bytes = sizeof(struct sof_ipc_ctrl_data) +
795 sizeof(struct sof_abi_hdr);
796 sparams.elems = cdata->data->size;
802 cdata->rhdr.hdr.size = sparams.msg_bytes + sparams.hdr_bytes;
803 cdata->num_elems = sparams.elems;
804 cdata->elems_remaining = 0;
806 /* send normal size ipc in one part */
807 if (cdata->rhdr.hdr.size <= SOF_IPC_MSG_MAX_SIZE) {
808 err = sof_ipc_tx_message(sdev->ipc, cdata->rhdr.hdr.cmd, cdata,
809 cdata->rhdr.hdr.size, cdata,
810 cdata->rhdr.hdr.size);
813 dev_err(sdev->dev, "error: set/get ctrl ipc comp %d\n",
819 /* data is bigger than max ipc size, chop into smaller pieces */
820 dev_dbg(sdev->dev, "large ipc size %u, control size %u\n",
821 cdata->rhdr.hdr.size, scontrol->size);
823 /* large messages is only supported from ABI 3.3.0 onwards */
824 if (v->abi_version < SOF_ABI_VER(3, 3, 0)) {
825 dev_err(sdev->dev, "error: incompatible FW ABI version\n");
829 err = sof_set_get_large_ctrl_data(sdev, cdata, &sparams, send);
832 dev_err(sdev->dev, "error: set/get large ctrl ipc comp %d\n",
837 EXPORT_SYMBOL(snd_sof_ipc_set_get_comp_data);
839 int snd_sof_ipc_valid(struct snd_sof_dev *sdev)
841 struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
842 struct sof_ipc_fw_version *v = &ready->version;
845 "Firmware info: version %d:%d:%d-%s\n", v->major, v->minor,
848 "Firmware: ABI %d:%d:%d Kernel ABI %d:%d:%d\n",
849 SOF_ABI_VERSION_MAJOR(v->abi_version),
850 SOF_ABI_VERSION_MINOR(v->abi_version),
851 SOF_ABI_VERSION_PATCH(v->abi_version),
852 SOF_ABI_MAJOR, SOF_ABI_MINOR, SOF_ABI_PATCH);
854 if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, v->abi_version)) {
855 dev_err(sdev->dev, "error: incompatible FW ABI version\n");
859 if (SOF_ABI_VERSION_MINOR(v->abi_version) > SOF_ABI_MINOR) {
860 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS)) {
861 dev_warn(sdev->dev, "warn: FW ABI is more recent than kernel\n");
863 dev_err(sdev->dev, "error: FW ABI is more recent than kernel\n");
868 if (ready->flags & SOF_IPC_INFO_BUILD) {
870 "Firmware debug build %d on %s-%s - options:\n"
873 " lock vdebug: %s\n",
874 v->build, v->date, v->time,
875 (ready->flags & SOF_IPC_INFO_GDB) ?
876 "enabled" : "disabled",
877 (ready->flags & SOF_IPC_INFO_LOCKS) ?
878 "enabled" : "disabled",
879 (ready->flags & SOF_IPC_INFO_LOCKSV) ?
880 "enabled" : "disabled");
883 /* copy the fw_version into debugfs at first boot */
884 memcpy(&sdev->fw_version, v, sizeof(*v));
888 EXPORT_SYMBOL(snd_sof_ipc_valid);
890 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev)
892 struct snd_sof_ipc *ipc;
893 struct snd_sof_ipc_msg *msg;
895 ipc = devm_kzalloc(sdev->dev, sizeof(*ipc), GFP_KERNEL);
899 mutex_init(&ipc->tx_mutex);
903 /* indicate that we aren't sending a message ATM */
904 msg->ipc_complete = true;
906 /* pre-allocate message data */
907 msg->msg_data = devm_kzalloc(sdev->dev, SOF_IPC_MSG_MAX_SIZE,
912 msg->reply_data = devm_kzalloc(sdev->dev, SOF_IPC_MSG_MAX_SIZE,
914 if (!msg->reply_data)
917 init_waitqueue_head(&msg->waitq);
921 EXPORT_SYMBOL(snd_sof_ipc_init);
923 void snd_sof_ipc_free(struct snd_sof_dev *sdev)
925 struct snd_sof_ipc *ipc = sdev->ipc;
930 /* disable sending of ipc's */
931 mutex_lock(&ipc->tx_mutex);
932 ipc->disable_ipc_tx = true;
933 mutex_unlock(&ipc->tx_mutex);
935 EXPORT_SYMBOL(snd_sof_ipc_free);