1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox Guest/VMM/host communication:
|
---|
4 | * Virtual communication device
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | /* #define LOG_ENABLED */
|
---|
20 |
|
---|
21 | /* Enable dev_vmm Log3 statements to get IRQ-related logging. */
|
---|
22 |
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <string.h>
|
---|
25 |
|
---|
26 | #define LOG_GROUP LOG_GROUP_DEV_VMM
|
---|
27 | #include <VBox/log.h>
|
---|
28 |
|
---|
29 | #include <VBox/VBoxDev.h>
|
---|
30 | #include <VBox/VBoxGuest.h>
|
---|
31 | #include <VBox/param.h>
|
---|
32 | #include <VBox/mm.h>
|
---|
33 | #include <VBox/pgm.h>
|
---|
34 | #include <VBox/err.h>
|
---|
35 | #include <VBox/vm.h> /* for VM_IS_EMT */
|
---|
36 |
|
---|
37 | #include <iprt/assert.h>
|
---|
38 | #include <iprt/time.h>
|
---|
39 | #ifndef IN_GC
|
---|
40 | #include <iprt/mem.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include "VMMDevState.h"
|
---|
44 |
|
---|
45 | #ifdef VBOX_HGCM
|
---|
46 | #include "VMMDevHGCM.h"
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | #define PCIDEV_2_VMMDEVSTATE(pPciDev) ( (VMMDevState *)(pPciDev) )
|
---|
50 | #define VMMDEVSTATE_2_DEVINS(pVMMDevState) ( (pVMMDevState)->pDevIns )
|
---|
51 |
|
---|
52 | #define VBOX_GUEST_ADDITIONS_VERSION_1_03(s) \
|
---|
53 | ((RT_HIWORD ((s)->guestInfo.additionsVersion) == 1) && \
|
---|
54 | (RT_LOWORD ((s)->guestInfo.additionsVersion) == 3))
|
---|
55 |
|
---|
56 | #define VBOX_GUEST_ADDITIONS_VERSION_OK(additionsVersion) \
|
---|
57 | (RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
|
---|
58 | && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION))
|
---|
59 |
|
---|
60 | #define VBOX_GUEST_ADDITIONS_VERSION_OLD(additionsVersion) \
|
---|
61 | ((RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) \
|
---|
62 | || ((RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
|
---|
63 | && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION))
|
---|
64 |
|
---|
65 | #define VBOX_GUEST_ADDITIONS_VERSION_TOO_OLD(additionsVersion) \
|
---|
66 | (RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION))
|
---|
67 |
|
---|
68 | #define VBOX_GUEST_ADDITIONS_VERSION_NEW(additionsVersion) \
|
---|
69 | ((RT_HIWORD(additionsVersion) > RT_HIWORD(VMMDEV_VERSION) \
|
---|
70 | || ((RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
|
---|
71 | && RT_LOWORD(additionsVersion) > RT_LOWORD(VMMDEV_VERSION))
|
---|
72 |
|
---|
73 | #ifndef VBOX_DEVICE_STRUCT_TESTCASE
|
---|
74 |
|
---|
75 | /* Whenever host wants to inform guest about something
|
---|
76 | * an IRQ notification will be raised.
|
---|
77 | *
|
---|
78 | * VMMDev PDM interface will contain the guest notification method.
|
---|
79 | *
|
---|
80 | * There is a 32 bit event mask which will be read
|
---|
81 | * by guest on an interrupt. A non zero bit in the mask
|
---|
82 | * means that the specific event occured and requires
|
---|
83 | * processing on guest side.
|
---|
84 | *
|
---|
85 | * After reading the event mask guest must issue a
|
---|
86 | * generic request AcknowlegdeEvents.
|
---|
87 | *
|
---|
88 | * IRQ line is set to 1 (request) if there are unprocessed
|
---|
89 | * events, that is the event mask is not zero.
|
---|
90 | *
|
---|
91 | * After receiving an interrupt and checking event mask,
|
---|
92 | * the guest must process events using the event specific
|
---|
93 | * mechanism.
|
---|
94 | *
|
---|
95 | * That is if mouse capabilities were changed,
|
---|
96 | * guest will use VMMDev_GetMouseStatus generic request.
|
---|
97 | *
|
---|
98 | * Event mask is only a set of flags indicating that guest
|
---|
99 | * must proceed with a procedure.
|
---|
100 | *
|
---|
101 | * Unsupported events are therefore ignored.
|
---|
102 | * The guest additions must inform host which events they
|
---|
103 | * want to receive, to avoid unnecessary IRQ processing.
|
---|
104 | * By default no events are signalled to guest.
|
---|
105 | *
|
---|
106 | * This seems to be fast method. It requires
|
---|
107 | * only one context switch for an event processing.
|
---|
108 | *
|
---|
109 | */
|
---|
110 |
|
---|
111 | static void vmmdevSetIRQ_Legacy_EMT (VMMDevState *pVMMDevState)
|
---|
112 | {
|
---|
113 | if (!pVMMDevState->fu32AdditionsOk)
|
---|
114 | {
|
---|
115 | Log(("vmmdevSetIRQ: IRQ is not generated, guest has not yet reported to us.\n"));
|
---|
116 | return;
|
---|
117 | }
|
---|
118 |
|
---|
119 | uint32_t u32IRQLevel = 0;
|
---|
120 |
|
---|
121 | /* Filter unsupported events */
|
---|
122 | uint32_t u32EventFlags =
|
---|
123 | pVMMDevState->u32HostEventFlags
|
---|
124 | & pVMMDevState->pVMMDevRAMHC->V.V1_03.u32GuestEventMask;
|
---|
125 |
|
---|
126 | Log(("vmmdevSetIRQ: u32EventFlags = 0x%08X, "
|
---|
127 | "pVMMDevState->u32HostEventFlags = 0x%08X, "
|
---|
128 | "pVMMDevState->pVMMDevRAMHC->u32GuestEventMask = 0x%08X\n",
|
---|
129 | u32EventFlags,
|
---|
130 | pVMMDevState->u32HostEventFlags,
|
---|
131 | pVMMDevState->pVMMDevRAMHC->V.V1_03.u32GuestEventMask));
|
---|
132 |
|
---|
133 | /* Move event flags to VMMDev RAM */
|
---|
134 | pVMMDevState->pVMMDevRAMHC->V.V1_03.u32HostEvents = u32EventFlags;
|
---|
135 |
|
---|
136 | if (u32EventFlags)
|
---|
137 | {
|
---|
138 | /* Clear host flags which will be delivered to guest. */
|
---|
139 | pVMMDevState->u32HostEventFlags &= ~u32EventFlags;
|
---|
140 | Log(("vmmdevSetIRQ: pVMMDevState->u32HostEventFlags = 0x%08X\n",
|
---|
141 | pVMMDevState->u32HostEventFlags));
|
---|
142 | u32IRQLevel = 1;
|
---|
143 | }
|
---|
144 |
|
---|
145 | /* Set IRQ level for pin 0 */
|
---|
146 | /** @todo make IRQ pin configurable, at least a symbolic constant */
|
---|
147 | PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
|
---|
148 | PDMDevHlpPCISetIrqNoWait(pDevIns, 0, u32IRQLevel);
|
---|
149 | Log(("vmmdevSetIRQ: IRQ set %d\n", u32IRQLevel));
|
---|
150 | }
|
---|
151 |
|
---|
152 | static void vmmdevMaybeSetIRQ_EMT (VMMDevState *pVMMDevState)
|
---|
153 | {
|
---|
154 | PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS (pVMMDevState);
|
---|
155 |
|
---|
156 | Log3(("vmmdevMaybeSetIRQ_EMT: u32HostEventFlags = 0x%08X, u32GuestFilterMask = 0x%08X.\n",
|
---|
157 | pVMMDevState->u32HostEventFlags, pVMMDevState->u32GuestFilterMask));
|
---|
158 |
|
---|
159 | if (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask)
|
---|
160 | {
|
---|
161 | pVMMDevState->pVMMDevRAMHC->V.V1_04.fHaveEvents = true;
|
---|
162 | PDMDevHlpPCISetIrqNoWait (pDevIns, 0, 1);
|
---|
163 | Log3(("vmmdevMaybeSetIRQ_EMT: IRQ set.\n"));
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | static void vmmdevNotifyGuest_EMT (VMMDevState *pVMMDevState, uint32_t u32EventMask)
|
---|
168 | {
|
---|
169 | Log3(("VMMDevNotifyGuest_EMT: u32EventMask = 0x%08X.\n", u32EventMask));
|
---|
170 |
|
---|
171 | if (VBOX_GUEST_ADDITIONS_VERSION_1_03 (pVMMDevState))
|
---|
172 | {
|
---|
173 | Log3(("VMMDevNotifyGuest_EMT: Old additions detected.\n"));
|
---|
174 |
|
---|
175 | pVMMDevState->u32HostEventFlags |= u32EventMask;
|
---|
176 | vmmdevSetIRQ_Legacy_EMT (pVMMDevState);
|
---|
177 | }
|
---|
178 | else
|
---|
179 | {
|
---|
180 | Log3(("VMMDevNotifyGuest_EMT: New additions detected.\n"));
|
---|
181 |
|
---|
182 | if (!pVMMDevState->fu32AdditionsOk)
|
---|
183 | {
|
---|
184 | pVMMDevState->u32HostEventFlags |= u32EventMask;
|
---|
185 | Log(("vmmdevNotifyGuest_EMT: IRQ is not generated, guest has not yet reported to us.\n"));
|
---|
186 | return;
|
---|
187 | }
|
---|
188 |
|
---|
189 | const bool fHadEvents =
|
---|
190 | (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask) != 0;
|
---|
191 |
|
---|
192 | Log3(("VMMDevNotifyGuest_EMT: fHadEvents = %d, u32HostEventFlags = 0x%08X, u32GuestFilterMask = 0x%08X.\n",
|
---|
193 | fHadEvents, pVMMDevState->u32HostEventFlags, pVMMDevState->u32GuestFilterMask));
|
---|
194 |
|
---|
195 | pVMMDevState->u32HostEventFlags |= u32EventMask;
|
---|
196 |
|
---|
197 | if (!fHadEvents)
|
---|
198 | vmmdevMaybeSetIRQ_EMT (pVMMDevState);
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | static void vmmdevCtlGuestFilterMask_EMT (VMMDevState *pVMMDevState,
|
---|
203 | uint32_t u32OrMask,
|
---|
204 | uint32_t u32NotMask)
|
---|
205 | {
|
---|
206 | const bool fHadEvents =
|
---|
207 | (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask) != 0;
|
---|
208 |
|
---|
209 | Log(("vmmdevCtlGuestFilterMask_EMT: u32OrMask = 0x%08X, u32NotMask = 0x%08X, fHadEvents = %d.\n", u32OrMask, u32NotMask, fHadEvents));
|
---|
210 | if (fHadEvents)
|
---|
211 | {
|
---|
212 | if (!pVMMDevState->fNewGuestFilterMask)
|
---|
213 | pVMMDevState->u32NewGuestFilterMask = pVMMDevState->u32GuestFilterMask;
|
---|
214 |
|
---|
215 | pVMMDevState->u32NewGuestFilterMask |= u32OrMask;
|
---|
216 | pVMMDevState->u32NewGuestFilterMask &= ~u32NotMask;
|
---|
217 | pVMMDevState->fNewGuestFilterMask = true;
|
---|
218 | }
|
---|
219 | else
|
---|
220 | {
|
---|
221 | pVMMDevState->u32GuestFilterMask |= u32OrMask;
|
---|
222 | pVMMDevState->u32GuestFilterMask &= ~u32NotMask;
|
---|
223 | vmmdevMaybeSetIRQ_EMT (pVMMDevState);
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | void VMMDevCtlSetGuestFilterMask (VMMDevState *pVMMDevState,
|
---|
228 | uint32_t u32OrMask,
|
---|
229 | uint32_t u32NotMask)
|
---|
230 | {
|
---|
231 | PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
|
---|
232 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
233 |
|
---|
234 | Log(("VMMDevCtlSetGuestFilterMask: u32OrMask = 0x%08X, u32NotMask = 0x%08X.\n", u32OrMask, u32NotMask));
|
---|
235 |
|
---|
236 | if (VM_IS_EMT(pVM))
|
---|
237 | {
|
---|
238 | vmmdevCtlGuestFilterMask_EMT (pVMMDevState, u32OrMask, u32NotMask);
|
---|
239 | }
|
---|
240 | else
|
---|
241 | {
|
---|
242 | int rc;
|
---|
243 | PVMREQ pReq;
|
---|
244 |
|
---|
245 | rc = VMR3ReqCallVoid (pVM, &pReq, RT_INDEFINITE_WAIT,
|
---|
246 | (PFNRT) vmmdevCtlGuestFilterMask_EMT,
|
---|
247 | 3, pVMMDevState, u32OrMask, u32NotMask);
|
---|
248 | AssertReleaseRC (rc);
|
---|
249 | VMR3ReqFree (pReq);
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 | void VMMDevNotifyGuest (VMMDevState *pVMMDevState, uint32_t u32EventMask)
|
---|
254 | {
|
---|
255 | PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
|
---|
256 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
257 | int rc;
|
---|
258 | PVMREQ pReq;
|
---|
259 |
|
---|
260 | Log3(("VMMDevNotifyGuest: u32EventMask = 0x%08X.\n", u32EventMask));
|
---|
261 |
|
---|
262 | rc = VMR3ReqCallVoid (pVM, &pReq, RT_INDEFINITE_WAIT,
|
---|
263 | (PFNRT) vmmdevNotifyGuest_EMT,
|
---|
264 | 2, pVMMDevState, u32EventMask);
|
---|
265 | AssertReleaseRC (rc);
|
---|
266 | VMR3ReqFree (pReq);
|
---|
267 | }
|
---|
268 |
|
---|
269 | /**
|
---|
270 | * Port I/O Handler for OUT operations.
|
---|
271 | *
|
---|
272 | * @returns VBox status code.
|
---|
273 | *
|
---|
274 | * @param pDevIns The device instance.
|
---|
275 | * @param pvUser User argument - ignored.
|
---|
276 | * @param uPort Port number used for the IN operation.
|
---|
277 | * @param u32 The value to output.
|
---|
278 | * @param cb The value size in bytes.
|
---|
279 | */
|
---|
280 | #undef LOG_GROUP
|
---|
281 | #define LOG_GROUP LOG_GROUP_DEV_VMM_BACKDOOR
|
---|
282 |
|
---|
283 | static DECLCALLBACK(int) vmmdevBackdoorLog(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
|
---|
284 | {
|
---|
285 | VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState *);
|
---|
286 |
|
---|
287 | if (!pData->fBackdoorLogDisabled && cb == 1 && Port == RTLOG_DEBUG_PORT)
|
---|
288 | {
|
---|
289 |
|
---|
290 | /* The raw version. */
|
---|
291 | switch (u32)
|
---|
292 | {
|
---|
293 | case '\r': Log2(("vmmdev: <return>\n")); break;
|
---|
294 | case '\n': Log2(("vmmdev: <newline>\n")); break;
|
---|
295 | case '\t': Log2(("vmmdev: <tab>\n")); break;
|
---|
296 | default: Log2(("vmmdev: %c (%02x)\n", u32, u32)); break;
|
---|
297 | }
|
---|
298 |
|
---|
299 | /* The readable, buffered version. */
|
---|
300 | if (u32 == '\n' || u32 == '\r')
|
---|
301 | {
|
---|
302 | pData->szMsg[pData->iMsg] = '\0';
|
---|
303 | if (pData->iMsg)
|
---|
304 | LogRel(("Guest Log: %s\n", pData->szMsg));
|
---|
305 | pData->iMsg = 0;
|
---|
306 | }
|
---|
307 | else
|
---|
308 | {
|
---|
309 | if (pData->iMsg >= sizeof(pData->szMsg)-1)
|
---|
310 | {
|
---|
311 | pData->szMsg[pData->iMsg] = '\0';
|
---|
312 | LogRel(("Guest Log: %s\n", pData->szMsg));
|
---|
313 | pData->iMsg = 0;
|
---|
314 | }
|
---|
315 | pData->szMsg[pData->iMsg] = (char )u32;
|
---|
316 | pData->szMsg[++pData->iMsg] = '\0';
|
---|
317 | }
|
---|
318 | }
|
---|
319 | return VINF_SUCCESS;
|
---|
320 | }
|
---|
321 | #undef LOG_GROUP
|
---|
322 | #define LOG_GROUP LOG_GROUP_DEV_VMM
|
---|
323 |
|
---|
324 | #ifdef TIMESYNC_BACKDOOR
|
---|
325 | /**
|
---|
326 | * Port I/O Handler for OUT operations.
|
---|
327 | *
|
---|
328 | * @returns VBox status code.
|
---|
329 | *
|
---|
330 | * @param pDevIns The device instance.
|
---|
331 | * @param pvUser User argument - ignored.
|
---|
332 | * @param uPort Port number used for the IN operation.
|
---|
333 | * @param u32 The value to output.
|
---|
334 | * @param cb The value size in bytes.
|
---|
335 | */
|
---|
336 | static DECLCALLBACK(int) vmmdevTimesyncBackdoorWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
|
---|
337 | {
|
---|
338 | NOREF(pvUser);
|
---|
339 | if (cb == 4)
|
---|
340 | {
|
---|
341 | VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState *);
|
---|
342 | switch (u32)
|
---|
343 | {
|
---|
344 | case 0:
|
---|
345 | pData->fTimesyncBackdoorLo = false;
|
---|
346 | break;
|
---|
347 | case 1:
|
---|
348 | pData->fTimesyncBackdoorLo = true;
|
---|
349 | }
|
---|
350 | return VINF_SUCCESS;
|
---|
351 |
|
---|
352 | }
|
---|
353 | return VINF_SUCCESS;
|
---|
354 | }
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * Port I/O Handler for backdoor timesync IN operations.
|
---|
358 | *
|
---|
359 | * @returns VBox status code.
|
---|
360 | *
|
---|
361 | * @param pDevIns The device instance.
|
---|
362 | * @param pvUser User argument - ignored.
|
---|
363 | * @param uPort Port number used for the IN operation.
|
---|
364 | * @param pu32 Where to store the result.
|
---|
365 | * @param cb Number of bytes read.
|
---|
366 | */
|
---|
367 | static DECLCALLBACK(int) vmmdevTimesyncBackdoorRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
|
---|
368 | {
|
---|
369 | int rc;
|
---|
370 | NOREF(pvUser);
|
---|
371 | if (cb == 4)
|
---|
372 | {
|
---|
373 | VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState *);
|
---|
374 | RTTIMESPEC now;
|
---|
375 |
|
---|
376 | if (pData->fTimesyncBackdoorLo)
|
---|
377 | {
|
---|
378 | *pu32 = (uint32_t)(pData->hostTime & (uint64_t)0xFFFFFFFF);
|
---|
379 | }
|
---|
380 | else
|
---|
381 | {
|
---|
382 | pData->hostTime = RTTimeSpecGetMilli(PDMDevHlpUTCNow(pDevIns, &now));
|
---|
383 | *pu32 = (uint32_t)(pData->hostTime >> 32);
|
---|
384 | }
|
---|
385 | rc = VINF_SUCCESS;
|
---|
386 | }
|
---|
387 | else
|
---|
388 | rc = VERR_IOM_IOPORT_UNUSED;
|
---|
389 | return rc;
|
---|
390 | }
|
---|
391 | #endif /* TIMESYNC_BACKDOOR */
|
---|
392 |
|
---|
393 | /**
|
---|
394 | * Port I/O Handler for the generic request interface
|
---|
395 | * @see FNIOMIOPORTOUT for details.
|
---|
396 | */
|
---|
397 | static DECLCALLBACK(int) vmmdevRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
|
---|
398 | {
|
---|
399 | VMMDevState *pData = (VMMDevState*)pvUser;
|
---|
400 | int rcRet = VINF_SUCCESS;
|
---|
401 |
|
---|
402 | /*
|
---|
403 | * The caller has passed the guest context physical address
|
---|
404 | * of the request structure. Copy the request packet.
|
---|
405 | */
|
---|
406 | VMMDevRequestHeader requestHeader = {0};
|
---|
407 | VMMDevRequestHeader *pRequestHeader = NULL;
|
---|
408 |
|
---|
409 | PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
|
---|
410 |
|
---|
411 | /* the structure size must be greater or equal to the header size */
|
---|
412 | if (requestHeader.size < sizeof(VMMDevRequestHeader))
|
---|
413 | {
|
---|
414 | Log(("VMMDev request header size too small! size = %d\n", requestHeader.size));
|
---|
415 | rcRet = VINF_SUCCESS;
|
---|
416 | goto end;
|
---|
417 | }
|
---|
418 |
|
---|
419 | /* check the version of the header structure */
|
---|
420 | if (requestHeader.version != VMMDEV_REQUEST_HEADER_VERSION)
|
---|
421 | {
|
---|
422 | Log(("VMMDev: guest header version (0x%08X) differs from ours (0x%08X)\n", requestHeader.version, VMMDEV_REQUEST_HEADER_VERSION));
|
---|
423 | rcRet = VINF_SUCCESS;
|
---|
424 | goto end;
|
---|
425 | }
|
---|
426 |
|
---|
427 | Log2(("VMMDev request issued: %d\n", requestHeader.requestType));
|
---|
428 |
|
---|
429 | if ( requestHeader.requestType != VMMDevReq_ReportGuestInfo
|
---|
430 | && !pData->fu32AdditionsOk)
|
---|
431 | {
|
---|
432 | Log(("VMMDev: guest has not yet reported to us. Refusing operation.\n"));
|
---|
433 | requestHeader.rc = VERR_NOT_SUPPORTED;
|
---|
434 | rcRet = VINF_SUCCESS;
|
---|
435 | goto end;
|
---|
436 | }
|
---|
437 |
|
---|
438 | /* Check upper limit */
|
---|
439 | if (requestHeader.size > VMMDEV_MAX_VMMDEVREQ_SIZE)
|
---|
440 | {
|
---|
441 | LogRel(("VMMDev: request packet too big (%x). Refusing operation.\n", requestHeader.size));
|
---|
442 | requestHeader.rc = VERR_NOT_SUPPORTED;
|
---|
443 | rcRet = VINF_SUCCESS;
|
---|
444 | goto end;
|
---|
445 | }
|
---|
446 |
|
---|
447 | /* Read the entire request packet */
|
---|
448 | pRequestHeader = (VMMDevRequestHeader *)RTMemAlloc(requestHeader.size);
|
---|
449 | if (!pRequestHeader)
|
---|
450 | {
|
---|
451 | Log(("VMMDev: RTMemAlloc failed!\n"));
|
---|
452 | rcRet = VINF_SUCCESS;
|
---|
453 | requestHeader.rc = VERR_NO_MEMORY;
|
---|
454 | goto end;
|
---|
455 | }
|
---|
456 | PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, pRequestHeader, requestHeader.size);
|
---|
457 |
|
---|
458 | /* which request was sent? */
|
---|
459 | switch (pRequestHeader->requestType)
|
---|
460 | {
|
---|
461 | /*
|
---|
462 | * Guest wants to give up a timeslice
|
---|
463 | */
|
---|
464 | case VMMDevReq_Idle:
|
---|
465 | {
|
---|
466 | /* just return to EMT telling it that we want to halt */
|
---|
467 | rcRet = VINF_EM_HALT;
|
---|
468 | break;
|
---|
469 | }
|
---|
470 |
|
---|
471 | /*
|
---|
472 | * Guest is reporting its information
|
---|
473 | */
|
---|
474 | case VMMDevReq_ReportGuestInfo:
|
---|
475 | {
|
---|
476 | if (pRequestHeader->size < sizeof(VMMDevReportGuestInfo))
|
---|
477 | {
|
---|
478 | AssertMsgFailed(("VMMDev guest information structure has invalid size!\n"));
|
---|
479 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
480 | }
|
---|
481 | else
|
---|
482 | {
|
---|
483 | VMMDevReportGuestInfo *guestInfo = (VMMDevReportGuestInfo*)pRequestHeader;
|
---|
484 |
|
---|
485 | if (memcmp (&pData->guestInfo, &guestInfo->guestInfo, sizeof (guestInfo->guestInfo)) != 0)
|
---|
486 | {
|
---|
487 | /* make a copy of supplied information */
|
---|
488 | pData->guestInfo = guestInfo->guestInfo;
|
---|
489 |
|
---|
490 | /* Check additions version */
|
---|
491 | pData->fu32AdditionsOk = VBOX_GUEST_ADDITIONS_VERSION_OK(pData->guestInfo.additionsVersion);
|
---|
492 |
|
---|
493 | LogRel(("Guest Additions information report: additionsVersion = 0x%08X osType = 0x%08X\n",
|
---|
494 | pData->guestInfo.additionsVersion,
|
---|
495 | pData->guestInfo.osType));
|
---|
496 | pData->pDrv->pfnUpdateGuestVersion(pData->pDrv, &pData->guestInfo);
|
---|
497 | }
|
---|
498 |
|
---|
499 | if (pData->fu32AdditionsOk)
|
---|
500 | {
|
---|
501 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
502 | }
|
---|
503 | else
|
---|
504 | {
|
---|
505 | pRequestHeader->rc = VERR_VERSION_MISMATCH;
|
---|
506 | }
|
---|
507 | }
|
---|
508 | break;
|
---|
509 | }
|
---|
510 |
|
---|
511 | /* Report guest capabilities */
|
---|
512 | case VMMDevReq_ReportGuestCapabilities:
|
---|
513 | {
|
---|
514 | if (pRequestHeader->size != sizeof(VMMDevReqGuestCapabilities))
|
---|
515 | {
|
---|
516 | AssertMsgFailed(("VMMDev guest caps structure has invalid size!\n"));
|
---|
517 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
518 | }
|
---|
519 | else
|
---|
520 | {
|
---|
521 | VMMDevReqGuestCapabilities *guestCaps = (VMMDevReqGuestCapabilities*)pRequestHeader;
|
---|
522 |
|
---|
523 | if (pData->guestCaps != guestCaps->caps)
|
---|
524 | {
|
---|
525 | /* make a copy of supplied information */
|
---|
526 | pData->guestCaps = guestCaps->caps;
|
---|
527 |
|
---|
528 | LogRel(("Guest Additions capability report: (0x%x) "
|
---|
529 | "VMMDEV_GUEST_SUPPORTS_SEAMLESS: %s "
|
---|
530 | "VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING: %s\n",
|
---|
531 | guestCaps->caps,
|
---|
532 | guestCaps->caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
|
---|
533 | guestCaps->caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no"));
|
---|
534 |
|
---|
535 | pData->pDrv->pfnUpdateGuestCapabilities(pData->pDrv, guestCaps->caps);
|
---|
536 | }
|
---|
537 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
538 | }
|
---|
539 | break;
|
---|
540 | }
|
---|
541 |
|
---|
542 | /*
|
---|
543 | * Retrieve mouse information
|
---|
544 | */
|
---|
545 | case VMMDevReq_GetMouseStatus:
|
---|
546 | {
|
---|
547 | if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
|
---|
548 | {
|
---|
549 | AssertMsgFailed(("VMMDev mouse status structure has invalid size!\n"));
|
---|
550 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
551 | }
|
---|
552 | else
|
---|
553 | {
|
---|
554 | VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)pRequestHeader;
|
---|
555 | mouseStatus->mouseFeatures = 0;
|
---|
556 | if (pData->mouseCapabilities & VMMDEV_MOUSEHOSTWANTSABS)
|
---|
557 | {
|
---|
558 | mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_HOST_CAN_ABSOLUTE;
|
---|
559 | }
|
---|
560 | if (pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS)
|
---|
561 | {
|
---|
562 | mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE;
|
---|
563 | }
|
---|
564 | if (pData->mouseCapabilities & VMMDEV_MOUSEHOSTCANNOTHWPOINTER)
|
---|
565 | {
|
---|
566 | mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_HOST_CANNOT_HWPOINTER;
|
---|
567 | }
|
---|
568 | mouseStatus->pointerXPos = pData->mouseXAbs;
|
---|
569 | mouseStatus->pointerYPos = pData->mouseYAbs;
|
---|
570 | Log2(("returning mouse status: features = %d, absX = %d, absY = %d\n", mouseStatus->mouseFeatures,
|
---|
571 | mouseStatus->pointerXPos, mouseStatus->pointerYPos));
|
---|
572 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
573 | }
|
---|
574 | break;
|
---|
575 | }
|
---|
576 |
|
---|
577 | /*
|
---|
578 | * Set mouse information
|
---|
579 | */
|
---|
580 | case VMMDevReq_SetMouseStatus:
|
---|
581 | {
|
---|
582 | if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
|
---|
583 | {
|
---|
584 | AssertMsgFailed(("VMMDev mouse status structure has invalid size %d (%#x) version=%d!\n",
|
---|
585 | pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
|
---|
586 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
587 | }
|
---|
588 | else
|
---|
589 | {
|
---|
590 | bool bCapsChanged = false;
|
---|
591 |
|
---|
592 | VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)pRequestHeader;
|
---|
593 |
|
---|
594 | /* check if the guest wants absolute coordinates */
|
---|
595 | if (mouseStatus->mouseFeatures & VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE)
|
---|
596 | {
|
---|
597 | /* set the capability flag and the changed flag if it's actually a change */
|
---|
598 | if (!(pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS))
|
---|
599 | {
|
---|
600 | pData->mouseCapabilities |= VMMDEV_MOUSEGUESTWANTSABS;
|
---|
601 | bCapsChanged = true;
|
---|
602 | LogRel(("Guest requests mouse pointer integration\n"));
|
---|
603 | }
|
---|
604 | } else
|
---|
605 | {
|
---|
606 | if (pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS)
|
---|
607 | {
|
---|
608 | pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTWANTSABS;
|
---|
609 | bCapsChanged = true;
|
---|
610 | LogRel(("Guest disables mouse pointer integration\n"));
|
---|
611 | }
|
---|
612 | }
|
---|
613 | if (mouseStatus->mouseFeatures & VBOXGUEST_MOUSE_GUEST_NEEDS_HOST_CURSOR)
|
---|
614 | pData->mouseCapabilities |= VMMDEV_MOUSEGUESTNEEDSHOSTCUR;
|
---|
615 | else
|
---|
616 | pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTNEEDSHOSTCUR;
|
---|
617 |
|
---|
618 | /*
|
---|
619 | * Notify connector if something has changed
|
---|
620 | */
|
---|
621 | if (bCapsChanged)
|
---|
622 | {
|
---|
623 | Log(("VMMDevReq_SetMouseStatus: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
|
---|
624 | pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
|
---|
625 | }
|
---|
626 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
627 | }
|
---|
628 |
|
---|
629 | break;
|
---|
630 | }
|
---|
631 |
|
---|
632 | /*
|
---|
633 | * Set a new mouse pointer shape
|
---|
634 | */
|
---|
635 | case VMMDevReq_SetPointerShape:
|
---|
636 | {
|
---|
637 | if (pRequestHeader->size < sizeof(VMMDevReqMousePointer))
|
---|
638 | {
|
---|
639 | AssertMsg(pRequestHeader->size == 0x10028 && pRequestHeader->version == 10000, /* don't bitch about legacy!!! */
|
---|
640 | ("VMMDev mouse shape structure has invalid size %d (%#x) version=%d!\n",
|
---|
641 | pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
|
---|
642 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
643 | }
|
---|
644 | else
|
---|
645 | {
|
---|
646 | VMMDevReqMousePointer *pointerShape = (VMMDevReqMousePointer*)pRequestHeader;
|
---|
647 |
|
---|
648 | bool fVisible = (pointerShape->fFlags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
|
---|
649 | bool fAlpha = (pointerShape->fFlags & VBOX_MOUSE_POINTER_ALPHA) != 0;
|
---|
650 | bool fShape = (pointerShape->fFlags & VBOX_MOUSE_POINTER_SHAPE) != 0;
|
---|
651 |
|
---|
652 | Log(("VMMDevReq_SetPointerShape: visible: %d, alpha: %d, shape = %d, width: %d, height: %d\n",
|
---|
653 | fVisible, fAlpha, fShape, pointerShape->width, pointerShape->height));
|
---|
654 |
|
---|
655 | if (pRequestHeader->size == sizeof(VMMDevReqMousePointer))
|
---|
656 | {
|
---|
657 | /* The guest did not provide the shape actually. */
|
---|
658 | fShape = false;
|
---|
659 | }
|
---|
660 |
|
---|
661 | /* forward call to driver */
|
---|
662 | if (fShape)
|
---|
663 | {
|
---|
664 | pData->pDrv->pfnUpdatePointerShape(pData->pDrv,
|
---|
665 | fVisible,
|
---|
666 | fAlpha,
|
---|
667 | pointerShape->xHot, pointerShape->yHot,
|
---|
668 | pointerShape->width, pointerShape->height,
|
---|
669 | pointerShape->pointerData);
|
---|
670 | }
|
---|
671 | else
|
---|
672 | {
|
---|
673 | pData->pDrv->pfnUpdatePointerShape(pData->pDrv,
|
---|
674 | fVisible,
|
---|
675 | 0,
|
---|
676 | 0, 0,
|
---|
677 | 0, 0,
|
---|
678 | NULL);
|
---|
679 | }
|
---|
680 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
681 | }
|
---|
682 | break;
|
---|
683 | }
|
---|
684 |
|
---|
685 | /*
|
---|
686 | * Query the system time from the host
|
---|
687 | */
|
---|
688 | case VMMDevReq_GetHostTime:
|
---|
689 | {
|
---|
690 | if (pRequestHeader->size != sizeof(VMMDevReqHostTime))
|
---|
691 | {
|
---|
692 | AssertMsgFailed(("VMMDev host time structure has invalid size!\n"));
|
---|
693 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
694 | }
|
---|
695 | else if (RT_UNLIKELY(pData->fGetHostTimeDisabled))
|
---|
696 | pRequestHeader->rc = VERR_NOT_SUPPORTED;
|
---|
697 | else
|
---|
698 | {
|
---|
699 | VMMDevReqHostTime *hostTimeReq = (VMMDevReqHostTime*)pRequestHeader;
|
---|
700 | RTTIMESPEC now;
|
---|
701 | hostTimeReq->time = RTTimeSpecGetMilli(PDMDevHlpUTCNow(pDevIns, &now));
|
---|
702 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
703 | }
|
---|
704 | break;
|
---|
705 | }
|
---|
706 |
|
---|
707 | /*
|
---|
708 | * Query information about the hypervisor
|
---|
709 | */
|
---|
710 | case VMMDevReq_GetHypervisorInfo:
|
---|
711 | {
|
---|
712 | if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
|
---|
713 | {
|
---|
714 | AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
|
---|
715 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
716 | }
|
---|
717 | else
|
---|
718 | {
|
---|
719 | VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
|
---|
720 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
721 | pRequestHeader->rc = PGMR3MappingsSize(pVM, &hypervisorInfo->hypervisorSize);
|
---|
722 | }
|
---|
723 | break;
|
---|
724 | }
|
---|
725 |
|
---|
726 | /*
|
---|
727 | * Set hypervisor information
|
---|
728 | */
|
---|
729 | case VMMDevReq_SetHypervisorInfo:
|
---|
730 | {
|
---|
731 | if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
|
---|
732 | {
|
---|
733 | AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
|
---|
734 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
735 | }
|
---|
736 | else
|
---|
737 | {
|
---|
738 | VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
|
---|
739 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
740 | if (hypervisorInfo->hypervisorStart == 0)
|
---|
741 | pRequestHeader->rc = PGMR3MappingsUnfix(pVM);
|
---|
742 | else
|
---|
743 | {
|
---|
744 | /* only if the client has queried the size before! */
|
---|
745 | uint32_t mappingsSize;
|
---|
746 | pRequestHeader->rc = PGMR3MappingsSize(pVM, &mappingsSize);
|
---|
747 | if (VBOX_SUCCESS(pRequestHeader->rc) && hypervisorInfo->hypervisorSize == mappingsSize)
|
---|
748 | {
|
---|
749 | /* new reservation */
|
---|
750 | pRequestHeader->rc = PGMR3MappingsFix(pVM, hypervisorInfo->hypervisorStart,
|
---|
751 | hypervisorInfo->hypervisorSize);
|
---|
752 | LogRel(("Guest reported fixed hypervisor window at 0x%p (size = 0x%x, rc = %Vrc)\n",
|
---|
753 | hypervisorInfo->hypervisorStart,
|
---|
754 | hypervisorInfo->hypervisorSize,
|
---|
755 | pRequestHeader->rc));
|
---|
756 | }
|
---|
757 | }
|
---|
758 | }
|
---|
759 | break;
|
---|
760 | }
|
---|
761 |
|
---|
762 | /*
|
---|
763 | * Set the system power status
|
---|
764 | */
|
---|
765 | case VMMDevReq_SetPowerStatus:
|
---|
766 | {
|
---|
767 | if (pRequestHeader->size != sizeof(VMMDevPowerStateRequest))
|
---|
768 | {
|
---|
769 | AssertMsgFailed(("VMMDev power state request structure has invalid size!\n"));
|
---|
770 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
771 | }
|
---|
772 | else
|
---|
773 | {
|
---|
774 | VMMDevPowerStateRequest *powerStateRequest = (VMMDevPowerStateRequest*)pRequestHeader;
|
---|
775 | switch(powerStateRequest->powerState)
|
---|
776 | {
|
---|
777 | case VMMDevPowerState_Pause:
|
---|
778 | {
|
---|
779 | LogRel(("Guest requests the VM to be suspended (paused)\n"));
|
---|
780 | pRequestHeader->rc = rcRet = PDMDevHlpVMSuspend(pDevIns);
|
---|
781 | break;
|
---|
782 | }
|
---|
783 |
|
---|
784 | case VMMDevPowerState_PowerOff:
|
---|
785 | {
|
---|
786 | LogRel(("Guest requests the VM to be turned off\n"));
|
---|
787 | pRequestHeader->rc = rcRet = PDMDevHlpVMPowerOff(pDevIns);
|
---|
788 | break;
|
---|
789 | }
|
---|
790 |
|
---|
791 | case VMMDevPowerState_SaveState:
|
---|
792 | {
|
---|
793 | /** @todo no API for that yet */
|
---|
794 | pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
|
---|
795 | break;
|
---|
796 | }
|
---|
797 |
|
---|
798 | default:
|
---|
799 | AssertMsgFailed(("VMMDev invalid power state request: %d\n", powerStateRequest->powerState));
|
---|
800 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
801 | break;
|
---|
802 | }
|
---|
803 | }
|
---|
804 | break;
|
---|
805 | }
|
---|
806 |
|
---|
807 | /*
|
---|
808 | * Get display change request
|
---|
809 | */
|
---|
810 | case VMMDevReq_GetDisplayChangeRequest:
|
---|
811 | {
|
---|
812 | if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest))
|
---|
813 | {
|
---|
814 | /* Assert only if the size also not equal to a previous version size to prevent
|
---|
815 | * assertion with old additions.
|
---|
816 | */
|
---|
817 | AssertMsg(pRequestHeader->size == sizeof(VMMDevDisplayChangeRequest) - sizeof (uint32_t),
|
---|
818 | ("VMMDev display change request structure has invalid size!\n"));
|
---|
819 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
820 | }
|
---|
821 | else
|
---|
822 | {
|
---|
823 | VMMDevDisplayChangeRequest *displayChangeRequest = (VMMDevDisplayChangeRequest*)pRequestHeader;
|
---|
824 | /* just pass on the information */
|
---|
825 | Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d\n",
|
---|
826 | pData->displayChangeRequest.xres, pData->displayChangeRequest.yres, pData->displayChangeRequest.bpp));
|
---|
827 | displayChangeRequest->xres = pData->displayChangeRequest.xres;
|
---|
828 | displayChangeRequest->yres = pData->displayChangeRequest.yres;
|
---|
829 | displayChangeRequest->bpp = pData->displayChangeRequest.bpp;
|
---|
830 |
|
---|
831 | if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
832 | {
|
---|
833 | /* Remember which resolution the client has queried. */
|
---|
834 | pData->lastReadDisplayChangeRequest = pData->displayChangeRequest;
|
---|
835 | }
|
---|
836 |
|
---|
837 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
838 | }
|
---|
839 | break;
|
---|
840 | }
|
---|
841 |
|
---|
842 | case VMMDevReq_GetDisplayChangeRequest2:
|
---|
843 | {
|
---|
844 | if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest2))
|
---|
845 | {
|
---|
846 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
847 | }
|
---|
848 | else
|
---|
849 | {
|
---|
850 | VMMDevDisplayChangeRequest2 *displayChangeRequest = (VMMDevDisplayChangeRequest2*)pRequestHeader;
|
---|
851 | /* just pass on the information */
|
---|
852 | Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d at %d\n",
|
---|
853 | pData->displayChangeRequest.xres, pData->displayChangeRequest.yres, pData->displayChangeRequest.bpp, pData->displayChangeRequest.display));
|
---|
854 | displayChangeRequest->xres = pData->displayChangeRequest.xres;
|
---|
855 | displayChangeRequest->yres = pData->displayChangeRequest.yres;
|
---|
856 | displayChangeRequest->bpp = pData->displayChangeRequest.bpp;
|
---|
857 | displayChangeRequest->display = pData->displayChangeRequest.display;
|
---|
858 |
|
---|
859 | if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
860 | {
|
---|
861 | /* Remember which resolution the client has queried. */
|
---|
862 | pData->lastReadDisplayChangeRequest = pData->displayChangeRequest;
|
---|
863 | }
|
---|
864 |
|
---|
865 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
866 | }
|
---|
867 | break;
|
---|
868 | }
|
---|
869 |
|
---|
870 | /*
|
---|
871 | * Query whether the given video mode is supported
|
---|
872 | */
|
---|
873 | case VMMDevReq_VideoModeSupported:
|
---|
874 | {
|
---|
875 | if (pRequestHeader->size != sizeof(VMMDevVideoModeSupportedRequest))
|
---|
876 | {
|
---|
877 | AssertMsgFailed(("VMMDev video mode supported request structure has invalid size!\n"));
|
---|
878 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
879 | }
|
---|
880 | else
|
---|
881 | {
|
---|
882 | VMMDevVideoModeSupportedRequest *videoModeSupportedRequest = (VMMDevVideoModeSupportedRequest*)pRequestHeader;
|
---|
883 | /* forward the call */
|
---|
884 | pRequestHeader->rc = pData->pDrv->pfnVideoModeSupported(pData->pDrv,
|
---|
885 | videoModeSupportedRequest->width,
|
---|
886 | videoModeSupportedRequest->height,
|
---|
887 | videoModeSupportedRequest->bpp,
|
---|
888 | &videoModeSupportedRequest->fSupported);
|
---|
889 | }
|
---|
890 | break;
|
---|
891 | }
|
---|
892 |
|
---|
893 | /*
|
---|
894 | * Query the height reduction in pixels
|
---|
895 | */
|
---|
896 | case VMMDevReq_GetHeightReduction:
|
---|
897 | {
|
---|
898 | if (pRequestHeader->size != sizeof(VMMDevGetHeightReductionRequest))
|
---|
899 | {
|
---|
900 | AssertMsgFailed(("VMMDev height reduction request structure has invalid size!\n"));
|
---|
901 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
902 | }
|
---|
903 | else
|
---|
904 | {
|
---|
905 | VMMDevGetHeightReductionRequest *heightReductionRequest = (VMMDevGetHeightReductionRequest*)pRequestHeader;
|
---|
906 | /* forward the call */
|
---|
907 | pRequestHeader->rc = pData->pDrv->pfnGetHeightReduction(pData->pDrv,
|
---|
908 | &heightReductionRequest->heightReduction);
|
---|
909 | }
|
---|
910 | break;
|
---|
911 | }
|
---|
912 |
|
---|
913 | /*
|
---|
914 | * Acknowledge VMMDev events
|
---|
915 | */
|
---|
916 | case VMMDevReq_AcknowledgeEvents:
|
---|
917 | {
|
---|
918 | if (pRequestHeader->size != sizeof(VMMDevEvents))
|
---|
919 | {
|
---|
920 | AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
|
---|
921 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
922 | }
|
---|
923 | else
|
---|
924 | {
|
---|
925 | if (VBOX_GUEST_ADDITIONS_VERSION_1_03 (pData))
|
---|
926 | {
|
---|
927 | vmmdevSetIRQ_Legacy_EMT (pData);
|
---|
928 | }
|
---|
929 | else
|
---|
930 | {
|
---|
931 | VMMDevEvents *pAckRequest;
|
---|
932 |
|
---|
933 | if (pData->fNewGuestFilterMask)
|
---|
934 | {
|
---|
935 | pData->fNewGuestFilterMask = false;
|
---|
936 | pData->u32GuestFilterMask = pData->u32NewGuestFilterMask;
|
---|
937 | }
|
---|
938 |
|
---|
939 | pAckRequest = (VMMDevEvents *)pRequestHeader;
|
---|
940 | pAckRequest->events =
|
---|
941 | pData->u32HostEventFlags & pData->u32GuestFilterMask;
|
---|
942 |
|
---|
943 | pData->u32HostEventFlags &= ~pData->u32GuestFilterMask;
|
---|
944 | pData->pVMMDevRAMHC->V.V1_04.fHaveEvents = false;
|
---|
945 | PDMDevHlpPCISetIrqNoWait (pData->pDevIns, 0, 0);
|
---|
946 | }
|
---|
947 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
948 | }
|
---|
949 | break;
|
---|
950 | }
|
---|
951 |
|
---|
952 | /*
|
---|
953 | * Change guest filter mask
|
---|
954 | */
|
---|
955 | case VMMDevReq_CtlGuestFilterMask:
|
---|
956 | {
|
---|
957 | if (pRequestHeader->size != sizeof(VMMDevCtlGuestFilterMask))
|
---|
958 | {
|
---|
959 | AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
|
---|
960 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
961 | }
|
---|
962 | else
|
---|
963 | {
|
---|
964 | VMMDevCtlGuestFilterMask *pCtlMaskRequest;
|
---|
965 |
|
---|
966 | pCtlMaskRequest = (VMMDevCtlGuestFilterMask *)pRequestHeader;
|
---|
967 | /* The HGCM events are enabled by the VMMDev device automatically when any
|
---|
968 | * HGCM command is issued. The guest then can not disable these events.
|
---|
969 | */
|
---|
970 | vmmdevCtlGuestFilterMask_EMT (pData,
|
---|
971 | pCtlMaskRequest->u32OrMask,
|
---|
972 | pCtlMaskRequest->u32NotMask & ~VMMDEV_EVENT_HGCM);
|
---|
973 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
974 |
|
---|
975 | }
|
---|
976 | break;
|
---|
977 | }
|
---|
978 |
|
---|
979 | #ifdef VBOX_HGCM
|
---|
980 | /*
|
---|
981 | * Process HGCM request
|
---|
982 | */
|
---|
983 | case VMMDevReq_HGCMConnect:
|
---|
984 | {
|
---|
985 | if (pRequestHeader->size < sizeof(VMMDevHGCMConnect))
|
---|
986 | {
|
---|
987 | AssertMsgFailed(("VMMDevReq_HGCMConnect structure has invalid size!\n"));
|
---|
988 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
989 | }
|
---|
990 | else if (!pData->pHGCMDrv)
|
---|
991 | {
|
---|
992 | Log(("VMMDevReq_HGCMConnect HGCM Connector is NULL!\n"));
|
---|
993 | pRequestHeader->rc = VERR_NOT_SUPPORTED;
|
---|
994 | }
|
---|
995 | else
|
---|
996 | {
|
---|
997 | VMMDevHGCMConnect *pHGCMConnect = (VMMDevHGCMConnect *)pRequestHeader;
|
---|
998 |
|
---|
999 | Log(("VMMDevReq_HGCMConnect\n"));
|
---|
1000 |
|
---|
1001 | pRequestHeader->rc = vmmdevHGCMConnect (pData, pHGCMConnect, (RTGCPHYS)u32);
|
---|
1002 | }
|
---|
1003 | break;
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | case VMMDevReq_HGCMDisconnect:
|
---|
1007 | {
|
---|
1008 | if (pRequestHeader->size < sizeof(VMMDevHGCMDisconnect))
|
---|
1009 | {
|
---|
1010 | AssertMsgFailed(("VMMDevReq_HGCMDisconnect structure has invalid size!\n"));
|
---|
1011 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1012 | }
|
---|
1013 | else if (!pData->pHGCMDrv)
|
---|
1014 | {
|
---|
1015 | Log(("VMMDevReq_HGCMDisconnect HGCM Connector is NULL!\n"));
|
---|
1016 | pRequestHeader->rc = VERR_NOT_SUPPORTED;
|
---|
1017 | }
|
---|
1018 | else
|
---|
1019 | {
|
---|
1020 | VMMDevHGCMDisconnect *pHGCMDisconnect = (VMMDevHGCMDisconnect *)pRequestHeader;
|
---|
1021 |
|
---|
1022 | Log(("VMMDevReq_VMMDevHGCMDisconnect\n"));
|
---|
1023 | pRequestHeader->rc = vmmdevHGCMDisconnect (pData, pHGCMDisconnect, (RTGCPHYS)u32);
|
---|
1024 | }
|
---|
1025 | break;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | case VMMDevReq_HGCMCall:
|
---|
1029 | {
|
---|
1030 | if (pRequestHeader->size < sizeof(VMMDevHGCMCall))
|
---|
1031 | {
|
---|
1032 | AssertMsgFailed(("VMMDevReq_HGCMCall structure has invalid size!\n"));
|
---|
1033 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1034 | }
|
---|
1035 | else if (!pData->pHGCMDrv)
|
---|
1036 | {
|
---|
1037 | Log(("VMMDevReq_HGCMCall HGCM Connector is NULL!\n"));
|
---|
1038 | pRequestHeader->rc = VERR_NOT_SUPPORTED;
|
---|
1039 | }
|
---|
1040 | else
|
---|
1041 | {
|
---|
1042 | VMMDevHGCMCall *pHGCMCall = (VMMDevHGCMCall *)pRequestHeader;
|
---|
1043 |
|
---|
1044 | Log2(("VMMDevReq_HGCMCall: sizeof (VMMDevHGCMRequest) = %04X\n", sizeof (VMMDevHGCMCall)));
|
---|
1045 | Log2(("%.*Vhxd\n", pRequestHeader->size, pRequestHeader));
|
---|
1046 |
|
---|
1047 | pRequestHeader->rc = vmmdevHGCMCall (pData, pHGCMCall, (RTGCPHYS)u32);
|
---|
1048 | }
|
---|
1049 | break;
|
---|
1050 | }
|
---|
1051 | #endif /* VBOX_HGCM */
|
---|
1052 |
|
---|
1053 | case VMMDevReq_VideoAccelEnable:
|
---|
1054 | {
|
---|
1055 | if (pRequestHeader->size < sizeof(VMMDevVideoAccelEnable))
|
---|
1056 | {
|
---|
1057 | Log(("VMMDevReq_VideoAccelEnable request size too small!!!\n"));
|
---|
1058 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1059 | }
|
---|
1060 | else if (!pData->pDrv)
|
---|
1061 | {
|
---|
1062 | Log(("VMMDevReq_VideoAccelEnable Connector is NULL!!!\n"));
|
---|
1063 | pRequestHeader->rc = VERR_NOT_SUPPORTED;
|
---|
1064 | }
|
---|
1065 | else
|
---|
1066 | {
|
---|
1067 | VMMDevVideoAccelEnable *ptr = (VMMDevVideoAccelEnable *)pRequestHeader;
|
---|
1068 |
|
---|
1069 | if (ptr->cbRingBuffer != VBVA_RING_BUFFER_SIZE)
|
---|
1070 | {
|
---|
1071 | /* The guest driver seems compiled with another headers. */
|
---|
1072 | Log(("VMMDevReq_VideoAccelEnable guest ring buffer size %d, should be %d!!!\n", ptr->cbRingBuffer, VBVA_RING_BUFFER_SIZE));
|
---|
1073 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1074 | }
|
---|
1075 | else
|
---|
1076 | {
|
---|
1077 | /* The request is correct. */
|
---|
1078 | ptr->fu32Status |= VBVA_F_STATUS_ACCEPTED;
|
---|
1079 |
|
---|
1080 | LogFlow(("VMMDevReq_VideoAccelEnable ptr->u32Enable = %d\n", ptr->u32Enable));
|
---|
1081 |
|
---|
1082 | pRequestHeader->rc = ptr->u32Enable?
|
---|
1083 | pData->pDrv->pfnVideoAccelEnable (pData->pDrv, true, &pData->pVMMDevRAMHC->vbvaMemory):
|
---|
1084 | pData->pDrv->pfnVideoAccelEnable (pData->pDrv, false, NULL);
|
---|
1085 |
|
---|
1086 | if ( ptr->u32Enable
|
---|
1087 | && VBOX_SUCCESS (pRequestHeader->rc))
|
---|
1088 | {
|
---|
1089 | ptr->fu32Status |= VBVA_F_STATUS_ENABLED;
|
---|
1090 |
|
---|
1091 | /* Remember that guest successfully enabled acceleration.
|
---|
1092 | * We need to reestablish it on restoring the VM from saved state.
|
---|
1093 | */
|
---|
1094 | pData->u32VideoAccelEnabled = 1;
|
---|
1095 | }
|
---|
1096 | else
|
---|
1097 | {
|
---|
1098 | /* The acceleration was not enabled. Remember that. */
|
---|
1099 | pData->u32VideoAccelEnabled = 0;
|
---|
1100 | }
|
---|
1101 | }
|
---|
1102 | }
|
---|
1103 | break;
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | case VMMDevReq_VideoAccelFlush:
|
---|
1107 | {
|
---|
1108 | if (pRequestHeader->size < sizeof(VMMDevVideoAccelFlush))
|
---|
1109 | {
|
---|
1110 | AssertMsgFailed(("VMMDevReq_VideoAccelFlush request size too small.\n"));
|
---|
1111 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1112 | }
|
---|
1113 | else if (!pData->pDrv)
|
---|
1114 | {
|
---|
1115 | Log(("VMMDevReq_VideoAccelFlush Connector is NULL!\n"));
|
---|
1116 | pRequestHeader->rc = VERR_NOT_SUPPORTED;
|
---|
1117 | }
|
---|
1118 | else
|
---|
1119 | {
|
---|
1120 | pData->pDrv->pfnVideoAccelFlush (pData->pDrv);
|
---|
1121 |
|
---|
1122 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
1123 | }
|
---|
1124 | break;
|
---|
1125 | }
|
---|
1126 |
|
---|
1127 | case VMMDevReq_VideoSetVisibleRegion:
|
---|
1128 | {
|
---|
1129 | if (pRequestHeader->size < sizeof(VMMDevVideoSetVisibleRegion))
|
---|
1130 | {
|
---|
1131 | Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
|
---|
1132 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1133 | }
|
---|
1134 | else if (!pData->pDrv)
|
---|
1135 | {
|
---|
1136 | Log(("VMMDevReq_VideoSetVisibleRegion Connector is NULL!!!\n"));
|
---|
1137 | pRequestHeader->rc = VERR_NOT_SUPPORTED;
|
---|
1138 | }
|
---|
1139 | else
|
---|
1140 | {
|
---|
1141 | VMMDevVideoSetVisibleRegion *ptr = (VMMDevVideoSetVisibleRegion *)pRequestHeader;
|
---|
1142 |
|
---|
1143 | if (!ptr->cRect)
|
---|
1144 | {
|
---|
1145 | Log(("VMMDevReq_VideoSetVisibleRegion no rectangles!!!\n"));
|
---|
1146 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1147 | }
|
---|
1148 | else
|
---|
1149 | if (pRequestHeader->size != sizeof(VMMDevVideoSetVisibleRegion) + (ptr->cRect-1)*sizeof(RTRECT))
|
---|
1150 | {
|
---|
1151 | Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
|
---|
1152 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1153 | }
|
---|
1154 | else
|
---|
1155 | {
|
---|
1156 | Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", ptr->cRect));
|
---|
1157 | /* forward the call */
|
---|
1158 | pRequestHeader->rc = pData->pDrv->pfnSetVisibleRegion(pData->pDrv, ptr->cRect, &ptr->Rect);
|
---|
1159 | }
|
---|
1160 | }
|
---|
1161 | break;
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | case VMMDevReq_GetSeamlessChangeRequest:
|
---|
1165 | {
|
---|
1166 | if (pRequestHeader->size != sizeof(VMMDevSeamlessChangeRequest))
|
---|
1167 | {
|
---|
1168 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1169 | }
|
---|
1170 | else
|
---|
1171 | {
|
---|
1172 | VMMDevSeamlessChangeRequest *seamlessChangeRequest = (VMMDevSeamlessChangeRequest*)pRequestHeader;
|
---|
1173 | /* just pass on the information */
|
---|
1174 | Log(("VMMDev: returning seamless change request mode=%d\n", pData->fSeamlessEnabled));
|
---|
1175 | if (pData->fSeamlessEnabled)
|
---|
1176 | seamlessChangeRequest->mode = VMMDev_Seamless_Visible_Region;
|
---|
1177 | else
|
---|
1178 | seamlessChangeRequest->mode = VMMDev_Seamless_Disabled;
|
---|
1179 |
|
---|
1180 | if (seamlessChangeRequest->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
|
---|
1181 | {
|
---|
1182 | /* Remember which mode the client has queried. */
|
---|
1183 | pData->fLastSeamlessEnabled = pData->fSeamlessEnabled;
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
1187 | }
|
---|
1188 | break;
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | case VMMDevReq_GetVRDPChangeRequest:
|
---|
1192 | {
|
---|
1193 | if (pRequestHeader->size != sizeof(VMMDevVRDPChangeRequest))
|
---|
1194 | {
|
---|
1195 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1196 | }
|
---|
1197 | else
|
---|
1198 | {
|
---|
1199 | VMMDevVRDPChangeRequest *vrdpChangeRequest = (VMMDevVRDPChangeRequest*)pRequestHeader;
|
---|
1200 | /* just pass on the information */
|
---|
1201 | Log(("VMMDev: returning VRDP status %d level %d\n", pData->fVRDPEnabled, pData->u32VRDPExperienceLevel));
|
---|
1202 |
|
---|
1203 | vrdpChangeRequest->u8VRDPActive = pData->fVRDPEnabled;
|
---|
1204 | vrdpChangeRequest->u32VRDPExperienceLevel = pData->u32VRDPExperienceLevel;
|
---|
1205 |
|
---|
1206 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
1207 | }
|
---|
1208 | break;
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | case VMMDevReq_GetMemBalloonChangeRequest:
|
---|
1212 | {
|
---|
1213 | Log(("VMMDevReq_GetMemBalloonChangeRequest\n"));
|
---|
1214 | if (pRequestHeader->size != sizeof(VMMDevGetMemBalloonChangeRequest))
|
---|
1215 | {
|
---|
1216 | AssertFailed();
|
---|
1217 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1218 | }
|
---|
1219 | else
|
---|
1220 | {
|
---|
1221 | VMMDevGetMemBalloonChangeRequest *memBalloonChangeRequest = (VMMDevGetMemBalloonChangeRequest*)pRequestHeader;
|
---|
1222 | /* just pass on the information */
|
---|
1223 | Log(("VMMDev: returning memory balloon size =%d\n", pData->u32MemoryBalloonSize));
|
---|
1224 | memBalloonChangeRequest->u32BalloonSize = pData->u32MemoryBalloonSize;
|
---|
1225 | memBalloonChangeRequest->u32PhysMemSize = (pData->u64GuestRAMSize / (uint64_t)_1M);
|
---|
1226 |
|
---|
1227 | if (memBalloonChangeRequest->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
|
---|
1228 | {
|
---|
1229 | /* Remember which mode the client has queried. */
|
---|
1230 | pData->u32LastMemoryBalloonSize = pData->u32MemoryBalloonSize;
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
1234 | }
|
---|
1235 | break;
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | case VMMDevReq_ChangeMemBalloon:
|
---|
1239 | {
|
---|
1240 | VMMDevChangeMemBalloon *memBalloonChange = (VMMDevChangeMemBalloon*)pRequestHeader;
|
---|
1241 |
|
---|
1242 | Log(("VMMDevReq_ChangeMemBalloon\n"));
|
---|
1243 | if ( pRequestHeader->size < sizeof(VMMDevChangeMemBalloon)
|
---|
1244 | || memBalloonChange->cPages != VMMDEV_MEMORY_BALLOON_CHUNK_PAGES
|
---|
1245 | || pRequestHeader->size != (uint32_t)RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[memBalloonChange->cPages]))
|
---|
1246 | {
|
---|
1247 | AssertFailed();
|
---|
1248 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1249 | }
|
---|
1250 | else
|
---|
1251 | {
|
---|
1252 | pRequestHeader->rc = pData->pDrv->pfnChangeMemoryBalloon(pData->pDrv, !!memBalloonChange->fInflate, memBalloonChange->cPages, memBalloonChange->aPhysPage);
|
---|
1253 | }
|
---|
1254 | break;
|
---|
1255 | }
|
---|
1256 |
|
---|
1257 | case VMMDevReq_GetStatisticsChangeRequest:
|
---|
1258 | {
|
---|
1259 | Log(("VMMDevReq_GetStatisticsChangeRequest\n"));
|
---|
1260 | if (pRequestHeader->size != sizeof(VMMDevGetStatisticsChangeRequest))
|
---|
1261 | {
|
---|
1262 | AssertFailed();
|
---|
1263 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1264 | }
|
---|
1265 | else
|
---|
1266 | {
|
---|
1267 | VMMDevGetStatisticsChangeRequest *statIntervalChangeRequest = (VMMDevGetStatisticsChangeRequest*)pRequestHeader;
|
---|
1268 | /* just pass on the information */
|
---|
1269 | Log(("VMMDev: returning statistics interval %d seconds\n", pData->u32StatIntervalSize));
|
---|
1270 | statIntervalChangeRequest->u32StatInterval = pData->u32StatIntervalSize;
|
---|
1271 |
|
---|
1272 | if (statIntervalChangeRequest->eventAck == VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
|
---|
1273 | {
|
---|
1274 | /* Remember which mode the client has queried. */
|
---|
1275 | pData->u32LastStatIntervalSize= pData->u32StatIntervalSize;
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
1279 | }
|
---|
1280 | break;
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | case VMMDevReq_ReportGuestStats:
|
---|
1284 | {
|
---|
1285 | Log(("VMMDevReq_ReportGuestStats\n"));
|
---|
1286 | if (pRequestHeader->size != sizeof(VMMDevReportGuestStats))
|
---|
1287 | {
|
---|
1288 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1289 | }
|
---|
1290 | else
|
---|
1291 | {
|
---|
1292 | VMMDevReportGuestStats *stats = (VMMDevReportGuestStats*)pRequestHeader;
|
---|
1293 |
|
---|
1294 | #ifdef DEBUG
|
---|
1295 | VBoxGuestStatistics *pGuestStats = &stats->guestStats;
|
---|
1296 |
|
---|
1297 | Log(("Current statistics:\n"));
|
---|
1298 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
|
---|
1299 | Log(("CPU%d: CPU Load Idle %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Idle));
|
---|
1300 |
|
---|
1301 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
|
---|
1302 | Log(("CPU%d: CPU Load Kernel %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Kernel));
|
---|
1303 |
|
---|
1304 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
|
---|
1305 | Log(("CPU%d: CPU Load User %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_User));
|
---|
1306 |
|
---|
1307 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
|
---|
1308 | Log(("CPU%d: Thread %d\n", pGuestStats->u32CpuId, pGuestStats->u32Threads));
|
---|
1309 |
|
---|
1310 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
|
---|
1311 | Log(("CPU%d: Processes %d\n", pGuestStats->u32CpuId, pGuestStats->u32Processes));
|
---|
1312 |
|
---|
1313 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
|
---|
1314 | Log(("CPU%d: Handles %d\n", pGuestStats->u32CpuId, pGuestStats->u32Handles));
|
---|
1315 |
|
---|
1316 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
|
---|
1317 | Log(("CPU%d: Memory Load %d%%\n", pGuestStats->u32CpuId, pGuestStats->u32MemoryLoad));
|
---|
1318 |
|
---|
1319 | /* Note that reported values are in pages; upper layers expect them in megabytes */
|
---|
1320 | Assert(pGuestStats->u32PageSize == 4096);
|
---|
1321 | if (pGuestStats->u32PageSize != 4096)
|
---|
1322 | pGuestStats->u32PageSize = 4096;
|
---|
1323 |
|
---|
1324 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
|
---|
1325 | Log(("CPU%d: Total physical memory %-4d MB\n", pGuestStats->u32CpuId, (pGuestStats->u32PhysMemTotal + (_1M/pGuestStats->u32PageSize)-1)/ (_1M/pGuestStats->u32PageSize)));
|
---|
1326 |
|
---|
1327 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
|
---|
1328 | Log(("CPU%d: Free physical memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemAvail / (_1M/pGuestStats->u32PageSize)));
|
---|
1329 |
|
---|
1330 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
|
---|
1331 | Log(("CPU%d: Memory balloon size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemBalloon / (_1M/pGuestStats->u32PageSize)));
|
---|
1332 |
|
---|
1333 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
|
---|
1334 | Log(("CPU%d: Committed memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemCommitTotal / (_1M/pGuestStats->u32PageSize)));
|
---|
1335 |
|
---|
1336 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
|
---|
1337 | Log(("CPU%d: Total kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelTotal / (_1M/pGuestStats->u32PageSize)));
|
---|
1338 |
|
---|
1339 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
|
---|
1340 | Log(("CPU%d: Paged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelPaged / (_1M/pGuestStats->u32PageSize)));
|
---|
1341 |
|
---|
1342 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
|
---|
1343 | Log(("CPU%d: Nonpaged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelNonPaged / (_1M/pGuestStats->u32PageSize)));
|
---|
1344 |
|
---|
1345 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
|
---|
1346 | Log(("CPU%d: System cache size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemSystemCache / (_1M/pGuestStats->u32PageSize)));
|
---|
1347 |
|
---|
1348 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
|
---|
1349 | Log(("CPU%d: Page file size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PageFileSize / (_1M/pGuestStats->u32PageSize)));
|
---|
1350 | Log(("Statistics end *******************\n"));
|
---|
1351 | #endif
|
---|
1352 |
|
---|
1353 | /* forward the call */
|
---|
1354 | pRequestHeader->rc = pData->pDrv->pfnReportStatistics(pData->pDrv, &stats->guestStats);
|
---|
1355 | }
|
---|
1356 | break;
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | case VMMDevReq_QueryCredentials:
|
---|
1360 | {
|
---|
1361 | if (pRequestHeader->size != sizeof(VMMDevCredentials))
|
---|
1362 | {
|
---|
1363 | AssertMsgFailed(("VMMDevReq_QueryCredentials request size too small.\n"));
|
---|
1364 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1365 | }
|
---|
1366 | else
|
---|
1367 | {
|
---|
1368 | VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
|
---|
1369 |
|
---|
1370 | /* let's start by nulling out the data */
|
---|
1371 | memset(credentials->szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1372 | memset(credentials->szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1373 | memset(credentials->szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1374 |
|
---|
1375 | /* should we return whether we got credentials for a logon? */
|
---|
1376 | if (credentials->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
|
---|
1377 | {
|
---|
1378 | if ( pData->credentialsLogon.szUserName[0]
|
---|
1379 | || pData->credentialsLogon.szPassword[0]
|
---|
1380 | || pData->credentialsLogon.szDomain[0])
|
---|
1381 | {
|
---|
1382 | credentials->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
|
---|
1383 | }
|
---|
1384 | else
|
---|
1385 | {
|
---|
1386 | credentials->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
|
---|
1387 | }
|
---|
1388 | }
|
---|
1389 |
|
---|
1390 | /* does the guest want to read logon credentials? */
|
---|
1391 | if (credentials->u32Flags & VMMDEV_CREDENTIALS_READ)
|
---|
1392 | {
|
---|
1393 | if (pData->credentialsLogon.szUserName[0])
|
---|
1394 | strcpy(credentials->szUserName, pData->credentialsLogon.szUserName);
|
---|
1395 | if (pData->credentialsLogon.szPassword[0])
|
---|
1396 | strcpy(credentials->szPassword, pData->credentialsLogon.szPassword);
|
---|
1397 | if (pData->credentialsLogon.szDomain[0])
|
---|
1398 | strcpy(credentials->szDomain, pData->credentialsLogon.szDomain);
|
---|
1399 | if (!pData->credentialsLogon.fAllowInteractiveLogon)
|
---|
1400 | credentials->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
|
---|
1401 | else
|
---|
1402 | credentials->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | /* does the caller want us to destroy the logon credentials? */
|
---|
1406 | if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
|
---|
1407 | {
|
---|
1408 | memset(pData->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1409 | memset(pData->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1410 | memset(pData->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | /* does the guest want to read credentials for verification? */
|
---|
1414 | if (credentials->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
|
---|
1415 | {
|
---|
1416 | if (pData->credentialsJudge.szUserName[0])
|
---|
1417 | strcpy(credentials->szUserName, pData->credentialsJudge.szUserName);
|
---|
1418 | if (pData->credentialsJudge.szPassword[0])
|
---|
1419 | strcpy(credentials->szPassword, pData->credentialsJudge.szPassword);
|
---|
1420 | if (pData->credentialsJudge.szDomain[0])
|
---|
1421 | strcpy(credentials->szDomain, pData->credentialsJudge.szDomain);
|
---|
1422 | }
|
---|
1423 |
|
---|
1424 | /* does the caller want us to destroy the judgement credentials? */
|
---|
1425 | if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
|
---|
1426 | {
|
---|
1427 | memset(pData->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1428 | memset(pData->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1429 | memset(pData->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
1430 | }
|
---|
1431 |
|
---|
1432 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
1433 | }
|
---|
1434 | break;
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | case VMMDevReq_ReportCredentialsJudgement:
|
---|
1438 | {
|
---|
1439 | if (pRequestHeader->size != sizeof(VMMDevCredentials))
|
---|
1440 | {
|
---|
1441 | AssertMsgFailed(("VMMDevReq_ReportCredentialsJudgement request size too small.\n"));
|
---|
1442 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1443 | }
|
---|
1444 | else
|
---|
1445 | {
|
---|
1446 | VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
|
---|
1447 |
|
---|
1448 | /* what does the guest think about the credentials? (note: the order is important here!) */
|
---|
1449 | if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
|
---|
1450 | {
|
---|
1451 | pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
|
---|
1452 | }
|
---|
1453 | else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
|
---|
1454 | {
|
---|
1455 | pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
|
---|
1456 | }
|
---|
1457 | else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
|
---|
1458 | {
|
---|
1459 | pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
|
---|
1460 | }
|
---|
1461 | else
|
---|
1462 | Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", credentials->u32Flags));
|
---|
1463 |
|
---|
1464 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
1465 | }
|
---|
1466 | break;
|
---|
1467 | }
|
---|
1468 |
|
---|
1469 | #ifdef DEBUG
|
---|
1470 | case VMMDevReq_LogString:
|
---|
1471 | {
|
---|
1472 | if (pRequestHeader->size < sizeof(VMMDevReqLogString))
|
---|
1473 | {
|
---|
1474 | AssertMsgFailed(("VMMDevReq_LogString request size too small.\n"));
|
---|
1475 | pRequestHeader->rc = VERR_INVALID_PARAMETER;
|
---|
1476 | }
|
---|
1477 | else
|
---|
1478 | {
|
---|
1479 | VMMDevReqLogString *pReqLogString = (VMMDevReqLogString*)pRequestHeader;
|
---|
1480 | #undef LOG_GROUP
|
---|
1481 | #define LOG_GROUP LOG_GROUP_DEV_VMM_BACKDOOR
|
---|
1482 | // Log(("Guest Log: %s", pReqLogString->szString));
|
---|
1483 | Log(("DEBUG LOG: %s", pReqLogString->szString));
|
---|
1484 |
|
---|
1485 | #undef LOG_GROUP
|
---|
1486 | #define LOG_GROUP LOG_GROUP_DEV_VMM
|
---|
1487 | pRequestHeader->rc = VINF_SUCCESS;
|
---|
1488 | }
|
---|
1489 | break;
|
---|
1490 | }
|
---|
1491 | #endif
|
---|
1492 | default:
|
---|
1493 | {
|
---|
1494 | pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
|
---|
1495 |
|
---|
1496 | Log(("VMMDev unknown request type %d\n", pRequestHeader->requestType));
|
---|
1497 |
|
---|
1498 | break;
|
---|
1499 | }
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | end:
|
---|
1503 | /* Write the result back to guest memory */
|
---|
1504 | if (pRequestHeader)
|
---|
1505 | {
|
---|
1506 | PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, pRequestHeader, pRequestHeader->size);
|
---|
1507 | RTMemFree(pRequestHeader);
|
---|
1508 | }
|
---|
1509 | else
|
---|
1510 | {
|
---|
1511 | /* early error case; write back header only */
|
---|
1512 | PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
|
---|
1513 | }
|
---|
1514 | return rcRet;
|
---|
1515 | }
|
---|
1516 |
|
---|
1517 | /**
|
---|
1518 | * Callback function for mapping an PCI I/O region.
|
---|
1519 | *
|
---|
1520 | * @return VBox status code.
|
---|
1521 | * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
|
---|
1522 | * @param iRegion The region number.
|
---|
1523 | * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
|
---|
1524 | * I/O port, else it's a physical address.
|
---|
1525 | * This address is *NOT* relative to pci_mem_base like earlier!
|
---|
1526 | * @param enmType One of the PCI_ADDRESS_SPACE_* values.
|
---|
1527 | */
|
---|
1528 | static DECLCALLBACK(int) vmmdevIORAMRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
|
---|
1529 | {
|
---|
1530 | int rc;
|
---|
1531 | VMMDevState *pData = PCIDEV_2_VMMDEVSTATE(pPciDev);
|
---|
1532 | LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%VGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
|
---|
1533 |
|
---|
1534 |
|
---|
1535 | Assert(pData->pVMMDevRAMHC != NULL);
|
---|
1536 |
|
---|
1537 | memset (pData->pVMMDevRAMHC, 0, sizeof (VMMDevMemory));
|
---|
1538 | pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
|
---|
1539 | pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
|
---|
1540 |
|
---|
1541 | /*
|
---|
1542 | * VMMDev RAM mapping.
|
---|
1543 | */
|
---|
1544 | if (iRegion == 1 && enmType == PCI_ADDRESS_SPACE_MEM)
|
---|
1545 | {
|
---|
1546 | /*
|
---|
1547 | * Register and lock the RAM.
|
---|
1548 | *
|
---|
1549 | * Windows usually re-initializes the PCI devices, so we have to check whether the memory was
|
---|
1550 | * already registered before trying to do that all over again.
|
---|
1551 | */
|
---|
1552 | PVM pVM = PDMDevHlpGetVM(pPciDev->pDevIns);
|
---|
1553 |
|
---|
1554 | if (pData->GCPhysVMMDevRAM)
|
---|
1555 | {
|
---|
1556 | /*
|
---|
1557 | * Relocate the already registered VMMDevRAM.
|
---|
1558 | */
|
---|
1559 | rc = MMR3PhysRelocate(pVM, pData->GCPhysVMMDevRAM, GCPhysAddress, VMMDEV_RAM_SIZE);
|
---|
1560 | if (VBOX_SUCCESS(rc))
|
---|
1561 | {
|
---|
1562 | pData->GCPhysVMMDevRAM = GCPhysAddress;
|
---|
1563 | return VINF_SUCCESS;
|
---|
1564 | }
|
---|
1565 | AssertReleaseMsgFailed(("Failed to relocate VMMDev RAM from %VGp to %VGp! rc=%Vra\n", pData->GCPhysVMMDevRAM, GCPhysAddress, rc));
|
---|
1566 | }
|
---|
1567 | else
|
---|
1568 | {
|
---|
1569 | /*
|
---|
1570 | * Register and lock the VMMDevRAM.
|
---|
1571 | */
|
---|
1572 | /** @todo MM_RAM_FLAGS_MMIO2 seems to be appropriate for a RW memory.
|
---|
1573 | * Need to check. May be a RO memory is enough for the device.
|
---|
1574 | */
|
---|
1575 | rc = MMR3PhysRegister(pVM, pData->pVMMDevRAMHC, GCPhysAddress, VMMDEV_RAM_SIZE, MM_RAM_FLAGS_MMIO2, "VBoxDev");
|
---|
1576 | if (VBOX_SUCCESS(rc))
|
---|
1577 | {
|
---|
1578 | pData->GCPhysVMMDevRAM = GCPhysAddress;
|
---|
1579 | return VINF_SUCCESS;
|
---|
1580 | }
|
---|
1581 | AssertReleaseMsgFailed(("Failed to register VMMDev RAM! rc=%Vra\n", rc));
|
---|
1582 | }
|
---|
1583 | return rc;
|
---|
1584 | }
|
---|
1585 |
|
---|
1586 | AssertReleaseMsgFailed(("VMMDev wrong region type: iRegion=%d enmType=%d\n", iRegion, enmType));
|
---|
1587 | return VERR_INTERNAL_ERROR;
|
---|
1588 | }
|
---|
1589 |
|
---|
1590 |
|
---|
1591 | /**
|
---|
1592 | * Callback function for mapping a PCI I/O region.
|
---|
1593 | *
|
---|
1594 | * @return VBox status code.
|
---|
1595 | * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
|
---|
1596 | * @param iRegion The region number.
|
---|
1597 | * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
|
---|
1598 | * I/O port, else it's a physical address.
|
---|
1599 | * This address is *NOT* relative to pci_mem_base like earlier!
|
---|
1600 | * @param enmType One of the PCI_ADDRESS_SPACE_* values.
|
---|
1601 | */
|
---|
1602 | static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
|
---|
1603 | {
|
---|
1604 | VMMDevState *pData = PCIDEV_2_VMMDEVSTATE(pPciDev);
|
---|
1605 | int rc = VINF_SUCCESS;
|
---|
1606 |
|
---|
1607 | Assert(enmType == PCI_ADDRESS_SPACE_IO);
|
---|
1608 | Assert(iRegion == 0);
|
---|
1609 | AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
|
---|
1610 |
|
---|
1611 | /*
|
---|
1612 | * Save the base port address to simplify Port offset calculations.
|
---|
1613 | */
|
---|
1614 | pData->PortBase = (RTIOPORT)GCPhysAddress;
|
---|
1615 |
|
---|
1616 | /*
|
---|
1617 | * Register our port IO handlers.
|
---|
1618 | */
|
---|
1619 | rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns,
|
---|
1620 | (RTIOPORT)GCPhysAddress + PORT_VMMDEV_REQUEST_OFFSET, 1,
|
---|
1621 | (void*)pData, vmmdevRequestHandler,
|
---|
1622 | NULL, NULL, NULL, "VMMDev Request Handler");
|
---|
1623 | AssertRC(rc);
|
---|
1624 | return rc;
|
---|
1625 | }
|
---|
1626 |
|
---|
1627 | /**
|
---|
1628 | * Queries an interface to the driver.
|
---|
1629 | *
|
---|
1630 | * @returns Pointer to interface.
|
---|
1631 | * @returns NULL if the interface was not supported by the driver.
|
---|
1632 | * @param pInterface Pointer to this interface structure.
|
---|
1633 | * @param enmInterface The requested interface identification.
|
---|
1634 | * @thread Any thread.
|
---|
1635 | */
|
---|
1636 | static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
|
---|
1637 | {
|
---|
1638 | VMMDevState *pData = (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, Base));
|
---|
1639 | switch (enmInterface)
|
---|
1640 | {
|
---|
1641 | case PDMINTERFACE_BASE:
|
---|
1642 | return &pData->Base;
|
---|
1643 | case PDMINTERFACE_VMMDEV_PORT:
|
---|
1644 | return &pData->Port;
|
---|
1645 | #ifdef VBOX_HGCM
|
---|
1646 | case PDMINTERFACE_HGCM_PORT:
|
---|
1647 | return &pData->HGCMPort;
|
---|
1648 | #endif
|
---|
1649 | case PDMINTERFACE_LED_PORTS:
|
---|
1650 | /* Currently only for shared folders */
|
---|
1651 | return &pData->SharedFolders.ILeds;
|
---|
1652 | default:
|
---|
1653 | return NULL;
|
---|
1654 | }
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | /**
|
---|
1658 | * Gets the pointer to the status LED of a unit.
|
---|
1659 | *
|
---|
1660 | * @returns VBox status code.
|
---|
1661 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1662 | * @param iLUN The unit which status LED we desire.
|
---|
1663 | * @param ppLed Where to store the LED pointer.
|
---|
1664 | */
|
---|
1665 | static DECLCALLBACK(int) vmmdevQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
|
---|
1666 | {
|
---|
1667 | VMMDevState *pData = (VMMDevState *)( (uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, SharedFolders.ILeds) );
|
---|
1668 | if (iLUN == 0) /* LUN 0 is shared folders */
|
---|
1669 | {
|
---|
1670 | *ppLed = &pData->SharedFolders.Led;
|
---|
1671 | return VINF_SUCCESS;
|
---|
1672 | }
|
---|
1673 | return VERR_PDM_LUN_NOT_FOUND;
|
---|
1674 | }
|
---|
1675 |
|
---|
1676 | /* -=-=-=-=-=- IVMMDevPort -=-=-=-=-=- */
|
---|
1677 |
|
---|
1678 | /** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
|
---|
1679 | #define IVMMDEVPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, Port)) )
|
---|
1680 |
|
---|
1681 |
|
---|
1682 | /**
|
---|
1683 | * Return the current absolute mouse position in pixels
|
---|
1684 | *
|
---|
1685 | * @returns VBox status code
|
---|
1686 | * @param pAbsX Pointer of result value, can be NULL
|
---|
1687 | * @param pAbsY Pointer of result value, can be NULL
|
---|
1688 | */
|
---|
1689 | static DECLCALLBACK(int) vmmdevQueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t *pAbsX, uint32_t *pAbsY)
|
---|
1690 | {
|
---|
1691 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1692 | if (pAbsX)
|
---|
1693 | *pAbsX = pData->mouseXAbs;
|
---|
1694 | if (pAbsY)
|
---|
1695 | *pAbsY = pData->mouseYAbs;
|
---|
1696 | return VINF_SUCCESS;
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 | /**
|
---|
1700 | * Set the new absolute mouse position in pixels
|
---|
1701 | *
|
---|
1702 | * @returns VBox status code
|
---|
1703 | * @param absX New absolute X position
|
---|
1704 | * @param absY New absolute Y position
|
---|
1705 | */
|
---|
1706 | static DECLCALLBACK(int) vmmdevSetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t absX, uint32_t absY)
|
---|
1707 | {
|
---|
1708 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1709 | Log2(("vmmdevSetAbsoluteMouse: settings absolute position to x = %d, y = %d\n", absX, absY));
|
---|
1710 | pData->mouseXAbs = absX;
|
---|
1711 | pData->mouseYAbs = absY;
|
---|
1712 | return VINF_SUCCESS;
|
---|
1713 | }
|
---|
1714 |
|
---|
1715 | /**
|
---|
1716 | * Return the current mouse capability flags
|
---|
1717 | *
|
---|
1718 | * @returns VBox status code
|
---|
1719 | * @param pCapabilities Pointer of result value
|
---|
1720 | */
|
---|
1721 | static DECLCALLBACK(int) vmmdevQueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pCapabilities)
|
---|
1722 | {
|
---|
1723 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1724 | if (!pCapabilities)
|
---|
1725 | return VERR_INVALID_PARAMETER;
|
---|
1726 | *pCapabilities = pData->mouseCapabilities;
|
---|
1727 | return VINF_SUCCESS;
|
---|
1728 | }
|
---|
1729 |
|
---|
1730 | /**
|
---|
1731 | * Set the current mouse capability flag (host side)
|
---|
1732 | *
|
---|
1733 | * @returns VBox status code
|
---|
1734 | * @param capabilities Capability mask
|
---|
1735 | */
|
---|
1736 | static DECLCALLBACK(int) vmmdevSetMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t capabilities)
|
---|
1737 | {
|
---|
1738 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1739 |
|
---|
1740 | bool bCapsChanged = ((capabilities & VMMDEV_MOUSEHOSTWANTSABS)
|
---|
1741 | != (pData->mouseCapabilities & VMMDEV_MOUSEHOSTWANTSABS));
|
---|
1742 |
|
---|
1743 | Log(("vmmdevSetMouseCapabilities: bCapsChanged %d\n", bCapsChanged));
|
---|
1744 |
|
---|
1745 | if (capabilities & VMMDEV_MOUSEHOSTCANNOTHWPOINTER)
|
---|
1746 | pData->mouseCapabilities |= VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
|
---|
1747 | else
|
---|
1748 | pData->mouseCapabilities &= ~VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
|
---|
1749 |
|
---|
1750 | if (capabilities & VMMDEV_MOUSEHOSTWANTSABS)
|
---|
1751 | pData->mouseCapabilities |= VMMDEV_MOUSEHOSTWANTSABS;
|
---|
1752 | else
|
---|
1753 | pData->mouseCapabilities &= ~VMMDEV_MOUSEHOSTWANTSABS;
|
---|
1754 |
|
---|
1755 | if (bCapsChanged)
|
---|
1756 | VMMDevNotifyGuest (pData, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
|
---|
1757 |
|
---|
1758 | return VINF_SUCCESS;
|
---|
1759 | }
|
---|
1760 |
|
---|
1761 |
|
---|
1762 | static DECLCALLBACK(int) vmmdevRequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t xres, uint32_t yres, uint32_t bpp, uint32_t display)
|
---|
1763 | {
|
---|
1764 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1765 |
|
---|
1766 | /* Verify that the new resolution is different and that guest does not yet know about it. */
|
---|
1767 | bool fSameResolution = (!xres || (pData->lastReadDisplayChangeRequest.xres == xres)) &&
|
---|
1768 | (!yres || (pData->lastReadDisplayChangeRequest.yres == yres)) &&
|
---|
1769 | (!bpp || (pData->lastReadDisplayChangeRequest.bpp == bpp)) &&
|
---|
1770 | pData->lastReadDisplayChangeRequest.display == display;
|
---|
1771 |
|
---|
1772 | if (!xres && !yres && !bpp)
|
---|
1773 | {
|
---|
1774 | /* Special case of reset video mode. */
|
---|
1775 | fSameResolution = false;
|
---|
1776 | }
|
---|
1777 |
|
---|
1778 | Log3(("vmmdevRequestDisplayChange: same=%d. new: xres=%d, yres=%d, bpp=%d, display=%d. old: xres=%d, yres=%d, bpp=%d, display=%d.\n",
|
---|
1779 | fSameResolution, xres, yres, bpp, display, pData->lastReadDisplayChangeRequest.xres, pData->lastReadDisplayChangeRequest.yres, pData->lastReadDisplayChangeRequest.bpp, pData->lastReadDisplayChangeRequest.display));
|
---|
1780 |
|
---|
1781 | if (!fSameResolution)
|
---|
1782 | {
|
---|
1783 | LogRel(("VMMDev::SetVideoModeHint: got a video mode hint (%dx%dx%d) at %d\n",
|
---|
1784 | xres, yres, bpp, display));
|
---|
1785 |
|
---|
1786 | /* we could validate the information here but hey, the guest can do that as well! */
|
---|
1787 | pData->displayChangeRequest.xres = xres;
|
---|
1788 | pData->displayChangeRequest.yres = yres;
|
---|
1789 | pData->displayChangeRequest.bpp = bpp;
|
---|
1790 | pData->displayChangeRequest.display = display;
|
---|
1791 |
|
---|
1792 | /* IRQ so the guest knows what's going on */
|
---|
1793 | VMMDevNotifyGuest (pData, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
|
---|
1794 | }
|
---|
1795 |
|
---|
1796 | return VINF_SUCCESS;
|
---|
1797 | }
|
---|
1798 |
|
---|
1799 | static DECLCALLBACK(int) vmmdevRequestSeamlessChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
|
---|
1800 | {
|
---|
1801 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1802 |
|
---|
1803 | /* Verify that the new resolution is different and that guest does not yet know about it. */
|
---|
1804 | bool fSameMode = (pData->fLastSeamlessEnabled == fEnabled);
|
---|
1805 |
|
---|
1806 | Log(("vmmdevRequestSeamlessChange: same=%d. new=%d\n", fSameMode, fEnabled));
|
---|
1807 |
|
---|
1808 | if (!fSameMode)
|
---|
1809 | {
|
---|
1810 | /* we could validate the information here but hey, the guest can do that as well! */
|
---|
1811 | pData->fSeamlessEnabled = fEnabled;
|
---|
1812 |
|
---|
1813 | /* IRQ so the guest knows what's going on */
|
---|
1814 | VMMDevNotifyGuest (pData, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
|
---|
1815 | }
|
---|
1816 |
|
---|
1817 | return VINF_SUCCESS;
|
---|
1818 | }
|
---|
1819 |
|
---|
1820 | static DECLCALLBACK(int) vmmdevSetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t ulBalloonSize)
|
---|
1821 | {
|
---|
1822 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1823 |
|
---|
1824 | /* Verify that the new resolution is different and that guest does not yet know about it. */
|
---|
1825 | bool fSame = (pData->u32LastMemoryBalloonSize == ulBalloonSize);
|
---|
1826 |
|
---|
1827 | Log(("vmmdevSetMemoryBalloon: old=%d. new=%d\n", pData->u32LastMemoryBalloonSize, ulBalloonSize));
|
---|
1828 |
|
---|
1829 | if (!fSame)
|
---|
1830 | {
|
---|
1831 | /* we could validate the information here but hey, the guest can do that as well! */
|
---|
1832 | pData->u32MemoryBalloonSize = ulBalloonSize;
|
---|
1833 |
|
---|
1834 | /* IRQ so the guest knows what's going on */
|
---|
1835 | VMMDevNotifyGuest (pData, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
|
---|
1836 | }
|
---|
1837 |
|
---|
1838 | return VINF_SUCCESS;
|
---|
1839 | }
|
---|
1840 |
|
---|
1841 | static DECLCALLBACK(int) vmmdevVRDPChange(PPDMIVMMDEVPORT pInterface, bool fVRDPEnabled, uint32_t u32VRDPExperienceLevel)
|
---|
1842 | {
|
---|
1843 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1844 |
|
---|
1845 | bool fSame = (pData->fVRDPEnabled == fVRDPEnabled);
|
---|
1846 |
|
---|
1847 | Log(("vmmdevVRDPChange: old=%d. new=%d\n", pData->fVRDPEnabled, fVRDPEnabled));
|
---|
1848 |
|
---|
1849 | if (!fSame)
|
---|
1850 | {
|
---|
1851 | pData->fVRDPEnabled = fVRDPEnabled;
|
---|
1852 | pData->u32VRDPExperienceLevel = u32VRDPExperienceLevel;
|
---|
1853 |
|
---|
1854 | VMMDevNotifyGuest (pData, VMMDEV_EVENT_VRDP);
|
---|
1855 | }
|
---|
1856 |
|
---|
1857 | return VINF_SUCCESS;
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | static DECLCALLBACK(int) vmmdevSetStatisticsInterval(PPDMIVMMDEVPORT pInterface, uint32_t ulStatInterval)
|
---|
1861 | {
|
---|
1862 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1863 |
|
---|
1864 | /* Verify that the new resolution is different and that guest does not yet know about it. */
|
---|
1865 | bool fSame = (pData->u32LastStatIntervalSize == ulStatInterval);
|
---|
1866 |
|
---|
1867 | Log(("vmmdevSetStatisticsInterval: old=%d. new=%d\n", pData->u32LastStatIntervalSize, ulStatInterval));
|
---|
1868 |
|
---|
1869 | if (!fSame)
|
---|
1870 | {
|
---|
1871 | /* we could validate the information here but hey, the guest can do that as well! */
|
---|
1872 | pData->u32StatIntervalSize = ulStatInterval;
|
---|
1873 |
|
---|
1874 | /* IRQ so the guest knows what's going on */
|
---|
1875 | VMMDevNotifyGuest (pData, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
|
---|
1876 | }
|
---|
1877 |
|
---|
1878 | return VINF_SUCCESS;
|
---|
1879 | }
|
---|
1880 |
|
---|
1881 |
|
---|
1882 | static DECLCALLBACK(int) vmmdevSetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
|
---|
1883 | const char *pszPassword, const char *pszDomain,
|
---|
1884 | uint32_t u32Flags)
|
---|
1885 | {
|
---|
1886 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1887 |
|
---|
1888 | /* logon mode? */
|
---|
1889 | if (u32Flags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
|
---|
1890 | {
|
---|
1891 | /* memorize the data */
|
---|
1892 | strcpy(pData->credentialsLogon.szUserName, pszUsername);
|
---|
1893 | strcpy(pData->credentialsLogon.szPassword, pszPassword);
|
---|
1894 | strcpy(pData->credentialsLogon.szDomain, pszDomain);
|
---|
1895 | pData->credentialsLogon.fAllowInteractiveLogon = !(u32Flags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
|
---|
1896 | }
|
---|
1897 | /* credentials verification mode? */
|
---|
1898 | else if (u32Flags & VMMDEV_SETCREDENTIALS_JUDGE)
|
---|
1899 | {
|
---|
1900 | /* memorize the data */
|
---|
1901 | strcpy(pData->credentialsJudge.szUserName, pszUsername);
|
---|
1902 | strcpy(pData->credentialsJudge.szPassword, pszPassword);
|
---|
1903 | strcpy(pData->credentialsJudge.szDomain, pszDomain);
|
---|
1904 |
|
---|
1905 | VMMDevNotifyGuest (pData, VMMDEV_EVENT_JUDGE_CREDENTIALS);
|
---|
1906 | }
|
---|
1907 | else
|
---|
1908 | return VERR_INVALID_PARAMETER;
|
---|
1909 |
|
---|
1910 | return VINF_SUCCESS;
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | /**
|
---|
1914 | * Notification from the Display. Especially useful when
|
---|
1915 | * acceleration is disabled after a video mode change.
|
---|
1916 | *
|
---|
1917 | * @param fEnable Current acceleration status.
|
---|
1918 | */
|
---|
1919 | static DECLCALLBACK(void) vmmdevVBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
|
---|
1920 | {
|
---|
1921 | VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
|
---|
1922 |
|
---|
1923 | Log(("vmmdevVBVAChange: fEnabled = %d\n", fEnabled));
|
---|
1924 |
|
---|
1925 | if (pData)
|
---|
1926 | {
|
---|
1927 | pData->u32VideoAccelEnabled = fEnabled;
|
---|
1928 | }
|
---|
1929 |
|
---|
1930 | return;
|
---|
1931 | }
|
---|
1932 |
|
---|
1933 |
|
---|
1934 | /* -=-=-=-=-=- IHGCMPort -=-=-=-=-=- */
|
---|
1935 |
|
---|
1936 | /** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
|
---|
1937 | #define IHGCMPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, HGCMPort)) )
|
---|
1938 |
|
---|
1939 |
|
---|
1940 |
|
---|
1941 | #define VMMDEV_SSM_VERSION 6
|
---|
1942 |
|
---|
1943 | /**
|
---|
1944 | * Saves a state of the VMM device.
|
---|
1945 | *
|
---|
1946 | * @returns VBox status code.
|
---|
1947 | * @param pDevIns The device instance.
|
---|
1948 | * @param pSSMHandle The handle to save the state to.
|
---|
1949 | */
|
---|
1950 | static DECLCALLBACK(int) vmmdevSaveState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
|
---|
1951 | {
|
---|
1952 | VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
|
---|
1953 | SSMR3PutU32(pSSMHandle, pData->hypervisorSize);
|
---|
1954 | SSMR3PutU32(pSSMHandle, pData->mouseCapabilities);
|
---|
1955 | SSMR3PutU32(pSSMHandle, pData->mouseXAbs);
|
---|
1956 | SSMR3PutU32(pSSMHandle, pData->mouseYAbs);
|
---|
1957 |
|
---|
1958 | SSMR3PutBool(pSSMHandle, pData->fNewGuestFilterMask);
|
---|
1959 | SSMR3PutU32(pSSMHandle, pData->u32NewGuestFilterMask);
|
---|
1960 | SSMR3PutU32(pSSMHandle, pData->u32GuestFilterMask);
|
---|
1961 | SSMR3PutU32(pSSMHandle, pData->u32HostEventFlags);
|
---|
1962 | // here be dragons (probably)
|
---|
1963 | // SSMR3PutBool(pSSMHandle, pData->pVMMDevRAMHC->V.V1_04.fHaveEvents);
|
---|
1964 | SSMR3PutMem(pSSMHandle, &pData->pVMMDevRAMHC->V, sizeof (pData->pVMMDevRAMHC->V));
|
---|
1965 |
|
---|
1966 | SSMR3PutMem(pSSMHandle, &pData->guestInfo, sizeof (pData->guestInfo));
|
---|
1967 | SSMR3PutU32(pSSMHandle, pData->fu32AdditionsOk);
|
---|
1968 | SSMR3PutU32(pSSMHandle, pData->u32VideoAccelEnabled);
|
---|
1969 |
|
---|
1970 | SSMR3PutU32(pSSMHandle, pData->guestCaps);
|
---|
1971 |
|
---|
1972 | #ifdef VBOX_HGCM
|
---|
1973 | vmmdevHGCMSaveState (pData, pSSMHandle);
|
---|
1974 | #endif /* VBOX_HGCM */
|
---|
1975 |
|
---|
1976 | return VINF_SUCCESS;
|
---|
1977 | }
|
---|
1978 |
|
---|
1979 | /**
|
---|
1980 | * Loads the saved VMM device state.
|
---|
1981 | *
|
---|
1982 | * @returns VBox status code.
|
---|
1983 | * @param pDevIns The device instance.
|
---|
1984 | * @param pSSMHandle The handle to the saved state.
|
---|
1985 | * @param u32Version The data unit version number.
|
---|
1986 | */
|
---|
1987 | static DECLCALLBACK(int) vmmdevLoadState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t u32Version)
|
---|
1988 | {
|
---|
1989 | VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
|
---|
1990 | if (u32Version != VMMDEV_SSM_VERSION)
|
---|
1991 | return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
|
---|
1992 | SSMR3GetU32(pSSMHandle, &pData->hypervisorSize);
|
---|
1993 | SSMR3GetU32(pSSMHandle, &pData->mouseCapabilities);
|
---|
1994 | SSMR3GetU32(pSSMHandle, &pData->mouseXAbs);
|
---|
1995 | SSMR3GetU32(pSSMHandle, &pData->mouseYAbs);
|
---|
1996 |
|
---|
1997 | SSMR3GetBool(pSSMHandle, &pData->fNewGuestFilterMask);
|
---|
1998 | SSMR3GetU32(pSSMHandle, &pData->u32NewGuestFilterMask);
|
---|
1999 | SSMR3GetU32(pSSMHandle, &pData->u32GuestFilterMask);
|
---|
2000 | SSMR3GetU32(pSSMHandle, &pData->u32HostEventFlags);
|
---|
2001 | // SSMR3GetBool(pSSMHandle, &pData->pVMMDevRAMHC->fHaveEvents);
|
---|
2002 | // here be dragons (probably)
|
---|
2003 | SSMR3GetMem(pSSMHandle, &pData->pVMMDevRAMHC->V, sizeof (pData->pVMMDevRAMHC->V));
|
---|
2004 |
|
---|
2005 | SSMR3GetMem(pSSMHandle, &pData->guestInfo, sizeof (pData->guestInfo));
|
---|
2006 | SSMR3GetU32(pSSMHandle, &pData->fu32AdditionsOk);
|
---|
2007 | SSMR3GetU32(pSSMHandle, &pData->u32VideoAccelEnabled);
|
---|
2008 |
|
---|
2009 | SSMR3GetU32(pSSMHandle, &pData->guestCaps);
|
---|
2010 |
|
---|
2011 | #ifdef VBOX_HGCM
|
---|
2012 | vmmdevHGCMLoadState (pData, pSSMHandle);
|
---|
2013 | #endif /* VBOX_HGCM */
|
---|
2014 |
|
---|
2015 | /*
|
---|
2016 | * On a resume, we send the capabilities changed message so
|
---|
2017 | * that listeners can sync their state again
|
---|
2018 | */
|
---|
2019 | Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
|
---|
2020 | if (pData->pDrv)
|
---|
2021 | pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
|
---|
2022 |
|
---|
2023 | /* Reestablish the acceleration status. */
|
---|
2024 | if ( pData->u32VideoAccelEnabled
|
---|
2025 | && pData->pDrv)
|
---|
2026 | {
|
---|
2027 | pData->pDrv->pfnVideoAccelEnable (pData->pDrv, !!pData->u32VideoAccelEnabled, &pData->pVMMDevRAMHC->vbvaMemory);
|
---|
2028 | }
|
---|
2029 |
|
---|
2030 | if (pData->fu32AdditionsOk)
|
---|
2031 | {
|
---|
2032 | LogRel(("Guest Additions information report: additionsVersion = 0x%08X osType = 0x%08X\n",
|
---|
2033 | pData->guestInfo.additionsVersion,
|
---|
2034 | pData->guestInfo.osType));
|
---|
2035 | if (pData->pDrv)
|
---|
2036 | pData->pDrv->pfnUpdateGuestVersion(pData->pDrv, &pData->guestInfo);
|
---|
2037 | }
|
---|
2038 | if (pData->pDrv)
|
---|
2039 | pData->pDrv->pfnUpdateGuestCapabilities(pData->pDrv, pData->guestCaps);
|
---|
2040 |
|
---|
2041 | return VINF_SUCCESS;
|
---|
2042 | }
|
---|
2043 |
|
---|
2044 | /**
|
---|
2045 | * Load state done callback. Notify guest of restore event.
|
---|
2046 | *
|
---|
2047 | * @returns VBox status code.
|
---|
2048 | * @param pDevIns The device instance.
|
---|
2049 | * @param pSSMHandle The handle to the saved state.
|
---|
2050 | */
|
---|
2051 | static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
|
---|
2052 | {
|
---|
2053 | VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
|
---|
2054 |
|
---|
2055 | #ifdef VBOX_HGCM
|
---|
2056 | vmmdevHGCMLoadStateDone (pData, pSSMHandle);
|
---|
2057 | #endif /* VBOX_HGCM */
|
---|
2058 |
|
---|
2059 | VMMDevNotifyGuest (pData, VMMDEV_EVENT_RESTORED);
|
---|
2060 |
|
---|
2061 | return VINF_SUCCESS;
|
---|
2062 | }
|
---|
2063 |
|
---|
2064 | /**
|
---|
2065 | * Construct a device instance for a VM.
|
---|
2066 | *
|
---|
2067 | * @returns VBox status.
|
---|
2068 | * @param pDevIns The device instance data.
|
---|
2069 | * If the registration structure is needed, pDevIns->pDevReg points to it.
|
---|
2070 | * @param iInstance Instance number. Use this to figure out which registers and such to use.
|
---|
2071 | * The device number is also found in pDevIns->iInstance, but since it's
|
---|
2072 | * likely to be freqently used PDM passes it as parameter.
|
---|
2073 | * @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
|
---|
2074 | * of the device instance. It's also found in pDevIns->pCfgHandle, but like
|
---|
2075 | * iInstance it's expected to be used a bit in this function.
|
---|
2076 | */
|
---|
2077 | static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfgHandle)
|
---|
2078 | {
|
---|
2079 | int rc;
|
---|
2080 | VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState *);
|
---|
2081 |
|
---|
2082 | Assert(iInstance == 0);
|
---|
2083 |
|
---|
2084 | /*
|
---|
2085 | * Validate and read the configuration.
|
---|
2086 | */
|
---|
2087 | if (!CFGMR3AreValuesValid(pCfgHandle, "GetHostTimeDisabled\0BackdoorLogDisabled\0"))
|
---|
2088 | return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
|
---|
2089 |
|
---|
2090 | rc = CFGMR3QueryBool(pCfgHandle, "GetHostTimeDisabled", &pData->fGetHostTimeDisabled);
|
---|
2091 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
2092 | pData->fGetHostTimeDisabled = false;
|
---|
2093 | else if (VBOX_FAILURE(rc))
|
---|
2094 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
2095 | N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
|
---|
2096 |
|
---|
2097 | rc = CFGMR3QueryBool(pCfgHandle, "BackdoorLogDisabled", &pData->fBackdoorLogDisabled);
|
---|
2098 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
2099 | pData->fBackdoorLogDisabled = false;
|
---|
2100 | else if (VBOX_FAILURE(rc))
|
---|
2101 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
2102 | N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
|
---|
2103 |
|
---|
2104 | /*
|
---|
2105 | * Initialize data (most of it anyway).
|
---|
2106 | */
|
---|
2107 | /* Save PDM device instance data for future reference. */
|
---|
2108 | pData->pDevIns = pDevIns;
|
---|
2109 |
|
---|
2110 | /* PCI vendor, just a free bogus value */
|
---|
2111 | pData->dev.config[0x00] = 0xee;
|
---|
2112 | pData->dev.config[0x01] = 0x80;
|
---|
2113 | /* device ID */
|
---|
2114 | pData->dev.config[0x02] = 0xfe;
|
---|
2115 | pData->dev.config[0x03] = 0xca;
|
---|
2116 | /* class sub code (other type of system peripheral) */
|
---|
2117 | pData->dev.config[0x0a] = 0x80;
|
---|
2118 | /* class base code (base system peripheral) */
|
---|
2119 | pData->dev.config[0x0b] = 0x08;
|
---|
2120 | /* header type */
|
---|
2121 | pData->dev.config[0x0e] = 0x00;
|
---|
2122 | /* interrupt on pin 0 */
|
---|
2123 | pData->dev.config[0x3d] = 0x01;
|
---|
2124 |
|
---|
2125 | /*
|
---|
2126 | * Register the backdoor logging port
|
---|
2127 | */
|
---|
2128 | rc = PDMDevHlpIOPortRegister(pDevIns, RTLOG_DEBUG_PORT, 1, NULL, vmmdevBackdoorLog, NULL, NULL, NULL, "VMMDev backdoor logging");
|
---|
2129 | AssertRCReturn(rc, rc);
|
---|
2130 |
|
---|
2131 | #ifdef TIMESYNC_BACKDOOR
|
---|
2132 | /*
|
---|
2133 | * Alternative timesync source (temporary!)
|
---|
2134 | */
|
---|
2135 | rc = PDMDevHlpIOPortRegister(pDevIns, 0x505, 1, NULL, vmmdevTimesyncBackdoorWrite, vmmdevTimesyncBackdoorRead, NULL, NULL, "VMMDev timesync backdoor");
|
---|
2136 | AssertRCReturn(rc, rc);
|
---|
2137 | #endif
|
---|
2138 |
|
---|
2139 | /*
|
---|
2140 | * Register the PCI device.
|
---|
2141 | */
|
---|
2142 | rc = PDMDevHlpPCIRegister(pDevIns, &pData->dev);
|
---|
2143 | if (VBOX_FAILURE(rc))
|
---|
2144 | return rc;
|
---|
2145 | if (pData->dev.devfn == 32 || iInstance != 0)
|
---|
2146 | Log(("!!WARNING!!: pData->dev.devfn=%d (ignore if testcase or no started by Main)\n", pData->dev.devfn));
|
---|
2147 | rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 0x20, PCI_ADDRESS_SPACE_IO, vmmdevIOPortRegionMap);
|
---|
2148 | if (VBOX_FAILURE(rc))
|
---|
2149 | return rc;
|
---|
2150 | rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, vmmdevIORAMRegionMap);
|
---|
2151 | if (VBOX_FAILURE(rc))
|
---|
2152 | return rc;
|
---|
2153 |
|
---|
2154 | /*
|
---|
2155 | * Interfaces
|
---|
2156 | */
|
---|
2157 | /* Base */
|
---|
2158 | pData->Base.pfnQueryInterface = vmmdevPortQueryInterface;
|
---|
2159 |
|
---|
2160 | /* VMMDev port */
|
---|
2161 | pData->Port.pfnQueryAbsoluteMouse = vmmdevQueryAbsoluteMouse;
|
---|
2162 | pData->Port.pfnSetAbsoluteMouse = vmmdevSetAbsoluteMouse;
|
---|
2163 | pData->Port.pfnQueryMouseCapabilities = vmmdevQueryMouseCapabilities;
|
---|
2164 | pData->Port.pfnSetMouseCapabilities = vmmdevSetMouseCapabilities;
|
---|
2165 | pData->Port.pfnRequestDisplayChange = vmmdevRequestDisplayChange;
|
---|
2166 | pData->Port.pfnSetCredentials = vmmdevSetCredentials;
|
---|
2167 | pData->Port.pfnVBVAChange = vmmdevVBVAChange;
|
---|
2168 | pData->Port.pfnRequestSeamlessChange = vmmdevRequestSeamlessChange;
|
---|
2169 | pData->Port.pfnSetMemoryBalloon = vmmdevSetMemoryBalloon;
|
---|
2170 | pData->Port.pfnSetStatisticsInterval = vmmdevSetStatisticsInterval;
|
---|
2171 | pData->Port.pfnVRDPChange = vmmdevVRDPChange;
|
---|
2172 |
|
---|
2173 | /* Shared folder LED */
|
---|
2174 | pData->SharedFolders.Led.u32Magic = PDMLED_MAGIC;
|
---|
2175 | pData->SharedFolders.ILeds.pfnQueryStatusLed = vmmdevQueryStatusLed;
|
---|
2176 |
|
---|
2177 | #ifdef VBOX_HGCM
|
---|
2178 | /* HGCM port */
|
---|
2179 | pData->HGCMPort.pfnCompleted = hgcmCompleted;
|
---|
2180 | #endif
|
---|
2181 |
|
---|
2182 | /*
|
---|
2183 | * Get the corresponding connector interface
|
---|
2184 | */
|
---|
2185 | rc = PDMDevHlpDriverAttach(pDevIns, 0, &pData->Base, &pData->pDrvBase, "VMM Driver Port");
|
---|
2186 | if (VBOX_SUCCESS(rc))
|
---|
2187 | {
|
---|
2188 | pData->pDrv = (PPDMIVMMDEVCONNECTOR)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_VMMDEV_CONNECTOR);
|
---|
2189 | if (!pData->pDrv)
|
---|
2190 | AssertMsgFailedReturn(("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
|
---|
2191 | #ifdef VBOX_HGCM
|
---|
2192 | pData->pHGCMDrv = (PPDMIHGCMCONNECTOR)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_HGCM_CONNECTOR);
|
---|
2193 | if (!pData->pHGCMDrv)
|
---|
2194 | {
|
---|
2195 | Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Vrc\n", rc));
|
---|
2196 | /* this is not actually an error, just means that there is no support for HGCM */
|
---|
2197 | }
|
---|
2198 | #endif
|
---|
2199 | }
|
---|
2200 | else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
|
---|
2201 | {
|
---|
2202 | Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
|
---|
2203 | rc = VINF_SUCCESS;
|
---|
2204 | }
|
---|
2205 | else
|
---|
2206 | AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Vrc\n", rc), rc);
|
---|
2207 |
|
---|
2208 | /*
|
---|
2209 | * Attach status driver for shared folders (optional).
|
---|
2210 | */
|
---|
2211 | PPDMIBASE pBase;
|
---|
2212 | rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pData->Base, &pBase, "Status Port");
|
---|
2213 | if (VBOX_SUCCESS(rc))
|
---|
2214 | pData->SharedFolders.pLedsConnector = (PPDMILEDCONNECTORS)
|
---|
2215 | pBase->pfnQueryInterface(pBase, PDMINTERFACE_LED_CONNECTORS);
|
---|
2216 | else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
|
---|
2217 | {
|
---|
2218 | AssertMsgFailed(("Failed to attach to status driver. rc=%Vrc\n", rc));
|
---|
2219 | return rc;
|
---|
2220 | }
|
---|
2221 |
|
---|
2222 | /*
|
---|
2223 | * Register saved state and init the HGCM CmdList critsect.
|
---|
2224 | */
|
---|
2225 | rc = PDMDevHlpSSMRegister(pDevIns, "VMMDev", iInstance, VMMDEV_SSM_VERSION, sizeof(*pData),
|
---|
2226 | NULL, vmmdevSaveState, NULL,
|
---|
2227 | NULL, vmmdevLoadState, vmmdevLoadStateDone);
|
---|
2228 | AssertRCReturn(rc, rc);
|
---|
2229 |
|
---|
2230 | #ifdef VBOX_HGCM
|
---|
2231 | pData->pHGCMCmdList = NULL;
|
---|
2232 | rc = RTCritSectInit(&pData->critsectHGCMCmdList);
|
---|
2233 | AssertRCReturn(rc, rc);
|
---|
2234 | pData->u32HGCMEnabled = 0;
|
---|
2235 | #endif /* VBOX_HGCM */
|
---|
2236 |
|
---|
2237 | /*
|
---|
2238 | * Allocate the VMMDev RAM region.
|
---|
2239 | */
|
---|
2240 | /** @todo freeing of the RAM. */
|
---|
2241 | rc = SUPPageAlloc(VMMDEV_RAM_SIZE >> PAGE_SHIFT, (void **)&pData->pVMMDevRAMHC);
|
---|
2242 | AssertMsgRCReturn(rc, ("VMMDev SUPPageAlloc(%#x,) -> %Vrc\n", VMMDEV_RAM_SIZE, rc), rc);
|
---|
2243 |
|
---|
2244 | /* initialize the VMMDev memory */
|
---|
2245 | pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
|
---|
2246 | pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
|
---|
2247 |
|
---|
2248 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
2249 | pData->u64GuestRAMSize = MMR3PhysGetRamSize(pVM);
|
---|
2250 | return rc;
|
---|
2251 | }
|
---|
2252 |
|
---|
2253 | /**
|
---|
2254 | * Reset notification.
|
---|
2255 | *
|
---|
2256 | * @returns VBox status.
|
---|
2257 | * @param pDrvIns The driver instance data.
|
---|
2258 | */
|
---|
2259 | static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
|
---|
2260 | {
|
---|
2261 | VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
|
---|
2262 | /*
|
---|
2263 | * Reset the mouse integration feature bit
|
---|
2264 | */
|
---|
2265 | if (pData->mouseCapabilities & (VMMDEV_MOUSEGUESTWANTSABS|VMMDEV_MOUSEGUESTNEEDSHOSTCUR))
|
---|
2266 | {
|
---|
2267 | pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTWANTSABS;
|
---|
2268 | /* notify the connector */
|
---|
2269 | Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
|
---|
2270 | pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
|
---|
2271 | }
|
---|
2272 |
|
---|
2273 | pData->hypervisorSize = 0;
|
---|
2274 |
|
---|
2275 | pData->u32HostEventFlags = 0;
|
---|
2276 |
|
---|
2277 | if (pData->pVMMDevRAMHC)
|
---|
2278 | {
|
---|
2279 | /* re-initialize the VMMDev memory */
|
---|
2280 | memset (pData->pVMMDevRAMHC, 0, VMMDEV_RAM_SIZE);
|
---|
2281 | pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
|
---|
2282 | pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
|
---|
2283 | }
|
---|
2284 |
|
---|
2285 | /* credentials have to go away */
|
---|
2286 | memset(pData->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
2287 | memset(pData->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
2288 | memset(pData->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
2289 | memset(pData->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
2290 | memset(pData->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
2291 | memset(pData->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
|
---|
2292 |
|
---|
2293 | /* Reset means that additions will report again. */
|
---|
2294 | pData->fu32AdditionsOk = false;
|
---|
2295 | memset (&pData->guestInfo, 0, sizeof (pData->guestInfo));
|
---|
2296 | pData->guestCaps = 0;
|
---|
2297 |
|
---|
2298 | memset (&pData->lastReadDisplayChangeRequest, 0, sizeof (pData->lastReadDisplayChangeRequest));
|
---|
2299 |
|
---|
2300 | /* disable seamless mode */
|
---|
2301 | pData->fLastSeamlessEnabled = false;
|
---|
2302 |
|
---|
2303 | /* disabled memory ballooning */
|
---|
2304 | pData->u32LastMemoryBalloonSize = 0;
|
---|
2305 |
|
---|
2306 | /* disabled statistics updating */
|
---|
2307 | pData->u32LastStatIntervalSize = 0;
|
---|
2308 |
|
---|
2309 | /* Clear the event variables.
|
---|
2310 | *
|
---|
2311 | * Note: The pData->u32HostEventFlags is not cleared.
|
---|
2312 | * It is designed that way so host events do not
|
---|
2313 | * depend on guest resets.
|
---|
2314 | */
|
---|
2315 | pData->u32GuestFilterMask = 0;
|
---|
2316 | pData->u32NewGuestFilterMask = 0;
|
---|
2317 | pData->fNewGuestFilterMask = 0;
|
---|
2318 | }
|
---|
2319 |
|
---|
2320 |
|
---|
2321 | /**
|
---|
2322 | * The device registration structure.
|
---|
2323 | */
|
---|
2324 | extern "C" const PDMDEVREG g_DeviceVMMDev =
|
---|
2325 | {
|
---|
2326 | /* u32Version */
|
---|
2327 | PDM_DEVREG_VERSION,
|
---|
2328 | /* szDeviceName */
|
---|
2329 | "VMMDev",
|
---|
2330 | /* szGCMod */
|
---|
2331 | "",
|
---|
2332 | /* szR0Mod */
|
---|
2333 | "",
|
---|
2334 | /* pszDescription */
|
---|
2335 | "VirtualBox VMM Device\n",
|
---|
2336 | /* fFlags */
|
---|
2337 | PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32,
|
---|
2338 | /* fClass */
|
---|
2339 | PDM_DEVREG_CLASS_VMM_DEV,
|
---|
2340 | /* cMaxInstances */
|
---|
2341 | 1,
|
---|
2342 | /* cbInstance */
|
---|
2343 | sizeof(VMMDevState),
|
---|
2344 | /* pfnConstruct */
|
---|
2345 | vmmdevConstruct,
|
---|
2346 | /* pfnDestruct */
|
---|
2347 | NULL,
|
---|
2348 | /* pfnRelocate */
|
---|
2349 | NULL,
|
---|
2350 | /* pfnIOCtl */
|
---|
2351 | NULL,
|
---|
2352 | /* pfnPowerOn */
|
---|
2353 | NULL,
|
---|
2354 | /* pfnReset */
|
---|
2355 | vmmdevReset,
|
---|
2356 | /* pfnSuspend */
|
---|
2357 | NULL,
|
---|
2358 | /* pfnResume */
|
---|
2359 | NULL,
|
---|
2360 | /* pfnAttach */
|
---|
2361 | NULL,
|
---|
2362 | /* pfnDetach */
|
---|
2363 | NULL,
|
---|
2364 | /* pfnQueryInterface. */
|
---|
2365 | NULL
|
---|
2366 | };
|
---|
2367 | #endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
|
---|
2368 |
|
---|