]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PM: Introduce new PMSG_POWEROFF event
authorMario Limonciello (AMD) <superm1@kernel.org>
Wed, 12 Nov 2025 22:40:23 +0000 (16:40 -0600)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 14 Nov 2025 16:05:53 +0000 (17:05 +0100)
PMSG_POWEROFF will be used for the PM core to allow differentiating between
a hibernation or shutdown sequence when re-using callbacks for common code.

Hibernation is started by writing a hibernation method (such as 'platform'
'shutdown', or 'reboot') to use into /sys/power/disk and writing 'disk' to
/sys/power/state.

Shutdown is initiated with the reboot() syscall with arguments on whether
to halt the system or power it off.

Tested-by: Eric Naim <dnaim@cachyos.org>
Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
Link: https://patch.msgid.link/20251112224025.2051702-2-superm1@kernel.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/main.c
include/linux/pm.h
include/trace/events/power.h

index 7a8807ec9a5d08d34a302100fa1a73a62409fdcb..38fc8a978b88c31b362f9b3761a1692ff8f8d4db 100644 (file)
@@ -96,6 +96,8 @@ static const char *pm_verb(int event)
                return "restore";
        case PM_EVENT_RECOVER:
                return "recover";
+       case PM_EVENT_POWEROFF:
+               return "poweroff";
        default:
                return "(unknown PM event)";
        }
@@ -368,6 +370,7 @@ static pm_callback_t pm_op(const struct dev_pm_ops *ops, pm_message_t state)
        case PM_EVENT_FREEZE:
        case PM_EVENT_QUIESCE:
                return ops->freeze;
+       case PM_EVENT_POWEROFF:
        case PM_EVENT_HIBERNATE:
                return ops->poweroff;
        case PM_EVENT_THAW:
@@ -402,6 +405,7 @@ static pm_callback_t pm_late_early_op(const struct dev_pm_ops *ops,
        case PM_EVENT_FREEZE:
        case PM_EVENT_QUIESCE:
                return ops->freeze_late;
+       case PM_EVENT_POWEROFF:
        case PM_EVENT_HIBERNATE:
                return ops->poweroff_late;
        case PM_EVENT_THAW:
@@ -436,6 +440,7 @@ static pm_callback_t pm_noirq_op(const struct dev_pm_ops *ops, pm_message_t stat
        case PM_EVENT_FREEZE:
        case PM_EVENT_QUIESCE:
                return ops->freeze_noirq;
+       case PM_EVENT_POWEROFF:
        case PM_EVENT_HIBERNATE:
                return ops->poweroff_noirq;
        case PM_EVENT_THAW:
index a72e42eec130331d568cb13a447992dee4305813..7f69f739f6130c06b88e597651a22e70daa938db 100644 (file)
@@ -508,6 +508,7 @@ const struct dev_pm_ops name = { \
  * RECOVER     Creation of a hibernation image or restoration of the main
  *             memory contents from a hibernation image has failed, call
  *             ->thaw() and ->complete() for all devices.
+ * POWEROFF    System will poweroff, call ->poweroff() for all devices.
  *
  * The following PM_EVENT_ messages are defined for internal use by
  * kernel subsystems.  They are never issued by the PM core.
@@ -538,6 +539,7 @@ const struct dev_pm_ops name = { \
 #define PM_EVENT_USER          0x0100
 #define PM_EVENT_REMOTE                0x0200
 #define PM_EVENT_AUTO          0x0400
+#define PM_EVENT_POWEROFF      0x0800
 
 #define PM_EVENT_SLEEP         (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
 #define PM_EVENT_USER_SUSPEND  (PM_EVENT_USER | PM_EVENT_SUSPEND)
@@ -552,6 +554,7 @@ const struct dev_pm_ops name = { \
 #define PMSG_QUIESCE   ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
 #define PMSG_SUSPEND   ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
 #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
+#define PMSG_POWEROFF  ((struct pm_message){ .event = PM_EVENT_POWEROFF, })
 #define PMSG_RESUME    ((struct pm_message){ .event = PM_EVENT_RESUME, })
 #define PMSG_THAW      ((struct pm_message){ .event = PM_EVENT_THAW, })
 #define PMSG_RESTORE   ((struct pm_message){ .event = PM_EVENT_RESTORE, })
index 82904291c2b812a3d8f7885731ae2d2e3411588f..370f8df2fdb4bce5041ea3a9012088d7a8162c2f 100644 (file)
@@ -179,7 +179,8 @@ TRACE_EVENT(pstate_sample,
                { PM_EVENT_HIBERNATE, "hibernate" }, \
                { PM_EVENT_THAW, "thaw" }, \
                { PM_EVENT_RESTORE, "restore" }, \
-               { PM_EVENT_RECOVER, "recover" })
+               { PM_EVENT_RECOVER, "recover" }, \
+               { PM_EVENT_POWEROFF, "poweroff" })
 
 DEFINE_EVENT(cpu, cpu_frequency,