Skip to contentSkip to conversation

xen: arm: parse modules from DT during early boot.

PATCH Superseded Ian Campbell 3 participants 17 messages Jan 30, 2013 – Feb 18, 2013

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover xen: arm: parse modules from DT during early boot.

Most of the early part of this series went in with V5 and only the PoC DTB based "protocol" remains.

Main change is that the match on /chosen/modules is now done based on compatible == "xen,multiboot-module" rather than by the path (Stefano's request).

I had to fix device_tree_for_each_node to handle #*-cells properly, this is at the start of the series.

I have also added a patch which makes the hypervisor insert the /hypervisor/ node automatically (and drop anything which is there already). This is a (small) step along the path of being able to use the unmodified DTS for the platform. I reckon the main remaining thing in this area is to automatically update /cpus/ based on dom0_vcpus=X (we already handle RAM).

Ian.

#1 lore raw

PATCH v6 1/4 dtb: correct handling of #address-cells and #size-cells.

If a node does not have #*-cells then the parent's value should be used. Currently we were asssuming zero which is useless.

---
 xen/arch/arm/domain_build.c   |    6 ++++--
 xen/common/device_tree.c      |   12 ++++++++----
 xen/include/xen/device_tree.h |    3 ++-
 3 files changed, 14 insertions(+), 7 deletions(-)
xen/arch/arm/domain_build.c +4 -2
index 7403f1a..bfbe7c7 100644
@@ -198,8 +198,10 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
         while ( last_depth-- >= depth )
             fdt_end_node(kinfo->fdt);
 
-        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells");
-        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells");
+        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells",
+                                    depth > 0 ? address_cells[depth-1] : 0);
+        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells",
+                                    depth > 0 ? size_cells[depth-1] : 0);
 
         fdt_begin_node(kinfo->fdt, name);
 
xen/common/device_tree.c +8 -4
index 260c2d4..f10ba1b 100644
@@ -120,13 +120,14 @@ void device_tree_set_reg(u32 **cell, u32 address_cells, u32 size_cells,
     set_val(cell, size_cells, size);
 }
 
-u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name)
+u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name,
+                        u32 dflt)
 {
     const struct fdt_property *prop;
 
     prop = fdt_get_property(fdt, node, prop_name, NULL);
     if ( !prop || prop->len < sizeof(u32) )
-        return 0; /* default to 0 */
+        return dflt;
 
     return fdt32_to_cpu(*(uint32_t*)prop->data);
 }
@@ -164,8 +165,11 @@ int device_tree_for_each_node(const void *fdt,
             continue;
         }
 
-        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells");
-        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells");
+        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells",
+                                depth > 0 ? address_cells[depth-1] : 0);
+        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells",
+                                depth > 0 ? size_cells[depth-1] : 0);
+
 
         ret = func(fdt, node, name, depth,
                    address_cells[depth-1], size_cells[depth-1], data);
xen/include/xen/device_tree.h +2 -1
index 52ef258..a8df493 100644
@@ -66,7 +66,8 @@ void device_tree_get_reg(const u32 **cell, u32 address_cells, u32 size_cells,
                          u64 *start, u64 *size);
 void device_tree_set_reg(u32 **cell, u32 address_cells, u32 size_cells,
                          u64 start, u64 size);
-u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name);
+u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name,
+			u32 dflt);
 bool_t device_tree_node_matches(const void *fdt, int node, const char *match);
 int device_tree_for_each_node(const void *fdt,
                               device_tree_node_func func, void *data);
Signature · 1 line
1.7.9.1
#2 lore raw

Re: [PATCH 1/4] dtb: correct handling of #address-cells and #size-cells.

Quoted 16 lines · Ian Campbell

If a node does not have #*-cells then the parent's value should be used. Currently we were asssuming zero which is useless.

---
 xen/arch/arm/domain_build.c   |    6 ++++--
 xen/common/device_tree.c      |   12 ++++++++----
 xen/include/xen/device_tree.h |    3 ++-
 3 files changed, 14 insertions(+), 7 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index 7403f1a..bfbe7c7 100644
@@ -198,8 +198,10 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
         while ( last_depth-- >= depth )

xen/arch/arm/domain_build.c static int write_nodes(struct domain *d, struct kernel_info *kinfo, · line 206

Quoted 10 lines
xen/arch/arm/domain_build.c +4 -2
             fdt_end_node(kinfo->fdt);
 
-        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells");
-        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells");
+        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells",
+                                    depth > 0 ? address_cells[depth-1] : 0);
+        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells",
+                                    depth > 0 ? size_cells[depth-1] : 0);
 
         fdt_begin_node(kinfo->fdt, name);

The depth is always increasing by steps of 1 in this loop, right? Because retrieving address-cells and size-cells should be recursive: if n-1 doesn't have them, let's look at n-2, etc. Of course if we start from depth = 0 and go from there without missing any levels the results will be the same.

I think I convinced myself that this is correct.

Quoted 11 lines
xen/common/device_tree.c +2 -1
index 260c2d4..f10ba1b 100644
@@ -120,13 +120,14 @@ void device_tree_set_reg(u32 **cell, u32 address_cells, u32 size_cells,
     set_val(cell, size_cells, size);
 }
 
-u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name)
+u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name,
+                        u32 dflt)

xen/common/device_tree.c void device_tree_set_reg(u32 **cell, u32 address_cells, u32 size_cells, · line 133

Quoted 10 lines
xen/common/device_tree.c +1 -1
 {
     const struct fdt_property *prop;
 
     prop = fdt_get_property(fdt, node, prop_name, NULL);
     if ( !prop || prop->len < sizeof(u32) )
-        return 0; /* default to 0 */
+        return dflt;
 
     return fdt32_to_cpu(*(uint32_t*)prop->data);
 }

where did the vowels go? :)

#3 lore raw

Re: [PATCH 1/4] dtb: correct handling of #address-cells and #size-cells.

Quoted 26 lines · Stefano Stabellini
Quoted 25 lines · Ian Campbell

If a node does not have #*-cells then the parent's value should be used. Currently we were asssuming zero which is useless.

---
 xen/arch/arm/domain_build.c   |    6 ++++--
 xen/common/device_tree.c      |   12 ++++++++----
 xen/include/xen/device_tree.h |    3 ++-
 3 files changed, 14 insertions(+), 7 deletions(-)
xen/arch/arm/domain_build.c +4 -2
index 7403f1a..bfbe7c7 100644
@@ -198,8 +198,10 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
         while ( last_depth-- >= depth )
             fdt_end_node(kinfo->fdt);
 
-        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells");
-        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells");
+        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells",
+                                    depth > 0 ? address_cells[depth-1] : 0);
+        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells",
+                                    depth > 0 ? size_cells[depth-1] : 0);
 
Quoted 7 lines

xen/arch/arm/domain_build.c static int write_nodes(struct domain *d, struct kernel_info *kinfo, · line 206

Quoted 1 line
xen/arch/arm/domain_build.c +0 -0
         fdt_begin_node(kinfo->fdt, name);

The depth is always increasing by steps of 1 in this loop, right? Because retrieving address-cells and size-cells should be recursive: if n-1 doesn't have them, let's look at n-2, etc. Of course if we start from depth = 0 and go from there without missing any levels the results will be the same.

That was what I thought too. Perhaps it is too subtle?

I bet my "xen: strip xen,multiboot-module nodes from dom0 device tree" patch changes this invariant. Better to make it explicitly walk backwards now I think. (or maybe set things for level in last_depth..depth). I'll change things along these lines.

Quoted 22 lines

I think I convinced myself that this is correct.

Quoted 19 lines
xen/common/device_tree.c +3 -2
index 260c2d4..f10ba1b 100644
@@ -120,13 +120,14 @@ void device_tree_set_reg(u32 **cell, u32 address_cells, u32 size_cells,
     set_val(cell, size_cells, size);
 }
 
-u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name)
+u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name,
+                        u32 dflt)
 {
     const struct fdt_property *prop;
 
     prop = fdt_get_property(fdt, node, prop_name, NULL);
     if ( !prop || prop->len < sizeof(u32) )
-        return 0; /* default to 0 */
+        return dflt;
 
Quoted 4 lines

xen/common/device_tree.c void device_tree_set_reg(u32 **cell, u32 address_cells, u32 size_cells, · line 133

Quoted 2 lines
xen/common/device_tree.c +0 -0
     return fdt32_to_cpu(*(uint32_t*)prop->data);
 }

where did the vowels go? :)

Not sure. Unlike me ;-)

Ian.

#4 lore raw

Re: [PATCH 1/4] dtb: correct handling of #address-cells and #size-cells.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
xen/common/device_tree.c +3 -2
-u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name)
+u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name,
+                        u32 dflt)
 {
     const struct fdt_property *prop;
 
     prop = fdt_get_property(fdt, node, prop_name, NULL);
     if ( !prop || prop->len < sizeof(u32) )
-        return 0; /* default to 0 */
+        return dflt;
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
     return fdt32_to_cpu(*(uint32_t*)prop->data);

}

where did the vowels go? :)

Not sure. Unlike me ;-)

I remembered when I went to change it, default is a C keyword...

Ian.

#5 lore raw

Re: [PATCH 1/4] dtb: correct handling of #address-cells and #size-cells.

Quoted 11 lines · Ian Campbell
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
xen/common/device_tree.c +3 -2
-u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name)
+u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name,
+                        u32 dflt)
 {
     const struct fdt_property *prop;
 
     prop = fdt_get_property(fdt, node, prop_name, NULL);
     if ( !prop || prop->len < sizeof(u32) )
-        return 0; /* default to 0 */
+        return dflt;
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
     return fdt32_to_cpu(*(uint32_t*)prop->data);

}

where did the vowels go? :)

Not sure. Unlike me ;-)

I remembered when I went to change it, default is a C keyword...

I would have gone for _default, but I am OK with this too.

#6 lore raw

Re: [PATCH 1/4] dtb: correct handling of #address-cells and #size-cells.

Quoted 17 lines · Stefano Stabellini
Quoted 16 lines · Ian Campbell
Quoted 16 lines
Quoted 15 lines

xen/common/device_tree.c void device_tree_set_reg(u32 **cell, u32 address_cells, u32 size_cells, · line 133

Quoted 13 lines
xen/common/device_tree.c +3 -2
-u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name)
+u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name,
+                        u32 dflt)
 {
     const struct fdt_property *prop;
 
     prop = fdt_get_property(fdt, node, prop_name, NULL);
     if ( !prop || prop->len < sizeof(u32) )
-        return 0; /* default to 0 */
+        return dflt;
 
     return fdt32_to_cpu(*(uint32_t*)prop->data);
 }

where did the vowels go? :)

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Not sure. Unlike me ;-)

I remembered when I went to change it, default is a C keyword...

I would have gone for _default, but I am OK with this too.

Technically _default is reserved for the implementation (compiler or system libraries, I forget which).

Ian.

#7 lore raw

Re: [PATCH 1/4] dtb: correct handling of #address-cells and #size-cells.

In reply to Ian Campbell
Quoted 35 lines · Ian Campbell
Quoted 26 lines · Stefano Stabellini
Quoted 25 lines · Ian Campbell

If a node does not have #*-cells then the parent's value should be used. Currently we were asssuming zero which is useless.

---
 xen/arch/arm/domain_build.c   |    6 ++++--
 xen/common/device_tree.c      |   12 ++++++++----
 xen/include/xen/device_tree.h |    3 ++-
 3 files changed, 14 insertions(+), 7 deletions(-)
xen/arch/arm/domain_build.c +4 -2
index 7403f1a..bfbe7c7 100644
@@ -198,8 +198,10 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
         while ( last_depth-- >= depth )
             fdt_end_node(kinfo->fdt);
 
-        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells");
-        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells");
+        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells",
+                                    depth > 0 ? address_cells[depth-1] : 0);
+        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells",
+                                    depth > 0 ? size_cells[depth-1] : 0);
 
Quoted 7 lines

xen/arch/arm/domain_build.c static int write_nodes(struct domain *d, struct kernel_info *kinfo, · line 206

Quoted 1 line
xen/arch/arm/domain_build.c +0 -0
         fdt_begin_node(kinfo->fdt, name);

The depth is always increasing by steps of 1 in this loop, right? Because retrieving address-cells and size-cells should be recursive: if n-1 doesn't have them, let's look at n-2, etc. Of course if we start from depth = 0 and go from there without missing any levels the results will be the same.

Quoted 6 lines

That was what I thought too. Perhaps it is too subtle?

I bet my "xen: strip xen,multiboot-module nodes from dom0 device tree" patch changes this invariant. Better to make it explicitly walk backwards now I think. (or maybe set things for level in last_depth..depth). I'll change things along these lines.

I looked into this and even with that patch the invariant that we cannot skip levels is present. This turns out to be obviously the case because you have actually open the node and name it... I'll add an ASSERT here though just in case.

Ian.

#8 lore raw

PATCH v6 2/4 xen: arm: parse modules from DT during early boot.

In reply to Ian Campbell

The bootloader should populate /chosen/modules/module@<N>/ for each module it wishes to pass to the hypervisor. The content of these nodes is described in docs/misc/arm/device-tree/booting.txt

---
v6: Match based on compatibility instead of path
v5: Moved later in the series
v4: Use /chosen/modules/module@N
Identify module type by compatible property not number.
v3: Use a reg = < > property for the module address/length.
v2: Reserve the zeroeth module for Xen itself (not used yet)
Use a more idiomatic DT layout
Document said layout

---
 docs/misc/arm/device-tree/booting.txt |   25 +++++++++++++++
 xen/common/device_tree.c              |   54 ++++++++++++++++++++++++++++++++-
 2 files changed, 78 insertions(+), 1 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/booting.txt
docs/misc/arm/device-tree/booting.txt new file +25 -0
new file mode 100644
index 0000000..94cd3f1
@@ -0,0 +1,25 @@
+Xen is passed the dom0 kernel and initrd via a reference in the /chosen
+node of the device tree.
+
+Each node has the form /chosen/modules/module@<N> and contains the following
+properties:
+
+- compatible
+
+	Must be:
+
+		"xen,<type>", "xen,multiboot-module"
+
+	where <type> must be one of:
+
+	- "linux-zimage" -- the dom0 kernel
+	- "linux-initrd" -- the dom0 ramdisk
+
+- reg
+
+	Specifies the physical address of the module in RAM and the
+	length of the module.
+
+- bootargs (optional)
+
+	Command line associated with this module
xen/common/device_tree.c +53 -1

77 lines not on this page · raw message

Signature · 1 line
1.7.9.1
Acked-by on v6 2/4
#9 lore raw
Quoted 5 lines · Ian Campbell

The bootloader should populate /chosen/modules/module@<N>/ for each module it wishes to pass to the hypervisor. The content of these nodes is described in docs/misc/arm/device-tree/booting.txt

Quoted 9 lines

---
v6: Match based on compatibility instead of path
v5: Moved later in the series
v4: Use /chosen/modules/module@N
Identify module type by compatible property not number.
v3: Use a reg = < > property for the module address/length.
v2: Reserve the zeroeth module for Xen itself (not used yet)
Use a more idiomatic DT layout
Document said layout

Quoted 123 lines
 docs/misc/arm/device-tree/booting.txt |   25 +++++++++++++++
 xen/common/device_tree.c              |   54 ++++++++++++++++++++++++++++++++-
 2 files changed, 78 insertions(+), 1 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/booting.txt
docs/misc/arm/device-tree/booting.txt new file +25 -0
new file mode 100644
index 0000000..94cd3f1
@@ -0,0 +1,25 @@
+Xen is passed the dom0 kernel and initrd via a reference in the /chosen
+node of the device tree.
+
+Each node has the form /chosen/modules/module@<N> and contains the following
+properties:
+
+- compatible
+
+	Must be:
+
+		"xen,<type>", "xen,multiboot-module"
+
+	where <type> must be one of:
+
+	- "linux-zimage" -- the dom0 kernel
+	- "linux-initrd" -- the dom0 ramdisk
+
+- reg
+
+	Specifies the physical address of the module in RAM and the
+	length of the module.
+
+- bootargs (optional)
+
+	Command line associated with this module
xen/common/device_tree.c +53 -1
index f10ba1b..c92f8ca 100644
@@ -341,6 +341,48 @@ static void __init process_gic_node(const void *fdt, int node,
     early_info.gic.gic_vcpu_addr = start;
 }
 
+static void __init process_multiboot_node(const void *fdt, int node,
+                                          const char *name,
+                                          u32 address_cells, u32 size_cells)
+{
+    const struct fdt_property *prop;
+    const u32 *cell;
+    int nr;
+    struct dt_mb_module *mod;
+    int len;
+
+    if ( fdt_node_check_compatible(fdt, node, "xen,linux-zimage") == 0 )
+        nr = 1;
+    else if ( fdt_node_check_compatible(fdt, node, "xen,linux-initrd") == 0)
+        nr = 2;
+    else
+        early_panic("%s not a known xen multiboot type\n", name);
+
+    mod = &early_info.modules.module[nr];
+
+    prop = fdt_get_property(fdt, node, "reg", NULL);
+    if ( !prop )
+        early_panic("node %s missing `reg' property\n", name);
+
+    cell = (const u32 *)prop->data;
+    device_tree_get_reg(&cell, address_cells, size_cells,
+                        &mod->start, &mod->size);
+
+    prop = fdt_get_property(fdt, node, "bootargs", &len);
+    if ( prop )
+    {
+        if ( len > sizeof(mod->cmdline) )
+            early_panic("module %d command line too long\n", nr);
+
+        safe_strcpy(mod->cmdline, prop->data);
+    }
+    else
+        mod->cmdline[0] = 0;
+
+    if ( nr > early_info.modules.nr_mods )
+        early_info.modules.nr_mods = nr;
+}
+
 static int __init early_scan_node(const void *fdt,
                                   int node, const char *name, int depth,
                                   u32 address_cells, u32 size_cells,
@@ -352,6 +394,8 @@ static int __init early_scan_node(const void *fdt,
         process_cpu_node(fdt, node, name, address_cells, size_cells);
     else if ( device_tree_node_compatible(fdt, node, "arm,cortex-a15-gic") )
         process_gic_node(fdt, node, name, address_cells, size_cells);
+    else if ( device_tree_node_compatible(fdt, node, "xen,multiboot-module" ) )
+        process_multiboot_node(fdt, node, name, address_cells, size_cells);
 
     return 0;
 }
@@ -359,12 +403,20 @@ static int __init early_scan_node(const void *fdt,
 static void __init early_print_info(void)
 {
     struct dt_mem_info *mi = &early_info.mem;
+    struct dt_module_info *mods = &early_info.modules;
     int i;
 
     for ( i = 0; i < mi->nr_banks; i++ )
-        early_printk("RAM: %016llx - %016llx\n",
+        early_printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n",
                      mi->bank[i].start,
                      mi->bank[i].start + mi->bank[i].size - 1);
+    early_printk("\n");
+    for ( i = 1 ; i < mods->nr_mods + 1; i++ )
+        early_printk("MODULE[%d]: %"PRIpaddr" - %"PRIpaddr" %s\n",
+                     i,
+                     mods->module[i].start,
+                     mods->module[i].start + mods->module[i].size,
+                     mods->module[i].cmdline);
 }
 
 /**
Signature · 1 line
1.7.9.1
#10 lore raw

PATCH v6 3/4 xen: strip xen, multiboot-module nodes from dom0 device tree

In reply to Ian Campbell

These nodes are used by Xen to find the initial modules.

---
v6 - filter based on compatibility node name and not path. v4 - /chosen/modules/modules@N not /chosen/module@N
v3 - use a helper to filter out DT elements which are not for dom0.
Better than an ad-hoc break in the middle of a loop.

---
 xen/arch/arm/domain_build.c |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +30 -2
index bfbe7c7..bb10096 100644
@@ -172,6 +172,33 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo,
     return prop;
 }
 
+/* Returns the next node in fdt (starting from offset) which should be
+ * passed through to dom0.
+ */
+static int fdt_next_dom0_node(const void *fdt, int node,
+                              int *depth_out)
+{
+    int depth = *depth_out;
+
+    while ( (node = fdt_next_node(fdt, node, &depth)) &&
+            node >= 0 && depth >= 0 )
+    {
+        if ( depth >= DEVICE_TREE_MAX_DEPTH )
+            break;
+
+        /* Skip multiboot subnodes */
+        if ( fdt_node_check_compatible(fdt, node,
+                                       "xen,multiboot-module" ) == 0 )
+            continue;
+
+        /* We've arrived at a node which dom0 is interested in. */
+        break;
+    }
+
+    *depth_out = depth;
+    return node;
+}
+
 static int write_nodes(struct domain *d, struct kernel_info *kinfo,
                        const void *fdt)
 {
@@ -183,7 +210,7 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
 
     for ( node = 0, depth = 0;
           node >= 0 && depth >= 0;
-          node = fdt_next_node(fdt, node, &depth) )
+          node = fdt_next_dom0_node(fdt, node, &depth) )
     {
         const char *name;
 
@@ -191,7 +218,8 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
 
         if ( depth >= DEVICE_TREE_MAX_DEPTH )
         {
-            printk("warning: node `%s' is nested too deep\n", name);
+            printk("warning: node `%s' is nested too deep (%d)\n",
+                   name, depth);
             continue;
         }
 
Signature · 1 line
1.7.9.1
Acked-by on v6 3/4
#11 lore raw

Re: [PATCH 3/4] xen: strip xen, multiboot-module nodes from dom0 device tree

Quoted 3 lines · Ian Campbell

These nodes are used by Xen to find the initial modules.

Quoted 68 lines

v6 - filter based on compatibility node name and not path. v4 - /chosen/modules/modules@N not /chosen/module@N
v3 - use a helper to filter out DT elements which are not for dom0.
Better than an ad-hoc break in the middle of a loop.

---
 xen/arch/arm/domain_build.c |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +30 -2
index bfbe7c7..bb10096 100644
@@ -172,6 +172,33 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo,
     return prop;
 }
 
+/* Returns the next node in fdt (starting from offset) which should be
+ * passed through to dom0.
+ */
+static int fdt_next_dom0_node(const void *fdt, int node,
+                              int *depth_out)
+{
+    int depth = *depth_out;
+
+    while ( (node = fdt_next_node(fdt, node, &depth)) &&
+            node >= 0 && depth >= 0 )
+    {
+        if ( depth >= DEVICE_TREE_MAX_DEPTH )
+            break;
+
+        /* Skip multiboot subnodes */
+        if ( fdt_node_check_compatible(fdt, node,
+                                       "xen,multiboot-module" ) == 0 )
+            continue;
+
+        /* We've arrived at a node which dom0 is interested in. */
+        break;
+    }
+
+    *depth_out = depth;
+    return node;
+}
+
 static int write_nodes(struct domain *d, struct kernel_info *kinfo,
                        const void *fdt)
 {
@@ -183,7 +210,7 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
 
     for ( node = 0, depth = 0;
           node >= 0 && depth >= 0;
-          node = fdt_next_node(fdt, node, &depth) )
+          node = fdt_next_dom0_node(fdt, node, &depth) )
     {
         const char *name;
 
@@ -191,7 +218,8 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
 
         if ( depth >= DEVICE_TREE_MAX_DEPTH )
         {
-            printk("warning: node `%s' is nested too deep\n", name);
+            printk("warning: node `%s' is nested too deep (%d)\n",
+                   name, depth);
             continue;
         }
 
Signature · 1 line
1.7.9.1
#12 lore raw

PATCH v6 4/4 xen: arm: create dom0 DTB /hypervisor/ node dynamically.

In reply to Ian Campbell

I initially added hypervisor-new and confirmed via /proc/device-model that the content is the same before changing it to drop and replace an existing node.

NB: There is an ambiguity in the compatibility property. linux/arch/arm/boot/dts/xenvm-4.2.dts says "xen,xen-4.2" while Documentation/devicetree/bindings/arm/xen.txt says "xen,xen-4.3". I don't know which is correct but I've erred on the side of the DTS.

---
 xen/arch/arm/domain_build.c |   53 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +51 -2
index bb10096..d3ef180 100644
@@ -34,7 +34,7 @@ custom_param("dom0_mem", parse_dom0_mem);
  * are added (yet) but one terminating reserve map entry (16 bytes) is
  * added.
  */
-#define DOM0_FDT_EXTRA_SIZE (sizeof(struct fdt_reserve_entry))
+#define DOM0_FDT_EXTRA_SIZE (128 + sizeof(struct fdt_reserve_entry))
 
 struct vcpu *__init alloc_dom0_vcpu0(void)
 {
@@ -186,6 +186,13 @@ static int fdt_next_dom0_node(const void *fdt, int node,
         if ( depth >= DEVICE_TREE_MAX_DEPTH )
             break;
 
+        /* Skip /hypervisor/ node. We will inject our own. */
+        if ( fdt_node_check_compatible(fdt, node, "xen,xen" ) == 0 )
+        {
+            printk("Device-tree contains \"xen,xen\" node. Ignoring.\n");
+            continue;
+        }
+
         /* Skip multiboot subnodes */
         if ( fdt_node_check_compatible(fdt, node,
                                        "xen,multiboot-module" ) == 0 )
@@ -199,6 +206,45 @@ static int fdt_next_dom0_node(const void *fdt, int node,
     return node;
 }
 
+static void make_hypervisor_node(void *fdt, int addrcells, int sizecells)
+{
+    const char compat[] = "xen,xen-4.2\0xen,xen";
+    u32 reg[4];
+    u32 intr[3];
+    u32 *cell;
+
+    /*
+     * Sanity-check address sizes, since addresses and sizes which do not take
+     * up exactly 4 or 8 bytes are not supported.
+     */
+    if ((addrcells != 1 && addrcells != 2) ||
+        (sizecells != 1 && sizecells != 2))
+        panic("Cannot cope with this size");
+
+    /* See linux Documentation/devicetree/bindings/arm/xen.txt */
+    fdt_begin_node(fdt, "hypervisor");
+
+    fdt_property(fdt, "compatible", compat, sizeof(compat) + 1);
+
+    /* reg 0 is grant table space */
+    cell = &reg[0];
+    device_tree_set_reg(&cell, addrcells, sizecells, 0xb0000000, 0x20000);
+    fdt_property(fdt, "reg", reg,
+                 sizeof(reg[0]) * (addrcells + sizecells));
+
+    /*
+     * interrupts is evtchn upcall  <1 15 0xf08>
+     * See linux Documentation/devicetree/bindings/arm/gic.txt
+     */
+    intr[0] = cpu_to_fdt32(1); /* is a PPI */
+    intr[1] = cpu_to_fdt32(VGIC_IRQ_EVTCHN_CALLBACK - 16); /* PPIs start at 16 */
+    intr[2] = cpu_to_fdt32(0xf08); /* Active-low level-sensitive */
+
+    fdt_property(fdt, "interrupts", intr, sizeof(intr[0]) * 3);
+
+    fdt_end_node(fdt);
+}
+
 static int write_nodes(struct domain *d, struct kernel_info *kinfo,
                        const void *fdt)
 {
@@ -241,9 +287,12 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
         last_depth = depth;
     }
 
-    while ( last_depth-- >= 0 )
+    while ( last_depth-- >= 1 )
         fdt_end_node(kinfo->fdt);
 
+    make_hypervisor_node(kinfo->fdt, address_cells[0], size_cells[0]);
+
+    fdt_end_node(kinfo->fdt);
     return 0;
 }
 
Signature · 1 line
1.7.9.1
#13 lore raw

Re: [PATCH 4/4] xen: arm: create dom0 DTB /hypervisor/ node dynamically.

Quoted 49 lines · Ian Campbell

I initially added hypervisor-new and confirmed via /proc/device-model that the content is the same before changing it to drop and replace an existing node.

NB: There is an ambiguity in the compatibility property. linux/arch/arm/boot/dts/xenvm-4.2.dts says "xen,xen-4.2" while Documentation/devicetree/bindings/arm/xen.txt says "xen,xen-4.3". I don't know which is correct but I've erred on the side of the DTS.

---
 xen/arch/arm/domain_build.c |   53 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +12 -1
index bb10096..d3ef180 100644
@@ -34,7 +34,7 @@ custom_param("dom0_mem", parse_dom0_mem);
  * are added (yet) but one terminating reserve map entry (16 bytes) is
  * added.
  */
-#define DOM0_FDT_EXTRA_SIZE (sizeof(struct fdt_reserve_entry))
+#define DOM0_FDT_EXTRA_SIZE (128 + sizeof(struct fdt_reserve_entry))
 
 struct vcpu *__init alloc_dom0_vcpu0(void)
 {
@@ -186,6 +186,13 @@ static int fdt_next_dom0_node(const void *fdt, int node,
         if ( depth >= DEVICE_TREE_MAX_DEPTH )
             break;
 
+        /* Skip /hypervisor/ node. We will inject our own. */
+        if ( fdt_node_check_compatible(fdt, node, "xen,xen" ) == 0 )
+        {
+            printk("Device-tree contains \"xen,xen\" node. Ignoring.\n");
+            continue;
+        }
+
         /* Skip multiboot subnodes */
         if ( fdt_node_check_compatible(fdt, node,
                                        "xen,multiboot-module" ) == 0 )
@@ -199,6 +206,45 @@ static int fdt_next_dom0_node(const void *fdt, int node,
     return node;
 }
 
+static void make_hypervisor_node(void *fdt, int addrcells, int sizecells)
+{
+    const char compat[] = "xen,xen-4.2\0xen,xen";
+    u32 reg[4];

xen/arch/arm/domain_build.c static int fdt_next_dom0_node(const void *fdt, int node, · line 222

Quoted 10 lines
xen/arch/arm/domain_build.c +10 -0
+    u32 intr[3];
+    u32 *cell;
+
+    /*
+     * Sanity-check address sizes, since addresses and sizes which do not take
+     * up exactly 4 or 8 bytes are not supported.
+     */
+    if ((addrcells != 1 && addrcells != 2) ||
+        (sizecells != 1 && sizecells != 2))
+        panic("Cannot cope with this size");

You could add those two properties in the hypervisor node if they don't match what we expect them to be. This would avoid panicking with a device tree that have different default values.

Signature · 1 line
Anthony PERARD
#14 lore raw

Re: [PATCH 4/4] xen: arm: create dom0 DTB /hypervisor/ node dynamically.

Quoted 10 lines · Anthony PERARD
Quoted 10 lines
xen/arch/arm/domain_build.c +10 -0
+static void make_hypervisor_node(void *fdt, int addrcells, int sizecells)
+{
+    const char compat[] = "xen,xen-4.2\0xen,xen";
+    u32 reg[4];
+    u32 intr[3];
+    u32 *cell;
+
+    /*
+     * Sanity-check address sizes, since addresses and sizes which do not take
+     * up exactly 4 or 8 bytes are not supported.
Quoted 8 lines

xen/arch/arm/domain_build.c static int fdt_next_dom0_node(const void *fdt, int node, · line 222

Quoted 4 lines
xen/arch/arm/domain_build.c +4 -0
+     */
+    if ((addrcells != 1 && addrcells != 2) ||
+        (sizecells != 1 && sizecells != 2))
+        panic("Cannot cope with this size");

You could add those two properties in the hypervisor node if they don't match what we expect them to be. This would avoid panicking with a device tree that have different default values.

Yes, I suppose that ought to work.

Ian.

#15 lore raw

Re: [PATCH 4/4] xen: arm: create dom0 DTB /hypervisor/ node dynamically.

In reply to Anthony PERARD
Quoted 11 lines · Anthony PERARD

xen/arch/arm/domain_build.c static int fdt_next_dom0_node(const void *fdt, int node, · line 222

Quoted 7 lines
xen/arch/arm/domain_build.c +7 -0
+    /*
+     * Sanity-check address sizes, since addresses and sizes which do not take
+     * up exactly 4 or 8 bytes are not supported.
+     */
+    if ((addrcells != 1 && addrcells != 2) ||
+        (sizecells != 1 && sizecells != 2))
+        panic("Cannot cope with this size");

You could add those two properties in the hypervisor node if they don't match what we expect them to be. This would avoid panicking with a device tree that have different default values.

Unfortunately the #address-cells nodes etc affect only the children of the current node. The sizes for this node are controlled by the parent's sizes.

In practice #address-cells more than 2 (i.e. using 16 or more bytes) seem like they are going to be rather rare.

Ian.

Acked-by on v6 4/4
#16 lore raw

Re: [PATCH 4/4] xen: arm: create dom0 DTB /hypervisor/ node dynamically.

In reply to Ian Campbell
Quoted 10 lines · Ian Campbell

I initially added hypervisor-new and confirmed via /proc/device-model that the content is the same before changing it to drop and replace an existing node.

NB: There is an ambiguity in the compatibility property. linux/arch/arm/boot/dts/xenvm-4.2.dts says "xen,xen-4.2" while Documentation/devicetree/bindings/arm/xen.txt says "xen,xen-4.3". I don't know which is correct but I've erred on the side of the DTS.

Quoted 93 lines
 xen/arch/arm/domain_build.c |   53 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +51 -2
index bb10096..d3ef180 100644
@@ -34,7 +34,7 @@ custom_param("dom0_mem", parse_dom0_mem);
  * are added (yet) but one terminating reserve map entry (16 bytes) is
  * added.
  */
-#define DOM0_FDT_EXTRA_SIZE (sizeof(struct fdt_reserve_entry))
+#define DOM0_FDT_EXTRA_SIZE (128 + sizeof(struct fdt_reserve_entry))
 
 struct vcpu *__init alloc_dom0_vcpu0(void)
 {
@@ -186,6 +186,13 @@ static int fdt_next_dom0_node(const void *fdt, int node,
         if ( depth >= DEVICE_TREE_MAX_DEPTH )
             break;
 
+        /* Skip /hypervisor/ node. We will inject our own. */
+        if ( fdt_node_check_compatible(fdt, node, "xen,xen" ) == 0 )
+        {
+            printk("Device-tree contains \"xen,xen\" node. Ignoring.\n");
+            continue;
+        }
+
         /* Skip multiboot subnodes */
         if ( fdt_node_check_compatible(fdt, node,
                                        "xen,multiboot-module" ) == 0 )
@@ -199,6 +206,45 @@ static int fdt_next_dom0_node(const void *fdt, int node,
     return node;
 }
 
+static void make_hypervisor_node(void *fdt, int addrcells, int sizecells)
+{
+    const char compat[] = "xen,xen-4.2\0xen,xen";
+    u32 reg[4];
+    u32 intr[3];
+    u32 *cell;
+
+    /*
+     * Sanity-check address sizes, since addresses and sizes which do not take
+     * up exactly 4 or 8 bytes are not supported.
+     */
+    if ((addrcells != 1 && addrcells != 2) ||
+        (sizecells != 1 && sizecells != 2))
+        panic("Cannot cope with this size");
+
+    /* See linux Documentation/devicetree/bindings/arm/xen.txt */
+    fdt_begin_node(fdt, "hypervisor");
+
+    fdt_property(fdt, "compatible", compat, sizeof(compat) + 1);
+
+    /* reg 0 is grant table space */
+    cell = &reg[0];
+    device_tree_set_reg(&cell, addrcells, sizecells, 0xb0000000, 0x20000);
+    fdt_property(fdt, "reg", reg,
+                 sizeof(reg[0]) * (addrcells + sizecells));
+
+    /*
+     * interrupts is evtchn upcall  <1 15 0xf08>
+     * See linux Documentation/devicetree/bindings/arm/gic.txt
+     */
+    intr[0] = cpu_to_fdt32(1); /* is a PPI */
+    intr[1] = cpu_to_fdt32(VGIC_IRQ_EVTCHN_CALLBACK - 16); /* PPIs start at 16 */
+    intr[2] = cpu_to_fdt32(0xf08); /* Active-low level-sensitive */
+
+    fdt_property(fdt, "interrupts", intr, sizeof(intr[0]) * 3);
+
+    fdt_end_node(fdt);
+}
+
 static int write_nodes(struct domain *d, struct kernel_info *kinfo,
                        const void *fdt)
 {
@@ -241,9 +287,12 @@ static int write_nodes(struct domain *d, struct kernel_info *kinfo,
         last_depth = depth;
     }
 
-    while ( last_depth-- >= 0 )
+    while ( last_depth-- >= 1 )
         fdt_end_node(kinfo->fdt);
 
+    make_hypervisor_node(kinfo->fdt, address_cells[0], size_cells[0]);
+
+    fdt_end_node(kinfo->fdt);
     return 0;
 }
 
Signature · 1 line
1.7.9.1