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