Commit 09b955f6 authored by Mark Brown's avatar Mark Brown

ASoC: SOF: Abstractions for top-level IPC ops

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

This series is continuation of the IPC abstraction in the SOF driver in
preparation for supporting the new IPC supported by the SOF firmware.
It introduces abstraction for top-level IPC ops for sending/receiving
regular and large IPC's.

Peter Ujfalusi (15):
  ASoC: SOF: Add helper function to prepare and send an IPC message
  ASoC: SOF: Add high level IPC IO callback definitions to ipc_ops
  ASoC: SOF: ipc3: Implement the tx_msg IPC ops
  ASoC: SOF: ipc3: Use sof_ipc3_tx_msg() internally for message sending
  ASoC: SOF: ipc3: Implement the set_get_data IPC ops
  ASoC: SOF: ipc3: Implement the get_reply IPC ops
  ASoC: SOF: ipc3: Implement rx_msg IPC ops
  ASoC: SOF: ipc: Separate the ops checks by functions/topics
  ASoC: SOF: ipc: Add check for mandatory IPC message handling ops
  ASoC: SOF: ipc: Use the get_reply ops in snd_sof_ipc_get_reply()
  ASoC: SOF: ipc: Switch over to use the tx_msg and set_get_data ops
  ASoC: SOF: ipc: Switch over to use the rx_msg ops
  ASoC: SOF: Add widget_kcontrol_setup control ops for IPC3
  ASoC: SOF: sof-audio: Use the widget_kcontrol_setup ops for kcontrol
    set up
  ASoC: SOF: ipc: Move the ipc_set_get_comp_data() local to ipc3-control

 sound/soc/sof/ipc.c          | 858 ++---------------------------------
 sound/soc/sof/ipc3-control.c | 131 +++++-
 sound/soc/sof/ipc3.c         | 682 +++++++++++++++++++++++++++-
 sound/soc/sof/sof-audio.c    |  54 +--
 sound/soc/sof/sof-audio.h    |   7 +-
 sound/soc/sof/sof-priv.h     |  28 +-
 6 files changed, 880 insertions(+), 880 deletions(-)

--
2.25.1
parents 2f7f0994 e760f102
This diff is collapsed.
...@@ -11,6 +11,85 @@ ...@@ -11,6 +11,85 @@
#include "sof-audio.h" #include "sof-audio.h"
#include "ipc3-ops.h" #include "ipc3-ops.h"
/* IPC set()/get() for kcontrols. */
static int sof_ipc3_set_get_kcontrol_data(struct snd_sof_control *scontrol, bool set)
{
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scontrol->scomp);
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
const struct sof_ipc_ops *iops = sdev->ipc->ops;
enum sof_ipc_ctrl_type ctrl_type;
struct snd_sof_widget *swidget;
bool widget_found = false;
u32 ipc_cmd, msg_bytes;
list_for_each_entry(swidget, &sdev->widget_list, list) {
if (swidget->comp_id == scontrol->comp_id) {
widget_found = true;
break;
}
}
if (!widget_found) {
dev_err(sdev->dev, "%s: can't find widget with id %d\n", __func__,
scontrol->comp_id);
return -EINVAL;
}
/*
* Volatile controls should always be part of static pipelines and the widget use_count
* would always be > 0 in this case. For the others, just return the cached value if the
* widget is not set up.
*/
if (!swidget->use_count)
return 0;
/*
* Select the IPC cmd and the ctrl_type based on the ctrl_cmd and the
* direction
* Note: SOF_CTRL_TYPE_VALUE_COMP_* is not used and supported currently
* for ctrl_type
*/
if (cdata->cmd == SOF_CTRL_CMD_BINARY) {
ipc_cmd = set ? SOF_IPC_COMP_SET_DATA : SOF_IPC_COMP_GET_DATA;
ctrl_type = set ? SOF_CTRL_TYPE_DATA_SET : SOF_CTRL_TYPE_DATA_GET;
} else {
ipc_cmd = set ? SOF_IPC_COMP_SET_VALUE : SOF_IPC_COMP_GET_VALUE;
ctrl_type = set ? SOF_CTRL_TYPE_VALUE_CHAN_SET : SOF_CTRL_TYPE_VALUE_CHAN_GET;
}
cdata->rhdr.hdr.cmd = SOF_IPC_GLB_COMP_MSG | ipc_cmd;
cdata->type = ctrl_type;
cdata->comp_id = scontrol->comp_id;
cdata->msg_index = 0;
/* calculate header and data size */
switch (cdata->type) {
case SOF_CTRL_TYPE_VALUE_CHAN_GET:
case SOF_CTRL_TYPE_VALUE_CHAN_SET:
cdata->num_elems = scontrol->num_channels;
msg_bytes = scontrol->num_channels *
sizeof(struct sof_ipc_ctrl_value_chan);
msg_bytes += sizeof(struct sof_ipc_ctrl_data);
break;
case SOF_CTRL_TYPE_DATA_GET:
case SOF_CTRL_TYPE_DATA_SET:
cdata->num_elems = cdata->data->size;
msg_bytes = cdata->data->size;
msg_bytes += sizeof(struct sof_ipc_ctrl_data) +
sizeof(struct sof_abi_hdr);
break;
default:
return -EINVAL;
}
cdata->rhdr.hdr.size = msg_bytes;
cdata->elems_remaining = 0;
return iops->set_get_data(sdev, cdata, cdata->rhdr.hdr.size, set);
}
static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size) static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size)
{ {
if (value >= size) if (value >= size)
...@@ -49,7 +128,7 @@ static void snd_sof_refresh_control(struct snd_sof_control *scontrol) ...@@ -49,7 +128,7 @@ static void snd_sof_refresh_control(struct snd_sof_control *scontrol)
/* refresh the component data from DSP */ /* refresh the component data from DSP */
scontrol->comp_data_dirty = false; scontrol->comp_data_dirty = false;
ret = snd_sof_ipc_set_get_comp_data(scontrol, false); ret = sof_ipc3_set_get_kcontrol_data(scontrol, false);
if (ret < 0) { if (ret < 0) {
dev_err(scomp->dev, "Failed to get control data: %d\n", ret); dev_err(scomp->dev, "Failed to get control data: %d\n", ret);
...@@ -97,7 +176,7 @@ static bool sof_ipc3_volume_put(struct snd_sof_control *scontrol, ...@@ -97,7 +176,7 @@ static bool sof_ipc3_volume_put(struct snd_sof_control *scontrol,
/* notify DSP of mixer updates */ /* notify DSP of mixer updates */
if (pm_runtime_active(scomp->dev)) { if (pm_runtime_active(scomp->dev)) {
int ret = snd_sof_ipc_set_get_comp_data(scontrol, true); int ret = sof_ipc3_set_get_kcontrol_data(scontrol, true);
if (ret < 0) { if (ret < 0) {
dev_err(scomp->dev, "Failed to set mixer updates for %s\n", dev_err(scomp->dev, "Failed to set mixer updates for %s\n",
...@@ -145,7 +224,7 @@ static bool sof_ipc3_switch_put(struct snd_sof_control *scontrol, ...@@ -145,7 +224,7 @@ static bool sof_ipc3_switch_put(struct snd_sof_control *scontrol,
/* notify DSP of mixer updates */ /* notify DSP of mixer updates */
if (pm_runtime_active(scomp->dev)) { if (pm_runtime_active(scomp->dev)) {
int ret = snd_sof_ipc_set_get_comp_data(scontrol, true); int ret = sof_ipc3_set_get_kcontrol_data(scontrol, true);
if (ret < 0) { if (ret < 0) {
dev_err(scomp->dev, "Failed to set mixer updates for %s\n", dev_err(scomp->dev, "Failed to set mixer updates for %s\n",
...@@ -193,7 +272,7 @@ static bool sof_ipc3_enum_put(struct snd_sof_control *scontrol, ...@@ -193,7 +272,7 @@ static bool sof_ipc3_enum_put(struct snd_sof_control *scontrol,
/* notify DSP of enum updates */ /* notify DSP of enum updates */
if (pm_runtime_active(scomp->dev)) { if (pm_runtime_active(scomp->dev)) {
int ret = snd_sof_ipc_set_get_comp_data(scontrol, true); int ret = sof_ipc3_set_get_kcontrol_data(scontrol, true);
if (ret < 0) { if (ret < 0) {
dev_err(scomp->dev, "Failed to set enum updates for %s\n", dev_err(scomp->dev, "Failed to set enum updates for %s\n",
...@@ -265,7 +344,7 @@ static int sof_ipc3_bytes_put(struct snd_sof_control *scontrol, ...@@ -265,7 +344,7 @@ static int sof_ipc3_bytes_put(struct snd_sof_control *scontrol,
/* notify DSP of byte control updates */ /* notify DSP of byte control updates */
if (pm_runtime_active(scomp->dev)) if (pm_runtime_active(scomp->dev))
return snd_sof_ipc_set_get_comp_data(scontrol, true); return sof_ipc3_set_get_kcontrol_data(scontrol, true);
return 0; return 0;
} }
...@@ -379,7 +458,7 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, ...@@ -379,7 +458,7 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol,
/* notify DSP of byte control updates */ /* notify DSP of byte control updates */
if (pm_runtime_active(scomp->dev)) if (pm_runtime_active(scomp->dev))
return snd_sof_ipc_set_get_comp_data(scontrol, true); return sof_ipc3_set_get_kcontrol_data(scontrol, true);
return 0; return 0;
} }
...@@ -409,7 +488,7 @@ static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol, ...@@ -409,7 +488,7 @@ static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol,
cdata->data->abi = SOF_ABI_VERSION; cdata->data->abi = SOF_ABI_VERSION;
/* get all the component data from DSP */ /* get all the component data from DSP */
ret = snd_sof_ipc_set_get_comp_data(scontrol, false); ret = sof_ipc3_set_get_kcontrol_data(scontrol, false);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -578,6 +657,43 @@ static void sof_ipc3_control_update(struct snd_sof_dev *sdev, void *ipc_control_ ...@@ -578,6 +657,43 @@ static void sof_ipc3_control_update(struct snd_sof_dev *sdev, void *ipc_control_
snd_ctl_notify_one(swidget->scomp->card->snd_card, SNDRV_CTL_EVENT_MASK_VALUE, kc, 0); snd_ctl_notify_one(swidget->scomp->card->snd_card, SNDRV_CTL_EVENT_MASK_VALUE, kc, 0);
} }
static int sof_ipc3_widget_kcontrol_setup(struct snd_sof_dev *sdev,
struct snd_sof_widget *swidget)
{
struct snd_sof_control *scontrol;
int ret;
/* set up all controls for the widget */
list_for_each_entry(scontrol, &sdev->kcontrol_list, list)
if (scontrol->comp_id == swidget->comp_id) {
/* set kcontrol data in DSP */
ret = sof_ipc3_set_get_kcontrol_data(scontrol, true);
if (ret < 0) {
dev_err(sdev->dev,
"kcontrol %d set up failed for widget %s\n",
scontrol->comp_id, swidget->widget->name);
return ret;
}
/*
* Read back the data from the DSP for static widgets.
* This is particularly useful for binary kcontrols
* associated with static pipeline widgets to initialize
* the data size to match that in the DSP.
*/
if (swidget->dynamic_pipeline_widget)
continue;
ret = sof_ipc3_set_get_kcontrol_data(scontrol, false);
if (ret < 0)
dev_warn(sdev->dev,
"kcontrol %d read failed for widget %s\n",
scontrol->comp_id, swidget->widget->name);
}
return 0;
}
const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = { const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = {
.volume_put = sof_ipc3_volume_put, .volume_put = sof_ipc3_volume_put,
.volume_get = sof_ipc3_volume_get, .volume_get = sof_ipc3_volume_get,
...@@ -591,4 +707,5 @@ const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = { ...@@ -591,4 +707,5 @@ const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops = {
.bytes_ext_get = sof_ipc3_bytes_ext_get, .bytes_ext_get = sof_ipc3_bytes_ext_get,
.bytes_ext_volatile_get = sof_ipc3_bytes_ext_volatile_get, .bytes_ext_volatile_get = sof_ipc3_bytes_ext_volatile_get,
.update = sof_ipc3_control_update, .update = sof_ipc3_control_update,
.widget_kcontrol_setup = sof_ipc3_widget_kcontrol_setup,
}; };
This diff is collapsed.
...@@ -12,51 +12,6 @@ ...@@ -12,51 +12,6 @@
#include "sof-audio.h" #include "sof-audio.h"
#include "ops.h" #include "ops.h"
static int sof_kcontrol_setup(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
{
int ret;
ret = snd_sof_ipc_set_get_comp_data(scontrol, true);
if (ret < 0)
dev_err(sdev->dev, "error: failed kcontrol value set for widget: %d\n",
scontrol->comp_id);
return ret;
}
static int sof_widget_kcontrol_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
{
struct snd_sof_control *scontrol;
int ret;
/* set up all controls for the widget */
list_for_each_entry(scontrol, &sdev->kcontrol_list, list)
if (scontrol->comp_id == swidget->comp_id) {
/* set kcontrol data in DSP */
ret = sof_kcontrol_setup(sdev, scontrol);
if (ret < 0) {
dev_err(sdev->dev, "error: fail to set up kcontrols for widget %s\n",
swidget->widget->name);
return ret;
}
/*
* Read back the data from the DSP for static widgets. This is particularly
* useful for binary kcontrols associated with static pipeline widgets to
* initialize the data size to match that in the DSP.
*/
if (swidget->dynamic_pipeline_widget)
continue;
ret = snd_sof_ipc_set_get_comp_data(scontrol, false);
if (ret < 0)
dev_warn(sdev->dev, "Failed kcontrol get for control in widget %s\n",
swidget->widget->name);
}
return 0;
}
static void sof_reset_route_setup_status(struct snd_sof_dev *sdev, struct snd_sof_widget *widget) static void sof_reset_route_setup_status(struct snd_sof_dev *sdev, struct snd_sof_widget *widget)
{ {
struct snd_sof_route *sroute; struct snd_sof_route *sroute;
...@@ -176,11 +131,10 @@ int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget) ...@@ -176,11 +131,10 @@ int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
} }
/* restore kcontrols for widget */ /* restore kcontrols for widget */
ret = sof_widget_kcontrol_setup(sdev, swidget); if (tplg_ops->control->widget_kcontrol_setup) {
if (ret < 0) { ret = tplg_ops->control->widget_kcontrol_setup(sdev, swidget);
dev_err(sdev->dev, "error: failed to restore kcontrols for widget %s\n", if (ret < 0)
swidget->widget->name); goto widget_free;
goto widget_free;
} }
dev_dbg(sdev->dev, "widget %s setup complete\n", swidget->widget->name); dev_dbg(sdev->dev, "widget %s setup complete\n", swidget->widget->name);
......
...@@ -86,6 +86,8 @@ struct sof_ipc_tplg_control_ops { ...@@ -86,6 +86,8 @@ struct sof_ipc_tplg_control_ops {
const unsigned int __user *binary_data, unsigned int size); const unsigned int __user *binary_data, unsigned int size);
/* update control data based on notification from the DSP */ /* update control data based on notification from the DSP */
void (*update)(struct snd_sof_dev *sdev, void *ipc_control_message); void (*update)(struct snd_sof_dev *sdev, void *ipc_control_message);
/* Optional callback to setup kcontrols associated with an swidget */
int (*widget_kcontrol_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
}; };
/** /**
...@@ -429,11 +431,6 @@ static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstre ...@@ -429,11 +431,6 @@ static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstre
static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { } static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { }
#endif #endif
/*
* Mixer IPC
*/
int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol, bool set);
/* DAI link fixup */ /* DAI link fixup */
int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params); int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
......
...@@ -377,11 +377,32 @@ struct sof_ipc_pcm_ops; ...@@ -377,11 +377,32 @@ struct sof_ipc_pcm_ops;
* @tplg: Pointer to IPC-specific topology ops * @tplg: Pointer to IPC-specific topology ops
* @pm: Pointer to PM ops * @pm: Pointer to PM ops
* @pcm: Pointer to PCM ops * @pcm: Pointer to PCM ops
*
* @tx_msg: Function pointer for sending a 'short' IPC message
* @set_get_data: Function pointer for set/get data ('large' IPC message). This
* function may split up the 'large' message and use the @tx_msg
* path to transfer individual chunks, or use other means to transfer
* the message.
* @get_reply: Function pointer for fetching the reply to
* sdev->ipc->msg.reply_data
* @rx_msg: Function pointer for handling a received message
*
* Note: both @tx_msg and @set_get_data considered as TX functions and they are
* serialized for the duration of the instructed transfer. A large message sent
* via @set_get_data is a single transfer even if at the hardware level it is
* handled with multiple chunks.
*/ */
struct sof_ipc_ops { struct sof_ipc_ops {
const struct sof_ipc_tplg_ops *tplg; const struct sof_ipc_tplg_ops *tplg;
const struct sof_ipc_pm_ops *pm; const struct sof_ipc_pm_ops *pm;
const struct sof_ipc_pcm_ops *pcm; const struct sof_ipc_pcm_ops *pcm;
int (*tx_msg)(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
void *reply_data, size_t reply_bytes, bool no_pm);
int (*set_get_data)(struct snd_sof_dev *sdev, void *data, size_t data_bytes,
bool set);
int (*get_reply)(struct snd_sof_dev *sdev);
void (*rx_msg)(struct snd_sof_dev *sdev);
}; };
/* SOF generic IPC data */ /* SOF generic IPC data */
...@@ -582,12 +603,17 @@ struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev); ...@@ -582,12 +603,17 @@ struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
void snd_sof_ipc_free(struct snd_sof_dev *sdev); void snd_sof_ipc_free(struct snd_sof_dev *sdev);
void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev); void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id); void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev); static inline void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
{
sdev->ipc->ops->rx_msg(sdev);
}
int snd_sof_ipc_valid(struct snd_sof_dev *sdev); int snd_sof_ipc_valid(struct snd_sof_dev *sdev);
int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
void *reply_data, size_t reply_bytes); void *reply_data, size_t reply_bytes);
int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
void *reply_data, size_t reply_bytes); void *reply_data, size_t reply_bytes);
int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
size_t reply_bytes);
int sof_ipc_init_msg_memory(struct snd_sof_dev *sdev); int sof_ipc_init_msg_memory(struct snd_sof_dev *sdev);
static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id) static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
{ {
......
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