blob: dc72e4a9289be037e65cb2a397199b8933cb975e [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
2 * Copyright 2018 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andrew Scullfbc938a2018-08-20 14:09:28 +010017#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010018
Andrew Scull18c78fc2018-08-20 12:57:41 +010019#include "hf/cpu.h"
20#include "hf/mm.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010021
Andrew Scullaa039b32018-10-04 15:02:26 +010022enum mailbox_state {
23 /* There is no message in the mailbox. */
24 mailbox_state_empty,
25
26 /* There is a message in the mailbox that is waiting for a reader. */
27 mailbox_state_received,
28
29 /* There is a message in the mailbox that has been read. */
30 mailbox_state_read,
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +010031};
32
Andrew Scullaa039b32018-10-04 15:02:26 +010033struct mailbox {
34 enum mailbox_state state;
35 uint32_t recv_from_id;
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +010036 int16_t recv_bytes;
37 void *recv;
38 const void *send;
39 struct vcpu *recv_waiter;
40};
41
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010042struct vm {
Andrew Scull8c3a63a2018-09-20 13:38:34 +010043 uint32_t id;
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +010044 struct spinlock lock;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010045 uint32_t vcpu_count;
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010046 struct vcpu vcpus[MAX_CPUS];
Andrew Scull89a75242018-08-06 17:04:55 +010047 struct mm_ptable ptable;
Andrew Scullaa039b32018-10-04 15:02:26 +010048 struct mailbox mailbox;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010049};
50
Andrew Scull19503262018-09-20 14:48:39 +010051bool vm_init(uint32_t vcpu_count, struct vm **new_vm);
52uint32_t vm_get_count(void);
53struct vm *vm_get(uint32_t id);
Andrew Scull37402872018-10-24 14:23:06 +010054void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, uintreg_t arg);
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010055void vm_set_current(struct vm *vm);