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: 9885247 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 7645860363 for ; Mon, 7 Aug 2017 12:25:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67DE828670 for ; Mon, 7 Aug 2017 12:25:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CC3828676; Mon, 7 Aug 2017 12:25:32 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, 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 EEF5628670 for ; Mon, 7 Aug 2017 12:25:31 +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 1deh41-0007vn-0u; Mon, 07 Aug 2017 12:23:17 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1deh3z-0007tF-Iy for xen-devel@lists.xen.org; Mon, 07 Aug 2017 12:23:15 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id D7/C3-09901-2BB58895; Mon, 07 Aug 2017 12:23:14 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrMIsWRWlGSWpSXmKPExsVyMfS6i+6m6I5 Ig+lPJC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyeni62gqnKFd++tbA3MH6Q62Lk4hAS6GeU mHlkHhOIwyLwkkXi973ZYI6EQD+rxMGuRyxdjJxATpzEzv19UHaFxMPmXYwgtpCAosTXZ9OZI EatYpLoutfNCpJgEzCSWH7jB1iDiECExLHHH9hAbGaBUokb++cwg9jCAsES+491gw1iEVCV2P v1AzuIzSvgJHF40xpWiGVyEjfPdYLVcwLFn/c+ZoNY7Cjx+cwM1gmMAgsYGVYxahSnFpWlFuk aG+klFWWmZ5TkJmbm6BoamOnlphYXJ6an5iQmFesl5+duYgQGFwMQ7GA8vS7wEKMkB5OSKG/8 irZIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8hVEdkUKCRanpqRVpmTnAMIdJS3DwKInwqoCke YsLEnOLM9MhUqcY7TmuXFn3hYljw+r1QHLKge1A8tWE/9+YhFjy8vNSpcR5w0DaBEDaMkrz4I bC4vISo6yUMC8j0JlCPAWpRbmZJajyrxjFORiVhHmTQKbwZOaVwO1+BXQWE9BZbxJbQc4qSUR ISTUwzi2PqqieLZx+5q04x/Nbu+2O3twbzsV04OWhPWv+Bh44EM77iyv2QYCFLyPrcsepN76t mTCh3PaNgVqYdrYWD8tO43MPbjS6bTc6vsLFrvDdHOk594TX/GcxD58QcXke10e2g78n72G62 dy4ukot6cPEeWesZqis/v6Qx+A89zuRyY8sLi65c1CJpTgj0VCLuag4EQAxkjxfxgIAAA== X-Env-Sender: andr2000@gmail.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1502108593!78862707!1 X-Originating-IP: [209.85.215.68] 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 49203 invoked from network); 7 Aug 2017 12:23:14 -0000 Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by server-11.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Aug 2017 12:23:14 -0000 Received: by mail-lf0-f68.google.com with SMTP id x16so211598lfb.4 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=EOfXwUB9gbmqOCWjSl5MAd0bYSAXqBr35dYRcfuTUkBDMy7/A7Fb1A0L6KXXoY6qOK fOASGfkfGV9yuGes9SdoxBOKnB3pvc/M5TFMObTwFw4r5iREdv72cJBDbrCvbkQglZ0o bRVoQnmepu6+5eRrqvfQioWtO1/G4+F3sVDlq98WpUDcxO7a4jonXHXGOlASPDBXkDkS 1NFShPiKOjhyPjTX9kG9aJ+SJIp8yhB+X03nEuT7c1OnZ0KXS6nJsNczPhanvkKiwsdW kge976bVrgEOOe5N/yGuIcJMzEbTxMwmv9Fbq5IHgIKMI8Y12hfJTG/LZDjTjddTzA9v 5DNA== X-Gm-Message-State: AHYfb5jkn+EAYRhPM9RsTzz+xP3tCmgvrre3JACGwYEGrzSFJqmu0iQ7 8njbBnfk9zk3VQ== 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, perex@perex.cz Subject: [Xen-devel] [PATCH RESEND1 09/12] ALSA: vsnd: Add timer for period interrupt emulation 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 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)