From patchwork Tue May 21 17:37:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10954367 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 A4F8313AD for ; Tue, 21 May 2019 17:39:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AED9288C7 for ; Tue, 21 May 2019 17:39:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79EF328A85; Tue, 21 May 2019 17:39:25 +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 1A7A9288C7 for ; Tue, 21 May 2019 17:39:25 +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 1hT8i5-0007Z0-73; Tue, 21 May 2019 17:37:57 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hT8i4-0007Yf-59 for xen-devel@lists.xenproject.org; Tue, 21 May 2019 17:37:56 +0000 X-Inumbo-ID: 29ba55bd-7bef-11e9-8980-bc764e045a96 Received: from mail-lf1-x144.google.com (unknown [2a00:1450:4864:20::144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 29ba55bd-7bef-11e9-8980-bc764e045a96; Tue, 21 May 2019 17:37:54 +0000 (UTC) Received: by mail-lf1-x144.google.com with SMTP id f1so13766714lfl.6 for ; Tue, 21 May 2019 10:37:54 -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=tSMA8QyqFc8QL3sLZnnhSEVNYV9FEcTYvBxJXAcykl8=; b=n3Is9VcDyA737g+CrDnIYIbQ7Jq+Tw5EmQh3+9yhQlQzslfXLIV2sdP8c1QMIG2+f8 k/5uUXiaZ5mr7tZyKpaIhiO/5AD59lpqax67SRX/AQLJY25Bi1xpiNbJe9AGEBckSE7L 62Aa6hEzAGj46kZSGvWIhJq/fZCCAmof193hqr1FtUUI0RGTzqf1GzMTtVheVdzIe6uk Eu5caUa2AFhOHZH2YsoFQYF5W7FeMpG2++glXYcLAGURlQA+LCu6ajK4YIgBnaGj/jKg siM8DppmJXjLbISsAeXFPtISgBbQ8542w8SdeNifn3bJWrUWoeXAbjX3wOgBe8vYEPPR 7Slw== 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=tSMA8QyqFc8QL3sLZnnhSEVNYV9FEcTYvBxJXAcykl8=; b=B+yOYubMbHZOFyptQgTshcUcZKY76aIrz4ZoWQ64VGjcHb8IE8xoLa9C88inZ7ENbb J/BiwCPNnXsfKAfwtMhCkHSb7u81+ASn6dpbAJ/pq6jPcjjyAMjV3UsZHwboiGi3rErW vFq3eVZQ61/MCGsebQMwRJMgIj9ebIhH1l3dslTteEYa5DueRLOgn5FSoZj6vMb+4gvX gvTJOKQH1CCC/jST0Ks87H+9EcuYni2cy3FnTUDfmYOAzAz7KORGNmeJiCDyiuFzBY0c kF34hG6NBhrRcldkr4y36tJyrEL777TnsXfJ1ECmJqxQvN5Cseh6phSDasjMKluGrjcx hI2Q== X-Gm-Message-State: APjAAAW++fxck970OcZ+1vICQ5PaPRU9lKDAm4J0SFICIOMQ+CGvpGeK +3fbq1XfrTQAf9v2LmV0K6395iEmdcg= X-Google-Smtp-Source: APXvYqx4gtZ5kbgyjl8OcA6itnnfJtEp+CA0vz4g7b5FiN6uQ52b28IPSE2RRFhunb0qWjMalh2/Zw== X-Received: by 2002:ac2:510b:: with SMTP id q11mr39598394lfb.11.1558460273136; Tue, 21 May 2019 10:37:53 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id w19sm4827807lfk.56.2019.05.21.10.37.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 May 2019 10:37:52 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 21 May 2019 20:37:33 +0300 Message-Id: <1558460254-7127-2-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558460254-7127-1-git-send-email-olekstysh@gmail.com> References: <1558460254-7127-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V1 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. Please note, this helper is ported from Linux v4.6. Signed-off-by: Oleksandr Tyshchenko Acked-by: Julien Grall --- Changes RFC -> V1: - Add Linux version which is used as the base. --- 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)