VirtualBox

source: vbox/trunk/src/VBox/VMM/include/GIMKvmInternal.h@ 55934

Last change on this file since 55934 was 55510, checked in by vboxsync, 10 years ago

VMM/GIM: EMT Rendezvous while updating global wall-clock struct.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1/* $Id: GIMKvmInternal.h 55510 2015-04-29 10:13:15Z vboxsync $ */
2/** @file
3 * GIM - KVM, Internal header file.
4 */
5
6/*
7 * Copyright (C) 2015 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#ifndef ___GIMKvmInternal_h
19#define ___GIMKvmInternal_h
20
21#include <VBox/vmm/gim.h>
22#include <VBox/vmm/cpum.h>
23
24
25/** @name KVM base features.
26 * @{
27 */
28/** Old, deprecated clock source available. */
29#define GIM_KVM_BASE_FEAT_CLOCK_OLD RT_BIT(0)
30/** No need for artifical delays on IO operations. */
31#define GIM_KVM_BASE_FEAT_NOP_IO_DELAY RT_BIT(1)
32/** MMU op supported (deprecated, unused). */
33#define GIM_KVM_BASE_FEAT_MMU_OP RT_BIT(2)
34/** Clock source available. */
35#define GIM_KVM_BASE_FEAT_CLOCK RT_BIT(3)
36/** Asynchronous page faults supported. */
37#define GIM_KVM_BASE_FEAT_ASYNC_PF RT_BIT(4)
38/** Steal time (VCPU not executing guest code time in ns) available. */
39#define GIM_KVM_BASE_FEAT_STEAL_TIME RT_BIT(5)
40/** Paravirtualized EOI (end-of-interrupt) supported. */
41#define GIM_KVM_BASE_FEAT_PV_EOI RT_BIT(6)
42/** Paravirtualized spinlock (unhalting VCPU) supported. */
43#define GIM_KVM_BASE_FEAT_PV_UNHALT RT_BIT(7)
44/** The TSC is stable (fixed rate, monotonic). */
45#define GIM_KVM_BASE_FEAT_TSC_STABLE RT_BIT(24)
46/** @} */
47
48
49/** @name KVM MSRs.
50 * @{
51 */
52/** Start of range 0. */
53#define MSR_GIM_KVM_RANGE0_START UINT32_C(0x11)
54/** Old, deprecated wall clock. */
55#define MSR_GIM_KVM_WALL_CLOCK_OLD UINT32_C(0x11)
56/** Old, deprecated System time. */
57#define MSR_GIM_KVM_SYSTEM_TIME_OLD UINT32_C(0x12)
58/** End of range 0. */
59#define MSR_GIM_KVM_RANGE0_END MSR_GIM_KVM_SYSTEM_TIME_OLD
60
61/** Start of range 1. */
62#define MSR_GIM_KVM_RANGE1_START UINT32_C(0x4b564d00)
63/** Wall clock. */
64#define MSR_GIM_KVM_WALL_CLOCK UINT32_C(0x4b564d00)
65/** System time. */
66#define MSR_GIM_KVM_SYSTEM_TIME UINT32_C(0x4b564d01)
67/** Asynchronous page fault. */
68#define MSR_GIM_KVM_ASYNC_PF UINT32_C(0x4b564d02)
69/** Steal time. */
70#define MSR_GIM_KVM_STEAL_TIME UINT32_C(0x4b564d03)
71/** Paravirtualized EOI (end-of-interrupt). */
72#define MSR_GIM_KVM_EOI UINT32_C(0x4b564d04)
73/** End of range 1. */
74#define MSR_GIM_KVM_RANGE1_END MSR_GIM_KVM_EOI
75
76AssertCompile(MSR_GIM_KVM_RANGE0_START <= MSR_GIM_KVM_RANGE0_END);
77AssertCompile(MSR_GIM_KVM_RANGE1_START <= MSR_GIM_KVM_RANGE1_END);
78
79/** KVM page size. */
80#define GIM_KVM_PAGE_SIZE 0x1000
81
82/**
83 * MMIO2 region indices.
84 */
85/** The system time page(s) region. */
86#define GIM_KVM_SYSTEM_TIME_PAGE_REGION_IDX UINT8_C(0)
87/** The steal time page(s) region. */
88#define GIM_KVM_STEAL_TIME_PAGE_REGION_IDX UINT8_C(1)
89/** The maximum region index (must be <= UINT8_MAX). */
90#define GIM_KVM_REGION_IDX_MAX GIM_KVM_STEAL_TIME_PAGE_REGION_IDX
91
92/**
93 * KVM system-time structure (GIM_KVM_SYSTEM_TIME_FLAGS_XXX) flags.
94 * See "Documentation/virtual/kvm/api.txt".
95 */
96/** The TSC is stable (monotonic). */
97#define GIM_KVM_SYSTEM_TIME_FLAGS_TSC_STABLE RT_BIT(0)
98/** The guest VCPU has been paused by the hypervisor. */
99#define GIM_KVM_SYSTEM_TIME_FLAGS_GUEST_PAUSED RT_BIT(1)
100/** */
101
102/** @name KVM MSR - System time (MSR_GIM_KVM_SYSTEM_TIME and
103 * MSR_GIM_KVM_SYSTEM_TIME_OLD).
104 * @{
105 */
106/** The system-time enable bit. */
107#define MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT RT_BIT_64(0)
108/** Whether the system-time struct. is enabled or not. */
109#define MSR_GIM_KVM_SYSTEM_TIME_IS_ENABLED(a) RT_BOOL((a) & MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT)
110/** Guest-physical address of the system-time struct. */
111#define MSR_GIM_KVM_SYSTEM_TIME_GUEST_GPA(a) ((a) & ~MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT)
112/** @} */
113
114/** @name KVM MSR - Wall clock (MSR_GIM_KVM_WALL_CLOCK and
115 * MSR_GIM_KVM_WALL_CLOCK_OLD).
116 * @{
117 */
118/** Guest-physical address of the wall-clock struct. */
119#define MSR_GIM_KVM_WALL_CLOCK_GUEST_GPA(a) (a)
120/** @} */
121
122
123/** @name KVM Hypercall operations.
124 * @{ */
125#define KVM_HYPERCALL_OP_VAPIC_POLL_IRQ 1
126#define KVM_HYPERCALL_OP_MMU 2
127#define KVM_HYPERCALL_OP_FEATURES 3
128#define KVM_HYPERCALL_OP_KICK_CPU 5
129/** @} */
130
131/** @name KVM Hypercall return values.
132 * @{ */
133/* Return values for hypercalls */
134#define KVM_HYPERCALL_RET_SUCCESS 0
135#define KVM_HYPERCALL_RET_ENOSYS (uint64_t)(-1000)
136#define KVM_HYPERCALL_RET_EFAULT (uint64_t)(-14)
137#define KVM_HYPERCALL_RET_E2BIG (uint64_t)(-7)
138#define KVM_HYPERCALL_RET_EPERM (uint64_t)(-1)
139/** @} */
140
141/**
142 * KVM per-VCPU system-time structure.
143 */
144typedef struct GIMKVMSYSTEMTIME
145{
146 /** Version (sequence number). */
147 uint32_t u32Version;
148 /** Alignment padding. */
149 uint32_t u32Padding0;
150 /** TSC time stamp. */
151 uint64_t u64Tsc;
152 /** System time in nanoseconds. */
153 uint64_t u64NanoTS;
154 /** TSC to system time scale factor. */
155 uint32_t u32TscScale;
156 /** TSC frequency shift. */
157 int8_t i8TscShift;
158 /** Clock source (GIM_KVM_SYSTEM_TIME_FLAGS_XXX) flags. */
159 uint8_t fFlags;
160 /** Alignment padding. */
161 uint8_t abPadding0[2];
162} GIMKVMSYSTEMTIME;
163/** Pointer to KVM system-time struct. */
164typedef GIMKVMSYSTEMTIME *PGIMKVMSYSTEMTIME;
165/** Pointer to a const KVM system-time struct. */
166typedef GIMKVMSYSTEMTIME const *PCGIMKVMSYSTEMTIME;
167AssertCompileSize(GIMKVMSYSTEMTIME, 32);
168
169
170/**
171 * KVM per-VM wall-clock structure.
172 */
173typedef struct GIMKVMWALLCLOCK
174{
175 /** Version (sequence number). */
176 uint32_t u32Version;
177 /** Number of seconds since boot. */
178 uint32_t u32Sec;
179 /** Number of nanoseconds since boot. */
180 uint32_t u32Nano;
181} GIMKVMWALLCLOCK;
182/** Pointer to KVM wall-clock struct. */
183typedef GIMKVMWALLCLOCK *PGIMKVMWALLCLOCK;
184/** Pointer to a const KVM wall-clock struct. */
185typedef GIMKVMWALLCLOCK const *PCGIMKVMWALLCLOCK;
186AssertCompileSize(GIMKVMWALLCLOCK, 12);
187
188
189/**
190 * GIM KVMV VM instance data.
191 * Changes to this must checked against the padding of the gim union in VM!
192 */
193typedef struct GIMKVM
194{
195 /** Wall-clock MSR. */
196 uint64_t u64WallClockMsr;
197
198 /** CPUID features: Basic. */
199 uint32_t uBaseFeat;
200
201 /** Whether GIM needs to trap #UD exceptions. */
202 bool fTrapXcptUD;
203 /** Disassembler opcode of hypercall instruction native for this host CPU. */
204 uint16_t uOpCodeNative;
205} GIMKVM;
206/** Pointer to per-VM GIM KVM instance data. */
207typedef GIMKVM *PGIMKVM;
208/** Pointer to const per-VM GIM KVM instance data. */
209typedef GIMKVM const *PCGIMKVM;
210
211/**
212 * GIM KVMV VCPU instance data.
213 * Changes to this must checked against the padding of the gim union in VMCPU!
214 */
215typedef struct GIMKVMCPU
216{
217 /** System-time MSR. */
218 uint64_t u64SystemTimeMsr;
219 /** The guest-physical address of the system-time struct. */
220 RTGCPHYS GCPhysSystemTime;
221 /** The version (sequence number) of the system-time struct. */
222 uint32_t u32SystemTimeVersion;
223 /** The guest TSC value while enabling the system-time MSR. */
224 uint64_t uTsc;
225 /** The guest virtual time while enabling the system-time MSR. */
226 uint64_t uVirtNanoTS;
227} GIMKVMCPU;
228/** Pointer to per-VCPU GIM KVM instance data. */
229typedef GIMKVMCPU *PGIMKVMCPU;
230/** Pointer to const per-VCPU GIM KVM instance data. */
231typedef GIMKVMCPU const *PCGIMKVMCPU;
232
233
234RT_C_DECLS_BEGIN
235
236#ifdef IN_RING0
237#if 0
238VMMR0_INT_DECL(int) gimR0KvmInitVM(PVM pVM);
239VMMR0_INT_DECL(int) gimR0KvmTermVM(PVM pVM);
240VMMR0_INT_DECL(int) gimR0KvmUpdateParavirtTsc(PVM pVM, uint64_t u64Offset);
241#endif
242#endif /* IN_RING0 */
243
244#ifdef IN_RING3
245VMMR3_INT_DECL(int) gimR3KvmInit(PVM pVM);
246VMMR3_INT_DECL(int) gimR3KvmInitCompleted(PVM pVM);
247VMMR3_INT_DECL(int) gimR3KvmTerm(PVM pVM);
248VMMR3_INT_DECL(void) gimR3KvmRelocate(PVM pVM, RTGCINTPTR offDelta);
249VMMR3_INT_DECL(void) gimR3KvmReset(PVM pVM);
250VMMR3_INT_DECL(int) gimR3KvmSave(PVM pVM, PSSMHANDLE pSSM);
251VMMR3_INT_DECL(int) gimR3KvmLoad(PVM pVM, PSSMHANDLE pSSM, uint32_t uSSMVersion);
252
253VMMR3_INT_DECL(int) gimR3KvmDisableSystemTime(PVM pVM);
254VMMR3_INT_DECL(int) gimR3KvmEnableSystemTime(PVM pVM, PVMCPU pVCpu, PGIMKVMCPU pKvmCpu, uint8_t fFlags);
255VMMR3_INT_DECL(int) gimR3KvmEnableWallClock(PVM pVM, RTGCPHYS GCPhysSysTime);
256#endif /* IN_RING3 */
257
258VMM_INT_DECL(bool) gimKvmIsParavirtTscEnabled(PVM pVM);
259VMM_INT_DECL(bool) gimKvmAreHypercallsEnabled(PVMCPU pVCpu);
260VMM_INT_DECL(int) gimKvmHypercall(PVMCPU pVCpu, PCPUMCTX pCtx);
261VMM_INT_DECL(VBOXSTRICTRC) gimKvmReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue);
262VMM_INT_DECL(VBOXSTRICTRC) gimKvmWriteMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t uRawValue);
263VMM_INT_DECL(bool) gimKvmShouldTrapXcptUD(PVMCPU pVCpu);
264VMM_INT_DECL(int) gimKvmXcptUD(PVMCPU pVCpu, PCPUMCTX pCtx, PDISCPUSTATE pDis);
265
266
267RT_C_DECLS_END
268
269#endif
270
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