hwesleep.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. *
  84. * RETURN: Status
  85. *
  86. * DESCRIPTION: Enter a system sleep state via the extended FADT sleep
  87. * registers (V5 FADT).
  88. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
  89. *
  90. ******************************************************************************/
  91. acpi_status acpi_hw_extended_sleep(u8 sleep_state)
  92. {
  93. acpi_status status;
  94. u8 sleep_type_value;
  95. u64 sleep_status;
  96. ACPI_FUNCTION_TRACE(hw_extended_sleep);
  97. /* Extended sleep registers must be valid */
  98. if (!acpi_gbl_FADT.sleep_control.address ||
  99. !acpi_gbl_FADT.sleep_status.address) {
  100. return_ACPI_STATUS(AE_NOT_EXIST);
  101. }
  102. /* Clear wake status (WAK_STS) */
  103. status =
  104. acpi_write((u64)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. /* Flush caches, as per ACPI specification */
  110. ACPI_FLUSH_CPU_CACHE();
  111. /*
  112. * Set the SLP_TYP and SLP_EN bits.
  113. *
  114. * Note: We only use the first value returned by the \_Sx method
  115. * (acpi_gbl_sleep_type_a) - As per ACPI specification.
  116. */
  117. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  118. "Entering sleep state [S%u]\n", sleep_state));
  119. sleep_type_value =
  120. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  121. ACPI_X_SLEEP_TYPE_MASK);
  122. status = acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
  123. &acpi_gbl_FADT.sleep_control);
  124. if (ACPI_FAILURE(status)) {
  125. return_ACPI_STATUS(status);
  126. }
  127. /* Wait for transition back to Working State */
  128. do {
  129. status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
  130. if (ACPI_FAILURE(status)) {
  131. return_ACPI_STATUS(status);
  132. }
  133. } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
  134. return_ACPI_STATUS(AE_OK);
  135. }
  136. /*******************************************************************************
  137. *
  138. * FUNCTION: acpi_hw_extended_wake_prep
  139. *
  140. * PARAMETERS: sleep_state - Which sleep state we just exited
  141. *
  142. * RETURN: Status
  143. *
  144. * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
  145. * a sleep. Called with interrupts ENABLED.
  146. *
  147. ******************************************************************************/
  148. acpi_status acpi_hw_extended_wake_prep(u8 sleep_state)
  149. {
  150. acpi_status status;
  151. u8 sleep_type_value;
  152. ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
  153. status = acpi_get_sleep_type_data(ACPI_STATE_S0,
  154. &acpi_gbl_sleep_type_a,
  155. &acpi_gbl_sleep_type_b);
  156. if (ACPI_SUCCESS(status)) {
  157. sleep_type_value =
  158. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  159. ACPI_X_SLEEP_TYPE_MASK);
  160. (void)acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
  161. &acpi_gbl_FADT.sleep_control);
  162. }
  163. return_ACPI_STATUS(AE_OK);
  164. }
  165. /*******************************************************************************
  166. *
  167. * FUNCTION: acpi_hw_extended_wake
  168. *
  169. * PARAMETERS: sleep_state - Which sleep state we just exited
  170. * flags - Reserved, set to zero
  171. *
  172. * RETURN: Status
  173. *
  174. * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
  175. * Called with interrupts ENABLED.
  176. *
  177. ******************************************************************************/
  178. acpi_status acpi_hw_extended_wake(u8 sleep_state)
  179. {
  180. ACPI_FUNCTION_TRACE(hw_extended_wake);
  181. /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
  182. acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
  183. /* Execute the wake methods */
  184. acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING);
  185. acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state);
  186. /*
  187. * Some BIOS code assumes that WAK_STS will be cleared on resume
  188. * and use it to determine whether the system is rebooting or
  189. * resuming. Clear WAK_STS for compatibility.
  190. */
  191. (void)acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
  192. acpi_gbl_system_awake_and_running = TRUE;
  193. acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING);
  194. return_ACPI_STATUS(AE_OK);
  195. }