Skip to contentSkip to conversation

xen/arm: merge make_timer_node and make_timer_domU_node

PATCH Superseded Viktor Mitin 2 participants 4 messages Jun 20, 2019 – Jul 16, 2019

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: merge make_timer_node and make_timer_domU_node

Functions make_timer_node and make_timer_domU_node are quite similar. The only difference between Dom0 and DomU timer DT node
is the timer interrupts used. All the rest code should be the same. So it is better to merge them to avoid discrepancy.

Tested dom0 boot with rcar h3 sk board.

---
 xen/arch/arm/domain_build.c | 66 ++++++++++++-------------------------
 1 file changed, 21 insertions(+), 45 deletions(-)
xen/arch/arm/domain_build.c +21 -45
index 7fb828cae2..610dd3e8e7 100644
@@ -976,6 +976,8 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
     gic_interrupt_t intrs[3];
     u32 clock_frequency;
     bool clock_valid;
+    bool d0 = is_hardware_domain(d);
+    uint32_t ip_val;
 
     dt_dprintk("Create timer node\n");
 
@@ -1004,22 +1006,36 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
     /* The timer IRQ is emulated by Xen. It always exposes an active-low
      * level-sensitive interrupt */
 
-    irq = timer_get_irq(TIMER_PHYS_SECURE_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_PHYS_SECURE_PPI)
+        : GUEST_TIMER_PHYS_S_PPI;
     dt_dprintk("  Secure interrupt %u\n", irq);
     set_interrupt(intrs[0], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_PHYS_NONSECURE_PPI)
+        : GUEST_TIMER_PHYS_NS_PPI;
     dt_dprintk("  Non secure interrupt %u\n", irq);
     set_interrupt(intrs[1], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_get_irq(TIMER_VIRT_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_VIRT_PPI)
+        : GUEST_TIMER_VIRT_PPI;
     dt_dprintk("  Virt interrupt %u\n", irq);
     set_interrupt(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    res = fdt_property_interrupts(fdt, intrs, 3);
+    res = fdt_property(fdt, "interrupts", intrs, sizeof (intrs[0]) * 3);
     if ( res )
         return res;
 
+    ip_val = d0
+           ? dt_interrupt_controller->phandle
+           : GUEST_PHANDLE_GIC;
+
+    res = fdt_property_cell(fdt, "interrupt-parent", ip_val);
+    if (res)
+        return res;
+
     clock_valid = dt_property_read_u32(dev, "clock-frequency",
                                        &clock_frequency);
     if ( clock_valid )
@@ -1581,46 +1597,6 @@ static int __init make_gic_domU_node(const struct domain *d, void *fdt)
     }
 }
 
-static int __init make_timer_domU_node(const struct domain *d, void *fdt)
-{
-    int res;
-    gic_interrupt_t intrs[3];
-
-    res = fdt_begin_node(fdt, "timer");
-    if ( res )
-        return res;
-
-    if ( !is_64bit_domain(d) )
-    {
-        res = fdt_property_string(fdt, "compatible", "arm,armv7-timer");
-        if ( res )
-            return res;
-    }
-    else
-    {
-        res = fdt_property_string(fdt, "compatible", "arm,armv8-timer");
-        if ( res )
-            return res;
-    }
-
-    set_interrupt(intrs[0], GUEST_TIMER_PHYS_S_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-    set_interrupt(intrs[1], GUEST_TIMER_PHYS_NS_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-    set_interrupt(intrs[2], GUEST_TIMER_VIRT_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-
-    res = fdt_property(fdt, "interrupts", intrs, sizeof (intrs[0]) * 3);
-    if ( res )
-        return res;
-
-    res = fdt_property_cell(fdt, "interrupt-parent",
-                            GUEST_PHANDLE_GIC);
-    if (res)
-        return res;
-
-    res = fdt_end_node(fdt);
-
-    return res;
-}
-
 #ifdef CONFIG_SBSA_VUART_CONSOLE
 static int __init make_vpl011_uart_node(const struct domain *d, void *fdt)
 {
@@ -1726,7 +1702,7 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)
     if ( ret )
         goto err;
 
-    ret = make_timer_domU_node(d, kinfo->fdt);
+    ret = make_timer_node(d, kinfo->fdt);
     if ( ret )
         goto err;
 
Signature · 7 lines
2.17.1


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

Hi Viktor,

Quoted 3 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. The only difference between Dom0 and DomU timer DT node
is the timer interrupts used. All the rest code should be the same.

This is a bit confusing to read. First you say there are only "one difference" but then the second part leads to think there are more difference.

The commit message should describe what are the differences and which version you are keeping.

Quoted 3 lines

So it is better to merge them to avoid discrepancy.

Tested dom0 boot with rcar h3 sk board.

How about domU support? Also, do you have the clock-frequency property in your DT timer node?

Quoted 12 lines
---
  xen/arch/arm/domain_build.c | 66 ++++++++++++-------------------------
  1 file changed, 21 insertions(+), 45 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index 7fb828cae2..610dd3e8e7 100644

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 979

Quoted 4 lines
xen/arch/arm/domain_build.c +1 -0
@@ -976,6 +976,8 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
      gic_interrupt_t intrs[3];
      u32 clock_frequency;
      bool clock_valid;
+    bool d0 = is_hardware_domain(d);

Please avoid to use the term "d0"/"dom0" whenever it is possible. While in practice the hardware domain is always dom0 on Arm, I want to avoid the mixing.

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 982

Quoted 3 lines
xen/arch/arm/domain_build.c +1 -0
+    uint32_t ip_val;
 
      dt_dprintk("Create timer node\n");

I am not sure where to comment, but the compatible will be different for DomU now. I would actually prefer if we keep the domU version for the compatible as it is simpler.

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 1011

Quoted 9 lines
xen/arch/arm/domain_build.c +3 -1
@@ -1004,22 +1006,36 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
      /* The timer IRQ is emulated by Xen. It always exposes an active-low
       * level-sensitive interrupt */
 
-    irq = timer_get_irq(TIMER_PHYS_SECURE_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_PHYS_SECURE_PPI)
+        : GUEST_TIMER_PHYS_S_PPI;

Rather than using ternary everywhere, how about introducing an array where the value will be stored.

So the code would look like:

if ( is_hardware_domain(...) )
{
timer_irq[...] = ...;
timer_irq[...] = ...;
}
else
{
}

[....]

set_interrupt(timer_irq[...]);

Have a look at time.c as we define handy value (enum timer_ppi and MAX_TIMER_PPI).

Quoted 17 lines
xen/arch/arm/domain_build.c +6 -2
      dt_dprintk("  Secure interrupt %u\n", irq);
      set_interrupt(intrs[0], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_PHYS_NONSECURE_PPI)
+        : GUEST_TIMER_PHYS_NS_PPI;
      dt_dprintk("  Non secure interrupt %u\n", irq);
      set_interrupt(intrs[1], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_get_irq(TIMER_VIRT_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_VIRT_PPI)
+        : GUEST_TIMER_VIRT_PPI;
      dt_dprintk("  Virt interrupt %u\n", irq);
      set_interrupt(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 1035

Quoted 10 lines
xen/arch/arm/domain_build.c +6 -1
-    res = fdt_property_interrupts(fdt, intrs, 3);
+    res = fdt_property(fdt, "interrupts", intrs, sizeof (intrs[0]) * 3);
      if ( res )
          return res;
 
+    ip_val = d0
+           ? dt_interrupt_controller->phandle
+           : GUEST_PHANDLE_GIC;
+
+    res = fdt_property_cell(fdt, "interrupt-parent", ip_val);

I would actually prefer if we extend fdt_property_interrupts to deal with other domain than the hwdom. This would avoid the function.

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 1036

Quoted 1 line
xen/arch/arm/domain_build.c +1 -0
+    if (res)

NIT: Coding style

if ( ... )

Cheers,

Signature · 6 lines
Julien Grall

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

Hi Julien,

Quoted 8 lines · Julien Grall

Hi Viktor,

Quoted 3 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. The only difference between Dom0 and DomU timer DT node
is the timer interrupts used. All the rest code should be the same.

Quoted 6 lines

This is a bit confusing to read. First you say there are only "one difference" but then the second part leads to think there are more difference.

The commit message should describe what are the differences and which version you are keeping.

Ok, will change it in the next version of the patch.

Quoted 5 lines
Quoted 3 lines

So it is better to merge them to avoid discrepancy.

Tested dom0 boot with rcar h3 sk board.

How about domU support? Also, do you have the clock-frequency property in your DT timer node?

Both Dom0 and DomU (dom0less) support has been tested. There are no the clock-frequency property in your DT timer node. Is it possible to test it anyway somehow?

Quoted 8 lines
Quoted 8 lines
---
  xen/arch/arm/domain_build.c | 66 ++++++++++++-------------------------
  1 file changed, 21 insertions(+), 45 deletions(-)
Quoted 12 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 979

Quoted 9 lines
xen/arch/arm/domain_build.c +1 -0
index 7fb828cae2..610dd3e8e7 100644
@@ -976,6 +976,8 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
      gic_interrupt_t intrs[3];
      u32 clock_frequency;
      bool clock_valid;
+    bool d0 = is_hardware_domain(d);

Please avoid to use the term "d0"/"dom0" whenever it is possible. While in practice the hardware domain is always dom0 on Arm, I want to avoid the mixing.

Ok, will use "if ( is_hardware_domain(...) )" approach you mentioned below.

Quoted 7 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 982

Quoted 3 lines
xen/arch/arm/domain_build.c +1 -0
+    uint32_t ip_val;
 
      dt_dprintk("Create timer node\n");

I am not sure where to comment, but the compatible will be different for DomU now. I would actually prefer if we keep the domU version for the compatible as it is simpler.

Ok, let's keep domU version for the compatible.

Quoted 25 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 1011

Quoted 10 lines
xen/arch/arm/domain_build.c +3 -1
@@ -1004,22 +1006,36 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
      /* The timer IRQ is emulated by Xen. It always exposes an active-low
       * level-sensitive interrupt */
 
-    irq = timer_get_irq(TIMER_PHYS_SECURE_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_PHYS_SECURE_PPI)
+        : GUEST_TIMER_PHYS_S_PPI;

Rather than using ternary everywhere, how about introducing an array where the value will be stored.

So the code would look like:

if ( is_hardware_domain(...) )

{
   timer_irq[...] = ...;
   timer_irq[...] = ...;
}

else
{
}

Quoted 5 lines

[....]

set_interrupt(timer_irq[...]);

Have a look at time.c as we define handy value (enum timer_ppi and MAX_TIMER_PPI).

Ok, will use this approach.

Quoted 22 lines
Quoted 22 lines
xen/arch/arm/domain_build.c +7 -3
      dt_dprintk("  Secure interrupt %u\n", irq);
      set_interrupt(intrs[0], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_PHYS_NONSECURE_PPI)
+        : GUEST_TIMER_PHYS_NS_PPI;
      dt_dprintk("  Non secure interrupt %u\n", irq);
      set_interrupt(intrs[1], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_get_irq(TIMER_VIRT_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_VIRT_PPI)
+        : GUEST_TIMER_VIRT_PPI;
      dt_dprintk("  Virt interrupt %u\n", irq);
      set_interrupt(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    res = fdt_property_interrupts(fdt, intrs, 3);
+    res = fdt_property(fdt, "interrupts", intrs, sizeof (intrs[0]) * 3);
      if ( res )
          return res;
 
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 1035

Quoted 5 lines
xen/arch/arm/domain_build.c +5 -0
+    ip_val = d0
+           ? dt_interrupt_controller->phandle
+           : GUEST_PHANDLE_GIC;
+
+    res = fdt_property_cell(fdt, "interrupt-parent", ip_val);

I would actually prefer if we extend fdt_property_interrupts to deal with other domain than the hwdom. This would avoid the function.

Do you mean adding one more parameter, for example interrupt_parent_val?

static int __init fdt_property_interrupts(void *fdt, gic_interrupt_t *intr,
unsigned num_irq, dt_phandle
interrupt_parent_val)

Quoted 6 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 1036

Quoted 2 lines
xen/arch/arm/domain_build.c +1 -0
+    if (res)

NIT: Coding style

if ( ... )

You are right, will fix this NIT as well.

Thanks

Quoted 4 lines

Cheers,

--
Julien Grall

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

#3 lore raw
Quoted 1 line · Viktor Mitin

Hi Julien,

Hi,

Quoted 19 lines · Julien Grall
Quoted 8 lines

Hi Viktor,

Quoted 3 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. The only difference between Dom0 and DomU timer DT node
is the timer interrupts used. All the rest code should be the same.

Quoted 6 lines

This is a bit confusing to read. First you say there are only "one difference" but then the second part leads to think there are more difference.

The commit message should describe what are the differences and which version you are keeping.

Ok, will change it in the next version of the patch.

Quoted 2 lines
Quoted 2 lines

So it is better to merge them to avoid discrepancy.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Tested dom0 boot with rcar h3 sk board.

How about domU support? Also, do you have the clock-frequency property in your DT timer node?

Both Dom0 and DomU (dom0less) support has been tested. There are no the clock-frequency property in your DT timer node. Is it possible to test it anyway somehow?

Yes by adding the property in your device-tree. The value should match the timer frequency read from CNTFREQ to avoid any big issues.

Quoted 98 lines
Quoted 9 lines
Quoted 9 lines
---
   xen/arch/arm/domain_build.c | 66 ++++++++++++-------------------------
   1 file changed, 21 insertions(+), 45 deletions(-)
Quoted 12 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 979

Quoted 9 lines
xen/arch/arm/domain_build.c +1 -0
index 7fb828cae2..610dd3e8e7 100644
@@ -976,6 +976,8 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
       gic_interrupt_t intrs[3];
       u32 clock_frequency;
       bool clock_valid;
+    bool d0 = is_hardware_domain(d);

Please avoid to use the term "d0"/"dom0" whenever it is possible. While in practice the hardware domain is always dom0 on Arm, I want to avoid the mixing.

Ok, will use "if ( is_hardware_domain(...) )" approach you mentioned below.

Quoted 7 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 982

Quoted 3 lines
xen/arch/arm/domain_build.c +1 -0
+    uint32_t ip_val;
 
       dt_dprintk("Create timer node\n");

I am not sure where to comment, but the compatible will be different for DomU now. I would actually prefer if we keep the domU version for the compatible as it is simpler.

Ok, let's keep domU version for the compatible.

Quoted 25 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 1011

Quoted 10 lines
xen/arch/arm/domain_build.c +3 -1
@@ -1004,22 +1006,36 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
       /* The timer IRQ is emulated by Xen. It always exposes an active-low
        * level-sensitive interrupt */
 
-    irq = timer_get_irq(TIMER_PHYS_SECURE_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_PHYS_SECURE_PPI)
+        : GUEST_TIMER_PHYS_S_PPI;

Rather than using ternary everywhere, how about introducing an array where the value will be stored.

So the code would look like:

if ( is_hardware_domain(...) )

{
    timer_irq[...] = ...;
    timer_irq[...] = ...;
}

else
{
}

Quoted 5 lines

[....]

set_interrupt(timer_irq[...]);

Have a look at time.c as we define handy value (enum timer_ppi and MAX_TIMER_PPI).

Ok, will use this approach.

Quoted 22 lines
Quoted 22 lines
xen/arch/arm/domain_build.c +7 -3
       dt_dprintk("  Secure interrupt %u\n", irq);
       set_interrupt(intrs[0], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_PHYS_NONSECURE_PPI)
+        : GUEST_TIMER_PHYS_NS_PPI;
       dt_dprintk("  Non secure interrupt %u\n", irq);
       set_interrupt(intrs[1], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_get_irq(TIMER_VIRT_PPI);
+    irq = d0
+        ? timer_get_irq(TIMER_VIRT_PPI)
+        : GUEST_TIMER_VIRT_PPI;
       dt_dprintk("  Virt interrupt %u\n", irq);
       set_interrupt(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    res = fdt_property_interrupts(fdt, intrs, 3);
+    res = fdt_property(fdt, "interrupts", intrs, sizeof (intrs[0]) * 3);
       if ( res )
           return res;
 
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct domain *d, void *fdt) · line 1035

Quoted 5 lines
xen/arch/arm/domain_build.c +5 -0
+    ip_val = d0
+           ? dt_interrupt_controller->phandle
+           : GUEST_PHANDLE_GIC;
+
+    res = fdt_property_cell(fdt, "interrupt-parent", ip_val);

I would actually prefer if we extend fdt_property_interrupts to deal with other domain than the hwdom. This would avoid the function.

Quoted 6 lines

Do you mean adding one more parameter, for example interrupt_parent_val?

static int __init fdt_property_interrupts(void *fdt, gic_interrupt_t *intr,
unsigned num_irq, dt_phandle
interrupt_parent_val)

I would prefer if you hide out that completely and infer from the domain (or kernel_info). A potential prototype would be:

int fdt_property_interrupts(struct kernel_info *kinfo, gic_interrupt_t *intr);

With the implementation looking like (pseudo-code):
if ( is_hardware_domain(kinfo->d) )

     /* Use host phandle */
   else
     /* Use GUEST_PHANDLE_GIC */

Ideally the prototype change should be done in a separate patch

Cheers,

Signature · 6 lines
Julien Grall

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