evevent.c 8.8 KB

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