summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2009-09-02 19:36:16 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2009-09-02 19:36:16 +0000
commite283f0801e842d8e892c2e0b0ca16639486b1819 (patch)
treede1fcc4a0530ad72487bcb5a6d9a0c822dffe891
parent11fd2ce9389d7e5cf072bd016a827bdb22572ee5 (diff)
Add a minimal set of OpenFirmware compatibility interfaces.
ok dms@
-rw-r--r--sys/arch/socppc/socppc/fdt.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/sys/arch/socppc/socppc/fdt.c b/sys/arch/socppc/socppc/fdt.c
index 8603404c844..472f81c7361 100644
--- a/sys/arch/socppc/socppc/fdt.c
+++ b/sys/arch/socppc/socppc/fdt.c
@@ -1,7 +1,8 @@
-/* $OpenBSD: fdt.c,v 1.4 2009/08/29 11:01:13 miod Exp $ */
+/* $OpenBSD: fdt.c,v 1.5 2009/09/02 19:36:15 kettenis Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
+ * Copyright (c) 2009 Mark Kettenis <kettenis@sfires.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -20,8 +21,11 @@
#include <sys/types.h>
#include <sys/param.h>
#include <sys/user.h>
+
#include <machine/fdt.h>
+#include <dev/ofw/openfirm.h>
+
unsigned int fdt_check_head(void *);
char *fdt_get_str(u_int32_t);
void *skip_property(u_int32_t *);
@@ -389,3 +393,63 @@ fdt_print_tree(void)
fdt_print_node_recurse(fdt_next_node(0), 0);
}
#endif
+
+int
+OF_peer(int handle)
+{
+ void *node = (char *)tree.header + handle;
+
+ if (handle == 0)
+ node = fdt_find_node("/");
+ else
+ node = fdt_next_node(node);
+ return node ? ((char *)node - (char *)tree.header) : 0;
+}
+
+int
+OF_child(int handle)
+{
+ void *node = (char *)tree.header + handle;
+
+ node = fdt_child_node(node);
+ return node ? ((char *)node - (char *)tree.header) : 0;
+}
+
+int
+OF_finddevice(char *name)
+{
+ void *node;
+
+ node = fdt_find_node(name);
+ return node ? ((char *)node - (char *)tree.header) : -1;
+}
+
+int
+OF_getprop(int handle, char *prop, void *buf, int buflen)
+{
+ void *node = (char *)tree.header + handle;
+ char *data;
+ int len;
+
+ len = fdt_node_property(node, prop, &data);
+
+ /*
+ * The "name" property is optional since version 16 of the
+ * flattened device tree specification, so we synthesize one
+ * from the unit name of the node if it is missing.
+ */
+ if (len == 0 && strcmp(prop, "name") == 0) {
+ data = fdt_node_name(node);
+ if (data) {
+ len = strlcpy(buf, data, buflen);
+ data = strchr(buf, '@');
+ if (data)
+ *data = 0;
+ return len + 1;
+ }
+ }
+
+ if (len > 0)
+ memcpy(buf, data, min(len, buflen));
+ return len;
+}