ReactOS 0.4.16-dev-306-g647d351
fxdevicebase.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxDeviceBase.cpp
8
9Abstract:
10
11 This is the class implementation for the base device class.
12
13Author:
14
15
16
17Environment:
18
19 Both kernel and user mode
20
21Revision History:
22
23--*/
24
25#include "coreprivshared.hpp"
26
27extern "C" {
28// #include "FxDeviceBase.tmh"
29}
30
32 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
36 ) :
37 FxNonPagedObject(Type, Size, FxDriverGlobals)
38{
40
43
45
47
50
52 SetDeviceBase(this);
53}
54
56 VOID
57 )
58{
59 if (m_DisposeList != NULL) {
62 }
63
64 if (m_CallbackLockPtr != NULL) {
65 delete m_CallbackLockPtr;
67 }
68}
69
74 )
75{
76 switch (Params->Type) {
78 *Params->Object = this;
79 break;
80
82 *Params->Object = (IFxHasCallbacks*) this;
83 break;
84
85 default:
86 return FxNonPagedObject::QueryInterface(Params); // __super call
87 }
88
89 return STATUS_SUCCESS;
90}
91
95 )
96{
98 WDF_EXECUTION_LEVEL driverLevel;
99 WDF_SYNCHRONIZATION_SCOPE driverScope;
100
101 ASSERT(m_Driver != NULL);
102
103 //
104 // If WDF_OBJECT_ATTRIBUTES is specified, these override any
105 // default settings.
106 //
107 if (ObjectAttributes != NULL) {
108 m_ExecutionLevel = ObjectAttributes->ExecutionLevel;
109 m_SynchronizationScope = ObjectAttributes->SynchronizationScope;
110 }
111
112 //
113 // If no WDFDEVICE specific attributes are specified, we
114 // get them from WDFDRIVER, which allows WDFDRIVER to
115 // provide a default for all WDFDEVICE's created.
116 //
117 m_Driver->GetConstraints(&driverLevel, &driverScope);
118
120 m_ExecutionLevel = driverLevel;
121 }
122
124 m_SynchronizationScope = driverScope;
125 }
126
127 //
128 // Configure The Execution Level Constraint
129 //
133 //
134 // Currently, all event callbacks from FxDevice into the driver
135 // are from PASSIVE_LEVEL threads, and there is no need to defer
136 // to a system workitem like IoQueue. So we don't allocate and
137 // setup an FxSystemWorkItem here.
138 //
139 // If the FxDevice starts raising events to the device driver
140 // whose thread starts out above PASSIVE_LEVEL, then an FxSystemWorkItem
141 // would need to be allocated when WdfExecutionLevelPassive is specified.
142 //
143 // (FDO and PDO variants of FxDevice may own their own event dispatch
144 // and deferral logic separate from FxDevice.)
145 //
146 }
147 else {
150 }
151
152 //
153 // Finish initializing the spin/mutex lock.
154 //
155 if (NULL == m_CallbackLockPtr) {
159 "WDFDEVICE %p, could not allocate callback lock, %!STATUS!",
160 GetHandle(), status);
161 goto Done;
162 }
163
166
168
169Done:
170 return status;
171}
172
173VOID
175 __out_opt WDF_EXECUTION_LEVEL* ExecutionLevel,
176 __out_opt WDF_SYNCHRONIZATION_SCOPE* SynchronizationScope
177 )
178{
179 if (ExecutionLevel != NULL) {
180 *ExecutionLevel = m_ExecutionLevel;
181 }
182
183 if (SynchronizationScope != NULL) {
184 *SynchronizationScope = m_SynchronizationScope;
185 }
186}
187
191 )
192{
193 if (LockObject != NULL) {
195 }
196
197 return m_CallbackLockPtr;
198}
199
200
201VOID
204 __in MdDeviceObject AttachedDevice,
206 )
207{
209 m_AttachedDevice.SetObject(AttachedDevice);
211}
212
217 )
218{
219 FxObject* pParent, *pOrigParent;
222 PVOID pTag;
223
225 if (pDeviceBase == NULL) {
227 Object->GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGOBJECT,
228 "WDFHANDLE %p does not have a WDFDEVICE as an ancestor",
229 Object->GetObjectHandle());
230 return NULL;
231 }
232
233 if (Callbacks == NULL) {
234 //
235 // Caller is not interested in the callbacks interface, just return
236 // now without searching for it.
237 //
238 return pDeviceBase;
239 }
240
241 //
242 // Init out parameter.
243 //
244 *Callbacks = NULL;
245
246 pOrigParent = Object;
247 pTag = pOrigParent;
248
249 //
250 // By adding a reference now, we simulate what GetParentObjectReferenced
251 // does later, thus allowing simple logic on when/how to release the
252 // reference on exit.
253 //
254 Object->ADDREF(pTag);
255
256 do {
257 //
258 // If successful, Callbacks will be != NULL
259 //
260 if (NT_SUCCESS(Object->QueryInterface(&cbParams))) {
261 ASSERT(*Callbacks != NULL);
262 //
263 // Release the reference previously taken by the top of the function
264 // or GetParentObjectReferenced in a previous pass in the loop.
265 //
266 Object->RELEASE(pTag);
267 return pDeviceBase;
268 }
269
271
272 //
273 // Release the reference previously taken by the top of the function
274 // or GetParentObjectReferenced in a previous pass in the loop.
275 //
276 Object->RELEASE(pTag);
277
278 Object = pParent;
279 } while (Object != NULL);
280
281 ASSERT(Object == NULL);
282
283 //
284 // Queue presented requests do not have parents (to increase performance).
285 // Try to find the callback interface on this object's device base.
286 //
287 if (NT_SUCCESS(pDeviceBase->QueryInterface(&cbParams))) {
288 ASSERT(*Callbacks != NULL);
289 //
290 // Success, we got a callback interface.
291 //
292 return pDeviceBase;
293 }
294
297 "WDFHANDLE %p does not have a callbacks interface in its object tree"
298 "(WDFDEVICE %p)", pOrigParent->GetObjectHandle(),
300
301 return pDeviceBase;
302}
303
306 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
308 )
309{
310 FxObject* pParentObject;
312
313 if (Attributes == NULL || Attributes->ParentObject == NULL) {
314 return NULL;
315 }
316
317 FxObjectHandleGetPtr(FxDriverGlobals,
318 Attributes->ParentObject,
320 (PVOID*) &pParentObject);
321
322 pDeviceBase = _SearchForDevice(pParentObject, NULL);
323
324 return pDeviceBase;
325}
326
331 _In_ BOOLEAN SelfTarget
332 )
333/*++
334
335Routine Description:
336
337 Allocates an IO Target or an Self IO target for the FxDevice.
338
339Arguments:
340
341 Target - Out - returns the pointer to the allocated IO target.
342
343 SelfTarget - If TRUE allocates an Self IO Target, if FALSE allocates
344 a regular IO target.
345
346Returns:
347
348 NTSTATUS
349
350--*/
351{
354
355 if (SelfTarget) {
358 } else {
361 }
362
363 if (pTarget == NULL) {
365
368 "WDFDEVICE %p could not allocate a WDFIOTARGET, %!STATUS!",
369 GetHandle(), status);
370
371 goto Done;
372 }
373
375 if (!NT_SUCCESS(status)) {
378 "WDFDEVICE %p failed to initialize (add) a WDFIOTARGET, %!STATUS!",
379 GetHandle(), status);
380
381 goto Done;
382 }
383
384 status = pTarget->Init(this);
385 if (!NT_SUCCESS(status)) {
388 "WDFDEVICE %p failed to initialize a WDFIOTARGET, %!STATUS!",
389 GetHandle(), status);
390
391 goto Done;
392 }
393
395 if (!NT_SUCCESS(status)) {
398 "WDFDEVICE %p failed to initialize (commit) a WDFIOTARGET, %!STATUS!",
399 GetHandle(), status);
400
401 goto Done;
402 }
403
405
406Done:
407 if (!NT_SUCCESS(status)) {
408 if (pTarget != NULL) {
410 pTarget = NULL;
411 }
412 }
413
414 *Target = pTarget;
415
416 return status;
417}
unsigned char BOOLEAN
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
const struct winhelp_callbacks Callbacks
Definition: callback.c:161
virtual void Initialize(FxObject *ParentObject)=0
MxDeviceObject m_AttachedDevice
Definition: fxdevice.hpp:472
static FxDeviceBase * _SearchForDevice(__in FxObject *Object, __out_opt IFxHasCallbacks **Callbacks)
FxObject * m_CallbackLockObjectPtr
Definition: fxdevice.hpp:476
WDF_SYNCHRONIZATION_SCOPE m_SynchronizationScope
Definition: fxdevice.hpp:479
WDF_EXECUTION_LEVEL m_ExecutionLevel
Definition: fxdevice.hpp:478
NTSTATUS ConfigureConstraints(__in_opt PWDF_OBJECT_ATTRIBUTES ObjectAttributes)
~FxDeviceBase(VOID)
_Must_inspect_result_ NTSTATUS AllocateTarget(_Out_ FxIoTarget **Target, _In_ BOOLEAN SelfTarget)
FxDeviceBase(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxDriver *Driver, __in WDFTYPE Type, __in USHORT Size)
MxDeviceObject m_DeviceObject
Definition: fxdevice.hpp:471
_Must_inspect_result_ NTSTATUS QueryInterface(__inout FxQueryInterfaceParams *Params)
virtual _Must_inspect_result_ NTSTATUS AddIoTarget(__inout FxIoTarget *IoTarget)
Definition: fxdevice.hpp:247
FxDriver * m_Driver
Definition: fxdevice.hpp:469
LONG m_DmaPacketTransactionStatus
Definition: fxdevice.hpp:484
MxDeviceObject m_PhysicalDevice
Definition: fxdevice.hpp:473
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
FxCallbackLock * GetCallbackLockPtr(__out_opt FxObject **LockObject)
VOID GetConstraints(__out_opt WDF_EXECUTION_LEVEL *ExecutionLevel, __out_opt WDF_SYNCHRONIZATION_SCOPE *SynchronizationScope)
VOID Init(__in MdDeviceObject DeviceObject, __in MdDeviceObject AttachedDevice, __in MdDeviceObject PhysicalDevice)
FxCallbackLock * m_CallbackLockPtr
Definition: fxdevice.hpp:475
FxDisposeList * m_DisposeList
Definition: fxdevice.hpp:466
virtual VOID GetConstraints(__out WDF_EXECUTION_LEVEL *ExecutionLevel, __out WDF_SYNCHRONIZATION_SCOPE *SynchronizationScope)
Definition: fxdriver.hpp:282
_Must_inspect_result_ NTSTATUS Init(__in CfxDeviceBase *Device)
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
VOID MarkPassiveDispose(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:944
VOID SetDeviceBase(__in CfxDeviceBase *DeviceBase)
Definition: fxobject.hpp:797
virtual VOID DeleteObject(VOID)
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
CfxDeviceBase * GetDeviceBase(VOID)
Definition: fxobject.hpp:789
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
_Must_inspect_result_ FxObject * GetParentObjectReferenced(__in PVOID Tag)
Definition: fxobject.cpp:856
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__in FxQueryInterfaceParams *Params)
Definition: fxobject.cpp:255
_Must_inspect_result_ NTSTATUS Commit(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
Definition: fxobject.cpp:904
__inline VOID SetObject(__in_opt MdDeviceObject DeviceObject)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define __out_opt
Definition: dbghelp.h:65
#define __in
Definition: dbghelp.h:35
#define __inout
Definition: dbghelp.h:50
#define __in_opt
Definition: dbghelp.h:38
#define TRACINGOBJECT
Definition: dbgtrace.h:59
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
@ FxDmaPacketTransactionCompleted
Definition: fxdevice.hpp:68
FxIoTarget * pTarget
Definition: fxdeviceapi.cpp:97
FxDeviceBase * pDeviceBase
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Fdo, FX_TYPE_DEVICE,(PVOID *)&pFdo)
FxObject * pParent
Definition: fxdpcapi.cpp:86
@ ObjectDoNotLock
Definition: fxobject.hpp:128
USHORT WDFTYPE
Definition: fxtypes.h:29
@ FX_TYPE_OBJECT
Definition: fxtypes.h:45
@ FX_TYPE_IHASCALLBACKS
Definition: fxtypes.h:114
@ FX_TYPE_DEVICE_BASE
Definition: fxtypes.h:83
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ps.c:97
#define LockObject(Object)
Definition: titypes.h:34
#define GetHandle(h)
Definition: treelist.c:116
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDRIVER Driver
Definition: wdfcontrol.h:83
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PDEVICE_OBJECT PhysicalDevice
Definition: wdfdevice.h:2323
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
@ WdfSynchronizationScopeInheritFromParent
Definition: wdfobject.h:63
@ WdfExecutionLevelPassive
Definition: wdfobject.h:54
@ WdfExecutionLevelInheritFromParent
Definition: wdfobject.h:53
WDF_EXTERN_C_START enum _WDF_EXECUTION_LEVEL WDF_EXECUTION_LEVEL
enum _WDF_SYNCHRONIZATION_SCOPE WDF_SYNCHRONIZATION_SCOPE
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105