sleep.c 33 KB

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