I understand when should call IoCompleteRequest for PnP Irp.
For Power Irp, it seems have different rule.
I am confused, I don't know when I should call IoCompleteRequest
for power Irp, when should not.

For example, bulk usb sample code of XP DDK.
In set device power state process, IoComplete routine of power Irp
calls IoCompleteRequest to complete Irp when power up.
However, IoComplete routine doesn't call IoCompleteRequest when
power down. Why it needn't call IoCompleteRequest?

What's the rule to call IoCompleteRequest for power Irp? Can anyone
tell me?

Best Regards

Jackal Huang

Re: What's the rule to call IoCompleteRequest for power Irp? by Bill

Bill
Thu Jan 08 11:04:54 CST 2004

This isn't unique to power IRPs, this is standard IRP handling. If an IRP
is sent down the stack with a completion routine, then some driver below
will complete the IRP and the completion routine need not do so. However,
if your driver reclaims the IRP from the completion routine and returns
STATUS_MORE_PROCESSING_REQUIRED, then your driver must call
IoCompleteRequest on the IRP at some point so the system can finish
processing it. This is exactly what is happening in FinishDevPoUpIrp in the
bulk USB sample.

--
Bill McKenzie
Compuware Corporation
Watch your IRPs/IRBs/URBs/SRBs/NDIS pkts with our free WDMSniffer tool:
http://frontline.compuware.com/nashua/patches/utility.htm


"Jackal Huang" <huangjj@hotmail.com> wrote in message
news:#T#APEe1DHA.2156@TK2MSFTNGP12.phx.gbl...
> I understand when should call IoCompleteRequest for PnP Irp.
> For Power Irp, it seems have different rule.
> I am confused, I don't know when I should call IoCompleteRequest
> for power Irp, when should not.
>
> For example, bulk usb sample code of XP DDK.
> In set device power state process, IoComplete routine of power Irp
> calls IoCompleteRequest to complete Irp when power up.
> However, IoComplete routine doesn't call IoCompleteRequest when
> power down. Why it needn't call IoCompleteRequest?
>
> What's the rule to call IoCompleteRequest for power Irp? Can anyone
> tell me?
>
> Best Regards
>
> Jackal Huang
>
>



Re: What's the rule to call IoCompleteRequest for power Irp? by Jackal

Jackal
Thu Jan 08 21:30:59 CST 2004

Thanks for your explanation.
Let me confirm what I understand.

If I call IoCompleteRequest in IoComplete routine, does it mean that
the upper driver's IoComplete routine will be called before return
control to dispatch routine?

In the sample code, can FinishDevPoUpIrp just return STATUS_SUCCESS
without calling IoCompleteRequest just like FinishDevPoDnIrp does?
HandleDeviceSetPower do nothing after call PoCallDriver.

Best Regards

Jackal Huang

"Bill McKenzie" <bill.mckenzie@compuware.com> ...
> This isn't unique to power IRPs, this is standard IRP handling. If an IRP
> is sent down the stack with a completion routine, then some driver below
> will complete the IRP and the completion routine need not do so. However,
> if your driver reclaims the IRP from the completion routine and returns
> STATUS_MORE_PROCESSING_REQUIRED, then your driver must call
> IoCompleteRequest on the IRP at some point so the system can finish
> processing it. This is exactly what is happening in FinishDevPoUpIrp in
the
> bulk USB sample.
>
> --
> Bill McKenzie
> Compuware Corporation
> Watch your IRPs/IRBs/URBs/SRBs/NDIS pkts with our free WDMSniffer tool:
> http://frontline.compuware.com/nashua/patches/utility.htm
>
>
> "Jackal Huang" <huangjj@hotmail.com> wrote in message
> news:#T#APEe1DHA.2156@TK2MSFTNGP12.phx.gbl...
> > I understand when should call IoCompleteRequest for PnP Irp.
> > For Power Irp, it seems have different rule.
> > I am confused, I don't know when I should call IoCompleteRequest
> > for power Irp, when should not.
> >
> > For example, bulk usb sample code of XP DDK.
> > In set device power state process, IoComplete routine of power Irp
> > calls IoCompleteRequest to complete Irp when power up.
> > However, IoComplete routine doesn't call IoCompleteRequest when
> > power down. Why it needn't call IoCompleteRequest?
> >
> > What's the rule to call IoCompleteRequest for power Irp? Can anyone
> > tell me?
> >
> > Best Regards
> >
> > Jackal Huang
> >
> >
>
>



Re: What's the rule to call IoCompleteRequest for power Irp? by Maxim

Maxim
Fri Jan 09 06:01:31 CST 2004

> If I call IoCompleteRequest in IoComplete routine, does it mean that
> the upper driver's IoComplete routine will be called before return
> control to dispatch routine?

Surely. The first thing which IoCompleteRequest does - is calling the
completion routines registered in stack locations. This loop - shift the stack
up/call the completion, shift the stack up/call the completion etc.

It is terminated and IoCompleteRequest does nothing more and quits if one of
the completions (possibly the first one) returns
STATUS_MORE_PROCESSING_REQUIRED. In this case, IoCompleteRequest is just to
"return the IRP back" to the upper layer, after it was received via the
dispatch routine.

Another condition is when all stack locations are processed. In this case,
IoCompleteRequest queues the IopCompleteRequest APC to the IRP's thread. So,
such a condition must never occur for IRPs created by IoAllocateIrp and
IoBuildAsynchronousFsdRequest.

Such a condition only occurs for IRPs created by IO manager as a result of
NtRead/Write/DeviceIoControlFile syscalls and for the IRPs allocated by
IoBuildSynchronousFsdRequest and IoBuildDeviceIoControlRequest.

> HandleDeviceSetPower do nothing after call PoCallDriver.

After Po/IoCallDriver, you must not touch the IRP till it will be delivered to
your completion routine.

Power IRPs have only the following special to them:
- you must not wait in DispatchPower (yes, you can in DispatchPnP, but not in
DispatchPower). This can cause a deadlock, since the number of threads the OS
uses to deliver power IRPs can be limited. So, be as async as possible in
DispatchPower.
- you must use PoCallDriver and not IoCallDriver for some power IRPs (nearly
for all, look at the documentation for details).
- you must also use PoStartNextPowerIrp, which is a pairing function to
PoCallDriver. PoCallDriver blocks some internal queue, while
PoStartNextPowerIrp releases it.
- PoStartNextPowerIrp must be called on a power IRP before stack location
manipulation - i.e. before IoCopyCurrentIrpStackLocationToNext or
IoSkipCurrentIrpStackLocation.
- so, the code must be like:

PoStartNextPowerIrp(Irp);
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(...);
return PoCallDriver(...);

- you must silently pass down all power IRPs unknown to you as:

PoStartNextPowerIrp(Irp);
IoSkipCurrentIrpStackLocation(Irp);
return PoCallDriver(...);

The Verifier checks this.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com



Re: What's the rule to call IoCompleteRequest for power Irp? by Bill

Bill
Fri Jan 09 10:02:05 CST 2004

Now might be a good time to pick up a copy of Walter Oney's "Programming the
Microsoft Windows Driver Model, Second Edition". In it are excellent
descriptions of most common driver issues, including IRP handling.

--
Bill McKenzie
Compuware Corporation
Watch your IRPs/IRBs/URBs/SRBs/NDIS pkts with our free WDMSniffer tool:
http://frontline.compuware.com/nashua/patches/utility.htm


"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:u7HcBhq1DHA.1684@TK2MSFTNGP12.phx.gbl...
> > If I call IoCompleteRequest in IoComplete routine, does it mean that
> > the upper driver's IoComplete routine will be called before return
> > control to dispatch routine?
>
> Surely. The first thing which IoCompleteRequest does - is calling the
> completion routines registered in stack locations. This loop - shift the
stack
> up/call the completion, shift the stack up/call the completion etc.
>
> It is terminated and IoCompleteRequest does nothing more and quits if one
of
> the completions (possibly the first one) returns
> STATUS_MORE_PROCESSING_REQUIRED. In this case, IoCompleteRequest is just
to
> "return the IRP back" to the upper layer, after it was received via the
> dispatch routine.
>
> Another condition is when all stack locations are processed. In this case,
> IoCompleteRequest queues the IopCompleteRequest APC to the IRP's thread.
So,
> such a condition must never occur for IRPs created by IoAllocateIrp and
> IoBuildAsynchronousFsdRequest.
>
> Such a condition only occurs for IRPs created by IO manager as a result of
> NtRead/Write/DeviceIoControlFile syscalls and for the IRPs allocated by
> IoBuildSynchronousFsdRequest and IoBuildDeviceIoControlRequest.
>
> > HandleDeviceSetPower do nothing after call PoCallDriver.
>
> After Po/IoCallDriver, you must not touch the IRP till it will be
delivered to
> your completion routine.
>
> Power IRPs have only the following special to them:
> - you must not wait in DispatchPower (yes, you can in DispatchPnP, but not
in
> DispatchPower). This can cause a deadlock, since the number of threads the
OS
> uses to deliver power IRPs can be limited. So, be as async as possible in
> DispatchPower.
> - you must use PoCallDriver and not IoCallDriver for some power IRPs
(nearly
> for all, look at the documentation for details).
> - you must also use PoStartNextPowerIrp, which is a pairing function to
> PoCallDriver. PoCallDriver blocks some internal queue, while
> PoStartNextPowerIrp releases it.
> - PoStartNextPowerIrp must be called on a power IRP before stack location
> manipulation - i.e. before IoCopyCurrentIrpStackLocationToNext or
> IoSkipCurrentIrpStackLocation.
> - so, the code must be like:
>
> PoStartNextPowerIrp(Irp);
> IoCopyCurrentIrpStackLocationToNext(Irp);
> IoSetCompletionRoutine(...);
> return PoCallDriver(...);
>
> - you must silently pass down all power IRPs unknown to you as:
>
> PoStartNextPowerIrp(Irp);
> IoSkipCurrentIrpStackLocation(Irp);
> return PoCallDriver(...);
>
> The Verifier checks this.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>



Re: What's the rule to call IoCompleteRequest for power Irp? by Maxim

Maxim
Fri Jan 09 12:30:17 CST 2004

There was also a native Microsoft article on the web in their KB.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com


"Bill McKenzie" <bill.mckenzie@compuware.com> wrote in message
news:OHy7Bls1DHA.4064@tk2msftngp13.phx.gbl...
> Now might be a good time to pick up a copy of Walter Oney's "Programming the
> Microsoft Windows Driver Model, Second Edition". In it are excellent
> descriptions of most common driver issues, including IRP handling.
>
> --
> Bill McKenzie
> Compuware Corporation
> Watch your IRPs/IRBs/URBs/SRBs/NDIS pkts with our free WDMSniffer tool:
> http://frontline.compuware.com/nashua/patches/utility.htm
>
>
> "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
> news:u7HcBhq1DHA.1684@TK2MSFTNGP12.phx.gbl...
> > > If I call IoCompleteRequest in IoComplete routine, does it mean that
> > > the upper driver's IoComplete routine will be called before return
> > > control to dispatch routine?
> >
> > Surely. The first thing which IoCompleteRequest does - is calling the
> > completion routines registered in stack locations. This loop - shift the
> stack
> > up/call the completion, shift the stack up/call the completion etc.
> >
> > It is terminated and IoCompleteRequest does nothing more and quits if one
> of
> > the completions (possibly the first one) returns
> > STATUS_MORE_PROCESSING_REQUIRED. In this case, IoCompleteRequest is just
> to
> > "return the IRP back" to the upper layer, after it was received via the
> > dispatch routine.
> >
> > Another condition is when all stack locations are processed. In this case,
> > IoCompleteRequest queues the IopCompleteRequest APC to the IRP's thread.
> So,
> > such a condition must never occur for IRPs created by IoAllocateIrp and
> > IoBuildAsynchronousFsdRequest.
> >
> > Such a condition only occurs for IRPs created by IO manager as a result of
> > NtRead/Write/DeviceIoControlFile syscalls and for the IRPs allocated by
> > IoBuildSynchronousFsdRequest and IoBuildDeviceIoControlRequest.
> >
> > > HandleDeviceSetPower do nothing after call PoCallDriver.
> >
> > After Po/IoCallDriver, you must not touch the IRP till it will be
> delivered to
> > your completion routine.
> >
> > Power IRPs have only the following special to them:
> > - you must not wait in DispatchPower (yes, you can in DispatchPnP, but not
> in
> > DispatchPower). This can cause a deadlock, since the number of threads the
> OS
> > uses to deliver power IRPs can be limited. So, be as async as possible in
> > DispatchPower.
> > - you must use PoCallDriver and not IoCallDriver for some power IRPs
> (nearly
> > for all, look at the documentation for details).
> > - you must also use PoStartNextPowerIrp, which is a pairing function to
> > PoCallDriver. PoCallDriver blocks some internal queue, while
> > PoStartNextPowerIrp releases it.
> > - PoStartNextPowerIrp must be called on a power IRP before stack location
> > manipulation - i.e. before IoCopyCurrentIrpStackLocationToNext or
> > IoSkipCurrentIrpStackLocation.
> > - so, the code must be like:
> >
> > PoStartNextPowerIrp(Irp);
> > IoCopyCurrentIrpStackLocationToNext(Irp);
> > IoSetCompletionRoutine(...);
> > return PoCallDriver(...);
> >
> > - you must silently pass down all power IRPs unknown to you as:
> >
> > PoStartNextPowerIrp(Irp);
> > IoSkipCurrentIrpStackLocation(Irp);
> > return PoCallDriver(...);
> >
> > The Verifier checks this.
> >
> > --
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > maxim@storagecraft.com
> > http://www.storagecraft.com
> >
> >
>
>



Re: What's the rule to call IoCompleteRequest for power Irp? by Alexander

Alexander
Fri Jan 09 22:09:54 CST 2004

Or you can call PoStartNextPowerIrp in your completion routine. The
condition is the stack location during the call should be of your driver.

"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:u7HcBhq1DHA.1684@TK2MSFTNGP12.phx.gbl...
> - PoStartNextPowerIrp must be called on a power IRP before stack location
> manipulation - i.e. before IoCopyCurrentIrpStackLocationToNext or
> IoSkipCurrentIrpStackLocation.
> - so, the code must be like:
>
> PoStartNextPowerIrp(Irp);
> IoCopyCurrentIrpStackLocationToNext(Irp);
> IoSetCompletionRoutine(...);
> return PoCallDriver(...);
>
> - you must silently pass down all power IRPs unknown to you as:
>
> PoStartNextPowerIrp(Irp);
> IoSkipCurrentIrpStackLocation(Irp);
> return PoCallDriver(...);
>
> The Verifier checks this.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>



Re: What's the rule to call IoCompleteRequest for power Irp? by Jackal

Jackal
Sun Jan 11 20:06:33 CST 2004

Thanks for your kindly reply.

Jackal Huang