hwacpi.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /******************************************************************************
  2. *
  3. * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #define _COMPONENT ACPI_HARDWARE
  44. ACPI_MODULE_NAME ("hwacpi")
  45. /******************************************************************************
  46. *
  47. * FUNCTION: acpi_hw_initialize
  48. *
  49. * PARAMETERS: None
  50. *
  51. * RETURN: Status
  52. *
  53. * DESCRIPTION: Initialize and validate the various ACPI registers defined in
  54. * the FADT.
  55. *
  56. ******************************************************************************/
  57. acpi_status
  58. acpi_hw_initialize (
  59. void)
  60. {
  61. acpi_status status;
  62. ACPI_FUNCTION_TRACE ("hw_initialize");
  63. /* We must have the ACPI tables by the time we get here */
  64. if (!acpi_gbl_FADT) {
  65. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No FADT is present\n"));
  66. return_ACPI_STATUS (AE_NO_ACPI_TABLES);
  67. }
  68. /* Sanity check the FADT for valid values */
  69. status = acpi_ut_validate_fadt ();
  70. if (ACPI_FAILURE (status)) {
  71. return_ACPI_STATUS (status);
  72. }
  73. return_ACPI_STATUS (AE_OK);
  74. }
  75. /******************************************************************************
  76. *
  77. * FUNCTION: acpi_hw_set_mode
  78. *
  79. * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
  80. *
  81. * RETURN: Status
  82. *
  83. * DESCRIPTION: Transitions the system into the requested mode.
  84. *
  85. ******************************************************************************/
  86. acpi_status
  87. acpi_hw_set_mode (
  88. u32 mode)
  89. {
  90. acpi_status status;
  91. u32 retry;
  92. ACPI_FUNCTION_TRACE ("hw_set_mode");
  93. /*
  94. * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
  95. * system does not support mode transition.
  96. */
  97. if (!acpi_gbl_FADT->smi_cmd) {
  98. ACPI_REPORT_ERROR (("No SMI_CMD in FADT, mode transition failed.\n"));
  99. return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
  100. }
  101. /*
  102. * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
  103. * in FADT: If it is zero, enabling or disabling is not supported.
  104. * As old systems may have used zero for mode transition,
  105. * we make sure both the numbers are zero to determine these
  106. * transitions are not supported.
  107. */
  108. if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) {
  109. ACPI_REPORT_ERROR ((
  110. "No ACPI mode transition supported in this system (enable/disable both zero)\n"));
  111. return_ACPI_STATUS (AE_OK);
  112. }
  113. switch (mode) {
  114. case ACPI_SYS_MODE_ACPI:
  115. /* BIOS should have disabled ALL fixed and GP events */
  116. status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
  117. (u32) acpi_gbl_FADT->acpi_enable, 8);
  118. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n"));
  119. break;
  120. case ACPI_SYS_MODE_LEGACY:
  121. /*
  122. * BIOS should clear all fixed status bits and restore fixed event
  123. * enable bits to default
  124. */
  125. status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
  126. (u32) acpi_gbl_FADT->acpi_disable, 8);
  127. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  128. "Attempting to enable Legacy (non-ACPI) mode\n"));
  129. break;
  130. default:
  131. return_ACPI_STATUS (AE_BAD_PARAMETER);
  132. }
  133. if (ACPI_FAILURE (status)) {
  134. ACPI_REPORT_ERROR (("Could not write mode change, %s\n",
  135. acpi_format_exception (status)));
  136. return_ACPI_STATUS (status);
  137. }
  138. /*
  139. * Some hardware takes a LONG time to switch modes. Give them 3 sec to
  140. * do so, but allow faster systems to proceed more quickly.
  141. */
  142. retry = 3000;
  143. while (retry) {
  144. if (acpi_hw_get_mode() == mode) {
  145. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n",
  146. mode));
  147. return_ACPI_STATUS (AE_OK);
  148. }
  149. acpi_os_stall(1000);
  150. retry--;
  151. }
  152. ACPI_REPORT_ERROR (("Hardware never changed modes\n"));
  153. return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
  154. }
  155. /*******************************************************************************
  156. *
  157. * FUNCTION: acpi_hw_get_mode
  158. *
  159. * PARAMETERS: none
  160. *
  161. * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
  162. *
  163. * DESCRIPTION: Return current operating state of system. Determined by
  164. * querying the SCI_EN bit.
  165. *
  166. ******************************************************************************/
  167. u32
  168. acpi_hw_get_mode (
  169. void)
  170. {
  171. acpi_status status;
  172. u32 value;
  173. ACPI_FUNCTION_TRACE ("hw_get_mode");
  174. /*
  175. * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
  176. * system does not support mode transition.
  177. */
  178. if (!acpi_gbl_FADT->smi_cmd) {
  179. return_VALUE (ACPI_SYS_MODE_ACPI);
  180. }
  181. status = acpi_get_register (ACPI_BITREG_SCI_ENABLE, &value, ACPI_MTX_LOCK);
  182. if (ACPI_FAILURE (status)) {
  183. return_VALUE (ACPI_SYS_MODE_LEGACY);
  184. }
  185. if (value) {
  186. return_VALUE (ACPI_SYS_MODE_ACPI);
  187. }
  188. else {
  189. return_VALUE (ACPI_SYS_MODE_LEGACY);
  190. }
  191. }