diff mbox

[RFC,19/24] xen/arm: Create a fake PSCI node in dom0 device tree

Message ID 1376687156-6737-20-git-send-email-julien.grall@linaro.org
State Superseded, archived
Headers show

Commit Message

Julien Grall Aug. 16, 2013, 9:05 p.m. UTC
Xen uses PSCI to bring up secondary cpus for the guest.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/domain_build.c |   44 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

Comments

Julien Grall Aug. 21, 2013, 1:50 p.m. UTC | #1
On 08/16/2013 10:05 PM, Julien Grall wrote:
> Xen uses PSCI to bring up secondary cpus for the guest.
> 
> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> ---
>  xen/arch/arm/domain_build.c |   44 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 44 insertions(+)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 567b1fe..d8d67a6 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -13,6 +13,7 @@
>  #include <xen/guest_access.h>
>  #include <asm/setup.h>
>  #include <asm/platform.h>
> +#include <asm/psci.h>
>  
>  #include <asm/gic.h>
>  #include <xen/irq.h>
> @@ -283,6 +284,44 @@ static int make_hypervisor_node(void *fdt, const struct dt_device_node *parent)
>      return res;
>  }
>  
> +static int make_psci_node(void *fdt, const struct dt_device_node *parent)
> +{
> +    int res;
> +    __be32 reg[0];

I should have written reg[1];

This code was working by luck.


> +    __be32 *cells;
> +
> +    DPRINT("Create PSCI node\n");
> +
> +    /* See linux Documentation/devicetree/bindings/arm/psci.txt */
> +    res = fdt_begin_node(fdt, "psci");
> +    if ( res )
> +        return res;
> +
> +    res = fdt_property_string(fdt, "compatible", "arm,psci");
> +    if ( res )
> +        return res;
> +
> +    res = fdt_property_string(fdt, "method", "hvc");
> +    if ( res )
> +        return res;
> +
> +    cells = &reg[0];
> +    dt_set_cell(&cells, 1, __PSCI_cpu_off);
> +    res = fdt_property(fdt, "cpu_off", reg, sizeof(reg[0]));
> +    if ( res )
> +        return res;
> +
> +    cells = &reg[0];
> +    dt_set_cell(&cells, 1, __PSCI_cpu_on);
> +    res = fdt_property(fdt, "cpu_on", reg, sizeof(reg[0]));
> +    if ( res )
> +        return res;
> +
> +    res = fdt_end_node(fdt);
> +
> +    return res;
> +}
> +
>  /* Map the device in the domain */
>  static int map_device(struct domain *d, const struct dt_device_node *dev)
>  {
> @@ -367,6 +406,7 @@ static const struct dt_device_match skip_matches[] __initconst =
>  {
>      DT_MATCH_COMPATIBLE("xen,xen"),
>      DT_MATCH_COMPATIBLE("xen,multiboot-module"),
> +    DT_MATCH_COMPATIBLE("arm,psci"),
>      { /* sentinel */ },
>  };
>  
> @@ -412,6 +452,10 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,
>          res = make_hypervisor_node(kinfo->fdt, np);
>          if ( res )
>              return res;
> +
> +        res = make_psci_node(kinfo->fdt, np);
> +        if ( res )
> +            return res;
>      }
>  
>      res = fdt_end_node(kinfo->fdt);
>
diff mbox

Patch

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 567b1fe..d8d67a6 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -13,6 +13,7 @@ 
 #include <xen/guest_access.h>
 #include <asm/setup.h>
 #include <asm/platform.h>
+#include <asm/psci.h>
 
 #include <asm/gic.h>
 #include <xen/irq.h>
@@ -283,6 +284,44 @@  static int make_hypervisor_node(void *fdt, const struct dt_device_node *parent)
     return res;
 }
 
+static int make_psci_node(void *fdt, const struct dt_device_node *parent)
+{
+    int res;
+    __be32 reg[0];
+    __be32 *cells;
+
+    DPRINT("Create PSCI node\n");
+
+    /* See linux Documentation/devicetree/bindings/arm/psci.txt */
+    res = fdt_begin_node(fdt, "psci");
+    if ( res )
+        return res;
+
+    res = fdt_property_string(fdt, "compatible", "arm,psci");
+    if ( res )
+        return res;
+
+    res = fdt_property_string(fdt, "method", "hvc");
+    if ( res )
+        return res;
+
+    cells = &reg[0];
+    dt_set_cell(&cells, 1, __PSCI_cpu_off);
+    res = fdt_property(fdt, "cpu_off", reg, sizeof(reg[0]));
+    if ( res )
+        return res;
+
+    cells = &reg[0];
+    dt_set_cell(&cells, 1, __PSCI_cpu_on);
+    res = fdt_property(fdt, "cpu_on", reg, sizeof(reg[0]));
+    if ( res )
+        return res;
+
+    res = fdt_end_node(fdt);
+
+    return res;
+}
+
 /* Map the device in the domain */
 static int map_device(struct domain *d, const struct dt_device_node *dev)
 {
@@ -367,6 +406,7 @@  static const struct dt_device_match skip_matches[] __initconst =
 {
     DT_MATCH_COMPATIBLE("xen,xen"),
     DT_MATCH_COMPATIBLE("xen,multiboot-module"),
+    DT_MATCH_COMPATIBLE("arm,psci"),
     { /* sentinel */ },
 };
 
@@ -412,6 +452,10 @@  static int handle_node(struct domain *d, struct kernel_info *kinfo,
         res = make_hypervisor_node(kinfo->fdt, np);
         if ( res )
             return res;
+
+        res = make_psci_node(kinfo->fdt, np);
+        if ( res )
+            return res;
     }
 
     res = fdt_end_node(kinfo->fdt);