VirtualBox

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

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

VMM/GIM: More bits for Hyper-V implementation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: GIMAll.cpp 51643 2014-06-18 11:06:06Z 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 * Gets the GIM provider configured for this VM.
48 *
49 * @returns The GIM provider Id.
50 * @param pVM Pointer to the VM.
51 */
52VMMDECL(GIMPROVIDERID) GIMGetProvider(PVM pVM)
53{
54 return pVM->gim.s.enmProviderId;
55}
56
57
58/**
59 * Implements a GIM hypercall with the provider configured for the VM.
60 *
61 * @returns VBox status code.
62 * @param pVCpu Pointer to the VMCPU.
63 * @param pCtx Pointer to the guest-CPU context.
64 */
65VMM_INT_DECL(int) GIMHypercall(PVMCPU pVCpu, PCPUMCTX pCtx)
66{
67 PVM pVM = pVCpu->CTX_SUFF(pVM);
68 Assert(GIMIsEnabled(pVM));
69 VMCPU_ASSERT_EMT(pVCpu);
70
71 switch (pVM->gim.s.enmProviderId)
72 {
73 case GIMPROVIDERID_HYPERV:
74 return GIMHvHypercall(pVCpu, pCtx);
75
76 default:
77 AssertMsgFailed(("GIMHypercall: for unknown provider %u\n", pVM->gim.s.enmProviderId));
78 return VERR_GIM_IPE_3;
79 }
80}
81
82VMMDECL(bool) GIMIsParavirtTscEnabled(PVM pVM)
83{
84 if (!pVM->gim.s.fEnabled)
85 return false;
86
87 switch (pVM->gim.s.enmProviderId)
88 {
89 case GIMPROVIDERID_HYPERV:
90 return GIMHvIsParavirtTscEnabled(pVM);
91
92 default:
93 break;
94 }
95 return false;
96}
97
98
99/**
100 * Invokes the read-MSR handler for the GIM provider configured for the VM.
101 *
102 * @returns VBox status code.
103 * @param pVCpu Pointer to the VMCPU.
104 * @param idMsr The MSR to read.
105 * @param pRange The range this MSR belongs to.
106 * @param puValue Where to store the MSR value read.
107 */
108VMM_INT_DECL(int) GIMReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue)
109{
110 Assert(pVCpu);
111 PVM pVM = pVCpu->CTX_SUFF(pVM);
112 Assert(GIMIsEnabled(pVM));
113 VMCPU_ASSERT_EMT(pVCpu);
114
115 switch (pVM->gim.s.enmProviderId)
116 {
117 case GIMPROVIDERID_HYPERV:
118 return GIMHvReadMsr(pVCpu, idMsr, pRange, puValue);
119
120 default:
121 AssertMsgFailed(("GIMReadMsr: for unknown provider %u idMsr=%#RX32 -> #GP(0)", pVM->gim.s.enmProviderId, idMsr));
122 return VERR_CPUM_RAISE_GP_0;
123 }
124}
125
126
127/**
128 * Invokes the write-MSR handler for the GIM provider configured for the VM.
129 *
130 * @returns VBox status code.
131 * @param pVCpu Pointer to the VMCPU.
132 * @param idMsr The MSR to write.
133 * @param pRange The range this MSR belongs to.
134 * @param uValue The value to set, ignored bits masked.
135 * @param uRawValue The raw value with the ignored bits not masked.
136 */
137VMM_INT_DECL(int) GIMWriteMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t uValue, uint64_t uRawValue)
138{
139 AssertPtr(pVCpu);
140 NOREF(uValue);
141
142 PVM pVM = pVCpu->CTX_SUFF(pVM);
143 Assert(GIMIsEnabled(pVM));
144 VMCPU_ASSERT_EMT(pVCpu);
145
146 switch (pVM->gim.s.enmProviderId)
147 {
148 case GIMPROVIDERID_HYPERV:
149 return GIMHvWriteMsr(pVCpu, idMsr, pRange, uRawValue);
150
151 default:
152 AssertMsgFailed(("GIMWriteMsr: for unknown provider %u idMsr=%#RX32 -> #GP(0)", pVM->gim.s.enmProviderId, idMsr));
153 return VERR_CPUM_RAISE_GP_0;
154 }
155}
156
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