From patchwork Mon Aug 7 11:50:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9885167 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 EA5DF60363 for ; Mon, 7 Aug 2017 11:53:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD3EA28514 for ; Mon, 7 Aug 2017 11:53:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1CF32861F; Mon, 7 Aug 2017 11:53:35 +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 476FC28514 for ; Mon, 7 Aug 2017 11:53:35 +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 1degYr-00040N-AP; Mon, 07 Aug 2017 11:51:05 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1degYq-0003zH-Ll for xen-devel@lists.xen.org; Mon, 07 Aug 2017 11:51:04 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id AA/82-01732-72458895; Mon, 07 Aug 2017 11:51:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPIsWRWlGSWpSXmKPExsVyMfS6i65aSEe kwcIVVhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aNJwoFx6wqpvY9Z2tgbDHuYuTkEBLoZ5R4 2qbexcjFwSLwkkXi07wORhBHQqCfVeLG2R0sIFUSAnES+250M0HYpRKzDm5mguhWlPj6bDqUv ZJJouFMOIjNJmAksfzGD7BeEYEIiWOPP7CB2MxAvTf2z2EGsYUF3CRO3X7ACmKzCKhK/Lx6iB HE5hVwlNi+5gYjxC45iZvnOoHqOTg4BZwkWpdWQKxylLi7ezb7BEaBBYwMqxg1ilOLylKLdA0 t9ZKKMtMzSnITM3N0DQ2M9XJTi4sT01NzEpOK9ZLzczcxAoOqnoGBcQfj7+N+hxglOZiURHnj V7RFCvEl5adUZiQWZ8QXleakFh9ilOHgUJLg3R/UESkkWJSanlqRlpkDDG+YtAQHj5IIbzZIm re4IDG3ODMdInWK0Z7jypV1X5g4NqxeDySnHNgOJF9N+P+NSYglLz8vVUqclzUYqE0ApC2jNA 9uKCweLzHKSgnzMjIwMAjxFKQW5WaWoMq/YhTnYFQS5pUGmcKTmVcCt/sV0FlMQGe9SWwFOas kESEl1cCovt5HJ1qRM0fQ7XWW3elTaqs7T4lk3U4s3Lxg5+l5++bdWeb/RzImgVH/Zcu5L7Z/ 1uYu1YrWr428YfvkkPjR7Xt4jpat0K96tmnah8yVQUde2gQ1unydpn7kTEWp+yfTog3rpAres t9in/7VqX9u0qFvnNMD+M1v5a/6bPrLqu3OgxOXf4ndUWIpzkg01GIuKk4EAJ2QXObCAgAA X-Env-Sender: andr2000@gmail.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1502106662!108745385!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 4346 invoked from network); 7 Aug 2017 11:51:02 -0000 Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by server-14.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Aug 2017 11:51:02 -0000 Received: by mail-lf0-f68.google.com with SMTP id x16so154516lfb.4 for ; Mon, 07 Aug 2017 04:51:02 -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=LZ0g0vaT//LxhiMluvu9ir5HUSuqdLviy7IeyHu9opk=; b=izOPcMhBNVMVgC9yfrNDmSZ0dJ7eWFCOusyaKE2yRX6xDbzc+3OUNW7ltAA+ybwwHT WPwa9wRZay9SFfCgI8BbHzwcpD1ogUsT6eyW8aW+DtLCrUWydN2lRVAadQByI3PpJnkN 7mX8gagAh2tfLnrK4MD3fagjCwpXzVb33lp6A94kse1SQIuGwHna4FC+IpjewaUHKnnR NbLuafeaFGd08vi2hoA3d0B7yu0+9VHPn7RuaumgwUPZOcgzqZ4AkvWLOXMhK9caIYhu TCxvlmqWEnchPfF76NGdbtJ59AUR6D4IBJgKOMUr450hnpaK8+cjw4bYHvA/QRtBtPV3 XNJw== 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=LZ0g0vaT//LxhiMluvu9ir5HUSuqdLviy7IeyHu9opk=; b=TCalIohbcjY3pEXenKVQqCKU3OKeOenHrZGCILY9T3Ax1Qouct6LmSTj6agtcAc940 4SimeO8PuodXgqSR9y0sx7gcDwstpZYUacdH4hcX/WLWzBfVxEu83gvl33FDNfrLqaXO QZcj4ksAofQxL3o+vx+cpzw6jVQPf4WWJf5ojHjAmaOQbVC/WoUJx90qh8hcPznXg8Rc bc+K+i3hen/i1aFCUtDMOHZGsKB1DMnKrnHn/nM9xTTeP7xwtm7sXs8SLj5NAG32hWUI 4b0m3N5yOxirNvsnUV0X3+0Mfkw6pyNnnWnLJuiII+8JnJ5oOuClOSjgXclsPorlJnf0 Ur5g== X-Gm-Message-State: AHYfb5jBtaF4fYylzsqWDPzAlO6kIX7ITlsPyCwgCuVFTlaxAgKDWpv6 fhZs4M7Xj4qw+g== X-Received: by 10.46.20.22 with SMTP id u22mr91405ljd.58.1502106662293; Mon, 07 Aug 2017 04:51:02 -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.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 04:51:01 -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:41 +0300 Message-Id: <1502106645-6731-8-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 07/11] ALSA: vsnd: Initialize virtul sound card 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 Initialize virtual sound card with streams according to the Xen store configuration. Add stubs for stream PCM operations. Signed-off-by: Oleksandr Andrushchenko --- sound/drivers/xen-front.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) diff --git a/sound/drivers/xen-front.c b/sound/drivers/xen-front.c index f3e3f64f0aa6..9f31e6832086 100644 --- a/sound/drivers/xen-front.c +++ b/sound/drivers/xen-front.c @@ -134,6 +134,129 @@ struct xdrv_info { struct sdev_card_plat_data cfg_plat_data; }; +static struct sdev_pcm_stream_info *sdrv_stream_get( + struct snd_pcm_substream *substream) +{ + struct sdev_pcm_instance_info *pcm_instance = + snd_pcm_substream_chip(substream); + struct sdev_pcm_stream_info *stream; + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + stream = &pcm_instance->streams_pb[substream->number]; + else + stream = &pcm_instance->streams_cap[substream->number]; + return stream; +} + +static void sdrv_copy_pcm_hw(struct snd_pcm_hardware *dst, + struct snd_pcm_hardware *src, + struct snd_pcm_hardware *ref_pcm_hw) +{ + *dst = *ref_pcm_hw; + + if (src->formats) + dst->formats = src->formats; + if (src->buffer_bytes_max) + dst->buffer_bytes_max = + src->buffer_bytes_max; + if (src->period_bytes_min) + dst->period_bytes_min = + src->period_bytes_min; + if (src->period_bytes_max) + dst->period_bytes_max = + src->period_bytes_max; + if (src->periods_min) + dst->periods_min = src->periods_min; + if (src->periods_max) + dst->periods_max = src->periods_max; + if (src->rates) + dst->rates = src->rates; + if (src->rate_min) + dst->rate_min = src->rate_min; + if (src->rate_max) + dst->rate_max = src->rate_max; + if (src->channels_min) + dst->channels_min = src->channels_min; + if (src->channels_max) + dst->channels_max = src->channels_max; + if (src->buffer_bytes_max) { + dst->buffer_bytes_max = src->buffer_bytes_max; + dst->period_bytes_max = src->buffer_bytes_max / + src->periods_max; + dst->periods_max = dst->buffer_bytes_max / + dst->period_bytes_max; + } +} + +static int sdrv_alsa_open(struct snd_pcm_substream *substream) +{ + return 0; +} + +static int sdrv_alsa_close(struct snd_pcm_substream *substream) +{ + return 0; +} + +static int sdrv_alsa_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + return 0; +} + +static int sdrv_alsa_hw_free(struct snd_pcm_substream *substream) +{ + return 0; +} + +static int sdrv_alsa_prepare(struct snd_pcm_substream *substream) +{ + return 0; +} + +static int sdrv_alsa_trigger(struct snd_pcm_substream *substream, int cmd) +{ + return 0; +} + +static inline snd_pcm_uframes_t sdrv_alsa_pointer( + struct snd_pcm_substream *substream) +{ + 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) +{ + return 0; +} + +static int sdrv_alsa_playback_copy_kernel(struct snd_pcm_substream *substream, + int channel, unsigned long pos, void *buf, unsigned long bytes) +{ + 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) +{ + return 0; +} + +static int sdrv_alsa_capture_copy_kernel(struct snd_pcm_substream *substream, + int channel, unsigned long pos, void *buf, unsigned long bytes) +{ + return 0; +} + +static int sdrv_alsa_playback_fill_silence(struct snd_pcm_substream *substream, + int channel, unsigned long pos, unsigned long bytes) +{ + return 0; +} + #define MAX_XEN_BUFFER_SIZE (64 * 1024) #define MAX_BUFFER_SIZE MAX_XEN_BUFFER_SIZE #define MIN_PERIOD_SIZE 64 @@ -168,10 +291,119 @@ static struct snd_pcm_hardware sdrv_pcm_hw_default = { .fifo_size = 0, }; +/* + * FIXME: The mmaped data transfer is asynchronous and there is no + * ack signal from user-space when it is done. This is the + * reason it is not implemented in the PV driver as we do need + * to know when the buffer can be transferred to the backend. + */ + +static struct snd_pcm_ops sdrv_alsa_playback_ops = { + .open = sdrv_alsa_open, + .close = sdrv_alsa_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = sdrv_alsa_hw_params, + .hw_free = sdrv_alsa_hw_free, + .prepare = sdrv_alsa_prepare, + .trigger = sdrv_alsa_trigger, + .pointer = sdrv_alsa_pointer, + .copy_user = sdrv_alsa_playback_copy_user, + .copy_kernel = sdrv_alsa_playback_copy_kernel, + .fill_silence = sdrv_alsa_playback_fill_silence, +}; + +static struct snd_pcm_ops sdrv_alsa_capture_ops = { + .open = sdrv_alsa_open, + .close = sdrv_alsa_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = sdrv_alsa_hw_params, + .hw_free = sdrv_alsa_hw_free, + .prepare = sdrv_alsa_prepare, + .trigger = sdrv_alsa_trigger, + .pointer = sdrv_alsa_pointer, + .copy_user = sdrv_alsa_capture_copy_user, + .copy_kernel = sdrv_alsa_capture_copy_kernel, +}; + static int sdrv_new_pcm(struct sdev_card_info *card_info, struct cfg_pcm_instance *instance_config, struct sdev_pcm_instance_info *pcm_instance_info) { + struct snd_pcm *pcm; + int ret, i; + + dev_dbg(&card_info->xdrv_info->xb_dev->dev, + "New PCM device \"%s\" with id %d playback %d capture %d", + instance_config->name, + instance_config->device_id, + instance_config->num_streams_pb, + instance_config->num_streams_cap); + + pcm_instance_info->card_info = card_info; + + sdrv_copy_pcm_hw(&pcm_instance_info->pcm_hw, + &instance_config->pcm_hw, &card_info->pcm_hw); + + if (instance_config->num_streams_pb) { + pcm_instance_info->streams_pb = devm_kcalloc( + &card_info->card->card_dev, + instance_config->num_streams_pb, + sizeof(struct sdev_pcm_stream_info), + GFP_KERNEL); + if (!pcm_instance_info->streams_pb) + return -ENOMEM; + } + + if (instance_config->num_streams_cap) { + pcm_instance_info->streams_cap = devm_kcalloc( + &card_info->card->card_dev, + instance_config->num_streams_cap, + sizeof(struct sdev_pcm_stream_info), + GFP_KERNEL); + if (!pcm_instance_info->streams_cap) + return -ENOMEM; + } + + pcm_instance_info->num_pcm_streams_pb = + instance_config->num_streams_pb; + pcm_instance_info->num_pcm_streams_cap = + instance_config->num_streams_cap; + + for (i = 0; i < pcm_instance_info->num_pcm_streams_pb; i++) { + pcm_instance_info->streams_pb[i].pcm_hw = + instance_config->streams_pb[i].pcm_hw; + pcm_instance_info->streams_pb[i].unique_id = + instance_config->streams_pb[i].unique_id; + } + + for (i = 0; i < pcm_instance_info->num_pcm_streams_cap; i++) { + pcm_instance_info->streams_cap[i].pcm_hw = + instance_config->streams_cap[i].pcm_hw; + pcm_instance_info->streams_cap[i].unique_id = + instance_config->streams_cap[i].unique_id; + } + + ret = snd_pcm_new(card_info->card, instance_config->name, + instance_config->device_id, + instance_config->num_streams_pb, + instance_config->num_streams_cap, + &pcm); + if (ret < 0) + return ret; + + pcm->private_data = pcm_instance_info; + pcm->info_flags = 0; + strncpy(pcm->name, "Virtual card PCM", sizeof(pcm->name)); + + if (instance_config->num_streams_pb) + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, + &sdrv_alsa_playback_ops); + + if (instance_config->num_streams_cap) + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, + &sdrv_alsa_capture_ops); + + pcm_instance_info->pcm = pcm; return 0; }