Allow messages to be sent between all VMs.

Any VM can send a message to any other VM. The hypervisor acts as a
router to deliver the message to the destination but does not track
higher level state about the communications.

When receiving a message, the source VM is reported so access controls
can be applies and replies can be sent back.

Bug: 116705004
Change-Id: Ib83988eb8ddee1753dfd67a3baa3fb991ebd4dd7
diff --git a/inc/hf/api.h b/inc/hf/api.h
index a936558..35aba8d 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -8,10 +8,9 @@
 int64_t api_vcpu_run(uint32_t vm_id, uint32_t vcpu_idx, struct vcpu **next);
 int64_t api_vm_configure(ipaddr_t send, ipaddr_t recv);
 
-int64_t api_rpc_request(uint32_t vm_id, size_t size);
-int64_t api_rpc_read_request(bool block, struct vcpu **next);
-int64_t api_rpc_reply(size_t size, bool ack, struct vcpu **next);
-int64_t api_rpc_ack(void);
+int64_t api_mailbox_send(uint32_t vm_id, size_t size, struct vcpu **next);
+int64_t api_mailbox_receive(bool block, struct vcpu **next);
+int64_t api_mailbox_clear(void);
 
 struct vcpu *api_wait_for_interrupt(void);
 struct vcpu *api_yield(void);
diff --git a/inc/hf/cpu.h b/inc/hf/cpu.h
index b263e39..d598296 100644
--- a/inc/hf/cpu.h
+++ b/inc/hf/cpu.h
@@ -10,10 +10,19 @@
 #include "hf/spinlock.h"
 
 enum vcpu_state {
+	/* The vcpu is switched off. */
 	vcpu_state_off,
+
+	/* The vcpu is ready to be run. */
 	vcpu_state_ready,
+
+	/* The vcpu is currently running. */
 	vcpu_state_running,
-	vcpu_state_blocked_rpc,
+
+	/* The vcpu is waiting for a message. */
+	vcpu_state_blocked_mailbox,
+
+	/* The vcpu is waiting for an interrupt. */
 	vcpu_state_blocked_interrupt,
 };
 
@@ -21,7 +30,7 @@
 	struct spinlock lock;
 	enum vcpu_state state;
 	struct vm *vm;
-	struct vcpu *rpc_next;
+	struct vcpu *mailbox_next;
 	struct arch_regs regs;
 };
 
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 3d7bf2e..64e4ee0 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -3,14 +3,20 @@
 #include "hf/cpu.h"
 #include "hf/mm.h"
 
-enum rpc_state {
-	rpc_state_idle,
-	rpc_state_pending,
-	rpc_state_inflight,
+enum mailbox_state {
+	/* There is no message in the mailbox. */
+	mailbox_state_empty,
+
+	/* There is a message in the mailbox that is waiting for a reader. */
+	mailbox_state_received,
+
+	/* There is a message in the mailbox that has been read. */
+	mailbox_state_read,
 };
 
-struct rpc {
-	enum rpc_state state;
+struct mailbox {
+	enum mailbox_state state;
+	uint32_t recv_from_id;
 	int16_t recv_bytes;
 	void *recv;
 	const void *send;
@@ -23,7 +29,7 @@
 	uint32_t vcpu_count;
 	struct vcpu vcpus[MAX_CPUS];
 	struct mm_ptable ptable;
-	struct rpc rpc;
+	struct mailbox mailbox;
 };
 
 bool vm_init(uint32_t vcpu_count, struct vm **new_vm);