ReactOS 0.4.16-dev-1946-g52006dd
fxdmaenablerapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxDmaEnablerAPI.cpp
8
9Abstract:
10
11 Base for WDF DMA Enabler object APIs
12
13Environment:
14
15 Kernel mode only.
16
17Notes:
18
19
20Revision History:
21
22--*/
23
24#include "fxdmapch.hpp"
25
26extern "C" {
27// #include "FxDmaEnablerAPI.tmh"
28}
29
30//
31// Extern "C" the entire file
32//
33extern "C" {
34
40WDFEXPORT(WdfDmaEnablerCreate)(
41 __in
42 PWDF_DRIVER_GLOBALS DriverGlobals,
43 __in
44 WDFDEVICE Device,
45 __in
49 __out
50 WDFDMAENABLER * DmaEnablerHandle
51 )
52{
56 WDFDMAENABLER handle;
60
61 //
62 // Validate the Device handle
63 //
65 Device,
67 (PVOID *) &pDevice,
69
72 return status;
73 }
74
77
79
81
82 if (!NT_SUCCESS(status)) {
83 return status;
84 }
85
86 if (Attributes != NULL && Attributes->ParentObject != NULL) {
88 Attributes->ParentObject,
90 (PVOID*)&pParent);
91
93 FxDeviceBase * pSearchDevice;
94
95 //
96 // If a parent object is passed-in it must be descendent of device.
97 // DmaEnabler stores device and uses it during dispose
98 // (to remove it from dmaenabler list maintained at device level),
99 // so DmaEnabler cannot outlive device.
100 //
101
103
104 if (pSearchDevice == NULL) {
106
109 "Attributes->ParentObject 0x%p must have WDFDEVICE as an "
110 "eventual ancestor, %!STATUS!",
111 Attributes->ParentObject, status);
112
113 return status;
114 }
115 else if (pSearchDevice != pDevice) {
117
120 "Attributes->ParentObject 0x%p ancestor is WDFDEVICE %p, but "
121 "not the same WDFDEVICE 0x%p passed to WdfDmaEnablerCreate, "
122 "%!STATUS!",
123 Attributes->ParentObject, pSearchDevice->GetHandle(),
124 Device, status);
125
126 return status;
127 }
128 }
129 else {
130 //
131 // For < 1.11 drivers we only allow pDevice to be the parent
132 // since that is what we were blindly setting the parent to.
133 //
134 // Using the passed-in parent for such drivers could cause
135 // side-effects such as earlier deletion of DmaEnabler object. So
136 // we don't do that.
137 //
138 // We cause this verifier breakpoint to warn downlevel drivers
139 // that the parent they passed in gets ignored.
140 //
141 if (pParent != pDevice) {
144 "For drivers bound to version <= 1.9 "
145 "WdfDmaEnablerCreate uses WDFDEVICE as the "
146 "parent object for the dma enabler object. "
147 "Attributes->ParentObject 0x%p, which is different from "
148 "WDFDEVICE 0x%p, gets ignored. Please note that DmaEnabler "
149 "would be disposed only when device is disposed.",
150 Attributes->ParentObject, Device);
151
154 }
155 }
156
158 }
159 }
160 else {
162 }
163
164 {
166 sizeof(WDF_DMA_ENABLER_CONFIG) :
168
169 if (Config->Size != expectedSize) {
171
174 "WDF_DMA_ENABLER_CONFIG Size 0x%x, expected 0x%x, %!STATUS!",
175 Config->Size, expectedSize, status);
176
177 return status;
178 }
179
180
181 //
182 // Normalize DMA config structure if necessary.
183 //
184 if (Config->Size < sizeof(WDF_DMA_ENABLER_CONFIG)) {
185 //
186 // Init new fields to default values.
187 //
190 Config->MaximumLength);
191 //
192 // Copy over existing fields and readjust the struct size.
193 //
195 dmaConfig.Size = sizeof(dmaConfig);
196
197 //
198 // Use new config structure from now on.
199 //
200 Config = &dmaConfig;
201 }
202 }
203
204 switch (Config->Profile) {
213 break;
214 default:
218 "DMA Profile value %d is unknown, %!STATUS!",
219 Config->Profile, status);
220 return status;
221 }
222
223 if (Config->MaximumLength == 0) {
225
228 "Config MaximumLength of zero is invalid, %!STATUS!",
229 status);
230
231 return status;
232 }
233
234 //
235 // Ok: create a new DmaEnabler
236 //
239
242
244 "Could not allocate memory for a WDFDMAENABLER, "
245 "%!STATUS!", status);
246
247 return status;
248 }
249
250 //
251 // Assign this FxDmaEnabler to its parent FxDevice object.
252 //
254
256 //
257 // Ok: start this DmaEnabler.
258 //
259 status = pDmaEnabler->Initialize( Config, pDevice );
260 }
261
262 if (NT_SUCCESS(status)) {
263 //
264 // Only return a valid handle on success.
265 //
267 }
268 else {
269 pDmaEnabler->DeleteFromFailedCreate();
270 }
271
272 return status;
273}
274
276WDFAPI
277size_t
278NTAPI
279WDFEXPORT(WdfDmaEnablerGetMaximumLength)(
280 __in
281 PWDF_DRIVER_GLOBALS DriverGlobals,
282 __in
283 WDFDMAENABLER DmaEnabler
284 )
285{
287
291 (PVOID *) &pDmaEnabler);
292
293 return pDmaEnabler->GetMaximumLength();
294}
295
297WDFAPI
298size_t
299NTAPI
300WDFEXPORT(WdfDmaEnablerGetMaximumScatterGatherElements)(
301 __in
302 PWDF_DRIVER_GLOBALS DriverGlobals,
303 __in
304 WDFDMAENABLER DmaEnabler
305 )
306{
308
312 (PVOID *) &pDmaEnabler);
313
314 return pDmaEnabler->GetMaxSGElements();
315}
316
317
319WDFAPI
320VOID
321NTAPI
322WDFEXPORT(WdfDmaEnablerSetMaximumScatterGatherElements)(
323 __in
324 PWDF_DRIVER_GLOBALS DriverGlobals,
325 __in
326 WDFDMAENABLER DmaEnabler,
327 __in
328 __drv_when(MaximumElements == 0, __drv_reportError(MaximumElements cannot be zero))
329 size_t MaximumElements
330 )
331{
335
339 (PVOID *) &pDmaEnabler,
341
343 if (!NT_SUCCESS(status)) {
344 return;
345 }
346
347 if (MaximumElements == 0) {
350 "Cannot set MaximumElements of zero on WDFDMAENABLER %p",
351 DmaEnabler);
352 return;
353 }
354
355 pDmaEnabler->SetMaxSGElements(MaximumElements);
356}
357
359WDFAPI
360size_t
361NTAPI
362WDFEXPORT(WdfDmaEnablerGetFragmentLength)(
363 __in
364 PWDF_DRIVER_GLOBALS DriverGlobals,
365 __in
366 WDFDMAENABLER DmaEnabler,
367 __in
369 )
370{
372 size_t length;
374
378 (PVOID *) &pDmaEnabler,
380
381 switch (DmaDirection) {
382
384 length = pDmaEnabler->GetReadDmaDescription()->MaximumFragmentLength;
385 break;
386
388 length = pDmaEnabler->GetWriteDmaDescription()->MaximumFragmentLength;
389 break;
390
391 default:
392 length = 0;
394 "Invalid value for Dma direction %d, %p",
397 break;
398 }
399
400 return length;
401}
402
404WDFAPI
406NTAPI
407WDFEXPORT(WdfDmaEnablerWdmGetDmaAdapter)(
408 __in
409 PWDF_DRIVER_GLOBALS DriverGlobals,
410 __in
411 WDFDMAENABLER DmaEnabler,
412 __in
414 )
415{
419
423 (PVOID *) &pDmaEnabler,
425
426 switch (DmaDirection) {
427
429 adapter = pDmaEnabler->GetReadDmaDescription()->AdapterObject;
430 break;
431
433 adapter = pDmaEnabler->GetWriteDmaDescription()->AdapterObject;
434 break;
435
436 default:
437 adapter = NULL;
439 "Invalid value for Dma direction %d, %p",
442 break;
443 }
444
445 return adapter;
446}
447
450WDFAPI
452NTAPI
453WDFEXPORT(WdfDmaEnablerConfigureSystemProfile)(
454 __in
455 PWDF_DRIVER_GLOBALS DriverGlobals,
456 __in
457 WDFDMAENABLER DmaEnabler,
458 __in
460 __in
462 )
463{
466
468
472 (PVOID *) &pDmaEnabler,
474
475 //
476 // Verify the DMA config
477 //
478
480 {
483 "ProfileConfig must be non-null, %!STATUS!",
484 status);
486 return status;
487 }
488
490 {
492
494 "WDF_DMA_SYSTEM_PROFILE_CONFIG Size 0x%x, expected 0x%x, %!STATUS!",
496
498
499 return status;
500 }
501
502 if (ProfileConfig->DmaDescriptor == NULL)
503 {
505
507 "ProfileConfig (%p) may not have NULL DmaDescriptor, %!STATUS!",
509
511
512 return status;
513 }
514
520 "ConfigDirection 0x%x is an invalid value, %!STATUS!",
522 return status;
523 }
524
525 status = pDmaEnabler->ConfigureSystemAdapter(ProfileConfig,
527 return status;
528}
529
530} // extern "C"
LONG NTSTATUS
Definition: precomp.h:26
static FxDeviceBase * _SearchForDevice(__in FxObject *Object, __out_opt IFxHasCallbacks **Callbacks)
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define TRACINGDMA
Definition: dbgtrace.h:71
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define __drv_when(cond, annotes)
Definition: driverspecs.h:335
#define __drv_reportError(why)
Definition: driverspecs.h:320
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
FxVerifierDbgBreakPoint(pFxDriverGlobals)
size_t length
_Must_inspect_result_ __in WDFDEVICE __in WDF_DMA_ENABLER_CONFIG __in_opt WDF_OBJECT_ATTRIBUTES * Attributes
_Must_inspect_result_ __in WDFDEVICE __in WDF_DMA_ENABLER_CONFIG * Config
__in WDFDMAENABLER __in WDF_DMA_DIRECTION DmaDirection
_Must_inspect_result_ __in WDFDMAENABLER __in PWDF_DMA_SYSTEM_PROFILE_CONFIG ProfileConfig
WDFDMAENABLER handle
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE_BASE,(PVOID *) &pDevice, &pFxDriverGlobals)
FxDeviceBase * pDevice
return adapter
_Must_inspect_result_ __in WDFDEVICE __in WDF_DMA_ENABLER_CONFIG __in_opt WDF_OBJECT_ATTRIBUTES __out WDFDMAENABLER * DmaEnablerHandle
_Must_inspect_result_ __in WDFDEVICE Device
FxObject * pParent
pDmaEnabler
NTSTATUS status
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), DmaEnabler, FX_TYPE_DMA_ENABLER,(PVOID *) &pDmaEnabler)
_Must_inspect_result_ __in WDFDMAENABLER __in PWDF_DMA_SYSTEM_PROFILE_CONFIG __in WDF_DMA_DIRECTION ConfigDirection
__in WDFDMAENABLER DmaEnabler
WDF_DMA_ENABLER_CONFIG dmaConfig
PFX_DRIVER_GLOBALS pFxDriverGlobals
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
@ FX_TYPE_OBJECT
Definition: fxtypes.h:45
@ FX_TYPE_DEVICE_BASE
Definition: fxtypes.h:83
@ FX_TYPE_DMA_ENABLER
Definition: fxtypes.h:107
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define _Must_inspect_result_
Definition: no_sal2.h:62
int zero
Definition: sehframes.cpp:29
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
_Must_inspect_result_ BOOLEAN IsVersionGreaterThanOrEqualTo(__in ULONG Major, __in ULONG Minor)
Definition: globalskm.cpp:92
__inline _Must_inspect_result_ BOOLEAN IsDownlevelVerificationEnabled()
Definition: fxglobals.h:314
WDF_DMA_PROFILE Profile
Definition: ps.c:97
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:476
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDMAENABLER DmaEnabler
@ WdfDmaProfileScatterGather
Definition: wdfdmaenabler.h:55
@ WdfDmaProfilePacket
Definition: wdfdmaenabler.h:54
@ WdfDmaProfileScatterGatherDuplex
Definition: wdfdmaenabler.h:58
@ WdfDmaProfileSystem
Definition: wdfdmaenabler.h:60
@ WdfDmaProfileSystemDuplex
Definition: wdfdmaenabler.h:61
@ WdfDmaProfilePacket64
Definition: wdfdmaenabler.h:56
@ WdfDmaProfileScatterGather64Duplex
Definition: wdfdmaenabler.h:59
@ WdfDmaProfileScatterGather64
Definition: wdfdmaenabler.h:57
FORCEINLINE VOID WDF_DMA_ENABLER_CONFIG_INIT(_Out_ PWDF_DMA_ENABLER_CONFIG Config, _In_ WDF_DMA_PROFILE Profile, _In_ size_t MaximumLength)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DMA_ENABLER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDMAENABLER * DmaEnablerHandle
struct _WDF_DMA_ENABLER_CONFIG WDF_DMA_ENABLER_CONFIG
_In_ WDFDMAENABLER _In_ WDF_DMA_DIRECTION DmaDirection
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ PWDF_DMA_SYSTEM_PROFILE_CONFIG ProfileConfig
enum _WDF_DMA_DIRECTION WDF_DMA_DIRECTION
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ PWDF_DMA_SYSTEM_PROFILE_CONFIG _In_ WDF_DMA_DIRECTION ConfigDirection
@ WdfDmaDirectionReadFromDevice
Definition: wdfdmaenabler.h:65
@ WdfDmaDirectionWriteToDevice
Definition: wdfdmaenabler.h:66
#define STATUS_WDF_OBJECT_ATTRIBUTES_INVALID
Definition: wdfstatus.h:171
#define WDFAPI
Definition: wdftypes.h:53