1 | /* $Id: VBoxGuest-win.h 53008 2014-10-09 11:34: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_WIN10
|
---|
140 | } VBGDNTVER;
|
---|
141 | extern VBGDNTVER g_enmVbgdNtVer;
|
---|
142 |
|
---|
143 |
|
---|
144 | #define VBOXGUEST_UPDATE_DEVSTATE(a_pDevExt, a_newDevState) \
|
---|
145 | do { \
|
---|
146 | (a_pDevExt)->prevDevState = (a_pDevExt)->devState; \
|
---|
147 | (a_pDevExt)->devState = (a_newDevState); \
|
---|
148 | } while (0)
|
---|
149 |
|
---|
150 | /** CM_RESOURCE_MEMORY_* flags which were used on XP or earlier. */
|
---|
151 | #define VBOX_CM_PRE_VISTA_MASK (0x3f)
|
---|
152 |
|
---|
153 |
|
---|
154 | RT_C_DECLS_BEGIN
|
---|
155 |
|
---|
156 | #ifdef TARGET_NT4
|
---|
157 | NTSTATUS vbgdNt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
|
---|
158 | #else
|
---|
159 | NTSTATUS vbgdNtInit(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
160 | NTSTATUS vbgdNtPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
161 | NTSTATUS vbgdNtPower(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
162 | #endif
|
---|
163 |
|
---|
164 | /** @name Common routines used in both (PnP and legacy) driver versions.
|
---|
165 | * @{
|
---|
166 | */
|
---|
167 | #ifdef TARGET_NT4
|
---|
168 | NTSTATUS vbgdNtInit(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
|
---|
169 | #else
|
---|
170 | NTSTATUS vbgdNtInit(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
171 | #endif
|
---|
172 | NTSTATUS vbgdNtCleanup(PDEVICE_OBJECT pDevObj);
|
---|
173 | VOID vbgdNtDpcHandler(PKDPC pDPC, PDEVICE_OBJECT pDevObj, PIRP pIrp, PVOID pContext);
|
---|
174 | BOOLEAN vbgdNtIsrHandler(PKINTERRUPT interrupt, PVOID serviceContext);
|
---|
175 | NTSTATUS vbgdNtScanPCIResourceList(PCM_RESOURCE_LIST pResList, PVBOXGUESTDEVEXTWIN pDevExt);
|
---|
176 | NTSTATUS vbgdNtMapVMMDevMemory(PVBOXGUESTDEVEXTWIN pDevExt, PHYSICAL_ADDRESS PhysAddr, ULONG cbToMap,
|
---|
177 | void **ppvMMIOBase, uint32_t *pcbMMIO);
|
---|
178 | void vbgdNtUnmapVMMDevMemory(PVBOXGUESTDEVEXTWIN pDevExt);
|
---|
179 | VBOXOSTYPE vbgdNtVersionToOSType(VBGDNTVER enmNtVer);
|
---|
180 | /** @} */
|
---|
181 |
|
---|
182 | RT_C_DECLS_END
|
---|
183 |
|
---|
184 | #ifdef TARGET_NT4
|
---|
185 | /*
|
---|
186 | * XP DDK #defines ExFreePool to ExFreePoolWithTag. The latter does not exist
|
---|
187 | * on NT4, so... The same for ExAllocatePool.
|
---|
188 | */
|
---|
189 | # undef ExAllocatePool
|
---|
190 | # undef ExFreePool
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | #endif /* !___VBoxGuest_win_h */
|
---|
194 |
|
---|