main.c 19 KB

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