From da4ade48e94302d5779f48451ac4a706a8ceaa81 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 8 Nov 2021 08:52:08 +0100 Subject: ARM: Rockchip: make rk3568's atf_load_bl31 reusable 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 Link: https://lore.barebox.org/20211108075209.2366770-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- arch/arm/mach-rockchip/atf.c | 53 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'arch') diff --git a/arch/arm/mach-rockchip/atf.c b/arch/arm/mach-rockchip/atf.c index 3c4c9d1c8a..de22784489 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); } -- cgit v1.2.3