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
This commit is contained in:
Nathan Whitehorn 2013-10-22 21:20:05 +00:00
parent f2de4d722e
commit 4231c48fa1
2 changed files with 35 additions and 0 deletions

View File

@ -312,6 +312,17 @@ OF_searchprop(phandle_t node, const char *propname, void *buf, size_t len)
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, const char *propname, int elsz, void **buf)
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)

View File

@ -110,8 +110,12 @@ ssize_t OF_getencprop(phandle_t node, const char *prop, pcell_t *buf,
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,