From patchwork Mon Aug 7 12:22:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9885251 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 7B07F60363 for ; Mon, 7 Aug 2017 12:25:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C44E28670 for ; Mon, 7 Aug 2017 12:25:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 611BB28676; Mon, 7 Aug 2017 12:25:34 +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 DD27528670 for ; Mon, 7 Aug 2017 12:25:33 +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 1deh3y-0007sI-E3; Mon, 07 Aug 2017 12:23:14 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1deh3x-0007qO-E5 for xen-devel@lists.xen.org; Mon, 07 Aug 2017 12:23:13 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id BC/98-02175-0BB58895; Mon, 07 Aug 2017 12:23:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRWlGSWpSXmKPExsVyMfS6k+6G6I5 Ig50mFks+LmZxYPQ4uvs3UwBjFGtmXlJ+RQJrxp3OlawF73Qr/k05wN7A+Fy9i5GTQ0igj1Fi 5r2SLkYuDhaBlywSXVfmsYIkJAT6WSWWtplA2HESG05dY4KwyySW7JjEBtGsKPH12XQmkGYhg VVMEt0XXjGDJNgEjCSW3/jBAmKLCERIHHv8AayBWaBU4sb+OWA1wgJ+Eq1dN8HiLAKqEh+/r2 cHsXkFHCUuHZzMDrFMTuLmuU6wek4BJ4nnvY+hFjtKfD4zg3UCo8ACRoZVjBrFqUVlqUW6RhZ 6SUWZ6RkluYmZObqGBqZ6uanFxYnpqTmJScV6yfm5mxiBYVXPwMC4g7Fvld8hRkkOJiVR3vgV bZFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHgLozoihQSLUtNTK9Iyc4ABDpOW4OBREuFVAUnzF hck5hZnpkOkTjG6cly5su4LE8eG1euB5JQD24Hkire7gOSrCf+/MQmx5OXnpUqJ84aBNAuANG eU5sGNhkXnJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvPNBpvBk5pXAXfAK6DgmoOPeJLa CHFeSiJCSamCcpO7iuIvx5GNriTP27MdPZ6Uuj1MTatM5oigikxh9e0faUlv7VQsbmX0ubJN8 4xfncvPnbzOup3/sFiz/dsdEZ8KVEyviWk/Mqq3cHWGmWnU2a/3BF10fLS1Zbvl8bP7Qtbvu2 dVOsfeypqVaXSLvKk6tDn1jaGExqX3nP+9FVhob5z80jt+qxFKckWioxVxUnAgAonBSNckCAA A= X-Env-Sender: andr2000@gmail.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1502108591!90291641!1 X-Originating-IP: [209.85.215.66] 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 43777 invoked from network); 7 Aug 2017 12:23:11 -0000 Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by server-16.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Aug 2017 12:23:11 -0000 Received: by mail-lf0-f66.google.com with SMTP id 65so225333lfa.0 for ; Mon, 07 Aug 2017 05:23:11 -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=QWCk48QTFd8dRXRYWoHHo9AICyn/sa2qSIqYMNHKeCk=; b=aMjHwLmI+C/9vMqlUiz7ZQxGV9xWBYupyTs60SMnODgbcnELD7MFkzZwkSrFu+Ictq GS3y5b2vwqHqL+jfHHNt0nX3bwq4B0H1r9fKcrnD3tf5uK4pY0cKQphdH3f7O1L37Qv9 UUY3QtwCraYULh/M3/oxONHEVRbGw5k/vDQfaCSkx7QAezlenVhso2Ou/d8fAUCBpKq8 twYBw56grRARHuDu/dwWmIko5TFaHwHGyPTBzPdTVx/jlXIG5mRY7ytfu68LrflGQZBD CyO8Lz7UcxCi3gUD7BIQ/zU9hmtGno68L/v9nlGs0o0+FOLkHWXNepktXqQY+r67TIhm e8dg== 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=QWCk48QTFd8dRXRYWoHHo9AICyn/sa2qSIqYMNHKeCk=; b=ZvaOSsEjODZm2CE4mCGTCocuHOPLPBeK5hLqWK83XJ6Nv6wnIb/BGwif4XkgM4WMHb AV10G32uZm2PbfA45/59mBvgSXM7RAEk2pB1j2S03pMsj232AB2KvcGJlzA4WmFRYzps fUB4dpxQCYV4v/YEEuXM66vgpzQHTUHBsvr3VJB7i5rhKiaMmUHsPtGjkiSDbJjWI6LN KsCV86ibh2GPzEpmw3aKpEwJ0RJZszwoh2Yd2edPES9A3ddNVh5aidE3gjRWMwHvC0qg LK4+2EhlvXPy0jxdpAAQJ9wHyeA6XBmwRSd9BWy4IkW1q+Xls77OtLHc9unzBSPGAMj7 Y40g== X-Gm-Message-State: AHYfb5gO4r0IfFm9mKzLbWV/I6IA0Y/wEJpneByODkRuufvkSP6Dh4/D PKxkLwcd1g53yg== X-Received: by 10.46.88.21 with SMTP id m21mr136397ljb.38.1502108591283; Mon, 07 Aug 2017 05:23:11 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 05:23:10 -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:52 +0300 Message-Id: <1502108577-8099-8-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 07/12] ALSA: vsnd: Introduce ALSA virtual sound driver 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 Implement essential initialization of the sound driver: - introduce required data structures - handle driver registration - handle sound card registration - register sound driver on backend connection - remove sound driver on backend disconnect Signed-off-by: Oleksandr Andrushchenko --- sound/drivers/xen-front.c | 161 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 2 deletions(-) diff --git a/sound/drivers/xen-front.c b/sound/drivers/xen-front.c index 04ebc15757f4..f3e3f64f0aa6 100644 --- a/sound/drivers/xen-front.c +++ b/sound/drivers/xen-front.c @@ -19,13 +19,14 @@ */ #include +#include #include #include -#include #include #include +#include #include #include @@ -66,6 +67,33 @@ struct sh_buf_info { size_t vbuffer_sz; }; +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 sh_buf_info sh_buf; +}; + +struct sdev_pcm_instance_info { + struct sdev_card_info *card_info; + struct snd_pcm *pcm; + struct snd_pcm_hardware pcm_hw; + int num_pcm_streams_pb; + struct sdev_pcm_stream_info *streams_pb; + int num_pcm_streams_cap; + struct sdev_pcm_stream_info *streams_cap; +}; + +struct sdev_card_info { + struct xdrv_info *xdrv_info; + struct snd_card *card; + struct snd_pcm_hardware pcm_hw; + int num_pcm_instances; + struct sdev_pcm_instance_info *pcm_instances; +}; + struct cfg_stream { int unique_id; char *xenstore_path; @@ -99,6 +127,8 @@ struct xdrv_info { struct xenbus_device *xb_dev; spinlock_t io_lock; struct mutex mutex; + bool sdrv_registered; + struct platform_device *sdrv_pdev; int num_evt_channels; struct xdrv_evtchnl_info *evt_chnls; struct sdev_card_plat_data cfg_plat_data; @@ -138,6 +168,132 @@ static struct snd_pcm_hardware sdrv_pcm_hw_default = { .fifo_size = 0, }; +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) +{ + return 0; +} + +static int sdrv_probe(struct platform_device *pdev) +{ + struct sdev_card_info *card_info; + struct sdev_card_plat_data *platdata; + struct snd_card *card; + int ret, i; + + platdata = dev_get_platdata(&pdev->dev); + + dev_dbg(&pdev->dev, "Creating virtual sound card\n"); + + ret = snd_card_new(&pdev->dev, 0, XENSND_DRIVER_NAME, THIS_MODULE, + sizeof(struct sdev_card_info), &card); + if (ret < 0) + return ret; + + card_info = card->private_data; + card_info->xdrv_info = platdata->xdrv_info; + card_info->card = card; + card_info->pcm_instances = devm_kcalloc(&pdev->dev, + platdata->cfg_card.num_pcm_instances, + sizeof(struct sdev_pcm_instance_info), GFP_KERNEL); + if (!card_info->pcm_instances) { + ret = -ENOMEM; + goto fail; + } + + card_info->num_pcm_instances = platdata->cfg_card.num_pcm_instances; + card_info->pcm_hw = platdata->cfg_card.pcm_hw; + + for (i = 0; i < platdata->cfg_card.num_pcm_instances; i++) { + ret = sdrv_new_pcm(card_info, + &platdata->cfg_card.pcm_instances[i], + &card_info->pcm_instances[i]); + if (ret < 0) + goto fail; + } + + strncpy(card->driver, XENSND_DRIVER_NAME, sizeof(card->driver)); + strncpy(card->shortname, platdata->cfg_card.name_short, + sizeof(card->shortname)); + strncpy(card->longname, platdata->cfg_card.name_long, + sizeof(card->longname)); + + ret = snd_card_register(card); + if (ret < 0) + goto fail; + + platform_set_drvdata(pdev, card); + return 0; + +fail: + snd_card_free(card); + return ret; +} + +static int sdrv_remove(struct platform_device *pdev) +{ + struct sdev_card_info *info; + struct snd_card *card = platform_get_drvdata(pdev); + + info = card->private_data; + dev_dbg(&pdev->dev, "Removing virtual sound card %d\n", + info->card->number); + snd_card_free(card); + return 0; +} + +static struct platform_driver sdrv_info = { + .probe = sdrv_probe, + .remove = sdrv_remove, + .driver = { + .name = XENSND_DRIVER_NAME, + }, +}; + +static void sdrv_cleanup(struct xdrv_info *drv_info) +{ + if (!drv_info->sdrv_registered) + return; + + if (drv_info->sdrv_pdev) { + struct platform_device *sdrv_pdev; + + sdrv_pdev = drv_info->sdrv_pdev; + if (sdrv_pdev) + platform_device_unregister(sdrv_pdev); + } + platform_driver_unregister(&sdrv_info); + drv_info->sdrv_registered = false; +} + +static int sdrv_init(struct xdrv_info *drv_info) +{ + struct platform_device *sdrv_pdev; + int ret; + + ret = platform_driver_register(&sdrv_info); + if (ret < 0) + return ret; + + drv_info->sdrv_registered = true; + /* pass card configuration via platform data */ + sdrv_pdev = platform_device_register_data(NULL, + XENSND_DRIVER_NAME, 0, &drv_info->cfg_plat_data, + sizeof(drv_info->cfg_plat_data)); + if (IS_ERR(sdrv_pdev)) + goto fail; + + drv_info->sdrv_pdev = sdrv_pdev; + return 0; + +fail: + dev_err(&drv_info->xb_dev->dev, + "failed to register virtual sound driver\n"); + sdrv_cleanup(drv_info); + return -ENODEV; +} + static irqreturn_t xdrv_evtchnl_interrupt(int irq, void *dev_id) { struct xdrv_evtchnl_info *channel = dev_id; @@ -830,6 +986,7 @@ static int cfg_card(struct xdrv_info *drv_info, static void xdrv_remove_internal(struct xdrv_info *drv_info) { + sdrv_cleanup(drv_info); xdrv_evtchnl_free_all(drv_info); } @@ -1018,7 +1175,7 @@ static int xdrv_be_on_initwait(struct xdrv_info *drv_info) static inline int xdrv_be_on_connected(struct xdrv_info *drv_info) { - return 0; + return sdrv_init(drv_info); } static inline void xdrv_be_on_disconnected(struct xdrv_info *drv_info)