GIMHv.cpp revision 98c2f57c4a24999b17e1e437f3e094956065792c
/* $Id$ */
/** @file
* GIM - Guest Interface Manager, Hyper-V implementation.
*/
/*
* Copyright (C) 2014 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_GIM
#include "GIMInternal.h"
#include <iprt/spinlock.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
//#define GIMHV_HYPERCALL "GIMHvHypercall"
#ifdef VBOX_WITH_STATISTICS
{ (a_uFirst), (a_uLast), kCpumMsrRdFn_Gim, kCpumMsrWrFn_Gim, 0, 0, 0, 0, 0, a_szName, { 0 }, { 0 }, { 0 }, { 0 } }
#else
#endif
/**
* Array of MSR ranges supported by Hyper-V.
*/
static CPUMMSRRANGE const g_aMsrRanges_HyperV[] =
{
};
/**
* Initializes the Hyper-V GIM provider.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param uVersion The interface version this VM should use.
*/
{
int rc;
/*
* Determine interface capabilities based on the version.
*/
{
/* Basic features. */
//| GIM_HV_BASE_FEAT_VP_RUNTIME_MSR
//| GIM_HV_BASE_FEAT_BASIC_SYNTH_IC
//| GIM_HV_BASE_FEAT_SYNTH_TIMER_MSRS
//| GIM_HV_BASE_FEAT_STAT_PAGES_MSR
//| GIM_HV_BASE_FEAT_GUEST_IDLE_STATE_MSR
//| GIM_HV_BASE_FEAT_DEBUG_MSRS
;
/* Miscellaneous features. */
/* Hypervisor recommendations to the guest. */
/* Hypervisor capabilities; features used by the hypervisor. */
}
/*
* Populate the required fields in MMIO2 region records for registering.
*/
pRegion->fRCMapping = false;
pRegion->fRCMapping = false;
/*
* Make sure the CPU ID bit are in accordance to the Hyper-V
* requirement and other paranoia checks.
* See "Requirements for implementing the Microsoft hypervisor interface" spec.
*/
{
}
/*
* Expose HVP (Hypervisor Present) bit to the guest.
*/
/*
* Modify the standard hypervisor leaves for Hyper-V.
*/
/*
* Add Hyper-V specific leaves.
*/
/*
* Insert all MSR ranges of Hyper-V.
*/
for (unsigned i = 0; i < RT_ELEMENTS(g_aMsrRanges_HyperV); i++)
{
}
return VINF_SUCCESS;
}
#if 0
{
if (!HMIsEnabled(pVM))
{
}
}
#endif
/**
* Terminates the Hyper-V GIM provider.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
*/
{
return VINF_SUCCESS;
}
/**
* Applies relocations to data and code managed by this component. This function
* will be called at init and whenever the VMM need to relocate itself inside
* the GC.
*
* @param pVM Pointer to the VM.
* @param offDelta Relocation delta relative to old location.
*/
{
#if 0
int rc = PDMR3LdrGetSymbolRC(pVM, NULL /* pszModule */, GIMHV_HYPERCALL, &pVM->gim.s.pfnHypercallRC);
#endif
}
/**
* The VM is being reset. This resets Hyper-V provider MSRs and unmaps whatever
* Hyper-V regions that the guest may have mapped.
*
* @param pVM Pointer to the VM.
*/
{
/*
* Unmap MMIO2 pages that the guest may have setup.
*/
LogRel(("GIM: HyperV: Resetting Hyper-V MMIO2 regions and MSRs\n"));
{
}
/*
* Reset MSRs.
*/
pHv->u64GuestOsIdMsr = 0;
pHv->u64HypercallMsr = 0;
pHv->u64TscPageMsr = 0;
}
/**
* Returns a pointer to the MMIO2 regions supported by Hyper-V.
*
* @returns Pointer to an array of MMIO2 regions.
* @param pVM Pointer to the VM.
* @param pcRegions Where to store the number of regions in the array.
*/
{
return pHv->aMmio2Regions;
}
/**
* Hyper-V state-save operation.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param pSSM Pointer to the SSM handle.
*/
{
/*
* Save the Hyper-V SSM version.
*/
/** @todo Save per-VCPU data. */
/*
* Save per-VM MSRs.
*/
/*
* Save Hyper-V features / capabilities.
*/
/*
* Save the Hypercall region.
*/
/*
* Save the reference TSC region.
*/
uint32_t uTscSequence = 0;
{
}
return VINF_SUCCESS;
}
/**
* Hyper-V state-load operation, final pass.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param pSSM Pointer to the SSM handle.
* @param uSSMVersion The GIM saved-state version.
*/
{
/*
* Load the Hyper-V SSM version first.
*/
/** @todo Load per-VCPU data. */
/*
* Load per-VM MSRs.
*/
/*
* Load Hyper-V features / capabilities.
*/
/*
* Load and enable the Hypercall region.
*/
{
{
if (RT_FAILURE(rc))
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Failed to enable the hypercall page. GCPhys=%#RGp rc=%Rrc"),
}
else
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Hypercall MMIO2 region not registered. Missing GIM device?!"));
}
/*
* Load and enable the reference TSC region.
*/
{
if (pRegion->fRegistered)
{
if (RT_FAILURE(rc))
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Failed to enable the TSC page. GCPhys=%#RGp rc=%Rrc"),
}
else
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("TSC-page MMIO2 region not registered. Missing GIM device?!"));
}
return rc;
}
/**
* Enables the Hyper-V TSC page.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param GCPhysTscPage Where to map the TSC page.
* @param fUseThisTscSequence Whether to set the TSC sequence number to
* the one specified in @a uTscSequence.
* @param uTscSequence The TSC sequence value to use. Ignored if @a
* fUseThisTscSequence is false.
*/
VMMR3_INT_DECL(int) GIMR3HvEnableTscPage(PVM pVM, RTGCPHYS GCPhysTscPage, bool fUseThisTscSequence, uint32_t uTscSequence)
{
int rc;
{
/*
* Is it already enabled at the given guest-address?
*/
return VINF_SUCCESS;
/*
* If it's mapped at a different address, unmap the previous address.
*/
}
/*
* Map the TSC-page at the specified address.
*/
if (RT_SUCCESS(rc))
{
/*
* Update the TSC scale. Windows guests expect a non-zero TSC sequence, otherwise
* they fallback to using the reference count MSR which is not ideal in terms of VM-exits.
*
* Also, Hyper-V normalizes the time in 10 MHz, see:
*/
if ( fUseThisTscSequence
{
}
LogRel(("GIM: HyperV: Enabled TSC page at %#RGp - u64TscScale=%#RX64 u64TscKHz=%#RX64 (%'RU64)\n", GCPhysTscPage,
return VINF_SUCCESS;
}
else
return VERR_GIM_OPERATION_FAILED;
}
/**
* Disables the Hyper-V TSC page.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
*/
{
{
LogRel(("GIM: HyperV: Disabled TSC-page\n"));
return VINF_SUCCESS;
}
return VERR_GIM_PVTSC_NOT_ENABLED;
}
/**
* Disables the Hyper-V Hypercall page.
*
* @returns VBox status code.
*/
{
{
LogRel(("GIM: HyperV: Disabled Hypercall-page\n"));
return VINF_SUCCESS;
}
return VERR_GIM_HYPERCALLS_NOT_ENABLED;
}
/**
* Enables the Hyper-V Hypercall page.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param GCPhysHypercallPage Where to map the hypercall page.
*/
{
{
/*
* Is it already enabled at the given guest-address?
*/
return VINF_SUCCESS;
/*
* If it's mapped at a different address, unmap the previous address.
*/
}
/*
* Map the hypercall-page at the specified address.
*/
if (RT_SUCCESS(rc))
{
/*
* Patch the hypercall-page.
*/
if (HMIsEnabled(pVM))
{
if ( RT_SUCCESS(rc)
{
return VINF_SUCCESS;
}
else
{
if (rc == VINF_SUCCESS)
}
}
else
{
/** @todo Handle raw-mode hypercall page patching. */
LogRel(("GIM: HyperV: Raw-mode not yet implemented!\n"));
}
}
else
return rc;
}