From owner-svn-src-head@FreeBSD.ORG  Tue Oct 22 20:57:25 2013
Return-Path: <owner-svn-src-head@FreeBSD.ORG>
Delivered-To: svn-src-head@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTP id A0D22414;
 Tue, 22 Oct 2013 20:57:25 +0000 (UTC)
 (envelope-from nwhitehorn@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by mx1.freebsd.org (Postfix) with ESMTPS id 74CE627F0;
 Tue, 22 Oct 2013 20:57:25 +0000 (UTC)
Received: from svn.freebsd.org ([127.0.1.70])
 by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9MKvPWx043043;
 Tue, 22 Oct 2013 20:57:25 GMT
 (envelope-from nwhitehorn@svn.freebsd.org)
Received: (from nwhitehorn@localhost)
 by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9MKvPuS043008;
 Tue, 22 Oct 2013 20:57:25 GMT
 (envelope-from nwhitehorn@svn.freebsd.org)
Message-Id: <201310222057.r9MKvPuS043008@svn.freebsd.org>
From: Nathan Whitehorn <nwhitehorn@FreeBSD.org>
Date: Tue, 22 Oct 2013 20:57:25 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-head@freebsd.org
Subject: svn commit: r256932 - head/sys/dev/ofw
X-SVN-Group: head
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-head@freebsd.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: SVN commit messages for the src tree for head/-current
 <svn-src-head.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head>
List-Post: <mailto:svn-src-head@freebsd.org>
List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 22 Oct 2013 20:57:25 -0000

Author: nwhitehorn
Date: Tue Oct 22 20:57:24 2013
New Revision: 256932
URL: http://svnweb.freebsd.org/changeset/base/256932

Log:
  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.

Modified:
  head/sys/dev/ofw/openfirm.c
  head/sys/dev/ofw/openfirm.h

Modified: head/sys/dev/ofw/openfirm.c
==============================================================================
--- head/sys/dev/ofw/openfirm.c	Tue Oct 22 20:50:41 2013	(r256931)
+++ head/sys/dev/ofw/openfirm.c	Tue Oct 22 20:57:24 2013	(r256932)
@@ -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
 	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

Modified: head/sys/dev/ofw/openfirm.h
==============================================================================
--- head/sys/dev/ofw/openfirm.h	Tue Oct 22 20:50:41 2013	(r256931)
+++ head/sys/dev/ofw/openfirm.h	Tue Oct 22 20:57:24 2013	(r256932)
@@ -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);