summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDariusz Swiderski <dms@cvs.openbsd.org>2009-10-01 20:21:06 +0000
committerDariusz Swiderski <dms@cvs.openbsd.org>2009-10-01 20:21:06 +0000
commit704df990a16b62da8b148b8402297fc455378df0 (patch)
tree239df86da727198f377b6d87a255d0d362cefb1c
parent2f170aacf72c46c917cdfe67ac32e89d65edf81d (diff)
add fdt_parent_node() and OF_parent() functions,
as requested by kettenis@ ok by kettenis@
-rw-r--r--sys/arch/socppc/include/fdt.h3
-rw-r--r--sys/arch/socppc/socppc/fdt.c37
-rw-r--r--sys/arch/socppc/stand/boot/fdt.c30
-rw-r--r--sys/arch/socppc/stand/boot/fdt.h3
4 files changed, 68 insertions, 5 deletions
diff --git a/sys/arch/socppc/include/fdt.h b/sys/arch/socppc/include/fdt.h
index bd92cc3947c..849f6b2a2eb 100644
--- a/sys/arch/socppc/include/fdt.h
+++ b/sys/arch/socppc/include/fdt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.h,v 1.2 2009/08/25 21:27:24 kettenis Exp $ */
+/* $OpenBSD: fdt.h,v 1.3 2009/10/01 20:21:05 dms Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
@@ -53,6 +53,7 @@ void *fdt_child_node(void *);
char *fdt_node_name(void *);
void *fdt_find_node(char *);
int fdt_node_property(void *, char *, char **);
+void *fdt_parent_node(void *);
#ifdef DEBUG
void *fdt_print_property(void *, int);
void fdt_print_node(void *, int);
diff --git a/sys/arch/socppc/socppc/fdt.c b/sys/arch/socppc/socppc/fdt.c
index 8b31fb26270..c99ab721b8e 100644
--- a/sys/arch/socppc/socppc/fdt.c
+++ b/sys/arch/socppc/socppc/fdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.c,v 1.6 2009/09/06 19:28:12 kettenis Exp $ */
+/* $OpenBSD: fdt.c,v 1.7 2009/10/01 20:21:05 dms Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
@@ -31,6 +31,7 @@ char *fdt_get_str(u_int32_t);
void *skip_property(u_int32_t *);
void *skip_props(u_int32_t *);
void *skip_node_name(u_int32_t *);
+void *fdt_parent_node_recurse(void *, void *);
#ifdef DEBUG
void fdt_print_node_recurse(void *, int);
#endif
@@ -302,6 +303,31 @@ fdt_find_node(char *name)
return node;
}
+void *
+fdt_parent_node_recurse(void *pnode, void *child)
+{
+ void *node = fdt_child_node(pnode);
+ void *tmp;
+
+ while (node && (node != child)) {
+ if ((tmp = fdt_parent_node_recurse(node, child)))
+ return tmp;
+ node = fdt_next_node(node);
+ }
+ return (node) ? pnode : NULL;
+}
+
+void *
+fdt_parent_node(void *node)
+{
+ void *pnode = fdt_next_node(0);
+
+ if (!tree_inited)
+ return NULL;
+
+ return fdt_parent_node_recurse(pnode, node);
+}
+
#ifdef DEBUG
/*
* Debug methods for printing whole tree, particular odes and properies
@@ -416,6 +442,15 @@ OF_child(int handle)
}
int
+OF_parent(int handle)
+{
+ void *node = (char *)tree.header + handle;
+
+ node = fdt_parent_node(node);
+ return node ? ((char *)node - (char *)tree.header) : 0;
+}
+
+int
OF_finddevice(char *name)
{
void *node;
diff --git a/sys/arch/socppc/stand/boot/fdt.c b/sys/arch/socppc/stand/boot/fdt.c
index 523c26e0a6b..066f33d3d9e 100644
--- a/sys/arch/socppc/stand/boot/fdt.c
+++ b/sys/arch/socppc/stand/boot/fdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.c,v 1.2 2009/09/11 17:45:01 dms Exp $ */
+/* $OpenBSD: fdt.c,v 1.3 2009/10/01 20:21:05 dms Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
@@ -30,7 +30,8 @@ char *fdt_get_str(u_int32_t);
void *skip_property(u_int32_t *);
void *skip_props(u_int32_t *);
void *skip_node_name(u_int32_t *);
-void *fdt_find_node_recurse(void *node, char *name);
+void *fdt_parent_node_recurse(void *, void *);
+void *fdt_find_node_recurse(void *, char *);
void fdt_print_node_recurse(void *, int);
static int tree_inited = 0;
@@ -300,6 +301,31 @@ fdt_find_node(char *name)
return node;
}
+void *
+fdt_parent_node_recurse(void *pnode, void *child)
+{
+ void *node = fdt_child_node(pnode);
+ void *tmp;
+
+ while (node && (node != child)) {
+ if ((tmp = fdt_parent_node_recurse(node, child)))
+ return tmp;
+ node = fdt_next_node(node);
+ }
+ return (node) ? pnode : NULL;
+}
+
+void *
+fdt_parent_node(void *node)
+{
+ void *pnode = fdt_next_node(0);
+
+ if (!tree_inited)
+ return NULL;
+
+ return fdt_parent_node_recurse(pnode, node);
+}
+
/*
* Debug methods for printing whole tree, particular odes and properies
*/
diff --git a/sys/arch/socppc/stand/boot/fdt.h b/sys/arch/socppc/stand/boot/fdt.h
index cde737e3323..88927157997 100644
--- a/sys/arch/socppc/stand/boot/fdt.h
+++ b/sys/arch/socppc/stand/boot/fdt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.h,v 1.2 2009/09/11 17:45:01 dms Exp $ */
+/* $OpenBSD: fdt.h,v 1.3 2009/10/01 20:21:05 dms Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
@@ -53,6 +53,7 @@ void *fdt_child_node(void *);
char *fdt_node_name(void *);
void *fdt_find_node(char *);
int fdt_node_property(void *, char *, char **);
+void *fdt_parent_node(void *);
void *fdt_print_property(void *, int);
void fdt_print_node(void *, int);
void fdt_print_tree(void);