diff mbox series

[3/3] thermal: core: register a crash callback

Message ID 20230525211655.627415-4-evalenti@kernel.org
State New
Headers show
Series thermal: hook in with reboot and crash | expand

Commit Message

Eduardo Valentin May 25, 2023, 9:16 p.m. UTC
From: Eduardo Valentin <eduval@amazon.com>

This commit will register a crash callback for
the thermal subsystem, this way the thermal
core can tear down the thermal zones and ask
governors to leave the hardware in a known
safe state prior upon the event of a crash.

Cc: "Rafael J. Wysocki" <rafael@kernel.org> (supporter:THERMAL)
Cc: Daniel Lezcano <daniel.lezcano@linaro.org> (supporter:THERMAL)
Cc: Amit Kucheria <amitk@kernel.org> (reviewer:THERMAL)
Cc: Zhang Rui <rui.zhang@intel.com> (reviewer:THERMAL)
Cc: Jonathan Corbet <corbet@lwn.net> (maintainer:DOCUMENTATION)
Cc: linux-pm@vger.kernel.org (open list:THERMAL)
Cc: linux-doc@vger.kernel.org (open list:DOCUMENTATION)
Cc: linux-kernel@vger.kernel.org (open list)

Signed-off-by: Eduardo Valentin <eduval@amazon.com>
---
 drivers/thermal/thermal_core.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 66a255fb650b..38b168b9245e 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -20,6 +20,7 @@ 
 #include <linux/string.h>
 #include <linux/of.h>
 #include <linux/suspend.h>
+#include <linux/panic_notifier.h>
 
 #define CREATE_TRACE_POINTS
 #include "thermal_trace.h"
@@ -1525,6 +1526,14 @@  static void thermal_reboot_prepare(void)
 	}
 }
 
+static int thermal_crash_notify(struct notifier_block *nb,
+				unsigned long mode, void *_unused)
+{
+	thermal_reboot_prepare();
+
+	return 0;
+}
+
 static int thermal_reboot_notify(struct notifier_block *nb,
 				 unsigned long mode, void *_unused)
 {
@@ -1569,6 +1578,10 @@  static struct notifier_block thermal_pm_nb = {
 	.notifier_call = thermal_pm_notify,
 };
 
+static struct notifier_block thermal_crash_nb = {
+	.notifier_call = thermal_crash_notify,
+};
+
 static struct notifier_block thermal_reboot_nb = {
 	.notifier_call = thermal_reboot_notify,
 };
@@ -1611,6 +1624,8 @@  static int __init thermal_init(void)
 		pr_warn("Thermal: Can not register reboot notifier, return %d\n",
 			result);
 
+	atomic_notifier_chain_register(&panic_notifier_list,
+				       &thermal_crash_nb);
 	return 0;
 
 unregister_governors: