VirtualBox

source: vbox/trunk/include/iprt/nt/vid.h@ 74517

Last change on this file since 74517 was 74517, checked in by vboxsync, 6 years ago

NEM/win: Updates for new builds. bugref:9044

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
1/** @file
2 * Virtualization Infrastructure Driver (VID) API.
3 */
4
5/*
6 * Copyright (C) 2018 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26
27#ifndef ___iprt_nt_vid_h
28#define ___iprt_nt_vid_h
29
30#include "hyperv.h"
31
32
33/**
34 * Output from VidMessageSlotMap.
35 */
36typedef struct VID_MAPPED_MESSAGE_SLOT
37{
38 /** The message block mapping. */
39 struct _HV_MESSAGE *pMsgBlock;
40 /** Copy of input iCpu. */
41 uint32_t iCpu;
42 /** Explicit padding. */
43 uint32_t uParentAdvisory;
44} VID_MAPPED_MESSAGE_SLOT;
45/** Pointer to VidMessageSlotMap output structure. */
46typedef VID_MAPPED_MESSAGE_SLOT *PVID_MAPPED_MESSAGE_SLOT;
47
48
49/** @name VID_MESSAGE_MAPPING_HEADER::enmVidMsgType values (wild guess).
50 * @{ */
51/** Type mask, strips flags. */
52#define VID_MESSAGE_TYPE_MASK UINT32_C(0x00ffffff)
53/** No return message necessary. */
54#define VID_MESSAGE_TYPE_FLAG_NO_RETURN UINT32_C(0x01000000)
55/** Observed message values. */
56typedef enum
57{
58 /** Invalid zero value. */
59 VidMessageInvalid = 0,
60 /** Guessing this means a message from the hypervisor. */
61 VidMessageHypervisorMessage = 0x00000c | VID_MESSAGE_TYPE_FLAG_NO_RETURN,
62 /** Guessing this means stop request completed. Message length is 1 byte. */
63 VidMessageStopRequestComplete = 0x00000d | VID_MESSAGE_TYPE_FLAG_NO_RETURN,
64} VID_MESSAGE_TYPE;
65AssertCompileSize(VID_MESSAGE_TYPE, 4);
66/** @} */
67
68/**
69 * Header of the message mapping returned by VidMessageSlotMap.
70 */
71typedef struct VID_MESSAGE_MAPPING_HEADER
72{
73 /** Current guess is that this is VID_MESSAGE_TYPE. */
74 VID_MESSAGE_TYPE enmVidMsgType;
75 /** The message size or so it seems (0x100). */
76 uint32_t cbMessage;
77 /** So far these have been zero. */
78 uint32_t aZeroPPadding[2+4];
79} VID_MESSAGE_MAPPING_HEADER;
80AssertCompileSize(VID_MESSAGE_MAPPING_HEADER, 32);
81
82/**
83 * VID processor status (VidGetVirtualProcessorRunningStatus).
84 *
85 * @note This is used internally in VID.SYS, in 17101 it's at offset 8 in their
86 * 'pVCpu' structure.
87 */
88typedef enum
89{
90 VidProcessorStatusStopped = 0,
91 VidProcessorStatusRunning,
92 VidProcessorStatusSuspended,
93 VidProcessorStatusUndefined = 0xffff
94} VID_PROCESSOR_STATUS;
95AssertCompileSize(VID_PROCESSOR_STATUS, 4);
96
97
98/** I/O control input for VidMessageSlotHandleAndGetNext. */
99typedef struct VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT
100{
101 HV_VP_INDEX iCpu;
102 uint32_t fFlags; /**< VID_MSHAGN_F_GET_XXX*/
103 uint32_t cMillies; /**< Not present in build 17758 as the API changed to always to infinite waits. */
104} VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT;
105/** Pointer to input for VidMessageSlotHandleAndGetNext. */
106typedef VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT *PVID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT;
107/** Pointer to const input for VidMessageSlotHandleAndGetNext. */
108typedef VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT const *PCVID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT;
109
110/** @name VID_MSHAGN_F_GET_XXX - Flags for VidMessageSlotHandleAndGetNext
111 * @{ */
112/** This will try get the next message, waiting if necessary.
113 * It is subject to NtAlertThread processing when it starts waiting. */
114#define VID_MSHAGN_F_GET_NEXT_MESSAGE RT_BIT_32(0)
115/** ACK the message as handled and resume execution/whatever.
116 * This is executed before VID_MSHAGN_F_GET_NEXT_MESSAGE and should not be
117 * subject to NtAlertThread side effects. */
118#define VID_MSHAGN_F_HANDLE_MESSAGE RT_BIT_32(1)
119/** Cancel VP execution (no other bit set).
120 * @since about build 17758. */
121#define VID_MSHAGN_F_CANCEL RT_BIT_32(2)
122/** @} */
123
124
125#ifdef IN_RING3
126RT_C_DECLS_BEGIN
127
128/** Calling convention. */
129#ifndef WINAPI
130# define VIDAPI __stdcall
131#else
132# define VIDAPI WINAPI
133#endif
134
135/** Partition handle. */
136#ifndef WINAPI
137typedef void *VID_PARTITION_HANDLE;
138#else
139typedef HANDLE VID_PARTITION_HANDLE;
140#endif
141
142/**
143 * Gets the partition ID.
144 *
145 * The partition ID is the numeric identifier used when making hypercalls to the
146 * hypervisor.
147 */
148DECLIMPORT(BOOL) VIDAPI VidGetHvPartitionId(VID_PARTITION_HANDLE hPartition, HV_PARTITION_ID *pidPartition);
149
150/**
151 * Starts asynchronous execution of a virtual CPU.
152 */
153DECLIMPORT(BOOL) VIDAPI VidStartVirtualProcessor(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu);
154
155/**
156 * Stops the asynchronous execution of a virtual CPU.
157 *
158 * @retval ERROR_VID_STOP_PENDING if busy with intercept, check messages.
159 */
160DECLIMPORT(BOOL) VIDAPI VidStopVirtualProcessor(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu);
161
162/**
163 * WHvCreateVirtualProcessor boils down to a call to VidMessageSlotMap and
164 * some internal WinHvPlatform state fiddling.
165 *
166 * Looks like it maps memory and returns the pointer to it.
167 * VidMessageSlotHandleAndGetNext is later used to wait for the next message and
168 * put (??) it into that memory mapping.
169 *
170 * @returns Success indicator (details in LastErrorValue).
171 *
172 * @param hPartition The partition handle.
173 * @param pOutput Where to return the pointer to the message memory
174 * mapping. The CPU index is also returned here.
175 * @param iCpu The CPU to wait-and-get messages for.
176 */
177DECLIMPORT(BOOL) VIDAPI VidMessageSlotMap(VID_PARTITION_HANDLE hPartition, PVID_MAPPED_MESSAGE_SLOT pOutput, HV_VP_INDEX iCpu);
178
179/**
180 * This is used by WHvRunVirtualProcessor to wait for the next exit msg.
181 *
182 * The message appears in the memory mapping returned by VidMessageSlotMap.
183 *
184 * @returns Success indicator (details only in LastErrorValue - LastStatusValue
185 * is not set).
186 * @retval STATUS_TIMEOUT for STATUS_TIMEOUT as well as STATUS_USER_APC and
187 * STATUS_ALERTED.
188 *
189 * @param hPartition The partition handle.
190 * @param iCpu The CPU to wait-and-get messages for.
191 * @param fFlags Flags, VID_MSHAGN_F_XXX.
192 *
193 * When starting or resuming execution, at least one of
194 * VID_MSHAGN_F_GET_NEXT_MESSAGE (bit 0) and
195 * VID_MSHAGN_F_HANDLE_MESSAGE (bit 1) must be set.
196 *
197 * When cancelling execution only VID_MSHAGN_F_CANCEL (big 2)
198 * must be set.
199 *
200 * @param cMillies The timeout, presumably in milliseconds. This parameter
201 * was dropped about build 17758.
202 *
203 * @todo Would be awfully nice if someone at Microsoft could hit at the
204 * flags here.
205 */
206DECLIMPORT(BOOL) VIDAPI VidMessageSlotHandleAndGetNext(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
207 uint32_t fFlags, uint32_t cMillies);
208/**
209 * Gets the processor running status.
210 *
211 * This is probably only available in special builds, as one of the early I/O
212 * control dispatching routines will not let it thru. Lower down routines does
213 * implement it, so it's possible to patch it into working. This works for
214 * build 17101: eb vid+12180 0f 84 98 00 00 00
215 *
216 * @retval ERROR_NOT_IMPLEMENTED
217 *
218 * @remarks VidExoFastIoControlPartition probably disapproves of this too. It
219 * could be very handy for debugging upon occation.
220 */
221DECLIMPORT(BOOL) VIDAPI VidGetVirtualProcessorRunningStatus(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
222 VID_PROCESSOR_STATUS *penmStatus);
223
224/**
225 * For query virtual processor registers and other state information.
226 *
227 * @returns Success indicator (details in LastErrorValue).
228 */
229DECLIMPORT(BOOL) VIDAPI VidGetVirtualProcessorState(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
230 HV_REGISTER_NAME const *paRegNames, uint32_t cRegisters,
231 HV_REGISTER_VALUE *paRegValues);
232
233/**
234 * For setting virtual processor registers and other state information.
235 *
236 * @returns Success indicator (details in LastErrorValue).
237 */
238DECLIMPORT(BOOL) VIDAPI VidSetVirtualProcessorState(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
239 HV_REGISTER_NAME const *paRegNames, uint32_t cRegisters,
240 HV_REGISTER_VALUE const *paRegValues);
241
242/**
243 * Wrapper around the HvCallGetMemoryBalance hypercall.
244 *
245 * When VID.SYS processes the request, it will also query
246 * HvPartitionPropertyVirtualTlbPageCount, so we're passing a 3rd return
247 * parameter in case the API is ever extended to match the I/O control.
248 *
249 * @returns Success indicator (details in LastErrorValue).
250 * @retval ERROR_NOT_IMPLEMENTED for exo partitions.
251 *
252 * @param hPartition The partition handle.
253 * @param pcPagesAvailable Where to return the number of unused pages
254 * still available to the partition.
255 * @param pcPagesInUse Where to return the number of pages currently
256 * in use by the partition.
257 * @param pReserved Pointer to dummy value, just in case they
258 * modify the API to include the nested TLB size.
259 *
260 * @note Not available for exo partitions, unfortunately. The
261 * VidExoFastIoControlPartition function deflects it, failing it with
262 * STATUS_NOT_IMPLEMENTED / ERROR_NOT_IMPLEMENTED.
263 */
264DECLIMPORT(BOOL) VIDAPI VidGetHvMemoryBalance(VID_PARTITION_HANDLE hPartition, uint64_t *pcPagesAvailable,
265 uint64_t *pcPagesInUse, uint64_t *pReserved);
266
267RT_C_DECLS_END
268#endif /* IN_RING3 */
269
270#endif
271
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