evxfevnt.c 10 KB

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