Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ofw add of_getprop_bool and of_getprop_uint32 helpers
details: https://anonhg.NetBSD.org/src/rev/c5f84c746fb8
branches: trunk
changeset: 342327:c5f84c746fb8
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Wed Dec 16 19:33:39 2015 +0000
description:
add of_getprop_bool and of_getprop_uint32 helpers
diffstat:
sys/dev/ofw/ofw_subr.c | 32 ++++++++++++++++++++++++++++++--
sys/dev/ofw/openfirm.h | 5 ++++-
2 files changed, 34 insertions(+), 3 deletions(-)
diffs (67 lines):
diff -r 5407a4925a35 -r c5f84c746fb8 sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c Wed Dec 16 19:33:16 2015 +0000
+++ b/sys/dev/ofw/ofw_subr.c Wed Dec 16 19:33:39 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_subr.c,v 1.26 2015/12/13 11:51:13 jmcneill Exp $ */
+/* $NetBSD: ofw_subr.c,v 1.27 2015/12/16 19:33:39 jmcneill Exp $ */
/*
* Copyright 1998
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.26 2015/12/13 11:51:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.27 2015/12/16 19:33:39 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -443,3 +443,31 @@
prop_dictionary_set_bool(props, "i2c-indirect-config", false);
}
+
+/*
+ * Get the value of a boolean property. If the property is present,
+ * return true. Otherwise, return false.
+ */
+bool
+of_getprop_bool(int node, const char *prop)
+{
+ return OF_getproplen(node, prop) >= 0;
+}
+
+/*
+ * Get the value of a uint32 property, compensating for host byte order.
+ * Returns 0 on success, non-zero on failure.
+ */
+int
+of_getprop_uint32(int node, const char *prop, uint32_t *val)
+{
+ uint32_t v;
+ int len;
+
+ len = OF_getprop(node, prop, &v, sizeof(v));
+ if (len != sizeof(v))
+ return -1;
+
+ *val = be32toh(v);
+ return 0;
+}
diff -r 5407a4925a35 -r c5f84c746fb8 sys/dev/ofw/openfirm.h
--- a/sys/dev/ofw/openfirm.h Wed Dec 16 19:33:16 2015 +0000
+++ b/sys/dev/ofw/openfirm.h Wed Dec 16 19:33:39 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: openfirm.h,v 1.32 2015/12/13 11:51:13 jmcneill Exp $ */
+/* $NetBSD: openfirm.h,v 1.33 2015/12/16 19:33:39 jmcneill Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -120,4 +120,7 @@
void of_enter_i2c_devs(prop_dictionary_t, int, size_t, int);
+bool of_getprop_bool(int, const char *);
+int of_getprop_uint32(int, const char *, uint32_t *);
+
#endif /*_OPENFIRM_H_*/
Home |
Main Index |
Thread Index |
Old Index