2 * Copyright 2016 Texas Instruments, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <fdt_support.h>
12 #include <asm/omap_common.h>
13 #include <asm/arch-omap5/sys_proto.h>
15 #ifdef CONFIG_TI_SECURE_DEVICE
17 /* Give zero values if not already defined */
18 #ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
19 #define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
21 #ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
22 #define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
25 static u32 hs_irq_skip
[] = {
26 8, /* Secure violation reporting interrupt */
27 15, /* One interrupt for SDMA by secure world */
28 118 /* One interrupt for Crypto DMA by secure world */
31 static int ft_hs_fixup_crossbar(void *fdt
, bd_t
*bd
)
36 int len
, i
, old_cnt
, new_cnt
;
41 * Increase the size of the fdt
42 * so we have some breathing room
44 ret
= fdt_increase_size(fdt
, 512);
46 printf("Could not increase size of device tree: %s\n",
51 /* Reserve IRQs that are used/needed by secure world */
52 path
= "/ocp/crossbar";
53 offs
= fdt_path_offset(fdt
, path
);
55 debug("Node %s not found.\n", path
);
59 /* Get current entries */
60 p_data
= fdt_getprop(fdt
, offs
, "ti,irqs-skip", &len
);
62 old_cnt
= len
/ sizeof(u32
);
66 new_cnt
= sizeof(hs_irq_skip
) /
67 sizeof(hs_irq_skip
[0]);
69 /* Create new/updated skip list for HS parts */
70 temp
= malloc(sizeof(u32
) * (old_cnt
+ new_cnt
));
71 for (i
= 0; i
< new_cnt
; i
++)
72 temp
[i
] = cpu_to_fdt32(hs_irq_skip
[i
]);
73 for (i
= 0; i
< old_cnt
; i
++)
74 temp
[i
+ new_cnt
] = p_data
[i
];
76 /* Blow away old data and set new data */
77 fdt_delprop(fdt
, offs
, "ti,irqs-skip");
78 ret
= fdt_setprop(fdt
, offs
, "ti,irqs-skip",
80 (old_cnt
+ new_cnt
) * sizeof(u32
));
83 /* Check if the update worked */
85 printf("Could not add ti,irqs-skip property to node %s: %s\n",
86 path
, fdt_strerror(ret
));
93 static int ft_hs_disable_rng(void *fdt
, bd_t
*bd
)
99 /* Make HW RNG reserved for secure world use */
101 offs
= fdt_path_offset(fdt
, path
);
103 debug("Node %s not found.\n", path
);
106 ret
= fdt_setprop_string(fdt
, offs
,
107 "status", "disabled");
109 printf("Could not add status property to node %s: %s\n",
110 path
, fdt_strerror(ret
));
116 #if ((TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ != 0) || \
117 (CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ != 0))
118 static int ft_hs_fixup_sram(void *fdt
, bd_t
*bd
)
126 * Update SRAM reservations on secure devices. The OCMC RAM
127 * is always reserved for secure use from the start of that
130 path
= "/ocp/ocmcram@40300000/sram-hs";
131 offs
= fdt_path_offset(fdt
, path
);
133 debug("Node %s not found.\n", path
);
137 /* relative start offset */
138 temp
[0] = cpu_to_fdt32(0);
139 /* reservation size */
140 temp
[1] = cpu_to_fdt32(max(TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
,
141 CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
));
142 fdt_delprop(fdt
, offs
, "reg");
143 ret
= fdt_setprop(fdt
, offs
, "reg", temp
, 2 * sizeof(u32
));
145 printf("Could not add reg property to node %s: %s\n",
146 path
, fdt_strerror(ret
));
153 static int ft_hs_fixup_sram(void *fdt
, bd_t
*bd
) { return 0; }
156 #if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0)
157 static int ft_hs_fixup_dram(void *fdt
, bd_t
*bd
)
159 const char *path
, *subpath
;
161 u32 sec_mem_start
= CONFIG_TI_SECURE_EMIF_REGION_START
;
162 u32 sec_mem_size
= CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE
;
165 /* If start address is zero, place at end of DRAM */
166 if (0 == sec_mem_start
)
168 (CONFIG_SYS_SDRAM_BASE
+
169 (omap_sdram_size() - sec_mem_size
));
171 /* Delete any original secure_reserved node */
172 path
= "/reserved-memory/secure_reserved";
173 offs
= fdt_path_offset(fdt
, path
);
175 fdt_del_node(fdt
, offs
);
177 /* Add new secure_reserved node */
178 path
= "/reserved-memory";
179 offs
= fdt_path_offset(fdt
, path
);
181 debug("Node %s not found\n", path
);
183 subpath
= "reserved-memory";
184 fdt_path_offset(fdt
, path
);
185 offs
= fdt_add_subnode(fdt
, offs
, subpath
);
187 printf("Could not create %s%s node.\n", path
, subpath
);
190 path
= "/reserved-memory";
191 offs
= fdt_path_offset(fdt
, path
);
194 subpath
= "secure_reserved";
195 offs
= fdt_add_subnode(fdt
, offs
, subpath
);
197 printf("Could not create %s%s node.\n", path
, subpath
);
201 temp
[0] = cpu_to_fdt64(((u64
)sec_mem_start
));
202 temp
[1] = cpu_to_fdt64(((u64
)sec_mem_size
));
203 fdt_setprop_string(fdt
, offs
, "compatible",
204 "ti,dra7-secure-memory");
205 fdt_setprop_string(fdt
, offs
, "status", "okay");
206 fdt_setprop(fdt
, offs
, "no-map", NULL
, 0);
207 fdt_setprop(fdt
, offs
, "reg", temp
, sizeof(temp
));
212 static int ft_hs_fixup_dram(void *fdt
, bd_t
*bd
) { return 0; }
215 static void ft_hs_fixups(void *fdt
, bd_t
*bd
)
217 /* Check we are running on an HS/EMU device type */
218 if (GP_DEVICE
!= get_device_type()) {
219 if ((ft_hs_fixup_crossbar(fdt
, bd
) == 0) &&
220 (ft_hs_disable_rng(fdt
, bd
) == 0) &&
221 (ft_hs_fixup_sram(fdt
, bd
) == 0) &&
222 (ft_hs_fixup_dram(fdt
, bd
) == 0))
225 printf("ERROR: Incorrect device type (GP) detected!");
227 /* Fixup failed or wrong device type */
231 static void ft_hs_fixups(void *fdt
, bd_t
*bd
)
234 #endif /* #ifdef CONFIG_TI_SECURE_DEVICE */
237 * Place for general cpu/SoC FDT fixups. Board specific
238 * fixups should remain in the board files which is where
239 * this function should be called from.
241 void ft_cpu_setup(void *fdt
, bd_t
*bd
)
243 ft_hs_fixups(fdt
, bd
);