Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evevent - Fixed Event handling and dispatch |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2005, R. Byron Moore |
| 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 | |
| 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acevents.h> |
| 46 | |
| 47 | #define _COMPONENT ACPI_EVENTS |
| 48 | ACPI_MODULE_NAME ("evevent") |
| 49 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 50 | /* Local prototypes */ |
| 51 | |
| 52 | static acpi_status |
| 53 | acpi_ev_fixed_event_initialize ( |
| 54 | void); |
| 55 | |
| 56 | static u32 |
| 57 | acpi_ev_fixed_event_dispatch ( |
| 58 | u32 event); |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | /******************************************************************************* |
| 62 | * |
| 63 | * FUNCTION: acpi_ev_initialize_events |
| 64 | * |
| 65 | * PARAMETERS: None |
| 66 | * |
| 67 | * RETURN: Status |
| 68 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 69 | * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | * |
| 71 | ******************************************************************************/ |
| 72 | |
| 73 | acpi_status |
| 74 | acpi_ev_initialize_events ( |
| 75 | void) |
| 76 | { |
| 77 | acpi_status status; |
| 78 | |
| 79 | |
| 80 | ACPI_FUNCTION_TRACE ("ev_initialize_events"); |
| 81 | |
| 82 | |
| 83 | /* Make sure we have ACPI tables */ |
| 84 | |
| 85 | if (!acpi_gbl_DSDT) { |
| 86 | ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No ACPI tables present!\n")); |
| 87 | return_ACPI_STATUS (AE_NO_ACPI_TABLES); |
| 88 | } |
| 89 | |
| 90 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 91 | * Initialize the Fixed and General Purpose Events. This is done prior to |
| 92 | * enabling SCIs to prevent interrupts from occurring before the handlers are |
| 93 | * installed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | */ |
| 95 | status = acpi_ev_fixed_event_initialize (); |
| 96 | if (ACPI_FAILURE (status)) { |
| 97 | ACPI_REPORT_ERROR (( |
| 98 | "Unable to initialize fixed events, %s\n", |
| 99 | acpi_format_exception (status))); |
| 100 | return_ACPI_STATUS (status); |
| 101 | } |
| 102 | |
| 103 | status = acpi_ev_gpe_initialize (); |
| 104 | if (ACPI_FAILURE (status)) { |
| 105 | ACPI_REPORT_ERROR (( |
| 106 | "Unable to initialize general purpose events, %s\n", |
| 107 | acpi_format_exception (status))); |
| 108 | return_ACPI_STATUS (status); |
| 109 | } |
| 110 | |
| 111 | return_ACPI_STATUS (status); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /******************************************************************************* |
| 116 | * |
| 117 | * FUNCTION: acpi_ev_install_xrupt_handlers |
| 118 | * |
| 119 | * PARAMETERS: None |
| 120 | * |
| 121 | * RETURN: Status |
| 122 | * |
| 123 | * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock |
| 124 | * |
| 125 | ******************************************************************************/ |
| 126 | |
| 127 | acpi_status |
| 128 | acpi_ev_install_xrupt_handlers ( |
| 129 | void) |
| 130 | { |
| 131 | acpi_status status; |
| 132 | |
| 133 | |
| 134 | ACPI_FUNCTION_TRACE ("ev_install_xrupt_handlers"); |
| 135 | |
| 136 | |
| 137 | /* Install the SCI handler */ |
| 138 | |
| 139 | status = acpi_ev_install_sci_handler (); |
| 140 | if (ACPI_FAILURE (status)) { |
| 141 | ACPI_REPORT_ERROR (( |
| 142 | "Unable to install System Control Interrupt Handler, %s\n", |
| 143 | acpi_format_exception (status))); |
| 144 | return_ACPI_STATUS (status); |
| 145 | } |
| 146 | |
| 147 | /* Install the handler for the Global Lock */ |
| 148 | |
| 149 | status = acpi_ev_init_global_lock_handler (); |
| 150 | if (ACPI_FAILURE (status)) { |
| 151 | ACPI_REPORT_ERROR (( |
| 152 | "Unable to initialize Global Lock handler, %s\n", |
| 153 | acpi_format_exception (status))); |
| 154 | return_ACPI_STATUS (status); |
| 155 | } |
| 156 | |
| 157 | acpi_gbl_events_initialized = TRUE; |
| 158 | return_ACPI_STATUS (status); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /******************************************************************************* |
| 163 | * |
| 164 | * FUNCTION: acpi_ev_fixed_event_initialize |
| 165 | * |
| 166 | * PARAMETERS: None |
| 167 | * |
| 168 | * RETURN: Status |
| 169 | * |
| 170 | * DESCRIPTION: Install the fixed event handlers and enable the fixed events. |
| 171 | * |
| 172 | ******************************************************************************/ |
| 173 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 174 | static acpi_status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | acpi_ev_fixed_event_initialize ( |
| 176 | void) |
| 177 | { |
| 178 | acpi_native_uint i; |
| 179 | acpi_status status; |
| 180 | |
| 181 | |
| 182 | /* |
| 183 | * Initialize the structure that keeps track of fixed event handlers |
| 184 | * and enable the fixed events. |
| 185 | */ |
| 186 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { |
| 187 | acpi_gbl_fixed_event_handlers[i].handler = NULL; |
| 188 | acpi_gbl_fixed_event_handlers[i].context = NULL; |
| 189 | |
| 190 | /* Enable the fixed event */ |
| 191 | |
| 192 | if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 193 | status = acpi_set_register ( |
| 194 | acpi_gbl_fixed_event_info[i].enable_register_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | 0, ACPI_MTX_LOCK); |
| 196 | if (ACPI_FAILURE (status)) { |
| 197 | return (status); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | return (AE_OK); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | /******************************************************************************* |
| 207 | * |
| 208 | * FUNCTION: acpi_ev_fixed_event_detect |
| 209 | * |
| 210 | * PARAMETERS: None |
| 211 | * |
| 212 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED |
| 213 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 214 | * DESCRIPTION: Checks the PM status register for active fixed events |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | * |
| 216 | ******************************************************************************/ |
| 217 | |
| 218 | u32 |
| 219 | acpi_ev_fixed_event_detect ( |
| 220 | void) |
| 221 | { |
| 222 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; |
| 223 | u32 fixed_status; |
| 224 | u32 fixed_enable; |
| 225 | acpi_native_uint i; |
| 226 | |
| 227 | |
| 228 | ACPI_FUNCTION_NAME ("ev_fixed_event_detect"); |
| 229 | |
| 230 | |
| 231 | /* |
| 232 | * Read the fixed feature status and enable registers, as all the cases |
| 233 | * depend on their values. Ignore errors here. |
| 234 | */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 235 | (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS, |
| 236 | &fixed_status); |
| 237 | (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE, |
| 238 | &fixed_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS, |
| 241 | "Fixed Event Block: Enable %08X Status %08X\n", |
| 242 | fixed_enable, fixed_status)); |
| 243 | |
| 244 | /* |
| 245 | * Check for all possible Fixed Events and dispatch those that are active |
| 246 | */ |
| 247 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { |
| 248 | /* Both the status and enable bits must be on for this event */ |
| 249 | |
| 250 | if ((fixed_status & acpi_gbl_fixed_event_info[i].status_bit_mask) && |
| 251 | (fixed_enable & acpi_gbl_fixed_event_info[i].enable_bit_mask)) { |
| 252 | /* Found an active (signalled) event */ |
| 253 | |
| 254 | int_status |= acpi_ev_fixed_event_dispatch ((u32) i); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return (int_status); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /******************************************************************************* |
| 263 | * |
| 264 | * FUNCTION: acpi_ev_fixed_event_dispatch |
| 265 | * |
| 266 | * PARAMETERS: Event - Event type |
| 267 | * |
| 268 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED |
| 269 | * |
| 270 | * DESCRIPTION: Clears the status bit for the requested event, calls the |
| 271 | * handler that previously registered for the event. |
| 272 | * |
| 273 | ******************************************************************************/ |
| 274 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 275 | static u32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | acpi_ev_fixed_event_dispatch ( |
| 277 | u32 event) |
| 278 | { |
| 279 | |
| 280 | |
| 281 | ACPI_FUNCTION_ENTRY (); |
| 282 | |
| 283 | |
| 284 | /* Clear the status bit */ |
| 285 | |
| 286 | (void) acpi_set_register (acpi_gbl_fixed_event_info[event].status_register_id, |
| 287 | 1, ACPI_MTX_DO_NOT_LOCK); |
| 288 | |
| 289 | /* |
| 290 | * Make sure we've got a handler. If not, report an error. |
| 291 | * The event is disabled to prevent further interrupts. |
| 292 | */ |
| 293 | if (NULL == acpi_gbl_fixed_event_handlers[event].handler) { |
| 294 | (void) acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id, |
| 295 | 0, ACPI_MTX_DO_NOT_LOCK); |
| 296 | |
| 297 | ACPI_REPORT_ERROR ( |
| 298 | ("No installed handler for fixed event [%08X]\n", |
| 299 | event)); |
| 300 | |
| 301 | return (ACPI_INTERRUPT_NOT_HANDLED); |
| 302 | } |
| 303 | |
| 304 | /* Invoke the Fixed Event handler */ |
| 305 | |
| 306 | return ((acpi_gbl_fixed_event_handlers[event].handler)( |
| 307 | acpi_gbl_fixed_event_handlers[event].context)); |
| 308 | } |
| 309 | |
| 310 | |