diff options
-rw-r--r-- | common/fdt_decode.c | 26 | ||||
-rw-r--r-- | include/fdt_decode.h | 17 |
2 files changed, 41 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; +} diff --git a/include/fdt_decode.h b/include/fdt_decode.h index e7485c3f83..b4daac86c6 100644 --- a/include/fdt_decode.h +++ b/include/fdt_decode.h @@ -594,3 +594,20 @@ int fdt_decode_get_machine_arch_id(const void *blob); * -FDT_ERR_MISSING. */ int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config); + +/** + * Look up a property in a node which contains a memory region address and + * size. Then return a pointer to this address. if the address is zero, it is + * allocated with malloc() instead. + * + * The property must hold one address with a length. This is only tested on + * 32-bit machines. + * + * @param blob FDT blob + * @param node node to examine + * @param prop_name name of property to find + * @param size returns size of region + * @return pointer to region, or NULL if property not found/malloc failed + */ +void *fdt_decode_alloc_region(const void *blob, int node, + const char *prop_name, size_t *size); |