VBoxGuest-win-pnp.cpp revision a57b3586d0f1a87e0024e318f3c8dad382113611
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VBoxGuest-win-pnp - Windows Plug'n'Play specifics.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2010-2013 Oracle Corporation
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * available from http://www.virtualbox.org. This file is free software;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync/*******************************************************************************
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync* Header Files *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync*******************************************************************************/
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/*******************************************************************************
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync* Defined Constants And Macros *
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync*******************************************************************************/
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncstatic NTSTATUS vbgdNtSendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncstatic NTSTATUS vbgdNtPnPIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncstatic VOID vbgdNtShowDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync# pragma alloc_text(PAGE, vbgdNtSendIrpSynchronously)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync# pragma alloc_text(PAGE, vbgdNtShowDeviceResources)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Irp completion routine for PnP Irps we send.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @param pDevObj Device object.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @param pIrp Request packet.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @param event Semaphore.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @return NT status code
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncstatic NTSTATUS vbgdNtPnpIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Helper to send a PnP IRP and wait until it's done.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @param pDevObj Device object.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @param pIrp Request packet.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @param fStrict When set, returns an error if the IRP gives an error.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @return NT status code
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncstatic NTSTATUS vbgdNtSendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync IoSetCompletionRoutine(pIrp, (PIO_COMPLETION_ROUTINE)vbgdNtPnpIrpComplete,
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync && (rc == STATUS_NOT_SUPPORTED || rc == STATUS_INVALID_DEVICE_REQUEST))
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync Log(("VBoxGuest::vbgdNtSendIrpSynchronously: Returning 0x%x\n", rc));
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * PnP Request handler.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @param pDevObj Device object.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * @param pIrp Request packet.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncNTSTATUS vbgdNtPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync static char *s_apszFnctName[] =
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_START_DEVICE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_REMOVE_DEVICE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_REMOVE_DEVICE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_CANCEL_REMOVE_DEVICE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_STOP_DEVICE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_STOP_DEVICE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_CANCEL_STOP_DEVICE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_DEVICE_RELATIONS",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_INTERFACE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_CAPABILITIES",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_RESOURCES",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_RESOURCE_REQUIREMENTS",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_DEVICE_TEXT",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_FILTER_RESOURCE_REQUIREMENTS",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_0xE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_READ_CONFIG",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_WRITE_CONFIG",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_EJECT",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_SET_LOCK",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_ID",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_PNP_DEVICE_STATE",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_QUERY_BUS_INFORMATION",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_DEVICE_USAGE_NOTIFICATION",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync "IRP_MN_SURPRISE_REMOVAL",
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync Log(("VBoxGuest::vbgdNtGuestPnp: MinorFunction: %s\n",
pStack->MinorFunction < RT_ELEMENTS(s_apszFnctName)) ? s_apszFnctName[pStack->MinorFunction] : "Unknown"));
case IRP_MN_START_DEVICE:
Log(("VBoxGuest::vbgdNtVBoxGuestPnP: START_DEVICE: pStack->Parameters.StartDevice.AllocatedResources = %p\n",
Log(("VBoxGuest::vbgdNtVBoxGuestPnP: START_DEVICE: No resources, pDevExt = %p, nextLowerDriver = %p!\n",
case IRP_MN_SURPRISE_REMOVAL:
return rc;
#ifdef VBOX_REBOOT_ON_UNINSTALL
Log(("VBoxGuest::vbgdNtGuestPnp: QUERY_REMOVE_DEVICE: Device cannot be removed without a reboot.\n"));
return rc;
case IRP_MN_REMOVE_DEVICE:
case IRP_MN_QUERY_STOP_DEVICE:
#ifdef VBOX_REBOOT_ON_UNINSTALL
Log(("VBoxGuest::vbgdNtGuestPnp: QUERY_STOP_DEVICE: Device cannot be stopped without a reboot!\n"));
return rc;
case IRP_MN_STOP_DEVICE:
return rc;
return rc;
return rc;
if (pIrpSp)
case IRP_MN_SET_POWER:
case DevicePowerState:
case PowerDeviceD0:
return STATUS_SUCCESS;
case IRP_MN_SET_POWER:
switch (enmPowerType)
case SystemPowerState:
switch (enmPowerAction)
case PowerActionSleep:
if ( pDevExt
case PowerActionShutdownReset:
case PowerActionShutdown:
case PowerActionShutdownOff:
if (pReq)
Log(("VBoxGuest::PowerStateRequest: Error communicating new power status to VMMDev. vrc = %Rrc\n", vrc));
case PowerActionHibernate:
if (pDevExt)
TRUE,
TRUE,
TRUE);