Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | a8357b0 | 2010-01-22 19:07:36 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2010, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acevents.h" |
| 47 | #include "acnamesp.h" |
| 48 | #include "actables.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("evxfevnt") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 53 | /* Local prototypes */ |
Bob Moore | e4c1ebf | 2009-04-22 13:02:06 +0800 | [diff] [blame] | 54 | static acpi_status |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 55 | acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
| 56 | struct acpi_gpe_block_info *gpe_block, void *context); |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /******************************************************************************* |
| 59 | * |
| 60 | * FUNCTION: acpi_enable |
| 61 | * |
| 62 | * PARAMETERS: None |
| 63 | * |
| 64 | * RETURN: Status |
| 65 | * |
| 66 | * DESCRIPTION: Transfers the system into ACPI mode. |
| 67 | * |
| 68 | ******************************************************************************/ |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 69 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | acpi_status acpi_enable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Len Brown | b430acb | 2010-05-06 17:41:08 -0400 | [diff] [blame] | 72 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 74 | ACPI_FUNCTION_TRACE(acpi_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Bob Moore | c857303 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 76 | /* ACPI tables must be present */ |
| 77 | |
| 78 | if (!acpi_tb_tables_loaded()) { |
| 79 | return_ACPI_STATUS(AE_NO_ACPI_TABLES); |
| 80 | } |
| 81 | |
| 82 | /* Check current mode */ |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 86 | "System is already in ACPI mode\n")); |
Len Brown | b430acb | 2010-05-06 17:41:08 -0400 | [diff] [blame] | 87 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Len Brown | b430acb | 2010-05-06 17:41:08 -0400 | [diff] [blame] | 90 | /* Transition to ACPI mode */ |
| 91 | |
| 92 | status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI); |
| 93 | if (ACPI_FAILURE(status)) { |
| 94 | ACPI_ERROR((AE_INFO, |
| 95 | "Could not transition to ACPI mode")); |
| 96 | return_ACPI_STATUS(status); |
| 97 | } |
| 98 | |
| 99 | /* Sanity check that transition succeeded */ |
| 100 | |
| 101 | if (acpi_hw_get_mode() != ACPI_SYS_MODE_ACPI) { |
| 102 | ACPI_ERROR((AE_INFO, |
| 103 | "Hardware did not enter ACPI mode")); |
| 104 | return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); |
| 105 | } |
| 106 | |
| 107 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 108 | "Transition to ACPI mode successful\n")); |
| 109 | |
| 110 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 113 | ACPI_EXPORT_SYMBOL(acpi_enable) |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /******************************************************************************* |
| 116 | * |
| 117 | * FUNCTION: acpi_disable |
| 118 | * |
| 119 | * PARAMETERS: None |
| 120 | * |
| 121 | * RETURN: Status |
| 122 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 123 | * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * |
| 125 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | acpi_status acpi_disable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 130 | ACPI_FUNCTION_TRACE(acpi_disable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 134 | "System is already in legacy (non-ACPI) mode\n")); |
| 135 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* Transition to LEGACY mode */ |
| 137 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 141 | ACPI_ERROR((AE_INFO, |
| 142 | "Could not exit ACPI mode to legacy mode")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 146 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 152 | ACPI_EXPORT_SYMBOL(acpi_disable) |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | /******************************************************************************* |
| 155 | * |
| 156 | * FUNCTION: acpi_enable_event |
| 157 | * |
| 158 | * PARAMETERS: Event - The fixed eventto be enabled |
| 159 | * Flags - Reserved |
| 160 | * |
| 161 | * RETURN: Status |
| 162 | * |
| 163 | * DESCRIPTION: Enable an ACPI event (fixed) |
| 164 | * |
| 165 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | acpi_status acpi_enable_event(u32 event, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | acpi_status status = AE_OK; |
| 169 | u32 value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 171 | ACPI_FUNCTION_TRACE(acpi_enable_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | /* Decode the Fixed Event */ |
| 174 | |
| 175 | if (event > ACPI_EVENT_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 180 | * Enable the requested fixed event (by writing a one to the enable |
| 181 | * register bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | status = |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 184 | acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. |
Bob Moore | 768aaaf | 2009-03-06 09:49:25 +0800 | [diff] [blame] | 185 | enable_register_id, ACPI_ENABLE_EVENT); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | if (ACPI_FAILURE(status)) { |
| 187 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* Make sure that the hardware responded */ |
| 191 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 192 | status = |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 193 | acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. |
| 194 | enable_register_id, &value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | if (ACPI_FAILURE(status)) { |
| 196 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if (value != 1) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 200 | ACPI_ERROR((AE_INFO, |
| 201 | "Could not enable %s event", |
| 202 | acpi_ut_get_event_name(event))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 209 | ACPI_EXPORT_SYMBOL(acpi_enable_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /******************************************************************************* |
| 212 | * |
Rafael J. Wysocki | fd24744 | 2010-06-08 10:49:08 +0200 | [diff] [blame] | 213 | * FUNCTION: acpi_clear_and_enable_gpe |
| 214 | * |
| 215 | * PARAMETERS: gpe_event_info - GPE to enable |
| 216 | * |
| 217 | * RETURN: Status |
| 218 | * |
| 219 | * DESCRIPTION: Clear the given GPE from stale events and enable it. |
| 220 | * |
| 221 | ******************************************************************************/ |
| 222 | static acpi_status |
| 223 | acpi_clear_and_enable_gpe(struct acpi_gpe_event_info *gpe_event_info) |
| 224 | { |
| 225 | acpi_status status; |
| 226 | |
| 227 | /* |
| 228 | * We will only allow a GPE to be enabled if it has either an |
| 229 | * associated method (_Lxx/_Exx) or a handler. Otherwise, the |
| 230 | * GPE will be immediately disabled by acpi_ev_gpe_dispatch the |
| 231 | * first time it fires. |
| 232 | */ |
| 233 | if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) { |
| 234 | return_ACPI_STATUS(AE_NO_HANDLER); |
| 235 | } |
| 236 | |
| 237 | /* Clear the GPE (of stale events) */ |
| 238 | status = acpi_hw_clear_gpe(gpe_event_info); |
| 239 | if (ACPI_FAILURE(status)) { |
| 240 | return_ACPI_STATUS(status); |
| 241 | } |
| 242 | |
| 243 | /* Enable the requested GPE */ |
| 244 | status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE); |
| 245 | |
| 246 | return_ACPI_STATUS(status); |
| 247 | } |
| 248 | |
| 249 | /******************************************************************************* |
| 250 | * |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 251 | * FUNCTION: acpi_set_gpe |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 253 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | * gpe_number - GPE level within the GPE block |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 255 | * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | * |
| 257 | * RETURN: Status |
| 258 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 259 | * DESCRIPTION: Enable or disable an individual GPE. This function bypasses |
| 260 | * the reference count mechanism used in the acpi_enable_gpe and |
| 261 | * acpi_disable_gpe interfaces -- and should be used with care. |
| 262 | * |
| 263 | * Note: Typically used to disable a runtime GPE for short period of time, |
| 264 | * then re-enable it, without disturbing the existing reference counts. This |
| 265 | * is useful, for example, in the Embedded Controller (EC) driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | * |
| 267 | ******************************************************************************/ |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 268 | acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 271 | acpi_status status; |
| 272 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 274 | ACPI_FUNCTION_TRACE(acpi_set_gpe); |
| 275 | |
| 276 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | /* Ensure that we have a valid GPE number */ |
| 279 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (!gpe_event_info) { |
| 282 | status = AE_BAD_PARAMETER; |
| 283 | goto unlock_and_exit; |
| 284 | } |
| 285 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 286 | /* Perform the action */ |
| 287 | |
| 288 | switch (action) { |
| 289 | case ACPI_GPE_ENABLE: |
Rafael J. Wysocki | fd24744 | 2010-06-08 10:49:08 +0200 | [diff] [blame] | 290 | status = acpi_clear_and_enable_gpe(gpe_event_info); |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 291 | break; |
| 292 | |
| 293 | case ACPI_GPE_DISABLE: |
Rafael J. Wysocki | fd24744 | 2010-06-08 10:49:08 +0200 | [diff] [blame] | 294 | status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE); |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 295 | break; |
| 296 | |
| 297 | default: |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 298 | status = AE_BAD_PARAMETER; |
| 299 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 302 | unlock_and_exit: |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 303 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 304 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 307 | ACPI_EXPORT_SYMBOL(acpi_set_gpe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /******************************************************************************* |
| 310 | * |
| 311 | * FUNCTION: acpi_enable_gpe |
| 312 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 313 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | * gpe_number - GPE level within the GPE block |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 315 | * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE |
| 316 | * or both |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | * |
| 318 | * RETURN: Status |
| 319 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 320 | * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is |
| 321 | * hardware-enabled (for runtime GPEs), or the GPE register mask |
| 322 | * is updated (for wake GPEs). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | * |
| 324 | ******************************************************************************/ |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 325 | acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | acpi_status status = AE_OK; |
| 328 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 329 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 331 | ACPI_FUNCTION_TRACE(acpi_enable_gpe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 333 | /* Parameter validation */ |
| 334 | |
| 335 | if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) { |
Rafael J. Wysocki | cbbc0de | 2010-02-24 00:52:08 +0100 | [diff] [blame] | 336 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 337 | } |
Rafael J. Wysocki | cbbc0de | 2010-02-24 00:52:08 +0100 | [diff] [blame] | 338 | |
Alexey Starikovskiy | 0b7084a | 2008-10-25 21:48:46 +0400 | [diff] [blame] | 339 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | /* Ensure that we have a valid GPE number */ |
| 342 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | if (!gpe_event_info) { |
| 345 | status = AE_BAD_PARAMETER; |
| 346 | goto unlock_and_exit; |
| 347 | } |
| 348 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 349 | if (gpe_type & ACPI_GPE_TYPE_RUNTIME) { |
| 350 | if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) { |
| 351 | status = AE_LIMIT; /* Too many references */ |
| 352 | goto unlock_and_exit; |
| 353 | } |
| 354 | |
| 355 | gpe_event_info->runtime_count++; |
| 356 | if (gpe_event_info->runtime_count == 1) { |
Rafael J. Wysocki | fd24744 | 2010-06-08 10:49:08 +0200 | [diff] [blame] | 357 | status = acpi_ev_update_gpe_enable_masks(gpe_event_info); |
| 358 | if (ACPI_SUCCESS(status)) { |
| 359 | status = acpi_clear_and_enable_gpe(gpe_event_info); |
| 360 | } |
| 361 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 362 | if (ACPI_FAILURE(status)) { |
Rafael J. Wysocki | cbbc0de | 2010-02-24 00:52:08 +0100 | [diff] [blame] | 363 | gpe_event_info->runtime_count--; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 364 | goto unlock_and_exit; |
| 365 | } |
Rafael J. Wysocki | cbbc0de | 2010-02-24 00:52:08 +0100 | [diff] [blame] | 366 | } |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 367 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 369 | if (gpe_type & ACPI_GPE_TYPE_WAKE) { |
| 370 | /* The GPE must have the ability to wake the system */ |
| 371 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 372 | if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) { |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 373 | status = AE_TYPE; |
| 374 | goto unlock_and_exit; |
| 375 | } |
| 376 | |
| 377 | if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) { |
| 378 | status = AE_LIMIT; /* Too many references */ |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 379 | goto unlock_and_exit; |
| 380 | } |
| 381 | |
| 382 | /* |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 383 | * Update the enable mask on the first wakeup reference. Wake GPEs |
| 384 | * are only hardware-enabled just before sleeping. |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 385 | */ |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 386 | gpe_event_info->wakeup_count++; |
| 387 | if (gpe_event_info->wakeup_count == 1) { |
Rafael J. Wysocki | fd24744 | 2010-06-08 10:49:08 +0200 | [diff] [blame] | 388 | status = acpi_ev_update_gpe_enable_masks(gpe_event_info); |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 389 | } |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | unlock_and_exit: |
Alexey Starikovskiy | 0b7084a | 2008-10-25 21:48:46 +0400 | [diff] [blame] | 393 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 396 | ACPI_EXPORT_SYMBOL(acpi_enable_gpe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | /******************************************************************************* |
| 399 | * |
| 400 | * FUNCTION: acpi_disable_gpe |
| 401 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 402 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | * gpe_number - GPE level within the GPE block |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 404 | * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE |
| 405 | * or both |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | * |
| 407 | * RETURN: Status |
| 408 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 409 | * DESCRIPTION: Remove a reference to a GPE. When the last reference is |
| 410 | * removed, only then is the GPE disabled (for runtime GPEs), or |
| 411 | * the GPE mask bit disabled (for wake GPEs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | * |
| 413 | ******************************************************************************/ |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 414 | acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | acpi_status status = AE_OK; |
| 417 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 418 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 420 | ACPI_FUNCTION_TRACE(acpi_disable_gpe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 422 | /* Parameter validation */ |
| 423 | |
| 424 | if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) { |
Rafael J. Wysocki | cbbc0de | 2010-02-24 00:52:08 +0100 | [diff] [blame] | 425 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 426 | } |
Rafael J. Wysocki | cbbc0de | 2010-02-24 00:52:08 +0100 | [diff] [blame] | 427 | |
Alexey Starikovskiy | 0b7084a | 2008-10-25 21:48:46 +0400 | [diff] [blame] | 428 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | /* Ensure that we have a valid GPE number */ |
| 431 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | if (!gpe_event_info) { |
| 434 | status = AE_BAD_PARAMETER; |
| 435 | goto unlock_and_exit; |
| 436 | } |
| 437 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 438 | /* Hardware-disable a runtime GPE on removal of the last reference */ |
| 439 | |
| 440 | if (gpe_type & ACPI_GPE_TYPE_RUNTIME) { |
| 441 | if (!gpe_event_info->runtime_count) { |
| 442 | status = AE_LIMIT; /* There are no references to remove */ |
| 443 | goto unlock_and_exit; |
| 444 | } |
| 445 | |
| 446 | gpe_event_info->runtime_count--; |
| 447 | if (!gpe_event_info->runtime_count) { |
Rafael J. Wysocki | fd24744 | 2010-06-08 10:49:08 +0200 | [diff] [blame] | 448 | status = acpi_ev_update_gpe_enable_masks(gpe_event_info); |
| 449 | if (ACPI_SUCCESS(status)) { |
| 450 | status = acpi_hw_low_set_gpe(gpe_event_info, |
| 451 | ACPI_GPE_DISABLE); |
| 452 | } |
| 453 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 454 | if (ACPI_FAILURE(status)) { |
| 455 | gpe_event_info->runtime_count++; |
| 456 | goto unlock_and_exit; |
| 457 | } |
| 458 | } |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 461 | /* |
| 462 | * Update masks for wake GPE on removal of the last reference. |
| 463 | * No need to hardware-disable wake GPEs here, they are not currently |
| 464 | * enabled. |
| 465 | */ |
| 466 | if (gpe_type & ACPI_GPE_TYPE_WAKE) { |
| 467 | if (!gpe_event_info->wakeup_count) { |
| 468 | status = AE_LIMIT; /* There are no references to remove */ |
| 469 | goto unlock_and_exit; |
| 470 | } |
| 471 | |
| 472 | gpe_event_info->wakeup_count--; |
| 473 | if (!gpe_event_info->wakeup_count) { |
Rafael J. Wysocki | fd24744 | 2010-06-08 10:49:08 +0200 | [diff] [blame] | 474 | status = acpi_ev_update_gpe_enable_masks(gpe_event_info); |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 475 | } |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Alexey Starikovskiy | 0b7084a | 2008-10-25 21:48:46 +0400 | [diff] [blame] | 478 | unlock_and_exit: |
| 479 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 480 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 482 | ACPI_EXPORT_SYMBOL(acpi_disable_gpe) |
| 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | /******************************************************************************* |
| 485 | * |
| 486 | * FUNCTION: acpi_disable_event |
| 487 | * |
| 488 | * PARAMETERS: Event - The fixed eventto be enabled |
| 489 | * Flags - Reserved |
| 490 | * |
| 491 | * RETURN: Status |
| 492 | * |
| 493 | * DESCRIPTION: Disable an ACPI event (fixed) |
| 494 | * |
| 495 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | acpi_status acpi_disable_event(u32 event, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | acpi_status status = AE_OK; |
| 499 | u32 value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 501 | ACPI_FUNCTION_TRACE(acpi_disable_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | /* Decode the Fixed Event */ |
| 504 | |
| 505 | if (event > ACPI_EVENT_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 506 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 510 | * Disable the requested fixed event (by writing a zero to the enable |
| 511 | * register bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 513 | status = |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 514 | acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. |
Bob Moore | 768aaaf | 2009-03-06 09:49:25 +0800 | [diff] [blame] | 515 | enable_register_id, ACPI_DISABLE_EVENT); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 516 | if (ACPI_FAILURE(status)) { |
| 517 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 520 | status = |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 521 | acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. |
| 522 | enable_register_id, &value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 523 | if (ACPI_FAILURE(status)) { |
| 524 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | if (value != 0) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 528 | ACPI_ERROR((AE_INFO, |
| 529 | "Could not disable %s events", |
| 530 | acpi_ut_get_event_name(event))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 531 | return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 534 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 537 | ACPI_EXPORT_SYMBOL(acpi_disable_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | /******************************************************************************* |
| 540 | * |
| 541 | * FUNCTION: acpi_clear_event |
| 542 | * |
| 543 | * PARAMETERS: Event - The fixed event to be cleared |
| 544 | * |
| 545 | * RETURN: Status |
| 546 | * |
| 547 | * DESCRIPTION: Clear an ACPI event (fixed) |
| 548 | * |
| 549 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 550 | acpi_status acpi_clear_event(u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 552 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 554 | ACPI_FUNCTION_TRACE(acpi_clear_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | /* Decode the Fixed Event */ |
| 557 | |
| 558 | if (event > ACPI_EVENT_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 559 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 563 | * Clear the requested fixed event (By writing a one to the status |
| 564 | * register bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 566 | status = |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 567 | acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. |
Bob Moore | 768aaaf | 2009-03-06 09:49:25 +0800 | [diff] [blame] | 568 | status_register_id, ACPI_CLEAR_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 570 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 573 | ACPI_EXPORT_SYMBOL(acpi_clear_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | /******************************************************************************* |
| 576 | * |
| 577 | * FUNCTION: acpi_clear_gpe |
| 578 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 579 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | * gpe_number - GPE level within the GPE block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | * |
| 582 | * RETURN: Status |
| 583 | * |
| 584 | * DESCRIPTION: Clear an ACPI event (general purpose) |
| 585 | * |
| 586 | ******************************************************************************/ |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 587 | acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 589 | acpi_status status = AE_OK; |
| 590 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 591 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 593 | ACPI_FUNCTION_TRACE(acpi_clear_gpe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 595 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
| 597 | /* Ensure that we have a valid GPE number */ |
| 598 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 599 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | if (!gpe_event_info) { |
| 601 | status = AE_BAD_PARAMETER; |
| 602 | goto unlock_and_exit; |
| 603 | } |
| 604 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 605 | status = acpi_hw_clear_gpe(gpe_event_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | unlock_and_exit: |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 608 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 609 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 612 | ACPI_EXPORT_SYMBOL(acpi_clear_gpe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /******************************************************************************* |
| 614 | * |
| 615 | * FUNCTION: acpi_get_event_status |
| 616 | * |
| 617 | * PARAMETERS: Event - The fixed event |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 618 | * event_status - Where the current status of the event will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | * be returned |
| 620 | * |
| 621 | * RETURN: Status |
| 622 | * |
| 623 | * DESCRIPTION: Obtains and returns the current status of the event |
| 624 | * |
| 625 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 626 | acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 628 | acpi_status status = AE_OK; |
Zhang Rui | 71b58cb | 2008-06-20 09:42:47 +0800 | [diff] [blame] | 629 | u32 value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 631 | ACPI_FUNCTION_TRACE(acpi_get_event_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | if (!event_status) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 634 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /* Decode the Fixed Event */ |
| 638 | |
| 639 | if (event > ACPI_EVENT_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /* Get the status of the requested fixed event */ |
| 644 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 645 | status = |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 646 | acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. |
Zhang Rui | 71b58cb | 2008-06-20 09:42:47 +0800 | [diff] [blame] | 647 | enable_register_id, &value); |
| 648 | if (ACPI_FAILURE(status)) |
| 649 | return_ACPI_STATUS(status); |
| 650 | |
| 651 | *event_status = value; |
| 652 | |
| 653 | status = |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 654 | acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. |
Zhang Rui | 71b58cb | 2008-06-20 09:42:47 +0800 | [diff] [blame] | 655 | status_register_id, &value); |
| 656 | if (ACPI_FAILURE(status)) |
| 657 | return_ACPI_STATUS(status); |
| 658 | |
| 659 | if (value) |
| 660 | *event_status |= ACPI_EVENT_FLAG_SET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
Zhang Rui | ed206fa | 2008-10-27 14:01:02 -0700 | [diff] [blame] | 662 | if (acpi_gbl_fixed_event_handlers[event].handler) |
| 663 | *event_status |= ACPI_EVENT_FLAG_HANDLE; |
| 664 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 665 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 668 | ACPI_EXPORT_SYMBOL(acpi_get_event_status) |
| 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /******************************************************************************* |
| 671 | * |
| 672 | * FUNCTION: acpi_get_gpe_status |
| 673 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 674 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | * gpe_number - GPE level within the GPE block |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 676 | * event_status - Where the current status of the event will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | * be returned |
| 678 | * |
| 679 | * RETURN: Status |
| 680 | * |
| 681 | * DESCRIPTION: Get status of an event (general purpose) |
| 682 | * |
| 683 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 685 | acpi_get_gpe_status(acpi_handle gpe_device, |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 686 | u32 gpe_number, acpi_event_status *event_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 688 | acpi_status status = AE_OK; |
| 689 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 690 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 692 | ACPI_FUNCTION_TRACE(acpi_get_gpe_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 694 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
| 696 | /* Ensure that we have a valid GPE number */ |
| 697 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 698 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | if (!gpe_event_info) { |
| 700 | status = AE_BAD_PARAMETER; |
| 701 | goto unlock_and_exit; |
| 702 | } |
| 703 | |
| 704 | /* Obtain status on the requested GPE number */ |
| 705 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 706 | status = acpi_hw_get_gpe_status(gpe_event_info, event_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
Zhang Rui | ed206fa | 2008-10-27 14:01:02 -0700 | [diff] [blame] | 708 | if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) |
| 709 | *event_status |= ACPI_EVENT_FLAG_HANDLE; |
| 710 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 711 | unlock_and_exit: |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 712 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 713 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 715 | |
| 716 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | /******************************************************************************* |
| 718 | * |
| 719 | * FUNCTION: acpi_install_gpe_block |
| 720 | * |
| 721 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device |
| 722 | * gpe_block_address - Address and space_iD |
| 723 | * register_count - Number of GPE register pairs in the block |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 724 | * interrupt_number - H/W interrupt for the block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | * |
| 726 | * RETURN: Status |
| 727 | * |
| 728 | * DESCRIPTION: Create and Install a block of GPE registers |
| 729 | * |
| 730 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 732 | acpi_install_gpe_block(acpi_handle gpe_device, |
| 733 | struct acpi_generic_address *gpe_block_address, |
| 734 | u32 register_count, u32 interrupt_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 736 | acpi_status status; |
| 737 | union acpi_operand_object *obj_desc; |
| 738 | struct acpi_namespace_node *node; |
| 739 | struct acpi_gpe_block_info *gpe_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 741 | ACPI_FUNCTION_TRACE(acpi_install_gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 743 | if ((!gpe_device) || (!gpe_block_address) || (!register_count)) { |
| 744 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 747 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 748 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | return (status); |
| 750 | } |
| 751 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 752 | node = acpi_ns_validate_handle(gpe_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | if (!node) { |
| 754 | status = AE_BAD_PARAMETER; |
| 755 | goto unlock_and_exit; |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | * For user-installed GPE Block Devices, the gpe_block_base_number |
| 760 | * is always zero |
| 761 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 762 | status = |
| 763 | acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0, |
| 764 | interrupt_number, &gpe_block); |
| 765 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | goto unlock_and_exit; |
| 767 | } |
| 768 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 769 | /* Install block in the device_object attached to the node */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 771 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | if (!obj_desc) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 773 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 774 | /* |
| 775 | * No object, create a new one (Device nodes do not always have |
| 776 | * an attached object) |
| 777 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 778 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | if (!obj_desc) { |
| 780 | status = AE_NO_MEMORY; |
| 781 | goto unlock_and_exit; |
| 782 | } |
| 783 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 784 | status = |
| 785 | acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | /* Remove local reference to the object */ |
| 788 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 789 | acpi_ut_remove_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 791 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | goto unlock_and_exit; |
| 793 | } |
| 794 | } |
| 795 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 796 | /* Now install the GPE block in the device_object */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
| 798 | obj_desc->device.gpe_block = gpe_block; |
| 799 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 800 | /* Run the _PRW methods and enable the runtime GPEs in the new block */ |
| 801 | |
| 802 | status = acpi_ev_initialize_gpe_block(node, gpe_block); |
| 803 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 804 | unlock_and_exit: |
| 805 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 806 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 809 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | /******************************************************************************* |
| 812 | * |
| 813 | * FUNCTION: acpi_remove_gpe_block |
| 814 | * |
| 815 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device |
| 816 | * |
| 817 | * RETURN: Status |
| 818 | * |
| 819 | * DESCRIPTION: Remove a previously installed block of GPE registers |
| 820 | * |
| 821 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 822 | acpi_status acpi_remove_gpe_block(acpi_handle gpe_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 824 | union acpi_operand_object *obj_desc; |
| 825 | acpi_status status; |
| 826 | struct acpi_namespace_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 828 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
| 830 | if (!gpe_device) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 831 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 834 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 835 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | return (status); |
| 837 | } |
| 838 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 839 | node = acpi_ns_validate_handle(gpe_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | if (!node) { |
| 841 | status = AE_BAD_PARAMETER; |
| 842 | goto unlock_and_exit; |
| 843 | } |
| 844 | |
| 845 | /* Get the device_object attached to the node */ |
| 846 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 847 | obj_desc = acpi_ns_get_attached_object(node); |
| 848 | if (!obj_desc || !obj_desc->device.gpe_block) { |
| 849 | return_ACPI_STATUS(AE_NULL_OBJECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /* Delete the GPE block (but not the device_object) */ |
| 853 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 854 | status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block); |
| 855 | if (ACPI_SUCCESS(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | obj_desc->device.gpe_block = NULL; |
| 857 | } |
| 858 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 859 | unlock_and_exit: |
| 860 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 861 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 863 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 864 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block) |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 865 | |
| 866 | /******************************************************************************* |
| 867 | * |
| 868 | * FUNCTION: acpi_get_gpe_device |
| 869 | * |
| 870 | * PARAMETERS: Index - System GPE index (0-current_gpe_count) |
| 871 | * gpe_device - Where the parent GPE Device is returned |
| 872 | * |
| 873 | * RETURN: Status |
| 874 | * |
| 875 | * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL |
| 876 | * gpe device indicates that the gpe number is contained in one of |
| 877 | * the FADT-defined gpe blocks. Otherwise, the GPE block device. |
| 878 | * |
| 879 | ******************************************************************************/ |
| 880 | acpi_status |
| 881 | acpi_get_gpe_device(u32 index, acpi_handle *gpe_device) |
| 882 | { |
| 883 | struct acpi_gpe_device_info info; |
| 884 | acpi_status status; |
| 885 | |
| 886 | ACPI_FUNCTION_TRACE(acpi_get_gpe_device); |
| 887 | |
| 888 | if (!gpe_device) { |
| 889 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 890 | } |
| 891 | |
| 892 | if (index >= acpi_current_gpe_count) { |
| 893 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 894 | } |
| 895 | |
| 896 | /* Setup and walk the GPE list */ |
| 897 | |
| 898 | info.index = index; |
| 899 | info.status = AE_NOT_EXIST; |
| 900 | info.gpe_device = NULL; |
| 901 | info.next_block_base_index = 0; |
| 902 | |
| 903 | status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info); |
| 904 | if (ACPI_FAILURE(status)) { |
| 905 | return_ACPI_STATUS(status); |
| 906 | } |
| 907 | |
| 908 | *gpe_device = info.gpe_device; |
| 909 | return_ACPI_STATUS(info.status); |
| 910 | } |
| 911 | |
| 912 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_device) |
| 913 | |
| 914 | /******************************************************************************* |
| 915 | * |
| 916 | * FUNCTION: acpi_ev_get_gpe_device |
| 917 | * |
| 918 | * PARAMETERS: GPE_WALK_CALLBACK |
| 919 | * |
| 920 | * RETURN: Status |
| 921 | * |
| 922 | * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE |
| 923 | * block device. NULL if the GPE is one of the FADT-defined GPEs. |
| 924 | * |
| 925 | ******************************************************************************/ |
Bob Moore | e4c1ebf | 2009-04-22 13:02:06 +0800 | [diff] [blame] | 926 | static acpi_status |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 927 | acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
| 928 | struct acpi_gpe_block_info *gpe_block, void *context) |
| 929 | { |
| 930 | struct acpi_gpe_device_info *info = context; |
| 931 | |
| 932 | /* Increment Index by the number of GPEs in this block */ |
| 933 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 934 | info->next_block_base_index += gpe_block->gpe_count; |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 935 | |
| 936 | if (info->index < info->next_block_base_index) { |
| 937 | /* |
| 938 | * The GPE index is within this block, get the node. Leave the node |
| 939 | * NULL for the FADT-defined GPEs |
| 940 | */ |
| 941 | if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) { |
| 942 | info->gpe_device = gpe_block->node; |
| 943 | } |
| 944 | |
| 945 | info->status = AE_OK; |
| 946 | return (AE_CTRL_END); |
| 947 | } |
| 948 | |
| 949 | return (AE_OK); |
| 950 | } |
Bob Moore | 08ac07b | 2008-12-30 09:55:48 +0800 | [diff] [blame] | 951 | |
| 952 | /****************************************************************************** |
| 953 | * |
| 954 | * FUNCTION: acpi_disable_all_gpes |
| 955 | * |
| 956 | * PARAMETERS: None |
| 957 | * |
| 958 | * RETURN: Status |
| 959 | * |
| 960 | * DESCRIPTION: Disable and clear all GPEs in all GPE blocks |
| 961 | * |
| 962 | ******************************************************************************/ |
| 963 | |
| 964 | acpi_status acpi_disable_all_gpes(void) |
| 965 | { |
| 966 | acpi_status status; |
| 967 | |
| 968 | ACPI_FUNCTION_TRACE(acpi_disable_all_gpes); |
| 969 | |
| 970 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 971 | if (ACPI_FAILURE(status)) { |
| 972 | return_ACPI_STATUS(status); |
| 973 | } |
| 974 | |
| 975 | status = acpi_hw_disable_all_gpes(); |
| 976 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 977 | |
| 978 | return_ACPI_STATUS(status); |
| 979 | } |
| 980 | |
| 981 | /****************************************************************************** |
| 982 | * |
| 983 | * FUNCTION: acpi_enable_all_runtime_gpes |
| 984 | * |
| 985 | * PARAMETERS: None |
| 986 | * |
| 987 | * RETURN: Status |
| 988 | * |
| 989 | * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks |
| 990 | * |
| 991 | ******************************************************************************/ |
| 992 | |
| 993 | acpi_status acpi_enable_all_runtime_gpes(void) |
| 994 | { |
| 995 | acpi_status status; |
| 996 | |
| 997 | ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes); |
| 998 | |
| 999 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 1000 | if (ACPI_FAILURE(status)) { |
| 1001 | return_ACPI_STATUS(status); |
| 1002 | } |
| 1003 | |
| 1004 | status = acpi_hw_enable_all_runtime_gpes(); |
| 1005 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 1006 | |
| 1007 | return_ACPI_STATUS(status); |
| 1008 | } |