akaros/kern/arch/x86/vmm/vmm.h
<<
>>
Prefs
   1#pragma once
   2
   3#include <ros/vmm.h>
   4#include <arch/vmm/intel/vmx.h>
   5
   6static inline int cpu_has_vmx(void)
   7{
   8        unsigned long ecx = cpuid_ecx(1);
   9
  10        return ecx & (1<<5); /* CPUID.1:ECX.VMX[bit 5] -> VT */
  11}
  12
  13/* maybe someday, not today. */
  14static inline int cpu_has_svm(const char **msg)
  15{
  16        return 0;
  17}
  18
  19#define VMM_VMEXIT_NR_TYPES             65
  20
  21struct vmm {
  22        spinlock_t lock;        /* protects guest_pcore assignment */
  23        qlock_t qlock;
  24        // always false.
  25        int amd;
  26        // true if this is a VMMCP.
  27        bool vmmcp;
  28
  29        int flags;
  30
  31        // Number of cores in this VMMCP.
  32        int nr_guest_pcores;
  33
  34        // The VMCS is intel-specific. But, maybe, someday, AMD will
  35        // be back.  Just make this an anon union and we'll work it
  36        // all out later. Again, remember, we're compiling in support
  37        // for both architectures to ensure that we can correctly
  38        // figure out at boot time what we're on and what we should
  39        // do. This avoids the problem seen years ago with RH6 where
  40        // you could install a kernel from the ISO, but the kernel it
  41        // installed would GPF on a K7.
  42        union {
  43                void *svm;
  44                struct vmx_vmm vmx;
  45        };
  46        struct guest_pcore **guest_pcores;
  47        size_t gpc_array_elem;
  48        unsigned long vmexits[VMM_VMEXIT_NR_TYPES];
  49};
  50
  51void vmm_init(void);
  52void vmm_pcpu_init(void);
  53
  54void __vmm_struct_init(struct proc *p);
  55void __vmm_add_gpcs(struct proc *p, unsigned int nr_more_gpcs,
  56                    struct vmm_gpcore_init *u_gpcis);
  57void __vmm_struct_cleanup(struct proc *p);
  58int vmm_poke_guest(struct proc *p, int guest_pcoreid);
  59
  60struct guest_pcore *create_guest_pcore(struct proc *p,
  61                                       struct vmm_gpcore_init *gpci);
  62void destroy_guest_pcore(struct guest_pcore *vcpu);
  63uint64_t construct_eptp(physaddr_t root_hpa);
  64void ept_flush(uint64_t eptp);
  65
  66struct guest_pcore *lookup_guest_pcore(struct proc *p, int guest_pcoreid);
  67struct guest_pcore *load_guest_pcore(struct proc *p, int guest_pcoreid);
  68void unload_guest_pcore(struct proc *p, int guest_pcoreid);
  69
  70#define VMM_MSR_EMU_READ                1
  71#define VMM_MSR_EMU_WRITE               2
  72bool vmm_emulate_msr(struct vm_trapframe *vm_tf, int op);
  73