aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/runtime_services/ffa_helpers.h20
-rw-r--r--spm/cactus/cactus.mk3
-rw-r--r--spm/cactus/cactus_debug.c2
-rw-r--r--spm/cactus/cactus_ffa_tests.c4
-rw-r--r--spm/cactus/cactus_main.c3
-rw-r--r--spm/cactus/ffa_helpers.h119
-rw-r--r--spm/common/sp_helpers.c42
-rw-r--r--spm/common/sp_helpers.h18
-rw-r--r--tftf/tests/runtime_services/secure_service/ffa_helpers.c49
-rw-r--r--tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c6
10 files changed, 134 insertions, 132 deletions
diff --git a/include/runtime_services/ffa_helpers.h b/include/runtime_services/ffa_helpers.h
index 8ce952ab2..d4ef8039c 100644
--- a/include/runtime_services/ffa_helpers.h
+++ b/include/runtime_services/ffa_helpers.h
@@ -14,14 +14,34 @@
/* This error code must be different to the ones used by FFA */
#define FFA_TFTF_ERROR -42
+/* Hypervisor ID at physical FFA instance */
+#define HYP_ID (0)
+
+/* By convention, SP IDs (as opposed to VM IDs) have bit 15 set */
+#define SP_ID(x) ((x) | (1 << 15))
+
+typedef unsigned short ffa_vm_id_t;
+typedef unsigned short ffa_vm_count_t;
+typedef unsigned short ffa_vcpu_count_t;
+
#ifndef __ASSEMBLY__
#include <stdint.h>
+/*
+ * TODO: In the future this file should be placed in a common folder, and not
+ * under tftf. The functions in this file are also used by SPs for SPM tests.
+ */
+
smc_ret_values ffa_msg_send_direct_req(uint32_t source_id, uint32_t dest_id, uint32_t message);
smc_ret_values ffa_msg_send_direct_req64(uint32_t source_id, uint32_t dest_id, uint64_t message);
smc_ret_values ffa_run(uint32_t dest_id, uint32_t vcpu_id);
smc_ret_values ffa_version(uint32_t input_version);
+smc_ret_values ffa_id_get(void);
+smc_ret_values ffa_msg_wait(void);
+smc_ret_values ffa_msg_send_direct_resp(ffa_vm_id_t source_id,
+ ffa_vm_id_t dest_id, uint32_t message);
+smc_ret_values ffa_error(int32_t error_code);
#endif /* __ASSEMBLY__ */
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index a32b7130e..e965499dc 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -36,7 +36,8 @@ CACTUS_SOURCES := \
# TODO: Remove dependency on TFTF files.
CACTUS_SOURCES += \
tftf/framework/debug.c \
- tftf/framework/${ARCH}/asm_debug.S
+ tftf/framework/${ARCH}/asm_debug.S \
+ tftf/tests/runtime_services/secure_service/ffa_helpers.c
CACTUS_SOURCES += drivers/arm/pl011/${ARCH}/pl011_console.S \
lib/${ARCH}/cache_helpers.S \
diff --git a/spm/cactus/cactus_debug.c b/spm/cactus/cactus_debug.c
index 91fbfda97..43093a6bb 100644
--- a/spm/cactus/cactus_debug.c
+++ b/spm/cactus/cactus_debug.c
@@ -6,9 +6,9 @@
#include <drivers/arm/pl011.h>
#include <drivers/console.h>
+#include <sp_helpers.h>
#include "cactus.h"
-#include "ffa_helpers.h"
static int (*putc_impl)(int);
diff --git a/spm/cactus/cactus_ffa_tests.c b/spm/cactus/cactus_ffa_tests.c
index 2143e7535..411cc9f2e 100644
--- a/spm/cactus/cactus_ffa_tests.c
+++ b/spm/cactus/cactus_ffa_tests.c
@@ -6,7 +6,7 @@
#include <assert.h>
#include <errno.h>
#include <debug.h>
-#include "ffa_helpers.h"
+#include <ffa_helpers.h>
#include <sp_helpers.h>
/* FFA version test helpers */
@@ -26,7 +26,7 @@ void ffa_tests(void)
uint32_t spm_version = (uint32_t)(0xFFFFFFFF & ret.ret0);
bool ffa_version_compatible = ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
- (FFA_VERSION_MINOR_MASK & spm_version) >= FFA_MINOR);
+ (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n",
spm_version >> FFA_VERSION_MAJOR_SHIFT,
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index 1508d9839..49764eccd 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -13,10 +13,11 @@
#include <debug.h>
#include <drivers/arm/pl011.h>
#include <drivers/console.h>
-#include "ffa_helpers.h"
+#include <ffa_helpers.h>
#include <lib/aarch64/arch_helpers.h>
#include <lib/xlat_tables/xlat_mmu_helpers.h>
#include <lib/xlat_tables/xlat_tables_v2.h>
+#include <sp_helpers.h>
#include <std_svc.h>
#include <plat/common/platform.h>
#include <plat_arm.h>
diff --git a/spm/cactus/ffa_helpers.h b/spm/cactus/ffa_helpers.h
deleted file mode 100644
index 8fdf727e6..000000000
--- a/spm/cactus/ffa_helpers.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef __FFA_HELPERS_H__
-#define __FFA_HELPERS_H__
-
-
-#include <ffa_svc.h>
-#include "tftf_lib.h"
-
-#define SPM_VM_ID_FIRST (1)
-
-#define SPM_VM_GET_COUNT (0xFF01)
-#define SPM_VCPU_GET_COUNT (0xFF02)
-#define SPM_DEBUG_LOG (0xBD000000)
-
-/* Hypervisor ID at physical FFA instance */
-#define HYP_ID (0)
-
-/* By convention, SP IDs (as opposed to VM IDs) have bit 15 set */
-#define SP_ID(x) ((x) | (1 << 15))
-
-typedef unsigned short ffa_vm_id_t;
-typedef unsigned short ffa_vm_count_t;
-typedef unsigned short ffa_vcpu_count_t;
-
-/* Functions */
-
-static inline ffa_vcpu_count_t spm_vcpu_get_count(ffa_vm_id_t vm_id)
-{
- hvc_args args = {
- .fid = SPM_VCPU_GET_COUNT,
- .arg1 = vm_id
- };
-
- hvc_ret_values ret = tftf_hvc(&args);
-
- return ret.ret0;
-}
-
-static inline ffa_vm_count_t spm_vm_get_count(void)
-{
- hvc_args args = {
- .fid = SPM_VM_GET_COUNT
- };
-
- hvc_ret_values ret = tftf_hvc(&args);
-
- return ret.ret0;
-}
-
-static inline void spm_debug_log(char c)
-{
- hvc_args args = {
- .fid = SPM_DEBUG_LOG,
- .arg1 = c
- };
-
- (void)tftf_hvc(&args);
-}
-
-static inline smc_ret_values ffa_id_get(void)
-{
- smc_args args = {
- .fid = FFA_ID_GET
- };
-
- return tftf_smc(&args);
-}
-
-static inline smc_ret_values ffa_msg_wait(void)
-{
- smc_args args = {
- .fid = FFA_MSG_WAIT
- };
-
- return tftf_smc(&args);
-}
-
-/* Send response through registers using direct messaging */
-static inline smc_ret_values ffa_msg_send_direct_resp(ffa_vm_id_t sender_vm_id,
- ffa_vm_id_t target_vm_id,
- uint32_t message)
-{
- smc_args args = {
- .fid = FFA_MSG_SEND_DIRECT_RESP_SMC32,
- .arg1 = ((uint32_t)sender_vm_id << 16) | target_vm_id,
- .arg3 = message
- };
-
- return tftf_smc(&args);
-}
-
-static inline smc_ret_values ffa_error(int32_t error_code)
-{
- smc_args args = {
- .fid = FFA_ERROR,
- .arg1 = 0,
- .arg2 = error_code
- };
-
- return tftf_smc(&args);
-}
-
-/* FFA Version ABI helper */
-static inline smc_ret_values ffa_version(uint32_t input_version)
-{
- smc_args args = {
- .fid = FFA_VERSION,
- .arg1 = input_version
- };
-
- return tftf_smc(&args);
-}
-
-#endif /* __FFA_HELPERS_H__ */
diff --git a/spm/common/sp_helpers.c b/spm/common/sp_helpers.c
index 5aec977d4..7dc164847 100644
--- a/spm/common/sp_helpers.c
+++ b/spm/common/sp_helpers.c
@@ -9,6 +9,9 @@
#include <platform_def.h>
#include <stdint.h>
#include <stdlib.h>
+#include <ffa_svc.h>
+
+#include "sp_helpers.h"
uintptr_t bound_rand(uintptr_t min, uintptr_t max)
{
@@ -52,7 +55,7 @@ void announce_test_start(const char *test_desc)
void announce_test_end(const char *test_desc)
{
- INFO("Test \"%s\" passed.\n", test_desc);
+ INFO("Test \"%s\" end.\n", test_desc);
}
void sp_sleep(uint32_t ms)
@@ -67,3 +70,40 @@ void sp_sleep(uint32_t ms)
time2 = mmio_read_64(SYS_CNT_READ_BASE);
}
}
+
+/*******************************************************************************
+ * Hypervisor Calls Wrappers
+ ******************************************************************************/
+
+ffa_vcpu_count_t spm_vcpu_get_count(ffa_vm_id_t vm_id)
+{
+ hvc_args args = {
+ .fid = SPM_VCPU_GET_COUNT,
+ .arg1 = vm_id
+ };
+
+ hvc_ret_values ret = tftf_hvc(&args);
+
+ return ret.ret0;
+}
+
+ffa_vm_count_t spm_vm_get_count(void)
+{
+ hvc_args args = {
+ .fid = SPM_VM_GET_COUNT
+ };
+
+ hvc_ret_values ret = tftf_hvc(&args);
+
+ return ret.ret0;
+}
+
+void spm_debug_log(char c)
+{
+ hvc_args args = {
+ .fid = SPM_DEBUG_LOG,
+ .arg1 = c
+ };
+
+ (void)tftf_hvc(&args);
+}
diff --git a/spm/common/sp_helpers.h b/spm/common/sp_helpers.h
index d06fec3b4..2b9cc2ed2 100644
--- a/spm/common/sp_helpers.h
+++ b/spm/common/sp_helpers.h
@@ -8,6 +8,14 @@
#define SP_HELPERS_H
#include <stdint.h>
+#include <tftf_lib.h>
+#include <ffa_helpers.h>
+
+#define SPM_VM_ID_FIRST (1)
+
+#define SPM_VM_GET_COUNT (0xFF01)
+#define SPM_VCPU_GET_COUNT (0xFF02)
+#define SPM_DEBUG_LOG (0xBD000000)
typedef struct {
u_register_t fid;
@@ -57,4 +65,14 @@ void announce_test_end(const char *test_desc);
/* Sleep for at least 'ms' milliseconds. */
void sp_sleep(uint32_t ms);
+/*
+ * Hypervisor Calls Wrappers
+ */
+
+ffa_vcpu_count_t spm_vcpu_get_count(ffa_vm_id_t vm_id);
+
+ffa_vm_count_t spm_vm_get_count(void);
+
+void spm_debug_log(char c);
+
#endif /* SP_HELPERS_H */
diff --git a/tftf/tests/runtime_services/secure_service/ffa_helpers.c b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
index ba57cfec3..9955c7ce8 100644
--- a/tftf/tests/runtime_services/secure_service/ffa_helpers.c
+++ b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
@@ -107,7 +107,12 @@ smc_ret_values ffa_msg_send_direct_req64(uint32_t source_id, uint32_t dest_id,
message, 0, 0, 0, 0);
}
-/* FFA Version ABI helper */
+/*
+ * FFA Version ABI helper.
+ * Version fields:
+ * -Bits[30:16]: Major version.
+ * -Bits[15:0]: Minor version.
+ */
smc_ret_values ffa_version(uint32_t input_version)
{
smc_args args = {
@@ -117,3 +122,45 @@ smc_ret_values ffa_version(uint32_t input_version)
return tftf_smc(&args);
}
+
+smc_ret_values ffa_id_get(void)
+{
+ smc_args args = {
+ .fid = FFA_ID_GET
+ };
+
+ return tftf_smc(&args);
+}
+
+smc_ret_values ffa_msg_wait(void)
+{
+ smc_args args = {
+ .fid = FFA_MSG_WAIT
+ };
+
+ return tftf_smc(&args);
+}
+
+smc_ret_values ffa_msg_send_direct_resp(ffa_vm_id_t source_id,
+ ffa_vm_id_t dest_id,
+ uint32_t message)
+{
+ smc_args args = {
+ .fid = FFA_MSG_SEND_DIRECT_RESP_SMC32,
+ .arg1 = ((uint32_t)source_id << 16) | dest_id,
+ .arg3 = message
+ };
+
+ return tftf_smc(&args);
+}
+
+smc_ret_values ffa_error(int32_t error_code)
+{
+ smc_args args = {
+ .fid = FFA_ERROR,
+ .arg1 = 0,
+ .arg2 = error_code
+ };
+
+ return tftf_smc(&args);
+}
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c b/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
index f18905430..d14374bef 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
@@ -12,12 +12,6 @@
#include <ffa_svc.h>
#include <test_helpers.h>
-/* Hypervisor ID at physical FFA instance */
-#define HYP_ID (0)
-
-/* By convention, SP IDs (as opposed to VM IDs) have bit 15 set */
-#define SP_ID(x) (x | (1 << 15))
-
#define DIRECT_MSG_TEST_PATTERN1 (0xaaaa0000)
#define DIRECT_MSG_TEST_PATTERN2 (0xbbbb0000)
#define DIRECT_MSG_TEST_PATTERN3 (0xcccc0000)