blob: d6a6d4a765926dff17da0b255bc3a9d4a49e7ae9 [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. Wysockifd247442010-06-08 10:49:08 +0200213 * 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 ******************************************************************************/
222static acpi_status
223acpi_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. Wysocki9630bdd2010-02-17 23:41:07 +0100251 * FUNCTION: acpi_set_gpe
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 *
Lin Ming0f849d22010-04-06 14:52:37 +0800253 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800255 * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 *
257 * RETURN: Status
258 *
Lin Ming0f849d22010-04-06 14:52:37 +0800259 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700266 *
267 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100268acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Len Brown4be44fc2005-08-05 00:44:28 -0400270 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800271 acpi_status status;
272 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100274 ACPI_FUNCTION_TRACE(acpi_set_gpe);
275
276 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 /* Ensure that we have a valid GPE number */
279
Len Brown4be44fc2005-08-05 00:44:28 -0400280 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 if (!gpe_event_info) {
282 status = AE_BAD_PARAMETER;
283 goto unlock_and_exit;
284 }
285
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100286 /* Perform the action */
287
288 switch (action) {
289 case ACPI_GPE_ENABLE:
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200290 status = acpi_clear_and_enable_gpe(gpe_event_info);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100291 break;
292
293 case ACPI_GPE_DISABLE:
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200294 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100295 break;
296
297 default:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100298 status = AE_BAD_PARAMETER;
299 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301
Len Brown4be44fc2005-08-05 00:44:28 -0400302 unlock_and_exit:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100303 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400304 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100307ACPI_EXPORT_SYMBOL(acpi_set_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309/*******************************************************************************
310 *
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200311 * FUNCTION: acpi_gpe_wakeup
312 *
313 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
314 * gpe_number - GPE level within the GPE block
315 * Action - Enable or Disable
316 *
317 * RETURN: Status
318 *
319 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
320 *
321 ******************************************************************************/
322acpi_status acpi_gpe_wakeup(acpi_handle gpe_device, u32 gpe_number, u8 action)
323{
324 acpi_status status = AE_OK;
325 struct acpi_gpe_event_info *gpe_event_info;
326 struct acpi_gpe_register_info *gpe_register_info;
327 acpi_cpu_flags flags;
328 u32 register_bit;
329
330 ACPI_FUNCTION_TRACE(acpi_gpe_wakeup);
331
332 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
333
334 /* Ensure that we have a valid GPE number */
335
336 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
337 if (!gpe_event_info) {
338 status = AE_BAD_PARAMETER;
339 goto unlock_and_exit;
340 }
341
342 gpe_register_info = gpe_event_info->register_info;
343 if (!gpe_register_info) {
344 status = AE_NOT_EXIST;
345 goto unlock_and_exit;
346 }
347
348 register_bit =
349 acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
350
351 /* Perform the action */
352
353 switch (action) {
354 case ACPI_GPE_ENABLE:
355 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
356 break;
357
358 case ACPI_GPE_DISABLE:
359 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
360 register_bit);
361 break;
362
363 default:
364 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
365 status = AE_BAD_PARAMETER;
366 break;
367 }
368
369unlock_and_exit:
370 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
371 return_ACPI_STATUS(status);
372}
373
374ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
375
376/*******************************************************************************
377 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 * FUNCTION: acpi_enable_gpe
379 *
Lin Ming0f849d22010-04-06 14:52:37 +0800380 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800382 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
383 * or both
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 *
385 * RETURN: Status
386 *
Lin Ming0f849d22010-04-06 14:52:37 +0800387 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
388 * hardware-enabled (for runtime GPEs), or the GPE register mask
389 * is updated (for wake GPEs).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 *
391 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800392acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Len Brown4be44fc2005-08-05 00:44:28 -0400394 acpi_status status = AE_OK;
395 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800396 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Bob Mooreb229cf92006-04-21 17:15:00 -0400398 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Lin Ming0f849d22010-04-06 14:52:37 +0800400 /* Parameter validation */
401
402 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100403 return_ACPI_STATUS(AE_BAD_PARAMETER);
Lin Ming0f849d22010-04-06 14:52:37 +0800404 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100405
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400406 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 /* Ensure that we have a valid GPE number */
409
Len Brown4be44fc2005-08-05 00:44:28 -0400410 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (!gpe_event_info) {
412 status = AE_BAD_PARAMETER;
413 goto unlock_and_exit;
414 }
415
Lin Ming0f849d22010-04-06 14:52:37 +0800416 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
417 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
418 status = AE_LIMIT; /* Too many references */
419 goto unlock_and_exit;
420 }
421
422 gpe_event_info->runtime_count++;
423 if (gpe_event_info->runtime_count == 1) {
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200424 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
425 if (ACPI_SUCCESS(status)) {
426 status = acpi_clear_and_enable_gpe(gpe_event_info);
427 }
428
Lin Ming0f849d22010-04-06 14:52:37 +0800429 if (ACPI_FAILURE(status)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100430 gpe_event_info->runtime_count--;
Lin Ming0f849d22010-04-06 14:52:37 +0800431 goto unlock_and_exit;
432 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100433 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Lin Ming0f849d22010-04-06 14:52:37 +0800436 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
437 /* The GPE must have the ability to wake the system */
438
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100439 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
Lin Ming0f849d22010-04-06 14:52:37 +0800440 status = AE_TYPE;
441 goto unlock_and_exit;
442 }
443
444 if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
445 status = AE_LIMIT; /* Too many references */
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100446 goto unlock_and_exit;
447 }
448
449 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800450 * Update the enable mask on the first wakeup reference. Wake GPEs
451 * are only hardware-enabled just before sleeping.
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100452 */
Lin Ming0f849d22010-04-06 14:52:37 +0800453 gpe_event_info->wakeup_count++;
454 if (gpe_event_info->wakeup_count == 1) {
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200455 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800456 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100457 }
458
459unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400460 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400461 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
Bob Moore83135242006-10-03 00:00:00 -0400463ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465/*******************************************************************************
466 *
467 * FUNCTION: acpi_disable_gpe
468 *
Lin Ming0f849d22010-04-06 14:52:37 +0800469 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800471 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
472 * or both
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 *
474 * RETURN: Status
475 *
Lin Ming0f849d22010-04-06 14:52:37 +0800476 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
477 * removed, only then is the GPE disabled (for runtime GPEs), or
478 * the GPE mask bit disabled (for wake GPEs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 *
480 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800481acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Len Brown4be44fc2005-08-05 00:44:28 -0400483 acpi_status status = AE_OK;
484 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800485 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Bob Mooreb229cf92006-04-21 17:15:00 -0400487 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Lin Ming0f849d22010-04-06 14:52:37 +0800489 /* Parameter validation */
490
491 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100492 return_ACPI_STATUS(AE_BAD_PARAMETER);
Lin Ming0f849d22010-04-06 14:52:37 +0800493 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100494
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400495 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Lin Ming0f849d22010-04-06 14:52:37 +0800496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 /* Ensure that we have a valid GPE number */
498
Len Brown4be44fc2005-08-05 00:44:28 -0400499 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if (!gpe_event_info) {
501 status = AE_BAD_PARAMETER;
502 goto unlock_and_exit;
503 }
504
Lin Ming0f849d22010-04-06 14:52:37 +0800505 /* Hardware-disable a runtime GPE on removal of the last reference */
506
507 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
508 if (!gpe_event_info->runtime_count) {
509 status = AE_LIMIT; /* There are no references to remove */
510 goto unlock_and_exit;
511 }
512
513 gpe_event_info->runtime_count--;
514 if (!gpe_event_info->runtime_count) {
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200515 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
516 if (ACPI_SUCCESS(status)) {
517 status = acpi_hw_low_set_gpe(gpe_event_info,
518 ACPI_GPE_DISABLE);
519 }
520
Lin Ming0f849d22010-04-06 14:52:37 +0800521 if (ACPI_FAILURE(status)) {
522 gpe_event_info->runtime_count++;
523 goto unlock_and_exit;
524 }
525 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100526 }
527
Lin Ming0f849d22010-04-06 14:52:37 +0800528 /*
529 * Update masks for wake GPE on removal of the last reference.
530 * No need to hardware-disable wake GPEs here, they are not currently
531 * enabled.
532 */
533 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
534 if (!gpe_event_info->wakeup_count) {
535 status = AE_LIMIT; /* There are no references to remove */
536 goto unlock_and_exit;
537 }
538
539 gpe_event_info->wakeup_count--;
540 if (!gpe_event_info->wakeup_count) {
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200541 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800542 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400545unlock_and_exit:
546 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400547 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
Bob Moore83135242006-10-03 00:00:00 -0400549ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551/*******************************************************************************
552 *
553 * FUNCTION: acpi_disable_event
554 *
555 * PARAMETERS: Event - The fixed eventto be enabled
556 * Flags - Reserved
557 *
558 * RETURN: Status
559 *
560 * DESCRIPTION: Disable an ACPI event (fixed)
561 *
562 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400563acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Len Brown4be44fc2005-08-05 00:44:28 -0400565 acpi_status status = AE_OK;
566 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Bob Mooreb229cf92006-04-21 17:15:00 -0400568 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 /* Decode the Fixed Event */
571
572 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400573 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575
576 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800577 * Disable the requested fixed event (by writing a zero to the enable
578 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 */
Len Brown4be44fc2005-08-05 00:44:28 -0400580 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800581 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800582 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400583 if (ACPI_FAILURE(status)) {
584 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
Len Brown4be44fc2005-08-05 00:44:28 -0400587 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800588 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
589 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400590 if (ACPI_FAILURE(status)) {
591 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593
594 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500595 ACPI_ERROR((AE_INFO,
596 "Could not disable %s events",
597 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400598 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600
Len Brown4be44fc2005-08-05 00:44:28 -0400601 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Bob Moore83135242006-10-03 00:00:00 -0400604ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606/*******************************************************************************
607 *
608 * FUNCTION: acpi_clear_event
609 *
610 * PARAMETERS: Event - The fixed event to be cleared
611 *
612 * RETURN: Status
613 *
614 * DESCRIPTION: Clear an ACPI event (fixed)
615 *
616 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400617acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
Len Brown4be44fc2005-08-05 00:44:28 -0400619 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Bob Mooreb229cf92006-04-21 17:15:00 -0400621 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 /* Decode the Fixed Event */
624
625 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400626 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 }
628
629 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800630 * Clear the requested fixed event (By writing a one to the status
631 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 */
Len Brown4be44fc2005-08-05 00:44:28 -0400633 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800634 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800635 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Bob Moore83135242006-10-03 00:00:00 -0400640ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642/*******************************************************************************
643 *
644 * FUNCTION: acpi_clear_gpe
645 *
Lin Ming0f849d22010-04-06 14:52:37 +0800646 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 *
649 * RETURN: Status
650 *
651 * DESCRIPTION: Clear an ACPI event (general purpose)
652 *
653 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800654acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Len Brown4be44fc2005-08-05 00:44:28 -0400656 acpi_status status = AE_OK;
657 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800658 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Bob Mooreb229cf92006-04-21 17:15:00 -0400660 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Lin Ming0f849d22010-04-06 14:52:37 +0800662 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 /* Ensure that we have a valid GPE number */
665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if (!gpe_event_info) {
668 status = AE_BAD_PARAMETER;
669 goto unlock_and_exit;
670 }
671
Len Brown4be44fc2005-08-05 00:44:28 -0400672 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800675 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400676 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
Bob Moore83135242006-10-03 00:00:00 -0400679ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680/*******************************************************************************
681 *
682 * FUNCTION: acpi_get_event_status
683 *
684 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400685 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 * be returned
687 *
688 * RETURN: Status
689 *
690 * DESCRIPTION: Obtains and returns the current status of the event
691 *
692 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400693acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
Len Brown4be44fc2005-08-05 00:44:28 -0400695 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800696 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Bob Mooreb229cf92006-04-21 17:15:00 -0400698 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400701 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
703
704 /* Decode the Fixed Event */
705
706 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400707 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
709
710 /* Get the status of the requested fixed event */
711
Len Brown4be44fc2005-08-05 00:44:28 -0400712 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800713 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800714 enable_register_id, &value);
715 if (ACPI_FAILURE(status))
716 return_ACPI_STATUS(status);
717
718 *event_status = value;
719
720 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800721 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800722 status_register_id, &value);
723 if (ACPI_FAILURE(status))
724 return_ACPI_STATUS(status);
725
726 if (value)
727 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Zhang Ruied206fa2008-10-27 14:01:02 -0700729 if (acpi_gbl_fixed_event_handlers[event].handler)
730 *event_status |= ACPI_EVENT_FLAG_HANDLE;
731
Len Brown4be44fc2005-08-05 00:44:28 -0400732 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733}
734
Bob Moore83135242006-10-03 00:00:00 -0400735ACPI_EXPORT_SYMBOL(acpi_get_event_status)
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737/*******************************************************************************
738 *
739 * FUNCTION: acpi_get_gpe_status
740 *
Lin Ming0f849d22010-04-06 14:52:37 +0800741 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 * gpe_number - GPE level within the GPE block
Robert Moore44f6c012005-04-18 22:49:35 -0400743 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 * be returned
745 *
746 * RETURN: Status
747 *
748 * DESCRIPTION: Get status of an event (general purpose)
749 *
750 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400752acpi_get_gpe_status(acpi_handle gpe_device,
Lin Ming0f849d22010-04-06 14:52:37 +0800753 u32 gpe_number, acpi_event_status *event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754{
Len Brown4be44fc2005-08-05 00:44:28 -0400755 acpi_status status = AE_OK;
756 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800757 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Bob Mooreb229cf92006-04-21 17:15:00 -0400759 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Lin Ming0f849d22010-04-06 14:52:37 +0800761 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 /* Ensure that we have a valid GPE number */
764
Len Brown4be44fc2005-08-05 00:44:28 -0400765 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 if (!gpe_event_info) {
767 status = AE_BAD_PARAMETER;
768 goto unlock_and_exit;
769 }
770
771 /* Obtain status on the requested GPE number */
772
Len Brown4be44fc2005-08-05 00:44:28 -0400773 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Zhang Ruied206fa2008-10-27 14:01:02 -0700775 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
776 *event_status |= ACPI_EVENT_FLAG_HANDLE;
777
Len Brown4be44fc2005-08-05 00:44:28 -0400778 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800779 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400780 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
Bob Moore83135242006-10-03 00:00:00 -0400782
783ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784/*******************************************************************************
785 *
786 * FUNCTION: acpi_install_gpe_block
787 *
788 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
789 * gpe_block_address - Address and space_iD
790 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400791 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 *
793 * RETURN: Status
794 *
795 * DESCRIPTION: Create and Install a block of GPE registers
796 *
797 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400799acpi_install_gpe_block(acpi_handle gpe_device,
800 struct acpi_generic_address *gpe_block_address,
801 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Len Brown4be44fc2005-08-05 00:44:28 -0400803 acpi_status status;
804 union acpi_operand_object *obj_desc;
805 struct acpi_namespace_node *node;
806 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Bob Mooreb229cf92006-04-21 17:15:00 -0400808 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Len Brown4be44fc2005-08-05 00:44:28 -0400810 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
811 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
813
Len Brown4be44fc2005-08-05 00:44:28 -0400814 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
815 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 return (status);
817 }
818
Bob Mooref24b6642009-12-11 14:57:00 +0800819 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (!node) {
821 status = AE_BAD_PARAMETER;
822 goto unlock_and_exit;
823 }
824
825 /*
826 * For user-installed GPE Block Devices, the gpe_block_base_number
827 * is always zero
828 */
Len Brown4be44fc2005-08-05 00:44:28 -0400829 status =
830 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
831 interrupt_number, &gpe_block);
832 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 goto unlock_and_exit;
834 }
835
Lin Ming0f849d22010-04-06 14:52:37 +0800836 /* Install block in the device_object attached to the node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Len Brown4be44fc2005-08-05 00:44:28 -0400838 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400840
Lin Ming0f849d22010-04-06 14:52:37 +0800841 /*
842 * No object, create a new one (Device nodes do not always have
843 * an attached object)
844 */
Len Brown4be44fc2005-08-05 00:44:28 -0400845 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 if (!obj_desc) {
847 status = AE_NO_MEMORY;
848 goto unlock_and_exit;
849 }
850
Len Brown4be44fc2005-08-05 00:44:28 -0400851 status =
852 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 /* Remove local reference to the object */
855
Len Brown4be44fc2005-08-05 00:44:28 -0400856 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Len Brown4be44fc2005-08-05 00:44:28 -0400858 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 goto unlock_and_exit;
860 }
861 }
862
Lin Ming0f849d22010-04-06 14:52:37 +0800863 /* Now install the GPE block in the device_object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865 obj_desc->device.gpe_block = gpe_block;
866
Lin Ming0f849d22010-04-06 14:52:37 +0800867 /* Run the _PRW methods and enable the runtime GPEs in the new block */
868
869 status = acpi_ev_initialize_gpe_block(node, gpe_block);
870
Len Brown4be44fc2005-08-05 00:44:28 -0400871 unlock_and_exit:
872 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
873 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Bob Moore83135242006-10-03 00:00:00 -0400876ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878/*******************************************************************************
879 *
880 * FUNCTION: acpi_remove_gpe_block
881 *
882 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
883 *
884 * RETURN: Status
885 *
886 * DESCRIPTION: Remove a previously installed block of GPE registers
887 *
888 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400889acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
Len Brown4be44fc2005-08-05 00:44:28 -0400891 union acpi_operand_object *obj_desc;
892 acpi_status status;
893 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Bob Mooreb229cf92006-04-21 17:15:00 -0400895 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400898 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 }
900
Len Brown4be44fc2005-08-05 00:44:28 -0400901 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
902 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 return (status);
904 }
905
Bob Mooref24b6642009-12-11 14:57:00 +0800906 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 if (!node) {
908 status = AE_BAD_PARAMETER;
909 goto unlock_and_exit;
910 }
911
912 /* Get the device_object attached to the node */
913
Len Brown4be44fc2005-08-05 00:44:28 -0400914 obj_desc = acpi_ns_get_attached_object(node);
915 if (!obj_desc || !obj_desc->device.gpe_block) {
916 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918
919 /* Delete the GPE block (but not the device_object) */
920
Len Brown4be44fc2005-08-05 00:44:28 -0400921 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
922 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 obj_desc->device.gpe_block = NULL;
924 }
925
Len Brown4be44fc2005-08-05 00:44:28 -0400926 unlock_and_exit:
927 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
928 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
Robert Moore44f6c012005-04-18 22:49:35 -0400930
Bob Moore83135242006-10-03 00:00:00 -0400931ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
Bob Mooree97d6bf2008-12-30 09:45:17 +0800932
933/*******************************************************************************
934 *
935 * FUNCTION: acpi_get_gpe_device
936 *
937 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
938 * gpe_device - Where the parent GPE Device is returned
939 *
940 * RETURN: Status
941 *
942 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
943 * gpe device indicates that the gpe number is contained in one of
944 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
945 *
946 ******************************************************************************/
947acpi_status
948acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
949{
950 struct acpi_gpe_device_info info;
951 acpi_status status;
952
953 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
954
955 if (!gpe_device) {
956 return_ACPI_STATUS(AE_BAD_PARAMETER);
957 }
958
959 if (index >= acpi_current_gpe_count) {
960 return_ACPI_STATUS(AE_NOT_EXIST);
961 }
962
963 /* Setup and walk the GPE list */
964
965 info.index = index;
966 info.status = AE_NOT_EXIST;
967 info.gpe_device = NULL;
968 info.next_block_base_index = 0;
969
970 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
971 if (ACPI_FAILURE(status)) {
972 return_ACPI_STATUS(status);
973 }
974
975 *gpe_device = info.gpe_device;
976 return_ACPI_STATUS(info.status);
977}
978
979ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
980
981/*******************************************************************************
982 *
983 * FUNCTION: acpi_ev_get_gpe_device
984 *
985 * PARAMETERS: GPE_WALK_CALLBACK
986 *
987 * RETURN: Status
988 *
989 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
990 * block device. NULL if the GPE is one of the FADT-defined GPEs.
991 *
992 ******************************************************************************/
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800993static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800994acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
995 struct acpi_gpe_block_info *gpe_block, void *context)
996{
997 struct acpi_gpe_device_info *info = context;
998
999 /* Increment Index by the number of GPEs in this block */
1000
Lin Ming0f849d22010-04-06 14:52:37 +08001001 info->next_block_base_index += gpe_block->gpe_count;
Bob Mooree97d6bf2008-12-30 09:45:17 +08001002
1003 if (info->index < info->next_block_base_index) {
1004 /*
1005 * The GPE index is within this block, get the node. Leave the node
1006 * NULL for the FADT-defined GPEs
1007 */
1008 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
1009 info->gpe_device = gpe_block->node;
1010 }
1011
1012 info->status = AE_OK;
1013 return (AE_CTRL_END);
1014 }
1015
1016 return (AE_OK);
1017}
Bob Moore08ac07b2008-12-30 09:55:48 +08001018
1019/******************************************************************************
1020 *
1021 * FUNCTION: acpi_disable_all_gpes
1022 *
1023 * PARAMETERS: None
1024 *
1025 * RETURN: Status
1026 *
1027 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
1028 *
1029 ******************************************************************************/
1030
1031acpi_status acpi_disable_all_gpes(void)
1032{
1033 acpi_status status;
1034
1035 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
1036
1037 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1038 if (ACPI_FAILURE(status)) {
1039 return_ACPI_STATUS(status);
1040 }
1041
1042 status = acpi_hw_disable_all_gpes();
1043 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1044
1045 return_ACPI_STATUS(status);
1046}
1047
1048/******************************************************************************
1049 *
1050 * FUNCTION: acpi_enable_all_runtime_gpes
1051 *
1052 * PARAMETERS: None
1053 *
1054 * RETURN: Status
1055 *
1056 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
1057 *
1058 ******************************************************************************/
1059
1060acpi_status acpi_enable_all_runtime_gpes(void)
1061{
1062 acpi_status status;
1063
1064 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
1065
1066 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1067 if (ACPI_FAILURE(status)) {
1068 return_ACPI_STATUS(status);
1069 }
1070
1071 status = acpi_hw_enable_all_runtime_gpes();
1072 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1073
1074 return_ACPI_STATUS(status);
1075}