blob: 64e4ee0f8889ad12b1030ebad92b2bc1b78ac83b [file] [log] [blame]
Andrew Scullfbc938a2018-08-20 14:09:28 +01001#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01002
Andrew Scull18c78fc2018-08-20 12:57:41 +01003#include "hf/cpu.h"
4#include "hf/mm.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01005
Andrew Scullaa039b32018-10-04 15:02:26 +01006enum mailbox_state {
7 /* There is no message in the mailbox. */
8 mailbox_state_empty,
9
10 /* There is a message in the mailbox that is waiting for a reader. */
11 mailbox_state_received,
12
13 /* There is a message in the mailbox that has been read. */
14 mailbox_state_read,
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +010015};
16
Andrew Scullaa039b32018-10-04 15:02:26 +010017struct mailbox {
18 enum mailbox_state state;
19 uint32_t recv_from_id;
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +010020 int16_t recv_bytes;
21 void *recv;
22 const void *send;
23 struct vcpu *recv_waiter;
24};
25
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010026struct vm {
Andrew Scull8c3a63a2018-09-20 13:38:34 +010027 uint32_t id;
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +010028 struct spinlock lock;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010029 uint32_t vcpu_count;
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010030 struct vcpu vcpus[MAX_CPUS];
Andrew Scull89a75242018-08-06 17:04:55 +010031 struct mm_ptable ptable;
Andrew Scullaa039b32018-10-04 15:02:26 +010032 struct mailbox mailbox;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010033};
34
Andrew Scull19503262018-09-20 14:48:39 +010035bool vm_init(uint32_t vcpu_count, struct vm **new_vm);
36uint32_t vm_get_count(void);
37struct vm *vm_get(uint32_t id);
Andrew Scull89a75242018-08-06 17:04:55 +010038void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, size_t arg);
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010039void vm_set_current(struct vm *vm);