evevent.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /******************************************************************************
  2. *
  3. * Module Name: evevent - Fixed Event handling and dispatch
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, R. Byron Moore
  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 <acpi/acevents.h>
  44. #define _COMPONENT ACPI_EVENTS
  45. ACPI_MODULE_NAME("evevent")
  46. /* Local prototypes */
  47. static acpi_status acpi_ev_fixed_event_initialize(void);
  48. static u32 acpi_ev_fixed_event_dispatch(u32 event);
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_ev_initialize_events
  52. *
  53. * PARAMETERS: None
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
  58. *
  59. ******************************************************************************/
  60. acpi_status acpi_ev_initialize_events(void)
  61. {
  62. acpi_status status;
  63. ACPI_FUNCTION_TRACE("ev_initialize_events");
  64. /* Make sure we have ACPI tables */
  65. if (!acpi_gbl_DSDT) {
  66. ACPI_WARNING((AE_INFO, "No ACPI tables present!"));
  67. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  68. }
  69. /*
  70. * Initialize the Fixed and General Purpose Events. This is done prior to
  71. * enabling SCIs to prevent interrupts from occurring before the handlers are
  72. * installed.
  73. */
  74. status = acpi_ev_fixed_event_initialize();
  75. if (ACPI_FAILURE(status)) {
  76. ACPI_EXCEPTION((AE_INFO, status,
  77. "Unable to initialize fixed events"));
  78. return_ACPI_STATUS(status);
  79. }
  80. status = acpi_ev_gpe_initialize();
  81. if (ACPI_FAILURE(status)) {
  82. ACPI_EXCEPTION((AE_INFO, status,
  83. "Unable to initialize general purpose events"));
  84. return_ACPI_STATUS(status);
  85. }
  86. return_ACPI_STATUS(status);
  87. }
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_ev_install_fadt_gpes
  91. *
  92. * PARAMETERS: None
  93. *
  94. * RETURN: Status
  95. *
  96. * DESCRIPTION: Completes initialization of the FADT-defined GPE blocks
  97. * (0 and 1). This causes the _PRW methods to be run, so the HW
  98. * must be fully initialized at this point, including global lock
  99. * support.
  100. *
  101. ******************************************************************************/
  102. acpi_status acpi_ev_install_fadt_gpes(void)
  103. {
  104. acpi_status status;
  105. ACPI_FUNCTION_TRACE("ev_install_fadt_gpes");
  106. /* Namespace must be locked */
  107. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  108. if (ACPI_FAILURE(status)) {
  109. return (status);
  110. }
  111. /* FADT GPE Block 0 */
  112. (void)acpi_ev_initialize_gpe_block(acpi_gbl_fadt_gpe_device,
  113. acpi_gbl_gpe_fadt_blocks[0]);
  114. /* FADT GPE Block 1 */
  115. (void)acpi_ev_initialize_gpe_block(acpi_gbl_fadt_gpe_device,
  116. acpi_gbl_gpe_fadt_blocks[1]);
  117. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  118. return_ACPI_STATUS(AE_OK);
  119. }
  120. /*******************************************************************************
  121. *
  122. * FUNCTION: acpi_ev_install_xrupt_handlers
  123. *
  124. * PARAMETERS: None
  125. *
  126. * RETURN: Status
  127. *
  128. * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
  129. *
  130. ******************************************************************************/
  131. acpi_status acpi_ev_install_xrupt_handlers(void)
  132. {
  133. acpi_status status;
  134. ACPI_FUNCTION_TRACE("ev_install_xrupt_handlers");
  135. /* Install the SCI handler */
  136. status = acpi_ev_install_sci_handler();
  137. if (ACPI_FAILURE(status)) {
  138. ACPI_EXCEPTION((AE_INFO, status,
  139. "Unable to install System Control Interrupt handler"));
  140. return_ACPI_STATUS(status);
  141. }
  142. /* Install the handler for the Global Lock */
  143. status = acpi_ev_init_global_lock_handler();
  144. if (ACPI_FAILURE(status)) {
  145. ACPI_EXCEPTION((AE_INFO, status,
  146. "Unable to initialize Global Lock handler"));
  147. return_ACPI_STATUS(status);
  148. }
  149. acpi_gbl_events_initialized = TRUE;
  150. return_ACPI_STATUS(status);
  151. }
  152. /*******************************************************************************
  153. *
  154. * FUNCTION: acpi_ev_fixed_event_initialize
  155. *
  156. * PARAMETERS: None
  157. *
  158. * RETURN: Status
  159. *
  160. * DESCRIPTION: Install the fixed event handlers and enable the fixed events.
  161. *
  162. ******************************************************************************/
  163. static acpi_status acpi_ev_fixed_event_initialize(void)
  164. {
  165. acpi_native_uint i;
  166. acpi_status status;
  167. /*
  168. * Initialize the structure that keeps track of fixed event handlers
  169. * and enable the fixed events.
  170. */
  171. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
  172. acpi_gbl_fixed_event_handlers[i].handler = NULL;
  173. acpi_gbl_fixed_event_handlers[i].context = NULL;
  174. /* Enable the fixed event */
  175. if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
  176. status =
  177. acpi_set_register(acpi_gbl_fixed_event_info[i].
  178. enable_register_id, 0,
  179. ACPI_MTX_LOCK);
  180. if (ACPI_FAILURE(status)) {
  181. return (status);
  182. }
  183. }
  184. }
  185. return (AE_OK);
  186. }
  187. /*******************************************************************************
  188. *
  189. * FUNCTION: acpi_ev_fixed_event_detect
  190. *
  191. * PARAMETERS: None
  192. *
  193. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  194. *
  195. * DESCRIPTION: Checks the PM status register for active fixed events
  196. *
  197. ******************************************************************************/
  198. u32 acpi_ev_fixed_event_detect(void)
  199. {
  200. u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
  201. u32 fixed_status;
  202. u32 fixed_enable;
  203. acpi_native_uint i;
  204. ACPI_FUNCTION_NAME("ev_fixed_event_detect");
  205. /*
  206. * Read the fixed feature status and enable registers, as all the cases
  207. * depend on their values. Ignore errors here.
  208. */
  209. (void)acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
  210. ACPI_REGISTER_PM1_STATUS, &fixed_status);
  211. (void)acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
  212. ACPI_REGISTER_PM1_ENABLE, &fixed_enable);
  213. ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
  214. "Fixed Event Block: Enable %08X Status %08X\n",
  215. fixed_enable, fixed_status));
  216. /*
  217. * Check for all possible Fixed Events and dispatch those that are active
  218. */
  219. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
  220. /* Both the status and enable bits must be on for this event */
  221. if ((fixed_status & acpi_gbl_fixed_event_info[i].
  222. status_bit_mask)
  223. && (fixed_enable & acpi_gbl_fixed_event_info[i].
  224. enable_bit_mask)) {
  225. /* Found an active (signalled) event */
  226. int_status |= acpi_ev_fixed_event_dispatch((u32) i);
  227. }
  228. }
  229. return (int_status);
  230. }
  231. /*******************************************************************************
  232. *
  233. * FUNCTION: acpi_ev_fixed_event_dispatch
  234. *
  235. * PARAMETERS: Event - Event type
  236. *
  237. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  238. *
  239. * DESCRIPTION: Clears the status bit for the requested event, calls the
  240. * handler that previously registered for the event.
  241. *
  242. ******************************************************************************/
  243. static u32 acpi_ev_fixed_event_dispatch(u32 event)
  244. {
  245. ACPI_FUNCTION_ENTRY();
  246. /* Clear the status bit */
  247. (void)acpi_set_register(acpi_gbl_fixed_event_info[event].
  248. status_register_id, 1, ACPI_MTX_DO_NOT_LOCK);
  249. /*
  250. * Make sure we've got a handler. If not, report an error.
  251. * The event is disabled to prevent further interrupts.
  252. */
  253. if (NULL == acpi_gbl_fixed_event_handlers[event].handler) {
  254. (void)acpi_set_register(acpi_gbl_fixed_event_info[event].
  255. enable_register_id, 0,
  256. ACPI_MTX_DO_NOT_LOCK);
  257. ACPI_ERROR((AE_INFO,
  258. "No installed handler for fixed event [%08X]",
  259. event));
  260. return (ACPI_INTERRUPT_NOT_HANDLED);
  261. }
  262. /* Invoke the Fixed Event handler */
  263. return ((acpi_gbl_fixed_event_handlers[event].
  264. handler) (acpi_gbl_fixed_event_handlers[event].context));
  265. }