sleep.c 31 KB

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