From patchwork Thu Nov 9 17:09:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10051381 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 8D20060381 for ; Thu, 9 Nov 2017 17:13:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 739922B04F for ; Thu, 9 Nov 2017 17:13:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6761A2B050; Thu, 9 Nov 2017 17:13:32 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, 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 0AD6B2B038 for ; Thu, 9 Nov 2017 17:13:32 +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 1eCqLj-00044n-Ra; Thu, 09 Nov 2017 17:10:43 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCqLi-00042q-K4 for xen-devel@lists.xenproject.org; Thu, 09 Nov 2017 17:10:42 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 0C/FB-25852-21C840A5; Thu, 09 Nov 2017 17:10:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHIsWRWlGSWpSXmKPExsVyMfS6i65gD0u UwYFpQhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bj4+vZCl6IVCz/8palgXGyQBcjF4eQwHRG iac9h1lBHBaBlywSr169YgJxJAT6WSUe9k0GcjiBnCyJvbNvsELYaRIT/xxhg7ArJHZ9bQSLC wkoSbzeuZkJYuxsJomJ9y8wgyTYBAwk9r97wg5iiwAV3VsFMZRZwEKi+fgsFhBbWCBQ4uuDZ2 BxFgFViT1Xz4EN5RVwlth45hHUEXISN891gs3kFHCRePPxOhvEYmeJi6+Ps01gFFzAyLCKUb0 4tagstUjXQi+pKDM9oyQ3MTNH19DATC83tbg4MT01JzGpWC85P3cTIzDkGIBgB+Psy/6HGCU5 mJREeaUsWaKE+JLyUyozEosz4otKc1KLDzHKcHAoSfDydAPlBItS01Mr0jJzgMEPk5bg4FES4 X3XBZTmLS5IzC3OTIdInWK057hw59IfJo4De24ByWczXzcwc0y72trELMSSl5+XKiXOawUyVQ CkLaM0D24oLFovMcpKCfMyAp0pxFOQWpSbWYIq/4pRnINRSZjXEGQKT2ZeCdzuV0BnMQGdFc0 OdlZJIkJKqoFxp25gydfTU4RDFnApmJ5g3/MnZp2m3Y2pH98GO9vNi1KZWVtml9kskZkk9eOZ yRI3W+lPsddf7Wj/WvIpOeC3WbxusngV6+v842K3GZ/2Cjzqac37xvgpawXz4h/fWRJ/2LHrH Xkkeal3k5ZN547qmZwvXiyJnqta916YmfFt7prts85dvj5HiaU4I9FQi7moOBEABU1/ktECAA A= X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-16.tower-27.messagelabs.com!1510247440!115444762!1 X-Originating-IP: [209.85.215.68] 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 59165 invoked from network); 9 Nov 2017 17:10:41 -0000 Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by server-16.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 9 Nov 2017 17:10:41 -0000 Received: by mail-lf0-f68.google.com with SMTP id 90so8023988lfs.13 for ; Thu, 09 Nov 2017 09:10:41 -0800 (PST) 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=2KxiGWY45muZYUJGOi1ABWYiII1S2F+wiHDur3uA1Ug=; b=FDtw74hAQWiBJ/2rXdRdpUPNhtfEg3N4x21WcnVKOW3vB1W29aDeO/6HDjEMmY2/uW sZ6RNma5X5tj1VCgqcoBe95F/j0U8N9Dhqgld2NQ+Rwt6MyfkNeAGPtXk3RMciswUsmy rW7eJIDezB/UaseKAfaZarHEuMCXTSLiYj69jYZCHgXs16LtwhY9sRGEW2mTYQJnamZG sR0mB/533vw1vwIpgk9sU9kbHmwq/LTEwm8XS00PP15SbLkKgh4VGIpoNGW6aXutZnGj lNLCesjzTdXs9HZqG5d8/lgGklhSHvJcna8NWb27IsiWsfllRIg+ZQvZgeXLLeeQMQOb qCBQ== 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=2KxiGWY45muZYUJGOi1ABWYiII1S2F+wiHDur3uA1Ug=; b=TFKKvbKZtj4Zqv46J9mP8FV6hho//IcUbucCqW7jT2b/mSNLJpvji7LdUJlQH+ezQG gxCYWRlMUocxB224Cc3utned1oKGvsfjWg/LcvNII0A6YGzr7D9TQ5Nf3cklql6DEJIy 8SXv5xyEpZkSmzbAmrMR6HhD8IPKQfaordeY32PJJHjiZP90jwV0XXpbvpO50RZ2NaAk nEDyl8kd+esoLZVLSFP0ZijlMv+ePaQDp/zLDX8HgpgN+hyW+0IxuYEnB1zO9Z0Asd5Y 8Iub6AZuCqJA9DY7UAP6oeTXJzuegGjej6PrjddsDsDNIaODRGBQMIJgdYrq6yroiNvT p+qw== X-Gm-Message-State: AJaThX65LwFyb2uLX93xEeoGLiTLOwUuKaurwkhCdIN6QPHrd0aCt7cr 9icZr4DHI4lVnW42EZ8O/LjxYA== X-Google-Smtp-Source: AGs4zMZ67zHkaRS+BNGDaowiguojPBMbh9eBo78WgULGP5kbcC9AHx4xqaZTcZwE+p1Xb4bCsoRDMw== X-Received: by 10.25.221.216 with SMTP id w85mr497798lfi.19.1510247440371; Thu, 09 Nov 2017 09:10:40 -0800 (PST) Received: from otyshchenko.kyiv.epam.com (ll-53.209.223.85.sovam.net.ua. [85.223.209.53]) by smtp.gmail.com with ESMTPSA id x90sm1394299ljb.86.2017.11.09.09.10.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Nov 2017 09:10:39 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Thu, 9 Nov 2017 19:09:58 +0200 Message-Id: <1510247421-24094-9-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510247421-24094-1-git-send-email-olekstysh@gmail.com> References: <1510247421-24094-1-git-send-email-olekstysh@gmail.com> Cc: Oleksandr Tyshchenko Subject: [Xen-devel] [RFC PATCH 08/31] xen/device-tree: Add dt_count_phandle_with_args helper 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 Tyshchenko Port Linux helper of_count_phandle_with_args for counting number of phandles in a property. Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Julien Grall --- Changes in v1: - Add Julien's reviewed-by Changes in v2: - --- xen/common/device_tree.c | 7 +++++++ xen/include/xen/device_tree.h | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 7b009ea..60b0095 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1663,6 +1663,13 @@ int dt_parse_phandle_with_args(const struct dt_device_node *np, index, out_args); } +int dt_count_phandle_with_args(const struct dt_device_node *np, + const char *list_name, + const char *cells_name) +{ + return __dt_parse_phandle_with_args(np, list_name, cells_name, 0, -1, NULL); +} + /** * unflatten_dt_node - Alloc and populate a device_node from the flat tree * @fdt: The parent device tree blob diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 0aecbe0..738f1b6 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -764,6 +764,25 @@ int dt_parse_phandle_with_args(const struct dt_device_node *np, const char *cells_name, int index, struct dt_phandle_args *out_args); +/** + * dt_count_phandle_with_args() - Find the number of phandles references in a property + * @np: pointer to a device tree node containing a list + * @list_name: property name that contains a list + * @cells_name: property name that specifies phandles' arguments count + * + * Returns the number of phandle + argument tuples within a property. It + * is a typical pattern to encode a list of phandle and variable + * arguments into a single property. The number of arguments is encoded + * by a property in the phandle-target node. For example, a gpios + * property would contain a list of GPIO specifies consisting of a + * phandle and 1 or more arguments. The number of arguments are + * determined by the #gpio-cells property in the node pointed to by the + * phandle. + */ +int dt_count_phandle_with_args(const struct dt_device_node *np, + const char *list_name, + const char *cells_name); + #ifdef CONFIG_DEVICE_TREE_DEBUG #define dt_dprintk(fmt, args...) \ printk(XENLOG_DEBUG fmt, ## args)