gsmi: Log event for critical thermal thresholds
authorDuncan Laurie <dlaurie@chromium.org>
Wed, 18 Jul 2012 18:13:30 +0000 (11:13 -0700)
committerGerrit <chrome-bot@google.com>
Thu, 19 Jul 2012 16:59:12 +0000 (09:59 -0700)
This registers a notifier for the new thermal notifier
introduced in a previous commit and logs a kernel shutdown
event when the notifier is called for crossing the
THERMAL_TRIP_CRITICAL threshold.

This change also adds an #ifdef around a variable that was
triggering an 'unused variable' warning when building
without CONFIG_EFI_VARS.

BUG=chrome-os-partner:9381
TEST=manual

1) Modify critical shutdown threshold in the BIOS
2) Generate a load on the system to increase temperature
3) Wait until system powers off
4) Power back on and read the event log:

4 | 2012-07-18 10:47:02 | Kernel Event | Critical Thermal Threshold
5 | 2012-07-18 10:47:06 | Kernel Event | Clean Shutdown
6 | 2012-07-18 10:47:06 | ACPI Enter | S5

Change-Id: I1bbda1b04888a467bf03e955a0e83e543b38c003
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27776
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
drivers/firmware/google/gsmi.c

index c8cb48d..0612a16 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/reboot.h>
 #include <linux/efi.h>
 #include <linux/module.h>
+#include <linux/thermal.h>
 
 #define GSMI_SHUTDOWN_CLEAN    0       /* Clean Shutdown */
 /* TODO(mikew@google.com): Tie in HARDLOCKUP_DETECTOR with NMIWDT */
@@ -39,6 +40,7 @@
 #define GSMI_SHUTDOWN_SOFTWDT  6       /* Software Watchdog */
 #define GSMI_SHUTDOWN_MBE      7       /* Uncorrected ECC */
 #define GSMI_SHUTDOWN_TRIPLE   8       /* Triple Fault */
+#define GSMI_SHUTDOWN_THERMAL  9       /* Critical Thermal Threshold */
 
 #define DRIVER_VERSION         "1.0"
 #define GSMI_GUID_SIZE         16
@@ -290,6 +292,8 @@ static int gsmi_exec(u8 func, u8 sub)
 
 #ifdef CONFIG_EFI_VARS
 
+static struct efivars efivars;
+
 /* Return the number of unicode characters in data */
 static size_t
 utf16_strlen(efi_char16_t *data, unsigned long maxlength)
@@ -683,6 +687,18 @@ static struct notifier_block gsmi_panic_notifier = {
        .notifier_call = gsmi_panic_callback,
 };
 
+static int gsmi_thermal_callback(struct notifier_block *nb,
+                                unsigned long reason, void *arg)
+{
+       if (reason == THERMAL_TRIP_CRITICAL)
+               gsmi_shutdown_reason(GSMI_SHUTDOWN_THERMAL);
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block gsmi_thermal_notifier = {
+       .notifier_call = gsmi_thermal_callback
+};
+
 /*
  * This hash function was blatantly copied from include/linux/hash.h.
  * It is used by this driver to obfuscate a board name that requires a
@@ -781,7 +797,6 @@ static __init int gsmi_system_valid(void)
 }
 
 static struct kobject *gsmi_kobj;
-static struct efivars efivars;
 
 static __init int gsmi_init(void)
 {
@@ -911,6 +926,7 @@ static __init int gsmi_init(void)
        }
 #endif
 
+       register_thermal_notifier(&gsmi_thermal_notifier);
        register_reboot_notifier(&gsmi_reboot_notifier);
        register_die_notifier(&gsmi_die_notifier);
        atomic_notifier_chain_register(&panic_notifier_list,
@@ -936,6 +952,7 @@ out_err:
 
 static void __exit gsmi_exit(void)
 {
+       unregister_thermal_notifier(&gsmi_thermal_notifier);
        unregister_reboot_notifier(&gsmi_reboot_notifier);
        unregister_die_notifier(&gsmi_die_notifier);
        atomic_notifier_chain_unregister(&panic_notifier_list,