blob: 69ceac7c09c0474c9a93c9e1f37bed01bd0437c4 [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 {
Andrew Walbranc3910f72018-11-27 14:24:36 +000023 /** There is no message in the mailbox. */
Andrew Scullaa039b32018-10-04 15:02:26 +010024 mailbox_state_empty,
25
Andrew Walbranc3910f72018-11-27 14:24:36 +000026 /** There is a message in the mailbox that is waiting for a reader. */
Andrew Scullaa039b32018-10-04 15:02:26 +010027 mailbox_state_received,
28
Andrew Walbranc3910f72018-11-27 14:24:36 +000029 /** There is a message in the mailbox that has been read. */
Andrew Scullaa039b32018-10-04 15:02:26 +010030 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;
Andrew Walbran0d7a0682018-12-06 16:48:47 +000044 /** See api.c for the partial ordering on locks. */
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +010045 struct spinlock lock;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010046 uint32_t vcpu_count;
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010047 struct vcpu vcpus[MAX_CPUS];
Andrew Scull89a75242018-08-06 17:04:55 +010048 struct mm_ptable ptable;
Andrew Scullaa039b32018-10-04 15:02:26 +010049 struct mailbox mailbox;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010050};
51
Andrew Scull19503262018-09-20 14:48:39 +010052bool vm_init(uint32_t vcpu_count, struct vm **new_vm);
53uint32_t vm_get_count(void);
54struct vm *vm_get(uint32_t id);
Andrew Scull37402872018-10-24 14:23:06 +010055void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, uintreg_t arg);