From patchwork Fri Mar 29 00:04:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah X-Patchwork-Id: 10876141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A84214DE for ; Fri, 29 Mar 2019 00:06:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E0F729038 for ; Fri, 29 Mar 2019 00:06:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EA7629049; Fri, 29 Mar 2019 00:06:05 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5C88B29038 for ; Fri, 29 Mar 2019 00:06:04 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 39142847; Fri, 29 Mar 2019 01:05:12 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 39142847 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1553817962; bh=kfzh5MYNg+YfW4DYTk9Itd/YBM3QHLS8LKGnbaynBAE=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=Y7WLW4SzJSlLo9UJ4ZpGg+LiT9xKii/GRF9sc1BegLg63ZiUopiJPV850UjsxlkVd FR5CdHm+47fG/BBdkKPQIgu6cN0oZVQj1MsmdlTEcVjmOhJD7VMUTRIH5VIZLn81hO Tfi0FJ6sLkmijPyeaxE1POE1+DRenPlqNqJ0zTtM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 51604F80769; Fri, 29 Mar 2019 01:05:11 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 54E55F896FF; Fri, 29 Mar 2019 01:05:09 +0100 (CET) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 5D069F80769 for ; Fri, 29 Mar 2019 01:05:05 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5D069F80769 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="NpStrgvr" Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BC71C2184C; Fri, 29 Mar 2019 00:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553817904; bh=SK20SRRqtaeWBcdShQMS9osKunRw0emHfDo3BzZhzCg=; h=From:To:Cc:Subject:Date:From; b=NpStrgvrIT6G/oS3QoEyxMM7Rwb4xMlHyVuy4CULcrz3aZ8YCaAcwkNFSO8zQwU5U AeAJzqp+LvJXPn2bc7wPlcZJrM2YFpeS7R8Mcb9r3nnNBGQIt9BGk3MagqS4MeqDw1 slzxjGavZeQc0P9PrkRukkshFkHYOR8M+74dcqY4= From: Shuah Khan To: mchehab@kernel.org, perex@perex.cz, tiwai@suse.com, hverkuil@xs4all.nl Date: Thu, 28 Mar 2019 18:04:55 -0600 Message-Id: X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Shuah Khan , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [alsa-devel] [PATCH v13 0/6] Media Device Allocator API X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP Media Device Allocator API to allows multiple drivers share a media device. This API solves a very common use-case for media devices where one physical device (an USB stick) provides both audio and video. When such media device exposes a standard USB Audio class, a proprietary Video class, two or more independent drivers will share a single physical USB bridge. In such cases, it is necessary to coordinate access to the shared resource. Using this API, drivers can allocate a media device with the shared struct device as the key. Once the media device is allocated by a driver, other drivers can get a reference to it. The media device is released when all the references are released. The primary focus for testing The patch series is making sure media device is released when both drivers release the media device with a series of unbind/binds on both drivers. - both au0828 and snd-usb-aduio as built-in - both au0828 and snd-usb-aduio as modules - au0828 as module and snd-usb-aduio as built-in - au0828 as built-in and snd-usb-aduio as module Test results can be found at: https://docs.google.com/document/d/1RMF8Rwj7xHJEoOx6_K2f-REgZJ63BMeAVEf-CV-0HsM/edit?usp=sharing Changes since v12: - Patch 1: Fixed prototype warns from media_dev_allocator.c. Removed dependency on find_module() by adding struct module to input args. Still need module name to pass into media_device API. - Patch 2 & 4: Update media dev allocator api calls to pass in struct module pointer. - No changes to Patches 3 & 5. - Added patch 6 with a test. It can go in separately. Changes since v11: - Patch 1: Add CONFIG_MODULES dependency in media_dev_allocator files. to fix compile errors when CONFIG_MODULES is disabled. - Patch 2, 3: No changes. - Patch 4: Fix sparse error reported by Dan Carpenter. - Patch 5: Fix warns found by Hans Verkuil. - v11 was tested on 5.0-rc7 and addresses comments on v10 series from Hans Verkuil. Fixed problems found in resource sharing logic in au0828 adding a patch 5 to this series. The test plan used for testing resource sharing could serve as a regression test plan and the test results can be found at: - v10 was tested on 5.0-rc3 and addresses comments on v9 series from Hans Verkuil. Changes since v10: - Patch 1: Fixed SPDX tag and removed redundant IS_ENABLED(CONFIG_USB) around media_device_usb_allocate() - Sakari Ailus's review comment. - Patch 2 and 3: No changes - Patch 4: Fixed SPDX tag - Sakari Ailus's review comment. - Carried Reviewed-by tag from Takashi Iwai for the sound from v9. - Patch 5: This is a new patch added to fix resource sharing inconsistencies and problem found during testing using Han's tests. Changes since v9: - Patch 1: Fix mutex assert warning from find_module() calls. This code was written before the change to find_module() that requires callers to hold module_mutex. I missed this during my testing on 4.20-rc6. Hans Verkuil reported the problem. - Patch 4: sound/usb: Initializes all the entities it can before registering the device based on comments from Hans Verkuil - Carried Reviewed-by tag from Takashi Iwai for the sound from v9. - No changes to Patches 2 and 3. References: https://lkml.org/lkml/2018/11/2/169 https://www.mail-archive.com/linux-media@vger.kernel.org/msg105854.html Shuah Khan (6): media: Media Device Allocator API media: change au0828 to use Media Device Allocator API media: media.h: Enable ALSA MEDIA_INTF_T* interface types sound/usb: Use Media Controller API to share media resources au0828: fix enable and disable source audio and video inconsistencies selftests: media_dev_allocator api test Documentation/media/kapi/mc-core.rst | 41 +++ drivers/media/Makefile | 6 + drivers/media/media-dev-allocator.c | 133 +++++++ drivers/media/usb/au0828/Kconfig | 2 + drivers/media/usb/au0828/au0828-core.c | 195 ++++++++--- drivers/media/usb/au0828/au0828.h | 6 +- include/media/media-dev-allocator.h | 63 ++++ include/uapi/linux/media.h | 25 +- sound/usb/Kconfig | 4 + sound/usb/Makefile | 2 + sound/usb/card.c | 14 + sound/usb/card.h | 3 + sound/usb/media.c | 327 ++++++++++++++++++ sound/usb/media.h | 74 ++++ sound/usb/mixer.h | 3 + sound/usb/pcm.c | 29 +- sound/usb/quirks-table.h | 1 + sound/usb/stream.c | 2 + sound/usb/usbaudio.h | 6 + .../media_tests/media_dev_allocator.sh | 81 +++++ 20 files changed, 956 insertions(+), 61 deletions(-) create mode 100644 drivers/media/media-dev-allocator.c create mode 100644 include/media/media-dev-allocator.h create mode 100644 sound/usb/media.c create mode 100644 sound/usb/media.h create mode 100755 tools/testing/selftests/media_tests/media_dev_allocator.sh