From c029ba154e257e5b886c279630681a5e7ce3d3de Mon Sep 17 00:00:00 2001 From: Silvano di Ninno Date: Wed, 25 Mar 2020 09:35:14 +0100 Subject: TEE-532-6: plat: imx8qx: add optee support Port and cleanup OP-TEE support. Signed-off-by: Silvano di Ninno --- plat/imx/imx8qx/imx8qx_bl31_setup.c | 30 ++++++++++++++++++++---------- plat/imx/imx8qx/include/platform_def.h | 9 ++++++--- plat/imx/imx8qx/platform.mk | 6 ++++++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/plat/imx/imx8qx/imx8qx_bl31_setup.c b/plat/imx/imx8qx/imx8qx_bl31_setup.c index 165846e5..9829e527 100644 --- a/plat/imx/imx8qx/imx8qx_bl31_setup.c +++ b/plat/imx/imx8qx/imx8qx_bl31_setup.c @@ -167,7 +167,7 @@ void imx8_partition_resources(void) sc_err_t err; bool owned; int i; -#ifdef SPD_trusty +#if defined(SPD_opteed) || defined(SPD_trusty) sc_rm_mr_t mr_tee = 64; bool mr_tee_atf_same = false; sc_faddr_t reg_start; @@ -216,7 +216,7 @@ void imx8_partition_resources(void) if (BL31_BASE >= start && (BL31_LIMIT - 1) <= end) { mr_record = mr; /* Record the mr for ATF running */ } -#ifdef SPD_trusty +#if defined(SPD_opteed) || defined(SPD_trusty) else if (BL32_BASE >= start && (BL32_LIMIT -1) <= end) { mr_tee = mr; } @@ -233,7 +233,7 @@ void imx8_partition_resources(void) } } -#ifdef SPD_trusty +#if defined(SPD_opteed) || defined(SPD_trusty) if (mr_tee != 64) { err = sc_rm_get_memreg_info(ipc_handle, mr_tee, &start, &end); if (err) { @@ -266,7 +266,7 @@ void imx8_partition_resources(void) if (mr_record != 64) { err = sc_rm_get_memreg_info(ipc_handle, mr_record, &start, &end); -#ifdef SPD_trusty +#if defined(SPD_opteed) || defined(SPD_trusty) if (BL32_BASE >= start && (BL32_LIMIT - 1) <= end) mr_tee_atf_same = true; #endif @@ -275,7 +275,7 @@ void imx8_partition_resources(void) ERROR("Memreg get info failed, %u\n", mr_record); } else { if ((BL31_LIMIT - 1) < end) { -#ifdef SPD_trusty +#if defined(SPD_opteed) || defined(SPD_trusty) if ((end > BL32_BASE) && mr_tee_atf_same) reg_end = BL32_BASE - 1; #endif @@ -288,7 +288,7 @@ void imx8_partition_resources(void) ERROR("Memreg assign failed, 0x%llx -- 0x%llx\n", (sc_faddr_t)BL31_LIMIT, reg_end); } } -#ifdef SPD_trusty +#if defined(SPD_opteed) || defined(SPD_trusty) if (mr_tee_atf_same) { if ((BL32_LIMIT - 1) < end) { reg_start = BL32_LIMIT; @@ -297,8 +297,8 @@ void imx8_partition_resources(void) ERROR("sc_rm_memreg_alloc failed, 0x%llx -- 0x%llx\n", reg_start, reg_end); } else { err = sc_rm_assign_memreg(ipc_handle, os_part, mr); - if (err) - ERROR("Memreg assign failed, 0x%llx -- 0x%llx\n", reg_start, reg_end); + if (err) + ERROR("Memreg assign failed, 0x%llx -- 0x%llx\n", reg_start, reg_end); } } } @@ -441,13 +441,23 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, bl33_image_ep_info.pc = PLAT_NS_IMAGE_OFFSET; bl33_image_ep_info.spsr = get_spsr_for_bl33_entry(); -#ifdef SPD_trusty +#if defined(SPD_opteed) || defined(SPD_trusty) SET_PARAM_HEAD(&bl32_image_ep_info, PARAM_EP, VERSION_1, 0); SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE); bl32_image_ep_info.pc = BL32_BASE; bl32_image_ep_info.spsr = 0; +#ifdef SPD_trusty bl32_image_ep_info.args.arg0 = BL32_SIZE; bl32_image_ep_info.args.arg1 = BL32_BASE; +#endif +#ifdef SPD_opteed + bl33_image_ep_info.args.arg1 = BL32_BASE; + bl33_image_ep_info.args.arg2 = BL32_SIZE; + /* Make sure memory is clean */ + mmio_write_32(BL32_FDT_OVERLAY_ADDR, 0); + bl33_image_ep_info.args.arg3 = BL32_FDT_OVERLAY_ADDR; + bl32_image_ep_info.args.arg3 = BL32_FDT_OVERLAY_ADDR; +#endif #endif SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE); } @@ -469,7 +479,7 @@ void bl31_plat_arch_setup(void) MT_RW | MT_MEMORY | MT_SECURE); mmap_add(imx_mmap); -#ifdef SPD_trusty +#if defined(SPD_opteed) || defined(SPD_trusty) mmap_add_region(BL32_BASE, BL32_BASE, BL32_SIZE, MT_MEMORY | MT_RW); #endif diff --git a/plat/imx/imx8qx/include/platform_def.h b/plat/imx/imx8qx/include/platform_def.h index 785e3bf8..debcdafb 100644 --- a/plat/imx/imx8qx/include/platform_def.h +++ b/plat/imx/imx8qx/include/platform_def.h @@ -38,11 +38,14 @@ #define OCRAM_BASE 0x100000 #define OCRAM_ALIAS_SIZE 0x18000 /* The lower 96KB is in OCRAM alias from 0x0 */ +#define BL32_SHM_SIZE 0x00400000 #ifdef SPD_trusty -#define BL32_BASE 0xfe000000 -#define BL32_SIZE 0x02000000 -#define BL32_LIMIT 0x100000000 +#define BL32_LIMIT (BL32_BASE + BL32_SIZE) +#else +#define BL32_LIMIT (BL32_BASE + BL32_SIZE - BL32_SHM_SIZE) #endif +#define BL32_FDT_OVERLAY_ADDR 0x9d000000 + #define PLAT_VIRT_ADDR_SPACE_SIZE (1ull << 32) #define PLAT_PHY_ADDR_SPACE_SIZE (1ull << 32) diff --git a/plat/imx/imx8qx/platform.mk b/plat/imx/imx8qx/platform.mk index c4b67f25..269e78a6 100644 --- a/plat/imx/imx8qx/platform.mk +++ b/plat/imx/imx8qx/platform.mk @@ -41,6 +41,12 @@ $(eval $(call add_define,ENABLE_CPU_DYNAMIC_RETENTION)) ENABLE_L2_DYNAMIC_RETENTION := 1 $(eval $(call add_define,ENABLE_L2_DYNAMIC_RETENTION)) +BL32_BASE ?= 0xfe000000 +$(eval $(call add_define,BL32_BASE)) + +BL32_SIZE ?= 0x2000000 +$(eval $(call add_define,BL32_SIZE)) + ifeq (${SPD},trusty) BL31_CFLAGS += -DPLAT_XLAT_TABLES_DYNAMIC=1 endif -- cgit v1.2.3