VirtualBox

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

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

VMM/GIM: Use proper-case for the "None" provider CFGM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: GIM.cpp 50961 2014-04-03 12:06:24Z 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 "GIMHvInternal.h"
59
60/*******************************************************************************
61* Internal Functions *
62*******************************************************************************/
63static DECLCALLBACK(int) gimR3Save(PVM pVM, PSSMHANDLE pSSM);
64static DECLCALLBACK(int) gimR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
65
66
67/**
68 * Initializes the GIM.
69 *
70 * @returns VBox status code.
71 * @param pVM Pointer to the VM.
72 */
73VMMR3_INT_DECL(int) GIMR3Init(PVM pVM)
74{
75 LogFlow(("GIMR3Init\n"));
76
77 /*
78 * Assert alignment and sizes.
79 */
80 AssertCompile(sizeof(pVM->gim.s) <= sizeof(pVM->gim.padding));
81
82 /*
83 * Register the saved state data unit.
84 */
85 int rc;
86#if 0
87 rc = SSMR3RegisterInternal(pVM, "GIM", 0, GIM_SSM_VERSION, sizeof(GIM),
88 NULL, NULL, NULL,
89 NULL, gimR3Save, NULL,
90 NULL, gimR3Load, NULL);
91 if (RT_FAILURE(rc))
92 return rc;
93#endif
94
95 /*
96 * Read configuration.
97 */
98 PCFGMNODE pCfgNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "GIM/");
99
100 /** @cfgm{GIM/Provider, string}
101 * The name of the GIM provider. The default is "none". */
102 char szProvider[64];
103 rc = CFGMR3QueryStringDef(pCfgNode, "Provider", szProvider, sizeof(szProvider), "None");
104 AssertLogRelRCReturn(rc, rc);
105
106 /*
107 * Setup the GIM provider for this VM.
108 */
109 LogRel(("GIM: Using provider \"%s\"\n", szProvider));
110 if (!RTStrCmp(szProvider, "None"))
111 {
112 Assert(!pVM->gim.s.fEnabled);
113 pVM->gim.s.enmProvider = GIMPROVIDER_NONE;
114 }
115 else
116 {
117 pVM->gim.s.fEnabled = true;
118 if (!RTStrCmp(szProvider, "HyperV"))
119 {
120 pVM->gim.s.enmProvider = GIMPROVIDER_HYPERV;
121 rc = GIMR3HvInit(pVM);
122 }
123 /** @todo KVM and others. */
124 else
125 {
126 LogRel(("GIM: Provider \"%s\" unknown.\n", szProvider));
127 rc = VERR_NOT_SUPPORTED;
128 }
129 }
130
131 return rc;
132}
133
134
135/**
136 * Applies relocations to data and code managed by this
137 * component. This function will be called at init and
138 * whenever the VMM need to relocate it self inside the GC.
139 *
140 * @param pVM Pointer to the VM.
141 * @param offDelta Relocation delta relative to old location.
142 */
143VMM_INT_DECL(void) GIMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
144{
145 LogFlow(("GIMR3Relocate\n"));
146
147 if ( !pVM->gim.s.fEnabled
148 || HMIsEnabled(pVM))
149 {
150 return;
151 }
152
153 switch (pVM->gim.s.enmProvider)
154 {
155 case GIMPROVIDER_HYPERV:
156 {
157 GIMR3HvRelocate(pVM, offDelta);
158 break;
159 }
160
161 case GIMPROVIDER_KVM: /** @todo KVM. */
162 default:
163 {
164 AssertMsgFailed(("Invalid provider id %#x\n", pVM->gim.s.enmProvider));
165 break;
166 }
167 }
168}
169
170
171/**
172 * Execute state save operation.
173 *
174 * @returns VBox status code.
175 * @param pVM Pointer to the VM.
176 * @param pSSM SSM operation handle.
177 */
178DECLCALLBACK(int) gimR3Save(PVM pVM, PSSMHANDLE pSSM)
179{
180 /** @todo save state. */
181 return VINF_SUCCESS;
182}
183
184
185/**
186 * Execute state load operation.
187 *
188 * @returns VBox status code.
189 * @param pVM Pointer to the VM.
190 * @param pSSM SSM operation handle.
191 * @param uVersion Data layout version.
192 * @param uPass The data pass.
193 */
194DECLCALLBACK(int) gimR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
195{
196 /** @todo load state. */
197 return VINF_SUCCESS;
198}
199
200
201/**
202 * Terminates the GIM.
203 *
204 * Termination means cleaning up and freeing all resources,
205 * the VM itself is, at this point, powered off or suspended.
206 *
207 * @returns VBox status code.
208 * @param pVM Pointer to the VM.
209 */
210VMMR3_INT_DECL(int) GIMR3Term(PVM pVM)
211{
212 return VINF_SUCCESS;
213}
214
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