[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xen/device_tree: introduce find_compatible_node


  • To: xen-changelog@xxxxxxxxxxxxxxxxxxx
  • From: Xen patchbot-unstable <patchbot@xxxxxxx>
  • Date: Tue, 19 Feb 2013 15:22:22 +0000
  • Delivery-date: Tue, 19 Feb 2013 15:22:29 +0000
  • List-id: "Change log for Mercurial \(receive only\)" <xen-changelog.lists.xen.org>

# HG changeset patch
# User Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
# Date 1360935138 0
# Node ID eff908f314224f9617d9fdcc57b166c29c44f78d
# Parent  5b09dc2856d57e09878f1106000f1d2904ff0c6c
xen/device_tree: introduce find_compatible_node

Introduce a find_compatible_node function that can be used by device
drivers to find the node corresponding to their device in the device
tree.

Initialize device_tree_flattened early in start_xen, so that it is
available before setup_mm. Get rid of fdt in the process.

Also add device_tree_node_compatible to device_tree.h, that is currently
missing.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
[ ijc - s/atag_paddr/fdt_paddr ]
Committed-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---


diff -r 5b09dc2856d5 -r eff908f31422 xen/arch/arm/setup.c
--- a/xen/arch/arm/setup.c      Fri Feb 15 13:32:18 2013 +0000
+++ b/xen/arch/arm/setup.c      Fri Feb 15 13:32:18 2013 +0000
@@ -332,7 +332,6 @@ void __init start_xen(unsigned long boot
                       unsigned long fdt_paddr,
                       unsigned long cpuid)
 {
-    void *fdt;
     size_t fdt_size;
     int cpus, i;
 
@@ -340,12 +339,12 @@ void __init start_xen(unsigned long boot
 
     smp_clear_cpu_maps();
 
-    fdt = (void *)BOOT_MISC_VIRT_START
+    device_tree_flattened = (void *)BOOT_MISC_VIRT_START
         + (fdt_paddr & ((1 << SECOND_SHIFT) - 1));
-    fdt_size = device_tree_early_init(fdt);
+    fdt_size = device_tree_early_init(device_tree_flattened);
 
     cpus = smp_get_max_cpus();
-    cmdline_parse(device_tree_bootargs(fdt));
+    cmdline_parse(device_tree_bootargs(device_tree_flattened));
 
     setup_pagetables(boot_phys_offset, get_xen_paddr());
     setup_mm(fdt_paddr, fdt_size);
diff -r 5b09dc2856d5 -r eff908f31422 xen/common/device_tree.c
--- a/xen/common/device_tree.c  Fri Feb 15 13:32:18 2013 +0000
+++ b/xen/common/device_tree.c  Fri Feb 15 13:32:18 2013 +0000
@@ -140,7 +140,7 @@ u32 device_tree_get_u32(const void *fdt,
  * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored.
  *
  * Returns 0 if all nodes were iterated over successfully.  If @func
- * returns a negative value, that value is returned immediately.
+ * returns a value different from 0, that value is returned immediately.
  */
 int device_tree_for_each_node(const void *fdt,
                               device_tree_node_func func, void *data)
@@ -169,12 +169,64 @@ int device_tree_for_each_node(const void
 
         ret = func(fdt, node, name, depth,
                    address_cells[depth-1], size_cells[depth-1], data);
-        if ( ret < 0 )
+        if ( ret != 0 )
             return ret;
     }
     return 0;
 }
 
+struct find_compat {
+    const char *compatible;
+    int found;
+    int node;
+    int depth;
+    u32 address_cells;
+    u32 size_cells;
+};
+
+static int _find_compatible_node(const void *fdt,
+                             int node, const char *name, int depth,
+                             u32 address_cells, u32 size_cells,
+                             void *data)
+{
+    struct find_compat *c = (struct find_compat *) data;
+
+    if (  c->found  )
+        return 1;
+
+    if ( device_tree_node_compatible(fdt, node, c->compatible) )
+    {
+        c->found = 1;
+        c->node = node;
+        c->depth = depth;
+        c->address_cells = address_cells;
+        c->size_cells = size_cells;
+        return 1;
+    }
+    return 0;
+}
+
+int find_compatible_node(const char *compatible, int *node, int *depth,
+                u32 *address_cells, u32 *size_cells)
+{
+    int ret;
+    struct find_compat c;
+    c.compatible = compatible;
+    c.found = 0;
+
+    ret = device_tree_for_each_node(device_tree_flattened, 
_find_compatible_node, &c);
+    if ( !c.found )
+        return ret;
+    else
+    {
+        *node = c.node;
+        *depth = c.depth;
+        *address_cells = c.address_cells;
+        *size_cells = c.size_cells;
+        return 1;
+    }
+}
+
 /**
  * device_tree_bootargs - return the bootargs (the Xen command line)
  * @fdt flat device tree.
diff -r 5b09dc2856d5 -r eff908f31422 xen/include/xen/device_tree.h
--- a/xen/include/xen/device_tree.h     Fri Feb 15 13:32:18 2013 +0000
+++ b/xen/include/xen/device_tree.h     Fri Feb 15 13:32:18 2013 +0000
@@ -68,6 +68,9 @@ void device_tree_set_reg(u32 **cell, u32
                          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);
+bool_t device_tree_node_compatible(const void *fdt, int node, const char 
*match);
+int find_compatible_node(const char *compatible, int *node, int *depth,
+                u32 *address_cells, u32 *size_cells);
 int device_tree_for_each_node(const void *fdt,
                               device_tree_node_func func, void *data);
 const char *device_tree_bootargs(const void *fdt);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.