Use attributes rather than header for legacy memory sharing.

This removes the architected message header.

Bug: 132420445
Change-Id: Id568f379be194bca552506a470355c018a611c2b
diff --git a/src/api.c b/src/api.c
index 210359b..d7e1eac 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1002,35 +1002,22 @@
 	}
 
 	/* Handle legacy memory sharing messages. */
-	if ((attributes & SPCI_MSG_SEND_LEGACY_MEMORY_MASK) ==
-	    SPCI_MSG_SEND_LEGACY_MEMORY) {
+	if ((attributes & SPCI_MSG_SEND_LEGACY_MEMORY_MASK) != 0) {
 		/*
 		 * Buffer holding the internal copy of the shared memory
 		 * regions.
 		 */
-		struct spci_architected_message_header
-			*architected_message_replica =
-				(struct spci_architected_message_header *)
-					cpu_get_buffer(current->cpu->id);
+		uint8_t *message_replica = cpu_get_buffer(current->cpu->id);
 		uint32_t message_buffer_size =
 			cpu_get_buffer_size(current->cpu->id);
 
-		struct spci_architected_message_header *architected_header =
-			(struct spci_architected_message_header *)from_msg;
-
 		if (size > message_buffer_size) {
 			ret = spci_error(SPCI_INVALID_PARAMETERS);
 			goto out;
 		}
 
-		if (size < sizeof(struct spci_architected_message_header)) {
-			ret = spci_error(SPCI_INVALID_PARAMETERS);
-			goto out;
-		}
-
 		/* Copy the architected message into the internal buffer. */
-		memcpy_s(architected_message_replica, message_buffer_size,
-			 architected_header, size);
+		memcpy_s(message_replica, message_buffer_size, from_msg, size);
 
 		/*
 		 * Note that architected_message_replica is passed as the third
@@ -1043,7 +1030,8 @@
 		 */
 		ret = spci_msg_handle_architected_message(
 			vm_to_from_lock.vm1, vm_to_from_lock.vm2,
-			architected_message_replica, size, &api_page_pool);
+			(struct spci_memory_region *)message_replica, size,
+			attributes, &api_page_pool);
 
 		if (ret.func != SPCI_SUCCESS_32) {
 			goto out;
diff --git a/src/spci_architected_message.c b/src/spci_architected_message.c
index 2c3ff89..d427cd2 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,
-				      enum spci_memory_share share,
+				      uint32_t share_type,
 				      uint32_t *orig_from_mode,
 				      struct spci_memory_region *memory_region,
 				      uint32_t memory_to_attributes,
@@ -267,23 +267,23 @@
 		return false;
 	}
 
-	switch (share) {
-	case SPCI_MEMORY_DONATE:
+	switch (share_type) {
+	case SPCI_MSG_SEND_LEGACY_MEMORY_DONATE:
 		mem_transition_table = donate_transitions;
 		transition_table_size = size_donate_transitions;
 		break;
 
-	case SPCI_MEMORY_LEND:
+	case SPCI_MSG_SEND_LEGACY_MEMORY_LEND:
 		mem_transition_table = lend_transitions;
 		transition_table_size = size_lend_transitions;
 		break;
 
-	case SPCI_MEMORY_SHARE:
+	case SPCI_MSG_SEND_LEGACY_MEMORY_SHARE:
 		mem_transition_table = share_transitions;
 		transition_table_size = size_share_transitions;
 		break;
 
-	case SPCI_MEMORY_RELINQUISH:
+	case SPCI_MSG_SEND_LEGACY_MEMORY_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,
-	enum spci_memory_share share, struct mpool *api_page_pool)
+	uint32_t share_type, 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, &orig_from_mode,
+	if (!spci_msg_check_transition(to, from, share_type, &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,
-	enum spci_memory_share share, struct mpool *api_page_pool)
+	uint32_t share_type, struct mpool *api_page_pool)
 {
 	uint32_t memory_to_attributes;
 	uint32_t attributes_size;
@@ -598,14 +598,14 @@
 		return spci_error(SPCI_INVALID_PARAMETERS);
 	}
 
-	switch (share) {
-	case SPCI_MEMORY_DONATE:
-	case SPCI_MEMORY_LEND:
-	case SPCI_MEMORY_SHARE:
+	switch (share_type) {
+	case SPCI_MSG_SEND_LEGACY_MEMORY_DONATE:
+	case SPCI_MSG_SEND_LEGACY_MEMORY_LEND:
+	case SPCI_MSG_SEND_LEGACY_MEMORY_SHARE:
 		memory_to_attributes = spci_memory_attrs_to_mode(
 			memory_region->attributes[0].memory_attributes);
 		break;
-	case SPCI_MEMORY_RELINQUISH:
+	case SPCI_MSG_SEND_LEGACY_MEMORY_RELINQUISH:
 		memory_to_attributes = MM_MODE_R | MM_MODE_W | MM_MODE_X;
 		break;
 	default:
@@ -614,7 +614,8 @@
 	}
 
 	return spci_share_memory(to_locked, from_locked, memory_region,
-				 memory_to_attributes, share, api_page_pool);
+				 memory_to_attributes, share_type,
+				 api_page_pool);
 }
 
 /**
@@ -624,21 +625,13 @@
  */
 struct spci_value spci_msg_handle_architected_message(
 	struct vm_locked to_locked, struct vm_locked from_locked,
-	const struct spci_architected_message_header
-		*architected_message_replica,
-	uint32_t size, struct mpool *api_page_pool)
+	struct spci_memory_region *memory_region, uint32_t size,
+	uint32_t attributes, struct mpool *api_page_pool)
 {
-	struct spci_value ret;
-	struct spci_memory_region *memory_region =
-		(struct spci_memory_region *)
-			architected_message_replica->payload;
-	uint32_t message_type = architected_message_replica->type;
-	uint32_t memory_share_size =
-		size - sizeof(struct spci_architected_message_header);
-
-	ret = spci_validate_call_share_memory(to_locked, from_locked,
-					      memory_region, memory_share_size,
-					      message_type, 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,
+		api_page_pool);
 
 	/* Copy data to the destination Rx. */
 	/*
@@ -651,11 +644,10 @@
 	 */
 	if (ret.func == SPCI_SUCCESS_32) {
 		memcpy_s(to_locked.vm->mailbox.recv, SPCI_MSG_PAYLOAD_MAX,
-			 architected_message_replica, size);
+			 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 =
-			SPCI_MSG_SEND_LEGACY_MEMORY;
+		to_locked.vm->mailbox.recv_attributes = share_type;
 	}
 
 	return ret;