1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7     FxPkgFdo.hpp
8 
9 Abstract:
10 
11     This module implements the pnp package for Fdo objects.
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19     Both kernel and user mode
20 
21 Revision History:
22 
23 --*/
24 
25 #ifndef _FXPKGFDO_H_
26 #define _FXPKGFDO_H_
27 
28 struct FxStaticChildDescription {
29     WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER Header;
30 
31     CfxDevice* Pdo;
32 };
33 
34 class FxPkgFdo : public FxPkgPnp
35 {
36 public:
37     //
38     // Pnp Properties
39     //
40     FxChildList* m_DefaultDeviceList;
41 
42     FxChildList* m_StaticDeviceList;
43 
44     //
45     // Default target to the attached device in the stack
46     //
47     FxIoTarget* m_DefaultTarget;
48 
49     //
50     // A virtual target to yourself. This allows a cx to send
51     // the client. It may also be used by the client to send IO to itself.
52     //
53     FxIoTargetSelf* m_SelfTarget;
54 
55 private:
56 
57     REENUMERATE_SELF_INTERFACE_STANDARD m_SurpriseRemoveAndReenumerateSelfInterface;
58 
59     //
60     // The following structure contains the function pointer table
61     // for the "events" this package can raise.
62     //
63     FxPnpDeviceFilterResourceRequirements m_DeviceFilterAddResourceRequirements;
64 
65     FxPnpDeviceFilterResourceRequirements m_DeviceFilterRemoveResourceRequirements;
66 
67     FxPnpDeviceRemoveAddedResources m_DeviceRemoveAddedResources;
68 
69     BOOLEAN m_Filter;
70 
71     //
72     // Table of internal methods to handle PnP minor function codes.
73     //
74     static const PFN_PNP_POWER_CALLBACK m_FdoPnpFunctionTable[IRP_MN_SURPRISE_REMOVAL + 1];
75 
76     //
77     // Table of internal methods to handle power minor function codes.
78     //
79     static const PFN_PNP_POWER_CALLBACK  m_FdoPowerFunctionTable[IRP_MN_QUERY_POWER + 1];
80 
81     FxPkgFdo(
82         __in PFX_DRIVER_GLOBALS FxDriverGlobals,
83         __in CfxDevice *Device
84         );
85 
86 public:
87 
88     _Must_inspect_result_
89     static
90     NTSTATUS
91     _Create(
92         __in PFX_DRIVER_GLOBALS pGlobals,
93         __in CfxDevice * Device,
94         __deref_out FxPkgFdo ** PkgFdo
95         );
96 
97     _Must_inspect_result_
98     NTSTATUS
99     RegisterCallbacks(
100         __in PWDF_FDO_EVENT_CALLBACKS DispatchTable
101         );
102 
103     _Must_inspect_result_
104     NTSTATUS
105     CreateDefaultDeviceList(
106         __in PWDF_CHILD_LIST_CONFIG ListConfig,
107         __in PWDF_OBJECT_ATTRIBUTES ListAttributes
108         );
109 
110     _Must_inspect_result_
111     virtual
112     NTSTATUS
113     Initialize(
114         __in PWDFDEVICE_INIT DeviceInit
115         );
116 
117     _Must_inspect_result_
118     NTSTATUS
119     PostCreateDeviceInitialize(
120         VOID
121         );
122 
123     _Must_inspect_result_
124     NTSTATUS
125     SetFilter(
126         __in BOOLEAN Value
127         );
128 
129     BOOLEAN
IsFilter(VOID)130     IsFilter(
131         VOID
132         )
133     {
134         return m_Filter;
135     }
136 
137 private:
138 
139     _Must_inspect_result_
140     virtual
141     NTSTATUS
142     SendIrpSynchronously(
143         __inout FxIrp* Irp
144         );
145 
146     _Must_inspect_result_
147     virtual
148     NTSTATUS
149     FireAndForgetIrp(
150         __inout FxIrp *Irp
151         );
152 
153     _Must_inspect_result_
154     static
155     NTSTATUS
156     _PnpPassDown(
157         __in FxPkgPnp* This,
158         __inout FxIrp* Irp
159         );
160 
161     _Must_inspect_result_
162     static
163     NTSTATUS
164     _PnpSurpriseRemoval(
165         __inout FxPkgPnp* This,
166         __inout FxIrp *Irp
167         );
168 
169     _Must_inspect_result_
170     static
171     NTSTATUS
172     _PnpQueryDeviceRelations(
173         __inout FxPkgPnp* This,
174         __inout FxIrp *Irp
175         );
176 
177     _Must_inspect_result_
178     NTSTATUS
179     PnpQueryDeviceRelations(
180         __inout FxIrp *Irp
181         );
182 
183     _Must_inspect_result_
184     static
185     NTSTATUS
186     _PnpQueryInterface(
187         __inout FxPkgPnp* This,
188         __inout FxIrp *Irp
189         );
190 
191     _Must_inspect_result_
192     static
193     NTSTATUS
194     _PnpQueryCapabilities(
195         __inout FxPkgPnp* This,
196         __inout FxIrp *Irp
197         );
198 
199     _Must_inspect_result_
200     NTSTATUS
201     PnpQueryCapabilities(
202         __inout FxIrp *Irp
203         );
204 
205     VOID
206     HandleQueryCapabilities(
207         __inout FxIrp *Irp
208         );
209 
210     VOID
211     HandleQueryCapabilitiesCompletion(
212         __inout FxIrp *Irp
213         );
214 
215     _Must_inspect_result_
216     static
217     NTSTATUS
218     _PnpQueryCapabilitiesCompletionRoutine(
219         __in    MdDeviceObject DeviceObject,
220         __inout MdIrp Irp,
221         __inout PVOID Context
222         );
223 
224     _Must_inspect_result_
225     static
226     NTSTATUS
227     _PnpFilterResourceRequirements(
228         __inout FxPkgPnp* This,
229         __inout FxIrp *Irp
230         );
231 
232     _Must_inspect_result_
233     NTSTATUS
234     PnpFilterResourceRequirements(
235         __inout FxIrp *Irp
236         );
237 
238     _Must_inspect_result_
239     static
240     NTSTATUS
241     _PnpQueryPnpDeviceState(
242         __inout FxPkgPnp* This,
243         __inout FxIrp *Irp
244         );
245 
246     _Must_inspect_result_
247     static
248     NTSTATUS
249     _PnpQueryPnpDeviceStateCompletionRoutine(
250         __in    MdDeviceObject DeviceObject,
251         __inout MdIrp Irp,
252         __inout PVOID Context
253         );
254 
255     VOID
256     HandleQueryPnpDeviceStateCompletion(
257         __inout FxIrp *Irp
258         );
259 
260     virtual
261     BOOLEAN
262     PnpSendStartDeviceDownTheStackOverload(
263         VOID
264         );
265 
266     virtual
267     WDF_DEVICE_PNP_STATE
268     PnpEventEjectHardwareOverload(
269         VOID
270         );
271 
272     virtual
273     WDF_DEVICE_PNP_STATE
274     PnpEventCheckForDevicePresenceOverload(
275         VOID
276         );
277 
278     virtual
279     WDF_DEVICE_PNP_STATE
280     PnpEventPdoRemovedOverload(
281         VOID
282         );
283 
284     virtual
285     WDF_DEVICE_PNP_STATE
286     PnpGetPostRemoveState(
287         VOID
288         );
289 
290     virtual
291     WDF_DEVICE_PNP_STATE
292     PnpEventFdoRemovedOverload(
293         VOID
294         );
295 
296     static
297     _Must_inspect_result_
298     NTSTATUS
299     _PowerPassDown(
300         __inout FxPkgPnp* This,
301         __in FxIrp *Irp
302         );
303 
304     static
305     _Must_inspect_result_
306     NTSTATUS
307     _DispatchSetPower(
308         __inout FxPkgPnp* This,
309         __in FxIrp *Irp
310         );
311 
312     static
313     _Must_inspect_result_
314     NTSTATUS
315     _DispatchQueryPower(
316         __inout FxPkgPnp* This,
317         __in FxIrp *Irp
318         );
319 
320     virtual
321     _Must_inspect_result_
322     NTSTATUS
323     PowerCheckParentOverload(
324         __out BOOLEAN* ParentOn
325         );
326 
327     virtual
328     WDF_DEVICE_POWER_STATE
329     PowerCheckDeviceTypeOverload(
330         VOID
331         );
332 
333     virtual
334     WDF_DEVICE_POWER_STATE
335     PowerCheckDeviceTypeNPOverload(
336         VOID
337         );
338 
339     virtual
340     VOID
341     PowerParentPowerDereference(
342         VOID
343         );
344 
345     _Must_inspect_result_
346     NTSTATUS
347     DispatchSystemSetPower(
348         __in FxIrp *Irp
349         );
350 
351     _Must_inspect_result_
352     NTSTATUS
353     DispatchDeviceSetPower(
354         __in FxIrp *Irp
355         );
356 
357     _Must_inspect_result_
358     NTSTATUS
359     DispatchSystemQueryPower(
360         __in FxIrp *Irp
361         );
362 
363     _Must_inspect_result_
364     NTSTATUS
365     DispatchDeviceQueryPower(
366         __in FxIrp *Irp
367         );
368 
369      _Must_inspect_result_
370    NTSTATUS
371     RaiseDevicePower(
372         __in FxIrp *Irp
373         );
374 
375     _Must_inspect_result_
376     NTSTATUS
377     LowerDevicePower(
378         __in FxIrp *Irp
379         );
380 
381     virtual
382     VOID
383     PowerReleasePendingDeviceIrp(
384         __in BOOLEAN IrpMustBePresent = TRUE
385         );
386 
387     _Must_inspect_result_
388     virtual
389     NTSTATUS
390     ProcessRemoveDeviceOverload(
391         __inout FxIrp* Irp
392         );
393 
394     virtual
395     VOID
396     DeleteSymbolicLinkOverload(
397         __in BOOLEAN GracefulRemove
398         );
399 
400     virtual
401     VOID
402     QueryForReenumerationInterface(
403         VOID
404         );
405 
406     virtual
407     VOID
408     ReleaseReenumerationInterface(
409         VOID
410         );
411 
412     _Must_inspect_result_
413     virtual
414     NTSTATUS
415     AskParentToRemoveAndReenumerate(
416         VOID
417         );
418 
419     _Must_inspect_result_
420     virtual
421     NTSTATUS
422     QueryForPowerThread(
423         VOID
424         );
425 
426     virtual
427     const PFN_PNP_POWER_CALLBACK*
GetDispatchPnp(VOID)428     GetDispatchPnp(
429         VOID
430         )
431     {
432         return m_FdoPnpFunctionTable;
433     }
434 
435     virtual
436     const PFN_PNP_POWER_CALLBACK*
GetDispatchPower(VOID)437     GetDispatchPower(
438         VOID
439         )
440     {
441         return m_FdoPowerFunctionTable;
442     }
443 
444     _Must_inspect_result_
445     NTSTATUS
446     QueryForDsfInterface(
447         VOID
448         );
449 
450 public:
451 
452     static
453     MdCompletionRoutineType
454     RaiseDevicePowerCompletion;
455 
456 protected:
457     ~FxPkgFdo();
458 
459     static
460     MdCompletionRoutineType
461     _SystemPowerS0Completion;
462 
463     static
464     MdCompletionRoutineType
465     _SystemPowerSxCompletion;
466 
467     _Must_inspect_result_
468     static
469     NTSTATUS
470     STDCALL
471     _PnpFilteredStartDeviceCompletionRoutine(
472         __in    MdDeviceObject DeviceObject,
473         __inout MdIrp Irp,
474         __inout PVOID Context
475         );
476 
477     _Must_inspect_result_
478     static
479     NTSTATUS
480     STDCALL
481     _PnpStartDeviceCompletionRoutine(
482         __in    MdDeviceObject DeviceObject,
483         __inout MdIrp Irp,
484         __inout PVOID Context
485         );
486 };
487 
488 #endif // _FXPKGFDO_H
489