evevent.c 8.6 KB

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