ACPI fan _DSM support
v3 cover ACPI fan _DSM support
Microsoft has designed a _DSM interface for the ACPI fan device [1] that allows the OS to set fan speed trip points. The ACPI firmware will notify the ACPI fan device when said trip points are triggered.
Unfortunately some device manufacturers (like HP) blindly assume that the OS will use this _DSM interface and thus only update the fan speed value returned by the _FST control method when sending a notification to the ACPI fan device. This results in stale fan speed values being reported by the ACPI fan driver [2].
The first two patches add support for the ACPI fan notifications as specified in ACPI 11.2.3. The last patch finally adds support for the Microsoft _DSM interface.
All patches where tested with a custom SSDT [3] and the acpi_call [4] kernel module and appear to work just fine.
[1] https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/design-guide
[2] https://github.com/lm-sensors/lm-sensors/issues/506
[3] https://github.com/Wer-Wolf/acpi-fan-ssdt/blob/master/ssdt-dsm.asl
[4] https://github.com/nix-community/acpi_call
Changes since v2:
- drop already merged patches
- add links to the MSFT documentation in patch 3
Changes since v1:
- use acpi_evaluate_dsm_typed() during _DSM initialization
- send ACPI netlink event when after handling a ACPI notification
Armin Wolf (3):
ACPI: fan: Add basic notification support
ACPI: fan: Add hwmon notification support
ACPI: fan: Add support for Microsoft fan extensions
drivers/acpi/fan.h | 7 ++ drivers/acpi/fan_core.c | 222 ++++++++++++++++++++++++++++++++++++++- drivers/acpi/fan_hwmon.c | 15 ++- 3 files changed, 239 insertions(+), 5 deletions(-)
Signature · 1 line
2.39.5
PATCH v3 1/3 ACPI: fan: Add basic notification support
The ACPI specification states that the platform firmware can notify the ACPI fan device that the fan speed has changed an that the _FST control method should be reevaluated. Add support for this mechanism to prepare for future changes.
--- drivers/acpi/fan_core.c | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
drivers/acpi/fan_core.c +50 -0
@@ -19,6 +19,8 @@#include "fan.h" +#define ACPI_FAN_NOTIFY_STATE_CHANGED 0x80 +static const struct acpi_device_id fan_device_ids[] = {ACPI_FAN_DEVICE_IDS , {"" ,0 },
@@ -308,6 +310,50 @@ static int acpi_fan_get_fps(struct acpi_device *device)return status; } +static void acpi_fan_notify_handler (acpi_handle handle,u32 event,void *context) +{ +struct device *dev = context; +struct acpi_fan_fst fst; +int ret; + +switch (event) { +case ACPI_FAN_NOTIFY_STATE_CHANGED : +/* +* The ACPI specification says that we must evaluate _FST when we +* receive an ACPI event indicating that the fan state has changed. +*/ + ret =acpi_fan_get_fst (handle, &fst); +if (ret <0 ) +dev_err (dev,"Error retrieving current fan status: %d\n" , ret); + +acpi_bus_generate_netlink_event ("fan" ,dev_name (dev), event,0 ); +break ; +default : +dev_dbg (dev,"Unsupported ACPI notification 0x%x\n" , event); +break ; + } +} + +static void acpi_fan_notify_remove (void *data) +{ +struct acpi_fan *fan = data; + +acpi_remove_notify_handler (fan->handle,ACPI_DEVICE_NOTIFY , acpi_fan_notify_handler); +} + +static int devm_acpi_fan_notify_init (struct device *dev) +{ +struct acpi_fan *fan =dev_get_drvdata (dev); +acpi_status status; + + status =acpi_install_notify_handler (fan->handle,ACPI_DEVICE_NOTIFY , + acpi_fan_notify_handler, dev); +if (ACPI_FAILURE (status)) +return -EIO ; + +return devm_add_action_or_reset (dev, acpi_fan_notify_remove, fan); +} +static int acpi_fan_probe (struct platform_device *pdev) {int result =0 ;
@@ -351,6 +397,10 @@ static int acpi_fan_probe(struct platform_device *pdev)if (result)return result; + result =devm_acpi_fan_notify_init (&pdev->dev); +if (result) +return result; + result =acpi_fan_create_attributes (device);if (result)return result;
Signature · 1 line
2.39.5
PATCH v3 2/3 ACPI: fan: Add hwmon notification support
In reply to Armin WolfThe platform firmware can notify the ACPI fan device that the fan speed has changed. Relay this notification to the hwmon device if present so that userspace applications can react to it.
--- drivers/acpi/fan.h | 5 +++++ drivers/acpi/fan_core.c | 1 + drivers/acpi/fan_hwmon.c | 15 +++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-)
drivers/acpi/fan.h +5 -0
@@ -56,6 +56,9 @@ struct acpi_fan {struct acpi_fan_fif fif;struct acpi_fan_fps *fps;int fps_count; +#if IS_REACHABLE (CONFIG_HWMON ) +struct device *hdev; +#endif struct thermal_cooling_device *cdev;struct device_attribute fst_speed;struct device_attribute fine_grain_control;
@@ -99,8 +102,10 @@ void acpi_fan_delete_attributes(struct acpi_device *device);#if IS_REACHABLE (CONFIG_HWMON )int devm_acpi_fan_create_hwmon (struct device *dev); +void acpi_fan_notify_hwmon (struct device *dev);#else static inline int devm_acpi_fan_create_hwmon (struct device *dev) {return 0 ; }; +static inline void acpi_fan_notify_hwmon (struct device *dev) { };#endif #endif
drivers/acpi/fan_core.c +1 -0
@@ -326,6 +326,7 @@ static void acpi_fan_notify_handler(acpi_handle handle, u32 event, void *contextif (ret <0 )dev_err (dev,"Error retrieving current fan status: %d\n" , ret); +acpi_fan_notify_hwmon (dev);acpi_bus_generate_netlink_event ("fan" ,dev_name (dev), event,0 );break ;default :
drivers/acpi/fan_hwmon.c +11 -4
@@ -162,12 +162,19 @@ static const struct hwmon_chip_info acpi_fan_hwmon_chip_info = { .info = acpi_fan_hwmon_info, }; +void acpi_fan_notify_hwmon (struct device *dev) +{ +struct acpi_fan *fan =dev_get_drvdata (dev); + +hwmon_notify_event (fan->hdev, hwmon_fan, hwmon_fan_input,0 ); +} +int devm_acpi_fan_create_hwmon (struct device *dev) {struct acpi_fan *fan =dev_get_drvdata (dev); -struct device *hdev; - hdev =devm_hwmon_device_register_with_info (dev,"acpi_fan" , fan, &acpi_fan_hwmon_chip_info, -NULL ); -return PTR_ERR_OR_ZERO (hdev); + fan->hdev =devm_hwmon_device_register_with_info (dev,"acpi_fan" , fan, + &acpi_fan_hwmon_chip_info,NULL ); + +return PTR_ERR_OR_ZERO (fan->hdev); }
Signature · 1 line
2.39.5
PATCH v3 3/3 ACPI: fan: Add support for Microsoft fan extensions
In reply to Armin WolfMicrosoft has designed a set of extensions for the ACPI fan device allowing the OS to specify a set of fan speed trip points. The platform firmware will then notify the ACPI fan device when one of the trip points is triggered.
Unfortunatly, some device manufacturers (like HP) blindly assume that the OS will use said extensions and thus only update the values returned by the _FST control method when receiving such a notification. As a result the ACPI fan driver is currently unusable on such machines, always reporting a constant value.
Fix this by adding support for the Microsoft extensions. During probe and when resuming from suspend the driver will attempt to trigger an initial notification that will update the values returned by _FST. Said trip points will be updated each time a notification is received from the platform firmware to ensure that the values returned by the _FST control method are updated.
--- drivers/acpi/fan.h | 2 + drivers/acpi/fan_core.c | 173 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 173 insertions(+), 2 deletions(-)
drivers/acpi/fan.h +2 -0
@@ -56,6 +56,8 @@ struct acpi_fan {struct acpi_fan_fif fif;struct acpi_fan_fps *fps;int fps_count; +/* A value of 0 means that trippoint-related functions are not supported */ +u32 fan_trip_granularity;#if IS_REACHABLE (CONFIG_HWMON )struct device *hdev;#endif
drivers/acpi/fan_core.c +171 -2
222 lines not on this page · raw message
Signature · 1 line
2.39.5
Rafael J. Wysocki
maintainerQuoted 27 lines · Armin Wolf
Microsoft has designed a
_DSMinterface for the ACPI fan device [1] that allows the OS to set fan speed trip points. The ACPI firmware will notify the ACPI fan device when said trip points are triggered.Unfortunately some device manufacturers (like HP) blindly assume that the OS will use this
_DSMinterface and thus only update the fan speed value returned by the_FSTcontrol method when sending a notification to the ACPI fan device. This results in stale fan speed values being reported by the ACPI fan driver [2].The first two patches add support for the ACPI fan notifications as specified in ACPI 11.2.3. The last patch finally adds support for the Microsoft
_DSMinterface.All patches where tested with a custom SSDT [3] and the
acpi_call[4] kernel module and appear to work just fine.[1] https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/design-guide
[2] https://github.com/lm-sensors/lm-sensors/issues/506
[3] https://github.com/Wer-Wolf/acpi-fan-ssdt/blob/master/ssdt-dsm.asl
[4] https://github.com/nix-community/acpi_callChanges since v2:
- drop already merged patches
- add links to the MSFT documentation in patch 3
Quoted 8 lines
Changes since v1:
- useacpi_evaluate_dsm_typed()during_DSMinitialization
- send ACPI netlink event when after handling a ACPI notificationArmin Wolf (3):
ACPI: fan: Add basic notification support
ACPI: fan: Add hwmon notification support
ACPI: fan: Add support for Microsoft fan extensions
All applied as 6.19 material, thanks!
Am 27.10.25 um 20:58 schrieb Rafael J. Wysocki:
Quoted 31 lines · Armin Wolf
Quoted 30 lines
Microsoft has designed a
_DSMinterface for the ACPI fan device [1] that allows the OS to set fan speed trip points. The ACPI firmware will notify the ACPI fan device when said trip points are triggered.Unfortunately some device manufacturers (like HP) blindly assume that the OS will use this
_DSMinterface and thus only update the fan speed value returned by the_FSTcontrol method when sending a notification to the ACPI fan device. This results in stale fan speed values being reported by the ACPI fan driver [2].The first two patches add support for the ACPI fan notifications as specified in ACPI 11.2.3. The last patch finally adds support for the Microsoft
_DSMinterface.All patches where tested with a custom SSDT [3] and the
acpi_call[4] kernel module and appear to work just fine.[1] https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/design-guide
[2] https://github.com/lm-sensors/lm-sensors/issues/506
[3] https://github.com/Wer-Wolf/acpi-fan-ssdt/blob/master/ssdt-dsm.asl
[4] https://github.com/nix-community/acpi_callChanges since v2:
- drop already merged patches
- add links to the MSFT documentation in patch 3Changes since v1:
- useacpi_evaluate_dsm_typed()during_DSMinitialization
- send ACPI netlink event when after handling a ACPI notification
Quoted 5 lines
Quoted 4 lines
Armin Wolf (3):
ACPI: fan: Add basic notification support
ACPI: fan: Add hwmon notification support
ACPI: fan: Add support for Microsoft fan extensionsAll applied as 6.19 material, thanks!
Thank you :)