From patchwork Mon Aug 7 12:22:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9885265 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 425A460363 for ; Mon, 7 Aug 2017 12:25:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3415928620 for ; Mon, 7 Aug 2017 12:25:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2915928671; Mon, 7 Aug 2017 12:25:43 +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 54DD728675 for ; Mon, 7 Aug 2017 12:25:42 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 0E68A267467; Mon, 7 Aug 2017 14:23:26 +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 E5447267283; Mon, 7 Aug 2017 14:23:20 +0200 (CEST) Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by alsa0.perex.cz (Postfix) with ESMTP id 9D46626721A for ; Mon, 7 Aug 2017 14:23:14 +0200 (CEST) Received: by mail-lf0-f67.google.com with SMTP id t128so214303lff.3 for ; Mon, 07 Aug 2017 05:23:14 -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=NckKIRBgJYBIODSm30l651AjFVE62PKum1NyUhf+RAZFu+h39siBA4JaD++m4Ws6bJ DIS2jgw/X3pmXrOb4cvfpKsf6l50M3pBhxLhn6H56TRQNbq6jBOqH6il7dR1IiSiqFDR 6ozSDyxmxPjDtcCh4v/aMuLwaQpkhMt4uSlW682xtmDyXGr2V1HECky3M8231rZ8wZCc TegIoT+UTUrHj/D2BytmG6Wb/pk9dhgSMqr5/nsmeVWrZG4GNSR9RGOfdLoLkDXckOug A7te0yV8Lug7QoyopCsr62GQ3HYxUw3IJlB2C933fITjZ4JgV+IrHZO+kmWyKaGNyY+z EPvg== 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=YI9GQ6vRhsN/LRPC0ydNaH+pSRdf1OEKSeaoZ+bhinpJpSFeOVLHFmQZJnuW1grRGW SSJ2kMIUvU8UOZaaepmQQM5rwrAE0HyTNymRejt+eAIUWFyXH2R3sne1xRTk8tqWP327 uGEzblN0FDQbu9iRPeKZ5tVMXQa9nyQaRO5nT2446mOjEiYeJXTT0Oq/S8dY+tq5YrbL 7L1wGarJiQ+DnWr+4Dtwd2m2WHD2dFug8r9UG9pLf6h84OpI52cRo2XlW7OapU3QDLdC vvfFz+onDTfBX4TQSHOKedutxzSh7QMQjlqQ7o0awd4KL4Mq7l71CDciGA+2VjwqorNc J4fQ== X-Gm-Message-State: AHYfb5iNPym6JySGY+hkCCfmSfdN04qVEBxi6IR554RrqFN8CvOFqpWi QbAfK6gJ3NUAfrX3 X-Received: by 10.46.32.207 with SMTP id g76mr103327lji.183.1502108593616; Mon, 07 Aug 2017 05:23:13 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-53.209.223.85.sovam.net.ua. [85.223.209.53]) by smtp.gmail.com with ESMTPSA id m143sm1031821lfm.77.2017.08.07.05.23.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 05:23:13 -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 15:22:54 +0300 Message-Id: <1502108577-8099-10-git-send-email-andr2000@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502108577-8099-1-git-send-email-andr2000@gmail.com> References: <1502108577-8099-1-git-send-email-andr2000@gmail.com> Cc: andr2000@gmail.com, Oleksandr Andrushchenko , tiwai@suse.com Subject: [alsa-devel] [PATCH RESEND1 09/12] 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)