Commit 0f14d02f authored by Max Shvetsov's avatar Max Shvetsov
Browse files

SPMD: SPMC init, SMC handler cosmetic changes



Change-Id: I8881d489994aea667e3dd59932ab4123f511d6ba
Signed-off-by: default avatarArtsem Artsemenka <artsem.artsemenka@arm.com>
Signed-off-by: default avatarMax Shvetsov <maksims.svecovs@arm.com>
parent e0f924a5
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <services/spci_svc.h> #include <services/spci_svc.h>
#include <stdint.h> #include <stdint.h>
int32_t spmd_setup(void); int spmd_setup(void);
uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t spmd_smc_handler(uint32_t smc_fid,
uint64_t x1, uint64_t x1,
uint64_t x2, uint64_t x2,
......
...@@ -33,7 +33,24 @@ spmd_spm_core_context_t spm_core_context[PLATFORM_CORE_COUNT]; ...@@ -33,7 +33,24 @@ spmd_spm_core_context_t spm_core_context[PLATFORM_CORE_COUNT];
/******************************************************************************* /*******************************************************************************
* SPM Core attribute information read from its manifest. * SPM Core attribute information read from its manifest.
******************************************************************************/ ******************************************************************************/
spmc_manifest_sect_attribute_t spmc_attrs; static spmc_manifest_sect_attribute_t spmc_attrs;
/*******************************************************************************
* SPM Core entry point information. Discovered on the primary core and reused
* on secondary cores.
******************************************************************************/
static entry_point_info_t *spmc_ep_info;
/*******************************************************************************
* Static function declaration.
******************************************************************************/
static int32_t spmd_init(void);
static int spmd_spmc_init(void *rd_base, size_t rd_size);
static uint64_t spmd_spci_error_return(void *handle, int error_code);
static uint64_t spmd_smc_forward(uint32_t smc_fid, uint32_t in_sstate,
uint32_t out_sstate, uint64_t x1,
uint64_t x2, uint64_t x3, uint64_t x4,
void *handle);
/******************************************************************************* /*******************************************************************************
* This function takes an SP context pointer and performs a synchronous entry * This function takes an SP context pointer and performs a synchronous entry
...@@ -111,63 +128,21 @@ static int32_t spmd_init(void) ...@@ -111,63 +128,21 @@ static int32_t spmd_init(void)
} }
/******************************************************************************* /*******************************************************************************
* Initialize context of SPM core. * Load SPMC manifest, init SPMC.
******************************************************************************/ ******************************************************************************/
int32_t spmd_setup(void) static int spmd_spmc_init(void *rd_base, size_t rd_size)
{ {
int rc; int rc;
void *rd_base;
size_t rd_size;
entry_point_info_t *spmc_ep_info;
uintptr_t rd_base_align;
uintptr_t rd_size_align;
uint32_t ep_attr; uint32_t ep_attr;
unsigned int linear_id = plat_my_core_pos();
spmc_ep_info = bl31_plat_get_next_image_ep_info(SECURE); spmd_spm_core_context_t *spm_ctx = &spm_core_context[linear_id];
if (!spmc_ep_info) {
WARN("No SPM core image provided by BL2 boot loader, Booting "
"device without SP initialization. SMC`s destined for SPM "
"core will return SMC_UNK\n");
return 1;
}
/* Under no circumstances will this parameter be 0 */
assert(spmc_ep_info->pc != 0U);
/*
* Check if BL32 ep_info has a reference to 'tos_fw_config'. This will
* be used as a manifest for the SPM core at the next lower EL/mode.
*/
if (spmc_ep_info->args.arg0 == 0U || spmc_ep_info->args.arg2 == 0U) {
ERROR("Invalid or absent SPM core manifest\n");
panic();
}
/* Obtain whereabouts of SPM core manifest */
rd_base = (void *) spmc_ep_info->args.arg0;
rd_size = spmc_ep_info->args.arg2;
rd_base_align = page_align((uintptr_t) rd_base, DOWN);
rd_size_align = page_align((uintptr_t) rd_size, UP);
/* Map the manifest in the SPMD translation regime first */
VERBOSE("SPM core manifest base : 0x%lx\n", rd_base_align);
VERBOSE("SPM core manifest size : 0x%lx\n", rd_size_align);
rc = mmap_add_dynamic_region((unsigned long long) rd_base_align,
(uintptr_t) rd_base_align,
rd_size_align,
MT_RO_DATA);
if (rc < 0) {
ERROR("Error while mapping SPM core manifest (%d).\n", rc);
panic();
}
/* Load the SPM core manifest */ /* Load the SPM core manifest */
rc = plat_spm_core_manifest_load(&spmc_attrs, rd_base, rd_size); rc = plat_spm_core_manifest_load(&spmc_attrs, rd_base, rd_size);
if (rc < 0) { if (rc != 0) {
WARN("No or invalid SPM core manifest image provided by BL2 " WARN("No or invalid SPM core manifest image provided by BL2 "
"boot loader. "); "boot loader. ");
goto error; return 1;
} }
/* /*
...@@ -179,7 +154,7 @@ int32_t spmd_setup(void) ...@@ -179,7 +154,7 @@ int32_t spmd_setup(void)
WARN("Unsupported SPCI version (%x.%x) specified in SPM core " WARN("Unsupported SPCI version (%x.%x) specified in SPM core "
"manifest image provided by BL2 boot loader.\n", "manifest image provided by BL2 boot loader.\n",
spmc_attrs.major_version, spmc_attrs.minor_version); spmc_attrs.major_version, spmc_attrs.minor_version);
goto error; return 1;
} }
INFO("SPCI version (%x.%x).\n", spmc_attrs.major_version, INFO("SPCI version (%x.%x).\n", spmc_attrs.major_version,
...@@ -191,7 +166,7 @@ int32_t spmd_setup(void) ...@@ -191,7 +166,7 @@ int32_t spmd_setup(void)
WARN("Unsupported SPM core run time EL%x specified in " WARN("Unsupported SPM core run time EL%x specified in "
"manifest image provided by BL2 boot loader.\n", "manifest image provided by BL2 boot loader.\n",
spmc_attrs.runtime_el); spmc_attrs.runtime_el);
goto error; return 1;
} }
INFO("SPM core run time EL%x.\n", spmc_attrs.runtime_el); INFO("SPM core run time EL%x.\n", spmc_attrs.runtime_el);
...@@ -202,7 +177,7 @@ int32_t spmd_setup(void) ...@@ -202,7 +177,7 @@ int32_t spmd_setup(void)
WARN("Unsupported SPM core execution state %x specified in " WARN("Unsupported SPM core execution state %x specified in "
"manifest image provided by BL2 boot loader.\n", "manifest image provided by BL2 boot loader.\n",
spmc_attrs.exec_state); spmc_attrs.exec_state);
goto error; return 1;
} }
INFO("SPM core execution state %x.\n", spmc_attrs.exec_state); INFO("SPM core execution state %x.\n", spmc_attrs.exec_state);
...@@ -213,7 +188,7 @@ int32_t spmd_setup(void) ...@@ -213,7 +188,7 @@ int32_t spmd_setup(void)
WARN("Invalid combination of SPM core execution state (%x) " WARN("Invalid combination of SPM core execution state (%x) "
"and run time EL (%x).\n", spmc_attrs.exec_state, "and run time EL (%x).\n", spmc_attrs.exec_state,
spmc_attrs.runtime_el); spmc_attrs.runtime_el);
goto error; return 1;
} }
/* /*
...@@ -230,14 +205,16 @@ int32_t spmd_setup(void) ...@@ -230,14 +205,16 @@ int32_t spmd_setup(void)
WARN("SPM core run time EL: S-EL%x is not supported " WARN("SPM core run time EL: S-EL%x is not supported "
"but specified in manifest image provided by " "but specified in manifest image provided by "
"BL2 boot loader.\n", spmc_attrs.runtime_el); "BL2 boot loader.\n", spmc_attrs.runtime_el);
goto error; return 1;
} }
} }
/* Initialise an entrypoint to set up the CPU context */ /* Initialise an entrypoint to set up the CPU context */
ep_attr = SECURE | EP_ST_ENABLE; ep_attr = SECURE | EP_ST_ENABLE;
if (read_sctlr_el3() & SCTLR_EE_BIT) if (read_sctlr_el3() & SCTLR_EE_BIT) {
ep_attr |= EP_EE_BIG; ep_attr |= EP_EE_BIG;
}
SET_PARAM_HEAD(spmc_ep_info, PARAM_EP, VERSION_1, ep_attr); SET_PARAM_HEAD(spmc_ep_info, PARAM_EP, VERSION_1, ep_attr);
assert(spmc_ep_info->pc == BL32_BASE); assert(spmc_ep_info->pc == BL32_BASE);
...@@ -258,8 +235,10 @@ int32_t spmd_setup(void) ...@@ -258,8 +235,10 @@ int32_t spmd_setup(void)
} }
/* Initialise SPM core context with this entry point information */ /* Initialise SPM core context with this entry point information */
cm_setup_context(&(spm_core_context[plat_my_core_pos()].cpu_ctx), cm_setup_context(&spm_ctx->cpu_ctx, spmc_ep_info);
spmc_ep_info);
/* Reuse PSCI affinity states to mark this SPMC context as off */
spm_ctx->state = AFF_STATE_OFF;
INFO("SPM core setup done.\n"); INFO("SPM core setup done.\n");
...@@ -267,20 +246,113 @@ int32_t spmd_setup(void) ...@@ -267,20 +246,113 @@ int32_t spmd_setup(void)
bl31_register_bl32_init(&spmd_init); bl31_register_bl32_init(&spmd_init);
return 0; return 0;
}
/*******************************************************************************
* Initialize context of SPM core.
******************************************************************************/
int spmd_setup(void)
{
int rc;
void *rd_base;
size_t rd_size;
uintptr_t rd_base_align;
uintptr_t rd_size_align;
spmc_ep_info = bl31_plat_get_next_image_ep_info(SECURE);
if (!spmc_ep_info) {
WARN("No SPM core image provided by BL2 boot loader, Booting "
"device without SP initialization. SMC`s destined for SPM "
"core will return SMC_UNK\n");
return 1;
}
/* Under no circumstances will this parameter be 0 */
assert(spmc_ep_info->pc != 0U);
/*
* Check if BL32 ep_info has a reference to 'tos_fw_config'. This will
* be used as a manifest for the SPM core at the next lower EL/mode.
*/
if (spmc_ep_info->args.arg0 == 0U || spmc_ep_info->args.arg2 == 0U) {
ERROR("Invalid or absent SPM core manifest\n");
panic();
}
/* Obtain whereabouts of SPM core manifest */
rd_base = (void *) spmc_ep_info->args.arg0;
rd_size = spmc_ep_info->args.arg2;
rd_base_align = page_align((uintptr_t) rd_base, DOWN);
rd_size_align = page_align((uintptr_t) rd_size, UP);
/* Map the manifest in the SPMD translation regime first */
VERBOSE("SPM core manifest base : 0x%lx\n", rd_base_align);
VERBOSE("SPM core manifest size : 0x%lx\n", rd_size_align);
rc = mmap_add_dynamic_region((unsigned long long) rd_base_align,
(uintptr_t) rd_base_align,
rd_size_align,
MT_RO_DATA);
if (rc != 0) {
ERROR("Error while mapping SPM core manifest (%d).\n", rc);
panic();
}
/* Load manifest, init SPMC */
rc = spmd_spmc_init(rd_base, rd_size);
if (rc != 0) {
int mmap_rc;
error:
WARN("Booting device without SPM initialization. " WARN("Booting device without SPM initialization. "
"SPCI SMCs destined for SPM core will return " "SPCI SMCs destined for SPM core will return "
"ENOTSUPPORTED\n"); "ENOTSUPPORTED\n");
rc = mmap_remove_dynamic_region(rd_base_align, rd_size_align); mmap_rc = mmap_remove_dynamic_region(rd_base_align,
if (rc < 0) { rd_size_align);
if (mmap_rc != 0) {
ERROR("Error while unmapping SPM core manifest (%d).\n", ERROR("Error while unmapping SPM core manifest (%d).\n",
rc); mmap_rc);
panic(); panic();
} }
return 1; return rc;
}
return 0;
}
/*******************************************************************************
* Forward SMC to the other security state
******************************************************************************/
static uint64_t spmd_smc_forward(uint32_t smc_fid, uint32_t in_sstate,
uint32_t out_sstate, uint64_t x1,
uint64_t x2, uint64_t x3, uint64_t x4,
void *handle)
{
/* Save incoming security state */
cm_el1_sysregs_context_save(in_sstate);
cm_el2_sysregs_context_save(in_sstate);
/* Restore outgoing security state */
cm_el1_sysregs_context_restore(out_sstate);
cm_el2_sysregs_context_restore(out_sstate);
cm_set_next_eret_context(out_sstate);
SMC_RET8(cm_get_context(out_sstate), smc_fid, x1, x2, x3, x4,
SMC_GET_GP(handle, CTX_GPREG_X5),
SMC_GET_GP(handle, CTX_GPREG_X6),
SMC_GET_GP(handle, CTX_GPREG_X7));
}
/*******************************************************************************
* Return SPCI_ERROR with specified error code
******************************************************************************/
static uint64_t spmd_spci_error_return(void *handle, int error_code)
{
SMC_RET8(handle, SPCI_ERROR,
SPCI_TARGET_INFO_MBZ, error_code,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ);
} }
/******************************************************************************* /*******************************************************************************
...@@ -318,22 +390,13 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -318,22 +390,13 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
* this CPU. If so, then indicate that the SPM core initialised * this CPU. If so, then indicate that the SPM core initialised
* unsuccessfully. * unsuccessfully.
*/ */
if ((in_sstate == SECURE) && (ctx->state == SPMC_STATE_RESET)) if ((in_sstate == SECURE) &&
(ctx->state == SPMC_STATE_RESET)) {
spmd_spm_core_sync_exit(x2); spmd_spm_core_sync_exit(x2);
}
/* Save incoming security state */ return spmd_smc_forward(smc_fid, in_sstate, out_sstate,
cm_el1_sysregs_context_save(in_sstate); x1, x2, x3, x4, handle);
cm_el2_sysregs_context_save(in_sstate);
/* Restore outgoing security state */
cm_el1_sysregs_context_restore(out_sstate);
cm_el2_sysregs_context_restore(out_sstate);
cm_set_next_eret_context(out_sstate);
SMC_RET8(cm_get_context(out_sstate), smc_fid, x1, x2, x3, x4,
SMC_GET_GP(handle, CTX_GPREG_X5),
SMC_GET_GP(handle, CTX_GPREG_X6),
SMC_GET_GP(handle, CTX_GPREG_X7));
break; /* not reached */ break; /* not reached */
case SPCI_VERSION: case SPCI_VERSION:
...@@ -357,31 +420,18 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -357,31 +420,18 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
*/ */
/* /*
* Check if w1 holds a valid SPCI fid. This is an * Check if x1 holds a valid SPCI fid. This is an
* optimization. * optimization.
*/ */
if (!is_spci_fid(x1)) if (!is_spci_fid(x1)) {
SMC_RET8(handle, SPCI_ERROR, return spmd_spci_error_return(handle,
SPCI_TARGET_INFO_MBZ, SPCI_ERROR_NOT_SUPPORTED, SPCI_ERROR_NOT_SUPPORTED);
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, }
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ);
/* Forward SMC from Normal world to the SPM core */ /* Forward SMC from Normal world to the SPM core */
if (in_sstate == NON_SECURE) { if (in_sstate == NON_SECURE) {
/* Save incoming security state */ return spmd_smc_forward(smc_fid, in_sstate, out_sstate,
cm_el1_sysregs_context_save(in_sstate); x1, x2, x3, x4, handle);
cm_el2_sysregs_context_save(in_sstate);
/* Restore outgoing security state */
cm_el1_sysregs_context_restore(out_sstate);
cm_el2_sysregs_context_restore(out_sstate);
cm_set_next_eret_context(out_sstate);
SMC_RET8(cm_get_context(out_sstate), smc_fid,
x1, x2, x3, x4,
SMC_GET_GP(handle, CTX_GPREG_X5),
SMC_GET_GP(handle, CTX_GPREG_X6),
SMC_GET_GP(handle, CTX_GPREG_X7));
} else { } else {
/* /*
* Return success if call was from secure world i.e. all * Return success if call was from secure world i.e. all
...@@ -393,6 +443,7 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -393,6 +443,7 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
SMC_GET_GP(handle, CTX_GPREG_X6), SMC_GET_GP(handle, CTX_GPREG_X6),
SMC_GET_GP(handle, CTX_GPREG_X7)); SMC_GET_GP(handle, CTX_GPREG_X7));
} }
break; /* not reached */ break; /* not reached */
case SPCI_RX_RELEASE: case SPCI_RX_RELEASE:
...@@ -402,10 +453,8 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -402,10 +453,8 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
case SPCI_MSG_RUN: case SPCI_MSG_RUN:
/* This interface must be invoked only by the Normal world */ /* This interface must be invoked only by the Normal world */
if (in_sstate == SECURE) { if (in_sstate == SECURE) {
SMC_RET8(handle, SPCI_ERROR, return spmd_spci_error_return(handle,
SPCI_TARGET_INFO_MBZ, SPCI_ERROR_NOT_SUPPORTED, SPCI_ERROR_NOT_SUPPORTED);
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ);
} }
/* Fall through to forward the call to the other world */ /* Fall through to forward the call to the other world */
...@@ -436,19 +485,8 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -436,19 +485,8 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
* simply forward the call to the Normal world. * simply forward the call to the Normal world.
*/ */
/* Save incoming security state */ return spmd_smc_forward(smc_fid, in_sstate, out_sstate,
cm_el1_sysregs_context_save(in_sstate); x1, x2, x3, x4, handle);
cm_el2_sysregs_context_save(in_sstate);
/* Restore outgoing security state */
cm_el1_sysregs_context_restore(out_sstate);
cm_el2_sysregs_context_restore(out_sstate);
cm_set_next_eret_context(out_sstate);
SMC_RET8(cm_get_context(out_sstate), smc_fid, x1, x2, x3, x4,
SMC_GET_GP(handle, CTX_GPREG_X5),
SMC_GET_GP(handle, CTX_GPREG_X6),
SMC_GET_GP(handle, CTX_GPREG_X7));
break; /* not reached */ break; /* not reached */
case SPCI_MSG_WAIT: case SPCI_MSG_WAIT:
...@@ -461,37 +499,21 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -461,37 +499,21 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
spmd_spm_core_sync_exit(0); spmd_spm_core_sync_exit(0);
} }
/* Intentional fall-through */ /* Fall through to forward the call to the other world */
case SPCI_MSG_YIELD: case SPCI_MSG_YIELD:
/* This interface must be invoked only by the Secure world */ /* This interface must be invoked only by the Secure world */
if (in_sstate == NON_SECURE) { if (in_sstate == NON_SECURE) {
SMC_RET8(handle, SPCI_ERROR, return spmd_spci_error_return(handle,
SPCI_TARGET_INFO_MBZ, SPCI_ERROR_NOT_SUPPORTED, SPCI_ERROR_NOT_SUPPORTED);
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ);
} }
/* Save incoming security state */ return spmd_smc_forward(smc_fid, in_sstate, out_sstate,
cm_el1_sysregs_context_save(in_sstate); x1, x2, x3, x4, handle);
cm_el2_sysregs_context_save(in_sstate);
/* Restore outgoing security state */
cm_el1_sysregs_context_restore(out_sstate);
cm_el2_sysregs_context_restore(out_sstate);
cm_set_next_eret_context(out_sstate);
SMC_RET8(cm_get_context(out_sstate), smc_fid, x1, x2, x3, x4,
SMC_GET_GP(handle, CTX_GPREG_X5),
SMC_GET_GP(handle, CTX_GPREG_X6),
SMC_GET_GP(handle, CTX_GPREG_X7));
break; /* not reached */ break; /* not reached */
default: default:
WARN("SPM: Unsupported call 0x%08x\n", smc_fid); WARN("SPM: Unsupported call 0x%08x\n", smc_fid);
SMC_RET8(handle, SPCI_ERROR, return spmd_spci_error_return(handle, SPCI_ERROR_NOT_SUPPORTED);
SPCI_TARGET_INFO_MBZ, SPCI_ERROR_NOT_SUPPORTED,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment