ReactOS  0.4.15-dev-3302-ga37d9a4
fxiotargetapikm.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxIoTargetAPIKm.cpp
8 
9 Abstract:
10 
11  This module implements the IO Target APIs
12 
13 Author:
14 
15 Environment:
16 
17  kernel mode only
18 
19 Revision History:
20 
21 --*/
22 
23 #include "../../fxtargetsshared.hpp"
24 
25 extern "C" {
26 // #include "FxIoTargetAPIKm.tmh"
27 }
28 
29 //
30 // Extern the entire file
31 //
32 extern "C" {
33 
36 STDCALL
37 WDFEXPORT(WdfIoTargetWdmGetTargetDeviceObject)(
38  __in
40  __in
41  WDFIOTARGET IoTarget
42  )
43 /*++
44 
45 Routine Description:
46  Returns the PDEVICE_OBJECT. This is the device which PIRPs are sent to.
47  This is not necessarily the PDEVICE_OBJECT that WDFDEVICE is attached to.
48 
49 Arguments:
50  IoTarget - target whose WDM device object is being returned
51 
52 Return Value:
53  valid PDEVICE_OBJECT or NULL on failure
54 
55  --*/
56 {
60 
62  IoTarget,
64  (PVOID*) &pTarget,
66 
68  "enter WDFIOTARGET 0x%p", IoTarget);
69 
71 
73  "exit WDFIOTARGET 0x%p, WDM DevObj 0x%p", IoTarget, pDevice);
74 
75  return pDevice;
76 }
77 
80 STDCALL
81 WDFEXPORT(WdfIoTargetWdmGetTargetPhysicalDevice)(
82  __in
84  __in
85  WDFIOTARGET IoTarget
86  )
87 /*++
88 
89 Routine Description:
90  Returns the PDO for the target itself. This is not necessarily the same
91  PDO as the WDFDEVICE that owns the target. Not all targets have a PDO since
92  you can open a legacy non pnp PDEVICE_OBJECT which does not have one.
93 
94 Arguments:
95  IoTarget - target whose PDO is being returned
96 
97 Return Value:
98  A valid PDEVICE_OBJECT or NULL upon success
99 
100  --*/
101 {
105 
107  IoTarget,
109  (PVOID*) &pTarget,
111 
113  "enter WDFIOTARGET 0x%p", IoTarget);
114 
116 
118  "exit WDFIOTARGET 0x%p, WDM PDO 0x%p", IoTarget, pPdo);
119 
120  return pPdo;
121 }
122 
123 
126 STDCALL
127 WDFEXPORT(WdfIoTargetWdmGetTargetFileObject)(
128  __in
130  __in
131  WDFIOTARGET IoTarget
132  )
133 /*++
134 
135 Routine Description:
136  Returns the PFILE_OBJECT associated with the target. Not all targets have
137  an underlying file object so NULL is a valid and successful return value.
138 
139 Arguments:
140  IoTarget - the target whose fileobject is being returned
141 
142 Return Value:
143  a valid PFILE_OBJECT or NULL upon success
144 
145  --*/
146 {
150 
152  IoTarget,
154  (PVOID*) &pTarget,
156 
158  "enter WDFIOTARGET 0x%p", IoTarget);
159 
161 
163  "exit WDFIOTARGET 0x%p, WDM FileObj 0x%p", IoTarget, pFile);
164 
165  return pFile;
166 }
167 
170 NTSTATUS
171 STDCALL
172 WDFEXPORT(WdfIoTargetQueryForInterface)(
173  __in
175  __in
176  WDFIOTARGET IoTarget,
177  __in
179  __out
181  __in
182  USHORT Size,
183  __in
184  USHORT Version,
185  __in_opt
187  )
188 /*++
189 
190 Routine Description:
191  Sends a query interface pnp request to the top of the target's stack.
192 
193 Arguments:
194  IoTarget - the target which is being queried
195 
196  InterfaceType - interface type specifier
197 
198  Interface - Interface block which will be filled in by the component which
199  responds to the query interface
200 
201  Size - size in bytes of Interface
202 
203  Version - version of InterfaceType being requested
204 
205  InterfaceSpecificData - Additional data associated with Interface
206 
207 Return Value:
208  NTSTATUS
209 
210  --*/
211 {
216 
218  IoTarget,
220  (PVOID*) &pTarget,
222 
225 
228  return status;
229  }
230 
232  ASSERT(pTopOfStack != NULL);
233 
236  Interface,
237  Size,
238  Version,
240 
242 
243  return status;
244 }
245 
248 NTSTATUS
249 STDCALL
250 WDFEXPORT(WdfIoTargetQueryTargetProperty)(
251  __in
253  __in
254  WDFIOTARGET IoTarget,
255  __in
257  __in
264  )
265 /*++
266 
267 Routine Description:
268  Retrieves the requested device property for the given target
269 
270 Arguments:
271  IoTarget - the target whose PDO whose will be queried
272 
273  DeviceProperty - the property being queried
274 
275  BufferLength - length of PropertyBuffer in bytes
276 
277  PropertyBuffer - Buffer which will receive the property being queried
278 
279  ResultLength - if STATUS_BUFFER_TOO_SMALL is returned, then this will contain
280  the required length
281 
282 Return Value:
283  NTSTATUS
284 
285  --*/
286 {
287  DDI_ENTRY();
288 
293 
295  IoTarget,
297  (PVOID*) &pTarget,
298  &pGlobals);
299 
301  if (BufferLength > 0) {
303  }
304 
306  if (!NT_SUCCESS(status)) {
307  return status;
308  }
309 
311 
312  if (pPdo == NULL) {
314 
316  "WDFIOTARGET 0x%p has no PDO (not opened yet?), %!STATUS!",
317  IoTarget, status);
318 
319  return status;
320  }
321 
324  BufferLength,
326  ResultLength);
327 
329  "exit WDFIOTARGET 0x%p, Property %d, %!STATUS!",
331 
332 
333 
334  return status;
335 }
336 
339 WDFAPI
340 NTSTATUS
341 STDCALL
342 WDFEXPORT(WdfIoTargetAllocAndQueryTargetProperty)(
343  __in
345  __in
346  WDFIOTARGET IoTarget,
347  __in
349  __in
352  __in_opt
354  __out
355  WDFMEMORY* PropertyMemory
356  )
357 /*++
358 
359 Routine Description:
360  Allocates and retrieves the requested device property for the given target
361 
362 Arguments:
363  IoTarget - the target whose PDO whose will be queried
364 
365  DeviceProperty - the property being queried
366 
367  PoolType - what type of pool to allocate
368 
369  PropertyMemoryAttributes - attributes to associate with PropertyMemory
370 
371  PropertyMemory - handle which will receive the property buffer
372 
373 Return Value:
374  NTSTATUS
375 
376  --*/
377 {
378  DDI_ENTRY();
379 
384 
386  IoTarget,
388  (PVOID*) &pTarget,
390 
392 
393  *PropertyMemory = NULL;
394 
396  if (!NT_SUCCESS(status)) {
397  return status;
398  }
399 
401 
403  if (!NT_SUCCESS(status)) {
404  return status;
405  }
406 
408 
409  if (pPdo == NULL) {
411 
413  "WDFIOTARGET %p has no PDO (not opened yet?), %!STATUS!",
414  IoTarget, status);
415 
416  return status;
417  }
418 
419  //
420  // Worker function which does the 2 passes. First pass to query the size,
421  // the second pass w/the correctly sized buffer.
422  //
424  NULL,
425  NULL,
426  pPdo,
428  PoolType,
431 
433  "exit WDFIOTARGET 0x%p, Property %d, %!STATUS!",
435 
436  return status;
437 }
438 
439 }
__in WDFIOTARGET IoTarget
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
DEVICE_REGISTRY_PROPERTY
Definition: iotypes.h:1194
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT _In_opt_ PVOID InterfaceSpecificData
Definition: wdffdo.h:461
#define __in_opt
Definition: dbghelp.h:38
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3767
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), IoTarget, FX_TYPE_IO_TARGET,(PVOID *) &pTarget, &pFxDriverGlobals)
static _Must_inspect_result_ NTSTATUS _AllocAndQueryProperty(_In_ PFX_DRIVER_GLOBALS Globals, _In_opt_ PWDFDEVICE_INIT DeviceInit, _In_opt_ FxDevice *Device, _In_opt_ MdDeviceObject RemotePdo, _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty, _In_ POOL_TYPE PoolType, _In_opt_ PWDF_OBJECT_ATTRIBUTES PropertyMemoryAttributes, _Out_ WDFMEMORY *PropertyMemory)
Definition: fxdevice.cpp:1988
LONG NTSTATUS
Definition: precomp.h:26
__in WDFIOTARGET __in LPCGUID __out PINTERFACE Interface
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_Must_inspect_result_ __in WDFIOTARGET __in DEVICE_REGISTRY_PROPERTY __in ULONG BufferLength
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFMEMORY * PropertyMemory
Definition: wdfdevice.h:3810
__drv_maxIRQL(DISPATCH_LEVEL) PDEVICE_OBJECT STDCALL WDFEXPORT(WdfIoTargetWdmGetTargetDeviceObject)(__in PWDF_DRIVER_GLOBALS DriverGlobals
DriverGlobals
PFILE_OBJECT MdFileObject
Definition: mxgeneralkm.h:32
PDEVICE_OBJECT pPdo
__inline MdDeviceObject GetTargetPDO(VOID)
Definition: fxiotarget.hpp:281
__inline MdFileObject GetTargetFileObject(VOID)
Definition: fxiotarget.hpp:290
_Must_inspect_result_ __in WDFIOTARGET __in DEVICE_REGISTRY_PROPERTY __in ULONG __out_opt PVOID __deref_out_range(<=, BufferLength) PULONG ResultLength)
FxPointerNotNull(pFxDriverGlobals, InterfaceType)
PDEVICE_OBJECT pDevice
FxIoTarget * pTarget
#define __out_opt
Definition: dbghelp.h:65
PDEVICE_OBJECT pTopOfStack
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define WDFAPI
Definition: wdftypes.h:53
#define __out
Definition: dbghelp.h:62
_Must_inspect_result_ __in WDFUSBDEVICE __in CONST GUID __in ULONG __out_bcount_part_opt(CapabilityBufferLength, *ResultLength)) PVOID CapabilityBuffer
__in WDFIOTARGET __in LPCGUID __out PINTERFACE __in USHORT __in USHORT Version
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
__inline MdDeviceObject GetTargetDevice(VOID)
Definition: fxiotarget.hpp:272
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
__in WDFIOTARGET __in LPCGUID __out PINTERFACE __in USHORT __in USHORT __in_opt PVOID InterfaceSpecificData
#define STDCALL
Definition: wdf.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:78
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:361
* PFILE_OBJECT
Definition: iotypes.h:1998
ASSERT(pTopOfStack !=NULL)
MdFileObject pFile
PFX_DRIVER_GLOBALS pFxDriverGlobals
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID PropertyBuffer
Definition: wdfdevice.h:4431
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
PFX_DRIVER_GLOBALS pGlobals
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES PropertyMemoryAttributes
Definition: wdfdevice.h:3810
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
static _Must_inspect_result_ NTSTATUS _QueryForInterface(__in PDEVICE_OBJECT TopOfStack, __in const GUID *InterfaceType, __out PINTERFACE Interface, __in USHORT Size, __in USHORT Version, __in_opt PVOID InterfaceSpecificData)
unsigned short USHORT
Definition: pedump.c:61
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
NTSTATUS status
static __inline NTSTATUS _GetDeviceProperty(_In_ MdDeviceObject DeviceObject, _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty, _In_ ULONG BufferLength, _Out_opt_ PVOID PropertyBuffer, _Out_ PULONG ResultLength)
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
_Must_inspect_result_ __in WDFIOTARGET __in DEVICE_REGISTRY_PROPERTY DeviceProperty
unsigned int ULONG
Definition: retypes.h:1
_Must_inspect_result_ _In_ WDFDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIOTARGET * IoTarget
Definition: wdfiotarget.h:363
__in WDFIOTARGET __in LPCGUID __out PINTERFACE __in USHORT Size
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
__in WDFIOTARGET __in LPCGUID InterfaceType
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, "enter WDFIOTARGET 0x%p", IoTarget)
#define __in
Definition: dbghelp.h:35
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
_Must_inspect_result_ __in WDFIOTARGET __in DEVICE_REGISTRY_PROPERTY __in __drv_strictTypeMatch(1) POOL_TYPE PoolType
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:461
ObDereferenceObject(pTopOfStack)
FxVerifierCheckNxPoolType(pFxDriverGlobals, PoolType, pFxDriverGlobals->Tag)
_Must_inspect_result_ __in WDFIOTARGET __in DEVICE_REGISTRY_PROPERTY __in ULONG __drv_when(BufferLength !=0, __out_bcount_part_opt(BufferLength, *ResultLength)) __drv_when(BufferLength
Definition: ps.c:97