From patchwork Wed Apr 9 15:21:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 3956361 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BD9A1BFF02 for ; Wed, 9 Apr 2014 15:22:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CDEA220562 for ; Wed, 9 Apr 2014 15:22:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC9182055C for ; Wed, 9 Apr 2014 15:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933979AbaDIPVb (ORCPT ); Wed, 9 Apr 2014 11:21:31 -0400 Received: from qmta13.emeryville.ca.mail.comcast.net ([76.96.27.243]:38669 "EHLO qmta13.emeryville.ca.mail.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933643AbaDIPV3 (ORCPT ); Wed, 9 Apr 2014 11:21:29 -0400 Received: from omta10.emeryville.ca.mail.comcast.net ([76.96.30.28]) by qmta13.emeryville.ca.mail.comcast.net with comcast id nq6C1n0030cQ2SLADrMUWF; Wed, 09 Apr 2014 15:21:28 +0000 Received: from mail.gonehiking.org ([50.134.149.16]) by omta10.emeryville.ca.mail.comcast.net with comcast id nrMT1n00C0MU7Qa8WrMT6V; Wed, 09 Apr 2014 15:21:28 +0000 Received: from lorien.sisa.samsung.com (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id 949123FCDF; Wed, 9 Apr 2014 09:21:26 -0600 (MDT) From: Shuah Khan To: gregkh@linuxfoundation.org, m.chehab@samsung.com, tj@kernel.org, rafael.j.wysocki@intel.com, linux@roeck-us.net, toshi.kani@hp.com Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, shuahkhan@gmail.com Subject: [RFC PATCH 1/2] drivers/base: add new devres_update() interface to devres_* Date: Wed, 9 Apr 2014 09:21:07 -0600 Message-Id: X-Mailer: git-send-email 1.8.3.2 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1397056888; bh=2E7Zj7yFaprLr4QanmOGveyDIeq8gg3gWm1d0dZ9QZg=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=dsQgJuUDqYz7Si4israiA0o3RBF0Mf1xqU01vMACmwMsrjmWMs2z45wpsEfwTZ7Lf oNQUahveePBI19fYApsk/2JTGcc+lVkZ6K6003qv9trqjpZKgh1vWl6KLmf+ILgDaj zqHuYfRsBGV/jPHZhrfips4ScOvLT5a3PopAi0ApR7RKFT7pncS3RBSKb1jXHqKRzE aH/Hnv5TGujgIOyN9tmYGYGp/czVSxHOjWzSlbmEqC2JNCIXdhiEeV0ydNW5Dr3sKB ZLQHK01uWD9oPfkoNxiJQf/OuHWqzqpqmzdHSayQ9TjQbdbqEPoFDHmdAH9L/yqGdV Mro/7aJuckN9g== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Media devices often have hardware resources that are shared across several functions. For instance, TV tuner cards often have MUXes, converters, radios, tuners, etc. that are shared across various functions. However, v4l2, alsa, DVB, usbfs, and all other drivers have no knowledge of what resources are shared. For example, users can't access DVB and alsa at the same time, or the DVB and V4L analog API at the same time, since many only have one converter that can be in either analog or digital mode. Accessing and/or changing mode of a converter while it is in use by another function results in video stream error. A shared devres that can be locked and unlocked by various drivers that control media functions on a single media device is needed to address the above problems. A token devres that can be looked up by a token for locking, try locking, unlocking will help avoid adding data structure dependencies between various media drivers. This token is a unique string that can be constructed from a common data structure such as struct device, bus_name, and hardware address. A new devres_* interface to update the status of this token resource to busy when locked and free when unlocked is necessary to implement this new managed resource. devres_update() searches for the resource that matches supplied match criteria similar to devres_find(). When a match is found, it calls the update function caller passed in. Signed-off-by: Shuah Khan --- drivers/base/devres.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/device.h | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index db4e264..8620600 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -272,6 +272,42 @@ void * devres_find(struct device *dev, dr_release_t release, EXPORT_SYMBOL_GPL(devres_find); /** + * devres_update - Find device resource and call update function + * @dev: Device to lookup resource from + * @release: Look for resources associated with this release function + * @match: Match function - must be specified + * @match_data: Data for the match function + * @update: Update function - must be specified + * + * Find the latest devres of @dev which is associated with @release + * and for which @match returns 1. If match is found, update will be + * called. This is intended for changes to status type data in a devres + * + * RETURNS: + * Pointer to found and updated devres, NULL if not found. + */ +void *devres_update(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data, dr_update_t update) +{ + struct devres *dr; + unsigned long flags; + + if (!match || !update) + return NULL; + + spin_lock_irqsave(&dev->devres_lock, flags); + dr = find_dr(dev, release, match, match_data); + if (dr) + update(dev, dr->data); + spin_unlock_irqrestore(&dev->devres_lock, flags); + + if (dr) + return dr->data; + return NULL; +} +EXPORT_SYMBOL_GPL(devres_update); + +/** * devres_get - Find devres, if non-existent, add one atomically * @dev: Device to lookup or add devres for * @new_res: Pointer to new initialized devres to add if not found diff --git a/include/linux/device.h b/include/linux/device.h index 233bbbe..39749df 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -576,6 +576,7 @@ extern int device_schedule_callback_owner(struct device *dev, /* device resource management */ typedef void (*dr_release_t)(struct device *dev, void *res); typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); +typedef void (*dr_update_t)(struct device *dev, void *data); #ifdef CONFIG_DEBUG_DEVRES extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp, @@ -593,6 +594,9 @@ extern void devres_free(void *res); extern void devres_add(struct device *dev, void *res); extern void *devres_find(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); +extern void *devres_update(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data, + dr_update_t update); extern void *devres_get(struct device *dev, void *new_res, dr_match_t match, void *match_data); extern void *devres_remove(struct device *dev, dr_release_t release,