hwacpi.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /******************************************************************************
  2. *
  3. * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, Intel Corp.
  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. #include "accommon.h"
  44. #define _COMPONENT ACPI_HARDWARE
  45. ACPI_MODULE_NAME("hwacpi")
  46. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  47. /******************************************************************************
  48. *
  49. * FUNCTION: acpi_hw_set_mode
  50. *
  51. * PARAMETERS: mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
  52. *
  53. * RETURN: Status
  54. *
  55. * DESCRIPTION: Transitions the system into the requested mode.
  56. *
  57. ******************************************************************************/
  58. acpi_status acpi_hw_set_mode(u32 mode)
  59. {
  60. acpi_status status;
  61. ACPI_FUNCTION_TRACE(hw_set_mode);
  62. /* If the Hardware Reduced flag is set, machine is always in acpi mode */
  63. if (acpi_gbl_reduced_hardware) {
  64. return_ACPI_STATUS(AE_OK);
  65. }
  66. /*
  67. * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
  68. * system does not support mode transition.
  69. */
  70. if (!acpi_gbl_FADT.smi_command) {
  71. ACPI_ERROR((AE_INFO,
  72. "No SMI_CMD in FADT, mode transition failed"));
  73. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  74. }
  75. /*
  76. * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
  77. * in FADT: If it is zero, enabling or disabling is not supported.
  78. * As old systems may have used zero for mode transition,
  79. * we make sure both the numbers are zero to determine these
  80. * transitions are not supported.
  81. */
  82. if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) {
  83. ACPI_ERROR((AE_INFO,
  84. "No ACPI mode transition supported in this system "
  85. "(enable/disable both zero)"));
  86. return_ACPI_STATUS(AE_OK);
  87. }
  88. switch (mode) {
  89. case ACPI_SYS_MODE_ACPI:
  90. /* BIOS should have disabled ALL fixed and GP events */
  91. status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
  92. (u32) acpi_gbl_FADT.acpi_enable, 8);
  93. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  94. "Attempting to enable ACPI mode\n"));
  95. break;
  96. case ACPI_SYS_MODE_LEGACY:
  97. /*
  98. * BIOS should clear all fixed status bits and restore fixed event
  99. * enable bits to default
  100. */
  101. status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
  102. (u32)acpi_gbl_FADT.acpi_disable, 8);
  103. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  104. "Attempting to enable Legacy (non-ACPI) mode\n"));
  105. break;
  106. default:
  107. return_ACPI_STATUS(AE_BAD_PARAMETER);
  108. }
  109. if (ACPI_FAILURE(status)) {
  110. ACPI_EXCEPTION((AE_INFO, status,
  111. "Could not write ACPI mode change"));
  112. return_ACPI_STATUS(status);
  113. }
  114. return_ACPI_STATUS(AE_OK);
  115. }
  116. /*******************************************************************************
  117. *
  118. * FUNCTION: acpi_hw_get_mode
  119. *
  120. * PARAMETERS: none
  121. *
  122. * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
  123. *
  124. * DESCRIPTION: Return current operating state of system. Determined by
  125. * querying the SCI_EN bit.
  126. *
  127. ******************************************************************************/
  128. u32 acpi_hw_get_mode(void)
  129. {
  130. acpi_status status;
  131. u32 value;
  132. ACPI_FUNCTION_TRACE(hw_get_mode);
  133. /* If the Hardware Reduced flag is set, machine is always in acpi mode */
  134. if (acpi_gbl_reduced_hardware) {
  135. return_UINT32(ACPI_SYS_MODE_ACPI);
  136. }
  137. /*
  138. * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
  139. * system does not support mode transition.
  140. */
  141. if (!acpi_gbl_FADT.smi_command) {
  142. return_UINT32(ACPI_SYS_MODE_ACPI);
  143. }
  144. status = acpi_read_bit_register(ACPI_BITREG_SCI_ENABLE, &value);
  145. if (ACPI_FAILURE(status)) {
  146. return_UINT32(ACPI_SYS_MODE_LEGACY);
  147. }
  148. if (value) {
  149. return_UINT32(ACPI_SYS_MODE_ACPI);
  150. } else {
  151. return_UINT32(ACPI_SYS_MODE_LEGACY);
  152. }
  153. }
  154. #endif /* !ACPI_REDUCED_HARDWARE */