2014-09-23 13:01:47 +02:00
|
|
|
/*
|
|
|
|
* \brief VirtualBox hardware-acceleration manager
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is distributed under the terms of the GNU General Public License
|
|
|
|
* version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/printf.h>
|
|
|
|
|
|
|
|
/* VirtualBox includes */
|
|
|
|
#include "HMInternal.h" /* enable access to hm.s.* */
|
|
|
|
#include <VBox/vmm/hm.h>
|
|
|
|
#include <VBox/vmm/vm.h>
|
|
|
|
|
|
|
|
/* Genode's VirtualBox includes */
|
|
|
|
#include "sup.h"
|
|
|
|
|
|
|
|
|
2015-01-14 17:31:34 +01:00
|
|
|
static bool enabled_hm = true;
|
|
|
|
static bool enable_pae_nx = false;
|
2014-09-23 13:01:47 +02:00
|
|
|
|
|
|
|
VMMR3DECL(int) HMR3Init(PVM pVM)
|
|
|
|
{
|
2015-01-14 17:31:34 +01:00
|
|
|
PCFGMNODE pCfgHM = CFGMR3GetChild(CFGMR3GetRoot(pVM), "HM/");
|
|
|
|
|
|
|
|
/* check whether to stay for non-paged modi in recompiler */
|
|
|
|
int rc = CFGMR3QueryBoolDef(pCfgHM, "EnableUX",
|
|
|
|
&pVM->hm.s.vmx.fAllowUnrestricted, true);
|
|
|
|
AssertRCReturn(rc, rc);
|
|
|
|
|
|
|
|
/* check whether to enable pae and nx bit - in 64bit host mode */
|
|
|
|
rc = CFGMR3QueryBoolDef(CFGMR3GetRoot(pVM), "EnablePAE", &enable_pae_nx,
|
|
|
|
false);
|
|
|
|
AssertRCReturn(rc, rc);
|
|
|
|
|
2014-09-23 13:01:47 +02:00
|
|
|
/*
|
|
|
|
* We always set the fHMEnabled flag. Otherwise, the EM won't
|
|
|
|
* consult us for taking scheduling decisions. The actual switch to
|
|
|
|
* HW accelerated mode is still dependent on the result of the
|
|
|
|
* HMR3CanExecuteGuest function.
|
|
|
|
*/
|
|
|
|
pVM->fHMEnabled = true;
|
|
|
|
|
|
|
|
for (VMCPUID i = 0; i < pVM->cCpus; i++)
|
|
|
|
pVM->aCpus[i].hm.s.fActive = false;
|
|
|
|
|
|
|
|
pVM->fHMEnabledFixed = true;
|
|
|
|
|
|
|
|
return VINF_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMMR3_INT_DECL(int) HMR3Term(PVM pVM)
|
|
|
|
{
|
|
|
|
return VINF_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMMR3_INT_DECL(int) HMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat)
|
|
|
|
{
|
2015-01-14 17:31:34 +01:00
|
|
|
enabled_hm = pVM->hm.s.svm.fSupported || pVM->hm.s.vmx.fSupported;
|
2014-09-23 13:01:47 +02:00
|
|
|
|
2015-01-14 17:31:34 +01:00
|
|
|
if (!enabled_hm || enmWhat != VMINITCOMPLETED_RING0)
|
2014-09-23 13:01:47 +02:00
|
|
|
return VINF_SUCCESS;
|
|
|
|
|
|
|
|
int rc = SUPR3CallVMMR0Ex(pVM->pVMR0, 0 /*idCpu*/, VMMR0_DO_HM_SETUP_VM, 0, NULL);
|
|
|
|
|
|
|
|
if (rc == VINF_SUCCESS) {
|
|
|
|
CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SEP);
|
2015-01-14 17:31:34 +01:00
|
|
|
|
|
|
|
/* nova kernel supports solely on 64bit the following features */
|
|
|
|
if (sizeof(void *) > 4 && enable_pae_nx) {
|
|
|
|
CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_PAE);
|
|
|
|
CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_NX);
|
|
|
|
}
|
2014-09-23 13:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMMDECL(bool) HMIsEnabledNotMacro(PVM pVM)
|
|
|
|
{
|
|
|
|
Assert(pVM->fHMEnabledFixed);
|
|
|
|
return pVM->fHMEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMMR3DECL(bool) HMR3IsVmxPreemptionTimerUsed(PVM pVM)
|
|
|
|
{
|
|
|
|
// PLOG("HMR3IsVmxPreemptionTimerUsed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMMR3DECL(bool) HMR3IsActive(PVMCPU pVCpu)
|
|
|
|
{
|
|
|
|
return pVCpu->hm.s.fActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
VMM_INT_DECL(bool) HMIsLongModeAllowed(PVM pVM)
|
|
|
|
{
|
|
|
|
return HMIsEnabled(pVM) && pVM->hm.s.fAllow64BitGuests;
|
|
|
|
}
|
|
|
|
|
|
|
|
VMMR3DECL(bool) HMR3IsRescheduleRequired(PVM pVM, PCPUMCTX pCtx)
|
|
|
|
{
|
2015-01-14 17:31:34 +01:00
|
|
|
if (pVM->hm.s.vmx.fAllowUnrestricted)
|
2014-09-23 13:01:47 +02:00
|
|
|
return false;
|
|
|
|
|
2015-01-14 17:31:34 +01:00
|
|
|
return !CPUMIsGuestInPagedProtectedModeEx(pCtx);
|
2014-09-23 13:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMMR3DECL(bool) HMR3IsEventPending(PVMCPU pVCpu)
|
|
|
|
{
|
|
|
|
// PLOG("HMR3IsEventPending false");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMMR3DECL(bool) HMR3CanExecuteGuest(PVM pVM, PCPUMCTX pCtx)
|
|
|
|
{
|
2015-01-14 17:31:34 +01:00
|
|
|
if (!enabled_hm)
|
|
|
|
return false;
|
|
|
|
|
2014-09-23 13:01:47 +02:00
|
|
|
PVMCPU pVCpu = VMMGetCpu(pVM);
|
|
|
|
|
2015-01-14 17:31:34 +01:00
|
|
|
if (pVM->hm.s.vmx.fAllowUnrestricted) {
|
2014-09-23 13:01:47 +02:00
|
|
|
pVCpu->hm.s.fActive = true;
|
2015-01-14 17:31:34 +01:00
|
|
|
} else
|
|
|
|
/* enable H/W acceleration in protected and paged mode only */
|
|
|
|
pVCpu->hm.s.fActive = CPUMIsGuestInPagedProtectedModeEx(pCtx);
|
2014-09-23 13:01:47 +02:00
|
|
|
|
2015-01-14 17:31:34 +01:00
|
|
|
return pVCpu->hm.s.fActive;
|
|
|
|
}
|
2014-09-23 13:01:47 +02:00
|
|
|
|
|
|
|
|
2015-01-14 17:31:34 +01:00
|
|
|
VMM_INT_DECL(int) HMFlushTLB(PVMCPU pVCpu) { return VINF_SUCCESS; }
|