From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: tim@xen.org, Ian.Campbell@citrix.com,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v3 6/8] xen/device_tree: introduce find_compatible_node
Date: Tue, 18 Dec 2012 18:46:39 +0000	[thread overview]
Message-ID: <1355856402-26614-6-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1212181843200.17523@kaball.uk.xensource.com>
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.
Changes in v2:
- remove fdt;
- return early from _find_compatible_node, if a node has already been
found.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 xen/arch/arm/setup.c          |    7 ++---
 xen/common/device_tree.c      |   51 +++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/device_tree.h |    3 ++
 3 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 06a878f..2c7ee5a 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -196,7 +196,6 @@ void __init start_xen(unsigned long boot_phys_offset,
                       unsigned long atag_paddr,
                       unsigned long cpuid)
 {
-    void *fdt;
     size_t fdt_size;
     int cpus, i;
 
@@ -204,12 +203,12 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     smp_clear_cpu_maps();
 
-    fdt = (void *)BOOT_MISC_VIRT_START
+    device_tree_flattened = (void *)BOOT_MISC_VIRT_START
         + (atag_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());
 
diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 8b4ef2f..d4391f8 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -172,6 +172,57 @@ int device_tree_for_each_node(const void *fdt,
     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 0;
+
+    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 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 --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index a0e3a97..5a75f0e 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -54,6 +54,9 @@ 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);
+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);
-- 
1.7.2.5
next prev parent reply	other threads:[~2012-12-18 18:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-18 18:45 [PATCH v3 0/8] xen: ARM HDLCD video driver Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 1/8] xen/arm: introduce early_ioremap Stefano Stabellini
2012-12-19 11:52   ` Ian Campbell
2013-01-08 19:02     ` Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 2/8] xen: infrastructure to have cross-platform video drivers Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 3/8] xen: introduce a generic framebuffer driver Stefano Stabellini
2012-12-19  8:08   ` Jan Beulich
2012-12-19  8:13   ` Jan Beulich
2012-12-18 18:46 ` [PATCH v3 4/8] xen/vesa: use the new fb_* functions Stefano Stabellini
2012-12-19 12:29   ` Ian Campbell
2012-12-18 18:46 ` [PATCH v3 5/8] xen/arm: preserve DTB mappings Stefano Stabellini
2012-12-19 12:36   ` Ian Campbell
2013-01-08 18:33     ` Stefano Stabellini
2013-01-08 19:04       ` David Vrabel
2013-01-08 19:32         ` Stefano Stabellini
2012-12-18 18:46 ` Stefano Stabellini [this message]
2012-12-19 14:06   ` [PATCH v3 6/8] xen/device_tree: introduce find_compatible_node Ian Campbell
2012-12-18 18:46 ` [PATCH v3 7/8] xen/arm: introduce vexpress_syscfg Stefano Stabellini
2012-12-19 12:47   ` Ian Campbell
2013-01-08 17:16     ` Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 8/8] xen/arm: introduce a driver for the ARM HDLCD controller Stefano Stabellini
2012-12-19 12:58   ` Ian Campbell
2013-01-08 13:51     ` Stefano Stabellini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=1355856402-26614-6-git-send-email-stefano.stabellini@eu.citrix.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).