main.c 17 KB

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