summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanchayan Maity <maitysanchayan@gmail.com>2016-10-19 17:36:21 +0530
committerMarcel Ziswiler <marcel.ziswiler@toradex.com>2018-02-01 15:14:58 +0100
commit6fe5177a1ab17fa971ac6c914676aa15c6402bcc (patch)
tree9df48896badfe336a28dcc7bbd9dcb940c5270bd
parentcf47f0af36b07883f92b22a00add2ac06c520a03 (diff)
common: fdt_support: Add support for setting usable memory
Add support for setting the linux,usable-memory in the memory node of device tree. Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com> Signed-off-by: Stefan Agner <stefan.agner@toradex.com> Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
-rw-r--r--common/fdt_support.c36
-rw-r--r--include/fdt_support.h1
2 files changed, 37 insertions, 0 deletions
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 8266bca7d6..a8f3540862 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -440,6 +440,42 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
return 0;
}
+int fdt_set_usable_memory(void *blob, u64 start[], u64 size[], int areas)
+{
+ int err, nodeoffset;
+ int len;
+ u8 tmp[8 * 16]; /* Up to 64-bit address + 64-bit size */
+
+ if (areas > 8) {
+ printf("%s: num areas %d exceeds hardcoded limit %d."
+ " Recompile with higher MEMORY_BANKS_MAX?\n",
+ __func__, areas, 8);
+ return -1;
+ }
+
+ err = fdt_check_header(blob);
+ if (err < 0) {
+ printf("%s: %s\n", __func__, fdt_strerror(err));
+ return err;
+ }
+
+ /* find or create "/memory" node. */
+ nodeoffset = fdt_find_or_add_subnode(blob, 0, "memory");
+ if (nodeoffset < 0)
+ return nodeoffset;
+
+ len = fdt_pack_reg(blob, tmp, start, size, areas);
+
+ err = fdt_setprop(blob, nodeoffset, "linux,usable-memory", tmp, len);
+ if (err < 0) {
+ printf("WARNING: could not set %s %s.\n",
+ "reg", fdt_strerror(err));
+ return err;
+ }
+
+ return 0;
+}
+
int fdt_fixup_memory(void *blob, u64 start, u64 size)
{
return fdt_fixup_memory_banks(blob, &start, &size, 1);
diff --git a/include/fdt_support.h b/include/fdt_support.h
index ae5e8a3ef6..beacb847f4 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -42,6 +42,7 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat,
const char *prop, u32 val, int create);
int fdt_fixup_memory(void *blob, u64 start, u64 size);
int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks);
+int fdt_set_usable_memory(void *blob, u64 start[], u64 size[], int banks);
void fdt_fixup_ethernet(void *fdt);
int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
const void *val, int len, int create);