hwacpi.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #define _COMPONENT ACPI_HARDWARE
  12. ACPI_MODULE_NAME("hwacpi")
  13. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  14. /******************************************************************************
  15. *
  16. * FUNCTION: acpi_hw_set_mode
  17. *
  18. * PARAMETERS: mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
  19. *
  20. * RETURN: Status
  21. *
  22. * DESCRIPTION: Transitions the system into the requested mode.
  23. *
  24. ******************************************************************************/
  25. acpi_status acpi_hw_set_mode(u32 mode)
  26. {
  27. acpi_status status;
  28. ACPI_FUNCTION_TRACE(hw_set_mode);
  29. /* If the Hardware Reduced flag is set, machine is always in acpi mode */
  30. if (acpi_gbl_reduced_hardware) {
  31. return_ACPI_STATUS(AE_OK);
  32. }
  33. /*
  34. * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
  35. * system does not support mode transition.
  36. */
  37. if (!acpi_gbl_FADT.smi_command) {
  38. ACPI_ERROR((AE_INFO,
  39. "No SMI_CMD in FADT, mode transition failed"));
  40. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  41. }
  42. /*
  43. * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
  44. * in FADT: If it is zero, enabling or disabling is not supported.
  45. * As old systems may have used zero for mode transition,
  46. * we make sure both the numbers are zero to determine these
  47. * transitions are not supported.
  48. */
  49. if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) {
  50. ACPI_ERROR((AE_INFO,
  51. "No ACPI mode transition supported in this system "
  52. "(enable/disable both zero)"));
  53. return_ACPI_STATUS(AE_OK);
  54. }
  55. switch (mode) {
  56. case ACPI_SYS_MODE_ACPI:
  57. /* BIOS should have disabled ALL fixed and GP events */
  58. status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
  59. (u32) acpi_gbl_FADT.acpi_enable, 8);
  60. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  61. "Attempting to enable ACPI mode\n"));
  62. break;
  63. case ACPI_SYS_MODE_LEGACY:
  64. /*
  65. * BIOS should clear all fixed status bits and restore fixed event
  66. * enable bits to default
  67. */
  68. status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
  69. (u32)acpi_gbl_FADT.acpi_disable, 8);
  70. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  71. "Attempting to enable Legacy (non-ACPI) mode\n"));
  72. break;
  73. default:
  74. return_ACPI_STATUS(AE_BAD_PARAMETER);
  75. }
  76. if (ACPI_FAILURE(status)) {
  77. ACPI_EXCEPTION((AE_INFO, status,
  78. "Could not write ACPI mode change"));
  79. return_ACPI_STATUS(status);
  80. }
  81. return_ACPI_STATUS(AE_OK);
  82. }
  83. /*******************************************************************************
  84. *
  85. * FUNCTION: acpi_hw_get_mode
  86. *
  87. * PARAMETERS: none
  88. *
  89. * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
  90. *
  91. * DESCRIPTION: Return current operating state of system. Determined by
  92. * querying the SCI_EN bit.
  93. *
  94. ******************************************************************************/
  95. u32 acpi_hw_get_mode(void)
  96. {
  97. acpi_status status;
  98. u32 value;
  99. ACPI_FUNCTION_TRACE(hw_get_mode);
  100. /* If the Hardware Reduced flag is set, machine is always in acpi mode */
  101. if (acpi_gbl_reduced_hardware) {
  102. return_UINT32(ACPI_SYS_MODE_ACPI);
  103. }
  104. /*
  105. * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
  106. * system does not support mode transition.
  107. */
  108. if (!acpi_gbl_FADT.smi_command) {
  109. return_UINT32(ACPI_SYS_MODE_ACPI);
  110. }
  111. status = acpi_read_bit_register(ACPI_BITREG_SCI_ENABLE, &value);
  112. if (ACPI_FAILURE(status)) {
  113. return_UINT32(ACPI_SYS_MODE_LEGACY);
  114. }
  115. if (value) {
  116. return_UINT32(ACPI_SYS_MODE_ACPI);
  117. } else {
  118. return_UINT32(ACPI_SYS_MODE_LEGACY);
  119. }
  120. }
  121. #endif /* !ACPI_REDUCED_HARDWARE */