1 // SPDX-License-Identifier: GPL-2.0-only
3 * kernel/power/main.c - PM subsystem core functionality.
5 * Copyright (c) 2003 Patrick Mochel
6 * Copyright (c) 2003 Open Source Development Lab
9 #include <linux/acpi.h>
10 #include <linux/export.h>
11 #include <linux/kobject.h>
12 #include <linux/string.h>
13 #include <linux/pm-trace.h>
14 #include <linux/workqueue.h>
15 #include <linux/debugfs.h>
16 #include <linux/seq_file.h>
17 #include <linux/suspend.h>
18 #include <linux/syscalls.h>
19 #include <linux/pm_runtime.h>
23 #ifdef CONFIG_PM_SLEEP
25 * The following functions are used by the suspend/hibernate code to temporarily
26 * change gfp_allowed_mask in order to avoid using I/O during memory allocations
27 * while devices are suspended. To avoid races with the suspend/hibernate code,
28 * they should always be called with system_transition_mutex held
29 * (gfp_allowed_mask also should only be modified with system_transition_mutex
30 * held, unless the suspend/hibernate code is guaranteed not to run in parallel
31 * with that modification).
33 static gfp_t saved_gfp_mask;
35 void pm_restore_gfp_mask(void)
37 WARN_ON(!mutex_is_locked(&system_transition_mutex));
39 gfp_allowed_mask = saved_gfp_mask;
44 void pm_restrict_gfp_mask(void)
46 WARN_ON(!mutex_is_locked(&system_transition_mutex));
47 WARN_ON(saved_gfp_mask);
48 saved_gfp_mask = gfp_allowed_mask;
49 gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
52 unsigned int lock_system_sleep(void)
54 unsigned int flags = current->flags;
55 current->flags |= PF_NOFREEZE;
56 mutex_lock(&system_transition_mutex);
59 EXPORT_SYMBOL_GPL(lock_system_sleep);
61 void unlock_system_sleep(unsigned int flags)
63 if (!(flags & PF_NOFREEZE))
64 current->flags &= ~PF_NOFREEZE;
65 mutex_unlock(&system_transition_mutex);
67 EXPORT_SYMBOL_GPL(unlock_system_sleep);
69 void ksys_sync_helper(void)
76 elapsed_msecs = ktime_to_ms(ktime_sub(ktime_get(), start));
77 pr_info("Filesystems sync: %ld.%03ld seconds\n",
78 elapsed_msecs / MSEC_PER_SEC, elapsed_msecs % MSEC_PER_SEC);
80 EXPORT_SYMBOL_GPL(ksys_sync_helper);
82 /* Routines for PM-transition notifications */
84 static BLOCKING_NOTIFIER_HEAD(pm_chain_head);
86 int register_pm_notifier(struct notifier_block *nb)
88 return blocking_notifier_chain_register(&pm_chain_head, nb);
90 EXPORT_SYMBOL_GPL(register_pm_notifier);
92 int unregister_pm_notifier(struct notifier_block *nb)
94 return blocking_notifier_chain_unregister(&pm_chain_head, nb);
96 EXPORT_SYMBOL_GPL(unregister_pm_notifier);
98 void pm_report_hw_sleep_time(u64 t)
100 suspend_stats.last_hw_sleep = t;
101 suspend_stats.total_hw_sleep += t;
103 EXPORT_SYMBOL_GPL(pm_report_hw_sleep_time);
105 void pm_report_max_hw_sleep(u64 t)
107 suspend_stats.max_hw_sleep = t;
109 EXPORT_SYMBOL_GPL(pm_report_max_hw_sleep);
111 int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down)
115 ret = blocking_notifier_call_chain_robust(&pm_chain_head, val_up, val_down, NULL);
117 return notifier_to_errno(ret);
120 int pm_notifier_call_chain(unsigned long val)
122 return blocking_notifier_call_chain(&pm_chain_head, val, NULL);
125 /* If set, devices may be suspended and resumed asynchronously. */
126 int pm_async_enabled = 1;
128 static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
131 return sprintf(buf, "%d\n", pm_async_enabled);
134 static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
135 const char *buf, size_t n)
139 if (kstrtoul(buf, 10, &val))
145 pm_async_enabled = val;
149 power_attr(pm_async);
151 #ifdef CONFIG_SUSPEND
152 static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr,
158 for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) {
159 if (i >= PM_SUSPEND_MEM && cxl_mem_active())
161 if (mem_sleep_states[i]) {
162 const char *label = mem_sleep_states[i];
164 if (mem_sleep_current == i)
165 s += sprintf(s, "[%s] ", label);
167 s += sprintf(s, "%s ", label);
171 /* Convert the last space to a newline if needed. */
178 static suspend_state_t decode_suspend_state(const char *buf, size_t n)
180 suspend_state_t state;
184 p = memchr(buf, '\n', n);
185 len = p ? p - buf : n;
187 for (state = PM_SUSPEND_MIN; state < PM_SUSPEND_MAX; state++) {
188 const char *label = mem_sleep_states[state];
190 if (label && len == strlen(label) && !strncmp(buf, label, len))
194 return PM_SUSPEND_ON;
197 static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr,
198 const char *buf, size_t n)
200 suspend_state_t state;
203 error = pm_autosleep_lock();
207 if (pm_autosleep_state() > PM_SUSPEND_ON) {
212 state = decode_suspend_state(buf, n);
213 if (state < PM_SUSPEND_MAX && state > PM_SUSPEND_ON)
214 mem_sleep_current = state;
219 pm_autosleep_unlock();
220 return error ? error : n;
223 power_attr(mem_sleep);
226 * sync_on_suspend: invoke ksys_sync_helper() before suspend.
228 * show() returns whether ksys_sync_helper() is invoked before suspend.
229 * store() accepts 0 or 1. 0 disables ksys_sync_helper() and 1 enables it.
231 bool sync_on_suspend_enabled = !IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC);
233 static ssize_t sync_on_suspend_show(struct kobject *kobj,
234 struct kobj_attribute *attr, char *buf)
236 return sprintf(buf, "%d\n", sync_on_suspend_enabled);
239 static ssize_t sync_on_suspend_store(struct kobject *kobj,
240 struct kobj_attribute *attr,
241 const char *buf, size_t n)
245 if (kstrtoul(buf, 10, &val))
251 sync_on_suspend_enabled = !!val;
255 power_attr(sync_on_suspend);
256 #endif /* CONFIG_SUSPEND */
258 #ifdef CONFIG_PM_SLEEP_DEBUG
259 int pm_test_level = TEST_NONE;
261 static const char * const pm_tests[__TEST_AFTER_LAST] = {
262 [TEST_NONE] = "none",
263 [TEST_CORE] = "core",
264 [TEST_CPUS] = "processors",
265 [TEST_PLATFORM] = "platform",
266 [TEST_DEVICES] = "devices",
267 [TEST_FREEZER] = "freezer",
270 static ssize_t pm_test_show(struct kobject *kobj, struct kobj_attribute *attr,
276 for (level = TEST_FIRST; level <= TEST_MAX; level++)
277 if (pm_tests[level]) {
278 if (level == pm_test_level)
279 s += sprintf(s, "[%s] ", pm_tests[level]);
281 s += sprintf(s, "%s ", pm_tests[level]);
285 /* convert the last space to a newline */
291 static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
292 const char *buf, size_t n)
294 unsigned int sleep_flags;
295 const char * const *s;
301 p = memchr(buf, '\n', n);
302 len = p ? p - buf : n;
304 sleep_flags = lock_system_sleep();
307 for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++)
308 if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
309 pm_test_level = level;
314 unlock_system_sleep(sleep_flags);
316 return error ? error : n;
320 #endif /* CONFIG_PM_SLEEP_DEBUG */
322 static char *suspend_step_name(enum suspend_stat_step step)
327 case SUSPEND_PREPARE:
329 case SUSPEND_SUSPEND:
331 case SUSPEND_SUSPEND_NOIRQ:
332 return "suspend_noirq";
333 case SUSPEND_RESUME_NOIRQ:
334 return "resume_noirq";
342 #define suspend_attr(_name, format_str) \
343 static ssize_t _name##_show(struct kobject *kobj, \
344 struct kobj_attribute *attr, char *buf) \
346 return sprintf(buf, format_str, suspend_stats._name); \
348 static struct kobj_attribute _name = __ATTR_RO(_name)
350 suspend_attr(success, "%d\n");
351 suspend_attr(fail, "%d\n");
352 suspend_attr(failed_freeze, "%d\n");
353 suspend_attr(failed_prepare, "%d\n");
354 suspend_attr(failed_suspend, "%d\n");
355 suspend_attr(failed_suspend_late, "%d\n");
356 suspend_attr(failed_suspend_noirq, "%d\n");
357 suspend_attr(failed_resume, "%d\n");
358 suspend_attr(failed_resume_early, "%d\n");
359 suspend_attr(failed_resume_noirq, "%d\n");
360 suspend_attr(last_hw_sleep, "%llu\n");
361 suspend_attr(total_hw_sleep, "%llu\n");
362 suspend_attr(max_hw_sleep, "%llu\n");
364 static ssize_t last_failed_dev_show(struct kobject *kobj,
365 struct kobj_attribute *attr, char *buf)
368 char *last_failed_dev = NULL;
370 index = suspend_stats.last_failed_dev + REC_FAILED_NUM - 1;
371 index %= REC_FAILED_NUM;
372 last_failed_dev = suspend_stats.failed_devs[index];
374 return sprintf(buf, "%s\n", last_failed_dev);
376 static struct kobj_attribute last_failed_dev = __ATTR_RO(last_failed_dev);
378 static ssize_t last_failed_errno_show(struct kobject *kobj,
379 struct kobj_attribute *attr, char *buf)
382 int last_failed_errno;
384 index = suspend_stats.last_failed_errno + REC_FAILED_NUM - 1;
385 index %= REC_FAILED_NUM;
386 last_failed_errno = suspend_stats.errno[index];
388 return sprintf(buf, "%d\n", last_failed_errno);
390 static struct kobj_attribute last_failed_errno = __ATTR_RO(last_failed_errno);
392 static ssize_t last_failed_step_show(struct kobject *kobj,
393 struct kobj_attribute *attr, char *buf)
396 enum suspend_stat_step step;
397 char *last_failed_step = NULL;
399 index = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
400 index %= REC_FAILED_NUM;
401 step = suspend_stats.failed_steps[index];
402 last_failed_step = suspend_step_name(step);
404 return sprintf(buf, "%s\n", last_failed_step);
406 static struct kobj_attribute last_failed_step = __ATTR_RO(last_failed_step);
408 static struct attribute *suspend_attrs[] = {
412 &failed_prepare.attr,
413 &failed_suspend.attr,
414 &failed_suspend_late.attr,
415 &failed_suspend_noirq.attr,
417 &failed_resume_early.attr,
418 &failed_resume_noirq.attr,
419 &last_failed_dev.attr,
420 &last_failed_errno.attr,
421 &last_failed_step.attr,
423 &total_hw_sleep.attr,
428 static umode_t suspend_attr_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
430 if (attr != &last_hw_sleep.attr &&
431 attr != &total_hw_sleep.attr &&
432 attr != &max_hw_sleep.attr)
436 if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)
442 static const struct attribute_group suspend_attr_group = {
443 .name = "suspend_stats",
444 .attrs = suspend_attrs,
445 .is_visible = suspend_attr_is_visible,
448 #ifdef CONFIG_DEBUG_FS
449 static int suspend_stats_show(struct seq_file *s, void *unused)
451 int i, index, last_dev, last_errno, last_step;
453 last_dev = suspend_stats.last_failed_dev + REC_FAILED_NUM - 1;
454 last_dev %= REC_FAILED_NUM;
455 last_errno = suspend_stats.last_failed_errno + REC_FAILED_NUM - 1;
456 last_errno %= REC_FAILED_NUM;
457 last_step = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
458 last_step %= REC_FAILED_NUM;
459 seq_printf(s, "%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n"
460 "%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n",
461 "success", suspend_stats.success,
462 "fail", suspend_stats.fail,
463 "failed_freeze", suspend_stats.failed_freeze,
464 "failed_prepare", suspend_stats.failed_prepare,
465 "failed_suspend", suspend_stats.failed_suspend,
466 "failed_suspend_late",
467 suspend_stats.failed_suspend_late,
468 "failed_suspend_noirq",
469 suspend_stats.failed_suspend_noirq,
470 "failed_resume", suspend_stats.failed_resume,
471 "failed_resume_early",
472 suspend_stats.failed_resume_early,
473 "failed_resume_noirq",
474 suspend_stats.failed_resume_noirq);
475 seq_printf(s, "failures:\n last_failed_dev:\t%-s\n",
476 suspend_stats.failed_devs[last_dev]);
477 for (i = 1; i < REC_FAILED_NUM; i++) {
478 index = last_dev + REC_FAILED_NUM - i;
479 index %= REC_FAILED_NUM;
480 seq_printf(s, "\t\t\t%-s\n",
481 suspend_stats.failed_devs[index]);
483 seq_printf(s, " last_failed_errno:\t%-d\n",
484 suspend_stats.errno[last_errno]);
485 for (i = 1; i < REC_FAILED_NUM; i++) {
486 index = last_errno + REC_FAILED_NUM - i;
487 index %= REC_FAILED_NUM;
488 seq_printf(s, "\t\t\t%-d\n",
489 suspend_stats.errno[index]);
491 seq_printf(s, " last_failed_step:\t%-s\n",
493 suspend_stats.failed_steps[last_step]));
494 for (i = 1; i < REC_FAILED_NUM; i++) {
495 index = last_step + REC_FAILED_NUM - i;
496 index %= REC_FAILED_NUM;
497 seq_printf(s, "\t\t\t%-s\n",
499 suspend_stats.failed_steps[index]));
504 DEFINE_SHOW_ATTRIBUTE(suspend_stats);
506 static int __init pm_debugfs_init(void)
508 debugfs_create_file("suspend_stats", S_IFREG | S_IRUGO,
509 NULL, NULL, &suspend_stats_fops);
513 late_initcall(pm_debugfs_init);
514 #endif /* CONFIG_DEBUG_FS */
516 #endif /* CONFIG_PM_SLEEP */
518 #ifdef CONFIG_PM_SLEEP_DEBUG
520 * pm_print_times: print time taken by devices to suspend and resume.
522 * show() returns whether printing of suspend and resume times is enabled.
523 * store() accepts 0 or 1. 0 disables printing and 1 enables it.
525 bool pm_print_times_enabled;
527 static ssize_t pm_print_times_show(struct kobject *kobj,
528 struct kobj_attribute *attr, char *buf)
530 return sprintf(buf, "%d\n", pm_print_times_enabled);
533 static ssize_t pm_print_times_store(struct kobject *kobj,
534 struct kobj_attribute *attr,
535 const char *buf, size_t n)
539 if (kstrtoul(buf, 10, &val))
545 pm_print_times_enabled = !!val;
549 power_attr(pm_print_times);
551 static inline void pm_print_times_init(void)
553 pm_print_times_enabled = !!initcall_debug;
556 static ssize_t pm_wakeup_irq_show(struct kobject *kobj,
557 struct kobj_attribute *attr,
560 if (!pm_wakeup_irq())
563 return sprintf(buf, "%u\n", pm_wakeup_irq());
566 power_attr_ro(pm_wakeup_irq);
568 bool pm_debug_messages_on __read_mostly;
570 bool pm_debug_messages_should_print(void)
572 return pm_debug_messages_on && pm_suspend_target_state != PM_SUSPEND_ON;
574 EXPORT_SYMBOL_GPL(pm_debug_messages_should_print);
576 static ssize_t pm_debug_messages_show(struct kobject *kobj,
577 struct kobj_attribute *attr, char *buf)
579 return sprintf(buf, "%d\n", pm_debug_messages_on);
582 static ssize_t pm_debug_messages_store(struct kobject *kobj,
583 struct kobj_attribute *attr,
584 const char *buf, size_t n)
588 if (kstrtoul(buf, 10, &val))
594 pm_debug_messages_on = !!val;
598 power_attr(pm_debug_messages);
600 static int __init pm_debug_messages_setup(char *str)
602 pm_debug_messages_on = true;
605 __setup("pm_debug_messages", pm_debug_messages_setup);
607 #else /* !CONFIG_PM_SLEEP_DEBUG */
608 static inline void pm_print_times_init(void) {}
609 #endif /* CONFIG_PM_SLEEP_DEBUG */
611 struct kobject *power_kobj;
614 * state - control system sleep states.
616 * show() returns available sleep state labels, which may be "mem", "standby",
617 * "freeze" and "disk" (hibernation).
618 * See Documentation/admin-guide/pm/sleep-states.rst for a description of
621 * store() accepts one of those strings, translates it into the proper
622 * enumerated value, and initiates a suspend transition.
624 static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
628 #ifdef CONFIG_SUSPEND
631 for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
633 s += sprintf(s,"%s ", pm_states[i]);
636 if (hibernation_available())
637 s += sprintf(s, "disk ");
639 /* convert the last space to a newline */
644 static suspend_state_t decode_state(const char *buf, size_t n)
646 #ifdef CONFIG_SUSPEND
647 suspend_state_t state;
652 p = memchr(buf, '\n', n);
653 len = p ? p - buf : n;
655 /* Check hibernation first. */
656 if (len == 4 && str_has_prefix(buf, "disk"))
657 return PM_SUSPEND_MAX;
659 #ifdef CONFIG_SUSPEND
660 for (state = PM_SUSPEND_MIN; state < PM_SUSPEND_MAX; state++) {
661 const char *label = pm_states[state];
663 if (label && len == strlen(label) && !strncmp(buf, label, len))
668 return PM_SUSPEND_ON;
671 static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
672 const char *buf, size_t n)
674 suspend_state_t state;
677 error = pm_autosleep_lock();
681 if (pm_autosleep_state() > PM_SUSPEND_ON) {
686 state = decode_state(buf, n);
687 if (state < PM_SUSPEND_MAX) {
688 if (state == PM_SUSPEND_MEM)
689 state = mem_sleep_current;
691 error = pm_suspend(state);
692 } else if (state == PM_SUSPEND_MAX) {
699 pm_autosleep_unlock();
700 return error ? error : n;
705 #ifdef CONFIG_PM_SLEEP
707 * The 'wakeup_count' attribute, along with the functions defined in
708 * drivers/base/power/wakeup.c, provides a means by which wakeup events can be
709 * handled in a non-racy way.
711 * If a wakeup event occurs when the system is in a sleep state, it simply is
712 * woken up. In turn, if an event that would wake the system up from a sleep
713 * state occurs when it is undergoing a transition to that sleep state, the
714 * transition should be aborted. Moreover, if such an event occurs when the
715 * system is in the working state, an attempt to start a transition to the
716 * given sleep state should fail during certain period after the detection of
717 * the event. Using the 'state' attribute alone is not sufficient to satisfy
718 * these requirements, because a wakeup event may occur exactly when 'state'
719 * is being written to and may be delivered to user space right before it is
720 * frozen, so the event will remain only partially processed until the system is
721 * woken up by another event. In particular, it won't cause the transition to
722 * a sleep state to be aborted.
724 * This difficulty may be overcome if user space uses 'wakeup_count' before
725 * writing to 'state'. It first should read from 'wakeup_count' and store
726 * the read value. Then, after carrying out its own preparations for the system
727 * transition to a sleep state, it should write the stored value to
728 * 'wakeup_count'. If that fails, at least one wakeup event has occurred since
729 * 'wakeup_count' was read and 'state' should not be written to. Otherwise, it
730 * is allowed to write to 'state', but the transition will be aborted if there
731 * are any wakeup events detected after 'wakeup_count' was written to.
734 static ssize_t wakeup_count_show(struct kobject *kobj,
735 struct kobj_attribute *attr,
740 return pm_get_wakeup_count(&val, true) ?
741 sprintf(buf, "%u\n", val) : -EINTR;
744 static ssize_t wakeup_count_store(struct kobject *kobj,
745 struct kobj_attribute *attr,
746 const char *buf, size_t n)
751 error = pm_autosleep_lock();
755 if (pm_autosleep_state() > PM_SUSPEND_ON) {
761 if (sscanf(buf, "%u", &val) == 1) {
762 if (pm_save_wakeup_count(val))
765 pm_print_active_wakeup_sources();
769 pm_autosleep_unlock();
773 power_attr(wakeup_count);
775 #ifdef CONFIG_PM_AUTOSLEEP
776 static ssize_t autosleep_show(struct kobject *kobj,
777 struct kobj_attribute *attr,
780 suspend_state_t state = pm_autosleep_state();
782 if (state == PM_SUSPEND_ON)
783 return sprintf(buf, "off\n");
785 #ifdef CONFIG_SUSPEND
786 if (state < PM_SUSPEND_MAX)
787 return sprintf(buf, "%s\n", pm_states[state] ?
788 pm_states[state] : "error");
790 #ifdef CONFIG_HIBERNATION
791 return sprintf(buf, "disk\n");
793 return sprintf(buf, "error");
797 static ssize_t autosleep_store(struct kobject *kobj,
798 struct kobj_attribute *attr,
799 const char *buf, size_t n)
801 suspend_state_t state = decode_state(buf, n);
804 if (state == PM_SUSPEND_ON
805 && strcmp(buf, "off") && strcmp(buf, "off\n"))
808 if (state == PM_SUSPEND_MEM)
809 state = mem_sleep_current;
811 error = pm_autosleep_set_state(state);
812 return error ? error : n;
815 power_attr(autosleep);
816 #endif /* CONFIG_PM_AUTOSLEEP */
818 #ifdef CONFIG_PM_WAKELOCKS
819 static ssize_t wake_lock_show(struct kobject *kobj,
820 struct kobj_attribute *attr,
823 return pm_show_wakelocks(buf, true);
826 static ssize_t wake_lock_store(struct kobject *kobj,
827 struct kobj_attribute *attr,
828 const char *buf, size_t n)
830 int error = pm_wake_lock(buf);
831 return error ? error : n;
834 power_attr(wake_lock);
836 static ssize_t wake_unlock_show(struct kobject *kobj,
837 struct kobj_attribute *attr,
840 return pm_show_wakelocks(buf, false);
843 static ssize_t wake_unlock_store(struct kobject *kobj,
844 struct kobj_attribute *attr,
845 const char *buf, size_t n)
847 int error = pm_wake_unlock(buf);
848 return error ? error : n;
851 power_attr(wake_unlock);
853 #endif /* CONFIG_PM_WAKELOCKS */
854 #endif /* CONFIG_PM_SLEEP */
856 #ifdef CONFIG_PM_TRACE
857 int pm_trace_enabled;
859 static ssize_t pm_trace_show(struct kobject *kobj, struct kobj_attribute *attr,
862 return sprintf(buf, "%d\n", pm_trace_enabled);
866 pm_trace_store(struct kobject *kobj, struct kobj_attribute *attr,
867 const char *buf, size_t n)
871 if (sscanf(buf, "%d", &val) == 1) {
872 pm_trace_enabled = !!val;
873 if (pm_trace_enabled) {
874 pr_warn("PM: Enabling pm_trace changes system date and time during resume.\n"
875 "PM: Correct system time has to be restored manually after resume.\n");
882 power_attr(pm_trace);
884 static ssize_t pm_trace_dev_match_show(struct kobject *kobj,
885 struct kobj_attribute *attr,
888 return show_trace_dev_match(buf, PAGE_SIZE);
891 power_attr_ro(pm_trace_dev_match);
893 #endif /* CONFIG_PM_TRACE */
895 #ifdef CONFIG_FREEZER
896 static ssize_t pm_freeze_timeout_show(struct kobject *kobj,
897 struct kobj_attribute *attr, char *buf)
899 return sprintf(buf, "%u\n", freeze_timeout_msecs);
902 static ssize_t pm_freeze_timeout_store(struct kobject *kobj,
903 struct kobj_attribute *attr,
904 const char *buf, size_t n)
908 if (kstrtoul(buf, 10, &val))
911 freeze_timeout_msecs = val;
915 power_attr(pm_freeze_timeout);
917 #endif /* CONFIG_FREEZER*/
919 static struct attribute * g[] = {
921 #ifdef CONFIG_PM_TRACE
923 &pm_trace_dev_match_attr.attr,
925 #ifdef CONFIG_PM_SLEEP
927 &wakeup_count_attr.attr,
928 #ifdef CONFIG_SUSPEND
929 &mem_sleep_attr.attr,
930 &sync_on_suspend_attr.attr,
932 #ifdef CONFIG_PM_AUTOSLEEP
933 &autosleep_attr.attr,
935 #ifdef CONFIG_PM_WAKELOCKS
936 &wake_lock_attr.attr,
937 &wake_unlock_attr.attr,
939 #ifdef CONFIG_PM_SLEEP_DEBUG
941 &pm_print_times_attr.attr,
942 &pm_wakeup_irq_attr.attr,
943 &pm_debug_messages_attr.attr,
946 #ifdef CONFIG_FREEZER
947 &pm_freeze_timeout_attr.attr,
952 static const struct attribute_group attr_group = {
956 static const struct attribute_group *attr_groups[] = {
958 #ifdef CONFIG_PM_SLEEP
964 struct workqueue_struct *pm_wq;
965 EXPORT_SYMBOL_GPL(pm_wq);
967 static int __init pm_start_workqueue(void)
969 pm_wq = alloc_workqueue("pm", WQ_FREEZABLE, 0);
971 return pm_wq ? 0 : -ENOMEM;
974 static int __init pm_init(void)
976 int error = pm_start_workqueue();
979 hibernate_image_size_init();
980 hibernate_reserved_size_init();
982 power_kobj = kobject_create_and_add("power", NULL);
985 error = sysfs_create_groups(power_kobj, attr_groups);
988 pm_print_times_init();
989 return pm_autosleep_init();
992 core_initcall(pm_init);