1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016-2017 Texas Instruments, Inc.
7 #include <linux/libfdt.h>
8 #include <fdt_support.h>
10 #include <asm/omap_common.h>
11 #include <asm/omap_sec_common.h>
13 #ifdef CONFIG_TI_SECURE_DEVICE
15 /* Give zero values if not already defined */
16 #ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
17 #define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
19 #ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
20 #define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
23 int ft_hs_disable_rng(void *fdt, bd_t *bd)
29 /* Make HW RNG reserved for secure world use */
31 offs = fdt_path_offset(fdt, path);
33 debug("Node %s not found.\n", path);
36 ret = fdt_setprop_string(fdt, offs,
37 "status", "disabled");
39 printf("Could not add status property to node %s: %s\n",
40 path, fdt_strerror(ret));
46 #if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0)
48 * fdt_pack_reg - pack address and size array into the "reg"-suitable stream
50 static int fdt_pack_reg(const void *fdt, void *buf, u64 address, u64 size)
52 int address_cells = fdt_address_cells(fdt, 0);
53 int size_cells = fdt_size_cells(fdt, 0);
56 if (address_cells == 2)
57 *(fdt64_t *)p = cpu_to_fdt64(address);
59 *(fdt32_t *)p = cpu_to_fdt32(address);
60 p += 4 * address_cells;
63 *(fdt64_t *)p = cpu_to_fdt64(size);
65 *(fdt32_t *)p = cpu_to_fdt32(size);
68 return p - (char *)buf;
71 int ft_hs_fixup_dram(void *fdt, bd_t *bd)
73 const char *path, *subpath;
75 u32 sec_mem_start = get_sec_mem_start();
76 u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;
77 fdt32_t address_cells = cpu_to_fdt32(fdt_address_cells(fdt, 0));
78 fdt32_t size_cells = cpu_to_fdt32(fdt_size_cells(fdt, 0));
79 u8 temp[16]; /* Up to 64-bit address + 64-bit size */
81 /* Delete any original secure_reserved node */
82 path = "/reserved-memory/secure_reserved";
83 offs = fdt_path_offset(fdt, path);
85 fdt_del_node(fdt, offs);
87 /* Add new secure_reserved node */
88 path = "/reserved-memory";
89 offs = fdt_path_offset(fdt, path);
91 debug("Node %s not found\n", path);
93 subpath = "reserved-memory";
94 offs = fdt_path_offset(fdt, path);
95 offs = fdt_add_subnode(fdt, offs, subpath);
97 printf("Could not create %s%s node.\n", path, subpath);
100 path = "/reserved-memory";
101 offs = fdt_path_offset(fdt, path);
103 fdt_setprop(fdt, offs, "#address-cells", &address_cells, sizeof(address_cells));
104 fdt_setprop(fdt, offs, "#size-cells", &size_cells, sizeof(size_cells));
105 fdt_setprop(fdt, offs, "ranges", NULL, 0);
108 subpath = "secure_reserved";
109 offs = fdt_add_subnode(fdt, offs, subpath);
111 printf("Could not create %s%s node.\n", path, subpath);
115 fdt_setprop_string(fdt, offs, "compatible", "ti,secure-memory");
116 fdt_setprop_string(fdt, offs, "status", "okay");
117 fdt_setprop(fdt, offs, "no-map", NULL, 0);
118 len = fdt_pack_reg(fdt, temp, sec_mem_start, sec_mem_size);
119 fdt_setprop(fdt, offs, "reg", temp, len);
124 int ft_hs_fixup_dram(void *fdt, bd_t *bd) { return 0; }
127 int ft_hs_add_tee(void *fdt, bd_t *bd)
129 const char *path, *subpath;
132 extern int tee_loaded;
137 offs = fdt_path_offset(fdt, path);
140 offs = fdt_path_offset(fdt, path);
142 printf("Could not find root node.\n");
146 subpath = "firmware";
147 offs = fdt_add_subnode(fdt, offs, subpath);
149 printf("Could not create %s node.\n", subpath);
155 offs = fdt_add_subnode(fdt, offs, subpath);
157 printf("Could not create %s node.\n", subpath);
161 fdt_setprop_string(fdt, offs, "compatible", "linaro,optee-tz");
162 fdt_setprop_string(fdt, offs, "method", "smc");