1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxGuest -- VirtualBox Win32 guest support driver PnP code
|
---|
4 | *
|
---|
5 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
6 | *
|
---|
7 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | * available from http://www.virtualbox.org. This file is free software;
|
---|
9 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | * General Public License (GPL) as published by the Free Software
|
---|
11 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | *
|
---|
15 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
16 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
17 | * additional information or have any questions.
|
---|
18 | */
|
---|
19 |
|
---|
20 | // enable backdoor logging
|
---|
21 | //#define LOG_ENABLED
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include "VBoxGuestPnP.h"
|
---|
27 | #include "Helper.h"
|
---|
28 | #include <VBox/err.h>
|
---|
29 |
|
---|
30 | #include <VBox/VBoxGuestLib.h>
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Defined Constants And Macros *
|
---|
34 | *******************************************************************************/
|
---|
35 |
|
---|
36 |
|
---|
37 | extern "C"
|
---|
38 | {
|
---|
39 | static NTSTATUS sendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict);
|
---|
40 | static NTSTATUS pnpIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT event);
|
---|
41 | static VOID showDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList);
|
---|
42 | }
|
---|
43 |
|
---|
44 | #ifdef ALLOC_PRAGMA
|
---|
45 | #pragma alloc_text (PAGE, VBoxGuestPnP)
|
---|
46 | #pragma alloc_text (PAGE, VBoxGuestPower)
|
---|
47 | #pragma alloc_text (PAGE, sendIrpSynchronously)
|
---|
48 | #pragma alloc_text (PAGE, showDeviceResources)
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | /* reenable logging, this was #undef'ed on iprt/log.h for RING0 */
|
---|
52 | #define LOG_ENABLED
|
---|
53 |
|
---|
54 | /*******************************************************************************
|
---|
55 | * Internal Functions *
|
---|
56 | *******************************************************************************/
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Irp completion routine for PnP Irps we send.
|
---|
60 | *
|
---|
61 | * @param pDevObj Device object.
|
---|
62 | * @param pIrp Request packet.
|
---|
63 | * @param event Semaphore.
|
---|
64 | * @return NT status code
|
---|
65 | */
|
---|
66 | static NTSTATUS pnpIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT event)
|
---|
67 | {
|
---|
68 | KeSetEvent(event, 0, FALSE);
|
---|
69 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Helper to send a PnP IRP and wait until it's done.
|
---|
74 | *
|
---|
75 | * @param pDevObj Device object.
|
---|
76 | * @param pIrp Request packet.
|
---|
77 | * @param fStrict When set, returns an error if the IRP gives an error.
|
---|
78 | * @return NT status code
|
---|
79 | */
|
---|
80 | static NTSTATUS sendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict)
|
---|
81 | {
|
---|
82 | KEVENT event;
|
---|
83 |
|
---|
84 | KeInitializeEvent(&event, SynchronizationEvent, FALSE);
|
---|
85 |
|
---|
86 | IoCopyCurrentIrpStackLocationToNext(pIrp);
|
---|
87 | IoSetCompletionRoutine(pIrp, (PIO_COMPLETION_ROUTINE)pnpIrpComplete, &event, TRUE, TRUE, TRUE);
|
---|
88 |
|
---|
89 | NTSTATUS rc = IoCallDriver(pDevObj, pIrp);
|
---|
90 |
|
---|
91 | if (rc == STATUS_PENDING)
|
---|
92 | {
|
---|
93 | KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
|
---|
94 | rc = pIrp->IoStatus.Status;
|
---|
95 | }
|
---|
96 |
|
---|
97 | if (!fStrict
|
---|
98 | && (rc == STATUS_NOT_SUPPORTED || rc == STATUS_INVALID_DEVICE_REQUEST))
|
---|
99 | {
|
---|
100 | rc = STATUS_SUCCESS;
|
---|
101 | }
|
---|
102 |
|
---|
103 | dprintf(("VBoxGuest::sendIrpSynchronously: returning 0x%x\n", rc));
|
---|
104 |
|
---|
105 | return rc;
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * PnP Request handler.
|
---|
111 | *
|
---|
112 | * @param pDevObj Device object.
|
---|
113 | * @param pIrp Request packet.
|
---|
114 | */
|
---|
115 | NTSTATUS VBoxGuestPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp)
|
---|
116 | {
|
---|
117 | PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
|
---|
118 | PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
|
---|
119 | NTSTATUS rc = STATUS_SUCCESS;
|
---|
120 |
|
---|
121 | #ifdef LOG_ENABLED
|
---|
122 | static char* fcnname[] =
|
---|
123 | {
|
---|
124 | "IRP_MN_START_DEVICE",
|
---|
125 | "IRP_MN_QUERY_REMOVE_DEVICE",
|
---|
126 | "IRP_MN_REMOVE_DEVICE",
|
---|
127 | "IRP_MN_CANCEL_REMOVE_DEVICE",
|
---|
128 | "IRP_MN_STOP_DEVICE",
|
---|
129 | "IRP_MN_QUERY_STOP_DEVICE",
|
---|
130 | "IRP_MN_CANCEL_STOP_DEVICE",
|
---|
131 | "IRP_MN_QUERY_DEVICE_RELATIONS",
|
---|
132 | "IRP_MN_QUERY_INTERFACE",
|
---|
133 | "IRP_MN_QUERY_CAPABILITIES",
|
---|
134 | "IRP_MN_QUERY_RESOURCES",
|
---|
135 | "IRP_MN_QUERY_RESOURCE_REQUIREMENTS",
|
---|
136 | "IRP_MN_QUERY_DEVICE_TEXT",
|
---|
137 | "IRP_MN_FILTER_RESOURCE_REQUIREMENTS",
|
---|
138 | "",
|
---|
139 | "IRP_MN_READ_CONFIG",
|
---|
140 | "IRP_MN_WRITE_CONFIG",
|
---|
141 | "IRP_MN_EJECT",
|
---|
142 | "IRP_MN_SET_LOCK",
|
---|
143 | "IRP_MN_QUERY_ID",
|
---|
144 | "IRP_MN_QUERY_PNP_DEVICE_STATE",
|
---|
145 | "IRP_MN_QUERY_BUS_INFORMATION",
|
---|
146 | "IRP_MN_DEVICE_USAGE_NOTIFICATION",
|
---|
147 | "IRP_MN_SURPRISE_REMOVAL",
|
---|
148 | };
|
---|
149 | dprintf(("VBoxGuest::VBoxGuestPnp: MinorFunction: %s\n", pStack->MinorFunction < (sizeof(fcnname)/sizeof(fcnname[0])) ? fcnname[pStack->MinorFunction] : "unknown"));
|
---|
150 | #endif
|
---|
151 | switch (pStack->MinorFunction)
|
---|
152 | {
|
---|
153 | case IRP_MN_START_DEVICE:
|
---|
154 | {
|
---|
155 | rc = sendIrpSynchronously(pDevExt->nextLowerDriver, pIrp, TRUE);
|
---|
156 |
|
---|
157 | if (NT_SUCCESS(rc) && NT_SUCCESS(pIrp->IoStatus.Status))
|
---|
158 | {
|
---|
159 | dprintf(("VBoxGuest::START_DEVICE: pStack->Parameters.StartDevice.AllocatedResources = %p\n", pStack->Parameters.StartDevice.AllocatedResources));
|
---|
160 |
|
---|
161 | if (!pStack->Parameters.StartDevice.AllocatedResources)
|
---|
162 | {
|
---|
163 | dprintf(("VBoxGuest::START_DEVICE: no resources, pDevExt = %p, nextLowerDriver = %p!!!\n", pDevExt, pDevExt? pDevExt->nextLowerDriver: NULL));
|
---|
164 | rc = STATUS_UNSUCCESSFUL;
|
---|
165 | }
|
---|
166 | else
|
---|
167 | {
|
---|
168 | showDeviceResources(&pStack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList);
|
---|
169 |
|
---|
170 | VBoxScanPCIResourceList(pStack->Parameters.StartDevice.AllocatedResourcesTranslated,
|
---|
171 | pDevExt);
|
---|
172 |
|
---|
173 | /** @todo cleanup and merging codepath with NT */
|
---|
174 | int rcVBox;
|
---|
175 | rcVBox = VbglInit (pDevExt->startPortAddress, pDevExt->pVMMDevMemory);
|
---|
176 | if (!VBOX_SUCCESS(rcVBox))
|
---|
177 | {
|
---|
178 | dprintf(("VBoxGuest::START_DEVICE: VbglInit failed. rcVBox = %d\n", rcVBox));
|
---|
179 | rc = STATUS_UNSUCCESSFUL;
|
---|
180 | }
|
---|
181 |
|
---|
182 | if (NT_SUCCESS(rc))
|
---|
183 | {
|
---|
184 | rcVBox = VbglGRAlloc ((VMMDevRequestHeader **)&pDevExt->irqAckEvents, sizeof (VMMDevEvents), VMMDevReq_AcknowledgeEvents);
|
---|
185 | if (!VBOX_SUCCESS(rc))
|
---|
186 | {
|
---|
187 | dprintf(("VBoxGuest::START_DEVICE: VbglAlloc failed. rcVBox = %d\n", rcVBox));
|
---|
188 | rc = STATUS_UNSUCCESSFUL;
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | if (NT_SUCCESS(rc))
|
---|
193 | {
|
---|
194 | // Map physical address of VMMDev memory
|
---|
195 | rc = hlpVBoxMapVMMDevMemory(pDevExt);
|
---|
196 | if (!NT_SUCCESS(rc))
|
---|
197 | {
|
---|
198 | dprintf(("VBoxGuest::START_DEVICE: can't map physical memory, rc = %d\n", rc));
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | if (NT_SUCCESS(rc))
|
---|
203 | {
|
---|
204 | rc = hlpVBoxReportGuestInfo (pDevExt);
|
---|
205 | if (!NT_SUCCESS(rc))
|
---|
206 | {
|
---|
207 | dprintf(("VBoxGuest::START_DEVICE: could not report information to host, rc = %d\n", rc));
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | if (NT_SUCCESS(rc))
|
---|
212 | {
|
---|
213 | // register DPC and ISR
|
---|
214 | dprintf(("VBoxGuest::VBoxGuestPnp: initializing DPC...\n"));
|
---|
215 | IoInitializeDpcRequest(pDevExt->deviceObject, VBoxGuestDpcHandler);
|
---|
216 |
|
---|
217 | rc = IoConnectInterrupt(&pDevExt->interruptObject, // out: interrupt object
|
---|
218 | (PKSERVICE_ROUTINE)VBoxGuestIsrHandler, // ISR
|
---|
219 | pDevExt, // context
|
---|
220 | NULL, // optional spinlock
|
---|
221 | pDevExt->interruptVector, // interrupt vector
|
---|
222 | (KIRQL)pDevExt->interruptLevel, // interrupt level
|
---|
223 | (KIRQL)pDevExt->interruptLevel, // interrupt level
|
---|
224 | pDevExt->interruptMode, // LevelSensitive or Latched
|
---|
225 | TRUE, // shareable interrupt
|
---|
226 | pDevExt->interruptAffinity, // CPU affinity
|
---|
227 | FALSE); // don't save FPU stack
|
---|
228 | if (!NT_SUCCESS(rc))
|
---|
229 | {
|
---|
230 | dprintf(("VBoxGuest::VBoxGuestPnp: could not connect interrupt: rc = 0x%x\n", rc));
|
---|
231 | }
|
---|
232 | }
|
---|
233 | }
|
---|
234 | }
|
---|
235 | if (NT_SUCCESS(rc))
|
---|
236 | {
|
---|
237 | createThreads(pDevExt);
|
---|
238 |
|
---|
239 | // initialize the event notification semaphore
|
---|
240 | KeInitializeEvent(&pDevExt->keventNotification, NotificationEvent, FALSE);
|
---|
241 |
|
---|
242 | /* Preallocated constant timeout 250ms for HGCM async waiter. */
|
---|
243 | pDevExt->HGCMWaitTimeout.QuadPart = 250;
|
---|
244 | pDevExt->HGCMWaitTimeout.QuadPart *= -10000; /* relative in 100ns units */
|
---|
245 |
|
---|
246 | VBoxInitMemBalloon(pDevExt);
|
---|
247 |
|
---|
248 | // ready to rumble!
|
---|
249 | dprintf(("VBoxGuest::VBoxGuestPnp: device is ready!\n"));
|
---|
250 | pDevExt->devState = WORKING;
|
---|
251 | } else
|
---|
252 | {
|
---|
253 | dprintf(("VBoxGuest::VBoxGuestPnp: error: rc = 0x%x\n", rc));
|
---|
254 |
|
---|
255 | // need to unmap memory in case of errors
|
---|
256 | hlpVBoxUnmapVMMDevMemory (pDevExt);
|
---|
257 | }
|
---|
258 | pIrp->IoStatus.Status = rc;
|
---|
259 | pIrp->IoStatus.Information = 0;
|
---|
260 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
|
---|
261 | break;
|
---|
262 | }
|
---|
263 |
|
---|
264 | case IRP_MN_QUERY_REMOVE_DEVICE:
|
---|
265 | {
|
---|
266 | #ifdef VBOX_REBOOT_ON_UNINSTALL
|
---|
267 | /* The device can not be removed without a reboot. */
|
---|
268 | if (pDevExt->devState == WORKING)
|
---|
269 | {
|
---|
270 | pDevExt->devState = PENDINGREMOVE;
|
---|
271 | }
|
---|
272 | pIrp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
---|
273 | pIrp->IoStatus.Information = 0;
|
---|
274 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
|
---|
275 | rc = STATUS_UNSUCCESSFUL;
|
---|
276 |
|
---|
277 | dprintf(("VBoxGuest::VBoxGuestPnp: refuse with rc = %p\n", pIrp->IoStatus.Status));
|
---|
278 | #else
|
---|
279 | pIrp->IoStatus.Status = STATUS_SUCCESS;
|
---|
280 | if (pDevExt->devState == WORKING)
|
---|
281 | {
|
---|
282 | pDevExt->devState = PENDINGREMOVE;
|
---|
283 | }
|
---|
284 | IoSkipCurrentIrpStackLocation(pIrp);
|
---|
285 | rc = IoCallDriver(pDevExt->nextLowerDriver, pIrp);
|
---|
286 | #endif /* VBOX_REBOOT_ON_UNINSTALL */
|
---|
287 | break;
|
---|
288 | }
|
---|
289 |
|
---|
290 | case IRP_MN_REMOVE_DEVICE:
|
---|
291 | {
|
---|
292 | /* @todo merge Remove and Stop, make a helper for common actions */
|
---|
293 | pIrp->IoStatus.Status = STATUS_SUCCESS;
|
---|
294 |
|
---|
295 | unreserveHypervisorMemory(pDevExt);
|
---|
296 |
|
---|
297 | if (pDevExt->workerThread)
|
---|
298 | {
|
---|
299 | dprintf(("VBoxGuest::VBoxGuestPnp: waiting for the worker thread to terminate...\n"));
|
---|
300 | pDevExt->stopThread = TRUE;
|
---|
301 | KeSetEvent(&pDevExt->workerThreadRequest, 0, FALSE);
|
---|
302 | KeWaitForSingleObject(pDevExt->workerThread,
|
---|
303 | Executive, KernelMode, FALSE, NULL);
|
---|
304 | dprintf(("VBoxGuest::VBoxGuestPnp: returned from KeWaitForSingleObject for worker thread\n"));
|
---|
305 | }
|
---|
306 |
|
---|
307 | if (pDevExt->idleThread)
|
---|
308 | {
|
---|
309 | dprintf(("VBoxGuest::VBoxGuestPnp: waiting for the idle thread to terminate...\n"));
|
---|
310 | pDevExt->stopThread = TRUE;
|
---|
311 | KeWaitForSingleObject(pDevExt->idleThread,
|
---|
312 | Executive, KernelMode, FALSE, NULL);
|
---|
313 | dprintf(("VBoxGuest::VBoxGuestPnp: returned from KeWaitForSingleObject for idle thread\n"));
|
---|
314 | }
|
---|
315 |
|
---|
316 | VbglTerminate ();
|
---|
317 |
|
---|
318 | // according to MSDN we have to unmap previously mapped memory
|
---|
319 | hlpVBoxUnmapVMMDevMemory (pDevExt);
|
---|
320 |
|
---|
321 | if (pDevExt->nextLowerDriver != NULL)
|
---|
322 | {
|
---|
323 | IoDetachDevice(pDevExt->nextLowerDriver);
|
---|
324 | }
|
---|
325 | UNICODE_STRING win32Name;
|
---|
326 | RtlInitUnicodeString(&win32Name, VBOXGUEST_DEVICE_NAME_DOS);
|
---|
327 | IoDeleteSymbolicLink(&win32Name);
|
---|
328 | IoDeleteDevice(pDevObj);
|
---|
329 | pDevExt->devState = REMOVED;
|
---|
330 | IoSkipCurrentIrpStackLocation(pIrp);
|
---|
331 | rc = IoCallDriver(pDevExt->nextLowerDriver, pIrp);
|
---|
332 | break;
|
---|
333 | }
|
---|
334 |
|
---|
335 | case IRP_MN_QUERY_STOP_DEVICE:
|
---|
336 | {
|
---|
337 | #ifdef VBOX_REBOOT_ON_UNINSTALL
|
---|
338 | dprintf(("VBoxGuest::VBoxGuestPnp: refuse\n"));
|
---|
339 | /* The device can not be stopped without a reboot. */
|
---|
340 | if (pDevExt->devState == WORKING)
|
---|
341 | {
|
---|
342 | pDevExt->devState = PENDINGSTOP;
|
---|
343 | }
|
---|
344 | pIrp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
---|
345 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
|
---|
346 | rc = STATUS_UNSUCCESSFUL;
|
---|
347 | #else
|
---|
348 | pIrp->IoStatus.Status = STATUS_SUCCESS;
|
---|
349 | if (pDevExt->devState == WORKING)
|
---|
350 | {
|
---|
351 | pDevExt->devState = PENDINGSTOP;
|
---|
352 | }
|
---|
353 | IoSkipCurrentIrpStackLocation(pIrp);
|
---|
354 | rc = IoCallDriver(pDevExt->nextLowerDriver, pIrp);
|
---|
355 | #endif /* VBOX_REBOOT_ON_UNINSTALL */
|
---|
356 | break;
|
---|
357 | }
|
---|
358 |
|
---|
359 | case IRP_MN_STOP_DEVICE:
|
---|
360 | {
|
---|
361 | pIrp->IoStatus.Status = STATUS_SUCCESS;
|
---|
362 | if (pDevExt->devState == PENDINGSTOP)
|
---|
363 | {
|
---|
364 | VbglTerminate ();
|
---|
365 |
|
---|
366 | // according to MSDN we have to unmap previously mapped memory
|
---|
367 | hlpVBoxUnmapVMMDevMemory (pDevExt);
|
---|
368 |
|
---|
369 | pDevExt->devState = STOPPED;
|
---|
370 | dprintf(("VBoxGuest::VBoxGuestPnp: device has been disabled\n"));
|
---|
371 | } else
|
---|
372 | {
|
---|
373 | dprintf(("VBoxGuest::VBoxGuestPnp: devState not PENDINGSTOP but %d\n", pDevExt->devState));
|
---|
374 | }
|
---|
375 | IoSkipCurrentIrpStackLocation(pIrp);
|
---|
376 | rc = IoCallDriver(pDevExt->nextLowerDriver, pIrp);
|
---|
377 | break;
|
---|
378 | }
|
---|
379 |
|
---|
380 | default:
|
---|
381 | {
|
---|
382 | IoSkipCurrentIrpStackLocation(pIrp);
|
---|
383 | rc = IoCallDriver(pDevExt->nextLowerDriver, pIrp);
|
---|
384 | }
|
---|
385 |
|
---|
386 | }
|
---|
387 | return rc;
|
---|
388 | }
|
---|
389 |
|
---|
390 |
|
---|
391 | /**
|
---|
392 | * Debug helper to dump a device resource list.
|
---|
393 | *
|
---|
394 | * @param pResourceList list of device resources.
|
---|
395 | */
|
---|
396 | static VOID showDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList)
|
---|
397 | {
|
---|
398 | #ifdef LOG_ENABLED
|
---|
399 | PCM_PARTIAL_RESOURCE_DESCRIPTOR resource = pResourceList->PartialDescriptors;
|
---|
400 | ULONG nres = pResourceList->Count;
|
---|
401 | ULONG i;
|
---|
402 |
|
---|
403 | for (i = 0; i < nres; ++i, ++resource)
|
---|
404 | {
|
---|
405 | ULONG type = resource->Type;
|
---|
406 |
|
---|
407 | static char* name[] =
|
---|
408 | {
|
---|
409 | "CmResourceTypeNull",
|
---|
410 | "CmResourceTypePort",
|
---|
411 | "CmResourceTypeInterrupt",
|
---|
412 | "CmResourceTypeMemory",
|
---|
413 | "CmResourceTypeDma",
|
---|
414 | "CmResourceTypeDeviceSpecific",
|
---|
415 | "CmResourceTypeBusNumber",
|
---|
416 | "CmResourceTypeDevicePrivate",
|
---|
417 | "CmResourceTypeAssignedResource",
|
---|
418 | "CmResourceTypeSubAllocateFrom",
|
---|
419 | };
|
---|
420 |
|
---|
421 | dprintf(("VBoxGuest::showDeviceResources: type %s", type < (sizeof(name)/sizeof(name[0])) ? name[type] : "unknown"));
|
---|
422 |
|
---|
423 | switch (type)
|
---|
424 | {
|
---|
425 | case CmResourceTypePort:
|
---|
426 | case CmResourceTypeMemory:
|
---|
427 | dprintf(("VBoxGuest::showDeviceResources: start %8X%8.8lX length %X\n",
|
---|
428 | resource->u.Port.Start.HighPart, resource->u.Port.Start.LowPart,
|
---|
429 | resource->u.Port.Length));
|
---|
430 | break;
|
---|
431 |
|
---|
432 | case CmResourceTypeInterrupt:
|
---|
433 | dprintf(("VBoxGuest::showDeviceResources: level %X, vector %X, affinity %X\n",
|
---|
434 | resource->u.Interrupt.Level, resource->u.Interrupt.Vector,
|
---|
435 | resource->u.Interrupt.Affinity));
|
---|
436 | break;
|
---|
437 |
|
---|
438 | case CmResourceTypeDma:
|
---|
439 | dprintf(("VBoxGuest::showDeviceResources: channel %d, port %X\n",
|
---|
440 | resource->u.Dma.Channel, resource->u.Dma.Port));
|
---|
441 | break;
|
---|
442 |
|
---|
443 | default:
|
---|
444 | dprintf(("\n"));
|
---|
445 | break;
|
---|
446 | }
|
---|
447 | }
|
---|
448 | #endif
|
---|
449 | }
|
---|
450 |
|
---|
451 | /**
|
---|
452 | * Handle the power completion event.
|
---|
453 | *
|
---|
454 | * @returns NT status code
|
---|
455 | * @param devObj targetted device object
|
---|
456 | * @param irp IO request packet
|
---|
457 | * @param context context value passed to IoSetCompletionRoutine in VBoxGuestPower
|
---|
458 | */
|
---|
459 | NTSTATUS VBoxGuestPowerComplete(IN PDEVICE_OBJECT devObj,
|
---|
460 | IN PIRP irp, IN PVOID context)
|
---|
461 | {
|
---|
462 | PIO_STACK_LOCATION irpSp;
|
---|
463 | PVBOXGUESTDEVEXT devExt = (PVBOXGUESTDEVEXT)context;
|
---|
464 |
|
---|
465 | ASSERT(devExt);
|
---|
466 | ASSERT(devExt->signature == DEVICE_EXTENSION_SIGNATURE);
|
---|
467 |
|
---|
468 | irpSp = IoGetCurrentIrpStackLocation(irp);
|
---|
469 | ASSERT(irpSp->MajorFunction == IRP_MJ_POWER);
|
---|
470 |
|
---|
471 | if (NT_SUCCESS(irp->IoStatus.Status))
|
---|
472 | {
|
---|
473 | switch (irpSp->MinorFunction)
|
---|
474 | {
|
---|
475 | case IRP_MN_SET_POWER:
|
---|
476 |
|
---|
477 | switch (irpSp->Parameters.Power.Type)
|
---|
478 | {
|
---|
479 | case DevicePowerState:
|
---|
480 | switch (irpSp->Parameters.Power.State.DeviceState)
|
---|
481 | {
|
---|
482 | case PowerDeviceD0:
|
---|
483 | break;
|
---|
484 | }
|
---|
485 | break;
|
---|
486 | }
|
---|
487 | break;
|
---|
488 | }
|
---|
489 | }
|
---|
490 |
|
---|
491 | return STATUS_SUCCESS;
|
---|
492 | }
|
---|
493 |
|
---|
494 |
|
---|
495 | /**
|
---|
496 | * Handle the Power requests.
|
---|
497 | *
|
---|
498 | * @returns NT status code
|
---|
499 | * @param pDevObj device object
|
---|
500 | * @param pIrp IRP
|
---|
501 | */
|
---|
502 | NTSTATUS VBoxGuestPower(PDEVICE_OBJECT pDevObj, PIRP pIrp)
|
---|
503 | {
|
---|
504 | PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
|
---|
505 | PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
|
---|
506 | POWER_STATE_TYPE powerType;
|
---|
507 | POWER_STATE powerState;
|
---|
508 | POWER_ACTION powerAction;
|
---|
509 |
|
---|
510 | dprintf(("VBoxGuest::VBoxGuestPower\n"));
|
---|
511 |
|
---|
512 | powerType = pStack->Parameters.Power.Type;
|
---|
513 | powerAction = pStack->Parameters.Power.ShutdownType;
|
---|
514 | powerState = pStack->Parameters.Power.State;
|
---|
515 |
|
---|
516 | switch (pStack->MinorFunction)
|
---|
517 | {
|
---|
518 | case IRP_MN_SET_POWER:
|
---|
519 | {
|
---|
520 | dprintf(("VBoxGuest::VBoxGuestPower: IRP_MN_SET_POWER\n"));
|
---|
521 | switch (powerType)
|
---|
522 | {
|
---|
523 | case SystemPowerState:
|
---|
524 | {
|
---|
525 | dprintf(("VBoxGuest::VBoxGuestPower: SystemPowerState\n"));
|
---|
526 | switch (powerAction)
|
---|
527 | {
|
---|
528 | case PowerActionShutdownReset:
|
---|
529 | {
|
---|
530 | dprintf(("VBoxGuest::VBoxGuestPower: power action reset!\n"));
|
---|
531 | /* tell the VMM that we no longer support mouse pointer integration */
|
---|
532 |
|
---|
533 | VMMDevReqMouseStatus *req = NULL;
|
---|
534 |
|
---|
535 | int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_SetMouseStatus);
|
---|
536 |
|
---|
537 | if (VBOX_SUCCESS(rc))
|
---|
538 | {
|
---|
539 | req->mouseFeatures = 0;
|
---|
540 | req->pointerXPos = 0;
|
---|
541 | req->pointerYPos = 0;
|
---|
542 |
|
---|
543 | rc = VbglGRPerform (&req->header);
|
---|
544 |
|
---|
545 | if (VBOX_FAILURE(rc) || VBOX_FAILURE(req->header.rc))
|
---|
546 | {
|
---|
547 | dprintf(("VBoxGuest::PowerStateRequest: error communicating new power status to VMMDev."
|
---|
548 | "rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc));
|
---|
549 | }
|
---|
550 |
|
---|
551 | VbglGRFree (&req->header);
|
---|
552 | }
|
---|
553 | break;
|
---|
554 | }
|
---|
555 |
|
---|
556 | case PowerActionShutdown:
|
---|
557 | case PowerActionShutdownOff:
|
---|
558 | {
|
---|
559 | dprintf(("VBoxGuest::VBoxGuestPower: power action shutdown!\n"));
|
---|
560 | if (powerState.SystemState >= PowerSystemShutdown)
|
---|
561 | {
|
---|
562 | dprintf(("VBoxGuest::VBoxGuestPower: Telling the VMMDev to close the VM...\n"));
|
---|
563 | VMMDevPowerStateRequest *req = NULL;
|
---|
564 |
|
---|
565 | int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevPowerStateRequest), VMMDevReq_SetPowerStatus);
|
---|
566 |
|
---|
567 | if (VBOX_SUCCESS(rc))
|
---|
568 | {
|
---|
569 | req->powerState = VMMDevPowerState_PowerOff;
|
---|
570 |
|
---|
571 | rc = VbglGRPerform (&req->header);
|
---|
572 |
|
---|
573 | if (VBOX_FAILURE(rc) || VBOX_FAILURE(req->header.rc))
|
---|
574 | {
|
---|
575 | dprintf(("VBoxGuest::PowerStateRequest: error communicating new power status to VMMDev."
|
---|
576 | "rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc));
|
---|
577 | }
|
---|
578 |
|
---|
579 | VbglGRFree (&req->header);
|
---|
580 | }
|
---|
581 | }
|
---|
582 | break;
|
---|
583 | }
|
---|
584 | }
|
---|
585 | break;
|
---|
586 | }
|
---|
587 | default:
|
---|
588 | break;
|
---|
589 | }
|
---|
590 | break;
|
---|
591 | }
|
---|
592 | default:
|
---|
593 | break;
|
---|
594 | }
|
---|
595 |
|
---|
596 | /*
|
---|
597 | * Whether we are completing or relaying this power IRP,
|
---|
598 | * we must call PoStartNextPowerIrp.
|
---|
599 | */
|
---|
600 | PoStartNextPowerIrp(pIrp);
|
---|
601 |
|
---|
602 | /*
|
---|
603 | * Send the IRP down the driver stack,
|
---|
604 | * using PoCallDriver (not IoCallDriver, as for non-power irps).
|
---|
605 | */
|
---|
606 | IoCopyCurrentIrpStackLocationToNext(pIrp);
|
---|
607 | IoSetCompletionRoutine(pIrp,
|
---|
608 | VBoxGuestPowerComplete,
|
---|
609 | (PVOID)pDevExt,
|
---|
610 | TRUE,
|
---|
611 | TRUE,
|
---|
612 | TRUE);
|
---|
613 | return PoCallDriver(pDevExt->nextLowerDriver, pIrp);
|
---|
614 | }
|
---|