[PATCH 8/9] ARM: Rockchip: make rk3568's atf_load_bl31 reusable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Future support for rk3399 can use the same function, so move the bulk
into a macro. We can't use a function here, because the function itself
uses macros like IS_ENABLED() and get_builtin_firmware(), which we
would have to call outside of the common code, reducing amount of code
we share.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 arch/arm/mach-rockchip/atf.c | 53 ++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/arch/arm/mach-rockchip/atf.c b/arch/arm/mach-rockchip/atf.c
index 3c4c9d1c8ae6..de22784489b5 100644
--- a/arch/arm/mach-rockchip/atf.c
+++ b/arch/arm/mach-rockchip/atf.c
@@ -33,30 +33,35 @@ static unsigned long load_elf64_image_phdr(const void *elf)
 	return ehdr->e_entry;
 }
 
-void rk3568_atf_load_bl31(void *fdt)
-{
-	const void *bl31_elf, *optee;
-	unsigned long bl31;
-	size_t bl31_elf_size, optee_size;
-	uintptr_t optee_load_address = 0;
-
-	get_builtin_firmware(rk3568_bl31_bin, &bl31_elf, &bl31_elf_size);
-
-	bl31 = load_elf64_image_phdr(bl31_elf);
-
-	if (IS_ENABLED(CONFIG_ARCH_RK3568_OPTEE)) {
-		optee_load_address = RK3568_OPTEE_LOAD_ADDRESS;
+#define rockchip_atf_load_bl31(SOC, atf_bin, tee_bin, fdt) do {                 \
+	const void *bl31_elf, *optee;                                           \
+	unsigned long bl31;                                                     \
+	size_t bl31_elf_size, optee_size;                                       \
+	uintptr_t optee_load_address = 0;                                       \
+										\
+	get_builtin_firmware(atf_bin, &bl31_elf, &bl31_elf_size);               \
+										\
+	bl31 = load_elf64_image_phdr(bl31_elf);                                 \
+										\
+	if (IS_ENABLED(CONFIG_ARCH_##SOC##_OPTEE)) {                            \
+		optee_load_address = SOC##_OPTEE_LOAD_ADDRESS;                  \
+										\
+		get_builtin_firmware(tee_bin, &optee, &optee_size);             \
+										\
+		memcpy((void *)optee_load_address, optee, optee_size);          \
+	}                                                                       \
+										\
+	/* Setup an initial stack for EL2 */                                    \
+	asm volatile("msr sp_el2, %0" : :                                       \
+			"r" (SOC##_BAREBOX_LOAD_ADDRESS - 16) :                 \
+			"cc");                                                  \
+										\
+	bl31_entry(bl31, optee_load_address,                                    \
+		   SOC##_BAREBOX_LOAD_ADDRESS, (uintptr_t)fdt);                 \
+} while (0)                                                                     \
 
-		get_builtin_firmware(rk3568_op_tee_bin, &optee, &optee_size);
 
-		memcpy((void *)optee_load_address, optee, optee_size);
-	}
-
-	/* Setup an initial stack for EL2 */
-	asm volatile("msr sp_el2, %0" : :
-			"r" (RK3568_BAREBOX_LOAD_ADDRESS - 16) :
-			"cc");
-
-	bl31_entry(bl31, optee_load_address,
-		   RK3568_BAREBOX_LOAD_ADDRESS, (uintptr_t)fdt);
+void rk3568_atf_load_bl31(void *fdt)
+{
+	rockchip_atf_load_bl31(RK3568, rk3568_bl31_bin, rk3568_op_tee_bin, fdt);
 }
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux