Power down consequences

Hi,

I am working on the power management for the first time. I am interested
to know, what the PCI bus driver and power manager do, in response to
device’s transition to D3 state.

I could not get direct help regarding this in DDK.

I observed that my data is not getting written to device after I power
it down. I did not receive any PnP IRP. It means power manager is doing
something at hardware level. I can write data again after powering it
up.

I have following questions,

  1. a. Do I need to do any unmapping/mapping of device resources while
    handling power down/up IRPs? I think I should not do it. Is it correct?

b. If not, then it means that my earlier mapped system virtual addresses
will be correct, even after second power up operation and it does not
depend on other devices’s PnP operations. Is it correct?

  1. The power manager does not provide the current power state of the
    device. Is there any way to know the current power state, apart from
    what I maintain in my device extension?

  2. I maintain PnPState in my device extension. It is normally equal to
    “Started”. Should I change PnPState to “StopPending” or “Stopped” while
    handling Power down Device IRP? Again I think I should not do it. Is it
    correct?

Thanks,

Aparna

I strongly suggest that you use KMDF for your driver. You will not have to deal with this complexity and state management. Now, to answer your questions

1a) you only need to unmap your resources on a pnp stop, pnp graceful remove, or a pnp surprise remove. A normal power down does not require you to unmap resources. A normal power down will not take the resources away from your driver, a power down will just stop the hw from decoding those resources.

1b) correct, the mapped VA will still be valid until the next pnp operation.

  1. yes you have to track state

  2. You should not change the pnp state when you power down, BUT when you get a pnp state change (stop, remove, surprise remove), it is essentially an implicit power down message coming from pnp so you should do the power down logic and then unmap the resources.

KMDF handles all of this for you, tracks the states, and gives you the right callbacks to implement this correctly and easily w/out your driver tracking any state. In addition to the pnp/power state tracking, you also get I/O queueing and I/O queue state management that can be coordinated with pnp/power state changes. To download KMDF, goto http://www.microsoft.com/whdc/driver/wdf/KMDF_pkg.mspx

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Aparna Argade
Sent: Friday, March 31, 2006 4:03 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Power down consequences

Hi,
I am working on the power management for the first time. I am interested to know, what the PCI bus driver and power manager do, in response to device’s transition to D3 state.
I could not get direct help regarding this in DDK.

I observed that my data is not getting written to device after I power it down. I did not receive any PnP IRP. It means power manager is doing something at hardware level. I can write data again after powering it up.

I have following questions,

  1. a. Do I need to do any unmapping/mapping of device resources while handling power down/up IRPs? I think I should not do it. Is it correct?
    b. If not, then it means that my earlier mapped system virtual addresses will be correct, even after second power up operation and it does not depend on other devices’s PnP ?operations. Is it correct?
  2. The power manager does not provide the current power state of the device. Is there any way to know the current power state, apart from what I maintain in my device extension?
  3. I maintain PnPState in my device extension. It is normally equal to “Started”. Should I change PnPState to “StopPending” or “Stopped” while handling Power down Device IRP? Again I think I should not do it. Is it correct?

Thanks,
Aparna


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>to know, what the PCI bus driver and power manager do, in response to

device’s transition to D3 state.

Power manager does nothing “in response”, since it is the controlling entity
which sends this command. Executing this command is not its job.

PCI bus driver can do something with the PCI config space (I have forgotten
whether there are power-state-related addresses there).

I observed that my data is not getting written to device after I power
it down.

Correct. You must not touch any device hardware if the device is not in D0.

I did not receive any PnP IRP. It means power manager is doing
something at hardware level.

No, the PCI or ACPI bus drivers do so, rendering your device unusable.

  1. a. Do I need to do any unmapping/mapping of device resources while
    handling power down/up IRPs? I think I should not do it. Is it correct?

No. You must not do any accesses to these addresses after the device is in D3,
but the addresses themselves cannot change due to suspend/resume cycle of the
device or of the whole machine. They can only change due to device
remove/restart or due to resource rebalancing (PnP stop/start).

b. If not, then it means that my earlier mapped system virtual addresses
will be correct

Yes.

  1. The power manager does not provide the current power state of the
    device. Is there any way to know the current power state, apart from
    what I maintain in my device extension?

No. You must track the device power IRPs and maintain the state in the device
extension.

  1. I maintain PnPState in my device extension. It is normally equal to
    “Started”. Should I change PnPState to “StopPending” or “Stopped” while
    handling Power down Device IRP?

No. PnP state and the power state are different things.

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

There is one other case you have to worried about and that is someone
removing your device while it is in a powered off state. Will you get a
notification? Could it have been removed and replaced while the power was
down and would that affect your device?

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> >to know, what the PCI bus driver and power manager do, in response to
>>device’s transition to D3 state.
>
> Power manager does nothing “in response”, since it is the controlling
> entity
> which sends this command. Executing this command is not its job.
>
> PCI bus driver can do something with the PCI config space (I have
> forgotten
> whether there are power-state-related addresses there).
>
>>I observed that my data is not getting written to device after I power
>>it down.
>
> Correct. You must not touch any device hardware if the device is not in
> D0.
>
>>I did not receive any PnP IRP. It means power manager is doing
>>something at hardware level.
>
> No, the PCI or ACPI bus drivers do so, rendering your device unusable.
>
>>1. a. Do I need to do any unmapping/mapping of device resources while
>>handling power down/up IRPs? I think I should not do it. Is it correct?
>
> No. You must not do any accesses to these addresses after the device is in
> D3,
> but the addresses themselves cannot change due to suspend/resume cycle of
> the
> device or of the whole machine. They can only change due to device
> remove/restart or due to resource rebalancing (PnP stop/start).
>
>>b. If not, then it means that my earlier mapped system virtual addresses
>>will be correct
>
> Yes.
>
>>2. The power manager does not provide the current power state of the
>>device. Is there any way to know the current power state, apart from
>>what I maintain in my device extension?
>
> No. You must track the device power IRPs and maintain the state in the
> device
> extension.
>
>>3. I maintain PnPState in my device extension. It is normally equal to
>>“Started”. Should I change PnPState to “StopPending” or “Stopped” while
>>handling Power down Device IRP?
>
> No. PnP state and the power state are different things.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

From a generic POV, if the device was removed and reinserted, you would
have the following consequences:

  1. If the device was not in D3 originally, it will be in D3 upon
    reinsertion
  2. if the device was armed for wake, it will no longer be armed for
    wake

If the machine was in S0 while the device was in Dx and the parent bus
was in D0, you may get a surprise remove upon removal of the device.
That is specific behavior depending on the bus.

D

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of David J. Craig
Sent: Sunday, April 09, 2006 2:19 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Power down consequences

There is one other case you have to worried about and that is someone
removing your device while it is in a powered off state. Will you get a

notification? Could it have been removed and replaced while the power
was
down and would that affect your device?

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> >to know, what the PCI bus driver and power manager do, in response to
>>device’s transition to D3 state.
>
> Power manager does nothing “in response”, since it is the controlling
> entity
> which sends this command. Executing this command is not its job.
>
> PCI bus driver can do something with the PCI config space (I have
> forgotten
> whether there are power-state-related addresses there).
>
>>I observed that my data is not getting written to device after I power
>>it down.
>
> Correct. You must not touch any device hardware if the device is not
in
> D0.
>
>>I did not receive any PnP IRP. It means power manager is doing
>>something at hardware level.
>
> No, the PCI or ACPI bus drivers do so, rendering your device unusable.
>
>>1. a. Do I need to do any unmapping/mapping of device resources while
>>handling power down/up IRPs? I think I should not do it. Is it
correct?
>
> No. You must not do any accesses to these addresses after the device
is in
> D3,
> but the addresses themselves cannot change due to suspend/resume cycle
of
> the
> device or of the whole machine. They can only change due to device
> remove/restart or due to resource rebalancing (PnP stop/start).
>
>>b. If not, then it means that my earlier mapped system virtual
addresses
>>will be correct
>
> Yes.
>
>>2. The power manager does not provide the current power state of the
>>device. Is there any way to know the current power state, apart from
>>what I maintain in my device extension?
>
> No. You must track the device power IRPs and maintain the state in the

> device
> extension.
>
>>3. I maintain PnPState in my device extension. It is normally equal to
>>“Started”. Should I change PnPState to “StopPending” or “Stopped”
while
>>handling Power down Device IRP?
>
> No. PnP state and the power state are different things.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Some of my questions were for the device driver writer. If he has one of
those devices that require a firmware reload after a loss of power for any
reason, that may require a different design than devices that have the
firmware in flash or rom. I have seen too many questions about different
devices and my questions were intended to get him to think about what his
hardware needs. Then he may have to consider more closely following the
WHQL design guidelines for his specific category of device. From the
quality and quantity of information provided with many questions posted
here, we can never cover all the possibilities. A ‘standard’ answer may
work or not.

“Doron Holan” wrote in message
news:xxxxx@ntdev…

From a generic POV, if the device was removed and reinserted, you would
have the following consequences:

1) If the device was not in D3 originally, it will be in D3 upon
reinsertion
2) if the device was armed for wake, it will no longer be armed for
wake

If the machine was in S0 while the device was in Dx and the parent bus
was in D0, you may get a surprise remove upon removal of the device.
That is specific behavior depending on the bus.

D

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of David J. Craig
Sent: Sunday, April 09, 2006 2:19 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Power down consequences

There is one other case you have to worried about and that is someone
removing your device while it is in a powered off state. Will you get a

notification? Could it have been removed and replaced while the power
was
down and would that affect your device?

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> >to know, what the PCI bus driver and power manager do, in response to
>>device’s transition to D3 state.
>
> Power manager does nothing “in response”, since it is the controlling
> entity
> which sends this command. Executing this command is not its job.
>
> PCI bus driver can do something with the PCI config space (I have
> forgotten
> whether there are power-state-related addresses there).
>
>>I observed that my data is not getting written to device after I power
>>it down.
>
> Correct. You must not touch any device hardware if the device is not
in
> D0.
>
>>I did not receive any PnP IRP. It means power manager is doing
>>something at hardware level.
>
> No, the PCI or ACPI bus drivers do so, rendering your device unusable.
>
>>1. a. Do I need to do any unmapping/mapping of device resources while
>>handling power down/up IRPs? I think I should not do it. Is it
correct?
>
> No. You must not do any accesses to these addresses after the device
is in
> D3,
> but the addresses themselves cannot change due to suspend/resume cycle
of
> the
> device or of the whole machine. They can only change due to device
> remove/restart or due to resource rebalancing (PnP stop/start).
>
>>b. If not, then it means that my earlier mapped system virtual
addresses
>>will be correct
>
> Yes.
>
>>2. The power manager does not provide the current power state of the
>>device. Is there any way to know the current power state, apart from
>>what I maintain in my device extension?
>
> No. You must track the device power IRPs and maintain the state in the

> device
> extension.
>
>>3. I maintain PnPState in my device extension. It is normally equal to
>>“Started”. Should I change PnPState to “StopPending” or “Stopped”
while
>>handling Power down Device IRP?
>
> No. PnP state and the power state are different things.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer