Return SPCI_MEM_* rather than SPCI_MSG_SEND for push memory sharing.

Bug: 132420445
Change-Id: I80cb9832f90899eeb57af2cf209f0fa5f2fc1ca9
diff --git a/inc/hf/api.h b/inc/hf/api.h
index dacc889..f8de195 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -60,7 +60,7 @@
 struct spci_value api_spci_features(uint32_t function_id);
 struct spci_value api_spci_run(spci_vm_id_t vm_id, spci_vcpu_index_t vcpu_idx,
 			       const struct vcpu *current, struct vcpu **next);
-struct spci_value api_spci_mem_send(uint32_t share_type, ipaddr_t address,
+struct spci_value api_spci_mem_send(uint32_t share_func, ipaddr_t address,
 				    uint32_t page_count,
 				    uint32_t remaining_fragment_count,
 				    uint32_t length, uint32_t handle,
diff --git a/inc/hf/spci_internal.h b/inc/hf/spci_internal.h
index 1fc226f..782b2d2 100644
--- a/inc/hf/spci_internal.h
+++ b/inc/hf/spci_internal.h
@@ -64,4 +64,4 @@
 struct spci_value spci_msg_handle_architected_message(
 	struct vm_locked to_locked, struct vm_locked from_locked,
 	struct spci_memory_region *memory_region, uint32_t size,
-	uint32_t attributes, struct mpool *api_page_pool);
+	uint32_t share_func, struct mpool *api_page_pool);
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 9fff714..e421a3d 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -79,8 +79,11 @@
 	/** The size of the message currently in `recv`. */
 	uint32_t recv_size;
 
-	/** The attributes of the message currently in `recv`. */
-	uint32_t recv_attributes;
+	/**
+	 * The SPCI function ID to use to deliver the message currently in
+	 * `recv`.
+	 */
+	uint32_t recv_func;
 
 	/**
 	 * List of wait_entry structs representing VMs that want to be notified
diff --git a/inc/vmapi/hf/spci.h b/inc/vmapi/hf/spci.h
index e42c8d5..a70dcdd 100644
--- a/inc/vmapi/hf/spci.h
+++ b/inc/vmapi/hf/spci.h
@@ -63,11 +63,6 @@
 
 #define SPCI_MSG_SEND_NOTIFY 0x1
 #define SPCI_MSG_SEND_NOTIFY_MASK 0x1
-#define SPCI_MSG_SEND_LEGACY_MEMORY_DONATE 0x10
-#define SPCI_MSG_SEND_LEGACY_MEMORY_LEND 0x20
-#define SPCI_MSG_SEND_LEGACY_MEMORY_SHARE 0x30
-#define SPCI_MSG_SEND_LEGACY_MEMORY_RELINQUISH 0x40
-#define SPCI_MSG_SEND_LEGACY_MEMORY_MASK 0x70
 
 #define SPCI_SLEEP_INDEFINITE 0
 
diff --git a/src/api.c b/src/api.c
index 143a624..5170a41 100644
--- a/src/api.c
+++ b/src/api.c
@@ -367,11 +367,25 @@
  */
 static struct spci_value spci_msg_recv_return(const struct vm *receiver)
 {
-	return (struct spci_value){
-		.func = SPCI_MSG_SEND_32,
-		.arg1 = (receiver->mailbox.recv_sender << 16) | receiver->id,
-		.arg3 = receiver->mailbox.recv_size,
-		.arg4 = receiver->mailbox.recv_attributes};
+	switch (receiver->mailbox.recv_func) {
+	case SPCI_MSG_SEND_32:
+		return (struct spci_value){
+			.func = SPCI_MSG_SEND_32,
+			.arg1 = (receiver->mailbox.recv_sender << 16) |
+				receiver->id,
+			.arg3 = receiver->mailbox.recv_size};
+	case SPCI_MEM_DONATE_32:
+	case SPCI_MEM_LEND_32:
+	case SPCI_MEM_SHARE_32:
+	case HF_SPCI_MEM_RELINQUISH:
+		return (struct spci_value){.func = receiver->mailbox.recv_func,
+					   .arg4 = receiver->mailbox.recv_size};
+	default:
+		/* This should never be reached, but return an error in case. */
+		dlog("Tried to return an invalid message function %#x\n",
+		     receiver->mailbox.recv_func);
+		return spci_error(SPCI_DENIED);
+	}
 }
 
 /**
@@ -905,11 +919,11 @@
 	/* Messages for the primary VM are delivered directly. */
 	if (to.vm->id == HF_PRIMARY_VM_ID) {
 		/*
-		 * Only tell the primary VM the size if the message is for it,
-		 * to avoid leaking data about messages for other VMs.
+		 * Only tell the primary VM the size and other details if the
+		 * message is for it, to avoid leaking data about messages for
+		 * other VMs.
 		 */
-		primary_ret.arg3 = to.vm->mailbox.recv_size;
-		primary_ret.arg4 = to.vm->mailbox.recv_attributes;
+		primary_ret = spci_msg_recv_return(to.vm);
 
 		to.vm->mailbox.state = MAILBOX_STATE_READ;
 		*next = api_switch_to_primary(current, primary_ret,
@@ -992,7 +1006,7 @@
 	memcpy_s(to->mailbox.recv, SPCI_MSG_PAYLOAD_MAX, from_msg, size);
 	to->mailbox.recv_size = size;
 	to->mailbox.recv_sender = sender_vm_id;
-	to->mailbox.recv_attributes = 0;
+	to->mailbox.recv_func = SPCI_MSG_SEND_32;
 	ret = (struct spci_value){.func = SPCI_SUCCESS_32};
 
 	deliver_msg(to_locked, sender_vm_id, current, next);
@@ -1407,7 +1421,7 @@
 	}
 }
 
-struct spci_value api_spci_mem_send(uint32_t share_type, ipaddr_t address,
+struct spci_value api_spci_mem_send(uint32_t share_func, ipaddr_t address,
 				    uint32_t page_count,
 				    uint32_t remaining_fragment_count,
 				    uint32_t length, uint32_t handle,
@@ -1487,7 +1501,7 @@
 
 	ret = spci_msg_handle_architected_message(
 		vm_to_from_lock.vm1, vm_to_from_lock.vm2, memory_region, length,
-		share_type, &api_page_pool);
+		share_func, &api_page_pool);
 
 	if (ret.func == SPCI_SUCCESS_32) {
 		deliver_msg(vm_to_from_lock.vm1, from->id, current, next);
diff --git a/src/arch/aarch64/hypervisor/handler.c b/src/arch/aarch64/hypervisor/handler.c
index b1b3b59..231bbe4 100644
--- a/src/arch/aarch64/hypervisor/handler.c
+++ b/src/arch/aarch64/hypervisor/handler.c
@@ -320,11 +320,13 @@
 
 static bool spci_handler(struct spci_value *args, struct vcpu **next)
 {
+	uint32_t func = args->func & ~SMCCC_CONVENTION_MASK;
+
 	/*
 	 * NOTE: When adding new methods to this handler update
 	 * api_spci_features accordingly.
 	 */
-	switch (args->func & ~SMCCC_CONVENTION_MASK) {
+	switch (func) {
 	case SPCI_VERSION_32:
 		*args = api_spci_version();
 		return true;
@@ -367,28 +369,12 @@
 				     current(), next);
 		return true;
 	case SPCI_MEM_DONATE_32:
-		*args = api_spci_mem_send(SPCI_MSG_SEND_LEGACY_MEMORY_DONATE,
-					  ipa_init(args->arg1), args->arg2,
-					  args->arg3, args->arg4, args->arg5,
-					  current(), next);
-		return true;
 	case SPCI_MEM_LEND_32:
-		*args = api_spci_mem_send(SPCI_MSG_SEND_LEGACY_MEMORY_LEND,
-					  ipa_init(args->arg1), args->arg2,
-					  args->arg3, args->arg4, args->arg5,
-					  current(), next);
-		return true;
 	case SPCI_MEM_SHARE_32:
-		*args = api_spci_mem_send(SPCI_MSG_SEND_LEGACY_MEMORY_SHARE,
-					  ipa_init(args->arg1), args->arg2,
-					  args->arg3, args->arg4, args->arg5,
-					  current(), next);
-		return true;
 	case HF_SPCI_MEM_RELINQUISH:
-		*args = api_spci_mem_send(
-			SPCI_MSG_SEND_LEGACY_MEMORY_RELINQUISH,
-			ipa_init(args->arg1), args->arg2, args->arg3,
-			args->arg4, args->arg5, current(), next);
+		*args = api_spci_mem_send(func, ipa_init(args->arg1),
+					  args->arg2, args->arg3, args->arg4,
+					  args->arg5, current(), next);
 		return true;
 	}
 
diff --git a/src/spci_architected_message.c b/src/spci_architected_message.c
index 9d9c6c0..dd24aee 100644
--- a/src/spci_architected_message.c
+++ b/src/spci_architected_message.c
@@ -71,7 +71,7 @@
  *
  */
 static bool spci_msg_check_transition(struct vm *to, struct vm *from,
-				      uint32_t share_type,
+				      uint32_t share_func,
 				      uint32_t *orig_from_mode,
 				      struct spci_memory_region *memory_region,
 				      uint32_t memory_to_attributes,
@@ -267,23 +267,23 @@
 		return false;
 	}
 
-	switch (share_type) {
-	case SPCI_MSG_SEND_LEGACY_MEMORY_DONATE:
+	switch (share_func) {
+	case SPCI_MEM_DONATE_32:
 		mem_transition_table = donate_transitions;
 		transition_table_size = size_donate_transitions;
 		break;
 
-	case SPCI_MSG_SEND_LEGACY_MEMORY_LEND:
+	case SPCI_MEM_LEND_32:
 		mem_transition_table = lend_transitions;
 		transition_table_size = size_lend_transitions;
 		break;
 
-	case SPCI_MSG_SEND_LEGACY_MEMORY_SHARE:
+	case SPCI_MEM_SHARE_32:
 		mem_transition_table = share_transitions;
 		transition_table_size = size_share_transitions;
 		break;
 
-	case SPCI_MSG_SEND_LEGACY_MEMORY_RELINQUISH:
+	case HF_SPCI_MEM_RELINQUISH:
 		mem_transition_table = relinquish_transitions;
 		transition_table_size = size_relinquish_transitions;
 		break;
@@ -452,7 +452,7 @@
 static struct spci_value spci_share_memory(
 	struct vm_locked to_locked, struct vm_locked from_locked,
 	struct spci_memory_region *memory_region, uint32_t memory_to_attributes,
-	uint32_t share_type, struct mpool *api_page_pool)
+	uint32_t share_func, struct mpool *api_page_pool)
 {
 	struct vm *to = to_locked.vm;
 	struct vm *from = from_locked.vm;
@@ -483,7 +483,7 @@
 	 * in the memory exchange, ensure that all constituents of a memory
 	 * region being shared are at the same state.
 	 */
-	if (!spci_msg_check_transition(to, from, share_type, &orig_from_mode,
+	if (!spci_msg_check_transition(to, from, share_func, &orig_from_mode,
 				       memory_region, memory_to_attributes,
 				       &from_mode, &to_mode)) {
 		return spci_error(SPCI_INVALID_PARAMETERS);
@@ -567,7 +567,7 @@
 static struct spci_value spci_validate_call_share_memory(
 	struct vm_locked to_locked, struct vm_locked from_locked,
 	struct spci_memory_region *memory_region, uint32_t memory_share_size,
-	uint32_t share_type, struct mpool *api_page_pool)
+	uint32_t share_func, struct mpool *api_page_pool)
 {
 	uint32_t memory_to_attributes;
 	uint32_t attributes_size;
@@ -603,14 +603,14 @@
 		return spci_error(SPCI_INVALID_PARAMETERS);
 	}
 
-	switch (share_type) {
-	case SPCI_MSG_SEND_LEGACY_MEMORY_DONATE:
-	case SPCI_MSG_SEND_LEGACY_MEMORY_LEND:
-	case SPCI_MSG_SEND_LEGACY_MEMORY_SHARE:
+	switch (share_func) {
+	case SPCI_MEM_DONATE_32:
+	case SPCI_MEM_LEND_32:
+	case SPCI_MEM_SHARE_32:
 		memory_to_attributes = spci_memory_attrs_to_mode(
 			memory_region->attributes[0].memory_attributes);
 		break;
-	case SPCI_MSG_SEND_LEGACY_MEMORY_RELINQUISH:
+	case HF_SPCI_MEM_RELINQUISH:
 		memory_to_attributes = MM_MODE_R | MM_MODE_W | MM_MODE_X;
 		break;
 	default:
@@ -619,7 +619,7 @@
 	}
 
 	return spci_share_memory(to_locked, from_locked, memory_region,
-				 memory_to_attributes, share_type,
+				 memory_to_attributes, share_func,
 				 api_page_pool);
 }
 
@@ -631,11 +631,10 @@
 struct spci_value spci_msg_handle_architected_message(
 	struct vm_locked to_locked, struct vm_locked from_locked,
 	struct spci_memory_region *memory_region, uint32_t size,
-	uint32_t attributes, struct mpool *api_page_pool)
+	uint32_t share_func, struct mpool *api_page_pool)
 {
-	uint32_t share_type = attributes & SPCI_MSG_SEND_LEGACY_MEMORY_MASK;
 	struct spci_value ret = spci_validate_call_share_memory(
-		to_locked, from_locked, memory_region, size, share_type,
+		to_locked, from_locked, memory_region, size, share_func,
 		api_page_pool);
 
 	/* Copy data to the destination Rx. */
@@ -652,7 +651,7 @@
 			 memory_region, size);
 		to_locked.vm->mailbox.recv_size = size;
 		to_locked.vm->mailbox.recv_sender = from_locked.vm->id;
-		to_locked.vm->mailbox.recv_attributes = share_type;
+		to_locked.vm->mailbox.recv_func = share_func;
 	}
 
 	return ret;
diff --git a/test/vmapi/primary_with_secondaries/memory_sharing.c b/test/vmapi/primary_with_secondaries/memory_sharing.c
index ecac191..73413cf 100644
--- a/test/vmapi/primary_with_secondaries/memory_sharing.c
+++ b/test/vmapi/primary_with_secondaries/memory_sharing.c
@@ -258,7 +258,7 @@
 
 	/* Let the memory be returned. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	for (int i = 0; i < PAGE_SIZE; ++i) {
 		ASSERT_EQ(ptr[i], 'c');
 	}
@@ -320,7 +320,7 @@
 	run_res = spci_run(SERVICE_VM1, 0);
 
 	/* Let the memory be returned. */
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Ensure that the secondary VM accessed the region. */
@@ -395,7 +395,7 @@
 
 	/* Let the memory be returned. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, SPCI_MEM_DONATE_32);
 	for (int i = 0; i < PAGE_SIZE; ++i) {
 		ASSERT_EQ(ptr[i], 'c');
 	}
@@ -433,7 +433,7 @@
 
 	/* Let the memory be returned. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	for (int i = 0; i < PAGE_SIZE; ++i) {
 		ASSERT_EQ(ptr[i], 'd');
 	}
@@ -468,7 +468,7 @@
 
 	/* Let the memory be returned. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Share the memory again after it has been returned. */
@@ -481,7 +481,7 @@
 
 	/* Observe the service doesn't fault when accessing the memory. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 }
 
@@ -510,7 +510,7 @@
 
 	/* Let the memory be returned. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Share the memory with a different VM after it has been returned. */
@@ -541,9 +541,7 @@
 
 	/* Have the memory be given. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
-	EXPECT_EQ(spci_msg_send_attributes(run_res),
-		  SPCI_MSG_SEND_LEGACY_MEMORY_DONATE);
+	EXPECT_EQ(run_res.func, SPCI_MEM_DONATE_32);
 
 	/* Check the memory was cleared. */
 	memory_region = (struct spci_memory_region *)mb.recv;
@@ -574,9 +572,7 @@
 
 	/* Have the memory be lent. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
-	EXPECT_EQ(spci_msg_send_attributes(run_res),
-		  SPCI_MSG_SEND_LEGACY_MEMORY_LEND);
+	EXPECT_EQ(run_res.func, SPCI_MEM_LEND_32);
 
 	/* Check the memory was cleared. */
 	memory_region = (struct spci_memory_region *)mb.recv;
@@ -747,7 +743,7 @@
 	run_res = spci_run(SERVICE_VM1, 0);
 
 	/* Let the memory be returned. */
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, SPCI_MEM_DONATE_32);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Share the memory with another VM. */
@@ -860,7 +856,7 @@
 
 	/* Let the memory be sent from VM1 to PRIMARY (returned). */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, SPCI_MEM_DONATE_32);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Check we have access again. */
@@ -998,7 +994,7 @@
 
 	/* Receive and return memory from VM1. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, SPCI_MEM_DONATE_32);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Use VM1 to fail to donate memory from the primary to VM2. */
@@ -1085,7 +1081,7 @@
 
 	/* Receive and return memory from VM1. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Try to lend memory from primary in VM1. */
@@ -1127,7 +1123,7 @@
 
 	/* Let service write to and return memory. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Re-initialise the memory before giving it. */
@@ -1190,7 +1186,7 @@
 
 	/* Let service write to and return memory. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Re-initialise the memory before giving it. */
@@ -1258,7 +1254,7 @@
 
 	/* Let service write to and return memory. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Re-initialise the memory before giving it. */
@@ -1319,7 +1315,7 @@
 
 	/* Attempt to execute from memory. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	msg_size = spci_memory_region_init(
@@ -1366,7 +1362,7 @@
 
 	/* Attempt to execute from memory. */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, HF_SPCI_MEM_RELINQUISH);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	msg_size = spci_memory_region_init(
diff --git a/test/vmapi/primary_with_secondaries/services/memory.c b/test/vmapi/primary_with_secondaries/services/memory.c
index a9d87f1..d10044b 100644
--- a/test/vmapi/primary_with_secondaries/services/memory.c
+++ b/test/vmapi/primary_with_secondaries/services/memory.c
@@ -42,9 +42,7 @@
 			spci_memory_region_get_constituents(memory_region);
 		spci_vm_id_t sender = memory_region->sender;
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-		EXPECT_EQ(spci_msg_send_attributes(ret),
-			  SPCI_MSG_SEND_LEGACY_MEMORY_SHARE);
+		EXPECT_EQ(ret.func, SPCI_MEM_SHARE_32);
 
 		ptr = (uint8_t *)constituents[0].address;
 
@@ -128,18 +126,13 @@
 		struct spci_memory_region *memory_region;
 		struct spci_memory_region_constituent *constituents;
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
 		/*
 		 * The memory may have been sent in one of several different
-		 * ways, but there shouldn't be any other attributes to the
-		 * message.
+		 * ways.
 		 */
-		EXPECT_NE(spci_msg_send_attributes(ret) &
-				  SPCI_MSG_SEND_LEGACY_MEMORY_MASK,
-			  0);
-		EXPECT_EQ(spci_msg_send_attributes(ret) &
-				  ~SPCI_MSG_SEND_LEGACY_MEMORY_MASK,
-			  0);
+		EXPECT_TRUE(ret.func == SPCI_MEM_DONATE_32 ||
+			    ret.func == SPCI_MEM_LEND_32 ||
+			    ret.func == SPCI_MEM_SHARE_32);
 
 		memory_region = (struct spci_memory_region *)recv_buf;
 		constituents =
@@ -186,9 +179,7 @@
 
 		exception_handler_reset();
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-		EXPECT_EQ(spci_msg_send_attributes(ret),
-			  SPCI_MSG_SEND_LEGACY_MEMORY_DONATE);
+		EXPECT_EQ(ret.func, SPCI_MEM_DONATE_32);
 
 		memory_region = (struct spci_memory_region *)recv_buf;
 		constituents =
@@ -221,9 +212,7 @@
 
 		exception_handler_reset();
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-		EXPECT_EQ(spci_msg_send_attributes(ret),
-			  SPCI_MSG_SEND_LEGACY_MEMORY_DONATE);
+		EXPECT_EQ(ret.func, SPCI_MEM_DONATE_32);
 
 		memory_region = (struct spci_memory_region *)recv_buf;
 		constituents =
@@ -257,9 +246,7 @@
 	struct spci_memory_region_constituent *constituents =
 		spci_memory_region_get_constituents(memory_region);
 
-	EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-	EXPECT_EQ(spci_msg_send_attributes(ret),
-		  SPCI_MSG_SEND_LEGACY_MEMORY_DONATE);
+	EXPECT_EQ(ret.func, SPCI_MEM_DONATE_32);
 
 	exception_setup(NULL, exception_handler_yield);
 
@@ -294,9 +281,7 @@
 	struct spci_memory_region_constituent constituent =
 		spci_memory_region_get_constituents(memory_region)[0];
 
-	EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-	EXPECT_EQ(spci_msg_send_attributes(ret),
-		  SPCI_MSG_SEND_LEGACY_MEMORY_DONATE);
+	EXPECT_EQ(ret.func, SPCI_MEM_DONATE_32);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Yield to allow attempt to re donate from primary. */
@@ -335,9 +320,7 @@
 		struct spci_memory_region_constituent *constituents =
 			spci_memory_region_get_constituents(memory_region);
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-		EXPECT_EQ(spci_msg_send_attributes(ret),
-			  SPCI_MSG_SEND_LEGACY_MEMORY_DONATE);
+		EXPECT_EQ(ret.func, SPCI_MEM_DONATE_32);
 
 		ptr = (uint8_t *)constituents[0].address;
 		EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
@@ -364,9 +347,7 @@
 	struct spci_memory_region_constituent *constituents =
 		spci_memory_region_get_constituents(memory_region);
 
-	EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-	EXPECT_EQ(spci_msg_send_attributes(ret),
-		  SPCI_MSG_SEND_LEGACY_MEMORY_DONATE);
+	EXPECT_EQ(ret.func, SPCI_MEM_DONATE_32);
 
 	/* Give the memory back and notify the sender. */
 	msg_size = spci_memory_region_init(
@@ -409,18 +390,13 @@
 		struct spci_memory_region_constituent *constituents =
 			spci_memory_region_get_constituents(memory_region);
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
 		/*
 		 * The memory may have been sent in one of several different
-		 * ways, but there shouldn't be any other attributes to the
-		 * message.
+		 * ways.
 		 */
-		EXPECT_NE(spci_msg_send_attributes(ret) &
-				  SPCI_MSG_SEND_LEGACY_MEMORY_MASK,
-			  0);
-		EXPECT_EQ(spci_msg_send_attributes(ret) &
-				  ~SPCI_MSG_SEND_LEGACY_MEMORY_MASK,
-			  0);
+		EXPECT_TRUE(ret.func == SPCI_MEM_DONATE_32 ||
+			    ret.func == SPCI_MEM_LEND_32 ||
+			    ret.func == SPCI_MEM_SHARE_32);
 
 		ptr = (uint8_t *)constituents[0].address;
 		count = constituents[0].page_count;
@@ -473,9 +449,7 @@
 		struct spci_memory_region_constituent *constituents =
 			spci_memory_region_get_constituents(memory_region);
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-		EXPECT_EQ(spci_msg_send_attributes(ret),
-			  SPCI_MSG_SEND_LEGACY_MEMORY_DONATE);
+		EXPECT_EQ(ret.func, SPCI_MEM_DONATE_32);
 
 		ptr = (uint8_t *)constituents[0].address;
 
@@ -519,9 +493,7 @@
 	struct spci_memory_region_constituent *constituents =
 		spci_memory_region_get_constituents(memory_region);
 
-	EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-	EXPECT_EQ(spci_msg_send_attributes(ret),
-		  SPCI_MSG_SEND_LEGACY_MEMORY_LEND);
+	EXPECT_EQ(ret.func, SPCI_MEM_LEND_32);
 
 	/* Attempt to relinquish to this same VM. */
 	msg_size = spci_memory_region_init(
@@ -581,9 +553,7 @@
 		struct spci_memory_region_constituent *constituents =
 			spci_memory_region_get_constituents(memory_region);
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-		EXPECT_EQ(spci_msg_send_attributes(ret),
-			  SPCI_MSG_SEND_LEGACY_MEMORY_LEND);
+		EXPECT_EQ(ret.func, SPCI_MEM_LEND_32);
 
 		ptr = (uint64_t *)constituents[0].address;
 		/*
@@ -629,18 +599,13 @@
 		struct spci_memory_region_constituent constituent_copy =
 			constituents[0];
 
-		EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
 		/*
 		 * The memory may have been sent in one of several different
-		 * ways, but there shouldn't be any other attributes to the
-		 * message.
+		 * ways.
 		 */
-		EXPECT_NE(spci_msg_send_attributes(ret) &
-				  SPCI_MSG_SEND_LEGACY_MEMORY_MASK,
-			  0);
-		EXPECT_EQ(spci_msg_send_attributes(ret) &
-				  ~SPCI_MSG_SEND_LEGACY_MEMORY_MASK,
-			  0);
+		EXPECT_TRUE(ret.func == SPCI_MEM_DONATE_32 ||
+			    ret.func == SPCI_MEM_LEND_32 ||
+			    ret.func == SPCI_MEM_SHARE_32);
 
 		EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
@@ -684,9 +649,7 @@
 	struct spci_memory_region_constituent *constituents =
 		spci_memory_region_get_constituents(memory_region);
 
-	EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-	EXPECT_EQ(spci_msg_send_attributes(ret),
-		  SPCI_MSG_SEND_LEGACY_MEMORY_LEND);
+	EXPECT_EQ(ret.func, SPCI_MEM_LEND_32);
 
 	exception_setup(NULL, exception_handler_yield);
 
@@ -718,9 +681,7 @@
 
 	exception_setup(NULL, exception_handler_yield);
 
-	EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-	EXPECT_EQ(spci_msg_send_attributes(ret),
-		  SPCI_MSG_SEND_LEGACY_MEMORY_LEND);
+	EXPECT_EQ(ret.func, SPCI_MEM_LEND_32);
 
 	/* Choose which constituent we want to test. */
 	index = *(uint8_t *)constituents[0].address;
@@ -749,17 +710,10 @@
 	struct spci_memory_region_constituent constituent_copy =
 		constituents[0];
 
-	EXPECT_EQ(ret.func, SPCI_MSG_SEND_32);
-	/*
-	 * The memory may have been sent in one of several different ways, but
-	 * there shouldn't be any other attributes to the message.
-	 */
-	EXPECT_NE(spci_msg_send_attributes(ret) &
-			  SPCI_MSG_SEND_LEGACY_MEMORY_MASK,
-		  0);
-	EXPECT_EQ(spci_msg_send_attributes(ret) &
-			  ~SPCI_MSG_SEND_LEGACY_MEMORY_MASK,
-		  0);
+	/* The memory may have been sent in one of several different ways. */
+	EXPECT_TRUE(ret.func == SPCI_MEM_DONATE_32 ||
+		    ret.func == SPCI_MEM_LEND_32 ||
+		    ret.func == SPCI_MEM_SHARE_32);
 
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
diff --git a/test/vmapi/primary_with_secondaries/unmapped.c b/test/vmapi/primary_with_secondaries/unmapped.c
index 0b9c116..45164c1 100644
--- a/test/vmapi/primary_with_secondaries/unmapped.c
+++ b/test/vmapi/primary_with_secondaries/unmapped.c
@@ -51,7 +51,7 @@
 	 * get the trap.
 	 */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, SPCI_MEM_DONATE_32);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	run_res = spci_run(SERVICE_VM1, 0);
@@ -89,7 +89,7 @@
 	 * get the trap.
 	 */
 	run_res = spci_run(SERVICE_VM1, 0);
-	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(run_res.func, SPCI_MEM_DONATE_32);
 	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	run_res = spci_run(SERVICE_VM1, 0);