-/* $OpenBSD: fdt.c,v 1.16 2016/07/08 18:20:48 kettenis Exp $ */
+/* $OpenBSD: fdt.c,v 1.17 2016/07/09 12:31:05 kettenis Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
void *skip_node(void *);
void *skip_nops(u_int32_t *);
void *fdt_parent_node_recurse(void *, void *);
+void *fdt_find_phandle_recurse(void *, uint32_t);
int fdt_node_property_int(void *, char *, int *);
int fdt_node_property_ints(void *, char *, int *, int);
int fdt_translate_memory_address(void *, struct fdt_memory *);
return fdt_parent_node_recurse(pnode, node);
}
+void *
+fdt_find_phandle_recurse(void *node, uint32_t phandle)
+{
+ void *child;
+ char *data;
+ void *tmp;
+ int len;
+
+ len = fdt_node_property(node, "phandle", &data);
+ if (len < 0)
+ len = fdt_node_property(node, "linux,phandle", &data);
+
+ if (len == sizeof(uint32_t) && bemtoh32(data) == phandle)
+ return node;
+
+ for (child = fdt_child_node(node); child; child = fdt_next_node(child))
+ if ((tmp = fdt_find_phandle_recurse(child, phandle)))
+ return tmp;
+
+ return NULL;
+}
+
+void *
+fdt_find_phandle(uint32_t phandle)
+{
+ return fdt_find_phandle_recurse(fdt_next_node(0), phandle);
+}
+
/*
* Translate memory address depending on parent's range.
*
return node ? ((char *)node - (char *)tree.header) : 0;
}
+int
+OF_getnodebyphandle(uint32_t phandle)
+{
+ void *node;
+
+ node = fdt_find_phandle(phandle);
+ return node ? ((char *)node - (char *)tree.header) : 0;
+}
+
int
OF_getproplen(int handle, char *prop)
{
-/* $OpenBSD: fdt.h,v 1.3 2016/06/08 15:27:05 jsg Exp $ */
+/* $OpenBSD: fdt.h,v 1.4 2016/07/09 12:31:05 kettenis Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
void *fdt_find_node(char *);
int fdt_node_property(void *, char *, char **);
void *fdt_parent_node(void *);
+void *fdt_find_phandle(uint32_t);
int fdt_get_memory_address(void *, int, struct fdt_memory *);
int fdt_is_compatible(void *, const char *);
#ifdef DEBUG
-/* $OpenBSD: openfirm.h,v 1.12 2016/06/12 12:55:42 kettenis Exp $ */
+/* $OpenBSD: openfirm.h,v 1.13 2016/07/09 12:31:05 kettenis Exp $ */
/* $NetBSD: openfirm.h,v 1.1 1996/09/30 16:35:10 ws Exp $ */
/*
void (*OF_set_callback(void (*newfunc)(void *))) ();
#endif
int OF_getnodebyname(int, const char *);
+int OF_getnodebyphandle(uint32_t);
/*
* Some generic routines for OpenFirmware handling.