summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/fdtdec.h16
-rw-r--r--lib/fdtdec.c20
2 files changed, 36 insertions, 0 deletions
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 4ae77be9ba..6b4000623d 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -445,6 +445,22 @@ int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
u32 *array, int count);
/**
+ * Look up a property in a node and return its contents in an integer
+ * array of given length. The property must exist but may have less data that
+ * expected (4*count bytes). It may have more, but this will be ignored.
+ *
+ * @param blob FDT blob
+ * @param node node to examine
+ * @param prop_name name of property to find
+ * @param array array to fill with data
+ * @param count number of array elements
+ * @return number of array elements if ok, or -FDT_ERR_NOTFOUND if the
+ * property is not found
+ */
+int fdtdec_get_int_array_count(const void *blob, int node,
+ const char *prop_name, u32 *array, int count);
+
+/**
* Look up a property in a node and return a pointer to its contents as a
* unsigned int array of given length. The property must have at least enough
* data for the array ('count' cells). It may have more, but this will be
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 9714620ab3..4aa227a0c3 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -485,6 +485,26 @@ int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
return err;
}
+int fdtdec_get_int_array_count(const void *blob, int node,
+ const char *prop_name, u32 *array, int count)
+{
+ const u32 *cell;
+ int len, elems;
+ int i;
+
+ debug("%s: %s\n", __func__, prop_name);
+ cell = fdt_getprop(blob, node, prop_name, &len);
+ if (!cell)
+ return -FDT_ERR_NOTFOUND;
+ elems = len / sizeof(u32);
+ if (count > elems)
+ count = elems;
+ for (i = 0; i < count; i++)
+ array[i] = fdt32_to_cpu(cell[i]);
+
+ return count;
+}
+
const u32 *fdtdec_locate_array(const void *blob, int node,
const char *prop_name, int count)
{
OpenPOWER on IntegriCloud