ReactOS  0.4.15-dev-2703-g05fb0f1
fxpkgio.hpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxPkgIo.hpp
8 
9 Abstract:
10 
11  This module implements the I/O package for the driver frameworks.
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Both kernel and user mode
20 
21 Revision History:
22 
23 --*/
24 
25 #ifndef _FXPKGIO_H_
26 #define _FXPKGIO_H_
27 
28 
29 
30 
31 #include "fxpkgioshared.hpp"
33 #include "fxdevicecallbacks.hpp"
34 #include "fxcxdeviceinfo.hpp"
35 
36 //
37 // This flag is or-ed with a pointer value that is ptr aligned, only lower 2 bits are available.
38 //
39 #define FX_IN_DISPATCH_CALLBACK 0x00000001
40 
45 };
46 
47 #define IO_ITERATOR_FLUSH_TAG (PVOID) 'sulf'
48 #define IO_ITERATOR_POWER_TAG (PVOID) 'ewop'
49 
50 //
51 // This class is allocated by the driver frameworks manager
52 // PER DEVICE, and is not package global, but per device global,
53 // data.
54 //
55 // This is similar to the NT DeviceExtension.
56 //
57 class FxPkgIo : public FxPackage
58 {
59 
60 private:
61 
63 
64  //
65  // This is the list of IoQueue objects allocated by the driver
66  // and associated with this device. The IoPackage instance
67  // will release these references automatically when the device
68  // is removed.
69  //
71 
72  //
73  // This is the forwarding table
74  //
76 
77  //
78  // This is the seed value used to pass to the
79  // FxRandom for testing forward progress
80  //
82 
83  // TRUE if behave as a filter (forward default requests)
85 
87 
88  //
89  // TRUE if queues are shutting down (surprise_remove/remove in progress).
90  //
92 
93  //
94  // We'll maintain the dynamic dispatch table "per device" so that it is possible
95  // to have different callbacks for each device.
96  // Note that each device may be associted with multiple class extension in the future.
97  //
99 
100  //
101  // If !=NULL, a pre-process callback was registered
102  //
104 
105 public:
106 
107  FxPkgIo(
108  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
110  );
111 
112  ~FxPkgIo();
113 
114  //
115  // Package manager dispatch entries
116  //
118  virtual
119  NTSTATUS
120  Dispatch(
122  );
123 
124  //
125  // Returns the Top level queue for the Io based on the Irp MajorFunction
126  //
127  FxIoQueue*
130  )
131  {
133  }
134 
135  // Do not specify argument names
137  NTSTATUS,
138  VerifyDispatchContext,
140  );
141 
142  //
143  // Api's supplied by this package
144  //
146  NTSTATUS
147  __fastcall
149  __inout MdIrp Irp,
151  );
152 
154  NTSTATUS
155  __fastcall
157  __inout MdIrp Irp,
158  __in_opt FxIoInCallerContext* IoInCallerCtx,
160  );
161 
162 /*++
163 
164  Routine Description:
165 
166  Initializes the default queue, and allows the driver to
167  pass configuration information.
168 
169  The driver callbacks registered in this call are used
170  to supply the callbacks for the driver default I/O queue.
171 
172 Arguments:
173 
174  hDevice - Pointer Device Object
175 
176 Return Value:
177 
178  NTSTATUS
179 
180 --*/
182  NTSTATUS
186  );
187 
188  //
189  // Register the I/O in-caller context callback
190  //
191  __inline
192  VOID
195  )
196  {
198  }
199 
200  // Do not specify argument names
202  NTSTATUS,
203  VerifyEnqueueRequestUpdateFlags,
204  _In_ FxRequest*,
205  _Inout_ SHORT*
206  );
207 
208  // Do not specify argument names
210  VOID,
211  VerifyEnqueueRequestRestoreFlags,
212  _In_ FxRequest*,
213  _In_ SHORT
214  );
215 
216  //
217  // Enqueue a request to the I/O processing pipeline
218  // from the device driver
219  //
221  NTSTATUS
225  );
226 
227  FxDriver*
228  GetDriver(
229  VOID
230  );
231 
232  __inline
233  CfxDevice*
235  VOID
236  )
237  {
238  return m_Device;
239  }
240 
241  __inline
242  FxIoQueue*
244  VOID
245  )
246  {
247  return m_DefaultQueue;
248  }
249 
250  __inline
251  BOOLEAN
253  VOID
254  )
255  {
256  return m_Filter;
257  }
258 
259  //
260  // This is called as a result of a power management state
261  // that requests that all I/O in progress stop.
262  //
263  //
264  // FxIoStopProcessingForPowerHold:
265  // the function returns when the driver has acknowledged that it has
266  // stopped all I/O processing, but may have outstanding "in-flight" requests
267  // that have not been completed.
268  //
269  // FxIoStopProcessingForPowerPurge:
270  // the function returns when all requests have been completed and/or
271  // cancelled., and there are no more in-flight requests.
272  //
273  // Any queues not marked as PowerManaged will be left alone.
274  //
275  // This is called on a PASSIVE_LEVEL thread that can block until
276  // I/O has been stopped, or completed/cancelled.
277  //
279  NTSTATUS
282  );
283 
284  //
285  // This is called to start, or resume processing when PNP/Power
286  // resources have been supplied to the device driver.
287  //
288  // The driver is notified of resumption for any in-flight I/O.
289  //
291  NTSTATUS
293 
294  //
295  // This is called on a device which has been restarted from the removed
296  // state. It will reset purged queues so that they can accept new requests
297  // when ResumeProcessingForPower is called afterwards.
298  //
299  VOID
301  VOID
302  );
303 
304  //
305  // Called by CfxDevice when WdfDeviceSetFilter is called.
306  //
308  NTSTATUS
309  SetFilter(
311  );
312 
313  //
314  // Create an IoQueue and associate it with the FxIoPkg per device
315  // instance.
316  //
318  NTSTATUS
319  CreateQueue(
322  __in_opt FxDriver* Caller,
323  __deref_out FxIoQueue** ppQueue
324  );
325 
326  VOID
329  );
330 
332  NTSTATUS
335  __in_opt FxCxDeviceInfo* CxDeviceInfo,
338  );
339 
341  NTSTATUS
343  __inout FxIoQueue* TargetQueue,
345  );
346 
348  NTSTATUS
351  );
352 
353  __inline
354  VOID
357  )
358  {
360 
361  //
362  // If this is called, the driver called WDFREQUEST.Complete
363  // from the PreProcess callback handler.
364  //
365  // Since we have a handler, the FXREQUEST object will
366  // dereference itself upon return from this callback, which
367  // will destroy the final reference count.
368  //
369  }
370 
371  __inline
372  BOOLEAN
375  )
376  {
377  UCHAR index;
378 
379  for (index = 0; index <= IRP_MJ_MAXIMUM_FUNCTION; index++) {
380  if (m_DispatchTable[index] == Queue) {
381  return TRUE;
382  }
383  }
384  return FALSE;
385  }
386 
387  NTSTATUS
389  __in FxIoInCallerContext *InCallerContextInfo,
392  );
393 
394  __inline
397  __in_opt FxCxDeviceInfo* CxDeviceInfo
398  )
399  {
400  if (CxDeviceInfo != NULL) {
401  return &CxDeviceInfo->IoInCallerContextCallback;
402  }
403  else {
405  }
406  }
407 
408 private:
409 
410  VOID
411  AddIoQueue(
412  __inout FxIoQueue* IoQueue
413  );
414 
415  VOID
417  __inout FxIoQueue* IoQueue
418  );
419 
420  FxIoQueue*
422  __in FxIoQueueNode* QueueBookmark,
423  __in PVOID Tag
424  );
425 
426  FxIoQueue*
428  __in FxIoQueueNode* QueueBookmark,
429  __in PVOID Tag
430  );
431 
432  VOID
434  __in PSINGLE_LIST_ENTRY SListHead,
435  __inout FxIoIteratorList ListType
436  );
437 
439  NTSTATUS
442  );
443 
444 };
445 
446 #endif // _FXPKGIO_H
VOID ResetStateForRestart(VOID)
Definition: fxpkgio.cpp:1332
NTSTATUS DispathToInCallerContextCallback(__in FxIoInCallerContext *InCallerContextInfo, __in FxRequest *Request, __inout MdIrp Irp)
Definition: fxpkgio.cpp:1699
CfxDevice * m_Device
Definition: fxobject.hpp:329
_Must_inspect_result_ NTSTATUS ResumeProcessingForPower()
Definition: fxpkgio.cpp:1254
__inline BOOLEAN IsFilter(VOID)
Definition: fxpkgio.hpp:252
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_IO_QUEUE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES QueueAttributes
Definition: wdfio.h:613
_In_ UCHAR _In_ UCHAR _In_ ULONG _In_ WDFCONTEXT _Inout_ PIRP _In_ WDFCONTEXT DispatchContext
Definition: wdfdevice.h:1697
#define _Must_inspect_result_
Definition: no_sal2.h:62
ULONG m_RandomSeed
Definition: fxpkgio.hpp:81
FxIoQueue * pQueue
LIST_ENTRY m_DynamicDispatchInfoListHead
Definition: fxpkgio.hpp:98
VOID RemoveQueueReferences(__inout FxIoQueue *pQueue)
Definition: fxpkgio.cpp:1091
FxIoInCallerContext m_InCallerContextCallback
Definition: fxpkgio.hpp:103
Definition: ntbasedef.h:628
#define __fastcall
Definition: sync.c:38
#define __in_opt
Definition: dbghelp.h:38
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
FxIoQueue * GetFirstIoQueueLocked(__in FxIoQueueNode *QueueBookmark, __in PVOID Tag)
Definition: fxpkgio.cpp:1610
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
Definition: wdfdevice.h:2221
FX_DECLARE_VF_FUNCTION_P1(NTSTATUS, VerifyDispatchContext, _In_ WDFCONTEXT)
#define IRP_MJ_MAXIMUM_FUNCTION
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN m_PowerStateOn
Definition: fxpkgio.hpp:86
FxRequest * pRequest
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
FxIoQueue * m_DispatchTable[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: fxpkgio.hpp:75
PFILE_OBJECT MdFileObject
Definition: mxgeneralkm.h:32
FxIoQueue * GetNextIoQueueLocked(__in FxIoQueueNode *QueueBookmark, __in PVOID Tag)
Definition: fxpkgio.cpp:1640
_Must_inspect_result_ NTSTATUS __fastcall DispatchStep2(__inout MdIrp Irp, __in_opt FxIoInCallerContext *IoInCallerCtx, __in_opt FxIoQueue *Queue)
Definition: fxpkgio.cpp:342
EVT_WDFDEVICE_WDM_IRP_DISPATCH * PFN_WDFDEVICE_WDM_IRP_DISPATCH
Definition: wdfdevice.h:1710
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFQUEUE _In_ _Strict_type_match_ WDF_REQUEST_TYPE RequestType
Definition: wdfdevice.h:4227
BOOLEAN m_Filter
Definition: fxpkgio.hpp:84
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_Must_inspect_result_ NTSTATUS EnqueueRequest(__in CfxDevice *Device, __inout FxRequest *pRequest)
Definition: fxpkgio.cpp:607
VOID GetIoQueueListLocked(__in PSINGLE_LIST_ENTRY SListHead, __inout FxIoIteratorList ListType)
Definition: fxpkgio.cpp:1480
short SHORT
Definition: pedump.c:59
FxPkgIo(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in CfxDevice *Device)
Definition: fxpkgio.cpp:47
BOOLEAN m_QueuesAreShuttingDown
Definition: fxpkgio.hpp:91
unsigned char BOOLEAN
__inline VOID RequestCompletedCallback(__in FxRequest *Request)
Definition: fxpkgio.hpp:355
IWudfIrp * MdIrp
Definition: mxum.h:103
GLuint index
Definition: glext.h:6031
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
FxIoQueue * m_DefaultQueue
Definition: fxpkgio.hpp:62
enum _WDF_REQUEST_TYPE WDF_REQUEST_TYPE
_Must_inspect_result_ NTSTATUS SetFilter(__in BOOLEAN Value)
Definition: fxpkgio.cpp:1120
_Must_inspect_result_ _In_ WDFDEVICE _In_opt_ WDFDRIVER _In_ UCHAR _In_ PFN_WDFDEVICE_WDM_IRP_DISPATCH EvtDeviceWdmIrpDispatch
PFN_WDF_IO_IN_CALLER_CONTEXT m_Method
#define _Inout_
Definition: no_sal2.h:162
FxIoStopProcessingForPowerAction
VOID AddIoQueue(__inout FxIoQueue *IoQueue)
Definition: fxpkgio.cpp:1533
_Must_inspect_result_ NTSTATUS VerifierFreeRequestToTestForwardProgess(__in FxRequest *Request)
Definition: fxpkgio.cpp:1758
_Must_inspect_result_ NTSTATUS __fastcall DispatchStep1(__inout MdIrp Irp, __in WDFCONTEXT DispatchContext)
Definition: fxpkgio.cpp:165
unsigned char UCHAR
Definition: xmlstorage.h:181
#define index(s, c)
Definition: various.h:29
FxIoQueue * GetDispatchQueue(_In_ UCHAR MajorFunction)
Definition: fxpkgio.hpp:128
FxIoIteratorList
Definition: fxpkgio.hpp:41
#define __inout
Definition: dbghelp.h:50
Definition: typedefs.h:119
_Must_inspect_result_ NTSTATUS InitializeDefaultQueue(__in CfxDevice *Device, __inout FxIoQueue *Queue)
Definition: fxpkgio.cpp:489
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
#define _In_
Definition: no_sal2.h:158
__inline VOID SetIoInCallerContextCallback(__inout PFN_WDF_IO_IN_CALLER_CONTEXT EvtIoInCallerContext)
Definition: fxpkgio.hpp:193
_Must_inspect_result_ NTSTATUS CreateQueue(__in PWDF_IO_QUEUE_CONFIG Config, __in PWDF_OBJECT_ATTRIBUTES QueueAttributes, __in_opt FxDriver *Caller, __deref_out FxIoQueue **ppQueue)
Definition: fxpkgio.cpp:981
_Must_inspect_result_ NTSTATUS FlushAllQueuesByFileObject(__in MdFileObject FileObject)
Definition: fxpkgio.cpp:1393
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:506
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
#define NULL
Definition: types.h:112
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_IO_IN_CALLER_CONTEXT EvtIoInCallerContext
Definition: wdfdevice.h:3502
_Must_inspect_result_ NTSTATUS ConfigureForwarding(__inout FxIoQueue *TargetQueue, __in WDF_REQUEST_TYPE RequestType)
Definition: fxpkgio.cpp:910
#define __deref_out
Definition: dbghelp.h:26
unsigned int ULONG
Definition: retypes.h:1
FX_DECLARE_VF_FUNCTION_P2(NTSTATUS, VerifyEnqueueRequestUpdateFlags, _In_ FxRequest *, _Inout_ SHORT *)
virtual _Must_inspect_result_ NTSTATUS Dispatch(__inout MdIrp Irp)
Definition: fxpkgio.cpp:104
__inline FxIoQueue * GetDefaultQueue(VOID)
Definition: fxpkgio.hpp:243
LIST_ENTRY m_IoQueueListHead
Definition: fxpkgio.hpp:70
#define __in
Definition: dbghelp.h:35
VOID RemoveIoQueue(__inout FxIoQueue *IoQueue)
Definition: fxpkgio.cpp:1593
EVT_WDF_IO_IN_CALLER_CONTEXT * PFN_WDF_IO_IN_CALLER_CONTEXT
Definition: wdfdevice.h:1728
_In_ UCHAR _In_ UCHAR _In_ ULONG _In_ WDFCONTEXT DriverContext
Definition: wdfdevice.h:1697
__inline FxIoInCallerContext * GetIoInCallerContextCallback(__in_opt FxCxDeviceInfo *CxDeviceInfo)
Definition: fxpkgio.hpp:396
~FxPkgIo()
Definition: fxpkgio.cpp:80
_Must_inspect_result_ NTSTATUS StopProcessingForPower(__in FxIoStopProcessingForPowerAction Action)
Definition: fxpkgio.cpp:1143
__inline CfxDevice * GetDevice(VOID)
Definition: fxpkgio.hpp:234
__inline BOOLEAN IsTopLevelQueue(__in FxIoQueue *Queue)
Definition: fxpkgio.hpp:373
FxDriver * GetDriver(VOID)
Definition: fxpkgio.cpp:543
_Must_inspect_result_ NTSTATUS ConfigureDynamicDispatching(__in UCHAR MajorFunction, __in_opt FxCxDeviceInfo *CxDeviceInfo, __in PFN_WDFDEVICE_WDM_IRP_DISPATCH EvtDeviceWdmIrpDispatch, __in_opt WDFCONTEXT DriverContext)
Definition: fxpkgio.cpp:786