Audio DSP VirtIO and vhost drivers
Subsystems (8)
cover Audio DSP VirtIO and vhost drivers
This patch set is a follow up to "Add a vhost RPMsg API" [1], it is marked as an RFC because firstly it depends on the RPMsg API series and secondly it is currently being reviewed on ALSA and SOF mailing lists, but any early comments from virtualisation developers would be highly appreciated too!
Thanks
Guennadi
[1] https://mailman.alsa-project.org/pipermail/sound-open-firmware/2020-May/003879.html
Guennadi Liakhovetski (12):
ASoC: add function parameters to enable forced path pruning
ASoC: SOF: extract firmware-related operation into a function
ASoC: SOF: support IPC with immediate response
ASoC: SOF: add a power status IPC
ASoC: SOF: add two helper lookup functions
ASoC: SOF: add an RPMsg VirtIO DSP driver
ASoC: SOF: use a macro instead of a hard-coded value
ASoC: SOF: add a vhost driver: sound part
ASoC: SOF: VirtIO: free guest pipelines upon termination
vhost: add an SOF Audio DSP driver
rpmsg: increase buffer size and reduce buffer number
rpmsg: add a device ID to also bind to the ADSP device
drivers/rpmsg/virtio_rpmsg_bus.c | 1 + drivers/vhost/Kconfig | 10 + drivers/vhost/Makefile | 3 + drivers/vhost/adsp.c | 618 +++++++++++++++++++ include/linux/virtio_rpmsg.h | 4 +- include/sound/soc-dpcm.h | 28 +- include/sound/soc-topology.h | 3 + include/sound/sof.h | 4 + include/sound/sof/header.h | 3 + include/sound/sof/rpmsg.h | 196 ++++++ include/sound/sof/topology.h | 9 +- include/uapi/linux/vhost.h | 5 + include/uapi/linux/vhost_types.h | 7 + include/uapi/linux/virtio_ids.h | 1 + sound/soc/soc-compress.c | 2 +- sound/soc/soc-dapm.c | 8 +- sound/soc/soc-pcm.c | 98 ++- sound/soc/sof/Kconfig | 7 + sound/soc/sof/Makefile | 2 + sound/soc/sof/core.c | 114 ++-- sound/soc/sof/ipc.c | 34 +- sound/soc/sof/loader.c | 4 + sound/soc/sof/ops.h | 10 +- sound/soc/sof/pcm.c | 13 +- sound/soc/sof/pm.c | 6 +- sound/soc/sof/rpmsg-vfe.c | 881 ++++++++++++++++++++++++++ sound/soc/sof/sof-audio.c | 33 + sound/soc/sof/sof-audio.h | 21 + sound/soc/sof/sof-priv.h | 48 ++ sound/soc/sof/topology.c | 71 ++- sound/soc/sof/vhost-vbe.c | 1258 ++++++++++++++++++++++++++++++++++++++ 31 files changed, 3391 insertions(+), 111 deletions(-) create mode 100644 drivers/vhost/adsp.c create mode 100644 include/sound/sof/rpmsg.h create mode 100644 sound/soc/sof/rpmsg-vfe.c create mode 100644 sound/soc/sof/vhost-vbe.c
Signature · 1 line
1.9.3
RFC 1/12 ASoC: add function parameters to enable forced path pruning
This is a preparation for the host part of a virtualised VirtIO audio host-guest driver pair. It adds a "mode" parameter to soc_dpcm_runtime_update() to allow it to be used when stopping streaming in a virtual machine, which requires forced DPCM audio path pruning.
For audio virtualisation the host side driver will be using the vhost API, i.e. it will run completely in the kernel. When a guest begins to stream audio, the vhost calls snd_soc_runtime_activate() and soc_dpcm_runtime_update() to activate an audio path and update audio routing. When streaming is stopped, the vhost driver calls soc_dpcm_runtime_update() and snd_soc_runtime_deactivate(). The latter doesn't work at the moment, because the DPCM doesn't recognise the path as inactive. We address this by adding a "mode" parameter to soc_dpcm_runtime_update(). If virtualisation isn't used, the current behaviour isn't affected.
--- include/sound/soc-dpcm.h | 28 ++++++++++++++++---- sound/soc/soc-compress.c | 2 +- sound/soc/soc-dapm.c | 8 +++--- sound/soc/soc-pcm.c | 67 +++++++++++++++++++++++++++++++++--------------- 4 files changed, 74 insertions(+), 31 deletions(-)
include/sound/soc-dpcm.h +23 -5
@@ -61,6 +61,23 @@ enum snd_soc_dpcm_trigger { SND_SOC_DPCM_TRIGGER_BESPOKE, }; +/** +* enum snd_soc_dpcm_update_mode - mode for calling soc_dpcm_runtime_update() +* +* @SND_SOC_DPCM_UPDATE_FULL: default mode, used for mux, mixer, and +* volume widgets +* @SND_SOC_DPCM_UPDATE_NEW_ONLY: a pipeline is starting. Skip checking +* for old paths. +* @SND_SOC_DPCM_UPDATE_OLD_ONLY: a pipeline is shutting down. Skip +* checking for new paths, force old path +* pruning. +*/ +enum snd_soc_dpcm_update_mode { +SND_SOC_DPCM_UPDATE_FULL , +SND_SOC_DPCM_UPDATE_NEW_ONLY , +SND_SOC_DPCM_UPDATE_OLD_ONLY , +}; +/* * Dynamic PCM link * This links together a FE and BE DAI at runtime and stores the link
@@ -133,7 +150,8 @@ struct snd_pcm_substream * snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream);/* update audio routing between PCMs and any DAI links */ -int snd_soc_dpcm_runtime_update (struct snd_soc_card *card); +int snd_soc_dpcm_runtime_update (struct snd_soc_card *card, +enum snd_soc_dpcm_update_mode mode);#ifdef CONFIG_DEBUG_FS void soc_dpcm_debugfs_add (struct snd_soc_pcm_runtime *rtd);
@@ -143,11 +161,11 @@ static inline void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) }#endif -int dpcm_path_get (struct snd_soc_pcm_runtime *fe, -int stream,struct snd_soc_dapm_widget_list **list_); +int dpcm_path_get (struct snd_soc_pcm_runtime *fe,int stream, +struct snd_soc_dapm_widget_list **list_);void dpcm_path_put (struct snd_soc_dapm_widget_list **list); -int dpcm_process_paths (struct snd_soc_pcm_runtime *fe, -int stream,struct snd_soc_dapm_widget_list **list,int new); +int dpcm_process_paths (struct snd_soc_pcm_runtime *fe,int stream, +struct snd_soc_dapm_widget_list **list,bool new,bool force_prune);int dpcm_be_dai_startup (struct snd_soc_pcm_runtime *fe,int stream);int dpcm_be_dai_shutdown (struct snd_soc_pcm_runtime *fe,int stream);void dpcm_be_disconnect (struct snd_soc_pcm_runtime *fe,int stream);
sound/soc/soc-compress.c +1 -1
@@ -155,7 +155,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)dev_dbg (fe->dev,"Compress ASoC: %s no valid %s route\n" , fe->dai_link->name, stream ?"capture" :"playback" );/* calculate valid and active FE <-> BE dpcms */ -dpcm_process_paths (fe, stream, &list,1 ); +dpcm_process_paths (fe, stream, &list, true, false); fe->dpcm[stream].runtime = fe_substream->runtime; fe->dpcm[stream].runtime_update =SND_SOC_DPCM_UPDATE_FE ;
sound/soc/soc-dapm.c +4 -4
@@ -2311,7 +2311,7 @@ int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm, card->update =NULL ;mutex_unlock (&card->dapm_mutex);if (ret >0 ) -snd_soc_dpcm_runtime_update (card); +snd_soc_dpcm_runtime_update (card,SND_SOC_DPCM_UPDATE_FULL );return ret; }EXPORT_SYMBOL_GPL (snd_soc_dapm_mux_update_power);
@@ -2376,7 +2376,7 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm, card->update =NULL ;mutex_unlock (&card->dapm_mutex);if (ret >0 ) -snd_soc_dpcm_runtime_update (card); +snd_soc_dpcm_runtime_update (card,SND_SOC_DPCM_UPDATE_FULL );return ret; }EXPORT_SYMBOL_GPL (snd_soc_dapm_mixer_update_power);
@@ -3416,7 +3416,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,mutex_unlock (&card->dapm_mutex);if (ret >0 ) -snd_soc_dpcm_runtime_update (card); +snd_soc_dpcm_runtime_update (card,SND_SOC_DPCM_UPDATE_FULL );return change; }
@@ -3521,7 +3521,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,mutex_unlock (&card->dapm_mutex);if (ret >0 ) -snd_soc_dpcm_runtime_update (card); +snd_soc_dpcm_runtime_update (card,SND_SOC_DPCM_UPDATE_FULL );return change; }
sound/soc/soc-pcm.c +46 -21
142 lines not on this page · raw message
Signature · 1 line
1.9.3
RFC 2/12 ASoC: SOF: extract firmware-related operation into a function
In reply to Guennadi LiakhovetskiIn the VirtIO guest case the SOF will not be dealing with the firmware directly. Extract related functionality into a function to make the separation easier.
--- sound/soc/sof/core.c | 85 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 36 deletions(-)
sound/soc/sof/core.c +49 -36
@@ -135,6 +135,53 @@ void snd_sof_get_status(struct snd_sof_dev *sdev, u32 panic_code,* (System Suspend/Runtime Suspend) */ +static int sof_load_and_run_firmware (struct snd_sof_dev *sdev) +{ +/* load the firmware */ +int ret =snd_sof_load_firmware (sdev); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to load DSP firmware %d\n" , + ret); +return ret; + } + + sdev->fw_state =SOF_FW_BOOT_IN_PROGRESS ; + +/* +* Boot the firmware. The FW boot status will be modified +* in snd_sof_run_firmware() depending on the outcome. +*/ + ret =snd_sof_run_firmware (sdev); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to boot DSP firmware %d\n" , + ret); + goto fw_run_err; + } + +if (IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_FIRMWARE_TRACE ) || + (sof_core_debug &SOF_DBG_ENABLE_TRACE )) { + sdev->dtrace_is_supported = true; + +/* init DMA trace */ + ret =snd_sof_init_trace (sdev); +if (ret <0 ) { +/* non fatal */ +dev_warn (sdev->dev, +"warning: failed to initialize trace %d\n" , + ret); + } + }else { +dev_dbg (sdev->dev,"SOF firmware trace disabled\n" ); + } + +return 0 ; + +fw_run_err: +snd_sof_fw_unload (sdev); + +return ret; +} +static int sof_probe_continue (struct snd_sof_dev *sdev) {struct snd_sof_pdata *plat_data = sdev->pdata;
@@ -181,42 +228,9 @@ static int sof_probe_continue(struct snd_sof_dev *sdev) goto ipc_err; } -/* load the firmware */ - ret =snd_sof_load_firmware (sdev); -if (ret <0 ) { -dev_err (sdev->dev,"error: failed to load DSP firmware %d\n" , - ret); + ret =sof_load_and_run_firmware (sdev); +if (ret <0 ) goto fw_load_err; - } - - sdev->fw_state =SOF_FW_BOOT_IN_PROGRESS ; - -/* -* Boot the firmware. The FW boot status will be modified -* in snd_sof_run_firmware() depending on the outcome. -*/ - ret =snd_sof_run_firmware (sdev); -if (ret <0 ) { -dev_err (sdev->dev,"error: failed to boot DSP firmware %d\n" , - ret); - goto fw_run_err; - } - -if (IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_FIRMWARE_TRACE ) || - (sof_core_debug &SOF_DBG_ENABLE_TRACE )) { - sdev->dtrace_is_supported = true; - -/* init DMA trace */ - ret =snd_sof_init_trace (sdev); -if (ret <0 ) { -/* non fatal */ -dev_warn (sdev->dev, -"warning: failed to initialize trace %d\n" , - ret); - } - }else { -dev_dbg (sdev->dev,"SOF firmware trace disabled\n" ); - }/* hereafter all FW boot flows are for PM reasons */ sdev->first_boot = false;
@@ -250,7 +264,6 @@ static int sof_probe_continue(struct snd_sof_dev *sdev) fw_trace_err:snd_sof_free_trace (sdev); -fw_run_err:snd_sof_fw_unload (sdev); fw_load_err:snd_sof_ipc_free (sdev);
Signature · 1 line
1.9.3
RFC 3/12 ASoC: SOF: support IPC with immediate response
In reply to Guennadi LiakhovetskiUsually when an IPC message is sent, we have to wait for a reply from the DSP or from the host in the VirtIO case. However, sometimes in the VirtIO case a response is available immediately. Skip sleeping in such cases.
--- sound/soc/sof/ipc.c | 11 +++++++---- sound/soc/sof/ops.h | 10 +++++++++- 2 files changed, 16 insertions(+), 5 deletions(-)
sound/soc/sof/ipc.c +7 -4
@@ -262,6 +262,12 @@ static int sof_ipc_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header, sdev->msg = msg; +/* +* If snd_sof_dsp_send_msg() returns a positive number it means, that a +* response is already available, no need to sleep waiting for it. In +* such a case msg->ipc_complete will stay true and tx_wait_done() will +* return immediately. +*/ ret =snd_sof_dsp_send_msg (sdev, msg);/* Next reply that we receive will be related to this message */ if (!ret)
@@ -279,10 +285,7 @@ static int sof_ipc_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header,ipc_log_header (sdev->dev,"ipc tx" , msg->header);/* now wait for completion */ -if (!ret) - ret =tx_wait_done (ipc, msg, reply_data); - -return ret; +return tx_wait_done (ipc, msg, reply_data); }/* send IPC message from host to DSP */
sound/soc/sof/ops.h +9 -1
@@ -274,7 +274,15 @@ static inline void snd_sof_dsp_block_write(struct snd_sof_dev *sdev, u32 bar,sof_ops (sdev)->block_write (sdev, bar, offset, src, bytes); } -/* ipc */ +/** +* snd_sof_dsp_send_msg - call sdev ops to send a message +* @sdev: sdev context +* @msg: message to send +* +* Returns < 0 - an error code +* 0 - the message has been sent, wait for a reply +* > 0 - the message has been sent, a reply is already available +*/ static inline int snd_sof_dsp_send_msg (struct snd_sof_dev *sdev,struct snd_sof_ipc_msg *msg) {
Signature · 1 line
1.9.3
RFC 4/12 ASoC: SOF: add a power status IPC
In reply to Guennadi LiakhovetskiIn a virtualised configuration the runtime PM of the host and any guests aren't synchronised. But guests have to be able to tell the host when they suspend and resume and know, whether the host has been runtime suspended since that guests's topology had been sent to the host last time. This is needed to decide whether to re-send the topology again. To support this we add a new PM IPC message SOF_IPC_PM_VFE_POWER_STATUS and a reset counter to track the state of the DSP.
--- include/sound/sof/header.h | 1 + sound/soc/sof/core.c | 2 ++ sound/soc/sof/ipc.c | 2 ++ sound/soc/sof/loader.c | 4 ++++ sound/soc/sof/sof-priv.h | 4 ++++ 5 files changed, 13 insertions(+)
include/sound/sof/header.h +1 -0
@@ -77,6 +77,7 @@#define SOF_IPC_PM_CLK_REQ SOF_CMD_TYPE(0x006)#define SOF_IPC_PM_CORE_ENABLE SOF_CMD_TYPE(0x007)#define SOF_IPC_PM_GATE SOF_CMD_TYPE(0x008) +#define SOF_IPC_PM_VFE_POWER_STATUS SOF_CMD_TYPE(0x010)/* component runtime config - multiple different types */ #define SOF_IPC_COMP_SET_VALUE SOF_CMD_TYPE(0x001)
sound/soc/sof/core.c +2 -0
@@ -8,6 +8,7 @@// Author: Liam Girdwood <[email protected]> // +#include <linux/atomic.h> #include <linux/firmware.h> #include <linux/module.h> #include <sound/soc.h>
@@ -312,6 +313,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)#if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_PROBES ) sdev->extractor_stream_tag =SOF_PROBE_INVALID_NODE_ID ;#endif +atomic_set (&sdev->dsp_reset_count,0 );dev_set_drvdata (dev, sdev);/* check all mandatory ops */
sound/soc/sof/ipc.c +2 -0
@@ -105,6 +105,8 @@ static void ipc_log_header(struct device *dev, u8 *text, u32 cmd) str2 ="CLK_REQ" ;break ;case SOF_IPC_PM_CORE_ENABLE : str2 ="CORE_ENABLE" ;break ; +case SOF_IPC_PM_VFE_POWER_STATUS : + str2 ="VFE_POWER_STATUS" ;break ;default : str2 ="unknown type" ;break ; }
sound/soc/sof/loader.c +4 -0
@@ -10,6 +10,7 @@// Generic firmware loader. // +#include <linux/atomic.h> #include <linux/firmware.h> #include <sound/sof.h> #include "ops.h"
@@ -620,6 +621,9 @@ int snd_sof_run_firmware(struct snd_sof_dev *sdev)/* fw boot is complete. Update the active cores mask */ sdev->enabled_cores_mask = init_core_mask; +/* increment reset count */ +atomic_add (1 , &sdev->dsp_reset_count); +return 0 ; }EXPORT_SYMBOL (snd_sof_run_firmware);
sound/soc/sof/sof-priv.h +4 -0
@@ -11,6 +11,7 @@#ifndef __SOUND_SOC_SOF_PRIV_H#define __SOUND_SOC_SOF_PRIV_H +#include <linux/atomic.h> #include <linux/device.h> #include <sound/hdaudio.h> #include <sound/sof.h>
@@ -425,6 +426,9 @@ struct snd_sof_dev {unsigned int extractor_stream_tag;#endif +/* VirtIO fields for host and guest */ +atomic_t dsp_reset_count; +/* DMA for Trace */ struct snd_dma_buffer dmatb;struct snd_dma_buffer dmatp;
Signature · 1 line
1.9.3
RFC 5/12 ASoC: SOF: add two helper lookup functions
In reply to Guennadi LiakhovetskiAdd two helper lookup functions for finding a widget by its component ID and a DAI by a pipeline ID.
--- sound/soc/sof/sof-audio.c | 24 ++++++++++++++++++++++++ sound/soc/sof/sof-audio.h | 5 +++++ sound/soc/sof/topology.c | 1 + 3 files changed, 30 insertions(+)
sound/soc/sof/sof-audio.c +24 -0
@@ -395,6 +395,30 @@ struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,return NULL ; } +struct snd_sof_widget *snd_sof_find_swidget_id (struct snd_sof_dev *sdev, +unsigned int comp_id) +{ +struct snd_sof_widget *swidget; + +list_for_each_entry (swidget, &sdev->widget_list, list) +if (swidget->comp_id == comp_id) +return swidget; + +return NULL ; +} + +struct snd_sof_dai *snd_sof_find_dai_pipe (struct snd_sof_dev *sdev, +unsigned int pipeline_id) +{ +struct snd_sof_dai *dai; + +list_for_each_entry (dai, &sdev->dai_list, list) +if (dai->pipeline_id == pipeline_id) +return dai; + +return NULL ; +} +/* * SOF Driver enumeration. */
sound/soc/sof/sof-audio.h +5 -0
@@ -106,6 +106,7 @@ struct snd_sof_dai {struct snd_soc_component *scomp;const char *name;const char *cpu_dai_name; +unsigned int pipeline_id;struct sof_ipc_comp_dai comp_dai;struct sof_ipc_dai_config *dai_config;
@@ -190,6 +191,10 @@ struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp, int *direction);struct snd_sof_pcm *snd_sof_find_spcm_pcm_id (struct snd_soc_component *scomp,unsigned int pcm_id); +struct snd_sof_widget *snd_sof_find_swidget_id (struct snd_sof_dev *sdev, +unsigned int comp_id); +struct snd_sof_dai *snd_sof_find_dai_pipe (struct snd_sof_dev *sdev, +unsigned int pipeline_id);void snd_sof_pcm_period_elapsed (struct snd_pcm_substream *substream);void snd_sof_pcm_period_elapsed_work (struct work_struct *work);
sound/soc/sof/topology.c +1 -0
@@ -1406,6 +1406,7 @@ static int sof_widget_load_dai(struct snd_soc_component *scomp, int index,if (ret ==0 && dai) { dai->scomp = scomp; + dai->pipeline_id = swidget->pipeline_id;memcpy (&dai->comp_dai, &comp_dai,sizeof (comp_dai)); }
Signature · 1 line
1.9.3
RFC 6/12 ASoC: SOF: add an RPMsg VirtIO DSP driver
In reply to Guennadi LiakhovetskiAdd a VirtIO driver, designed to work with the SOF vhost driver, using the RPMsg protocol layer. This driver allows SOF to be used on Virtual Machines (VMs) where the host is also a Linux system, using the SOF driver natively. This driver communicates with the host using the RPMsg standard over Virtual Queues. This version uses 3 RPMsg
endpoints: for control, for data and for position updates. The control endpoint uses exactly the same IPC protocol as what is used by the SOF driver natively to communicate with the DSP. In the future a zero-copy capability should be added thus eliminating 2 out of 3 endpoints and only preserving the control channel.
--- include/sound/sof.h | 4 + include/sound/sof/header.h | 2 + include/sound/sof/rpmsg.h | 120 ++++++ include/sound/sof/topology.h | 9 +- include/uapi/linux/virtio_ids.h | 1 + sound/soc/sof/Kconfig | 7 + sound/soc/sof/Makefile | 4 + sound/soc/sof/core.c | 29 +- sound/soc/sof/ipc.c | 16 +- sound/soc/sof/pcm.c | 9 + sound/soc/sof/rpmsg-vfe.c | 881 ++++++++++++++++++++++++++++++++++++++++ sound/soc/sof/sof-priv.h | 28 ++ sound/soc/sof/topology.c | 18 +- 13 files changed, 1099 insertions(+), 29 deletions(-) create mode 100644 include/sound/sof/rpmsg.h create mode 100644 sound/soc/sof/rpmsg-vfe.c
include/sound/sof.h +4 -0
@@ -17,6 +17,8 @@struct snd_sof_dsp_ops ; +struct sof_vfe ; +/* * SOF Platform data. */
@@ -30,6 +32,8 @@ struct snd_sof_pdata {/* indicate how many first bytes shouldn't be loaded into DSP memory. */ size_t fw_offset; +struct sof_vfe *vfe; +/* * notification callback used if the hardware initialization * can take time or is handled in a workqueue. This callback
include/sound/sof/header.h +2 -0
@@ -67,6 +67,8 @@#define SOF_IPC_TPLG_PIPE_COMPLETE SOF_CMD_TYPE(0x013)#define SOF_IPC_TPLG_BUFFER_NEW SOF_CMD_TYPE(0x020)#define SOF_IPC_TPLG_BUFFER_FREE SOF_CMD_TYPE(0x021) +#define SOF_IPC_TPLG_VFE_GET SOF_CMD_TYPE(0x030) +#define SOF_IPC_TPLG_VFE_COMP_ID SOF_CMD_TYPE(0x031)/* PM */ #define SOF_IPC_PM_CTX_SAVE SOF_CMD_TYPE(0x001)
include/sound/sof/rpmsg.h new file +120 -0
120 lines not on this page · raw message
include/sound/sof/topology.h +5 -4
@@ -33,12 +33,13 @@ enum sof_comp_type {SOF_COMP_EQ_IIR ,SOF_COMP_EQ_FIR ,SOF_COMP_KEYWORD_DETECT , -SOF_COMP_KPB ,/* A key phrase buffer component */ -SOF_COMP_SELECTOR ,/**< channel selector component */ +SOF_COMP_KPB ,/**< key phrase buffer component */ +SOF_COMP_SELECTOR ,/**< channel selector component */ SOF_COMP_DEMUX , -SOF_COMP_ASRC ,/**< Asynchronous sample rate converter */ +SOF_COMP_ASRC ,/**< asynchronous sample rate converter */ SOF_COMP_DCBLOCK , -SOF_COMP_SMART_AMP ,/**< smart amplifier component */ +SOF_COMP_SMART_AMP ,/**< smart amplifier component */ +SOF_COMP_VIRT_CON ,/**< virtual connection, sent by the VirtIO guest */ /* keep FILEREAD/FILEWRITE as the last ones */ SOF_COMP_FILEREAD =10000 ,/**< host test based file IO */ SOF_COMP_FILEWRITE = 10001, /**< host test based file IO */
include/uapi/linux/virtio_ids.h +1 -0
@@ -46,6 +46,7 @@#define VIRTIO_ID_IOMMU 23/* virtio IOMMU */ #define VIRTIO_ID_FS 26/* virtio filesystem */ #define VIRTIO_ID_PMEM 27/* virtio pmem */ +#define VIRTIO_ID_ADSP 28/* virtio AudioDSP */ #define VIRTIO_ID_MAC80211_HWSIM 29/* virtio mac80211-hwsim */ #endif /* _LINUX_VIRTIO_IDS_H */
sound/soc/sof/Kconfig +7 -0
@@ -96,6 +96,13 @@ config SND_SOC_SOF_STRICT_ABI_CHECKS If you are not involved in SOF releases and CI development select "N". +config SND_SOC_SOF_RPMSG_FE + bool "SOF VirtIO guest role" + depends on SND_SOC_SOF_NOCODEC_SUPPORT + depends on VIRTIO && RPMSG_VIRTIO + ---help--- + Enable SOF for a VirtIO based guest configuration. + config SND_SOC_SOF_DEBUG bool "SOF debugging features" help
sound/soc/sof/Makefile +4 -0
@@ -10,6 +10,10 @@ snd-sof-of-objs := sof-of-dev.o snd-sof-nocodec-objs := nocodec.o +ifdef CONFIG_SND_SOC_SOF_RPMSG_FE +snd-sof-objs += rpmsg-vfe.o +endif + obj-$(CONFIG_SND_SOC_SOF) += snd-sof.o obj-$(CONFIG_SND_SOC_SOF_NOCODEC) += snd-sof-nocodec.o
sound/soc/sof/core.c +19 -10
@@ -178,7 +178,8 @@ static int sof_load_and_run_firmware(struct snd_sof_dev *sdev)return 0 ; fw_run_err: -snd_sof_fw_unload (sdev); +if (!sdev->pdata->vfe) +snd_sof_fw_unload (sdev);return ret; }
@@ -229,9 +230,12 @@ static int sof_probe_continue(struct snd_sof_dev *sdev) goto ipc_err; } - ret =sof_load_and_run_firmware (sdev); -if (ret <0 ) - goto fw_load_err; +/* virtio front-end mode will not touch HW, skip fw loading */ +if (!plat_data->vfe) { + ret =sof_load_and_run_firmware (sdev); +if (ret <0 ) + goto fw_load_err; + }/* hereafter all FW boot flows are for PM reasons */ sdev->first_boot = false;
@@ -265,7 +269,8 @@ static int sof_probe_continue(struct snd_sof_dev *sdev) fw_trace_err:snd_sof_free_trace (sdev); -snd_sof_fw_unload (sdev); +if (!sdev->pdata->vfe) +snd_sof_fw_unload (sdev); fw_load_err:snd_sof_ipc_free (sdev); ipc_err:
@@ -369,10 +374,12 @@ int snd_sof_device_remove(struct device *dev)cancel_work_sync (&sdev->probe_work);if (sdev->fw_state >SOF_FW_BOOT_NOT_STARTED ) { -snd_sof_fw_unload (sdev); +if (!pdata->vfe) { +snd_sof_fw_unload (sdev); +snd_sof_free_trace (sdev); + }snd_sof_ipc_free (sdev);snd_sof_free_debug (sdev); -snd_sof_free_trace (sdev); }/*
@@ -391,9 +398,11 @@ int snd_sof_device_remove(struct device *dev)if (sdev->fw_state >SOF_FW_BOOT_NOT_STARTED )snd_sof_remove (sdev); -/* release firmware */ -release_firmware (pdata->fw); - pdata->fw =NULL ; +if (!pdata->vfe) { +/* release firmware */ +release_firmware (pdata->fw); + pdata->fw =NULL ; + }return 0 ; }
sound/soc/sof/ipc.c +4 -12
@@ -25,18 +25,6 @@* IPC message Tx/Rx message handling. */ -/* SOF generic IPC data */ -struct snd_sof_ipc { -struct snd_sof_dev *sdev; - -/* protects messages and the disable flag */ -struct mutex tx_mutex; -/* disables further sending of ipc's */ -bool disable_ipc_tx; - -struct snd_sof_ipc_msg msg; -}; -struct sof_ipc_ctrl_data_params {size_t msg_bytes;size_t hdr_bytes;
@@ -84,6 +72,10 @@ static void ipc_log_header(struct device *dev, u8 *text, u32 cmd) str2 ="BUFFER_NEW" ;break ;case SOF_IPC_TPLG_BUFFER_FREE : str2 ="BUFFER_FREE" ;break ; +case SOF_IPC_TPLG_VFE_GET : + str2 ="VFE_GET" ;break ; +case SOF_IPC_TPLG_VFE_COMP_ID : + str2 ="VFE_COMP_ID" ;break ;default : str2 ="unknown type" ;break ; }
sound/soc/sof/pcm.c +9 -0
@@ -678,6 +678,13 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,return -EINVAL ; } +/* VirtIO guests have no .dai_config, DAIs are configured by the host */ +if (!dai->dai_config) { +dev_dbg (component->dev,"no DAI config for %s!\n" , + rtd->dai_link->name); +return 0 ; + } +/* read rate and channels from topology */ switch (dai->dai_config->type) {case SOF_DAI_INTEL_SSP :
@@ -793,6 +800,8 @@ void snd_sof_new_platform_drv(struct snd_sof_dev *sdev) pd->hw_free = sof_pcm_hw_free; pd->trigger = sof_pcm_trigger; pd->pointer = sof_pcm_pointer; +if (plat_data->vfe) + pd->copy_user = sof_vfe_pcm_copy_user;#if IS_ENABLED (CONFIG_SND_SOC_SOF_COMPRESS ) pd->compress_ops = &sof_compressed_ops;
sound/soc/sof/rpmsg-vfe.c new file +881 -0
881 lines not on this page · raw message
sound/soc/sof/sof-priv.h +28 -0
@@ -55,6 +55,9 @@ (IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE ) || \IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST )) +/* The maximum number of components a virtio user vFE driver can use */ +#define SOF_RPMSG_MAX_UOS_COMPS 1000 +/* DSP power state */ enum sof_dsp_power_states {SOF_DSP_PM_D0 ,
@@ -250,6 +253,10 @@ struct snd_sof_dsp_ops {void (*set_mach_params)(const struct snd_soc_acpi_mach *mach,struct device *dev);/* optional */ +/* VirtIO operations */ +int (*request_topology)(struct snd_sof_dev *sdev, +struct firmware *fw);/* optional */ +/* DAI ops */ struct snd_soc_dai_driver *drv;int num_drv;
@@ -445,6 +452,18 @@ struct snd_sof_dev {void *private;/* core does not touch this */ }; +/* SOF generic IPC data */ +struct snd_sof_ipc { +struct snd_sof_dev *sdev; + +/* protects messages and the disable flag */ +struct mutex tx_mutex; +/* disables further sending of ipc's */ +bool disable_ipc_tx; + +struct snd_sof_ipc_msg msg; +}; +/* * Device Level. */
@@ -524,6 +543,15 @@ void snd_sof_get_status(struct snd_sof_dev *sdev, u32 panic_code,int snd_sof_init_trace_ipc (struct snd_sof_dev *sdev);void snd_sof_handle_fw_exception (struct snd_sof_dev *sdev); +#if IS_ENABLED (CONFIG_SND_SOC_SOF_RPMSG_FE ) +int sof_vfe_pcm_copy_user (struct snd_soc_component *component, +struct snd_pcm_substream *substream,int channel, +unsigned long pos,void __user *buf, +unsigned long bytes); +#else +#define sof_vfe_pcm_copy_user NULL +#endif +/* * Platform specific ops. */
sound/soc/sof/topology.c +15 -3
@@ -1375,7 +1375,8 @@ static int sof_widget_load_dai(struct snd_soc_component *scomp, int index, comp_dai.comp.hdr.size =sizeof (comp_dai); comp_dai.comp.hdr.cmd =SOF_IPC_GLB_TPLG_MSG |SOF_IPC_TPLG_COMP_NEW ; comp_dai.comp.id = swidget->comp_id; - comp_dai.comp.type =SOF_COMP_DAI ; + comp_dai.comp.type = sdev->pdata->vfe ?SOF_COMP_VIRT_CON : +SOF_COMP_DAI ; comp_dai.comp.pipeline_id = index; comp_dai.config.hdr.size =sizeof (comp_dai.config);
@@ -3604,12 +3605,21 @@ static int sof_manifest(struct snd_soc_component *scomp, int index,int snd_sof_load_topology (struct snd_soc_component *scomp,const char *file) { +struct snd_sof_dev *sdev =snd_soc_component_get_drvdata (scomp); +struct firmware vfe_fw;const struct firmware *fw;int ret;dev_dbg (scomp->dev,"loading topology:%s\n" , file); - ret =request_firmware (&fw, file, scomp->dev); +/* VirtIO guests request topology from the host */ +if (sdev->pdata->vfe) { + fw = &vfe_fw; + ret =sof_ops (sdev)->request_topology (sdev, file, &vfe_fw); + }else { + ret =request_firmware (&fw, file, sdev->dev); + } +if (ret <0 ) {dev_err (scomp->dev,"error: tplg request firmware %s failed err: %d\n" , file, ret);
@@ -3625,7 +3635,9 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file) ret = -EINVAL ; } -release_firmware (fw); +if (!sdev->pdata->vfe) +release_firmware (fw); +return ret; }EXPORT_SYMBOL (snd_sof_load_topology);
Signature · 1 line
1.9.3
RFC 7/12 ASoC: SOF: use a macro instead of a hard-coded value
In reply to Guennadi Liakhovetskitarget_stats in sof_suspend should contain one of SOF_DSP_PM_* power state macros, not a hard-coded value 0.
--- sound/soc/sof/pm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sof/pm.c +1 -1
@@ -174,7 +174,7 @@ static int sof_resume(struct device *dev, bool runtime_resume)static int sof_suspend (struct device *dev,bool runtime_suspend) {struct snd_sof_dev *sdev =dev_get_drvdata (dev); -u32 target_state =0 ; +u32 target_state =SOF_DSP_PM_D0 ;int ret;/* do nothing if dsp suspend callback is not set */
Signature · 1 line
1.9.3
RFC 8/12 ASoC: SOF: add a vhost driver: sound part
In reply to Guennadi LiakhovetskiThe SOF VirtIO driver uses a vhost RPMsg driver as a counterpart to communicate with the DSP. This patch adds a sound interface of the vhost driver.
--- include/sound/soc-topology.h | 3 + include/sound/sof/rpmsg.h | 72 +++ include/uapi/linux/vhost.h | 5 + include/uapi/linux/vhost_types.h | 7 + sound/soc/soc-pcm.c | 31 +- sound/soc/sof/Makefile | 6 +- sound/soc/sof/core.c | 6 + sound/soc/sof/ipc.c | 5 + sound/soc/sof/pcm.c | 4 +- sound/soc/sof/pm.c | 4 + sound/soc/sof/sof-audio.c | 9 + sound/soc/sof/sof-audio.h | 16 + sound/soc/sof/sof-priv.h | 16 + sound/soc/sof/topology.c | 54 +- sound/soc/sof/vhost-vbe.c | 1102 ++++++++++++++++++++++++++++++++++++++ 15 files changed, 1324 insertions(+), 16 deletions(-) create mode 100644 sound/soc/sof/vhost-vbe.c
include/sound/soc-topology.h +3 -0
@@ -34,6 +34,9 @@/* object scan be loaded and unloaded in groups with identfying indexes */ #define SND_SOC_TPLG_INDEX_ALL 0/* ID that matches all FW objects */ +#define SOC_VIRT_DAI_PLAYBACK "VM FE Playback" +#define SOC_VIRT_DAI_CAPTURE "VM FE Capture" +/* dynamic object type */ enum snd_soc_dobj_type {SND_SOC_DOBJ_NONE =0 ,/* object is not dynamic */
include/sound/sof/rpmsg.h +72 -0
82 lines not on this page · raw message
include/uapi/linux/vhost.h +5 -0
@@ -142,4 +142,9 @@/* Get the max ring size. */ #define VHOST_VDPA_GET_VRING_NUM _IOR(VHOST_VIRTIO, 0x76, __u16) +/* VHOST_ADSP specific defines */ + +#define VHOST_ADSP_SET_GUEST_TPLG _IOW(VHOST_VIRTIO, 0x80, \ + struct vhost_adsp_topology) +#endif
include/uapi/linux/vhost_types.h +7 -0
@@ -13,6 +13,7 @@#include <linux/types.h> #include <linux/compiler.h> +#include <linux/limits.h> #include <linux/virtio_config.h> #include <linux/virtio_ring.h>
@@ -127,6 +128,12 @@ struct vhost_vdpa_config {__u8 buf[0 ]; }; +/* VHOST_ADSP */ + +struct vhost_adsp_topology { +char name[NAME_MAX +1 ]; +}; +/* Feature bits */ /* Log all write descriptors. Can be changed while device is active. */ #define VHOST_F_LOG_ALL 26
sound/soc/soc-pcm.c +21 -10
@@ -24,6 +24,7 @@#include <sound/pcm_params.h> #include <sound/soc.h> #include <sound/soc-dpcm.h> +#include <sound/soc-topology.h> #include <sound/initval.h> #define DPCM_MAX_BE_USERS 8
@@ -1418,10 +1419,15 @@ static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget,int stream;/* adjust dir to stream */ -if (dir ==SND_SOC_DAPM_DIR_OUT ) +if (dir ==SND_SOC_DAPM_DIR_OUT ) { +if (!strcmp (widget->sname,SOC_VIRT_DAI_PLAYBACK )) +return false; stream =SNDRV_PCM_STREAM_PLAYBACK ; -else + }else { +if (!strcmp (widget->sname,SOC_VIRT_DAI_CAPTURE )) +return false; stream =SNDRV_PCM_STREAM_CAPTURE ; + } rtd =dpcm_get_be (card, widget, stream);if (rtd)
@@ -2977,14 +2983,6 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) rtd->pcm = pcm; pcm->private_data = rtd; -if (rtd->dai_link->no_pcm || rtd->dai_link->params) { -if (playback) - pcm->streams[SNDRV_PCM_STREAM_PLAYBACK ].substream->private_data = rtd; -if (capture) - pcm->streams[SNDRV_PCM_STREAM_CAPTURE ].substream->private_data = rtd; - goto out; - } -/* ASoC PCM operations */ if (rtd->dai_link->dynamic) { rtd->ops.open = dpcm_fe_dai_open;
@@ -3004,6 +3002,19 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) rtd->ops.pointer = soc_pcm_pointer; } +if (rtd->dai_link->no_pcm || rtd->dai_link->params) { +/* +* Usually in this case we also don't need to assign .ops +* callbacks, but in case of a "no PCM" pipeline, used by a VM +* we use the .prepare() hook to configure the hardware. +*/ +if (playback) + pcm->streams[SNDRV_PCM_STREAM_PLAYBACK ].substream->private_data = rtd; +if (capture) + pcm->streams[SNDRV_PCM_STREAM_CAPTURE ].substream->private_data = rtd; + goto out; + } +for_each_rtd_components (rtd, i, component) {const struct snd_soc_component_driver *drv = component->driver;
sound/soc/sof/Makefile +2 -4
@@ -3,6 +3,8 @@ 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 snd-sof-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += probe.o compress.o +snd-sof-$(CONFIG_SND_SOC_SOF_RPMSG_FE) += rpmsg-vfe.o +snd-sof-$(CONFIG_VHOST_SOF) += vhost-vbe.o snd-sof-pci-objs := sof-pci-dev.o snd-sof-acpi-objs := sof-acpi-dev.o
@@ -10,10 +12,6 @@ snd-sof-of-objs := sof-of-dev.o snd-sof-nocodec-objs := nocodec.o -ifdef CONFIG_SND_SOC_SOF_RPMSG_FE -snd-sof-objs += rpmsg-vfe.o -endif - obj-$(CONFIG_SND_SOC_SOF) += snd-sof.o obj-$(CONFIG_SND_SOC_SOF_NOCODEC) += snd-sof-nocodec.o
sound/soc/sof/core.c +6 -0
@@ -13,6 +13,8 @@#include <linux/module.h> #include <sound/soc.h> #include <sound/sof.h> +#include <sound/sof/rpmsg.h> +#include "sof-audio.h" #include "sof-priv.h" #include "ops.h" #if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_PROBES )
@@ -222,6 +224,9 @@ static int sof_probe_continue(struct snd_sof_dev *sdev) goto dbg_err; } +/* enable the vhost driver on this device */ +sof_vhost_dev_set (sdev); +/* init the IPC */ sdev->ipc =snd_sof_ipc_init (sdev);if (!sdev->ipc) {
@@ -334,6 +339,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)INIT_LIST_HEAD (&sdev->widget_list);INIT_LIST_HEAD (&sdev->dai_list);INIT_LIST_HEAD (&sdev->route_list); +INIT_LIST_HEAD (&sdev->vbe_list);spin_lock_init (&sdev->ipc_lock);spin_lock_init (&sdev->hw_lock);
sound/soc/sof/ipc.c +5 -0
@@ -14,6 +14,8 @@#include <linux/mutex.h> #include <linux/types.h> +#include <sound/sof/rpmsg.h> +#include "sof-priv.h" #include "sof-audio.h" #include "ops.h"
@@ -452,6 +454,9 @@ static void ipc_period_elapsed(struct snd_sof_dev *sdev, u32 msg_id)memcpy (&stream->posn, &posn,sizeof (posn)); +/* optionally update position for vBE */ +sof_vhost_update_guest_posn (sdev, &posn); +/* only inform ALSA for period_wakeup mode */ if (!stream->substream->runtime->no_period_wakeup)snd_sof_pcm_period_elapsed (stream->substream);
sound/soc/sof/pcm.c +3 -1
@@ -91,7 +91,8 @@ void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)* To avoid sending IPC before the previous IPC is handled, we * schedule delayed work here to call the snd_pcm_period_elapsed(). */ -schedule_work (&spcm->stream[substream->stream].period_elapsed_work); +if (spcm->stream[substream->stream].substream) +schedule_work (&spcm->stream[substream->stream].period_elapsed_work); }EXPORT_SYMBOL (snd_sof_pcm_period_elapsed);
@@ -758,6 +759,7 @@ static int sof_pcm_probe(struct snd_soc_component *component)/* load the default topology */ sdev->component = component; + sdev->card = component->card; tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, "%s/%s",
sound/soc/sof/pm.c +4 -0
@@ -8,6 +8,8 @@// Author: Liam Girdwood <[email protected]> // +#include <sound/sof/rpmsg.h> +#include "ops.h" #include "sof-priv.h" #include "sof-audio.h"
@@ -253,6 +255,8 @@ static int sof_suspend(struct device *dev, bool runtime_suspend)/* reset FW state */ sdev->fw_state =SOF_FW_BOOT_NOT_STARTED ; +sof_vhost_suspend (sdev); +return ret; }
sound/soc/sof/sof-audio.c +9 -0
@@ -151,6 +151,7 @@ int sof_restore_pipelines(struct device *dev)struct snd_sof_dai *dai;struct sof_ipc_comp_dai *comp_dai;struct sof_ipc_cmd_hdr *hdr; +struct sof_ipc_buffer *buffer;int ret;/* restore pipeline components */
@@ -182,6 +183,14 @@ int sof_restore_pipelines(struct device *dev) pipeline = swidget->private; ret =sof_load_pipeline_ipc (dev, pipeline, &r);break ; + +case snd_soc_dapm_buffer: + + buffer = swidget->private; +if (!buffer->size) +break ; + +/* Fall through */ default : hdr = swidget->private; ret = sof_ipc_tx_message(sdev->ipc, hdr->cmd,
sound/soc/sof/sof-audio.h +16 -0
@@ -41,6 +41,7 @@ struct snd_sof_pcm_stream {* active or not while suspending the stream */ bool suspend_ignored; +size_t guest_offset; };/* ALSA SOF PCM device */
@@ -217,4 +218,19 @@ int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol,int sof_machine_register (struct snd_sof_dev *sdev,void *pdata);void sof_machine_unregister (struct snd_sof_dev *sdev,void *pdata); +#if IS_ENABLED (CONFIG_VHOST_SOF ) +int sof_vhost_add_conn (struct snd_sof_dev *sdev, +struct snd_sof_widget *w_host, +struct snd_sof_widget *w_guest, +enum sof_ipc_stream_direction direction); +#else +static inline int sof_vhost_add_conn (struct snd_sof_dev *sdev, +struct snd_sof_widget *w_host, +struct snd_sof_widget *w_guest, +enum sof_ipc_stream_direction direction) +{ +return 0 ; +} +#endif +#endif
sound/soc/sof/sof-priv.h +16 -0
@@ -57,6 +57,18 @@/* The maximum number of components a virtio user vFE driver can use */ #define SOF_RPMSG_MAX_UOS_COMPS 1000 +#define SOF_RPMSG_COMP_ID_UNASSIGNED 0xffffffff + +/* +* in virtio iovec array: +* iovec[0]: the ipc message data between vFE and vBE +* iovec[1]: the ipc reply data between vFE and vBE +*/ +#define SOF_RPMSG_IPC_MSG 0 +#define SOF_RPMSG_IPC_REPLY 1 + +/* Maximum supported number of VirtIO clients */ +#define SND_SOF_MAX_VFES BITS_PER_LONG/* DSP power state */ enum sof_dsp_power_states {
@@ -368,6 +380,7 @@ struct snd_sof_dev {* can't use const */ struct snd_soc_component_driver plat_drv; +struct snd_soc_card *card;/* current DSP power state */ struct sof_dsp_power_state dsp_power_state;
@@ -435,6 +448,9 @@ struct snd_sof_dev {/* VirtIO fields for host and guest */ atomic_t dsp_reset_count; +struct list_head vbe_list; +struct list_head connector_list; +unsigned long vfe_mask[DIV_ROUND_UP (SND_SOF_MAX_VFES ,BITS_PER_LONG )];/* DMA for Trace */ struct snd_dma_buffer dmatb;
sound/soc/sof/topology.c +53 -1
84 lines not on this page · raw message
sound/soc/sof/vhost-vbe.c new file +1102 -0
1,102 lines not on this page · raw message
Signature · 1 line
1.9.3
RFC 9/12 ASoC: SOF: VirtIO: free guest pipelines upon termination
In reply to Guennadi LiakhovetskiCurrently the SOF driver switches off the DSP every time runtime or system-wide suspend is entered. After the DSP is turned off, next time it's turned on, the firmware and topology have to be re-sent to it.
When a guest SOF instance restarts it sends its topology to the host, which then forwards it to the DSP. This is correct if the DSP was suspended during that time and lost the guest's topology. However, if the DSP stayed active during that entire time, sending duplicate components to it produces errors. To prevent this from happening this patch adds freeing of components during guest shut down.
--- include/sound/sof/rpmsg.h | 4 ++ sound/soc/sof/vhost-vbe.c | 158 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 161 insertions(+), 1 deletion(-)
include/sound/sof/rpmsg.h +4 -0
@@ -137,6 +137,9 @@ struct sof_vhost_client {struct list_head pipe_conn;/* List of vhost instances on a DSP */ struct list_head list; +/* List of widgets to free for tear-down */ +struct list_head comp_list; +struct list_head pipe_list;/* Component ID range index in the bitmap */ unsigned int id;
@@ -167,6 +170,7 @@ void *sof_vhost_stream_data(struct sof_vhost_client *client,int sof_vhost_ipc_fwd (struct sof_vhost_client *client,void *ipc_buf,void *reply_buf,size_t count,size_t reply_sz); +void sof_vhost_topology_purge (struct sof_vhost_client *client);/* The below functions are always referenced, they need dummy counterparts */ int sof_vhost_update_guest_posn(struct snd_sof_dev *sdev,
sound/soc/sof/vhost-vbe.c +157 -1
224 lines not on this page · raw message
Signature · 1 line
1.9.3
RFC 10/12 vhost: add an SOF Audio DSP driver
In reply to Guennadi LiakhovetskiThe SOF ADSP vhost driver consists of two parts: a sound and a vhost part. This patch implements the vhost part of the driver. It handles QEMU communication with the vhost misc device and virtual queues to any VirtIO RPMsg guests.
--- drivers/vhost/Kconfig | 10 + drivers/vhost/Makefile | 3 + drivers/vhost/adsp.c | 618 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 631 insertions(+) create mode 100644 drivers/vhost/adsp.c
drivers/vhost/Kconfig +10 -0
@@ -54,6 +54,16 @@ config VHOST_SCSI Say M here to enable the vhost_scsi TCM fabric module for use with virtio-scsi guests +config VHOST_SOF + tristate "Vhost SOF driver" + depends on SND_SOC_SOF + select VHOST + select VHOST_RPMSG + default n + help + SOF vhost VirtIO driver. It exports the same IPC interface, as the + one, used for Audio DSP communication, to Linux VirtIO guests. + config VHOST_VSOCK tristate "vhost virtio-vsock driver" depends on VSOCKETS && EVENTFD
drivers/vhost/Makefile +3 -0
@@ -8,6 +8,9 @@ vhost_rpmsg-y := rpmsg.o obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o vhost_scsi-y := scsi.o +obj-$(CONFIG_VHOST_SOF) += vhost_sof.o +vhost_sof-y := adsp.o + obj-$(CONFIG_VHOST_VSOCK) += vhost_vsock.o vhost_vsock-y := vsock.o
drivers/vhost/adsp.c new file +618 -0
618 lines not on this page · raw message
Signature · 1 line
1.9.3
RFC 11/12 rpmsg: increase buffer size and reduce buffer number
In reply to Guennadi LiakhovetskiIt is hard to imagine use-cases where 512 buffers would really be needed, whereas 512 bytes per buffer might be too little. Change this to use 16 16KiB buffers instead.
--- include/linux/virtio_rpmsg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/virtio_rpmsg.h +2 -2
@@ -72,8 +72,8 @@ enum rpmsg_ns_flags {* can change this without changing anything in the firmware of the remote * processor. */ -#define MAX_RPMSG_NUM_BUFS 512 -#define MAX_RPMSG_BUF_SIZE 512 +#define MAX_RPMSG_NUM_BUFS (512 / 32) +#define MAX_RPMSG_BUF_SIZE (512 * 32)/* Address 53 is reserved for advertising remote services */ #define RPMSG_NS_ADDR 53
Signature · 1 line
1.9.3
Mathieu Poirier
maintainerRe: [RFC 11/12] rpmsg: increase buffer size and reduce buffer number
Hi Guennadi,
Quoted 14 lines · Guennadi Liakhovetski
It is hard to imagine use-cases where 512 buffers would really be needed, whereas 512 bytes per buffer might be too little. Change this to use 16 16KiB buffers instead.
Signed-off-by Guennadi Liakhovetski <[email protected]>--- include/linux/virtio_rpmsg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/virtio_rpmsg.h +0
-0
include/linux/virtio_rpmsg.h enum rpmsg_ns_flags { · line 76
Quoted 7 lines
include/linux/virtio_rpmsg.h +2
-2@@ -72,8 +72,8 @@ enum rpmsg_ns_flags {* can change this without changing anything in the firmware of the remote * processor. */ -#define MAX_RPMSG_NUM_BUFS 512 -#define MAX_RPMSG_BUF_SIZE 512 +#define MAX_RPMSG_NUM_BUFS (512 / 32) +#define MAX_RPMSG_BUF_SIZE (512 * 32)
These have been a standard in the rpmsg protocol since the inception of the subsystem 9 years ago and can't be changed without serious impact to existing implementations.
I suggest to dynamically set the number and size of the buffers to use based on the value of virtio_device_id::device. To do that please spin off a new function, something like rpmsg_get_buffer_size(), and in there use the device ID to fetch the numbers based on vdev->id->device. That way the rpmsg driver can be used by multiple clients and the specifics of the buffers adjusted without impact to other users.
Thanks,
Mathieu
Quoted 6 lines
include/linux/virtio_rpmsg.h +0
-0/* Address 53 is reserved for advertising remote services */ #define RPMSG_NS_ADDR 53Signature · 1 line
1.9.3
Re: [RFC 11/12] rpmsg: increase buffer size and reduce buffer number
Hi Mathieu,
Quoted 12 lines · Mathieu Poirier
Hi Guennadi,
Quoted 9 lines · Guennadi Liakhovetski
It is hard to imagine use-cases where 512 buffers would really be needed, whereas 512 bytes per buffer might be too little. Change this to use 16 16KiB buffers instead.
Signed-off-by Guennadi Liakhovetski <[email protected]>--- include/linux/virtio_rpmsg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 16 lines
include/linux/virtio_rpmsg.h enum rpmsg_ns_flags { · line 76
Quoted 12 lines
include/linux/virtio_rpmsg.h +2
-2@@ -72,8 +72,8 @@ enum rpmsg_ns_flags {* can change this without changing anything in the firmware of the remote * processor. */ -#define MAX_RPMSG_NUM_BUFS 512 -#define MAX_RPMSG_BUF_SIZE 512 +#define MAX_RPMSG_NUM_BUFS (512 / 32) +#define MAX_RPMSG_BUF_SIZE (512 * 32)These have been a standard in the rpmsg protocol since the inception of the subsystem 9 years ago and can't be changed without serious impact to existing implementations.
Yes, I expected this to raise complaints. I just modified them to be able to run my code, but a better solution is needed for sure.
Quoted 6 lines
I suggest to dynamically set the number and size of the buffers to use based on the value of
virtio_device_id::device. To do that please spin off a new function, something likerpmsg_get_buffer_size(), and in there use the device ID to fetch the numbers based onvdev->id->device. That way the rpmsg driver can be used by multiple clients and the specifics of the buffers adjusted without impact to other users.
I'll look into this!
Thanks
Guennadi
Quoted 9 lines
Thanks,
MathieuQuoted 6 lines
include/linux/virtio_rpmsg.h +0
-0/* Address 53 is reserved for advertising remote services */ #define RPMSG_NS_ADDR 53Signature · 1 line
1.9.3
RFC 12/12 rpmsg: add a device ID to also bind to the ADSP device
In reply to Guennadi LiakhovetskiThe ADSP device uses the RPMsg API to connect vhost and VirtIO SOF Audio DSP drivers on KVM host and guest.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 1 + 1 file changed, 1 insertion(+)
drivers/rpmsg/virtio_rpmsg_bus.c +1 -0
@@ -949,6 +949,7 @@ static void rpmsg_remove(struct virtio_device *vdev)static struct virtio_device_id id_table[] = { {VIRTIO_ID_RPMSG ,VIRTIO_DEV_ANY_ID }, + {VIRTIO_ID_ADSP ,VIRTIO_DEV_ANY_ID }, {0 }, };
Signature · 1 line
1.9.3
Mathieu Poirier
maintainerRe: [RFC 12/12] rpmsg: add a device ID to also bind to the ADSP device
Quoted 13 lines · Guennadi Liakhovetski
The ADSP device uses the RPMsg API to connect vhost and VirtIO SOF Audio DSP drivers on KVM host and guest.
Signed-off-by Guennadi Liakhovetski <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 1 + 1 file changed, 1 insertion(+)drivers/rpmsg/virtio_rpmsg_bus.c +0
-0
drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_remove(struct virtio_device *vdev) · line 952
Quoted 4 lines
drivers/rpmsg/virtio_rpmsg_bus.c +1
-0@@ -949,6 +949,7 @@ static void rpmsg_remove(struct virtio_device *vdev)static struct virtio_device_id id_table[] = { {VIRTIO_ID_RPMSG ,VIRTIO_DEV_ANY_ID }, + {VIRTIO_ID_ADSP ,VIRTIO_DEV_ANY_ID },
I am fine with this patch but won't add an RB because of the (many) checkpatch errors. Based on the comment I made on the previous set seeing those was unexpected.
Thanks,
Mathieu
Quoted 6 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0{ 0 }, };Signature · 1 line
1.9.3
Re: [RFC 12/12] rpmsg: add a device ID to also bind to the ADSP device
Hi Mathieu,
Quoted 15 lines · Mathieu Poirier
Quoted 14 lines · Guennadi Liakhovetski
The ADSP device uses the RPMsg API to connect vhost and VirtIO SOF Audio DSP drivers on KVM host and guest.
Signed-off-by Guennadi Liakhovetski <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 1 + 1 file changed, 1 insertion(+)drivers/rpmsg/virtio_rpmsg_bus.c +0
-0@@ -949,6 +949,7 @@ static void rpmsg_remove(struct virtio_device *vdev)
Quoted 7 lines
drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_remove(struct virtio_device *vdev) · line 952
Quoted 3 lines
drivers/rpmsg/virtio_rpmsg_bus.c +1
-0static struct virtio_device_id id_table[] = { {VIRTIO_ID_RPMSG ,VIRTIO_DEV_ANY_ID }, + {VIRTIO_ID_ADSP ,VIRTIO_DEV_ANY_ID },I am fine with this patch but won't add an RB because of the (many) checkpatch errors. Based on the comment I made on the previous set seeing those was unexpected.
Are you using "--strict?" Sorry, I don't see any checkpatch errors, only warnings. Most of them are "over 80 characters" which as we now know is no more an issue, I just haven't updated my tree yet. Most others are really minor IMHO. Maybe one of them I actually would want to fix - using "help" instead of "---help---" in Kconfig. What errors are you seeing in your checks?
Thanks
Guennadi
Quoted 9 lines
Thanks,
MathieuQuoted 6 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0{ 0 }, };Signature · 1 line
1.9.3
Mathieu Poirier
maintainerRe: [RFC 12/12] rpmsg: add a device ID to also bind to the ADSP device
Quoted 26 lines · Guennadi Liakhovetski
Hi Mathieu,
Quoted 15 lines · Mathieu Poirier
Quoted 14 lines · Guennadi Liakhovetski
The ADSP device uses the RPMsg API to connect vhost and VirtIO SOF Audio DSP drivers on KVM host and guest.
Signed-off-by Guennadi Liakhovetski <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 1 + 1 file changed, 1 insertion(+)drivers/rpmsg/virtio_rpmsg_bus.c +0
-0@@ -949,6 +949,7 @@ static void rpmsg_remove(struct virtio_device *vdev)Quoted 7 lines
drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_remove(struct virtio_device *vdev) · line 952
Quoted 3 lines
drivers/rpmsg/virtio_rpmsg_bus.c +1
-0static struct virtio_device_id id_table[] = { {VIRTIO_ID_RPMSG ,VIRTIO_DEV_ANY_ID }, + {VIRTIO_ID_ADSP ,VIRTIO_DEV_ANY_ID },I am fine with this patch but won't add an RB because of the (many) checkpatch errors. Based on the comment I made on the previous set seeing those was unexpected.
Quoted 1 line
Are you using "--strict?" Sorry, I don't see any checkpatch errors, only warnings.
No, plane checkpatch on the rproc-next branch.
Quoted 1 line
Most of them are "over 80 characters" which as we now know is no more an issue,
There is a thread discussing the matter but I have not seen a clear resolution yet.
Quoted 1 line
I just haven't updated my tree yet. Most others are really minor IMHO. Maybe one
Minor or not, if checkpatch complains then it is important enough to address. I am willing to overlook the lines over 80 characters but everything else needs to be dealt with.
Thanks,
Mathieu
Quoted 15 lines
of them I actually would want to fix - using "help" instead of "---help---" in
Kconfig. What errors are you seeing in your checks?Thanks
GuennadiQuoted 9 lines
Thanks,
MathieuQuoted 6 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0{ 0 }, };Signature · 1 line
1.9.3
Re: [RFC 12/12] rpmsg: add a device ID to also bind to the ADSP device
Hi Mathieu,
Quoted 27 lines · Mathieu Poirier
Quoted 26 lines · Guennadi Liakhovetski
Hi Mathieu,
Quoted 22 lines · Mathieu Poirier
Quoted 13 lines · Guennadi Liakhovetski
The ADSP device uses the RPMsg API to connect vhost and VirtIO SOF Audio DSP drivers on KVM host and guest.
Signed-off-by Guennadi Liakhovetski <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 1 + 1 file changed, 1 insertion(+)drivers/rpmsg/virtio_rpmsg_bus.c +0
-0drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_remove(struct virtio_device *vdev) · line 952
Quoted 4 lines
drivers/rpmsg/virtio_rpmsg_bus.c +1
-0@@ -949,6 +949,7 @@ static void rpmsg_remove(struct virtio_device *vdev)static struct virtio_device_id id_table[] = { {VIRTIO_ID_RPMSG ,VIRTIO_DEV_ANY_ID }, + {VIRTIO_ID_ADSP ,VIRTIO_DEV_ANY_ID },I am fine with this patch but won't add an RB because of the (many) checkpatch errors. Based on the comment I made on the previous set seeing those was unexpected.
Quoted 8 lines
Quoted 1 line
Are you using "--strict?" Sorry, I don't see any checkpatch errors, only warnings.
No, plane checkpatch on the rproc-next branch.
Quoted 1 line
Most of them are "over 80 characters" which as we now know is no more an issue,
There is a thread discussing the matter but I have not seen a clear resolution yet.
I think the resolution is pretty clear as defined by Linus, but maybe it has changed again since I last checked.
Quoted 5 lines
Quoted 1 line
I just haven't updated my tree yet. Most others are really minor IMHO. Maybe one
Minor or not, if checkpatch complains then it is important enough to address. I am willing to overlook the lines over 80 characters but everything else needs to be dealt with.
Sure, checkpatch should be run before each patch submission and whatever it reports should be considered. As Documentation/process/submitting-patches.rst clearly states:
"Check your patches with the patch style checker prior to submission (scripts/checkpatch.pl). Note, though, that the style checker should be viewed as a guide, not as a replacement for human judgment. If your code looks better with a violation then its probably best left alone."
So, yes, I checked all what checkepatch reported and used my judgement to decide which recommendations to take and which to ignore.
Thanks
Guennadi
Quoted 18 lines
Thanks,
MathieuQuoted 15 lines
of them I actually would want to fix - using "help" instead of "---help---" in
Kconfig. What errors are you seeing in your checks?Thanks
GuennadiQuoted 9 lines
Thanks,
MathieuQuoted 6 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0{ 0 }, };Signature · 1 line
1.9.3
Mathieu Poirier
maintainerRe: [RFC 12/12] rpmsg: add a device ID to also bind to the ADSP device
Quoted 52 lines · Guennadi Liakhovetski
Hi Mathieu,
Quoted 27 lines · Mathieu Poirier
Quoted 26 lines · Guennadi Liakhovetski
Hi Mathieu,
Quoted 22 lines · Mathieu Poirier
Quoted 13 lines · Guennadi Liakhovetski
The ADSP device uses the RPMsg API to connect vhost and VirtIO SOF Audio DSP drivers on KVM host and guest.
Signed-off-by Guennadi Liakhovetski <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 1 + 1 file changed, 1 insertion(+)drivers/rpmsg/virtio_rpmsg_bus.c +0
-0drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_remove(struct virtio_device *vdev) · line 952
Quoted 4 lines
drivers/rpmsg/virtio_rpmsg_bus.c +1
-0@@ -949,6 +949,7 @@ static void rpmsg_remove(struct virtio_device *vdev)static struct virtio_device_id id_table[] = { {VIRTIO_ID_RPMSG ,VIRTIO_DEV_ANY_ID }, + {VIRTIO_ID_ADSP ,VIRTIO_DEV_ANY_ID },I am fine with this patch but won't add an RB because of the (many) checkpatch errors. Based on the comment I made on the previous set seeing those was unexpected.
Quoted 8 lines
Quoted 1 line
Are you using "--strict?" Sorry, I don't see any checkpatch errors, only warnings.
No, plane checkpatch on the rproc-next branch.
Quoted 1 line
Most of them are "over 80 characters" which as we now know is no more an issue,
There is a thread discussing the matter but I have not seen a clear resolution yet.
I think the resolution is pretty clear as defined by Linus, but maybe it has changed again since I last checked.
Quoted 5 lines
Quoted 1 line
I just haven't updated my tree yet. Most others are really minor IMHO. Maybe one
Minor or not, if checkpatch complains then it is important enough to address. I am willing to overlook the lines over 80 characters but everything else needs to be dealt with.
Sure, checkpatch should be run before each patch submission and whatever it reports should be considered. As
Documentation/process/submitting-patches.rstclearly states:
Quoted 7 lines
"Check your patches with the patch style checker prior to submission (
scripts/checkpatch.pl). Note, though, that the style checker should be viewed as a guide, not as a replacement for human judgment. If your code looks better with a violation then its probably best left alone."So, yes, I checked all what checkepatch reported and used my judgement to decide which recommendations to take and which to ignore.
I will let Michael and friends decide how to handle checkpatch warnings in the vhost subsystem but as far as remoteproc/rpmsg are concerned, I will not review patches that trigger warnings.
There is a patch in linux-next that deprecates warnings for lines over 80 characters, so those are no longer a problem.
Quoted 22 lines
Thanks
GuennadiQuoted 18 lines
Thanks,
MathieuQuoted 15 lines
of them I actually would want to fix - using "help" instead of "---help---" in
Kconfig. What errors are you seeing in your checks?Thanks
GuennadiQuoted 9 lines
Thanks,
MathieuQuoted 6 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0{ 0 }, };Signature · 1 line
1.9.3