History log of /linux-master/drivers/acpi/x86/s2idle.c
Revision Date Author Comments
# 68301ef4 23-Apr-2024 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: PM: s2idle: Evaluate all Low-Power S0 Idle _DSM functions

Commit 073237281a50 ("ACPI: PM: s2idle: Enable Low-Power S0 Idle MSFT
UUID for non-AMD systems") attempted to avoid evaluating the same Low-
Power S0 Idle _DSM functions for different UUIDs, but that turns out to
be a mistake, because some systems in the field are adversely affected
by it.

Address this by allowing all Low-Power S0 Idle _DSM functions to be
evaluated, but still print the message regarding duplication of Low-
Power S0 Idle _DSM function sets for different UUIDs.

Fixes: 073237281a50 ("ACPI: PM: s2idle: Enable Low-Power S0 Idle MSFT UUID for non-AMD systems")
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218750
Reported-and-tested-by: Mark Pearson <mpearson@lenovo.com>
Suggested-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>


# 07323728 06-Feb-2024 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: PM: s2idle: Enable Low-Power S0 Idle MSFT UUID for non-AMD systems

Systems based on Intel platforms that use the MSFT UUID for Low-Power S0
Idle (LPS0) have started to ship, so allow the kernel to use the MSFT
UUID in the non-AMD case too, but in that case make it avoid evaluating
the same _DSM function for two different UUIDs and prioritize the MSFT
one.

While at it, combine two MSFT _DSM function mask checks in
acpi_s2idle_restore_early() so as to make it reflect the
acpi_s2idle_prepare_late() flow more closely and adjust the
Modern Standby entry and exit comments slightly.

Non-AMD systems that do not support MSFT UUID for Low-power S0 Idle are
not expected to be affected by this change in any way.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>


# 55392187 02-Oct-2023 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

ACPI: x86: s2idle: Switch to use acpi_evaluate_dsm_typed()

The acpi_evaluate_dsm_typed() provides a way to check the type of the
object evaluated by _DSM call. Use it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 1c2a66d4 18-Aug-2023 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Add a function to get LPS0 constraint for a device

Other parts of the kernel may use LPS0 constraints information to make
decisions on what power state to put a device into.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
[ rjw: Rewrite kerneldoc, rearrange if () statement, edit subject and
changelog ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 41233988 18-Aug-2023 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

ACPI: x86: s2idle: Add for_each_lpi_constraint() helper

We have one existing and one coming user of this macro.
Introduce a helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# a879058d 18-Aug-2023 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Add more debugging for AMD constraints parsing

While parsing the constraints show all the entries for the table
to aid with debugging other problems later.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 9cc8cd08 18-Aug-2023 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Fix a logic error parsing AMD constraints table

The constraints table should be resetting the `list` object
after running through all of `info_obj` iterations.

This adjusts whitespace as well as less code will now be included
with each loop. This fixes a functional problem is fixed where a
badly formed package in the inner loop may have incorrect data.

Fixes: 146f1ed852a8 ("ACPI: PM: s2idle: Add AMD support to handle _DSM")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 883cf0d4 18-Aug-2023 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Catch multiple ACPI_TYPE_PACKAGE objects

If a badly constructed firmware includes multiple `ACPI_TYPE_PACKAGE`
objects while evaluating the AMD LPS0 _DSM, there will be a memory
leak. Explicitly guard against this.

Suggested-by: Bjorn Helgaas <helgaas@kernel.org>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 3c6b1212 18-Aug-2023 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Post-increment variables when getting constraints

When code uses a pre-increment it makes the reader question "why".
In the constraint fetching code there is no reason for the variables
to be pre-incremented so adjust to post-increment.
No intended functional changes.

Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Suggested-by: Bjorn Helgaas <helgaas@kernel.org>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# f7540060 02-Jun-2023 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: Add pm_debug_messages for LPS0 _DSM state tracking

Enabling debugging messages for the state requires turning on dynamic
debugging for the file. To make it more accessible, use
`pm_debug_messages` and clearer strings for what is happening.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# f198478c 01-Jun-2023 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Adjust Microsoft LPS0 _DSM handling sequence

In Windows the Microsoft _DSM doesn't call functions 3->5->7 for suspend
and 8->6->4 for resume like Linux currently does.

Rather it calls 3->7->5 for suspend and 6->8->4 for resume.
Align this calling order for Linux as well.

Link: https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/modern-standby-states
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# e32d546c 23-Feb-2023 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: Drop quirk for HP Elitebook

There was a quirk in `acpi/x86/s2idle.c` for an HP Elitebook G9
platforms to force AMD GUID codepath instead of Microsoft codepath.

This was due to a bug with WCN6855 WLAN firmware interaction with
the system.

This bug is fixed by WCN6855 firmware:
WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.23

Remove the quirk as it's no longer necessary with this firmware.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/commit/?id=c7a57ef688f7d99d8338a5d8edddc8836ff0e6de
Tested-by: Anson Tsao <anson.tsao@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# e555c857 15-Dec-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Stop using AMD specific codepath for Rembrandt+

After we introduced a module parameter and quirk infrastructure for
picking the Microsoft GUID over the SOC vendor GUID we discovered
that lots and lots of systems are getting this wrong.

The table continues to grow, and is becoming unwieldy.

We don't really have any benefit to forcing vendors to populate the
AMD GUID. This is just extra work, and more and more vendors seem
to mess it up. As the Microsoft GUID is used by Windows as well,
it's very likely that it won't be messed up like this.

So drop all the quirks forcing it and the Rembrandt behavior. This
means that Cezanne or later effectively only run the Microsoft GUID
codepath with the exception of HP Elitebook 8*5 G9.

Fixes: fd894f05cf30 ("ACPI: x86: s2idle: If a new AMD _HID is missing assume Rembrandt")
Cc: stable@vger.kernel.org # 6.1
Reported-by: Benjamin Cheng <ben@bcheng.me>
Reported-by: bilkow@tutanota.com
Reported-by: Paul <paul@zogpog.com>
Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2292
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216768
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Philipp Zabel <philipp.zabel@gmail.com>
Tested-by: Philipp Zabel <philipp.zabel@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 3ea45390 15-Dec-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Force AMD GUID/_REV 2 on HP Elitebook 865

HP Elitebook 865 supports both the AMD GUID w/ _REV 2 and Microsoft
GUID with _REV 0. Both have very similar code but the AMD GUID
has a special workaround that is specific to a problem with
spurious wakeups on systems with Qualcomm WLAN.

This is believed to be a bug in the Qualcomm WLAN F/W (it doesn't
affect any other WLAN H/W). If this WLAN firmware is fixed this
quirk can be dropped.

Cc: stable@vger.kernel.org # 6.1
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 5950e5d5 22-Aug-2022 Peter Zijlstra <peterz@infradead.org>

freezer: Have {,un}lock_system_sleep() save/restore flags

Rafael explained that the reason for having both PF_NOFREEZE and
PF_FREEZER_SKIP is that {,un}lock_system_sleep() is callable from
kthread context that has previously called set_freezable().

In preparation of merging the flags, have {,un}lock_system_slee() save
and restore current->flags.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220822114648.725003428@infradead.org


# 811d59fd 29-Aug-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: s2idle: Add a new ->check() callback for platform_s2idle_ops

On some platforms it is found that Linux more aggressively enters s2idle
than Windows enters Modern Standby and this uncovers some synchronization
issues for the platform. To aid in debugging this class of problems in
the future, add support for an extra optional callback intended for
drivers to emit extra debugging.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220829162953.5947-2-mario.limonciello@amd.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# 54bd1e54 28-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Add another ID to s2idle_dmi_table

It's reported that "ASUSTeK COMPUTER INC. ROG Flow X16 GV601RW" has
non-functional fans after resume when using the AMD codepath. This
issue is fixed using the Microsoft codepath.

Add the 3 variants of this system to the Microsoft codepath DMI table.
* GV601RW
* GV601RM
* GV601RE

Link: https://www.reddit.com/r/linuxhardware/comments/wh50nd/compatibility_report_asus_rog_flow_x16_gv601rm/
Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2148#note_1571241
Reported-by: Luke Jones <luke@ljones.dev>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 39f81776 28-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Fix a NULL pointer dereference

Ryzen 7000 (Raphael) introduced AMDI0008 for _HID. This ID was added
in commit ed470febf837 ("ACPI: PM: s2idle: Add support for upcoming AMD
uPEP HID AMDI008"), but then removed in favor of aligning all new IDs
to Rembrandt support in commit fd894f05cf30 ("ACPI: x86: s2idle: If a
new AMD _HID is missing assume Rembrandt").

Unfortunately there was a mistake in commit 100a57379380 ("ACPI: x86:
s2idle: Move _HID handling for AMD systems into structures") that can
lead to a NULL pointer dereference accessing `dev_id->driver_data` in
the sentinel of `amd_hid_ids`. Fix this dereference.

Reported-by: Richard Gong <Richard.Gong@amd.com>
Fixes: 100a57379380 ("ACPI: x86: s2idle: Move _HID handling for AMD systems into structures")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 631b5451 21-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Add a quirk for ASUSTeK COMPUTER INC. ROG Flow X13

ASUSTeK COMPUTER INC. ROG Flow X13 has a problem with fans upon wakeup from
s2idle. In examining the ASL, functions 3 and 4 are not called in the AMD
codepath but only in the Microsoft codepath.

Add the system to the quirk list to force Microsoft codepath.

Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2148
Tested-by: short-circuit <davidedp91@gmail.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 888ca9c7 21-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Add a quirk for Lenovo Slim 7 Pro 14ARH7

Lenovo Slim 7 Pro 14ARH7 has a sporadically non-functional keyboard
when resuming from s2idle. This is caused by some missing calls to the
EC that don't occur in the AMD codepath but only in the Microsoft codepath.

Add the system to the quirk list to force Microsoft codepath.

Reported-by: Travis Glenn Hansen <travisghansen@yahoo.com>
Reported-by: Sebastian S. <iam@decentr.al>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216473
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216438
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# ddeea2c3 21-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Add a quirk for ASUS ROG Zephyrus G14

ASUS ROG Zephyrus G14 is affected by the same BIOS bug as ASUS TUF
Gaming A17 where important ASL is not called in the AMD code path.
Use the Microsoft codepath instead.

Reported-and-suggested-by: Philipp Zabel <philipp.zabel@gmail.com>
Tested-by: Philipp Zabel <philipp.zabel@gmail.com>
Tested-by: Matthew Anderson <ruinairas1992@gmail.com>
Tested-by: Marko Cekrlic <marko.cekrlic.26@gmail.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# d0f61e89 21-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Add a quirk for ASUS TUF Gaming A17 FA707RE

ASUS TUF Gaming A17 FA707RE has problems with ACPI events after
s2idle resume. It's from a missing call to an ASL method in AMD
the s2idle calling path. Force the system to use the Microsoft
Modern Standby calling path instead.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=216101
Reported-and-tested-by: catalin@antebit.com
Reviewed-by: Philipp Zabel <philipp.zabel@gmail.com>
Tested-by: Philipp Zabel <philipp.zabel@gmail.com> # GA402RJ
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# a0bc0023 21-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Add module parameter to prefer Microsoft GUID

OEMs have made some mistakes in the past for the AMD GUID support
and not populated the method properly. To add an escape hatch for
this problem introduce a module parameter that can force using
the Microsoft GUID.

This is intentionally introduced to both Intel and AMD codepaths
to allow using the parameter as a debugging tactic on either.

Reviewed-by: Philipp Zabel <philipp.zabel@gmail.com>
Tested-by: Philipp Zabel <philipp.zabel@gmail.com> # GA402RJ
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# fd894f05 21-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: If a new AMD _HID is missing assume Rembrandt

A mistake was made that only AMDI0007 was set to rev of "2", but
it should have been also set for AMDI008. If an ID is missing from
the _HID table, then assume it matches Rembrandt behavior.

This implicitly means that if any other behavior changes happen
in the future missing IDs must be added to that table.

Tested-by: catalin@antebit.com
Reviewed-by: Philipp Zabel <philipp.zabel@gmail.com>
Tested-by: Philipp Zabel <philipp.zabel@gmail.com> # GA402RJ
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 100a5737 21-Sep-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: x86: s2idle: Move _HID handling for AMD systems into structures

Right now the information about which cases to use for what are in a
comment, but this is error prone. Instead move all information into
a dedicated structure.

Tested-by: catalin@antebit.com
Reviewed-by: Philipp Zabel <philipp.zabel@gmail.com>
Tested-by: Philipp Zabel <philipp.zabel@gmail.com> # GA402RJ
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# ec6c0503 21-Jul-2022 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: PM: x86: Print messages regarding LPS0 idle support

Because suspend-to-idle is always supported and on x86 it is the only
way to suspend the system if S3 is not supported by the platform, the
kernel attempts to enter low-power S0 idle in the suspend-to-idle flow
regardless of whether or not the ACPI_FADT_LOW_POWER_S0 flag is set in
the FADT. However, if that flag is not set, residency counters
associated with low-power S0 idle may not count and the platform may
refuse to put the EC into a low-power mode, for example.

For this reason, print diagnostic messages when the platform should
achieve significant energy savings in low-power S0 idle (because the
ACPI_FADT_LOW_POWER_S0 flag is set in the FADT) and when
suspend-to-idle becomes the default suspend method (because low-power
S0 idle should be equally or more efficient than S3, if available).

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>


# 1a2dcab5 13-Jul-2022 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: PM: s2idle: Use LPS0 idle if ACPI_FADT_LOW_POWER_S0 is unset

If the PNP0D80 device is present and its _DSM appears to be valid,
there is no reason to avoid using it even if ACPI_FADT_LOW_POWER_S0
is unset in the FADT, because suspend-to-idle may be the only way to
suspend the system if S3 is not supported by the platform, so do not
return early from lps0_device_attach() in that case.

However, still check ACPI_FADT_LOW_POWER_S0 when deciding whether or
not suspend-to-idle should be the default system suspend method.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>


# ed470feb 03-Jul-2022 Shyam Sundar S K <Shyam-sundar.S-k@amd.com>

ACPI: PM: s2idle: Add support for upcoming AMD uPEP HID AMDI008

New version of uPEP will have a separate ACPI id, add that
to the support list.

Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 20e1d640 17-Mar-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI / x86: Add support for LPS0 callback handler

Currenty the latest thing run during a suspend to idle attempt is
the LPS0 `prepare_late` callback and the earliest thing is the
`resume_early` callback.

There is a desire for the `amd-pmc` driver to suspend later in the
suspend process (ideally the very last thing), so create a callback
that it or any other driver can hook into to do this.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220317141445.6498-1-mario.limonciello@amd.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>


# d6ebb17c 28-Jan-2022 Mario Limonciello <mario.limonciello@amd.com>

ACPI: PM: Revert "Only mark EC GPE for wakeup on Intel systems"

Testing on various upcoming OEM systems shows commit 7b167c4cb48e ("ACPI:
PM: Only mark EC GPE for wakeup on Intel systems") was short
sighted and the symptoms were indicative of other problems. Some OEMs
do have the dedicated GPIOs for the power button but also rely upon
an interrupt to the EC SCI to let the lid work.

The original commit showed spurious activity on Lenovo systems:
* On both Lenovo T14 and P14s the keyboard wakeup doesn't work, and
sometimes the power button event doesn't work.

This was confirmed on my end at that time.

However further development in the kernel showed that the issue was
actually the IRQ for the GPIO controller was also shared with the EC SCI.
This was actually fixed by commit 2d54067fcd23 ("pinctrl: amd: Fix
wakeups when IRQ is shared with SCI").

The original commit also showed problems with AC adapter:
* On HP 635 G7 detaching or attaching AC during suspend will cause
the system not to wakeup
* On Asus vivobook to prevent detaching AC causing resume problems
* On Lenovo 14ARE05 to prevent detaching AC causing resume problems
* On HP ENVY x360 to prevent detaching AC causing resume problems

Detaching AC adapter causing problems appears to have been a problem
because the EC SCI went off to notify the OS of the power adapter change
but the SCI was ignored and there was no other way to wake up this system
since GPIO controller wasn't properly enabled. The wakeups were fixed by
enabling the GPIO controller in commit acd47b9f28e5 ("pinctrl: amd: Handle
wake-up interrupt").

I've confirmed on a variety of OEM notebooks with the following test

1) echo 1 | sudo tee /sys/power/pm_debug_messages
2) sudo systemctl suspend
3) unplug AC adapter, make sure system is still asleep
4) wake system from lid (which is provided by ACPI SCI on some of them)
5) dmesg
a) see the EC GPE dispatched, timekeeping for X seconds (matching ~time
until AC adapter plug out)
b) see timekeeping for Y seconds until woke (matching ~time from AC
adapter until lid event)
6) Look at /sys/kernel/debug/amd_pmc/s0ix_stats
"Time (in us) in S0i3" = X + Y - firmware processing time

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 99ece713 03-Dec-2021 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: Use acpi_fetch_acpi_dev() instead of acpi_bus_get_device()

Modify the ACPI code to use acpi_fetch_acpi_dev() instead of
acpi_bus_get_device() where applicable.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>


# 1ea1dbf1 01-Oct-2021 Sachi King <nakato@nakato.io>

ACPI: PM: Include alternate AMDI0005 id in special behaviour

The Surface Laptop 4 AMD has used the AMD0005 to identify this
controller instead of using the appropriate ACPI ID AMDI0005. The
AMD0005 needs the same special casing as AMDI0005.

Link: https://github.com/linux-surface/acpidumps/tree/master/surface_laptop_4_amd
Link: https://gist.github.com/nakato/2a1a7df1a45fe680d7a08c583e1bf863
Signed-off-by: Sachi King <nakato@nakato.io>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Cc: 5.14+ <stable@vger.kernel.org> # 5.14+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# fa209644 01-Sep-2021 Mario Limonciello <mario.limonciello@amd.com>

ACPI: PM: s2idle: Run both AMD and Microsoft methods if both are supported

It was reported that on "HP ENVY x360" that power LED does not come
back, certain keys like brightness controls do not work, and the fan
never spins up, even under load on 5.14 final.

In analysis of the SSDT it's clear that the Microsoft UUID doesn't
provide functional support, but rather the AMD UUID should be
supporting this system.

Because this is a gap in the expected logic, we checked back with
internal team. The conclusion was that on Windows AMD uPEP *does*
run even when Microsoft UUID present, but most OEM systems have
adopted value of "0x3" for supported functions and hence nothing
runs.

Henceforth add support for running both Microsoft and AMD methods.
This approach will also allow the same logic on Intel systems if
desired at a future time as well by pulling the evaluation of
`lps0_dsm_func_mask_microsoft` out of the `if` block for
`acpi_s2idle_vendor_amd`.

Link: https://gitlab.freedesktop.org/drm/amd/uploads/9fbcd7ec3a385cc6949c9bacf45dc41b/acpi-f.20.bin
BugLink: https://gitlab.freedesktop.org/drm/amd/-/issues/1691
Reported-by: Maxwell Beck <max@ryt.one>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
[ rjw: Edits of the new comments ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 4753b46e 09-Aug-2021 Mario Limonciello <mario.limonciello@amd.com>

ACPI: PM: s2idle: Invert Microsoft UUID entry and exit

It was reported by a user with a Dell m15 R5 (5800H) that
the keyboard backlight was turning on when entering suspend
and turning off when exiting (the opposite of how it should be).

The user bisected it back to commit 5dbf50997578 ("ACPI: PM:
s2idle: Add support for new Microsoft UUID"). Previous to that
commit the LEDs didn't turn off at all. Confirming in the spec,
these were reversed when introduced.

Fix them to match the spec.

BugLink: https://gitlab.freedesktop.org/drm/amd/-/issues/1230#note_1021836
Fixes: 5dbf50997578 ("ACPI: PM: s2idle: Add support for new Microsoft UUID")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# f0c62255 17-Jul-2021 Mario Limonciello <mario.limonciello@amd.com>

ACPI: PM: Add support for upcoming AMD uPEP HID AMDI007

AMD systems with uPEP HID AMDI007 should be using revision 2 and
the AMD method.

Fixes: 8fbd6c15ea0a ("ACPI: PM: Adjust behavior for field problems on AMD systems")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 7b167c4c 30-Jun-2021 Mario Limonciello <mario.limonciello@amd.com>

ACPI: PM: Only mark EC GPE for wakeup on Intel systems

When using s2idle on a variety of AMD notebook systems, they are
experiencing spurious events that the EC or SMU are in the wrong
state leading to a hard time waking up or higher than expected
power consumption.

These events only occur when the EC GPE is inadvertently set as a wakeup
source. Originally the EC GPE was only set as a wakeup source when using
the intel-vbtn or intel-hid drivers in commit 10a08fd65ec1 ("ACPI: PM:
Set up EC GPE for system wakeup from drivers that need it") but during
testing a reporter discovered that this was not enough for their ASUS
Zenbook UX430UNR/i7-8550U to wakeup by lid event or keypress.
Marking the EC GPE for wakeup universally resolved this for that
reporter in commit b90ff3554aa3 ("ACPI: PM: s2idle: Always set up EC GPE
for system wakeup").

However this behavior has lead to a number of problems:

* On both Lenovo T14 and P14s the keyboard wakeup doesn't work, and
sometimes the power button event doesn't work.
* On HP 635 G7 detaching or attaching AC during suspend will cause
the system not to wakeup
* On Asus vivobook to prevent detaching AC causing resume problems
* On Lenovo 14ARE05 to prevent detaching AC causing resume problems
* On HP ENVY x360 to prevent detaching AC causing resume problems

As there may be other Intel systems besides ASUS Zenbook UX430UNR/i7-8550U
that don't use intel-vbtn or intel-hid, avoid these problems by only
universally marking the EC GPE wakesource on non-AMD systems.

Link: https://patchwork.kernel.org/project/linux-pm/cover/5997740.FPbUVk04hV@kreacher/#22825489
Link: https://gitlab.freedesktop.org/drm/amd/-/issues/1230
Link: https://gitlab.freedesktop.org/drm/amd/-/issues/1629
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 8fbd6c15 17-Jun-2021 Mario Limonciello <mario.limonciello@amd.com>

ACPI: PM: Adjust behavior for field problems on AMD systems

Some AMD Systems with uPEP _HID AMD004/AMDI005 have an off by one bug
in their function mask return. This means that they will call entrance
but not exit for matching functions.

Other AMD systems with this HID should use the Microsoft generic UUID.

AMD systems with uPEP HID AMDI006 should be using the Microsoft method.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Tested-by: Julian Sikorski <belegdol@gmail.com>
Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 5dbf5099 17-Jun-2021 Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>

ACPI: PM: s2idle: Add support for new Microsoft UUID

This adds supports for _DSM notifications to the Microsoft UUID
described by Microsoft documentation for s2idle.

Link: https://docs.microsoft.com/en-us/windows-hardware/design/device-experiences/modern-standby-firmware-notifications
Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>
Tested-by: Julian Sikorski <belegdol@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 3f4b116c 17-Jun-2021 Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>

ACPI: PM: s2idle: Add support for multiple func mask

Required for follow-up patch adding new UUID needing new function
mask.

Signed-off-by: Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>
Tested-by: Julian Sikorski <belegdol@gmail.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 4a012dc8 17-Jun-2021 Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>

ACPI: PM: s2idle: Refactor common code

Refactor common code to prepare for upcoming changes.
* Remove unused struct.
* Print error before returning.
* Frees ACPI obj if _DSM type is not as expected.
* Treat lps0_dsm_func_mask as an integer rather than character
* Remove extra out_obj
* Move rev_id

Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>
Tested-by: Julian Sikorski <belegdol@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# 904d4a6c 17-Jun-2021 Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>

ACPI: PM: s2idle: Use correct revision id

AMD spec mentions only revision 0. With this change,
device constraint list is populated properly.

Signed-off-by: Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>
Tested-by: Julian Sikorski <belegdol@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# f59a905b 05-May-2021 Alex Deucher <alexander.deucher@amd.com>

ACPI: PM: s2idle: Add missing LPS0 functions for AMD

These are supposedly not required for AMD platforms,
but at least some HP laptops seem to require it to
properly turn off the keyboard backlight.

Based on a patch from Marcin Bachry <hegel666@gmail.com>.

Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1230
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# aa7a1bb0 05-Jan-2021 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: PM: s2idle: Drop unused local variables and related code

Two local variables in drivers/acpi/x86/s2idle.c are never read, so
drop them along with the code updating their values (in vain).

Fixes: fef98671194b ("ACPI: PM: s2idle: Move x86-specific code to the x86 directory")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


# fef98671 17-Dec-2020 Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: PM: s2idle: Move x86-specific code to the x86 directory

Some code in drivers/acpi/sleep.c (which is regarded as a generic
file) related to suspend-to-idle support has grown direct dependencies
on x86, but in fact it has been specific to x86 (which is the only
user of it) anyway for a long time.

For this reason, move that code to a separate file under acpi/x86/
and make it build and run as before under the right conditions.

While at it, rename a vendor checking function in that code and
consistently use acpi_handle_debug() for printing debug-related
information in it.

No expected functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>