lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250113-platform_profile-v4-4-23be0dff19f1@gmail.com>
Date: Mon, 13 Jan 2025 18:44:12 +0530
From: Hridesh MG <hridesh699@...il.com>
To: Hans de Goede <hdegoede@...hat.com>, 
 Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>, 
 Armin Wolf <W_Armin@....de>, Kurt Borja <kuurtb@...il.com>
Cc: platform-driver-x86@...r.kernel.org, linux-kernel@...r.kernel.org, 
 Shuah Khan <skhan@...uxfoundation.org>, Hridesh MG <hridesh699@...il.com>
Subject: [PATCH v4 4/5] platform/x86: acer-wmi: use an ACPI bitmap to set
 the platform profile choices

Currently the choices for the platform profile are hardcoded. There is
an ACPI bitmap accessible via WMI that specifies the supported profiles,
use this bitmap to dynamically set the choices for the platform profile.

Link: https://lore.kernel.org/platform-driver-x86/ecb60ee5-3df7-4d7e-8ebf-8c162b339ade@gmx.de/
Signed-off-by: Hridesh MG <hridesh699@...il.com>
---
 drivers/platform/x86/acer-wmi.c | 67 ++++++++++++++++++++++++++++++++---------
 1 file changed, 52 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index 88416c37eca0af2099b0c8d91b38912a4e5d108f..37f8c2019925391185e1e0952dac563daf923320 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -33,6 +33,7 @@
 #include <linux/units.h>
 #include <linux/unaligned.h>
 #include <linux/bitfield.h>
+#include <linux/bitmap.h>
 
 MODULE_AUTHOR("Carlos Corbacho");
 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
@@ -127,6 +128,7 @@ enum acer_wmi_predator_v4_oc {
 enum acer_wmi_gaming_misc_setting {
 	ACER_WMID_MISC_SETTING_OC_1			= 0x0005,
 	ACER_WMID_MISC_SETTING_OC_2			= 0x0007,
+	ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES	= 0x000A,
 	ACER_WMID_MISC_SETTING_PLATFORM_PROFILE		= 0x000B,
 };
 
@@ -766,6 +768,9 @@ static bool platform_profile_support;
  */
 static int last_non_turbo_profile;
 
+/* The most performant supported profile */
+static int acer_predator_v4_max_perf;
+
 enum acer_predator_v4_thermal_profile {
 	ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET		= 0x00,
 	ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED	= 0x01,
@@ -1983,7 +1988,7 @@ acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,
 	if (err)
 		return err;
 
-	if (tp != ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO)
+	if (tp != acer_predator_v4_max_perf)
 		last_non_turbo_profile = tp;
 
 	return 0;
@@ -1992,6 +1997,7 @@ acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,
 static int acer_platform_profile_setup(struct platform_device *device)
 {
 	if (quirks->predator_v4) {
+		unsigned long supported_profiles;
 		int err;
 
 		platform_profile_handler.name = "acer-wmi";
@@ -2001,16 +2007,46 @@ static int acer_platform_profile_setup(struct platform_device *device)
 		platform_profile_handler.profile_set =
 			acer_predator_v4_platform_profile_set;
 
-		set_bit(PLATFORM_PROFILE_PERFORMANCE,
-			platform_profile_handler.choices);
-		set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE,
-			platform_profile_handler.choices);
-		set_bit(PLATFORM_PROFILE_BALANCED,
-			platform_profile_handler.choices);
-		set_bit(PLATFORM_PROFILE_QUIET,
-			platform_profile_handler.choices);
-		set_bit(PLATFORM_PROFILE_LOW_POWER,
-			platform_profile_handler.choices);
+		err = WMID_gaming_get_misc_setting(ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES,
+						   (u8 *)&supported_profiles);
+		if (err)
+			return err;
+
+		/* Iterate through supported profiles in order of increasing performance */
+		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_ECO, &supported_profiles)) {
+			set_bit(PLATFORM_PROFILE_LOW_POWER,
+				platform_profile_handler.choices);
+			acer_predator_v4_max_perf =
+				ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
+		}
+
+		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET, &supported_profiles)) {
+			set_bit(PLATFORM_PROFILE_QUIET,
+				platform_profile_handler.choices);
+			acer_predator_v4_max_perf =
+				ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
+		}
+
+		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED, &supported_profiles)) {
+			set_bit(PLATFORM_PROFILE_BALANCED,
+				platform_profile_handler.choices);
+			acer_predator_v4_max_perf =
+				ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
+		}
+
+		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE, &supported_profiles)) {
+			set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE,
+				platform_profile_handler.choices);
+			acer_predator_v4_max_perf =
+				ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
+		}
+
+		if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO, &supported_profiles)) {
+			set_bit(PLATFORM_PROFILE_PERFORMANCE,
+				platform_profile_handler.choices);
+			acer_predator_v4_max_perf =
+				ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
+		}
 
 		err = platform_profile_register(&platform_profile_handler);
 		if (err)
@@ -2028,7 +2064,8 @@ static int acer_platform_profile_setup(struct platform_device *device)
 static int acer_thermal_profile_change(void)
 {
 	/*
-	 * This mode key will either cycle through each mode or toggle the turbo profile.
+	 * This mode key will either cycle through each mode or toggle the
+	 * most performant profile.
 	 */
 	if (quirks->predator_v4) {
 		u8 current_tp;
@@ -2042,10 +2079,10 @@ static int acer_thermal_profile_change(void)
 			if (err)
 				return err;
 
-			if (current_tp == ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO)
+			if (current_tp == acer_predator_v4_max_perf)
 				tp = last_non_turbo_profile;
 			else
-				tp = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
+				tp = acer_predator_v4_max_perf;
 
 			err = WMID_gaming_set_misc_setting(
 				ACER_WMID_MISC_SETTING_PLATFORM_PROFILE, tp);
@@ -2053,7 +2090,7 @@ static int acer_thermal_profile_change(void)
 				return err;
 
 			/* Store last profile for toggle */
-			if (current_tp != ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO)
+			if (current_tp != acer_predator_v4_max_perf)
 				last_non_turbo_profile = current_tp;
 
 			platform_profile_notify(&platform_profile_handler);

-- 
2.47.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ