evevent.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /******************************************************************************
  2. *
  3. * Module Name: evevent - Fixed Event handling and dispatch
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, 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. /* If Hardware Reduced flag is set, there are no fixed events */
  66. if (acpi_gbl_reduced_hardware) {
  67. return_ACPI_STATUS(AE_OK);
  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
  72. * are 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_xrupt_handlers
  91. *
  92. * PARAMETERS: None
  93. *
  94. * RETURN: Status
  95. *
  96. * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
  97. *
  98. ******************************************************************************/
  99. acpi_status acpi_ev_install_xrupt_handlers(void)
  100. {
  101. acpi_status status;
  102. ACPI_FUNCTION_TRACE(ev_install_xrupt_handlers);
  103. /* If Hardware Reduced flag is set, there is no ACPI h/w */
  104. if (acpi_gbl_reduced_hardware) {
  105. return_ACPI_STATUS(AE_OK);
  106. }
  107. /* Install the SCI handler */
  108. status = acpi_ev_install_sci_handler();
  109. if (ACPI_FAILURE(status)) {
  110. ACPI_EXCEPTION((AE_INFO, status,
  111. "Unable to install System Control Interrupt handler"));
  112. return_ACPI_STATUS(status);
  113. }
  114. /* Install the handler for the Global Lock */
  115. status = acpi_ev_init_global_lock_handler();
  116. if (ACPI_FAILURE(status)) {
  117. ACPI_EXCEPTION((AE_INFO, status,
  118. "Unable to initialize Global Lock handler"));
  119. return_ACPI_STATUS(status);
  120. }
  121. acpi_gbl_events_initialized = TRUE;
  122. return_ACPI_STATUS(status);
  123. }
  124. /*******************************************************************************
  125. *
  126. * FUNCTION: acpi_ev_fixed_event_initialize
  127. *
  128. * PARAMETERS: None
  129. *
  130. * RETURN: Status
  131. *
  132. * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
  133. *
  134. ******************************************************************************/
  135. static acpi_status acpi_ev_fixed_event_initialize(void)
  136. {
  137. u32 i;
  138. acpi_status status;
  139. /*
  140. * Initialize the structure that keeps track of fixed event handlers and
  141. * enable the fixed events.
  142. */
  143. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
  144. acpi_gbl_fixed_event_handlers[i].handler = NULL;
  145. acpi_gbl_fixed_event_handlers[i].context = NULL;
  146. /* Disable the fixed event */
  147. if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
  148. status =
  149. acpi_write_bit_register(acpi_gbl_fixed_event_info
  150. [i].enable_register_id,
  151. ACPI_DISABLE_EVENT);
  152. if (ACPI_FAILURE(status)) {
  153. return (status);
  154. }
  155. }
  156. }
  157. return (AE_OK);
  158. }
  159. /*******************************************************************************
  160. *
  161. * FUNCTION: acpi_ev_fixed_event_detect
  162. *
  163. * PARAMETERS: None
  164. *
  165. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  166. *
  167. * DESCRIPTION: Checks the PM status register for active fixed events
  168. *
  169. ******************************************************************************/
  170. u32 acpi_ev_fixed_event_detect(void)
  171. {
  172. u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
  173. u32 fixed_status;
  174. u32 fixed_enable;
  175. u32 i;
  176. ACPI_FUNCTION_NAME(ev_fixed_event_detect);
  177. /*
  178. * Read the fixed feature status and enable registers, as all the cases
  179. * depend on their values. Ignore errors here.
  180. */
  181. (void)acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, &fixed_status);
  182. (void)acpi_hw_register_read(ACPI_REGISTER_PM1_ENABLE, &fixed_enable);
  183. ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
  184. "Fixed Event Block: Enable %08X Status %08X\n",
  185. fixed_enable, fixed_status));
  186. /*
  187. * Check for all possible Fixed Events and dispatch those that are active
  188. */
  189. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
  190. /* Both the status and enable bits must be on for this event */
  191. if ((fixed_status & acpi_gbl_fixed_event_info[i].
  192. status_bit_mask)
  193. && (fixed_enable & acpi_gbl_fixed_event_info[i].
  194. enable_bit_mask)) {
  195. /*
  196. * Found an active (signalled) event. Invoke global event
  197. * handler if present.
  198. */
  199. acpi_fixed_event_count[i]++;
  200. if (acpi_gbl_global_event_handler) {
  201. acpi_gbl_global_event_handler
  202. (ACPI_EVENT_TYPE_FIXED, NULL, i,
  203. acpi_gbl_global_event_handler_context);
  204. }
  205. int_status |= acpi_ev_fixed_event_dispatch(i);
  206. }
  207. }
  208. return (int_status);
  209. }
  210. /*******************************************************************************
  211. *
  212. * FUNCTION: acpi_ev_fixed_event_dispatch
  213. *
  214. * PARAMETERS: Event - Event type
  215. *
  216. * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  217. *
  218. * DESCRIPTION: Clears the status bit for the requested event, calls the
  219. * handler that previously registered for the event.
  220. *
  221. ******************************************************************************/
  222. static u32 acpi_ev_fixed_event_dispatch(u32 event)
  223. {
  224. ACPI_FUNCTION_ENTRY();
  225. /* Clear the status bit */
  226. (void)acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  227. status_register_id, ACPI_CLEAR_STATUS);
  228. /*
  229. * Make sure we've got a handler. If not, report an error. The event is
  230. * disabled to prevent further interrupts.
  231. */
  232. if (NULL == acpi_gbl_fixed_event_handlers[event].handler) {
  233. (void)acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  234. enable_register_id,
  235. ACPI_DISABLE_EVENT);
  236. ACPI_ERROR((AE_INFO,
  237. "No installed handler for fixed event [0x%08X]",
  238. event));
  239. return (ACPI_INTERRUPT_NOT_HANDLED);
  240. }
  241. /* Invoke the Fixed Event handler */
  242. return ((acpi_gbl_fixed_event_handlers[event].
  243. handler) (acpi_gbl_fixed_event_handlers[event].context));
  244. }