sleep.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /*
  2. * sleep.c - ACPI sleep support.
  3. *
  4. * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
  5. * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
  6. * Copyright (c) 2000-2003 Patrick Mochel
  7. * Copyright (c) 2003 Open Source Development Lab
  8. *
  9. * This file is released under the GPLv2.
  10. *
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/irq.h>
  14. #include <linux/dmi.h>
  15. #include <linux/device.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/suspend.h>
  18. #include <linux/reboot.h>
  19. #include <linux/acpi.h>
  20. #include <linux/module.h>
  21. #include <linux/syscore_ops.h>
  22. #include <asm/io.h>
  23. #include <trace/events/power.h>
  24. #include "internal.h"
  25. #include "sleep.h"
  26. /*
  27. * Some HW-full platforms do not have _S5, so they may need
  28. * to leverage efi power off for a shutdown.
  29. */
  30. bool acpi_no_s5;
  31. static u8 sleep_states[ACPI_S_STATE_COUNT];
  32. static void acpi_sleep_tts_switch(u32 acpi_state)
  33. {
  34. acpi_status status;
  35. status = acpi_execute_simple_method(NULL, "\\_TTS", acpi_state);
  36. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  37. /*
  38. * OS can't evaluate the _TTS object correctly. Some warning
  39. * message will be printed. But it won't break anything.
  40. */
  41. printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
  42. }
  43. }
  44. static int tts_notify_reboot(struct notifier_block *this,
  45. unsigned long code, void *x)
  46. {
  47. acpi_sleep_tts_switch(ACPI_STATE_S5);
  48. return NOTIFY_DONE;
  49. }
  50. static struct notifier_block tts_notifier = {
  51. .notifier_call = tts_notify_reboot,
  52. .next = NULL,
  53. .priority = 0,
  54. };
  55. static int acpi_sleep_prepare(u32 acpi_state)
  56. {
  57. #ifdef CONFIG_ACPI_SLEEP
  58. /* do we have a wakeup address for S2 and S3? */
  59. if (acpi_state == ACPI_STATE_S3) {
  60. if (!acpi_wakeup_address)
  61. return -EFAULT;
  62. acpi_set_waking_vector(acpi_wakeup_address);
  63. }
  64. ACPI_FLUSH_CPU_CACHE();
  65. #endif
  66. printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
  67. acpi_state);
  68. acpi_enable_wakeup_devices(acpi_state);
  69. acpi_enter_sleep_state_prep(acpi_state);
  70. return 0;
  71. }
  72. static bool acpi_sleep_state_supported(u8 sleep_state)
  73. {
  74. acpi_status status;
  75. u8 type_a, type_b;
  76. status = acpi_get_sleep_type_data(sleep_state, &type_a, &type_b);
  77. return ACPI_SUCCESS(status) && (!acpi_gbl_reduced_hardware
  78. || (acpi_gbl_FADT.sleep_control.address
  79. && acpi_gbl_FADT.sleep_status.address));
  80. }
  81. #ifdef CONFIG_ACPI_SLEEP
  82. static u32 acpi_target_sleep_state = ACPI_STATE_S0;
  83. u32 acpi_target_system_state(void)
  84. {
  85. return acpi_target_sleep_state;
  86. }
  87. EXPORT_SYMBOL_GPL(acpi_target_system_state);
  88. static bool pwr_btn_event_pending;
  89. /*
  90. * The ACPI specification wants us to save NVS memory regions during hibernation
  91. * and to restore them during the subsequent resume. Windows does that also for
  92. * suspend to RAM. However, it is known that this mechanism does not work on
  93. * all machines, so we allow the user to disable it with the help of the
  94. * 'acpi_sleep=nonvs' kernel command line option.
  95. */
  96. static bool nvs_nosave;
  97. void __init acpi_nvs_nosave(void)
  98. {
  99. nvs_nosave = true;
  100. }
  101. /*
  102. * The ACPI specification wants us to save NVS memory regions during hibernation
  103. * but says nothing about saving NVS during S3. Not all versions of Windows
  104. * save NVS on S3 suspend either, and it is clear that not all systems need
  105. * NVS to be saved at S3 time. To improve suspend/resume time, allow the
  106. * user to disable saving NVS on S3 if their system does not require it, but
  107. * continue to save/restore NVS for S4 as specified.
  108. */
  109. static bool nvs_nosave_s3;
  110. void __init acpi_nvs_nosave_s3(void)
  111. {
  112. nvs_nosave_s3 = true;
  113. }
  114. static int __init init_nvs_save_s3(const struct dmi_system_id *d)
  115. {
  116. nvs_nosave_s3 = false;
  117. return 0;
  118. }
  119. /*
  120. * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
  121. * user to request that behavior by using the 'acpi_old_suspend_ordering'
  122. * kernel command line option that causes the following variable to be set.
  123. */
  124. static bool old_suspend_ordering;
  125. void __init acpi_old_suspend_ordering(void)
  126. {
  127. old_suspend_ordering = true;
  128. }
  129. static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
  130. {
  131. acpi_old_suspend_ordering();
  132. return 0;
  133. }
  134. static int __init init_nvs_nosave(const struct dmi_system_id *d)
  135. {
  136. acpi_nvs_nosave();
  137. return 0;
  138. }
  139. static bool acpi_sleep_no_lps0;
  140. static int __init init_no_lps0(const struct dmi_system_id *d)
  141. {
  142. acpi_sleep_no_lps0 = true;
  143. return 0;
  144. }
  145. static const struct dmi_system_id acpisleep_dmi_table[] __initconst = {
  146. {
  147. .callback = init_old_suspend_ordering,
  148. .ident = "Abit KN9 (nForce4 variant)",
  149. .matches = {
  150. DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
  151. DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
  152. },
  153. },
  154. {
  155. .callback = init_old_suspend_ordering,
  156. .ident = "HP xw4600 Workstation",
  157. .matches = {
  158. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  159. DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
  160. },
  161. },
  162. {
  163. .callback = init_old_suspend_ordering,
  164. .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
  165. .matches = {
  166. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
  167. DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
  168. },
  169. },
  170. {
  171. .callback = init_old_suspend_ordering,
  172. .ident = "Panasonic CF51-2L",
  173. .matches = {
  174. DMI_MATCH(DMI_BOARD_VENDOR,
  175. "Matsushita Electric Industrial Co.,Ltd."),
  176. DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
  177. },
  178. },
  179. {
  180. .callback = init_nvs_nosave,
  181. .ident = "Sony Vaio VGN-FW41E_H",
  182. .matches = {
  183. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  184. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW41E_H"),
  185. },
  186. },
  187. {
  188. .callback = init_nvs_nosave,
  189. .ident = "Sony Vaio VGN-FW21E",
  190. .matches = {
  191. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  192. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
  193. },
  194. },
  195. {
  196. .callback = init_nvs_nosave,
  197. .ident = "Sony Vaio VGN-FW21M",
  198. .matches = {
  199. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  200. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21M"),
  201. },
  202. },
  203. {
  204. .callback = init_nvs_nosave,
  205. .ident = "Sony Vaio VPCEB17FX",
  206. .matches = {
  207. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  208. DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
  209. },
  210. },
  211. {
  212. .callback = init_nvs_nosave,
  213. .ident = "Sony Vaio VGN-SR11M",
  214. .matches = {
  215. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  216. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
  217. },
  218. },
  219. {
  220. .callback = init_nvs_nosave,
  221. .ident = "Everex StepNote Series",
  222. .matches = {
  223. DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
  224. DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
  225. },
  226. },
  227. {
  228. .callback = init_nvs_nosave,
  229. .ident = "Sony Vaio VPCEB1Z1E",
  230. .matches = {
  231. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  232. DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
  233. },
  234. },
  235. {
  236. .callback = init_nvs_nosave,
  237. .ident = "Sony Vaio VGN-NW130D",
  238. .matches = {
  239. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  240. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
  241. },
  242. },
  243. {
  244. .callback = init_nvs_nosave,
  245. .ident = "Sony Vaio VPCCW29FX",
  246. .matches = {
  247. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  248. DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
  249. },
  250. },
  251. {
  252. .callback = init_nvs_nosave,
  253. .ident = "Averatec AV1020-ED2",
  254. .matches = {
  255. DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
  256. DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
  257. },
  258. },
  259. {
  260. .callback = init_old_suspend_ordering,
  261. .ident = "Asus A8N-SLI DELUXE",
  262. .matches = {
  263. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  264. DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
  265. },
  266. },
  267. {
  268. .callback = init_old_suspend_ordering,
  269. .ident = "Asus A8N-SLI Premium",
  270. .matches = {
  271. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  272. DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
  273. },
  274. },
  275. {
  276. .callback = init_nvs_nosave,
  277. .ident = "Sony Vaio VGN-SR26GN_P",
  278. .matches = {
  279. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  280. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
  281. },
  282. },
  283. {
  284. .callback = init_nvs_nosave,
  285. .ident = "Sony Vaio VPCEB1S1E",
  286. .matches = {
  287. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  288. DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1S1E"),
  289. },
  290. },
  291. {
  292. .callback = init_nvs_nosave,
  293. .ident = "Sony Vaio VGN-FW520F",
  294. .matches = {
  295. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  296. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
  297. },
  298. },
  299. {
  300. .callback = init_nvs_nosave,
  301. .ident = "Asus K54C",
  302. .matches = {
  303. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  304. DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
  305. },
  306. },
  307. {
  308. .callback = init_nvs_nosave,
  309. .ident = "Asus K54HR",
  310. .matches = {
  311. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  312. DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
  313. },
  314. },
  315. /*
  316. * https://bugzilla.kernel.org/show_bug.cgi?id=189431
  317. * Lenovo G50-45 is a platform later than 2012, but needs nvs memory
  318. * saving during S3.
  319. */
  320. {
  321. .callback = init_nvs_save_s3,
  322. .ident = "Lenovo G50-45",
  323. .matches = {
  324. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  325. DMI_MATCH(DMI_PRODUCT_NAME, "80E3"),
  326. },
  327. },
  328. /*
  329. * https://bugzilla.kernel.org/show_bug.cgi?id=196907
  330. * Some Dell XPS13 9360 cannot do suspend-to-idle using the Low Power
  331. * S0 Idle firmware interface.
  332. */
  333. {
  334. .callback = init_no_lps0,
  335. .ident = "Dell XPS13 9360",
  336. .matches = {
  337. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  338. DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"),
  339. },
  340. },
  341. /*
  342. * ThinkPad X1 Tablet(2016) cannot do suspend-to-idle using
  343. * the Low Power S0 Idle firmware interface (see
  344. * https://bugzilla.kernel.org/show_bug.cgi?id=199057).
  345. */
  346. {
  347. .callback = init_no_lps0,
  348. .ident = "ThinkPad X1 Tablet(2016)",
  349. .matches = {
  350. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  351. DMI_MATCH(DMI_PRODUCT_NAME, "20GGA00L00"),
  352. },
  353. },
  354. {},
  355. };
  356. static bool ignore_blacklist;
  357. void __init acpi_sleep_no_blacklist(void)
  358. {
  359. ignore_blacklist = true;
  360. }
  361. static void __init acpi_sleep_dmi_check(void)
  362. {
  363. if (ignore_blacklist)
  364. return;
  365. if (dmi_get_bios_year() >= 2012)
  366. acpi_nvs_nosave_s3();
  367. dmi_check_system(acpisleep_dmi_table);
  368. }
  369. /**
  370. * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
  371. */
  372. static int acpi_pm_freeze(void)
  373. {
  374. acpi_disable_all_gpes();
  375. acpi_os_wait_events_complete();
  376. acpi_ec_block_transactions();
  377. return 0;
  378. }
  379. /**
  380. * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
  381. */
  382. static int acpi_pm_pre_suspend(void)
  383. {
  384. acpi_pm_freeze();
  385. return suspend_nvs_save();
  386. }
  387. /**
  388. * __acpi_pm_prepare - Prepare the platform to enter the target state.
  389. *
  390. * If necessary, set the firmware waking vector and do arch-specific
  391. * nastiness to get the wakeup code to the waking vector.
  392. */
  393. static int __acpi_pm_prepare(void)
  394. {
  395. int error = acpi_sleep_prepare(acpi_target_sleep_state);
  396. if (error)
  397. acpi_target_sleep_state = ACPI_STATE_S0;
  398. return error;
  399. }
  400. /**
  401. * acpi_pm_prepare - Prepare the platform to enter the target sleep
  402. * state and disable the GPEs.
  403. */
  404. static int acpi_pm_prepare(void)
  405. {
  406. int error = __acpi_pm_prepare();
  407. if (!error)
  408. error = acpi_pm_pre_suspend();
  409. return error;
  410. }
  411. static int find_powerf_dev(struct device *dev, void *data)
  412. {
  413. struct acpi_device *device = to_acpi_device(dev);
  414. const char *hid = acpi_device_hid(device);
  415. return !strcmp(hid, ACPI_BUTTON_HID_POWERF);
  416. }
  417. /**
  418. * acpi_pm_finish - Instruct the platform to leave a sleep state.
  419. *
  420. * This is called after we wake back up (or if entering the sleep state
  421. * failed).
  422. */
  423. static void acpi_pm_finish(void)
  424. {
  425. struct device *pwr_btn_dev;
  426. u32 acpi_state = acpi_target_sleep_state;
  427. acpi_ec_unblock_transactions();
  428. suspend_nvs_free();
  429. if (acpi_state == ACPI_STATE_S0)
  430. return;
  431. printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
  432. acpi_state);
  433. acpi_disable_wakeup_devices(acpi_state);
  434. acpi_leave_sleep_state(acpi_state);
  435. /* reset firmware waking vector */
  436. acpi_set_waking_vector(0);
  437. acpi_target_sleep_state = ACPI_STATE_S0;
  438. acpi_resume_power_resources();
  439. /* If we were woken with the fixed power button, provide a small
  440. * hint to userspace in the form of a wakeup event on the fixed power
  441. * button device (if it can be found).
  442. *
  443. * We delay the event generation til now, as the PM layer requires
  444. * timekeeping to be running before we generate events. */
  445. if (!pwr_btn_event_pending)
  446. return;
  447. pwr_btn_event_pending = false;
  448. pwr_btn_dev = bus_find_device(&acpi_bus_type, NULL, NULL,
  449. find_powerf_dev);
  450. if (pwr_btn_dev) {
  451. pm_wakeup_event(pwr_btn_dev, 0);
  452. put_device(pwr_btn_dev);
  453. }
  454. }
  455. /**
  456. * acpi_pm_start - Start system PM transition.
  457. */
  458. static void acpi_pm_start(u32 acpi_state)
  459. {
  460. acpi_target_sleep_state = acpi_state;
  461. acpi_sleep_tts_switch(acpi_target_sleep_state);
  462. acpi_scan_lock_acquire();
  463. }
  464. /**
  465. * acpi_pm_end - Finish up system PM transition.
  466. */
  467. static void acpi_pm_end(void)
  468. {
  469. acpi_turn_off_unused_power_resources();
  470. acpi_scan_lock_release();
  471. /*
  472. * This is necessary in case acpi_pm_finish() is not called during a
  473. * failing transition to a sleep state.
  474. */
  475. acpi_target_sleep_state = ACPI_STATE_S0;
  476. acpi_sleep_tts_switch(acpi_target_sleep_state);
  477. }
  478. #else /* !CONFIG_ACPI_SLEEP */
  479. #define acpi_target_sleep_state ACPI_STATE_S0
  480. #define acpi_sleep_no_lps0 (false)
  481. static inline void acpi_sleep_dmi_check(void) {}
  482. #endif /* CONFIG_ACPI_SLEEP */
  483. #ifdef CONFIG_SUSPEND
  484. static u32 acpi_suspend_states[] = {
  485. [PM_SUSPEND_ON] = ACPI_STATE_S0,
  486. [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
  487. [PM_SUSPEND_MEM] = ACPI_STATE_S3,
  488. [PM_SUSPEND_MAX] = ACPI_STATE_S5
  489. };
  490. /**
  491. * acpi_suspend_begin - Set the target system sleep state to the state
  492. * associated with given @pm_state, if supported.
  493. */
  494. static int acpi_suspend_begin(suspend_state_t pm_state)
  495. {
  496. u32 acpi_state = acpi_suspend_states[pm_state];
  497. int error;
  498. error = (nvs_nosave || nvs_nosave_s3) ? 0 : suspend_nvs_alloc();
  499. if (error)
  500. return error;
  501. if (!sleep_states[acpi_state]) {
  502. pr_err("ACPI does not support sleep state S%u\n", acpi_state);
  503. return -ENOSYS;
  504. }
  505. if (acpi_state > ACPI_STATE_S1)
  506. pm_set_suspend_via_firmware();
  507. acpi_pm_start(acpi_state);
  508. return 0;
  509. }
  510. /**
  511. * acpi_suspend_enter - Actually enter a sleep state.
  512. * @pm_state: ignored
  513. *
  514. * Flush caches and go to sleep. For STR we have to call arch-specific
  515. * assembly, which in turn call acpi_enter_sleep_state().
  516. * It's unfortunate, but it works. Please fix if you're feeling frisky.
  517. */
  518. static int acpi_suspend_enter(suspend_state_t pm_state)
  519. {
  520. acpi_status status = AE_OK;
  521. u32 acpi_state = acpi_target_sleep_state;
  522. int error;
  523. ACPI_FLUSH_CPU_CACHE();
  524. trace_suspend_resume(TPS("acpi_suspend"), acpi_state, true);
  525. switch (acpi_state) {
  526. case ACPI_STATE_S1:
  527. barrier();
  528. status = acpi_enter_sleep_state(acpi_state);
  529. break;
  530. case ACPI_STATE_S3:
  531. if (!acpi_suspend_lowlevel)
  532. return -ENOSYS;
  533. error = acpi_suspend_lowlevel();
  534. if (error)
  535. return error;
  536. pr_info(PREFIX "Low-level resume complete\n");
  537. pm_set_resume_via_firmware();
  538. break;
  539. }
  540. trace_suspend_resume(TPS("acpi_suspend"), acpi_state, false);
  541. /* This violates the spec but is required for bug compatibility. */
  542. acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
  543. /* Reprogram control registers */
  544. acpi_leave_sleep_state_prep(acpi_state);
  545. /* ACPI 3.0 specs (P62) says that it's the responsibility
  546. * of the OSPM to clear the status bit [ implying that the
  547. * POWER_BUTTON event should not reach userspace ]
  548. *
  549. * However, we do generate a small hint for userspace in the form of
  550. * a wakeup event. We flag this condition for now and generate the
  551. * event later, as we're currently too early in resume to be able to
  552. * generate wakeup events.
  553. */
  554. if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) {
  555. acpi_event_status pwr_btn_status = ACPI_EVENT_FLAG_DISABLED;
  556. acpi_get_event_status(ACPI_EVENT_POWER_BUTTON, &pwr_btn_status);
  557. if (pwr_btn_status & ACPI_EVENT_FLAG_STATUS_SET) {
  558. acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
  559. /* Flag for later */
  560. pwr_btn_event_pending = true;
  561. }
  562. }
  563. /*
  564. * Disable and clear GPE status before interrupt is enabled. Some GPEs
  565. * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
  566. * acpi_leave_sleep_state will reenable specific GPEs later
  567. */
  568. acpi_disable_all_gpes();
  569. /* Allow EC transactions to happen. */
  570. acpi_ec_unblock_transactions();
  571. suspend_nvs_restore();
  572. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  573. }
  574. static int acpi_suspend_state_valid(suspend_state_t pm_state)
  575. {
  576. u32 acpi_state;
  577. switch (pm_state) {
  578. case PM_SUSPEND_ON:
  579. case PM_SUSPEND_STANDBY:
  580. case PM_SUSPEND_MEM:
  581. acpi_state = acpi_suspend_states[pm_state];
  582. return sleep_states[acpi_state];
  583. default:
  584. return 0;
  585. }
  586. }
  587. static const struct platform_suspend_ops acpi_suspend_ops = {
  588. .valid = acpi_suspend_state_valid,
  589. .begin = acpi_suspend_begin,
  590. .prepare_late = acpi_pm_prepare,
  591. .enter = acpi_suspend_enter,
  592. .wake = acpi_pm_finish,
  593. .end = acpi_pm_end,
  594. };
  595. /**
  596. * acpi_suspend_begin_old - Set the target system sleep state to the
  597. * state associated with given @pm_state, if supported, and
  598. * execute the _PTS control method. This function is used if the
  599. * pre-ACPI 2.0 suspend ordering has been requested.
  600. */
  601. static int acpi_suspend_begin_old(suspend_state_t pm_state)
  602. {
  603. int error = acpi_suspend_begin(pm_state);
  604. if (!error)
  605. error = __acpi_pm_prepare();
  606. return error;
  607. }
  608. /*
  609. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  610. * been requested.
  611. */
  612. static const struct platform_suspend_ops acpi_suspend_ops_old = {
  613. .valid = acpi_suspend_state_valid,
  614. .begin = acpi_suspend_begin_old,
  615. .prepare_late = acpi_pm_pre_suspend,
  616. .enter = acpi_suspend_enter,
  617. .wake = acpi_pm_finish,
  618. .end = acpi_pm_end,
  619. .recover = acpi_pm_finish,
  620. };
  621. static bool s2idle_in_progress;
  622. static bool s2idle_wakeup;
  623. /*
  624. * On platforms supporting the Low Power S0 Idle interface there is an ACPI
  625. * device object with the PNP0D80 compatible device ID (System Power Management
  626. * Controller) and a specific _DSM method under it. That method, if present,
  627. * can be used to indicate to the platform that the OS is transitioning into a
  628. * low-power state in which certain types of activity are not desirable or that
  629. * it is leaving such a state, which allows the platform to adjust its operation
  630. * mode accordingly.
  631. */
  632. static const struct acpi_device_id lps0_device_ids[] = {
  633. {"PNP0D80", },
  634. {"", },
  635. };
  636. #define ACPI_LPS0_DSM_UUID "c4eb40a0-6cd2-11e2-bcfd-0800200c9a66"
  637. #define ACPI_LPS0_GET_DEVICE_CONSTRAINTS 1
  638. #define ACPI_LPS0_SCREEN_OFF 3
  639. #define ACPI_LPS0_SCREEN_ON 4
  640. #define ACPI_LPS0_ENTRY 5
  641. #define ACPI_LPS0_EXIT 6
  642. #define ACPI_LPS0_SCREEN_MASK ((1 << ACPI_LPS0_SCREEN_OFF) | (1 << ACPI_LPS0_SCREEN_ON))
  643. #define ACPI_LPS0_PLATFORM_MASK ((1 << ACPI_LPS0_ENTRY) | (1 << ACPI_LPS0_EXIT))
  644. static acpi_handle lps0_device_handle;
  645. static guid_t lps0_dsm_guid;
  646. static char lps0_dsm_func_mask;
  647. /* Device constraint entry structure */
  648. struct lpi_device_info {
  649. char *name;
  650. int enabled;
  651. union acpi_object *package;
  652. };
  653. /* Constraint package structure */
  654. struct lpi_device_constraint {
  655. int uid;
  656. int min_dstate;
  657. int function_states;
  658. };
  659. struct lpi_constraints {
  660. acpi_handle handle;
  661. int min_dstate;
  662. };
  663. static struct lpi_constraints *lpi_constraints_table;
  664. static int lpi_constraints_table_size;
  665. static void lpi_device_get_constraints(void)
  666. {
  667. union acpi_object *out_obj;
  668. int i;
  669. out_obj = acpi_evaluate_dsm_typed(lps0_device_handle, &lps0_dsm_guid,
  670. 1, ACPI_LPS0_GET_DEVICE_CONSTRAINTS,
  671. NULL, ACPI_TYPE_PACKAGE);
  672. acpi_handle_debug(lps0_device_handle, "_DSM function 1 eval %s\n",
  673. out_obj ? "successful" : "failed");
  674. if (!out_obj)
  675. return;
  676. lpi_constraints_table = kcalloc(out_obj->package.count,
  677. sizeof(*lpi_constraints_table),
  678. GFP_KERNEL);
  679. if (!lpi_constraints_table)
  680. goto free_acpi_buffer;
  681. acpi_handle_debug(lps0_device_handle, "LPI: constraints list begin:\n");
  682. for (i = 0; i < out_obj->package.count; i++) {
  683. struct lpi_constraints *constraint;
  684. acpi_status status;
  685. union acpi_object *package = &out_obj->package.elements[i];
  686. struct lpi_device_info info = { };
  687. int package_count = 0, j;
  688. if (!package)
  689. continue;
  690. for (j = 0; j < package->package.count; ++j) {
  691. union acpi_object *element =
  692. &(package->package.elements[j]);
  693. switch (element->type) {
  694. case ACPI_TYPE_INTEGER:
  695. info.enabled = element->integer.value;
  696. break;
  697. case ACPI_TYPE_STRING:
  698. info.name = element->string.pointer;
  699. break;
  700. case ACPI_TYPE_PACKAGE:
  701. package_count = element->package.count;
  702. info.package = element->package.elements;
  703. break;
  704. }
  705. }
  706. if (!info.enabled || !info.package || !info.name)
  707. continue;
  708. constraint = &lpi_constraints_table[lpi_constraints_table_size];
  709. status = acpi_get_handle(NULL, info.name, &constraint->handle);
  710. if (ACPI_FAILURE(status))
  711. continue;
  712. acpi_handle_debug(lps0_device_handle,
  713. "index:%d Name:%s\n", i, info.name);
  714. constraint->min_dstate = -1;
  715. for (j = 0; j < package_count; ++j) {
  716. union acpi_object *info_obj = &info.package[j];
  717. union acpi_object *cnstr_pkg;
  718. union acpi_object *obj;
  719. struct lpi_device_constraint dev_info;
  720. switch (info_obj->type) {
  721. case ACPI_TYPE_INTEGER:
  722. /* version */
  723. break;
  724. case ACPI_TYPE_PACKAGE:
  725. if (info_obj->package.count < 2)
  726. break;
  727. cnstr_pkg = info_obj->package.elements;
  728. obj = &cnstr_pkg[0];
  729. dev_info.uid = obj->integer.value;
  730. obj = &cnstr_pkg[1];
  731. dev_info.min_dstate = obj->integer.value;
  732. acpi_handle_debug(lps0_device_handle,
  733. "uid:%d min_dstate:%s\n",
  734. dev_info.uid,
  735. acpi_power_state_string(dev_info.min_dstate));
  736. constraint->min_dstate = dev_info.min_dstate;
  737. break;
  738. }
  739. }
  740. if (constraint->min_dstate < 0) {
  741. acpi_handle_debug(lps0_device_handle,
  742. "Incomplete constraint defined\n");
  743. continue;
  744. }
  745. lpi_constraints_table_size++;
  746. }
  747. acpi_handle_debug(lps0_device_handle, "LPI: constraints list end\n");
  748. free_acpi_buffer:
  749. ACPI_FREE(out_obj);
  750. }
  751. static void lpi_check_constraints(void)
  752. {
  753. int i;
  754. for (i = 0; i < lpi_constraints_table_size; ++i) {
  755. acpi_handle handle = lpi_constraints_table[i].handle;
  756. struct acpi_device *adev;
  757. if (!handle || acpi_bus_get_device(handle, &adev))
  758. continue;
  759. acpi_handle_debug(handle,
  760. "LPI: required min power state:%s current power state:%s\n",
  761. acpi_power_state_string(lpi_constraints_table[i].min_dstate),
  762. acpi_power_state_string(adev->power.state));
  763. if (!adev->flags.power_manageable) {
  764. acpi_handle_info(handle, "LPI: Device not power manageable\n");
  765. lpi_constraints_table[i].handle = NULL;
  766. continue;
  767. }
  768. if (adev->power.state < lpi_constraints_table[i].min_dstate)
  769. acpi_handle_info(handle,
  770. "LPI: Constraint not met; min power state:%s current power state:%s\n",
  771. acpi_power_state_string(lpi_constraints_table[i].min_dstate),
  772. acpi_power_state_string(adev->power.state));
  773. }
  774. }
  775. static void acpi_sleep_run_lps0_dsm(unsigned int func)
  776. {
  777. union acpi_object *out_obj;
  778. if (!(lps0_dsm_func_mask & (1 << func)))
  779. return;
  780. out_obj = acpi_evaluate_dsm(lps0_device_handle, &lps0_dsm_guid, 1, func, NULL);
  781. ACPI_FREE(out_obj);
  782. acpi_handle_debug(lps0_device_handle, "_DSM function %u evaluation %s\n",
  783. func, out_obj ? "successful" : "failed");
  784. }
  785. static int lps0_device_attach(struct acpi_device *adev,
  786. const struct acpi_device_id *not_used)
  787. {
  788. union acpi_object *out_obj;
  789. if (lps0_device_handle)
  790. return 0;
  791. if (acpi_sleep_no_lps0) {
  792. acpi_handle_info(adev->handle,
  793. "Low Power S0 Idle interface disabled\n");
  794. return 0;
  795. }
  796. if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0))
  797. return 0;
  798. guid_parse(ACPI_LPS0_DSM_UUID, &lps0_dsm_guid);
  799. /* Check if the _DSM is present and as expected. */
  800. out_obj = acpi_evaluate_dsm(adev->handle, &lps0_dsm_guid, 1, 0, NULL);
  801. if (out_obj && out_obj->type == ACPI_TYPE_BUFFER) {
  802. char bitmask = *(char *)out_obj->buffer.pointer;
  803. if ((bitmask & ACPI_LPS0_PLATFORM_MASK) == ACPI_LPS0_PLATFORM_MASK ||
  804. (bitmask & ACPI_LPS0_SCREEN_MASK) == ACPI_LPS0_SCREEN_MASK) {
  805. lps0_dsm_func_mask = bitmask;
  806. lps0_device_handle = adev->handle;
  807. /*
  808. * Use suspend-to-idle by default if the default
  809. * suspend mode was not set from the command line.
  810. */
  811. if (mem_sleep_default > PM_SUSPEND_MEM)
  812. mem_sleep_current = PM_SUSPEND_TO_IDLE;
  813. }
  814. acpi_handle_debug(adev->handle, "_DSM function mask: 0x%x\n",
  815. bitmask);
  816. } else {
  817. acpi_handle_debug(adev->handle,
  818. "_DSM function 0 evaluation failed\n");
  819. }
  820. ACPI_FREE(out_obj);
  821. lpi_device_get_constraints();
  822. return 0;
  823. }
  824. static struct acpi_scan_handler lps0_handler = {
  825. .ids = lps0_device_ids,
  826. .attach = lps0_device_attach,
  827. };
  828. static int acpi_s2idle_begin(void)
  829. {
  830. acpi_scan_lock_acquire();
  831. s2idle_in_progress = true;
  832. return 0;
  833. }
  834. static int acpi_s2idle_prepare(void)
  835. {
  836. if (lps0_device_handle) {
  837. acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_OFF);
  838. acpi_sleep_run_lps0_dsm(ACPI_LPS0_ENTRY);
  839. }
  840. if (acpi_sci_irq_valid())
  841. enable_irq_wake(acpi_sci_irq);
  842. return 0;
  843. }
  844. static void acpi_s2idle_wake(void)
  845. {
  846. if (pm_debug_messages_on)
  847. lpi_check_constraints();
  848. /*
  849. * If IRQD_WAKEUP_ARMED is not set for the SCI at this point, it means
  850. * that the SCI has triggered while suspended, so cancel the wakeup in
  851. * case it has not been a wakeup event (the GPEs will be checked later).
  852. */
  853. if (acpi_sci_irq_valid() &&
  854. !irqd_is_wakeup_armed(irq_get_irq_data(acpi_sci_irq))) {
  855. pm_system_cancel_wakeup();
  856. s2idle_wakeup = true;
  857. }
  858. }
  859. static void acpi_s2idle_sync(void)
  860. {
  861. /*
  862. * Process all pending events in case there are any wakeup ones.
  863. *
  864. * The EC driver uses the system workqueue and an additional special
  865. * one, so those need to be flushed too.
  866. */
  867. acpi_os_wait_events_complete(); /* synchronize SCI IRQ handling */
  868. acpi_ec_flush_work();
  869. acpi_os_wait_events_complete(); /* synchronize Notify handling */
  870. s2idle_wakeup = false;
  871. }
  872. static void acpi_s2idle_restore(void)
  873. {
  874. if (acpi_sci_irq_valid())
  875. disable_irq_wake(acpi_sci_irq);
  876. if (lps0_device_handle) {
  877. acpi_sleep_run_lps0_dsm(ACPI_LPS0_EXIT);
  878. acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_ON);
  879. }
  880. }
  881. static void acpi_s2idle_end(void)
  882. {
  883. s2idle_in_progress = false;
  884. acpi_scan_lock_release();
  885. }
  886. static const struct platform_s2idle_ops acpi_s2idle_ops = {
  887. .begin = acpi_s2idle_begin,
  888. .prepare = acpi_s2idle_prepare,
  889. .wake = acpi_s2idle_wake,
  890. .sync = acpi_s2idle_sync,
  891. .restore = acpi_s2idle_restore,
  892. .end = acpi_s2idle_end,
  893. };
  894. static void acpi_sleep_suspend_setup(void)
  895. {
  896. int i;
  897. for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++)
  898. if (acpi_sleep_state_supported(i))
  899. sleep_states[i] = 1;
  900. suspend_set_ops(old_suspend_ordering ?
  901. &acpi_suspend_ops_old : &acpi_suspend_ops);
  902. acpi_scan_add_handler(&lps0_handler);
  903. s2idle_set_ops(&acpi_s2idle_ops);
  904. }
  905. #else /* !CONFIG_SUSPEND */
  906. #define s2idle_in_progress (false)
  907. #define s2idle_wakeup (false)
  908. #define lps0_device_handle (NULL)
  909. static inline void acpi_sleep_suspend_setup(void) {}
  910. #endif /* !CONFIG_SUSPEND */
  911. bool acpi_s2idle_wakeup(void)
  912. {
  913. return s2idle_wakeup;
  914. }
  915. bool acpi_sleep_no_ec_events(void)
  916. {
  917. return !s2idle_in_progress || !lps0_device_handle;
  918. }
  919. #ifdef CONFIG_PM_SLEEP
  920. static u32 saved_bm_rld;
  921. static int acpi_save_bm_rld(void)
  922. {
  923. acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &saved_bm_rld);
  924. return 0;
  925. }
  926. static void acpi_restore_bm_rld(void)
  927. {
  928. u32 resumed_bm_rld = 0;
  929. acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &resumed_bm_rld);
  930. if (resumed_bm_rld == saved_bm_rld)
  931. return;
  932. acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, saved_bm_rld);
  933. }
  934. static struct syscore_ops acpi_sleep_syscore_ops = {
  935. .suspend = acpi_save_bm_rld,
  936. .resume = acpi_restore_bm_rld,
  937. };
  938. static void acpi_sleep_syscore_init(void)
  939. {
  940. register_syscore_ops(&acpi_sleep_syscore_ops);
  941. }
  942. #else
  943. static inline void acpi_sleep_syscore_init(void) {}
  944. #endif /* CONFIG_PM_SLEEP */
  945. #ifdef CONFIG_HIBERNATION
  946. static unsigned long s4_hardware_signature;
  947. static struct acpi_table_facs *facs;
  948. static bool nosigcheck;
  949. void __init acpi_no_s4_hw_signature(void)
  950. {
  951. nosigcheck = true;
  952. }
  953. static int acpi_hibernation_begin(void)
  954. {
  955. int error;
  956. error = nvs_nosave ? 0 : suspend_nvs_alloc();
  957. if (!error)
  958. acpi_pm_start(ACPI_STATE_S4);
  959. return error;
  960. }
  961. static int acpi_hibernation_enter(void)
  962. {
  963. acpi_status status = AE_OK;
  964. ACPI_FLUSH_CPU_CACHE();
  965. /* This shouldn't return. If it returns, we have a problem */
  966. status = acpi_enter_sleep_state(ACPI_STATE_S4);
  967. /* Reprogram control registers */
  968. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  969. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  970. }
  971. static void acpi_hibernation_leave(void)
  972. {
  973. pm_set_resume_via_firmware();
  974. /*
  975. * If ACPI is not enabled by the BIOS and the boot kernel, we need to
  976. * enable it here.
  977. */
  978. acpi_enable();
  979. /* Reprogram control registers */
  980. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  981. /* Check the hardware signature */
  982. if (facs && s4_hardware_signature != facs->hardware_signature)
  983. pr_crit("ACPI: Hardware changed while hibernated, success doubtful!\n");
  984. /* Restore the NVS memory area */
  985. suspend_nvs_restore();
  986. /* Allow EC transactions to happen. */
  987. acpi_ec_unblock_transactions();
  988. }
  989. static void acpi_pm_thaw(void)
  990. {
  991. acpi_ec_unblock_transactions();
  992. acpi_enable_all_runtime_gpes();
  993. }
  994. static const struct platform_hibernation_ops acpi_hibernation_ops = {
  995. .begin = acpi_hibernation_begin,
  996. .end = acpi_pm_end,
  997. .pre_snapshot = acpi_pm_prepare,
  998. .finish = acpi_pm_finish,
  999. .prepare = acpi_pm_prepare,
  1000. .enter = acpi_hibernation_enter,
  1001. .leave = acpi_hibernation_leave,
  1002. .pre_restore = acpi_pm_freeze,
  1003. .restore_cleanup = acpi_pm_thaw,
  1004. };
  1005. /**
  1006. * acpi_hibernation_begin_old - Set the target system sleep state to
  1007. * ACPI_STATE_S4 and execute the _PTS control method. This
  1008. * function is used if the pre-ACPI 2.0 suspend ordering has been
  1009. * requested.
  1010. */
  1011. static int acpi_hibernation_begin_old(void)
  1012. {
  1013. int error;
  1014. /*
  1015. * The _TTS object should always be evaluated before the _PTS object.
  1016. * When the old_suspended_ordering is true, the _PTS object is
  1017. * evaluated in the acpi_sleep_prepare.
  1018. */
  1019. acpi_sleep_tts_switch(ACPI_STATE_S4);
  1020. error = acpi_sleep_prepare(ACPI_STATE_S4);
  1021. if (!error) {
  1022. if (!nvs_nosave)
  1023. error = suspend_nvs_alloc();
  1024. if (!error) {
  1025. acpi_target_sleep_state = ACPI_STATE_S4;
  1026. acpi_scan_lock_acquire();
  1027. }
  1028. }
  1029. return error;
  1030. }
  1031. /*
  1032. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  1033. * been requested.
  1034. */
  1035. static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
  1036. .begin = acpi_hibernation_begin_old,
  1037. .end = acpi_pm_end,
  1038. .pre_snapshot = acpi_pm_pre_suspend,
  1039. .prepare = acpi_pm_freeze,
  1040. .finish = acpi_pm_finish,
  1041. .enter = acpi_hibernation_enter,
  1042. .leave = acpi_hibernation_leave,
  1043. .pre_restore = acpi_pm_freeze,
  1044. .restore_cleanup = acpi_pm_thaw,
  1045. .recover = acpi_pm_finish,
  1046. };
  1047. static void acpi_sleep_hibernate_setup(void)
  1048. {
  1049. if (!acpi_sleep_state_supported(ACPI_STATE_S4))
  1050. return;
  1051. hibernation_set_ops(old_suspend_ordering ?
  1052. &acpi_hibernation_ops_old : &acpi_hibernation_ops);
  1053. sleep_states[ACPI_STATE_S4] = 1;
  1054. if (nosigcheck)
  1055. return;
  1056. acpi_get_table(ACPI_SIG_FACS, 1, (struct acpi_table_header **)&facs);
  1057. if (facs)
  1058. s4_hardware_signature = facs->hardware_signature;
  1059. }
  1060. #else /* !CONFIG_HIBERNATION */
  1061. static inline void acpi_sleep_hibernate_setup(void) {}
  1062. #endif /* !CONFIG_HIBERNATION */
  1063. static void acpi_power_off_prepare(void)
  1064. {
  1065. /* Prepare to power off the system */
  1066. acpi_sleep_prepare(ACPI_STATE_S5);
  1067. acpi_disable_all_gpes();
  1068. acpi_os_wait_events_complete();
  1069. }
  1070. static void acpi_power_off(void)
  1071. {
  1072. /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
  1073. printk(KERN_DEBUG "%s called\n", __func__);
  1074. local_irq_disable();
  1075. acpi_enter_sleep_state(ACPI_STATE_S5);
  1076. }
  1077. int __init acpi_sleep_init(void)
  1078. {
  1079. char supported[ACPI_S_STATE_COUNT * 3 + 1];
  1080. char *pos = supported;
  1081. int i;
  1082. acpi_sleep_dmi_check();
  1083. sleep_states[ACPI_STATE_S0] = 1;
  1084. acpi_sleep_syscore_init();
  1085. acpi_sleep_suspend_setup();
  1086. acpi_sleep_hibernate_setup();
  1087. if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
  1088. sleep_states[ACPI_STATE_S5] = 1;
  1089. pm_power_off_prepare = acpi_power_off_prepare;
  1090. pm_power_off = acpi_power_off;
  1091. } else {
  1092. acpi_no_s5 = true;
  1093. }
  1094. supported[0] = 0;
  1095. for (i = 0; i < ACPI_S_STATE_COUNT; i++) {
  1096. if (sleep_states[i])
  1097. pos += sprintf(pos, " S%d", i);
  1098. }
  1099. pr_info(PREFIX "(supports%s)\n", supported);
  1100. /*
  1101. * Register the tts_notifier to reboot notifier list so that the _TTS
  1102. * object can also be evaluated when the system enters S5.
  1103. */
  1104. register_reboot_notifier(&tts_notifier);
  1105. return 0;
  1106. }