hwesleep.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /******************************************************************************
  2. *
  3. * Name: hwesleep.c - ACPI Hardware Sleep/Wake Support functions for the
  4. * extended FADT-V5 sleep registers.
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2012, Intel Corp.
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #define _COMPONENT ACPI_HARDWARE
  46. ACPI_MODULE_NAME("hwesleep")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_hw_execute_sleep_method
  50. *
  51. * PARAMETERS: method_pathname - Pathname of method to execute
  52. * integer_argument - Argument to pass to the method
  53. *
  54. * RETURN: None
  55. *
  56. * DESCRIPTION: Execute a sleep/wake related method with one integer argument
  57. * and no return value.
  58. *
  59. ******************************************************************************/
  60. void acpi_hw_execute_sleep_method(char *method_pathname, u32 integer_argument)
  61. {
  62. struct acpi_object_list arg_list;
  63. union acpi_object arg;
  64. acpi_status status;
  65. ACPI_FUNCTION_TRACE(hw_execute_sleep_method);
  66. /* One argument, integer_argument; No return value expected */
  67. arg_list.count = 1;
  68. arg_list.pointer = &arg;
  69. arg.type = ACPI_TYPE_INTEGER;
  70. arg.integer.value = (u64)integer_argument;
  71. status = acpi_evaluate_object(NULL, method_pathname, &arg_list, NULL);
  72. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  73. ACPI_EXCEPTION((AE_INFO, status, "While executing method %s",
  74. method_pathname));
  75. }
  76. return_VOID;
  77. }
  78. /*******************************************************************************
  79. *
  80. * FUNCTION: acpi_hw_extended_sleep
  81. *
  82. * PARAMETERS: sleep_state - Which sleep state to enter
  83. * Flags - ACPI_EXECUTE_GTS to run optional method
  84. *
  85. * RETURN: Status
  86. *
  87. * DESCRIPTION: Enter a system sleep state via the extended FADT sleep
  88. * registers (V5 FADT).
  89. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
  90. *
  91. ******************************************************************************/
  92. acpi_status acpi_hw_extended_sleep(u8 sleep_state, u8 flags)
  93. {
  94. acpi_status status;
  95. u8 sleep_type_value;
  96. u64 sleep_status;
  97. ACPI_FUNCTION_TRACE(hw_extended_sleep);
  98. /* Extended sleep registers must be valid */
  99. if (!acpi_gbl_FADT.sleep_control.address ||
  100. !acpi_gbl_FADT.sleep_status.address) {
  101. return_ACPI_STATUS(AE_NOT_EXIST);
  102. }
  103. /* Clear wake status (WAK_STS) */
  104. status = acpi_write(ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
  105. if (ACPI_FAILURE(status)) {
  106. return_ACPI_STATUS(status);
  107. }
  108. acpi_gbl_system_awake_and_running = FALSE;
  109. /* Optionally execute _GTS (Going To Sleep) */
  110. if (flags & ACPI_EXECUTE_GTS) {
  111. acpi_hw_execute_sleep_method(METHOD_PATHNAME__GTS, sleep_state);
  112. }
  113. /* Flush caches, as per ACPI specification */
  114. ACPI_FLUSH_CPU_CACHE();
  115. /*
  116. * Set the SLP_TYP and SLP_EN bits.
  117. *
  118. * Note: We only use the first value returned by the \_Sx method
  119. * (acpi_gbl_sleep_type_a) - As per ACPI specification.
  120. */
  121. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  122. "Entering sleep state [S%u]\n", sleep_state));
  123. sleep_type_value =
  124. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  125. ACPI_X_SLEEP_TYPE_MASK);
  126. status = acpi_write((sleep_type_value | ACPI_X_SLEEP_ENABLE),
  127. &acpi_gbl_FADT.sleep_control);
  128. if (ACPI_FAILURE(status)) {
  129. return_ACPI_STATUS(status);
  130. }
  131. /* Wait for transition back to Working State */
  132. do {
  133. status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
  134. if (ACPI_FAILURE(status)) {
  135. return_ACPI_STATUS(status);
  136. }
  137. } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
  138. return_ACPI_STATUS(AE_OK);
  139. }
  140. /*******************************************************************************
  141. *
  142. * FUNCTION: acpi_hw_extended_wake_prep
  143. *
  144. * PARAMETERS: sleep_state - Which sleep state we just exited
  145. * Flags - ACPI_EXECUTE_BFS to run optional method
  146. *
  147. * RETURN: Status
  148. *
  149. * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
  150. * a sleep. Called with interrupts ENABLED.
  151. *
  152. ******************************************************************************/
  153. acpi_status acpi_hw_extended_wake_prep(u8 sleep_state, u8 flags)
  154. {
  155. acpi_status status;
  156. u8 sleep_type_value;
  157. ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
  158. status = acpi_get_sleep_type_data(ACPI_STATE_S0,
  159. &acpi_gbl_sleep_type_a,
  160. &acpi_gbl_sleep_type_b);
  161. if (ACPI_SUCCESS(status)) {
  162. sleep_type_value =
  163. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  164. ACPI_X_SLEEP_TYPE_MASK);
  165. (void)acpi_write((sleep_type_value | ACPI_X_SLEEP_ENABLE),
  166. &acpi_gbl_FADT.sleep_control);
  167. }
  168. /* Optionally execute _BFS (Back From Sleep) */
  169. if (flags & ACPI_EXECUTE_BFS) {
  170. acpi_hw_execute_sleep_method(METHOD_PATHNAME__BFS, sleep_state);
  171. }
  172. return_ACPI_STATUS(AE_OK);
  173. }
  174. /*******************************************************************************
  175. *
  176. * FUNCTION: acpi_hw_extended_wake
  177. *
  178. * PARAMETERS: sleep_state - Which sleep state we just exited
  179. * Flags - Reserved, set to zero
  180. *
  181. * RETURN: Status
  182. *
  183. * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
  184. * Called with interrupts ENABLED.
  185. *
  186. ******************************************************************************/
  187. acpi_status acpi_hw_extended_wake(u8 sleep_state, u8 flags)
  188. {
  189. ACPI_FUNCTION_TRACE(hw_extended_wake);
  190. /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
  191. acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
  192. /* Execute the wake methods */
  193. acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING);
  194. acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state);
  195. /*
  196. * Some BIOS code assumes that WAK_STS will be cleared on resume
  197. * and use it to determine whether the system is rebooting or
  198. * resuming. Clear WAK_STS for compatibility.
  199. */
  200. (void)acpi_write(ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
  201. acpi_gbl_system_awake_and_running = TRUE;
  202. acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING);
  203. return_ACPI_STATUS(AE_OK);
  204. }