blob: 7c7bbb4d402ca31a7dcbfe766e5ed2a0eb0e47b3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
48#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Bob Mooree97d6bf2008-12-30 09:45:17 +080053/* Local prototypes */
Bob Mooree4c1ebf2009-04-22 13:02:06 +080054static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +080055acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
56 struct acpi_gpe_block_info *gpe_block, void *context);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*******************************************************************************
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 Mooree97d6bf2008-12-30 09:45:17 +080069
Len Brown4be44fc2005-08-05 00:44:28 -040070acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Len Brown4be44fc2005-08-05 00:44:28 -040072 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bob Mooreb229cf92006-04-21 17:15:00 -040074 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bob Moorec8573032007-02-02 19:48:23 +030076 /* 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 Torvalds1da177e2005-04-16 15:20:36 -070084 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040085 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
86 "System is already in ACPI mode\n"));
87 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* Transition to ACPI mode */
89
Len Brown4be44fc2005-08-05 00:44:28 -040090 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
91 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050092 ACPI_ERROR((AE_INFO,
93 "Could not transition to ACPI mode"));
Len Brown4be44fc2005-08-05 00:44:28 -040094 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
Len Brown4be44fc2005-08-05 00:44:28 -040097 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
98 "Transition to ACPI mode successful\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
100
Len Brown4be44fc2005-08-05 00:44:28 -0400101 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Bob Moore83135242006-10-03 00:00:00 -0400104ACPI_EXPORT_SYMBOL(acpi_enable)
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/*******************************************************************************
107 *
108 * FUNCTION: acpi_disable
109 *
110 * PARAMETERS: None
111 *
112 * RETURN: Status
113 *
Robert Moore44f6c012005-04-18 22:49:35 -0400114 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400117acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Len Brown4be44fc2005-08-05 00:44:28 -0400119 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Bob Mooreb229cf92006-04-21 17:15:00 -0400121 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400124 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
125 "System is already in legacy (non-ACPI) mode\n"));
126 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /* Transition to LEGACY mode */
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Len Brown4be44fc2005-08-05 00:44:28 -0400131 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500132 ACPI_ERROR((AE_INFO,
133 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400134 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139
Len Brown4be44fc2005-08-05 00:44:28 -0400140 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Bob Moore83135242006-10-03 00:00:00 -0400143ACPI_EXPORT_SYMBOL(acpi_disable)
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*******************************************************************************
146 *
147 * FUNCTION: acpi_enable_event
148 *
149 * PARAMETERS: Event - The fixed eventto be enabled
150 * Flags - Reserved
151 *
152 * RETURN: Status
153 *
154 * DESCRIPTION: Enable an ACPI event (fixed)
155 *
156 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400157acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Len Brown4be44fc2005-08-05 00:44:28 -0400159 acpi_status status = AE_OK;
160 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Bob Mooreb229cf92006-04-21 17:15:00 -0400162 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 /* Decode the Fixed Event */
165
166 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400167 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169
170 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800171 * Enable the requested fixed event (by writing a one to the enable
172 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 */
Len Brown4be44fc2005-08-05 00:44:28 -0400174 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800175 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800176 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400177 if (ACPI_FAILURE(status)) {
178 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
181 /* Make sure that the hardware responded */
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800184 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
185 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
190 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500191 ACPI_ERROR((AE_INFO,
192 "Could not enable %s event",
193 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400194 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Bob Moore83135242006-10-03 00:00:00 -0400200ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202/*******************************************************************************
203 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100204 * FUNCTION: acpi_set_gpe
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 *
Lin Ming0f849d22010-04-06 14:52:37 +0800206 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800208 * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 *
210 * RETURN: Status
211 *
Lin Ming0f849d22010-04-06 14:52:37 +0800212 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
213 * the reference count mechanism used in the acpi_enable_gpe and
214 * acpi_disable_gpe interfaces -- and should be used with care.
215 *
216 * Note: Typically used to disable a runtime GPE for short period of time,
217 * then re-enable it, without disturbing the existing reference counts. This
218 * is useful, for example, in the Embedded Controller (EC) driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 *
220 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100221acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Len Brown4be44fc2005-08-05 00:44:28 -0400223 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800224 acpi_status status;
225 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100227 ACPI_FUNCTION_TRACE(acpi_set_gpe);
228
229 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 /* Ensure that we have a valid GPE number */
232
Len Brown4be44fc2005-08-05 00:44:28 -0400233 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 if (!gpe_event_info) {
235 status = AE_BAD_PARAMETER;
236 goto unlock_and_exit;
237 }
238
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100239 /* Perform the action */
240
241 switch (action) {
242 case ACPI_GPE_ENABLE:
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100243 status = acpi_ev_enable_gpe(gpe_event_info);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100244 break;
245
246 case ACPI_GPE_DISABLE:
247 status = acpi_ev_disable_gpe(gpe_event_info);
248 break;
249
250 default:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100251 status = AE_BAD_PARAMETER;
252 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255 unlock_and_exit:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100256 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400257 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100260ACPI_EXPORT_SYMBOL(acpi_set_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262/*******************************************************************************
263 *
264 * FUNCTION: acpi_enable_gpe
265 *
Lin Ming0f849d22010-04-06 14:52:37 +0800266 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800268 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
269 * or both
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 *
271 * RETURN: Status
272 *
Lin Ming0f849d22010-04-06 14:52:37 +0800273 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
274 * hardware-enabled (for runtime GPEs), or the GPE register mask
275 * is updated (for wake GPEs).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 *
277 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800278acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Len Brown4be44fc2005-08-05 00:44:28 -0400280 acpi_status status = AE_OK;
281 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800282 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Bob Mooreb229cf92006-04-21 17:15:00 -0400284 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Lin Ming0f849d22010-04-06 14:52:37 +0800286 /* Parameter validation */
287
288 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100289 return_ACPI_STATUS(AE_BAD_PARAMETER);
Lin Ming0f849d22010-04-06 14:52:37 +0800290 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100291
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400292 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 /* Ensure that we have a valid GPE number */
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 if (!gpe_event_info) {
298 status = AE_BAD_PARAMETER;
299 goto unlock_and_exit;
300 }
301
Lin Ming0f849d22010-04-06 14:52:37 +0800302 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
303 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
304 status = AE_LIMIT; /* Too many references */
305 goto unlock_and_exit;
306 }
307
308 gpe_event_info->runtime_count++;
309 if (gpe_event_info->runtime_count == 1) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100310 status = acpi_ev_enable_gpe(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800311 if (ACPI_FAILURE(status)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100312 gpe_event_info->runtime_count--;
Lin Ming0f849d22010-04-06 14:52:37 +0800313 goto unlock_and_exit;
314 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100315 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Lin Ming0f849d22010-04-06 14:52:37 +0800318 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
319 /* The GPE must have the ability to wake the system */
320
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100321 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
Lin Ming0f849d22010-04-06 14:52:37 +0800322 status = AE_TYPE;
323 goto unlock_and_exit;
324 }
325
326 if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
327 status = AE_LIMIT; /* Too many references */
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100328 goto unlock_and_exit;
329 }
330
331 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800332 * Update the enable mask on the first wakeup reference. Wake GPEs
333 * are only hardware-enabled just before sleeping.
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100334 */
Lin Ming0f849d22010-04-06 14:52:37 +0800335 gpe_event_info->wakeup_count++;
336 if (gpe_event_info->wakeup_count == 1) {
337 (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
338 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100339 }
340
341unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400342 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400343 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
Bob Moore83135242006-10-03 00:00:00 -0400345ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347/*******************************************************************************
348 *
349 * FUNCTION: acpi_disable_gpe
350 *
Lin Ming0f849d22010-04-06 14:52:37 +0800351 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800353 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
354 * or both
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 *
356 * RETURN: Status
357 *
Lin Ming0f849d22010-04-06 14:52:37 +0800358 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
359 * removed, only then is the GPE disabled (for runtime GPEs), or
360 * the GPE mask bit disabled (for wake GPEs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 *
362 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800363acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Len Brown4be44fc2005-08-05 00:44:28 -0400365 acpi_status status = AE_OK;
366 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800367 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Bob Mooreb229cf92006-04-21 17:15:00 -0400369 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Lin Ming0f849d22010-04-06 14:52:37 +0800371 /* Parameter validation */
372
373 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100374 return_ACPI_STATUS(AE_BAD_PARAMETER);
Lin Ming0f849d22010-04-06 14:52:37 +0800375 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100376
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400377 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Lin Ming0f849d22010-04-06 14:52:37 +0800378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 /* Ensure that we have a valid GPE number */
380
Len Brown4be44fc2005-08-05 00:44:28 -0400381 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (!gpe_event_info) {
383 status = AE_BAD_PARAMETER;
384 goto unlock_and_exit;
385 }
386
Lin Ming0f849d22010-04-06 14:52:37 +0800387 /* Hardware-disable a runtime GPE on removal of the last reference */
388
389 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
390 if (!gpe_event_info->runtime_count) {
391 status = AE_LIMIT; /* There are no references to remove */
392 goto unlock_and_exit;
393 }
394
395 gpe_event_info->runtime_count--;
396 if (!gpe_event_info->runtime_count) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100397 status = acpi_ev_disable_gpe(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800398 if (ACPI_FAILURE(status)) {
399 gpe_event_info->runtime_count++;
400 goto unlock_and_exit;
401 }
402 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100403 }
404
Lin Ming0f849d22010-04-06 14:52:37 +0800405 /*
406 * Update masks for wake GPE on removal of the last reference.
407 * No need to hardware-disable wake GPEs here, they are not currently
408 * enabled.
409 */
410 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
411 if (!gpe_event_info->wakeup_count) {
412 status = AE_LIMIT; /* There are no references to remove */
413 goto unlock_and_exit;
414 }
415
416 gpe_event_info->wakeup_count--;
417 if (!gpe_event_info->wakeup_count) {
418 (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
419 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400422unlock_and_exit:
423 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400424 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
Bob Moore83135242006-10-03 00:00:00 -0400426ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428/*******************************************************************************
429 *
430 * FUNCTION: acpi_disable_event
431 *
432 * PARAMETERS: Event - The fixed eventto be enabled
433 * Flags - Reserved
434 *
435 * RETURN: Status
436 *
437 * DESCRIPTION: Disable an ACPI event (fixed)
438 *
439 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400440acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Len Brown4be44fc2005-08-05 00:44:28 -0400442 acpi_status status = AE_OK;
443 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Bob Mooreb229cf92006-04-21 17:15:00 -0400445 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 /* Decode the Fixed Event */
448
449 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400450 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
452
453 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800454 * Disable the requested fixed event (by writing a zero to the enable
455 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 */
Len Brown4be44fc2005-08-05 00:44:28 -0400457 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800458 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800459 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400460 if (ACPI_FAILURE(status)) {
461 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
463
Len Brown4be44fc2005-08-05 00:44:28 -0400464 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800465 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
466 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400467 if (ACPI_FAILURE(status)) {
468 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
470
471 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500472 ACPI_ERROR((AE_INFO,
473 "Could not disable %s events",
474 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400475 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477
Len Brown4be44fc2005-08-05 00:44:28 -0400478 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Bob Moore83135242006-10-03 00:00:00 -0400481ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483/*******************************************************************************
484 *
485 * FUNCTION: acpi_clear_event
486 *
487 * PARAMETERS: Event - The fixed event to be cleared
488 *
489 * RETURN: Status
490 *
491 * DESCRIPTION: Clear an ACPI event (fixed)
492 *
493 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400494acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Len Brown4be44fc2005-08-05 00:44:28 -0400496 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Bob Mooreb229cf92006-04-21 17:15:00 -0400498 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 /* Decode the Fixed Event */
501
502 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400503 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505
506 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800507 * Clear the requested fixed event (By writing a one to the status
508 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 */
Len Brown4be44fc2005-08-05 00:44:28 -0400510 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800511 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800512 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Len Brown4be44fc2005-08-05 00:44:28 -0400514 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Bob Moore83135242006-10-03 00:00:00 -0400517ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519/*******************************************************************************
520 *
521 * FUNCTION: acpi_clear_gpe
522 *
Lin Ming0f849d22010-04-06 14:52:37 +0800523 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 *
526 * RETURN: Status
527 *
528 * DESCRIPTION: Clear an ACPI event (general purpose)
529 *
530 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800531acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Len Brown4be44fc2005-08-05 00:44:28 -0400533 acpi_status status = AE_OK;
534 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800535 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Bob Mooreb229cf92006-04-21 17:15:00 -0400537 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Lin Ming0f849d22010-04-06 14:52:37 +0800539 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541 /* Ensure that we have a valid GPE number */
542
Len Brown4be44fc2005-08-05 00:44:28 -0400543 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (!gpe_event_info) {
545 status = AE_BAD_PARAMETER;
546 goto unlock_and_exit;
547 }
548
Len Brown4be44fc2005-08-05 00:44:28 -0400549 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Len Brown4be44fc2005-08-05 00:44:28 -0400551 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800552 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400553 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
Bob Moore83135242006-10-03 00:00:00 -0400556ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557/*******************************************************************************
558 *
559 * FUNCTION: acpi_get_event_status
560 *
561 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400562 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 * be returned
564 *
565 * RETURN: Status
566 *
567 * DESCRIPTION: Obtains and returns the current status of the event
568 *
569 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400570acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Len Brown4be44fc2005-08-05 00:44:28 -0400572 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800573 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Bob Mooreb229cf92006-04-21 17:15:00 -0400575 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400578 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
581 /* Decode the Fixed Event */
582
583 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400584 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
587 /* Get the status of the requested fixed event */
588
Len Brown4be44fc2005-08-05 00:44:28 -0400589 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800590 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800591 enable_register_id, &value);
592 if (ACPI_FAILURE(status))
593 return_ACPI_STATUS(status);
594
595 *event_status = value;
596
597 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800598 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800599 status_register_id, &value);
600 if (ACPI_FAILURE(status))
601 return_ACPI_STATUS(status);
602
603 if (value)
604 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Zhang Ruied206fa2008-10-27 14:01:02 -0700606 if (acpi_gbl_fixed_event_handlers[event].handler)
607 *event_status |= ACPI_EVENT_FLAG_HANDLE;
608
Len Brown4be44fc2005-08-05 00:44:28 -0400609 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610}
611
Bob Moore83135242006-10-03 00:00:00 -0400612ACPI_EXPORT_SYMBOL(acpi_get_event_status)
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614/*******************************************************************************
615 *
616 * FUNCTION: acpi_get_gpe_status
617 *
Lin Ming0f849d22010-04-06 14:52:37 +0800618 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 * gpe_number - GPE level within the GPE block
Robert Moore44f6c012005-04-18 22:49:35 -0400620 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 * be returned
622 *
623 * RETURN: Status
624 *
625 * DESCRIPTION: Get status of an event (general purpose)
626 *
627 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400629acpi_get_gpe_status(acpi_handle gpe_device,
Lin Ming0f849d22010-04-06 14:52:37 +0800630 u32 gpe_number, acpi_event_status *event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
Len Brown4be44fc2005-08-05 00:44:28 -0400632 acpi_status status = AE_OK;
633 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800634 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Bob Mooreb229cf92006-04-21 17:15:00 -0400636 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Lin Ming0f849d22010-04-06 14:52:37 +0800638 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 /* Ensure that we have a valid GPE number */
641
Len Brown4be44fc2005-08-05 00:44:28 -0400642 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 if (!gpe_event_info) {
644 status = AE_BAD_PARAMETER;
645 goto unlock_and_exit;
646 }
647
648 /* Obtain status on the requested GPE number */
649
Len Brown4be44fc2005-08-05 00:44:28 -0400650 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Zhang Ruied206fa2008-10-27 14:01:02 -0700652 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
653 *event_status |= ACPI_EVENT_FLAG_HANDLE;
654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800656 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400657 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
Bob Moore83135242006-10-03 00:00:00 -0400659
660ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661/*******************************************************************************
662 *
663 * FUNCTION: acpi_install_gpe_block
664 *
665 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
666 * gpe_block_address - Address and space_iD
667 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400668 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 *
670 * RETURN: Status
671 *
672 * DESCRIPTION: Create and Install a block of GPE registers
673 *
674 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400676acpi_install_gpe_block(acpi_handle gpe_device,
677 struct acpi_generic_address *gpe_block_address,
678 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
Len Brown4be44fc2005-08-05 00:44:28 -0400680 acpi_status status;
681 union acpi_operand_object *obj_desc;
682 struct acpi_namespace_node *node;
683 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Bob Mooreb229cf92006-04-21 17:15:00 -0400685 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Len Brown4be44fc2005-08-05 00:44:28 -0400687 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
688 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690
Len Brown4be44fc2005-08-05 00:44:28 -0400691 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
692 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 return (status);
694 }
695
Bob Mooref24b6642009-12-11 14:57:00 +0800696 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 if (!node) {
698 status = AE_BAD_PARAMETER;
699 goto unlock_and_exit;
700 }
701
702 /*
703 * For user-installed GPE Block Devices, the gpe_block_base_number
704 * is always zero
705 */
Len Brown4be44fc2005-08-05 00:44:28 -0400706 status =
707 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
708 interrupt_number, &gpe_block);
709 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 goto unlock_and_exit;
711 }
712
Lin Ming0f849d22010-04-06 14:52:37 +0800713 /* Install block in the device_object attached to the node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400717
Lin Ming0f849d22010-04-06 14:52:37 +0800718 /*
719 * No object, create a new one (Device nodes do not always have
720 * an attached object)
721 */
Len Brown4be44fc2005-08-05 00:44:28 -0400722 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if (!obj_desc) {
724 status = AE_NO_MEMORY;
725 goto unlock_and_exit;
726 }
727
Len Brown4be44fc2005-08-05 00:44:28 -0400728 status =
729 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 /* Remove local reference to the object */
732
Len Brown4be44fc2005-08-05 00:44:28 -0400733 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Len Brown4be44fc2005-08-05 00:44:28 -0400735 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 goto unlock_and_exit;
737 }
738 }
739
Lin Ming0f849d22010-04-06 14:52:37 +0800740 /* Now install the GPE block in the device_object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 obj_desc->device.gpe_block = gpe_block;
743
Lin Ming0f849d22010-04-06 14:52:37 +0800744 /* Run the _PRW methods and enable the runtime GPEs in the new block */
745
746 status = acpi_ev_initialize_gpe_block(node, gpe_block);
747
Len Brown4be44fc2005-08-05 00:44:28 -0400748 unlock_and_exit:
749 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
750 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Bob Moore83135242006-10-03 00:00:00 -0400753ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755/*******************************************************************************
756 *
757 * FUNCTION: acpi_remove_gpe_block
758 *
759 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
760 *
761 * RETURN: Status
762 *
763 * DESCRIPTION: Remove a previously installed block of GPE registers
764 *
765 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400766acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Len Brown4be44fc2005-08-05 00:44:28 -0400768 union acpi_operand_object *obj_desc;
769 acpi_status status;
770 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Bob Mooreb229cf92006-04-21 17:15:00 -0400772 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400775 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777
Len Brown4be44fc2005-08-05 00:44:28 -0400778 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
779 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 return (status);
781 }
782
Bob Mooref24b6642009-12-11 14:57:00 +0800783 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 if (!node) {
785 status = AE_BAD_PARAMETER;
786 goto unlock_and_exit;
787 }
788
789 /* Get the device_object attached to the node */
790
Len Brown4be44fc2005-08-05 00:44:28 -0400791 obj_desc = acpi_ns_get_attached_object(node);
792 if (!obj_desc || !obj_desc->device.gpe_block) {
793 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795
796 /* Delete the GPE block (but not the device_object) */
797
Len Brown4be44fc2005-08-05 00:44:28 -0400798 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
799 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 obj_desc->device.gpe_block = NULL;
801 }
802
Len Brown4be44fc2005-08-05 00:44:28 -0400803 unlock_and_exit:
804 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
805 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806}
Robert Moore44f6c012005-04-18 22:49:35 -0400807
Bob Moore83135242006-10-03 00:00:00 -0400808ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
Bob Mooree97d6bf2008-12-30 09:45:17 +0800809
810/*******************************************************************************
811 *
812 * FUNCTION: acpi_get_gpe_device
813 *
814 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
815 * gpe_device - Where the parent GPE Device is returned
816 *
817 * RETURN: Status
818 *
819 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
820 * gpe device indicates that the gpe number is contained in one of
821 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
822 *
823 ******************************************************************************/
824acpi_status
825acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
826{
827 struct acpi_gpe_device_info info;
828 acpi_status status;
829
830 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
831
832 if (!gpe_device) {
833 return_ACPI_STATUS(AE_BAD_PARAMETER);
834 }
835
836 if (index >= acpi_current_gpe_count) {
837 return_ACPI_STATUS(AE_NOT_EXIST);
838 }
839
840 /* Setup and walk the GPE list */
841
842 info.index = index;
843 info.status = AE_NOT_EXIST;
844 info.gpe_device = NULL;
845 info.next_block_base_index = 0;
846
847 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
848 if (ACPI_FAILURE(status)) {
849 return_ACPI_STATUS(status);
850 }
851
852 *gpe_device = info.gpe_device;
853 return_ACPI_STATUS(info.status);
854}
855
856ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
857
858/*******************************************************************************
859 *
860 * FUNCTION: acpi_ev_get_gpe_device
861 *
862 * PARAMETERS: GPE_WALK_CALLBACK
863 *
864 * RETURN: Status
865 *
866 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
867 * block device. NULL if the GPE is one of the FADT-defined GPEs.
868 *
869 ******************************************************************************/
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800870static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800871acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
872 struct acpi_gpe_block_info *gpe_block, void *context)
873{
874 struct acpi_gpe_device_info *info = context;
875
876 /* Increment Index by the number of GPEs in this block */
877
Lin Ming0f849d22010-04-06 14:52:37 +0800878 info->next_block_base_index += gpe_block->gpe_count;
Bob Mooree97d6bf2008-12-30 09:45:17 +0800879
880 if (info->index < info->next_block_base_index) {
881 /*
882 * The GPE index is within this block, get the node. Leave the node
883 * NULL for the FADT-defined GPEs
884 */
885 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
886 info->gpe_device = gpe_block->node;
887 }
888
889 info->status = AE_OK;
890 return (AE_CTRL_END);
891 }
892
893 return (AE_OK);
894}
Bob Moore08ac07b2008-12-30 09:55:48 +0800895
896/******************************************************************************
897 *
898 * FUNCTION: acpi_disable_all_gpes
899 *
900 * PARAMETERS: None
901 *
902 * RETURN: Status
903 *
904 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
905 *
906 ******************************************************************************/
907
908acpi_status acpi_disable_all_gpes(void)
909{
910 acpi_status status;
911
912 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
913
914 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
915 if (ACPI_FAILURE(status)) {
916 return_ACPI_STATUS(status);
917 }
918
919 status = acpi_hw_disable_all_gpes();
920 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
921
922 return_ACPI_STATUS(status);
923}
924
925/******************************************************************************
926 *
927 * FUNCTION: acpi_enable_all_runtime_gpes
928 *
929 * PARAMETERS: None
930 *
931 * RETURN: Status
932 *
933 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
934 *
935 ******************************************************************************/
936
937acpi_status acpi_enable_all_runtime_gpes(void)
938{
939 acpi_status status;
940
941 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
942
943 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
944 if (ACPI_FAILURE(status)) {
945 return_ACPI_STATUS(status);
946 }
947
948 status = acpi_hw_enable_all_runtime_gpes();
949 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
950
951 return_ACPI_STATUS(status);
952}