Make supported FF-A version configurable in libsp

Introduce CFG_FFA_VERSION macro for configuring FF-A version in libsp.
The value of CFG_FFA_VERSION follows the version format of FFA_VERSION.
The allowed versions are FF-A v1.0 and v1.1.

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I7f2b425f9267758c4dfec513bc7a3bde773c7a97
diff --git a/components/messaging/ffa/libsp/component.cmake b/components/messaging/ffa/libsp/component.cmake
index 64e8814..624982a 100644
--- a/components/messaging/ffa/libsp/component.cmake
+++ b/components/messaging/ffa/libsp/component.cmake
@@ -9,6 +9,7 @@
 endif()
 
 set(FFA_DIRECT_MSG_ROUTING_EXTENSION ON CACHE BOOL "Enable FF-A direct message routing extension")
+set(CFG_FFA_VERSION 0x00010000 CACHE STRING "The supported FF-A protocol's version: (major << 16) | minor")
 
 target_sources(${TGT} PRIVATE
 	"${CMAKE_CURRENT_LIST_DIR}/aarch64/ffa_syscalls_a64.S"
@@ -46,6 +47,11 @@
 		)
 endif()
 
+target_compile_definitions(${TGT}
+	PUBLIC
+		"CFG_FFA_VERSION=${CFG_FFA_VERSION}"
+	)
+
 target_include_directories(${TGT}
 	 PUBLIC
 		"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
diff --git a/components/messaging/ffa/libsp/ffa.c b/components/messaging/ffa/libsp/ffa.c
index 6a51379..1afe44d 100644
--- a/components/messaging/ffa/libsp/ffa.c
+++ b/components/messaging/ffa/libsp/ffa.c
@@ -79,7 +79,7 @@
 	uint32_t self_version = 0;
 
 	self_version = (FFA_VERSION_MAJOR << FFA_VERSION_MAJOR_SHIFT) |
-		       (FFA_VERSION_MINOR << FFA_VERSION_MINOR);
+		       (FFA_VERSION_MINOR << FFA_VERSION_MINOR_SHIFT);
 
 	ffa_svc(FFA_VERSION, self_version, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
 		FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
diff --git a/components/messaging/ffa/libsp/include/ffa_api_defines.h b/components/messaging/ffa/libsp/include/ffa_api_defines.h
index e5aea41..007860f 100644
--- a/components/messaging/ffa/libsp/include/ffa_api_defines.h
+++ b/components/messaging/ffa/libsp/include/ffa_api_defines.h
@@ -9,6 +9,15 @@
 #include <stdint.h>
 #include "util.h"
 
+#define FFA_VERSION_1_0	(0x00010000)
+#define FFA_VERSION_1_1	(0x00010001)
+
+#ifndef CFG_FFA_VERSION
+#error CFG_FFA_VERSION must be defined
+#elif CFG_FFA_VERSION != FFA_VERSION_1_0 && CFG_FFA_VERSION != FFA_VERSION_1_1
+#error Only FF-A versions 1.0 and 1.1 are supported
+#endif
+
 /* Status codes */
 #define FFA_OK				(0)
 #define FFA_NOT_SUPPORTED		(-1)
@@ -101,10 +110,16 @@
 #define FFA_BOOT_INFO_NAME_FMT_UUID	UINT32_C(1)
 
 /* FFA_VERSION */
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
 #define FFA_VERSION_MAJOR		UINT32_C(1)
+#define FFA_VERSION_MINOR		UINT32_C(0)
+#elif CFG_FFA_VERSION == FFA_VERSION_1_1
+#define FFA_VERSION_MAJOR		UINT32_C(1)
+#define FFA_VERSION_MINOR		UINT32_C(1)
+#endif /* CFG_FFA_VERSION */
+
 #define FFA_VERSION_MAJOR_SHIFT		UINT32_C(16)
 #define FFA_VERSION_MAJOR_MASK		GENMASK_32(14, 0)
-#define FFA_VERSION_MINOR		UINT32_C(0)
 #define FFA_VERSION_MINOR_SHIFT		UINT32_C(0)
 #define FFA_VERSION_MINOR_MASK		GENMASK_32(15, 0)
 
diff --git a/components/messaging/ffa/libsp/mock/component.cmake b/components/messaging/ffa/libsp/mock/component.cmake
index 375cb46..101a56f 100644
--- a/components/messaging/ffa/libsp/mock/component.cmake
+++ b/components/messaging/ffa/libsp/mock/component.cmake
@@ -8,6 +8,8 @@
 	message(FATAL_ERROR "mandatory parameter TGT is not defined.")
 endif()
 
+set(CFG_FFA_VERSION 0x00010001 CACHE STRING "The supported FF-A protocol's version: (major << 16) | minor")
+
 target_sources(${TGT} PRIVATE
 	"${CMAKE_CURRENT_LIST_DIR}/mock_assert.cpp"
 	"${CMAKE_CURRENT_LIST_DIR}/mock_ffa_api.cpp"
@@ -27,4 +29,5 @@
 target_compile_definitions(${TGT}
 	PUBLIC
 		"ARM64=1"
+		"CFG_FFA_VERSION=${CFG_FFA_VERSION}"
 )
\ No newline at end of file
diff --git a/components/messaging/ffa/libsp/test/test_ffa_api.cpp b/components/messaging/ffa/libsp/test/test_ffa_api.cpp
index 8395662..077028b 100644
--- a/components/messaging/ffa/libsp/test/test_ffa_api.cpp
+++ b/components/messaging/ffa/libsp/test/test_ffa_api.cpp
@@ -80,9 +80,14 @@
 {
 	uint32_t version = 0;
 	const uint32_t test_version = 0x78901234;
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
+	const uint32_t cfg_ffa_version = 0x00010000;
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+	const uint32_t cfg_ffa_version = 0x00010001;
+#endif /* CFG_FFA_VERSION */
 
 	svc_result.a0 = test_version;
-	expect_ffa_svc(0x84000063, 0x10000U, 0, 0, 0, 0, 0, 0, &svc_result);
+	expect_ffa_svc(0x84000063, cfg_ffa_version, 0, 0, 0, 0, 0, 0, &svc_result);
 
 	ffa_result result = ffa_version(&version);
 	LONGS_EQUAL(FFA_OK, result);
@@ -92,9 +97,14 @@
 TEST(ffa_api, ffa_version_error)
 {
 	uint32_t version = 0;
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
+	const uint32_t cfg_ffa_version = 0x00010000;
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+	const uint32_t cfg_ffa_version = 0x00010001;
+#endif /* CFG_FFA_VERSION */
 
 	svc_result.a0 = 0xffffffff;
-	expect_ffa_svc(0x84000063, 0x10000U, 0, 0, 0, 0, 0, 0, &svc_result);
+	expect_ffa_svc(0x84000063, cfg_ffa_version, 0, 0, 0, 0, 0, 0, &svc_result);
 
 	ffa_result result = ffa_version(&version);
 	LONGS_EQUAL(-1, result);
diff --git a/components/messaging/ffa/libsp/tests.cmake b/components/messaging/ffa/libsp/tests.cmake
index eb0b41e..8ef5479 100644
--- a/components/messaging/ffa/libsp/tests.cmake
+++ b/components/messaging/ffa/libsp/tests.cmake
@@ -47,6 +47,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -60,6 +61,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -74,6 +76,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -87,6 +90,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -102,6 +106,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -115,6 +120,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -132,6 +138,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -145,6 +152,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -160,6 +168,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -174,6 +183,7 @@
 		${UNIT_TEST_PROJECT_PATH}/components/common/utils/include
 	COMPILE_DEFINITIONS
 		-DARM64
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -188,6 +198,7 @@
 	COMPILE_DEFINITIONS
 		-DARM64
 		-DFFA_DIRECT_MSG_ROUTING_EXTENSION=1
+		-DCFG_FFA_VERSION=0x00010000
 )
 
 unit_test_add_suite(
@@ -204,4 +215,5 @@
 	COMPILE_DEFINITIONS
 		-DARM64
 		-DFFA_DIRECT_MSG_ROUTING_EXTENSION=1
+		-DCFG_FFA_VERSION=0x00010000
 )
\ No newline at end of file