FF-A: Error code should be 32-bit sized

Change-Id: I35a17d4801cdb9456a68495a248807aacb175e8d
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/inc/hf/ffa_internal.h b/inc/hf/ffa_internal.h
index 8a35ebe..fa28251 100644
--- a/inc/hf/ffa_internal.h
+++ b/inc/hf/ffa_internal.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The Hafnium Authors.
+ * Copyright 2021 The Hafnium Authors.
  *
  * Use of this source code is governed by a BSD-style
  * license that can be found in the LICENSE file or at
@@ -15,10 +15,10 @@
 #include "vmapi/hf/ffa.h"
 
 #define FFA_VERSION_RESERVED_BIT UINT32_C(1U << 31)
-
-static inline struct ffa_value ffa_error(uint64_t error_code)
+static inline struct ffa_value ffa_error(int32_t error_code)
 {
-	return (struct ffa_value){.func = FFA_ERROR_32, .arg2 = error_code};
+	return (struct ffa_value){.func = FFA_ERROR_32,
+				  .arg2 = (uint32_t)error_code};
 }
 
 /**
diff --git a/inc/vmapi/hf/ffa.h b/inc/vmapi/hf/ffa.h
index 2cb0514..4e09301 100644
--- a/inc/vmapi/hf/ffa.h
+++ b/inc/vmapi/hf/ffa.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The Hafnium Authors.
+ * Copyright 2021 The Hafnium Authors.
  *
  * Use of this source code is governed by a BSD-style
  * license that can be found in the LICENSE file or at
@@ -228,6 +228,11 @@
 	uint64_t arg7;
 };
 
+static inline int32_t ffa_error_code(struct ffa_value val)
+{
+	return (int32_t)val.arg2;
+}
+
 static inline ffa_vm_id_t ffa_msg_send_sender(struct ffa_value args)
 {
 	return (args.arg1 >> 16) & 0xffff;
diff --git a/src/api.c b/src/api.c
index 2667283..75a06b7 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018 The Hafnium Authors.
+ * Copyright 2021 The Hafnium Authors.
  *
  * Use of this source code is governed by a BSD-style
  * license that can be found in the LICENSE file or at
@@ -1549,7 +1549,7 @@
 		      "Minor revision representation takes more than 16 bits.");
 	if (requested_version & FFA_VERSION_RESERVED_BIT) {
 		/* Invalid encoding, return an error. */
-		return (struct ffa_value){.func = FFA_NOT_SUPPORTED};
+		return (struct ffa_value){.func = (uint32_t)FFA_NOT_SUPPORTED};
 	}
 
 	return (struct ffa_value){
diff --git a/test/inc/test/vmapi/ffa.h b/test/inc/test/vmapi/ffa.h
index c2add9e..85d00a9 100644
--- a/test/inc/test/vmapi/ffa.h
+++ b/test/inc/test/vmapi/ffa.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018 The Hafnium Authors.
+ * Copyright 2021 The Hafnium Authors.
  *
  * Use of this source code is governed by a BSD-style
  * license that can be found in the LICENSE file or at
@@ -17,11 +17,11 @@
 #define FRAGMENTED_SHARE_PAGE_COUNT \
 	(PAGE_SIZE / sizeof(struct ffa_memory_region_constituent))
 
-#define EXPECT_FFA_ERROR(value, ffa_error)       \
-	do {                                     \
-		struct ffa_value v = (value);    \
-		EXPECT_EQ(v.func, FFA_ERROR_32); \
-		EXPECT_EQ(v.arg2, (ffa_error));  \
+#define EXPECT_FFA_ERROR(value, ffa_error)                 \
+	do {                                               \
+		struct ffa_value v = (value);              \
+		EXPECT_EQ(v.func, FFA_ERROR_32);           \
+		EXPECT_EQ(ffa_error_code(v), (ffa_error)); \
 	} while (0)
 
 struct mailbox_buffers {
diff --git a/test/vmapi/primary_with_secondaries/memory_sharing.c b/test/vmapi/primary_with_secondaries/memory_sharing.c
index ee13e2d..393dfc3 100644
--- a/test/vmapi/primary_with_secondaries/memory_sharing.c
+++ b/test/vmapi/primary_with_secondaries/memory_sharing.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018 The Hafnium Authors.
+ * Copyright 2021 The Hafnium Authors.
  *
  * Use of this source code is governed by a BSD-style
  * license that can be found in the LICENSE file or at
@@ -92,9 +92,9 @@
 						EXPECT_EQ(ret.func,
 							  FFA_ERROR_32);
 						EXPECT_TRUE(
-							ret.arg2 ==
+							ffa_error_code(ret) ==
 								FFA_DENIED ||
-							ret.arg2 ==
+							ffa_error_code(ret) ==
 								FFA_INVALID_PARAMETERS);
 					}
 					for (m = 0; m < ARRAY_SIZE(device);
@@ -125,9 +125,9 @@
 						EXPECT_EQ(ret.func,
 							  FFA_ERROR_32);
 						EXPECT_TRUE(
-							ret.arg2 ==
+							ffa_error_code(ret) ==
 								FFA_DENIED ||
-							ret.arg2 ==
+							ffa_error_code(ret) ==
 								FFA_INVALID_PARAMETERS);
 					}
 				}
@@ -193,8 +193,8 @@
 			  0);
 		ret = ffa_mem_donate(msg_size, msg_size);
 		EXPECT_EQ(ret.func, FFA_ERROR_32);
-		EXPECT_TRUE(ret.arg2 == FFA_DENIED ||
-			    ret.arg2 == FFA_INVALID_PARAMETERS);
+		EXPECT_TRUE((ffa_error_code(ret) == FFA_DENIED) ||
+			    (ffa_error_code(ret) == FFA_INVALID_PARAMETERS));
 	}
 }
 
diff --git a/test/vmapi/primary_with_secondaries/run_race.c b/test/vmapi/primary_with_secondaries/run_race.c
index 2368fdc..69fdd89 100644
--- a/test/vmapi/primary_with_secondaries/run_race.c
+++ b/test/vmapi/primary_with_secondaries/run_race.c
@@ -39,7 +39,7 @@
 		do {
 			run_res = ffa_run(SERVICE_VM1, 0);
 		} while (run_res.func == FFA_ERROR_32 &&
-			 run_res.arg2 == FFA_BUSY);
+			 ffa_error_code(run_res) == FFA_BUSY);
 
 		/* Break out if we received a message with non-zero length. */
 		if (run_res.func == FFA_MSG_SEND_32 &&
diff --git a/test/vmapi/primary_with_secondaries/services/interruptible.c b/test/vmapi/primary_with_secondaries/services/interruptible.c
index 92e0136..1a85f64 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018 The Hafnium Authors.
+ * Copyright 2021 The Hafnium Authors.
  *
  * Use of this source code is governed by a BSD-style
  * license that can be found in the LICENSE file or at
@@ -47,7 +47,7 @@
 	do {
 		received = ffa_msg_wait();
 	} while (received.func == FFA_ERROR_32 &&
-		 received.arg2 == FFA_INTERRUPTED);
+		 ffa_error_code(received) == FFA_INTERRUPTED);
 
 	return received;
 }