VBoxGuest-win.h revision b4a81d521ea7f88aca6f77b2725541e58a2dc018
1e40f57c72c881067b0314f898e1004211bb7650vboxsync/** @file
1e40f57c72c881067b0314f898e1004211bb7650vboxsync *
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VBoxGuest - Windows specifics.
1e40f57c72c881067b0314f898e1004211bb7650vboxsync *
1e40f57c72c881067b0314f898e1004211bb7650vboxsync * Copyright (C) 2010 Oracle Corporation
1e40f57c72c881067b0314f898e1004211bb7650vboxsync *
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1e40f57c72c881067b0314f898e1004211bb7650vboxsync * available from http://www.virtualbox.org. This file is free software;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1e40f57c72c881067b0314f898e1004211bb7650vboxsync * General Public License (GPL) as published by the Free Software
1e40f57c72c881067b0314f898e1004211bb7650vboxsync * 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
1e40f57c72c881067b0314f898e1004211bb7650vboxsync#ifndef ___VBoxGuest_win_h
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#define ___VBoxGuest_win_h
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync/*******************************************************************************
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync* Header Files *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync*******************************************************************************/
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#include <iprt/cdefs.h>
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsyncRT_C_DECLS_BEGIN
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync#include <ntddk.h>
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsyncRT_C_DECLS_END
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsync#include <iprt/spinlock.h>
1e40f57c72c881067b0314f898e1004211bb7650vboxsync#include <iprt/memobj.h>
1e40f57c72c881067b0314f898e1004211bb7650vboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsync#include <VBox/VMMDev.h>
1e40f57c72c881067b0314f898e1004211bb7650vboxsync#include <VBox/VBoxGuest.h>
1e40f57c72c881067b0314f898e1004211bb7650vboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsync/*******************************************************************************
1e40f57c72c881067b0314f898e1004211bb7650vboxsync* Structures and Typedefs *
1e40f57c72c881067b0314f898e1004211bb7650vboxsync*******************************************************************************/
1e40f57c72c881067b0314f898e1004211bb7650vboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsync/** Pointer to the VBoxGuest per session data. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsynctypedef struct VBOXGUESTSESSION *PVBOXGUESTSESSION;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsync/** Possible device states for our state machine. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsyncenum DEVSTATE
1e40f57c72c881067b0314f898e1004211bb7650vboxsync{
1e40f57c72c881067b0314f898e1004211bb7650vboxsync STOPPED,
1e40f57c72c881067b0314f898e1004211bb7650vboxsync WORKING,
1e40f57c72c881067b0314f898e1004211bb7650vboxsync PENDINGSTOP,
1e40f57c72c881067b0314f898e1004211bb7650vboxsync PENDINGREMOVE,
1e40f57c72c881067b0314f898e1004211bb7650vboxsync SURPRISEREMOVED,
1e40f57c72c881067b0314f898e1004211bb7650vboxsync REMOVED
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync};
1e40f57c72c881067b0314f898e1004211bb7650vboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsynctypedef struct VBOXGUESTWINBASEADDRESS
1e40f57c72c881067b0314f898e1004211bb7650vboxsync{
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Original device physical address. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync PHYSICAL_ADDRESS RangeStart;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Length of I/O or memory range. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync ULONG RangeLength;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Flag: Unmapped range is I/O or memory range. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync BOOLEAN RangeInMemory;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Mapped I/O or memory range. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync PVOID MappedRangeStart;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Flag: mapped range is I/O or memory range. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync BOOLEAN MappedRangeInMemory;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Flag: resource is mapped (i.e. MmMapIoSpace called). */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync BOOLEAN ResourceMapped;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync} VBOXGUESTWINBASEADDRESS, *PVBOXGUESTWINBASEADDRESS;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsync
1e40f57c72c881067b0314f898e1004211bb7650vboxsync/** Windows-specific device extension bits. */
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsynctypedef struct VBOXGUESTDEVEXTWIN
1e40f57c72c881067b0314f898e1004211bb7650vboxsync{
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Our functional driver object. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync PDEVICE_OBJECT pDeviceObject;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Top of the stack. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync PDEVICE_OBJECT pNextLowerDriver;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Currently active Irp. */
1e40f57c72c881067b0314f898e1004211bb7650vboxsync IRP *pCurrentIrp;
1e40f57c72c881067b0314f898e1004211bb7650vboxsync /** Interrupt object pointer. */
PKINTERRUPT pInterruptObject;
/** Bus number where the device is located. */
ULONG busNumber;
/** Slot number where the device is located. */
ULONG slotNumber;
/** Device interrupt level. */
ULONG interruptLevel;
/** Device interrupt vector. */
ULONG interruptVector;
/** Affinity mask. */
KAFFINITY interruptAffinity;
/** LevelSensitive or Latched. */
KINTERRUPT_MODE interruptMode;
/** PCI base address information. */
ULONG pciAddressCount;
VBOXGUESTWINBASEADDRESS pciBaseAddress[PCI_TYPE0_ADDRESSES];
/** Physical address and length of VMMDev memory. */
PHYSICAL_ADDRESS vmmDevPhysMemoryAddress;
ULONG vmmDevPhysMemoryLength;
/** Device state. */
DEVSTATE devState;
DEVSTATE prevDevState;
/** Last system power action set (see VBoxGuestPower). */
POWER_ACTION LastSystemPowerAction;
/** Preallocated generic request for shutdown. */
VMMDevPowerStateRequest *pPowerStateRequest;
/** Preallocated VMMDevEvents for IRQ handler. */
VMMDevEvents *pIrqAckEvents;
/** Pre-allocated kernel session data. This is needed
* for handling kernel IOCtls. */
PVBOXGUESTSESSION pKernelSession;
KSPIN_LOCK MouseEventAccessLock;
PFNVBOXMOUSENOTIFYCB pfnMouseNotify;
void *pvMouseNotify;
} VBOXGUESTDEVEXTWIN, *PVBOXGUESTDEVEXTWIN;
#define VBOXGUEST_UPDATE_DEVSTATE(_pDevExt, _newDevState) do { \
(_pDevExt)->win.s.prevDevState = (_pDevExt)->win.s.devState; \
(_pDevExt)->win.s.devState = (_newDevState); \
} while (0)
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** CM_RESOURCE_MEMORY_* flags which were used on XP or earlier. */
#define VBOX_CM_PRE_VISTA_MASK (0x3f)
/** Windows version identifier. */
typedef enum
{
WINNT4 = 1,
WIN2K = 2,
WINXP = 3,
WIN2K3 = 4,
WINVISTA = 5,
WIN7 = 6,
WIN8 = 7
} winVersion_t;
extern winVersion_t winVersion;
/*******************************************************************************
* Declared prototypes for helper routines used in both (PnP and legacy) *
* driver versions. *
*******************************************************************************/
#include "VBoxGuestInternal.h"
RT_C_DECLS_BEGIN
#ifdef TARGET_NT4
NTSTATUS vboxguestwinnt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
NTSTATUS vboxguestwinInit(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
#else
NTSTATUS vboxguestwinInit(PDEVICE_OBJECT pDevObj, PIRP pIrp);
#endif
NTSTATUS vboxguestwinCleanup(PDEVICE_OBJECT pDevObj);
NTSTATUS vboxguestwinPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp);
VOID vboxguestwinDpcHandler(PKDPC pDPC, PDEVICE_OBJECT pDevObj, PIRP pIrp, PVOID pContext);
BOOLEAN vboxguestwinIsrHandler(PKINTERRUPT interrupt, PVOID serviceContext);
NTSTATUS vboxguestwinScanPCIResourceList(PCM_RESOURCE_LIST pResList, PVBOXGUESTDEVEXT pDevExt);
NTSTATUS vboxguestwinMapVMMDevMemory(PVBOXGUESTDEVEXT pDevExt, PHYSICAL_ADDRESS physicalAdr, ULONG ulLength,
void **ppvMMIOBase, uint32_t *pcbMMIO);
void vboxguestwinUnmapVMMDevMemory(PVBOXGUESTDEVEXT pDevExt);
VBOXOSTYPE vboxguestwinVersionToOSType(winVersion_t winVer);
NTSTATUS vboxguestwinPower(PDEVICE_OBJECT pDevObj, PIRP pIrp);
RT_C_DECLS_END
#ifdef TARGET_NT4
/*
* XP DDK #defines ExFreePool to ExFreePoolWithTag. The latter does not exist
* on NT4, so... The same for ExAllocatePool.
*/
#undef ExAllocatePool
#undef ExFreePool
#endif
#endif /* ___VBoxGuest_win_h */