thermal/core: Prepare for introduction of thermal reboot
authorFabio Estevam <festevam@denx.de>
Wed, 29 Nov 2023 12:43:28 +0000 (09:43 -0300)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Tue, 2 Jan 2024 08:33:18 +0000 (09:33 +0100)
Add some helper functions to make it easier introducing the support
for thermal reboot.

No functional change.

Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20231129124330.519423-2-festevam@gmail.com
drivers/thermal/thermal_core.c
include/linux/reboot.h
kernel/reboot.c

index 5e5fcbd81ddadfc61d310767799350dfa796f084..859f62e9d77975addbb4536fcb08c3b3cb2625ba 100644 (file)
@@ -311,18 +311,24 @@ static void handle_non_critical_trips(struct thermal_zone_device *tz,
                       def_governor->throttle(tz, trip);
 }
 
-void thermal_zone_device_critical(struct thermal_zone_device *tz)
+static void thermal_zone_device_halt(struct thermal_zone_device *tz, bool shutdown)
 {
        /*
         * poweroff_delay_ms must be a carefully profiled positive value.
         * Its a must for forced_emergency_poweroff_work to be scheduled.
         */
        int poweroff_delay_ms = CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS;
+       const char *msg = "Temperature too high";
+
+       dev_emerg(&tz->device, "%s: critical temperature reached\n", tz->type);
 
-       dev_emerg(&tz->device, "%s: critical temperature reached, "
-                 "shutting down\n", tz->type);
+       if (shutdown)
+               hw_protection_shutdown(msg, poweroff_delay_ms);
+}
 
-       hw_protection_shutdown("Temperature too high", poweroff_delay_ms);
+void thermal_zone_device_critical(struct thermal_zone_device *tz)
+{
+       thermal_zone_device_halt(tz, true);
 }
 EXPORT_SYMBOL(thermal_zone_device_critical);
 
index c4cc3b89ced1fbed2cfc903cde2ceb2a5e5ff9cb..4586c663884ee350e4c45e90944c582fba51fd1c 100644 (file)
@@ -177,7 +177,12 @@ void ctrl_alt_del(void);
 
 extern void orderly_poweroff(bool force);
 extern void orderly_reboot(void);
-void hw_protection_shutdown(const char *reason, int ms_until_forced);
+void __hw_protection_shutdown(const char *reason, int ms_until_forced, bool shutdown);
+
+static inline void hw_protection_shutdown(const char *reason, int ms_until_forced)
+{
+       __hw_protection_shutdown(reason, ms_until_forced, true);
+}
 
 /*
  * Emergency restart, callable from an interrupt handler.
index 395a0ea3c7a8a647d5cebb56dc56701c185b768e..b236c4c06bb3c722718337a94724d8e70b231d91 100644 (file)
@@ -957,7 +957,7 @@ static void hw_failure_emergency_poweroff(int poweroff_delay_ms)
 }
 
 /**
- * hw_protection_shutdown - Trigger an emergency system poweroff
+ * __hw_protection_shutdown - Trigger an emergency system poweroff
  *
  * @reason:            Reason of emergency shutdown to be printed.
  * @ms_until_forced:   Time to wait for orderly shutdown before tiggering a
@@ -971,7 +971,7 @@ static void hw_failure_emergency_poweroff(int poweroff_delay_ms)
  * if the previous request has given a large timeout for forced shutdown.
  * Can be called from any context.
  */
-void hw_protection_shutdown(const char *reason, int ms_until_forced)
+void __hw_protection_shutdown(const char *reason, int ms_until_forced, bool shutdown)
 {
        static atomic_t allow_proceed = ATOMIC_INIT(1);
 
@@ -986,9 +986,9 @@ void hw_protection_shutdown(const char *reason, int ms_until_forced)
         * orderly_poweroff failure
         */
        hw_failure_emergency_poweroff(ms_until_forced);
-       orderly_poweroff(true);
+       if (shutdown)
+               orderly_poweroff(true);
 }
-EXPORT_SYMBOL_GPL(hw_protection_shutdown);
 
 static int __init reboot_setup(char *str)
 {