Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * |
| 4 | * Module Name: evsci - System Control Interrupt configuration and |
| 5 | * legacy to ACPI mode state transition functions |
| 6 | * |
| 7 | ******************************************************************************/ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 10 | #include "accommon.h" |
| 11 | #include "acevents.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 14 | ACPI_MODULE_NAME("evsci") |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 15 | #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 16 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 17 | static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | /******************************************************************************* |
| 20 | * |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 21 | * FUNCTION: acpi_ev_sci_dispatch |
| 22 | * |
| 23 | * PARAMETERS: None |
| 24 | * |
| 25 | * RETURN: Status code indicates whether interrupt was handled. |
| 26 | * |
| 27 | * DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers. |
| 28 | * |
| 29 | ******************************************************************************/ |
| 30 | |
| 31 | u32 acpi_ev_sci_dispatch(void) |
| 32 | { |
| 33 | struct acpi_sci_handler_info *sci_handler; |
| 34 | acpi_cpu_flags flags; |
| 35 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; |
| 36 | |
| 37 | ACPI_FUNCTION_NAME(ev_sci_dispatch); |
| 38 | |
| 39 | /* Are there any host-installed SCI handlers? */ |
| 40 | |
| 41 | if (!acpi_gbl_sci_handler_list) { |
| 42 | return (int_status); |
| 43 | } |
| 44 | |
| 45 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 46 | |
| 47 | /* Invoke all host-installed SCI handlers */ |
| 48 | |
| 49 | sci_handler = acpi_gbl_sci_handler_list; |
| 50 | while (sci_handler) { |
| 51 | |
| 52 | /* Invoke the installed handler (at interrupt level) */ |
| 53 | |
Bob Moore | c53ae3a | 2013-09-23 09:52:45 +0800 | [diff] [blame] | 54 | int_status |= sci_handler->address(sci_handler->context); |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 55 | |
| 56 | sci_handler = sci_handler->next; |
| 57 | } |
| 58 | |
| 59 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 60 | return (int_status); |
| 61 | } |
| 62 | |
| 63 | /******************************************************************************* |
| 64 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | * FUNCTION: acpi_ev_sci_xrupt_handler |
| 66 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 67 | * PARAMETERS: context - Calling Context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * |
| 69 | * RETURN: Status code indicates whether interrupt was handled. |
| 70 | * |
| 71 | * DESCRIPTION: Interrupt handler that will figure out what function or |
| 72 | * control method to call to deal with a SCI. |
| 73 | * |
| 74 | ******************************************************************************/ |
| 75 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | struct acpi_gpe_xrupt_info *gpe_xrupt_list = context; |
| 79 | u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 81 | ACPI_FUNCTION_TRACE(ev_sci_xrupt_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* |
Bob Moore | 6085bb1 | 2014-04-04 12:37:11 +0800 | [diff] [blame] | 84 | * We are guaranteed by the ACPICA initialization/shutdown code that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | * if this interrupt handler is installed, ACPI is enabled. |
| 86 | */ |
| 87 | |
| 88 | /* |
| 89 | * Fixed Events: |
| 90 | * Check for and dispatch any Fixed Events that have occurred |
| 91 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | interrupt_handled |= acpi_ev_fixed_event_detect(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * General Purpose Events: |
| 96 | * Check for and dispatch any GPEs that have occurred |
| 97 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 100 | /* Invoke all host-installed SCI handlers */ |
| 101 | |
| 102 | interrupt_handled |= acpi_ev_sci_dispatch(); |
| 103 | |
Lv Zheng | 9187a41 | 2013-10-31 09:30:28 +0800 | [diff] [blame] | 104 | acpi_sci_count++; |
Bob Moore | fd1af71 | 2013-03-08 09:22:23 +0000 | [diff] [blame] | 105 | return_UINT32(interrupt_handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | /******************************************************************************* |
| 109 | * |
| 110 | * FUNCTION: acpi_ev_gpe_xrupt_handler |
| 111 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 112 | * PARAMETERS: context - Calling Context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * |
| 114 | * RETURN: Status code indicates whether interrupt was handled. |
| 115 | * |
| 116 | * DESCRIPTION: Handler for GPE Block Device interrupts |
| 117 | * |
| 118 | ******************************************************************************/ |
| 119 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_xrupt_handler(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | struct acpi_gpe_xrupt_info *gpe_xrupt_list = context; |
| 123 | u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 125 | ACPI_FUNCTION_TRACE(ev_gpe_xrupt_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 128 | * We are guaranteed by the ACPICA initialization/shutdown code that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | * if this interrupt handler is installed, ACPI is enabled. |
| 130 | */ |
| 131 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 132 | /* GPEs: Check for and dispatch any GPEs that have occurred */ |
| 133 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list); |
Bob Moore | fd1af71 | 2013-03-08 09:22:23 +0000 | [diff] [blame] | 135 | return_UINT32(interrupt_handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /****************************************************************************** |
| 139 | * |
| 140 | * FUNCTION: acpi_ev_install_sci_handler |
| 141 | * |
| 142 | * PARAMETERS: none |
| 143 | * |
| 144 | * RETURN: Status |
| 145 | * |
| 146 | * DESCRIPTION: Installs SCI handler. |
| 147 | * |
| 148 | ******************************************************************************/ |
| 149 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | u32 acpi_ev_install_sci_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | u32 status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 154 | ACPI_FUNCTION_TRACE(ev_install_sci_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 156 | status = |
| 157 | acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt, |
| 158 | acpi_ev_sci_xrupt_handler, |
| 159 | acpi_gbl_gpe_xrupt_list_head); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /****************************************************************************** |
| 164 | * |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 165 | * FUNCTION: acpi_ev_remove_all_sci_handlers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | * |
| 167 | * PARAMETERS: none |
| 168 | * |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 169 | * RETURN: AE_OK if handler uninstalled, AE_ERROR if handler was not |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | * installed to begin with |
| 171 | * |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 172 | * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 173 | * taken. Remove all host-installed SCI handlers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | * |
| 175 | * Note: It doesn't seem important to disable all events or set the event |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 176 | * enable registers to their original values. The OS should disable |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | * the SCI interrupt level when the handler is removed, so no more |
| 178 | * events will come in. |
| 179 | * |
| 180 | ******************************************************************************/ |
| 181 | |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 182 | acpi_status acpi_ev_remove_all_sci_handlers(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 184 | struct acpi_sci_handler_info *sci_handler; |
| 185 | acpi_cpu_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 188 | ACPI_FUNCTION_TRACE(ev_remove_all_sci_handlers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /* Just let the OS remove the handler and disable the level */ |
| 191 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 192 | status = |
| 193 | acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt, |
| 194 | acpi_ev_sci_xrupt_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 196 | if (!acpi_gbl_sci_handler_list) { |
| 197 | return (status); |
| 198 | } |
| 199 | |
| 200 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 201 | |
| 202 | /* Free all host-installed SCI handlers */ |
| 203 | |
| 204 | while (acpi_gbl_sci_handler_list) { |
| 205 | sci_handler = acpi_gbl_sci_handler_list; |
| 206 | acpi_gbl_sci_handler_list = sci_handler->next; |
| 207 | ACPI_FREE(sci_handler); |
| 208 | } |
| 209 | |
| 210 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 213 | |
| 214 | #endif /* !ACPI_REDUCED_HARDWARE */ |