evsci.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*******************************************************************************
  2. *
  3. * Module Name: evsci - System Control Interrupt configuration and
  4. * legacy to ACPI mode state transition functions
  5. *
  6. ******************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2015, Intel Corp.
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "acevents.h"
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evsci")
  48. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  49. /* Local prototypes */
  50. static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context);
  51. /*******************************************************************************
  52. *
  53. * FUNCTION: acpi_ev_sci_dispatch
  54. *
  55. * PARAMETERS: None
  56. *
  57. * RETURN: Status code indicates whether interrupt was handled.
  58. *
  59. * DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers.
  60. *
  61. ******************************************************************************/
  62. u32 acpi_ev_sci_dispatch(void)
  63. {
  64. struct acpi_sci_handler_info *sci_handler;
  65. acpi_cpu_flags flags;
  66. u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
  67. ACPI_FUNCTION_NAME(ev_sci_dispatch);
  68. /* Are there any host-installed SCI handlers? */
  69. if (!acpi_gbl_sci_handler_list) {
  70. return (int_status);
  71. }
  72. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  73. /* Invoke all host-installed SCI handlers */
  74. sci_handler = acpi_gbl_sci_handler_list;
  75. while (sci_handler) {
  76. /* Invoke the installed handler (at interrupt level) */
  77. int_status |= sci_handler->address(sci_handler->context);
  78. sci_handler = sci_handler->next;
  79. }
  80. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  81. return (int_status);
  82. }
  83. /*******************************************************************************
  84. *
  85. * FUNCTION: acpi_ev_sci_xrupt_handler
  86. *
  87. * PARAMETERS: context - Calling Context
  88. *
  89. * RETURN: Status code indicates whether interrupt was handled.
  90. *
  91. * DESCRIPTION: Interrupt handler that will figure out what function or
  92. * control method to call to deal with a SCI.
  93. *
  94. ******************************************************************************/
  95. static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context)
  96. {
  97. struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
  98. u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
  99. ACPI_FUNCTION_TRACE(ev_sci_xrupt_handler);
  100. /*
  101. * We are guaranteed by the ACPICA initialization/shutdown code that
  102. * if this interrupt handler is installed, ACPI is enabled.
  103. */
  104. /*
  105. * Fixed Events:
  106. * Check for and dispatch any Fixed Events that have occurred
  107. */
  108. interrupt_handled |= acpi_ev_fixed_event_detect();
  109. /*
  110. * General Purpose Events:
  111. * Check for and dispatch any GPEs that have occurred
  112. */
  113. interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
  114. /* Invoke all host-installed SCI handlers */
  115. interrupt_handled |= acpi_ev_sci_dispatch();
  116. acpi_sci_count++;
  117. return_UINT32(interrupt_handled);
  118. }
  119. /*******************************************************************************
  120. *
  121. * FUNCTION: acpi_ev_gpe_xrupt_handler
  122. *
  123. * PARAMETERS: context - Calling Context
  124. *
  125. * RETURN: Status code indicates whether interrupt was handled.
  126. *
  127. * DESCRIPTION: Handler for GPE Block Device interrupts
  128. *
  129. ******************************************************************************/
  130. u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_xrupt_handler(void *context)
  131. {
  132. struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
  133. u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
  134. ACPI_FUNCTION_TRACE(ev_gpe_xrupt_handler);
  135. /*
  136. * We are guaranteed by the ACPICA initialization/shutdown code that
  137. * if this interrupt handler is installed, ACPI is enabled.
  138. */
  139. /* GPEs: Check for and dispatch any GPEs that have occurred */
  140. interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
  141. return_UINT32(interrupt_handled);
  142. }
  143. /******************************************************************************
  144. *
  145. * FUNCTION: acpi_ev_install_sci_handler
  146. *
  147. * PARAMETERS: none
  148. *
  149. * RETURN: Status
  150. *
  151. * DESCRIPTION: Installs SCI handler.
  152. *
  153. ******************************************************************************/
  154. u32 acpi_ev_install_sci_handler(void)
  155. {
  156. u32 status = AE_OK;
  157. ACPI_FUNCTION_TRACE(ev_install_sci_handler);
  158. status =
  159. acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
  160. acpi_ev_sci_xrupt_handler,
  161. acpi_gbl_gpe_xrupt_list_head);
  162. return_ACPI_STATUS(status);
  163. }
  164. /******************************************************************************
  165. *
  166. * FUNCTION: acpi_ev_remove_all_sci_handlers
  167. *
  168. * PARAMETERS: none
  169. *
  170. * RETURN: AE_OK if handler uninstalled, AE_ERROR if handler was not
  171. * installed to begin with
  172. *
  173. * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
  174. * taken. Remove all host-installed SCI handlers.
  175. *
  176. * Note: It doesn't seem important to disable all events or set the event
  177. * enable registers to their original values. The OS should disable
  178. * the SCI interrupt level when the handler is removed, so no more
  179. * events will come in.
  180. *
  181. ******************************************************************************/
  182. acpi_status acpi_ev_remove_all_sci_handlers(void)
  183. {
  184. struct acpi_sci_handler_info *sci_handler;
  185. acpi_cpu_flags flags;
  186. acpi_status status;
  187. ACPI_FUNCTION_TRACE(ev_remove_all_sci_handlers);
  188. /* Just let the OS remove the handler and disable the level */
  189. status =
  190. acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
  191. acpi_ev_sci_xrupt_handler);
  192. if (!acpi_gbl_sci_handler_list) {
  193. return (status);
  194. }
  195. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  196. /* Free all host-installed SCI handlers */
  197. while (acpi_gbl_sci_handler_list) {
  198. sci_handler = acpi_gbl_sci_handler_list;
  199. acpi_gbl_sci_handler_list = sci_handler->next;
  200. ACPI_FREE(sci_handler);
  201. }
  202. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  203. return_ACPI_STATUS(status);
  204. }
  205. #endif /* !ACPI_REDUCED_HARDWARE */