Use new SPCI beta function identifiers.

Note that this commit doesn't move to the new style of return values yet,
nor does it follow all the semantics of the new version.

Bug: 132395846
Change-Id: I02f41f2b84cfd9babd37aa5e2aae875da85f949e
diff --git a/inc/hf/api.h b/inc/hf/api.h
index a808e5d..e041c96 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -55,8 +55,7 @@
 
 spci_return_t api_spci_msg_send(uint32_t attributes, struct vcpu *current,
 				struct vcpu **next);
-int32_t api_spci_msg_recv(uint32_t attributes, struct vcpu *current,
-			  struct vcpu **next);
+int32_t api_spci_msg_recv(bool block, struct vcpu *current, struct vcpu **next);
 int32_t api_spci_yield(struct vcpu *current, struct vcpu **next);
 int32_t api_spci_version(void);
 spci_return_t api_spci_share_memory(struct vm_locked to_locked,
diff --git a/inc/vmapi/hf/call.h b/inc/vmapi/hf/call.h
index 67c8e35..9edc542 100644
--- a/inc/vmapi/hf/call.h
+++ b/inc/vmapi/hf/call.h
@@ -125,17 +125,16 @@
 }
 
 /**
- * Called by secondary VMs to receive a message. The call can optionally block
- * until a message is received.
+ * Called by secondary VMs to receive a message. This will block until a message
+ * is received.
  *
  * The mailbox must be cleared before a new message can be received.
  *
- * If no message is immediately available, `block` is true, and there are no
- * enabled and pending interrupts (irrespective of whether interrupts are
- * enabled globally), then this will block until a message is available or an
- * enabled interrupt becomes pending. This matches the behaviour of the WFI
- * instruction on aarch64, except that a message becoming available is also
- * treated like a wake-up event.
+ * If no message is immediately available and there are no enabled and pending
+ * interrupts (irrespective of whether interrupts are enabled globally), then
+ * this will block until a message is available or an enabled interrupt becomes
+ * pending. This matches the behaviour of the WFI instruction on aarch64, except
+ * that a message becoming available is also treated like a wake-up event.
  *
  * Returns:
  *  - SPCI_SUCCESS if a message is successfully received.
@@ -143,9 +142,26 @@
  *    during the call.
  *  - SPCI_RETRY if there was no pending message, and `block` was false.
  */
-static inline int32_t spci_msg_recv(int32_t attributes)
+static inline int32_t spci_msg_wait(void)
 {
-	return hf_call(SPCI_MSG_RECV_32, attributes, 0, 0);
+	return hf_call(SPCI_MSG_WAIT_32, 0, 0, 0);
+}
+
+/**
+ * Called by secondary VMs to receive a message. The call will return whether or
+ * not a message is available.
+ *
+ * The mailbox must be cleared before a new message can be received.
+ *
+ * Returns:
+ *  - SPCI_SUCCESS if a message is successfully received.
+ *  - SPCI_INTERRUPTED if the caller is the primary VM or an interrupt happened
+ *    during the call.
+ *  - SPCI_RETRY if there was no pending message, and `block` was false.
+ */
+static inline int32_t spci_msg_poll(void)
+{
+	return hf_call(SPCI_MSG_POLL_32, 0, 0, 0);
 }
 
 /**
diff --git a/inc/vmapi/hf/spci.h b/inc/vmapi/hf/spci.h
index 98d4155..39fcaf1 100644
--- a/inc/vmapi/hf/spci.h
+++ b/inc/vmapi/hf/spci.h
@@ -26,24 +26,31 @@
 #define SPCI_HIGH_32_ID 0x8400007F
 
 /* SPCI function identifiers. */
-#define SPCI_VERSION_32               0x84000060
-#define SPCI_MSG_BUF_LIST_EXCHANGE_32 0x84000061
-#define SPCI_MSG_RECV_32              0x84000062
-#define SPCI_MSG_PUT_32               0x84000063
-#define SPCI_MSG_SEND_32              0x84000064
-#define SPCI_MSG_SEND_REC_32          0x84000065
-#define SPCI_RUN_32                   0x84000066
-#define SPCI_YIELD_32                 0x84000067
+#define SPCI_ERROR_32                 0x84000060
+#define SPCI_SUCCESS_32               0x84000061
+#define SPCI_INTERRUPT_32             0x84000062
+#define SPCI_VERSION_32               0x84000063
+#define SPCI_RX_RELEASE_32            0x84000064
+#define SPCI_RXTX_MAP_32              0x84000065
+#define SPCI_RXTX_UNMAP_32            0x84000066
+#define SPCI_PARTITION_INFO_GET_32    0x84000067
+#define SPCI_ID_GET_32                0x84000068
+#define SPCI_MSG_WAIT_32              0x84000069
+#define SPCI_MSG_POLL_32              0x8400006A
+#define SPCI_YIELD_32                 0x8400006B
+#define SPCI_MSG_SEND_32              0x8400006C
+#define SPCI_RUN_32                   0x8400006D
+#define SPCI_MSG_SEND_DIRECT_REQ_32   0x8400006E
+#define SPCI_MSG_SEND_DIRECT_RESP_32  0x8400006F
 
-/* SPCI return codes. */
 #define SPCI_SUCCESS            INT32_C(0)
+/* SPCI error codes. */
 #define SPCI_NOT_SUPPORTED      INT32_C(-1)
 #define SPCI_INVALID_PARAMETERS INT32_C(-2)
 #define SPCI_NO_MEMORY          INT32_C(-3)
 #define SPCI_BUSY               INT32_C(-4)
 #define SPCI_INTERRUPTED        INT32_C(-5)
 #define SPCI_DENIED             INT32_C(-6)
-/* TODO: return code currently undefined in SPCI alpha2. */
 #define SPCI_RETRY              INT32_C(-7)
 
 /* Architected memory sharing message IDs. */
diff --git a/src/api.c b/src/api.c
index f4ec664..ff56751 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1040,13 +1040,10 @@
  *
  * No new messages can be received until the mailbox has been cleared.
  */
-int32_t api_spci_msg_recv(uint32_t attributes, struct vcpu *current,
-			  struct vcpu **next)
+int32_t api_spci_msg_recv(bool block, struct vcpu *current, struct vcpu **next)
 {
 	struct vm *vm = current->vm;
 	int32_t return_code;
-	bool block =
-		(attributes & SPCI_MSG_RECV_BLOCK_MASK) == SPCI_MSG_RECV_BLOCK;
 
 	/*
 	 * The primary VM will receive messages as a status code from running
diff --git a/src/arch/aarch64/hypervisor/handler.c b/src/arch/aarch64/hypervisor/handler.c
index d896c80..a695938 100644
--- a/src/arch/aarch64/hypervisor/handler.c
+++ b/src/arch/aarch64/hypervisor/handler.c
@@ -303,8 +303,11 @@
 	case SPCI_MSG_SEND_32:
 		*ret = api_spci_msg_send(arg1, current(), next);
 		return true;
-	case SPCI_MSG_RECV_32:
-		*ret = api_spci_msg_recv(arg1, current(), next);
+	case SPCI_MSG_WAIT_32:
+		*ret = api_spci_msg_recv(true, current(), next);
+		return true;
+	case SPCI_MSG_POLL_32:
+		*ret = api_spci_msg_recv(false, current(), next);
 		return true;
 	}
 
diff --git a/test/hftest/service.c b/test/hftest/service.c
index 72efa7d..3031772 100644
--- a/test/hftest/service.c
+++ b/test/hftest/service.c
@@ -102,7 +102,7 @@
 	hf_vm_configure(send_addr, recv_addr);
 
 	/* Receive the name of the service to run. */
-	spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+	spci_msg_wait();
 	memiter_init(&args, recv_msg->payload, recv_msg->length);
 	service = find_service(&args);
 	hf_mailbox_clear();
diff --git a/test/linux/hftest_socket.c b/test/linux/hftest_socket.c
index 0b69ea7..7a9d7f1 100644
--- a/test/linux/hftest_socket.c
+++ b/test/linux/hftest_socket.c
@@ -83,7 +83,7 @@
 		struct spci_message *recv_buf = (struct spci_message *)recv;
 
 		/* Receive the packet. */
-		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		spci_msg_wait();
 		EXPECT_LE(recv_buf->length, SPCI_MSG_PAYLOAD_MAX);
 
 		/* Echo the message back to the sender. */
diff --git a/test/vmapi/gicv3/services/common.c b/test/vmapi/gicv3/services/common.c
index b6edc56..d5d3cd2 100644
--- a/test/vmapi/gicv3/services/common.c
+++ b/test/vmapi/gicv3/services/common.c
@@ -28,7 +28,7 @@
 	int32_t received;
 
 	do {
-		received = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		received = spci_msg_wait();
 	} while (received == SPCI_INTERRUPTED);
 
 	return received;
diff --git a/test/vmapi/gicv3/services/timer.c b/test/vmapi/gicv3/services/timer.c
index 0cc7341..d99aa78 100644
--- a/test/vmapi/gicv3/services/timer.c
+++ b/test/vmapi/gicv3/services/timer.c
@@ -113,7 +113,7 @@
 				event_wait();
 			}
 		} else if (receive) {
-			int32_t res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+			int32_t res = spci_msg_wait();
 
 			EXPECT_EQ(res, SPCI_INTERRUPTED);
 		} else {
diff --git a/test/vmapi/primary_with_secondaries/no_services.c b/test/vmapi/primary_with_secondaries/no_services.c
index 975ea6d..2f2c0b5 100644
--- a/test/vmapi/primary_with_secondaries/no_services.c
+++ b/test/vmapi/primary_with_secondaries/no_services.c
@@ -146,7 +146,7 @@
  */
 TEST(hf_mailbox_receive, cannot_receive_from_primary_blocking)
 {
-	int32_t res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+	int32_t res = spci_msg_wait();
 	EXPECT_NE(res, SPCI_SUCCESS);
 }
 
@@ -155,6 +155,6 @@
  */
 TEST(hf_mailbox_receive, cannot_receive_from_primary_non_blocking)
 {
-	int32_t res = spci_msg_recv(0);
+	int32_t res = spci_msg_poll();
 	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 04cb6a3..a9d5b02 100644
--- a/test/vmapi/primary_with_secondaries/services/echo.c
+++ b/test/vmapi/primary_with_secondaries/services/echo.c
@@ -25,7 +25,7 @@
 {
 	/* Loop, echo messages back to the sender. */
 	for (;;) {
-		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		spci_msg_wait();
 		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 03dcfd4..b32a6f6 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 (;;) {
-		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		spci_msg_wait();
 
 		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 5a04515..adc9b16 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible.c
@@ -56,7 +56,7 @@
 	int32_t received;
 
 	do {
-		received = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		received = spci_msg_wait();
 	} 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 296065f..07a4cbc 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
@@ -38,14 +38,14 @@
 	arch_irq_enable();
 
 	for (;;) {
-		uint32_t res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		uint32_t res = spci_msg_wait();
 		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 == SPCI_INTERRUPTED) {
 			spci_yield();
-			res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+			res = spci_msg_wait();
 		}
 
 		memcpy_s(message->payload, SPCI_MSG_PAYLOAD_MAX,
diff --git a/test/vmapi/primary_with_secondaries/services/memory.c b/test/vmapi/primary_with_secondaries/services/memory.c
index cfd05f6..fbd7cb1 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 (;;) {
-		EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+		EXPECT_EQ(spci_msg_wait(), 0);
 		uint8_t *ptr;
 		size_t i;
 
@@ -60,7 +60,7 @@
 {
 	/* Loop, giving memory back to the sender. */
 	for (;;) {
-		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		spci_msg_wait();
 		uint8_t *ptr;
 
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -98,7 +98,7 @@
 {
 	/* Loop, giving memory back to the sender. */
 	for (;;) {
-		EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+		EXPECT_EQ(spci_msg_wait(), 0);
 		uint8_t *ptr;
 
 		/* Check the memory was cleared. */
@@ -179,7 +179,7 @@
 {
 	/* Loop, giving memory back to the sender. */
 	for (;;) {
-		EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+		EXPECT_EQ(spci_msg_wait(), 0);
 		uint8_t *ptr;
 
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -211,7 +211,7 @@
 
 TEST_SERVICE(spci_donate_check_upper_bound)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+	EXPECT_EQ(spci_msg_wait(), 0);
 	uint8_t *ptr;
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -227,7 +227,7 @@
 
 TEST_SERVICE(spci_donate_check_lower_bound)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+	EXPECT_EQ(spci_msg_wait(), 0);
 	uint8_t *ptr;
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -246,7 +246,7 @@
  */
 TEST_SERVICE(spci_donate_secondary_and_fault)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+	EXPECT_EQ(spci_msg_wait(), 0);
 	uint8_t *ptr;
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -274,7 +274,7 @@
  */
 TEST_SERVICE(spci_donate_twice)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+	EXPECT_EQ(spci_msg_wait(), 0);
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
 	struct spci_message *send_buf = SERVICE_SEND_BUFFER();
@@ -307,7 +307,7 @@
 TEST_SERVICE(spci_memory_receive)
 {
 	for (;;) {
-		EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+		EXPECT_EQ(spci_msg_wait(), 0);
 		uint8_t *ptr;
 
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -330,7 +330,7 @@
  */
 TEST_SERVICE(spci_donate_invalid_source)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), 0);
+	EXPECT_EQ(spci_msg_wait(), 0);
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
 	struct spci_message *send_buf = SERVICE_SEND_BUFFER();
@@ -356,7 +356,7 @@
 {
 	/* Loop, giving memory back to the sender. */
 	for (;;) {
-		EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), SPCI_SUCCESS);
+		EXPECT_EQ(spci_msg_wait(), SPCI_SUCCESS);
 		uint8_t *ptr;
 
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -396,7 +396,7 @@
 TEST_SERVICE(spci_memory_donate_relinquish)
 {
 	for (;;) {
-		EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), SPCI_SUCCESS);
+		EXPECT_EQ(spci_msg_wait(), SPCI_SUCCESS);
 		uint8_t *ptr;
 
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -429,7 +429,7 @@
  */
 TEST_SERVICE(spci_lend_invalid_source)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), SPCI_SUCCESS);
+	EXPECT_EQ(spci_msg_wait(), SPCI_SUCCESS);
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
 	struct spci_message *send_buf = SERVICE_SEND_BUFFER();
@@ -465,7 +465,7 @@
 TEST_SERVICE(spci_memory_lend_relinquish_X)
 {
 	for (;;) {
-		EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), SPCI_SUCCESS);
+		EXPECT_EQ(spci_msg_wait(), SPCI_SUCCESS);
 		uint64_t *ptr;
 
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -499,7 +499,7 @@
 TEST_SERVICE(spci_memory_lend_relinquish_RW)
 {
 	for (;;) {
-		EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), SPCI_SUCCESS);
+		EXPECT_EQ(spci_msg_wait(), SPCI_SUCCESS);
 		uint8_t *ptr;
 
 		struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -537,7 +537,7 @@
  */
 TEST_SERVICE(spci_lend_check_lower_bound)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), SPCI_SUCCESS);
+	EXPECT_EQ(spci_msg_wait(), SPCI_SUCCESS);
 	uint8_t *ptr;
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -557,7 +557,7 @@
  */
 TEST_SERVICE(spci_lend_check_upper_bound)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), SPCI_SUCCESS);
+	EXPECT_EQ(spci_msg_wait(), SPCI_SUCCESS);
 	uint8_t *ptr;
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
@@ -574,7 +574,7 @@
 
 TEST_SERVICE(spci_memory_lend_twice)
 {
-	EXPECT_EQ(spci_msg_recv(SPCI_MSG_RECV_BLOCK), SPCI_SUCCESS);
+	EXPECT_EQ(spci_msg_wait(), SPCI_SUCCESS);
 	uint8_t *ptr;
 
 	struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
diff --git a/test/vmapi/primary_with_secondaries/services/receive_block.c b/test/vmapi/primary_with_secondaries/services/receive_block.c
index 0b8a1b5..1b03506 100644
--- a/test/vmapi/primary_with_secondaries/services/receive_block.c
+++ b/test/vmapi/primary_with_secondaries/services/receive_block.c
@@ -46,7 +46,7 @@
 	hf_interrupt_enable(EXTERNAL_INTERRUPT_ID_A, true);
 
 	for (i = 0; i < 10; ++i) {
-		int32_t res = spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		int32_t res = spci_msg_wait();
 		EXPECT_EQ(res, SPCI_INTERRUPTED);
 	}
 
diff --git a/test/vmapi/primary_with_secondaries/services/relay.c b/test/vmapi/primary_with_secondaries/services/relay.c
index 5ccda5f..86eed79 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. */
-		spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+		spci_msg_wait();
 
 		/* 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 d44da6a..1d626ba 100644
--- a/test/vmapi/primary_with_secondaries/services/spci_check.c
+++ b/test/vmapi/primary_with_secondaries/services/spci_check.c
@@ -41,7 +41,7 @@
 	};
 
 	/* Wait for single message to be sent by the primary VM. */
-	spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+	spci_msg_wait();
 
 	/* Ensure message header has all fields correctly set. */
 	EXPECT_EQ(recv_buf->flags, expected_message.flags);
@@ -70,7 +70,7 @@
 	const char message[] = "this should be truncated";
 
 	/* Wait for single message to be sent by the primary VM. */
-	spci_msg_recv(SPCI_MSG_RECV_BLOCK);
+	spci_msg_wait();
 
 	/* Verify the length is as expected. */
 	EXPECT_EQ(16, recv_buf->length);
@@ -85,7 +85,7 @@
 TEST_SERVICE(spci_recv_non_blocking)
 {
 	/* Wait for single message to be sent by the primary VM. */
-	EXPECT_EQ(spci_msg_recv(0), SPCI_RETRY);
+	EXPECT_EQ(spci_msg_poll(), SPCI_RETRY);
 
 	spci_yield();
 }