evsci.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Module Name: evsci - System Control Interrupt configuration and
  5. * legacy to ACPI mode state transition functions
  6. *
  7. ******************************************************************************/
  8. #include <acpi/acpi.h>
  9. #include "accommon.h"
  10. #include "acevents.h"
  11. #define _COMPONENT ACPI_EVENTS
  12. ACPI_MODULE_NAME("evsci")
  13. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  14. /* Local prototypes */
  15. static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context);
  16. /*******************************************************************************
  17. *
  18. * FUNCTION: acpi_ev_sci_dispatch
  19. *
  20. * PARAMETERS: None
  21. *
  22. * RETURN: Status code indicates whether interrupt was handled.
  23. *
  24. * DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers.
  25. *
  26. ******************************************************************************/
  27. u32 acpi_ev_sci_dispatch(void)
  28. {
  29. struct acpi_sci_handler_info *sci_handler;
  30. acpi_cpu_flags flags;
  31. u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
  32. ACPI_FUNCTION_NAME(ev_sci_dispatch);
  33. /* Are there any host-installed SCI handlers? */
  34. if (!acpi_gbl_sci_handler_list) {
  35. return (int_status);
  36. }
  37. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  38. /* Invoke all host-installed SCI handlers */
  39. sci_handler = acpi_gbl_sci_handler_list;
  40. while (sci_handler) {
  41. /* Invoke the installed handler (at interrupt level) */
  42. int_status |= sci_handler->address(sci_handler->context);
  43. sci_handler = sci_handler->next;
  44. }
  45. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  46. return (int_status);
  47. }
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_ev_sci_xrupt_handler
  51. *
  52. * PARAMETERS: context - Calling Context
  53. *
  54. * RETURN: Status code indicates whether interrupt was handled.
  55. *
  56. * DESCRIPTION: Interrupt handler that will figure out what function or
  57. * control method to call to deal with a SCI.
  58. *
  59. ******************************************************************************/
  60. static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context)
  61. {
  62. struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
  63. u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
  64. ACPI_FUNCTION_TRACE(ev_sci_xrupt_handler);
  65. /*
  66. * We are guaranteed by the ACPICA initialization/shutdown code that
  67. * if this interrupt handler is installed, ACPI is enabled.
  68. */
  69. /*
  70. * Fixed Events:
  71. * Check for and dispatch any Fixed Events that have occurred
  72. */
  73. interrupt_handled |= acpi_ev_fixed_event_detect();
  74. /*
  75. * General Purpose Events:
  76. * Check for and dispatch any GPEs that have occurred
  77. */
  78. interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
  79. /* Invoke all host-installed SCI handlers */
  80. interrupt_handled |= acpi_ev_sci_dispatch();
  81. acpi_sci_count++;
  82. return_UINT32(interrupt_handled);
  83. }
  84. /*******************************************************************************
  85. *
  86. * FUNCTION: acpi_ev_gpe_xrupt_handler
  87. *
  88. * PARAMETERS: context - Calling Context
  89. *
  90. * RETURN: Status code indicates whether interrupt was handled.
  91. *
  92. * DESCRIPTION: Handler for GPE Block Device interrupts
  93. *
  94. ******************************************************************************/
  95. u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_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_gpe_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. /* GPEs: Check for and dispatch any GPEs that have occurred */
  105. interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
  106. return_UINT32(interrupt_handled);
  107. }
  108. /******************************************************************************
  109. *
  110. * FUNCTION: acpi_ev_install_sci_handler
  111. *
  112. * PARAMETERS: none
  113. *
  114. * RETURN: Status
  115. *
  116. * DESCRIPTION: Installs SCI handler.
  117. *
  118. ******************************************************************************/
  119. u32 acpi_ev_install_sci_handler(void)
  120. {
  121. u32 status = AE_OK;
  122. ACPI_FUNCTION_TRACE(ev_install_sci_handler);
  123. status =
  124. acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
  125. acpi_ev_sci_xrupt_handler,
  126. acpi_gbl_gpe_xrupt_list_head);
  127. return_ACPI_STATUS(status);
  128. }
  129. /******************************************************************************
  130. *
  131. * FUNCTION: acpi_ev_remove_all_sci_handlers
  132. *
  133. * PARAMETERS: none
  134. *
  135. * RETURN: AE_OK if handler uninstalled, AE_ERROR if handler was not
  136. * installed to begin with
  137. *
  138. * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
  139. * taken. Remove all host-installed SCI handlers.
  140. *
  141. * Note: It doesn't seem important to disable all events or set the event
  142. * enable registers to their original values. The OS should disable
  143. * the SCI interrupt level when the handler is removed, so no more
  144. * events will come in.
  145. *
  146. ******************************************************************************/
  147. acpi_status acpi_ev_remove_all_sci_handlers(void)
  148. {
  149. struct acpi_sci_handler_info *sci_handler;
  150. acpi_cpu_flags flags;
  151. acpi_status status;
  152. ACPI_FUNCTION_TRACE(ev_remove_all_sci_handlers);
  153. /* Just let the OS remove the handler and disable the level */
  154. status =
  155. acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
  156. acpi_ev_sci_xrupt_handler);
  157. if (!acpi_gbl_sci_handler_list) {
  158. return (status);
  159. }
  160. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  161. /* Free all host-installed SCI handlers */
  162. while (acpi_gbl_sci_handler_list) {
  163. sci_handler = acpi_gbl_sci_handler_list;
  164. acpi_gbl_sci_handler_list = sci_handler->next;
  165. ACPI_FREE(sci_handler);
  166. }
  167. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  168. return_ACPI_STATUS(status);
  169. }
  170. #endif /* !ACPI_REDUCED_HARDWARE */