alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: Liam Girdwood <liam.r.girdwood@linux.intel.com>,
	Takashi Iwai <tiwai@suse.de>, Mark Brown <broonie@kernel.org>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	sound-open-firmware@alsa-project.org
Subject: [PATCH v2 12/12] [RESEND] ASoC: SOF: VirtIO: enable simultaneous playback and capture
Date: Fri,  3 Apr 2020 11:14:06 +0200	[thread overview]
Message-ID: <20200403091406.22381-13-guennadi.liakhovetski@linux.intel.com> (raw)
In-Reply-To: <20200403091406.22381-1-guennadi.liakhovetski@linux.intel.com>

Dynamically allocate separate playback and capture buffers to enable
simultaneous playback and capture.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
---
 sound/soc/sof/virtio-fe.c | 53 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/sound/soc/sof/virtio-fe.c b/sound/soc/sof/virtio-fe.c
index aa6da81..807562d 100644
--- a/sound/soc/sof/virtio-fe.c
+++ b/sound/soc/sof/virtio-fe.c
@@ -79,17 +79,13 @@ struct sof_vfe {
 	struct completion completion;
 	spinlock_t vq_lock;
 
-	/* A shared capture / playback virtual queue data buffer */
-	union {
-		struct dsp_sof_data_req data_req;
-		struct dsp_sof_data_resp data_resp;
-	};
+	/* Pointers for virtual queue data buffers */
+	struct dsp_sof_data_req *playback_buf;
+	struct dsp_sof_data_resp *capture_buf;
 
 	/* Headers, used as a playback response or capture request */
-	union {
-		u8 hdr_req[HDR_SIZE_REQ];
-		u8 hdr_resp[HDR_SIZE_RESP];
-	};
+	u8 hdr_req[HDR_SIZE_REQ];
+	u8 hdr_resp[HDR_SIZE_RESP];
 };
 
 /* Firmware ready IPC. */
@@ -422,7 +418,7 @@ static int sof_vfe_pcm_read_part(struct snd_sof_dev *sdev,
 				 void __user *buf, unsigned long chunk_size)
 {
 	struct sof_vfe *vfe = sdev->pdata->vfe;
-	struct dsp_sof_data_resp *data = &vfe->data_resp;
+	struct dsp_sof_data_resp *data = vfe->capture_buf;
 	struct scatterlist sg_out, sg_in, *sgs[] = {&sg_out, &sg_in};
 	struct dsp_sof_data_req *req = (struct dsp_sof_data_req *)vfe->hdr_req;
 	unsigned int len;
@@ -480,7 +476,7 @@ static int sof_vfe_pcm_write_part(struct snd_sof_dev *sdev,
 				  void __user *buf, unsigned long chunk_size)
 {
 	struct sof_vfe *vfe = sdev->pdata->vfe;
-	struct dsp_sof_data_req *data = &vfe->data_req;
+	struct dsp_sof_data_req *data = vfe->playback_buf;
 	struct scatterlist sg_out, sg_in, *sgs[] = {&sg_out, &sg_in};
 	struct dsp_sof_data_resp *resp = (struct dsp_sof_data_resp *)vfe->hdr_resp;
 	unsigned int len;
@@ -596,9 +592,43 @@ static int sof_vfe_pcm_open(struct snd_sof_dev *sdev,
 static int sof_vfe_pcm_close(struct snd_sof_dev *sdev,
 			     struct snd_pcm_substream *substream)
 {
+	struct sof_vfe *vfe = sdev->pdata->vfe;
+
 	pm_runtime_mark_last_busy(sdev->dev);
 	pm_runtime_put_autosuspend(sdev->dev);
 
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		kfree(vfe->playback_buf);
+		vfe->playback_buf = NULL;
+	} else {
+		kfree(vfe->capture_buf);
+		vfe->capture_buf = NULL;
+	}
+
+	return 0;
+}
+
+static int sof_vfe_pcm_hw_params(struct snd_sof_dev *sdev,
+				 struct snd_pcm_substream *substream,
+				 struct snd_pcm_hw_params *params,
+				 struct sof_ipc_stream_params *ipc_params)
+{
+	struct sof_vfe *vfe = sdev->pdata->vfe;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+	    !vfe->playback_buf) {
+		vfe->playback_buf = kmalloc(sizeof(*vfe->playback_buf),
+					    GFP_KERNEL);
+		if (!vfe->playback_buf)
+			return -ENOMEM;
+	} else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
+		   !vfe->capture_buf) {
+		vfe->capture_buf = kmalloc(sizeof(*vfe->capture_buf),
+					   GFP_KERNEL);
+		if (!vfe->capture_buf)
+			return -ENOMEM;
+	}
+
 	return 0;
 }
 
@@ -629,6 +659,7 @@ struct snd_sof_dsp_ops snd_sof_vfe_ops = {
 
 	.pcm_open	= sof_vfe_pcm_open,
 	.pcm_close	= sof_vfe_pcm_close,
+	.pcm_hw_params	= sof_vfe_pcm_hw_params,
 
 	.run		= sof_vfe_run,
 	.block_read	= sof_vfe_block_read,
-- 
1.9.3


  parent reply	other threads:[~2020-04-03  9:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-03  9:13 [PATCH v2 00/12] [RESEND] ASoC: SOF DSP virtualisation Guennadi Liakhovetski
2020-04-03  9:13 ` [PATCH v2 01/12] [RESEND] ASoC: add function parameters to enable forced path pruning Guennadi Liakhovetski
2020-04-03  9:13 ` [PATCH v2 02/12] [RESEND] ASoC: SOF: extract firmware-related operation into a function Guennadi Liakhovetski
2020-04-03  9:13 ` [PATCH v2 03/12] [RESEND] ASoC: SOF: VirtIO: make a function global Guennadi Liakhovetski
2020-04-03  9:13 ` [PATCH v2 04/12] [RESEND] vhost: convert VHOST_VSOCK_SET_RUNNING to a generic ioctl Guennadi Liakhovetski
2020-04-03  9:13 ` [PATCH v2 05/12] [RESEND] ASoC: SOF: support IPC with immediate response Guennadi Liakhovetski
2020-04-03  9:14 ` [PATCH v2 06/12] [RESEND] ASoC: SOF: add a power status IPC Guennadi Liakhovetski
2020-04-03  9:14 ` [PATCH v2 07/12] [RESEND] ASoC: SOF: add two helper lookup functions Guennadi Liakhovetski
2020-04-03  9:14 ` [PATCH v2 08/12] [RESEND] ASoC: SOF: add a VirtIO DSP driver Guennadi Liakhovetski
2020-04-03  9:14 ` [PATCH v2 09/12] [RESEND] ASoC: SOF: add a vhost driver: sound part Guennadi Liakhovetski
2020-04-03  9:14 ` [PATCH v2 10/12] [RESEND] vhost: add an SOF DSP driver Guennadi Liakhovetski
2020-04-03  9:14 ` [PATCH v2 11/12] [RESEND] ASoC: SOF: VirtIO: free guest pipelines upon termination Guennadi Liakhovetski
2020-04-03  9:14 ` Guennadi Liakhovetski [this message]
2020-04-03  9:28 ` [PATCH v2 00/12] [RESEND] ASoC: SOF DSP virtualisation Mark Brown
2020-04-03 11:04   ` Guennadi Liakhovetski
2020-04-03 11:26     ` Mark Brown
2020-04-03 16:10     ` [Sound-open-firmware] " Liam Girdwood
2020-04-03 16:21       ` Mark Brown
2020-04-03 18:09       ` Guennadi Liakhovetski
2020-04-07 11:24         ` Guennadi Liakhovetski
2020-04-07 11:30           ` Mark Brown
2020-04-07 12:44             ` Guennadi Liakhovetski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200403091406.22381-13-guennadi.liakhovetski@linux.intel.com \
    --to=guennadi.liakhovetski@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=sound-open-firmware@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).