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: <8f49e3a9-e9ce-44d4-8d9a-4447202f2b61@gmx.de>
Date: Sun, 20 Oct 2024 22:12:48 +0200
From: Armin Wolf <W_Armin@....de>
To: Kurt Borja <kuurtb@...il.com>
Cc: hdegoede@...hat.com, ilpo.jarvinen@...ux.intel.com,
 linux-kernel@...r.kernel.org, platform-driver-x86@...r.kernel.org
Subject: Re: [PATCH v6 3/5] alienware-wmi: added platform profile support

Am 17.10.24 um 10:15 schrieb Kurt Borja:

> Implements platform profile support for Dell laptops with new WMAX
> thermal interface, present on some Alienware X-Series, Alienware
> M-Series and Dell's G-Series laptops.
>
> This implementation supports three sets of thermal tables declared in
> enum WMAX_THERMAL_TABLE and gmode, using quirks *thermal* and *gmode*
> respectively. These sets are found in most Dell's devices that support
> WMAX's thermal interface.
>
> Signed-off-by: Kurt Borja <kuurtb@...il.com>
>
> ---
> v6:
>   - Fixed alignment on some function definitions
>   - Fixed braces on if statment
>   - Removed quirk thermal_ustt
>   - Now quirk thermal can take values defined in enum WMAX_THERMAL_TABLE.
>   - Proper removal of thermal_profile
> ---
>   drivers/platform/x86/dell/Kconfig         |   1 +
>   drivers/platform/x86/dell/alienware-wmi.c | 251 ++++++++++++++++++++++
>   2 files changed, 252 insertions(+)
>
> diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig
> index 68a49788a..b06d634cd 100644
> --- a/drivers/platform/x86/dell/Kconfig
> +++ b/drivers/platform/x86/dell/Kconfig
> @@ -21,6 +21,7 @@ config ALIENWARE_WMI
>   	depends on LEDS_CLASS
>   	depends on NEW_LEDS
>   	depends on ACPI_WMI
> +	select ACPI_PLATFORM_PROFILE
>   	help
>   	 This is a driver for controlling Alienware BIOS driven
>   	 features.  It exposes an interface for controlling the AlienFX
> diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c
> index b27f3b64c..37a898273 100644
> --- a/drivers/platform/x86/dell/alienware-wmi.c
> +++ b/drivers/platform/x86/dell/alienware-wmi.c
> @@ -8,8 +8,11 @@
>   #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
>   #include <linux/acpi.h>
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
>   #include <linux/module.h>
>   #include <linux/platform_device.h>
> +#include <linux/platform_profile.h>
>   #include <linux/dmi.h>
>   #include <linux/leds.h>
>
> @@ -25,6 +28,12 @@
>   #define WMAX_METHOD_AMPLIFIER_CABLE	0x6
>   #define WMAX_METHOD_DEEP_SLEEP_CONTROL	0x0B
>   #define WMAX_METHOD_DEEP_SLEEP_STATUS	0x0C
> +#define WMAX_METHOD_THERMAL_INFORMATION	0x14
> +#define WMAX_METHOD_THERMAL_CONTROL	0x15
> +
> +#define WMAX_ARG_GET_CURRENT_PROF	0x0B
> +
> +#define WMAX_FAILURE_CODE		0xFFFFFFFF
>
>   MODULE_AUTHOR("Mario Limonciello <mario.limonciello@...look.com>");
>   MODULE_DESCRIPTION("Alienware special feature control");
> @@ -49,11 +58,33 @@ enum WMAX_CONTROL_STATES {
>   	WMAX_SUSPEND = 3,
>   };
>
> +enum WMAX_THERMAL_TABLE {
> +	WMAX_THERMAL_TABLE_SIMPLE	= 1,
> +	WMAX_THERMAL_TABLE_USTT		= 2,
> +	WMAX_THERMAL_TABLE_USTT_COOL	= 3,
> +};
> +
> +enum WMAX_THERMAL_PROFILE {
> +	WMAX_THERMAL_QUIET			= 0x96,
> +	WMAX_THERMAL_BALANCED			= 0x97,
> +	WMAX_THERMAL_BALANCED_PERFORMANCE	= 0x98,
> +	WMAX_THERMAL_PERFORMANCE		= 0x99,
> +	WMAX_THERMAL_USTT_LOW_POWER		= 0xA5,
> +	WMAX_THERMAL_USTT_COOL			= 0xA2,
> +	WMAX_THERMAL_USTT_QUIET			= 0xA3,
> +	WMAX_THERMAL_USTT_BALANCED		= 0xA0,
> +	WMAX_THERMAL_USTT_BALANCED_PERFORMANCE	= 0xA1,
> +	WMAX_THERMAL_USTT_PERFORMANCE		= 0xA4,
> +	WMAX_THERMAL_GMODE			= 0xAB,
> +};
> +
>   struct quirk_entry {
>   	u8 num_zones;
>   	u8 hdmi_mux;
>   	u8 amplifier;
>   	u8 deepslp;
> +	u8 thermal;
> +	u8 gmode;
>   };
>
>   static struct quirk_entry *quirks;
> @@ -64,6 +95,8 @@ static struct quirk_entry quirk_inspiron5675 = {
>   	.hdmi_mux = 0,
>   	.amplifier = 0,
>   	.deepslp = 0,
> +	.thermal = 0,
> +	.gmode = 0,
>   };
>
>   static struct quirk_entry quirk_unknown = {
> @@ -71,6 +104,8 @@ static struct quirk_entry quirk_unknown = {
>   	.hdmi_mux = 0,
>   	.amplifier = 0,
>   	.deepslp = 0,
> +	.thermal = 0,
> +	.gmode = 0,
>   };
>
>   static struct quirk_entry quirk_x51_r1_r2 = {
> @@ -78,6 +113,8 @@ static struct quirk_entry quirk_x51_r1_r2 = {
>   	.hdmi_mux = 0,
>   	.amplifier = 0,
>   	.deepslp = 0,
> +	.thermal = 0,
> +	.gmode = 0,
>   };
>
>   static struct quirk_entry quirk_x51_r3 = {
> @@ -85,6 +122,8 @@ static struct quirk_entry quirk_x51_r3 = {
>   	.hdmi_mux = 0,
>   	.amplifier = 1,
>   	.deepslp = 0,
> +	.thermal = 0,
> +	.gmode = 0,
>   };
>
>   static struct quirk_entry quirk_asm100 = {
> @@ -92,6 +131,8 @@ static struct quirk_entry quirk_asm100 = {
>   	.hdmi_mux = 1,
>   	.amplifier = 0,
>   	.deepslp = 0,
> +	.thermal = 0,
> +	.gmode = 0,
>   };
>
>   static struct quirk_entry quirk_asm200 = {
> @@ -99,6 +140,8 @@ static struct quirk_entry quirk_asm200 = {
>   	.hdmi_mux = 1,
>   	.amplifier = 0,
>   	.deepslp = 1,
> +	.thermal = 0,
> +	.gmode = 0,
>   };
>
>   static struct quirk_entry quirk_asm201 = {
> @@ -106,6 +149,17 @@ static struct quirk_entry quirk_asm201 = {
>   	.hdmi_mux = 1,
>   	.amplifier = 1,
>   	.deepslp = 1,
> +	.thermal = 0,
> +	.gmode = 0,
> +};
> +
> +static struct quirk_entry quirk_x15_r1 = {
> +	.num_zones = 2,
> +	.hdmi_mux = 0,
> +	.amplifier = 0,
> +	.deepslp = 0,
> +	.thermal = WMAX_THERMAL_TABLE_USTT,
> +	.gmode = 0,
>   };
>
>   static int __init dmi_matched(const struct dmi_system_id *dmi)
> @@ -169,6 +223,15 @@ static const struct dmi_system_id alienware_quirks[] __initconst = {
>   		},
>   		.driver_data = &quirk_asm201,
>   	},
> +	{
> +		.callback = dmi_matched,
> +		.ident = "Alienware x15 R1",
> +		.matches = {
> +			DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
> +			DMI_MATCH(DMI_PRODUCT_NAME, "Alienware x15 R1")
> +		},
> +		.driver_data = &quirk_x15_r1,
> +	},
>   	{
>   		.callback = dmi_matched,
>   		.ident = "Dell Inc. Inspiron 5675",
> @@ -218,6 +281,7 @@ static struct platform_device *platform_device;
>   static struct device_attribute *zone_dev_attrs;
>   static struct attribute **zone_attrs;
>   static struct platform_zone *zone_data;
> +static struct platform_profile_handler pp_handler;
>
>   static struct platform_driver platform_driver = {
>   	.driver = {
> @@ -761,6 +825,184 @@ static int create_deepsleep(struct platform_device *dev)
>   	return ret;
>   }
>
> +/*
> + * Thermal Profile control
> + *  - Provides thermal profile control through the Platform Profile API
> + */
> +#define WMAX_ARGUMENT_MASK	GENMASK(15, 8)
> +#define WMAX_PROFILE_ACTIVATE	0x01
> +
> +static u32 profile_to_wmax_arg(enum WMAX_THERMAL_PROFILE prof)
> +{
> +	return FIELD_PREP(WMAX_ARGUMENT_MASK, prof) | WMAX_PROFILE_ACTIVATE;
> +}
> +
> +static int thermal_profile_get(struct platform_profile_handler *pprof,
> +			       enum platform_profile_option *profile)
> +{
> +	acpi_status status;
> +	u32 in_args = WMAX_ARG_GET_CURRENT_PROF;
> +	u32 out_data;
> +
> +	status = alienware_wmax_command(&in_args, sizeof(in_args),
> +					WMAX_METHOD_THERMAL_INFORMATION, &out_data);
> +
> +	if (ACPI_FAILURE(status))
> +		return -EIO;
> +
> +	if (out_data == WMAX_FAILURE_CODE)
> +		return -EBADRQC;
> +
> +	switch (out_data) {
> +	case WMAX_THERMAL_USTT_LOW_POWER:
> +		*profile = PLATFORM_PROFILE_LOW_POWER;
> +		break;
> +	case WMAX_THERMAL_USTT_COOL:
> +		*profile = PLATFORM_PROFILE_COOL;
> +		break;
> +	case WMAX_THERMAL_QUIET:
> +	case WMAX_THERMAL_USTT_QUIET:
> +		*profile = PLATFORM_PROFILE_QUIET;
> +		break;
> +	case WMAX_THERMAL_BALANCED:
> +	case WMAX_THERMAL_USTT_BALANCED:
> +		*profile = PLATFORM_PROFILE_BALANCED;
> +		break;
> +	case WMAX_THERMAL_BALANCED_PERFORMANCE:
> +	case WMAX_THERMAL_USTT_BALANCED_PERFORMANCE:
> +		*profile = PLATFORM_PROFILE_BALANCED_PERFORMANCE;
> +		break;
> +	case WMAX_THERMAL_GMODE:
> +	case WMAX_THERMAL_PERFORMANCE:
> +	case WMAX_THERMAL_USTT_PERFORMANCE:
> +		*profile = PLATFORM_PROFILE_PERFORMANCE;
> +		break;
> +	default:
> +		return -ENODATA;
> +	}
> +
> +	return 0;
> +}
> +
> +static int thermal_profile_set(struct platform_profile_handler *pprof,
> +			       enum platform_profile_option profile)
> +{
> +	acpi_status status;
> +	u32 in_args;
> +	u32 out_data;
> +
> +	switch (profile) {
> +	case PLATFORM_PROFILE_QUIET:
> +		in_args = profile_to_wmax_arg(WMAX_THERMAL_QUIET);
> +		break;
> +	case PLATFORM_PROFILE_BALANCED:
> +		in_args = profile_to_wmax_arg(WMAX_THERMAL_BALANCED);
> +		break;
> +	case PLATFORM_PROFILE_BALANCED_PERFORMANCE:
> +		in_args = profile_to_wmax_arg(WMAX_THERMAL_BALANCED_PERFORMANCE);
> +		break;
> +	case PLATFORM_PROFILE_PERFORMANCE:
> +		if (quirks->gmode > 0)
> +			in_args = profile_to_wmax_arg(WMAX_THERMAL_GMODE);
> +		else
> +			in_args = profile_to_wmax_arg(WMAX_THERMAL_PERFORMANCE);
> +		break;
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +
> +	status = alienware_wmax_command(&in_args, sizeof(in_args),
> +					WMAX_METHOD_THERMAL_CONTROL, &out_data);
> +
> +	if (ACPI_FAILURE(status))
> +		return -EIO;
> +
> +	if (out_data == WMAX_FAILURE_CODE)
> +		return -EBADRQC;
> +
> +	return 0;
> +}
> +
> +static int thermal_profile_set_ustt(struct platform_profile_handler *pprof,
> +				    enum platform_profile_option profile)
> +{
> +	acpi_status status;
> +	u32 in_args;
> +	u32 out_data;
> +
> +	switch (profile) {
> +	case PLATFORM_PROFILE_LOW_POWER:
> +		in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_LOW_POWER);
> +		break;
> +	case PLATFORM_PROFILE_COOL:
> +		in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_COOL);
> +		break;
> +	case PLATFORM_PROFILE_QUIET:
> +		in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_QUIET);
> +		break;
> +	case PLATFORM_PROFILE_BALANCED:
> +		in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_BALANCED);
> +		break;
> +	case PLATFORM_PROFILE_BALANCED_PERFORMANCE:
> +		in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_BALANCED_PERFORMANCE);
> +		break;
> +	case PLATFORM_PROFILE_PERFORMANCE:
> +		if (quirks->gmode > 0)
> +			in_args = profile_to_wmax_arg(WMAX_THERMAL_GMODE);
> +		else
> +			in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_PERFORMANCE);
> +		break;
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +
> +	status = alienware_wmax_command(&in_args, sizeof(in_args),
> +					WMAX_METHOD_THERMAL_CONTROL, &out_data);
> +
> +	if (ACPI_FAILURE(status))
> +		return -EIO;
> +
> +	if (out_data == WMAX_FAILURE_CODE)
> +		return -EBADRQC;
> +
> +	return 0;
> +}
> +
> +static int create_thermal_profile(void)
> +{
> +	pp_handler.profile_get = thermal_profile_get;
> +
> +	switch (quirks->thermal) {
> +	case WMAX_THERMAL_TABLE_SIMPLE:
> +		pp_handler.profile_set = thermal_profile_set;
> +		break;
> +	case WMAX_THERMAL_TABLE_USTT:
> +		pp_handler.profile_set = thermal_profile_set_ustt;
> +		set_bit(PLATFORM_PROFILE_LOW_POWER, pp_handler.choices);
> +		set_bit(PLATFORM_PROFILE_QUIET, pp_handler.choices);
> +		set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, pp_handler.choices);
> +		break;
> +	case WMAX_THERMAL_TABLE_USTT_COOL:
> +		pp_handler.profile_set = thermal_profile_set_ustt;
> +		set_bit(PLATFORM_PROFILE_LOW_POWER, pp_handler.choices);
> +		set_bit(PLATFORM_PROFILE_QUIET, pp_handler.choices);
> +		set_bit(PLATFORM_PROFILE_COOL, pp_handler.choices);
> +		set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, pp_handler.choices);
> +		break;
> +	}

Please add a default statement here to return -EINVAL just in case.

Other than that:

Reviewed-by: Armin Wolf <W_Armin@....de>

> +
> +	set_bit(PLATFORM_PROFILE_BALANCED, pp_handler.choices);
> +	set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices);
> +
> +	return platform_profile_register(&pp_handler);
> +}
> +
> +static void remove_thermal_profile(void)
> +{
> +	if (quirks->thermal > 0)
> +		platform_profile_remove();
> +}
> +
>   static int __init alienware_wmi_init(void)
>   {
>   	int ret;
> @@ -808,6 +1050,12 @@ static int __init alienware_wmi_init(void)
>   			goto fail_prep_deepsleep;
>   	}
>
> +	if (quirks->thermal > 0) {
> +		ret = create_thermal_profile();
> +		if (ret)
> +			goto fail_prep_thermal_profile;
> +	}
> +
>   	ret = alienware_zone_init(platform_device);
>   	if (ret)
>   		goto fail_prep_zones;
> @@ -816,6 +1064,8 @@ static int __init alienware_wmi_init(void)
>
>   fail_prep_zones:
>   	alienware_zone_exit(platform_device);
> +	remove_thermal_profile();
> +fail_prep_thermal_profile:
>   fail_prep_deepsleep:
>   fail_prep_amplifier:
>   fail_prep_hdmi:
> @@ -835,6 +1085,7 @@ static void __exit alienware_wmi_exit(void)
>   	if (platform_device) {
>   		alienware_zone_exit(platform_device);
>   		remove_hdmi(platform_device);
> +		remove_thermal_profile();
>   		platform_device_unregister(platform_device);
>   		platform_driver_unregister(&platform_driver);
>   	}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ