]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
arm: mach-omap2: Factor out common FDT fixup suport
authorAndrew F. Davis <afd@ti.com>
Mon, 10 Jul 2017 19:45:50 +0000 (14:45 -0500)
committerTom Rini <trini@konsulko.com>
Sun, 23 Jul 2017 02:22:43 +0000 (22:22 -0400)
Some of the fixups currently done for OMAP5 class boards are common to
other OMAP family devices, move these to fdt-common.c.

Signed-off-by: Andrew F. Davis <afd@ti.com>
arch/arm/include/asm/omap_common.h
arch/arm/include/asm/omap_sec_common.h
arch/arm/mach-omap2/Makefile
arch/arm/mach-omap2/fdt-common.c [new file with mode: 0644]
arch/arm/mach-omap2/omap5/fdt.c
arch/arm/mach-omap2/sec-common.c

index d2ca2777721a9b6a4334bf0b8ea71686b658e0a8..ef5c481349f6f4dd169a04b44cda8849478f0e42 100644 (file)
@@ -680,6 +680,11 @@ void omap_die_id(unsigned int *die_id);
 /* Initialize general purpose I2C(0) on the SoC */
 void gpi2c_init(void);
 
+/* Common FDT Fixups */
+int ft_hs_disable_rng(void *fdt, bd_t *bd);
+int ft_hs_fixup_dram(void *fdt, bd_t *bd);
+int ft_hs_add_tee(void *fdt, bd_t *bd);
+
 /* ABB */
 #define OMAP_ABB_NOMINAL_OPP           0
 #define OMAP_ABB_FAST_OPP              1
index 79f1fbd2c156ee87ddf0dfde8c4a48892fba9ee8..76d0862270322787f7f1e9bda3daafabb87bd1aa 100644 (file)
@@ -27,6 +27,12 @@ u32 secure_rom_call(u32 service, u32 proc_id, u32 flag, ...);
  */
 int secure_boot_verify_image(void **p_image, size_t *p_size);
 
+/*
+ * Return the start of secure reserved RAM, if a default start address has
+ * not been configured then return a region at the end of the external DRAM.
+ */
+u32 get_sec_mem_start(void);
+
 /*
  * Invoke a secure HAL API that allows configuration of the external memory
  * firewall regions.
index d43085ca98b210b2e1f22c6f4707419c2bc6809d..d86643db34a7afa308785ec32504a9553431eba8 100644 (file)
@@ -45,4 +45,6 @@ obj-y += lowlevel_init.o
 
 obj-y  += mem-common.o
 
+obj-y  += fdt-common.o
+
 obj-$(CONFIG_TI_SECURE_DEVICE) += sec-common.o
diff --git a/arch/arm/mach-omap2/fdt-common.c b/arch/arm/mach-omap2/fdt-common.c
new file mode 100644 (file)
index 0000000..297d4d4
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2016-2017 Texas Instruments, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <libfdt.h>
+#include <fdt_support.h>
+
+#include <asm/omap_common.h>
+#include <asm/omap_sec_common.h>
+
+#ifdef CONFIG_TI_SECURE_DEVICE
+
+/* Give zero values if not already defined */
+#ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
+#define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
+#endif
+#ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
+#define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
+#endif
+
+int ft_hs_disable_rng(void *fdt, bd_t *bd)
+{
+       const char *path;
+       int offs;
+       int ret;
+
+       /* Make HW RNG reserved for secure world use */
+       path = "/ocp/rng";
+       offs = fdt_path_offset(fdt, path);
+       if (offs < 0) {
+               debug("Node %s not found.\n", path);
+               return 0;
+       }
+       ret = fdt_setprop_string(fdt, offs,
+                                "status", "disabled");
+       if (ret < 0) {
+               printf("Could not add status property to node %s: %s\n",
+                      path, fdt_strerror(ret));
+               return ret;
+       }
+       return 0;
+}
+
+#if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0)
+/*
+ * fdt_pack_reg - pack address and size array into the "reg"-suitable stream
+ */
+static int fdt_pack_reg(const void *fdt, void *buf, u64 address, u64 size)
+{
+       int address_cells = fdt_address_cells(fdt, 0);
+       int size_cells = fdt_size_cells(fdt, 0);
+       char *p = buf;
+
+       if (address_cells == 2)
+               *(fdt64_t *)p = cpu_to_fdt64(address);
+       else
+               *(fdt32_t *)p = cpu_to_fdt32(address);
+       p += 4 * address_cells;
+
+       if (size_cells == 2)
+               *(fdt64_t *)p = cpu_to_fdt64(size);
+       else
+               *(fdt32_t *)p = cpu_to_fdt32(size);
+       p += 4 * size_cells;
+
+       return p - (char *)buf;
+}
+
+int ft_hs_fixup_dram(void *fdt, bd_t *bd)
+{
+       const char *path, *subpath;
+       int offs, len;
+       u32 sec_mem_start = get_sec_mem_start();
+       u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;
+       fdt32_t address_cells = cpu_to_fdt32(fdt_address_cells(fdt, 0));
+       fdt32_t size_cells = cpu_to_fdt32(fdt_size_cells(fdt, 0));
+       u8 temp[16]; /* Up to 64-bit address + 64-bit size */
+
+       /* Delete any original secure_reserved node */
+       path = "/reserved-memory/secure_reserved";
+       offs = fdt_path_offset(fdt, path);
+       if (offs >= 0)
+               fdt_del_node(fdt, offs);
+
+       /* Add new secure_reserved node */
+       path = "/reserved-memory";
+       offs = fdt_path_offset(fdt, path);
+       if (offs < 0) {
+               debug("Node %s not found\n", path);
+               path = "/";
+               subpath = "reserved-memory";
+               offs = fdt_path_offset(fdt, path);
+               offs = fdt_add_subnode(fdt, offs, subpath);
+               if (offs < 0) {
+                       printf("Could not create %s%s node.\n", path, subpath);
+                       return 1;
+               }
+               path = "/reserved-memory";
+               offs = fdt_path_offset(fdt, path);
+
+               fdt_setprop(fdt, offs, "#address-cells", &address_cells, sizeof(address_cells));
+               fdt_setprop(fdt, offs, "#size-cells", &size_cells, sizeof(size_cells));
+               fdt_setprop(fdt, offs, "ranges", NULL, 0);
+       }
+
+       subpath = "secure_reserved";
+       offs = fdt_add_subnode(fdt, offs, subpath);
+       if (offs < 0) {
+               printf("Could not create %s%s node.\n", path, subpath);
+               return 1;
+       }
+
+       fdt_setprop_string(fdt, offs, "compatible", "ti,secure-memory");
+       fdt_setprop_string(fdt, offs, "status", "okay");
+       fdt_setprop(fdt, offs, "no-map", NULL, 0);
+       len = fdt_pack_reg(fdt, temp, sec_mem_start, sec_mem_size);
+       fdt_setprop(fdt, offs, "reg", temp, len);
+
+       return 0;
+}
+#else
+int ft_hs_fixup_dram(void *fdt, bd_t *bd) { return 0; }
+#endif
+
+int ft_hs_add_tee(void *fdt, bd_t *bd)
+{
+       const char *path, *subpath;
+       int offs;
+
+       extern int tee_loaded;
+       if (!tee_loaded)
+               return 0;
+
+       path = "/";
+       offs = fdt_path_offset(fdt, path);
+
+       subpath = "firmware";
+       offs = fdt_add_subnode(fdt, offs, subpath);
+       if (offs < 0) {
+               printf("Could not create %s node.\n", subpath);
+               return 1;
+       }
+
+       subpath = "optee";
+       offs = fdt_add_subnode(fdt, offs, subpath);
+       if (offs < 0) {
+               printf("Could not create %s node.\n", subpath);
+               return 1;
+       }
+
+       fdt_setprop_string(fdt, offs, "compatible", "linaro,optee-tz");
+       fdt_setprop_string(fdt, offs, "method", "smc");
+
+       return 0;
+}
+
+#endif
index 7a3a8db5179408bd7c06f6a8ebe8d2c7569494b6..1e556da9beefb4e76f74d9c2f75228b61bcca0e0 100644 (file)
@@ -90,29 +90,6 @@ static int ft_hs_fixup_crossbar(void *fdt, bd_t *bd)
        return 0;
 }
 
-static int ft_hs_disable_rng(void *fdt, bd_t *bd)
-{
-       const char *path;
-       int offs;
-       int ret;
-
-       /* Make HW RNG reserved for secure world use */
-       path = "/ocp/rng";
-       offs = fdt_path_offset(fdt, path);
-       if (offs < 0) {
-               debug("Node %s not found.\n", path);
-               return 0;
-       }
-       ret = fdt_setprop_string(fdt, offs,
-                                "status", "disabled");
-       if (ret < 0) {
-               printf("Could not add status property to node %s: %s\n",
-                      path, fdt_strerror(ret));
-               return ret;
-       }
-       return 0;
-}
-
 #if ((TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ != 0) || \
     (CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ != 0))
 static int ft_hs_fixup_sram(void *fdt, bd_t *bd)
@@ -153,102 +130,6 @@ static int ft_hs_fixup_sram(void *fdt, bd_t *bd)
 static int ft_hs_fixup_sram(void *fdt, bd_t *bd) { return 0; }
 #endif
 
-#if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0)
-static int ft_hs_fixup_dram(void *fdt, bd_t *bd)
-{
-       const char *path, *subpath;
-       int offs;
-       u32 sec_mem_start = CONFIG_TI_SECURE_EMIF_REGION_START;
-       u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;
-       fdt64_t temp[2];
-       fdt32_t two;
-
-       /* If start address is zero, place at end of DRAM */
-       if (0 == sec_mem_start)
-               sec_mem_start =
-                       (CONFIG_SYS_SDRAM_BASE +
-                       (omap_sdram_size() - sec_mem_size));
-
-       /* Delete any original secure_reserved node */
-       path = "/reserved-memory/secure_reserved";
-       offs = fdt_path_offset(fdt, path);
-       if (offs >= 0)
-               fdt_del_node(fdt, offs);
-
-       /* Add new secure_reserved node */
-       path = "/reserved-memory";
-       offs = fdt_path_offset(fdt, path);
-       if (offs < 0) {
-               debug("Node %s not found\n", path);
-               path = "/";
-               subpath = "reserved-memory";
-               offs = fdt_path_offset(fdt, path);
-               offs = fdt_add_subnode(fdt, offs, subpath);
-               if (offs < 0) {
-                       printf("Could not create %s%s node.\n", path, subpath);
-                       return 1;
-               }
-               path = "/reserved-memory";
-               offs = fdt_path_offset(fdt, path);
-               two = cpu_to_fdt32(2);
-               fdt_setprop(fdt, offs, "#address-cells", &two, sizeof(two));
-               fdt_setprop(fdt, offs, "#size-cells", &two, sizeof(two));
-               fdt_setprop(fdt, offs, "ranges", NULL, 0);
-       }
-
-       subpath = "secure_reserved";
-       offs = fdt_add_subnode(fdt, offs, subpath);
-       if (offs < 0) {
-               printf("Could not create %s%s node.\n", path, subpath);
-               return 1;
-       }
-
-       temp[0] = cpu_to_fdt64(((u64)sec_mem_start));
-       temp[1] = cpu_to_fdt64(((u64)sec_mem_size));
-       fdt_setprop_string(fdt, offs, "compatible",
-                          "ti,dra7-secure-memory");
-       fdt_setprop_string(fdt, offs, "status", "okay");
-       fdt_setprop(fdt, offs, "no-map", NULL, 0);
-       fdt_setprop(fdt, offs, "reg", temp, sizeof(temp));
-
-       return 0;
-}
-#else
-static int ft_hs_fixup_dram(void *fdt, bd_t *bd) { return 0; }
-#endif
-
-static int ft_hs_add_tee(void *fdt, bd_t *bd)
-{
-       const char *path, *subpath;
-       int offs;
-
-       extern int tee_loaded;
-       if (!tee_loaded)
-               return 0;
-
-       path = "/";
-       offs = fdt_path_offset(fdt, path);
-
-       subpath = "firmware";
-       offs = fdt_add_subnode(fdt, offs, subpath);
-       if (offs < 0) {
-               printf("Could not create %s node.\n", subpath);
-               return 1;
-       }
-
-       subpath = "optee";
-       offs = fdt_add_subnode(fdt, offs, subpath);
-       if (offs < 0) {
-               printf("Could not create %s node.\n", subpath);
-               return 1;
-       }
-
-       fdt_setprop_string(fdt, offs, "compatible", "linaro,optee-tz");
-       fdt_setprop_string(fdt, offs, "method", "smc");
-
-       return 0;
-}
-
 static void ft_hs_fixups(void *fdt, bd_t *bd)
 {
        /* Check we are running on an HS/EMU device type */
index f230c9ea4e316f10bdd0bcdfc4a484c74ac6e197..030b36f332a7338db3b9020eedffca8be53a635c 100644 (file)
@@ -176,7 +176,7 @@ auth_exit:
        return result;
 }
 
-static u32 get_sec_mem_start(void)
+u32 get_sec_mem_start(void)
 {
        u32 sec_mem_start = CONFIG_TI_SECURE_EMIF_REGION_START;
        u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;