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 =
  105. acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
  106. if (ACPI_FAILURE(status)) {
  107. return_ACPI_STATUS(status);
  108. }
  109. acpi_gbl_system_awake_and_running = FALSE;
  110. /* Optionally execute _GTS (Going To Sleep) */
  111. if (flags & ACPI_EXECUTE_GTS) {
  112. acpi_hw_execute_sleep_method(METHOD_PATHNAME__GTS, sleep_state);
  113. }
  114. /* Flush caches, as per ACPI specification */
  115. ACPI_FLUSH_CPU_CACHE();
  116. /*
  117. * Set the SLP_TYP and SLP_EN bits.
  118. *
  119. * Note: We only use the first value returned by the \_Sx method
  120. * (acpi_gbl_sleep_type_a) - As per ACPI specification.
  121. */
  122. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  123. "Entering sleep state [S%u]\n", sleep_state));
  124. sleep_type_value =
  125. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  126. ACPI_X_SLEEP_TYPE_MASK);
  127. status = acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
  128. &acpi_gbl_FADT.sleep_control);
  129. if (ACPI_FAILURE(status)) {
  130. return_ACPI_STATUS(status);
  131. }
  132. /* Wait for transition back to Working State */
  133. do {
  134. status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
  135. if (ACPI_FAILURE(status)) {
  136. return_ACPI_STATUS(status);
  137. }
  138. } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
  139. return_ACPI_STATUS(AE_OK);
  140. }
  141. /*******************************************************************************
  142. *
  143. * FUNCTION: acpi_hw_extended_wake_prep
  144. *
  145. * PARAMETERS: sleep_state - Which sleep state we just exited
  146. * flags - ACPI_EXECUTE_BFS to run optional method
  147. *
  148. * RETURN: Status
  149. *
  150. * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
  151. * a sleep. Called with interrupts ENABLED.
  152. *
  153. ******************************************************************************/
  154. acpi_status acpi_hw_extended_wake_prep(u8 sleep_state, u8 flags)
  155. {
  156. acpi_status status;
  157. u8 sleep_type_value;
  158. ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
  159. status = acpi_get_sleep_type_data(ACPI_STATE_S0,
  160. &acpi_gbl_sleep_type_a,
  161. &acpi_gbl_sleep_type_b);
  162. if (ACPI_SUCCESS(status)) {
  163. sleep_type_value =
  164. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  165. ACPI_X_SLEEP_TYPE_MASK);
  166. (void)acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
  167. &acpi_gbl_FADT.sleep_control);
  168. }
  169. /* Optionally execute _BFS (Back From Sleep) */
  170. if (flags & ACPI_EXECUTE_BFS) {
  171. acpi_hw_execute_sleep_method(METHOD_PATHNAME__BFS, sleep_state);
  172. }
  173. return_ACPI_STATUS(AE_OK);
  174. }
  175. /*******************************************************************************
  176. *
  177. * FUNCTION: acpi_hw_extended_wake
  178. *
  179. * PARAMETERS: sleep_state - Which sleep state we just exited
  180. * flags - Reserved, set to zero
  181. *
  182. * RETURN: Status
  183. *
  184. * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
  185. * Called with interrupts ENABLED.
  186. *
  187. ******************************************************************************/
  188. acpi_status acpi_hw_extended_wake(u8 sleep_state, u8 flags)
  189. {
  190. ACPI_FUNCTION_TRACE(hw_extended_wake);
  191. /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
  192. acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
  193. /* Execute the wake methods */
  194. acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING);
  195. acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state);
  196. /*
  197. * Some BIOS code assumes that WAK_STS will be cleared on resume
  198. * and use it to determine whether the system is rebooting or
  199. * resuming. Clear WAK_STS for compatibility.
  200. */
  201. (void)acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
  202. acpi_gbl_system_awake_and_running = TRUE;
  203. acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING);
  204. return_ACPI_STATUS(AE_OK);
  205. }