aboutsummaryrefslogtreecommitdiff
path: root/secure_fw
diff options
context:
space:
mode:
authorKevin Peng <kevin.peng@arm.com>2021-05-08 13:42:56 +0800
committerKevin Peng <kevin.peng@arm.com>2021-05-20 04:03:39 +0200
commitfc7b7717aebe7c5d00ba581bb9968af23fd8279e (patch)
tree3098fcc59f2e3a611e458640458ba064d158bd61 /secure_fw
parent211f5d6a6b1d766eaa1dc1deba32304e91665b5b (diff)
downloadtrusted-firmware-m-fc7b7717aebe7c5d00ba581bb9968af23fd8279e.tar.gz
SPM: Convert SVC number to uint8_t
SVC number encoded in SVC instruction is 8-bit long. Currently it relies on the short-enum compiler option to have a 8-bit long SVC number type. This patch converts the enum to uint8_t for SVC number and divids the SVC numbers to two parts for IPC model: - 0x0 ~ 0x7F for SVC calls only allowed from Thread Mode - 0x80 ~ 0xFF for SVC calls only allowed from interrupt handling Note: For library model, the SVC numbers have no restrictions. Since the requirements for SVC number assignment are different, this patch also split the SVC number header for IPC and Library models. Change-Id: I0fb4dd110be6bab05e1c4b9a8fc55e1b8bfbc0eb Signed-off-by: Kevin Peng <kevin.peng@arm.com>
Diffstat (limited to 'secure_fw')
-rw-r--r--secure_fw/include/tfm/tfm_core_svc.h60
-rw-r--r--secure_fw/partitions/lib/sprt/service_api.c8
-rwxr-xr-xsecure_fw/spm/CMakeLists.txt3
-rw-r--r--secure_fw/spm/cmsis_func/include/tfm_core_svc.h29
-rw-r--r--secure_fw/spm/cmsis_func/tfm_core_svcalls_func.c5
-rw-r--r--secure_fw/spm/cmsis_psa/arch/tfm_arch.c4
-rw-r--r--secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_base.c2
-rw-r--r--secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_main.c2
-rw-r--r--secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c10
-rw-r--r--secure_fw/spm/cmsis_psa/tfm_thread.c2
-rw-r--r--secure_fw/spm/include/interface/svc_num.h50
-rw-r--r--secure_fw/spm/include/tfm_secure_api.h8
12 files changed, 105 insertions, 78 deletions
diff --git a/secure_fw/include/tfm/tfm_core_svc.h b/secure_fw/include/tfm/tfm_core_svc.h
deleted file mode 100644
index 74ad157fac..0000000000
--- a/secure_fw/include/tfm/tfm_core_svc.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __TFM_CORE_SVC_H__
-#define __TFM_CORE_SVC_H__
-
-#include "tfm_hal_device_header.h"
-#include "tfm_spm_log.h"
-
-typedef enum {
- TFM_SVC_SFN_REQUEST = 0,
- TFM_SVC_SFN_RETURN,
- TFM_SVC_GET_CALLER_CLIENT_ID,
- TFM_SVC_SPM_REQUEST,
- TFM_SVC_GET_BOOT_DATA,
- TFM_SVC_DEPRIV_REQ,
- TFM_SVC_DEPRIV_RET,
-#ifndef TFM_PSA_API
- TFM_SVC_ENABLE_IRQ,
- TFM_SVC_DISABLE_IRQ,
-#endif
- TFM_SVC_PSA_WAIT,
- TFM_SVC_PSA_EOI,
- TFM_SVC_HANDLER_MODE,
-#ifdef TFM_PSA_API
- /* PSA Client SVC */
- TFM_SVC_PSA_FRAMEWORK_VERSION,
- TFM_SVC_PSA_VERSION,
- TFM_SVC_PSA_CONNECT,
- TFM_SVC_PSA_CALL,
- TFM_SVC_PSA_CLOSE,
- /* PSA Service SVC */
- TFM_SVC_PSA_GET,
- TFM_SVC_PSA_SET_RHANDLE,
- TFM_SVC_PSA_READ,
- TFM_SVC_PSA_SKIP,
- TFM_SVC_PSA_WRITE,
- TFM_SVC_PSA_REPLY,
- TFM_SVC_PSA_NOTIFY,
- TFM_SVC_PSA_CLEAR,
- TFM_SVC_PSA_PANIC,
- TFM_SVC_PSA_LIFECYCLE,
-#endif
-#if (TFM_SPM_LOG_LEVEL > TFM_SPM_LOG_LEVEL_SILENCE)
- TFM_SVC_OUTPUT_UNPRIV_STRING,
-#endif
- /* Secure Partition API for interrupt control */
- TFM_SVC_PSA_IRQ_ENABLE,
- TFM_SVC_PSA_IRQ_DISABLE,
-
- TFM_SVC_PLATFORM_BASE = 50 /* leave room for additional Core handlers */
-} tfm_svc_number_t;
-
-#define SVC(code) __ASM volatile("svc %0" : : "I" (code))
-
-#endif /* __TFM_CORE_SVC_H__ */
diff --git a/secure_fw/partitions/lib/sprt/service_api.c b/secure_fw/partitions/lib/sprt/service_api.c
index 09d48fd6dd..72bd536b09 100644
--- a/secure_fw/partitions/lib/sprt/service_api.c
+++ b/secure_fw/partitions/lib/sprt/service_api.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -7,7 +7,11 @@
#include "cmsis_compiler.h"
#include "service_api.h"
-#include "tfm/tfm_core_svc.h"
+#ifdef TFM_PSA_API
+#include "svc_num.h"
+#else
+#include "tfm_core_svc.h"
+#endif /* TFM_PSA_API */
__attribute__((naked))
int32_t tfm_core_get_boot_data(uint8_t major_type,
diff --git a/secure_fw/spm/CMakeLists.txt b/secure_fw/spm/CMakeLists.txt
index 22416764ca..8ad1f2dc0c 100755
--- a/secure_fw/spm/CMakeLists.txt
+++ b/secure_fw/spm/CMakeLists.txt
@@ -157,7 +157,8 @@ target_link_libraries(tfm_secure_api
target_include_directories(tfm_secure_api
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
- $<$<BOOL:${TFM_PSA_API}>:${CMAKE_CURRENT_SOURCE_DIR}/model_ipc/include>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/interface>
+ $<$<NOT:$<BOOL:${TFM_PSA_API}>>:${CMAKE_CURRENT_SOURCE_DIR}/cmsis_func/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/arch/include>
)
diff --git a/secure_fw/spm/cmsis_func/include/tfm_core_svc.h b/secure_fw/spm/cmsis_func/include/tfm_core_svc.h
new file mode 100644
index 0000000000..accf1b80da
--- /dev/null
+++ b/secure_fw/spm/cmsis_func/include/tfm_core_svc.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_CORE_SVC_H__
+#define __TFM_CORE_SVC_H__
+
+#include "tfm_spm_log.h"
+
+/* SVC numbers */
+#define TFM_SVC_PSA_WAIT (0x0)
+#define TFM_SVC_PSA_EOI (0x1)
+#define TFM_SVC_SFN_REQUEST (0x2)
+#define TFM_SVC_SFN_RETURN (0x3)
+#define TFM_SVC_GET_CALLER_CLIENT_ID (0x4)
+#define TFM_SVC_SPM_REQUEST (0x5)
+#define TFM_SVC_GET_BOOT_DATA (0x6)
+#define TFM_SVC_DEPRIV_REQ (0x7)
+#define TFM_SVC_DEPRIV_RET (0x8)
+#define TFM_SVC_ENABLE_IRQ (0x9)
+#define TFM_SVC_DISABLE_IRQ (0xA)
+#if (TFM_SPM_LOG_LEVEL > TFM_SPM_LOG_LEVEL_SILENCE)
+#define TFM_SVC_OUTPUT_UNPRIV_STRING (0xB)
+#endif
+
+#endif /* __TFM_CORE_SVC_H__ */
diff --git a/secure_fw/spm/cmsis_func/tfm_core_svcalls_func.c b/secure_fw/spm/cmsis_func/tfm_core_svcalls_func.c
index a3c536b3a9..193ab27271 100644
--- a/secure_fw/spm/cmsis_func/tfm_core_svcalls_func.c
+++ b/secure_fw/spm/cmsis_func/tfm_core_svcalls_func.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -7,7 +7,6 @@
#include <string.h>
-#include "tfm/tfm_core_svc.h"
#include "tfm_secure_api.h"
#include "region_defs.h"
#include "spm_func.h"
@@ -20,7 +19,7 @@
#include "ffm/tfm_boot_data.h"
#ifdef PLATFORM_SVC_HANDLERS
-extern int32_t platform_svc_handlers(tfm_svc_number_t svc_num,
+extern int32_t platform_svc_handlers(uint8_t svc_num,
uint32_t *svc_args, uint32_t lr);
#endif
diff --git a/secure_fw/spm/cmsis_psa/arch/tfm_arch.c b/secure_fw/spm/cmsis_psa/arch/tfm_arch.c
index cb10c600a5..412e8c226b 100644
--- a/secure_fw/spm/cmsis_psa/arch/tfm_arch.c
+++ b/secure_fw/spm/cmsis_psa/arch/tfm_arch.c
@@ -1,13 +1,13 @@
/*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
+#include "svc_num.h"
#include "tfm_arch.h"
#include "tfm_core_utils.h"
-#include "tfm/tfm_core_svc.h"
#include "tfm/tfm_spm_services.h"
__attribute__((naked))
diff --git a/secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_base.c b/secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_base.c
index 72d1685367..465a26d55b 100644
--- a/secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_base.c
+++ b/secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_base.c
@@ -11,7 +11,7 @@
#include "tfm_arch.h"
#include "exception_info.h"
#include "tfm_secure_api.h"
-#include "tfm/tfm_core_svc.h"
+#include "svc_num.h"
#if !defined(__ARM_ARCH_8M_BASE__)
#error "Unsupported ARM Architecture."
diff --git a/secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_main.c b/secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_main.c
index 7ee168b141..6fbebff93d 100644
--- a/secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_main.c
+++ b/secure_fw/spm/cmsis_psa/arch/tfm_arch_v8m_main.c
@@ -14,7 +14,7 @@
#include "exception_info.h"
#include "tfm_secure_api.h"
#include "spm_ipc.h"
-#include "tfm/tfm_core_svc.h"
+#include "svc_num.h"
#if !defined(__ARM_ARCH_8M_MAIN__) && !defined(__ARM_ARCH_8_1M_MAIN__)
#error "Unsupported ARM Architecture."
diff --git a/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c b/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
index 753b6cd40b..60d83e9f56 100644
--- a/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
+++ b/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c
@@ -13,7 +13,7 @@
#include "tfm_core_trustzone.h"
#include "tfm_svcalls.h"
#include "utilities.h"
-#include "tfm/tfm_core_svc.h"
+#include "svc_num.h"
#include "ffm/tfm_boot_data.h"
#include "ffm/psa_client_service_apis.h"
#include "tfm_hal_spm_logdev.h"
@@ -23,11 +23,11 @@ REGION_DECLARE(Image$$, TFM_UNPRIV_CODE, $$RO$$Base);
REGION_DECLARE(Image$$, TFM_UNPRIV_CODE, $$RO$$Limit);
#ifdef PLATFORM_SVC_HANDLERS
-extern int32_t platform_svc_handlers(tfm_svc_number_t svc_num,
+extern int32_t platform_svc_handlers(uint8_t svc_num,
uint32_t *ctx, uint32_t lr);
#endif
-static int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx,
+static int32_t SVC_Handler_IPC(uint8_t svc_num, uint32_t *ctx,
uint32_t lr)
{
bool ns_caller = false;
@@ -125,7 +125,7 @@ static int32_t SVC_Handler_IPC(tfm_svc_number_t svc_num, uint32_t *ctx,
uint32_t tfm_core_svc_handler(uint32_t *msp, uint32_t *psp, uint32_t exc_return)
{
- tfm_svc_number_t svc_number = TFM_SVC_PSA_FRAMEWORK_VERSION;
+ uint8_t svc_number = TFM_SVC_PSA_FRAMEWORK_VERSION;
uint32_t *svc_args = msp;
if (!(exc_return & EXC_RETURN_MODE)) {
@@ -149,7 +149,7 @@ uint32_t tfm_core_svc_handler(uint32_t *msp, uint32_t *psp, uint32_t exc_return)
/* SV called directly from secure context. Check instruction for
* svc_number
*/
- svc_number = ((tfm_svc_number_t *)svc_args[6])[-2];
+ svc_number = ((uint8_t *)svc_args[6])[-2];
} else {
/* Secure SV executing with NS return.
* NS cannot directly trigger S SVC so this should not happen. This is
diff --git a/secure_fw/spm/cmsis_psa/tfm_thread.c b/secure_fw/spm/cmsis_psa/tfm_thread.c
index 4c4ef16553..91d272de40 100644
--- a/secure_fw/spm/cmsis_psa/tfm_thread.c
+++ b/secure_fw/spm/cmsis_psa/tfm_thread.c
@@ -8,8 +8,8 @@
#include "tfm_arch.h"
#include "tfm_thread.h"
#include "utilities.h"
+#include "svc_num.h"
#include "tfm_memory_utils.h"
-#include "tfm/tfm_core_svc.h"
#include "tfm_core_utils.h"
/* Force ZERO in case ZI(bss) clear is missing */
diff --git a/secure_fw/spm/include/interface/svc_num.h b/secure_fw/spm/include/interface/svc_num.h
new file mode 100644
index 0000000000..1ffa32ee11
--- /dev/null
+++ b/secure_fw/spm/include/interface/svc_num.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __SVC_NUM_H__
+#define __SVC_NUM_H__
+
+#include "tfm_spm_log.h"
+
+/*
+ * SVC numbers for FF-M compliant implementations.
+ * 0x0 ~ 0x7F can be only called from Thread Mode, the rest from ISR only.
+ */
+
+/********************* SVC for Thread Mode ************************************/
+/* PSA Client APIs */
+#define TFM_SVC_PSA_FRAMEWORK_VERSION (0x0)
+#define TFM_SVC_PSA_VERSION (0x1)
+#define TFM_SVC_PSA_CONNECT (0x2)
+#define TFM_SVC_PSA_CALL (0x3)
+#define TFM_SVC_PSA_CLOSE (0x4)
+/* PSA Secure Partition APIs */
+#define TFM_SVC_PSA_WAIT (0x5)
+#define TFM_SVC_PSA_GET (0x6)
+#define TFM_SVC_PSA_SET_RHANDLE (0x7)
+#define TFM_SVC_PSA_READ (0x8)
+#define TFM_SVC_PSA_SKIP (0x9)
+#define TFM_SVC_PSA_WRITE (0xA)
+#define TFM_SVC_PSA_REPLY (0xB)
+#define TFM_SVC_PSA_NOTIFY (0xC)
+#define TFM_SVC_PSA_CLEAR (0xD)
+#define TFM_SVC_PSA_EOI (0xE)
+#define TFM_SVC_PSA_PANIC (0xF)
+#define TFM_SVC_PSA_LIFECYCLE (0x10)
+#define TFM_SVC_PSA_IRQ_ENABLE (0x11)
+#define TFM_SVC_PSA_IRQ_DISABLE (0x12)
+/* TF-M specific, starts from 0x40 */
+#define TFM_SVC_SPM_REQUEST (0x40)
+#define TFM_SVC_GET_BOOT_DATA (0x41)
+#define TFM_SVC_HANDLER_MODE (0x42)
+#if (TFM_SPM_LOG_LEVEL > TFM_SPM_LOG_LEVEL_SILENCE)
+#define TFM_SVC_OUTPUT_UNPRIV_STRING (0x7F)
+#endif
+#define TFM_SVC_NUMBER_DIVIDER (0x7F)
+/********************* SVC for interrupt handling *****************************/
+
+#endif /* __SVC_NUM_H__ */
diff --git a/secure_fw/spm/include/tfm_secure_api.h b/secure_fw/spm/include/tfm_secure_api.h
index 8ed7a799b4..0fa9cc9f0b 100644
--- a/secure_fw/spm/include/tfm_secure_api.h
+++ b/secure_fw/spm/include/tfm_secure_api.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -12,11 +12,15 @@
#include <arm_cmse.h>
#endif
#include "tfm_arch.h"
-#include "tfm/tfm_core_svc.h"
#include "tfm_api.h"
#include "utilities.h"
#include "tfm_boot_status.h"
#include "psa/service.h"
+#ifdef TFM_PSA_API
+#include "svc_num.h"
+#else
+#include "tfm_core_svc.h"
+#endif /* TFM_PSA_API */
#ifndef TFM_MULTI_CORE_TOPOLOGY
#ifndef TFM_PSA_API