SPCI: SPCI_MSG_RECV.

Morph the existing vmapi api_mailbox_receive onto
api_spci_msg_recv.

Change-Id: Ie78f8985cfc55509fcd71eece22d6397b52d717d
diff --git a/test/hftest/hftest_service.c b/test/hftest/hftest_service.c
index 2a1b2a0..98c237b 100644
--- a/test/hftest/hftest_service.c
+++ b/test/hftest/hftest_service.c
@@ -91,7 +91,7 @@
 	hf_vm_configure(send_addr, recv_addr);
 
 	/* Receive the name of the service to run. */
-	hf_mailbox_receive(true);
+	spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 	memiter_init(&args, recv_msg->payload, recv_msg->length);
 	service = find_service(&args);
 	hf_mailbox_clear();
diff --git a/test/vmapi/gicv3/services/common.c b/test/vmapi/gicv3/services/common.c
index 79a9690..b6edc56 100644
--- a/test/vmapi/gicv3/services/common.c
+++ b/test/vmapi/gicv3/services/common.c
@@ -18,15 +18,18 @@
 
 #include "vmapi/hf/call.h"
 
+#include "hftest.h"
 /**
  * Try to receive a message from the mailbox, blocking if necessary, and
  * retrying if interrupted.
  */
-struct hf_mailbox_receive_return mailbox_receive_retry(void)
+int32_t mailbox_receive_retry(void)
 {
-	struct hf_mailbox_receive_return received;
+	int32_t received;
+
 	do {
-		received = hf_mailbox_receive(true);
-	} while (received.vm_id == HF_INVALID_VM_ID && received.size == 0);
+		received = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+	} while (received == SPCI_INTERRUPTED);
+
 	return received;
 }
diff --git a/test/vmapi/gicv3/services/common.h b/test/vmapi/gicv3/services/common.h
index ec81f1d..635fa0f 100644
--- a/test/vmapi/gicv3/services/common.h
+++ b/test/vmapi/gicv3/services/common.h
@@ -16,4 +16,4 @@
 
 #include "vmapi/hf/call.h"
 
-struct hf_mailbox_receive_return mailbox_receive_retry(void);
+int32_t mailbox_receive_retry(void);
diff --git a/test/vmapi/gicv3/services/timer.c b/test/vmapi/gicv3/services/timer.c
index 79a2b8a..2daf2b9 100644
--- a/test/vmapi/gicv3/services/timer.c
+++ b/test/vmapi/gicv3/services/timer.c
@@ -112,14 +112,9 @@
 				event_wait();
 			}
 		} else if (receive) {
-			struct hf_mailbox_receive_return received =
-				hf_mailbox_receive(true);
-			/*
-			 * Expect to be interrupted, not to actually
-			 * receive a message.
-			 */
-			EXPECT_EQ(received.vm_id, HF_INVALID_VM_ID);
-			EXPECT_EQ(received.size, 0);
+			int32_t res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+
+			EXPECT_EQ(res, SPCI_INTERRUPTED);
 		} else {
 			/* Busy wait until the timer fires. */
 			while (!timer_fired) {
diff --git a/test/vmapi/primary_with_secondaries/no_services.c b/test/vmapi/primary_with_secondaries/no_services.c
index 9d7f29b..4d9b213 100644
--- a/test/vmapi/primary_with_secondaries/no_services.c
+++ b/test/vmapi/primary_with_secondaries/no_services.c
@@ -147,9 +147,8 @@
  */
 TEST(hf_mailbox_receive, cannot_receive_from_primary_blocking)
 {
-	struct hf_mailbox_receive_return res = hf_mailbox_receive(true);
-	EXPECT_EQ(res.vm_id, HF_INVALID_VM_ID);
-	EXPECT_EQ(res.size, 0);
+	int32_t res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+	EXPECT_NE(res, SPCI_SUCCESS);
 }
 
 /**
@@ -157,7 +156,6 @@
  */
 TEST(hf_mailbox_receive, cannot_receive_from_primary_non_blocking)
 {
-	struct hf_mailbox_receive_return res = hf_mailbox_receive(false);
-	EXPECT_EQ(res.vm_id, HF_INVALID_VM_ID);
-	EXPECT_EQ(res.size, 0);
+	int32_t res = spci_msg_recv(0);
+	EXPECT_NE(res, SPCI_SUCCESS);
 }
diff --git a/test/vmapi/primary_with_secondaries/services/echo.c b/test/vmapi/primary_with_secondaries/services/echo.c
index c58ccfb..bc33a25 100644
--- a/test/vmapi/primary_with_secondaries/services/echo.c
+++ b/test/vmapi/primary_with_secondaries/services/echo.c
@@ -26,7 +26,7 @@
 {
 	/* Loop, echo messages back to the sender. */
 	for (;;) {
-		hf_mailbox_receive(true);
+		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 		struct spci_message *send_buf = SERVICE_SEND_BUFFER();
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
 
diff --git a/test/vmapi/primary_with_secondaries/services/echo_with_notification.c b/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
index e6c66c0..424e3ab 100644
--- a/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
+++ b/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
@@ -53,7 +53,7 @@
 
 	/* Loop, echo messages back to the sender. */
 	for (;;) {
-		hf_mailbox_receive(true);
+		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 
 		struct spci_message *send_buf = SERVICE_SEND_BUFFER();
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
diff --git a/test/vmapi/primary_with_secondaries/services/interruptible.c b/test/vmapi/primary_with_secondaries/services/interruptible.c
index c5c67a5..523eaca 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible.c
@@ -21,6 +21,7 @@
 #include "hf/dlog.h"
 
 #include "vmapi/hf/call.h"
+#include "vmapi/hf/spci.h"
 
 #include "hftest.h"
 #include "primary_with_secondary.h"
@@ -49,15 +50,14 @@
  * Try to receive a message from the mailbox, blocking if necessary, and
  * retrying if interrupted.
  */
-struct hf_mailbox_receive_return mailbox_receive_retry()
+int32_t mailbox_receive_retry()
 {
-	struct hf_mailbox_receive_return received = {
-		.vm_id = HF_INVALID_VM_ID,
-		.size = 0,
-	};
-	while (received.vm_id == HF_INVALID_VM_ID && received.size == 0) {
-		received = hf_mailbox_receive(true);
-	}
+	int32_t received;
+
+	do {
+		received = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+	} while (received == SPCI_INTERRUPTED);
+
 	return received;
 }
 
diff --git a/test/vmapi/primary_with_secondaries/services/interruptible_echo.c b/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
index dff3b6d..036566c 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
@@ -38,19 +38,20 @@
 	arch_irq_enable();
 
 	for (;;) {
-		struct hf_mailbox_receive_return res = hf_mailbox_receive(true);
+		uint32_t res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 		struct spci_message *message = SERVICE_SEND_BUFFER();
+		struct spci_message *recv_message = SERVICE_RECV_BUFFER();
 
 		/* Retry if interrupted but made visible with the yield. */
-		while (res.vm_id == HF_INVALID_VM_ID && res.size == 0) {
+		while (res == SPCI_INTERRUPTED) {
 			hf_vcpu_yield();
-			res = hf_mailbox_receive(true);
+			res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 		}
 
-		memcpy(message->payload, SERVICE_RECV_BUFFER()->payload,
-		       res.size);
-		spci_message_init(message, res.size, HF_PRIMARY_VM_ID,
-				  SERVICE_VM0);
+		memcpy(message->payload, recv_message->payload,
+		       recv_message->length);
+		spci_message_init(message, recv_message->length,
+				  HF_PRIMARY_VM_ID, SERVICE_VM0);
 
 		hf_mailbox_clear();
 		spci_msg_send(0);
diff --git a/test/vmapi/primary_with_secondaries/services/memory.c b/test/vmapi/primary_with_secondaries/services/memory.c
index a826184..babb911 100644
--- a/test/vmapi/primary_with_secondaries/services/memory.c
+++ b/test/vmapi/primary_with_secondaries/services/memory.c
@@ -28,7 +28,7 @@
 {
 	/* Loop, writing message to the shared memory. */
 	for (;;) {
-		hf_mailbox_receive(true);
+		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 		uint8_t *ptr;
 		size_t i;
 
@@ -60,7 +60,7 @@
 {
 	/* Loop, giving memory back to the sender. */
 	for (;;) {
-		hf_mailbox_receive(true);
+		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 		uint8_t *ptr;
 
 		/* Check the memory was cleared. */
diff --git a/test/vmapi/primary_with_secondaries/services/receive_block.c b/test/vmapi/primary_with_secondaries/services/receive_block.c
index 59a10a5..b241b76 100644
--- a/test/vmapi/primary_with_secondaries/services/receive_block.c
+++ b/test/vmapi/primary_with_secondaries/services/receive_block.c
@@ -46,9 +46,8 @@
 	hf_interrupt_enable(EXTERNAL_INTERRUPT_ID_A, true);
 
 	for (i = 0; i < 10; ++i) {
-		struct hf_mailbox_receive_return res = hf_mailbox_receive(true);
-		EXPECT_EQ(res.vm_id, HF_INVALID_VM_ID);
-		EXPECT_EQ(res.size, 0);
+		int32_t res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		EXPECT_EQ(res, SPCI_INTERRUPTED);
 	}
 
 	memcpy(SERVICE_SEND_BUFFER()->payload, message, sizeof(message));
diff --git a/test/vmapi/primary_with_secondaries/services/relay.c b/test/vmapi/primary_with_secondaries/services/relay.c
index 627a461..7ac7ade 100644
--- a/test/vmapi/primary_with_secondaries/services/relay.c
+++ b/test/vmapi/primary_with_secondaries/services/relay.c
@@ -36,7 +36,7 @@
 		uint32_t next_message_size;
 
 		/* Receive the message to relay. */
-		hf_mailbox_receive(true);
+		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 
 		/* Prepare to relay the message. */
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
diff --git a/test/vmapi/primary_with_secondaries/services/spci_check.c b/test/vmapi/primary_with_secondaries/services/spci_check.c
index a81fc01..53a063a 100644
--- a/test/vmapi/primary_with_secondaries/services/spci_check.c
+++ b/test/vmapi/primary_with_secondaries/services/spci_check.c
@@ -42,7 +42,7 @@
 	};
 
 	/* Wait for single message to be sent by the primary VM. */
-	hf_mailbox_receive(true);
+	spci_msg_recv(SPCI_MSG_RECV_BLOCK);
 
 	/* Ensure message header has all fields correctly set. */
 	EXPECT_EQ(recv_buf->flags, expected_message.flags);