diff mbox series

[RFC,1/2] xen/device-tree: Add dt_count_phandle_with_args helper

Message ID 1556806436-26283-2-git-send-email-olekstysh@gmail.com (mailing list archive)
State Superseded
Headers show
Series Add ability to handle nodes with interrupts-extended property | expand

Commit Message

Oleksandr Tyshchenko May 2, 2019, 2:13 p.m. UTC
From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

Port Linux helper of_count_phandle_with_args for counting
number of phandles in a property.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
---
 xen/common/device_tree.c      |  7 +++++++
 xen/include/xen/device_tree.h | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+)

Comments

Julien Grall May 20, 2019, 11:03 a.m. UTC | #1
Hi,

On 02/05/2019 15:13, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> 
> Port Linux helper of_count_phandle_with_args for counting
> number of phandles in a property.

Linux 5.1 uses a completely different implementation for 
of_count_phandle_with_args. So which version of Linux did you port from?

Cheers,
Oleksandr Tyshchenko May 20, 2019, 1:48 p.m. UTC | #2
On 20.05.19 14:03, Julien Grall wrote:
> Hi,

Hi, Julien


>
> On 02/05/2019 15:13, Oleksandr Tyshchenko wrote:
>> From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>>
>> Port Linux helper of_count_phandle_with_args for counting
>> number of phandles in a property.
>
> Linux 5.1 uses a completely different implementation for 
> of_count_phandle_with_args. So which version of Linux did you port from?

This patch is exactly the same one [1], I did more than 2 years ago in 
the context of non-shared IOMMU patch series. Likely, I was based on v4.4.

Sorry for the confusing description.


You are right, current implementation of_count_phandle_with_args is 
completely different, and I am afraid, is not easily back-portable to Xen.

If the implementation "v4.4" looks correct and fits in current Xen 
codebase, I can recollect an exact version and update the patch 
description.

What do you think?


[1] https://patchwork.kernel.org/patch/9862557/

>
> Cheers,
>
Julien Grall May 20, 2019, 2:37 p.m. UTC | #3
On 20/05/2019 14:48, Oleksandr wrote:
> 
> On 20.05.19 14:03, Julien Grall wrote:
>> Hi,
> 
> Hi, Julien
> 
> 
>>
>> On 02/05/2019 15:13, Oleksandr Tyshchenko wrote:
>>> From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>>>
>>> Port Linux helper of_count_phandle_with_args for counting
>>> number of phandles in a property.
>>
>> Linux 5.1 uses a completely different implementation for 
>> of_count_phandle_with_args. So which version of Linux did you port from?
> 
> This patch is exactly the same one [1], I did more than 2 years ago in the 
> context of non-shared IOMMU patch series. Likely, I was based on v4.4.
> 
> Sorry for the confusing description.
> 
> 
> You are right, current implementation of_count_phandle_with_args is completely 
> different, and I am afraid, is not easily back-portable to Xen.
> 
> If the implementation "v4.4" looks correct and fits in current Xen codebase, I 
> can recollect an exact version and update the patch description.
> 
> What do you think?

The current implementation looks correct. So the commit message needs to be updated.

Cheers,
diff mbox series

Patch

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)