hwesleep.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 - 2015, 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 <linux/acpi.h>
  45. #include "accommon.h"
  46. #define _COMPONENT ACPI_HARDWARE
  47. ACPI_MODULE_NAME("hwesleep")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_hw_execute_sleep_method
  51. *
  52. * PARAMETERS: method_pathname - Pathname of method to execute
  53. * integer_argument - Argument to pass to the method
  54. *
  55. * RETURN: None
  56. *
  57. * DESCRIPTION: Execute a sleep/wake related method with one integer argument
  58. * and no return value.
  59. *
  60. ******************************************************************************/
  61. void acpi_hw_execute_sleep_method(char *method_pathname, u32 integer_argument)
  62. {
  63. struct acpi_object_list arg_list;
  64. union acpi_object arg;
  65. acpi_status status;
  66. ACPI_FUNCTION_TRACE(hw_execute_sleep_method);
  67. /* One argument, integer_argument; No return value expected */
  68. arg_list.count = 1;
  69. arg_list.pointer = &arg;
  70. arg.type = ACPI_TYPE_INTEGER;
  71. arg.integer.value = (u64)integer_argument;
  72. status = acpi_evaluate_object(NULL, method_pathname, &arg_list, NULL);
  73. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  74. ACPI_EXCEPTION((AE_INFO, status, "While executing method %s",
  75. method_pathname));
  76. }
  77. return_VOID;
  78. }
  79. /*******************************************************************************
  80. *
  81. * FUNCTION: acpi_hw_extended_sleep
  82. *
  83. * PARAMETERS: sleep_state - Which sleep state to enter
  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)
  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. /* Flush caches, as per ACPI specification */
  111. ACPI_FLUSH_CPU_CACHE();
  112. status = acpi_os_prepare_extended_sleep(sleep_state,
  113. acpi_gbl_sleep_type_a,
  114. acpi_gbl_sleep_type_b);
  115. if (ACPI_SKIP(status))
  116. return_ACPI_STATUS(AE_OK);
  117. if (ACPI_FAILURE(status))
  118. return_ACPI_STATUS(status);
  119. /*
  120. * Set the SLP_TYP and SLP_EN bits.
  121. *
  122. * Note: We only use the first value returned by the \_Sx method
  123. * (acpi_gbl_sleep_type_a) - As per ACPI specification.
  124. */
  125. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  126. "Entering sleep state [S%u]\n", sleep_state));
  127. sleep_type_value =
  128. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  129. ACPI_X_SLEEP_TYPE_MASK);
  130. status = acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
  131. &acpi_gbl_FADT.sleep_control);
  132. if (ACPI_FAILURE(status)) {
  133. return_ACPI_STATUS(status);
  134. }
  135. /* Wait for transition back to Working State */
  136. do {
  137. status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
  138. if (ACPI_FAILURE(status)) {
  139. return_ACPI_STATUS(status);
  140. }
  141. } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
  142. return_ACPI_STATUS(AE_OK);
  143. }
  144. /*******************************************************************************
  145. *
  146. * FUNCTION: acpi_hw_extended_wake_prep
  147. *
  148. * PARAMETERS: sleep_state - Which sleep state we just exited
  149. *
  150. * RETURN: Status
  151. *
  152. * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
  153. * a sleep. Called with interrupts ENABLED.
  154. *
  155. ******************************************************************************/
  156. acpi_status acpi_hw_extended_wake_prep(u8 sleep_state)
  157. {
  158. acpi_status status;
  159. u8 sleep_type_value;
  160. ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
  161. status = acpi_get_sleep_type_data(ACPI_STATE_S0,
  162. &acpi_gbl_sleep_type_a,
  163. &acpi_gbl_sleep_type_b);
  164. if (ACPI_SUCCESS(status)) {
  165. sleep_type_value =
  166. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  167. ACPI_X_SLEEP_TYPE_MASK);
  168. (void)acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
  169. &acpi_gbl_FADT.sleep_control);
  170. }
  171. return_ACPI_STATUS(AE_OK);
  172. }
  173. /*******************************************************************************
  174. *
  175. * FUNCTION: acpi_hw_extended_wake
  176. *
  177. * PARAMETERS: sleep_state - Which sleep state we just exited
  178. *
  179. * RETURN: Status
  180. *
  181. * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
  182. * Called with interrupts ENABLED.
  183. *
  184. ******************************************************************************/
  185. acpi_status acpi_hw_extended_wake(u8 sleep_state)
  186. {
  187. ACPI_FUNCTION_TRACE(hw_extended_wake);
  188. /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
  189. acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
  190. /* Execute the wake methods */
  191. acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING);
  192. acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state);
  193. /*
  194. * Some BIOS code assumes that WAK_STS will be cleared on resume
  195. * and use it to determine whether the system is rebooting or
  196. * resuming. Clear WAK_STS for compatibility.
  197. */
  198. (void)acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
  199. acpi_gbl_system_awake_and_running = TRUE;
  200. acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING);
  201. return_ACPI_STATUS(AE_OK);
  202. }