Skip to content

Commit 0ca0499

Browse files
superm1rafaeljw
authored andcommitted
PM: Introduce new PMSG_POWEROFF event
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>
1 parent 9cf0280 commit 0ca0499

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

drivers/base/power/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ static const char *pm_verb(int event)
9696
return "restore";
9797
case PM_EVENT_RECOVER:
9898
return "recover";
99+
case PM_EVENT_POWEROFF:
100+
return "poweroff";
99101
default:
100102
return "(unknown PM event)";
101103
}
@@ -368,6 +370,7 @@ static pm_callback_t pm_op(const struct dev_pm_ops *ops, pm_message_t state)
368370
case PM_EVENT_FREEZE:
369371
case PM_EVENT_QUIESCE:
370372
return ops->freeze;
373+
case PM_EVENT_POWEROFF:
371374
case PM_EVENT_HIBERNATE:
372375
return ops->poweroff;
373376
case PM_EVENT_THAW:
@@ -402,6 +405,7 @@ static pm_callback_t pm_late_early_op(const struct dev_pm_ops *ops,
402405
case PM_EVENT_FREEZE:
403406
case PM_EVENT_QUIESCE:
404407
return ops->freeze_late;
408+
case PM_EVENT_POWEROFF:
405409
case PM_EVENT_HIBERNATE:
406410
return ops->poweroff_late;
407411
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
436440
case PM_EVENT_FREEZE:
437441
case PM_EVENT_QUIESCE:
438442
return ops->freeze_noirq;
443+
case PM_EVENT_POWEROFF:
439444
case PM_EVENT_HIBERNATE:
440445
return ops->poweroff_noirq;
441446
case PM_EVENT_THAW:

include/linux/pm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ const struct dev_pm_ops name = { \
508508
* RECOVER Creation of a hibernation image or restoration of the main
509509
* memory contents from a hibernation image has failed, call
510510
* ->thaw() and ->complete() for all devices.
511+
* POWEROFF System will poweroff, call ->poweroff() for all devices.
511512
*
512513
* The following PM_EVENT_ messages are defined for internal use by
513514
* kernel subsystems. They are never issued by the PM core.
@@ -538,6 +539,7 @@ const struct dev_pm_ops name = { \
538539
#define PM_EVENT_USER 0x0100
539540
#define PM_EVENT_REMOTE 0x0200
540541
#define PM_EVENT_AUTO 0x0400
542+
#define PM_EVENT_POWEROFF 0x0800
541543

542544
#define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
543545
#define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND)
@@ -552,6 +554,7 @@ const struct dev_pm_ops name = { \
552554
#define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
553555
#define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
554556
#define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
557+
#define PMSG_POWEROFF ((struct pm_message){ .event = PM_EVENT_POWEROFF, })
555558
#define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, })
556559
#define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, })
557560
#define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, })

include/trace/events/power.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ TRACE_EVENT(pstate_sample,
179179
{ PM_EVENT_HIBERNATE, "hibernate" }, \
180180
{ PM_EVENT_THAW, "thaw" }, \
181181
{ PM_EVENT_RESTORE, "restore" }, \
182-
{ PM_EVENT_RECOVER, "recover" })
182+
{ PM_EVENT_RECOVER, "recover" }, \
183+
{ PM_EVENT_POWEROFF, "poweroff" })
183184

184185
DEFINE_EVENT(cpu, cpu_frequency,
185186

0 commit comments

Comments
 (0)