Skip to contentSkip to conversation

arm: pass a device tree to dom0

PATCH Superseded David Vrabel 3 participants 25 messages Mar 19, 2012 – Mar 22, 2012

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover arm: pass a device tree to dom0

This series of patches makes Xen pass a (somewhat) valid device tree to dom0. The device tree for dom0 is the same as the one supplied to Xen except the memory and chosen nodes are adjusted appropriately.

We don't yet make use of the device tree to map MMIO regions or setup interrupts for the guest and we still include the UART used for Xen's console.

Note that loading Linux using a vmlinux file is no longer supported and the kernel must support device tree (ATAGS are no longer provided by Xen).

It is also possible to provide the Xen and dom0 command line via the device tree. This isn't as useful as it seems as Xen still needs to be rebuilt to included the updated device tree.

The instructions on the wiki[1] have been updated to reflect these changes.

Changes since v1:
- coding style
- move libfdt headers
- added myself as device tree maintainer
- fix potential infinite loop when assigning mem
- check dtb destination more carefully
- minor updates for clarity

David

[1] http://wiki.xen.org/wiki/Xen_ARMv7_with_Virtualization_Extensions

#1 lore raw

PATCH v2 1/11 libfdt: move headers to xen/include/xen/libfdt/

From: David Vrabel <[email protected]>

Move the public libfdt headers to xen/include/xen/libfdt/ so CFLAGS does need to be set to find them. This requires minor tweaks to one of the headers imported from upstream.

---
 xen/common/Makefile                 |    2 -
 xen/common/device_tree.c            |    3 +-
 xen/common/libfdt/Makefile          |    2 +-
 xen/common/libfdt/fdt.h             |   60 --
 xen/common/libfdt/libfdt.h          | 1235 -----------------------------------
 xen/common/libfdt/libfdt_env.h      |   16 -
 xen/include/xen/libfdt/fdt.h        |   60 ++
 xen/include/xen/libfdt/libfdt.h     | 1235 +++++++++++++++++++++++++++++++++++
 xen/include/xen/libfdt/libfdt_env.h |   16 +
 9 files changed, 1313 insertions(+), 1316 deletions(-)
 delete mode 100644 xen/common/libfdt/fdt.h
 delete mode 100644 xen/common/libfdt/libfdt.h
 delete mode 100644 xen/common/libfdt/libfdt_env.h
 create mode 100644 xen/include/xen/libfdt/fdt.h
 create mode 100644 xen/include/xen/libfdt/libfdt.h
 create mode 100644 xen/include/xen/libfdt/libfdt_env.h
xen/common/Makefile +0 -2
index 372b259..9f2e0d6 100644
@@ -61,5 +61,3 @@ subdir-$(ia64) += hvm
 
 subdir-y += libelf
 subdir-$(HAS_DEVICE_TREE) += libfdt
-
-CFLAGS += -Ilibfdt
xen/common/device_tree.c +1 -2
index d50cb9c..140d342 100644
@@ -14,13 +14,12 @@
 #include <xen/device_tree.h>
 #include <xen/kernel.h>
 #include <xen/lib.h>
+#include <xen/libfdt/libfdt.h>
 #include <xen/mm.h>
 #include <xen/stdarg.h>
 #include <xen/string.h>
 #include <asm/early_printk.h>
 
-#include <libfdt.h>
-
 struct dt_early_info __initdata early_info;
 void *device_tree_flattened;
 
xen/common/libfdt/Makefile +1 -1
index 0e65bc0..7578fe9 100644
@@ -2,4 +2,4 @@ include Makefile.libfdt
 
 obj-y += $(LIBFDT_OBJS)
 
-CFLAGS += -I.
+CFLAGS += -I$(BASEDIR)/include/xen/libfdt/
xen/common/libfdt/fdt.h deleted +0 -60

60 lines not on this page · raw message

xen/common/libfdt/libfdt.h deleted +0 -1235

1,235 lines not on this page · raw message

xen/common/libfdt/libfdt_env.h deleted +0 -16
deleted file mode 100644
index 8c0c030..0000000
@@ -1,16 +0,0 @@
-#ifndef _LIBFDT_ENV_H
-#define _LIBFDT_ENV_H
-
-#include <xen/config.h>
-#include <xen/types.h>
-#include <xen/string.h>
-#include <asm/byteorder.h>
-
-#define fdt16_to_cpu(x) be16_to_cpu(x)
-#define cpu_to_fdt16(x) cpu_to_be16(x)
-#define fdt32_to_cpu(x) be32_to_cpu(x)
-#define cpu_to_fdt32(x) cpu_to_be32(x)
-#define fdt64_to_cpu(x) be64_to_cpu(x)
-#define cpu_to_fdt64(x) cpu_to_be64(x)
-
-#endif /* _LIBFDT_ENV_H */
xen/include/xen/libfdt/fdt.h new file +60 -0

60 lines not on this page · raw message

xen/include/xen/libfdt/libfdt.h new file +1235 -0

1,235 lines not on this page · raw message

xen/include/xen/libfdt/libfdt_env.h new file +16 -0
new file mode 100644
index 0000000..8c0c030
@@ -0,0 +1,16 @@
+#ifndef _LIBFDT_ENV_H
+#define _LIBFDT_ENV_H
+
+#include <xen/config.h>
+#include <xen/types.h>
+#include <xen/string.h>
+#include <asm/byteorder.h>
+
+#define fdt16_to_cpu(x) be16_to_cpu(x)
+#define cpu_to_fdt16(x) cpu_to_be16(x)
+#define fdt32_to_cpu(x) be32_to_cpu(x)
+#define cpu_to_fdt32(x) cpu_to_be32(x)
+#define fdt64_to_cpu(x) be64_to_cpu(x)
+#define cpu_to_fdt64(x) cpu_to_be64(x)
+
+#endif /* _LIBFDT_ENV_H */
Signature · 1 line
1.7.2.5
#3 lore raw

PATCH v2 2/11 MAINTAINERS: add device tree maintainer

In reply to David Vrabel

From: David Vrabel <[email protected]>

---
 MAINTAINERS |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
MAINTAINERS +8 -0
index dfc76dd..c1d8696 100644
@@ -111,6 +111,14 @@ M:	Juergen Gross <[email protected]>
 S:	Supported
 F:	xen/common/cpupool.c
 
+DEVICE TREE
+M:	David Vrabel <[email protected]>
+S:	Supported
+F:	xen/common/libfdt/
+F:	xen/common/device_tree.c
+F:	xen/include/xen/libfdt/
+F:	xen/include/xen/device_tree.h
+
 EFI
 M:     Jan Beulich <[email protected]>
 S:     Supported
Signature · 1 line
1.7.2.5
#5 lore raw

PATCH v2 3/11 device tree: follow coding style

In reply to David Vrabel

From: David Vrabel <[email protected]>

Only changes to the coding style, no functional changes.

---
 xen/common/device_tree.c |   48 ++++++++++++++++++++++++++++-----------------
 1 files changed, 30 insertions(+), 18 deletions(-)
xen/common/device_tree.c +30 -18
index 140d342..4a7166d 100644
@@ -27,25 +27,28 @@ static void __init get_val(const u32 **cell, u32 cells, u64 *val)
 {
     *val = 0;
 
-    while (cells--) {
+    while ( cells-- )
+    {
         *val <<= 32;
         *val |= fdt32_to_cpu(*(*cell)++);
     }
 }
 
-static void __init get_register(const u32 **cell, u32 address_cells, u32 size_cells,
+static void __init get_register(const u32 **cell,
+                                u32 address_cells, u32 size_cells,
                                 u64 *start, u64 *size)
 {
     get_val(cell, address_cells, start);
     get_val(cell, size_cells, size);
 }
 
-static u32 __init prop_by_name_u32(const void *fdt, int node, const char *prop_name)
+static u32 __init prop_by_name_u32(const void *fdt, int node,
+                                   const char *prop_name)
 {
     const struct fdt_property *prop;
 
     prop = fdt_get_property(fdt, node, prop_name, NULL);
-    if (!prop || prop->len < sizeof(u32))
+    if ( !prop || prop->len < sizeof(u32) )
         return 0; /* default to 0 */
 
     return fdt32_to_cpu(*(uint32_t*)prop->data);
@@ -61,14 +64,16 @@ static void __init process_memory_node(const void *fdt, int node,
     const u32 *cell;
     paddr_t start, size;
 
-    if (address_cells < 1 || size_cells < 1) {
+    if ( address_cells < 1 || size_cells < 1 )
+    {
         early_printk("fdt: node `%s': invalid #address-cells or #size-cells",
                      fdt_get_name(fdt, node, NULL));
         return;
     }
 
     prop = fdt_get_property(fdt, node, "reg", NULL);
-    if (!prop) {
+    if ( !prop )
+    {
         early_printk("fdt: node `%s': missing `reg' property\n",
                      fdt_get_name(fdt, node, NULL));
         return;
@@ -78,7 +83,8 @@ static void __init process_memory_node(const void *fdt, int node,
     reg_cells = address_cells + size_cells;
     banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof(u32));
 
-    for (i = 0; i < banks && early_info.mem.nr_banks < NR_MEM_BANKS; i++) {
+    for ( i = 0; i < banks && early_info.mem.nr_banks < NR_MEM_BANKS; i++ )
+    {
         get_register(&cell, address_cells, size_cells, &start, &size);
         early_info.mem.bank[early_info.mem.nr_banks].start = start;
         early_info.mem.bank[early_info.mem.nr_banks].size = size;
@@ -96,10 +102,12 @@ static void __init early_scan(const void *fdt)
     u32 address_cells[MAX_DEPTH];
     u32 size_cells[MAX_DEPTH];
 
-    for (node = 0; depth >= 0; node = fdt_next_node(fdt, node, &depth)) {
+    for ( node = 0; depth >= 0; node = fdt_next_node(fdt, node, &depth) )
+    {
         name = fdt_get_name(fdt, node, NULL);
 
-        if (depth >= MAX_DEPTH) {
+        if ( depth >= MAX_DEPTH )
+        {
             early_printk("fdt: node '%s': nested too deep\n",
                          fdt_get_name(fdt, node, NULL));
             continue;
@@ -108,8 +116,9 @@ static void __init early_scan(const void *fdt)
         address_cells[depth] = prop_by_name_u32(fdt, node, "#address-cells");
         size_cells[depth] = prop_by_name_u32(fdt, node, "#size-cells");
 
-        if (strncmp(name, "memory", 6) == 0)
-            process_memory_node(fdt, node, address_cells[depth-1], size_cells[depth-1]);
+        if ( strncmp(name, "memory", 6) == 0 )
+            process_memory_node(fdt, node,
+                                address_cells[depth-1], size_cells[depth-1]);
     }
 }
 
@@ -118,9 +127,10 @@ static void __init early_print_info(void)
     struct dt_mem_info *mi = &early_info.mem;
     int i;
 
-    for (i = 0; i < mi->nr_banks; i++)
+    for ( i = 0; i < mi->nr_banks; i++ )
         early_printk("RAM: %016llx - %016llx\n",
-                     mi->bank[i].start, mi->bank[i].start + mi->bank[i].size - 1);
+                     mi->bank[i].start,
+                     mi->bank[i].start + mi->bank[i].size - 1);
 }
 
 /**
@@ -134,7 +144,7 @@ size_t __init device_tree_early_init(const void *fdt)
     int ret;
 
     ret = fdt_check_header(fdt);
-    if (ret < 0)
+    if ( ret < 0 )
         early_panic("No valid device tree\n");
 
     early_scan(fdt);
@@ -159,15 +169,17 @@ paddr_t __init device_tree_get_xen_paddr(void)
     min_size = (_end - _start + (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
 
     /* Find the highest bank with enough space. */
-    for (i = 0; i < mi->nr_banks; i++) {
-        if (mi->bank[i].size >= min_size) {
+    for ( i = 0; i < mi->nr_banks; i++ )
+    {
+        if ( mi->bank[i].size >= min_size )
+        {
             t = mi->bank[i].start + mi->bank[i].size - min_size;
-            if (t > paddr)
+            if ( t > paddr )
                 paddr = t;
         }
     }
 
-    if (!paddr)
+    if ( !paddr )
         early_panic("Not enough memory to relocate Xen\n");
 
     return paddr;
Signature · 1 line
1.7.2.5
#6 lore raw

PATCH v2 4/11 device tree: correctly ignore unit-address when matching nodes by name

In reply to David Vrabel

From: David Vrabel <[email protected]>

When matching node by their name, correctly ignore the unit address (@...) part of the name. Previously, a "memory-controller" node would be incorrectly matched as a "memory" node.

---
 xen/common/device_tree.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)
xen/common/device_tree.c +16 -6
index 4a7166d..5329956 100644
@@ -23,6 +23,20 @@
 struct dt_early_info __initdata early_info;
 void *device_tree_flattened;
 
+static bool_t __init node_matches(const void *fdt, int node, const char *match)
+{
+    const char *name;
+    size_t match_len;
+
+    name = fdt_get_name(fdt, node, NULL);
+    match_len = strlen(match);
+
+    /* Match both "match" and "match@..." patterns but not
+       "match-foo". */
+    return strncmp(name, match, match_len) == 0
+        && (name[match_len] == '@' || name[match_len] == '\0');
+}
+
 static void __init get_val(const u32 **cell, u32 cells, u64 *val)
 {
     *val = 0;
@@ -98,14 +112,11 @@ static void __init early_scan(const void *fdt)
 {
     int node;
     int depth;
-    const char *name;
     u32 address_cells[MAX_DEPTH];
     u32 size_cells[MAX_DEPTH];
 
     for ( node = 0; depth >= 0; node = fdt_next_node(fdt, node, &depth) )
     {
-        name = fdt_get_name(fdt, node, NULL);
-
         if ( depth >= MAX_DEPTH )
         {
             early_printk("fdt: node '%s': nested too deep\n",
@@ -116,9 +127,8 @@ static void __init early_scan(const void *fdt)
         address_cells[depth] = prop_by_name_u32(fdt, node, "#address-cells");
         size_cells[depth] = prop_by_name_u32(fdt, node, "#size-cells");
 
-        if ( strncmp(name, "memory", 6) == 0 )
-            process_memory_node(fdt, node,
-                                address_cells[depth-1], size_cells[depth-1]);
+        if ( node_matches(fdt, node, "memory") )
+            process_memory_node(fdt, node, address_cells[depth-1], size_cells[depth-1]);
     }
 }
 
Signature · 1 line
1.7.2.5
#7 lore raw

PATCH v2 5/11 device tree: add device_tree_for_each_node()

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add device_tree_for_each_node() to iterate over all nodes in a flat device tree. Use this in device_tree_early_init().

---
 xen/common/device_tree.c      |   72 ++++++++++++++++++++++++++---------------
 xen/include/xen/device_tree.h |    8 ++++
 2 files changed, 54 insertions(+), 26 deletions(-)
xen/common/device_tree.c +46 -26
index 5329956..8f5d899 100644
@@ -68,7 +68,43 @@ static u32 __init prop_by_name_u32(const void *fdt, int node,
     return fdt32_to_cpu(*(uint32_t*)prop->data);
 }
 
+#define MAX_DEPTH 16
+
+/**
+ * device_tree_for_each_node - iterate over all device tree nodes
+ * @fdt: flat device tree.
+ * @func: function to call for each node.
+ * @data: data to pass to @func.
+ */
+int device_tree_for_each_node(const void *fdt,
+                              device_tree_node_func func, void *data)
+{
+    int node;
+    int depth;
+    u32 address_cells[MAX_DEPTH];
+    u32 size_cells[MAX_DEPTH];
+    int ret;
+
+    for ( node = 0, depth = 0;
+          node >=0 && depth >= 0;
+          node = fdt_next_node(fdt, node, &depth) )
+    {
+        if ( depth >= MAX_DEPTH )
+            continue;
+
+        address_cells[depth] = prop_by_name_u32(fdt, node, "#address-cells");
+        size_cells[depth] = prop_by_name_u32(fdt, node, "#size-cells");
+
+        ret = func(fdt, node, fdt_get_name(fdt, node, NULL), depth,
+                   address_cells[depth-1], size_cells[depth-1], data);
+        if ( ret < 0 )
+            return ret;
+    }
+    return 0;
+}
+
 static void __init process_memory_node(const void *fdt, int node,
+                                       const char *name,
                                        u32 address_cells, u32 size_cells)
 {
     const struct fdt_property *prop;
@@ -81,15 +117,14 @@ static void __init process_memory_node(const void *fdt, int node,
     if ( address_cells < 1 || size_cells < 1 )
     {
         early_printk("fdt: node `%s': invalid #address-cells or #size-cells",
-                     fdt_get_name(fdt, node, NULL));
+                     name);
         return;
     }
 
     prop = fdt_get_property(fdt, node, "reg", NULL);
     if ( !prop )
     {
-        early_printk("fdt: node `%s': missing `reg' property\n",
-                     fdt_get_name(fdt, node, NULL));
+        early_printk("fdt: node `%s': missing `reg' property\n", name);
         return;
     }
 
@@ -106,30 +141,15 @@ static void __init process_memory_node(const void *fdt, int node,
     }
 }
 
-#define MAX_DEPTH 16
-
-static void __init early_scan(const void *fdt)
+static int __init early_scan_node(const void *fdt,
+                                  int node, const char *name, int depth,
+                                  u32 address_cells, u32 size_cells,
+                                  void *data)
 {
-    int node;
-    int depth;
-    u32 address_cells[MAX_DEPTH];
-    u32 size_cells[MAX_DEPTH];
-
-    for ( node = 0; depth >= 0; node = fdt_next_node(fdt, node, &depth) )
-    {
-        if ( depth >= MAX_DEPTH )
-        {
-            early_printk("fdt: node '%s': nested too deep\n",
-                         fdt_get_name(fdt, node, NULL));
-            continue;
-        }
+    if ( node_matches(fdt, node, "memory") )
+        process_memory_node(fdt, node, name, address_cells, size_cells);
 
-        address_cells[depth] = prop_by_name_u32(fdt, node, "#address-cells");
-        size_cells[depth] = prop_by_name_u32(fdt, node, "#size-cells");
-
-        if ( node_matches(fdt, node, "memory") )
-            process_memory_node(fdt, node, address_cells[depth-1], size_cells[depth-1]);
-    }
+    return 0;
 }
 
 static void __init early_print_info(void)
@@ -157,7 +177,7 @@ size_t __init device_tree_early_init(const void *fdt)
     if ( ret < 0 )
         early_panic("No valid device tree\n");
 
-    early_scan(fdt);
+    device_tree_for_each_node((void *)fdt, early_scan_node, NULL);
     early_print_info();
 
     return fdt_totalsize(fdt);
xen/include/xen/device_tree.h +8 -0
index 28a3dee..505f3e3 100644
@@ -28,10 +28,18 @@ struct dt_early_info {
     struct dt_mem_info mem;
 };
 
+typedef int (*device_tree_node_func)(const void *fdt,
+                                     int node, const char *name, int depth,
+                                     u32 address_cells, u32 size_cells,
+                                     void *data);
+
 extern struct dt_early_info early_info;
 extern void *device_tree_flattened;
 
 size_t device_tree_early_init(const void *fdt);
 paddr_t device_tree_get_xen_paddr(void);
 
+int device_tree_for_each_node(const void *fdt,
+                              device_tree_node_func func, void *data);
+
 #endif
Signature · 1 line
1.7.2.5
#10 lore raw

PATCH v2 6/11 device tree: add device_tree_dump() to print a flat device tree

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add a device_tree_dump() function which prints to main structure and properties names of a flat device tree (but not the properties values yet).

This will be useful for debugging problems with the device tree generated for dom0.

---
 xen/common/device_tree.c      |   38 ++++++++++++++++++++++++++++++++++++++
 xen/include/xen/device_tree.h |    1 +
 2 files changed, 39 insertions(+), 0 deletions(-)
xen/common/device_tree.c +38 -0
index 8f5d899..d4b1556 100644
@@ -103,6 +103,44 @@ int device_tree_for_each_node(const void *fdt,
     return 0;
 }
 
+static int dump_node(const void *fdt, int node, const char *name, int depth,
+                     u32 address_cells, u32 size_cells, void *data)
+{
+    char prefix[2*MAX_DEPTH + 1] = "";
+    int i;
+    int prop;
+
+    for ( i = 0; i < depth; i++ )
+        safe_strcat(prefix, "  ");
+
+    if ( name[0] == '\0' )
+        name = "/";
+    printk("%s%s:\n", prefix, name);
+
+    for ( prop = fdt_first_property_offset(fdt, node);
+          prop >= 0;
+          prop = fdt_next_property_offset(fdt, prop) )
+    {
+        const struct fdt_property *p;
+
+        p = fdt_get_property_by_offset(fdt, prop, NULL);
+
+        printk("%s  %s\n", prefix, fdt_string(fdt, fdt32_to_cpu(p->nameoff)));
+    }
+
+    return 0;
+}
+
+/**
+ * device_tree_dump - print a text representation of a device tree
+ * @fdt: flat device tree to print
+ */
+void device_tree_dump(const void *fdt)
+{
+    device_tree_for_each_node(fdt, dump_node, NULL);
+}
+
+
 static void __init process_memory_node(const void *fdt, int node,
                                        const char *name,
                                        u32 address_cells, u32 size_cells)
xen/include/xen/device_tree.h +1 -0
index 505f3e3..b91b39f 100644
@@ -41,5 +41,6 @@ paddr_t device_tree_get_xen_paddr(void);
 
 int device_tree_for_each_node(const void *fdt,
                               device_tree_node_func func, void *data);
+void device_tree_dump(const void *fdt);
 
 #endif
Signature · 1 line
1.7.2.5
#11 lore raw

PATCH v2 7/11 arm: remove the hack for loading vmlinux images

In reply to David Vrabel

From: David Vrabel <[email protected]>

Don't adjust the RAM location/size when loading an ELF for dom0. It was vmlinux specific and no longer needed because Linux can be loaded from a zImage. Support for loading ELF images is not removed as it may be useful for loading things other than the Linux kernel.

This also makes preparing the device tree for dom0 easier.

---
 xen/arch/arm/kernel.c |   11 ++---------
 1 files changed, 2 insertions(+), 9 deletions(-)
xen/arch/arm/kernel.c +2 -9
index 71a204d..dd757e5 100644
@@ -91,7 +91,6 @@ static void kernel_zimage_load(struct kernel_info *info)
 
 /**
  * Check the image is a zImage and return the load address and length
- * (FIXME: including any appended DTB).
  */
 static int kernel_try_zimage_prepare(struct kernel_info *info)
 {
@@ -117,8 +116,6 @@ static int kernel_try_zimage_prepare(struct kernel_info *info)
         end += be32_to_cpu(dtb_hdr.total_size);
     }
 
-    /* FIXME: get RAM location from appended DTB (if there is one)? */
-
     /*
      * If start is zero, the zImage is position independent -- load it
      * at 32k from start of RAM.
@@ -166,13 +163,9 @@ static int kernel_try_elf_prepare(struct kernel_info *info)
         return rc;
 
     /*
-     * FIXME: can the ELF header be used to find the physical address
-     * to load the image to?  Instead of making virt == phys by
-     * relocating the guest's RAM.
+     * TODO: can the ELF header be used to find the physical address
+     * to load the image to?  Instead of assuming virt == phys.
      */
-    info->ram_start = 0xc0000000;
-    info->ram_end   = 0xc8000000;
-
     info->entry = info->elf.parms.virt_entry;
     info->load = kernel_elf_load;
 
Signature · 1 line
1.7.2.5
#12 lore raw

PATCH v2 8/11 device tree, arm: supply a flat device tree to dom0

In reply to David Vrabel

From: David Vrabel <[email protected]>

Build a flat device tree for dom0 based on the one supplied to Xen. The following changes are made:

* In the /chosen node, the xen,dom0-bootargs parameter is renamed to bootargs.

* In all memory nodes, the reg parameters are adjusted to reflect the amount of memory dom0 can use. The p2m is updated using this info.

Support for passing ATAGS to dom0 is removed.

---
 xen/arch/arm/Makefile         |    2 +
 xen/arch/arm/domain_build.c   |  253 ++++++++++++++++++++++++++++++++++-------
 xen/arch/arm/kernel.c         |    2 +-
 xen/arch/arm/kernel.h         |    8 +-
 xen/common/device_tree.c      |   47 +++++---
 xen/include/xen/device_tree.h |    8 ++
 6 files changed, 260 insertions(+), 60 deletions(-)
xen/arch/arm/Makefile +2 -0
index d5afb6b..8d6edf5 100644
@@ -27,6 +27,8 @@ obj-y += vtimer.o
 
 #obj-bin-y += ....o
 
+CFLAGS += -I../../common/libfdt
+
 ifdef CONFIG_DTB_FILE
 obj-y += dtb.o
 AFLAGS += -DCONFIG_DTB_FILE=\"$(CONFIG_DTB_FILE)\"
xen/arch/arm/domain_build.c +212 -41

309 lines not on this page · raw message

xen/arch/arm/kernel.c +1 -1
index dd757e5..130d488 100644
@@ -121,7 +121,7 @@ static int kernel_try_zimage_prepare(struct kernel_info *info)
      * at 32k from start of RAM.
      */
     if (start == 0)
-        info->zimage.load_addr = info->ram_start + 0x8000;
+        info->zimage.load_addr = info->mem.bank[0].start + 0x8000;
     else
         info->zimage.load_addr = start;
     info->zimage.len = end - start;
xen/arch/arm/kernel.h +6 -2
index 5caebe5..4533568 100644
@@ -7,11 +7,15 @@
 #define __ARCH_ARM_KERNEL_H__
 
 #include <xen/libelf.h>
+#include <xen/device_tree.h>
 
 struct kernel_info {
+    void *fdt; /* flat device tree */
+    paddr_t unassigned_mem; /* RAM not (yet) assigned to a bank */
+    struct dt_mem_info mem;
+
+    paddr_t dtb_paddr;
     paddr_t entry;
-    paddr_t ram_start;
-    paddr_t ram_end;
 
     void *kernel_img;
     unsigned kernel_order;
xen/common/device_tree.c +31 -16

102 lines not on this page · raw message

xen/include/xen/device_tree.h +8 -0
index b91b39f..510b5b4 100644
@@ -12,6 +12,8 @@
 
 #include <xen/types.h>
 
+#define DEVICE_TREE_MAX_DEPTH 16
+
 #define NR_MEM_BANKS 8
 
 struct membank {
@@ -39,6 +41,12 @@ extern void *device_tree_flattened;
 size_t device_tree_early_init(const void *fdt);
 paddr_t device_tree_get_xen_paddr(void);
 
+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);
+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);
 void device_tree_dump(const void *fdt);
Signature · 1 line
1.7.2.5
#18 lore raw

PATCH v2 9/11 Allow cmdline_parse() to be used with const strings

In reply to David Vrabel

From: David Vrabel <[email protected]>

---
 xen/common/kernel.c   |    2 +-
 xen/include/xen/lib.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
xen/common/kernel.c +1 -1
index 88984d2..145b0b6 100644
@@ -46,7 +46,7 @@ static void __init assign_integer_param(
     }
 }
 
-void __init cmdline_parse(char *cmdline)
+void __init cmdline_parse(const char *cmdline)
 {
     char opt[100], *optval, *optkey, *q;
     const char *p = cmdline;
xen/include/xen/lib.h +1 -1
index d6f9182..36b4c7f 100644
@@ -56,7 +56,7 @@ do {                                                            \
 
 struct domain;
 
-void cmdline_parse(char *cmdline);
+void cmdline_parse(const char *cmdline);
 int parse_bool(const char *s);
 
 /*#define DEBUG_TRACE_DUMP*/
Signature · 1 line
1.7.2.5
#20 lore raw

PATCH v2 10/11 arm: use bootargs for the command line

In reply to David Vrabel

From: David Vrabel <[email protected]>

Use the /chosen node's bootargs parameter for the Xen command line. Parse it early on before the serial console is setup.

---
 xen/arch/arm/setup.c          |    2 ++
 xen/common/device_tree.c      |   20 ++++++++++++++++++++
 xen/include/xen/device_tree.h |    1 +
 3 files changed, 23 insertions(+), 0 deletions(-)
xen/arch/arm/setup.c +2 -0
index 777f8fb..f89a1f7 100644
@@ -152,6 +152,8 @@ void __init start_xen(unsigned long boot_phys_offset,
         + (atag_paddr & ((1 << SECOND_SHIFT) - 1));
     fdt_size = device_tree_early_init(fdt);
 
+    cmdline_parse(device_tree_bootargs(fdt));
+
     setup_pagetables(boot_phys_offset);
 
 #ifdef EARLY_UART_ADDRESS
xen/common/device_tree.c +20 -0
index 715fbf6..8fb6d46 100644
@@ -118,6 +118,26 @@ int device_tree_for_each_node(const void *fdt,
     return 0;
 }
 
+/**
+ * device_tree_bootargs - return the bootargs (the Xen command line)
+ * @fdt flat device tree.
+ */
+const char *device_tree_bootargs(const void *fdt)
+{
+    int node; 
+    const struct fdt_property *prop;
+
+    node = fdt_path_offset(fdt, "/chosen");
+    if ( node < 0 )
+        return NULL;
+
+    prop = fdt_get_property(fdt, node, "bootargs", NULL);
+    if ( prop == NULL )
+        return NULL;
+
+    return prop->data;
+}
+
 static int dump_node(const void *fdt, int node, const char *name, int depth,
                      u32 address_cells, u32 size_cells, void *data)
 {
xen/include/xen/device_tree.h +1 -0
index 510b5b4..8e1626c 100644
@@ -49,6 +49,7 @@ u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name);
 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);
+const char *device_tree_bootargs(const void *fdt);
 void device_tree_dump(const void *fdt);
 
 #endif
Signature · 1 line
1.7.2.5
#24 lore raw

PATCH v2 11/11 arm: add dom0_mem command line argument

In reply to David Vrabel

From: David Vrabel <[email protected]>

Add a simple dom0_mem command line argument. It's not as flexible as the x86 equivalent (the 'max' and 'min' prefixes are not supported).

---
 xen/arch/arm/domain_build.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +13 -2
index 963f1cf..cefd693 100644
@@ -17,6 +17,17 @@
 static unsigned int __initdata opt_dom0_max_vcpus;
 integer_param("dom0_max_vcpus", opt_dom0_max_vcpus);
 
+#define DOM0_MEM_DEFAULT 0x8000000 /* 128 MiB */
+static u64 __initdata dom0_mem = DOM0_MEM_DEFAULT;
+
+static void __init parse_dom0_mem(const char *s)
+{
+    dom0_mem = parse_size_and_unit(s, &s);
+    if ( dom0_mem == 0 )
+        dom0_mem = DOM0_MEM_DEFAULT;
+}
+custom_param("dom0_mem", parse_dom0_mem);
+
 /*
  * Amount of extra space required to dom0's device tree.  No new nodes
  * are added (yet) so no additional space is needed.
@@ -193,6 +204,8 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
     int new_size;
     int ret;
 
+    kinfo->unassigned_mem = dom0_mem;
+
     fdt = device_tree_flattened;
 
     new_size = fdt_totalsize(fdt) + DOM0_FDT_EXTRA_SIZE;
@@ -261,8 +274,6 @@ int construct_dom0(struct domain *d)
     if ( (rc = p2m_alloc_table(d)) != 0 )
         return rc;
 
-    kinfo.unassigned_mem = 0x08000000; /* XXX */
-
     rc = prepare_dtb(d, &kinfo);
     if ( rc < 0 )
         return rc;
Signature · 1 line
1.7.2.5
Acked-by on v2 9/11
#19 lore raw

Re: [PATCH 09/11] Allow cmdline_parse() to be used with const strings

In reply to David Vrabel
Quoted 4 lines · David Vrabel

From: David Vrabel <[email protected]>

Quoted 32 lines
---
 xen/common/kernel.c   |    2 +-
 xen/include/xen/lib.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
xen/common/kernel.c +1 -1
index 88984d2..145b0b6 100644
@@ -46,7 +46,7 @@ static void __init assign_integer_param(
     }
 }
 
-void __init cmdline_parse(char *cmdline)
+void __init cmdline_parse(const char *cmdline)
 {
     char opt[100], *optval, *optkey, *q;
     const char *p = cmdline;
xen/include/xen/lib.h +1 -1
index d6f9182..36b4c7f 100644
@@ -56,7 +56,7 @@ do {
 \
 
 struct domain;
 
-void cmdline_parse(char *cmdline);
+void cmdline_parse(const char *cmdline);
 int parse_bool(const char *s);
 

/*#define DEBUG_TRACE_DUMP*/

Acked-by on v2 2/11
#4 lore raw

Re: [PATCH 02/11] MAINTAINERS: add device tree maintainer

In reply to David Vrabel
Quoted 4 lines · David Vrabel

From: David Vrabel <[email protected]>

Quoted 23 lines
---
 MAINTAINERS |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
MAINTAINERS +8 -0
index dfc76dd..c1d8696 100644
@@ -111,6 +111,14 @@ M: Juergen Gross <[email protected]>
 S: Supported
 F: xen/common/cpupool.c
 
+DEVICE TREE
+M: David Vrabel <[email protected]>
+S: Supported
+F: xen/common/libfdt/
+F: xen/common/device_tree.c
+F: xen/include/xen/libfdt/
+F: xen/include/xen/device_tree.h
+
 EFI
 M:     Jan Beulich <[email protected]>
 S:     Supported
#2 lore raw

Re: [PATCH 01/11] libfdt: move headers to xen/include/xen/libfdt/

In reply to David Vrabel
Quoted 7 lines · David Vrabel

From: David Vrabel <[email protected]>

Move the public libfdt headers to xen/include/xen/libfdt/ so CFLAGS does need to be set to find them. This requires minor tweaks to one of the headers imported from upstream.

Sorry, forgot the -M option when generating this. The real diff is much more modest.

8<--------------------
[PATCH] libfdt: move headers to xen/include/xen/libfdt/

Move the public libfdt headers to xen/include/xen/libfdt/ so CFLAGS does need to be set to find them. This requires minor tweaks to one of the headers imported from upstream.

---
 xen/common/Makefile                             |    2 --
 xen/common/device_tree.c                        |    3 +--
 xen/common/libfdt/Makefile                      |    2 +-
 xen/{common => include/xen}/libfdt/fdt.h        |    0
 xen/{common => include/xen}/libfdt/libfdt.h     |    4 ++--
 xen/{common => include/xen}/libfdt/libfdt_env.h |    0
 6 files changed, 4 insertions(+), 7 deletions(-)
 rename xen/{common => include/xen}/libfdt/fdt.h (100%)
 rename xen/{common => include/xen}/libfdt/libfdt.h (99%)
 rename xen/{common => include/xen}/libfdt/libfdt_env.h (100%)
xen/common/Makefile +0 -2
index 372b259..9f2e0d6 100644
@@ -61,5 +61,3 @@ subdir-$(ia64) += hvm
 
 subdir-y += libelf
 subdir-$(HAS_DEVICE_TREE) += libfdt
-
-CFLAGS += -Ilibfdt
xen/common/device_tree.c +1 -2
index d50cb9c..140d342 100644
@@ -14,13 +14,12 @@
 #include <xen/device_tree.h>
 #include <xen/kernel.h>
 #include <xen/lib.h>
+#include <xen/libfdt/libfdt.h>
 #include <xen/mm.h>
 #include <xen/stdarg.h>
 #include <xen/string.h>
 #include <asm/early_printk.h>
 
-#include <libfdt.h>
-
 struct dt_early_info __initdata early_info;
 void *device_tree_flattened;
 
xen/common/libfdt/Makefile +1 -1
index 0e65bc0..7578fe9 100644
@@ -2,4 +2,4 @@ include Makefile.libfdt
 
 obj-y += $(LIBFDT_OBJS)
 
-CFLAGS += -I.
+CFLAGS += -I$(BASEDIR)/include/xen/libfdt/
xen/include/xen/libfdt/fdt.h renamed from xen/common/libfdt/fdt.h +0 -0
similarity index 100%
rename from xen/common/libfdt/fdt.h
rename to xen/include/xen/libfdt/fdt.h
xen/include/xen/libfdt/libfdt.h renamed from xen/common/libfdt/libfdt.h +2 -2
similarity index 99%
rename from xen/common/libfdt/libfdt.h
rename to xen/include/xen/libfdt/libfdt.h
index 55f3eb3..6086047 100644
@@ -51,8 +51,8 @@
  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <libfdt_env.h>
-#include <fdt.h>
+#include <xen/libfdt/libfdt_env.h>
+#include <xen/libfdt/fdt.h>
 
 #define FDT_FIRST_SUPPORTED_VERSION	0x10
 #define FDT_LAST_SUPPORTED_VERSION	0x11
(quoted diff) +0 -0

b/xen/include/xen/libfdt/libfdt_env.h
similarity index 100%
rename from xen/common/libfdt/libfdt_env.h
rename to xen/include/xen/libfdt/libfdt_env.h

Signature · 1 line
1.7.2.5
#13 lore raw

Re: [PATCH 08/11] device tree, arm: supply a flat device tree to dom0

In reply to David Vrabel
Quoted 7 lines · David Vrabel

Build a flat device tree for dom0 based on the one supplied to Xen. The following changes are made:
[...]

xen/arch/arm/Makefile obj-y += vtimer.o · line 34

Quoted 8 lines
xen/arch/arm/Makefile +2 -0
@@ -27,6 +27,8 @@ obj-y += vtimer.o
 
 #obj-bin-y += ....o
 
+CFLAGS += -I../../common/libfdt
+
 ifdef CONFIG_DTB_FILE
 obj-y += dtb.o
 AFLAGS += -DCONFIG_DTB_FILE=\"$(CONFIG_DTB_FILE)\"

I accidentally left this hunk in after moving the libfdt headers. Ian, can you drop this hunk or should I respin the series?

David

#14 lore raw

Re: [PATCH 08/11] device tree, arm: supply a flat device tree to dom0

Quoted 11 lines · David Vrabel
Quoted 10 lines · David Vrabel

Build a flat device tree for dom0 based on the one supplied to Xen. The following changes are made:
[...]

xen/arch/arm/Makefile +0 -0
@@ -27,6 +27,8 @@ obj-y += vtimer.o
 
 #obj-bin-y += ....o
 
Quoted 8 lines

xen/arch/arm/Makefile obj-y += vtimer.o · line 34

Quoted 5 lines
xen/arch/arm/Makefile +2 -0
+CFLAGS += -I../../common/libfdt
+
 ifdef CONFIG_DTB_FILE
 obj-y += dtb.o
 AFLAGS += -DCONFIG_DTB_FILE=\"$(CONFIG_DTB_FILE)\"

I accidentally left this hunk in after moving the libfdt headers. Ian, can you drop this hunk or should I respin the series?

I'll nuke it while applying. thanks.

#8 lore raw

Re: [PATCH 05/11] device tree: add device_tree_for_each_node()

In reply to David Vrabel

xen/common/device_tree.c static u32 __init prop_by_name_u32(const void *fdt, int node, · line 93

Quoted 6 lines · David Vrabel
xen/common/device_tree.c +6 -0
+    for ( node = 0, depth = 0;
+          node >=0 && depth >= 0;
+          node = fdt_next_node(fdt, node, &depth) )
+    {
+        if ( depth >= MAX_DEPTH )
+            continue;

Perhaps we should fail and return an error here (which the caller can log with whatever facilities are available, e.g. early_printk or printk)? Silently just not walking a bit of the tree seem liable to lead to odd errors...

Ian.

#9 lore raw

Re: [PATCH 05/11] device tree: add device_tree_for_each_node()

Quoted 8 lines · Ian Campbell

xen/common/device_tree.c static u32 __init prop_by_name_u32(const void *fdt, int node, · line 93

Quoted 6 lines · David Vrabel
xen/common/device_tree.c +6 -0
+    for ( node = 0, depth = 0;
+          node >=0 && depth >= 0;
+          node = fdt_next_node(fdt, node, &depth) )
+    {
+        if ( depth >= MAX_DEPTH )
+            continue;
Quoted 4 lines

Perhaps we should fail and return an error here (which the caller can log with whatever facilities are available, e.g. early_printk or printk)? Silently just not walking a bit of the tree seem liable to lead to odd errors...

Not sure about making it an error. May be best to make it a warning as at least in the early scan we want to try as hard as possible to get the memory and console info so we have a better chance of printing a diagnostic.

I'm post a separate patch for this later because: a) it's unlikely a device tree will have a depth of more than 16 (the current device tree for the model is only 5 levels deep); and b) there is a test and a warning message when generating dom0's device tree (so unless your console and memory is 16 nodes deep you'll get a message).

David

#15 lore raw

Re: [PATCH 08/11] device tree, arm: supply a flat device tree to dom0

In reply to David Vrabel
Quoted 5 lines · David Vrabel

From: David Vrabel <[email protected]>

Build a flat device tree for dom0 based on the one supplied to Xen. The following changes are made:

Quoted 8 lines

* In the /chosen node, the xen,dom0-bootargs parameter is renamed to bootargs.

* In all memory nodes, the reg parameters are adjusted to reflect the amount of memory dom0 can use. The p2m is updated using this info.

Support for passing ATAGS to dom0 is removed.

With the series applied up to and including this patch my dom0 kernel fails to boot with:

[    0.000000] Linux version 3.2.0-rc5-arm-native+ (ianc@drall) (gcc version 4.6.0 (GCC) ) #77 Thu Mar 22 13:58:33 GMT 2012
[    0.000000] CPU: ARMv7 Processor [410fc0f0] revision 0 (ARMv7), cr=10c53c7d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] Machine: ARM Versatile Express, model: V2P-AEMv7A
[    0.000000] bootconsole [earlycon0] enabled
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] Kernel panic - not syncing: ERROR: Failed to allocate 0x1000 bytes below 0x0.
[    0.000000] 
[    0.000000] [<c000d64c>] (unwind_backtrace+0x0/0xe0) from [<c0273558>] (panic+0x50/0x17c)
[    0.000000] [<c0273558>] (panic+0x50/0x17c) from [<c032ff04>] (memblock_alloc_base+0x2c/0x34)
[    0.000000] [<c032ff04>] (memblock_alloc_base+0x2c/0x34) from [<c0329f30>] (early_alloc.constprop.3+0x10/0x28)
[    0.000000] [<c0329f30>] (early_alloc.constprop.3+0x10/0x28) from [<c032a8c0>] (paging_init+0x48c/0x628)
[    0.000000] [<c032a8c0>] (paging_init+0x48c/0x628) from [<c0328678>] (setup_arch+0x508/0x7ac)
[    0.000000] [<c0328678>] (setup_arch+0x508/0x7ac) from [<c03254dc>] (start_kernel+0x6c/0x2c0)
[    0.000000] [<c03254dc>] (start_kernel+0x6c/0x2c0) from [<80008048>] (0x80008048)

I'm guessing that the memory isn't being passed in correctly?

Quoted 520 lines
---
 xen/arch/arm/Makefile         |    2 +
 xen/arch/arm/domain_build.c   |  253 ++++++++++++++++++++++++++++++++++-------
 xen/arch/arm/kernel.c         |    2 +-
 xen/arch/arm/kernel.h         |    8 +-
 xen/common/device_tree.c      |   47 +++++---
 xen/include/xen/device_tree.h |    8 ++
 6 files changed, 260 insertions(+), 60 deletions(-)
xen/arch/arm/Makefile +2 -0
index d5afb6b..8d6edf5 100644
@@ -27,6 +27,8 @@ obj-y += vtimer.o
 
 #obj-bin-y += ....o
 
+CFLAGS += -I../../common/libfdt
+
 ifdef CONFIG_DTB_FILE
 obj-y += dtb.o
 AFLAGS += -DCONFIG_DTB_FILE=\"$(CONFIG_DTB_FILE)\"
xen/arch/arm/domain_build.c +212 -41
index 15632f7..963f1cf 100644
@@ -6,6 +6,10 @@
 #include <xen/sched.h>
 #include <asm/irq.h>
 #include <asm/regs.h>
+#include <xen/errno.h>
+#include <xen/device_tree.h>
+#include <xen/libfdt/libfdt.h>
+#include <xen/guest_access.h>
 
 #include "gic.h"
 #include "kernel.h"
@@ -13,6 +17,12 @@
 static unsigned int __initdata opt_dom0_max_vcpus;
 integer_param("dom0_max_vcpus", opt_dom0_max_vcpus);
 
+/*
+ * Amount of extra space required to dom0's device tree.  No new nodes
+ * are added (yet) so no additional space is needed.
+ */
+#define DOM0_FDT_EXTRA_SIZE 0
+
 struct vcpu *__init alloc_dom0_vcpu0(void)
 {
     if ( opt_dom0_max_vcpus == 0 )
@@ -28,43 +38,207 @@ struct vcpu *__init alloc_dom0_vcpu0(void)
     return alloc_vcpu(dom0, 0, 0);
 }
 
-extern void guest_mode_entry(void);
+static void set_memory_reg(struct domain *d, struct kernel_info *kinfo,
+                           const void *fdt,
+                           const u32 *cell, int address_cells, int size_cells,
+                           u32 *new_cell, int *len)
+{
+    int reg_size = (address_cells + size_cells) * sizeof(*cell);
+    int l;
+    u64 start;
+    u64 size;
+
+    l = *len;
+
+    while ( kinfo->unassigned_mem > 0 && l >= reg_size
+            && kinfo->mem.nr_banks < NR_MEM_BANKS )
+    {
+        device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
+        if ( size > kinfo->unassigned_mem )
+            size = kinfo->unassigned_mem;
+
+        device_tree_set_reg(&new_cell, address_cells, size_cells, start, size);
+
+        printk("Populate P2M %#llx->%#llx\n", start, start + size);
+        p2m_populate_ram(d, start, start + size);
+        kinfo->mem.bank[kinfo->mem.nr_banks].start = start;
+        kinfo->mem.bank[kinfo->mem.nr_banks].size = size;
+        kinfo->mem.nr_banks++;
+        kinfo->unassigned_mem -= size;
+
+        l -= reg_size;
+    }
+
+    *len -= l;
+}
+
+static int write_properties(struct domain *d, struct kernel_info *kinfo,
+                            const void *fdt,
+                            int node, const char *name, int depth,
+                            u32 address_cells, u32 size_cells)
+{
+    int prop;
+
+    for ( prop = fdt_first_property_offset(fdt, node);
+          prop >= 0;
+          prop = fdt_next_property_offset(fdt, prop) )
+    {
+        const struct fdt_property *p;
+        const char *prop_name;
+        const char *prop_data;
+        int prop_len;
+        char *new_data = NULL;
+
+        p = fdt_get_property_by_offset(fdt, prop, NULL);
+        prop_name = fdt_string(fdt, fdt32_to_cpu(p->nameoff));
+        prop_data = p->data;
+        prop_len  = fdt32_to_cpu(p->len);
+
+        /*
+         * In chosen node: replace bootargs with value from
+         * xen,dom0-bootargs.
+         */
+        if ( device_tree_node_matches(fdt, node, "chosen") )
+        {
+            if ( strcmp(prop_name, "bootargs") == 0 )
+                continue;
+            if ( strcmp(prop_name, "xen,dom0-bootargs") == 0 )
+                prop_name = "bootargs";
+        }
+        /*
+         * In a memory node: adjust reg property.
+         */
+        else if ( device_tree_node_matches(fdt, node, "memory") )
+        {
+            if ( strcmp(prop_name, "reg") == 0 )
+            {
+                new_data = xzalloc_bytes(prop_len);
+                if ( new_data  == NULL )
+                    return -ENOMEM;
+
+                set_memory_reg(d, kinfo, fdt,
+                               (u32 *)prop_data, address_cells, size_cells,
+                               (u32 *)new_data, &prop_len);
+                prop_data = new_data;
+            }
+        }
+
+        /*
+         * TODO: Should call map_mmio_regions() for all devices in the
+         * tree that have a "reg" parameter (except cpus).  This
+         * requires looking into the parent node's "ranges" property
+         * to translate the bus address in the "reg" value into
+         * physical addresses.  Regions also need to be rounded up to
+         * whole pages.
+         */
+
+        fdt_property(kinfo->fdt, prop_name, prop_data, prop_len);
+
+        xfree(new_data);
+    }
+
+    if ( prop == -FDT_ERR_NOTFOUND )
+        return 0;
+    return prop;
+}
 
-static void setup_linux_atag(paddr_t tags, paddr_t ram_s, paddr_t ram_e)
+static int write_nodes(struct domain *d, struct kernel_info *kinfo,
+                       const void *fdt)
 {
-    paddr_t ma = gvirt_to_maddr(tags);
-    void *map = map_domain_page(ma>>PAGE_SHIFT);
-    void *p = map + (tags & (PAGE_SIZE - 1));
-    char cmdline[] = "earlyprintk=xenboot console=ttyAMA1 root=/dev/mmcblk0 debug rw";
+    int node;
+    int depth = 0, last_depth = -1;
+    u32 address_cells[DEVICE_TREE_MAX_DEPTH];
+    u32 size_cells[DEVICE_TREE_MAX_DEPTH];
+    int ret;
 
-    /* not enough room on this page for all the tags */
-    BUG_ON(PAGE_SIZE - (tags & (PAGE_SIZE - 1)) < 8 * sizeof(uint32_t));
+    for ( node = 0, depth = 0;
+          node >= 0 && depth >= 0;
+          node = fdt_next_node(fdt, node, &depth) )
+    {
+        const char *name;
 
-#define TAG(type, val) *(type*)p = val; p+= sizeof(type)
+        name = fdt_get_name(fdt, node, NULL);
 
-    /* ATAG_CORE */
-    TAG(uint32_t, 2);
-    TAG(uint32_t, 0x54410001);
+        if ( depth >= DEVICE_TREE_MAX_DEPTH )
+        {
+            printk("warning: node `%s' is nested too deep\n", name);
+            continue;
+        }
 
-    /* ATAG_MEM */
-    TAG(uint32_t, 4);
-    TAG(uint32_t, 0x54410002);
-    TAG(uint32_t, (ram_e - ram_s) & 0xFFFFFFFF);
-    TAG(uint32_t, ram_s & 0xFFFFFFFF);
+        while ( last_depth-- >= depth )
+            fdt_end_node(kinfo->fdt);
 
-    /* ATAG_CMDLINE */
-    TAG(uint32_t, 2 + ((strlen(cmdline) + 4) >> 2));
-    TAG(uint32_t, 0x54410009);
-    memcpy(p, cmdline, strlen(cmdline) + 1);
-    p += ((strlen(cmdline) + 4) >> 2) << 2;
+        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells");
+        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells");
 
-    /* ATAG_NONE */
-    TAG(uint32_t, 0);
-    TAG(uint32_t, 0);
+        fdt_begin_node(kinfo->fdt, name);
 
-#undef TAG
+        ret = write_properties(d, kinfo, fdt, node, name, depth,
+                               address_cells[depth-1], size_cells[depth-1]);
+        if ( ret < 0 )
+            return ret;
 
-    unmap_domain_page(map);
+        last_depth = depth;
+    }
+
+    while ( last_depth-- >= 0 )
+        fdt_end_node(kinfo->fdt);
+
+    return 0;
+}
+
+static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
+{
+    void *fdt;
+    int new_size;
+    int ret;
+
+    fdt = device_tree_flattened;
+
+    new_size = fdt_totalsize(fdt) + DOM0_FDT_EXTRA_SIZE;
+    kinfo->fdt = xmalloc_bytes(new_size);
+    if ( kinfo->fdt == NULL )
+        return -ENOMEM;
+
+    ret = fdt_create(kinfo->fdt, new_size);
+    if ( ret < 0 )
+        goto err;
+
+    fdt_finish_reservemap(kinfo->fdt);
+
+    ret = write_nodes(d, kinfo, fdt);
+    if ( ret < 0 )
+        goto err;
+
+    fdt_finish(kinfo->fdt);
+
+    device_tree_dump(kinfo->fdt);
+
+    /*
+     * Put the device tree at the beginning of the first bank.  It
+     * must be below 4 GiB.
+     */
+    kinfo->dtb_paddr = kinfo->mem.bank[0].start + 0x100;
+    if ( kinfo->dtb_paddr + fdt_totalsize(kinfo->fdt) > (1ull << 32) )
+    {
+        printk("Not enough memory below 4 GiB for the device tree.");
+        ret = -EINVAL;
+        goto err;
+    }
+
+    return 0;
+
+  err:
+    xfree(kinfo->fdt);
+    return ret;
+}
+
+static void dtb_load(struct kernel_info *kinfo)
+{
+    void * __user dtb_virt = (void *)(u32)kinfo->dtb_paddr;
+
+    raw_copy_to_guest(dtb_virt, kinfo->fdt, fdt_totalsize(kinfo->fdt));
+    xfree(kinfo->fdt);
 }
 
 int construct_dom0(struct domain *d)
@@ -82,22 +256,20 @@ int construct_dom0(struct domain *d)
 
     printk("*** LOADING DOMAIN 0 ***\n");
 
-    /* 128M at 2G physical */
-    /* TODO size and location from DT. */
-    kinfo.ram_start = 0x80000000;
-    kinfo.ram_end   = 0x88000000;
+    d->max_pages = ~0U;
 
-    rc = kernel_prepare(&kinfo);
-    if (rc < 0)
+    if ( (rc = p2m_alloc_table(d)) != 0 )
         return rc;
 
-    d->max_pages = ~0U;
+    kinfo.unassigned_mem = 0x08000000; /* XXX */
 
-    if ( (rc = p2m_alloc_table(d)) != 0 )
+    rc = prepare_dtb(d, &kinfo);
+    if ( rc < 0 )
         return rc;
 
-    printk("Populate P2M %#llx->%#llx\n", kinfo.ram_start, kinfo.ram_end);
-    p2m_populate_ram(d, kinfo.ram_start, kinfo.ram_end);
+    rc = kernel_prepare(&kinfo);
+    if ( rc < 0 )
+        return rc;
 
     printk("Map CS2 MMIO regions 1:1 in the P2M %#llx->%#llx\n", 0x18000000ULL, 0x1BFFFFFFULL);
     map_mmio_regions(d, 0x18000000, 0x1BFFFFFF, 0x18000000);
@@ -125,13 +297,12 @@ int construct_dom0(struct domain *d)
     /* Enable second stage translation */
     WRITE_CP32(READ_CP32(HCR) | HCR_VM, HCR); isb();
 
-    /* The following load uses domain's p2m */
+    /* The following loads use the domain's p2m */
     p2m_load_VTTBR(d);
 
+    dtb_load(&kinfo);
     kernel_load(&kinfo);
 
-    setup_linux_atag(kinfo.ram_start + 0x100, kinfo.ram_start, kinfo.ram_end);
-
     clear_bit(_VPF_down, &v->pause_flags);
 
     memset(regs, 0, sizeof(*regs));
@@ -153,7 +324,7 @@ int construct_dom0(struct domain *d)
 
     regs->r0 = 0; /* SBZ */
     regs->r1 = 2272; /* Machine NR: Versatile Express */
-    regs->r2 = kinfo.ram_start + 0x100; /* ATAGS */
+    regs->r2 = kinfo.dtb_paddr;
 
     WRITE_CP32(SCTLR_BASE, SCTLR);
 
xen/arch/arm/kernel.c +1 -1
index dd757e5..130d488 100644
@@ -121,7 +121,7 @@ static int kernel_try_zimage_prepare(struct kernel_info *info)
      * at 32k from start of RAM.
      */
     if (start == 0)
-        info->zimage.load_addr = info->ram_start + 0x8000;
+        info->zimage.load_addr = info->mem.bank[0].start + 0x8000;
     else
         info->zimage.load_addr = start;
     info->zimage.len = end - start;
xen/arch/arm/kernel.h +6 -2
index 5caebe5..4533568 100644
@@ -7,11 +7,15 @@
 #define __ARCH_ARM_KERNEL_H__
 
 #include <xen/libelf.h>
+#include <xen/device_tree.h>
 
 struct kernel_info {
+    void *fdt; /* flat device tree */
+    paddr_t unassigned_mem; /* RAM not (yet) assigned to a bank */
+    struct dt_mem_info mem;
+
+    paddr_t dtb_paddr;
     paddr_t entry;
-    paddr_t ram_start;
-    paddr_t ram_end;
 
     void *kernel_img;
     unsigned kernel_order;
xen/common/device_tree.c +31 -16
index d4b1556..715fbf6 100644
@@ -23,7 +23,7 @@
 struct dt_early_info __initdata early_info;
 void *device_tree_flattened;
 
-static bool_t __init node_matches(const void *fdt, int node, const char *match)
+bool_t device_tree_node_matches(const void *fdt, int node, const char *match)
 {
     const char *name;
     size_t match_len;
@@ -48,16 +48,33 @@ static void __init get_val(const u32 **cell, u32 cells, u64 *val)
     }
 }
 
-static void __init get_register(const u32 **cell,
-                                u32 address_cells, u32 size_cells,
-                                u64 *start, u64 *size)
+void device_tree_get_reg(const u32 **cell, u32 address_cells, u32 size_cells,
+                         u64 *start, u64 *size)
 {
     get_val(cell, address_cells, start);
     get_val(cell, size_cells, size);
 }
 
-static u32 __init prop_by_name_u32(const void *fdt, int node,
-                                   const char *prop_name)
+static void set_val(u32 **cell, u32 cells, u64 val)
+{
+    u32 c = cells;
+
+    while ( c-- )
+    {
+        (*cell)[c] = cpu_to_fdt32(val);
+        val >>= 32;
+    }
+    (*cell) += cells;
+}
+
+void device_tree_set_reg(u32 **cell, u32 address_cells, u32 size_cells,
+                         u64 start, u64 size)
+{
+    set_val(cell, address_cells, start);
+    set_val(cell, size_cells, size);
+}
+
+u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name)
 {
     const struct fdt_property *prop;
 
@@ -68,8 +85,6 @@ static u32 __init prop_by_name_u32(const void *fdt, int node,
     return fdt32_to_cpu(*(uint32_t*)prop->data);
 }
 
-#define MAX_DEPTH 16
-
 /**
  * device_tree_for_each_node - iterate over all device tree nodes
  * @fdt: flat device tree.
@@ -81,19 +96,19 @@ int device_tree_for_each_node(const void *fdt,
 {
     int node;
     int depth;
-    u32 address_cells[MAX_DEPTH];
-    u32 size_cells[MAX_DEPTH];
+    u32 address_cells[DEVICE_TREE_MAX_DEPTH];
+    u32 size_cells[DEVICE_TREE_MAX_DEPTH];
     int ret;
 
     for ( node = 0, depth = 0;
           node >=0 && depth >= 0;
           node = fdt_next_node(fdt, node, &depth) )
     {
-        if ( depth >= MAX_DEPTH )
+        if ( depth >= DEVICE_TREE_MAX_DEPTH )
             continue;
 
-        address_cells[depth] = prop_by_name_u32(fdt, node, "#address-cells");
-        size_cells[depth] = prop_by_name_u32(fdt, node, "#size-cells");
+        address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells");
+        size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells");
 
         ret = func(fdt, node, fdt_get_name(fdt, node, NULL), depth,
                    address_cells[depth-1], size_cells[depth-1], data);
@@ -106,7 +121,7 @@ int device_tree_for_each_node(const void *fdt,
 static int dump_node(const void *fdt, int node, const char *name, int depth,
                      u32 address_cells, u32 size_cells, void *data)
 {
-    char prefix[2*MAX_DEPTH + 1] = "";
+    char prefix[2*DEVICE_TREE_MAX_DEPTH + 1] = "";
     int i;
     int prop;
 
@@ -172,7 +187,7 @@ static void __init process_memory_node(const void *fdt, int node,
 
     for ( i = 0; i < banks && early_info.mem.nr_banks < NR_MEM_BANKS; i++ )
     {
-        get_register(&cell, address_cells, size_cells, &start, &size);
+        device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
         early_info.mem.bank[early_info.mem.nr_banks].start = start;
         early_info.mem.bank[early_info.mem.nr_banks].size = size;
         early_info.mem.nr_banks++;
@@ -184,7 +199,7 @@ static int __init early_scan_node(const void *fdt,
                                   u32 address_cells, u32 size_cells,
                                   void *data)
 {
-    if ( node_matches(fdt, node, "memory") )
+    if ( device_tree_node_matches(fdt, node, "memory") )
         process_memory_node(fdt, node, name, address_cells, size_cells);
 
     return 0;
xen/include/xen/device_tree.h +8 -1
index b91b39f..510b5b4 100644
@@ -12,6 +12,8 @@
 
 #include <xen/types.h>
 
+#define DEVICE_TREE_MAX_DEPTH 16
+
 #define NR_MEM_BANKS 8
 
 struct membank {
@@ -39,6 +41,12 @@ extern void *device_tree_flattened;
 size_t device_tree_early_init(const void *fdt);
 paddr_t device_tree_get_xen_paddr(void);
 
+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);
+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);
 void device_tree_dump(const void *fdt);
--

1.7.2.5

#21 lore raw

Re: [PATCH 10/11] arm: use bootargs for the command line

In reply to David Vrabel
Quoted 6 lines · David Vrabel

From: David Vrabel <[email protected]>

Use the /chosen node's bootargs parameter for the Xen command line. Parse it early on before the serial console is setup.

With this my hypervisor hangs after:
- UART enabled -
- CPU 00000000 booting -
- Started in Secure state -
- Entering Hyp mode -
- Setting up control registers -
- Turning on paging -
- Ready -
RAM: 0000000080000000 - 00000000ffffffff

I'm going to try and apply 1..7 and 9. Skipping 8, 10 and 11.

Ian.

#16 lore raw

Re: [PATCH 08/11] device tree, arm: supply a flat device tree to dom0

In reply to Ian Campbell
Quoted 33 lines · Ian Campbell
Quoted 5 lines · David Vrabel

From: David Vrabel <[email protected]>

Build a flat device tree for dom0 based on the one supplied to Xen. The following changes are made:

Quoted 8 lines

* In the /chosen node, the xen,dom0-bootargs parameter is renamed to bootargs.

* In all memory nodes, the reg parameters are adjusted to reflect the amount of memory dom0 can use. The p2m is updated using this info.

Support for passing ATAGS to dom0 is removed.

With the series applied up to and including this patch my dom0 kernel fails to boot with:

[    0.000000] Linux version 3.2.0-rc5-arm-native+ (ianc@drall) (gcc version 4.6.0 (GCC) ) #77 Thu Mar 22 13:58:33 GMT 2012
[    0.000000] CPU: ARMv7 Processor [410fc0f0] revision 0 (ARMv7), cr=10c53c7d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] Machine: ARM Versatile Express, model: V2P-AEMv7A
[    0.000000] bootconsole [earlycon0] enabled
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] Kernel panic - not syncing: ERROR: Failed to allocate 0x1000 bytes below 0x0.
[    0.000000]
[    0.000000] [<c000d64c>] (unwind_backtrace+0x0/0xe0) from [<c0273558>] (panic+0x50/0x17c)
[    0.000000] [<c0273558>] (panic+0x50/0x17c) from [<c032ff04>] (memblock_alloc_base+0x2c/0x34)
[    0.000000] [<c032ff04>] (memblock_alloc_base+0x2c/0x34) from [<c0329f30>] (early_alloc.constprop.3+0x10/0x28)
[    0.000000] [<c0329f30>] (early_alloc.constprop.3+0x10/0x28) from [<c032a8c0>] (paging_init+0x48c/0x628)
[    0.000000] [<c032a8c0>] (paging_init+0x48c/0x628) from [<c0328678>] (setup_arch+0x508/0x7ac)
[    0.000000] [<c0328678>] (setup_arch+0x508/0x7ac) from [<c03254dc>] (start_kernel+0x6c/0x2c0)
[    0.000000] [<c03254dc>] (start_kernel+0x6c/0x2c0) from [<80008048>] (0x80008048)
Quoted 1 line

I'm guessing that the memory isn't being passed in correctly?

This was with a kernel with ARM_DTB_APPENDED and ARM_ATAG_DTB_COMPAT enabled. I would have thought it ought to work but the kernel must be getting confused and mangling the device tree someone.

I'll look into it.

David

#22 lore raw

Re: [PATCH 10/11] arm: use bootargs for the command line

In reply to Ian Campbell
Quoted 18 lines · Ian Campbell
Quoted 6 lines · David Vrabel

From: David Vrabel <[email protected]>

Use the /chosen node's bootargs parameter for the Xen command line. Parse it early on before the serial console is setup.

With this my hypervisor hangs after:
- UART enabled -
- CPU 00000000 booting -
- Started in Secure state -
- Entering Hyp mode -
- Setting up control registers -
- Turning on paging -
- Ready -
RAM: 0000000080000000 - 00000000ffffffff

Quoted 1 line

I'm going to try and apply 1..7 and 9. Skipping 8, 10 and 11.

Which I've now done and pushed.

Ian.

#23 lore raw

Re: [PATCH 10/11] arm: use bootargs for the command line

In reply to Ian Campbell
Quoted 18 lines · Ian Campbell
Quoted 6 lines · David Vrabel

From: David Vrabel <[email protected]>

Use the /chosen node's bootargs parameter for the Xen command line. Parse it early on before the serial console is setup.

With this my hypervisor hangs after:
- UART enabled -
- CPU 00000000 booting -
- Started in Secure state -
- Entering Hyp mode -
- Setting up control registers -
- Turning on paging -
- Ready -
RAM: 0000000080000000 - 00000000ffffffff

Quoted 1 line

I'm going to try and apply 1..7 and 9. Skipping 8, 10 and 11.#

This happens with the device tree from the kernel, but not the device tree from git://xenbits.xen.org/people/dvrabel/device-trees.git

I happens when either the /chosen node is missing or bootargs is missing. This is easy to fix. However, the kernel fails to boot because it doesn't get the device tree which is odd.

I'll look into it some more.

David

#17 lore raw

Re: [PATCH 08/11] device tree, arm: supply a flat device tree to dom0

In reply to Ian Campbell
Quoted 17 lines · Ian Campbell
Quoted 5 lines · David Vrabel

From: David Vrabel <[email protected]>

Build a flat device tree for dom0 based on the one supplied to Xen. The following changes are made:

Quoted 8 lines

* In the /chosen node, the xen,dom0-bootargs parameter is renamed to bootargs.

* In all memory nodes, the reg parameters are adjusted to reflect the amount of memory dom0 can use. The p2m is updated using this info.

Support for passing ATAGS to dom0 is removed.

With the series applied up to and including this patch my dom0 kernel fails to boot with:

Quoted 15 lines
[    0.000000] Linux version 3.2.0-rc5-arm-native+ (ianc@drall) (gcc version 4.6.0 (GCC) ) #77 Thu Mar 22 13:58:33 GMT 2012
[    0.000000] CPU: ARMv7 Processor [410fc0f0] revision 0 (ARMv7), cr=10c53c7d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] Machine: ARM Versatile Express, model: V2P-AEMv7A
[    0.000000] bootconsole [earlycon0] enabled
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] Kernel panic - not syncing: ERROR: Failed to allocate 0x1000 bytes below 0x0.
[    0.000000] 
[    0.000000] [<c000d64c>] (unwind_backtrace+0x0/0xe0) from [<c0273558>] (panic+0x50/0x17c)
[    0.000000] [<c0273558>] (panic+0x50/0x17c) from [<c032ff04>] (memblock_alloc_base+0x2c/0x34)
[    0.000000] [<c032ff04>] (memblock_alloc_base+0x2c/0x34) from [<c0329f30>] (early_alloc.constprop.3+0x10/0x28)
[    0.000000] [<c0329f30>] (early_alloc.constprop.3+0x10/0x28) from [<c032a8c0>] (paging_init+0x48c/0x628)
[    0.000000] [<c032a8c0>] (paging_init+0x48c/0x628) from [<c0328678>] (setup_arch+0x508/0x7ac)
[    0.000000] [<c0328678>] (setup_arch+0x508/0x7ac) from [<c03254dc>] (start_kernel+0x6c/0x2c0)
[    0.000000] [<c03254dc>] (start_kernel+0x6c/0x2c0) from [<80008048>] (0x80008048)

This is really a bug in the memblock allocator. You have ARM_APPENDED_DTB enabled and you have actually appended a DTB. The appended DTB takes precedence over the one passed from the bootloader and DTB in the Linux tree has 2 GiB of memory @ 2 GiB. It looks like the memblock allocator adds start + size, overflows and ends up with the end of the region at 0.

You can either: a) disable ARM_APPENDED_DTB; b) not append a DTB; or c) ensure the appended DTB's memory regions match that supplied by Xen.

David