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