sleep.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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/suspend.h>
  17. #include <linux/reboot.h>
  18. #include <linux/acpi.h>
  19. #include <linux/module.h>
  20. #include <asm/io.h>
  21. #include <acpi/acpi_bus.h>
  22. #include <acpi/acpi_drivers.h>
  23. #include "internal.h"
  24. #include "sleep.h"
  25. static u8 sleep_states[ACPI_S_STATE_COUNT];
  26. static void acpi_sleep_tts_switch(u32 acpi_state)
  27. {
  28. union acpi_object in_arg = { ACPI_TYPE_INTEGER };
  29. struct acpi_object_list arg_list = { 1, &in_arg };
  30. acpi_status status = AE_OK;
  31. in_arg.integer.value = acpi_state;
  32. status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL);
  33. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  34. /*
  35. * OS can't evaluate the _TTS object correctly. Some warning
  36. * message will be printed. But it won't break anything.
  37. */
  38. printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
  39. }
  40. }
  41. static int tts_notify_reboot(struct notifier_block *this,
  42. unsigned long code, void *x)
  43. {
  44. acpi_sleep_tts_switch(ACPI_STATE_S5);
  45. return NOTIFY_DONE;
  46. }
  47. static struct notifier_block tts_notifier = {
  48. .notifier_call = tts_notify_reboot,
  49. .next = NULL,
  50. .priority = 0,
  51. };
  52. static int acpi_sleep_prepare(u32 acpi_state)
  53. {
  54. #ifdef CONFIG_ACPI_SLEEP
  55. /* do we have a wakeup address for S2 and S3? */
  56. if (acpi_state == ACPI_STATE_S3) {
  57. if (!acpi_wakeup_address)
  58. return -EFAULT;
  59. acpi_set_firmware_waking_vector(acpi_wakeup_address);
  60. }
  61. ACPI_FLUSH_CPU_CACHE();
  62. #endif
  63. printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
  64. acpi_state);
  65. acpi_enable_wakeup_devices(acpi_state);
  66. acpi_enter_sleep_state_prep(acpi_state);
  67. return 0;
  68. }
  69. #ifdef CONFIG_ACPI_SLEEP
  70. static u32 acpi_target_sleep_state = ACPI_STATE_S0;
  71. u32 acpi_target_system_state(void)
  72. {
  73. return acpi_target_sleep_state;
  74. }
  75. static bool pwr_btn_event_pending;
  76. /*
  77. * The ACPI specification wants us to save NVS memory regions during hibernation
  78. * and to restore them during the subsequent resume. Windows does that also for
  79. * suspend to RAM. However, it is known that this mechanism does not work on
  80. * all machines, so we allow the user to disable it with the help of the
  81. * 'acpi_sleep=nonvs' kernel command line option.
  82. */
  83. static bool nvs_nosave;
  84. void __init acpi_nvs_nosave(void)
  85. {
  86. nvs_nosave = true;
  87. }
  88. /*
  89. * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
  90. * user to request that behavior by using the 'acpi_old_suspend_ordering'
  91. * kernel command line option that causes the following variable to be set.
  92. */
  93. static bool old_suspend_ordering;
  94. void __init acpi_old_suspend_ordering(void)
  95. {
  96. old_suspend_ordering = true;
  97. }
  98. /**
  99. * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
  100. */
  101. static int acpi_pm_freeze(void)
  102. {
  103. acpi_disable_all_gpes();
  104. acpi_os_wait_events_complete();
  105. acpi_ec_block_transactions();
  106. return 0;
  107. }
  108. /**
  109. * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
  110. */
  111. static int acpi_pm_pre_suspend(void)
  112. {
  113. acpi_pm_freeze();
  114. return suspend_nvs_save();
  115. }
  116. /**
  117. * __acpi_pm_prepare - Prepare the platform to enter the target state.
  118. *
  119. * If necessary, set the firmware waking vector and do arch-specific
  120. * nastiness to get the wakeup code to the waking vector.
  121. */
  122. static int __acpi_pm_prepare(void)
  123. {
  124. int error = acpi_sleep_prepare(acpi_target_sleep_state);
  125. if (error)
  126. acpi_target_sleep_state = ACPI_STATE_S0;
  127. return error;
  128. }
  129. /**
  130. * acpi_pm_prepare - Prepare the platform to enter the target sleep
  131. * state and disable the GPEs.
  132. */
  133. static int acpi_pm_prepare(void)
  134. {
  135. int error = __acpi_pm_prepare();
  136. if (!error)
  137. error = acpi_pm_pre_suspend();
  138. return error;
  139. }
  140. static int find_powerf_dev(struct device *dev, void *data)
  141. {
  142. struct acpi_device *device = to_acpi_device(dev);
  143. const char *hid = acpi_device_hid(device);
  144. return !strcmp(hid, ACPI_BUTTON_HID_POWERF);
  145. }
  146. /**
  147. * acpi_pm_finish - Instruct the platform to leave a sleep state.
  148. *
  149. * This is called after we wake back up (or if entering the sleep state
  150. * failed).
  151. */
  152. static void acpi_pm_finish(void)
  153. {
  154. struct device *pwr_btn_dev;
  155. u32 acpi_state = acpi_target_sleep_state;
  156. acpi_ec_unblock_transactions();
  157. suspend_nvs_free();
  158. if (acpi_state == ACPI_STATE_S0)
  159. return;
  160. printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
  161. acpi_state);
  162. acpi_disable_wakeup_devices(acpi_state);
  163. acpi_leave_sleep_state(acpi_state);
  164. /* reset firmware waking vector */
  165. acpi_set_firmware_waking_vector((acpi_physical_address) 0);
  166. acpi_target_sleep_state = ACPI_STATE_S0;
  167. /* If we were woken with the fixed power button, provide a small
  168. * hint to userspace in the form of a wakeup event on the fixed power
  169. * button device (if it can be found).
  170. *
  171. * We delay the event generation til now, as the PM layer requires
  172. * timekeeping to be running before we generate events. */
  173. if (!pwr_btn_event_pending)
  174. return;
  175. pwr_btn_event_pending = false;
  176. pwr_btn_dev = bus_find_device(&acpi_bus_type, NULL, NULL,
  177. find_powerf_dev);
  178. if (pwr_btn_dev) {
  179. pm_wakeup_event(pwr_btn_dev, 0);
  180. put_device(pwr_btn_dev);
  181. }
  182. }
  183. /**
  184. * acpi_pm_end - Finish up suspend sequence.
  185. */
  186. static void acpi_pm_end(void)
  187. {
  188. /*
  189. * This is necessary in case acpi_pm_finish() is not called during a
  190. * failing transition to a sleep state.
  191. */
  192. acpi_target_sleep_state = ACPI_STATE_S0;
  193. acpi_sleep_tts_switch(acpi_target_sleep_state);
  194. }
  195. #else /* !CONFIG_ACPI_SLEEP */
  196. #define acpi_target_sleep_state ACPI_STATE_S0
  197. #endif /* CONFIG_ACPI_SLEEP */
  198. #ifdef CONFIG_SUSPEND
  199. static u32 acpi_suspend_states[] = {
  200. [PM_SUSPEND_ON] = ACPI_STATE_S0,
  201. [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
  202. [PM_SUSPEND_MEM] = ACPI_STATE_S3,
  203. [PM_SUSPEND_MAX] = ACPI_STATE_S5
  204. };
  205. /**
  206. * acpi_suspend_begin - Set the target system sleep state to the state
  207. * associated with given @pm_state, if supported.
  208. */
  209. static int acpi_suspend_begin(suspend_state_t pm_state)
  210. {
  211. u32 acpi_state = acpi_suspend_states[pm_state];
  212. int error = 0;
  213. error = nvs_nosave ? 0 : suspend_nvs_alloc();
  214. if (error)
  215. return error;
  216. if (sleep_states[acpi_state]) {
  217. acpi_target_sleep_state = acpi_state;
  218. acpi_sleep_tts_switch(acpi_target_sleep_state);
  219. } else {
  220. printk(KERN_ERR "ACPI does not support this state: %d\n",
  221. pm_state);
  222. error = -ENOSYS;
  223. }
  224. return error;
  225. }
  226. /**
  227. * acpi_suspend_enter - Actually enter a sleep state.
  228. * @pm_state: ignored
  229. *
  230. * Flush caches and go to sleep. For STR we have to call arch-specific
  231. * assembly, which in turn call acpi_enter_sleep_state().
  232. * It's unfortunate, but it works. Please fix if you're feeling frisky.
  233. */
  234. static int acpi_suspend_enter(suspend_state_t pm_state)
  235. {
  236. acpi_status status = AE_OK;
  237. u32 acpi_state = acpi_target_sleep_state;
  238. int error;
  239. ACPI_FLUSH_CPU_CACHE();
  240. switch (acpi_state) {
  241. case ACPI_STATE_S1:
  242. barrier();
  243. status = acpi_enter_sleep_state(acpi_state);
  244. break;
  245. case ACPI_STATE_S3:
  246. error = acpi_suspend_lowlevel();
  247. if (error)
  248. return error;
  249. pr_info(PREFIX "Low-level resume complete\n");
  250. break;
  251. }
  252. /* This violates the spec but is required for bug compatibility. */
  253. acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
  254. /* Reprogram control registers */
  255. acpi_leave_sleep_state_prep(acpi_state);
  256. /* ACPI 3.0 specs (P62) says that it's the responsibility
  257. * of the OSPM to clear the status bit [ implying that the
  258. * POWER_BUTTON event should not reach userspace ]
  259. *
  260. * However, we do generate a small hint for userspace in the form of
  261. * a wakeup event. We flag this condition for now and generate the
  262. * event later, as we're currently too early in resume to be able to
  263. * generate wakeup events.
  264. */
  265. if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) {
  266. acpi_event_status pwr_btn_status;
  267. acpi_get_event_status(ACPI_EVENT_POWER_BUTTON, &pwr_btn_status);
  268. if (pwr_btn_status & ACPI_EVENT_FLAG_SET) {
  269. acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
  270. /* Flag for later */
  271. pwr_btn_event_pending = true;
  272. }
  273. }
  274. /*
  275. * Disable and clear GPE status before interrupt is enabled. Some GPEs
  276. * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
  277. * acpi_leave_sleep_state will reenable specific GPEs later
  278. */
  279. acpi_disable_all_gpes();
  280. /* Allow EC transactions to happen. */
  281. acpi_ec_unblock_transactions_early();
  282. suspend_nvs_restore();
  283. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  284. }
  285. static int acpi_suspend_state_valid(suspend_state_t pm_state)
  286. {
  287. u32 acpi_state;
  288. switch (pm_state) {
  289. case PM_SUSPEND_ON:
  290. case PM_SUSPEND_STANDBY:
  291. case PM_SUSPEND_MEM:
  292. acpi_state = acpi_suspend_states[pm_state];
  293. return sleep_states[acpi_state];
  294. default:
  295. return 0;
  296. }
  297. }
  298. static const struct platform_suspend_ops acpi_suspend_ops = {
  299. .valid = acpi_suspend_state_valid,
  300. .begin = acpi_suspend_begin,
  301. .prepare_late = acpi_pm_prepare,
  302. .enter = acpi_suspend_enter,
  303. .wake = acpi_pm_finish,
  304. .end = acpi_pm_end,
  305. };
  306. /**
  307. * acpi_suspend_begin_old - Set the target system sleep state to the
  308. * state associated with given @pm_state, if supported, and
  309. * execute the _PTS control method. This function is used if the
  310. * pre-ACPI 2.0 suspend ordering has been requested.
  311. */
  312. static int acpi_suspend_begin_old(suspend_state_t pm_state)
  313. {
  314. int error = acpi_suspend_begin(pm_state);
  315. if (!error)
  316. error = __acpi_pm_prepare();
  317. return error;
  318. }
  319. /*
  320. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  321. * been requested.
  322. */
  323. static const struct platform_suspend_ops acpi_suspend_ops_old = {
  324. .valid = acpi_suspend_state_valid,
  325. .begin = acpi_suspend_begin_old,
  326. .prepare_late = acpi_pm_pre_suspend,
  327. .enter = acpi_suspend_enter,
  328. .wake = acpi_pm_finish,
  329. .end = acpi_pm_end,
  330. .recover = acpi_pm_finish,
  331. };
  332. static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
  333. {
  334. old_suspend_ordering = true;
  335. return 0;
  336. }
  337. static int __init init_nvs_nosave(const struct dmi_system_id *d)
  338. {
  339. acpi_nvs_nosave();
  340. return 0;
  341. }
  342. static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
  343. {
  344. .callback = init_old_suspend_ordering,
  345. .ident = "Abit KN9 (nForce4 variant)",
  346. .matches = {
  347. DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
  348. DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
  349. },
  350. },
  351. {
  352. .callback = init_old_suspend_ordering,
  353. .ident = "HP xw4600 Workstation",
  354. .matches = {
  355. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  356. DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
  357. },
  358. },
  359. {
  360. .callback = init_old_suspend_ordering,
  361. .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
  362. .matches = {
  363. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
  364. DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
  365. },
  366. },
  367. {
  368. .callback = init_old_suspend_ordering,
  369. .ident = "Panasonic CF51-2L",
  370. .matches = {
  371. DMI_MATCH(DMI_BOARD_VENDOR,
  372. "Matsushita Electric Industrial Co.,Ltd."),
  373. DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
  374. },
  375. },
  376. {
  377. .callback = init_nvs_nosave,
  378. .ident = "Sony Vaio VGN-FW21E",
  379. .matches = {
  380. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  381. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
  382. },
  383. },
  384. {
  385. .callback = init_nvs_nosave,
  386. .ident = "Sony Vaio VPCEB17FX",
  387. .matches = {
  388. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  389. DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
  390. },
  391. },
  392. {
  393. .callback = init_nvs_nosave,
  394. .ident = "Sony Vaio VGN-SR11M",
  395. .matches = {
  396. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  397. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
  398. },
  399. },
  400. {
  401. .callback = init_nvs_nosave,
  402. .ident = "Everex StepNote Series",
  403. .matches = {
  404. DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
  405. DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
  406. },
  407. },
  408. {
  409. .callback = init_nvs_nosave,
  410. .ident = "Sony Vaio VPCEB1Z1E",
  411. .matches = {
  412. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  413. DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
  414. },
  415. },
  416. {
  417. .callback = init_nvs_nosave,
  418. .ident = "Sony Vaio VGN-NW130D",
  419. .matches = {
  420. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  421. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
  422. },
  423. },
  424. {
  425. .callback = init_nvs_nosave,
  426. .ident = "Sony Vaio VPCCW29FX",
  427. .matches = {
  428. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  429. DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
  430. },
  431. },
  432. {
  433. .callback = init_nvs_nosave,
  434. .ident = "Averatec AV1020-ED2",
  435. .matches = {
  436. DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
  437. DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
  438. },
  439. },
  440. {
  441. .callback = init_old_suspend_ordering,
  442. .ident = "Asus A8N-SLI DELUXE",
  443. .matches = {
  444. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  445. DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
  446. },
  447. },
  448. {
  449. .callback = init_old_suspend_ordering,
  450. .ident = "Asus A8N-SLI Premium",
  451. .matches = {
  452. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  453. DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
  454. },
  455. },
  456. {
  457. .callback = init_nvs_nosave,
  458. .ident = "Sony Vaio VGN-SR26GN_P",
  459. .matches = {
  460. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  461. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
  462. },
  463. },
  464. {
  465. .callback = init_nvs_nosave,
  466. .ident = "Sony Vaio VGN-FW520F",
  467. .matches = {
  468. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  469. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
  470. },
  471. },
  472. {
  473. .callback = init_nvs_nosave,
  474. .ident = "Asus K54C",
  475. .matches = {
  476. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  477. DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
  478. },
  479. },
  480. {
  481. .callback = init_nvs_nosave,
  482. .ident = "Asus K54HR",
  483. .matches = {
  484. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  485. DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
  486. },
  487. },
  488. {},
  489. };
  490. #endif /* CONFIG_SUSPEND */
  491. #ifdef CONFIG_HIBERNATION
  492. static unsigned long s4_hardware_signature;
  493. static struct acpi_table_facs *facs;
  494. static bool nosigcheck;
  495. void __init acpi_no_s4_hw_signature(void)
  496. {
  497. nosigcheck = true;
  498. }
  499. static int acpi_hibernation_begin(void)
  500. {
  501. int error;
  502. error = nvs_nosave ? 0 : suspend_nvs_alloc();
  503. if (!error) {
  504. acpi_target_sleep_state = ACPI_STATE_S4;
  505. acpi_sleep_tts_switch(acpi_target_sleep_state);
  506. }
  507. return error;
  508. }
  509. static int acpi_hibernation_enter(void)
  510. {
  511. acpi_status status = AE_OK;
  512. ACPI_FLUSH_CPU_CACHE();
  513. /* This shouldn't return. If it returns, we have a problem */
  514. status = acpi_enter_sleep_state(ACPI_STATE_S4);
  515. /* Reprogram control registers */
  516. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  517. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  518. }
  519. static void acpi_hibernation_leave(void)
  520. {
  521. /*
  522. * If ACPI is not enabled by the BIOS and the boot kernel, we need to
  523. * enable it here.
  524. */
  525. acpi_enable();
  526. /* Reprogram control registers */
  527. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  528. /* Check the hardware signature */
  529. if (facs && s4_hardware_signature != facs->hardware_signature) {
  530. printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
  531. "cannot resume!\n");
  532. panic("ACPI S4 hardware signature mismatch");
  533. }
  534. /* Restore the NVS memory area */
  535. suspend_nvs_restore();
  536. /* Allow EC transactions to happen. */
  537. acpi_ec_unblock_transactions_early();
  538. }
  539. static void acpi_pm_thaw(void)
  540. {
  541. acpi_ec_unblock_transactions();
  542. acpi_enable_all_runtime_gpes();
  543. }
  544. static const struct platform_hibernation_ops acpi_hibernation_ops = {
  545. .begin = acpi_hibernation_begin,
  546. .end = acpi_pm_end,
  547. .pre_snapshot = acpi_pm_prepare,
  548. .finish = acpi_pm_finish,
  549. .prepare = acpi_pm_prepare,
  550. .enter = acpi_hibernation_enter,
  551. .leave = acpi_hibernation_leave,
  552. .pre_restore = acpi_pm_freeze,
  553. .restore_cleanup = acpi_pm_thaw,
  554. };
  555. /**
  556. * acpi_hibernation_begin_old - Set the target system sleep state to
  557. * ACPI_STATE_S4 and execute the _PTS control method. This
  558. * function is used if the pre-ACPI 2.0 suspend ordering has been
  559. * requested.
  560. */
  561. static int acpi_hibernation_begin_old(void)
  562. {
  563. int error;
  564. /*
  565. * The _TTS object should always be evaluated before the _PTS object.
  566. * When the old_suspended_ordering is true, the _PTS object is
  567. * evaluated in the acpi_sleep_prepare.
  568. */
  569. acpi_sleep_tts_switch(ACPI_STATE_S4);
  570. error = acpi_sleep_prepare(ACPI_STATE_S4);
  571. if (!error) {
  572. if (!nvs_nosave)
  573. error = suspend_nvs_alloc();
  574. if (!error)
  575. acpi_target_sleep_state = ACPI_STATE_S4;
  576. }
  577. return error;
  578. }
  579. /*
  580. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  581. * been requested.
  582. */
  583. static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
  584. .begin = acpi_hibernation_begin_old,
  585. .end = acpi_pm_end,
  586. .pre_snapshot = acpi_pm_pre_suspend,
  587. .prepare = acpi_pm_freeze,
  588. .finish = acpi_pm_finish,
  589. .enter = acpi_hibernation_enter,
  590. .leave = acpi_hibernation_leave,
  591. .pre_restore = acpi_pm_freeze,
  592. .restore_cleanup = acpi_pm_thaw,
  593. .recover = acpi_pm_finish,
  594. };
  595. #endif /* CONFIG_HIBERNATION */
  596. int acpi_suspend(u32 acpi_state)
  597. {
  598. suspend_state_t states[] = {
  599. [1] = PM_SUSPEND_STANDBY,
  600. [3] = PM_SUSPEND_MEM,
  601. [5] = PM_SUSPEND_MAX
  602. };
  603. if (acpi_state < 6 && states[acpi_state])
  604. return pm_suspend(states[acpi_state]);
  605. if (acpi_state == 4)
  606. return hibernate();
  607. return -EINVAL;
  608. }
  609. static void acpi_power_off_prepare(void)
  610. {
  611. /* Prepare to power off the system */
  612. acpi_sleep_prepare(ACPI_STATE_S5);
  613. acpi_disable_all_gpes();
  614. }
  615. static void acpi_power_off(void)
  616. {
  617. /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
  618. printk(KERN_DEBUG "%s called\n", __func__);
  619. local_irq_disable();
  620. acpi_enter_sleep_state(ACPI_STATE_S5);
  621. }
  622. int __init acpi_sleep_init(void)
  623. {
  624. acpi_status status;
  625. u8 type_a, type_b;
  626. #ifdef CONFIG_SUSPEND
  627. int i = 0;
  628. dmi_check_system(acpisleep_dmi_table);
  629. #endif
  630. if (acpi_disabled)
  631. return 0;
  632. sleep_states[ACPI_STATE_S0] = 1;
  633. printk(KERN_INFO PREFIX "(supports S0");
  634. #ifdef CONFIG_SUSPEND
  635. for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
  636. status = acpi_get_sleep_type_data(i, &type_a, &type_b);
  637. if (ACPI_SUCCESS(status)) {
  638. sleep_states[i] = 1;
  639. printk(KERN_CONT " S%d", i);
  640. }
  641. }
  642. suspend_set_ops(old_suspend_ordering ?
  643. &acpi_suspend_ops_old : &acpi_suspend_ops);
  644. #endif
  645. #ifdef CONFIG_HIBERNATION
  646. status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
  647. if (ACPI_SUCCESS(status)) {
  648. hibernation_set_ops(old_suspend_ordering ?
  649. &acpi_hibernation_ops_old : &acpi_hibernation_ops);
  650. sleep_states[ACPI_STATE_S4] = 1;
  651. printk(KERN_CONT " S4");
  652. if (!nosigcheck) {
  653. acpi_get_table(ACPI_SIG_FACS, 1,
  654. (struct acpi_table_header **)&facs);
  655. if (facs)
  656. s4_hardware_signature =
  657. facs->hardware_signature;
  658. }
  659. }
  660. #endif
  661. status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
  662. if (ACPI_SUCCESS(status)) {
  663. sleep_states[ACPI_STATE_S5] = 1;
  664. printk(KERN_CONT " S5");
  665. pm_power_off_prepare = acpi_power_off_prepare;
  666. pm_power_off = acpi_power_off;
  667. }
  668. printk(KERN_CONT ")\n");
  669. /*
  670. * Register the tts_notifier to reboot notifier list so that the _TTS
  671. * object can also be evaluated when the system enters S5.
  672. */
  673. register_reboot_notifier(&tts_notifier);
  674. return 0;
  675. }