From patchwork Mon Aug 7 11:50:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9885141 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 4B95960363 for ; Mon, 7 Aug 2017 11:53:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E36228514 for ; Mon, 7 Aug 2017 11:53:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 331692860D; Mon, 7 Aug 2017 11:53:03 +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=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BA0528514 for ; Mon, 7 Aug 2017 11:53:02 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id F4095267214; Mon, 7 Aug 2017 13:51:11 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1885F2671DC; Mon, 7 Aug 2017 13:51:09 +0200 (CEST) Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by alsa0.perex.cz (Postfix) with ESMTP id A4AF12671C3 for ; Mon, 7 Aug 2017 13:51:04 +0200 (CEST) Received: by mail-lf0-f68.google.com with SMTP id w199so162980lff.2 for ; Mon, 07 Aug 2017 04:51:04 -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=bQ4Taq0YTW0KLAU5fonfVvYQVPffkxiWOmbdQdfezmI=; b=vFXNGAUZlzfTK4Ui42ITUdqhjloKHm6L7Rf6glKkVcZSGsFzFEIJccHRLGUhOWkiIo TW9Gi19UHylZXMWF8h+EvJzzGlX9RCqMVdEVjZ2nY/lKRiRFQixPcQswapUVBrCW6j0R d4eyI2jPEYLT9fTtpBQcxb8Zhz7FIyOIBsrie5ZMltg9w0L2yTRhJb9V0ah+uAvPNocY jCUOBy3Zv/RhlV+2rTNgvgS8FNKhP1XBywBsGPOoIRC1TVJFl+Ey++/zGcX75g3QV7+i LaHAlBFUuIT/WJ9gRkmL72qZQV25rLPs88rd6zWKRwsOWSm2wqTnr3viBYkqqICJxTTZ +Wag== 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=bQ4Taq0YTW0KLAU5fonfVvYQVPffkxiWOmbdQdfezmI=; b=PdJZIuxuEgP3ry3zVGM77l/dbbeyQQ8BtkDYbH2i21vwUFV8JldUo0BVKnAT7Qn16/ Ew1ivpVOmH3fFJt3tN2P0pu7S8GCgvZfIw4LU2tIXt46a4h0ASiGMItc/0vz0dk+80k2 hUi0sxYSCwn1bkkfW3zJ7FWHPAuKQKH99YzDqcuKW9mjn9jS1XJUTttTckYV75vqM/z7 7m70/l98ojanpPCiVdX9lWhQRxcsobahDIC2cfEIu2M+ZPuwtIuy/wE1kDT85694wr8B Zt2P38zfq2PC3ahAhufojesMAVXc8ndvTIHY3J7jaHj6R/jMA0ulsoPtl4h6DFa3KyN5 PU5Q== X-Gm-Message-State: AHYfb5jiHbA0y/sRyeKHCeoq3eCP3rr8gD46nrM7DL0vGVm78lJLIGKl SOHmAgIiPfpl0iob X-Received: by 10.46.21.71 with SMTP id 7mr100695ljv.74.1502106663865; Mon, 07 Aug 2017 04:51:03 -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.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 04:51:02 -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:42 +0300 Message-Id: <1502106645-6731-9-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 Subject: [alsa-devel] [PATCH RESEND 08/11] ALSA: vsnd: Add timer for period interrupt emulation X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Andrushchenko Front sound driver has no real interrupts, so playback/capture period passed interrupt needs to be emulated: this is done via timer. Add required timer operations, this is based on sound/drivers/dummy.c. Signed-off-by: Oleksandr Andrushchenko --- sound/drivers/xen-front.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/sound/drivers/xen-front.c b/sound/drivers/xen-front.c index 9f31e6832086..507c5eb343c8 100644 --- a/sound/drivers/xen-front.c +++ b/sound/drivers/xen-front.c @@ -67,12 +67,29 @@ struct sh_buf_info { size_t vbuffer_sz; }; +struct sdev_alsa_timer_info { + spinlock_t lock; + struct timer_list timer; + unsigned long base_time; + /* fractional sample position (based HZ) */ + unsigned int frac_pos; + unsigned int frac_period_rest; + /* buffer_size * HZ */ + unsigned int frac_buffer_size; + /* period_size * HZ */ + unsigned int frac_period_size; + unsigned int rate; + int elapsed; + struct snd_pcm_substream *substream; +}; + struct sdev_pcm_stream_info { int unique_id; struct snd_pcm_hardware pcm_hw; struct xdrv_evtchnl_info *evt_chnl; bool is_open; uint8_t req_next_id; + struct sdev_alsa_timer_info timer; struct sh_buf_info sh_buf; }; @@ -148,6 +165,110 @@ static struct sdev_pcm_stream_info *sdrv_stream_get( return stream; } +static inline void sdrv_alsa_timer_rearm(struct sdev_alsa_timer_info *dpcm) +{ + mod_timer(&dpcm->timer, jiffies + + (dpcm->frac_period_rest + dpcm->rate - 1) / dpcm->rate); +} + +static void sdrv_alsa_timer_update(struct sdev_alsa_timer_info *dpcm) +{ + unsigned long delta; + + delta = jiffies - dpcm->base_time; + if (!delta) + return; + dpcm->base_time += delta; + delta *= dpcm->rate; + dpcm->frac_pos += delta; + while (dpcm->frac_pos >= dpcm->frac_buffer_size) + dpcm->frac_pos -= dpcm->frac_buffer_size; + while (dpcm->frac_period_rest <= delta) { + dpcm->elapsed++; + dpcm->frac_period_rest += dpcm->frac_period_size; + } + dpcm->frac_period_rest -= delta; +} + +static int sdrv_alsa_timer_start(struct snd_pcm_substream *substream) +{ + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct sdev_alsa_timer_info *dpcm = &stream->timer; + + spin_lock(&dpcm->lock); + dpcm->base_time = jiffies; + sdrv_alsa_timer_rearm(dpcm); + spin_unlock(&dpcm->lock); + return 0; +} + +static int sdrv_alsa_timer_stop(struct snd_pcm_substream *substream) +{ + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct sdev_alsa_timer_info *dpcm = &stream->timer; + + spin_lock(&dpcm->lock); + del_timer(&dpcm->timer); + spin_unlock(&dpcm->lock); + return 0; +} + +static int sdrv_alsa_timer_prepare(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct sdev_alsa_timer_info *dpcm = &stream->timer; + + dpcm->frac_pos = 0; + dpcm->rate = runtime->rate; + dpcm->frac_buffer_size = runtime->buffer_size * HZ; + dpcm->frac_period_size = runtime->period_size * HZ; + dpcm->frac_period_rest = dpcm->frac_period_size; + dpcm->elapsed = 0; + return 0; +} + +static void sdrv_alsa_timer_callback(unsigned long data) +{ + struct sdev_alsa_timer_info *dpcm = (struct sdev_alsa_timer_info *)data; + int elapsed; + + spin_lock(&dpcm->lock); + sdrv_alsa_timer_update(dpcm); + sdrv_alsa_timer_rearm(dpcm); + elapsed = dpcm->elapsed; + dpcm->elapsed = 0; + spin_unlock(&dpcm->lock); + if (elapsed) + snd_pcm_period_elapsed(dpcm->substream); +} + +static snd_pcm_uframes_t sdrv_alsa_timer_pointer( + struct snd_pcm_substream *substream) +{ + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct sdev_alsa_timer_info *dpcm = &stream->timer; + snd_pcm_uframes_t pos; + + spin_lock(&dpcm->lock); + sdrv_alsa_timer_update(dpcm); + pos = dpcm->frac_pos / HZ; + spin_unlock(&dpcm->lock); + return pos; +} + +static int sdrv_alsa_timer_create(struct snd_pcm_substream *substream) +{ + struct sdev_pcm_stream_info *stream = sdrv_stream_get(substream); + struct sdev_alsa_timer_info *dpcm = &stream->timer; + + spin_lock_init(&dpcm->lock); + dpcm->substream = substream; + setup_timer(&dpcm->timer, sdrv_alsa_timer_callback, + (unsigned long) dpcm); + return 0; +} + static void sdrv_copy_pcm_hw(struct snd_pcm_hardware *dst, struct snd_pcm_hardware *src, struct snd_pcm_hardware *ref_pcm_hw)