Commit 753132f0 authored by Mark Brown's avatar Mark Brown

Introduce IPC abstraction for SOF topology parsing

Merge series from Ranjani Sridharan <ranjani.sridharan@linux.intel.com>:

This patchset makes the topology parsing layer in the SOF driver
IPC-agnostic in preparation for supporting the new IPC version
introduced in the SOF firmware. These patches purely contain abstraction
changes for the current IPC version (IPC3) supported and do not introduce
any functional changes.
parents 835ca597 61ad28ff
# 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 iomem-utils.o sof-audio.o stream-ipc.o
control.o trace.o iomem-utils.o sof-audio.o stream-ipc.o\
ipc3-topology.o
ifneq ($(CONFIG_SND_SOC_SOF_CLIENT),)
snd-sof-objs += sof-client.o
endif
......
......@@ -67,7 +67,7 @@ static inline u32 ipc_to_mixer(u32 value, u32 *volume_map, int size)
static void snd_sof_refresh_control(struct snd_sof_control *scontrol)
{
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_soc_component *scomp = scontrol->scomp;
int ret;
......@@ -97,7 +97,7 @@ int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
struct soc_mixer_control *sm =
(struct soc_mixer_control *)kcontrol->private_value;
struct snd_sof_control *scontrol = sm->dobj.private;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
unsigned int i, channels = scontrol->num_channels;
snd_sof_refresh_control(scontrol);
......@@ -118,7 +118,7 @@ int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
(struct soc_mixer_control *)kcontrol->private_value;
struct snd_sof_control *scontrol = sm->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
unsigned int i, channels = scontrol->num_channels;
bool change = false;
u32 value;
......@@ -166,7 +166,7 @@ int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
struct soc_mixer_control *sm =
(struct soc_mixer_control *)kcontrol->private_value;
struct snd_sof_control *scontrol = sm->dobj.private;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
unsigned int i, channels = scontrol->num_channels;
snd_sof_refresh_control(scontrol);
......@@ -185,7 +185,7 @@ int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
(struct soc_mixer_control *)kcontrol->private_value;
struct snd_sof_control *scontrol = sm->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
unsigned int i, channels = scontrol->num_channels;
bool change = false;
u32 value;
......@@ -214,7 +214,7 @@ int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
struct soc_enum *se =
(struct soc_enum *)kcontrol->private_value;
struct snd_sof_control *scontrol = se->dobj.private;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
unsigned int i, channels = scontrol->num_channels;
snd_sof_refresh_control(scontrol);
......@@ -233,7 +233,7 @@ int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
(struct soc_enum *)kcontrol->private_value;
struct snd_sof_control *scontrol = se->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
unsigned int i, channels = scontrol->num_channels;
bool change = false;
u32 value;
......@@ -260,7 +260,7 @@ int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
(struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct sof_abi_hdr *data = cdata->data;
size_t size;
......@@ -296,7 +296,7 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
(struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct sof_abi_hdr *data = cdata->data;
size_t size;
......@@ -335,7 +335,7 @@ int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
(struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_ctl_tlv header;
const struct snd_ctl_tlv __user *tlvd =
(const struct snd_ctl_tlv __user *)binary_data;
......@@ -409,7 +409,7 @@ int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int _
struct soc_bytes_ext *be = (struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_ctl_tlv header;
struct snd_ctl_tlv __user *tlvd = (struct snd_ctl_tlv __user *)binary_data;
size_t data_size;
......@@ -482,7 +482,7 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
(struct soc_bytes_ext *)kcontrol->private_value;
struct snd_sof_control *scontrol = be->dobj.private;
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_ctl_tlv header;
struct snd_ctl_tlv __user *tlvd =
(struct snd_ctl_tlv __user *)binary_data;
......@@ -534,7 +534,7 @@ static void snd_sof_update_control(struct snd_sof_control *scontrol,
struct sof_ipc_ctrl_data *local_cdata;
int i;
local_cdata = scontrol->control_data;
local_cdata = scontrol->ipc_control_data;
if (cdata->cmd == SOF_CTRL_CMD_BINARY) {
if (cdata->num_elems != local_cdata->data->size) {
......
......@@ -370,6 +370,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
INIT_LIST_HEAD(&sdev->kcontrol_list);
INIT_LIST_HEAD(&sdev->widget_list);
INIT_LIST_HEAD(&sdev->dai_list);
INIT_LIST_HEAD(&sdev->dai_link_list);
INIT_LIST_HEAD(&sdev->route_list);
INIT_LIST_HEAD(&sdev->ipc_client_list);
INIT_LIST_HEAD(&sdev->ipc_rx_handler_list);
......
......@@ -812,7 +812,7 @@ static int sof_set_get_large_ctrl_data(struct snd_sof_dev *sdev,
int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol, bool set)
{
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
struct sof_ipc_fw_version *v = &ready->version;
......@@ -1023,6 +1023,18 @@ struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev)
init_waitqueue_head(&msg->waitq);
/*
* Use IPC3 ops as it is the only available version now. With the addition of new IPC
* versions, this will need to be modified to use the selected version at runtime.
*/
ipc->ops = &ipc3_ops;
/* check for mandatory ops */
if (!ipc->ops->tplg || !ipc->ops->tplg->widget) {
dev_err(sdev->dev, "Invalid topology IPC ops\n");
return NULL;
}
return ipc;
}
EXPORT_SYMBOL(snd_sof_ipc_init);
......
This diff is collapsed.
......@@ -263,45 +263,15 @@ int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
}
EXPORT_SYMBOL(sof_widget_setup);
static int sof_route_setup_ipc(struct snd_sof_dev *sdev, struct snd_sof_route *sroute)
{
struct sof_ipc_pipe_comp_connect connect;
struct sof_ipc_reply reply;
int ret;
/* nothing to do if route is already set up */
if (sroute->setup)
return 0;
connect.hdr.size = sizeof(connect);
connect.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_CONNECT;
connect.source_id = sroute->src_widget->comp_id;
connect.sink_id = sroute->sink_widget->comp_id;
dev_dbg(sdev->dev, "setting up route %s -> %s\n",
sroute->src_widget->widget->name,
sroute->sink_widget->widget->name);
/* send ipc */
ret = sof_ipc_tx_message(sdev->ipc, connect.hdr.cmd, &connect, sizeof(connect),
&reply, sizeof(reply));
if (ret < 0) {
dev_err(sdev->dev, "%s: route setup failed %d\n", __func__, ret);
return ret;
}
sroute->setup = true;
return 0;
}
static int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
struct snd_soc_dapm_widget *wsink)
{
const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
struct snd_sof_widget *src_widget = wsource->dobj.private;
struct snd_sof_widget *sink_widget = wsink->dobj.private;
struct snd_sof_route *sroute;
bool route_found = false;
int ret;
/* ignore routes involving virtual widgets in topology */
switch (src_widget->id) {
......@@ -335,7 +305,16 @@ static int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget
return -EINVAL;
}
return sof_route_setup_ipc(sdev, sroute);
/* nothing to do if route is already set up */
if (sroute->setup)
return 0;
ret = ipc_tplg_ops->route_setup(sdev, sroute);
if (ret < 0)
return ret;
sroute->setup = true;
return 0;
}
static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
......@@ -383,6 +362,7 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir)
{
const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
struct snd_soc_dapm_widget *widget;
int i, ret, num_widgets;
......@@ -453,10 +433,12 @@ int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, in
if (pipe_widget->complete)
continue;
pipe_widget->complete = snd_sof_complete_pipeline(sdev, pipe_widget);
if (pipe_widget->complete < 0) {
ret = pipe_widget->complete;
goto widget_free;
if (ipc_tplg_ops->pipeline_complete) {
pipe_widget->complete = ipc_tplg_ops->pipeline_complete(sdev, pipe_widget);
if (pipe_widget->complete < 0) {
ret = pipe_widget->complete;
goto widget_free;
}
}
}
......@@ -604,6 +586,7 @@ int sof_set_hw_params_upon_resume(struct device *dev)
int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify)
{
const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
struct snd_sof_widget *swidget;
struct snd_sof_route *sroute;
......@@ -656,7 +639,7 @@ int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify)
sroute->sink_widget->dynamic_pipeline_widget))
continue;
ret = sof_route_setup_ipc(sdev, sroute);
ret = ipc_tplg_ops->route_setup(sdev, sroute);
if (ret < 0) {
dev_err(sdev->dev, "%s: restore pipeline connections failed\n", __func__);
return ret;
......@@ -677,8 +660,11 @@ int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify)
return ret;
}
swidget->complete =
snd_sof_complete_pipeline(sdev, swidget);
if (ipc_tplg_ops->pipeline_complete) {
swidget->complete = ipc_tplg_ops->pipeline_complete(sdev, swidget);
if (swidget->complete < 0)
return swidget->complete;
}
break;
default:
break;
......
......@@ -30,6 +30,55 @@
#define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)
/*
* Volume fractional word length define to 16 sets
* the volume linear gain value to use Qx.16 format
*/
#define VOLUME_FWL 16
struct snd_sof_widget;
struct snd_sof_route;
struct snd_sof_control;
/**
* struct sof_ipc_tplg_widget_ops - IPC-specific ops for topology widgets
* @ipc_setup: Function pointer for setting up widget IPC params
* @ipc_free: Function pointer for freeing widget IPC params
* @token_list: List of token ID's that should be parsed for the widget
* @token_list_size: number of elements in token_list
* @bind_event: Function pointer for binding events to the widget
*/
struct sof_ipc_tplg_widget_ops {
int (*ipc_setup)(struct snd_sof_widget *swidget);
void (*ipc_free)(struct snd_sof_widget *swidget);
enum sof_tokens *token_list;
int token_list_size;
int (*bind_event)(struct snd_soc_component *scomp, struct snd_sof_widget *swidget,
u16 event_type);
};
/**
* struct sof_ipc_tplg_ops - IPC-specific topology ops
* @widget: Array of pointers to IPC-specific ops for widgets. This should always be of size
* SND_SOF_DAPM_TYPE_COUNT i.e one per widget type. Unsupported widget types will be
* initialized to 0.
* @route_setup: Function pointer for setting up pipeline connections
* @token_list: List of all tokens supported by the IPC version. The size of the token_list
* array should be SOF_TOKEN_COUNT. The unused elements in the array will be
* initialized to 0.
* @control_setup: Function pointer for setting up kcontrol IPC-specific data
* @control_free: Function pointer for freeing kcontrol IPC-specific data
* @pipeline_complete: Function pointer for pipeline complete IPC
*/
struct sof_ipc_tplg_ops {
const struct sof_ipc_tplg_widget_ops *widget;
int (*route_setup)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
const struct sof_token_info *token_list;
int (*control_setup)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
int (*control_free)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
int (*pipeline_complete)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
};
/** struct snd_sof_tuple - Tuple info
* @token: Token ID
* @value: union of a string or a u32 values
......@@ -42,6 +91,57 @@ struct snd_sof_tuple {
} value;
};
/*
* List of SOF token ID's. The order of ID's does not matter as token arrays are looked up based on
* the ID.
*/
enum sof_tokens {
SOF_PCM_TOKENS,
SOF_PIPELINE_TOKENS,
SOF_SCHED_TOKENS,
SOF_ASRC_TOKENS,
SOF_SRC_TOKENS,
SOF_COMP_TOKENS,
SOF_BUFFER_TOKENS,
SOF_VOLUME_TOKENS,
SOF_PROCESS_TOKENS,
SOF_DAI_TOKENS,
SOF_DAI_LINK_TOKENS,
SOF_HDA_TOKENS,
SOF_SSP_TOKENS,
SOF_ALH_TOKENS,
SOF_DMIC_TOKENS,
SOF_DMIC_PDM_TOKENS,
SOF_ESAI_TOKENS,
SOF_SAI_TOKENS,
SOF_AFE_TOKENS,
SOF_CORE_TOKENS,
SOF_COMP_EXT_TOKENS,
/* this should be the last */
SOF_TOKEN_COUNT,
};
/**
* struct sof_topology_token - SOF topology token definition
* @token: Token number
* @type: Token type
* @get_token: Function pointer to parse the token value and save it in a object
* @offset: Offset within an object to save the token value into
*/
struct sof_topology_token {
u32 token;
u32 type;
int (*get_token)(void *elem, void *object, u32 offset);
u32 offset;
};
struct sof_token_info {
const char *name;
const struct sof_topology_token *tokens;
int count;
};
/* PCM stream, mapped to FW component */
struct snd_sof_pcm_stream {
u32 comp_id;
......@@ -78,13 +178,20 @@ struct snd_sof_led_control {
/* ALSA SOF Kcontrol device */
struct snd_sof_control {
struct snd_soc_component *scomp;
const char *name;
int comp_id;
int min_volume_step; /* min volume step for volume_table */
int max_volume_step; /* max volume step for volume_table */
int num_channels;
unsigned int access;
u32 readback_offset; /* offset to mmapped data if used */
struct sof_ipc_ctrl_data *control_data;
int info_type;
int index; /* pipeline ID */
void *priv; /* private data copied from topology */
size_t priv_size; /* size of private data */
size_t max_size;
void *ipc_control_data;
int max; /* applicable to volume controls */
u32 size; /* cdata size */
u32 *volume_table; /* volume table computed from tlv data*/
......@@ -96,7 +203,26 @@ struct snd_sof_control {
bool comp_data_dirty;
};
struct snd_sof_widget;
/** struct snd_sof_dai_link - DAI link info
* @tuples: array of parsed tuples
* @num_tuples: number of tuples in the tuples array
* @link: Pointer to snd_soc_dai_link
* @hw_configs: Pointer to hw configs in topology
* @num_hw_configs: Number of hw configs in topology
* @default_hw_cfg_id: Default hw config ID
* @type: DAI type
* @list: item in snd_sof_dev dai_link list
*/
struct snd_sof_dai_link {
struct snd_sof_tuple *tuples;
int num_tuples;
struct snd_soc_dai_link *link;
struct snd_soc_tplg_hw_config *hw_configs;
int num_hw_configs;
int default_hw_cfg_id;
int type;
struct list_head list;
};
/* ASoC SOF DAPM widget */
struct snd_sof_widget {
......@@ -194,8 +320,6 @@ void snd_sof_control_notify(struct snd_sof_dev *sdev,
* be freed by snd_soc_unregister_component,
*/
int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file);
int snd_sof_complete_pipeline(struct snd_sof_dev *sdev,
struct snd_sof_widget *swidget);
/*
* Stream IPC
......@@ -278,4 +402,7 @@ int get_token_u16(void *elem, void *object, u32 offset);
int get_token_comp_format(void *elem, void *object, u32 offset);
int get_token_dai_type(void *elem, void *object, u32 offset);
int get_token_uuid(void *elem, void *object, u32 offset);
int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum sof_tokens token_id,
struct snd_sof_tuple *tuples, int num_tuples,
size_t object_size, int token_instance_num);
#endif
......@@ -360,6 +360,18 @@ struct snd_sof_ipc_msg {
bool ipc_complete;
};
struct sof_ipc_tplg_ops;
/**
* struct sof_ipc_ops - IPC-specific ops
* @tplg: Pointer to IPC-specific topology ops
*/
struct sof_ipc_ops {
const struct sof_ipc_tplg_ops *tplg;
};
extern const struct sof_ipc_ops ipc3_ops;
/* SOF generic IPC data */
struct snd_sof_ipc {
struct snd_sof_dev *sdev;
......@@ -370,6 +382,9 @@ struct snd_sof_ipc {
bool disable_ipc_tx;
struct snd_sof_ipc_msg msg;
/* IPC ops based on version */
const struct sof_ipc_ops *ops;
};
/*
......@@ -441,6 +456,7 @@ struct snd_sof_dev {
struct list_head kcontrol_list;
struct list_head widget_list;
struct list_head dai_list;
struct list_head dai_link_list;
struct list_head route_list;
struct snd_soc_component *component;
u32 enabled_cores_mask; /* keep track of enabled cores */
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment