GIMKvmInternal.h revision 6fd7ca38c2e6dbc9871b33b11cf70ed6bf4e7d03
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * GIM - KVM, Internal header file.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * Copyright (C) 2015 Oracle Corporation
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * available from http://www.virtualbox.org. This file is free software;
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * you can redistribute it and/or modify it under the terms of the GNU
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * General Public License (GPL) as published by the Free Software
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** @name KVM base features.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Old, deprecated clock source available. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** No need for artifical delays on IO operations. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** MMU op supported (deprecated, unused). */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Clock source available. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Asynchronous page faults supported. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Steal time (VCPU not executing guest code time in ns) available. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Paravirtualized EOI (end-of-interrupt) supported. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Paravirtualized spinlock (unhalting VCPU) supported. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** The TSC is stable (fixed rate, monotonic). */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** @name KVM MSRs.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Start of range 0. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Old, deprecated wall clock. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Old, deprecated System time. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** End of range 0. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define MSR_GIM_KVM_RANGE0_END MSR_GIM_KVM_SYSTEM_TIME_OLD
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Start of range 1. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define MSR_GIM_KVM_RANGE1_START UINT32_C(0x4b564d00)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Wall clock. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** System time. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define MSR_GIM_KVM_SYSTEM_TIME UINT32_C(0x4b564d01)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Asynchronous page fault. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Steal time. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Paravirtualized EOI (end-of-interrupt). */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** End of range 1. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncAssertCompile(MSR_GIM_KVM_RANGE0_START <= MSR_GIM_KVM_RANGE0_END);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncAssertCompile(MSR_GIM_KVM_RANGE1_START <= MSR_GIM_KVM_RANGE1_END);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** KVM page size. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * MMIO2 region indices.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** The system time page(s) region. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define GIM_KVM_SYSTEM_TIME_PAGE_REGION_IDX UINT8_C(0)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** The steal time page(s) region. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define GIM_KVM_STEAL_TIME_PAGE_REGION_IDX UINT8_C(1)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** The maximum region index (must be <= UINT8_MAX). */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define GIM_KVM_REGION_IDX_MAX GIM_KVM_STEAL_TIME_PAGE_REGION_IDX
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * KVM system-time structure (GIM_KVM_SYSTEM_TIME_FLAGS_XXX) flags.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** The TSC is stable (monotonic). */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define GIM_KVM_SYSTEM_TIME_FLAGS_TSC_STABLE RT_BIT(0)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** The guest VCPU has been paused by the hypervisor. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define GIM_KVM_SYSTEM_TIME_FLAGS_GUEST_PAUSED RT_BIT(1)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** @name KVM MSR - System time (MSR_GIM_KVM_SYSTEM_TIME and
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * MSR_GIM_KVM_SYSTEM_TIME_OLD).
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** The system-time enable bit. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT RT_BIT_64(0)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Whether the system-time struct. is enabled or not. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define MSR_GIM_KVM_SYSTEM_TIME_IS_ENABLED(a) RT_BOOL((a) & MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Guest-physical address of the system-time struct. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#define MSR_GIM_KVM_SYSTEM_TIME_GUEST_GPA(a) ((a) & ~MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT)
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** @name KVM MSR - Wall clock (MSR_GIM_KVM_WALL_CLOCK and
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * MSR_GIM_KVM_WALL_CLOCK_OLD).
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Guest-physical address of the wall-clock struct. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * KVM per-VCPU system-time structure.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Version (sequence number). */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Alignment padding. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** TSC time stamp. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** System time in nanoseconds. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** TSC to system time scale factor. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** TSC frequency shift. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Clock source (GIM_KVM_SYSTEM_TIME_FLAGS_XXX) flags. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Alignment padding. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Pointer to KVM system-time struct. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Pointer to a const KVM system-time struct. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * KVM per-VM wall-clock structure.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Version (sequence number). */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Number of seconds since boot. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Number of nanoseconds since boot. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Pointer to KVM wall-clock struct. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Pointer to a const KVM wall-clock struct. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * GIM KVMV VM instance data.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * Changes to this must checked against the padding of the gim union in VM!
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsynctypedef struct GIMKVM
6fd7ca38c2e6dbc9871b33b11cf70ed6bf4e7d03vboxsync /** @name MSRs. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Wall-clock MSR. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** @name CPUID features. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** Basic features. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Pointer to per-VM GIM KVM instance data. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Pointer to const per-VM GIM KVM instance data. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * GIM KVMV VCPU instance data.
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync * Changes to this must checked against the padding of the gim union in VMCPU!
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsynctypedef struct GIMKVMCPU
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** System-time MSR. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** The guest-physical address of the system-time struct. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync /** The version (sequence number) of the system-time struct. */
6fd7ca38c2e6dbc9871b33b11cf70ed6bf4e7d03vboxsync /** The guest TSC value while enabling the system-time MSR. */
6fd7ca38c2e6dbc9871b33b11cf70ed6bf4e7d03vboxsync /** The guest virtual time while enabling the system-time MSR. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Pointer to per-VCPU GIM KVM instance data. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync/** Pointer to const per-VCPU GIM KVM instance data. */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMMR0_INT_DECL(int) gimR0KvmUpdateParavirtTsc(PVM pVM, uint64_t u64Offset);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#endif /* IN_RING0 */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMMR3_INT_DECL(void) gimR3KvmRelocate(PVM pVM, RTGCINTPTR offDelta);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMMR3_INT_DECL(int) gimR3KvmSave(PVM pVM, PSSMHANDLE pSSM);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMMR3_INT_DECL(int) gimR3KvmLoad(PVM pVM, PSSMHANDLE pSSM, uint32_t uSSMVersion);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMMR3_INT_DECL(int) gimR3KvmDisableSystemTime(PVM pVM);
6fd7ca38c2e6dbc9871b33b11cf70ed6bf4e7d03vboxsyncVMMR3_INT_DECL(int) gimR3KvmEnableSystemTime(PVM pVM, PVMCPU pVCpu, PGIMKVMCPU pKvmCpu, uint8_t fFlags);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMMR3_INT_DECL(int) gimR3KvmEnableWallClock(PVM pVM, RTGCPHYS GCPhysSysTime, uint32_t uVersion);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsync#endif /* IN_RING3 */
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMM_INT_DECL(bool) gimKvmIsParavirtTscEnabled(PVM pVM);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMM_INT_DECL(bool) gimKvmAreHypercallsEnabled(PVMCPU pVCpu);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMM_INT_DECL(int) gimKvmHypercall(PVMCPU pVCpu, PCPUMCTX pCtx);
0bc35f54322c5f9b2d43b064f839a8cf8c99a234vboxsyncVMM_INT_DECL(VBOXSTRICTRC) gimKvmReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue);