ReactOS 0.4.16-dev-122-g325d74c
fxcommonbufferapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxCommonBufferAPI.cpp
8
9Abstract:
10
11 Base for WDF CommonBuffer 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 "FxCommonBufferAPI.tmh"
28}
29
30//
31// Extern "C" the entire file
32//
33extern "C" {
34
39WDFEXPORT(WdfCommonBufferCreate)(
40 __in
42 __in
43 WDFDMAENABLER DmaEnabler,
44 __in
46 size_t Length,
49 __out
50 WDFCOMMONBUFFER * CommonBufferHandle
51 )
52{
58
59 //
60 // Get validate DmaEnabler handle
61 //
65 (PVOID *) &pDmaEnabler,
67
69
71
74 return status;
75 }
76
77 //
78 // Basic parameter validation
79 //
80 if (Length == 0) {
83 "Length is 0, %!STATUS!", status);
84 return status;
85 }
86
90 );
91 if (!NT_SUCCESS(status)) {
92 return status;
93 }
94
95 //
96 // Create a new CommonBuffer object
97 //
100
101 if (pComBuf == NULL) {
103
105 "Could not allocate memory for a WDFCOMMONBUFFER, "
106 "%!STATUS!", status);
107 return status;
108 }
109
110 //
111 // Assign this FxCommonBuffer to its parent FxDmaEnabler object.
112 //
114
116 //
117 // Ok: now allocate a CommonBuffer via this DmaEnabler
118 //
119 status = pComBuf->AllocateCommonBuffer( Length );
120 }
121
122 if (NT_SUCCESS(status)) {
123 //
124 // Only return a valid handle on success.
125 //
126 *CommonBufferHandle = (WDFCOMMONBUFFER) handle;
127 }
128 else {
129 pComBuf->DeleteFromFailedCreate();
130 }
131
132 return status;
133}
134
139WDFEXPORT(WdfCommonBufferCreateWithConfig)(
140 __in
142 __in
143 WDFDMAENABLER DmaEnabler,
144 __in
146 size_t Length,
147 __in
151 __out
152 WDFCOMMONBUFFER * CommonBufferHandle
153 )
154{
160
161 //
162 // Get validate DmaEnabler handle
163 //
167 (PVOID *) &pDmaEnabler,
169
170 //
171 // Basic parameter validation
172 //
174
175 if (Config->Size != sizeof(WDF_COMMON_BUFFER_CONFIG)) {
177
180 "WDF_COMMON_BUFFER_CONFIG Size 0x%x, expected 0x%x, %!STATUS!",
181 Config->Size, sizeof(WDF_COMMON_BUFFER_CONFIG), status);
182
183 return status;
184 }
185
187
189
191 if (!NT_SUCCESS(status)) {
192 return status;
193 }
194
195 if (Length == 0) {
198 "Length is 0, %!STATUS!", status);
199 return status;
200 }
201
205 );
206 if (!NT_SUCCESS(status)) {
207 return status;
208 }
209
212
213 if (pComBuf == NULL) {
215
217 "Could not allocate memory for a WDFCOMMONBUFFER, "
218 "%!STATUS!", status);
219 return status;
220 }
221
222 //
223 // Assign this FxCommonBuffer to its parent FxDmaEnabler object.
224 //
226
227 if (NT_SUCCESS(status)) {
228 //
229 // Set the alignment value before calling AllocateCommonBuffer.
230 //
231 pComBuf->SetAlignment(Config->AlignmentRequirement);
232 status = pComBuf->AllocateCommonBuffer( Length );
233 }
234
235 if (NT_SUCCESS(status)) {
236 //
237 // Only return a valid handle on success.
238 //
239 *CommonBufferHandle = (WDFCOMMONBUFFER) handle;
240 }
241 else {
242 pComBuf->DeleteFromFailedCreate();
243 }
244
245 return status;
246}
247
249PVOID
251WDFEXPORT(WdfCommonBufferGetAlignedVirtualAddress)(
252 __in
254 __in
255 WDFCOMMONBUFFER CommonBuffer
256 )
257{
259
263 (PVOID *) &pComBuf);
264
265 return pComBuf->GetAlignedVirtualAddress();
266}
267
271WDFEXPORT(WdfCommonBufferGetAlignedLogicalAddress)(
272 __in
274 __in
275 WDFCOMMONBUFFER CommonBuffer
276 )
277{
279
283 (PVOID *) &pComBuf);
284
285 return pComBuf->GetAlignedLogicalAddress();
286}
287
289size_t
291WDFEXPORT(WdfCommonBufferGetLength)(
292 __in
294 __in
295 WDFCOMMONBUFFER CommonBuffer
296 )
297{
299
303 (PVOID *) &pComBuf);
304
305 return pComBuf->GetLength();
306}
307
308} // extern "C"
LONG NTSTATUS
Definition: precomp.h:26
#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)
_Must_inspect_result_ __in WDFDMAENABLER __in __in_opt WDF_OBJECT_ATTRIBUTES __out WDFCOMMONBUFFER * CommonBufferHandle
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), DmaEnabler, FX_TYPE_DMA_ENABLER,(PVOID *) &pDmaEnabler, &pFxDriverGlobals)
_Must_inspect_result_ __in WDFDMAENABLER __in __in PWDF_COMMON_BUFFER_CONFIG Config
NTSTATUS status
__in WDFCOMMONBUFFER CommonBuffer
FxDmaEnabler * pDmaEnabler
_Must_inspect_result_ __in WDFDMAENABLER __in __in_opt WDF_OBJECT_ATTRIBUTES * Attributes
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), CommonBuffer, FX_TYPE_COMMON_BUFFER,(PVOID *) &pComBuf)
_Must_inspect_result_ __in WDFDMAENABLER DmaEnabler
WDFOBJECT handle
PFX_DRIVER_GLOBALS pFxDriverGlobals
DriverGlobals
__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_COMMON_BUFFER
Definition: fxtypes.h:109
@ FX_TYPE_DMA_ENABLER
Definition: fxtypes.h:107
@ FX_VALIDATE_OPTION_PARENT_NOT_ALLOWED
_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
#define _Must_inspect_result_
Definition: ms_sal.h:558
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
int zero
Definition: sehframes.cpp:29
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ps.c:97
#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
#define STDCALL
Definition: wdf.h:45
_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
WDF_EXTERN_C_START struct _WDF_COMMON_BUFFER_CONFIG WDF_COMMON_BUFFER_CONFIG
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFCOMMONBUFFER * CommonBuffer
WDF_EXTERN_C_START struct _WDF_COMMON_BUFFER_CONFIG * PWDF_COMMON_BUFFER_CONFIG