From owner-svn-src-stable@FreeBSD.ORG Thu Dec 12 12:17:21 2013 Return-Path: Delivered-To: svn-src-stable@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 ESMTPS id 9A04612D; Thu, 12 Dec 2013 12:17:21 +0000 (UTC) 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 857EE1A9F; Thu, 12 Dec 2013 12:17:21 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBCCHLNO090435; Thu, 12 Dec 2013 12:17:21 GMT (envelope-from andreast@svn.freebsd.org) Received: (from andreast@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBCCHLwu090433; Thu, 12 Dec 2013 12:17:21 GMT (envelope-from andreast@svn.freebsd.org) Message-Id: <201312121217.rBCCHLwu090433@svn.freebsd.org> From: Andreas Tobler Date: Thu, 12 Dec 2013 12:17:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r259255 - stable/10/sys/dev/ofw X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Dec 2013 12:17:21 -0000 Author: andreast Date: Thu Dec 12 12:17:20 2013 New Revision: 259255 URL: http://svnweb.freebsd.org/changeset/base/259255 Log: MFC: r256932, r256938, r256953 r256932: 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. r256938: A few other common cases for encode-int decoding: OF_getencprop_alloc() and OF_searchencprop(). I thought about using the element size parameter to OF_getprop_alloc() to do endian-switching automatically, but it breaks use with structs and a *lot* of FDT code (which can hopefully be moved to these new APIs). r256953: Fix build. Modified: stable/10/sys/dev/ofw/openfirm.c stable/10/sys/dev/ofw/openfirm.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/ofw/openfirm.c ============================================================================== --- stable/10/sys/dev/ofw/openfirm.c Thu Dec 12 11:05:48 2013 (r259254) +++ stable/10/sys/dev/ofw/openfirm.c Thu Dec 12 12:17:20 2013 (r259255) @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include @@ -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 @@ -296,6 +312,17 @@ OF_searchprop(phandle_t node, const char return (-1); } +ssize_t +OF_searchencprop(phandle_t node, const char *propname, void *buf, size_t len) +{ + ssize_t rv; + + for (; node != 0; node = OF_parent(node)) + if ((rv = OF_getencprop(node, propname, buf, len)) != -1) + return (rv); + return (-1); +} + /* * Store the value of a property of a package into newly allocated memory * (using the M_OFWPROP malloc pool and M_WAITOK). elsz is the size of a @@ -320,6 +347,26 @@ OF_getprop_alloc(phandle_t package, cons return (len / elsz); } +ssize_t +OF_getencprop_alloc(phandle_t package, const char *name, int elsz, void **buf) +{ + ssize_t retval; + pcell_t *cell; + int i; + + KASSERT(elsz % 4 == 0, ("Need a multiple of 4 bytes")); + + retval = OF_getprop_alloc(package, name, elsz, buf); + if (retval == -1) + return (retval); + + cell = *buf; + for (i = 0; i < retval*elsz/4; i++) + cell[i] = be32toh(cell[i]); + + return (retval); +} + /* Get the next property of a package. */ int OF_nextprop(phandle_t package, const char *previous, char *buf, size_t size) Modified: stable/10/sys/dev/ofw/openfirm.h ============================================================================== --- stable/10/sys/dev/ofw/openfirm.h Thu Dec 12 11:05:48 2013 (r259254) +++ stable/10/sys/dev/ofw/openfirm.h Thu Dec 12 12:17:20 2013 (r259255) @@ -105,11 +105,17 @@ 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); +ssize_t OF_searchencprop(phandle_t node, const char *propname, + void *buf, size_t len); ssize_t OF_getprop_alloc(phandle_t node, const char *propname, int elsz, void **buf); +ssize_t OF_getencprop_alloc(phandle_t node, const char *propname, + int elsz, void **buf); int OF_nextprop(phandle_t node, const char *propname, char *buf, size_t len); int OF_setprop(phandle_t node, const char *name, const void *buf,