From: Fabio Estevam <festevam@gmail.com>
To: daniel.lezcano@linaro.org
Cc: rafael@kernel.org, krzysztof.kozlowski+dt@linaro.org,
robh+dt@kernel.org, conor+dt@kernel.org,
linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
Fabio Estevam <festevam@denx.de>
Subject: [PATCH v10 2/4] thermal_core: Prepare for introduction of thermal reboot
Date: Fri, 6 Oct 2023 15:04:51 -0300 [thread overview]
Message-ID: <20231006180453.2903342-2-festevam@gmail.com> (raw)
In-Reply-To: <20231006180453.2903342-1-festevam@gmail.com>
From: Fabio Estevam <festevam@denx.de>
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>
---
Changes since v9:
- Newly introduced.
drivers/thermal/thermal_core.c | 14 ++++++++++----
include/linux/reboot.h | 7 ++++++-
kernel/reboot.c | 8 ++++----
3 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 45d0aa0b69b7..3184e9f2eadd 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -313,18 +313,24 @@ static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip)
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);
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index c4cc3b89ced1..4586c663884e 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -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.
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 395a0ea3c7a8..b236c4c06bb3 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -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)
{
--
2.34.1
next prev parent reply other threads:[~2023-10-06 18:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-06 18:04 [PATCH v10 1/4] dt-bindings: thermal-zones: Document critical-action Fabio Estevam
2023-10-06 18:04 ` Fabio Estevam [this message]
2023-10-06 18:04 ` [PATCH v10 3/4] reboot: Introduce thermal_zone_device_critical_reboot() Fabio Estevam
2023-10-06 18:04 ` [PATCH v10 4/4] thermal: thermal_of: Allow rebooting after critical temp Fabio Estevam
2023-10-13 10:39 ` [PATCH v10 1/4] dt-bindings: thermal-zones: Document critical-action Fabio Estevam
2023-10-15 21:54 ` Daniel Lezcano
2023-10-17 12:37 ` Fabio Estevam
2023-11-13 16:03 ` Fabio Estevam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231006180453.2903342-2-festevam@gmail.com \
--to=festevam@gmail.com \
--cc=conor+dt@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@denx.de \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).