VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/GIMHv.cpp@ 51367

Last change on this file since 51367 was 51367, checked in by vboxsync, 11 years ago

VMM/GIM: Hyper-V provider, work-in-progress.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: GIMHv.cpp 51367 2014-05-23 07:45:35Z vboxsync $ */
2/** @file
3 * GIM - Guest Interface Manager, Hyper-V implementation.
4 */
5
6/*
7 * Copyright (C) 2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_GIM
22#include "GIMHvInternal.h"
23#include "GIMInternal.h"
24
25#include <iprt/assert.h>
26#include <iprt/err.h>
27#include <iprt/string.h>
28
29#include <VBox/vmm/cpum.h>
30#include <VBox/vmm/vm.h>
31#include <VBox/vmm/hm.h>
32#include <VBox/vmm/pdmapi.h>
33#include <VBox/version.h>
34
35/*******************************************************************************
36* Defined Constants And Macros *
37*******************************************************************************/
38//#define GIMHV_HYPERCALL "GIMHvHypercall"
39#ifdef VBOX_WITH_STATISTICS
40# define GIMHV_MSRRANGE(a_uFirst, a_uLast, a_szName) \
41 { (a_uFirst), (a_uLast), kCpumMsrRdFn_Gim, kCpumMsrWrFn_Gim, 0, 0, 0, 0, 0, a_szName, { 0 }, { 0 }, { 0 }, { 0 } }
42#else
43# define GIMHV_MSRRANGE(a_uFirst, a_uLast, a_szName) \
44 { (a_uFirst), (a_uLast), kCpumMsrRdFn_Gim, kCpumMsrWrFn_Gim, 0, 0, 0, 0, 0, a_szName }
45#endif
46
47/**
48 * Array of MSR ranges supported by Hyper-V.
49 */
50static CPUMMSRRANGE const g_aMsrRanges_HyperV[] =
51{
52 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE0_START, MSR_GIM_HV_RANGE0_END, "Hyper-V range 0"),
53 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE1_START, MSR_GIM_HV_RANGE1_END, "Hyper-V range 1"),
54 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE2_START, MSR_GIM_HV_RANGE2_END, "Hyper-V range 2"),
55 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE3_START, MSR_GIM_HV_RANGE3_END, "Hyper-V range 3"),
56 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE4_START, MSR_GIM_HV_RANGE4_END, "Hyper-V range 4"),
57 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE5_START, MSR_GIM_HV_RANGE5_END, "Hyper-V range 5"),
58 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE6_START, MSR_GIM_HV_RANGE6_END, "Hyper-V range 6"),
59 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE7_START, MSR_GIM_HV_RANGE7_END, "Hyper-V range 7"),
60 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE8_START, MSR_GIM_HV_RANGE8_END, "Hyper-V range 8"),
61 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE9_START, MSR_GIM_HV_RANGE9_END, "Hyper-V range 9"),
62 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE10_START, MSR_GIM_HV_RANGE10_END, "Hyper-V range 10"),
63 GIMHV_MSRRANGE(MSR_GIM_HV_RANGE11_START, MSR_GIM_HV_RANGE11_END, "Hyper-V range 11")
64};
65#undef GIMHV_MSR
66
67
68/**
69 * Initializes the Hyper-V GIM provider.
70 *
71 * @returns VBox status code.
72 * @param pVM Pointer to the VM.
73 * @param uVersion The interface version this VM should use.
74 */
75VMMR3_INT_DECL(int) GIMR3HvInit(PVM pVM)
76{
77 AssertReturn(pVM, VERR_INVALID_PARAMETER);
78 AssertReturn(pVM->gim.s.enmProviderId == GIMPROVIDERID_HYPERV, VERR_INTERNAL_ERROR_5);
79
80 int rc;
81#if 0
82 pVM->gim.s.pfnHypercallR3 = &GIMHvHypercall;
83 if (!HMIsEnabled(pVM))
84 {
85 rc = PDMR3LdrGetSymbolRC(pVM, NULL /* pszModule */, GIMHV_HYPERCALL, &pVM->gim.s.pfnHypercallRC);
86 AssertRCReturn(rc, rc);
87 }
88 rc = PDMR3LdrGetSymbolR0(pVM, NULL /* pszModule */, GIMHV_HYPERCALL, &pVM->gim.s.pfnHypercallR0);
89 AssertRCReturn(rc, rc);
90#endif
91
92 /*
93 * Determine interface capabilities based on the version.
94 */
95 uint32_t uBaseFeat = 0;
96 uint32_t uPartFlags = 0;
97 uint32_t uPowMgmtFeat = 0;
98 uint32_t uMiscFeat = 0;
99 uint32_t uHyperHints = 0;
100 if (!pVM->gim.s.u32Version)
101 {
102 uBaseFeat = 0
103 //| GIM_HV_BASE_FEAT_VP_RUNTIME_MSR
104 | GIM_HV_BASE_FEAT_PART_REF_COUNT_MSR
105 //| GIM_HV_BASE_FEAT_BASIC_SYNTH_IC
106 //| GIM_HV_BASE_FEAT_SYNTH_TIMER_MSRS
107 //| GIM_HV_BASE_FEAT_APIC_ACCESS_MSRS
108 //| GIM_HV_BASE_FEAT_HYPERCALL_MSRS
109 | GIM_HV_BASE_FEAT_VP_ID_MSR
110 //| GIM_HV_BASE_FEAT_VIRT_SYS_RESET_MSR
111 //| GIM_HV_BASE_FEAT_STAT_PAGES_MSR
112 //| GIM_HV_BASE_FEAT_PART_REF_TSC_MSR
113 //| GIM_HV_BASE_FEAT_GUEST_IDLE_STATE_MSR
114 //| GIM_HV_BASE_FEAT_TIMER_FREQ_MSRS
115 //| GIM_HV_BASE_FEAT_DEBUG_MSRS
116 ;
117
118 pVM->gim.s.u.hv.u16HyperIdVersionMajor = VBOX_VERSION_MAJOR;
119 pVM->gim.s.u.hv.u16HyperIdVersionMajor = VBOX_VERSION_MINOR;
120 pVM->gim.s.u.hv.u32HyperIdBuildNumber = VBOX_VERSION_BUILD;
121 }
122
123 /*
124 * Expose HVP (Hypervisor Present) bit to the guest.
125 */
126 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_HVP);
127
128 /*
129 * Modify the standard hypervisor leaves for Hyper-V.
130 */
131 CPUMCPUIDLEAF HyperLeaf;
132 RT_ZERO(HyperLeaf);
133 HyperLeaf.uLeaf = UINT32_C(0x40000000);
134 HyperLeaf.uEax = UINT32_C(0x40000005); /* Minimum value for Hyper-V */
135 HyperLeaf.uEbx = 0x7263694D; /* 'Micr' */
136 HyperLeaf.uEcx = 0x666F736F; /* 'osof' */
137 HyperLeaf.uEdx = 0x76482074; /* 't Hv' */
138 rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
139 AssertLogRelRCReturn(rc, rc);
140
141 HyperLeaf.uLeaf = UINT32_C(0x40000001);
142 HyperLeaf.uEax = 0x31237648; /* 'Hv#1' */
143 HyperLeaf.uEbx = 0; /* Reserved */
144 HyperLeaf.uEcx = 0; /* Reserved */
145 HyperLeaf.uEdx = 0; /* Reserved */
146 rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
147 AssertLogRelRCReturn(rc, rc);
148
149 /*
150 * Add Hyper-V specific leaves.
151 */
152 HyperLeaf.uLeaf = UINT32_C(0x40000002); /* MBZ until MSR_GIM_HV_GUEST_OS_ID is set by the guest. */
153 HyperLeaf.uEax = 0;
154 HyperLeaf.uEbx = 0;
155 HyperLeaf.uEcx = 0;
156 HyperLeaf.uEdx = 0;
157 rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
158 AssertLogRelRCReturn(rc, rc);
159
160 HyperLeaf.uLeaf = UINT32_C(0x40000003);
161 HyperLeaf.uEax = uBaseFeat;
162 HyperLeaf.uEbx = uPartFlags;
163 HyperLeaf.uEcx = uPowMgmtFeat;
164 HyperLeaf.uEdx = uMiscFeat;
165 rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
166 AssertLogRelRCReturn(rc, rc);
167
168 /*
169 * Insert all MSR ranges of Hyper-V.
170 */
171 for (uint32_t i = 0; i < RT_ELEMENTS(g_aMsrRanges_HyperV); i++)
172 {
173 rc = CPUMR3MsrRangesInsert(pVM, &g_aMsrRanges_HyperV[i]);
174 AssertLogRelRCReturn(rc, rc);
175 }
176 return VINF_SUCCESS;
177}
178
179
180VMMR3_INT_DECL(void) GIMR3HvRelocate(PVM pVM, RTGCINTPTR offDelta)
181{
182#if 0
183 int rc = PDMR3LdrGetSymbolRC(pVM, NULL /* pszModule */, GIMHV_HYPERCALL, &pVM->gim.s.pfnHypercallRC);
184 AssertFatalRC(rc);
185#endif
186}
187
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette