VBoxGuest-win.h revision b2640405e06105d868b5fc8f7b676bb680884380
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/** @file
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * VBoxGuest - Windows specifics.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Copyright (C) 2010 Oracle Corporation
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * available from http://www.virtualbox.org. This file is free software;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * General Public License (GPL) as published by the Free Software
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#ifndef ___VBoxGuest_win_h
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#define ___VBoxGuest_win_h
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/*******************************************************************************
b2640405e06105d868b5fc8f7b676bb680884380vboxsync* Header Files *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync*******************************************************************************/
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#include <iprt/cdefs.h>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncRT_C_DECLS_BEGIN
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#include <ntddk.h>
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncRT_C_DECLS_END
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#include <iprt/spinlock.h>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#include <iprt/memobj.h>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#include <VBox/VMMDev.h>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#include <VBox/VBoxGuest.h>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/*******************************************************************************
b2640405e06105d868b5fc8f7b676bb680884380vboxsync* Structures and Typedefs *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync*******************************************************************************/
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/** Pointer to the VBoxGuest per session data. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsynctypedef struct VBOXGUESTSESSION *PVBOXGUESTSESSION;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/** Possible device states for our state machine. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncenum DEVSTATE
b2640405e06105d868b5fc8f7b676bb680884380vboxsync{
b2640405e06105d868b5fc8f7b676bb680884380vboxsync STOPPED,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync WORKING,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PENDINGSTOP,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PENDINGREMOVE,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync SURPRISEREMOVED,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync REMOVED
b2640405e06105d868b5fc8f7b676bb680884380vboxsync};
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsynctypedef struct VBOXGUESTWINBASEADDRESS
b2640405e06105d868b5fc8f7b676bb680884380vboxsync{
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Original device physical address. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PHYSICAL_ADDRESS RangeStart;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Length of I/O or memory range. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync ULONG RangeLength;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Flag: Unmapped range is I/O or memory range. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync BOOLEAN RangeInMemory;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Mapped I/O or memory range. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PVOID MappedRangeStart;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Flag: mapped range is I/O or memory range. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync BOOLEAN MappedRangeInMemory;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Flag: resource is mapped (i.e. MmMapIoSpace called). */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync BOOLEAN ResourceMapped;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync} VBOXGUESTWINBASEADDRESS, *PVBOXGUESTWINBASEADDRESS;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/** Windows-specific HGCM device extension bits. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsynctypedef struct VBOXGUESTDEVEXTWINHGCM
b2640405e06105d868b5fc8f7b676bb680884380vboxsync{
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** The callback wait timeout. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync LARGE_INTEGER WaitTimeout;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Notification semaphore. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync KEVENT keventNotification;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync} VBOXGUESTDEVEXTWINHGCM, *PVBOXGUESTDEVEXTWINHGCM;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/** Windows-specific device extension bits. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsynctypedef struct VBOXGUESTDEVEXTWIN
b2640405e06105d868b5fc8f7b676bb680884380vboxsync{
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Our functional driver object. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PDEVICE_OBJECT pDeviceObject;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Top of the stack. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PDEVICE_OBJECT pNextLowerDriver;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Currently active Irp. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync IRP *pCurrentIrp;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Interrupt object pointer. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PKINTERRUPT pInterruptObject;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Bus number where the device is located. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync ULONG busNumber;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Slot number where the device is located. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync ULONG slotNumber;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Device interrupt level. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync ULONG interruptLevel;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Device interrupt vector. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync ULONG interruptVector;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Affinity mask. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync KAFFINITY interruptAffinity;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** LevelSensitive or Latched. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync KINTERRUPT_MODE interruptMode;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** PCI base address information. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync ULONG pciAddressCount;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync VBOXGUESTWINBASEADDRESS pciBaseAddress[PCI_TYPE0_ADDRESSES];
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Physical address and length of VMMDev memory. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PHYSICAL_ADDRESS vmmDevPhysMemoryAddress;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync ULONG vmmDevPhysMemoryLength;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Device state. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync DEVSTATE devState;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Last system power action set (see VBoxGuestPower). */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync POWER_ACTION LastSystemPowerAction;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Preallocated generic request for shutdown. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync VMMDevPowerStateRequest *pPowerStateRequest;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Preallocated VMMDevEvents for IRQ handler. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync VMMDevEvents *pIrqAckEvents;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Pre-allocated kernel session data. This is needed
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * for handling kernel IOCtls. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync PVBOXGUESTSESSION pKernelSession;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** Align the next bit on a 64-byte boundary and make sure it starts at the same
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * offset in both 64-bit and 32-bit builds.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @remarks The aligments of the members that are larger than 48 bytes should be
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * 64-byte for cache line reasons. structs containing small amounts of
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * data could be lumped together at the end with a < 64 byte padding
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * following it (to grow into and align the struct size).
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync uint8_t abAlignment1[HC_ARCH_BITS == 32 ? 24 : 4];
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /** HGCM stuff. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync union
b2640405e06105d868b5fc8f7b676bb680884380vboxsync {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#ifdef VBOX_WITH_HGCM
b2640405e06105d868b5fc8f7b676bb680884380vboxsync VBOXGUESTDEVEXTWINHGCM s;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#endif
b2640405e06105d868b5fc8f7b676bb680884380vboxsync uint8_t padding[256]; /* Multiple of 64; fix me! */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync } hgcm;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync} VBOXGUESTDEVEXTWIN, *PVBOXGUESTDEVEXTWIN;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/*******************************************************************************
b2640405e06105d868b5fc8f7b676bb680884380vboxsync* Defined Constants And Macros *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync*******************************************************************************/
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/** CM_RESOURCE_MEMORY_* flags which were used on XP or earlier. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#define VBOX_CM_PRE_VISTA_MASK (0x3f)
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/** Windows version identifier. */
b2640405e06105d868b5fc8f7b676bb680884380vboxsynctypedef enum
b2640405e06105d868b5fc8f7b676bb680884380vboxsync{
b2640405e06105d868b5fc8f7b676bb680884380vboxsync WINNT4 = 1,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync WIN2K = 2,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync WINXP = 3,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync WIN2K3 = 4,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync WINVISTA = 5,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync WIN7 = 6
b2640405e06105d868b5fc8f7b676bb680884380vboxsync} winVersion_t;
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncextern winVersion_t winVersion;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync/*******************************************************************************
b2640405e06105d868b5fc8f7b676bb680884380vboxsync* Declared prototypes for helper routines used in both (PnP and legacy) *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync* driver versions. *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync*******************************************************************************/
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#include "VBoxGuestInternal.h"
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncRT_C_DECLS_BEGIN
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncNTSTATUS vboxguestwinPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp);
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncVOID vboxguestwinDpcHandler(PKDPC pDPC, PDEVICE_OBJECT pDevObj, PIRP pIrp, PVOID pContext);
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncBOOLEAN vboxguestwinIsrHandler(PKINTERRUPT interrupt, PVOID serviceContext);
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncNTSTATUS vboxguestwinScanPCIResourceList(PCM_RESOURCE_LIST pResList, PVBOXGUESTDEVEXT pDevExt);
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncNTSTATUS vboxguestwinMapVMMDevMemory(PVBOXGUESTDEVEXT pDevExt, PHYSICAL_ADDRESS physicalAdr, ULONG ulLength,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync void **ppvMMIOBase, uint32_t *pcbMMIO);
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncvoid vboxguestwinUnmapVMMDevMemory(PVBOXGUESTDEVEXT pDevExt);
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncVBOXOSTYPE vboxguestwinVersionToOSType(winVersion_t winVer);
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncNTSTATUS vboxguestwinPower(PDEVICE_OBJECT pDevObj, PIRP pIrp);
b2640405e06105d868b5fc8f7b676bb680884380vboxsyncRT_C_DECLS_END
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync#endif /* ___VBoxGuest_win_h */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync