main.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * kernel/power/main.c - PM subsystem core functionality.
  3. *
  4. * Copyright (c) 2003 Patrick Mochel
  5. * Copyright (c) 2003 Open Source Development Lab
  6. *
  7. * This file is released under the GPLv2
  8. *
  9. */
  10. #include <linux/export.h>
  11. #include <linux/kobject.h>
  12. #include <linux/string.h>
  13. #include <linux/resume-trace.h>
  14. #include <linux/workqueue.h>
  15. #include <linux/debugfs.h>
  16. #include <linux/seq_file.h>
  17. #include "power.h"
  18. #define HIB_PM_DEBUG 1
  19. #define _TAG_HIB_M "HIB/PM"
  20. #if (HIB_PM_DEBUG)
  21. #undef hib_log
  22. #define hib_log(fmt, ...) pr_warn("[%s][%s]" fmt, _TAG_HIB_M, __func__, ##__VA_ARGS__)
  23. #else
  24. #define hib_log(fmt, ...)
  25. #endif
  26. #undef hib_warn
  27. #define hib_warn(fmt, ...) pr_warn("[%s][%s]" fmt, _TAG_HIB_M, __func__, ##__VA_ARGS__)
  28. DEFINE_MUTEX(pm_mutex);
  29. EXPORT_SYMBOL_GPL(pm_mutex);
  30. #ifdef CONFIG_PM_SLEEP
  31. /* Routines for PM-transition notifications */
  32. static BLOCKING_NOTIFIER_HEAD(pm_chain_head);
  33. int register_pm_notifier(struct notifier_block *nb)
  34. {
  35. return blocking_notifier_chain_register(&pm_chain_head, nb);
  36. }
  37. EXPORT_SYMBOL_GPL(register_pm_notifier);
  38. int unregister_pm_notifier(struct notifier_block *nb)
  39. {
  40. return blocking_notifier_chain_unregister(&pm_chain_head, nb);
  41. }
  42. EXPORT_SYMBOL_GPL(unregister_pm_notifier);
  43. int pm_notifier_call_chain(unsigned long val)
  44. {
  45. int ret = blocking_notifier_call_chain(&pm_chain_head, val, NULL);
  46. return notifier_to_errno(ret);
  47. }
  48. EXPORT_SYMBOL_GPL(pm_notifier_call_chain);
  49. /* If set, devices may be suspended and resumed asynchronously. */
  50. int pm_async_enabled = 1;
  51. static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
  52. char *buf)
  53. {
  54. return sprintf(buf, "%d\n", pm_async_enabled);
  55. }
  56. static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
  57. const char *buf, size_t n)
  58. {
  59. unsigned long val;
  60. if (kstrtoul(buf, 10, &val))
  61. return -EINVAL;
  62. if (val > 1)
  63. return -EINVAL;
  64. pm_async_enabled = val;
  65. return n;
  66. }
  67. power_attr(pm_async);
  68. #ifdef CONFIG_PM_DEBUG
  69. int pm_test_level = TEST_NONE;
  70. static const char * const pm_tests[__TEST_AFTER_LAST] = {
  71. [TEST_NONE] = "none",
  72. [TEST_CORE] = "core",
  73. [TEST_CPUS] = "processors",
  74. [TEST_PLATFORM] = "platform",
  75. [TEST_DEVICES] = "devices",
  76. [TEST_FREEZER] = "freezer",
  77. };
  78. static ssize_t pm_test_show(struct kobject *kobj, struct kobj_attribute *attr,
  79. char *buf)
  80. {
  81. char *s = buf;
  82. int level;
  83. for (level = TEST_FIRST; level <= TEST_MAX; level++)
  84. if (pm_tests[level]) {
  85. if (level == pm_test_level)
  86. s += sprintf(s, "[%s] ", pm_tests[level]);
  87. else
  88. s += sprintf(s, "%s ", pm_tests[level]);
  89. }
  90. if (s != buf)
  91. /* convert the last space to a newline */
  92. *(s-1) = '\n';
  93. return (s - buf);
  94. }
  95. static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
  96. const char *buf, size_t n)
  97. {
  98. const char * const *s;
  99. int level;
  100. char *p;
  101. int len;
  102. int error = -EINVAL;
  103. p = memchr(buf, '\n', n);
  104. len = p ? p - buf : n;
  105. lock_system_sleep();
  106. level = TEST_FIRST;
  107. for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++)
  108. if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
  109. pm_test_level = level;
  110. error = 0;
  111. break;
  112. }
  113. unlock_system_sleep();
  114. return error ? error : n;
  115. }
  116. power_attr(pm_test);
  117. #endif /* CONFIG_PM_DEBUG */
  118. #ifdef CONFIG_DEBUG_FS
  119. static char *suspend_step_name(enum suspend_stat_step step)
  120. {
  121. switch (step) {
  122. case SUSPEND_FREEZE:
  123. return "freeze";
  124. case SUSPEND_PREPARE:
  125. return "prepare";
  126. case SUSPEND_SUSPEND:
  127. return "suspend";
  128. case SUSPEND_SUSPEND_NOIRQ:
  129. return "suspend_noirq";
  130. case SUSPEND_RESUME_NOIRQ:
  131. return "resume_noirq";
  132. case SUSPEND_RESUME:
  133. return "resume";
  134. default:
  135. return "";
  136. }
  137. }
  138. static int suspend_stats_show(struct seq_file *s, void *unused)
  139. {
  140. int i, index, last_dev, last_errno, last_step;
  141. last_dev = suspend_stats.last_failed_dev + REC_FAILED_NUM - 1;
  142. last_dev %= REC_FAILED_NUM;
  143. last_errno = suspend_stats.last_failed_errno + REC_FAILED_NUM - 1;
  144. last_errno %= REC_FAILED_NUM;
  145. last_step = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
  146. last_step %= REC_FAILED_NUM;
  147. seq_printf(s, "%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n"
  148. "%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n",
  149. "success", suspend_stats.success,
  150. "fail", suspend_stats.fail,
  151. "failed_freeze", suspend_stats.failed_freeze,
  152. "failed_prepare", suspend_stats.failed_prepare,
  153. "failed_suspend", suspend_stats.failed_suspend,
  154. "failed_suspend_late",
  155. suspend_stats.failed_suspend_late,
  156. "failed_suspend_noirq",
  157. suspend_stats.failed_suspend_noirq,
  158. "failed_resume", suspend_stats.failed_resume,
  159. "failed_resume_early",
  160. suspend_stats.failed_resume_early,
  161. "failed_resume_noirq",
  162. suspend_stats.failed_resume_noirq);
  163. seq_printf(s, "failures:\n last_failed_dev:\t%-s\n",
  164. suspend_stats.failed_devs[last_dev]);
  165. for (i = 1; i < REC_FAILED_NUM; i++) {
  166. index = last_dev + REC_FAILED_NUM - i;
  167. index %= REC_FAILED_NUM;
  168. seq_printf(s, "\t\t\t%-s\n",
  169. suspend_stats.failed_devs[index]);
  170. }
  171. seq_printf(s, " last_failed_errno:\t%-d\n",
  172. suspend_stats.errno[last_errno]);
  173. for (i = 1; i < REC_FAILED_NUM; i++) {
  174. index = last_errno + REC_FAILED_NUM - i;
  175. index %= REC_FAILED_NUM;
  176. seq_printf(s, "\t\t\t%-d\n",
  177. suspend_stats.errno[index]);
  178. }
  179. seq_printf(s, " last_failed_step:\t%-s\n",
  180. suspend_step_name(
  181. suspend_stats.failed_steps[last_step]));
  182. for (i = 1; i < REC_FAILED_NUM; i++) {
  183. index = last_step + REC_FAILED_NUM - i;
  184. index %= REC_FAILED_NUM;
  185. seq_printf(s, "\t\t\t%-s\n",
  186. suspend_step_name(
  187. suspend_stats.failed_steps[index]));
  188. }
  189. return 0;
  190. }
  191. static int suspend_stats_open(struct inode *inode, struct file *file)
  192. {
  193. return single_open(file, suspend_stats_show, NULL);
  194. }
  195. static const struct file_operations suspend_stats_operations = {
  196. .open = suspend_stats_open,
  197. .read = seq_read,
  198. .llseek = seq_lseek,
  199. .release = single_release,
  200. };
  201. static int __init pm_debugfs_init(void)
  202. {
  203. debugfs_create_file("suspend_stats", S_IFREG | S_IRUGO,
  204. NULL, NULL, &suspend_stats_operations);
  205. return 0;
  206. }
  207. late_initcall(pm_debugfs_init);
  208. #endif /* CONFIG_DEBUG_FS */
  209. #endif /* CONFIG_PM_SLEEP */
  210. #ifdef CONFIG_PM_SLEEP_DEBUG
  211. /*
  212. * pm_print_times: print time taken by devices to suspend and resume.
  213. *
  214. * show() returns whether printing of suspend and resume times is enabled.
  215. * store() accepts 0 or 1. 0 disables printing and 1 enables it.
  216. */
  217. bool pm_print_times_enabled;
  218. static ssize_t pm_print_times_show(struct kobject *kobj,
  219. struct kobj_attribute *attr, char *buf)
  220. {
  221. return sprintf(buf, "%d\n", pm_print_times_enabled);
  222. }
  223. static ssize_t pm_print_times_store(struct kobject *kobj,
  224. struct kobj_attribute *attr,
  225. const char *buf, size_t n)
  226. {
  227. unsigned long val;
  228. if (kstrtoul(buf, 10, &val))
  229. return -EINVAL;
  230. if (val > 1)
  231. return -EINVAL;
  232. pm_print_times_enabled = !!val;
  233. return n;
  234. }
  235. power_attr(pm_print_times);
  236. static inline void pm_print_times_init(void)
  237. {
  238. pm_print_times_enabled = !!initcall_debug;
  239. }
  240. #else /* !CONFIG_PP_SLEEP_DEBUG */
  241. static inline void pm_print_times_init(void) {}
  242. #endif /* CONFIG_PM_SLEEP_DEBUG */
  243. struct kobject *power_kobj;
  244. EXPORT_SYMBOL_GPL(power_kobj);
  245. /**
  246. * state - control system sleep states.
  247. *
  248. * show() returns available sleep state labels, which may be "mem", "standby",
  249. * "freeze" and "disk" (hibernation). See Documentation/power/states.txt for a
  250. * description of what they mean.
  251. *
  252. * store() accepts one of those strings, translates it into the proper
  253. * enumerated value, and initiates a suspend transition.
  254. */
  255. static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
  256. char *buf)
  257. {
  258. char *s = buf;
  259. #ifdef CONFIG_SUSPEND
  260. suspend_state_t i;
  261. for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
  262. if (pm_states[i])
  263. s += sprintf(s,"%s ", pm_states[i]);
  264. #endif
  265. if (hibernation_available())
  266. s += sprintf(s, "disk ");
  267. if (s != buf)
  268. /* convert the last space to a newline */
  269. *(s-1) = '\n';
  270. return (s - buf);
  271. }
  272. static suspend_state_t decode_state(const char *buf, size_t n)
  273. {
  274. #ifdef CONFIG_SUSPEND
  275. suspend_state_t state;
  276. #endif
  277. char *p;
  278. int len;
  279. p = memchr(buf, '\n', n);
  280. len = p ? p - buf : n;
  281. /* Check hibernation first. */
  282. if (len == 4 && !strncmp(buf, "disk", len))
  283. return PM_SUSPEND_MAX;
  284. #ifdef CONFIG_SUSPEND
  285. for (state = PM_SUSPEND_MIN; state < PM_SUSPEND_MAX; state++) {
  286. const char *label = pm_states[state];
  287. if (label && len == strlen(label) && !strncmp(buf, label, len))
  288. return state;
  289. }
  290. #endif
  291. return PM_SUSPEND_ON;
  292. }
  293. static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
  294. const char *buf, size_t n)
  295. {
  296. suspend_state_t state;
  297. int error;
  298. #ifdef CONFIG_MTK_HIBERNATION
  299. char *p;
  300. int len;
  301. #endif
  302. error = pm_autosleep_lock();
  303. if (error)
  304. return error;
  305. if (pm_autosleep_state() > PM_SUSPEND_ON) {
  306. error = -EBUSY;
  307. goto out;
  308. }
  309. state = decode_state(buf, n);
  310. #ifdef CONFIG_MTK_HIBERNATION
  311. p = memchr(buf, '\n', n);
  312. len = p ? p - buf : n;
  313. if (len == 8 && !strncmp(buf, "hibabort", len)) {
  314. hib_log("abort hibernation...\n");
  315. error = mtk_hibernate_abort();
  316. goto out;
  317. }
  318. #endif
  319. pr_warn("[%s]: state = (%d)\n", __func__, state);
  320. if (state < PM_SUSPEND_MAX) {
  321. error = pm_suspend(state);
  322. pr_warn("[%s]: pm_suspend() return (%d)\n", __func__, error);
  323. } else if (state == PM_SUSPEND_MAX) {
  324. #ifdef CONFIG_MTK_HIBERNATION
  325. hib_log("trigger hibernation...\n");
  326. if (!pre_hibernate()) {
  327. error = 0;
  328. error = mtk_hibernate();
  329. }
  330. #else /* !CONFIG_MTK_HIBERNATION */
  331. error = hibernate();
  332. #endif /* CONFIG_MTK_HIBERNATION */
  333. } else {
  334. error = -EINVAL;
  335. }
  336. out:
  337. pm_autosleep_unlock();
  338. return error ? error : n;
  339. }
  340. power_attr(state);
  341. #ifdef CONFIG_PM_SLEEP
  342. /*
  343. * The 'wakeup_count' attribute, along with the functions defined in
  344. * drivers/base/power/wakeup.c, provides a means by which wakeup events can be
  345. * handled in a non-racy way.
  346. *
  347. * If a wakeup event occurs when the system is in a sleep state, it simply is
  348. * woken up. In turn, if an event that would wake the system up from a sleep
  349. * state occurs when it is undergoing a transition to that sleep state, the
  350. * transition should be aborted. Moreover, if such an event occurs when the
  351. * system is in the working state, an attempt to start a transition to the
  352. * given sleep state should fail during certain period after the detection of
  353. * the event. Using the 'state' attribute alone is not sufficient to satisfy
  354. * these requirements, because a wakeup event may occur exactly when 'state'
  355. * is being written to and may be delivered to user space right before it is
  356. * frozen, so the event will remain only partially processed until the system is
  357. * woken up by another event. In particular, it won't cause the transition to
  358. * a sleep state to be aborted.
  359. *
  360. * This difficulty may be overcome if user space uses 'wakeup_count' before
  361. * writing to 'state'. It first should read from 'wakeup_count' and store
  362. * the read value. Then, after carrying out its own preparations for the system
  363. * transition to a sleep state, it should write the stored value to
  364. * 'wakeup_count'. If that fails, at least one wakeup event has occurred since
  365. * 'wakeup_count' was read and 'state' should not be written to. Otherwise, it
  366. * is allowed to write to 'state', but the transition will be aborted if there
  367. * are any wakeup events detected after 'wakeup_count' was written to.
  368. */
  369. static ssize_t wakeup_count_show(struct kobject *kobj,
  370. struct kobj_attribute *attr,
  371. char *buf)
  372. {
  373. unsigned int val;
  374. return pm_get_wakeup_count(&val, true) ?
  375. sprintf(buf, "%u\n", val) : -EINTR;
  376. }
  377. static ssize_t wakeup_count_store(struct kobject *kobj,
  378. struct kobj_attribute *attr,
  379. const char *buf, size_t n)
  380. {
  381. unsigned int val;
  382. int error;
  383. error = pm_autosleep_lock();
  384. if (error)
  385. return error;
  386. if (pm_autosleep_state() > PM_SUSPEND_ON) {
  387. error = -EBUSY;
  388. goto out;
  389. }
  390. error = -EINVAL;
  391. if (sscanf(buf, "%u", &val) == 1) {
  392. if (pm_save_wakeup_count(val))
  393. error = n;
  394. else
  395. pm_print_active_wakeup_sources();
  396. }
  397. out:
  398. pm_autosleep_unlock();
  399. return error;
  400. }
  401. power_attr(wakeup_count);
  402. #ifdef CONFIG_PM_AUTOSLEEP
  403. static ssize_t autosleep_show(struct kobject *kobj,
  404. struct kobj_attribute *attr,
  405. char *buf)
  406. {
  407. suspend_state_t state = pm_autosleep_state();
  408. if (state == PM_SUSPEND_ON)
  409. return sprintf(buf, "off\n");
  410. #ifdef CONFIG_SUSPEND
  411. if (state < PM_SUSPEND_MAX)
  412. return sprintf(buf, "%s\n", pm_states[state] ?
  413. pm_states[state] : "error");
  414. #endif
  415. #ifdef CONFIG_HIBERNATION
  416. return sprintf(buf, "disk\n");
  417. #else
  418. return sprintf(buf, "error");
  419. #endif
  420. }
  421. static ssize_t autosleep_store(struct kobject *kobj,
  422. struct kobj_attribute *attr,
  423. const char *buf, size_t n)
  424. {
  425. suspend_state_t state = decode_state(buf, n);
  426. int error;
  427. if (state == PM_SUSPEND_ON
  428. && strcmp(buf, "off") && strcmp(buf, "off\n"))
  429. return -EINVAL;
  430. error = pm_autosleep_set_state(state);
  431. return error ? error : n;
  432. }
  433. power_attr(autosleep);
  434. #endif /* CONFIG_PM_AUTOSLEEP */
  435. #ifdef CONFIG_PM_WAKELOCKS
  436. static ssize_t wake_lock_show(struct kobject *kobj,
  437. struct kobj_attribute *attr,
  438. char *buf)
  439. {
  440. return pm_show_wakelocks(buf, true);
  441. }
  442. static ssize_t wake_lock_store(struct kobject *kobj,
  443. struct kobj_attribute *attr,
  444. const char *buf, size_t n)
  445. {
  446. int error = pm_wake_lock(buf);
  447. return error ? error : n;
  448. }
  449. power_attr(wake_lock);
  450. static ssize_t wake_unlock_show(struct kobject *kobj,
  451. struct kobj_attribute *attr,
  452. char *buf)
  453. {
  454. return pm_show_wakelocks(buf, false);
  455. }
  456. static ssize_t wake_unlock_store(struct kobject *kobj,
  457. struct kobj_attribute *attr,
  458. const char *buf, size_t n)
  459. {
  460. int error = pm_wake_unlock(buf);
  461. return error ? error : n;
  462. }
  463. power_attr(wake_unlock);
  464. #endif /* CONFIG_PM_WAKELOCKS */
  465. #endif /* CONFIG_PM_SLEEP */
  466. #ifdef CONFIG_PM_TRACE
  467. int pm_trace_enabled;
  468. static ssize_t pm_trace_show(struct kobject *kobj, struct kobj_attribute *attr,
  469. char *buf)
  470. {
  471. return sprintf(buf, "%d\n", pm_trace_enabled);
  472. }
  473. static ssize_t
  474. pm_trace_store(struct kobject *kobj, struct kobj_attribute *attr,
  475. const char *buf, size_t n)
  476. {
  477. int val;
  478. if (sscanf(buf, "%d", &val) == 1) {
  479. pm_trace_enabled = !!val;
  480. if (pm_trace_enabled) {
  481. pr_warn("PM: Enabling pm_trace changes system date and time during resume.\n"
  482. "PM: Correct system time has to be restored manually after resume.\n");
  483. }
  484. return n;
  485. }
  486. return -EINVAL;
  487. }
  488. power_attr(pm_trace);
  489. static ssize_t pm_trace_dev_match_show(struct kobject *kobj,
  490. struct kobj_attribute *attr,
  491. char *buf)
  492. {
  493. return show_trace_dev_match(buf, PAGE_SIZE);
  494. }
  495. static ssize_t
  496. pm_trace_dev_match_store(struct kobject *kobj, struct kobj_attribute *attr,
  497. const char *buf, size_t n)
  498. {
  499. return -EINVAL;
  500. }
  501. power_attr(pm_trace_dev_match);
  502. #endif /* CONFIG_PM_TRACE */
  503. #ifdef CONFIG_FREEZER
  504. static ssize_t pm_freeze_timeout_show(struct kobject *kobj,
  505. struct kobj_attribute *attr, char *buf)
  506. {
  507. return sprintf(buf, "%u\n", freeze_timeout_msecs);
  508. }
  509. static ssize_t pm_freeze_timeout_store(struct kobject *kobj,
  510. struct kobj_attribute *attr,
  511. const char *buf, size_t n)
  512. {
  513. unsigned long val;
  514. if (kstrtoul(buf, 10, &val))
  515. return -EINVAL;
  516. freeze_timeout_msecs = val;
  517. return n;
  518. }
  519. power_attr(pm_freeze_timeout);
  520. #endif /* CONFIG_FREEZER*/
  521. static struct attribute * g[] = {
  522. &state_attr.attr,
  523. #ifdef CONFIG_PM_TRACE
  524. &pm_trace_attr.attr,
  525. &pm_trace_dev_match_attr.attr,
  526. #endif
  527. #ifdef CONFIG_PM_SLEEP
  528. &pm_async_attr.attr,
  529. &wakeup_count_attr.attr,
  530. #ifdef CONFIG_PM_AUTOSLEEP
  531. &autosleep_attr.attr,
  532. #endif
  533. #ifdef CONFIG_PM_WAKELOCKS
  534. &wake_lock_attr.attr,
  535. &wake_unlock_attr.attr,
  536. #endif
  537. #ifdef CONFIG_PM_DEBUG
  538. &pm_test_attr.attr,
  539. #endif
  540. #ifdef CONFIG_PM_SLEEP_DEBUG
  541. &pm_print_times_attr.attr,
  542. #endif
  543. #endif
  544. #ifdef CONFIG_FREEZER
  545. &pm_freeze_timeout_attr.attr,
  546. #endif
  547. NULL,
  548. };
  549. static struct attribute_group attr_group = {
  550. .attrs = g,
  551. };
  552. struct workqueue_struct *pm_wq;
  553. EXPORT_SYMBOL_GPL(pm_wq);
  554. static int __init pm_start_workqueue(void)
  555. {
  556. pm_wq = alloc_workqueue("pm", WQ_FREEZABLE, 0);
  557. return pm_wq ? 0 : -ENOMEM;
  558. }
  559. static int __init pm_init(void)
  560. {
  561. int error = pm_start_workqueue();
  562. if (error)
  563. return error;
  564. hibernate_image_size_init();
  565. hibernate_reserved_size_init();
  566. power_kobj = kobject_create_and_add("power", NULL);
  567. if (!power_kobj)
  568. return -ENOMEM;
  569. error = sysfs_create_group(power_kobj, &attr_group);
  570. if (error)
  571. return error;
  572. pm_print_times_init();
  573. return pm_autosleep_init();
  574. }
  575. core_initcall(pm_init);