sleep.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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. * On some platforms with the LPS0 _DSM device noirq resume
  859. * takes too much time for EC wakeup events to survive, so look
  860. * for them now.
  861. */
  862. if (lps0_device_handle)
  863. acpi_ec_dispatch_gpe();
  864. }
  865. }
  866. static void acpi_s2idle_sync(void)
  867. {
  868. /*
  869. * Process all pending events in case there are any wakeup ones.
  870. *
  871. * The EC driver uses the system workqueue and an additional special
  872. * one, so those need to be flushed too.
  873. */
  874. acpi_os_wait_events_complete(); /* synchronize SCI IRQ handling */
  875. acpi_ec_flush_work();
  876. acpi_os_wait_events_complete(); /* synchronize Notify handling */
  877. s2idle_wakeup = false;
  878. }
  879. static void acpi_s2idle_restore(void)
  880. {
  881. if (acpi_sci_irq_valid())
  882. disable_irq_wake(acpi_sci_irq);
  883. if (lps0_device_handle) {
  884. acpi_sleep_run_lps0_dsm(ACPI_LPS0_EXIT);
  885. acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_ON);
  886. }
  887. }
  888. static void acpi_s2idle_end(void)
  889. {
  890. s2idle_in_progress = false;
  891. acpi_scan_lock_release();
  892. }
  893. static const struct platform_s2idle_ops acpi_s2idle_ops = {
  894. .begin = acpi_s2idle_begin,
  895. .prepare = acpi_s2idle_prepare,
  896. .wake = acpi_s2idle_wake,
  897. .sync = acpi_s2idle_sync,
  898. .restore = acpi_s2idle_restore,
  899. .end = acpi_s2idle_end,
  900. };
  901. static void acpi_sleep_suspend_setup(void)
  902. {
  903. int i;
  904. for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++)
  905. if (acpi_sleep_state_supported(i))
  906. sleep_states[i] = 1;
  907. suspend_set_ops(old_suspend_ordering ?
  908. &acpi_suspend_ops_old : &acpi_suspend_ops);
  909. acpi_scan_add_handler(&lps0_handler);
  910. s2idle_set_ops(&acpi_s2idle_ops);
  911. }
  912. #else /* !CONFIG_SUSPEND */
  913. #define s2idle_in_progress (false)
  914. #define s2idle_wakeup (false)
  915. #define lps0_device_handle (NULL)
  916. static inline void acpi_sleep_suspend_setup(void) {}
  917. #endif /* !CONFIG_SUSPEND */
  918. bool acpi_s2idle_wakeup(void)
  919. {
  920. return s2idle_wakeup;
  921. }
  922. bool acpi_sleep_no_ec_events(void)
  923. {
  924. return !s2idle_in_progress || !lps0_device_handle;
  925. }
  926. #ifdef CONFIG_PM_SLEEP
  927. static u32 saved_bm_rld;
  928. static int acpi_save_bm_rld(void)
  929. {
  930. acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &saved_bm_rld);
  931. return 0;
  932. }
  933. static void acpi_restore_bm_rld(void)
  934. {
  935. u32 resumed_bm_rld = 0;
  936. acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &resumed_bm_rld);
  937. if (resumed_bm_rld == saved_bm_rld)
  938. return;
  939. acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, saved_bm_rld);
  940. }
  941. static struct syscore_ops acpi_sleep_syscore_ops = {
  942. .suspend = acpi_save_bm_rld,
  943. .resume = acpi_restore_bm_rld,
  944. };
  945. static void acpi_sleep_syscore_init(void)
  946. {
  947. register_syscore_ops(&acpi_sleep_syscore_ops);
  948. }
  949. #else
  950. static inline void acpi_sleep_syscore_init(void) {}
  951. #endif /* CONFIG_PM_SLEEP */
  952. #ifdef CONFIG_HIBERNATION
  953. static unsigned long s4_hardware_signature;
  954. static struct acpi_table_facs *facs;
  955. static bool nosigcheck;
  956. void __init acpi_no_s4_hw_signature(void)
  957. {
  958. nosigcheck = true;
  959. }
  960. static int acpi_hibernation_begin(void)
  961. {
  962. int error;
  963. error = nvs_nosave ? 0 : suspend_nvs_alloc();
  964. if (!error)
  965. acpi_pm_start(ACPI_STATE_S4);
  966. return error;
  967. }
  968. static int acpi_hibernation_enter(void)
  969. {
  970. acpi_status status = AE_OK;
  971. ACPI_FLUSH_CPU_CACHE();
  972. /* This shouldn't return. If it returns, we have a problem */
  973. status = acpi_enter_sleep_state(ACPI_STATE_S4);
  974. /* Reprogram control registers */
  975. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  976. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  977. }
  978. static void acpi_hibernation_leave(void)
  979. {
  980. pm_set_resume_via_firmware();
  981. /*
  982. * If ACPI is not enabled by the BIOS and the boot kernel, we need to
  983. * enable it here.
  984. */
  985. acpi_enable();
  986. /* Reprogram control registers */
  987. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  988. /* Check the hardware signature */
  989. if (facs && s4_hardware_signature != facs->hardware_signature)
  990. pr_crit("ACPI: Hardware changed while hibernated, success doubtful!\n");
  991. /* Restore the NVS memory area */
  992. suspend_nvs_restore();
  993. /* Allow EC transactions to happen. */
  994. acpi_ec_unblock_transactions();
  995. }
  996. static void acpi_pm_thaw(void)
  997. {
  998. acpi_ec_unblock_transactions();
  999. acpi_enable_all_runtime_gpes();
  1000. }
  1001. static const struct platform_hibernation_ops acpi_hibernation_ops = {
  1002. .begin = acpi_hibernation_begin,
  1003. .end = acpi_pm_end,
  1004. .pre_snapshot = acpi_pm_prepare,
  1005. .finish = acpi_pm_finish,
  1006. .prepare = acpi_pm_prepare,
  1007. .enter = acpi_hibernation_enter,
  1008. .leave = acpi_hibernation_leave,
  1009. .pre_restore = acpi_pm_freeze,
  1010. .restore_cleanup = acpi_pm_thaw,
  1011. };
  1012. /**
  1013. * acpi_hibernation_begin_old - Set the target system sleep state to
  1014. * ACPI_STATE_S4 and execute the _PTS control method. This
  1015. * function is used if the pre-ACPI 2.0 suspend ordering has been
  1016. * requested.
  1017. */
  1018. static int acpi_hibernation_begin_old(void)
  1019. {
  1020. int error;
  1021. /*
  1022. * The _TTS object should always be evaluated before the _PTS object.
  1023. * When the old_suspended_ordering is true, the _PTS object is
  1024. * evaluated in the acpi_sleep_prepare.
  1025. */
  1026. acpi_sleep_tts_switch(ACPI_STATE_S4);
  1027. error = acpi_sleep_prepare(ACPI_STATE_S4);
  1028. if (!error) {
  1029. if (!nvs_nosave)
  1030. error = suspend_nvs_alloc();
  1031. if (!error) {
  1032. acpi_target_sleep_state = ACPI_STATE_S4;
  1033. acpi_scan_lock_acquire();
  1034. }
  1035. }
  1036. return error;
  1037. }
  1038. /*
  1039. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  1040. * been requested.
  1041. */
  1042. static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
  1043. .begin = acpi_hibernation_begin_old,
  1044. .end = acpi_pm_end,
  1045. .pre_snapshot = acpi_pm_pre_suspend,
  1046. .prepare = acpi_pm_freeze,
  1047. .finish = acpi_pm_finish,
  1048. .enter = acpi_hibernation_enter,
  1049. .leave = acpi_hibernation_leave,
  1050. .pre_restore = acpi_pm_freeze,
  1051. .restore_cleanup = acpi_pm_thaw,
  1052. .recover = acpi_pm_finish,
  1053. };
  1054. static void acpi_sleep_hibernate_setup(void)
  1055. {
  1056. if (!acpi_sleep_state_supported(ACPI_STATE_S4))
  1057. return;
  1058. hibernation_set_ops(old_suspend_ordering ?
  1059. &acpi_hibernation_ops_old : &acpi_hibernation_ops);
  1060. sleep_states[ACPI_STATE_S4] = 1;
  1061. if (nosigcheck)
  1062. return;
  1063. acpi_get_table(ACPI_SIG_FACS, 1, (struct acpi_table_header **)&facs);
  1064. if (facs)
  1065. s4_hardware_signature = facs->hardware_signature;
  1066. }
  1067. #else /* !CONFIG_HIBERNATION */
  1068. static inline void acpi_sleep_hibernate_setup(void) {}
  1069. #endif /* !CONFIG_HIBERNATION */
  1070. static void acpi_power_off_prepare(void)
  1071. {
  1072. /* Prepare to power off the system */
  1073. acpi_sleep_prepare(ACPI_STATE_S5);
  1074. acpi_disable_all_gpes();
  1075. acpi_os_wait_events_complete();
  1076. }
  1077. static void acpi_power_off(void)
  1078. {
  1079. /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
  1080. printk(KERN_DEBUG "%s called\n", __func__);
  1081. local_irq_disable();
  1082. acpi_enter_sleep_state(ACPI_STATE_S5);
  1083. }
  1084. int __init acpi_sleep_init(void)
  1085. {
  1086. char supported[ACPI_S_STATE_COUNT * 3 + 1];
  1087. char *pos = supported;
  1088. int i;
  1089. acpi_sleep_dmi_check();
  1090. sleep_states[ACPI_STATE_S0] = 1;
  1091. acpi_sleep_syscore_init();
  1092. acpi_sleep_suspend_setup();
  1093. acpi_sleep_hibernate_setup();
  1094. if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
  1095. sleep_states[ACPI_STATE_S5] = 1;
  1096. pm_power_off_prepare = acpi_power_off_prepare;
  1097. pm_power_off = acpi_power_off;
  1098. } else {
  1099. acpi_no_s5 = true;
  1100. }
  1101. supported[0] = 0;
  1102. for (i = 0; i < ACPI_S_STATE_COUNT; i++) {
  1103. if (sleep_states[i])
  1104. pos += sprintf(pos, " S%d", i);
  1105. }
  1106. pr_info(PREFIX "(supports%s)\n", supported);
  1107. /*
  1108. * Register the tts_notifier to reboot notifier list so that the _TTS
  1109. * object can also be evaluated when the system enters S5.
  1110. */
  1111. register_reboot_notifier(&tts_notifier);
  1112. return 0;
  1113. }