hwesleep.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. #include <linux/module.h>
  46. #define _COMPONENT ACPI_HARDWARE
  47. ACPI_MODULE_NAME("hwesleep")
  48. static unsigned int gts, bfs;
  49. module_param(gts, uint, 0644);
  50. module_param(bfs, uint, 0644);
  51. MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend.");
  52. MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".);
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_hw_execute_sleep_method
  56. *
  57. * PARAMETERS: method_name - Pathname of method to execute
  58. * integer_argument - Argument to pass to the method
  59. *
  60. * RETURN: None
  61. *
  62. * DESCRIPTION: Execute a sleep/wake related method with one integer argument
  63. * and no return value.
  64. *
  65. ******************************************************************************/
  66. void acpi_hw_execute_sleep_method(char *method_name, u32 integer_argument)
  67. {
  68. struct acpi_object_list arg_list;
  69. union acpi_object arg;
  70. acpi_status status;
  71. ACPI_FUNCTION_TRACE(hw_execute_sleep_method);
  72. if (!ACPI_STRCMP(METHOD_NAME__GTS, method_name) && !gts)
  73. return_VOID;
  74. if (!ACPI_STRCMP(METHOD_NAME__BFS, method_name) && !bfs)
  75. return_VOID;
  76. /* One argument, integer_argument; No return value expected */
  77. arg_list.count = 1;
  78. arg_list.pointer = &arg;
  79. arg.type = ACPI_TYPE_INTEGER;
  80. arg.integer.value = (u64)integer_argument;
  81. status = acpi_evaluate_object(NULL, method_name, &arg_list, NULL);
  82. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  83. ACPI_EXCEPTION((AE_INFO, status, "While executing method %s",
  84. method_name));
  85. }
  86. return_VOID;
  87. }
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_hw_extended_sleep
  91. *
  92. * PARAMETERS: sleep_state - Which sleep state to enter
  93. *
  94. * RETURN: Status
  95. *
  96. * DESCRIPTION: Enter a system sleep state via the extended FADT sleep
  97. * registers (V5 FADT).
  98. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
  99. *
  100. ******************************************************************************/
  101. acpi_status acpi_hw_extended_sleep(u8 sleep_state)
  102. {
  103. acpi_status status;
  104. u8 sleep_type_value;
  105. u64 sleep_status;
  106. ACPI_FUNCTION_TRACE(hw_extended_sleep);
  107. /* Extended sleep registers must be valid */
  108. if (!acpi_gbl_FADT.sleep_control.address ||
  109. !acpi_gbl_FADT.sleep_status.address) {
  110. return_ACPI_STATUS(AE_NOT_EXIST);
  111. }
  112. /* Clear wake status (WAK_STS) */
  113. status = acpi_write(ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
  114. if (ACPI_FAILURE(status)) {
  115. return_ACPI_STATUS(status);
  116. }
  117. acpi_gbl_system_awake_and_running = FALSE;
  118. /* Execute the _GTS method (Going To Sleep) */
  119. acpi_hw_execute_sleep_method(METHOD_NAME__GTS, sleep_state);
  120. /* Flush caches, as per ACPI specification */
  121. ACPI_FLUSH_CPU_CACHE();
  122. /*
  123. * Set the SLP_TYP and SLP_EN bits.
  124. *
  125. * Note: We only use the first value returned by the \_Sx method
  126. * (acpi_gbl_sleep_type_a) - As per ACPI specification.
  127. */
  128. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  129. "Entering sleep state [S%u]\n", sleep_state));
  130. sleep_type_value =
  131. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  132. ACPI_X_SLEEP_TYPE_MASK);
  133. status = acpi_write((sleep_type_value | ACPI_X_SLEEP_ENABLE),
  134. &acpi_gbl_FADT.sleep_control);
  135. if (ACPI_FAILURE(status)) {
  136. return_ACPI_STATUS(status);
  137. }
  138. /* Wait for transition back to Working State */
  139. do {
  140. status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
  141. if (ACPI_FAILURE(status)) {
  142. return_ACPI_STATUS(status);
  143. }
  144. } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
  145. return_ACPI_STATUS(AE_OK);
  146. }
  147. /*******************************************************************************
  148. *
  149. * FUNCTION: acpi_hw_extended_wake_prep
  150. *
  151. * PARAMETERS: sleep_state - Which sleep state we just exited
  152. *
  153. * RETURN: Status
  154. *
  155. * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
  156. * a sleep. Called with interrupts ENABLED.
  157. *
  158. ******************************************************************************/
  159. acpi_status acpi_hw_extended_wake_prep(u8 sleep_state)
  160. {
  161. acpi_status status;
  162. u8 sleep_type_value;
  163. ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
  164. status = acpi_get_sleep_type_data(ACPI_STATE_S0,
  165. &acpi_gbl_sleep_type_a,
  166. &acpi_gbl_sleep_type_b);
  167. if (ACPI_SUCCESS(status)) {
  168. sleep_type_value =
  169. ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
  170. ACPI_X_SLEEP_TYPE_MASK);
  171. (void)acpi_write((sleep_type_value | ACPI_X_SLEEP_ENABLE),
  172. &acpi_gbl_FADT.sleep_control);
  173. }
  174. acpi_hw_execute_sleep_method(METHOD_NAME__BFS, sleep_state);
  175. return_ACPI_STATUS(AE_OK);
  176. }
  177. /*******************************************************************************
  178. *
  179. * FUNCTION: acpi_hw_extended_wake
  180. *
  181. * PARAMETERS: sleep_state - Which sleep state we just exited
  182. *
  183. * RETURN: Status
  184. *
  185. * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
  186. * Called with interrupts ENABLED.
  187. *
  188. ******************************************************************************/
  189. acpi_status acpi_hw_extended_wake(u8 sleep_state)
  190. {
  191. ACPI_FUNCTION_TRACE(hw_extended_wake);
  192. /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
  193. acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
  194. /* Execute the wake methods */
  195. acpi_hw_execute_sleep_method(METHOD_NAME__SST, ACPI_SST_WAKING);
  196. acpi_hw_execute_sleep_method(METHOD_NAME__WAK, sleep_state);
  197. /*
  198. * Some BIOS code assumes that WAK_STS will be cleared on resume
  199. * and use it to determine whether the system is rebooting or
  200. * resuming. Clear WAK_STS for compatibility.
  201. */
  202. (void)acpi_write(ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
  203. acpi_gbl_system_awake_and_running = TRUE;
  204. acpi_hw_execute_sleep_method(METHOD_NAME__SST, ACPI_SST_WORKING);
  205. return_ACPI_STATUS(AE_OK);
  206. }