Skip to content
3 changes: 2 additions & 1 deletion sound/soc/sof/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)

snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
control.o trace.o utils.o sof-audio.o stream-ipc.o ipc4.o
control.o trace.o utils.o sof-audio.o stream-ipc.o ipc4.o\
ipc3-topology.o

snd-sof-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += sof-probes.o
snd-sof-$(CONFIG_SND_SOC_SOF_COMPRESS) += compress.o
Expand Down
206 changes: 206 additions & 0 deletions sound/soc/sof/ipc3-topology.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
// 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) 2021 Intel Corporation. All rights reserved.
//
//

#include <uapi/sound/sof/tokens.h>
#include "sof-priv.h"
#include "sof-audio.h"
#include "ops.h"

int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget)
{
struct sof_ipc_comp_host *host;
size_t ipc_size = sizeof(*host);

host = (struct sof_ipc_comp_host *)
sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
if (!host)
return -ENOMEM;

/* configure host comp IPC message */
host->comp.type = SOF_COMP_HOST;
if (swidget->id == snd_soc_dapm_aif_out)
host->direction = SOF_IPC_STREAM_CAPTURE;
else
host->direction = SOF_IPC_STREAM_PLAYBACK;
host->config.hdr.size = sizeof(host->config);

/* update pcm_tokens */
sof_update_ipc_object(host, pcm_tokens, pcm_token_size, swidget->num_tuples,
swidget->tuples, sizeof(*host), 1);

/* update comp_tokens */
sof_update_ipc_object(&host->config, comp_tokens_new, comp_token_size, swidget->num_tuples,
swidget->tuples, sizeof(host->config), 1);

dev_dbg(scomp->dev, "loaded host %s\n", swidget->widget->name);
sof_dbg_comp_config(scomp, &host->config);

swidget->private = host;

return 0;
}


int sof_widget_update_ipc_comp_dai(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget)
{
struct sof_ipc_comp_dai *comp_dai;
size_t ipc_size = sizeof(*comp_dai);
struct snd_sof_dai *dai = swidget->private;

comp_dai = (struct sof_ipc_comp_dai *)
sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
if (!comp_dai)
return -ENOMEM;

/* configure dai IPC message */
comp_dai->comp.type = SOF_COMP_DAI;
comp_dai->config.hdr.size = sizeof(comp_dai->config);

/* update dai_tokens */
sof_update_ipc_object(comp_dai, dai_tokens_new, dai_token_size, dai->num_tuples,
dai->tuples, sizeof(*comp_dai), 1);

/* update comp_tokens */
sof_update_ipc_object(&comp_dai->config, comp_tokens_new, comp_token_size, dai->num_tuples,
dai->tuples, sizeof(comp_dai->config), 1);

/*
* copy only the sof_ipc_comp_dai to avoid collapsing
* the snd_sof_dai, the extended data is kept in the
* snd_sof_widget.
*/
memcpy(&dai->comp_dai, comp_dai, sizeof(*comp_dai));

dev_dbg(scomp->dev, "%s dai %s: type %d index %d\n",
__func__, swidget->widget->name, comp_dai->type, comp_dai->dai_index);
sof_dbg_comp_config(scomp, &comp_dai->config);
return 0;
}

int sof_widget_update_ipc_comp_pipeline(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget)
{
struct sof_ipc_pipe_new *pipeline;
struct snd_sof_widget *comp_swidget;
size_t ipc_size = sizeof(*pipeline);

pipeline = (struct sof_ipc_pipe_new *)
sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
if (!pipeline)
return -ENOMEM;

/* configure dai IPC message */
pipeline->hdr.size = sizeof(*pipeline);
pipeline->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_NEW;
pipeline->pipeline_id = swidget->pipeline_id;
pipeline->comp_id = swidget->comp_id;

/* component at start of pipeline is our stream id */
comp_swidget = snd_sof_find_swidget(scomp, swidget->sname);;

if (!comp_swidget) {
dev_err(scomp->dev, "error: widget %s refers to non existent widget %s\n",
swidget->widget->name, swidget->sname);
return -EINVAL;
}

pipeline->sched_id = comp_swidget->comp_id;

sof_update_ipc_object(pipeline, sched_tokens, sched_token_size, swidget->num_tuples,
swidget->tuples, sizeof(*pipeline), 1);

sof_update_ipc_object(swidget, pipeline_tokens, pipeline_token_size, swidget->num_tuples,
swidget->tuples, sizeof(*swidget), 1);

if (sof_debug_check_flag(SOF_DBG_DISABLE_MULTICORE))
pipeline->core = SOF_DSP_PRIMARY_CORE;

if (sof_debug_check_flag(SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE))
swidget->dynamic_pipeline_widget =
sof_debug_check_flag(SOF_DBG_DYNAMIC_PIPELINES_ENABLE);

dev_dbg(scomp->dev, "pipeline %s: period %d pri %d mips %d core %d frames %d dynamic %d\n",
swidget->widget->name, pipeline->period, pipeline->priority,
pipeline->period_mips, pipeline->core, pipeline->frames_per_sched,
swidget->dynamic_pipeline_widget);

swidget->private = pipeline;

return 0;
}

int sof_widget_update_ipc_comp_mixer(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget)
{
struct sof_ipc_comp_mixer *mixer;
size_t ipc_size = sizeof(*mixer);

mixer = (struct sof_ipc_comp_mixer *)
sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
if (!mixer)
return -ENOMEM;

/* configure mixer IPC message */
mixer->comp.type = SOF_COMP_MIXER;
mixer->config.hdr.size = sizeof(mixer->config);

sof_update_ipc_object(&mixer->config, comp_tokens_new, comp_token_size, swidget->num_tuples,
swidget->tuples, sizeof(mixer->config), 1);

sof_dbg_comp_config(scomp, &mixer->config);

swidget->private = mixer;

return 0;
}
int sof_widget_update_ipc_comp_pga(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget)
{
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
struct sof_ipc_comp_volume *volume;
struct snd_sof_control *scontrol;
size_t ipc_size = sizeof(*volume);
int min_step;
int max_step;

volume = (struct sof_ipc_comp_volume *)
sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
if (!volume)
return -ENOMEM;

/* configure volume IPC message */
volume->comp.type = SOF_COMP_VOLUME;
volume->config.hdr.size = sizeof(volume->config);

sof_update_ipc_object(volume, volume_tokens, volume_token_size, swidget->num_tuples,
swidget->tuples, sizeof(*volume), 1);

sof_update_ipc_object(&volume->config, comp_tokens_new, comp_token_size, swidget->num_tuples,
swidget->tuples, sizeof(volume->config), 1);

sof_dbg_comp_config(scomp, &volume->config);

swidget->private = volume;

list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
if (scontrol->comp_id == swidget->comp_id &&
scontrol->volume_table) {
min_step = scontrol->min_volume_step;
max_step = scontrol->max_volume_step;
volume->min_value = scontrol->volume_table[min_step];
volume->max_value = scontrol->volume_table[max_step];
volume->channels = scontrol->num_channels;
break;
}
}

return 0;
}
63 changes: 61 additions & 2 deletions sound/soc/sof/sof-audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sound/sof/control.h>
#include <sound/sof/dai.h>
#include <sound/sof/topology.h>
#include <uapi/sound/sof/tokens.h>
#include "sof-priv.h"

#define SOF_AUDIO_PCM_DRV_NAME "sof-audio-component"
Expand All @@ -30,6 +31,40 @@

#define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)

struct snd_sof_widget;
struct sof_ipc_comp *sof_comp_alloc(struct snd_sof_widget *swidget, size_t *ipc_size, int index);

/*
* Topology Token Parsing.
* New tokens should be added to headers and parsing tables below.
*/

struct sof_topology_token {
u32 token;
u32 type;
u32 (*get_token)(void *elem, void *object, u32 offset, u32 size);
u32 offset;
u32 size;
};

struct snd_sof_tuple {
u32 token;
u32 value;
};

extern const struct sof_topology_token pcm_tokens[];
extern const struct sof_topology_token dai_tokens_new[];
extern const struct sof_topology_token sched_tokens[];
extern const struct sof_topology_token pipeline_tokens[];
extern const struct sof_topology_token volume_tokens[];
extern const struct sof_topology_token comp_tokens_new[];
extern int pcm_token_size;
extern int comp_token_size;
extern int dai_token_size;
extern int sched_token_size;
extern int pipeline_token_size;
extern int volume_token_size;

/* PCM stream, mapped to FW component */
struct snd_sof_pcm_stream {
u32 comp_id;
Expand All @@ -55,6 +90,8 @@ struct snd_sof_pcm {
struct list_head list; /* list in sdev pcm list */
struct snd_pcm_hw_params params[2];
bool prepared[2]; /* PCM_PARAMS set successfully */
int num_tuples;
struct snd_sof_tuple *tuples;
};

struct snd_sof_led_control {
Expand Down Expand Up @@ -82,9 +119,10 @@ struct snd_sof_control {

/* if true, the control's data needs to be updated from Firmware */
bool comp_data_dirty;
};

struct snd_sof_widget;
int num_tuples;
struct snd_sof_tuple *tuples;
};

/* ASoC SOF DAPM widget */
struct snd_sof_widget {
Expand All @@ -95,6 +133,7 @@ struct snd_sof_widget {
int use_count; /* use_count will be protected by the PCM mutex held by the core */
int core;
int id;
int num_tuples;

/*
* Flag indicating if the widget should be set up dynamically when a PCM is opened.
Expand All @@ -113,6 +152,10 @@ struct snd_sof_widget {
/* extended data for UUID components */
struct sof_ipc_comp_ext comp_ext;

struct snd_sof_tuple *tuples;

char sname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];

void *private; /* core does not touch this */
};

Expand All @@ -133,13 +176,15 @@ struct snd_sof_route {
struct snd_sof_dai {
struct snd_soc_component *scomp;
const char *name;
int num_tuples;

struct sof_ipc_comp_dai comp_dai;
int number_configs;
int current_config;
bool configured; /* DAI configured during BE hw_params */
struct sof_ipc_dai_config *dai_config;
struct list_head list; /* list in sdev dai list */
struct snd_sof_tuple *tuples;
};

/*
Expand Down Expand Up @@ -264,4 +309,18 @@ int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev
struct snd_sof_pcm *spcm);
int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
struct snd_sof_pcm *spcm, int dir, bool free_widget_list);
int sof_widget_update_ipc_comp_host(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget);
int sof_widget_update_ipc_comp_dai(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget);
int sof_widget_update_ipc_comp_pipeline(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget);
int sof_widget_update_ipc_comp_mixer(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget);
int sof_widget_update_ipc_comp_pga(struct snd_soc_component *scomp,
struct snd_sof_widget *swidget);
void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config);
void sof_update_ipc_object(void *object, const struct sof_topology_token *tokens, int count,
int num_tuples, struct snd_sof_tuple *tuples,
size_t object_size, int num_sets);
#endif
Loading