From patchwork Mon Aug 7 11:50:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9885173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5A41C60363 for ; Mon, 7 Aug 2017 11:53:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C8C928514 for ; Mon, 7 Aug 2017 11:53:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FA382861F; Mon, 7 Aug 2017 11:53:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A2CF128514 for ; Mon, 7 Aug 2017 11:53:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1degYu-00044u-Pt; Mon, 07 Aug 2017 11:51:08 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1degYt-00041g-8h for xen-devel@lists.xen.org; Mon, 07 Aug 2017 11:51:07 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id EF/61-03044-A2458895; Mon, 07 Aug 2017 11:51:06 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRWlGSWpSXmKPExsVyMfS6o65mSEe kwd9TJhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aWzRsZC3bbVDR2nmFuYDxj0sXIxSEk0M8o 8XjvNCYQh0XgJYvE2rbzrCCOhEA/q8TD19+BHE4gJ07i/7597BB2ucSjS0cZQWwhAUWJr8+mM 0GMWskkMf/wCiaQBJuAkcTyGz9YQGwRgQiJY48/sIHYzAKlEjf2z2EGsYUF3CW6Jy4Fq2cRUJ WY8Pg20FAODl4BJ4kLqzkhdslJ3DzXyQwS5gQKty6tgFjrKHF392z2CYwCCxgZVjFqFKcWlaU W6RoZ6SUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCYV6yXn525iBAYWAxDsYFwzP/AQoyQHk5Io b/yKtkghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErz7gzoihQSLUtNTK9Iyc4AhDpOW4OBREuHNB knzFhck5hZnpkOkTjHac1y5su4LE8eG1euB5JQD24Hkqwn/vzEJseTl56VKifOuB2kTAGnLKM 2DGwqLyUuMslLCvIxAZwrxFKQW5WaWoMq/YhTnYFQS5n0AMoUnM68EbvcroLOYgM56k9gKclZ JIkJKqoFReMoZHSEj7r0Lv7Bsf8fe7hF798/KmcXOF75+0sz9acXyfeXaJaek4z/+mqd8UvbS lqbDWXwBr739Yi+slg0v6HbuXByrZXhd8+XtX/y/LKY/5Oxf/nZRcHTVY93e8yJLL+vYLvf4m CJ8VcFg9/Wj7s6Spokbj9rZRrbccrW/8eaHRNM2L2s7JZbijERDLeai4kQA/zHiEMQCAAA= X-Env-Sender: andr2000@gmail.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1502106665!68791335!1 X-Originating-IP: [209.85.215.65] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54769 invoked from network); 7 Aug 2017 11:51:05 -0000 Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by server-5.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Aug 2017 11:51:05 -0000 Received: by mail-lf0-f65.google.com with SMTP id o85so166530lff.1 for ; Mon, 07 Aug 2017 04:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IeqZbqZPo/wa1CXG1qms2ugXQAVQ6Zn5wqYjXXhXKD4=; b=V7CNUWNS44uXNArX8W38OX+kzJSjCz3WGXij88HG9XnvD42miA+S8AH6amkq6JgP7R yVBwV/7PneOv8Pbg4Pbygpp85/i0SEQ49Mb8RC0WCeFLU/qKIvaCUJeLCnQISARoUV5E b+QEW/7UDEM0Or8BlQcRDQxWcQ/Qgz0g05tI3k3ULSREiUqURGOdR/lsw7ROHCtZPqd+ x5hEfr6IjVc33BI43B0VxwQFYIa2e4INNtpqoRbnCxccPqbKRg4YVMSjodB7BhQzXP+E /b8MdHJY2Lc5RrciX/fw7quM9Tgt//JAO+h+f4SQa5/hNyQ5FsWcq8rEeqMpsl8cH+bR YFOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IeqZbqZPo/wa1CXG1qms2ugXQAVQ6Zn5wqYjXXhXKD4=; b=biXkGTzjbocUOW6roRaiKJ7KhX2GYa3uJcBrG3Hl52TGhNDatQhvQwTT/QFRKm7tEi Q0IUK+015mPt26VGwqGjYMs4eXFLszHz1wU2RwGqDdyh0iwOd+6FRLGVuI7/qCS8pWn/ NUcShp/hsjfK3FXSI106Hej23LvjR399+ZNgY9Z6J2o0OSos5NOtWcfgzDCaFx6iovU6 0RsuDqAmaZ156CE+AOwum/QVpK8+VqwVE0Gu6jR51T6XVhNKvpJKVjRqqiwqgr6bKPD6 w6vSQQ9BfPY8dWGh0JWOjVcnwNKxBEXPi5h2U1R0qi9rCxsOKdFheY5UWsMg2fDUOgWo WyJw== X-Gm-Message-State: AHYfb5gmFnUjLsP7vLBnUxGH2nJo3hKS4mcyPOtnRJTZKxTPS7RtDxuN JkudaUJMKjttNZX1 X-Received: by 10.25.141.10 with SMTP id p10mr92490lfd.188.1502106665052; Mon, 07 Aug 2017 04:51:05 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-51.209.223.85.sovam.net.ua. [85.223.209.51]) by smtp.gmail.com with ESMTPSA id n88sm2844587lja.43.2017.08.07.04.51.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 04:51:04 -0700 (PDT) From: Oleksandr Andrushchenko To: alsa-devel@alsa-project.org, xen-devel@lists.xen.org, linux-kernel@vger.kernel.org Date: Mon, 7 Aug 2017 14:50:43 +0300 Message-Id: <1502106645-6731-10-git-send-email-andr2000@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502106645-6731-1-git-send-email-andr2000@gmail.com> References: <1502106645-6731-1-git-send-email-andr2000@gmail.com> Cc: andr2000@gmail.com, Oleksandr Andrushchenko , tiwai@suse.com, perex@perex.cz Subject: [Xen-devel] [PATCH RESEND 09/11] ALSA: vsnd: Implement ALSA PCM operations X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Andrushchenko Implement ALSA driver operations including: - start/stop period interrupt emulation - manage frontend/backend shraed buffers - manage Xen bus event channel state Signed-off-by: Oleksandr Andrushchenko --- sound/drivers/xen-front.c | 175 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 163 insertions(+), 12 deletions(-) diff --git a/sound/drivers/xen-front.c b/sound/drivers/xen-front.c index 507c5eb343c8..7275e9cb38c0 100644 --- a/sound/drivers/xen-front.c +++ b/sound/drivers/xen-front.c @@ -151,6 +151,11 @@ struct xdrv_info { struct sdev_card_plat_data cfg_plat_data; }; +static inline void sh_buf_clear(struct sh_buf_info *buf); +static void sh_buf_free(struct sh_buf_info *buf); +static int sh_buf_alloc(struct xenbus_device *xb_dev, struct sh_buf_info *buf, + unsigned int buffer_size); + static struct sdev_pcm_stream_info *sdrv_stream_get( struct snd_pcm_substream *substream) { @@ -311,71 +316,217 @@ static void sdrv_copy_pcm_hw(struct snd_pcm_hardware *dst, static int sdrv_alsa_open(struct snd_pcm_substream *substream) { - return 0; + struct sdev_pcm_instance_info *pcm_instance = + snd_pcm_substream_chip(substream); + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct xdrv_info *xdrv_info; + unsigned long flags; + int ret; + + sdrv_copy_pcm_hw(&runtime->hw, &stream->pcm_hw, &pcm_instance->pcm_hw); + runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_DOUBLE | + SNDRV_PCM_INFO_BATCH | + SNDRV_PCM_INFO_NONINTERLEAVED | + SNDRV_PCM_INFO_RESUME | + SNDRV_PCM_INFO_PAUSE); + runtime->hw.info |= SNDRV_PCM_INFO_INTERLEAVED; + + xdrv_info = pcm_instance->card_info->xdrv_info; + + ret = sdrv_alsa_timer_create(substream); + + spin_lock_irqsave(&xdrv_info->io_lock, flags); + sh_buf_clear(&stream->sh_buf); + stream->evt_chnl = &xdrv_info->evt_chnls[stream->unique_id]; + if (ret < 0) + stream->evt_chnl->state = EVTCHNL_STATE_DISCONNECTED; + else + stream->evt_chnl->state = EVTCHNL_STATE_CONNECTED; + spin_unlock_irqrestore(&xdrv_info->io_lock, flags); + return ret; } static int sdrv_alsa_close(struct snd_pcm_substream *substream) { + struct sdev_pcm_instance_info *pcm_instance = + snd_pcm_substream_chip(substream); + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct xdrv_info *xdrv_info; + unsigned long flags; + + xdrv_info = pcm_instance->card_info->xdrv_info; + + sdrv_alsa_timer_stop(substream); + + spin_lock_irqsave(&xdrv_info->io_lock, flags); + stream->evt_chnl->state = EVTCHNL_STATE_DISCONNECTED; + spin_unlock_irqrestore(&xdrv_info->io_lock, flags); return 0; } static int sdrv_alsa_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { + struct sdev_pcm_instance_info *pcm_instance = + snd_pcm_substream_chip(substream); + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct xdrv_info *xdrv_info; + unsigned int buffer_size; + int ret; + + buffer_size = params_buffer_bytes(params); + sh_buf_clear(&stream->sh_buf); + xdrv_info = pcm_instance->card_info->xdrv_info; + ret = sh_buf_alloc(xdrv_info->xb_dev, + &stream->sh_buf, buffer_size); + if (ret < 0) + goto fail; return 0; + +fail: + dev_err(&xdrv_info->xb_dev->dev, + "Failed to allocate buffers for stream idx %d\n", + stream->unique_id); + return ret; } static int sdrv_alsa_hw_free(struct snd_pcm_substream *substream) { + struct sdev_pcm_instance_info *pcm_instance = + snd_pcm_substream_chip(substream); + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct xdrv_info *xdrv_info; + unsigned long flags; + + xdrv_info = pcm_instance->card_info->xdrv_info; + spin_lock_irqsave(&xdrv_info->io_lock, flags); + sh_buf_free(&stream->sh_buf); + spin_unlock_irqrestore(&xdrv_info->io_lock, flags); return 0; } static int sdrv_alsa_prepare(struct snd_pcm_substream *substream) { - return 0; + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + int ret = 0; + + if (!stream->is_open) + ret = sdrv_alsa_timer_prepare(substream); + return ret; } static int sdrv_alsa_trigger(struct snd_pcm_substream *substream, int cmd) { + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + /* fall through */ + case SNDRV_PCM_TRIGGER_RESUME: + return sdrv_alsa_timer_start(substream); + + case SNDRV_PCM_TRIGGER_STOP: + /* fall through */ + case SNDRV_PCM_TRIGGER_SUSPEND: + return sdrv_alsa_timer_stop(substream); + + default: + break; + } return 0; } static inline snd_pcm_uframes_t sdrv_alsa_pointer( struct snd_pcm_substream *substream) { + return sdrv_alsa_timer_pointer(substream); +} + +static int sdrv_alsa_playback_do_write(struct snd_pcm_substream *substream, + unsigned long pos, unsigned long count) +{ return 0; } static int sdrv_alsa_playback_copy_user(struct snd_pcm_substream *substream, - int channel, unsigned long pos, void __user *buf, - unsigned long bytes) + int channel, unsigned long pos, void __user *src, + unsigned long count) { - return 0; + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + + if (unlikely(pos + count > stream->sh_buf.vbuffer_sz)) + return -EINVAL; + + if (copy_from_user(stream->sh_buf.vbuffer + pos, src, count)) + return -EFAULT; + + return sdrv_alsa_playback_do_write(substream, pos, count); } static int sdrv_alsa_playback_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, void *buf, unsigned long bytes) + int channel, unsigned long pos, void *src, unsigned long count) +{ + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + + if (unlikely(pos + count > stream->sh_buf.vbuffer_sz)) + return -EINVAL; + + memcpy(stream->sh_buf.vbuffer + pos, src, count); + return sdrv_alsa_playback_do_write(substream, pos, count); +} + +static int sdrv_alsa_playback_do_read(struct snd_pcm_substream *substream, + unsigned long pos, unsigned long count) { return 0; } static int sdrv_alsa_capture_copy_user(struct snd_pcm_substream *substream, - int channel, unsigned long pos, void __user *buf, - unsigned long bytes) + int channel, unsigned long pos, void __user *dst, + unsigned long count) { - return 0; + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + int ret; + + if (unlikely(pos + count > stream->sh_buf.vbuffer_sz)) + return -EINVAL; + + ret = sdrv_alsa_playback_do_read(substream, pos, count); + if (ret < 0) + return ret; + + return copy_to_user(dst, stream->sh_buf.vbuffer + pos, count) ? + -EFAULT : 0; } static int sdrv_alsa_capture_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, void *buf, unsigned long bytes) + int channel, unsigned long pos, void *dst, unsigned long count) { + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + int ret; + + if (unlikely(pos + count > stream->sh_buf.vbuffer_sz)) + return -EINVAL; + + ret = sdrv_alsa_playback_do_read(substream, pos, count); + if (ret < 0) + return ret; + + memcpy(dst, stream->sh_buf.vbuffer + pos, count); return 0; } static int sdrv_alsa_playback_fill_silence(struct snd_pcm_substream *substream, - int channel, unsigned long pos, unsigned long bytes) + int channel, unsigned long pos, unsigned long count) { - return 0; + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + + if (unlikely(pos + count > stream->sh_buf.vbuffer_sz)) + return -EINVAL; + + memset(stream->sh_buf.vbuffer + pos, 0, count); + return sdrv_alsa_playback_do_write(substream, pos, count); } #define MAX_XEN_BUFFER_SIZE (64 * 1024)