From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDF44C282DE for ; Fri, 24 May 2019 03:31:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A3C412184B for ; Fri, 24 May 2019 03:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558668669; bh=h341EBXdLK6cOhUdc2aJHH3YPAWToqT/9Mx16lDync0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zpHjzDT1NUP7t/DqvLyP6WQFa6n1Lu/rb6CMd1cji5EJwYLVAyLsuu+l+8D8JDXhG WNSFK9TTXSfb1TexgJSfn456E2EhwloQ5NlINgH5B3HhmJ/mY9FtMqeHvRjGUvQhnT /1OsGO662In2Qj82s4Tr9K9w0ORZhAFHstiefsDk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388860AbfEXDbJ (ORCPT ); Thu, 23 May 2019 23:31:09 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:38644 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388803AbfEXDbG (ORCPT ); Thu, 23 May 2019 23:31:06 -0400 Received: by mail-it1-f196.google.com with SMTP id i63so11730497ita.3 for ; Thu, 23 May 2019 20:31:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mv9CMN0i6nNcIH3+gboQPHuQ3PFIry51DtN3+zdUF0M=; b=IxNxaYrz95tN91XjVNI3UZ+WlfGO3SRzMiNHHQNCCLJouwGqKBfnwmZbq6bRWDhQrG aUOM8bJ4BAs6XD6I8cStJ6rWQQ+syKvXrRPJeXM6MmzODaNCzxsNOQaFm6HNC8HCwaqn xvXZ/p4QpAcYet2UxsjZ461n6UGmxiei8k9NM= 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:mime-version:content-transfer-encoding; bh=Mv9CMN0i6nNcIH3+gboQPHuQ3PFIry51DtN3+zdUF0M=; b=LkpDIBaW3DdE1eQAb1LwASaAHira9nvLgTLByH6uVwgaOJe4AOhrM6/0oiUn6lmQ8m wROh0fpHEuXDxOW5Q3SwAvtw4x+dYTERVBZYHWRnmGmQ3lUk+cQsqXSiFlMHjcc9kgJp OP0ANIZlfwVNI5NgriMCxHxwANhVUnLbJNisRSQdvJWe2TiBJ21K639mR9ZAAgoMbeEv nqbFCaNEZMQaIXoTCCWRxkdR2zSrNtE+hXfI+HHSq+/Qyt243m+Vak46pNqfL8mgQqqp xdpvz9dbE+SZxEgdcuv0K97v4KLGK2GlMCQtoQAvwPVhVlOERIvesZrw9ERerk6OnpnD eWow== X-Gm-Message-State: APjAAAW7uUx7KV6mwlOAaQfqeB866Snxke5tm2R5h5EvVKva66L6sENS 8DDBT2ni2+Gbq43Oh2gsoliwdA== X-Google-Smtp-Source: APXvYqzu4HFk3XLY67ReDmSSeHuX4CFH8VygT+5D9E6iMHvE0v5XoUNZtGm8DWCnSZ9pIcW9imvfKg== X-Received: by 2002:a02:1006:: with SMTP id 6mr66453369jay.47.1558668665524; Thu, 23 May 2019 20:31:05 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id h185sm794380itb.16.2019.05.23.20.31.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 20:31:05 -0700 (PDT) From: Shuah Khan To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, helen.koike@collabora.com Cc: Shuah Khan , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] media: add generic device allocate interface to media-dev-allocator Date: Thu, 23 May 2019 21:31:01 -0600 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Media Device Allocator API supports just USB devices. Enhance it adding a genetic device allocate interface to support other media drivers. The new interface takes pointer to struct device instead and creates media device. This interface allows a group of drivers that have a common root device to share media device resource and ensure media device doesn't get deleted as long as one of the drivers holds its reference. The new interface has been tested with vimc component driver to fix panics when vimc module is removed while streaming is in progress. Signed-off-by: Shuah Khan --- drivers/media/Makefile | 4 +-- drivers/media/media-dev-allocator.c | 39 ++++++++++++++++++++++++ include/media/media-dev-allocator.h | 46 +++++++++++++++++++++++++---- 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/drivers/media/Makefile b/drivers/media/Makefile index 4a330d0e5e40..3a4f7f74301d 100644 --- a/drivers/media/Makefile +++ b/drivers/media/Makefile @@ -7,9 +7,7 @@ media-objs := media-device.o media-devnode.o media-entity.o \ media-request.o ifeq ($(CONFIG_MEDIA_CONTROLLER),y) - ifeq ($(CONFIG_USB),y) - media-objs += media-dev-allocator.o - endif + media-objs += media-dev-allocator.o endif # diff --git a/drivers/media/media-dev-allocator.c b/drivers/media/media-dev-allocator.c index ae17887dec59..4078e098cede 100644 --- a/drivers/media/media-dev-allocator.c +++ b/drivers/media/media-dev-allocator.c @@ -94,6 +94,7 @@ static struct media_device *__media_device_get(struct device *dev, return &mdi->mdev; } +#if IS_ENABLED(CONFIG_USB) struct media_device *media_device_usb_allocate(struct usb_device *udev, const char *module_name, struct module *owner) @@ -115,6 +116,44 @@ struct media_device *media_device_usb_allocate(struct usb_device *udev, return mdev; } EXPORT_SYMBOL_GPL(media_device_usb_allocate); +#endif + +struct media_device *media_device_allocate(struct device *dev, + const char *model, + const char *bus_info, + const char *module_name, + struct module *owner) +{ + struct media_device *mdev; + + mutex_lock(&media_device_lock); + mdev = __media_device_get(dev, module_name, owner); + if (!mdev) { + mutex_unlock(&media_device_lock); + return ERR_PTR(-ENOMEM); + } + + if (!mdev->dev) { + /* Initialize media device */ + if (model) + strscpy(mdev->model, model, sizeof(mdev->model)); + else + strscpy(mdev->model, "Unkonw model", + sizeof(mdev->model)); + if (bus_info) + strscpy(mdev->bus_info, bus_info, + sizeof(mdev->bus_info)); + else + strscpy(mdev->bus_info, "Unknown bus_info", + sizeof(mdev->bus_info)); + mdev->dev = dev; + media_device_init(mdev); + } + + mutex_unlock(&media_device_lock); + return mdev; +} +EXPORT_SYMBOL_GPL(media_device_allocate); void media_device_delete(struct media_device *mdev, const char *module_name, struct module *owner) diff --git a/include/media/media-dev-allocator.h b/include/media/media-dev-allocator.h index b35ea6062596..479a3c52cf89 100644 --- a/include/media/media-dev-allocator.h +++ b/include/media/media-dev-allocator.h @@ -19,7 +19,8 @@ struct usb_device; -#if defined(CONFIG_MEDIA_CONTROLLER) && defined(CONFIG_USB) +#if defined(CONFIG_MEDIA_CONTROLLER) +#if defined(CONFIG_USB) /** * media_device_usb_allocate() - Allocate and return struct &media device * @@ -38,6 +39,36 @@ struct usb_device; struct media_device *media_device_usb_allocate(struct usb_device *udev, const char *module_name, struct module *owner); +#else +static inline struct media_device *media_device_usb_allocate( + struct usb_device *udev, const char *module_name, + struct module *owner) + { return NULL; } +#endif /* CONFIG_USB */ +/** + * media_device_allocate() - Allocate and return struct &media device + * + * @udev: struct &device pointer + * @model: should be filled with device model name + * @bus_info: should be filled with device bus information: + * Unique and stable device location identifier + * as defined in struct media_device + * @module_name: should be filled with %KBUILD_MODNAME + * @owner: struct module pointer %THIS_MODULE for the driver. + * %THIS_MODULE is null for a built-in driver. + * It is safe even when %THIS_MODULE is null. + * + * This interface should be called to allocate a Media Device when multiple + * drivers/sub-drivers share device and the media device. This interface + * allocates &media_device structure and calls media_device_init() to + * initialize it. + * + */ +struct media_device *media_device_allocate(struct device *dev, + const char *model, + const char *bus_info, + const char *module_name, + struct module *owner); /** * media_device_delete() - Release media device. Calls kref_put(). * @@ -52,12 +83,15 @@ struct media_device *media_device_usb_allocate(struct usb_device *udev, void media_device_delete(struct media_device *mdev, const char *module_name, struct module *owner); #else -static inline struct media_device *media_device_usb_allocate( - struct usb_device *udev, const char *module_name, - struct module *owner) - { return NULL; } +static inline struct media_device *media_device_allocate( + struct device *dev, + const char *model, + const char *bus_info, + const char *module_name, + struct module *owner) + { return NULL; } static inline void media_device_delete( struct media_device *mdev, const char *module_name, struct module *owner) { } -#endif /* CONFIG_MEDIA_CONTROLLER && CONFIG_USB */ +#endif /* CONFIG_MEDIA_CONTROLLER */ #endif /* _MEDIA_DEV_ALLOCATOR_H */ -- 2.17.1