1*8a978a17SVictor Perevertkin /*++
2*8a978a17SVictor Perevertkin
3*8a978a17SVictor Perevertkin Copyright (c) Microsoft Corporation
4*8a978a17SVictor Perevertkin
5*8a978a17SVictor Perevertkin Module Name:
6*8a978a17SVictor Perevertkin
7*8a978a17SVictor Perevertkin FxDeviceUM.hpp
8*8a978a17SVictor Perevertkin
9*8a978a17SVictor Perevertkin Abstract:
10*8a978a17SVictor Perevertkin
11*8a978a17SVictor Perevertkin This is the definition of the FxDevice object UM specific
12*8a978a17SVictor Perevertkin
13*8a978a17SVictor Perevertkin Author:
14*8a978a17SVictor Perevertkin
15*8a978a17SVictor Perevertkin
16*8a978a17SVictor Perevertkin
17*8a978a17SVictor Perevertkin Environment:
18*8a978a17SVictor Perevertkin
19*8a978a17SVictor Perevertkin User mode only
20*8a978a17SVictor Perevertkin
21*8a978a17SVictor Perevertkin Revision History:
22*8a978a17SVictor Perevertkin
23*8a978a17SVictor Perevertkin --*/
24*8a978a17SVictor Perevertkin
25*8a978a17SVictor Perevertkin #ifndef _FXDEVICEUM_H_
26*8a978a17SVictor Perevertkin #define _FXDEVICEUM_H_
27*8a978a17SVictor Perevertkin
28*8a978a17SVictor Perevertkin #define WDF_PATH_SEPARATOR L"\\"
29*8a978a17SVictor Perevertkin #define WUDF_SUB_KEY L"WUDF"
30*8a978a17SVictor Perevertkin #define WUDF_ADDITIONAL_SUB_KEY L"WDF"
31*8a978a17SVictor Perevertkin
32*8a978a17SVictor Perevertkin #define FX_DIRECT_HARDWARE_ACCESS L"DirectHardwareAccess"
33*8a978a17SVictor Perevertkin #define FX_DIRECT_HARDWARE_ACCESS_DEFAULT (WdfRejectDirectHardwareAccess)
34*8a978a17SVictor Perevertkin
35*8a978a17SVictor Perevertkin #define FX_REGISTER_ACCESS_MODE L"RegisterAccessMode"
36*8a978a17SVictor Perevertkin #define FX_REGISTER_ACCESS_MODE_DEFAULT (WdfRegisterAccessUsingSystemCall)
37*8a978a17SVictor Perevertkin
38*8a978a17SVictor Perevertkin #define FX_FILE_OBJECT_POLICY L"FileObjectPolicy"
39*8a978a17SVictor Perevertkin #define FX_FILE_OBJECT_POLICY_DEFAULT (WdfRejectNullAndUnknownFileObjects)
40*8a978a17SVictor Perevertkin
41*8a978a17SVictor Perevertkin #define FX_FS_CONTEXT_USE_POLICY L"FsContextUsePolicy"
42*8a978a17SVictor Perevertkin #define FX_FS_CONTEXT_USE_POLICY_DEFAULT (WdfDefaultFsContextUsePolicy)
43*8a978a17SVictor Perevertkin
44*8a978a17SVictor Perevertkin #define FX_KERNEL_MODE_CLIENT_POLICY L"KernelModeClientPolicy"
45*8a978a17SVictor Perevertkin #define FX_METHOD_NEITHER_ACTION L"MethodNeitherAction"
46*8a978a17SVictor Perevertkin #define FX_PROCESS_SHARING_ENABLED L"HostProcessSharingEnabled"
47*8a978a17SVictor Perevertkin #define FX_DEVICE_GROUP_ID L"DeviceGroupId"
48*8a978a17SVictor Perevertkin #define FX_FILE_OBJECT_POLICY L"FileObjectPolicy"
49*8a978a17SVictor Perevertkin
50*8a978a17SVictor Perevertkin //
51*8a978a17SVictor Perevertkin // READ/WRITE_REGISTER_Xxx macros need compiler and memory barrier. Each
52*8a978a17SVictor Perevertkin // platform has a different set of compiler intrinsics to support that.
53*8a978a17SVictor Perevertkin // In kernel, x86 READ/WRITE macros are implemented in assembly and use
54*8a978a17SVictor Perevertkin // lock prefix to force real access. For amd64, _ReadWriteBarrier
55*8a978a17SVictor Perevertkin // (compiler barrier) is used for reads and __faststorefence (CPU barrier) for
56*8a978a17SVictor Perevertkin // writes. For ARM, _ReadWriteBarrier (compiler barrier) is used for reads and
57*8a978a17SVictor Perevertkin // both _ReadWriteBarrier and __emit(Value) for writes.
58*8a978a17SVictor Perevertkin //
59*8a978a17SVictor Perevertkin // Because of this variation, UMDF will use the macros directly from wdm.h
60*8a978a17SVictor Perevertkin // by autogenerating those macros from wdm.h into a private UMDF header.
61*8a978a17SVictor Perevertkin // For x86, there are no macros so either UMDF could directly link to the
62*8a978a17SVictor Perevertkin // ntosrtl.lib (that has these macros implemented in assembly), or implement
63*8a978a17SVictor Perevertkin // its own macros that use MemoryBarrier() macro from winnt.h.
64*8a978a17SVictor Perevertkin //
65*8a978a17SVictor Perevertkin // Below is UMDF's implementation for x86. The macros for other platforms are
66*8a978a17SVictor Perevertkin // in WudfWdm_private.h.
67*8a978a17SVictor Perevertkin //
68*8a978a17SVictor Perevertkin #if defined(_X86_)
69*8a978a17SVictor Perevertkin
70*8a978a17SVictor Perevertkin #define READ_REGISTER_UCHAR(x) \
71*8a978a17SVictor Perevertkin (MemoryBarrier(), *(volatile UCHAR * const)(x))
72*8a978a17SVictor Perevertkin
73*8a978a17SVictor Perevertkin #define READ_REGISTER_USHORT(x) \
74*8a978a17SVictor Perevertkin (MemoryBarrier(), *(volatile USHORT * const)(x))
75*8a978a17SVictor Perevertkin
76*8a978a17SVictor Perevertkin #define READ_REGISTER_ULONG(x) \
77*8a978a17SVictor Perevertkin (MemoryBarrier(), *(volatile ULONG * const)(x))
78*8a978a17SVictor Perevertkin
79*8a978a17SVictor Perevertkin #define READ_REGISTER_ULONG64(x) \
80*8a978a17SVictor Perevertkin (MemoryBarrier(), *(volatile ULONG64 * const)(x))
81*8a978a17SVictor Perevertkin
82*8a978a17SVictor Perevertkin #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
83*8a978a17SVictor Perevertkin PUCHAR registerBuffer = x; \
84*8a978a17SVictor Perevertkin PUCHAR readBuffer = y; \
85*8a978a17SVictor Perevertkin ULONG readCount; \
86*8a978a17SVictor Perevertkin MemoryBarrier(); \
87*8a978a17SVictor Perevertkin for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
88*8a978a17SVictor Perevertkin *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
89*8a978a17SVictor Perevertkin } \
90*8a978a17SVictor Perevertkin }
91*8a978a17SVictor Perevertkin
92*8a978a17SVictor Perevertkin #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
93*8a978a17SVictor Perevertkin PUSHORT registerBuffer = x; \
94*8a978a17SVictor Perevertkin PUSHORT readBuffer = y; \
95*8a978a17SVictor Perevertkin ULONG readCount; \
96*8a978a17SVictor Perevertkin MemoryBarrier(); \
97*8a978a17SVictor Perevertkin for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
98*8a978a17SVictor Perevertkin *readBuffer = *(volatile USHORT * const)(registerBuffer); \
99*8a978a17SVictor Perevertkin } \
100*8a978a17SVictor Perevertkin }
101*8a978a17SVictor Perevertkin
102*8a978a17SVictor Perevertkin #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
103*8a978a17SVictor Perevertkin PULONG registerBuffer = x; \
104*8a978a17SVictor Perevertkin PULONG readBuffer = y; \
105*8a978a17SVictor Perevertkin ULONG readCount; \
106*8a978a17SVictor Perevertkin MemoryBarrier(); \
107*8a978a17SVictor Perevertkin for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
108*8a978a17SVictor Perevertkin *readBuffer = *(volatile ULONG * const)(registerBuffer); \
109*8a978a17SVictor Perevertkin } \
110*8a978a17SVictor Perevertkin }
111*8a978a17SVictor Perevertkin
112*8a978a17SVictor Perevertkin #define READ_REGISTER_BUFFER_ULONG64(x, y, z) { \
113*8a978a17SVictor Perevertkin PULONG64 registerBuffer = x; \
114*8a978a17SVictor Perevertkin PULONG64 readBuffer = y; \
115*8a978a17SVictor Perevertkin ULONG readCount; \
116*8a978a17SVictor Perevertkin MemoryBarrier(); \
117*8a978a17SVictor Perevertkin for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
118*8a978a17SVictor Perevertkin *readBuffer = *(volatile ULONG64 * const)(registerBuffer); \
119*8a978a17SVictor Perevertkin } \
120*8a978a17SVictor Perevertkin }
121*8a978a17SVictor Perevertkin
122*8a978a17SVictor Perevertkin #define WRITE_REGISTER_UCHAR(x, y) { \
123*8a978a17SVictor Perevertkin *(volatile UCHAR * const)(x) = y; \
124*8a978a17SVictor Perevertkin MemoryBarrier(); \
125*8a978a17SVictor Perevertkin }
126*8a978a17SVictor Perevertkin
127*8a978a17SVictor Perevertkin #define WRITE_REGISTER_USHORT(x, y) { \
128*8a978a17SVictor Perevertkin *(volatile USHORT * const)(x) = y; \
129*8a978a17SVictor Perevertkin MemoryBarrier(); \
130*8a978a17SVictor Perevertkin }
131*8a978a17SVictor Perevertkin
132*8a978a17SVictor Perevertkin #define WRITE_REGISTER_ULONG(x, y) { \
133*8a978a17SVictor Perevertkin *(volatile ULONG * const)(x) = y; \
134*8a978a17SVictor Perevertkin MemoryBarrier(); \
135*8a978a17SVictor Perevertkin }
136*8a978a17SVictor Perevertkin
137*8a978a17SVictor Perevertkin #define WRITE_REGISTER_ULONG64(x, y) { \
138*8a978a17SVictor Perevertkin *(volatile ULONG64 * const)(x) = y; \
139*8a978a17SVictor Perevertkin MemoryBarrier(); \
140*8a978a17SVictor Perevertkin }
141*8a978a17SVictor Perevertkin
142*8a978a17SVictor Perevertkin #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
143*8a978a17SVictor Perevertkin PUCHAR registerBuffer = x; \
144*8a978a17SVictor Perevertkin PUCHAR writeBuffer = y; \
145*8a978a17SVictor Perevertkin ULONG writeCount; \
146*8a978a17SVictor Perevertkin for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
147*8a978a17SVictor Perevertkin *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
148*8a978a17SVictor Perevertkin } \
149*8a978a17SVictor Perevertkin MemoryBarrier(); \
150*8a978a17SVictor Perevertkin }
151*8a978a17SVictor Perevertkin
152*8a978a17SVictor Perevertkin #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
153*8a978a17SVictor Perevertkin PUSHORT registerBuffer = x; \
154*8a978a17SVictor Perevertkin PUSHORT writeBuffer = y; \
155*8a978a17SVictor Perevertkin ULONG writeCount; \
156*8a978a17SVictor Perevertkin for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
157*8a978a17SVictor Perevertkin *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
158*8a978a17SVictor Perevertkin } \
159*8a978a17SVictor Perevertkin MemoryBarrier(); \
160*8a978a17SVictor Perevertkin }
161*8a978a17SVictor Perevertkin
162*8a978a17SVictor Perevertkin #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
163*8a978a17SVictor Perevertkin PULONG registerBuffer = x; \
164*8a978a17SVictor Perevertkin PULONG writeBuffer = y; \
165*8a978a17SVictor Perevertkin ULONG writeCount; \
166*8a978a17SVictor Perevertkin for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
167*8a978a17SVictor Perevertkin *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
168*8a978a17SVictor Perevertkin } \
169*8a978a17SVictor Perevertkin MemoryBarrier(); \
170*8a978a17SVictor Perevertkin }
171*8a978a17SVictor Perevertkin
172*8a978a17SVictor Perevertkin #define WRITE_REGISTER_BUFFER_ULONG64(x, y, z) { \
173*8a978a17SVictor Perevertkin PULONG64 registerBuffer = x; \
174*8a978a17SVictor Perevertkin PULONG64 writeBuffer = y; \
175*8a978a17SVictor Perevertkin ULONG writeCount; \
176*8a978a17SVictor Perevertkin for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
177*8a978a17SVictor Perevertkin *(volatile ULONG64 * const)(registerBuffer) = *writeBuffer; \
178*8a978a17SVictor Perevertkin } \
179*8a978a17SVictor Perevertkin MemoryBarrier(); \
180*8a978a17SVictor Perevertkin }
181*8a978a17SVictor Perevertkin
182*8a978a17SVictor Perevertkin #endif // _X86_
183*8a978a17SVictor Perevertkin
184*8a978a17SVictor Perevertkin __inline
185*8a978a17SVictor Perevertkin SIZE_T
ReadRegister(__in WDF_DEVICE_HWACCESS_TARGET_SIZE Size,__in PVOID Register)186*8a978a17SVictor Perevertkin FxDevice::ReadRegister(
187*8a978a17SVictor Perevertkin __in WDF_DEVICE_HWACCESS_TARGET_SIZE Size,
188*8a978a17SVictor Perevertkin __in PVOID Register
189*8a978a17SVictor Perevertkin )
190*8a978a17SVictor Perevertkin {
191*8a978a17SVictor Perevertkin SIZE_T value = 0;
192*8a978a17SVictor Perevertkin
193*8a978a17SVictor Perevertkin //
194*8a978a17SVictor Perevertkin // ETW start event for perf measurement
195*8a978a17SVictor Perevertkin //
196*8a978a17SVictor Perevertkin EventWriteEVENT_UMDF_FX_READ_FROM_HARDWARE_START(
197*8a978a17SVictor Perevertkin WdfDeviceHwAccessTargetTypeRegister, Size, 0);
198*8a978a17SVictor Perevertkin
199*8a978a17SVictor Perevertkin switch(Size) {
200*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUchar:
201*8a978a17SVictor Perevertkin value = READ_REGISTER_UCHAR((PUCHAR)Register);
202*8a978a17SVictor Perevertkin break;
203*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUshort:
204*8a978a17SVictor Perevertkin value = READ_REGISTER_USHORT((PUSHORT)Register);
205*8a978a17SVictor Perevertkin break;
206*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUlong:
207*8a978a17SVictor Perevertkin value = READ_REGISTER_ULONG((PULONG)Register);
208*8a978a17SVictor Perevertkin break;
209*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUlong64:
210*8a978a17SVictor Perevertkin #if defined(_WIN64)
211*8a978a17SVictor Perevertkin value = READ_REGISTER_ULONG64((PULONG64)Register);
212*8a978a17SVictor Perevertkin #else
213*8a978a17SVictor Perevertkin FX_VERIFY(DRIVER(BadArgument, TODO), CHECK("Invalid call to ULONG64 "
214*8a978a17SVictor Perevertkin "hardware access function", FALSE));
215*8a978a17SVictor Perevertkin #endif
216*8a978a17SVictor Perevertkin break;
217*8a978a17SVictor Perevertkin default:
218*8a978a17SVictor Perevertkin FX_VERIFY(INTERNAL, TRAPMSG("Unexpected"));
219*8a978a17SVictor Perevertkin break;
220*8a978a17SVictor Perevertkin }
221*8a978a17SVictor Perevertkin
222*8a978a17SVictor Perevertkin //
223*8a978a17SVictor Perevertkin // ETW end event for perf measurement
224*8a978a17SVictor Perevertkin //
225*8a978a17SVictor Perevertkin EventWriteEVENT_UMDF_FX_READ_FROM_HARDWARE_END(
226*8a978a17SVictor Perevertkin WdfDeviceHwAccessTargetTypeRegister, Size, 0);
227*8a978a17SVictor Perevertkin
228*8a978a17SVictor Perevertkin return value;
229*8a978a17SVictor Perevertkin }
230*8a978a17SVictor Perevertkin
231*8a978a17SVictor Perevertkin __inline
232*8a978a17SVictor Perevertkin VOID
ReadRegisterBuffer(__in WDF_DEVICE_HWACCESS_TARGET_SIZE Size,__in PVOID Register,__out_ecount_full (Count)PVOID Buffer,__in ULONG Count)233*8a978a17SVictor Perevertkin FxDevice::ReadRegisterBuffer(
234*8a978a17SVictor Perevertkin __in WDF_DEVICE_HWACCESS_TARGET_SIZE Size,
235*8a978a17SVictor Perevertkin __in PVOID Register,
236*8a978a17SVictor Perevertkin __out_ecount_full(Count) PVOID Buffer,
237*8a978a17SVictor Perevertkin __in ULONG Count
238*8a978a17SVictor Perevertkin )
239*8a978a17SVictor Perevertkin {
240*8a978a17SVictor Perevertkin //
241*8a978a17SVictor Perevertkin // ETW start event for perf measurement
242*8a978a17SVictor Perevertkin //
243*8a978a17SVictor Perevertkin EventWriteEVENT_UMDF_FX_READ_FROM_HARDWARE_START(
244*8a978a17SVictor Perevertkin WdfDeviceHwAccessTargetTypeRegisterBuffer, Size, Count);
245*8a978a17SVictor Perevertkin
246*8a978a17SVictor Perevertkin switch(Size) {
247*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUchar:
248*8a978a17SVictor Perevertkin READ_REGISTER_BUFFER_UCHAR(((PUCHAR)Register), (PUCHAR)Buffer, Count );
249*8a978a17SVictor Perevertkin break;
250*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUshort:
251*8a978a17SVictor Perevertkin #pragma prefast(suppress:26000, "The Size parameter dictates the buffer size")
252*8a978a17SVictor Perevertkin READ_REGISTER_BUFFER_USHORT(((PUSHORT)Register), (PUSHORT)Buffer, Count );
253*8a978a17SVictor Perevertkin break;
254*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUlong:
255*8a978a17SVictor Perevertkin READ_REGISTER_BUFFER_ULONG(((PULONG)Register), (PULONG)Buffer, Count );
256*8a978a17SVictor Perevertkin break;
257*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUlong64:
258*8a978a17SVictor Perevertkin #if defined(_WIN64)
259*8a978a17SVictor Perevertkin READ_REGISTER_BUFFER_ULONG64(((PULONG64)Register), (PULONG64)Buffer, Count );
260*8a978a17SVictor Perevertkin #else
261*8a978a17SVictor Perevertkin FX_VERIFY(DRIVER(BadArgument, TODO), CHECK("Invalid call to ULONG64 "
262*8a978a17SVictor Perevertkin "hardware access function", FALSE));
263*8a978a17SVictor Perevertkin #endif
264*8a978a17SVictor Perevertkin break;
265*8a978a17SVictor Perevertkin default:
266*8a978a17SVictor Perevertkin FX_VERIFY(INTERNAL, TRAPMSG("Unexpected"));
267*8a978a17SVictor Perevertkin break;
268*8a978a17SVictor Perevertkin }
269*8a978a17SVictor Perevertkin
270*8a978a17SVictor Perevertkin //
271*8a978a17SVictor Perevertkin // ETW start event for perf measurement
272*8a978a17SVictor Perevertkin //
273*8a978a17SVictor Perevertkin EventWriteEVENT_UMDF_FX_READ_FROM_HARDWARE_END(
274*8a978a17SVictor Perevertkin WdfDeviceHwAccessTargetTypeRegisterBuffer, Size, Count);
275*8a978a17SVictor Perevertkin }
276*8a978a17SVictor Perevertkin
277*8a978a17SVictor Perevertkin __inline
278*8a978a17SVictor Perevertkin VOID
WriteRegister(__in WDF_DEVICE_HWACCESS_TARGET_SIZE Size,__in PVOID Register,__in SIZE_T Value)279*8a978a17SVictor Perevertkin FxDevice::WriteRegister(
280*8a978a17SVictor Perevertkin __in WDF_DEVICE_HWACCESS_TARGET_SIZE Size,
281*8a978a17SVictor Perevertkin __in PVOID Register,
282*8a978a17SVictor Perevertkin __in SIZE_T Value
283*8a978a17SVictor Perevertkin )
284*8a978a17SVictor Perevertkin {
285*8a978a17SVictor Perevertkin //
286*8a978a17SVictor Perevertkin // ETW start event for perf measurement
287*8a978a17SVictor Perevertkin //
288*8a978a17SVictor Perevertkin EventWriteEVENT_UMDF_FX_WRITE_TO_HARDWARE_START(
289*8a978a17SVictor Perevertkin WdfDeviceHwAccessTargetTypeRegister, Size, 0);
290*8a978a17SVictor Perevertkin
291*8a978a17SVictor Perevertkin switch(Size) {
292*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUchar:
293*8a978a17SVictor Perevertkin WRITE_REGISTER_UCHAR((PUCHAR)Register, (UCHAR)Value);
294*8a978a17SVictor Perevertkin break;
295*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUshort:
296*8a978a17SVictor Perevertkin WRITE_REGISTER_USHORT((PUSHORT)Register, (USHORT)Value);
297*8a978a17SVictor Perevertkin break;
298*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUlong:
299*8a978a17SVictor Perevertkin WRITE_REGISTER_ULONG((PULONG)Register, (ULONG)Value);
300*8a978a17SVictor Perevertkin break;
301*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUlong64:
302*8a978a17SVictor Perevertkin #if defined(_WIN64)
303*8a978a17SVictor Perevertkin WRITE_REGISTER_ULONG64((PULONG64)Register, (ULONG64)Value);
304*8a978a17SVictor Perevertkin #else
305*8a978a17SVictor Perevertkin FX_VERIFY(DRIVER(BadArgument, TODO), CHECK("Invalid call to ULONG64 "
306*8a978a17SVictor Perevertkin "hardware access function", FALSE));
307*8a978a17SVictor Perevertkin #endif
308*8a978a17SVictor Perevertkin break;
309*8a978a17SVictor Perevertkin default:
310*8a978a17SVictor Perevertkin FX_VERIFY(INTERNAL, TRAPMSG("Unexpected"));
311*8a978a17SVictor Perevertkin break;
312*8a978a17SVictor Perevertkin }
313*8a978a17SVictor Perevertkin
314*8a978a17SVictor Perevertkin //
315*8a978a17SVictor Perevertkin // ETW start event for perf measurement
316*8a978a17SVictor Perevertkin //
317*8a978a17SVictor Perevertkin EventWriteEVENT_UMDF_FX_WRITE_TO_HARDWARE_END(
318*8a978a17SVictor Perevertkin WdfDeviceHwAccessTargetTypeRegister, Size, 0);
319*8a978a17SVictor Perevertkin }
320*8a978a17SVictor Perevertkin
321*8a978a17SVictor Perevertkin __inline
322*8a978a17SVictor Perevertkin VOID
WriteRegisterBuffer(__in WDF_DEVICE_HWACCESS_TARGET_SIZE Size,__in PVOID Register,__in_ecount (Count)PVOID Buffer,__in ULONG Count)323*8a978a17SVictor Perevertkin FxDevice::WriteRegisterBuffer(
324*8a978a17SVictor Perevertkin __in WDF_DEVICE_HWACCESS_TARGET_SIZE Size,
325*8a978a17SVictor Perevertkin __in PVOID Register,
326*8a978a17SVictor Perevertkin __in_ecount(Count) PVOID Buffer,
327*8a978a17SVictor Perevertkin __in ULONG Count
328*8a978a17SVictor Perevertkin )
329*8a978a17SVictor Perevertkin {
330*8a978a17SVictor Perevertkin //
331*8a978a17SVictor Perevertkin // ETW start event for perf measurement
332*8a978a17SVictor Perevertkin //
333*8a978a17SVictor Perevertkin EventWriteEVENT_UMDF_FX_WRITE_TO_HARDWARE_START(
334*8a978a17SVictor Perevertkin WdfDeviceHwAccessTargetTypeRegisterBuffer, Size, Count);
335*8a978a17SVictor Perevertkin
336*8a978a17SVictor Perevertkin switch(Size) {
337*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUchar:
338*8a978a17SVictor Perevertkin WRITE_REGISTER_BUFFER_UCHAR(((PUCHAR)Register), (PUCHAR)Buffer, Count);
339*8a978a17SVictor Perevertkin break;
340*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUshort:
341*8a978a17SVictor Perevertkin #pragma prefast(suppress:26000, "The Size parameter dictates the buffer size")
342*8a978a17SVictor Perevertkin WRITE_REGISTER_BUFFER_USHORT(((PUSHORT)Register), (PUSHORT)Buffer, Count);
343*8a978a17SVictor Perevertkin break;
344*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUlong:
345*8a978a17SVictor Perevertkin WRITE_REGISTER_BUFFER_ULONG(((PULONG)Register), (PULONG)Buffer, Count);
346*8a978a17SVictor Perevertkin break;
347*8a978a17SVictor Perevertkin case WdfDeviceHwAccessTargetSizeUlong64:
348*8a978a17SVictor Perevertkin #if defined(_WIN64)
349*8a978a17SVictor Perevertkin WRITE_REGISTER_BUFFER_ULONG64(((PULONG64)Register), (PULONG64)Buffer, Count);
350*8a978a17SVictor Perevertkin #else
351*8a978a17SVictor Perevertkin FX_VERIFY(DRIVER(BadArgument, TODO), CHECK("Invalid call to ULONG64 "
352*8a978a17SVictor Perevertkin "hardware access function", FALSE));
353*8a978a17SVictor Perevertkin #endif
354*8a978a17SVictor Perevertkin break;
355*8a978a17SVictor Perevertkin default:
356*8a978a17SVictor Perevertkin FX_VERIFY(INTERNAL, TRAPMSG("Unexpected"));
357*8a978a17SVictor Perevertkin break;
358*8a978a17SVictor Perevertkin }
359*8a978a17SVictor Perevertkin
360*8a978a17SVictor Perevertkin //
361*8a978a17SVictor Perevertkin // ETW start event for perf measurement
362*8a978a17SVictor Perevertkin //
363*8a978a17SVictor Perevertkin EventWriteEVENT_UMDF_FX_WRITE_TO_HARDWARE_END(
364*8a978a17SVictor Perevertkin WdfDeviceHwAccessTargetTypeRegisterBuffer, Size, Count);
365*8a978a17SVictor Perevertkin }
366*8a978a17SVictor Perevertkin
367*8a978a17SVictor Perevertkin __inline
368*8a978a17SVictor Perevertkin FxWdmDeviceExtension*
_GetFxWdmExtension(__in MdDeviceObject DeviceObject)369*8a978a17SVictor Perevertkin FxDevice::_GetFxWdmExtension(
370*8a978a17SVictor Perevertkin __in MdDeviceObject DeviceObject
371*8a978a17SVictor Perevertkin )
372*8a978a17SVictor Perevertkin {
373*8a978a17SVictor Perevertkin return (FxWdmDeviceExtension*)
374*8a978a17SVictor Perevertkin ((static_cast<IWudfDevice2*> (DeviceObject))->GetDeviceExtension());
375*8a978a17SVictor Perevertkin }
376*8a978a17SVictor Perevertkin
377*8a978a17SVictor Perevertkin __inline
378*8a978a17SVictor Perevertkin BOOLEAN
IsRemoveLockEnabledForIo(VOID)379*8a978a17SVictor Perevertkin FxDevice::IsRemoveLockEnabledForIo(
380*8a978a17SVictor Perevertkin VOID
381*8a978a17SVictor Perevertkin )
382*8a978a17SVictor Perevertkin {
383*8a978a17SVictor Perevertkin return FALSE;
384*8a978a17SVictor Perevertkin }
385*8a978a17SVictor Perevertkin
386*8a978a17SVictor Perevertkin __inline
387*8a978a17SVictor Perevertkin MdRemoveLock
GetRemoveLock(VOID)388*8a978a17SVictor Perevertkin FxDevice::GetRemoveLock(
389*8a978a17SVictor Perevertkin VOID
390*8a978a17SVictor Perevertkin )
391*8a978a17SVictor Perevertkin {
392*8a978a17SVictor Perevertkin return &FxDevice::_GetFxWdmExtension(
393*8a978a17SVictor Perevertkin GetDeviceObject())->IoRemoveLock;
394*8a978a17SVictor Perevertkin }
395*8a978a17SVictor Perevertkin
396*8a978a17SVictor Perevertkin __inline
397*8a978a17SVictor Perevertkin NTSTATUS
WmiPkgRegister(VOID)398*8a978a17SVictor Perevertkin FxDevice::WmiPkgRegister(
399*8a978a17SVictor Perevertkin VOID
400*8a978a17SVictor Perevertkin )
401*8a978a17SVictor Perevertkin {
402*8a978a17SVictor Perevertkin //
403*8a978a17SVictor Perevertkin // WMI doesn't apply for UMDF
404*8a978a17SVictor Perevertkin //
405*8a978a17SVictor Perevertkin DO_NOTHING();
406*8a978a17SVictor Perevertkin return STATUS_SUCCESS;
407*8a978a17SVictor Perevertkin }
408*8a978a17SVictor Perevertkin
409*8a978a17SVictor Perevertkin __inline
410*8a978a17SVictor Perevertkin VOID
WmiPkgDeregister(VOID)411*8a978a17SVictor Perevertkin FxDevice::WmiPkgDeregister(
412*8a978a17SVictor Perevertkin VOID
413*8a978a17SVictor Perevertkin )
414*8a978a17SVictor Perevertkin {
415*8a978a17SVictor Perevertkin //
416*8a978a17SVictor Perevertkin // WMI doesn't apply for UMDF
417*8a978a17SVictor Perevertkin //
418*8a978a17SVictor Perevertkin DO_NOTHING();
419*8a978a17SVictor Perevertkin }
420*8a978a17SVictor Perevertkin
421*8a978a17SVictor Perevertkin __inline
422*8a978a17SVictor Perevertkin VOID
WmiPkgCleanup(VOID)423*8a978a17SVictor Perevertkin FxDevice::WmiPkgCleanup(
424*8a978a17SVictor Perevertkin VOID
425*8a978a17SVictor Perevertkin )
426*8a978a17SVictor Perevertkin {
427*8a978a17SVictor Perevertkin //
428*8a978a17SVictor Perevertkin // WMI doesn't apply for UMDF
429*8a978a17SVictor Perevertkin //
430*8a978a17SVictor Perevertkin DO_NOTHING();
431*8a978a17SVictor Perevertkin }
432*8a978a17SVictor Perevertkin
433*8a978a17SVictor Perevertkin __inline
434*8a978a17SVictor Perevertkin IWudfDeviceStack*
GetDeviceStack(VOID)435*8a978a17SVictor Perevertkin FxDevice::GetDeviceStack(
436*8a978a17SVictor Perevertkin VOID
437*8a978a17SVictor Perevertkin )
438*8a978a17SVictor Perevertkin {
439*8a978a17SVictor Perevertkin return m_DevStack;
440*8a978a17SVictor Perevertkin }
441*8a978a17SVictor Perevertkin
442*8a978a17SVictor Perevertkin __inline
443*8a978a17SVictor Perevertkin IWudfDeviceStack2 *
GetDeviceStack2()444*8a978a17SVictor Perevertkin FxDevice::GetDeviceStack2(
445*8a978a17SVictor Perevertkin )
446*8a978a17SVictor Perevertkin {
447*8a978a17SVictor Perevertkin IWudfDeviceStack2 *pDeviceStack2;
448*8a978a17SVictor Perevertkin HRESULT hrQI;
449*8a978a17SVictor Perevertkin
450*8a978a17SVictor Perevertkin hrQI = m_DevStack->QueryInterface(IID_IWudfDeviceStack2,
451*8a978a17SVictor Perevertkin (PVOID*)&pDeviceStack2);
452*8a978a17SVictor Perevertkin FX_VERIFY(INTERNAL, CHECK_QI(hrQI, pDeviceStack2));
453*8a978a17SVictor Perevertkin
454*8a978a17SVictor Perevertkin m_DevStack->Release();
455*8a978a17SVictor Perevertkin
456*8a978a17SVictor Perevertkin return pDeviceStack2;
457*8a978a17SVictor Perevertkin }
458*8a978a17SVictor Perevertkin
459*8a978a17SVictor Perevertkin #endif //_FXDEVICEUM_H_
460*8a978a17SVictor Perevertkin
461