summaryrefslogtreecommitdiff
path: root/sys/dev/ofw
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2016-05-16 21:12:18 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2016-05-16 21:12:18 +0000
commit0c4de3e597a810cb7cd15be2f8ad5ff160f1e8a5 (patch)
treec6329dd6da237a7acaf8d1f64eed47713ad2a48d /sys/dev/ofw
parent27a4384aae17f5953af0fc1b66067610e3a1b7d7 (diff)
Introduce OF_is_compatible(9), a convenience function to check the "compatible"
property of an OFW/FDT node. ok deraadt@, pactrick@
Diffstat (limited to 'sys/dev/ofw')
-rw-r--r--sys/dev/ofw/fdt.c21
-rw-r--r--sys/dev/ofw/openfirm.h3
2 files changed, 22 insertions, 2 deletions
diff --git a/sys/dev/ofw/fdt.c b/sys/dev/ofw/fdt.c
index cdb588b3f5c..988cdbb8030 100644
--- a/sys/dev/ofw/fdt.c
+++ b/sys/dev/ofw/fdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.c,v 1.8 2016/04/06 12:10:04 patrick Exp $ */
+/* $OpenBSD: fdt.c,v 1.9 2016/05/16 21:12:17 kettenis Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
@@ -701,3 +701,22 @@ OF_getprop(int handle, char *prop, void *buf, int buflen)
memcpy(buf, data, min(len, buflen));
return len;
}
+
+int
+OF_is_compatible(int handle, const char *name)
+{
+ void *node = (char *)tree.header + handle;
+ char *data;
+ int len;
+
+ len = fdt_node_property(node, "compatible", &data);
+ while (len > 0) {
+ if (strcmp(data, name) == 0)
+ return 1;
+ len -= strlen(data) + 1;
+ data += strlen(data) + 1;
+ }
+
+ return 0;
+}
+
diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h
index 5affb5fcfa4..4b9c3cf0976 100644
--- a/sys/dev/ofw/openfirm.h
+++ b/sys/dev/ofw/openfirm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: openfirm.h,v 1.10 2007/10/14 17:26:59 kettenis Exp $ */
+/* $OpenBSD: openfirm.h,v 1.11 2016/05/16 21:12:17 kettenis Exp $ */
/* $NetBSD: openfirm.h,v 1.1 1996/09/30 16:35:10 ws Exp $ */
/*
@@ -51,6 +51,7 @@ int OF_getprop(int handle, char *prop, void *buf, int buflen);
int OF_setprop(int, char *, const void *, int);
int OF_nextprop(int, char *, void *);
int OF_finddevice(char *name);
+int OF_is_compatible(int, const char *);
int OF_instance_to_path(int ihandle, char *buf, int buflen);
int OF_package_to_path(int phandle, char *buf, int buflen);
int OF_call_method_1(char *method, int ihandle, int nargs, ...);