GIMKvmInternal.h revision fa35e2dfd910e18dbb7f136bfe56030e5116d51c
/* $Id$ */
/** @file
* GIM - KVM, Internal header file.
*/
/*
* Copyright (C) 2015 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ___GIMKvmInternal_h
#define ___GIMKvmInternal_h
/** @name KVM base features.
* @{
*/
/** Old, deprecated clock source available. */
#define GIM_KVM_BASE_FEAT_CLOCK_OLD RT_BIT(0)
/** No need for artifical delays on IO operations. */
/** MMU op supported (deprecated, unused). */
/** Clock source available. */
/** Asynchronous page faults supported. */
/** Steal time (VCPU not executing guest code time in ns) available. */
/** Paravirtualized EOI (end-of-interrupt) supported. */
/** Paravirtualized spinlock (unhalting VCPU) supported. */
/** The TSC is stable (fixed rate, monotonic). */
/** @} */
/** @name KVM MSRs.
* @{
*/
/** Start of range 0. */
/** Old, deprecated wall clock. */
/** Old, deprecated System time. */
/** End of range 0. */
/** Start of range 1. */
/** Wall clock. */
/** System time. */
/** Asynchronous page fault. */
/** Steal time. */
/** Paravirtualized EOI (end-of-interrupt). */
/** End of range 1. */
/** KVM page size. */
#define GIM_KVM_PAGE_SIZE 0x1000
/**
* MMIO2 region indices.
*/
/** The system time page(s) region. */
#define GIM_KVM_SYSTEM_TIME_PAGE_REGION_IDX UINT8_C(0)
/** The steal time page(s) region. */
/** The maximum region index (must be <= UINT8_MAX). */
/**
* KVM system-time structure (GIM_KVM_SYSTEM_TIME_FLAGS_XXX) flags.
* See "Documentation/virtual/kvm/api.txt".
*/
/** The TSC is stable (monotonic). */
#define GIM_KVM_SYSTEM_TIME_FLAGS_TSC_STABLE RT_BIT(0)
/** The guest VCPU has been paused by the hypervisor. */
/** */
/** @name KVM MSR - System time (MSR_GIM_KVM_SYSTEM_TIME and
* MSR_GIM_KVM_SYSTEM_TIME_OLD).
* @{
*/
/** The system-time enable bit. */
#define MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT RT_BIT_64(0)
/** Whether the system-time struct. is enabled or not. */
/** Guest-physical address of the system-time struct. */
#define MSR_GIM_KVM_SYSTEM_TIME_GUEST_GPA(a) ((a) & ~MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT)
/** @} */
/** @name KVM MSR - Wall clock (MSR_GIM_KVM_WALL_CLOCK and
* MSR_GIM_KVM_WALL_CLOCK_OLD).
* @{
*/
/** Guest-physical address of the wall-clock struct. */
#define MSR_GIM_KVM_WALL_CLOCK_GUEST_GPA(a) (a)
/** @} */
/** @name KVM Hypercall operations.
* @{ */
#define KVM_HYPERCALL_OP_VAPIC_POLL_IRQ 1
#define KVM_HYPERCALL_OP_MMU 2
#define KVM_HYPERCALL_OP_FEATURES 3
#define KVM_HYPERCALL_OP_KICK_CPU 5
/** @} */
/** @name KVM Hypercall return values.
* @{ */
/* Return values for hypercalls */
#define KVM_HYPERCALL_RET_SUCCESS 0
/** @} */
/**
* KVM per-VCPU system-time structure.
*/
typedef struct GIMKVMSYSTEMTIME
{
/** Version (sequence number). */
/** Alignment padding. */
/** TSC time stamp. */
/** System time in nanoseconds. */
/** TSC to system time scale factor. */
/** TSC frequency shift. */
/** Clock source (GIM_KVM_SYSTEM_TIME_FLAGS_XXX) flags. */
/** Alignment padding. */
/** Pointer to KVM system-time struct. */
typedef GIMKVMSYSTEMTIME *PGIMKVMSYSTEMTIME;
/** Pointer to a const KVM system-time struct. */
typedef GIMKVMSYSTEMTIME const *PCGIMKVMSYSTEMTIME;
/**
* KVM per-VM wall-clock structure.
*/
typedef struct GIMKVMWALLCLOCK
{
/** Version (sequence number). */
/** Number of seconds since boot. */
/** Number of nanoseconds since boot. */
/** Pointer to KVM wall-clock struct. */
typedef GIMKVMWALLCLOCK *PGIMKVMWALLCLOCK;
/** Pointer to a const KVM wall-clock struct. */
typedef GIMKVMWALLCLOCK const *PCGIMKVMWALLCLOCK;
/**
* GIM KVMV VM instance data.
* Changes to this must checked against the padding of the gim union in VM!
*/
typedef struct GIMKVM
{
/** Wall-clock MSR. */
/** CPUID features: Basic. */
/** Whether GIM needs to trap #UD exceptions. */
bool fTrapXcptUD;
/** Disassembler opcode of hypercall instruction native for this host CPU. */
} GIMKVM;
/** Pointer to per-VM GIM KVM instance data. */
/** Pointer to const per-VM GIM KVM instance data. */
/**
* GIM KVMV VCPU instance data.
* Changes to this must checked against the padding of the gim union in VMCPU!
*/
typedef struct GIMKVMCPU
{
/** System-time MSR. */
/** The guest-physical address of the system-time struct. */
/** The version (sequence number) of the system-time struct. */
/** The guest TSC value while enabling the system-time MSR. */
/** The guest virtual time while enabling the system-time MSR. */
} GIMKVMCPU;
/** Pointer to per-VCPU GIM KVM instance data. */
typedef GIMKVMCPU *PGIMKVMCPU;
/** Pointer to const per-VCPU GIM KVM instance data. */
typedef GIMKVMCPU const *PCGIMKVMCPU;
#ifdef IN_RING0
#if 0
#endif
#endif /* IN_RING0 */
#ifdef IN_RING3
VMMR3_INT_DECL(int) gimR3KvmEnableSystemTime(PVM pVM, PVMCPU pVCpu, PGIMKVMCPU pKvmCpu, uint8_t fFlags);
#endif /* IN_RING3 */
VMM_INT_DECL(VBOXSTRICTRC) gimKvmReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue);
VMM_INT_DECL(VBOXSTRICTRC) gimKvmWriteMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t uRawValue);
#endif