From patchwork Thu May 2 14:13:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10926921 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 6245713AD for ; Thu, 2 May 2019 14:16:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51A4A24BFE for ; Thu, 2 May 2019 14:16:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 456062640A; Thu, 2 May 2019 14:16:02 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C8DC924BFE for ; Thu, 2 May 2019 14:16:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hMCTx-0001VN-EZ; Thu, 02 May 2019 14:14:41 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hMCTv-0001V5-J6 for xen-devel@lists.xenproject.org; Thu, 02 May 2019 14:14:39 +0000 X-Inumbo-ID: 9e8fce8e-6ce4-11e9-843c-bc764e045a96 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 9e8fce8e-6ce4-11e9-843c-bc764e045a96; Thu, 02 May 2019 14:14:38 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id h21so2291458ljk.13 for ; Thu, 02 May 2019 07:14:38 -0700 (PDT) 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=czcrQJ4ZOkigVhUXJ1PqpCqEbSt+PWnfNBwK7rAOIVo=; b=HggtKAWincswp8O2AwNnv0IVbVU+lVSKShIk/+ZJ2A0UTcX0jEe6Vhm0LjSN+pLA+6 fIaiIsxyTfR3npN1xPsqALFShEJkMz0KnlsF7rPVPspQ5rMrScdnmB/Dchi1Vh7pFRTU R1et7HwuOCihJm9kH60eAHq3H9/n00o6bb04GmwMAw7ECj4Sx2EC5JxJ3UbmVKPQSWaH 9ucgdRQ0wsANIQDArMgdZNxFk5YuOod015U5nJEQyxkIK/yb0VdVkmivFgpxyDeke/3j d82w55+qdb2KejIfP/SEOc0P8wwVrFnZf9pmOsGqjjNBlXtmMSqRzOBny1oROHqXHwj2 rphA== 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=czcrQJ4ZOkigVhUXJ1PqpCqEbSt+PWnfNBwK7rAOIVo=; b=DLptbDWtA79EExGtI6XH2PFzDntwMY1Gfe9TZ41E45PK3DM8O7SsOf83e9jDYZkqOq lNRL15mce7U2dTkJWgsxahVf78KEPAaCxwj7H9XBLjsM9V4xVSyFZS8aUHmWxDIWqEo/ pKkW6gdrAPOvAvZXgnKCa7096hWVPq0n7osJarHURlQXB0b4H4zAvNRug9Ayh3riL4Z0 rmSWicQkWEkhJkR89JIcfNqIB4bBDwn1kYSOLqsjv+ZUljSzgTE+eDsAgTT9u2IdUmK/ X5caeiTIseDW7ucTvazMyRKnK+KN8kmMOA/rlmmEj5NvfioInMm/j/7cZ9X32uHrGX6P AYTg== X-Gm-Message-State: APjAAAU/56npV+qTGLAFgT7csiNefy0/AxbBSTog7N8+6EuUVbU+WL4R UYdHg+lapkYcp9onoPP1jlSFKq21DqA= X-Google-Smtp-Source: APXvYqxwvUq+coxxlISjHlNCZ3dkTi2eTt9o3LlhLai1hthYE5COmHJ43XZFMVCDMJTuwrIKKi55Yg== X-Received: by 2002:a2e:5c49:: with SMTP id q70mr2092746ljb.16.1556806477373; Thu, 02 May 2019 07:14:37 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id v11sm9447761lfb.68.2019.05.02.07.14.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 May 2019 07:14:36 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Thu, 2 May 2019 17:13:55 +0300 Message-Id: <1556806436-26283-2-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556806436-26283-1-git-send-email-olekstysh@gmail.com> References: <1556806436-26283-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [RFC PATCH 1/2] xen/device-tree: Add dt_count_phandle_with_args helper X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.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 --- 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 8fc401d..65862b5 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 7408a6c..8315629 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -738,6 +738,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)