Lines Matching +full:primary +full:- +full:dai +full:- +full:link
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
11 #include "sof-audio.h"
12 #include "sof-priv.h"
14 #include "ipc4-priv.h"
15 #include "ipc4-topology.h"
16 #include "ipc4-fw-reg.h"
19 * struct sof_ipc4_timestamp_info - IPC4 timestamp info
21 * @dai_copier: the dai copier of the pcm stream
41 * struct sof_ipc4_pcm_stream_priv - IPC4 specific private data
54 struct sof_ipc4_pcm_stream_priv *stream_priv = sps->private;
56 return stream_priv->time_info;
63 u32 primary, ipc_size;
66 if (trigger_list->count == 1)
67 return sof_ipc4_set_pipeline_state(sdev, trigger_list->pipeline_instance_ids[0],
70 primary = state;
71 primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_GLB_SET_PIPELINE_STATE);
72 primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
73 primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_FW_GEN_MSG);
74 msg.primary = primary;
80 ipc_size = sizeof(u32) * (trigger_list->count + 1);
84 return sof_ipc_tx_message_no_reply(sdev->ipc, &msg, ipc_size);
90 u32 primary;
92 dev_dbg(sdev->dev, "ipc4 set pipeline instance %d state %d", instance_id, state);
94 primary = state;
95 primary |= SOF_IPC4_GLB_PIPE_STATE_ID(instance_id);
96 primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_GLB_SET_PIPELINE_STATE);
97 primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
98 primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_FW_GEN_MSG);
100 msg.primary = primary;
102 return sof_ipc_tx_message_no_reply(sdev->ipc, &msg, 0);
110 struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
113 for (i = 0; i < trigger_list->count; i++) {
115 if (ascend && pipeline->priority < pipe_priority[i])
118 else if (!ascend && pipeline->priority > pipe_priority[i])
122 for (j = trigger_list->count - 1; j >= i; j--) {
123 trigger_list->pipeline_instance_ids[j + 1] = trigger_list->pipeline_instance_ids[j];
127 trigger_list->pipeline_instance_ids[i] = pipe_widget->instance_id;
128 trigger_list->count++;
129 pipe_priority[i] = pipeline->priority;
138 struct snd_sof_widget *pipe_widget = spipe->pipe_widget;
139 struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
141 if (pipeline->skip_during_fe_trigger && state != SOF_IPC4_PIPE_RESET)
150 if (spipe->started_count == spipe->paused_count)
156 if (!spipe->started_count && !spipe->paused_count)
162 if (spipe->paused_count == (spipe->started_count - 1))
176 struct snd_sof_widget *pipe_widget = spipe->pipe_widget;
177 struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
180 if (pipeline->skip_during_fe_trigger && state != SOF_IPC4_PIPE_RESET)
184 for (i = 0; i < trigger_list->count; i++) {
185 if (trigger_list->pipeline_instance_ids[i] == pipe_widget->instance_id) {
186 pipeline->state = state;
199 spipe->paused_count++;
207 spipe->started_count--;
217 spipe->paused_count--;
222 spipe->started_count++;
236 * +---------------+
240 * +-------+-------+
246 * +----------------+ +------v-------+ +-------------+
248 * | RUNNING <-------------+ PAUSED +--------------> + RESET |
250 * +------+---------+ RELEASE +---------+----+ +-------------+
256 * +---------------------------------+
268 * buffer on DSP and directly from there to link DMA. However, the
269 * model on SOF driver has two notional pipelines, one at host DAI,
270 * and another at link DAI. They both shall have the use_chain_dma
279 struct sof_ipc4_fw_data *ipc4_data = sdev->private;
285 stream_priv = spcm->stream[direction].private;
308 if (!stream_priv->chain_dma_allocated)
316 dev_err(sdev->dev, "Unexpected state %d", state);
317 return -EINVAL;
320 msg.primary = SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_GLB_CHAIN_DMA);
321 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
322 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_FW_GEN_MSG);
325 * To set-up the DMA chain, the host DMA ID and SCS setting
327 * the link DMA ID and fifo_size are retrieved from the link
330 for (i = 0; i < pipeline_list->count; i++) {
331 struct snd_sof_pipeline *spipe = pipeline_list->pipelines[i];
332 struct snd_sof_widget *pipe_widget = spipe->pipe_widget;
333 struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
335 if (!pipeline->use_chain_dma) {
336 dev_err(sdev->dev,
338 return -EINVAL;
341 msg.primary |= pipeline->msg.primary;
345 msg.extension |= pipeline->msg.extension;
351 * playback: 0 - (num_playback_streams - 1)
352 * capture: num_playback_streams - (num_playback_streams +
353 * num_capture_streams - 1)
356 * msg.primary in case capture
358 msg.primary += SOF_IPC4_GLB_CHAIN_DMA_HOST_ID(ipc4_data->num_playback_streams);
359 msg.primary += SOF_IPC4_GLB_CHAIN_DMA_LINK_ID(ipc4_data->num_playback_streams);
363 msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_ALLOCATE_MASK;
366 msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_ENABLE_MASK;
368 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &msg, 0);
371 stream_priv->chain_dma_allocated = allocate;
382 struct sof_ipc4_fw_data *ipc4_data = sdev->private;
392 dev_dbg(sdev->dev, "trigger cmd: %d state: %d\n", cmd, state);
396 return -EINVAL;
398 pipeline_list = &spcm->stream[substream->stream].pipeline_list;
401 if (!pipeline_list->pipelines || !pipeline_list->count)
404 spipe = pipeline_list->pipelines[0];
405 pipe_widget = spipe->pipe_widget;
406 pipeline = pipe_widget->private;
412 if (pipeline->use_chain_dma)
413 return sof_ipc4_chain_dma_trigger(sdev, spcm, substream->stream,
418 pipeline_list->count), GFP_KERNEL);
420 return -ENOMEM;
422 pipe_priority = kzalloc(pipeline_list->count, GFP_KERNEL);
425 return -ENOMEM;
428 mutex_lock(&ipc4_data->pipeline_state_mutex);
433 * sink->source when starting PCM's and in the reverse order to pause/stop PCM's.
436 * indeterministic. But the sink->source trigger order sink->source would still be
440 for (i = pipeline_list->count - 1; i >= 0; i--) {
441 spipe = pipeline_list->pipelines[i];
446 for (i = 0; i < pipeline_list->count; i++) {
447 spipe = pipeline_list->pipelines[i];
453 if (!trigger_list->count) {
468 dev_err(sdev->dev, "failed to pause all pipelines\n");
473 for (i = 0; i < pipeline_list->count ; i++) {
474 spipe = pipeline_list->pipelines[i];
487 time_info = sof_ipc4_sps_to_time_info(&spcm->stream[substream->stream]);
489 time_info->stream_start_offset = SOF_IPC4_INVALID_STREAM_POSITION;
497 dev_err(sdev->dev, "failed to set final state %d for all pipelines\n", state);
506 if (sdev->fw_state != SOF_FW_CRASHED || state != SOF_IPC4_PIPE_RESET)
513 for (i = 0; i < pipeline_list->count; i++) {
514 spipe = pipeline_list->pipelines[i];
519 mutex_unlock(&ipc4_data->pipeline_state_mutex);
543 dev_err(component->dev, "%s: unhandled trigger cmd %d\n", __func__, cmd);
544 return -EINVAL;
562 struct snd_sof_dai *dai;
566 list_for_each_entry(slink, &sdev->dai_link_list, list) {
567 if (!strcmp(slink->link->name, link_name)) {
576 for (i = 0; i < slink->num_hw_configs; i++) {
577 struct snd_soc_tplg_hw_config *hw_config = &slink->hw_configs[i];
579 if (params_rate(params) == le32_to_cpu(hw_config->fsync_rate)) {
580 /* set current config for all DAI's with matching name */
581 list_for_each_entry(dai, &sdev->dai_list, list)
582 if (!strcmp(slink->link->name, dai->name))
583 dai->current_config = le32_to_cpu(hw_config->id);
590 * Fixup DAI link parameters for sampling rate based on
591 * DAI copier configuration.
597 struct sof_ipc4_pin_format *pin_fmts = ipc4_copier->available_fmt.input_pin_fmts;
599 int num_input_formats = ipc4_copier->available_fmt.num_input_formats;
627 * define a single rate in the DAI copier config in
632 dev_err(sdev->dev, "Unable to select sampling rate for DAI link\n");
633 return -EINVAL;
636 rate->min = be_rate;
637 rate->max = rate->min;
647 struct snd_sof_dai *dai = snd_sof_find_dai(component, rtd->dai_link->name);
657 if (!dai) {
658 dev_err(component->dev, "%s: No DAI found with name %s\n", __func__,
659 rtd->dai_link->name);
660 return -EINVAL;
663 ipc4_copier = dai->private;
665 dev_err(component->dev, "%s: No private data found for DAI %s\n",
666 __func__, rtd->dai_link->name);
667 return -EINVAL;
675 &ipc4_copier->available_fmt;
676 struct snd_sof_widget *swidget = w->dobj.private;
677 struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
678 struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
681 if (pipeline->use_chain_dma)
686 available_fmt->output_pin_fmts,
687 available_fmt->num_output_formats)) {
688 ipc4_fmt = &available_fmt->output_pin_fmts->audio_fmt;
693 available_fmt->input_pin_fmts,
694 available_fmt->num_input_formats)) {
695 ipc4_fmt = &available_fmt->input_pin_fmts->audio_fmt;
708 valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(ipc4_fmt->fmt_cfg);
709 dev_dbg(component->dev, "Set %s to %d bit format\n", dai->name, valid_bits);
727 switch (ipc4_copier->dai_type) {
729 ipc4_ssp_dai_config_pcm_params_match(sdev, (char *)rtd->dai_link->name, params);
745 pipeline_list = &spcm->stream[stream].pipeline_list;
746 kfree(pipeline_list->pipelines);
747 pipeline_list->pipelines = NULL;
749 stream_priv = spcm->stream[stream].private;
750 kfree(stream_priv->time_info);
751 kfree(spcm->stream[stream].private);
752 spcm->stream[stream].private = NULL;
759 struct sof_ipc4_fw_data *ipc4_data = sdev->private;
768 sof_mailbox_read(sdev, sdev->fw_info_box.offset + abi_offset, &abi_version,
775 if (!sof_ops(sdev) || !sof_ops(sdev)->get_host_byte_counter)
779 pipeline_list = &spcm->stream[stream].pipeline_list;
782 pipeline_list->pipelines = kcalloc(ipc4_data->max_num_pipelines,
784 if (!pipeline_list->pipelines) {
786 return -ENOMEM;
792 return -ENOMEM;
795 spcm->stream[stream].private = stream_priv;
803 return -ENOMEM;
806 stream_priv->time_info = time_info;
819 struct snd_sof_dai *dai;
822 /* find host & dai to locate info in memory window */
823 for_each_dapm_widgets(sps->list, i, widget) {
824 struct snd_sof_widget *swidget = widget->dobj.private;
829 if (WIDGET_IS_AIF(swidget->widget->id)) {
830 host_copier = swidget->private;
831 } else if (WIDGET_IS_DAI(swidget->widget->id)) {
832 dai = swidget->private;
833 dai_copier = dai->private;
837 /* both host and dai copier must be valid for time_info */
839 dev_err(sdev->dev, "host or dai copier are not found\n");
844 time_info->host_copier = host_copier;
845 time_info->dai_copier = dai_copier;
846 time_info->llp_offset = offsetof(struct sof_ipc4_fw_registers,
847 llp_gpdma_reading_slots) + sdev->fw_info_box.offset;
849 /* find llp slot used by current dai */
851 sof_mailbox_read(sdev, time_info->llp_offset, &llp_slot, sizeof(llp_slot));
852 if (llp_slot.node_id == dai_copier->data.gtw_cfg.node_id)
855 time_info->llp_offset += sizeof(llp_slot);
862 time_info->llp_offset = offsetof(struct sof_ipc4_fw_registers,
863 llp_sndw_reading_slots) + sdev->fw_info_box.offset;
865 sof_mailbox_read(sdev, time_info->llp_offset, &llp_slot, sizeof(llp_slot));
866 if (llp_slot.node_id == dai_copier->data.gtw_cfg.node_id)
869 time_info->llp_offset += sizeof(llp_slot);
876 time_info->llp_offset = offsetof(struct sof_ipc4_fw_registers,
877 llp_evad_reading_slot) + sdev->fw_info_box.offset;
878 sof_mailbox_read(sdev, time_info->llp_offset, &llp_slot, sizeof(llp_slot));
879 if (llp_slot.node_id != dai_copier->data.gtw_cfg.node_id)
880 time_info->llp_offset = 0;
895 return -EINVAL;
897 time_info = sof_ipc4_sps_to_time_info(&spcm->stream[substream->stream]);
902 time_info->stream_start_offset = SOF_IPC4_INVALID_STREAM_POSITION;
903 time_info->llp_offset = 0;
905 sof_ipc4_build_time_info(sdev, &spcm->stream[substream->stream]);
915 struct sof_ipc4_copier *host_copier = time_info->host_copier;
916 struct sof_ipc4_copier *dai_copier = time_info->dai_copier;
923 return -EINVAL;
925 if (host_copier->data.gtw_cfg.node_id == SOF_IPC4_INVALID_NODE_ID)
926 return -EINVAL;
928 node_index = SOF_IPC4_NODE_INDEX(host_copier->data.gtw_cfg.node_id);
930 sof_mailbox_read(sdev, sdev->fw_info_box.offset + offset, &ppl_reg, sizeof(ppl_reg));
932 return -EINVAL;
934 ch = dai_copier->data.out_format.fmt_cfg;
936 dai_sample_size = (dai_copier->data.out_format.bit_depth >> 3) * ch;
939 time_info->stream_start_offset = ppl_reg.stream_start_offset;
940 do_div(time_info->stream_start_offset, dai_sample_size);
941 time_info->stream_end_offset = ppl_reg.stream_end_offset;
942 do_div(time_info->stream_end_offset, dai_sample_size);
947 * based link counter.
949 time_info->boundary = div64_u64(~((u64)0),
950 frames_to_bytes(substream->runtime, 1));
952 time_info->delay = 0;
973 return -EOPNOTSUPP;
975 sps = &spcm->stream[substream->stream];
978 return -EOPNOTSUPP;
985 if (time_info->stream_start_offset == SOF_IPC4_INVALID_STREAM_POSITION) {
988 return -EOPNOTSUPP;
996 host_cnt = div64_u64(host_cnt, frames_to_bytes(substream->runtime, 1));
1000 * then read the dai (link) counter via host accessible means if
1003 if (!time_info->llp_offset) {
1006 return -EOPNOTSUPP;
1008 sof_mailbox_read(sdev, time_info->llp_offset, &llp, sizeof(llp));
1011 dai_cnt += time_info->stream_end_offset;
1013 /* In two cases dai dma counter is not accurate
1014 * (1) dai pipeline is started before host pipeline
1015 * (2) multiple streams mixed into one. Each stream has the same dai dma
1020 * Driver subtracts stream_start_offset from dai dma counter to get
1025 * On stream start the dai counter might not yet have reached the
1030 * increasing the host counter by (offset - dai_counter).
1032 * of valid frames passed on the DAI side.
1037 if (dai_cnt < time_info->stream_start_offset) {
1038 host_cnt += time_info->stream_start_offset - dai_cnt;
1041 dai_cnt -= time_info->stream_start_offset;
1044 /* Wrap the dai counter at the boundary where the host counter wraps */
1045 div64_u64_rem(dai_cnt, time_info->boundary, &dai_cnt);
1047 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1056 time_info->delay = time_info->boundary - tail_cnt + head_cnt;
1060 time_info->delay = head_cnt - tail_cnt;
1068 *pointer = bytes_to_frames(substream->runtime, host_ptr);
1084 time_info = sof_ipc4_sps_to_time_info(&spcm->stream[substream->stream]);
1091 return time_info->delay;