2 * Copyright 2016-2017 Texas Instruments, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <fdt_support.h>
11 #include <asm/omap_common.h>
12 #include <asm/omap_sec_common.h>
14 #ifdef CONFIG_TI_SECURE_DEVICE
16 /* Give zero values if not already defined */
17 #ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
18 #define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
20 #ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
21 #define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
24 int ft_hs_disable_rng(void *fdt, bd_t *bd)
30 /* Make HW RNG reserved for secure world use */
32 offs = fdt_path_offset(fdt, path);
34 debug("Node %s not found.\n", path);
37 ret = fdt_setprop_string(fdt, offs,
38 "status", "disabled");
40 printf("Could not add status property to node %s: %s\n",
41 path, fdt_strerror(ret));
47 #if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0)
49 * fdt_pack_reg - pack address and size array into the "reg"-suitable stream
51 static int fdt_pack_reg(const void *fdt, void *buf, u64 address, u64 size)
53 int address_cells = fdt_address_cells(fdt, 0);
54 int size_cells = fdt_size_cells(fdt, 0);
57 if (address_cells == 2)
58 *(fdt64_t *)p = cpu_to_fdt64(address);
60 *(fdt32_t *)p = cpu_to_fdt32(address);
61 p += 4 * address_cells;
64 *(fdt64_t *)p = cpu_to_fdt64(size);
66 *(fdt32_t *)p = cpu_to_fdt32(size);
69 return p - (char *)buf;
72 int ft_hs_fixup_dram(void *fdt, bd_t *bd)
74 const char *path, *subpath;
76 u32 sec_mem_start = get_sec_mem_start();
77 u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;
78 fdt32_t address_cells = cpu_to_fdt32(fdt_address_cells(fdt, 0));
79 fdt32_t size_cells = cpu_to_fdt32(fdt_size_cells(fdt, 0));
80 u8 temp[16]; /* Up to 64-bit address + 64-bit size */
82 /* Delete any original secure_reserved node */
83 path = "/reserved-memory/secure_reserved";
84 offs = fdt_path_offset(fdt, path);
86 fdt_del_node(fdt, offs);
88 /* Add new secure_reserved node */
89 path = "/reserved-memory";
90 offs = fdt_path_offset(fdt, path);
92 debug("Node %s not found\n", path);
94 subpath = "reserved-memory";
95 offs = fdt_path_offset(fdt, path);
96 offs = fdt_add_subnode(fdt, offs, subpath);
98 printf("Could not create %s%s node.\n", path, subpath);
101 path = "/reserved-memory";
102 offs = fdt_path_offset(fdt, path);
104 fdt_setprop(fdt, offs, "#address-cells", &address_cells, sizeof(address_cells));
105 fdt_setprop(fdt, offs, "#size-cells", &size_cells, sizeof(size_cells));
106 fdt_setprop(fdt, offs, "ranges", NULL, 0);
109 subpath = "secure_reserved";
110 offs = fdt_add_subnode(fdt, offs, subpath);
112 printf("Could not create %s%s node.\n", path, subpath);
116 fdt_setprop_string(fdt, offs, "compatible", "ti,secure-memory");
117 fdt_setprop_string(fdt, offs, "status", "okay");
118 fdt_setprop(fdt, offs, "no-map", NULL, 0);
119 len = fdt_pack_reg(fdt, temp, sec_mem_start, sec_mem_size);
120 fdt_setprop(fdt, offs, "reg", temp, len);
125 int ft_hs_fixup_dram(void *fdt, bd_t *bd) { return 0; }
128 int ft_hs_add_tee(void *fdt, bd_t *bd)
130 const char *path, *subpath;
133 extern int tee_loaded;
138 offs = fdt_path_offset(fdt, path);
141 offs = fdt_path_offset(fdt, path);
143 printf("Could not find root node.\n");
147 subpath = "firmware";
148 offs = fdt_add_subnode(fdt, offs, subpath);
150 printf("Could not create %s node.\n", subpath);
156 offs = fdt_add_subnode(fdt, offs, subpath);
158 printf("Could not create %s node.\n", subpath);
162 fdt_setprop_string(fdt, offs, "compatible", "linaro,optee-tz");
163 fdt_setprop_string(fdt, offs, "method", "smc");