evxfevnt.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #define EXPORT_ACPI_INTERFACES
  10. #include <acpi/acpi.h>
  11. #include "accommon.h"
  12. #include "actables.h"
  13. #define _COMPONENT ACPI_EVENTS
  14. ACPI_MODULE_NAME("evxfevnt")
  15. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  16. /*******************************************************************************
  17. *
  18. * FUNCTION: acpi_enable
  19. *
  20. * PARAMETERS: None
  21. *
  22. * RETURN: Status
  23. *
  24. * DESCRIPTION: Transfers the system into ACPI mode.
  25. *
  26. ******************************************************************************/
  27. acpi_status acpi_enable(void)
  28. {
  29. acpi_status status;
  30. int retry;
  31. ACPI_FUNCTION_TRACE(acpi_enable);
  32. /* ACPI tables must be present */
  33. if (acpi_gbl_fadt_index == ACPI_INVALID_TABLE_INDEX) {
  34. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  35. }
  36. /* If the Hardware Reduced flag is set, machine is always in acpi mode */
  37. if (acpi_gbl_reduced_hardware) {
  38. return_ACPI_STATUS(AE_OK);
  39. }
  40. /* Check current mode */
  41. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  42. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  43. "System is already in ACPI mode\n"));
  44. return_ACPI_STATUS(AE_OK);
  45. }
  46. /* Transition to ACPI mode */
  47. status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
  48. if (ACPI_FAILURE(status)) {
  49. ACPI_ERROR((AE_INFO,
  50. "Could not transition to ACPI mode"));
  51. return_ACPI_STATUS(status);
  52. }
  53. /* Sanity check that transition succeeded */
  54. for (retry = 0; retry < 30000; ++retry) {
  55. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  56. if (retry != 0)
  57. ACPI_WARNING((AE_INFO,
  58. "Platform took > %d00 usec to enter ACPI mode", retry));
  59. return_ACPI_STATUS(AE_OK);
  60. }
  61. acpi_os_stall(100); /* 100 usec */
  62. }
  63. ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
  64. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  65. }
  66. ACPI_EXPORT_SYMBOL(acpi_enable)
  67. /*******************************************************************************
  68. *
  69. * FUNCTION: acpi_disable
  70. *
  71. * PARAMETERS: None
  72. *
  73. * RETURN: Status
  74. *
  75. * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
  76. *
  77. ******************************************************************************/
  78. acpi_status acpi_disable(void)
  79. {
  80. acpi_status status = AE_OK;
  81. ACPI_FUNCTION_TRACE(acpi_disable);
  82. /* If the Hardware Reduced flag is set, machine is always in acpi mode */
  83. if (acpi_gbl_reduced_hardware) {
  84. return_ACPI_STATUS(AE_OK);
  85. }
  86. if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
  87. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  88. "System is already in legacy (non-ACPI) mode\n"));
  89. } else {
  90. /* Transition to LEGACY mode */
  91. status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
  92. if (ACPI_FAILURE(status)) {
  93. ACPI_ERROR((AE_INFO,
  94. "Could not exit ACPI mode to legacy mode"));
  95. return_ACPI_STATUS(status);
  96. }
  97. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
  98. }
  99. return_ACPI_STATUS(status);
  100. }
  101. ACPI_EXPORT_SYMBOL(acpi_disable)
  102. /*******************************************************************************
  103. *
  104. * FUNCTION: acpi_enable_event
  105. *
  106. * PARAMETERS: event - The fixed eventto be enabled
  107. * flags - Reserved
  108. *
  109. * RETURN: Status
  110. *
  111. * DESCRIPTION: Enable an ACPI event (fixed)
  112. *
  113. ******************************************************************************/
  114. acpi_status acpi_enable_event(u32 event, u32 flags)
  115. {
  116. acpi_status status = AE_OK;
  117. u32 value;
  118. ACPI_FUNCTION_TRACE(acpi_enable_event);
  119. /* If Hardware Reduced flag is set, there are no fixed events */
  120. if (acpi_gbl_reduced_hardware) {
  121. return_ACPI_STATUS(AE_OK);
  122. }
  123. /* Decode the Fixed Event */
  124. if (event > ACPI_EVENT_MAX) {
  125. return_ACPI_STATUS(AE_BAD_PARAMETER);
  126. }
  127. /*
  128. * Enable the requested fixed event (by writing a one to the enable
  129. * register bit)
  130. */
  131. status =
  132. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  133. enable_register_id, ACPI_ENABLE_EVENT);
  134. if (ACPI_FAILURE(status)) {
  135. return_ACPI_STATUS(status);
  136. }
  137. /* Make sure that the hardware responded */
  138. status =
  139. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  140. enable_register_id, &value);
  141. if (ACPI_FAILURE(status)) {
  142. return_ACPI_STATUS(status);
  143. }
  144. if (value != 1) {
  145. ACPI_ERROR((AE_INFO,
  146. "Could not enable %s event",
  147. acpi_ut_get_event_name(event)));
  148. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  149. }
  150. return_ACPI_STATUS(status);
  151. }
  152. ACPI_EXPORT_SYMBOL(acpi_enable_event)
  153. /*******************************************************************************
  154. *
  155. * FUNCTION: acpi_disable_event
  156. *
  157. * PARAMETERS: event - The fixed event to be disabled
  158. * flags - Reserved
  159. *
  160. * RETURN: Status
  161. *
  162. * DESCRIPTION: Disable an ACPI event (fixed)
  163. *
  164. ******************************************************************************/
  165. acpi_status acpi_disable_event(u32 event, u32 flags)
  166. {
  167. acpi_status status = AE_OK;
  168. u32 value;
  169. ACPI_FUNCTION_TRACE(acpi_disable_event);
  170. /* If Hardware Reduced flag is set, there are no fixed events */
  171. if (acpi_gbl_reduced_hardware) {
  172. return_ACPI_STATUS(AE_OK);
  173. }
  174. /* Decode the Fixed Event */
  175. if (event > ACPI_EVENT_MAX) {
  176. return_ACPI_STATUS(AE_BAD_PARAMETER);
  177. }
  178. /*
  179. * Disable the requested fixed event (by writing a zero to the enable
  180. * register bit)
  181. */
  182. status =
  183. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  184. enable_register_id, ACPI_DISABLE_EVENT);
  185. if (ACPI_FAILURE(status)) {
  186. return_ACPI_STATUS(status);
  187. }
  188. status =
  189. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  190. enable_register_id, &value);
  191. if (ACPI_FAILURE(status)) {
  192. return_ACPI_STATUS(status);
  193. }
  194. if (value != 0) {
  195. ACPI_ERROR((AE_INFO,
  196. "Could not disable %s events",
  197. acpi_ut_get_event_name(event)));
  198. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  199. }
  200. return_ACPI_STATUS(status);
  201. }
  202. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  203. /*******************************************************************************
  204. *
  205. * FUNCTION: acpi_clear_event
  206. *
  207. * PARAMETERS: event - The fixed event to be cleared
  208. *
  209. * RETURN: Status
  210. *
  211. * DESCRIPTION: Clear an ACPI event (fixed)
  212. *
  213. ******************************************************************************/
  214. acpi_status acpi_clear_event(u32 event)
  215. {
  216. acpi_status status = AE_OK;
  217. ACPI_FUNCTION_TRACE(acpi_clear_event);
  218. /* If Hardware Reduced flag is set, there are no fixed events */
  219. if (acpi_gbl_reduced_hardware) {
  220. return_ACPI_STATUS(AE_OK);
  221. }
  222. /* Decode the Fixed Event */
  223. if (event > ACPI_EVENT_MAX) {
  224. return_ACPI_STATUS(AE_BAD_PARAMETER);
  225. }
  226. /*
  227. * Clear the requested fixed event (By writing a one to the status
  228. * register bit)
  229. */
  230. status =
  231. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  232. status_register_id, ACPI_CLEAR_STATUS);
  233. return_ACPI_STATUS(status);
  234. }
  235. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  236. /*******************************************************************************
  237. *
  238. * FUNCTION: acpi_get_event_status
  239. *
  240. * PARAMETERS: event - The fixed event
  241. * event_status - Where the current status of the event will
  242. * be returned
  243. *
  244. * RETURN: Status
  245. *
  246. * DESCRIPTION: Obtains and returns the current status of the event
  247. *
  248. ******************************************************************************/
  249. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  250. {
  251. acpi_status status;
  252. acpi_event_status local_event_status = 0;
  253. u32 in_byte;
  254. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  255. if (!event_status) {
  256. return_ACPI_STATUS(AE_BAD_PARAMETER);
  257. }
  258. /* Decode the Fixed Event */
  259. if (event > ACPI_EVENT_MAX) {
  260. return_ACPI_STATUS(AE_BAD_PARAMETER);
  261. }
  262. /* Fixed event currently can be dispatched? */
  263. if (acpi_gbl_fixed_event_handlers[event].handler) {
  264. local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER;
  265. }
  266. /* Fixed event currently enabled? */
  267. status =
  268. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  269. enable_register_id, &in_byte);
  270. if (ACPI_FAILURE(status)) {
  271. return_ACPI_STATUS(status);
  272. }
  273. if (in_byte) {
  274. local_event_status |=
  275. (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
  276. }
  277. /* Fixed event currently active? */
  278. status =
  279. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  280. status_register_id, &in_byte);
  281. if (ACPI_FAILURE(status)) {
  282. return_ACPI_STATUS(status);
  283. }
  284. if (in_byte) {
  285. local_event_status |= ACPI_EVENT_FLAG_STATUS_SET;
  286. }
  287. (*event_status) = local_event_status;
  288. return_ACPI_STATUS(AE_OK);
  289. }
  290. ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  291. #endif /* !ACPI_REDUCED_HARDWARE */