sleep.c 20 KB

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