From patchwork Mon Aug 7 07:43:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9884639 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 9BF92602CC for ; Mon, 7 Aug 2017 07:46:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EF47285B7 for ; Mon, 7 Aug 2017 07:46:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83AB0285C4; Mon, 7 Aug 2017 07:46:55 +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 29567285E1 for ; Mon, 7 Aug 2017 07:46:50 +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 1dechX-0005TO-9T; Mon, 07 Aug 2017 07:43:47 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dechV-0005R9-Iq for xen-devel@lists.xen.org; Mon, 07 Aug 2017 07:43:45 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id 30/A6-01732-03A18895; Mon, 07 Aug 2017 07:43:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHIsWRWlGSWpSXmKPExsVyMfS6i66BVEe kwabvbBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa0ZPTxdbwVTlim/fWtgbGD/IdTFycQgJ9DNK nDv9lgXEYRF4ySLRdWI1I4gjIdDPKvH2cRdbFyMnkBMncfvEM6YuRg4gu1Si8TY3SFhIQFHi6 7PpTBD2SiaJE0ciQGw2ASOJ5Td+sIDYIgIREscefwAbwwzUemP/HGYQW1jAW6Lx8wk2kJEsAq oSXx9lgoR5BZwkVh/oZofYKidx81wnWDmngLPE+fNrWEHKhYBqTrxKncAosICRYRWjenFqUVl qka6FXlJRZnpGSW5iZo6uoYGxXm5qcXFiempOYlKxXnJ+7iZGYEgxAMEOxgvtzocYJTmYlER5 41e0RQrxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4L0n0REpJFiUmp5akZaZAwxumLQEB4+SCO9qk DRvcUFibnFmOkTqFKM9x5Ur674wcWxYvR5ITjmwHUi+mvD/G5MQS15+XqqUOK+2JFCbAEhbRm ke3FBYNF5ilJUS5mUEOlOIpyC1KDezBFX+FaM4B6OSMO9TkOU8mXklcLtfAZ3FBHTWm8RWkLN KEhFSUg2MnuyuImJGwY+cNtjtYnTWmzNvnxfT7qQ5/qVPUt7Jdd2yfviS5zb7dXWV5y5NjfVF zrpbuY4ouOrv1OgpEFE479XRsHhRia3WRL6UqqLAmqCrM7IsM35lpYQ4Gsw5yX42d1akfVcD3 /rnZe5CDCb6YRbiMx7NTJP5t+bnEmOemgyzbVrR25VYijMSDbWYi4oTAfiHChzBAgAA X-Env-Sender: andr2000@gmail.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1502091823!92053803!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.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 56570 invoked from network); 7 Aug 2017 07:43:44 -0000 Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by server-12.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Aug 2017 07:43:44 -0000 Received: by mail-lf0-f68.google.com with SMTP id 65so4871942lfa.0 for ; Mon, 07 Aug 2017 00:43:44 -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=u6C0u9wH+C2ISkN5V3jzlcso9yf0jt2g1T/zs3z2hoPSsx9n9ak12X/WUuNpGwJJIk NSxfssp1UtQYiHMbHcbxN9/A7S5n7Ol5wfrnLeX8AQ7T567oSZOaFoQ4625j9/hrK86k wQnoYYWSpjdy2xJ8uHQgGYbzQsB6mFVmdwX/4Csjf0rp9rVb7RMkDD2xx+9MEkQZqYWr 50g2LLCB4LQjBURkLsoigc7pbarR9t98QLamE67Z55rHfOPruh90w3L1ja63WR7JnMyU U7ynsY2mWTVz3iQwM7gfwxNzPCn6MNP6ylvBcyclviOenSNoNBilcCARj+wqvUICcy2B uKOw== 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=WhuogfPf8ZvfVmiJ3cZNPdgiEp3KVmECW/jnX4Q1KYcVv73oShcA4CKfaiMsOD4Vap 3ypAxj3XzrCyJQ7H1jXxLN7T2wqdX1kqkB1UZU5dAqZrbEewSDO6F4uolmF6Snrg6XXK ojSb5ycV5+JmT5D2pGVk2foxkegAdQEZiLPy2xybeKI5OquMBGPZ2ZLU6EdeAgDh+JAK ckxpxNT//Li7DsC+C6RTY0j8Er0Zf3VWbY1jAJeDgo5wV0O5Se3xQJzSgXQxvhRYBjii AlwAO7Nbcq13NEvwqHQKOcdwcbXTlJdVSYWCYx9EO2Bbc5VCQ/NUWstnaWpYPQVE9mjL R0OA== X-Gm-Message-State: AHYfb5gdqyPW55ieF6omtRFv8y9Fds+Sjt3t5r1uH4YL33t/O4lCQkcx 6tJcrdn6pHsxrg== X-Received: by 10.46.7.79 with SMTP id i15mr345669ljd.86.1502091823414; Mon, 07 Aug 2017 00:43:43 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-52.209.223.85.sovam.net.ua. [85.223.209.52]) by smtp.gmail.com with ESMTPSA id f136sm399062lff.34.2017.08.07.00.43.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 00:43:42 -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 10:43:13 +0300 Message-Id: <1502091796-14413-9-git-send-email-andr2000@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502091796-14413-1-git-send-email-andr2000@gmail.com> References: <1502091796-14413-1-git-send-email-andr2000@gmail.com> Cc: andr2000@gmail.com, Oleksandr Andrushchenko , tiwai@suse.com, perex@perex.cz Subject: [Xen-devel] [PATCH 08/11] 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)