Commit 52696946 authored by Olivier Deprez's avatar Olivier Deprez
Browse files

SPMD: code/comments cleanup

As a follow-up to bdd2596d

, and related to SPM Dispatcher
EL3 component and SPM Core S-EL2/S-EL1 component: update
with cosmetic and coding rules changes. In addition:
-Add Armv8.4-SecEL2 arch detection helper.
-Add an SPMC context (on current core) get helper.
-Return more meaningful error return codes.
-Remove complexity in few spmd_smc_handler switch-cases.
-Remove unused defines and structures from spmd_private.h
Signed-off-by: default avatarOlivier Deprez <olivier.deprez@arm.com>
Change-Id: I99e642450b0dafb19d3218a2f0e2d3107e8ca3fe
parent 4e2887f2
/* /*
* Copyright (c) 2019, Arm Limited. All rights reserved. * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -52,4 +52,10 @@ static inline unsigned int get_armv8_5_mte_support(void) ...@@ -52,4 +52,10 @@ static inline unsigned int get_armv8_5_mte_support(void)
ID_AA64PFR1_EL1_MTE_MASK); ID_AA64PFR1_EL1_MTE_MASK);
} }
static inline bool is_armv8_4_sel2_present(void)
{
return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SEL2_SHIFT) &
ID_AA64PFR0_SEL2_MASK) == 1ULL;
}
#endif /* ARCH_FEATURES_H */ #endif /* ARCH_FEATURES_H */
...@@ -289,7 +289,7 @@ int plat_spm_sp_rd_load(struct sp_res_desc *rd, const void *ptr, size_t size); ...@@ -289,7 +289,7 @@ int plat_spm_sp_rd_load(struct sp_res_desc *rd, const void *ptr, size_t size);
int plat_spm_sp_get_next_address(void **sp_base, size_t *sp_size, int plat_spm_sp_get_next_address(void **sp_base, size_t *sp_size,
void **rd_base, size_t *rd_size); void **rd_base, size_t *rd_size);
#if defined(SPD_spmd) #if defined(SPD_spmd)
int plat_spm_core_manifest_load(spmc_manifest_sect_attribute_t *manifest, int plat_spm_core_manifest_load(spmc_manifest_attribute_t *manifest,
const void *ptr, const void *ptr,
size_t size); size_t size);
#endif #endif
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef SPMC_MANIFEST_H #ifndef SPM_CORE_MANIFEST_H
#define SPMC_MANIFEST_H #define SPM_CORE_MANIFEST_H
#include <stdint.h> #include <stdint.h>
...@@ -28,18 +28,18 @@ typedef struct spm_core_manifest_sect_attribute { ...@@ -28,18 +28,18 @@ typedef struct spm_core_manifest_sect_attribute {
uint32_t exec_state; uint32_t exec_state;
/* /*
* Address of binary image containing SPM core in bytes (optional). * Address of binary image containing SPM Core (optional).
*/ */
uint64_t load_address; uint64_t load_address;
/* /*
* Offset from the base of the partition's binary image to the entry * Offset from the base of the partition's binary image to the entry
* point of the partition. * point of the partition (optional).
*/ */
uint64_t entrypoint; uint64_t entrypoint;
/* /*
* Size of binary image containing SPM core in bytes (mandatory). * Size of binary image containing SPM Core in bytes (mandatory).
*/ */
uint32_t binary_size; uint32_t binary_size;
...@@ -48,6 +48,6 @@ typedef struct spm_core_manifest_sect_attribute { ...@@ -48,6 +48,6 @@ typedef struct spm_core_manifest_sect_attribute {
*/ */
uint16_t spmc_id; uint16_t spmc_id;
} spmc_manifest_sect_attribute_t; } spmc_manifest_attribute_t;
#endif /* SPMC_MANIFEST_H */ #endif /* SPM_CORE_MANIFEST_H */
...@@ -5,65 +5,78 @@ ...@@ -5,65 +5,78 @@
*/ */
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <libfdt.h> #include <libfdt.h>
#include <common/debug.h> #include <common/debug.h>
#include <common/fdt_wrappers.h> #include <common/fdt_wrappers.h>
#include <errno.h>
#include <platform_def.h> #include <platform_def.h>
#include <services/spm_core_manifest.h> #include <services/spm_core_manifest.h>
#define ATTRIBUTE_ROOT_NODE_STR "attribute"
/******************************************************************************* /*******************************************************************************
* Attribute section handler * SPMC attribute node parser
******************************************************************************/ ******************************************************************************/
static int manifest_parse_attribute(spmc_manifest_sect_attribute_t *attr, static int manifest_parse_attribute(spmc_manifest_attribute_t *attr,
const void *fdt, const void *fdt,
int node) int node)
{ {
uint32_t val32; uint32_t val32;
int rc = 0; int rc;
assert(attr && fdt); assert((attr != NULL) && (fdt != NULL));
rc = fdt_read_uint32(fdt, node, "maj_ver", &attr->major_version); rc = fdt_read_uint32(fdt, node, "maj_ver", &attr->major_version);
if (rc) { if (rc != 0) {
ERROR("Missing SPCI major version in SPM core manifest.\n"); ERROR("Missing SPCI %s version in SPM Core manifest.\n",
return -ENOENT; "major");
return rc;
} }
rc = fdt_read_uint32(fdt, node, "min_ver", &attr->minor_version); rc = fdt_read_uint32(fdt, node, "min_ver", &attr->minor_version);
if (rc) { if (rc != 0) {
ERROR("Missing SPCI minor version in SPM core manifest.\n"); ERROR("Missing SPCI %s version in SPM Core manifest.\n",
return -ENOENT; "minor");
return rc;
} }
rc = fdt_read_uint32(fdt, node, "spmc_id", &val32); rc = fdt_read_uint32(fdt, node, "spmc_id", &val32);
if (rc) { if (rc != 0) {
ERROR("Missing SPMC ID in manifest.\n"); ERROR("Missing SPMC ID in manifest.\n");
return -ENOENT; return rc;
} }
attr->spmc_id = val32;
attr->spmc_id = val32 & 0xffff;
rc = fdt_read_uint32(fdt, node, "exec_state", &attr->exec_state); rc = fdt_read_uint32(fdt, node, "exec_state", &attr->exec_state);
if (rc) if (rc != 0) {
NOTICE("Execution state not specified in SPM core manifest.\n"); NOTICE("%s not specified in SPM Core manifest.\n",
"Execution state");
}
rc = fdt_read_uint32(fdt, node, "binary_size", &attr->binary_size); rc = fdt_read_uint32(fdt, node, "binary_size", &attr->binary_size);
if (rc) if (rc != 0) {
NOTICE("Binary size not specified in SPM core manifest.\n"); NOTICE("%s not specified in SPM Core manifest.\n",
"Binary size");
}
rc = fdt_read_uint64(fdt, node, "load_address", &attr->load_address); rc = fdt_read_uint64(fdt, node, "load_address", &attr->load_address);
if (rc) if (rc != 0) {
NOTICE("Load address not specified in SPM core manifest.\n"); NOTICE("%s not specified in SPM Core manifest.\n",
"Load address");
}
rc = fdt_read_uint64(fdt, node, "entrypoint", &attr->entrypoint); rc = fdt_read_uint64(fdt, node, "entrypoint", &attr->entrypoint);
if (rc) if (rc != 0) {
NOTICE("Entrypoint not specified in SPM core manifest.\n"); NOTICE("%s not specified in SPM Core manifest.\n",
"Entry point");
}
VERBOSE("SPM core manifest attribute section:\n"); VERBOSE("SPM Core manifest attribute section:\n");
VERBOSE(" version: %x.%x\n", attr->major_version, attr->minor_version); VERBOSE(" version: %u.%u\n", attr->major_version, attr->minor_version);
VERBOSE(" spmc_id: %x\n", attr->spmc_id); VERBOSE(" spmc_id: 0x%x\n", attr->spmc_id);
VERBOSE(" binary_size: 0x%x\n", attr->binary_size); VERBOSE(" binary_size: 0x%x\n", attr->binary_size);
VERBOSE(" load_address: 0x%llx\n", attr->load_address); VERBOSE(" load_address: 0x%llx\n", attr->load_address);
VERBOSE(" entrypoint: 0x%llx\n", attr->entrypoint); VERBOSE(" entrypoint: 0x%llx\n", attr->entrypoint);
...@@ -74,53 +87,51 @@ static int manifest_parse_attribute(spmc_manifest_sect_attribute_t *attr, ...@@ -74,53 +87,51 @@ static int manifest_parse_attribute(spmc_manifest_sect_attribute_t *attr,
/******************************************************************************* /*******************************************************************************
* Root node handler * Root node handler
******************************************************************************/ ******************************************************************************/
static int manifest_parse_root(spmc_manifest_sect_attribute_t *manifest, static int manifest_parse_root(spmc_manifest_attribute_t *manifest,
const void *fdt, const void *fdt,
int root) int root)
{ {
int node; int node;
char *str;
str = "attribute"; assert(manifest != NULL);
node = fdt_subnode_offset_namelen(fdt, root, str, strlen(str));
node = fdt_subnode_offset_namelen(fdt, root, ATTRIBUTE_ROOT_NODE_STR,
sizeof(ATTRIBUTE_ROOT_NODE_STR) - 1);
if (node < 0) { if (node < 0) {
ERROR("Root node doesn't contain subnode '%s'\n", str); ERROR("Root node doesn't contain subnode '%s'\n",
return -ENOENT; ATTRIBUTE_ROOT_NODE_STR);
return node;
} }
return manifest_parse_attribute(manifest, fdt, node); return manifest_parse_attribute(manifest, fdt, node);
} }
/******************************************************************************* /*******************************************************************************
* Platform handler to parse a SPM core manifest. * Platform handler to parse a SPM Core manifest.
******************************************************************************/ ******************************************************************************/
int plat_spm_core_manifest_load(spmc_manifest_sect_attribute_t *manifest, int plat_spm_core_manifest_load(spmc_manifest_attribute_t *manifest,
const void *ptr, const void *ptr,
size_t size) size_t size)
{ {
int rc; int rc;
int root_node;
assert(manifest != NULL); assert(manifest != NULL);
assert(ptr != NULL); assert(ptr != NULL);
INFO("Reading SPM core manifest at address %p\n", ptr); INFO("Reading SPM Core manifest at address %p\n", ptr);
rc = fdt_check_header(ptr); rc = fdt_check_header(ptr);
if (rc != 0) { if (rc != 0) {
ERROR("Wrong format for SPM core manifest (%d).\n", rc); ERROR("Wrong format for SPM Core manifest (%d).\n", rc);
return -EINVAL; return rc;
} }
INFO("Reading SPM core manifest at address %p\n", ptr); rc = fdt_node_offset_by_compatible(ptr, -1,
root_node = fdt_node_offset_by_compatible(ptr, -1,
"arm,spci-core-manifest-1.0"); "arm,spci-core-manifest-1.0");
if (root_node < 0) { if (rc < 0) {
ERROR("Unrecognized SPM core manifest\n"); ERROR("Unrecognized SPM Core manifest\n");
return -ENOENT; return rc;
} }
INFO("Reading SPM core manifest at address %p\n", ptr); return manifest_parse_root(manifest, ptr, rc);
return manifest_parse_root(manifest, ptr, root_node);
} }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string.h> #include <string.h>
#include <arch_helpers.h> #include <arch_helpers.h>
#include <arch/aarch64/arch_features.h>
#include <bl31/bl31.h> #include <bl31/bl31.h>
#include <common/debug.h> #include <common/debug.h>
#include <common/runtime_svc.h> #include <common/runtime_svc.h>
...@@ -28,12 +29,12 @@ ...@@ -28,12 +29,12 @@
/******************************************************************************* /*******************************************************************************
* SPM Core context information. * SPM Core context information.
******************************************************************************/ ******************************************************************************/
spmd_spm_core_context_t spm_core_context[PLATFORM_CORE_COUNT]; static 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.
******************************************************************************/ ******************************************************************************/
static spmc_manifest_sect_attribute_t spmc_attrs; static spmc_manifest_attribute_t spmc_attrs;
/******************************************************************************* /*******************************************************************************
* SPM Core entry point information. Discovered on the primary core and reused * SPM Core entry point information. Discovered on the primary core and reused
...@@ -41,19 +42,35 @@ static spmc_manifest_sect_attribute_t spmc_attrs; ...@@ -41,19 +42,35 @@ static spmc_manifest_sect_attribute_t spmc_attrs;
******************************************************************************/ ******************************************************************************/
static entry_point_info_t *spmc_ep_info; static entry_point_info_t *spmc_ep_info;
/*******************************************************************************
* SPM Core context on current CPU get helper.
******************************************************************************/
spmd_spm_core_context_t *spmd_get_context(void)
{
unsigned int linear_id = plat_my_core_pos();
return &spm_core_context[linear_id];
}
/******************************************************************************* /*******************************************************************************
* Static function declaration. * Static function declaration.
******************************************************************************/ ******************************************************************************/
static int32_t spmd_init(void); static int32_t spmd_init(void);
static int spmd_spmc_init(void *rd_base, size_t rd_size); static int spmd_spmc_init(void *rd_base,
static uint64_t spmd_spci_error_return(void *handle, int error_code); size_t rd_size);
static uint64_t spmd_smc_forward(uint32_t smc_fid, bool secure_origin, static uint64_t spmd_spci_error_return(void *handle,
uint64_t x1, uint64_t x2, uint64_t x3, int error_code);
uint64_t x4, void *handle); static uint64_t spmd_smc_forward(uint32_t smc_fid,
bool secure_origin,
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 SPMC context pointer and performs a synchronous
* into it. * SPMC entry.
******************************************************************************/ ******************************************************************************/
uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *spmc_ctx) uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *spmc_ctx)
{ {
...@@ -83,14 +100,14 @@ uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *spmc_ctx) ...@@ -83,14 +100,14 @@ uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *spmc_ctx)
} }
/******************************************************************************* /*******************************************************************************
* This function returns to the place where spm_sp_synchronous_entry() was * This function returns to the place where spmd_spm_core_sync_entry() was
* called originally. * called originally.
******************************************************************************/ ******************************************************************************/
__dead2 void spmd_spm_core_sync_exit(uint64_t rc) __dead2 void spmd_spm_core_sync_exit(uint64_t rc)
{ {
spmd_spm_core_context_t *ctx = &spm_core_context[plat_my_core_pos()]; spmd_spm_core_context_t *ctx = spmd_get_context();
/* Get context of the SP in use by this CPU. */ /* Get current CPU context from SPMC context */
assert(cm_get_context(SECURE) == &(ctx->cpu_ctx)); assert(cm_get_context(SECURE) == &(ctx->cpu_ctx));
/* /*
...@@ -104,110 +121,98 @@ __dead2 void spmd_spm_core_sync_exit(uint64_t rc) ...@@ -104,110 +121,98 @@ __dead2 void spmd_spm_core_sync_exit(uint64_t rc)
} }
/******************************************************************************* /*******************************************************************************
* Jump to the SPM core for the first time. * Jump to the SPM Core for the first time.
******************************************************************************/ ******************************************************************************/
static int32_t spmd_init(void) static int32_t spmd_init(void)
{ {
uint64_t rc = 0; spmd_spm_core_context_t *ctx = spmd_get_context();
spmd_spm_core_context_t *ctx = &spm_core_context[plat_my_core_pos()]; uint64_t rc;
INFO("SPM Core init start.\n"); VERBOSE("SPM Core init start.\n");
ctx->state = SPMC_STATE_RESET; ctx->state = SPMC_STATE_RESET;
rc = spmd_spm_core_sync_entry(ctx); rc = spmd_spm_core_sync_entry(ctx);
if (rc) { if (rc != 0ULL) {
ERROR("SPMC initialisation failed 0x%llx\n", rc); ERROR("SPMC initialisation failed 0x%llx\n", rc);
panic(); return 0;
} }
ctx->state = SPMC_STATE_IDLE; ctx->state = SPMC_STATE_IDLE;
INFO("SPM Core init end.\n"); VERBOSE("SPM Core init end.\n");
return 1; return 1;
} }
/******************************************************************************* /*******************************************************************************
* Load SPMC manifest, init SPMC. * Loads SPMC manifest and inits SPMC.
******************************************************************************/ ******************************************************************************/
static int spmd_spmc_init(void *rd_base, size_t rd_size) static int spmd_spmc_init(void *rd_base, size_t rd_size)
{ {
int rc; spmd_spm_core_context_t *spm_ctx = spmd_get_context();
uint32_t ep_attr; uint32_t ep_attr;
unsigned int linear_id = plat_my_core_pos(); int rc;
spmd_spm_core_context_t *spm_ctx = &spm_core_context[linear_id];
/* 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\n");
"boot loader. "); return rc;
return 1;
} }
/* /*
* Ensure that the SPM core version is compatible with the SPM * Ensure that the SPM Core version is compatible with the SPM
* dispatcher version * Dispatcher version.
*/ */
if ((spmc_attrs.major_version != SPCI_VERSION_MAJOR) || if ((spmc_attrs.major_version != SPCI_VERSION_MAJOR) ||
(spmc_attrs.minor_version > SPCI_VERSION_MINOR)) { (spmc_attrs.minor_version > SPCI_VERSION_MINOR)) {
WARN("Unsupported SPCI version (%x.%x) specified in SPM core " WARN("Unsupported SPCI version (%u.%u)\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);
return 1; return -EINVAL;
} }
INFO("SPCI version (%x.%x).\n", spmc_attrs.major_version, VERBOSE("SPCI version (%u.%u).\n", spmc_attrs.major_version,
spmc_attrs.minor_version); spmc_attrs.minor_version);
INFO("SPM core run time EL%x.\n", VERBOSE("SPM Core run time EL%x.\n",
SPMD_SPM_AT_SEL2 ? MODE_EL2 : MODE_EL1); SPMD_SPM_AT_SEL2 ? MODE_EL2 : MODE_EL1);
/* Validate the SPMC ID, Ensure high bit is set */ /* Validate the SPMC ID, Ensure high bit is set */
if (!(spmc_attrs.spmc_id >> SPMC_SECURE_ID_SHIFT) & if (((spmc_attrs.spmc_id >> SPMC_SECURE_ID_SHIFT) &
SPMC_SECURE_ID_MASK) { SPMC_SECURE_ID_MASK) == 0U) {
WARN("Invalid ID (0x%x) for SPMC.\n", WARN("Invalid ID (0x%x) for SPMC.\n", spmc_attrs.spmc_id);
spmc_attrs.spmc_id); return -EINVAL;
return 1;
} }
INFO("SPMC ID %x.\n", spmc_attrs.spmc_id); /* Validate the SPM Core execution state */
/* Validate the SPM core execution state */
if ((spmc_attrs.exec_state != MODE_RW_64) && if ((spmc_attrs.exec_state != MODE_RW_64) &&
(spmc_attrs.exec_state != MODE_RW_32)) { (spmc_attrs.exec_state != MODE_RW_32)) {
WARN("Unsupported SPM core execution state %x specified in " WARN("Unsupported SPM Core execution state 0x%x.\n",
"manifest image provided by BL2 boot loader.\n",
spmc_attrs.exec_state); spmc_attrs.exec_state);
return 1; return -EINVAL;
} }
INFO("SPM core execution state %x.\n", spmc_attrs.exec_state); VERBOSE("SPM Core execution state 0x%x.\n", spmc_attrs.exec_state);
#if SPMD_SPM_AT_SEL2 #if SPMD_SPM_AT_SEL2
/* Ensure manifest has not requested AArch32 state in S-EL2 */ /* Ensure manifest has not requested AArch32 state in S-EL2 */
if (spmc_attrs.exec_state == MODE_RW_32) { if (spmc_attrs.exec_state == MODE_RW_32) {
WARN("AArch32 state at S-EL2 is not supported.\n"); WARN("AArch32 state at S-EL2 is not supported.\n");
return 1; return -EINVAL;
} }
/* /*
* Check if S-EL2 is supported on this system if S-EL2 * Check if S-EL2 is supported on this system if S-EL2
* is required for SPM * is required for SPM
*/ */
uint64_t sel2 = read_id_aa64pfr0_el1(); if (!is_armv8_4_sel2_present()) {
WARN("SPM Core run time S-EL2 is not supported.\n");
sel2 >>= ID_AA64PFR0_SEL2_SHIFT; return -EINVAL;
sel2 &= ID_AA64PFR0_SEL2_MASK;
if (!sel2) {
WARN("SPM core run time S-EL2 is not supported.");
return 1;
} }
#endif /* SPMD_SPM_AT_SEL2 */ #endif /* SPMD_SPM_AT_SEL2 */
/* 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) != 0ULL) {
ep_attr |= EP_EE_BIG; ep_attr |= EP_EE_BIG;
} }
...@@ -215,8 +220,8 @@ static int spmd_spmc_init(void *rd_base, size_t rd_size) ...@@ -215,8 +220,8 @@ static int spmd_spmc_init(void *rd_base, size_t rd_size)
assert(spmc_ep_info->pc == BL32_BASE); assert(spmc_ep_info->pc == BL32_BASE);
/* /*
* Populate SPSR for SPM core based upon validated parameters from the * Populate SPSR for SPM Core based upon validated parameters from the
* manifest * manifest.
*/ */
if (spmc_attrs.exec_state == MODE_RW_32) { if (spmc_attrs.exec_state == MODE_RW_32) {
spmc_ep_info->spsr = SPSR_MODE32(MODE32_svc, SPSR_T_ARM, spmc_ep_info->spsr = SPSR_MODE32(MODE32_svc, SPSR_T_ARM,
...@@ -236,22 +241,22 @@ static int spmd_spmc_init(void *rd_base, size_t rd_size) ...@@ -236,22 +241,22 @@ static int spmd_spmc_init(void *rd_base, size_t rd_size)
DISABLE_ALL_EXCEPTIONS); DISABLE_ALL_EXCEPTIONS);
} }
/* Initialise SPM core context with this entry point information */ /* Initialise SPM Core context with this entry point information */
cm_setup_context(&spm_ctx->cpu_ctx, spmc_ep_info); cm_setup_context(&spm_ctx->cpu_ctx, spmc_ep_info);
/* Reuse PSCI affinity states to mark this SPMC context as off */ /* Reuse PSCI affinity states to mark this SPMC context as off */
spm_ctx->state = AFF_STATE_OFF; spm_ctx->state = AFF_STATE_OFF;
INFO("SPM core setup done.\n"); INFO("SPM Core setup done.\n");
/* Register init function for deferred init. */ /* Register init function for deferred init. */
bl31_register_bl32_init(&spmd_init); bl31_register_bl32_init(&spmd_init);
return 0; return 0;
} }
/******************************************************************************* /*******************************************************************************
* Initialize context of SPM core. * Initialize context of SPM Core.
******************************************************************************/ ******************************************************************************/
int spmd_setup(void) int spmd_setup(void)
{ {
...@@ -262,26 +267,24 @@ int spmd_setup(void) ...@@ -262,26 +267,24 @@ int spmd_setup(void)
uintptr_t rd_size_align; uintptr_t rd_size_align;
spmc_ep_info = bl31_plat_get_next_image_ep_info(SECURE); spmc_ep_info = bl31_plat_get_next_image_ep_info(SECURE);
if (!spmc_ep_info) { if (spmc_ep_info == NULL) {
WARN("No SPM core image provided by BL2 boot loader, Booting " WARN("No SPM Core image provided by BL2 boot loader.\n");
"device without SP initialization. SMC`s destined for SPM " return -EINVAL;
"core will return SMC_UNK\n");
return 1;
} }
/* Under no circumstances will this parameter be 0 */ /* Under no circumstances will this parameter be 0 */
assert(spmc_ep_info->pc != 0U); assert(spmc_ep_info->pc != 0ULL);
/* /*
* Check if BL32 ep_info has a reference to 'tos_fw_config'. This will * 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. * 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) { if (spmc_ep_info->args.arg0 == 0U || spmc_ep_info->args.arg2 == 0U) {
ERROR("Invalid or absent SPM core manifest\n"); ERROR("Invalid or absent SPM core manifest\n");
panic(); panic();
} }
/* Obtain whereabouts of SPM core manifest */ /* Obtain whereabouts of SPM Core manifest */
rd_base = (void *) spmc_ep_info->args.arg0; rd_base = (void *) spmc_ep_info->args.arg0;
rd_size = spmc_ep_info->args.arg2; rd_size = spmc_ep_info->args.arg2;
...@@ -305,9 +308,7 @@ int spmd_setup(void) ...@@ -305,9 +308,7 @@ int spmd_setup(void)
if (rc != 0) { if (rc != 0) {
int mmap_rc; int mmap_rc;
WARN("Booting device without SPM initialization. " WARN("Booting device without SPM initialization.\n");
"SPCI SMCs destined for SPM core will return "
"ENOTSUPPORTED\n");
mmap_rc = mmap_remove_dynamic_region(rd_base_align, mmap_rc = mmap_remove_dynamic_region(rd_base_align,
rd_size_align); rd_size_align);
...@@ -326,9 +327,13 @@ int spmd_setup(void) ...@@ -326,9 +327,13 @@ int spmd_setup(void)
/******************************************************************************* /*******************************************************************************
* Forward SMC to the other security state * Forward SMC to the other security state
******************************************************************************/ ******************************************************************************/
static uint64_t spmd_smc_forward(uint32_t smc_fid, bool secure_origin, static uint64_t spmd_smc_forward(uint32_t smc_fid,
uint64_t x1, uint64_t x2, uint64_t x3, bool secure_origin,
uint64_t x4, void *handle) uint64_t x1,
uint64_t x2,
uint64_t x3,
uint64_t x4,
void *handle)
{ {
uint32_t secure_state_in = (secure_origin) ? SECURE : NON_SECURE; uint32_t secure_state_in = (secure_origin) ? SECURE : NON_SECURE;
uint32_t secure_state_out = (!secure_origin) ? SECURE : NON_SECURE; uint32_t secure_state_out = (!secure_origin) ? SECURE : NON_SECURE;
...@@ -367,19 +372,23 @@ static uint64_t spmd_spci_error_return(void *handle, int error_code) ...@@ -367,19 +372,23 @@ static uint64_t spmd_spci_error_return(void *handle, int error_code)
* This function handles all SMCs in the range reserved for SPCI. Each call is * This function handles all SMCs in the range reserved for SPCI. Each call is
* either forwarded to the other security state or handled by the SPM dispatcher * either forwarded to the other security state or handled by the SPM dispatcher
******************************************************************************/ ******************************************************************************/
uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t spmd_smc_handler(uint32_t smc_fid,
uint64_t x3, uint64_t x4, void *cookie, void *handle, uint64_t x1,
uint64_t x2,
uint64_t x3,
uint64_t x4,
void *cookie,
void *handle,
uint64_t flags) uint64_t flags)
{ {
spmd_spm_core_context_t *ctx = &spm_core_context[plat_my_core_pos()]; spmd_spm_core_context_t *ctx = spmd_get_context();
bool secure_origin; bool secure_origin;
int32_t ret; int32_t ret;
/* Determine which security state this SMC originated from */ /* Determine which security state this SMC originated from */
secure_origin = is_caller_secure(flags); secure_origin = is_caller_secure(flags);
INFO("SPM: 0x%x, 0x%llx, 0x%llx, 0x%llx, 0x%llx, " INFO("SPM: 0x%x 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx\n",
"0x%llx, 0x%llx, 0x%llx\n",
smc_fid, x1, x2, x3, x4, SMC_GET_GP(handle, CTX_GPREG_X5), 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_X6),
SMC_GET_GP(handle, CTX_GPREG_X7)); SMC_GET_GP(handle, CTX_GPREG_X7));
...@@ -388,7 +397,7 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -388,7 +397,7 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
case SPCI_ERROR: case SPCI_ERROR:
/* /*
* Check if this is the first invocation of this interface on * Check if this is the first invocation of this interface on
* 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 (secure_origin && (ctx->state == SPMC_STATE_RESET)) { if (secure_origin && (ctx->state == SPMC_STATE_RESET)) {
...@@ -402,9 +411,9 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -402,9 +411,9 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
case SPCI_VERSION: case SPCI_VERSION:
/* /*
* TODO: This is an optimization that the version information * TODO: This is an optimization that the version information
* provided by the SPM core manifest is returned by the SPM * provided by the SPM Core manifest is returned by the SPM
* dispatcher. It might be a better idea to simply forward this * dispatcher. It might be a better idea to simply forward this
* call to the SPM core and wash our hands completely. * call to the SPM Core and wash our hands completely.
*/ */
ret = MAKE_SPCI_VERSION(spmc_attrs.major_version, ret = MAKE_SPCI_VERSION(spmc_attrs.major_version,
spmc_attrs.minor_version); spmc_attrs.minor_version);
...@@ -416,7 +425,7 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -416,7 +425,7 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
case SPCI_FEATURES: case SPCI_FEATURES:
/* /*
* This is an optional interface. Do the minimal checks and * This is an optional interface. Do the minimal checks and
* forward to SPM core which will handle it if implemented. * forward to SPM Core which will handle it if implemented.
*/ */
/* /*
...@@ -428,42 +437,42 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -428,42 +437,42 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
SPCI_ERROR_NOT_SUPPORTED); SPCI_ERROR_NOT_SUPPORTED);
} }
/* Forward SMC from Normal world to the SPM core */ /* Forward SMC from Normal world to the SPM Core */
if (!secure_origin) { if (!secure_origin) {
return spmd_smc_forward(smc_fid, secure_origin, return spmd_smc_forward(smc_fid, secure_origin,
x1, x2, x3, x4, handle); x1, x2, x3, x4, handle);
} else {
/*
* Return success if call was from secure world i.e. all
* SPCI functions are supported. This is essentially a
* nop.
*/
SMC_RET8(handle, SPCI_SUCCESS_SMC32, 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 success if call was from secure world i.e. all
* SPCI functions are supported. This is essentially a
* nop.
*/
SMC_RET8(handle, SPCI_SUCCESS_SMC32, 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_ID_GET: case SPCI_ID_GET:
/* /*
* Returns the ID of the calling SPCI component. * Returns the ID of the calling SPCI component.
*/ */
if (!secure_origin) { if (!secure_origin) {
SMC_RET8(handle, SPCI_SUCCESS_SMC32, SMC_RET8(handle, SPCI_SUCCESS_SMC32,
SPCI_TARGET_INFO_MBZ, SPCI_NS_ENDPOINT_ID, SPCI_TARGET_INFO_MBZ, SPCI_NS_ENDPOINT_ID,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ); SPCI_PARAM_MBZ);
} else {
SMC_RET8(handle, SPCI_SUCCESS_SMC32,
SPCI_TARGET_INFO_MBZ, spmc_attrs.spmc_id,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ);
} }
SMC_RET8(handle, SPCI_SUCCESS_SMC32,
SPCI_TARGET_INFO_MBZ, spmc_attrs.spmc_id,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ, SPCI_PARAM_MBZ,
SPCI_PARAM_MBZ);
break; /* not reached */ break; /* not reached */
case SPCI_RX_RELEASE: case SPCI_RX_RELEASE:
...@@ -513,7 +522,7 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, ...@@ -513,7 +522,7 @@ uint64_t spmd_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
/* /*
* Check if this is the first invocation of this interface on * Check if this is the first invocation of this interface on
* this CPU from the Secure world. If so, then indicate that the * this CPU from the Secure world. If so, then indicate that the
* SPM core initialised successfully. * SPM Core initialised successfully.
*/ */
if (secure_origin && (ctx->state == SPMC_STATE_RESET)) { if (secure_origin && (ctx->state == SPMC_STATE_RESET)) {
spmd_spm_core_sync_exit(0); spmd_spm_core_sync_exit(0);
......
...@@ -33,12 +33,6 @@ ...@@ -33,12 +33,6 @@
#include <services/spci_svc.h> #include <services/spci_svc.h>
#include <stdint.h> #include <stdint.h>
/*
* Convert a function no. in a FID to a bit position. All function nos. are
* between 0 and 0x1f
*/
#define SPCI_FNO_TO_BIT_POS(_fid) (1 << ((_fid) & U(0x1f)))
typedef enum spmc_state { typedef enum spmc_state {
SPMC_STATE_RESET = 0, SPMC_STATE_RESET = 0,
SPMC_STATE_IDLE SPMC_STATE_IDLE
...@@ -60,21 +54,10 @@ typedef struct spmd_spm_core_context { ...@@ -60,21 +54,10 @@ typedef struct spmd_spm_core_context {
#define SPCI_NS_ENDPOINT_ID U(0) #define SPCI_NS_ENDPOINT_ID U(0)
/* Mask and shift to check valid secure SPCI Endpoint ID. */ /* Mask and shift to check valid secure SPCI Endpoint ID. */
#define SPMC_SECURE_ID_MASK 0x1 #define SPMC_SECURE_ID_MASK U(1)
#define SPMC_SECURE_ID_SHIFT 15 #define SPMC_SECURE_ID_SHIFT U(15)
/*
* Data structure used by the SPM dispatcher (SPMD) in EL3 to track sequence of
* SPCI calls from lower ELs.
*
* next_smc_bit_map: Per-cpu bit map of SMCs from each world that are expected
* next.
*/
typedef struct spmd_spci_context {
uint32_t next_smc_bit_map[2];
} spmd_spci_context_t;
/* Functions used to enter/exit a Secure Partition synchronously */ /* Functions used to enter/exit SPMC synchronously */
uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *ctx); uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *ctx);
__dead2 void spmd_spm_core_sync_exit(uint64_t rc); __dead2 void spmd_spm_core_sync_exit(uint64_t rc);
...@@ -82,6 +65,9 @@ __dead2 void spmd_spm_core_sync_exit(uint64_t rc); ...@@ -82,6 +65,9 @@ __dead2 void spmd_spm_core_sync_exit(uint64_t rc);
uint64_t spmd_spm_core_enter(uint64_t *c_rt_ctx); uint64_t spmd_spm_core_enter(uint64_t *c_rt_ctx);
void __dead2 spmd_spm_core_exit(uint64_t c_rt_ctx, uint64_t ret); void __dead2 spmd_spm_core_exit(uint64_t c_rt_ctx, uint64_t ret);
/* SPMC context on current CPU get helper */
spmd_spm_core_context_t *spmd_get_context(void);
#endif /* __ASSEMBLER__ */ #endif /* __ASSEMBLER__ */
#endif /* SPMD_PRIVATE_H */ #endif /* SPMD_PRIVATE_H */
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