Skip to content

Commit

Permalink
Sync to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
uejji committed Aug 26, 2024
2 parents 2c44b7d + c31f07b commit aea1aa3
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 1 deletion.
73 changes: 73 additions & 0 deletions PKGBUILD/linux/0053-add-support-for-screen-off-and-screen-on.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
From 8ca27ffa9b97e14cf771c5d1c887072e30bdb268 Mon Sep 17 00:00:00 2001
From: Mario Limonciello <mario.limonciello@amd.com>
Date: Wed, 14 Aug 2024 12:50:25 -0500
Subject: [PATCH] acpi/x86: s2idle: add support for screen off and screen on
callbacks

All the _DSM methods for the LPS0 method are called back to back
currently. The intended use of the screen off and screen on calls is
supposed to be matching the screen being turned on or off though.
Add support for other parts of the kernel to call such a callback.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
include/linux/suspend.h | 8 ++++++++
kernel/power/suspend.c | 12 ++++++++++++
2 files changed, 20 insertions(+)

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index da6ebca3ff774c..4535ae82363c1f 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -133,6 +133,8 @@ struct platform_suspend_ops {

struct platform_s2idle_ops {
int (*begin)(void);
+ int (*screen_off)(void);
+ int (*screen_on)(void);
int (*prepare)(void);
int (*prepare_late)(void);
void (*check)(void);
@@ -160,6 +162,9 @@ extern unsigned int pm_suspend_global_flags;
#define PM_SUSPEND_FLAG_FW_RESUME BIT(1)
#define PM_SUSPEND_FLAG_NO_PLATFORM BIT(2)

+int platform_suspend_screen_off(void);
+int platform_suspend_screen_on(void);
+
static inline void pm_suspend_clear_flags(void)
{
pm_suspend_global_flags = 0;
@@ -296,6 +301,9 @@ static inline bool idle_should_enter_s2idle(void) { return false; }
static inline void __init pm_states_init(void) {}
static inline void s2idle_set_ops(const struct platform_s2idle_ops *ops) {}
static inline void s2idle_wake(void) {}
+static inline int platform_suspend_screen_off(void) { return -ENODEV };
+static inline int platform_suspend_screen_on(void) { return -ENODEV };
+
#endif /* !CONFIG_SUSPEND */

/* struct pbe is used for creating lists of pages that should be restored
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 09f8397bae15fb..19734b297527c2 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -254,6 +254,18 @@ static bool sleep_state_supported(suspend_state_t state)
(valid_state(state) && !cxl_mem_active());
}

+int platform_suspend_screen_off(void)
+{
+ return s2idle_ops && s2idle_ops->screen_off ? s2idle_ops->screen_off() : 0;
+}
+EXPORT_SYMBOL_GPL(platform_suspend_screen_off);
+
+int platform_suspend_screen_on(void)
+{
+ return s2idle_ops && s2idle_ops->screen_on ? s2idle_ops->screen_on() : 0;
+}
+EXPORT_SYMBOL_GPL(platform_suspend_screen_on);
+
static int platform_suspend_prepare(suspend_state_t state)
{
return state != PM_SUSPEND_TO_IDLE && suspend_ops->prepare ?
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
From 85bbc00e7ffdb0a799f4ce8f4a4fa8fb560d3046 Mon Sep 17 00:00:00 2001
From: Mario Limonciello <mario.limonciello@amd.com>
Date: Wed, 14 Aug 2024 20:19:09 -0500
Subject: [PATCH] drm: Notify the suspend core when displays are changed at
suspend

This allows notifying the BIOS with the LPS0 _DSM for "Screen off"
and "Screen on".

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/gpu/drm/drm_atomic_helper.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 39ef0a6addeba8..8afabbfe4c1b6f 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -27,6 +27,7 @@

#include <linux/dma-fence.h>
#include <linux/ktime.h>
+#include <linux/suspend.h>

#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
@@ -3526,6 +3527,13 @@ struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev)
goto unlock;
}

+ err = platform_suspend_screen_off();
+ if (err < 0) {
+ drm_atomic_state_put(state);
+ state = ERR_PTR(err);
+ goto unlock;
+ }
+
unlock:
DRM_MODESET_LOCK_ALL_END(dev, ctx, err);
if (err)
@@ -3607,7 +3615,12 @@ int drm_atomic_helper_resume(struct drm_device *dev,
DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err);

err = drm_atomic_helper_commit_duplicated_state(state, &ctx);
+ if (err < 0)
+ goto unlock;

+ err = platform_suspend_screen_on();
+
+unlock:
DRM_MODESET_LOCK_ALL_END(dev, ctx, err);
drm_atomic_state_put(state);

123 changes: 123 additions & 0 deletions PKGBUILD/linux/0055-Move-screen-off_on-code-into-dedicated.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
From 9217190b15982ba259576eb0a605f806113b1f50 Mon Sep 17 00:00:00 2001
From: Mario Limonciello <mario.limonciello@amd.com>
Date: Wed, 14 Aug 2024 20:20:13 -0500
Subject: [PATCH] acpi/x86: s2idle: Move screen off/on code into dedicated
callbacks

This lets the DRM core notify on screen events instead of calling
them back to back.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/acpi/x86/s2idle.c | 75 ++++++++++++++++++++++++++++++---------
1 file changed, 59 insertions(+), 16 deletions(-)

diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c
index dd0b40b9bbe8be..e7f9748937d68e 100644
--- a/drivers/acpi/x86/s2idle.c
+++ b/drivers/acpi/x86/s2idle.c
@@ -539,17 +539,21 @@ static struct acpi_scan_handler lps0_handler = {
.attach = lps0_device_attach,
};

-int acpi_s2idle_prepare_late(void)
+static int acpi_s2idle_screen_off(void)
{
- struct acpi_s2idle_dev_ops *handler;
-
if (!lps0_device_handle || sleep_no_lps0)
return 0;

- if (pm_debug_messages_on)
- lpi_check_constraints();
+ switch (lps0_dsm_state) {
+ case ACPI_LPS0_SCREEN_OFF_AMD:
+ case ACPI_LPS0_SCREEN_OFF:
+ if (pm_debug_messages_on)
+ acpi_handle_info(lps0_device_handle,
+ "already in %s\n",
+ acpi_sleep_dsm_state_to_str(lps0_dsm_state));
+ return 0;
+ }

- /* Screen off */
if (lps0_dsm_func_mask > 0)
acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ?
ACPI_LPS0_SCREEN_OFF_AMD :
@@ -560,6 +564,47 @@ int acpi_s2idle_prepare_late(void)
acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_OFF,
lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);

+ return 0;
+}
+
+static int acpi_s2idle_screen_on(void)
+{
+ if (!lps0_device_handle || sleep_no_lps0)
+ return 0;
+
+ switch (lps0_dsm_state) {
+ case ACPI_LPS0_SCREEN_ON_AMD:
+ case ACPI_LPS0_SCREEN_ON:
+ if (pm_debug_messages_on)
+ acpi_handle_info(lps0_device_handle,
+ "already in %s\n",
+ acpi_sleep_dsm_state_to_str(lps0_dsm_state));
+ return 0;
+ }
+
+ if (lps0_dsm_func_mask_microsoft > 0)
+ acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_ON,
+ lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
+
+ if (lps0_dsm_func_mask > 0)
+ acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ?
+ ACPI_LPS0_SCREEN_ON_AMD :
+ ACPI_LPS0_SCREEN_ON,
+ lps0_dsm_func_mask, lps0_dsm_guid);
+
+ return 0;
+}
+
+int acpi_s2idle_prepare_late(void)
+{
+ struct acpi_s2idle_dev_ops *handler;
+
+ if (!lps0_device_handle || sleep_no_lps0)
+ return 0;
+
+ if (pm_debug_messages_on)
+ lpi_check_constraints();
+
/* LPS0 entry */
if (lps0_dsm_func_mask > 0 && acpi_s2idle_vendor_amd())
acpi_sleep_run_lps0_dsm(ACPI_LPS0_ENTRY_AMD,
@@ -623,20 +668,18 @@ void acpi_s2idle_restore_early(void)
acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,
lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
}
+}

- /* Screen on */
- if (lps0_dsm_func_mask_microsoft > 0)
- acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_ON,
- lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
- if (lps0_dsm_func_mask > 0)
- acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ?
- ACPI_LPS0_SCREEN_ON_AMD :
- ACPI_LPS0_SCREEN_ON,
- lps0_dsm_func_mask, lps0_dsm_guid);
+static int acpi_x86_s2idle_begin(void)
+{
+ lps0_dsm_state = -1;
+ return acpi_s2idle_begin();
}

static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = {
- .begin = acpi_s2idle_begin,
+ .begin = acpi_x86_s2idle_begin,
+ .screen_off = acpi_s2idle_screen_off,
+ .screen_on = acpi_s2idle_screen_on,
.prepare = acpi_s2idle_prepare,
.prepare_late = acpi_s2idle_prepare_late,
.check = acpi_s2idle_check,
8 changes: 7 additions & 1 deletion PKGBUILD/linux/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

pkgbase=linux
pkgver=6.10.6
pkgrel=2.1
pkgrel=3.1
pkgdesc="Linux Stable"
arch=(x86_64)
url="https://kernel.org/"
Expand Down Expand Up @@ -56,6 +56,9 @@ source=(
0050-AMD-Pstate-Core-Performance-Boost.patch
0051-drm-amd-display-let-update_planes_and_stream_state-d.patch
0052-asus-armoury-support.patch
0053-add-support-for-screen-off-and-screen-on.patch
0054-Notify-the-suspend-core-when-displays-are-changed-at.patch
0055-Move-screen-off_on-code-into-dedicated.patch
0098-add-ally-and-armoury-drivers.patch
0099-add-ayaneo-and-ayn-platform-drivers.patch
)
Expand Down Expand Up @@ -85,6 +88,9 @@ sha256sums=('SKIP'
'c6ff653b1e55c5524b237a40683a34240d4ec7b95e524441ed3ae09ed885f674' # 0050-AMD-Pstate-Core-Performance-Boost.patch
'7c7df8d4427c807e2cea0f1e147efcdfb1e7c1c5271823cc6bb49f10b1846d19' # 0051-drm-amd-display-let-update_planes_and_stream_state-d.patch
'543bf5b9cd779a6f89845bf160aee1a2594c5df0ad4fd2f7f975920a99ad082f' # 0052-asus-armoury-support.patch
'a8e3c0f7a3cdcc82a12a5dc44772263c2dd7bc3207f16b98dac42e0e74184172' # 0053-add-support-for-screen-off-and-screen-on.patch
'abf7ddb74fa9eb0cfdbe81dba7bf4003e5d85ac1a4e1f2b5333ab97986c3e68e' # 0054-Notify-the-suspend-core-when-displays-are-changed-at.patch
'713653bbb8d96eba905d87864989ca2ee0363efbcdf8217121924f538be2adc8' # 0055-Move-screen-off_on-code-into-dedicated.patch
'd60a3cb38b99873937a0c4e3df4a969a7bfb25ed298ee2824b56081353f90d8d' # 0098-add-ally-and-armoury-drivers.patch
'bd570655bb7df92472ad8e9c823b23112bd142f394d20f26097a279f66f0634b' # 0099-add-ayaneo-and-ayn-platform-drivers.patch
)
Expand Down

0 comments on commit aea1aa3

Please sign in to comment.