blob: 467fde961aefe164c748d2e37d48c474571391cb [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:
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800355 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
356 (u8)register_bit);
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200357 break;
358
359 case ACPI_GPE_DISABLE:
360 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800361 (u8)register_bit);
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200362 break;
363
364 default:
365 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
366 status = AE_BAD_PARAMETER;
367 break;
368 }
369
370unlock_and_exit:
371 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
372 return_ACPI_STATUS(status);
373}
374
375ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
376
377/*******************************************************************************
378 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 * FUNCTION: acpi_enable_gpe
380 *
Lin Ming0f849d22010-04-06 14:52:37 +0800381 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 *
384 * RETURN: Status
385 *
Lin Ming0f849d22010-04-06 14:52:37 +0800386 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800387 * hardware-enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 *
389 ******************************************************************************/
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800390acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
Len Brown4be44fc2005-08-05 00:44:28 -0400392 acpi_status status = AE_OK;
393 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800394 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Bob Mooreb229cf92006-04-21 17:15:00 -0400396 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400398 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /* Ensure that we have a valid GPE number */
401
Len Brown4be44fc2005-08-05 00:44:28 -0400402 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (!gpe_event_info) {
404 status = AE_BAD_PARAMETER;
405 goto unlock_and_exit;
406 }
407
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800408 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
409 status = AE_LIMIT; /* Too many references */
410 goto unlock_and_exit;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800413 gpe_event_info->runtime_count++;
414 if (gpe_event_info->runtime_count == 1) {
415 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
416 if (ACPI_SUCCESS(status)) {
417 status = acpi_clear_and_enable_gpe(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800418 }
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800419 if (ACPI_FAILURE(status)) {
420 gpe_event_info->runtime_count--;
Lin Ming0f849d22010-04-06 14:52:37 +0800421 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100422 }
423
424unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400425 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400426 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
Bob Moore83135242006-10-03 00:00:00 -0400428ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430/*******************************************************************************
431 *
432 * FUNCTION: acpi_disable_gpe
433 *
Lin Ming0f849d22010-04-06 14:52:37 +0800434 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 *
437 * RETURN: Status
438 *
Lin Ming0f849d22010-04-06 14:52:37 +0800439 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
440 * removed, only then is the GPE disabled (for runtime GPEs), or
441 * the GPE mask bit disabled (for wake GPEs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 *
443 ******************************************************************************/
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800444acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Len Brown4be44fc2005-08-05 00:44:28 -0400446 acpi_status status = AE_OK;
447 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800448 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Bob Mooreb229cf92006-04-21 17:15:00 -0400450 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400452 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Lin Ming0f849d22010-04-06 14:52:37 +0800453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 /* Ensure that we have a valid GPE number */
455
Len Brown4be44fc2005-08-05 00:44:28 -0400456 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if (!gpe_event_info) {
458 status = AE_BAD_PARAMETER;
459 goto unlock_and_exit;
460 }
461
Lin Ming0f849d22010-04-06 14:52:37 +0800462 /* Hardware-disable a runtime GPE on removal of the last reference */
463
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800464 if (!gpe_event_info->runtime_count) {
465 status = AE_LIMIT; /* There are no references to remove */
466 goto unlock_and_exit;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100467 }
468
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800469 gpe_event_info->runtime_count--;
470 if (!gpe_event_info->runtime_count) {
471 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
472 if (ACPI_SUCCESS(status)) {
473 status =
474 acpi_hw_low_set_gpe(gpe_event_info,
475 ACPI_GPE_DISABLE);
Lin Ming0f849d22010-04-06 14:52:37 +0800476 }
Rafael J. Wysockia44061a2010-07-01 10:11:45 +0800477 if (ACPI_FAILURE(status)) {
478 gpe_event_info->runtime_count++;
Lin Ming0f849d22010-04-06 14:52:37 +0800479 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400482unlock_and_exit:
483 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400484 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
Bob Moore83135242006-10-03 00:00:00 -0400486ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488/*******************************************************************************
489 *
490 * FUNCTION: acpi_disable_event
491 *
492 * PARAMETERS: Event - The fixed eventto be enabled
493 * Flags - Reserved
494 *
495 * RETURN: Status
496 *
497 * DESCRIPTION: Disable an ACPI event (fixed)
498 *
499 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400500acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Len Brown4be44fc2005-08-05 00:44:28 -0400502 acpi_status status = AE_OK;
503 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Bob Mooreb229cf92006-04-21 17:15:00 -0400505 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 /* Decode the Fixed Event */
508
509 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400510 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512
513 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800514 * Disable the requested fixed event (by writing a zero to the enable
515 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 */
Len Brown4be44fc2005-08-05 00:44:28 -0400517 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800518 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800519 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400520 if (ACPI_FAILURE(status)) {
521 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 }
523
Len Brown4be44fc2005-08-05 00:44:28 -0400524 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800525 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
526 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400527 if (ACPI_FAILURE(status)) {
528 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
530
531 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500532 ACPI_ERROR((AE_INFO,
533 "Could not disable %s events",
534 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400535 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
537
Len Brown4be44fc2005-08-05 00:44:28 -0400538 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Bob Moore83135242006-10-03 00:00:00 -0400541ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543/*******************************************************************************
544 *
545 * FUNCTION: acpi_clear_event
546 *
547 * PARAMETERS: Event - The fixed event to be cleared
548 *
549 * RETURN: Status
550 *
551 * DESCRIPTION: Clear an ACPI event (fixed)
552 *
553 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400554acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Len Brown4be44fc2005-08-05 00:44:28 -0400556 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Bob Mooreb229cf92006-04-21 17:15:00 -0400558 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 /* Decode the Fixed Event */
561
562 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400563 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565
566 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800567 * Clear the requested fixed event (By writing a one to the status
568 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 */
Len Brown4be44fc2005-08-05 00:44:28 -0400570 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800571 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800572 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Len Brown4be44fc2005-08-05 00:44:28 -0400574 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Bob Moore83135242006-10-03 00:00:00 -0400577ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579/*******************************************************************************
580 *
581 * FUNCTION: acpi_clear_gpe
582 *
Lin Ming0f849d22010-04-06 14:52:37 +0800583 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 *
586 * RETURN: Status
587 *
588 * DESCRIPTION: Clear an ACPI event (general purpose)
589 *
590 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800591acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Len Brown4be44fc2005-08-05 00:44:28 -0400593 acpi_status status = AE_OK;
594 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800595 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Bob Mooreb229cf92006-04-21 17:15:00 -0400597 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Lin Ming0f849d22010-04-06 14:52:37 +0800599 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 /* Ensure that we have a valid GPE number */
602
Len Brown4be44fc2005-08-05 00:44:28 -0400603 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 if (!gpe_event_info) {
605 status = AE_BAD_PARAMETER;
606 goto unlock_and_exit;
607 }
608
Len Brown4be44fc2005-08-05 00:44:28 -0400609 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Len Brown4be44fc2005-08-05 00:44:28 -0400611 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800612 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400613 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614}
615
Bob Moore83135242006-10-03 00:00:00 -0400616ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617/*******************************************************************************
618 *
619 * FUNCTION: acpi_get_event_status
620 *
621 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400622 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 * be returned
624 *
625 * RETURN: Status
626 *
627 * DESCRIPTION: Obtains and returns the current status of the event
628 *
629 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400630acpi_status acpi_get_event_status(u32 event, 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;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800633 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Bob Mooreb229cf92006-04-21 17:15:00 -0400635 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400638 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640
641 /* Decode the Fixed Event */
642
643 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400644 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646
647 /* Get the status of the requested fixed event */
648
Len Brown4be44fc2005-08-05 00:44:28 -0400649 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800650 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800651 enable_register_id, &value);
652 if (ACPI_FAILURE(status))
653 return_ACPI_STATUS(status);
654
655 *event_status = value;
656
657 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800658 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800659 status_register_id, &value);
660 if (ACPI_FAILURE(status))
661 return_ACPI_STATUS(status);
662
663 if (value)
664 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Zhang Ruied206fa2008-10-27 14:01:02 -0700666 if (acpi_gbl_fixed_event_handlers[event].handler)
667 *event_status |= ACPI_EVENT_FLAG_HANDLE;
668
Len Brown4be44fc2005-08-05 00:44:28 -0400669 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670}
671
Bob Moore83135242006-10-03 00:00:00 -0400672ACPI_EXPORT_SYMBOL(acpi_get_event_status)
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674/*******************************************************************************
675 *
676 * FUNCTION: acpi_get_gpe_status
677 *
Lin Ming0f849d22010-04-06 14:52:37 +0800678 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 * gpe_number - GPE level within the GPE block
Robert Moore44f6c012005-04-18 22:49:35 -0400680 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 * be returned
682 *
683 * RETURN: Status
684 *
685 * DESCRIPTION: Get status of an event (general purpose)
686 *
687 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400689acpi_get_gpe_status(acpi_handle gpe_device,
Lin Ming0f849d22010-04-06 14:52:37 +0800690 u32 gpe_number, acpi_event_status *event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Len Brown4be44fc2005-08-05 00:44:28 -0400692 acpi_status status = AE_OK;
693 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800694 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Bob Mooreb229cf92006-04-21 17:15:00 -0400696 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Lin Ming0f849d22010-04-06 14:52:37 +0800698 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 /* Ensure that we have a valid GPE number */
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (!gpe_event_info) {
704 status = AE_BAD_PARAMETER;
705 goto unlock_and_exit;
706 }
707
708 /* Obtain status on the requested GPE number */
709
Len Brown4be44fc2005-08-05 00:44:28 -0400710 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Zhang Ruied206fa2008-10-27 14:01:02 -0700712 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
713 *event_status |= ACPI_EVENT_FLAG_HANDLE;
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800716 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400717 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718}
Bob Moore83135242006-10-03 00:00:00 -0400719
720ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721/*******************************************************************************
722 *
723 * FUNCTION: acpi_install_gpe_block
724 *
725 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
726 * gpe_block_address - Address and space_iD
727 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400728 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 *
730 * RETURN: Status
731 *
732 * DESCRIPTION: Create and Install a block of GPE registers
733 *
734 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400736acpi_install_gpe_block(acpi_handle gpe_device,
737 struct acpi_generic_address *gpe_block_address,
738 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739{
Len Brown4be44fc2005-08-05 00:44:28 -0400740 acpi_status status;
741 union acpi_operand_object *obj_desc;
742 struct acpi_namespace_node *node;
743 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Bob Mooreb229cf92006-04-21 17:15:00 -0400745 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Len Brown4be44fc2005-08-05 00:44:28 -0400747 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
748 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 }
750
Len Brown4be44fc2005-08-05 00:44:28 -0400751 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
752 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 return (status);
754 }
755
Bob Mooref24b6642009-12-11 14:57:00 +0800756 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 if (!node) {
758 status = AE_BAD_PARAMETER;
759 goto unlock_and_exit;
760 }
761
762 /*
763 * For user-installed GPE Block Devices, the gpe_block_base_number
764 * is always zero
765 */
Len Brown4be44fc2005-08-05 00:44:28 -0400766 status =
767 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
768 interrupt_number, &gpe_block);
769 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 goto unlock_and_exit;
771 }
772
Lin Ming0f849d22010-04-06 14:52:37 +0800773 /* Install block in the device_object attached to the node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Len Brown4be44fc2005-08-05 00:44:28 -0400775 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400777
Lin Ming0f849d22010-04-06 14:52:37 +0800778 /*
779 * No object, create a new one (Device nodes do not always have
780 * an attached object)
781 */
Len Brown4be44fc2005-08-05 00:44:28 -0400782 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 if (!obj_desc) {
784 status = AE_NO_MEMORY;
785 goto unlock_and_exit;
786 }
787
Len Brown4be44fc2005-08-05 00:44:28 -0400788 status =
789 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 /* Remove local reference to the object */
792
Len Brown4be44fc2005-08-05 00:44:28 -0400793 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Len Brown4be44fc2005-08-05 00:44:28 -0400795 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 goto unlock_and_exit;
797 }
798 }
799
Lin Ming0f849d22010-04-06 14:52:37 +0800800 /* Now install the GPE block in the device_object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 obj_desc->device.gpe_block = gpe_block;
803
Lin Ming0f849d22010-04-06 14:52:37 +0800804 /* Run the _PRW methods and enable the runtime GPEs in the new block */
805
806 status = acpi_ev_initialize_gpe_block(node, gpe_block);
807
Len Brown4be44fc2005-08-05 00:44:28 -0400808 unlock_and_exit:
809 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
810 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Bob Moore83135242006-10-03 00:00:00 -0400813ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815/*******************************************************************************
816 *
817 * FUNCTION: acpi_remove_gpe_block
818 *
819 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
820 *
821 * RETURN: Status
822 *
823 * DESCRIPTION: Remove a previously installed block of GPE registers
824 *
825 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400826acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Len Brown4be44fc2005-08-05 00:44:28 -0400828 union acpi_operand_object *obj_desc;
829 acpi_status status;
830 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Bob Mooreb229cf92006-04-21 17:15:00 -0400832 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400835 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 }
837
Len Brown4be44fc2005-08-05 00:44:28 -0400838 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
839 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 return (status);
841 }
842
Bob Mooref24b6642009-12-11 14:57:00 +0800843 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 if (!node) {
845 status = AE_BAD_PARAMETER;
846 goto unlock_and_exit;
847 }
848
849 /* Get the device_object attached to the node */
850
Len Brown4be44fc2005-08-05 00:44:28 -0400851 obj_desc = acpi_ns_get_attached_object(node);
852 if (!obj_desc || !obj_desc->device.gpe_block) {
853 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 }
855
856 /* Delete the GPE block (but not the device_object) */
857
Len Brown4be44fc2005-08-05 00:44:28 -0400858 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
859 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 obj_desc->device.gpe_block = NULL;
861 }
862
Len Brown4be44fc2005-08-05 00:44:28 -0400863 unlock_and_exit:
864 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
865 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866}
Robert Moore44f6c012005-04-18 22:49:35 -0400867
Bob Moore83135242006-10-03 00:00:00 -0400868ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
Bob Mooree97d6bf2008-12-30 09:45:17 +0800869
870/*******************************************************************************
871 *
872 * FUNCTION: acpi_get_gpe_device
873 *
874 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
875 * gpe_device - Where the parent GPE Device is returned
876 *
877 * RETURN: Status
878 *
879 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
880 * gpe device indicates that the gpe number is contained in one of
881 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
882 *
883 ******************************************************************************/
884acpi_status
885acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
886{
887 struct acpi_gpe_device_info info;
888 acpi_status status;
889
890 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
891
892 if (!gpe_device) {
893 return_ACPI_STATUS(AE_BAD_PARAMETER);
894 }
895
896 if (index >= acpi_current_gpe_count) {
897 return_ACPI_STATUS(AE_NOT_EXIST);
898 }
899
900 /* Setup and walk the GPE list */
901
902 info.index = index;
903 info.status = AE_NOT_EXIST;
904 info.gpe_device = NULL;
905 info.next_block_base_index = 0;
906
907 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
908 if (ACPI_FAILURE(status)) {
909 return_ACPI_STATUS(status);
910 }
911
912 *gpe_device = info.gpe_device;
913 return_ACPI_STATUS(info.status);
914}
915
916ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
917
918/*******************************************************************************
919 *
920 * FUNCTION: acpi_ev_get_gpe_device
921 *
922 * PARAMETERS: GPE_WALK_CALLBACK
923 *
924 * RETURN: Status
925 *
926 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
927 * block device. NULL if the GPE is one of the FADT-defined GPEs.
928 *
929 ******************************************************************************/
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800930static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800931acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
932 struct acpi_gpe_block_info *gpe_block, void *context)
933{
934 struct acpi_gpe_device_info *info = context;
935
936 /* Increment Index by the number of GPEs in this block */
937
Lin Ming0f849d22010-04-06 14:52:37 +0800938 info->next_block_base_index += gpe_block->gpe_count;
Bob Mooree97d6bf2008-12-30 09:45:17 +0800939
940 if (info->index < info->next_block_base_index) {
941 /*
942 * The GPE index is within this block, get the node. Leave the node
943 * NULL for the FADT-defined GPEs
944 */
945 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
946 info->gpe_device = gpe_block->node;
947 }
948
949 info->status = AE_OK;
950 return (AE_CTRL_END);
951 }
952
953 return (AE_OK);
954}
Bob Moore08ac07b2008-12-30 09:55:48 +0800955
956/******************************************************************************
957 *
958 * FUNCTION: acpi_disable_all_gpes
959 *
960 * PARAMETERS: None
961 *
962 * RETURN: Status
963 *
964 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
965 *
966 ******************************************************************************/
967
968acpi_status acpi_disable_all_gpes(void)
969{
970 acpi_status status;
971
972 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
973
974 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
975 if (ACPI_FAILURE(status)) {
976 return_ACPI_STATUS(status);
977 }
978
979 status = acpi_hw_disable_all_gpes();
980 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
981
982 return_ACPI_STATUS(status);
983}
984
985/******************************************************************************
986 *
987 * FUNCTION: acpi_enable_all_runtime_gpes
988 *
989 * PARAMETERS: None
990 *
991 * RETURN: Status
992 *
993 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
994 *
995 ******************************************************************************/
996
997acpi_status acpi_enable_all_runtime_gpes(void)
998{
999 acpi_status status;
1000
1001 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
1002
1003 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1004 if (ACPI_FAILURE(status)) {
1005 return_ACPI_STATUS(status);
1006 }
1007
1008 status = acpi_hw_enable_all_runtime_gpes();
1009 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1010
1011 return_ACPI_STATUS(status);
1012}