VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/GIMAll.cpp@ 51594

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

VMM/GIM: bits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: GIMAll.cpp 51563 2014-06-06 06:09:36Z vboxsync $ */
2/** @file
3 * GIM - Guest Interface Manager - All Contexts.
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/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_GIM
23#include "GIMInternal.h"
24#include <VBox/err.h>
25#include <VBox/vmm/vm.h>
26
27/* Include all the providers. */
28#include "GIMHvInternal.h"
29#include "GIMMinimalInternal.h"
30
31
32/**
33 * Checks whether GIM is being used by this VM.
34 *
35 * @retval @c true if used.
36 * @retval @c false if no GIM provider ("none") is used.
37 *
38 * @param pVM Pointer to the VM.
39 */
40VMMDECL(bool) GIMIsEnabled(PVM pVM)
41{
42 return pVM->gim.s.fEnabled;
43}
44
45
46/**
47 * Implements a GIM hypercall with the provider configured for the VM.
48 *
49 * @returns VBox status code.
50 * @param pVCpu Pointer to the VMCPU.
51 * @param pCtx Pointer to the guest-CPU context.
52 */
53VMM_INT_DECL(int) GIMHypercall(PVMCPU pVCpu, PCPUMCTX pCtx)
54{
55 PVM pVM = pVCpu->CTX_SUFF(pVM);
56 Assert(GIMIsEnabled(pVM));
57 VMCPU_ASSERT_EMT(pVCpu);
58
59 switch (pVM->gim.s.enmProviderId)
60 {
61 case GIMPROVIDERID_HYPERV:
62 return GIMHvHypercall(pVCpu, pCtx);
63
64 default:
65 AssertMsgFailed(("GIMHypercall: for unknown provider %u\n", pVM->gim.s.enmProviderId));
66 return VERR_GIM_IPE_3;
67 }
68}
69
70
71/**
72 * Updates the paravirtualized TSC supported by the GIM provider.
73 *
74 * @returns VBox status code.
75 * @retval VINF_SUCCESS if the paravirt. TSC is setup and in use.
76 * @retval VERR_GIM_NOT_ENABLED if no GIM provider is configured for this VM.
77 * @retval VERR_GIM_PVTSC_NOT_AVAILABLE if the GIM provider does not support any
78 * paravirt. TSC.
79 * @retval VERR_GIM_PVTSC_NOT_IN_USE if the GIM provider supports paravirt. TSC
80 * but the guest isn't currently using it.
81 *
82 * @param pVM Pointer to the VM.
83 * @param u64Offset The computed TSC offset.
84 *
85 * @thread EMT(pVCpu)
86 */
87VMMDECL(int) GIMUpdateParavirtTsc(PVM pVM, uint64_t u64Offset)
88{
89 if (!pVM->gim.s.fEnabled)
90 return VERR_GIM_NOT_ENABLED;
91
92 switch (pVM->gim.s.enmProviderId)
93 {
94 case GIMPROVIDERID_HYPERV:
95 return GIMHvUpdateParavirtTsc(pVM, u64Offset);
96
97 default:
98 break;
99 }
100 return VERR_GIM_PVTSC_NOT_AVAILABLE;
101}
102
103
104VMMDECL(bool) GIMIsParavirtTscEnabled(PVM pVM)
105{
106 if (!pVM->gim.s.fEnabled)
107 return false;
108
109 switch (pVM->gim.s.enmProviderId)
110 {
111 case GIMPROVIDERID_HYPERV:
112 return GIMHvIsParavirtTscEnabled(pVM);
113
114 default:
115 break;
116 }
117 return false;
118}
119
120
121/**
122 * Invokes the read-MSR handler for the GIM provider configured for the VM.
123 *
124 * @returns VBox status code.
125 * @param pVCpu Pointer to the VMCPU.
126 * @param idMsr The MSR to read.
127 * @param pRange The range this MSR belongs to.
128 * @param puValue Where to store the MSR value read.
129 */
130VMM_INT_DECL(int) GIMReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue)
131{
132 Assert(pVCpu);
133 PVM pVM = pVCpu->CTX_SUFF(pVM);
134 Assert(GIMIsEnabled(pVM));
135 VMCPU_ASSERT_EMT(pVCpu);
136
137 switch (pVM->gim.s.enmProviderId)
138 {
139 case GIMPROVIDERID_HYPERV:
140 return GIMHvReadMsr(pVCpu, idMsr, pRange, puValue);
141
142 default:
143 AssertMsgFailed(("GIMReadMsr: for unknown provider %u idMsr=%#RX32 -> #GP(0)", pVM->gim.s.enmProviderId, idMsr));
144 return VERR_CPUM_RAISE_GP_0;
145 }
146}
147
148
149/**
150 * Invokes the write-MSR handler for the GIM provider configured for the VM.
151 *
152 * @returns VBox status code.
153 * @param pVCpu Pointer to the VMCPU.
154 * @param idMsr The MSR to write.
155 * @param pRange The range this MSR belongs to.
156 * @param uValue The value to set, ignored bits masked.
157 * @param uRawValue The raw value with the ignored bits not masked.
158 */
159VMM_INT_DECL(int) GIMWriteMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t uValue, uint64_t uRawValue)
160{
161 AssertPtr(pVCpu);
162 NOREF(uValue);
163
164 PVM pVM = pVCpu->CTX_SUFF(pVM);
165 Assert(GIMIsEnabled(pVM));
166 VMCPU_ASSERT_EMT(pVCpu);
167
168 switch (pVM->gim.s.enmProviderId)
169 {
170 case GIMPROVIDERID_HYPERV:
171 return GIMHvWriteMsr(pVCpu, idMsr, pRange, uRawValue);
172
173 default:
174 AssertMsgFailed(("GIMWriteMsr: for unknown provider %u idMsr=%#RX32 -> #GP(0)", pVM->gim.s.enmProviderId, idMsr));
175 return VERR_CPUM_RAISE_GP_0;
176 }
177}
178
Note: See TracBrowser for help on using the repository browser.

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