diff options
author | Nathan Whitehorn <nwhitehorn@FreeBSD.org> | 2013-10-22 20:57:24 +0000 |
---|---|---|
committer | Nathan Whitehorn <nwhitehorn@FreeBSD.org> | 2013-10-22 20:57:24 +0000 |
commit | 29fdf9ef00a14b61a7afb354582a121a33c60e7b (patch) | |
tree | 90ab8376158617b05727c00d24bc2aabed68cda9 /sys/dev | |
parent | c40ecff1b27dc8b78f87a8349221863cdad7cc05 (diff) |
Add a new function (OF_getencprop()) that undoes the transformation applied
by encode-int. Specifically, it takes a set of 32-bit cell values and
changes them to host byte order. Most non-string instances of OF_getprop()
should be using this function, which is a no-op on big-endian platforms.
Notes
Notes:
svn path=/head/; revision=256932
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ofw/openfirm.c | 16 | ||||
-rw-r--r-- | sys/dev/ofw/openfirm.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c index 0760854079c7..95b78c596300 100644 --- a/sys/dev/ofw/openfirm.c +++ b/sys/dev/ofw/openfirm.c @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/systm.h> +#include <sys/endian.h> #include <machine/stdarg.h> @@ -280,6 +281,21 @@ OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen) return (OFW_GETPROP(ofw_obj, package, propname, buf, buflen)); } +ssize_t +OF_getencprop(phandle_t node, const char *propname, pcell_t *buf, size_t len) +{ + ssize_t retval; + int i; + + KASSERT(len % 4 == 0, "Need a multiple of 4 bytes"); + + retval = OF_getprop(node, propname, buf, len); + for (i = 0; i < len/4; i++) + buf[i] = be32toh(buf[i]); + + return (retval); +} + /* * Recursively search the node and its parent for the given property, working * downward from the node to the device tree root. Returns the value of the diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h index e6ede1d6a9ba..1ffface2ef63 100644 --- a/sys/dev/ofw/openfirm.h +++ b/sys/dev/ofw/openfirm.h @@ -105,6 +105,8 @@ phandle_t OF_parent(phandle_t node); ssize_t OF_getproplen(phandle_t node, const char *propname); ssize_t OF_getprop(phandle_t node, const char *propname, void *buf, size_t len); +ssize_t OF_getencprop(phandle_t node, const char *prop, pcell_t *buf, + size_t len); /* Same as getprop, but maintains endianness */ int OF_hasprop(phandle_t node, const char *propname); ssize_t OF_searchprop(phandle_t node, const char *propname, void *buf, size_t len); |