evxfevnt.c 9.3 KB

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