aboutsummaryrefslogtreecommitdiffstats
path: root/xen/common
diff options
context:
space:
mode:
authorJulien Grall <julien.grall@linaro.org>2013-09-13 13:49:11 +0100
committerIan Campbell <ian.campbell@citrix.com>2013-09-17 15:27:48 +0100
commitc88d32f463f75664285fd98856a7cdc6e01409bc (patch)
tree4d5f3ffff34b183f05f58af6d2ba20c78807c8e1 /xen/common
parent190ece328e74d04bcf1c1bed386a7d1cfe9b031e (diff)
downloadxen-c88d32f463f75664285fd98856a7cdc6e01409bc.tar.gz
xen-c88d32f463f75664285fd98856a7cdc6e01409bc.tar.bz2
xen-c88d32f463f75664285fd98856a7cdc6e01409bc.zip
xen/dts: Add new helpers to use the device tree
List of new helpers taken from linux (commit 74b9272): - dt_property_read_string - dt_match_node - dt_find_maching_node - dt_device_is_available - dt_prop_cmp Other new helpers: - dt_set_cell - dt_for_each_child - dt_set_range - dt_cells_to_size - dt_next_cell - dt_get_range - dt_node_name_is_equal - dt_node_path_is_equal - dt_property_name_is_equal Signed-off-by: Julien Grall <julien.grall@linaro.org> Acked-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'xen/common')
-rw-r--r--xen/common/device_tree.c109
1 files changed, 102 insertions, 7 deletions
diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 61134fe404..7e451b19e9 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -182,23 +182,38 @@ void __init device_tree_get_reg(const u32 **cell, u32 address_cells,
get_val(cell, size_cells, size);
}
-static void __init set_val(u32 **cell, u32 cells, u64 val)
+void dt_get_range(const __be32 **cell, const struct dt_device_node *np,
+ u64 *address, u64 *size)
{
- u32 c = cells;
+ *address = dt_next_cell(dt_n_addr_cells(np), cell);
+ *size = dt_next_cell(dt_n_size_cells(np), cell);
+}
+
+void dt_set_cell(__be32 **cellp, int size, u64 val)
+{
+ int cells = size;
- while ( c-- )
+ while ( size-- )
{
- (*cell)[c] = cpu_to_fdt32(val);
+ (*cellp)[size] = cpu_to_fdt32(val);
val >>= 32;
}
- (*cell) += cells;
+
+ (*cellp) += cells;
}
void __init 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);
+ dt_set_cell(cell, address_cells, start);
+ dt_set_cell(cell, size_cells, size);
+}
+
+void dt_set_range(__be32 **cellp, const struct dt_device_node *np,
+ u64 address, u64 size)
+{
+ dt_set_cell(cellp, dt_n_addr_cells(np), address);
+ dt_set_cell(cellp, dt_n_size_cells(np), size);
}
u32 __init device_tree_get_u32(const void *fdt, int node, const char *prop_name,
@@ -583,6 +598,23 @@ bool_t dt_property_read_u32(const struct dt_device_node *np,
return 1;
}
+int dt_property_read_string(const struct dt_device_node *np,
+ const char *propname, const char **out_string)
+{
+ const struct dt_property *pp = dt_find_property(np, propname, NULL);
+
+ if ( !pp )
+ return -EINVAL;
+ if ( !pp->value )
+ return -ENODATA;
+ if ( strnlen(pp->value, pp->length) >= pp->length )
+ return -EILSEQ;
+
+ *out_string = pp->value;
+
+ return 0;
+}
+
bool_t dt_device_is_compatible(const struct dt_device_node *device,
const char *compat)
{
@@ -655,6 +687,34 @@ struct dt_device_node *dt_find_node_by_alias(const char *alias)
return NULL;
}
+bool_t dt_match_node(const struct dt_device_match *matches,
+ const struct dt_device_node *node)
+{
+ if ( !matches )
+ return 0;
+
+ while ( matches->path || matches->type || matches->compatible )
+ {
+ bool_t match = 1;
+
+ if ( matches->path )
+ match &= dt_node_path_is_equal(node, matches->path);
+
+ if ( matches->type )
+ match &= dt_device_type_is_equal(node, matches->type);
+
+ if ( matches->compatible )
+ match &= dt_device_is_compatible(node, matches->compatible);
+
+ if ( match )
+ return match;
+
+ matches++;
+ }
+
+ return 0;
+}
+
const struct dt_device_node *dt_get_parent(const struct dt_device_node *node)
{
if ( !node )
@@ -684,6 +744,23 @@ dt_find_compatible_node(struct dt_device_node *from,
return np;
}
+struct dt_device_node *
+dt_find_matching_node(struct dt_device_node *from,
+ const struct dt_device_match *matches)
+{
+ struct dt_device_node *np;
+ struct dt_device_node *dt;
+
+ dt = from ? from->allnext : dt_host;
+ dt_for_each_device_node(dt, np)
+ {
+ if ( dt_match_node(matches, np) )
+ return np;
+ }
+
+ return NULL;
+}
+
int dt_n_addr_cells(const struct dt_device_node *np)
{
const __be32 *ip;
@@ -1372,6 +1449,24 @@ int dt_device_get_irq(const struct dt_device_node *device, int index,
return dt_irq_translate(&raw, out_irq);
}
+bool_t dt_device_is_available(const struct dt_device_node *device)
+{
+ const char *status;
+ u32 statlen;
+
+ status = dt_get_property(device, "status", &statlen);
+ if ( status == NULL )
+ return 1;
+
+ if ( statlen > 0 )
+ {
+ if ( !strcmp(status, "okay") || !strcmp(status, "ok") )
+ return 1;
+ }
+
+ return 0;
+}
+
/**
* unflatten_dt_node - Alloc and populate a device_node from the flat tree
* @fdt: The parent device tree blob