sleep.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  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. .callback = init_nvs_save_s3,
  317. .ident = "Asus 1025C",
  318. .matches = {
  319. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  320. DMI_MATCH(DMI_PRODUCT_NAME, "1025C"),
  321. },
  322. },
  323. /*
  324. * https://bugzilla.kernel.org/show_bug.cgi?id=189431
  325. * Lenovo G50-45 is a platform later than 2012, but needs nvs memory
  326. * saving during S3.
  327. */
  328. {
  329. .callback = init_nvs_save_s3,
  330. .ident = "Lenovo G50-45",
  331. .matches = {
  332. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  333. DMI_MATCH(DMI_PRODUCT_NAME, "80E3"),
  334. },
  335. },
  336. /*
  337. * https://bugzilla.kernel.org/show_bug.cgi?id=196907
  338. * Some Dell XPS13 9360 cannot do suspend-to-idle using the Low Power
  339. * S0 Idle firmware interface.
  340. */
  341. {
  342. .callback = init_no_lps0,
  343. .ident = "Dell XPS13 9360",
  344. .matches = {
  345. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  346. DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"),
  347. },
  348. },
  349. /*
  350. * ThinkPad X1 Tablet(2016) cannot do suspend-to-idle using
  351. * the Low Power S0 Idle firmware interface (see
  352. * https://bugzilla.kernel.org/show_bug.cgi?id=199057).
  353. */
  354. {
  355. .callback = init_no_lps0,
  356. .ident = "ThinkPad X1 Tablet(2016)",
  357. .matches = {
  358. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  359. DMI_MATCH(DMI_PRODUCT_NAME, "20GGA00L00"),
  360. },
  361. },
  362. {},
  363. };
  364. static bool ignore_blacklist;
  365. void __init acpi_sleep_no_blacklist(void)
  366. {
  367. ignore_blacklist = true;
  368. }
  369. static void __init acpi_sleep_dmi_check(void)
  370. {
  371. if (ignore_blacklist)
  372. return;
  373. if (dmi_get_bios_year() >= 2012)
  374. acpi_nvs_nosave_s3();
  375. dmi_check_system(acpisleep_dmi_table);
  376. }
  377. /**
  378. * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
  379. */
  380. static int acpi_pm_freeze(void)
  381. {
  382. acpi_disable_all_gpes();
  383. acpi_os_wait_events_complete();
  384. acpi_ec_block_transactions();
  385. return 0;
  386. }
  387. /**
  388. * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
  389. */
  390. static int acpi_pm_pre_suspend(void)
  391. {
  392. acpi_pm_freeze();
  393. return suspend_nvs_save();
  394. }
  395. /**
  396. * __acpi_pm_prepare - Prepare the platform to enter the target state.
  397. *
  398. * If necessary, set the firmware waking vector and do arch-specific
  399. * nastiness to get the wakeup code to the waking vector.
  400. */
  401. static int __acpi_pm_prepare(void)
  402. {
  403. int error = acpi_sleep_prepare(acpi_target_sleep_state);
  404. if (error)
  405. acpi_target_sleep_state = ACPI_STATE_S0;
  406. return error;
  407. }
  408. /**
  409. * acpi_pm_prepare - Prepare the platform to enter the target sleep
  410. * state and disable the GPEs.
  411. */
  412. static int acpi_pm_prepare(void)
  413. {
  414. int error = __acpi_pm_prepare();
  415. if (!error)
  416. error = acpi_pm_pre_suspend();
  417. return error;
  418. }
  419. static int find_powerf_dev(struct device *dev, void *data)
  420. {
  421. struct acpi_device *device = to_acpi_device(dev);
  422. const char *hid = acpi_device_hid(device);
  423. return !strcmp(hid, ACPI_BUTTON_HID_POWERF);
  424. }
  425. /**
  426. * acpi_pm_finish - Instruct the platform to leave a sleep state.
  427. *
  428. * This is called after we wake back up (or if entering the sleep state
  429. * failed).
  430. */
  431. static void acpi_pm_finish(void)
  432. {
  433. struct device *pwr_btn_dev;
  434. u32 acpi_state = acpi_target_sleep_state;
  435. acpi_ec_unblock_transactions();
  436. suspend_nvs_free();
  437. if (acpi_state == ACPI_STATE_S0)
  438. return;
  439. printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
  440. acpi_state);
  441. acpi_disable_wakeup_devices(acpi_state);
  442. acpi_leave_sleep_state(acpi_state);
  443. /* reset firmware waking vector */
  444. acpi_set_waking_vector(0);
  445. acpi_target_sleep_state = ACPI_STATE_S0;
  446. acpi_resume_power_resources();
  447. /* If we were woken with the fixed power button, provide a small
  448. * hint to userspace in the form of a wakeup event on the fixed power
  449. * button device (if it can be found).
  450. *
  451. * We delay the event generation til now, as the PM layer requires
  452. * timekeeping to be running before we generate events. */
  453. if (!pwr_btn_event_pending)
  454. return;
  455. pwr_btn_event_pending = false;
  456. pwr_btn_dev = bus_find_device(&acpi_bus_type, NULL, NULL,
  457. find_powerf_dev);
  458. if (pwr_btn_dev) {
  459. pm_wakeup_event(pwr_btn_dev, 0);
  460. put_device(pwr_btn_dev);
  461. }
  462. }
  463. /**
  464. * acpi_pm_start - Start system PM transition.
  465. */
  466. static void acpi_pm_start(u32 acpi_state)
  467. {
  468. acpi_target_sleep_state = acpi_state;
  469. acpi_sleep_tts_switch(acpi_target_sleep_state);
  470. acpi_scan_lock_acquire();
  471. }
  472. /**
  473. * acpi_pm_end - Finish up system PM transition.
  474. */
  475. static void acpi_pm_end(void)
  476. {
  477. acpi_turn_off_unused_power_resources();
  478. acpi_scan_lock_release();
  479. /*
  480. * This is necessary in case acpi_pm_finish() is not called during a
  481. * failing transition to a sleep state.
  482. */
  483. acpi_target_sleep_state = ACPI_STATE_S0;
  484. acpi_sleep_tts_switch(acpi_target_sleep_state);
  485. }
  486. #else /* !CONFIG_ACPI_SLEEP */
  487. #define acpi_target_sleep_state ACPI_STATE_S0
  488. #define acpi_sleep_no_lps0 (false)
  489. static inline void acpi_sleep_dmi_check(void) {}
  490. #endif /* CONFIG_ACPI_SLEEP */
  491. #ifdef CONFIG_SUSPEND
  492. static u32 acpi_suspend_states[] = {
  493. [PM_SUSPEND_ON] = ACPI_STATE_S0,
  494. [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
  495. [PM_SUSPEND_MEM] = ACPI_STATE_S3,
  496. [PM_SUSPEND_MAX] = ACPI_STATE_S5
  497. };
  498. /**
  499. * acpi_suspend_begin - Set the target system sleep state to the state
  500. * associated with given @pm_state, if supported.
  501. */
  502. static int acpi_suspend_begin(suspend_state_t pm_state)
  503. {
  504. u32 acpi_state = acpi_suspend_states[pm_state];
  505. int error;
  506. error = (nvs_nosave || nvs_nosave_s3) ? 0 : suspend_nvs_alloc();
  507. if (error)
  508. return error;
  509. if (!sleep_states[acpi_state]) {
  510. pr_err("ACPI does not support sleep state S%u\n", acpi_state);
  511. return -ENOSYS;
  512. }
  513. if (acpi_state > ACPI_STATE_S1)
  514. pm_set_suspend_via_firmware();
  515. acpi_pm_start(acpi_state);
  516. return 0;
  517. }
  518. /**
  519. * acpi_suspend_enter - Actually enter a sleep state.
  520. * @pm_state: ignored
  521. *
  522. * Flush caches and go to sleep. For STR we have to call arch-specific
  523. * assembly, which in turn call acpi_enter_sleep_state().
  524. * It's unfortunate, but it works. Please fix if you're feeling frisky.
  525. */
  526. static int acpi_suspend_enter(suspend_state_t pm_state)
  527. {
  528. acpi_status status = AE_OK;
  529. u32 acpi_state = acpi_target_sleep_state;
  530. int error;
  531. ACPI_FLUSH_CPU_CACHE();
  532. trace_suspend_resume(TPS("acpi_suspend"), acpi_state, true);
  533. switch (acpi_state) {
  534. case ACPI_STATE_S1:
  535. barrier();
  536. status = acpi_enter_sleep_state(acpi_state);
  537. break;
  538. case ACPI_STATE_S3:
  539. if (!acpi_suspend_lowlevel)
  540. return -ENOSYS;
  541. error = acpi_suspend_lowlevel();
  542. if (error)
  543. return error;
  544. pr_info(PREFIX "Low-level resume complete\n");
  545. pm_set_resume_via_firmware();
  546. break;
  547. }
  548. trace_suspend_resume(TPS("acpi_suspend"), acpi_state, false);
  549. /* This violates the spec but is required for bug compatibility. */
  550. acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
  551. /* Reprogram control registers */
  552. acpi_leave_sleep_state_prep(acpi_state);
  553. /* ACPI 3.0 specs (P62) says that it's the responsibility
  554. * of the OSPM to clear the status bit [ implying that the
  555. * POWER_BUTTON event should not reach userspace ]
  556. *
  557. * However, we do generate a small hint for userspace in the form of
  558. * a wakeup event. We flag this condition for now and generate the
  559. * event later, as we're currently too early in resume to be able to
  560. * generate wakeup events.
  561. */
  562. if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) {
  563. acpi_event_status pwr_btn_status = ACPI_EVENT_FLAG_DISABLED;
  564. acpi_get_event_status(ACPI_EVENT_POWER_BUTTON, &pwr_btn_status);
  565. if (pwr_btn_status & ACPI_EVENT_FLAG_STATUS_SET) {
  566. acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
  567. /* Flag for later */
  568. pwr_btn_event_pending = true;
  569. }
  570. }
  571. /*
  572. * Disable and clear GPE status before interrupt is enabled. Some GPEs
  573. * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
  574. * acpi_leave_sleep_state will reenable specific GPEs later
  575. */
  576. acpi_disable_all_gpes();
  577. /* Allow EC transactions to happen. */
  578. acpi_ec_unblock_transactions();
  579. suspend_nvs_restore();
  580. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  581. }
  582. static int acpi_suspend_state_valid(suspend_state_t pm_state)
  583. {
  584. u32 acpi_state;
  585. switch (pm_state) {
  586. case PM_SUSPEND_ON:
  587. case PM_SUSPEND_STANDBY:
  588. case PM_SUSPEND_MEM:
  589. acpi_state = acpi_suspend_states[pm_state];
  590. return sleep_states[acpi_state];
  591. default:
  592. return 0;
  593. }
  594. }
  595. static const struct platform_suspend_ops acpi_suspend_ops = {
  596. .valid = acpi_suspend_state_valid,
  597. .begin = acpi_suspend_begin,
  598. .prepare_late = acpi_pm_prepare,
  599. .enter = acpi_suspend_enter,
  600. .wake = acpi_pm_finish,
  601. .end = acpi_pm_end,
  602. };
  603. /**
  604. * acpi_suspend_begin_old - Set the target system sleep state to the
  605. * state associated with given @pm_state, if supported, and
  606. * execute the _PTS control method. This function is used if the
  607. * pre-ACPI 2.0 suspend ordering has been requested.
  608. */
  609. static int acpi_suspend_begin_old(suspend_state_t pm_state)
  610. {
  611. int error = acpi_suspend_begin(pm_state);
  612. if (!error)
  613. error = __acpi_pm_prepare();
  614. return error;
  615. }
  616. /*
  617. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  618. * been requested.
  619. */
  620. static const struct platform_suspend_ops acpi_suspend_ops_old = {
  621. .valid = acpi_suspend_state_valid,
  622. .begin = acpi_suspend_begin_old,
  623. .prepare_late = acpi_pm_pre_suspend,
  624. .enter = acpi_suspend_enter,
  625. .wake = acpi_pm_finish,
  626. .end = acpi_pm_end,
  627. .recover = acpi_pm_finish,
  628. };
  629. static bool s2idle_in_progress;
  630. static bool s2idle_wakeup;
  631. /*
  632. * On platforms supporting the Low Power S0 Idle interface there is an ACPI
  633. * device object with the PNP0D80 compatible device ID (System Power Management
  634. * Controller) and a specific _DSM method under it. That method, if present,
  635. * can be used to indicate to the platform that the OS is transitioning into a
  636. * low-power state in which certain types of activity are not desirable or that
  637. * it is leaving such a state, which allows the platform to adjust its operation
  638. * mode accordingly.
  639. */
  640. static const struct acpi_device_id lps0_device_ids[] = {
  641. {"PNP0D80", },
  642. {"", },
  643. };
  644. #define ACPI_LPS0_DSM_UUID "c4eb40a0-6cd2-11e2-bcfd-0800200c9a66"
  645. #define ACPI_LPS0_GET_DEVICE_CONSTRAINTS 1
  646. #define ACPI_LPS0_SCREEN_OFF 3
  647. #define ACPI_LPS0_SCREEN_ON 4
  648. #define ACPI_LPS0_ENTRY 5
  649. #define ACPI_LPS0_EXIT 6
  650. static acpi_handle lps0_device_handle;
  651. static guid_t lps0_dsm_guid;
  652. static char lps0_dsm_func_mask;
  653. /* Device constraint entry structure */
  654. struct lpi_device_info {
  655. char *name;
  656. int enabled;
  657. union acpi_object *package;
  658. };
  659. /* Constraint package structure */
  660. struct lpi_device_constraint {
  661. int uid;
  662. int min_dstate;
  663. int function_states;
  664. };
  665. struct lpi_constraints {
  666. acpi_handle handle;
  667. int min_dstate;
  668. };
  669. static struct lpi_constraints *lpi_constraints_table;
  670. static int lpi_constraints_table_size;
  671. static void lpi_device_get_constraints(void)
  672. {
  673. union acpi_object *out_obj;
  674. int i;
  675. out_obj = acpi_evaluate_dsm_typed(lps0_device_handle, &lps0_dsm_guid,
  676. 1, ACPI_LPS0_GET_DEVICE_CONSTRAINTS,
  677. NULL, ACPI_TYPE_PACKAGE);
  678. acpi_handle_debug(lps0_device_handle, "_DSM function 1 eval %s\n",
  679. out_obj ? "successful" : "failed");
  680. if (!out_obj)
  681. return;
  682. lpi_constraints_table = kcalloc(out_obj->package.count,
  683. sizeof(*lpi_constraints_table),
  684. GFP_KERNEL);
  685. if (!lpi_constraints_table)
  686. goto free_acpi_buffer;
  687. acpi_handle_debug(lps0_device_handle, "LPI: constraints list begin:\n");
  688. for (i = 0; i < out_obj->package.count; i++) {
  689. struct lpi_constraints *constraint;
  690. acpi_status status;
  691. union acpi_object *package = &out_obj->package.elements[i];
  692. struct lpi_device_info info = { };
  693. int package_count = 0, j;
  694. if (!package)
  695. continue;
  696. for (j = 0; j < package->package.count; ++j) {
  697. union acpi_object *element =
  698. &(package->package.elements[j]);
  699. switch (element->type) {
  700. case ACPI_TYPE_INTEGER:
  701. info.enabled = element->integer.value;
  702. break;
  703. case ACPI_TYPE_STRING:
  704. info.name = element->string.pointer;
  705. break;
  706. case ACPI_TYPE_PACKAGE:
  707. package_count = element->package.count;
  708. info.package = element->package.elements;
  709. break;
  710. }
  711. }
  712. if (!info.enabled || !info.package || !info.name)
  713. continue;
  714. constraint = &lpi_constraints_table[lpi_constraints_table_size];
  715. status = acpi_get_handle(NULL, info.name, &constraint->handle);
  716. if (ACPI_FAILURE(status))
  717. continue;
  718. acpi_handle_debug(lps0_device_handle,
  719. "index:%d Name:%s\n", i, info.name);
  720. constraint->min_dstate = -1;
  721. for (j = 0; j < package_count; ++j) {
  722. union acpi_object *info_obj = &info.package[j];
  723. union acpi_object *cnstr_pkg;
  724. union acpi_object *obj;
  725. struct lpi_device_constraint dev_info;
  726. switch (info_obj->type) {
  727. case ACPI_TYPE_INTEGER:
  728. /* version */
  729. break;
  730. case ACPI_TYPE_PACKAGE:
  731. if (info_obj->package.count < 2)
  732. break;
  733. cnstr_pkg = info_obj->package.elements;
  734. obj = &cnstr_pkg[0];
  735. dev_info.uid = obj->integer.value;
  736. obj = &cnstr_pkg[1];
  737. dev_info.min_dstate = obj->integer.value;
  738. acpi_handle_debug(lps0_device_handle,
  739. "uid:%d min_dstate:%s\n",
  740. dev_info.uid,
  741. acpi_power_state_string(dev_info.min_dstate));
  742. constraint->min_dstate = dev_info.min_dstate;
  743. break;
  744. }
  745. }
  746. if (constraint->min_dstate < 0) {
  747. acpi_handle_debug(lps0_device_handle,
  748. "Incomplete constraint defined\n");
  749. continue;
  750. }
  751. lpi_constraints_table_size++;
  752. }
  753. acpi_handle_debug(lps0_device_handle, "LPI: constraints list end\n");
  754. free_acpi_buffer:
  755. ACPI_FREE(out_obj);
  756. }
  757. static void lpi_check_constraints(void)
  758. {
  759. int i;
  760. for (i = 0; i < lpi_constraints_table_size; ++i) {
  761. acpi_handle handle = lpi_constraints_table[i].handle;
  762. struct acpi_device *adev;
  763. if (!handle || acpi_bus_get_device(handle, &adev))
  764. continue;
  765. acpi_handle_debug(handle,
  766. "LPI: required min power state:%s current power state:%s\n",
  767. acpi_power_state_string(lpi_constraints_table[i].min_dstate),
  768. acpi_power_state_string(adev->power.state));
  769. if (!adev->flags.power_manageable) {
  770. acpi_handle_info(handle, "LPI: Device not power manageable\n");
  771. lpi_constraints_table[i].handle = NULL;
  772. continue;
  773. }
  774. if (adev->power.state < lpi_constraints_table[i].min_dstate)
  775. acpi_handle_info(handle,
  776. "LPI: Constraint not met; min power state:%s current power state:%s\n",
  777. acpi_power_state_string(lpi_constraints_table[i].min_dstate),
  778. acpi_power_state_string(adev->power.state));
  779. }
  780. }
  781. static void acpi_sleep_run_lps0_dsm(unsigned int func)
  782. {
  783. union acpi_object *out_obj;
  784. if (!(lps0_dsm_func_mask & (1 << func)))
  785. return;
  786. out_obj = acpi_evaluate_dsm(lps0_device_handle, &lps0_dsm_guid, 1, func, NULL);
  787. ACPI_FREE(out_obj);
  788. acpi_handle_debug(lps0_device_handle, "_DSM function %u evaluation %s\n",
  789. func, out_obj ? "successful" : "failed");
  790. }
  791. static int lps0_device_attach(struct acpi_device *adev,
  792. const struct acpi_device_id *not_used)
  793. {
  794. union acpi_object *out_obj;
  795. if (lps0_device_handle)
  796. return 0;
  797. if (acpi_sleep_no_lps0) {
  798. acpi_handle_info(adev->handle,
  799. "Low Power S0 Idle interface disabled\n");
  800. return 0;
  801. }
  802. if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0))
  803. return 0;
  804. guid_parse(ACPI_LPS0_DSM_UUID, &lps0_dsm_guid);
  805. /* Check if the _DSM is present and as expected. */
  806. out_obj = acpi_evaluate_dsm(adev->handle, &lps0_dsm_guid, 1, 0, NULL);
  807. if (out_obj && out_obj->type == ACPI_TYPE_BUFFER) {
  808. char bitmask = *(char *)out_obj->buffer.pointer;
  809. lps0_dsm_func_mask = bitmask;
  810. lps0_device_handle = adev->handle;
  811. /*
  812. * Use suspend-to-idle by default if the default
  813. * suspend mode was not set from the command line.
  814. */
  815. if (mem_sleep_default > PM_SUSPEND_MEM)
  816. mem_sleep_current = PM_SUSPEND_TO_IDLE;
  817. acpi_handle_debug(adev->handle, "_DSM function mask: 0x%x\n",
  818. bitmask);
  819. acpi_ec_mark_gpe_for_wake();
  820. } else {
  821. acpi_handle_debug(adev->handle,
  822. "_DSM function 0 evaluation failed\n");
  823. }
  824. ACPI_FREE(out_obj);
  825. lpi_device_get_constraints();
  826. return 0;
  827. }
  828. static struct acpi_scan_handler lps0_handler = {
  829. .ids = lps0_device_ids,
  830. .attach = lps0_device_attach,
  831. };
  832. static int acpi_s2idle_begin(void)
  833. {
  834. acpi_scan_lock_acquire();
  835. s2idle_in_progress = true;
  836. return 0;
  837. }
  838. static int acpi_s2idle_prepare(void)
  839. {
  840. if (lps0_device_handle) {
  841. acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_OFF);
  842. acpi_sleep_run_lps0_dsm(ACPI_LPS0_ENTRY);
  843. acpi_ec_set_gpe_wake_mask(ACPI_GPE_ENABLE);
  844. }
  845. if (acpi_sci_irq_valid())
  846. enable_irq_wake(acpi_sci_irq);
  847. acpi_enable_wakeup_devices(ACPI_STATE_S0);
  848. /* Change the configuration of GPEs to avoid spurious wakeup. */
  849. acpi_enable_all_wakeup_gpes();
  850. acpi_os_wait_events_complete();
  851. return 0;
  852. }
  853. static void acpi_s2idle_wake(void)
  854. {
  855. if (pm_debug_messages_on)
  856. lpi_check_constraints();
  857. /*
  858. * If IRQD_WAKEUP_ARMED is not set for the SCI at this point, it means
  859. * that the SCI has triggered while suspended, so cancel the wakeup in
  860. * case it has not been a wakeup event (the GPEs will be checked later).
  861. */
  862. if (acpi_sci_irq_valid() &&
  863. !irqd_is_wakeup_armed(irq_get_irq_data(acpi_sci_irq))) {
  864. pm_system_cancel_wakeup();
  865. s2idle_wakeup = true;
  866. /*
  867. * On some platforms with the LPS0 _DSM device noirq resume
  868. * takes too much time for EC wakeup events to survive, so look
  869. * for them now.
  870. */
  871. if (lps0_device_handle)
  872. acpi_ec_dispatch_gpe();
  873. }
  874. }
  875. static void acpi_s2idle_sync(void)
  876. {
  877. /*
  878. * Process all pending events in case there are any wakeup ones.
  879. *
  880. * The EC driver uses the system workqueue and an additional special
  881. * one, so those need to be flushed too.
  882. */
  883. acpi_os_wait_events_complete(); /* synchronize SCI IRQ handling */
  884. acpi_ec_flush_work();
  885. acpi_os_wait_events_complete(); /* synchronize Notify handling */
  886. s2idle_wakeup = false;
  887. }
  888. static void acpi_s2idle_restore(void)
  889. {
  890. acpi_enable_all_runtime_gpes();
  891. acpi_disable_wakeup_devices(ACPI_STATE_S0);
  892. if (acpi_sci_irq_valid())
  893. disable_irq_wake(acpi_sci_irq);
  894. if (lps0_device_handle) {
  895. acpi_ec_set_gpe_wake_mask(ACPI_GPE_DISABLE);
  896. acpi_sleep_run_lps0_dsm(ACPI_LPS0_EXIT);
  897. acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_ON);
  898. }
  899. }
  900. static void acpi_s2idle_end(void)
  901. {
  902. s2idle_in_progress = false;
  903. acpi_scan_lock_release();
  904. }
  905. static const struct platform_s2idle_ops acpi_s2idle_ops = {
  906. .begin = acpi_s2idle_begin,
  907. .prepare = acpi_s2idle_prepare,
  908. .wake = acpi_s2idle_wake,
  909. .sync = acpi_s2idle_sync,
  910. .restore = acpi_s2idle_restore,
  911. .end = acpi_s2idle_end,
  912. };
  913. static void acpi_sleep_suspend_setup(void)
  914. {
  915. int i;
  916. for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++)
  917. if (acpi_sleep_state_supported(i))
  918. sleep_states[i] = 1;
  919. suspend_set_ops(old_suspend_ordering ?
  920. &acpi_suspend_ops_old : &acpi_suspend_ops);
  921. acpi_scan_add_handler(&lps0_handler);
  922. s2idle_set_ops(&acpi_s2idle_ops);
  923. }
  924. #else /* !CONFIG_SUSPEND */
  925. #define s2idle_in_progress (false)
  926. #define s2idle_wakeup (false)
  927. #define lps0_device_handle (NULL)
  928. static inline void acpi_sleep_suspend_setup(void) {}
  929. #endif /* !CONFIG_SUSPEND */
  930. bool acpi_s2idle_wakeup(void)
  931. {
  932. return s2idle_wakeup;
  933. }
  934. bool acpi_sleep_no_ec_events(void)
  935. {
  936. return !s2idle_in_progress || !lps0_device_handle;
  937. }
  938. #ifdef CONFIG_PM_SLEEP
  939. static u32 saved_bm_rld;
  940. static int acpi_save_bm_rld(void)
  941. {
  942. acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &saved_bm_rld);
  943. return 0;
  944. }
  945. static void acpi_restore_bm_rld(void)
  946. {
  947. u32 resumed_bm_rld = 0;
  948. acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &resumed_bm_rld);
  949. if (resumed_bm_rld == saved_bm_rld)
  950. return;
  951. acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, saved_bm_rld);
  952. }
  953. static struct syscore_ops acpi_sleep_syscore_ops = {
  954. .suspend = acpi_save_bm_rld,
  955. .resume = acpi_restore_bm_rld,
  956. };
  957. static void acpi_sleep_syscore_init(void)
  958. {
  959. register_syscore_ops(&acpi_sleep_syscore_ops);
  960. }
  961. #else
  962. static inline void acpi_sleep_syscore_init(void) {}
  963. #endif /* CONFIG_PM_SLEEP */
  964. #ifdef CONFIG_HIBERNATION
  965. static unsigned long s4_hardware_signature;
  966. static struct acpi_table_facs *facs;
  967. static bool nosigcheck;
  968. void __init acpi_no_s4_hw_signature(void)
  969. {
  970. nosigcheck = true;
  971. }
  972. static int acpi_hibernation_begin(void)
  973. {
  974. int error;
  975. error = nvs_nosave ? 0 : suspend_nvs_alloc();
  976. if (!error)
  977. acpi_pm_start(ACPI_STATE_S4);
  978. return error;
  979. }
  980. static int acpi_hibernation_enter(void)
  981. {
  982. acpi_status status = AE_OK;
  983. ACPI_FLUSH_CPU_CACHE();
  984. /* This shouldn't return. If it returns, we have a problem */
  985. status = acpi_enter_sleep_state(ACPI_STATE_S4);
  986. /* Reprogram control registers */
  987. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  988. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  989. }
  990. static void acpi_hibernation_leave(void)
  991. {
  992. pm_set_resume_via_firmware();
  993. /*
  994. * If ACPI is not enabled by the BIOS and the boot kernel, we need to
  995. * enable it here.
  996. */
  997. acpi_enable();
  998. /* Reprogram control registers */
  999. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  1000. /* Check the hardware signature */
  1001. if (facs && s4_hardware_signature != facs->hardware_signature)
  1002. pr_crit("ACPI: Hardware changed while hibernated, success doubtful!\n");
  1003. /* Restore the NVS memory area */
  1004. suspend_nvs_restore();
  1005. /* Allow EC transactions to happen. */
  1006. acpi_ec_unblock_transactions();
  1007. }
  1008. static void acpi_pm_thaw(void)
  1009. {
  1010. acpi_ec_unblock_transactions();
  1011. acpi_enable_all_runtime_gpes();
  1012. }
  1013. static const struct platform_hibernation_ops acpi_hibernation_ops = {
  1014. .begin = acpi_hibernation_begin,
  1015. .end = acpi_pm_end,
  1016. .pre_snapshot = acpi_pm_prepare,
  1017. .finish = acpi_pm_finish,
  1018. .prepare = acpi_pm_prepare,
  1019. .enter = acpi_hibernation_enter,
  1020. .leave = acpi_hibernation_leave,
  1021. .pre_restore = acpi_pm_freeze,
  1022. .restore_cleanup = acpi_pm_thaw,
  1023. };
  1024. /**
  1025. * acpi_hibernation_begin_old - Set the target system sleep state to
  1026. * ACPI_STATE_S4 and execute the _PTS control method. This
  1027. * function is used if the pre-ACPI 2.0 suspend ordering has been
  1028. * requested.
  1029. */
  1030. static int acpi_hibernation_begin_old(void)
  1031. {
  1032. int error;
  1033. /*
  1034. * The _TTS object should always be evaluated before the _PTS object.
  1035. * When the old_suspended_ordering is true, the _PTS object is
  1036. * evaluated in the acpi_sleep_prepare.
  1037. */
  1038. acpi_sleep_tts_switch(ACPI_STATE_S4);
  1039. error = acpi_sleep_prepare(ACPI_STATE_S4);
  1040. if (!error) {
  1041. if (!nvs_nosave)
  1042. error = suspend_nvs_alloc();
  1043. if (!error) {
  1044. acpi_target_sleep_state = ACPI_STATE_S4;
  1045. acpi_scan_lock_acquire();
  1046. }
  1047. }
  1048. return error;
  1049. }
  1050. /*
  1051. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  1052. * been requested.
  1053. */
  1054. static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
  1055. .begin = acpi_hibernation_begin_old,
  1056. .end = acpi_pm_end,
  1057. .pre_snapshot = acpi_pm_pre_suspend,
  1058. .prepare = acpi_pm_freeze,
  1059. .finish = acpi_pm_finish,
  1060. .enter = acpi_hibernation_enter,
  1061. .leave = acpi_hibernation_leave,
  1062. .pre_restore = acpi_pm_freeze,
  1063. .restore_cleanup = acpi_pm_thaw,
  1064. .recover = acpi_pm_finish,
  1065. };
  1066. static void acpi_sleep_hibernate_setup(void)
  1067. {
  1068. if (!acpi_sleep_state_supported(ACPI_STATE_S4))
  1069. return;
  1070. hibernation_set_ops(old_suspend_ordering ?
  1071. &acpi_hibernation_ops_old : &acpi_hibernation_ops);
  1072. sleep_states[ACPI_STATE_S4] = 1;
  1073. if (nosigcheck)
  1074. return;
  1075. acpi_get_table(ACPI_SIG_FACS, 1, (struct acpi_table_header **)&facs);
  1076. if (facs)
  1077. s4_hardware_signature = facs->hardware_signature;
  1078. }
  1079. #else /* !CONFIG_HIBERNATION */
  1080. static inline void acpi_sleep_hibernate_setup(void) {}
  1081. #endif /* !CONFIG_HIBERNATION */
  1082. static void acpi_power_off_prepare(void)
  1083. {
  1084. /* Prepare to power off the system */
  1085. acpi_sleep_prepare(ACPI_STATE_S5);
  1086. acpi_disable_all_gpes();
  1087. acpi_os_wait_events_complete();
  1088. }
  1089. static void acpi_power_off(void)
  1090. {
  1091. /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
  1092. printk(KERN_DEBUG "%s called\n", __func__);
  1093. local_irq_disable();
  1094. acpi_enter_sleep_state(ACPI_STATE_S5);
  1095. }
  1096. int __init acpi_sleep_init(void)
  1097. {
  1098. char supported[ACPI_S_STATE_COUNT * 3 + 1];
  1099. char *pos = supported;
  1100. int i;
  1101. acpi_sleep_dmi_check();
  1102. sleep_states[ACPI_STATE_S0] = 1;
  1103. acpi_sleep_syscore_init();
  1104. acpi_sleep_suspend_setup();
  1105. acpi_sleep_hibernate_setup();
  1106. if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
  1107. sleep_states[ACPI_STATE_S5] = 1;
  1108. pm_power_off_prepare = acpi_power_off_prepare;
  1109. pm_power_off = acpi_power_off;
  1110. } else {
  1111. acpi_no_s5 = true;
  1112. }
  1113. supported[0] = 0;
  1114. for (i = 0; i < ACPI_S_STATE_COUNT; i++) {
  1115. if (sleep_states[i])
  1116. pos += sprintf(pos, " S%d", i);
  1117. }
  1118. pr_info(PREFIX "(supports%s)\n", supported);
  1119. /*
  1120. * Register the tts_notifier to reboot notifier list so that the _TTS
  1121. * object can also be evaluated when the system enters S5.
  1122. */
  1123. register_reboot_notifier(&tts_notifier);
  1124. return 0;
  1125. }