From patchwork Wed Jul 1 09:40:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6701911 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1001EC05AC for ; Wed, 1 Jul 2015 09:42:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 130DE2066E for ; Wed, 1 Jul 2015 09:42:37 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 854D820689 for ; Wed, 1 Jul 2015 09:42:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 81B4D6EAA8; Wed, 1 Jul 2015 02:42:34 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by gabe.freedesktop.org (Postfix) with ESMTPS id 47B236EAA8 for ; Wed, 1 Jul 2015 02:42:33 -0700 (PDT) Received: by wibdq8 with SMTP id dq8so39833216wib.1 for ; Wed, 01 Jul 2015 02:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nzNLkLZlbVSdhcNlAfuEM79vuIIqmzLQdbDOFkWub5c=; b=B45/vakO6yf9R4rvX1mwtHcnhDi8vbAQzPl2WtUrAfjI2pWiS4Pa475D8CmyDyp+m1 C9VjDW3osijaWTKUU8472spra9O42bkYDOBqdoqEu7rxKJa+E2HTEc9TIcoA7zhDvC2f W/GQn4qLB4iySjXTHPVQ2PZoYlXyUCE0Vn0reNCLvJHVQCkGPF5sPryoLmzKW2vZ2pRX CcqrJRE6h2SoU5DQQZ5w6LTPBOCQbW1Jkw3z82rJlSswVAjvSG1LhcFB/uHb9zCVV2o7 u28UsyQt5UUG5CTKKaJfFPbJ/PWFnOqSHzsVvv8hRce6UcvbJjkkOR9sTyS1IpMHMcQ5 HZVA== X-Received: by 10.194.206.65 with SMTP id lm1mr47654071wjc.117.1435743752052; Wed, 01 Jul 2015 02:42:32 -0700 (PDT) Received: from cizrna.lan ([109.72.12.160]) by mx.google.com with ESMTPSA id x10sm1992663wjr.25.2015.07.01.02.42.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jul 2015 02:42:31 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v2 02/12] device: property: find dependencies of a firmware node Date: Wed, 1 Jul 2015 11:40:57 +0200 Message-Id: <1435743667-11987-3-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1435743667-11987-1-git-send-email-tomeu.vizoso@collabora.com> References: <1435743667-11987-1-git-send-email-tomeu.vizoso@collabora.com> Cc: devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, Tomeu Vizoso , linux-gpio@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , alsa-devel@alsa-project.org, dri-devel@lists.freedesktop.org, linux-acpi@vger.kernel.org, Mark Brown , linux-pwm@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 Adds API that allows callers to find out what other firmware nodes a node depends on. Implementors of bindings documentation can register callbacks that return the dependencies of a node. Dependency information can be used to change the order in which devices are probed, or to print a warning when a device node is going to be probed without all its dependencies fulfilled. Signed-off-by: Tomeu Vizoso --- Changes in v2: - Allow bindings implementations register a function instead of using class callbacks, as not only subsystems implement firmware bindings. drivers/base/property.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fwnode.h | 5 +++ include/linux/property.h | 12 +++++++ 3 files changed, 108 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 8ead1ba..9d38ede 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -19,7 +19,13 @@ #include #include +struct dependency_parser { + struct list_head parser; + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps); +}; + static bool fwnode_match_enable = false; +static LIST_HEAD(dependency_parsers); /** * device_add_property_set - Add a collection of properties to a device object. @@ -553,6 +559,27 @@ bool device_dma_is_coherent(struct device *dev) EXPORT_SYMBOL_GPL(device_dma_is_coherent); /** + * fwnode_add_dependency - add firmware node to the passed dependency list + * @fwnode: Firmware node to add to dependency list + * @list: Dependency list to add the fwnode to + */ +void fwnode_add_dependency(struct fwnode_handle *fwnode, + struct list_head *list) +{ + struct fwnode_dependency *dep; + + dep = kzalloc(sizeof(*dep), GFP_KERNEL); + if (!dep) + return; + + INIT_LIST_HEAD(&dep->dependency); + dep->fwnode = fwnode; + + list_add_tail(&dep->dependency, list); +} +EXPORT_SYMBOL_GPL(fwnode_add_dependency); + +/** * fwnode_get_parent - return the parent node of a device node * @fwnode: Device node to find the parent node of */ @@ -600,6 +627,70 @@ bool fwnode_is_compatible(struct fwnode_handle *fwnode, const char *compatible) EXPORT_SYMBOL_GPL(fwnode_is_compatible); /** + * fwnode_add_dependency_parser - register dependency parser + * @func: Function that will be called to find out dependencies of a node + * + * Registers a callback that will be called when collecting the dependencies + * of a firmware node. The callback should inspect the properties of the node + * and call fwnode_add_dependency() for each dependency it recognizes, from + * the bindings documentation. + */ +void fwnode_add_dependency_parser( + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps)) +{ + struct dependency_parser *parser; + + parser = kzalloc(sizeof(*parser), GFP_KERNEL); + if (!parser) + return; + + INIT_LIST_HEAD(&parser->parser); + parser->func = func; + + list_add_tail(&parser->parser, &dependency_parsers); +} +EXPORT_SYMBOL_GPL(fwnode_add_dependency_parser); + +/** + * fwnode_remove_dependency_parser - unregister dependency parser + * @func: Function that was to be called to find out dependencies of a node + */ +void fwnode_remove_dependency_parser( + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps)) +{ + struct dependency_parser *parser, *tmp; + + list_for_each_entry_safe(parser, tmp, &dependency_parsers, parser) { + if (parser->func == func) { + list_del(&parser->parser); + kfree(parser); + return; + } + } +} +EXPORT_SYMBOL_GPL(fwnode_remove_dependency_parser); + +/** + * fwnode_get_dependencies - find out what dependencies a firmware node has + * @fwnode: firmware node to find its dependencies + * @deps: list of struct fwnode_dependency in which dependencies will be placed + */ +void fwnode_get_dependencies(struct fwnode_handle *fwnode, + struct list_head *deps) +{ + struct dependency_parser *parser; + struct fwnode_handle *child; + + list_for_each_entry(parser, &dependency_parsers, parser) + parser->func(fwnode, deps); + + /* Some device nodes will have dependencies in non-device sub-nodes */ + fwnode_for_each_child_node(fwnode, child) + if (!fwnode_property_present(child, "compatible")) + fwnode_get_dependencies(child, deps); +} + +/** * fwnode_driver_match_device - Tell if a driver matches a device. * @drv: the device_driver structure to test * @dev: the device structure to match against diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 0408545..68ab558 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -24,4 +24,9 @@ struct fwnode_handle { struct fwnode_handle *secondary; }; +struct fwnode_dependency { + struct fwnode_handle *fwnode; + struct list_head dependency; +}; + #endif diff --git a/include/linux/property.h b/include/linux/property.h index 4e453c4..b8b86ea 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -86,6 +86,18 @@ bool fwnode_is_compatible(struct fwnode_handle *fwnode, const char *compatible); bool fwnode_driver_match_device(struct device *dev, const struct device_driver *drv); +void fwnode_add_dependency(struct fwnode_handle *fwnode, + struct list_head *list); + +void fwnode_add_dependency_parser( + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps)); + +void fwnode_remove_dependency_parser( + void (*func)(struct fwnode_handle *fwnode, struct list_head *deps)); + +void fwnode_get_dependencies(struct fwnode_handle *fwnode, + struct list_head *list); + unsigned int device_get_child_node_count(struct device *dev); static inline bool device_property_read_bool(struct device *dev,