Merge tag 'ti-v2020.07-rc3' of https://gitlab.denx.de/u-boot/custodians/u-boot-ti
[oweals/u-boot.git] / common / fdt_support.c
index e0043e8da68acf5b5cf73152e94f376cd0ad37a6..3778de5368661369e41b8c6b435e86202e31f225 100644 (file)
@@ -7,7 +7,10 @@
  */
 
 #include <common.h>
+#include <env.h>
+#include <log.h>
 #include <mapmem.h>
+#include <net.h>
 #include <stdio_dev.h>
 #include <linux/ctype.h>
 #include <linux/types.h>
@@ -466,6 +469,41 @@ 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\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;
+}
 #endif
 
 int fdt_fixup_memory(void *blob, u64 start, u64 size)
@@ -1295,6 +1333,12 @@ u64 fdt_translate_address(const void *blob, int node_offset,
        return __of_translate_address(blob, node_offset, in_addr, "ranges");
 }
 
+u64 fdt_translate_dma_address(const void *blob, int node_offset,
+                             const fdt32_t *in_addr)
+{
+       return __of_translate_address(blob, node_offset, in_addr, "dma-ranges");
+}
+
 /**
  * fdt_node_offset_by_compat_reg: Find a node that matches compatiable and
  * who's reg property matches a physical cpu address
@@ -1549,7 +1593,7 @@ u64 fdt_get_base_address(const void *fdt, int node)
 
        prop = fdt_getprop(fdt, node, "reg", &size);
 
-       return prop ? fdt_translate_address(fdt, node, prop) : 0;
+       return prop ? fdt_translate_address(fdt, node, prop) : OF_BAD_ADDR;
 }
 
 /*
@@ -1559,7 +1603,7 @@ static int fdt_read_prop(const fdt32_t *prop, int prop_len, int cell_off,
                         uint64_t *val, int cells)
 {
        const fdt32_t *prop32 = &prop[cell_off];
-       const fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off];
+       const unaligned_fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off];
 
        if ((cell_off + cells) > prop_len)
                return -FDT_ERR_NOSPACE;