VBoxGuestPnP.cpp revision 296cdbced70651cbf4c98767398d0c898885b54b
/** @file
*
* VBoxGuest -- VirtualBox Win32 guest support driver PnP code
*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
// enable backdoor logging
//#define LOG_ENABLED
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxGuestPnP.h"
#include "Helper.h"
#include <VBox/VBoxGuestLib.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
extern "C"
{
}
#ifdef ALLOC_PRAGMA
#endif
#define LOG_ENABLED
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/**
* Irp completion routine for PnP Irps we send.
*
* @param pDevObj Device object.
* @param pIrp Request packet.
* @param event Semaphore.
* @return NT status code
*/
{
return STATUS_MORE_PROCESSING_REQUIRED;
}
/**
* Helper to send a PnP IRP and wait until it's done.
*
* @param pDevObj Device object.
* @param pIrp Request packet.
* @param fStrict When set, returns an error if the IRP gives an error.
* @return NT status code
*/
{
if (rc == STATUS_PENDING)
{
}
if (!fStrict
{
rc = STATUS_SUCCESS;
}
return rc;
}
/**
* PnP Request handler.
*
* @param pDevObj Device object.
* @param pIrp Request packet.
*/
{
#ifdef LOG_ENABLED
static char* fcnname[] =
{
"IRP_MN_START_DEVICE",
"IRP_MN_QUERY_REMOVE_DEVICE",
"IRP_MN_REMOVE_DEVICE",
"IRP_MN_CANCEL_REMOVE_DEVICE",
"IRP_MN_STOP_DEVICE",
"IRP_MN_QUERY_STOP_DEVICE",
"IRP_MN_CANCEL_STOP_DEVICE",
"IRP_MN_QUERY_DEVICE_RELATIONS",
"IRP_MN_QUERY_INTERFACE",
"IRP_MN_QUERY_CAPABILITIES",
"IRP_MN_QUERY_RESOURCES",
"IRP_MN_QUERY_RESOURCE_REQUIREMENTS",
"IRP_MN_QUERY_DEVICE_TEXT",
"IRP_MN_FILTER_RESOURCE_REQUIREMENTS",
"",
"IRP_MN_READ_CONFIG",
"IRP_MN_WRITE_CONFIG",
"IRP_MN_EJECT",
"IRP_MN_SET_LOCK",
"IRP_MN_QUERY_ID",
"IRP_MN_QUERY_PNP_DEVICE_STATE",
"IRP_MN_QUERY_BUS_INFORMATION",
"IRP_MN_DEVICE_USAGE_NOTIFICATION",
"IRP_MN_SURPRISE_REMOVAL",
};
dprintf(("VBoxGuest::VBoxGuestPnp: MinorFunction: %s\n", pStack->MinorFunction < (sizeof(fcnname)/sizeof(fcnname[0])) ? fcnname[pStack->MinorFunction] : "unknown"));
#endif
switch (pStack->MinorFunction)
{
case IRP_MN_START_DEVICE:
{
{
dprintf(("VBoxGuest::START_DEVICE: pStack->Parameters.StartDevice.AllocatedResources = %p\n", pStack->Parameters.StartDevice.AllocatedResources));
{
dprintf(("VBoxGuest::START_DEVICE: no resources, pDevExt = %p, nextLowerDriver = %p!!!\n", pDevExt, pDevExt? pDevExt->nextLowerDriver: NULL));
}
else
{
showDeviceResources(&pStack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList);
pDevExt);
/** @todo cleanup and merging codepath with NT */
int rcVBox;
if (!RT_SUCCESS(rcVBox))
{
}
if (NT_SUCCESS(rc))
{
rcVBox = VbglGRAlloc ((VMMDevRequestHeader **)&pDevExt->irqAckEvents, sizeof (VMMDevEvents), VMMDevReq_AcknowledgeEvents);
if (!RT_SUCCESS(rc))
{
}
}
if (NT_SUCCESS(rc))
{
rcVBox = VbglGRAlloc ((VMMDevRequestHeader **)&pDevExt->powerStateRequest, sizeof (VMMDevPowerStateRequest), VMMDevReq_SetPowerStatus);
if (!RT_SUCCESS(rc))
{
dprintf(("VBoxGuest::START_DEVICE: VbglAlloc failed for powerStateRequest. rcVBox = %d\n", rcVBox));
}
}
if (NT_SUCCESS(rc))
{
// Map physical address of VMMDev memory
if (!NT_SUCCESS(rc))
{
}
}
if (NT_SUCCESS(rc))
{
// register DPC and ISR
dprintf(("VBoxGuest::VBoxGuestPnp: initializing DPC...\n"));
pDevExt, // context
NULL, // optional spinlock
TRUE, // shareable interrupt
FALSE); // don't save FPU stack
if (!NT_SUCCESS(rc))
{
}
}
}
}
if (NT_SUCCESS(rc))
{
// initialize the event notification semaphore
/* Preallocated constant timeout 250ms for HGCM async waiter. */
if (RT_SUCCESS(vrc))
{
if (RT_FAILURE(vrc))
dprintf(("VBoxGuest::VBoxGuestPnp::IRP_MN_START_DEVICE: could not report information to host, rc = %d\n", rc));
}
// ready to rumble!
dprintf(("VBoxGuest::VBoxGuestPnp: device is ready!\n"));
} else
{
// need to unmap memory in case of errors
}
break;
}
{
#ifdef VBOX_REBOOT_ON_UNINSTALL
/* The device can not be removed without a reboot. */
{
}
#else
{
}
#endif /* VBOX_REBOOT_ON_UNINSTALL */
break;
}
case IRP_MN_REMOVE_DEVICE:
{
/* @todo merge Remove and Stop, make a helper for common actions */
if (pDevExt->workerThread)
{
dprintf(("VBoxGuest::VBoxGuestPnp: waiting for the worker thread to terminate...\n"));
dprintf(("VBoxGuest::VBoxGuestPnp: returned from KeWaitForSingleObject for worker thread\n"));
}
if (pDevExt->idleThread)
{
dprintf(("VBoxGuest::VBoxGuestPnp: waiting for the idle thread to terminate...\n"));
dprintf(("VBoxGuest::VBoxGuestPnp: returned from KeWaitForSingleObject for idle thread\n"));
}
VbglTerminate ();
// according to MSDN we have to unmap previously mapped memory
/* Free the memory balloon (if any) */
{
}
#ifdef VBOX_WITH_HGCM
#endif
break;
}
case IRP_MN_QUERY_STOP_DEVICE:
{
#ifdef VBOX_REBOOT_ON_UNINSTALL
dprintf(("VBoxGuest::VBoxGuestPnp: refuse\n"));
/* The device can not be stopped without a reboot. */
{
}
#else
{
}
#endif /* VBOX_REBOOT_ON_UNINSTALL */
break;
}
case IRP_MN_STOP_DEVICE:
{
{
VbglTerminate ();
// according to MSDN we have to unmap previously mapped memory
dprintf(("VBoxGuest::VBoxGuestPnp: device has been disabled\n"));
} else
{
}
break;
}
default:
{
}
}
return rc;
}
/**
* Debug helper to dump a device resource list.
*
* @param pResourceList list of device resources.
*/
{
#ifdef LOG_ENABLED
ULONG i;
{
static char* name[] =
{
"CmResourceTypeNull",
"CmResourceTypePort",
"CmResourceTypeInterrupt",
"CmResourceTypeMemory",
"CmResourceTypeDma",
"CmResourceTypeDeviceSpecific",
"CmResourceTypeBusNumber",
"CmResourceTypeDevicePrivate",
"CmResourceTypeAssignedResource",
"CmResourceTypeSubAllocateFrom",
};
dprintf(("VBoxGuest::showDeviceResources: type %s", type < (sizeof(name)/sizeof(name[0])) ? name[type] : "unknown"));
switch (type)
{
case CmResourceTypePort:
case CmResourceTypeMemory:
dprintf(("VBoxGuest::showDeviceResources: start %8X%8.8lX length %X\n",
break;
case CmResourceTypeInterrupt:
dprintf(("VBoxGuest::showDeviceResources: level %X, vector %X, affinity %X\n",
break;
case CmResourceTypeDma:
dprintf(("VBoxGuest::showDeviceResources: channel %d, port %X\n",
break;
default:
dprintf(("\n"));
break;
}
}
#endif
}
/**
* Handle the power completion event.
*
* @returns NT status code
* @param devObj targetted device object
* @param irp IO request packet
* @param context context value passed to IoSetCompletionRoutine in VBoxGuestPower
*/
{
{
switch (irpSp->MinorFunction)
{
case IRP_MN_SET_POWER:
{
case DevicePowerState:
{
case PowerDeviceD0:
break;
}
break;
}
break;
}
}
return STATUS_SUCCESS;
}
/**
* Handle the Power requests.
*
* @returns NT status code
* @param pDevObj device object
* @param pIrp IRP
*/
{
dprintf(("VBoxGuest::VBoxGuestPower\n"));
switch (pStack->MinorFunction)
{
case IRP_MN_SET_POWER:
{
dprintf(("VBoxGuest::VBoxGuestPower: IRP_MN_SET_POWER\n"));
switch (powerType)
{
case SystemPowerState:
{
dprintf(("VBoxGuest::VBoxGuestPower: SystemPowerState\n"));
switch (powerAction)
{
case PowerActionShutdownReset:
{
dprintf(("VBoxGuest::VBoxGuestPower: power action reset!\n"));
/* tell the VMM that we no longer support mouse pointer integration */
int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_SetMouseStatus);
if (RT_SUCCESS(rc))
{
req->mouseFeatures = 0;
req->pointerXPos = 0;
req->pointerYPos = 0;
if (RT_FAILURE(rc))
{
dprintf(("VBoxGuest::PowerStateRequest: error communicating new power status to VMMDev. "
"rc = %Rrc\n", rc));
}
}
break;
}
case PowerActionShutdown:
case PowerActionShutdownOff:
{
dprintf(("VBoxGuest::VBoxGuestPower: power action shutdown!\n"));
{
dprintf(("VBoxGuest::VBoxGuestPower: Telling the VMMDev to close the VM...\n"));
{
if (RT_FAILURE(rc))
{
dprintf(("VBoxGuest::PowerStateRequest: error communicating new power status to VMMDev. "
"rc = %Rrc\n", rc));
}
}
}
break;
}
}
break;
}
default:
break;
}
break;
}
default:
break;
}
/*
* Whether we are completing or relaying this power IRP,
* we must call PoStartNextPowerIrp.
*/
/*
* Send the IRP down the driver stack,
* using PoCallDriver (not IoCallDriver, as for non-power irps).
*/
TRUE,
TRUE,
TRUE);
}