blob: e3d9f5c8e53d92b5147afeccf8c764879c2ac6d2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
48#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Bob Mooree97d6bf2008-12-30 09:45:17 +080053/* Local prototypes */
Bob Mooree4c1ebf2009-04-22 13:02:06 +080054static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +080055acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
56 struct acpi_gpe_block_info *gpe_block, void *context);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*******************************************************************************
59 *
60 * FUNCTION: acpi_enable
61 *
62 * PARAMETERS: None
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Transfers the system into ACPI mode.
67 *
68 ******************************************************************************/
Bob Mooree97d6bf2008-12-30 09:45:17 +080069
Len Brown4be44fc2005-08-05 00:44:28 -040070acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Len Brown4be44fc2005-08-05 00:44:28 -040072 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bob Mooreb229cf92006-04-21 17:15:00 -040074 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bob Moorec8573032007-02-02 19:48:23 +030076 /* ACPI tables must be present */
77
78 if (!acpi_tb_tables_loaded()) {
79 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
80 }
81
82 /* Check current mode */
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040085 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
86 "System is already in ACPI mode\n"));
87 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* Transition to ACPI mode */
89
Len Brown4be44fc2005-08-05 00:44:28 -040090 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
91 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050092 ACPI_ERROR((AE_INFO,
93 "Could not transition to ACPI mode"));
Len Brown4be44fc2005-08-05 00:44:28 -040094 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
Len Brown4be44fc2005-08-05 00:44:28 -040097 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
98 "Transition to ACPI mode successful\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
100
Len Brown4be44fc2005-08-05 00:44:28 -0400101 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Bob Moore83135242006-10-03 00:00:00 -0400104ACPI_EXPORT_SYMBOL(acpi_enable)
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/*******************************************************************************
107 *
108 * FUNCTION: acpi_disable
109 *
110 * PARAMETERS: None
111 *
112 * RETURN: Status
113 *
Robert Moore44f6c012005-04-18 22:49:35 -0400114 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400117acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Len Brown4be44fc2005-08-05 00:44:28 -0400119 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Bob Mooreb229cf92006-04-21 17:15:00 -0400121 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400124 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
125 "System is already in legacy (non-ACPI) mode\n"));
126 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /* Transition to LEGACY mode */
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Len Brown4be44fc2005-08-05 00:44:28 -0400131 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500132 ACPI_ERROR((AE_INFO,
133 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400134 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139
Len Brown4be44fc2005-08-05 00:44:28 -0400140 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Bob Moore83135242006-10-03 00:00:00 -0400143ACPI_EXPORT_SYMBOL(acpi_disable)
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*******************************************************************************
146 *
147 * FUNCTION: acpi_enable_event
148 *
149 * PARAMETERS: Event - The fixed eventto be enabled
150 * Flags - Reserved
151 *
152 * RETURN: Status
153 *
154 * DESCRIPTION: Enable an ACPI event (fixed)
155 *
156 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400157acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Len Brown4be44fc2005-08-05 00:44:28 -0400159 acpi_status status = AE_OK;
160 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Bob Mooreb229cf92006-04-21 17:15:00 -0400162 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 /* Decode the Fixed Event */
165
166 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400167 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169
170 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800171 * Enable the requested fixed event (by writing a one to the enable
172 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 */
Len Brown4be44fc2005-08-05 00:44:28 -0400174 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800175 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800176 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400177 if (ACPI_FAILURE(status)) {
178 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
181 /* Make sure that the hardware responded */
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800184 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
185 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
190 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500191 ACPI_ERROR((AE_INFO,
192 "Could not enable %s event",
193 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400194 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Bob Moore83135242006-10-03 00:00:00 -0400200ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202/*******************************************************************************
203 *
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200204 * FUNCTION: acpi_clear_and_enable_gpe
205 *
206 * PARAMETERS: gpe_event_info - GPE to enable
207 *
208 * RETURN: Status
209 *
210 * DESCRIPTION: Clear the given GPE from stale events and enable it.
211 *
212 ******************************************************************************/
213static acpi_status
214acpi_clear_and_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
215{
216 acpi_status status;
217
218 /*
219 * We will only allow a GPE to be enabled if it has either an
220 * associated method (_Lxx/_Exx) or a handler. Otherwise, the
221 * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
222 * first time it fires.
223 */
224 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
225 return_ACPI_STATUS(AE_NO_HANDLER);
226 }
227
228 /* Clear the GPE (of stale events) */
229 status = acpi_hw_clear_gpe(gpe_event_info);
230 if (ACPI_FAILURE(status)) {
231 return_ACPI_STATUS(status);
232 }
233
234 /* Enable the requested GPE */
235 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
236
237 return_ACPI_STATUS(status);
238}
239
240/*******************************************************************************
241 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100242 * FUNCTION: acpi_set_gpe
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 *
Lin Ming0f849d22010-04-06 14:52:37 +0800244 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800246 * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 *
248 * RETURN: Status
249 *
Lin Ming0f849d22010-04-06 14:52:37 +0800250 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
251 * the reference count mechanism used in the acpi_enable_gpe and
252 * acpi_disable_gpe interfaces -- and should be used with care.
253 *
254 * Note: Typically used to disable a runtime GPE for short period of time,
255 * then re-enable it, without disturbing the existing reference counts. This
256 * is useful, for example, in the Embedded Controller (EC) driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 *
258 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100259acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Len Brown4be44fc2005-08-05 00:44:28 -0400261 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800262 acpi_status status;
263 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100265 ACPI_FUNCTION_TRACE(acpi_set_gpe);
266
267 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 /* Ensure that we have a valid GPE number */
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (!gpe_event_info) {
273 status = AE_BAD_PARAMETER;
274 goto unlock_and_exit;
275 }
276
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100277 /* Perform the action */
278
279 switch (action) {
280 case ACPI_GPE_ENABLE:
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200281 status = acpi_clear_and_enable_gpe(gpe_event_info);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100282 break;
283
284 case ACPI_GPE_DISABLE:
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200285 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100286 break;
287
288 default:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100289 status = AE_BAD_PARAMETER;
290 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293 unlock_and_exit:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100294 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400295 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100298ACPI_EXPORT_SYMBOL(acpi_set_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300/*******************************************************************************
301 *
302 * FUNCTION: acpi_enable_gpe
303 *
Lin Ming0f849d22010-04-06 14:52:37 +0800304 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800306 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
307 * or both
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 *
309 * RETURN: Status
310 *
Lin Ming0f849d22010-04-06 14:52:37 +0800311 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
312 * hardware-enabled (for runtime GPEs), or the GPE register mask
313 * is updated (for wake GPEs).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 *
315 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800316acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Len Brown4be44fc2005-08-05 00:44:28 -0400318 acpi_status status = AE_OK;
319 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800320 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Bob Mooreb229cf92006-04-21 17:15:00 -0400322 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Lin Ming0f849d22010-04-06 14:52:37 +0800324 /* Parameter validation */
325
326 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100327 return_ACPI_STATUS(AE_BAD_PARAMETER);
Lin Ming0f849d22010-04-06 14:52:37 +0800328 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100329
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400330 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 /* Ensure that we have a valid GPE number */
333
Len Brown4be44fc2005-08-05 00:44:28 -0400334 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (!gpe_event_info) {
336 status = AE_BAD_PARAMETER;
337 goto unlock_and_exit;
338 }
339
Lin Ming0f849d22010-04-06 14:52:37 +0800340 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
341 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
342 status = AE_LIMIT; /* Too many references */
343 goto unlock_and_exit;
344 }
345
346 gpe_event_info->runtime_count++;
347 if (gpe_event_info->runtime_count == 1) {
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200348 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
349 if (ACPI_SUCCESS(status)) {
350 status = acpi_clear_and_enable_gpe(gpe_event_info);
351 }
352
Lin Ming0f849d22010-04-06 14:52:37 +0800353 if (ACPI_FAILURE(status)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100354 gpe_event_info->runtime_count--;
Lin Ming0f849d22010-04-06 14:52:37 +0800355 goto unlock_and_exit;
356 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100357 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Lin Ming0f849d22010-04-06 14:52:37 +0800360 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
361 /* The GPE must have the ability to wake the system */
362
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100363 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
Lin Ming0f849d22010-04-06 14:52:37 +0800364 status = AE_TYPE;
365 goto unlock_and_exit;
366 }
367
368 if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
369 status = AE_LIMIT; /* Too many references */
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100370 goto unlock_and_exit;
371 }
372
373 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800374 * Update the enable mask on the first wakeup reference. Wake GPEs
375 * are only hardware-enabled just before sleeping.
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100376 */
Lin Ming0f849d22010-04-06 14:52:37 +0800377 gpe_event_info->wakeup_count++;
378 if (gpe_event_info->wakeup_count == 1) {
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200379 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800380 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100381 }
382
383unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400384 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400385 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
Bob Moore83135242006-10-03 00:00:00 -0400387ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389/*******************************************************************************
390 *
391 * FUNCTION: acpi_disable_gpe
392 *
Lin Ming0f849d22010-04-06 14:52:37 +0800393 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 * gpe_number - GPE level within the GPE block
Lin Ming0f849d22010-04-06 14:52:37 +0800395 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
396 * or both
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 *
398 * RETURN: Status
399 *
Lin Ming0f849d22010-04-06 14:52:37 +0800400 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
401 * removed, only then is the GPE disabled (for runtime GPEs), or
402 * the GPE mask bit disabled (for wake GPEs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 *
404 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800405acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Len Brown4be44fc2005-08-05 00:44:28 -0400407 acpi_status status = AE_OK;
408 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800409 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Bob Mooreb229cf92006-04-21 17:15:00 -0400411 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Lin Ming0f849d22010-04-06 14:52:37 +0800413 /* Parameter validation */
414
415 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100416 return_ACPI_STATUS(AE_BAD_PARAMETER);
Lin Ming0f849d22010-04-06 14:52:37 +0800417 }
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100418
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400419 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Lin Ming0f849d22010-04-06 14:52:37 +0800420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /* Ensure that we have a valid GPE number */
422
Len Brown4be44fc2005-08-05 00:44:28 -0400423 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 if (!gpe_event_info) {
425 status = AE_BAD_PARAMETER;
426 goto unlock_and_exit;
427 }
428
Lin Ming0f849d22010-04-06 14:52:37 +0800429 /* Hardware-disable a runtime GPE on removal of the last reference */
430
431 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
432 if (!gpe_event_info->runtime_count) {
433 status = AE_LIMIT; /* There are no references to remove */
434 goto unlock_and_exit;
435 }
436
437 gpe_event_info->runtime_count--;
438 if (!gpe_event_info->runtime_count) {
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200439 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
440 if (ACPI_SUCCESS(status)) {
441 status = acpi_hw_low_set_gpe(gpe_event_info,
442 ACPI_GPE_DISABLE);
443 }
444
Lin Ming0f849d22010-04-06 14:52:37 +0800445 if (ACPI_FAILURE(status)) {
446 gpe_event_info->runtime_count++;
447 goto unlock_and_exit;
448 }
449 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100450 }
451
Lin Ming0f849d22010-04-06 14:52:37 +0800452 /*
453 * Update masks for wake GPE on removal of the last reference.
454 * No need to hardware-disable wake GPEs here, they are not currently
455 * enabled.
456 */
457 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
458 if (!gpe_event_info->wakeup_count) {
459 status = AE_LIMIT; /* There are no references to remove */
460 goto unlock_and_exit;
461 }
462
463 gpe_event_info->wakeup_count--;
464 if (!gpe_event_info->wakeup_count) {
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200465 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800466 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400469unlock_and_exit:
470 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400471 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
Bob Moore83135242006-10-03 00:00:00 -0400473ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475/*******************************************************************************
476 *
477 * FUNCTION: acpi_disable_event
478 *
479 * PARAMETERS: Event - The fixed eventto be enabled
480 * Flags - Reserved
481 *
482 * RETURN: Status
483 *
484 * DESCRIPTION: Disable an ACPI event (fixed)
485 *
486 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400487acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
Len Brown4be44fc2005-08-05 00:44:28 -0400489 acpi_status status = AE_OK;
490 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Bob Mooreb229cf92006-04-21 17:15:00 -0400492 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 /* Decode the Fixed Event */
495
496 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400497 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499
500 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800501 * Disable the requested fixed event (by writing a zero to the enable
502 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 */
Len Brown4be44fc2005-08-05 00:44:28 -0400504 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800505 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800506 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400507 if (ACPI_FAILURE(status)) {
508 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
510
Len Brown4be44fc2005-08-05 00:44:28 -0400511 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800512 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
513 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400514 if (ACPI_FAILURE(status)) {
515 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517
518 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500519 ACPI_ERROR((AE_INFO,
520 "Could not disable %s events",
521 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400522 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524
Len Brown4be44fc2005-08-05 00:44:28 -0400525 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Bob Moore83135242006-10-03 00:00:00 -0400528ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530/*******************************************************************************
531 *
532 * FUNCTION: acpi_clear_event
533 *
534 * PARAMETERS: Event - The fixed event to be cleared
535 *
536 * RETURN: Status
537 *
538 * DESCRIPTION: Clear an ACPI event (fixed)
539 *
540 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400541acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Len Brown4be44fc2005-08-05 00:44:28 -0400543 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Bob Mooreb229cf92006-04-21 17:15:00 -0400545 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 /* Decode the Fixed Event */
548
549 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400550 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
552
553 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800554 * Clear the requested fixed event (By writing a one to the status
555 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 */
Len Brown4be44fc2005-08-05 00:44:28 -0400557 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800558 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800559 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Bob Moore83135242006-10-03 00:00:00 -0400564ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566/*******************************************************************************
567 *
568 * FUNCTION: acpi_clear_gpe
569 *
Lin Ming0f849d22010-04-06 14:52:37 +0800570 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * gpe_number - GPE level within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 *
573 * RETURN: Status
574 *
575 * DESCRIPTION: Clear an ACPI event (general purpose)
576 *
577 ******************************************************************************/
Lin Ming0f849d22010-04-06 14:52:37 +0800578acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Len Brown4be44fc2005-08-05 00:44:28 -0400580 acpi_status status = AE_OK;
581 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800582 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Bob Mooreb229cf92006-04-21 17:15:00 -0400584 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Lin Ming0f849d22010-04-06 14:52:37 +0800586 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 /* Ensure that we have a valid GPE number */
589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 if (!gpe_event_info) {
592 status = AE_BAD_PARAMETER;
593 goto unlock_and_exit;
594 }
595
Len Brown4be44fc2005-08-05 00:44:28 -0400596 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Len Brown4be44fc2005-08-05 00:44:28 -0400598 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800599 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400600 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
Bob Moore83135242006-10-03 00:00:00 -0400603ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604/*******************************************************************************
605 *
606 * FUNCTION: acpi_get_event_status
607 *
608 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400609 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 * be returned
611 *
612 * RETURN: Status
613 *
614 * DESCRIPTION: Obtains and returns the current status of the event
615 *
616 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400617acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
Len Brown4be44fc2005-08-05 00:44:28 -0400619 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800620 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Bob Mooreb229cf92006-04-21 17:15:00 -0400622 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400625 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 }
627
628 /* Decode the Fixed Event */
629
630 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400631 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633
634 /* Get the status of the requested fixed event */
635
Len Brown4be44fc2005-08-05 00:44:28 -0400636 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800637 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800638 enable_register_id, &value);
639 if (ACPI_FAILURE(status))
640 return_ACPI_STATUS(status);
641
642 *event_status = value;
643
644 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800645 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800646 status_register_id, &value);
647 if (ACPI_FAILURE(status))
648 return_ACPI_STATUS(status);
649
650 if (value)
651 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Zhang Ruied206fa2008-10-27 14:01:02 -0700653 if (acpi_gbl_fixed_event_handlers[event].handler)
654 *event_status |= ACPI_EVENT_FLAG_HANDLE;
655
Len Brown4be44fc2005-08-05 00:44:28 -0400656 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Bob Moore83135242006-10-03 00:00:00 -0400659ACPI_EXPORT_SYMBOL(acpi_get_event_status)
660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661/*******************************************************************************
662 *
663 * FUNCTION: acpi_get_gpe_status
664 *
Lin Ming0f849d22010-04-06 14:52:37 +0800665 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 * gpe_number - GPE level within the GPE block
Robert Moore44f6c012005-04-18 22:49:35 -0400667 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 * be returned
669 *
670 * RETURN: Status
671 *
672 * DESCRIPTION: Get status of an event (general purpose)
673 *
674 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400676acpi_get_gpe_status(acpi_handle gpe_device,
Lin Ming0f849d22010-04-06 14:52:37 +0800677 u32 gpe_number, acpi_event_status *event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Len Brown4be44fc2005-08-05 00:44:28 -0400679 acpi_status status = AE_OK;
680 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming0f849d22010-04-06 14:52:37 +0800681 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Bob Mooreb229cf92006-04-21 17:15:00 -0400683 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Lin Ming0f849d22010-04-06 14:52:37 +0800685 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 /* Ensure that we have a valid GPE number */
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 if (!gpe_event_info) {
691 status = AE_BAD_PARAMETER;
692 goto unlock_and_exit;
693 }
694
695 /* Obtain status on the requested GPE number */
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Zhang Ruied206fa2008-10-27 14:01:02 -0700699 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
700 *event_status |= ACPI_EVENT_FLAG_HANDLE;
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 unlock_and_exit:
Lin Ming0f849d22010-04-06 14:52:37 +0800703 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400704 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
Bob Moore83135242006-10-03 00:00:00 -0400706
707ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708/*******************************************************************************
709 *
710 * FUNCTION: acpi_install_gpe_block
711 *
712 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
713 * gpe_block_address - Address and space_iD
714 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400715 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 *
717 * RETURN: Status
718 *
719 * DESCRIPTION: Create and Install a block of GPE registers
720 *
721 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400723acpi_install_gpe_block(acpi_handle gpe_device,
724 struct acpi_generic_address *gpe_block_address,
725 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Len Brown4be44fc2005-08-05 00:44:28 -0400727 acpi_status status;
728 union acpi_operand_object *obj_desc;
729 struct acpi_namespace_node *node;
730 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Bob Mooreb229cf92006-04-21 17:15:00 -0400732 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Len Brown4be44fc2005-08-05 00:44:28 -0400734 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
735 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737
Len Brown4be44fc2005-08-05 00:44:28 -0400738 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
739 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return (status);
741 }
742
Bob Mooref24b6642009-12-11 14:57:00 +0800743 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 if (!node) {
745 status = AE_BAD_PARAMETER;
746 goto unlock_and_exit;
747 }
748
749 /*
750 * For user-installed GPE Block Devices, the gpe_block_base_number
751 * is always zero
752 */
Len Brown4be44fc2005-08-05 00:44:28 -0400753 status =
754 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
755 interrupt_number, &gpe_block);
756 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 goto unlock_and_exit;
758 }
759
Lin Ming0f849d22010-04-06 14:52:37 +0800760 /* Install block in the device_object attached to the node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Len Brown4be44fc2005-08-05 00:44:28 -0400762 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400764
Lin Ming0f849d22010-04-06 14:52:37 +0800765 /*
766 * No object, create a new one (Device nodes do not always have
767 * an attached object)
768 */
Len Brown4be44fc2005-08-05 00:44:28 -0400769 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 if (!obj_desc) {
771 status = AE_NO_MEMORY;
772 goto unlock_and_exit;
773 }
774
Len Brown4be44fc2005-08-05 00:44:28 -0400775 status =
776 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 /* Remove local reference to the object */
779
Len Brown4be44fc2005-08-05 00:44:28 -0400780 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Len Brown4be44fc2005-08-05 00:44:28 -0400782 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 goto unlock_and_exit;
784 }
785 }
786
Lin Ming0f849d22010-04-06 14:52:37 +0800787 /* Now install the GPE block in the device_object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 obj_desc->device.gpe_block = gpe_block;
790
Lin Ming0f849d22010-04-06 14:52:37 +0800791 /* Run the _PRW methods and enable the runtime GPEs in the new block */
792
793 status = acpi_ev_initialize_gpe_block(node, gpe_block);
794
Len Brown4be44fc2005-08-05 00:44:28 -0400795 unlock_and_exit:
796 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
797 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Bob Moore83135242006-10-03 00:00:00 -0400800ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802/*******************************************************************************
803 *
804 * FUNCTION: acpi_remove_gpe_block
805 *
806 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
807 *
808 * RETURN: Status
809 *
810 * DESCRIPTION: Remove a previously installed block of GPE registers
811 *
812 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400813acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Len Brown4be44fc2005-08-05 00:44:28 -0400815 union acpi_operand_object *obj_desc;
816 acpi_status status;
817 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Bob Mooreb229cf92006-04-21 17:15:00 -0400819 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400822 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
824
Len Brown4be44fc2005-08-05 00:44:28 -0400825 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
826 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return (status);
828 }
829
Bob Mooref24b6642009-12-11 14:57:00 +0800830 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 if (!node) {
832 status = AE_BAD_PARAMETER;
833 goto unlock_and_exit;
834 }
835
836 /* Get the device_object attached to the node */
837
Len Brown4be44fc2005-08-05 00:44:28 -0400838 obj_desc = acpi_ns_get_attached_object(node);
839 if (!obj_desc || !obj_desc->device.gpe_block) {
840 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 }
842
843 /* Delete the GPE block (but not the device_object) */
844
Len Brown4be44fc2005-08-05 00:44:28 -0400845 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
846 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 obj_desc->device.gpe_block = NULL;
848 }
849
Len Brown4be44fc2005-08-05 00:44:28 -0400850 unlock_and_exit:
851 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
852 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
Robert Moore44f6c012005-04-18 22:49:35 -0400854
Bob Moore83135242006-10-03 00:00:00 -0400855ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
Bob Mooree97d6bf2008-12-30 09:45:17 +0800856
857/*******************************************************************************
858 *
859 * FUNCTION: acpi_get_gpe_device
860 *
861 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
862 * gpe_device - Where the parent GPE Device is returned
863 *
864 * RETURN: Status
865 *
866 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
867 * gpe device indicates that the gpe number is contained in one of
868 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
869 *
870 ******************************************************************************/
871acpi_status
872acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
873{
874 struct acpi_gpe_device_info info;
875 acpi_status status;
876
877 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
878
879 if (!gpe_device) {
880 return_ACPI_STATUS(AE_BAD_PARAMETER);
881 }
882
883 if (index >= acpi_current_gpe_count) {
884 return_ACPI_STATUS(AE_NOT_EXIST);
885 }
886
887 /* Setup and walk the GPE list */
888
889 info.index = index;
890 info.status = AE_NOT_EXIST;
891 info.gpe_device = NULL;
892 info.next_block_base_index = 0;
893
894 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
895 if (ACPI_FAILURE(status)) {
896 return_ACPI_STATUS(status);
897 }
898
899 *gpe_device = info.gpe_device;
900 return_ACPI_STATUS(info.status);
901}
902
903ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
904
905/*******************************************************************************
906 *
907 * FUNCTION: acpi_ev_get_gpe_device
908 *
909 * PARAMETERS: GPE_WALK_CALLBACK
910 *
911 * RETURN: Status
912 *
913 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
914 * block device. NULL if the GPE is one of the FADT-defined GPEs.
915 *
916 ******************************************************************************/
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800917static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800918acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
919 struct acpi_gpe_block_info *gpe_block, void *context)
920{
921 struct acpi_gpe_device_info *info = context;
922
923 /* Increment Index by the number of GPEs in this block */
924
Lin Ming0f849d22010-04-06 14:52:37 +0800925 info->next_block_base_index += gpe_block->gpe_count;
Bob Mooree97d6bf2008-12-30 09:45:17 +0800926
927 if (info->index < info->next_block_base_index) {
928 /*
929 * The GPE index is within this block, get the node. Leave the node
930 * NULL for the FADT-defined GPEs
931 */
932 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
933 info->gpe_device = gpe_block->node;
934 }
935
936 info->status = AE_OK;
937 return (AE_CTRL_END);
938 }
939
940 return (AE_OK);
941}
Bob Moore08ac07b2008-12-30 09:55:48 +0800942
943/******************************************************************************
944 *
945 * FUNCTION: acpi_disable_all_gpes
946 *
947 * PARAMETERS: None
948 *
949 * RETURN: Status
950 *
951 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
952 *
953 ******************************************************************************/
954
955acpi_status acpi_disable_all_gpes(void)
956{
957 acpi_status status;
958
959 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
960
961 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
962 if (ACPI_FAILURE(status)) {
963 return_ACPI_STATUS(status);
964 }
965
966 status = acpi_hw_disable_all_gpes();
967 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
968
969 return_ACPI_STATUS(status);
970}
971
972/******************************************************************************
973 *
974 * FUNCTION: acpi_enable_all_runtime_gpes
975 *
976 * PARAMETERS: None
977 *
978 * RETURN: Status
979 *
980 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
981 *
982 ******************************************************************************/
983
984acpi_status acpi_enable_all_runtime_gpes(void)
985{
986 acpi_status status;
987
988 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
989
990 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
991 if (ACPI_FAILURE(status)) {
992 return_ACPI_STATUS(status);
993 }
994
995 status = acpi_hw_enable_all_runtime_gpes();
996 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
997
998 return_ACPI_STATUS(status);
999}