// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) // // This file is provided under a dual BSD/GPLv2 license. When using or // redistributing this file, you may do so under either license. // // Copyright(c) 2022 Intel Corporation //
/* trigger multiple pipelines with a single IPC */
msg.extension = SOF_IPC4_GLB_PIPE_STATE_EXT_MULTI;
/* ipc_size includes the count and the pipeline IDs for the number of pipelines */
ipc_size = sizeof(u32) * (trigger_list->count + 1);
msg.data_size = ipc_size;
msg.data_ptr = trigger_list;
staticvoid sof_ipc4_add_pipeline_by_priority(struct ipc4_pipeline_set_state_data *trigger_list, struct snd_sof_widget *pipe_widget,
s8 *pipe_priority, bool ascend)
{ struct sof_ipc4_pipeline *pipeline = pipe_widget->private; int i, j;
for (i = 0; i < trigger_list->count; i++) { /* add pipeline from low priority to high */ if (ascend && pipeline->priority < pipe_priority[i]) break; /* add pipeline from high priority to low */ elseif (!ascend && pipeline->priority > pipe_priority[i]) break;
}
if (pipeline->skip_during_fe_trigger && state != SOF_IPC4_PIPE_RESET) return;
switch (state) { case SOF_IPC4_PIPE_RUNNING: /* *TriggerpipelineifallPCMscontainingitarepausedorifitisRUNNING *forthefirsttime
*/ if (spipe->started_count == spipe->paused_count)
sof_ipc4_add_pipeline_by_priority(trigger_list, pipe_widget, pipe_priority, false); break; case SOF_IPC4_PIPE_RESET: /* RESET if the pipeline is neither running nor paused */ if (!spipe->started_count && !spipe->paused_count)
sof_ipc4_add_pipeline_by_priority(trigger_list, pipe_widget, pipe_priority, true); break; case SOF_IPC4_PIPE_PAUSED: /* Pause the pipeline only when its started_count is 1 more than paused_count */ if (spipe->paused_count == (spipe->started_count - 1))
sof_ipc4_add_pipeline_by_priority(trigger_list, pipe_widget, pipe_priority, true); break; default: break;
}
}
staticvoid
sof_ipc4_update_pipeline_state(struct snd_sof_dev *sdev, int state, int cmd, struct snd_sof_pipeline *spipe, struct ipc4_pipeline_set_state_data *trigger_list)
{ struct snd_sof_widget *pipe_widget = spipe->pipe_widget; struct sof_ipc4_pipeline *pipeline = pipe_widget->private; int i;
if (pipeline->skip_during_fe_trigger && state != SOF_IPC4_PIPE_RESET) return;
/* set state for pipeline if it was just triggered */ for (i = 0; i < trigger_list->count; i++) { if (trigger_list->pipeline_instance_ids[i] == pipe_widget->instance_id) {
pipeline->state = state; break;
}
}
switch (state) { case SOF_IPC4_PIPE_PAUSED: switch (cmd) { case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* *incrementpaused_countifthePAUSEDisthefinalstateduring *thePAUSEtrigger
*/
spipe->paused_count++; break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: /* *decrementstarted_countifPAUSEDisthefinalstateduringthe *STOPtrigger
*/
spipe->started_count--; break; default: break;
} break; case SOF_IPC4_PIPE_RUNNING: switch (cmd) { case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* decrement paused_count for RELEASE */
spipe->paused_count--; break; case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: /* increment started_count for START/RESUME */
spipe->started_count++; break; default: break;
} break; default: break;
}
}
/* *Toset-uptheDMAchain,thehostDMAIDandSCSsetting *areretrievedfromthehostpipelineconfiguration.Likewise *thelinkDMAIDandfifo_sizeareretrievedfromthelink *pipelineconfiguration.
*/ for (i = 0; i < pipeline_list->count; i++) { struct snd_sof_pipeline *spipe = pipeline_list->pipelines[i]; struct snd_sof_widget *pipe_widget = spipe->pipe_widget; struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
if (!pipeline->use_chain_dma) {
spcm_err(spcm, direction, "All pipelines in chained DMA path should have use_chain_dma attribute set."); return -EINVAL;
}
msg.primary |= pipeline->msg.primary;
/* Add fifo_size (actually DMA buffer size) field to the message */ if (set_fifo_size)
msg.extension |= pipeline->msg.extension;
}
if (allocate)
msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_ALLOCATE_MASK;
if (enable)
msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_ENABLE_MASK;
ret = sof_ipc_tx_message_no_reply(sdev->ipc, &msg, 0); /* Update the ChainDMA allocation state */ if (!ret)
stream_priv->chain_dma_allocated = allocate;
time_info->stream_end_offset += pos;
} elseif (state == SOF_IPC4_PIPE_RESET) { /* Reset the end offset as the stream is stopped */
time_info->stream_end_offset = 0;
}
return0;
}
/* allocate memory for the pipeline data */
trigger_list = kzalloc(struct_size(trigger_list, pipeline_instance_ids,
pipeline_list->count), GFP_KERNEL); if (!trigger_list) return -ENOMEM;
/* *IPC4requirespipelinestobetriggeredinorderstartingatthesinkand *walkingallthewaytothesource.Sotraversethepipeline_listintheorder *sink->sourcewhenstartingPCM'sandinthereverseordertopause/stopPCM's. *Skipthepipelinesthathavetheirskip_during_fe_triggerflagset.Ifthereisafork *inthepipeline,theorderoftriggeringbetweentheleft/rightpathswillbe *indeterministic.Butthesink->sourcetriggerordersink->sourcewouldstillbe *guaranteedforeachforkindependently.
*/ if (state == SOF_IPC4_PIPE_RUNNING || state == SOF_IPC4_PIPE_RESET) for (i = pipeline_list->count - 1; i >= 0; i--) {
spipe = pipeline_list->pipelines[i];
sof_ipc4_add_pipeline_to_trigger_list(sdev, state, spipe, trigger_list,
pipe_priority);
} else for (i = 0; i < pipeline_list->count; i++) {
spipe = pipeline_list->pipelines[i];
sof_ipc4_add_pipeline_to_trigger_list(sdev, state, spipe, trigger_list,
pipe_priority);
}
/* return if all pipelines are in the requested state already */ if (!trigger_list->count) {
ret = 0; goto free;
}
/* no need to pause before reset or before pause release */ if (state == SOF_IPC4_PIPE_RESET || cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) goto skip_pause_transition;
/* *setpausedstateforpipelinesifthefinalstateisPAUSEDorwhenthepipeline *issettoRUNNINGforthefirsttimeafterthePCMisstarted.
*/
ret = sof_ipc4_set_multi_pipeline_state(sdev, SOF_IPC4_PIPE_PAUSED, trigger_list); if (ret < 0) {
spcm_err(spcm, substream->stream, "failed to pause all pipelines\n"); goto free;
}
/* update PAUSED state for all pipelines just triggered */ for (i = 0; i < pipeline_list->count ; i++) {
spipe = pipeline_list->pipelines[i];
sof_ipc4_update_pipeline_state(sdev, SOF_IPC4_PIPE_PAUSED, cmd, spipe,
trigger_list);
}
/* return if this is the final state */ if (state == SOF_IPC4_PIPE_PAUSED) { struct sof_ipc4_timestamp_info *time_info;
goto free;
}
skip_pause_transition: /* else set the RUNNING/RESET state in the DSP */
ret = sof_ipc4_set_multi_pipeline_state(sdev, state, trigger_list); if (ret < 0) {
spcm_err(spcm, substream->stream, "failed to set final state %d for all pipelines\n",
state); /* *workaround:ifthefirmwareiscrashedwhilesettingthe *pipelinestoresetstatewemustignoretheerrorcodeand *resetitto0. *SincethefirmwareiscrashedwewillnotsendIPCmessages *andwearegoingtoseeerrorsprinted,butthestateofthe *widgetswillbecorrectforthenextboot.
*/ if (sdev->fw_state != SOF_FW_CRASHED || state != SOF_IPC4_PIPE_RESET) goto free;
ret = 0;
}
/* update RUNNING/RESET state for all pipelines that were just triggered */ for (i = 0; i < pipeline_list->count; i++) {
spipe = pipeline_list->pipelines[i];
sof_ipc4_update_pipeline_state(sdev, state, cmd, spipe, trigger_list);
}
staticint sof_ipc4_pcm_trigger(struct snd_soc_component *component, struct snd_pcm_substream *substream, int cmd)
{ int state;
/* determine the pipeline state */ switch (cmd) { case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_START:
state = SOF_IPC4_PIPE_RUNNING; break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_STOP:
state = SOF_IPC4_PIPE_PAUSED; break; default:
dev_err(component->dev, "%s: unhandled trigger cmd %d\n", __func__, cmd); return -EINVAL;
}
/* set the pipeline state */ return sof_ipc4_trigger_pipelines(component, substream, state, cmd);
}
staticint sof_ipc4_pcm_hw_free(struct snd_soc_component *component, struct snd_pcm_substream *substream)
{ /* command is not relevant with RESET, so just pass 0 */ return sof_ipc4_trigger_pipelines(component, substream, SOF_IPC4_PIPE_RESET, 0);
}
if (WARN_ON_ONCE(!num_input_formats)) return -EINVAL;
/* *Copierdoesnotchangesamplingrate,sowe *needtoonlyconsidertheinputpininformation.
*/
be_rate = pin_fmts[0].audio_fmt.sampling_frequency; for (i = 0; i < num_input_formats; i++) { unsignedint val = pin_fmts[i].audio_fmt.sampling_frequency;
/* *IfrateisdifferentthanFErate,topologymust *containanSRC.Butwedorequiretopologyto *defineasinglerateintheDAIcopierconfigin *thiscase(FEratemaybevariable).
*/ if (!fe_be_rate_match) { if (!single_be_rate) {
dev_err(sdev->dev, "Unable to select sampling rate for DAI link\n"); return -EINVAL;
}
if (WARN_ON_ONCE(!num_input_formats)) return -EINVAL;
/* *Copierdoesnotchangechannels,sowe *needtoonlyconsidertheinputpininformation.
*/
be_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(pin_fmts[0].audio_fmt.fmt_cfg); for (i = 0; i < num_input_formats; i++) {
val = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(pin_fmts[i].audio_fmt.fmt_cfg);
if (val != be_channels)
single_be_channels = false;
/* *IfchannelsisdifferentthanFEchannels,topologymustcontaina *modulewhichcanchangethenumberofchannels.Butwedorequire *topologytodefineasinglechannelsintheDAIcopierconfigin *thiscase(FEchannelsmaybevariable).
*/ if (!fe_be_match) { if (!single_be_channels) {
dev_err(sdev->dev, "Unable to select channels for DAI link\n"); return -EINVAL;
}
if (!dai) {
dev_err(component->dev, "%s: No DAI found with name %s\n", __func__,
rtd->dai_link->name); return -EINVAL;
}
ipc4_copier = dai->private; if (!ipc4_copier) {
dev_err(component->dev, "%s: No private data found for DAI %s\n",
__func__, rtd->dai_link->name); return -EINVAL;
}
if (abi_version < SOF_IPC4_FW_REGS_ABI_VER)
support_info = false;
/* For delay reporting the get_host_byte_counter callback is needed */ if (!sof_ops(sdev) || !sof_ops(sdev)->get_host_byte_counter)
support_info = false;
/* allocate memory for max number of pipeline IDs */
pipeline_list->pipelines = kcalloc(ipc4_data->max_num_pipelines, sizeof(*pipeline_list->pipelines),
GFP_KERNEL); if (!pipeline_list->pipelines) {
sof_ipc4_pcm_free(sdev, spcm); return -ENOMEM;
}
/* find host & dai to locate info in memory window */
for_each_dapm_widgets(sps->list, i, widget) { struct snd_sof_widget *swidget = widget->dobj.private;
if (!swidget) continue;
if (WIDGET_IS_AIF(swidget->widget->id)) {
host_copier = swidget->private;
} elseif (WIDGET_IS_DAI(swidget->widget->id)) {
dai = swidget->private;
dai_copier = dai->private;
}
}
/* both host and dai copier must be valid for time_info */ if (!host_copier || !dai_copier) {
dev_err(sdev->dev, "host or dai copier are not found\n"); return;
}
/* find llp slot used by current dai */ for (i = 0; i < SOF_IPC4_MAX_LLP_GPDMA_READING_SLOTS; i++) {
sof_mailbox_read(sdev, time_info->llp_offset, &llp_slot, sizeof(llp_slot)); if (llp_slot.node_id == dai_copier->data.gtw_cfg.node_id) break;
time_info->llp_offset += sizeof(llp_slot);
}
if (i < SOF_IPC4_MAX_LLP_GPDMA_READING_SLOTS) return;
/* if no llp gpdma slot is used, check aggregated sdw slot */
time_info->llp_offset = offsetof(struct sof_ipc4_fw_registers,
llp_sndw_reading_slots) + sdev->fw_info_box.offset; for (i = 0; i < SOF_IPC4_MAX_LLP_SNDW_READING_SLOTS; i++) {
sof_mailbox_read(sdev, time_info->llp_offset, &llp_slot, sizeof(llp_slot)); if (llp_slot.node_id == dai_copier->data.gtw_cfg.node_id) break;
time_info->llp_offset += sizeof(llp_slot);
}
if (i < SOF_IPC4_MAX_LLP_SNDW_READING_SLOTS) return;
spcm = snd_sof_find_spcm_dai(component, rtd); if (!spcm) return -EINVAL;
time_info = sof_ipc4_sps_to_time_info(&spcm->stream[substream->stream]); /* delay calculation is not supported by current fw_reg ABI */ if (!time_info) return0;
if (!dai_rate || !host_rate || dai_rate == host_rate) return value;
/* take care not to overflow u64, rates can be up to 768000 */ if (value > U32_MAX) {
value = div64_u64(value, dai_rate);
value *= host_rate;
} else {
value *= host_rate;
value = div64_u64(value, dai_rate);
}
/* In two cases dai dma counter is not accurate *(1)daipipelineisstartedbeforehostpipeline *(2)multiplestreamsmixedintoone.Eachstreamhasthesamedaidma *counter * *Firmwarecalculatescorrectstream_start_offsetforallcases *includingabovetwo. *Driversubtractsstream_start_offsetfromdaidmacountertoget *accurateone
*/
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.28Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.