blob: b094cc0183d7355cef57aa2131e97e92be20c947 [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 Brownb430acb2010-05-06 17:41:08 -040072 acpi_status status;
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"));
Len Brownb430acb2010-05-06 17:41:08 -040087 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
Len Brownb430acb2010-05-06 17:41:08 -040090 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Bob Moore83135242006-10-03 00:00:00 -0400113ACPI_EXPORT_SYMBOL(acpi_enable)
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/*******************************************************************************
116 *
117 * FUNCTION: acpi_disable
118 *
119 * PARAMETERS: None
120 *
121 * RETURN: Status
122 *
Robert Moore44f6c012005-04-18 22:49:35 -0400123 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 *
125 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400126acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Len Brown4be44fc2005-08-05 00:44:28 -0400128 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Bob Mooreb229cf92006-04-21 17:15:00 -0400130 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400133 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
134 "System is already in legacy (non-ACPI) mode\n"));
135 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* Transition to LEGACY mode */
137
Len Brown4be44fc2005-08-05 00:44:28 -0400138 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Len Brown4be44fc2005-08-05 00:44:28 -0400140 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500141 ACPI_ERROR((AE_INFO,
142 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400143 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145
Len Brown4be44fc2005-08-05 00:44:28 -0400146 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Bob Moore83135242006-10-03 00:00:00 -0400152ACPI_EXPORT_SYMBOL(acpi_disable)
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154/*******************************************************************************
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 Brown4be44fc2005-08-05 00:44:28 -0400166acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Len Brown4be44fc2005-08-05 00:44:28 -0400168 acpi_status status = AE_OK;
169 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Bob Mooreb229cf92006-04-21 17:15:00 -0400171 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* Decode the Fixed Event */
174
175 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400176 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178
179 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800180 * Enable the requested fixed event (by writing a one to the enable
181 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 */
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800184 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800185 enable_register_id, ACPI_ENABLE_EVENT);
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 /* Make sure that the hardware responded */
191
Len Brown4be44fc2005-08-05 00:44:28 -0400192 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800193 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
194 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400195 if (ACPI_FAILURE(status)) {
196 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198
199 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500200 ACPI_ERROR((AE_INFO,
201 "Could not enable %s event",
202 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400203 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
205
Len Brown4be44fc2005-08-05 00:44:28 -0400206 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Bob Moore83135242006-10-03 00:00:00 -0400209ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211/*******************************************************************************
212 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100213 * FUNCTION: acpi_set_gpe
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 *
Lin Ming0f849d22010-04-06 14:52:37 +0800215 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800217 * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 *
219 * RETURN: Status
220 *
Lin Ming0f849d22010-04-06 14:52:37 +0800221 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
222 * the reference count mechanism used in the acpi_enable_gpe and
223 * acpi_disable_gpe interfaces -- and should be used with care.
224 *
225 * Note: Typically used to disable a runtime GPE for short period of time,
226 * then re-enable it, without disturbing the existing reference counts. This
227 * is useful, for example, in the Embedded Controller (EC) driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 *
229 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100230acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Len Brown4be44fc2005-08-05 00:44:28 -0400232 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800233 acpi_status status;
234 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100236 ACPI_FUNCTION_TRACE(acpi_set_gpe);
237
238 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 /* Ensure that we have a valid GPE number */
241
Len Brown4be44fc2005-08-05 00:44:28 -0400242 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 if (!gpe_event_info) {
244 status = AE_BAD_PARAMETER;
245 goto unlock_and_exit;
246 }
247
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100248 /* Perform the action */
249
250 switch (action) {
251 case ACPI_GPE_ENABLE:
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800252 status = acpi_ev_enable_gpe(gpe_event_info);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100253 break;
254
255 case ACPI_GPE_DISABLE:
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200256 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100257 break;
258
259 default:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100260 status = AE_BAD_PARAMETER;
261 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264 unlock_and_exit:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100265 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400266 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100269ACPI_EXPORT_SYMBOL(acpi_set_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271/*******************************************************************************
272 *
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200273 * FUNCTION: acpi_gpe_wakeup
274 *
275 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
276 * gpe_number - GPE level within the GPE block
277 * Action - Enable or Disable
278 *
279 * RETURN: Status
280 *
281 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
282 *
283 ******************************************************************************/
284acpi_status acpi_gpe_wakeup(acpi_handle gpe_device, u32 gpe_number, u8 action)
285{
286 acpi_status status = AE_OK;
287 struct acpi_gpe_event_info *gpe_event_info;
288 struct acpi_gpe_register_info *gpe_register_info;
289 acpi_cpu_flags flags;
290 u32 register_bit;
291
292 ACPI_FUNCTION_TRACE(acpi_gpe_wakeup);
293
294 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
295
296 /* Ensure that we have a valid GPE number */
297
298 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
299 if (!gpe_event_info) {
300 status = AE_BAD_PARAMETER;
301 goto unlock_and_exit;
302 }
303
304 gpe_register_info = gpe_event_info->register_info;
305 if (!gpe_register_info) {
306 status = AE_NOT_EXIST;
307 goto unlock_and_exit;
308 }
309
310 register_bit =
311 acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
312
313 /* Perform the action */
314
315 switch (action) {
316 case ACPI_GPE_ENABLE:
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800317 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
318 (u8)register_bit);
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200319 break;
320
321 case ACPI_GPE_DISABLE:
322 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800323 (u8)register_bit);
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200324 break;
325
326 default:
327 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
328 status = AE_BAD_PARAMETER;
329 break;
330 }
331
332unlock_and_exit:
333 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
334 return_ACPI_STATUS(status);
335}
336
337ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
338
339/*******************************************************************************
340 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 * FUNCTION: acpi_enable_gpe
342 *
Lin Ming0f849d22010-04-06 14:52:37 +0800343 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 *
346 * RETURN: Status
347 *
Lin Ming0f849d22010-04-06 14:52:37 +0800348 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800349 * hardware-enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 *
351 ******************************************************************************/
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800352acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Len Brown4be44fc2005-08-05 00:44:28 -0400354 acpi_status status = AE_OK;
355 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800356 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Bob Mooreb229cf92006-04-21 17:15:00 -0400358 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400360 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /* Ensure that we have a valid GPE number */
363
Len Brown4be44fc2005-08-05 00:44:28 -0400364 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (!gpe_event_info) {
366 status = AE_BAD_PARAMETER;
367 goto unlock_and_exit;
368 }
369
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800370 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
371 status = AE_LIMIT; /* Too many references */
372 goto unlock_and_exit;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800375 gpe_event_info->runtime_count++;
376 if (gpe_event_info->runtime_count == 1) {
377 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
378 if (ACPI_SUCCESS(status)) {
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800379 status = acpi_ev_enable_gpe(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800380 }
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800381 if (ACPI_FAILURE(status)) {
382 gpe_event_info->runtime_count--;
Lin Ming0f849d22010-04-06 14:52:37 +0800383 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100384 }
385
386unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400387 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400388 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
Bob Moore83135242006-10-03 00:00:00 -0400390ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392/*******************************************************************************
393 *
394 * FUNCTION: acpi_disable_gpe
395 *
Lin Ming0f849d22010-04-06 14:52:37 +0800396 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 *
399 * RETURN: Status
400 *
Lin Ming0f849d22010-04-06 14:52:37 +0800401 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
402 * removed, only then is the GPE disabled (for runtime GPEs), or
403 * the GPE mask bit disabled (for wake GPEs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 *
405 ******************************************************************************/
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800406acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
Len Brown4be44fc2005-08-05 00:44:28 -0400408 acpi_status status = AE_OK;
409 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800410 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Bob Mooreb229cf92006-04-21 17:15:00 -0400412 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400414 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Lin Ming0f849d22010-04-06 14:52:37 +0800415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 /* Ensure that we have a valid GPE number */
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 if (!gpe_event_info) {
420 status = AE_BAD_PARAMETER;
421 goto unlock_and_exit;
422 }
423
Lin Ming0f849d22010-04-06 14:52:37 +0800424 /* Hardware-disable a runtime GPE on removal of the last reference */
425
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800426 if (!gpe_event_info->runtime_count) {
427 status = AE_LIMIT; /* There are no references to remove */
428 goto unlock_and_exit;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100429 }
430
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800431 gpe_event_info->runtime_count--;
432 if (!gpe_event_info->runtime_count) {
433 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
434 if (ACPI_SUCCESS(status)) {
435 status =
436 acpi_hw_low_set_gpe(gpe_event_info,
437 ACPI_GPE_DISABLE);
Lin Ming0f849d22010-04-06 14:52:37 +0800438 }
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800439 if (ACPI_FAILURE(status)) {
440 gpe_event_info->runtime_count++;
Lin Ming0f849d22010-04-06 14:52:37 +0800441 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400444unlock_and_exit:
445 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400446 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447}
Bob Moore83135242006-10-03 00:00:00 -0400448ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450/*******************************************************************************
451 *
452 * FUNCTION: acpi_disable_event
453 *
454 * PARAMETERS: Event - The fixed eventto be enabled
455 * Flags - Reserved
456 *
457 * RETURN: Status
458 *
459 * DESCRIPTION: Disable an ACPI event (fixed)
460 *
461 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400462acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Len Brown4be44fc2005-08-05 00:44:28 -0400464 acpi_status status = AE_OK;
465 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Bob Mooreb229cf92006-04-21 17:15:00 -0400467 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 /* Decode the Fixed Event */
470
471 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400472 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 }
474
475 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800476 * Disable the requested fixed event (by writing a zero to the enable
477 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 */
Len Brown4be44fc2005-08-05 00:44:28 -0400479 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800480 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800481 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400482 if (ACPI_FAILURE(status)) {
483 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
485
Len Brown4be44fc2005-08-05 00:44:28 -0400486 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800487 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
488 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400489 if (ACPI_FAILURE(status)) {
490 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492
493 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500494 ACPI_ERROR((AE_INFO,
495 "Could not disable %s events",
496 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400497 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499
Len Brown4be44fc2005-08-05 00:44:28 -0400500 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Bob Moore83135242006-10-03 00:00:00 -0400503ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505/*******************************************************************************
506 *
507 * FUNCTION: acpi_clear_event
508 *
509 * PARAMETERS: Event - The fixed event to be cleared
510 *
511 * RETURN: Status
512 *
513 * DESCRIPTION: Clear an ACPI event (fixed)
514 *
515 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400516acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
Len Brown4be44fc2005-08-05 00:44:28 -0400518 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Bob Mooreb229cf92006-04-21 17:15:00 -0400520 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 /* Decode the Fixed Event */
523
524 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400525 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527
528 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800529 * Clear the requested fixed event (By writing a one to the status
530 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 */
Len Brown4be44fc2005-08-05 00:44:28 -0400532 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800533 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800534 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Len Brown4be44fc2005-08-05 00:44:28 -0400536 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Bob Moore83135242006-10-03 00:00:00 -0400539ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541/*******************************************************************************
542 *
543 * FUNCTION: acpi_clear_gpe
544 *
Lin Ming0f849d22010-04-06 14:52:37 +0800545 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 *
548 * RETURN: Status
549 *
550 * DESCRIPTION: Clear an ACPI event (general purpose)
551 *
552 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800553acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554{
Len Brown4be44fc2005-08-05 00:44:28 -0400555 acpi_status status = AE_OK;
556 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800557 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Bob Mooreb229cf92006-04-21 17:15:00 -0400559 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Lin Ming0f849d22010-04-06 14:52:37 +0800561 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 /* Ensure that we have a valid GPE number */
564
Len Brown4be44fc2005-08-05 00:44:28 -0400565 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 if (!gpe_event_info) {
567 status = AE_BAD_PARAMETER;
568 goto unlock_and_exit;
569 }
570
Len Brown4be44fc2005-08-05 00:44:28 -0400571 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Len Brown4be44fc2005-08-05 00:44:28 -0400573 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800574 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400575 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
Bob Moore83135242006-10-03 00:00:00 -0400578ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579/*******************************************************************************
580 *
581 * FUNCTION: acpi_get_event_status
582 *
583 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400584 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 * be returned
586 *
587 * RETURN: Status
588 *
589 * DESCRIPTION: Obtains and returns the current status of the event
590 *
591 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400592acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Len Brown4be44fc2005-08-05 00:44:28 -0400594 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800595 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Bob Mooreb229cf92006-04-21 17:15:00 -0400597 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400600 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
602
603 /* Decode the Fixed Event */
604
605 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400606 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608
609 /* Get the status of the requested fixed event */
610
Len Brown4be44fc2005-08-05 00:44:28 -0400611 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800612 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800613 enable_register_id, &value);
614 if (ACPI_FAILURE(status))
615 return_ACPI_STATUS(status);
616
617 *event_status = value;
618
619 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800620 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800621 status_register_id, &value);
622 if (ACPI_FAILURE(status))
623 return_ACPI_STATUS(status);
624
625 if (value)
626 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Zhang Ruied206fa2008-10-27 14:01:02 -0700628 if (acpi_gbl_fixed_event_handlers[event].handler)
629 *event_status |= ACPI_EVENT_FLAG_HANDLE;
630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632}
633
Bob Moore83135242006-10-03 00:00:00 -0400634ACPI_EXPORT_SYMBOL(acpi_get_event_status)
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636/*******************************************************************************
637 *
638 * FUNCTION: acpi_get_gpe_status
639 *
Lin Ming0f849d22010-04-06 14:52:37 +0800640 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 * gpe_number - GPE level within the GPE block
Robert Moore44f6c012005-04-18 22:49:35 -0400642 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 * be returned
644 *
645 * RETURN: Status
646 *
647 * DESCRIPTION: Get status of an event (general purpose)
648 *
649 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400651acpi_get_gpe_status(acpi_handle gpe_device,
Lin Ming0f849d22010-04-06 14:52:37 +0800652 u32 gpe_number, acpi_event_status *event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Len Brown4be44fc2005-08-05 00:44:28 -0400654 acpi_status status = AE_OK;
655 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800656 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Bob Mooreb229cf92006-04-21 17:15:00 -0400658 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Lin Ming0f849d22010-04-06 14:52:37 +0800660 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 /* Ensure that we have a valid GPE number */
663
Len Brown4be44fc2005-08-05 00:44:28 -0400664 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 if (!gpe_event_info) {
666 status = AE_BAD_PARAMETER;
667 goto unlock_and_exit;
668 }
669
670 /* Obtain status on the requested GPE number */
671
Len Brown4be44fc2005-08-05 00:44:28 -0400672 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Zhang Ruied206fa2008-10-27 14:01:02 -0700674 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
675 *event_status |= ACPI_EVENT_FLAG_HANDLE;
676
Len Brown4be44fc2005-08-05 00:44:28 -0400677 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800678 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400679 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
Bob Moore83135242006-10-03 00:00:00 -0400681
682ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683/*******************************************************************************
684 *
685 * FUNCTION: acpi_install_gpe_block
686 *
687 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
688 * gpe_block_address - Address and space_iD
689 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400690 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 *
692 * RETURN: Status
693 *
694 * DESCRIPTION: Create and Install a block of GPE registers
695 *
696 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400698acpi_install_gpe_block(acpi_handle gpe_device,
699 struct acpi_generic_address *gpe_block_address,
700 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Len Brown4be44fc2005-08-05 00:44:28 -0400702 acpi_status status;
703 union acpi_operand_object *obj_desc;
704 struct acpi_namespace_node *node;
705 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Bob Mooreb229cf92006-04-21 17:15:00 -0400707 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Len Brown4be44fc2005-08-05 00:44:28 -0400709 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
710 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 }
712
Len Brown4be44fc2005-08-05 00:44:28 -0400713 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
714 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 return (status);
716 }
717
Bob Mooref24b6642009-12-11 14:57:00 +0800718 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (!node) {
720 status = AE_BAD_PARAMETER;
721 goto unlock_and_exit;
722 }
723
724 /*
725 * For user-installed GPE Block Devices, the gpe_block_base_number
726 * is always zero
727 */
Len Brown4be44fc2005-08-05 00:44:28 -0400728 status =
729 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
730 interrupt_number, &gpe_block);
731 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 goto unlock_and_exit;
733 }
734
Lin Ming0f849d22010-04-06 14:52:37 +0800735 /* Install block in the device_object attached to the node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Len Brown4be44fc2005-08-05 00:44:28 -0400737 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400739
Lin Ming0f849d22010-04-06 14:52:37 +0800740 /*
741 * No object, create a new one (Device nodes do not always have
742 * an attached object)
743 */
Len Brown4be44fc2005-08-05 00:44:28 -0400744 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 if (!obj_desc) {
746 status = AE_NO_MEMORY;
747 goto unlock_and_exit;
748 }
749
Len Brown4be44fc2005-08-05 00:44:28 -0400750 status =
751 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /* Remove local reference to the object */
754
Len Brown4be44fc2005-08-05 00:44:28 -0400755 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Len Brown4be44fc2005-08-05 00:44:28 -0400757 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 goto unlock_and_exit;
759 }
760 }
761
Lin Ming0f849d22010-04-06 14:52:37 +0800762 /* Now install the GPE block in the device_object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 obj_desc->device.gpe_block = gpe_block;
765
Lin Ming0f849d22010-04-06 14:52:37 +0800766 /* Run the _PRW methods and enable the runtime GPEs in the new block */
767
768 status = acpi_ev_initialize_gpe_block(node, gpe_block);
769
Len Brown4be44fc2005-08-05 00:44:28 -0400770 unlock_and_exit:
771 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
772 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Bob Moore83135242006-10-03 00:00:00 -0400775ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777/*******************************************************************************
778 *
779 * FUNCTION: acpi_remove_gpe_block
780 *
781 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
782 *
783 * RETURN: Status
784 *
785 * DESCRIPTION: Remove a previously installed block of GPE registers
786 *
787 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400788acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Len Brown4be44fc2005-08-05 00:44:28 -0400790 union acpi_operand_object *obj_desc;
791 acpi_status status;
792 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Bob Mooreb229cf92006-04-21 17:15:00 -0400794 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400797 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
799
Len Brown4be44fc2005-08-05 00:44:28 -0400800 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
801 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 return (status);
803 }
804
Bob Mooref24b6642009-12-11 14:57:00 +0800805 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 if (!node) {
807 status = AE_BAD_PARAMETER;
808 goto unlock_and_exit;
809 }
810
811 /* Get the device_object attached to the node */
812
Len Brown4be44fc2005-08-05 00:44:28 -0400813 obj_desc = acpi_ns_get_attached_object(node);
814 if (!obj_desc || !obj_desc->device.gpe_block) {
815 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817
818 /* Delete the GPE block (but not the device_object) */
819
Len Brown4be44fc2005-08-05 00:44:28 -0400820 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
821 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 obj_desc->device.gpe_block = NULL;
823 }
824
Len Brown4be44fc2005-08-05 00:44:28 -0400825 unlock_and_exit:
826 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
827 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828}
Robert Moore44f6c012005-04-18 22:49:35 -0400829
Bob Moore83135242006-10-03 00:00:00 -0400830ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
Bob Mooree97d6bf2008-12-30 09:45:17 +0800831
832/*******************************************************************************
833 *
834 * FUNCTION: acpi_get_gpe_device
835 *
836 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
837 * gpe_device - Where the parent GPE Device is returned
838 *
839 * RETURN: Status
840 *
841 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
842 * gpe device indicates that the gpe number is contained in one of
843 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
844 *
845 ******************************************************************************/
846acpi_status
847acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
848{
849 struct acpi_gpe_device_info info;
850 acpi_status status;
851
852 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
853
854 if (!gpe_device) {
855 return_ACPI_STATUS(AE_BAD_PARAMETER);
856 }
857
858 if (index >= acpi_current_gpe_count) {
859 return_ACPI_STATUS(AE_NOT_EXIST);
860 }
861
862 /* Setup and walk the GPE list */
863
864 info.index = index;
865 info.status = AE_NOT_EXIST;
866 info.gpe_device = NULL;
867 info.next_block_base_index = 0;
868
869 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
870 if (ACPI_FAILURE(status)) {
871 return_ACPI_STATUS(status);
872 }
873
874 *gpe_device = info.gpe_device;
875 return_ACPI_STATUS(info.status);
876}
877
878ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
879
880/*******************************************************************************
881 *
882 * FUNCTION: acpi_ev_get_gpe_device
883 *
884 * PARAMETERS: GPE_WALK_CALLBACK
885 *
886 * RETURN: Status
887 *
888 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
889 * block device. NULL if the GPE is one of the FADT-defined GPEs.
890 *
891 ******************************************************************************/
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800892static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800893acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
894 struct acpi_gpe_block_info *gpe_block, void *context)
895{
896 struct acpi_gpe_device_info *info = context;
897
898 /* Increment Index by the number of GPEs in this block */
899
Lin Ming0f849d22010-04-06 14:52:37 +0800900 info->next_block_base_index += gpe_block->gpe_count;
Bob Mooree97d6bf2008-12-30 09:45:17 +0800901
902 if (info->index < info->next_block_base_index) {
903 /*
904 * The GPE index is within this block, get the node. Leave the node
905 * NULL for the FADT-defined GPEs
906 */
907 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
908 info->gpe_device = gpe_block->node;
909 }
910
911 info->status = AE_OK;
912 return (AE_CTRL_END);
913 }
914
915 return (AE_OK);
916}
Bob Moore08ac07b2008-12-30 09:55:48 +0800917
918/******************************************************************************
919 *
920 * FUNCTION: acpi_disable_all_gpes
921 *
922 * PARAMETERS: None
923 *
924 * RETURN: Status
925 *
926 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
927 *
928 ******************************************************************************/
929
930acpi_status acpi_disable_all_gpes(void)
931{
932 acpi_status status;
933
934 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
935
936 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
937 if (ACPI_FAILURE(status)) {
938 return_ACPI_STATUS(status);
939 }
940
941 status = acpi_hw_disable_all_gpes();
942 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
943
944 return_ACPI_STATUS(status);
945}
946
947/******************************************************************************
948 *
949 * FUNCTION: acpi_enable_all_runtime_gpes
950 *
951 * PARAMETERS: None
952 *
953 * RETURN: Status
954 *
955 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
956 *
957 ******************************************************************************/
958
959acpi_status acpi_enable_all_runtime_gpes(void)
960{
961 acpi_status status;
962
963 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
964
965 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
966 if (ACPI_FAILURE(status)) {
967 return_ACPI_STATUS(status);
968 }
969
970 status = acpi_hw_enable_all_runtime_gpes();
971 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
972
973 return_ACPI_STATUS(status);
974}