aboutsummaryrefslogtreecommitdiffstats
path: root/xen/common/device_tree.c
diff options
context:
space:
mode:
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>2013-02-15 13:32:18 +0000
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>2013-02-15 13:32:18 +0000
commitea40403e1c493848ed30a433550b564191be46bd (patch)
treef15c5441a81a9c9baa66861cccd277777bf6cc48 /xen/common/device_tree.c
parent92b31a9099c3ba4ce7910e5a2ee5f36dbb8b336e (diff)
downloadxen-ea40403e1c493848ed30a433550b564191be46bd.tar.gz
xen-ea40403e1c493848ed30a433550b564191be46bd.tar.bz2
xen-ea40403e1c493848ed30a433550b564191be46bd.zip
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@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com> [ ijc - s/atag_paddr/fdt_paddr ] Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'xen/common/device_tree.c')
-rw-r--r--xen/common/device_tree.c56
1 files changed, 54 insertions, 2 deletions
diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 260c2d4862..5301d63d9f 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -140,7 +140,7 @@ u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name)
* 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 *fdt,
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.