Use 64-bit FF-A calls where necessary

According to the FF-A spec if a call has any 64-bit arguments, it should
use the 64-bit version of the function ID. Fix this to get aligned with
the spec.

Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
Change-Id: I33d353daf0ddedb7e1328e4df2de9a395477a475
diff --git a/components/messaging/ffa/libsp/ffa.c b/components/messaging/ffa/libsp/ffa.c
index 648d3c8..6af0760 100644
--- a/components/messaging/ffa/libsp/ffa.c
+++ b/components/messaging/ffa/libsp/ffa.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: BSD-3-Clause
 /*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
  */
 
 #include <assert.h>            // for assert
@@ -133,13 +133,17 @@
 	page_count = SHIFT_U32(page_count & FFA_RXTX_MAP_PAGE_COUNT_MASK,
 			       FFA_RXTX_MAP_PAGE_COUNT_SHIFT);
 
-	ffa_svc(FFA_RXTX_MAP_32, (uintptr_t)tx_buffer, (uintptr_t)rx_buffer,
+	ffa_svc(FFA_RXTX_MAP_64, (uintptr_t)tx_buffer, (uintptr_t)rx_buffer,
 		page_count, FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
 		FFA_PARAM_MBZ, &result);
 
 	if (result.a0 == FFA_ERROR)
 		return ffa_get_errorcode(&result);
 
+	/*
+	 * There are no 64-bit parameters returned with FFA_SUCCESS, the SPMC
+	 * will use the default 32-bit version.
+	 */
 	assert(result.a0 == FFA_SUCCESS_32);
 	return FFA_OK;
 }
@@ -283,15 +287,20 @@
 {
 	struct ffa_params result = {0};
 
-	ffa_svc(FFA_MEM_DONATE_32, total_length, fragment_length,
-		(uintptr_t)buffer_address, page_count, FFA_PARAM_MBZ,
-		FFA_PARAM_MBZ, FFA_PARAM_MBZ, &result);
+	ffa_svc((buffer_address) ? FFA_MEM_DONATE_64 : FFA_MEM_DONATE_32,
+		total_length, fragment_length, (uintptr_t)buffer_address,
+		page_count, FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
+		&result);
 
 	if (result.a0 == FFA_ERROR) {
 		*handle = 0U;
 		return ffa_get_errorcode(&result);
 	}
 
+	/*
+	 * There are no 64-bit parameters returned with FFA_SUCCESS, the SPMC
+	 * will use the default 32-bit version.
+	 */
 	assert(result.a0 == FFA_SUCCESS_32);
 	*handle = reg_pair_to_64(result.a3, result.a2);
 	return FFA_OK;
@@ -309,15 +318,20 @@
 {
 	struct ffa_params result = {0};
 
-	ffa_svc(FFA_MEM_LEND_32, total_length, fragment_length,
-		(uintptr_t)buffer_address, page_count, FFA_PARAM_MBZ,
-		FFA_PARAM_MBZ, FFA_PARAM_MBZ, &result);
+	ffa_svc((buffer_address) ? FFA_MEM_LEND_64 : FFA_MEM_LEND_32,
+		total_length, fragment_length, (uintptr_t)buffer_address,
+		page_count, FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
+		&result);
 
 	if (result.a0 == FFA_ERROR) {
 		*handle = 0U;
 		return ffa_get_errorcode(&result);
 	}
 
+	/*
+	 * There are no 64-bit parameters returned with FFA_SUCCESS, the SPMC
+	 * will use the default 32-bit version.
+	 */
 	assert(result.a0 == FFA_SUCCESS_32);
 	*handle = reg_pair_to_64(result.a3, result.a2);
 	return FFA_OK;
@@ -335,15 +349,20 @@
 {
 	struct ffa_params result = {0};
 
-	ffa_svc(FFA_MEM_SHARE_32, total_length, fragment_length,
-		(uintptr_t)buffer_address, page_count, FFA_PARAM_MBZ,
-		FFA_PARAM_MBZ, FFA_PARAM_MBZ, &result);
+	ffa_svc((buffer_address) ? FFA_MEM_SHARE_64 : FFA_MEM_SHARE_32,
+		total_length, fragment_length, (uintptr_t)buffer_address,
+		page_count, FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
+		&result);
 
 	if (result.a0 == FFA_ERROR) {
 		*handle = 0U;
 		return ffa_get_errorcode(&result);
 	}
 
+	/*
+	 * There are no 64-bit parameters returned with FFA_SUCCESS, the SPMC
+	 * will use the default 32-bit version.
+	 */
 	assert(result.a0 == FFA_SUCCESS_32);
 	*handle = reg_pair_to_64(result.a3, result.a2);
 	return FFA_OK;
@@ -362,9 +381,10 @@
 {
 	struct ffa_params result = {0};
 
-	ffa_svc(FFA_MEM_RETRIEVE_REQ_32, total_length, fragment_length,
-		(uintptr_t)buffer_address, page_count, FFA_PARAM_MBZ,
-		FFA_PARAM_MBZ, FFA_PARAM_MBZ, &result);
+	ffa_svc((buffer_address) ? FFA_MEM_RETRIEVE_REQ_64 : FFA_MEM_RETRIEVE_REQ_32,
+		total_length, fragment_length, (uintptr_t)buffer_address,
+		page_count, FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
+		&result);
 
 	if (result.a0 == FFA_ERROR) {
 		*resp_total_length = 0U;
diff --git a/components/messaging/ffa/libsp/sp_rxtx.c b/components/messaging/ffa/libsp/sp_rxtx.c
index fb88f73..317ecec 100644
--- a/components/messaging/ffa/libsp/sp_rxtx.c
+++ b/components/messaging/ffa/libsp/sp_rxtx.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: BSD-3-Clause
 /*
- * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
  */
 
 #include "sp_rxtx.h"
@@ -99,7 +99,7 @@
 		return SP_RESULT_INVALID_PARAMETERS;
 
 	/* Querying FFX_RXTX_MAP features */
-	result = ffa_features(FFA_RXTX_MAP_32, &interface_props);
+	result = ffa_features(FFA_RXTX_MAP_64, &interface_props);
 	if (result != FFA_OK) {
 		*alignment = 0;
 		return SP_RESULT_FFA(result);
diff --git a/components/messaging/ffa/libsp/test/test_ffa_api.cpp b/components/messaging/ffa/libsp/test/test_ffa_api.cpp
index 5ab7c8a..dcde1d1 100644
--- a/components/messaging/ffa/libsp/test/test_ffa_api.cpp
+++ b/components/messaging/ffa/libsp/test/test_ffa_api.cpp
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: BSD-3-Clause
 /*
- * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
  */
 
 #include <CppUTest/TestHarness.h>
@@ -169,7 +169,7 @@
 	const uint64_t page_count = (1 << 6) - 1;
 
 	svc_result.a0 = 0x84000061;
-	expect_ffa_svc(0x84000066, tx_buffer, rx_buffer, page_count, 0, 0, 0, 0,
+	expect_ffa_svc(0xc4000066, tx_buffer, rx_buffer, page_count, 0, 0, 0, 0,
 		       &svc_result);
 
 	ffa_result result = ffa_rxtx_map((const void *)tx_buffer,
@@ -184,7 +184,7 @@
 	const uint64_t page_count = (1 << 6) - 1;
 
 	setup_error_response(-1);
-	expect_ffa_svc(0x84000066, tx_buffer, rx_buffer, page_count, 0, 0, 0, 0,
+	expect_ffa_svc(0xc4000066, tx_buffer, rx_buffer, page_count, 0, 0, 0, 0,
 		       &svc_result);
 
 	ffa_result result = ffa_rxtx_map((const void *)tx_buffer,
@@ -200,7 +200,7 @@
 	assert_environment_t assert_env;
 
 	svc_result.a0 = 0x12345678;
-	expect_ffa_svc(0x84000066, tx_buffer, rx_buffer, page_count, 0, 0, 0, 0,
+	expect_ffa_svc(0xc4000066, tx_buffer, rx_buffer, page_count, 0, 0, 0, 0,
 		       &svc_result);
 
 	if (SETUP_ASSERT_ENVIRONMENT(assert_env)) {
@@ -762,7 +762,7 @@
 	svc_result.a0 = 0x84000061;
 	svc_result.a2 = (handle_result & 0xffffffffULL);
 	svc_result.a3 = (handle_result >> 32);
-	expect_ffa_svc(0x84000071, total_length, fragment_length,
+	expect_ffa_svc(0xc4000071, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	ffa_result result =
@@ -782,7 +782,7 @@
 	const uint64_t handle_result = 0xaabbccdd11223344ULL;
 
 	setup_error_response(-1);
-	expect_ffa_svc(0x84000071, total_length, fragment_length,
+	expect_ffa_svc(0xc4000071, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	ffa_result result =
@@ -803,7 +803,7 @@
 	assert_environment_t assert_env;
 
 	svc_result.a0 = 0x12345678;
-	expect_ffa_svc(0x84000071, total_length, fragment_length,
+	expect_ffa_svc(0xc4000071, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	if (SETUP_ASSERT_ENVIRONMENT(assert_env)) {
@@ -843,7 +843,7 @@
 	svc_result.a0 = 0x84000061;
 	svc_result.a2 = (handle_result & 0xffffffffULL);
 	svc_result.a3 = (handle_result >> 32);
-	expect_ffa_svc(0x84000072, total_length, fragment_length,
+	expect_ffa_svc(0xc4000072, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	ffa_result result =
@@ -863,7 +863,7 @@
 	const uint64_t handle_result = 0xaabbccdd11223344ULL;
 
 	setup_error_response(-1);
-	expect_ffa_svc(0x84000072, total_length, fragment_length,
+	expect_ffa_svc(0xc4000072, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	ffa_result result =
@@ -884,7 +884,7 @@
 	assert_environment_t assert_env;
 
 	svc_result.a0 = 0x12345678;
-	expect_ffa_svc(0x84000072, total_length, fragment_length,
+	expect_ffa_svc(0xc4000072, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	if (SETUP_ASSERT_ENVIRONMENT(assert_env)) {
@@ -924,7 +924,7 @@
 	svc_result.a0 = 0x84000061;
 	svc_result.a2 = (handle_result & 0xffffffffULL);
 	svc_result.a3 = (handle_result >> 32);
-	expect_ffa_svc(0x84000073, total_length, fragment_length,
+	expect_ffa_svc(0xc4000073, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	ffa_result result =
@@ -944,7 +944,7 @@
 	const uint64_t handle_result = 0xaabbccdd11223344ULL;
 
 	setup_error_response(-1);
-	expect_ffa_svc(0x84000073, total_length, fragment_length,
+	expect_ffa_svc(0xc4000073, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	ffa_result result =
@@ -965,7 +965,7 @@
 	assert_environment_t assert_env;
 
 	svc_result.a0 = 0x12345678;
-	expect_ffa_svc(0x84000073, total_length, fragment_length,
+	expect_ffa_svc(0xc4000073, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	if (SETUP_ASSERT_ENVIRONMENT(assert_env)) {
@@ -1007,7 +1007,7 @@
 	svc_result.a0 = 0x84000075;
 	svc_result.a1 = resp_total_length_result;
 	svc_result.a2 = resp_frament_length_result;
-	expect_ffa_svc(0x84000074, total_length, fragment_length,
+	expect_ffa_svc(0xc4000074, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	ffa_result result =
@@ -1031,7 +1031,7 @@
 	const uint32_t resp_frament_length_result = 0x11223344;
 
 	setup_error_response(-1);
-	expect_ffa_svc(0x84000074, total_length, fragment_length,
+	expect_ffa_svc(0xc4000074, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	ffa_result result =
@@ -1056,7 +1056,7 @@
 	assert_environment_t assert_env;
 
 	svc_result.a0 = 0x12345678;
-	expect_ffa_svc(0x84000074, total_length, fragment_length,
+	expect_ffa_svc(0xc4000074, total_length, fragment_length,
 		       buffer_address, page_count, 0, 0, 0, &svc_result);
 
 	if (SETUP_ASSERT_ENVIRONMENT(assert_env)) {
diff --git a/components/messaging/ffa/libsp/test/test_sp_rxtx.cpp b/components/messaging/ffa/libsp/test/test_sp_rxtx.cpp
index a26d301..15685d2 100644
--- a/components/messaging/ffa/libsp/test/test_sp_rxtx.cpp
+++ b/components/messaging/ffa/libsp/test/test_sp_rxtx.cpp
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: BSD-3-Clause
 /*
- * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
  */
 
 #include <CppUTest/TestHarness.h>
@@ -40,7 +40,7 @@
 			[FFA_FEATURES_RXTX_MAP_GRANULARITY_INDEX] =
 			(granularity & FFA_FEATURES_RXTX_MAP_GRANULARITY_MASK)
 			<< FFA_FEATURES_RXTX_MAP_GRANULARITY_SHIFT;
-		expect_ffa_features(FFA_RXTX_MAP_32, &props, result);
+		expect_ffa_features(FFA_RXTX_MAP_64, &props, result);
 	}
 
 	void do_successful_mapping()
@@ -318,7 +318,7 @@
 
 	props.interface_properties[FFA_FEATURES_RXTX_MAP_GRANULARITY_INDEX] =
 		0 << FFA_FEATURES_RXTX_MAP_GRANULARITY_SHIFT;
-	expect_ffa_features(FFA_RXTX_MAP_32, &props, result);
+	expect_ffa_features(FFA_RXTX_MAP_64, &props, result);
 
 	LONGS_EQUAL(SP_RESULT_FFA(result),
 		    sp_rxtx_buffer_alignment_boundary_get(&alignment));
@@ -332,7 +332,7 @@
 
 	props.interface_properties[FFA_FEATURES_RXTX_MAP_GRANULARITY_INDEX] =
 		0 << FFA_FEATURES_RXTX_MAP_GRANULARITY_SHIFT;
-	expect_ffa_features(FFA_RXTX_MAP_32, &props, FFA_OK);
+	expect_ffa_features(FFA_RXTX_MAP_64, &props, FFA_OK);
 
 	LONGS_EQUAL(SP_RESULT_OK,
 		    sp_rxtx_buffer_alignment_boundary_get(&alignment));
@@ -346,7 +346,7 @@
 
 	props.interface_properties[FFA_FEATURES_RXTX_MAP_GRANULARITY_INDEX] =
 		1 << FFA_FEATURES_RXTX_MAP_GRANULARITY_SHIFT;
-	expect_ffa_features(FFA_RXTX_MAP_32, &props, FFA_OK);
+	expect_ffa_features(FFA_RXTX_MAP_64, &props, FFA_OK);
 
 	LONGS_EQUAL(SP_RESULT_OK,
 		    sp_rxtx_buffer_alignment_boundary_get(&alignment));
@@ -360,7 +360,7 @@
 
 	props.interface_properties[FFA_FEATURES_RXTX_MAP_GRANULARITY_INDEX] =
 		2 << FFA_FEATURES_RXTX_MAP_GRANULARITY_SHIFT;
-	expect_ffa_features(FFA_RXTX_MAP_32, &props, FFA_OK);
+	expect_ffa_features(FFA_RXTX_MAP_64, &props, FFA_OK);
 
 	LONGS_EQUAL(SP_RESULT_OK,
 		    sp_rxtx_buffer_alignment_boundary_get(&alignment));
@@ -375,7 +375,7 @@
 
 	props.interface_properties[FFA_FEATURES_RXTX_MAP_GRANULARITY_INDEX] =
 		3 << FFA_FEATURES_RXTX_MAP_GRANULARITY_SHIFT;
-	expect_ffa_features(FFA_RXTX_MAP_32, &props, FFA_OK);
+	expect_ffa_features(FFA_RXTX_MAP_64, &props, FFA_OK);
 
 	LONGS_EQUAL(SP_RESULT_INTERNAL_ERROR,
 		    sp_rxtx_buffer_alignment_boundary_get(&alignment));