ReactOS 0.4.15-dev-5884-gab5aff5
irp.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS
4 * FILE: drivers/wdm/audio/backpln/portcls/irp.cpp
5 * PURPOSE: Port Class driver / IRP Handling
6 * PROGRAMMER: Andrew Greenwood
7 * Johannes Anderwald
8 * HISTORY:
9 * 27 Jan 07 Created
10 */
11
12#include "private.hpp"
13
14#ifndef YDEBUG
15#define NDEBUG
16#endif
17
18#include <debug.h>
19
20typedef struct
21{
25
26
31 IN PIRP Irp)
32{
33 DPRINT("PortClsCreate called\n");
34
36}
37
38
43 IN PIRP Irp)
44{
47 PIO_STACK_LOCATION IoStack;
49 IResourceList* resource_list = NULL;
50 //ULONG Index;
51 //PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor, UnPartialDescriptor;
52
53 DeviceExt = (PPCLASS_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
55
56
57 DPRINT("PortClsPnp called %u\n", IoStack->MinorFunction);
58
59 //PC_ASSERT(DeviceExt);
60
61 switch (IoStack->MinorFunction)
62 {
64 DPRINT("IRP_MN_START_DEVICE\n");
65
66 // Create the resource list
68 &resource_list,
69 NULL,
71 IoStack->Parameters.StartDevice.AllocatedResourcesTranslated,
72 IoStack->Parameters.StartDevice.AllocatedResources);
73 if (!NT_SUCCESS(Status))
74 {
75 DPRINT("PcNewResourceList failed [0x%8x]\n", Status);
76 Irp->IoStatus.Status = Status;
78 return Status;
79 }
80
81 // forward irp to lower device object
83
84 if (!NT_SUCCESS(Status))
85 {
86 // lower device object failed to start
87 resource_list->Release();
88 // complete the request
90 // return result
91 return Status;
92 }
93
94 // sanity check
95 //PC_ASSERT(DeviceExt->StartDevice);
96 // Call the StartDevice routine
97 DPRINT("Calling StartDevice at 0x%8p\n", DeviceExt->StartDevice);
98 Status = DeviceExt->StartDevice(DeviceObject, Irp, resource_list);
99 if (!NT_SUCCESS(Status))
100 {
101 DPRINT("StartDevice returned a failure code [0x%8x]\n", Status);
102 Irp->IoStatus.Status = Status;
104 return Status;
105 }
106
107 // Assign the resource list to our extension
108 DeviceExt->resources = resource_list;
109
110 // store device power state
111 DeviceExt->DevicePowerState = PowerDeviceD0;
113
114 // notify power manager of current state
115 PowerState.DeviceState = DeviceExt->DevicePowerState;
117
118 Irp->IoStatus.Status = STATUS_SUCCESS;
120 return Status;
121
123 // Clean up
124 DPRINT("IRP_MN_REMOVE_DEVICE\n");
125
126 // sanity check
127 PC_ASSERT(DeviceExt);
128
129 // FIXME more cleanup */
130 if (DeviceExt->resources)
131 {
132 // free resource list */
133 DeviceExt->resources->Release();
134
135 // set to null
136 DeviceExt->resources = NULL;
137 }
138
139 // Forward request
141
143
145 DPRINT("IRP_MN_QUERY_INTERFACE\n");
149 DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS\n");
153 DPRINT("IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
157 DPRINT("IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
161 DPRINT("IRP_MN_READ_CONFIG\n");
164 }
165
166 DPRINT("unhandled function %u\n", IoStack->MinorFunction);
167 Status = Irp->IoStatus.Status;
169 return Status;
170}
171
172VOID
180{
183
184 if (NT_SUCCESS(IoStatus->Status))
185 {
186 // forward request to lower device object
187 Status = PcForwardIrpSynchronous(PwrContext->DeviceObject, PwrContext->Irp);
188 }
189 else
190 {
191 // failed
192 Status = IoStatus->Status;
193 }
194
195 // start next power irp
196 PoStartNextPowerIrp(PwrContext->Irp);
197
198 // complete request
199 PwrContext->Irp->IoStatus.Status = Status;
201
202 // free context
203 FreeItem(PwrContext, TAG_PORTCLASS);
204}
205
206
208NTAPI
211 IN PIRP Irp)
212{
213 PIO_STACK_LOCATION IoStack;
214 PPCLASS_DEVICE_EXTENSION DeviceExtension;
215 PQUERY_POWER_CONTEXT PwrContext;
218
219 DPRINT("PortClsPower called\n");
220
221 // get currrent stack location
223
224 // get device extension
225 DeviceExtension = (PPCLASS_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
226
228 {
229 // forward unknown requests down the stack and forget
232 return PoCallDriver(DeviceExtension->PrevDeviceObject, Irp);
233 }
234
235 // get current request type
236 if (IoStack->Parameters.Power.Type == DevicePowerState)
237 {
238 // request for device power state
239 if (DeviceExtension->DevicePowerState == IoStack->Parameters.Power.State.DeviceState)
240 {
241 // nothing has changed
242 if (IoStack->MinorFunction == IRP_MN_QUERY_POWER)
243 {
244 // only forward query requests; we can forget about them
247 return PoCallDriver(DeviceExtension->PrevDeviceObject, Irp);
248 }
249
250 // start next power irp
252
253 // complete request
254 Irp->IoStatus.Status = Status;
256
257 // done
258 return Status;
259 }
260
261 if (IoStack->MinorFunction == IRP_MN_QUERY_POWER)
262 {
263 // check if there is a registered adapter power management
264 if (DeviceExtension->AdapterPowerManagement)
265 {
266 // it is query if the change can be changed
267 PowerState = IoStack->Parameters.Power.State;
268 Status = DeviceExtension->AdapterPowerManagement->QueryPowerChangeState(PowerState);
269
270 if (!NT_SUCCESS(Status))
271 {
272 // fail the IRP if the adapter power manager failed
274 Irp->IoStatus.Status = Status;
276 return Status;
277 }
278 }
279
280 // only forward query requests
283 return PoCallDriver(DeviceExtension->PrevDeviceObject, Irp);
284 }
285 else
286 {
287 // set power state
288 PowerState = IoStack->Parameters.Power.State;
290
291 // check if there is a registered adapter power management
292 if (DeviceExtension->AdapterPowerManagement)
293 {
294 // notify of a power change state
295 DeviceExtension->AdapterPowerManagement->PowerChangeState(PowerState);
296 }
297
298 // FIXME call all registered IPowerNotify interfaces via ISubdevice interface
299
300 // store new power state
301 DeviceExtension->DevicePowerState = IoStack->Parameters.Power.State.DeviceState;
302
303 // complete request
304 Irp->IoStatus.Status = Status;
306
307 // done
308 return Status;
309 }
310 }
311 else
312 {
313 // sanity check
314 PC_ASSERT(IoStack->Parameters.Power.Type == SystemPowerState);
315
316 if (IoStack->MinorFunction == IRP_MN_QUERY_POWER)
317 {
318 // mark irp as pending
320
321 // allocate power completion context
323
324 if (!PwrContext)
325 {
326 // no memory
328
329 // complete and forget
330 Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
332
333 // done
334 return STATUS_PENDING;
335 }
336
337 // setup power context
338 PwrContext->Irp = Irp;
339 PwrContext->DeviceObject = DeviceObject;
340
341 // pass the irp down
342 PowerState = IoStack->Parameters.Power.State;
344
345 // check for success
346 if (!NT_SUCCESS(Status))
347 {
348 // failed
349 Irp->IoStatus.Status = Status;
351
352 // done
353 return STATUS_PENDING;
354 }
355
356 // done
357 return STATUS_PENDING;
358 }
359 else
360 {
361 // set power request
362 DeviceExtension->SystemPowerState = IoStack->Parameters.Power.State.SystemState;
363
364 // only forward query requests
367 return PoCallDriver(DeviceExtension->PrevDeviceObject, Irp);
368 }
369 }
370}
371
373NTAPI
376 IN PIRP Irp)
377{
378 DPRINT("PortClsSysControl called\n");
379
380 // TODO
381
382 Irp->IoStatus.Status = STATUS_SUCCESS;
383 Irp->IoStatus.Information = 0;
385
386 return STATUS_SUCCESS;
387}
388
390NTAPI
393 IN PIRP Irp)
394{
395 PPCLASS_DEVICE_EXTENSION DeviceExtension;
396 DPRINT("PortClsShutdown called\n");
397
398 // get device extension
399 DeviceExtension = (PPCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
400
401 if (DeviceExtension->AdapterPowerManagement)
402 {
403 // release adapter power management
404 DPRINT("Power %u\n", DeviceExtension->AdapterPowerManagement->Release());
405 }
406
407 Irp->IoStatus.Status = STATUS_SUCCESS;
408 Irp->IoStatus.Information = 0;
410
411 return STATUS_SUCCESS;
412}
413
415NTAPI
418 IN PIRP Irp)
419{
420 PIO_STACK_LOCATION IoStack;
421
423
424 DPRINT("PcDispatchIrp called - handling IRP in PortCls MajorFunction %x MinorFunction %x\n", IoStack->MajorFunction, IoStack->MinorFunction);
425
426 switch ( IoStack->MajorFunction )
427 {
428 // PortCls
429 case IRP_MJ_CREATE :
431
432 case IRP_MJ_PNP :
433 return PortClsPnp(DeviceObject, Irp);
434
435 case IRP_MJ_POWER :
437
440
441 case IRP_MJ_CLOSE:
443
446
447 case IRP_MJ_SHUTDOWN:
449
450 default:
451 DPRINT("Unhandled function %x\n", IoStack->MajorFunction);
452 break;
453 };
454
455 // If we reach here, we just complete the IRP
456 Irp->IoStatus.Status = STATUS_SUCCESS;
457 Irp->IoStatus.Information = 0;
459
460 return STATUS_SUCCESS;
461}
462
463
465NTAPI
468 IN PIRP Irp,
470{
471#if 0
473 PC_ASSERT(Irp);
475#endif
476
477 Irp->IoStatus.Status = Status;
479
480 return Status;
481}
482
484NTAPI
487 IN PIRP Irp,
489{
490 if (Irp->PendingReturned != FALSE)
491 {
493 }
495}
496
497#undef IoSetCompletionRoutine
498#define IoSetCompletionRoutine(_Irp, \
499 _CompletionRoutine, \
500 _Context, \
501 _InvokeOnSuccess, \
502 _InvokeOnError, \
503 _InvokeOnCancel) \
504{ \
505 PIO_STACK_LOCATION _IrpSp; \
506 _IrpSp = IoGetNextIrpStackLocation(_Irp); \
507 _IrpSp->CompletionRoutine = (PIO_COMPLETION_ROUTINE)(_CompletionRoutine); \
508 _IrpSp->Context = (_Context); \
509 _IrpSp->Control = 0; \
510 if (_InvokeOnSuccess) _IrpSp->Control = SL_INVOKE_ON_SUCCESS; \
511 if (_InvokeOnError) _IrpSp->Control |= SL_INVOKE_ON_ERROR; \
512 if (_InvokeOnCancel) _IrpSp->Control |= SL_INVOKE_ON_CANCEL; \
513}
514
515
516
518NTAPI
521 IN PIRP Irp)
522{
524 PPCLASS_DEVICE_EXTENSION DeviceExt;
526
528
529 DeviceExt = (PPCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
530
531 // initialize the notification event
533
534 // are there enough irp stack locations
535 if (Irp->CurrentLocation < Irp->StackCount + 1)
536 {
538 }
539
541
542 // now call the driver
544 // did the request complete yet
545 if (Status == STATUS_PENDING)
546 {
547 // not yet, lets wait a bit
549 Status = Irp->IoStatus.Status;
550 }
551 return Status;
552}
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CALLBACK
Definition: compat.h:35
KSDDKAPI NTSTATUS NTAPI KsDispatchIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:2063
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
IoMarkIrpPending(Irp)
struct QUERY_POWER_CONTEXT * PQUERY_POWER_CONTEXT
NTSTATUS NTAPI PortClsPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.cpp:41
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
NTSTATUS NTAPI PcDispatchIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.cpp:416
NTSTATUS NTAPI PcForwardIrpSynchronous(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.cpp:519
NTSTATUS NTAPI PortClsShutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.cpp:391
NTSTATUS NTAPI PortClsPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.cpp:209
NTSTATUS NTAPI PortClsCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.cpp:29
NTSTATUS NTAPI PcCompleteIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN NTSTATUS Status)
Definition: irp.cpp:466
VOID CALLBACK PwrCompletionFunction(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
Definition: irp.cpp:174
NTSTATUS NTAPI PortClsSysControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.cpp:374
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
if(dx< 0)
Definition: linetemp.h:194
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCopyCurrentIrpStackLocationToNext(Irp)
Definition: ntifs_ex.h:413
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:717
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:746
NTSTATUS NTAPI PoRequestPowerIrp(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction, _In_opt_ __drv_aliasesMem PVOID Context, _Outptr_opt_ PIRP *pIrp)
Definition: power.c:647
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ DevicePowerState
Definition: ntpoapi.h:63
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define STATUS_PENDING
Definition: ntstatus.h:82
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
struct PCLASS_DEVICE_EXTENSION * PPCLASS_DEVICE_EXTENSION
#define TAG_PORTCLASS
Definition: private.hpp:24
#define PC_ASSERT(exp)
Definition: private.hpp:26
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
PORTCLASSAPI NTSTATUS NTAPI PcNewResourceList(OUT PRESOURCELIST *OutResourceList, IN PUNKNOWN OuterUnknown OPTIONAL, IN POOL_TYPE PoolType, IN PCM_RESOURCE_LIST TranslatedResourceList, IN PCM_RESOURCE_LIST UntranslatedResourceList)
Definition: resource.cpp:300
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
IResourceList * resources
Definition: private.hpp:410
PDEVICE_OBJECT PhysicalDeviceObject
Definition: private.hpp:402
PDEVICE_OBJECT PrevDeviceObject
Definition: private.hpp:403
IAdapterPowerManagement * AdapterPowerManagement
Definition: private.hpp:406
SYSTEM_POWER_STATE SystemPowerState
Definition: private.hpp:416
PCPFNSTARTDEVICE StartDevice
Definition: private.hpp:404
DEVICE_POWER_STATE DevicePowerState
Definition: private.hpp:415
PDEVICE_OBJECT DeviceObject
Definition: irp.cpp:23
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
IO_STATUS_BLOCK IoStatus
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:895
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_QUERY_INTERFACE
#define IRP_MN_START_DEVICE
#define IRP_MN_READ_CONFIG
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MN_SET_POWER
#define IRP_MJ_SHUTDOWN
#define IRP_MJ_POWER
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7519
#define IRP_MN_QUERY_POWER
@ Executive
Definition: ketypes.h:403
unsigned char UCHAR
Definition: xmlstorage.h:181