]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
fdt: Add fdtdec_decode_region() to decode memory region
authorSimon Glass <sjg@chromium.org>
Thu, 25 Oct 2012 16:31:00 +0000 (16:31 +0000)
committerGerald Van Baren <gvb@unssw.com>
Tue, 13 Nov 2012 04:00:34 +0000 (23:00 -0500)
A memory region has a start and a size and is often specified in
a node by a 'reg' property. Add a function to decode this information
from the fdt.

Signed-off-by: Simon Glass <sjg@chromium.org>
include/fdtdec.h
lib/fdtdec.c

index e828662425f3c50c10bc7a1b25133751a1ec0873..341e6a18a0a87b8970fc4c9f6abb884a8cc7d40f 100644 (file)
 typedef u64 fdt_addr_t;
 #define FDT_ADDR_T_NONE (-1ULL)
 #define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
+#define fdt_size_to_cpu(reg) be64_to_cpu(reg)
 #else
 typedef u32 fdt_addr_t;
 #define FDT_ADDR_T_NONE (-1U)
 #define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
+#define fdt_size_to_cpu(reg) be32_to_cpu(reg)
 #endif
 
 /* Information obtained about memory from the FDT */
@@ -408,4 +410,21 @@ int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
  */
 const u8 *fdtdec_locate_byte_array(const void *blob, int node,
                             const char *prop_name, int count);
+
+/**
+ * Look up a property in a node which contains a memory region address and
+ * size. Then return a pointer to this address.
+ *
+ * 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 ptrp         returns pointer to region, or NULL if no address
+ * @param size         returns size of region
+ * @return 0 if ok, -1 on error (propery not found)
+ */
+int fdtdec_decode_region(const void *blob, int node,
+               const char *prop_name, void **ptrp, size_t *size);
 #endif
index 2d60c8aaafe679316efec9c07012a1a20bbd3490..557097217ce0412566d5eedc28a018962e415635 100644 (file)
@@ -542,3 +542,20 @@ char *fdtdec_get_config_string(const void *blob, const char *prop_name)
 
        return (char *)nodep;
 }
+
+int fdtdec_decode_region(const void *blob, int node,
+               const char *prop_name, void **ptrp, size_t *size)
+{
+       const fdt_addr_t *cell;
+       int len;
+
+       debug("%s: %s\n", __func__, prop_name);
+       cell = fdt_getprop(blob, node, prop_name, &len);
+       if (!cell || (len != sizeof(fdt_addr_t) * 2))
+               return -1;
+
+       *ptrp = (void *)fdt_addr_to_cpu(*cell);
+       *size = fdt_size_to_cpu(cell[1]);
+       debug("%s: size=%zx\n", __func__, *size);
+       return 0;
+}