1 | /* $Id: VBoxGuest-win.h 48938 2013-10-07 21:23:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuest - Windows specifics.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2013 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___VBoxGuest_win_h
|
---|
19 | #define ___VBoxGuest_win_h
|
---|
20 |
|
---|
21 |
|
---|
22 | #include <iprt/cdefs.h>
|
---|
23 |
|
---|
24 | RT_C_DECLS_BEGIN
|
---|
25 | #ifdef RT_ARCH_X86
|
---|
26 | # define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
|
---|
27 | #endif
|
---|
28 | #include <ntddk.h>
|
---|
29 | #ifdef RT_ARCH_X86
|
---|
30 | # undef _InterlockedAddLargeStatistic
|
---|
31 | #endif
|
---|
32 | RT_C_DECLS_END
|
---|
33 |
|
---|
34 | #include <iprt/spinlock.h>
|
---|
35 | #include <iprt/memobj.h>
|
---|
36 |
|
---|
37 | #include <VBox/VMMDev.h>
|
---|
38 | #include <VBox/VBoxGuest.h>
|
---|
39 | #include "VBoxGuestInternal.h"
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 | /** Possible device states for our state machine. */
|
---|
44 | enum DEVSTATE
|
---|
45 | {
|
---|
46 | STOPPED,
|
---|
47 | WORKING,
|
---|
48 | PENDINGSTOP,
|
---|
49 | PENDINGREMOVE,
|
---|
50 | SURPRISEREMOVED,
|
---|
51 | REMOVED
|
---|
52 | };
|
---|
53 |
|
---|
54 | typedef struct VBOXGUESTWINBASEADDRESS
|
---|
55 | {
|
---|
56 | /** Original device physical address. */
|
---|
57 | PHYSICAL_ADDRESS RangeStart;
|
---|
58 | /** Length of I/O or memory range. */
|
---|
59 | ULONG RangeLength;
|
---|
60 | /** Flag: Unmapped range is I/O or memory range. */
|
---|
61 | BOOLEAN RangeInMemory;
|
---|
62 | /** Mapped I/O or memory range. */
|
---|
63 | PVOID MappedRangeStart;
|
---|
64 | /** Flag: mapped range is I/O or memory range. */
|
---|
65 | BOOLEAN MappedRangeInMemory;
|
---|
66 | /** Flag: resource is mapped (i.e. MmMapIoSpace called). */
|
---|
67 | BOOLEAN ResourceMapped;
|
---|
68 | } VBOXGUESTWINBASEADDRESS, *PVBOXGUESTWINBASEADDRESS;
|
---|
69 |
|
---|
70 |
|
---|
71 | /** Windows-specific device extension bits. */
|
---|
72 | typedef struct VBOXGUESTDEVEXTWIN
|
---|
73 | {
|
---|
74 | VBOXGUESTDEVEXT Core;
|
---|
75 |
|
---|
76 | /** Our functional driver object. */
|
---|
77 | PDEVICE_OBJECT pDeviceObject;
|
---|
78 | /** Top of the stack. */
|
---|
79 | PDEVICE_OBJECT pNextLowerDriver;
|
---|
80 | /** Currently active Irp. */
|
---|
81 | IRP *pCurrentIrp;
|
---|
82 | /** Interrupt object pointer. */
|
---|
83 | PKINTERRUPT pInterruptObject;
|
---|
84 |
|
---|
85 | /** Bus number where the device is located. */
|
---|
86 | ULONG busNumber;
|
---|
87 | /** Slot number where the device is located. */
|
---|
88 | ULONG slotNumber;
|
---|
89 | /** Device interrupt level. */
|
---|
90 | ULONG interruptLevel;
|
---|
91 | /** Device interrupt vector. */
|
---|
92 | ULONG interruptVector;
|
---|
93 | /** Affinity mask. */
|
---|
94 | KAFFINITY interruptAffinity;
|
---|
95 | /** LevelSensitive or Latched. */
|
---|
96 | KINTERRUPT_MODE interruptMode;
|
---|
97 |
|
---|
98 | /** PCI base address information. */
|
---|
99 | ULONG pciAddressCount;
|
---|
100 | VBOXGUESTWINBASEADDRESS pciBaseAddress[PCI_TYPE0_ADDRESSES];
|
---|
101 |
|
---|
102 | /** Physical address and length of VMMDev memory. */
|
---|
103 | PHYSICAL_ADDRESS vmmDevPhysMemoryAddress;
|
---|
104 | ULONG vmmDevPhysMemoryLength;
|
---|
105 |
|
---|
106 | /** Device state. */
|
---|
107 | DEVSTATE devState;
|
---|
108 | DEVSTATE prevDevState;
|
---|
109 |
|
---|
110 | /** Last system power action set (see VBoxGuestPower). */
|
---|
111 | POWER_ACTION LastSystemPowerAction;
|
---|
112 | /** Preallocated generic request for shutdown. */
|
---|
113 | VMMDevPowerStateRequest *pPowerStateRequest;
|
---|
114 | /** Preallocated VMMDevEvents for IRQ handler. */
|
---|
115 | VMMDevEvents *pIrqAckEvents;
|
---|
116 |
|
---|
117 | /** Pre-allocated kernel session data. This is needed
|
---|
118 | * for handling kernel IOCtls. */
|
---|
119 | struct VBOXGUESTSESSION *pKernelSession;
|
---|
120 |
|
---|
121 | /** Spinlock protecting MouseNotifyCallback. Required since the consumer is
|
---|
122 | * in a DPC callback and not the ISR. */
|
---|
123 | KSPIN_LOCK MouseEventAccessLock;
|
---|
124 | } VBOXGUESTDEVEXTWIN, *PVBOXGUESTDEVEXTWIN;
|
---|
125 |
|
---|
126 |
|
---|
127 | /** NT (windows) version identifier. */
|
---|
128 | typedef enum VBGDNTVER
|
---|
129 | {
|
---|
130 | VBGDNTVER_INVALID = 0,
|
---|
131 | VBGDNTVER_WINNT4,
|
---|
132 | VBGDNTVER_WIN2K,
|
---|
133 | VBGDNTVER_WINXP,
|
---|
134 | VBGDNTVER_WIN2K3,
|
---|
135 | VBGDNTVER_WINVISTA,
|
---|
136 | VBGDNTVER_WIN7,
|
---|
137 | VBGDNTVER_WIN8,
|
---|
138 | VBGDNTVER_WIN81,
|
---|
139 | } VBGDNTVER;
|
---|
140 | extern VBGDNTVER g_enmVbgdNtVer;
|
---|
141 |
|
---|
142 |
|
---|
143 | #define VBOXGUEST_UPDATE_DEVSTATE(a_pDevExt, a_newDevState) \
|
---|
144 | do { \
|
---|
145 | (a_pDevExt)->prevDevState = (a_pDevExt)->devState; \
|
---|
146 | (a_pDevExt)->devState = (a_newDevState); \
|
---|
147 | } while (0)
|
---|
148 |
|
---|
149 | /** CM_RESOURCE_MEMORY_* flags which were used on XP or earlier. */
|
---|
150 | #define VBOX_CM_PRE_VISTA_MASK (0x3f)
|
---|
151 |
|
---|
152 |
|
---|
153 | RT_C_DECLS_BEGIN
|
---|
154 |
|
---|
155 | #ifdef TARGET_NT4
|
---|
156 | NTSTATUS vbgdNt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
|
---|
157 | #else
|
---|
158 | NTSTATUS vbgdNtInit(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
159 | NTSTATUS vbgdNtPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
160 | NTSTATUS vbgdNtPower(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
161 | #endif
|
---|
162 |
|
---|
163 | /** @name Common routines used in both (PnP and legacy) driver versions.
|
---|
164 | * @{
|
---|
165 | */
|
---|
166 | #ifdef TARGET_NT4
|
---|
167 | NTSTATUS vbgdNtInit(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
|
---|
168 | #else
|
---|
169 | NTSTATUS vbgdNtInit(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
170 | #endif
|
---|
171 | NTSTATUS vbgdNtCleanup(PDEVICE_OBJECT pDevObj);
|
---|
172 | VOID vbgdNtDpcHandler(PKDPC pDPC, PDEVICE_OBJECT pDevObj, PIRP pIrp, PVOID pContext);
|
---|
173 | BOOLEAN vbgdNtIsrHandler(PKINTERRUPT interrupt, PVOID serviceContext);
|
---|
174 | NTSTATUS vbgdNtScanPCIResourceList(PCM_RESOURCE_LIST pResList, PVBOXGUESTDEVEXTWIN pDevExt);
|
---|
175 | NTSTATUS vbgdNtMapVMMDevMemory(PVBOXGUESTDEVEXTWIN pDevExt, PHYSICAL_ADDRESS PhysAddr, ULONG cbToMap,
|
---|
176 | void **ppvMMIOBase, uint32_t *pcbMMIO);
|
---|
177 | void vbgdNtUnmapVMMDevMemory(PVBOXGUESTDEVEXTWIN pDevExt);
|
---|
178 | VBOXOSTYPE vbgdNtVersionToOSType(VBGDNTVER enmNtVer);
|
---|
179 | /** @} */
|
---|
180 |
|
---|
181 | RT_C_DECLS_END
|
---|
182 |
|
---|
183 | #ifdef TARGET_NT4
|
---|
184 | /*
|
---|
185 | * XP DDK #defines ExFreePool to ExFreePoolWithTag. The latter does not exist
|
---|
186 | * on NT4, so... The same for ExAllocatePool.
|
---|
187 | */
|
---|
188 | # undef ExAllocatePool
|
---|
189 | # undef ExFreePool
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | #endif /* !___VBoxGuest_win_h */
|
---|
193 |
|
---|