/drivers/acpi/hardware/hwacpi.c

https://bitbucket.org/evzijst/gittest · C · 230 lines · 85 code · 44 blank · 101 comment · 14 complexity · d426a77ba390ee2a4af60cd17c95db2d MD5 · raw file

  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 various ACPI registers
  54. *
  55. ******************************************************************************/
  56. acpi_status
  57. acpi_hw_initialize (
  58. void)
  59. {
  60. acpi_status status;
  61. ACPI_FUNCTION_TRACE ("hw_initialize");
  62. /* We must have the ACPI tables by the time we get here */
  63. if (!acpi_gbl_FADT) {
  64. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "A FADT is not loaded\n"));
  65. return_ACPI_STATUS (AE_NO_ACPI_TABLES);
  66. }
  67. /* Sanity check the FADT for valid values */
  68. status = acpi_ut_validate_fadt ();
  69. if (ACPI_FAILURE (status)) {
  70. return_ACPI_STATUS (status);
  71. }
  72. return_ACPI_STATUS (AE_OK);
  73. }
  74. /******************************************************************************
  75. *
  76. * FUNCTION: acpi_hw_set_mode
  77. *
  78. * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
  79. *
  80. * RETURN: Status
  81. *
  82. * DESCRIPTION: Transitions the system into the requested mode.
  83. *
  84. ******************************************************************************/
  85. acpi_status
  86. acpi_hw_set_mode (
  87. u32 mode)
  88. {
  89. acpi_status status;
  90. u32 retry;
  91. ACPI_FUNCTION_TRACE ("hw_set_mode");
  92. /*
  93. * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
  94. * system does not support mode transition.
  95. */
  96. if (!acpi_gbl_FADT->smi_cmd) {
  97. ACPI_REPORT_ERROR (("No SMI_CMD in FADT, mode transition failed.\n"));
  98. return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
  99. }
  100. /*
  101. * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
  102. * in FADT: If it is zero, enabling or disabling is not supported.
  103. * As old systems may have used zero for mode transition,
  104. * we make sure both the numbers are zero to determine these
  105. * transitions are not supported.
  106. */
  107. if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) {
  108. ACPI_REPORT_ERROR (("No ACPI mode transition supported in this system (enable/disable both zero)\n"));
  109. return_ACPI_STATUS (AE_OK);
  110. }
  111. switch (mode) {
  112. case ACPI_SYS_MODE_ACPI:
  113. /* BIOS should have disabled ALL fixed and GP events */
  114. status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
  115. (u32) acpi_gbl_FADT->acpi_enable, 8);
  116. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n"));
  117. break;
  118. case ACPI_SYS_MODE_LEGACY:
  119. /*
  120. * BIOS should clear all fixed status bits and restore fixed event
  121. * enable bits to default
  122. */
  123. status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
  124. (u32) acpi_gbl_FADT->acpi_disable, 8);
  125. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  126. "Attempting to enable Legacy (non-ACPI) mode\n"));
  127. break;
  128. default:
  129. return_ACPI_STATUS (AE_BAD_PARAMETER);
  130. }
  131. if (ACPI_FAILURE (status)) {
  132. ACPI_REPORT_ERROR (("Could not write mode change, %s\n", acpi_format_exception (status)));
  133. return_ACPI_STATUS (status);
  134. }
  135. /*
  136. * Some hardware takes a LONG time to switch modes. Give them 3 sec to
  137. * do so, but allow faster systems to proceed more quickly.
  138. */
  139. retry = 3000;
  140. while (retry) {
  141. if (acpi_hw_get_mode() == mode) {
  142. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n", mode));
  143. return_ACPI_STATUS (AE_OK);
  144. }
  145. acpi_os_stall(1000);
  146. retry--;
  147. }
  148. ACPI_REPORT_ERROR (("Hardware never changed modes\n"));
  149. return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
  150. }
  151. /******************************************************************************
  152. *
  153. * FUNCTION: acpi_hw_get_mode
  154. *
  155. * PARAMETERS: none
  156. *
  157. * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
  158. *
  159. * DESCRIPTION: Return current operating state of system. Determined by
  160. * querying the SCI_EN bit.
  161. *
  162. ******************************************************************************/
  163. u32
  164. acpi_hw_get_mode (void)
  165. {
  166. acpi_status status;
  167. u32 value;
  168. ACPI_FUNCTION_TRACE ("hw_get_mode");
  169. /*
  170. * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
  171. * system does not support mode transition.
  172. */
  173. if (!acpi_gbl_FADT->smi_cmd) {
  174. return_VALUE (ACPI_SYS_MODE_ACPI);
  175. }
  176. status = acpi_get_register (ACPI_BITREG_SCI_ENABLE, &value, ACPI_MTX_LOCK);
  177. if (ACPI_FAILURE (status)) {
  178. return_VALUE (ACPI_SYS_MODE_LEGACY);
  179. }
  180. if (value) {
  181. return_VALUE (ACPI_SYS_MODE_ACPI);
  182. }
  183. else {
  184. return_VALUE (ACPI_SYS_MODE_LEGACY);
  185. }
  186. }