VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/GIM.cpp@ 51234

Last change on this file since 51234 was 50994, checked in by vboxsync, 10 years ago

VMM/GIM: Introduce the Minimal provider.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: GIM.cpp 50994 2014-04-08 12:30:50Z vboxsync $ */
2/** @file
3 * GIM - Guest Interface Manager.
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/** @page pg_gim GIM - The Guest Interface Manager
19 *
20 * The Guest Interface Manager abstracts an interface provider through which
21 * guests may interact with the hypervisor.
22 *
23 * @see grp_gim
24 *
25 *
26 * @section sec_gim_provider Providers
27 *
28 * A GIM provider implements a particular hypervisor interface such as Microsoft
29 * Hyper-V, Linux KVM and so on. It hooks into various components in the VMM to
30 * ease the guest in running under a recognized virtualized environment. This is
31 * also referred to as paravirtualization interfaces.
32 *
33 * The idea behind this is primarily for making guests more accurate and
34 * efficient when operating in a virtualized environment.
35 *
36 * For instance, a guest when interfaced to VirtualBox through a GIM provider
37 * may rely on the provider (and VirtualBox ultimately) for providing the
38 * correct TSC frequency and may therefore not have to caliberate the TSC
39 * itself, resulting in higher accuracy and saving several CPU cycles.
40 *
41 * Only one provider can be active for a running VM.
42 */
43
44/*******************************************************************************
45* Header Files *
46*******************************************************************************/
47#define LOG_GROUP LOG_GROUP_GIM
48#include <VBox/log.h>
49#include "GIMInternal.h"
50#include <VBox/vmm/vm.h>
51#include <VBox/vmm/hm.h>
52#include <VBox/vmm/ssm.h>
53
54#include <iprt/err.h>
55#include <iprt/string.h>
56
57/* Include all GIM providers. */
58#include "GIMMinimalInternal.h"
59#include "GIMHvInternal.h"
60
61/*******************************************************************************
62* Internal Functions *
63*******************************************************************************/
64static DECLCALLBACK(int) gimR3Save(PVM pVM, PSSMHANDLE pSSM);
65static DECLCALLBACK(int) gimR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
66
67
68/**
69 * Initializes the GIM.
70 *
71 * @returns VBox status code.
72 * @param pVM Pointer to the VM.
73 */
74VMMR3_INT_DECL(int) GIMR3Init(PVM pVM)
75{
76 LogFlow(("GIMR3Init\n"));
77
78 /*
79 * Assert alignment and sizes.
80 */
81 AssertCompile(sizeof(pVM->gim.s) <= sizeof(pVM->gim.padding));
82
83 /*
84 * Register the saved state data unit.
85 */
86 int rc;
87#if 0
88 rc = SSMR3RegisterInternal(pVM, "GIM", 0, GIM_SSM_VERSION, sizeof(GIM),
89 NULL, NULL, NULL,
90 NULL, gimR3Save, NULL,
91 NULL, gimR3Load, NULL);
92 if (RT_FAILURE(rc))
93 return rc;
94#endif
95
96 /*
97 * Read configuration.
98 */
99 PCFGMNODE pCfgNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "GIM/");
100
101 /** @cfgm{GIM/Provider, string}
102 * The name of the GIM provider. The default is "none". */
103 char szProvider[64];
104 rc = CFGMR3QueryStringDef(pCfgNode, "Provider", szProvider, sizeof(szProvider), "None");
105 AssertLogRelRCReturn(rc, rc);
106
107 /*
108 * Setup the GIM provider for this VM.
109 */
110 LogRel(("GIM: Using provider \"%s\"\n", szProvider));
111 if (!RTStrCmp(szProvider, "None"))
112 {
113 Assert(!pVM->gim.s.fEnabled);
114 pVM->gim.s.enmProvider = GIMPROVIDER_NONE;
115 }
116 else
117 {
118 pVM->gim.s.fEnabled = true;
119 if (!RTStrCmp(szProvider, "Minimal"))
120 {
121 pVM->gim.s.enmProvider = GIMPROVIDER_MINIMAL;
122 rc = GIMR3MinimalInit(pVM);
123 }
124 else if (!RTStrCmp(szProvider, "HyperV"))
125 {
126 pVM->gim.s.enmProvider = GIMPROVIDER_HYPERV;
127 rc = GIMR3HvInit(pVM);
128 }
129 /** @todo KVM and others. */
130 else
131 {
132 LogRel(("GIM: Provider \"%s\" unknown.\n", szProvider));
133 rc = VERR_NOT_SUPPORTED;
134 }
135 }
136
137 return rc;
138}
139
140
141/**
142 * Applies relocations to data and code managed by this component. This function
143 * will be called at init and whenever the VMM need to relocate itself inside
144 * the GC.
145 *
146 * @param pVM Pointer to the VM.
147 * @param offDelta Relocation delta relative to old location.
148 */
149VMM_INT_DECL(void) GIMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
150{
151 LogFlow(("GIMR3Relocate\n"));
152
153 if ( !pVM->gim.s.fEnabled
154 || HMIsEnabled(pVM))
155 {
156 return;
157 }
158
159 switch (pVM->gim.s.enmProvider)
160 {
161 case GIMPROVIDER_MINIMAL:
162 {
163 GIMR3MinimalRelocate(pVM, offDelta);
164 break;
165 }
166
167 case GIMPROVIDER_HYPERV:
168 {
169 GIMR3HvRelocate(pVM, offDelta);
170 break;
171 }
172
173 case GIMPROVIDER_KVM: /** @todo KVM. */
174 default:
175 {
176 AssertMsgFailed(("Invalid provider id %#x\n", pVM->gim.s.enmProvider));
177 break;
178 }
179 }
180}
181
182
183/**
184 * Execute state save operation.
185 *
186 * @returns VBox status code.
187 * @param pVM Pointer to the VM.
188 * @param pSSM SSM operation handle.
189 */
190DECLCALLBACK(int) gimR3Save(PVM pVM, PSSMHANDLE pSSM)
191{
192 /** @todo save state. */
193 return VINF_SUCCESS;
194}
195
196
197/**
198 * Execute state load operation.
199 *
200 * @returns VBox status code.
201 * @param pVM Pointer to the VM.
202 * @param pSSM SSM operation handle.
203 * @param uVersion Data layout version.
204 * @param uPass The data pass.
205 */
206DECLCALLBACK(int) gimR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
207{
208 /** @todo load state. */
209 return VINF_SUCCESS;
210}
211
212
213/**
214 * Terminates the GIM.
215 *
216 * Termination means cleaning up and freeing all resources,
217 * the VM itself is, at this point, powered off or suspended.
218 *
219 * @returns VBox status code.
220 * @param pVM Pointer to the VM.
221 */
222VMMR3_INT_DECL(int) GIMR3Term(PVM pVM)
223{
224 return VINF_SUCCESS;
225}
226
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use