evevent.c 9.1 KB

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