VMM: Make new virtio implementation work with new vmm 2LS
[akaros.git] / user / vmm / include / vmm / vmm.h
1 /* Copyright (c) 2015 Google Inc.
2  * Ron Minnich <rminnich@google.com>
3  * See LICENSE for details.
4  *
5  * VMM.h */
6
7 #pragma once
8
9 #include <ros/vmm.h>
10 #include <vmm/sched.h>
11
12 /* Structure to encapsulate all of the bookkeeping for a VM. */
13 struct virtual_machine {
14         struct guest_thread                     **gths;
15         unsigned int                            nr_gpcs;
16         struct vmm_gpcore_init          *gpcis;
17
18         /* TODO: put these in appropriate structures.  e.g., virtio things in
19          * something related to virtio.  low4k in something related to the guest's
20          * memory. */
21         uintptr_t                                       virtio_mmio_base;
22         int                                                     virtio_irq;
23         uint8_t                                         *low4k;
24         struct virtio_mmio_dev          *cons_mmio_dev;
25 };
26
27 char *regname(uint8_t reg);
28 int decode(struct guest_thread *vm_thread, uint64_t *gpa, uint8_t *destreg,
29            uint64_t **regp, int *store, int *size, int *advance);
30 int io(struct guest_thread *vm_thread);
31 void showstatus(FILE *f, struct guest_thread *vm_thread);
32 int msrio(struct guest_thread *vm_thread, struct vmm_gpcore_init *gpci,
33           uint32_t opcode);
34 int do_ioapic(struct guest_thread *vm_thread, uint64_t gpa,
35               int destreg, uint64_t *regp, int store);
36 bool handle_vmexit(struct guest_thread *gth);
37 int __apic_access(struct guest_thread *vm_thread, uint64_t gpa, int destreg,
38                   uint64_t *regp, int store);
39
40 /* Lookup helpers */
41
42 static struct virtual_machine *gth_to_vm(struct guest_thread *gth)
43 {
44         return ((struct vmm_thread*)gth)->vm;
45 }
46
47 static struct vm_trapframe *gth_to_vmtf(struct guest_thread *gth)
48 {
49         return &gth->uthread.u_ctx.tf.vm_tf;
50 }
51
52 static struct vmm_gpcore_init *gth_to_gpci(struct guest_thread *gth)
53 {
54         struct virtual_machine *vm = gth_to_vm(gth);
55
56         return &vm->gpcis[gth->gpc_id];
57 }
58
59 static struct virtual_machine *get_my_vm(void)
60 {
61         return ((struct vmm_thread*)current_uthread)->vm;
62 }