summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2011-08-22 08:06:19 -0600
committerSimon Glass <sjg@chromium.org>2011-09-13 15:53:29 -0700
commit1ca0c7d8356936a85c91db14672aea95f3c822ef (patch)
tree6743abc2334637deb4ca83cb1ce39ff3a80547ed /common
parent391839609251aa6121399fd864c126b39d88319e (diff)
fdt: Add function to locate or allocate region
This function looks up a property in a node which contains a memory region address and size. It returns a pointer to this address, but if the address is zero, it is allocated with malloc() instead. It is used to allocate Chrome OS GBB memory regions and the like. BUG=chromium-os:19353 TEST=build for Seaboard Change-Id: I91fe8656f3ea50839998ab0e16b023635adbc119 Reviewed-on: http://gerrit.chromium.org/gerrit/7640 Reviewed-by: Stefan Reinauer <reinauer@google.com> Tested-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/fdt_decode.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/common/fdt_decode.c b/common/fdt_decode.c
index 4e889db0eb..adad546fb0 100644
--- a/common/fdt_decode.c
+++ b/common/fdt_decode.c
@@ -20,9 +20,11 @@
*/
#include <common.h>
-#include <serial.h>
-#include <libfdt.h>
+
#include <fdt_decode.h>
+#include <libfdt.h>
+#include <malloc.h>
+#include <serial.h>
/* we need a generic GPIO interface here */
#include <asm/arch/gpio.h>
@@ -676,3 +678,23 @@ int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config)
config->width = get_int(blob, node, "width", 8);
return fdt_decode_gpio(blob, node, "wp-gpio", &config->wp_gpio);
}
+
+void *fdt_decode_alloc_region(const void *blob, int node,
+ const char *prop_name, size_t *size)
+{
+ const addr_t *cell;
+ void *ptr;
+ int len;
+
+ debug("fdt_decode_alloc: %s\n", prop_name);
+ cell = fdt_getprop(blob, node, prop_name, &len);
+ if (!cell || (len != sizeof(addr_t) * 2))
+ return NULL;
+
+ ptr = (void *)addr_to_cpu(*cell);
+ *size = size_to_cpu(cell[1]);
+ debug("fdt_decode_alloc: size=%zx\n", *size);
+ if (!ptr)
+ ptr = malloc(*size);
+ return ptr;
+}