ACPI: power: Save the last known state of each power resource
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 24 May 2021 15:25:23 +0000 (17:25 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 31 May 2021 11:59:01 +0000 (13:59 +0200)
commitca84f18798a457e9a92c52882813901e15a3b38b
tree438c13defab125b76678179601d61b5cc6e0c7f3
parent587024b8210d4eeeab457323141c92e134cd3dbf
ACPI: power: Save the last known state of each power resource

Currently, there are two ways to check the state of an ACPI power
resource and they may not be consistent with each other.  The first
one is to evaluate the power resource's _STA object and the other one
is to check its reference counter value.  However, on some systems
the value returned by _STA may not be consistent with the value of
the power resource's reference counter (for example, on some systems
it returns the same value every time for certain power resources).

Moreover, evaluating _STA is unnecessary overhead for a power
resource for which it has been evaluated already or whose state is
otherwise known, because either the _ON or the _OFF method has been
executed for it.

For this reason, save the state of each power resource in its
struct acpi_power_resource object and use the saved value whenever
its state needs to be checked, except when its stats is unknown, in
which case the _STA method is evaluated for it and the value
returned by that method is saved as the last known state of
the power resource.

Moreover, drop the power resource _STA method evaluation from
acpi_add_power_resource(), so as to avoid doing that unnecessarily
for power resources that will never be used.

Tested-by: Dave Olsthoorn <dave@bewaar.me>
Tested-by: Shujun Wang <wsj20369@163.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/power.c