Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Oct 2013 21:20:05 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r256938 - head/sys/dev/ofw
Message-ID:  <201310222120.r9MLK591053015@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Tue Oct 22 21:20:05 2013
New Revision: 256938
URL: http://svnweb.freebsd.org/changeset/base/256938

Log:
  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).
  
  MFC after:	2 weeks

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 21:16:57 2013	(r256937)
+++ head/sys/dev/ofw/openfirm.c	Tue Oct 22 21:20:05 2013	(r256938)
@@ -312,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
@@ -336,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: head/sys/dev/ofw/openfirm.h
==============================================================================
--- head/sys/dev/ofw/openfirm.h	Tue Oct 22 21:16:57 2013	(r256937)
+++ head/sys/dev/ofw/openfirm.h	Tue Oct 22 21:20:05 2013	(r256938)
@@ -110,8 +110,12 @@ ssize_t		OF_getencprop(phandle_t node, c
 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,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310222120.r9MLK591053015>