Tidying FFA helpers
Moved SP specific functions/macros to "sp_helpers.c/h".
Placed ffa interfaces/symbols shared between tftf and SPs in
"ffa_helpers.c/h".
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I4cf967f87837ce3e7d0f7244f9cc0677f608f9cd
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index a32b713..e965499 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -36,7 +36,8 @@
# 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 91fbfda..43093a6 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 2143e75..411cc9f 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 @@
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 1508d98..49764ec 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 8fdf727..0000000
--- 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__ */