Changeset 32282 in vbox for trunk/src/VBox
- Timestamp:
- Sep 7, 2010 12:03:42 PM (14 years ago)
- Location:
- trunk/src/VBox/Additions/common/VBoxGuest
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-pnp.cpp
r32080 r32282 1 1 /** @file 2 * VBoxGuest -- VirtualBox Win32 guest support driver PnP code 3 */ 4 5 /* 6 * Copyright (C) 2006-2007 Oracle Corporation 2 * 3 * VBoxGuest-win-pnp - Windows Plug'n'Play specifics. 4 * 5 * Copyright (C) 2010 Oracle Corporation 7 6 * 8 7 * This file is part of VirtualBox Open Source Edition (OSE), as … … 15 14 */ 16 15 17 // enable backdoor logging18 //#define LOG_ENABLED19 20 16 /******************************************************************************* 21 17 * Header Files * 22 18 *******************************************************************************/ 23 #include "VBoxGuest PnP.h"24 #include " Helper.h"19 #include "VBoxGuest-win.h" 20 #include "VBoxGuestInternal.h" 25 21 #include <VBox/err.h> 26 22 #include <VBox/log.h> 23 #include <VBox/version.h> 27 24 #include <VBox/VBoxGuestLib.h> 28 #include "../../common/VBoxGuest/VBoxGuest2.h" 25 29 26 30 27 /******************************************************************************* 31 28 * Defined Constants And Macros * 32 29 *******************************************************************************/ 33 34 35 extern "C" 36 { 37 static NTSTATUS sendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict); 38 static NTSTATUS pnpIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT event); 39 static VOID showDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList); 40 } 30 extern winVersion_t g_winVersion; 31 32 RT_C_DECLS_BEGIN 33 static NTSTATUS vboxguestwinSendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict); 34 static NTSTATUS vboxguestwinPnPIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent); 35 static VOID vboxguestwinShowDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList); 36 RT_C_DECLS_END 41 37 42 38 #ifdef ALLOC_PRAGMA 43 #pragma alloc_text (PAGE, VBoxGuestPnP)44 #pragma alloc_text (PAGE, VBoxGuestPower)45 #pragma alloc_text (PAGE, sendIrpSynchronously)46 #pragma alloc_text (PAGE, showDeviceResources)39 #pragma alloc_text (PAGE, vboxguestwinPnP) 40 #pragma alloc_text (PAGE, vboxguestwinPower) 41 #pragma alloc_text (PAGE, vboxguestwinSendIrpSynchronously) 42 #pragma alloc_text (PAGE, vboxguestwinShowDeviceResources) 47 43 #endif 48 44 49 /* reenable logging, this was #undef'ed on iprt/log.h for RING0*/45 /* Reenable logging, this was #undef'ed on iprt/log.h for RING0. */ 50 46 #define LOG_ENABLED 47 51 48 52 49 /******************************************************************************* … … 62 59 * @return NT status code 63 60 */ 64 static NTSTATUS pnpIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT event)61 static NTSTATUS vboxguestwinPnpIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent) 65 62 { 66 KeSetEvent( event, 0, FALSE);63 KeSetEvent(pEvent, 0, FALSE); 67 64 return STATUS_MORE_PROCESSING_REQUIRED; 68 65 } 66 69 67 70 68 /** … … 76 74 * @return NT status code 77 75 */ 78 static NTSTATUS sendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict)76 static NTSTATUS vboxguestwinSendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict) 79 77 { 80 78 KEVENT event; … … 83 81 84 82 IoCopyCurrentIrpStackLocationToNext(pIrp); 85 IoSetCompletionRoutine(pIrp, (PIO_COMPLETION_ROUTINE)pnpIrpComplete, &event, TRUE, TRUE, TRUE); 83 IoSetCompletionRoutine(pIrp, (PIO_COMPLETION_ROUTINE)vboxguestwinPnpIrpComplete, 84 &event, TRUE, TRUE, TRUE); 86 85 87 86 NTSTATUS rc = IoCallDriver(pDevObj, pIrp); … … 99 98 } 100 99 101 dprintf(("VBoxGuest::sendIrpSynchronously: returning 0x%x\n", rc)); 102 100 Log(("VBoxGuest::vboxguestwinSendIrpSynchronously: Returning 0x%x\n", rc)); 103 101 return rc; 104 102 } … … 111 109 * @param pIrp Request packet. 112 110 */ 113 NTSTATUS VBoxGuestPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp)111 NTSTATUS vboxguestwinPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp) 114 112 { 115 113 PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension; 116 114 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp); 117 NTSTATUS rc = STATUS_SUCCESS;118 115 119 116 #ifdef LOG_ENABLED 120 static char* fcnname[] =117 static char* aszFnctName[] = 121 118 { 122 119 "IRP_MN_START_DEVICE", … … 145 142 "IRP_MN_SURPRISE_REMOVAL", 146 143 }; 147 dprintf(("VBoxGuest::VBoxGuestPnp: MinorFunction: %s\n", pStack->MinorFunction < (sizeof(fcnname)/sizeof(fcnname[0])) ? fcnname[pStack->MinorFunction] : "unknown")); 144 Log(("VBoxGuest::vboxguestwinGuestPnp: MinorFunction: %s\n", 145 pStack->MinorFunction < (sizeof(aszFnctName) / sizeof(aszFnctName[0])) 146 ? aszFnctName[pStack->MinorFunction] 147 : "Unknown")); 148 148 #endif 149 150 NTSTATUS rc = STATUS_SUCCESS; 149 151 switch (pStack->MinorFunction) 150 152 { 151 153 case IRP_MN_START_DEVICE: 152 154 { 153 rc = sendIrpSynchronously(pDevExt->nextLowerDriver, pIrp, TRUE); 154 155 if (NT_SUCCESS(rc) && NT_SUCCESS(pIrp->IoStatus.Status)) 156 { 157 dprintf(("VBoxGuest::START_DEVICE: pStack->Parameters.StartDevice.AllocatedResources = %p\n", pStack->Parameters.StartDevice.AllocatedResources)); 155 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE\n")); 156 rc = vboxguestwinSendIrpSynchronously(pDevExt->win.s.pNextLowerDriver, pIrp, TRUE); 157 158 if ( NT_SUCCESS(rc) 159 && NT_SUCCESS(pIrp->IoStatus.Status)) 160 { 161 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: pStack->Parameters.StartDevice.AllocatedResources = %p\n", 162 pStack->Parameters.StartDevice.AllocatedResources)); 158 163 159 164 if (!pStack->Parameters.StartDevice.AllocatedResources) 160 165 { 161 dprintf(("VBoxGuest::START_DEVICE: no resources, pDevExt = %p, nextLowerDriver = %p!!!\n", pDevExt, pDevExt? pDevExt->nextLowerDriver: NULL)); 166 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: No resources, pDevExt = %p, nextLowerDriver = %p!\n", 167 pDevExt, pDevExt ? pDevExt->win.s.pNextLowerDriver : NULL)); 162 168 rc = STATUS_UNSUCCESSFUL; 163 169 } 164 170 else 165 171 { 166 showDeviceResources(&pStack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList); 167 168 VBoxScanPCIResourceList(pStack->Parameters.StartDevice.AllocatedResourcesTranslated, 169 pDevExt); 170 171 /** @todo cleanup and merging codepath with NT */ 172 int rcVBox; 173 rcVBox = VbglInit (pDevExt->startPortAddress, pDevExt->pVMMDevMemory); 174 if (!RT_SUCCESS(rcVBox)) 175 { 176 dprintf(("VBoxGuest::START_DEVICE: VbglInit failed. rcVBox = %d\n", rcVBox)); 177 rc = STATUS_UNSUCCESSFUL; 178 } 179 172 vboxguestwinShowDeviceResources(&pStack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList); 173 174 vboxguestwinScanPCIResourceList(pStack->Parameters.StartDevice.AllocatedResourcesTranslated, 175 pDevExt); 176 177 /* Map physical address of VMMDev memory into MMIO region. */ 178 void *pvMMIOBase = NULL; 179 uint32_t cbMMIO = 0; 180 rc = vboxguestwinMapVMMDevMemory(pDevExt, 181 pDevExt->win.s.vmmDevPhysMemoryAddress, 182 pDevExt->win.s.vmmDevPhysMemoryLength, 183 &pvMMIOBase, 184 &cbMMIO); 180 185 if (NT_SUCCESS(rc)) 181 186 { 182 rcVBox = VbglGRAlloc ((VMMDevRequestHeader **)&pDevExt->irqAckEvents, sizeof (VMMDevEvents), VMMDevReq_AcknowledgeEvents); 183 if (!RT_SUCCESS(rc)) 187 pDevExt->pVMMDevMemory = (VMMDevMemory *)pvMMIOBase; 188 189 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: pvMMIOBase = 0x%p, pDevExt = 0x%p, pDevExt->pVMMDevMemory = 0x%p\n", 190 pvMMIOBase, pDevExt, pDevExt ? pDevExt->pVMMDevMemory : NULL)); 191 192 int vrc = VBoxGuestInitDevExt(pDevExt, 193 pDevExt->IOPortBase, 194 pvMMIOBase, cbMMIO, 195 vboxguestwinVersionToOSType(g_winVersion), 196 VMMDEV_EVENT_MOUSE_POSITION_CHANGED); 197 if (RT_FAILURE(vrc)) 184 198 { 185 dprintf(("VBoxGuest::START_DEVICE: VbglAlloc failed for irqAckEvents. rcVBox = %d\n", rcVBox)); 199 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: Could not init device extension, rc = %Rrc!\n", vrc)); 200 rc = STATUS_DEVICE_CONFIGURATION_ERROR; 201 } 202 } 203 else 204 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: Could not map physical address of VMMDev, rc = 0x%x!\n", rc)); 205 206 if (NT_SUCCESS(rc)) 207 { 208 int vrc = VbglGRAlloc((VMMDevRequestHeader **)&pDevExt->win.s.pPowerStateRequest, 209 sizeof (VMMDevPowerStateRequest), VMMDevReq_SetPowerStatus); 210 if (RT_FAILURE(vrc)) 211 { 212 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: Alloc for pPowerStateRequest failed, rc = %Rrc\n", vrc)); 186 213 rc = STATUS_UNSUCCESSFUL; 187 214 } … … 190 217 if (NT_SUCCESS(rc)) 191 218 { 192 rcVBox = VbglGRAlloc ((VMMDevRequestHeader **)&pDevExt->powerStateRequest, sizeof (VMMDevPowerStateRequest), VMMDevReq_SetPowerStatus); 193 if (!RT_SUCCESS(rc)) 194 { 195 dprintf(("VBoxGuest::START_DEVICE: VbglAlloc failed for powerStateRequest. rcVBox = %d\n", rcVBox)); 196 rc = STATUS_UNSUCCESSFUL; 197 } 198 } 199 200 if (NT_SUCCESS(rc)) 201 { 202 // Map physical address of VMMDev memory 203 rc = hlpVBoxMapVMMDevMemory(pDevExt); 204 if (!NT_SUCCESS(rc)) 205 { 206 dprintf(("VBoxGuest::START_DEVICE: can't map physical memory, rc = %d\n", rc)); 207 } 208 } 209 210 if (NT_SUCCESS(rc)) 211 { 212 // register DPC and ISR 213 dprintf(("VBoxGuest::VBoxGuestPnp: initializing DPC...\n")); 214 IoInitializeDpcRequest(pDevExt->deviceObject, VBoxGuestDpcHandler); 215 216 rc = IoConnectInterrupt(&pDevExt->interruptObject, // out: interrupt object 217 (PKSERVICE_ROUTINE)VBoxGuestIsrHandler, // ISR 218 pDevExt, // context 219 NULL, // optional spinlock 220 pDevExt->interruptVector, // interrupt vector 221 (KIRQL)pDevExt->interruptLevel, // interrupt level 222 (KIRQL)pDevExt->interruptLevel, // interrupt level 223 pDevExt->interruptMode, // LevelSensitive or Latched 224 TRUE, // shareable interrupt 225 pDevExt->interruptAffinity, // CPU affinity 226 FALSE); // don't save FPU stack 227 if (!NT_SUCCESS(rc)) 228 { 229 dprintf(("VBoxGuest::VBoxGuestPnp: could not connect interrupt: rc = 0x%x\n", rc)); 230 } 219 /* Register DPC and ISR. */ 220 Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Initializing DPC/ISR ...\n")); 221 222 IoInitializeDpcRequest(pDevExt->win.s.pDeviceObject, vboxguestwinDpcHandler); 223 rc = IoConnectInterrupt(&pDevExt->win.s.pInterruptObject, /* Out: interrupt object. */ 224 (PKSERVICE_ROUTINE)vboxguestwinIsrHandler, /* Our ISR handler. */ 225 pDevExt, /* Device context. */ 226 NULL, /* Optional spinlock. */ 227 pDevExt->win.s.interruptVector, /* Interrupt vector. */ 228 (KIRQL)pDevExt->win.s.interruptLevel, /* Interrupt level. */ 229 (KIRQL)pDevExt->win.s.interruptLevel, /* Interrupt level. */ 230 pDevExt->win.s.interruptMode, /* LevelSensitive or Latched. */ 231 TRUE, /* Shareable interrupt. */ 232 pDevExt->win.s.interruptAffinity, /* CPU affinity. */ 233 FALSE); /* Don't save FPU stack. */ 234 if (NT_ERROR(rc)) 235 Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Could not connect interrupt, rc = 0x%x\n", rc)); 231 236 } 232 237 } 233 238 } 234 235 /** @todo Don't mix up IPRT rc and NTSTATUS rc above! */ 236 239 /* 240 #ifdef VBOX_WITH_HGCM 237 241 if (NT_SUCCESS(rc)) 238 242 { 239 int vrc = VBoxGuestReportGuestInfo(hlpVBoxWinVersionToOSType(winVersion)); 240 if (RT_SUCCESS(vrc)) 241 { 242 vrc = VBoxInitMemBalloon(pDevExt); 243 if (RT_SUCCESS(vrc)) 244 { 245 vrc = VBoxGuestReportDriverStatus(true /* Driver is active */); 246 if (RT_FAILURE(vrc)) 247 dprintf(("VBoxGuest::VBoxGuestPnp::IRP_MN_START_DEVICE: could not report guest driver status, vrc = %d\n", vrc)); 248 } 249 else 250 dprintf(("VBoxGuest::VBoxGuestPnp::IRP_MN_START_DEVICE: could not init mem balloon, vrc = %d\n", vrc)); 251 } 252 else 253 dprintf(("VBoxGuest::VBoxGuestPnp::IRP_MN_START_DEVICE: could not report guest information to host, vrc = %d\n", vrc)); 254 243 int vrc = VBoxGuestHGCMInitCommunication(pDevExt, vboxguestwinVersionToOSType(g_winVersion)); 255 244 if (RT_FAILURE(vrc)) 256 245 rc = STATUS_UNSUCCESSFUL; 257 246 } 258 247 #endif 248 */ 259 249 if (NT_SUCCESS(rc)) 260 250 { 261 createThreads(pDevExt); 262 263 // initialize the event notification semaphore 264 KeInitializeEvent(&pDevExt->keventNotification, NotificationEvent, FALSE); 251 #ifdef VBOX_WITH_HGCM 252 /* Initialize the HGCM event notification semaphore. */ 253 KeInitializeEvent(&pDevExt->win.s.hgcm.s.keventNotification, NotificationEvent, FALSE); 265 254 266 255 /* Preallocated constant timeout 250ms for HGCM async waiter. */ 267 pDevExt->HGCMWaitTimeout.QuadPart = 250; 268 pDevExt->HGCMWaitTimeout.QuadPart *= -10000; /* relative in 100ns units */ 269 270 // ready to rumble! 271 dprintf(("VBoxGuest::VBoxGuestPnp: device is ready!\n")); 272 pDevExt->devState = WORKING; 256 pDevExt->win.s.hgcm.s.WaitTimeout.QuadPart = 250; 257 pDevExt->win.s.hgcm.s.WaitTimeout.QuadPart *= -10000; /* Relative in 100ns units. */ 258 259 int vrc = VBoxGuestCreateKernelSession(pDevExt, &pDevExt->win.s.pKernelSession); 260 if (RT_FAILURE(vrc)) 261 Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Failed to allocated kernel session data! rc = %Rrc\n", rc)); 262 #endif 263 264 /* Ready to rumble! */ 265 Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Device is ready!\n")); 266 pDevExt->win.s.devState = WORKING; 273 267 } 274 268 else 275 269 { 276 dprintf(("VBoxGuest::VBoxGuestPnp: error: rc = 0x%x\n", rc));277 278 / / need to unmap memory in case of errors279 hlpVBoxUnmapVMMDevMemory(pDevExt);270 Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Error: rc = 0x%x\n", rc)); 271 272 /* Need to unmap memory in case of errors ... */ 273 vboxguestwinUnmapVMMDevMemory(pDevExt); 280 274 } 281 275 pIrp->IoStatus.Status = rc; … … 287 281 case IRP_MN_QUERY_REMOVE_DEVICE: 288 282 { 283 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: QUERY_REMOVE_DEVICE\n")); 284 289 285 #ifdef VBOX_REBOOT_ON_UNINSTALL 290 286 /* The device can not be removed without a reboot. */ 291 if (pDevExt->devState == WORKING) 292 { 293 pDevExt->devState = PENDINGREMOVE; 294 } 287 if (pDevExt->win.s.devState == WORKING) 288 { 289 Log(("VBoxGuest::vboxguestwinGuestPnp: QUERY_REMOVE_DEVICE: Device cannot be removed without a reboot!\n")); 290 pDevExt->win.s.devState = PENDINGREMOVE; 291 } 292 295 293 pIrp->IoStatus.Status = STATUS_UNSUCCESSFUL; 296 294 pIrp->IoStatus.Information = 0; … … 298 296 rc = STATUS_UNSUCCESSFUL; 299 297 300 dprintf(("VBoxGuest::VBoxGuestPnp: refuse with rc = %p\n", pIrp->IoStatus.Status));298 Log(("VBoxGuest::vboxguestwinGuestPnp: QUERY_REMOVE_DEVICE: Refuse with rc = %p\n", pIrp->IoStatus.Status)); 301 299 #else 302 300 pIrp->IoStatus.Status = STATUS_SUCCESS; 303 if (pDevExt->devState == WORKING) 304 { 305 pDevExt->devState = PENDINGREMOVE; 306 } 301 if (pDevExt->win.s.devState == WORKING) 302 pDevExt->win.s.devState = PENDINGREMOVE; 307 303 IoSkipCurrentIrpStackLocation(pIrp); 308 rc = IoCallDriver(pDevExt-> nextLowerDriver, pIrp);304 rc = IoCallDriver(pDevExt->win.s.pNextLowerDriver, pIrp); 309 305 #endif /* VBOX_REBOOT_ON_UNINSTALL */ 310 306 break; … … 313 309 case IRP_MN_REMOVE_DEVICE: 314 310 { 315 /* @todo merge Remove and Stop, make a helper for common actions */ 311 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: REMOVE_DEVICE\n")); 312 313 /** @todo Merge Remove and Stop, make a helper for common actions. */ 316 314 pIrp->IoStatus.Status = STATUS_SUCCESS; 317 315 318 unreserveHypervisorMemory(pDevExt); 319 320 if (pDevExt->workerThread) 321 { 322 dprintf(("VBoxGuest::VBoxGuestPnp: waiting for the worker thread to terminate...\n")); 323 pDevExt->stopThread = TRUE; 324 KeSetEvent(&pDevExt->workerThreadRequest, 0, FALSE); 325 KeWaitForSingleObject(pDevExt->workerThread, 326 Executive, KernelMode, FALSE, NULL); 327 dprintf(("VBoxGuest::VBoxGuestPnp: returned from KeWaitForSingleObject for worker thread\n")); 328 } 329 330 if (pDevExt->idleThread) 331 { 332 dprintf(("VBoxGuest::VBoxGuestPnp: waiting for the idle thread to terminate...\n")); 333 pDevExt->stopThread = TRUE; 334 KeWaitForSingleObject(pDevExt->idleThread, 335 Executive, KernelMode, FALSE, NULL); 336 dprintf(("VBoxGuest::VBoxGuestPnp: returned from KeWaitForSingleObject for idle thread\n")); 337 } 338 339 VbglTerminate (); 340 341 // according to MSDN we have to unmap previously mapped memory 342 hlpVBoxUnmapVMMDevMemory (pDevExt); 343 344 /* Free the memory balloon (if any) */ 345 VBoxCleanupMemBalloon(pDevExt); 346 347 if (pDevExt->nextLowerDriver != NULL) 348 { 349 IoDetachDevice(pDevExt->nextLowerDriver); 350 } 316 /* According to MSDN we have to unmap previously mapped memory. */ 317 vboxguestwinUnmapVMMDevMemory(pDevExt); 318 319 /* Destroy device extension and clean up everything else. */ 320 VBoxGuestDeleteDevExt(pDevExt); 321 322 if (pDevExt->win.s.pNextLowerDriver != NULL) 323 IoDetachDevice(pDevExt->win.s.pNextLowerDriver); 351 324 352 325 #ifdef VBOX_WITH_HGCM … … 354 327 RTSpinlockDestroy(pDevExt->SessionSpinlock); 355 328 #endif 356 329 /* Remove DOS device + symbolic link. */ 357 330 UNICODE_STRING win32Name; 358 331 RtlInitUnicodeString(&win32Name, VBOXGUEST_DEVICE_NAME_DOS); 359 332 IoDeleteSymbolicLink(&win32Name); 360 333 IoDeleteDevice(pDevObj); 361 pDevExt-> devState = REMOVED;334 pDevExt->win.s.devState = REMOVED; 362 335 IoSkipCurrentIrpStackLocation(pIrp); 363 rc = IoCallDriver(pDevExt-> nextLowerDriver, pIrp);336 rc = IoCallDriver(pDevExt->win.s.pNextLowerDriver, pIrp); 364 337 break; 365 338 } … … 367 340 case IRP_MN_QUERY_STOP_DEVICE: 368 341 { 342 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: QUERY_STOP_DEVICE\n")); 369 343 #ifdef VBOX_REBOOT_ON_UNINSTALL 370 dprintf(("VBoxGuest::VBoxGuestPnp: refuse\n")); 344 Log(("VBoxGuest::vboxguestwinGuestPnp: QUERY_STOP_DEVICE: Device cannot be stopped!\n")); 345 371 346 /* The device can not be stopped without a reboot. */ 372 if (pDevExt->devState == WORKING) 373 { 374 pDevExt->devState = PENDINGSTOP; 375 } 347 if (pDevExt->win.s.devState == WORKING) 348 pDevExt->win.s.devState = PENDINGSTOP; 376 349 pIrp->IoStatus.Status = STATUS_UNSUCCESSFUL; 377 350 IoCompleteRequest(pIrp, IO_NO_INCREMENT); … … 379 352 #else 380 353 pIrp->IoStatus.Status = STATUS_SUCCESS; 381 if (pDevExt-> devState == WORKING)382 { 383 pDevExt-> devState = PENDINGSTOP;354 if (pDevExt->win.s.devState == WORKING) 355 { 356 pDevExt->win.s.devState = PENDINGSTOP; 384 357 } 385 358 IoSkipCurrentIrpStackLocation(pIrp); 386 rc = IoCallDriver(pDevExt-> nextLowerDriver, pIrp);359 rc = IoCallDriver(pDevExt->win.s.pNextLowerDriver, pIrp); 387 360 #endif /* VBOX_REBOOT_ON_UNINSTALL */ 388 361 break; … … 391 364 case IRP_MN_STOP_DEVICE: 392 365 { 366 Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: STOP_DEVICE\n")); 367 393 368 pIrp->IoStatus.Status = STATUS_SUCCESS; 394 if (pDevExt->devState == PENDINGSTOP) 395 { 396 VbglTerminate (); 397 398 // according to MSDN we have to unmap previously mapped memory 399 hlpVBoxUnmapVMMDevMemory (pDevExt); 400 401 pDevExt->devState = STOPPED; 402 dprintf(("VBoxGuest::VBoxGuestPnp: device has been disabled\n")); 403 } else 404 { 405 dprintf(("VBoxGuest::VBoxGuestPnp: devState not PENDINGSTOP but %d\n", pDevExt->devState)); 369 if (pDevExt->win.s.devState == PENDINGSTOP) 370 { 371 VbglTerminate(); 372 373 /* According to MSDN we have to unmap previously mapped memory. */ 374 vboxguestwinUnmapVMMDevMemory(pDevExt); 375 376 pDevExt->win.s.devState = STOPPED; 377 Log(("VBoxGuest::vboxguestwinGuestPnp: STOP_DEVICE: Device has been disabled\n")); 378 } 379 else 380 { 381 Log(("VBoxGuest::vboxguestwinGuestPnp: STOP_DEVICE: Devices state is not PENDINGSTOP but %d\n", 382 pDevExt->win.s.devState)); 406 383 } 407 384 IoSkipCurrentIrpStackLocation(pIrp); 408 rc = IoCallDriver(pDevExt-> nextLowerDriver, pIrp);385 rc = IoCallDriver(pDevExt->win.s.pNextLowerDriver, pIrp); 409 386 break; 410 387 } … … 413 390 { 414 391 IoSkipCurrentIrpStackLocation(pIrp); 415 rc = IoCallDriver(pDevExt->nextLowerDriver, pIrp); 416 } 417 392 rc = IoCallDriver(pDevExt->win.s.pNextLowerDriver, pIrp); 393 } 418 394 } 419 395 return rc; … … 426 402 * @param pResourceList list of device resources. 427 403 */ 428 static VOID showDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList)404 static VOID vboxguestwinShowDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList) 429 405 { 430 406 #ifdef LOG_ENABLED … … 435 411 for (i = 0; i < nres; ++i, ++resource) 436 412 { 437 ULONG type = resource->Type; 438 439 static char* name[] = 413 ULONG uType = resource->Type; 414 static char* aszName[] = 440 415 { 441 416 "CmResourceTypeNull", … … 451 426 }; 452 427 453 dprintf(("VBoxGuest::showDeviceResources: type %s", type < (sizeof(name)/sizeof(name[0])) ? name[type] : "unknown")); 454 455 switch (type) 428 Log(("VBoxGuest::vboxguestwinShowDeviceResources: Type %s", 429 uType < (sizeof(aszName) / sizeof(aszName[0])) 430 ? aszName[uType] : "Unknown")); 431 432 switch (uType) 456 433 { 457 434 case CmResourceTypePort: 458 435 case CmResourceTypeMemory: 459 dprintf(("VBoxGuest::showDeviceResources: start %8X%8.8lX length %X\n",436 Log(("VBoxGuest::vboxguestwinShowDeviceResources: Start %8X%8.8lX length %X\n", 460 437 resource->u.Port.Start.HighPart, resource->u.Port.Start.LowPart, 461 438 resource->u.Port.Length)); … … 463 440 464 441 case CmResourceTypeInterrupt: 465 dprintf(("VBoxGuest::showDeviceResources: level %X, vector %X, affinity %X\n",442 Log(("VBoxGuest::vboxguestwinShowDeviceResources: Level %X, Vector %X, Affinity %X\n", 466 443 resource->u.Interrupt.Level, resource->u.Interrupt.Vector, 467 444 resource->u.Interrupt.Affinity)); … … 469 446 470 447 case CmResourceTypeDma: 471 dprintf(("VBoxGuest::showDeviceResources: channel %d, port %X\n",448 Log(("VBoxGuest::vboxguestwinShowDeviceResources: Channel %d, Port %X\n", 472 449 resource->u.Dma.Channel, resource->u.Dma.Port)); 473 450 break; 474 451 475 452 default: 476 dprintf(("\n"));453 Log(("\n")); 477 454 break; 478 455 } … … 484 461 * Handle the power completion event. 485 462 * 486 * @returns NT status code 487 * @param devObj targetted device object488 * @param irp IO request packet489 * @param context context value passed to IoSetCompletionRoutine in VBoxGuestPower463 * @returns NT status code. 464 * @param pDevObj Targetted device object. 465 * @param pIrp IO request packet. 466 * @param pContext Context value passed to IoSetCompletionRoutine in VBoxGuestPower. 490 467 */ 491 NTSTATUS VBoxGuestPowerComplete(IN PDEVICE_OBJECT devObj,492 IN PIRP irp, IN PVOID context)468 NTSTATUS vboxguestwinPowerComplete(IN PDEVICE_OBJECT pDevObj, 469 IN PIRP pIrp, IN PVOID pContext) 493 470 { 494 PIO_STACK_LOCATION irpSp; 495 PVBOXGUESTDEVEXT devExt = (PVBOXGUESTDEVEXT)context; 496 497 ASSERT(devExt); 498 ASSERT(devExt->signature == DEVICE_EXTENSION_SIGNATURE); 499 500 irpSp = IoGetCurrentIrpStackLocation(irp); 501 ASSERT(irpSp->MajorFunction == IRP_MJ_POWER); 502 503 if (NT_SUCCESS(irp->IoStatus.Status)) 471 PIO_STACK_LOCATION pIrpSp; 472 PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pContext; 473 474 ASSERT(pDevExt); 475 ASSERT(pDevExt->signature == DEVICE_EXTENSION_SIGNATURE); 476 477 pIrpSp = IoGetCurrentIrpStackLocation(pIrp); 478 if (pIrpSp) 504 479 { 505 switch (irpSp->MinorFunction) 506 { 507 case IRP_MN_SET_POWER: 508 509 switch (irpSp->Parameters.Power.Type) 510 { 511 case DevicePowerState: 512 switch (irpSp->Parameters.Power.State.DeviceState) 513 { 514 case PowerDeviceD0: 515 break; 516 } 517 break; 518 } 519 break; 480 ASSERT(pIrpSp->MajorFunction == IRP_MJ_POWER); 481 if (NT_SUCCESS(pIrp->IoStatus.Status)) 482 { 483 switch (pIrpSp->MinorFunction) 484 { 485 case IRP_MN_SET_POWER: 486 487 switch (pIrpSp->Parameters.Power.Type) 488 { 489 case DevicePowerState: 490 switch (pIrpSp->Parameters.Power.State.DeviceState) 491 { 492 case PowerDeviceD0: 493 break; 494 } 495 break; 496 } 497 break; 498 } 520 499 } 521 500 } … … 532 511 * @param pIrp IRP 533 512 */ 534 NTSTATUS VBoxGuestPower(PDEVICE_OBJECT pDevObj, PIRP pIrp)513 NTSTATUS vboxguestwinPower(PDEVICE_OBJECT pDevObj, PIRP pIrp) 535 514 { 536 515 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp); … … 540 519 POWER_ACTION powerAction; 541 520 542 dprintf(("VBoxGuest::VBoxGuestPower\n"));521 Log(("VBoxGuest::vboxguestwinGuestPower\n")); 543 522 544 523 powerType = pStack->Parameters.Power.Type; … … 550 529 case IRP_MN_SET_POWER: 551 530 { 552 dprintf(("VBoxGuest::VBoxGuestPower: IRP_MN_SET_POWER\n"));531 Log(("VBoxGuest::vboxguestwinGuestPower: IRP_MN_SET_POWER, type= %d\n", powerType)); 553 532 switch (powerType) 554 533 { 555 534 case SystemPowerState: 556 535 { 557 dprintf(("VBoxGuest::VBoxGuestPower: SystemPowerState\n")); 536 Log(("VBoxGuest::vboxguestwinGuestPower: SystemPowerState, action = %d, state = %d\n", powerAction, powerState)); 537 558 538 switch (powerAction) 559 539 { 540 case PowerActionSleep: 541 542 /* System now is in a working state. */ 543 if (powerState.SystemState == PowerSystemWorking) 544 { 545 if ( pDevExt 546 && pDevExt->win.s.LastSystemPowerAction == PowerActionHibernate) 547 { 548 Log(("VBoxGuest::vboxguestwinGuestPower: Returning from hibernation!\n")); 549 #ifdef VBOX_WITH_HGCM 550 int rc = VBoxGuestHGCMInitCommunication(pDevExt, vboxguestwinVersionToOSType(g_winVersion)); 551 if (RT_FAILURE(rc)) 552 Log(("VBoxGuest::vboxguestwinGuestPower: Cannot re-init HGCM chain, rc = %d!\n", rc)); 553 #endif 554 } 555 } 556 break; 557 560 558 case PowerActionShutdownReset: 561 559 { 562 dprintf(("VBoxGuest::VBoxGuestPower: power action reset!\n")); 563 /* tell the VMM that we no longer support mouse pointer integration */ 564 565 VMMDevReqMouseStatus *req = NULL; 566 567 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_SetMouseStatus); 568 560 Log(("VBoxGuest::vboxguestwinGuestPower: Power action reset!\n")); 561 562 /* Tell the VMM that we no longer support mouse pointer integration. */ 563 VMMDevReqMouseStatus *pReq = NULL; 564 int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, sizeof (VMMDevReqMouseStatus), VMMDevReq_SetMouseStatus); 569 565 if (RT_SUCCESS(rc)) 570 566 { 571 req->mouseFeatures = 0; 572 req->pointerXPos = 0; 573 req->pointerYPos = 0; 574 575 rc = VbglGRPerform (&req->header); 576 567 pReq->mouseFeatures = 0; 568 pReq->pointerXPos = 0; 569 pReq->pointerYPos = 0; 570 571 rc = VbglGRPerform(&pReq->header); 577 572 if (RT_FAILURE(rc)) 578 573 { 579 dprintf(("VBoxGuest::PowerStateRequest: error communicating new power status to VMMDev. "574 Log(("VBoxGuest::PowerStateRequest: error communicating new power status to VMMDev. " 580 575 "rc = %Rrc\n", rc)); 581 576 } 582 577 583 VbglGRFree (&req->header);578 VbglGRFree(&pReq->header); 584 579 } 585 580 break; … … 589 584 case PowerActionShutdownOff: 590 585 { 591 dprintf(("VBoxGuest::VBoxGuestPower: power action shutdown!\n"));586 Log(("VBoxGuest::vboxguestwinGuestPower: Power action shutdown!\n")); 592 587 if (powerState.SystemState >= PowerSystemShutdown) 593 588 { 594 dprintf(("VBoxGuest::VBoxGuestPower: Telling the VMMDev to close the VM...\n")); 595 596 if (pDevExt && pDevExt->powerStateRequest) 589 Log(("VBoxGuest::vboxguestwinGuestPower: Telling the VMMDev to close the VM ...\n")); 590 591 VMMDevPowerStateRequest *pReq = pDevExt->win.s.pPowerStateRequest; 592 int rc = VERR_NOT_IMPLEMENTED; 593 if (pReq) 597 594 { 598 VMMDevPowerStateRequest *req = pDevExt->powerStateRequest; 599 600 req->header.requestType = VMMDevReq_SetPowerStatus; 601 req->powerState = VMMDevPowerState_PowerOff; 602 603 int rc = VbglGRPerform (&req->header); 604 605 if (RT_FAILURE(rc)) 606 { 607 dprintf(("VBoxGuest::PowerStateRequest: error communicating new power status to VMMDev. " 608 "rc = %Rrc\n", rc)); 609 } 595 pReq->header.requestType = VMMDevReq_SetPowerStatus; 596 pReq->powerState = VMMDevPowerState_PowerOff; 597 598 rc = VbglGRPerform(&pReq->header); 599 } 600 if (RT_FAILURE(rc)) 601 { 602 Log(("VBoxGuest::PowerStateRequest: Error communicating new power status to VMMDev. " 603 "rc = %Rrc\n", rc)); 610 604 } 611 605 } 612 606 break; 613 607 } 608 609 case PowerActionHibernate: 610 611 Log(("VBoxGuest::vboxguestwinGuestPower: Power action hibernate!\n")); 612 break; 614 613 } 614 615 /* 616 * Save the current system power action for later use. 617 * This becomes handy when we return from hibernation for example. 618 */ 619 if (pDevExt) 620 pDevExt->win.s.LastSystemPowerAction = powerAction; 621 615 622 break; 616 623 } … … 636 643 IoCopyCurrentIrpStackLocationToNext(pIrp); 637 644 IoSetCompletionRoutine(pIrp, 638 VBoxGuestPowerComplete,645 vboxguestwinPowerComplete, 639 646 (PVOID)pDevExt, 640 647 TRUE, 641 648 TRUE, 642 649 TRUE); 643 return PoCallDriver(pDevExt-> nextLowerDriver, pIrp);650 return PoCallDriver(pDevExt->win.s.pNextLowerDriver, pIrp); 644 651 }
Note:
See TracChangeset
for help on using the changeset viewer.