Skip to contentSkip to conversation

Add ability to handle nodes with interrupts-extended property

PATCH In review Oleksandr Tyshchenko 2 participants 9 messages May 21, 2019 – Jun 11, 2019

lore
Share & tools
lore
#0 lore raw

cover Add ability to handle nodes with interrupts-extended property

From: Oleksandr Tyshchenko <[email protected]>

Hello, all.

The purpose of this small series is to add minimal required support for Xen to be able to handle device-tree nodes with "interrupts-extended" property [1].

The "interrupts-extended" property is a special form for use when a node needs to reference multiple interrupt parents.

But, there are cases when "interrupts-extended" property is used for "outside /soc node" with a single interrupt parent as an equivalent of pairs ("interrupt-parent" + "interrupts").

----------
Tested on R-Car Gen2 based board using current staging (commit 91f86f8634f99abd8f242943e62452211a09fa0a). Log (with debug enabled) shows that Xen recognized ARCH timer interrupts represented with "interrupts-extended" property:

timer {
	compatible = "arm,armv7-timer";
	interrupts-extended = <&gic GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(8) | IRQ_TYPE_LEVEL_LOW)>,
			      <&gic GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(8) | IRQ_TYPE_LEVEL_LOW)>,
			      <&gic GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(8) | IRQ_TYPE_LEVEL_LOW)>,
			      <&gic GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(8) | IRQ_TYPE_LEVEL_LOW)>;
};

Xen 4.13-unstable
(XEN) Xen version 4.13-unstable (otyshchenko@) (arm-linux-gnueabi-gcc (Linaro GCC 7.3-2018.05) 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701]) debug=y Tue May 21 17:08:47 E9 (XEN) Latest ChangeSet: Thu Feb 2 11:59:05 2017 +0200 git:85faf88
(XEN) build-id: f0739ad25a57b50d508afd5e22e93af3d052acbf
(XEN) Processor: 413fc0f2: "ARM Limited", variant: 0x3, part 0xc0f, rev 0x2
(XEN) 32-bit Execution:
(XEN) Processor Features: 00001131:00011011
(XEN) Instruction Sets: AArch32 A32 Thumb Thumb-2 ThumbEE Jazelle
(XEN) Extensions: GenericTimer Security

(XEN)   Debug Features: 02010555
(XEN)   Auxiliary Features: 00000000
(XEN)   Memory Model Features: 10201105 40000000 01240000 02102211

(XEN) ISA Features: 02101110 13112111 21232041 11112131 10011142 00000000
(XEN) Using SMC Calling Convention v1.0
(XEN) Using PSCI v1.0
(XEN) SMP: Allowing 8 CPUs
(XEN) dt_device_get_raw_irq: dev=/timer, index=0
(XEN) using 'interrupts-extended' property
(XEN) intspec=1 intsize=3
(XEN) dt_irq_map_raw: par=/soc/interrupt-controller@f1001000,intspec=[0x00000001 0x0000000d...],ointsize=3 (XEN) dt_irq_map_raw: ipar=/soc/interrupt-controller@f1001000, size=3
(XEN) -> addrsize=0
(XEN) -> got it !
(XEN) dt_device_get_raw_irq: dev=/timer, index=1
(XEN) using 'interrupts-extended' property
(XEN) intspec=1 intsize=3
(XEN) dt_irq_map_raw: par=/soc/interrupt-controller@f1001000,intspec=[0x00000001 0x0000000e...],ointsize=3 (XEN) dt_irq_map_raw: ipar=/soc/interrupt-controller@f1001000, size=3
(XEN) -> addrsize=0
(XEN) -> got it !
(XEN) dt_device_get_raw_irq: dev=/timer, index=2
(XEN) using 'interrupts-extended' property
(XEN) intspec=1 intsize=3
(XEN) dt_irq_map_raw: par=/soc/interrupt-controller@f1001000,intspec=[0x00000001 0x0000000b...],ointsize=3 (XEN) dt_irq_map_raw: ipar=/soc/interrupt-controller@f1001000, size=3
(XEN) -> addrsize=0
(XEN) -> got it !
(XEN) dt_device_get_raw_irq: dev=/timer, index=3
(XEN) using 'interrupts-extended' property
(XEN) intspec=1 intsize=3
(XEN) dt_irq_map_raw: par=/soc/interrupt-controller@f1001000,intspec=[0x00000001 0x0000000a...],ointsize=3 (XEN) dt_irq_map_raw: ipar=/soc/interrupt-controller@f1001000, size=3
(XEN) -> addrsize=0
(XEN) -> got it !
(XEN) Generic Timer IRQ: phys=30 hyp=26 virt=27 Freq: 10000 KHz
----------

[1] https://elixir.bootlin.com/linux/v5.2-rc1/source/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt

Oleksandr Tyshchenko (2):
xen/device-tree: Add dt_count_phandle_with_args helper xen/device-tree: Add ability to handle nodes with interrupts-extended
prop

 xen/common/device_tree.c      | 43 ++++++++++++++++++++++++++++++++++++++++---
 xen/include/xen/device_tree.h | 19 +++++++++++++++++++
 2 files changed, 59 insertions(+), 3 deletions(-)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/2 xen/device-tree: Add dt_count_phandle_with_args helper

From: Oleksandr Tyshchenko <[email protected]>

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.

---
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(+)
xen/common/device_tree.c +7 -0
index 8fc401d..65862b5 100644
@@ -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
xen/include/xen/device_tree.h +19 -0
index 7408a6c..8315629 100644
@@ -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)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH V1 1/2] xen/device-tree: Add dt_count_phandle_with_args helper

Hi Oleksandr,

Quoted 8 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

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.

Cheers,

Quoted 58 lines

---
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(+)
xen/common/device_tree.c +7 -0
index 8fc401d..65862b5 100644
@@ -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
xen/include/xen/device_tree.h +19 -0
index 7408a6c..8315629 100644
@@ -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)
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

PATCH 2/2 xen/device-tree: Add ability to handle nodes with interrupts-extended prop

In reply to Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The "interrupts-extended" property is a special form for use when a node needs to reference multiple interrupt parents.

According to the:
Linux/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt

But, there are cases when "interrupts-extended" property is used for "outside /soc node" with a single interrupt parent as an equivalent of pairs ("interrupt-parent" + "interrupts").

The good example here is ARCH timer node for R-Car Gen3/Gen2 family, which is mandatory device for Xen usage on ARM. And without ability to handle such nodes, Xen fails to operate.

So, this patch adds required support for Xen to be able to handle nodes with that property.

---
Changes RFC -> V1:
- Explain in the commit message regarding property usage, add a link to the bindings.
- Don't try to look for "interrupts" property if "interrupts-extended" property is present, but doesn't contain any interrupts (dt_count_phandle_with_args returns 0).
- Add messages to tell which property is used.

---
 xen/common/device_tree.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
xen/common/device_tree.c +33 -3
index 65862b5..e107c6f 100644
@@ -987,15 +987,27 @@ unsigned int dt_number_of_irq(const struct dt_device_node *device)
     const struct dt_device_node *p;
     const __be32 *intspec, *tmp;
     u32 intsize, intlen;
+    int intnum;
 
     dt_dprintk("dt_irq_number: dev=%s\n", device->full_name);
 
+    /* Try the new-style interrupts-extended first */
+    intnum = dt_count_phandle_with_args(device, "interrupts-extended",
+                                        "#interrupt-cells");
+    if ( intnum >= 0 )
+    {
+        dt_dprintk(" using 'interrupts-extended' property\n");
+        dt_dprintk(" intnum=%d\n", intnum);
+        return intnum;
+    }
+
     /* Get the interrupts property */
     intspec = dt_get_property(device, "interrupts", &intlen);
     if ( intspec == NULL )
         return 0;
     intlen /= sizeof(*intspec);
 
+    dt_dprintk(" using 'interrupts' property\n");
     dt_dprintk(" intspec=%d intlen=%d\n", be32_to_cpup(intspec), intlen);
 
     /* Look for the interrupt parent. */
@@ -1420,21 +1432,39 @@ int dt_device_get_raw_irq(const struct dt_device_node *device,
     const __be32 *intspec, *tmp, *addr;
     u32 intsize, intlen;
     int res = -EINVAL;
+    struct dt_phandle_args args;
+    int i;
 
     dt_dprintk("dt_device_get_raw_irq: dev=%s, index=%u\n",
                device->full_name, index);
 
+    /* Get the reg property (if any) */
+    addr = dt_get_property(device, "reg", NULL);
+
+    /* Try the new-style interrupts-extended first */
+    res = dt_parse_phandle_with_args(device, "interrupts-extended",
+                                     "#interrupt-cells", index, &args);
+    if ( !res )
+    {
+        dt_dprintk(" using 'interrupts-extended' property\n");
+        dt_dprintk(" intspec=%d intsize=%d\n", args.args[0], args.args_count);
+
+        for ( i = 0; i < args.args_count; i++ )
+            args.args[i] = cpu_to_be32(args.args[i]);
+
+        return dt_irq_map_raw(args.np, args.args, args.args_count,
+                              addr, out_irq);
+    }
+
     /* Get the interrupts property */
     intspec = dt_get_property(device, "interrupts", &intlen);
     if ( intspec == NULL )
         return -EINVAL;
     intlen /= sizeof(*intspec);
 
+    dt_dprintk(" using 'interrupts' property\n");
     dt_dprintk(" intspec=%d intlen=%d\n", be32_to_cpup(intspec), intlen);
 
-    /* Get the reg property (if any) */
-    addr = dt_get_property(device, "reg", NULL);
-
     /* Look for the interrupt parent. */
     p = dt_irq_find_parent(device);
     if ( p == NULL )
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by Stefano Stabellini on v1 2/2
#4 lore raw

Re: [PATCH V1 2/2] xen/device-tree: Add ability to handle nodes with interrupts-extended prop

Hi Oleksandr,

Quoted 5 lines · Oleksandr Tyshchenko

From: Oleksandr Tyshchenko <[email protected]>

The "interrupts-extended" property is a special form for use when a node needs to reference multiple interrupt parents. > According to the:

NIT: s/the//

Quoted 7 lines

Linux/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt

But, there are cases when "interrupts-extended" property is used for "outside /soc node" with a single interrupt parent as an equivalent of pairs ("interrupt-parent" + "interrupts").

The good example here is ARCH timer node for R-Car Gen3/Gen2 family,

NIT: s/The/A/ I think

Quoted 7 lines

which is mandatory device for Xen usage on ARM. And without ability to handle such nodes, Xen fails to operate.

So, this patch adds required support for Xen to be able to handle nodes with that property.

I will give an opportunity to Stefano to review it. If I don't hear anything by Monday, I will merge it.

Thank you!

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#5 lore raw

Re: [PATCH V1 2/2] xen/device-tree: Add ability to handle nodes with interrupts-extended prop

Quoted 1 line · Julien Grall

Hi Oleksandr,

Hi, Julien

Quoted 24 lines · Oleksandr Tyshchenko
Quoted 5 lines

From: Oleksandr Tyshchenko <[email protected]>

The "interrupts-extended" property is a special form for use when a node needs to reference multiple interrupt parents. > According to the:

NIT: s/the//

Quoted 8 lines

Linux/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt

But, there are cases when "interrupts-extended" property is used for "outside /soc node" with a single interrupt parent as an equivalent of pairs ("interrupt-parent" + "interrupts").

The good example here is ARCH timer node for R-Car Gen3/Gen2 family,

NIT: s/The/A/ I think

Quoted 3 lines

which is mandatory device for Xen usage on ARM. And without ability to handle such nodes, Xen fails to operate.

Quoted 6 lines
Quoted 4 lines

So, this patch adds required support for Xen to be able to handle nodes with that property.

Thank you! I assume you meant Reviewed-by: Julien Grall <[email protected]> )

Shall I send new version with proposed changes?

Quoted 7 lines

I will give an opportunity to Stefano to review it. If I don't hear anything by Monday, I will merge it.

Thank you!

Cheers,

Signature · 9 lines
Regards,

Oleksandr Tyshchenko


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

Re: [PATCH V1 2/2] xen/device-tree: Add ability to handle nodes with interrupts-extended prop

Quoted 34 lines · Oleksandr
Quoted 1 line · Julien Grall

Hi Oleksandr,

Hi, Julien

Quoted 27 lines · Oleksandr Tyshchenko
Quoted 5 lines

From: Oleksandr Tyshchenko <[email protected]>

The "interrupts-extended" property is a special form for use when a node needs to reference multiple interrupt parents. > According to the:

NIT: s/the//

Quoted 8 lines

Linux/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt

But, there are cases when "interrupts-extended" property is used for "outside /soc node" with a single interrupt parent as an equivalent of pairs ("interrupt-parent" + "interrupts").

The good example here is ARCH timer node for R-Car Gen3/Gen2 family,

NIT: s/The/A/ I think

Quoted 6 lines

which is mandatory device for Xen usage on ARM. And without ability to handle such nodes, Xen fails to operate.

So, this patch adds required support for Xen to be able to handle nodes with that property.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Thank you! I assume you meant Reviewed-by: Julien Grall <[email protected]> )

Yes sorry, I was adding is reviewed-by on some of my patches and mechanically copied here. Apologies for the inconvenience.

Quoted 2 lines

Shall I send new version with proposed changes?

No need, I can do the change while committing (assuming Stefano has no other comments).

Cheers,

Signature · 5 lines
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw

Re: [Xen-devel] [PATCH V1 2/2] xen/device-tree: Add ability to handle nodes with interrupts-extended prop

Hi,

Quoted 41 lines · Julien Grall
Quoted 38 lines · Oleksandr
Quoted 1 line · Julien Grall

Hi Oleksandr,

Hi, Julien

Quoted 30 lines · Oleksandr Tyshchenko
Quoted 5 lines

From: Oleksandr Tyshchenko <[email protected]>

The "interrupts-extended" property is a special form for use when a node needs to reference multiple interrupt parents. > According to the:

NIT: s/the//

Quoted 8 lines

Linux/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt

But, there are cases when "interrupts-extended" property is used for "outside /soc node" with a single interrupt parent as an equivalent of pairs ("interrupt-parent" + "interrupts").

The good example here is ARCH timer node for R-Car Gen3/Gen2 family,

NIT: s/The/A/ I think

Quoted 7 lines

which is mandatory device for Xen usage on ARM. And without ability to handle such nodes, Xen fails to operate.

So, this patch adds required support for Xen to be able to handle nodes with that property.

Quoted 8 lines
Quoted 1 line

Thank you! I assume you meant Reviewed-by: Julien Grall <[email protected]> )

Yes sorry, I was adding is reviewed-by on some of my patches and mechanically copied here. Apologies for the inconvenience.

Quoted 2 lines

Shall I send new version with proposed changes?

No need, I can do the change while committing (assuming Stefano has no other comments).

Now applied to my staging branch. It will be committed tonight.

Thank you for the patches.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#8 lore raw

Re: [Xen-devel] [PATCH V1 2/2] xen/device-tree: Add ability to handle nodes with interrupts-extended prop

Quoted 1 line · Julien Grall

Hi,

Hi Julien

Quoted 3 lines

Now applied to my staging branch. It will be committed tonight.

Thank you for the patches.

Thank you for the review.

Quoted 4 lines

Cheers,

Signature · 9 lines
Regards,

Oleksandr Tyshchenko


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel