blob: 5ff32c78ea2db417ba2e303fbb9b401454701508 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
48#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Bob Mooree97d6bf2008-12-30 09:45:17 +080053/* Local prototypes */
Bob Mooree4c1ebf2009-04-22 13:02:06 +080054static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +080055acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
56 struct acpi_gpe_block_info *gpe_block, void *context);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*******************************************************************************
59 *
60 * FUNCTION: acpi_enable
61 *
62 * PARAMETERS: None
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Transfers the system into ACPI mode.
67 *
68 ******************************************************************************/
Bob Mooree97d6bf2008-12-30 09:45:17 +080069
Len Brown4be44fc2005-08-05 00:44:28 -040070acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Len Brown4be44fc2005-08-05 00:44:28 -040072 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bob Mooreb229cf92006-04-21 17:15:00 -040074 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bob Moorec8573032007-02-02 19:48:23 +030076 /* ACPI tables must be present */
77
78 if (!acpi_tb_tables_loaded()) {
79 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
80 }
81
82 /* Check current mode */
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040085 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
86 "System is already in ACPI mode\n"));
87 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* Transition to ACPI mode */
89
Len Brown4be44fc2005-08-05 00:44:28 -040090 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
91 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050092 ACPI_ERROR((AE_INFO,
93 "Could not transition to ACPI mode"));
Len Brown4be44fc2005-08-05 00:44:28 -040094 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
Len Brown4be44fc2005-08-05 00:44:28 -040097 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
98 "Transition to ACPI mode successful\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
100
Len Brown4be44fc2005-08-05 00:44:28 -0400101 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Bob Moore83135242006-10-03 00:00:00 -0400104ACPI_EXPORT_SYMBOL(acpi_enable)
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/*******************************************************************************
107 *
108 * FUNCTION: acpi_disable
109 *
110 * PARAMETERS: None
111 *
112 * RETURN: Status
113 *
Robert Moore44f6c012005-04-18 22:49:35 -0400114 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400117acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Len Brown4be44fc2005-08-05 00:44:28 -0400119 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Bob Mooreb229cf92006-04-21 17:15:00 -0400121 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400124 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
125 "System is already in legacy (non-ACPI) mode\n"));
126 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /* Transition to LEGACY mode */
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Len Brown4be44fc2005-08-05 00:44:28 -0400131 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500132 ACPI_ERROR((AE_INFO,
133 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400134 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139
Len Brown4be44fc2005-08-05 00:44:28 -0400140 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Bob Moore83135242006-10-03 00:00:00 -0400143ACPI_EXPORT_SYMBOL(acpi_disable)
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*******************************************************************************
146 *
147 * FUNCTION: acpi_enable_event
148 *
149 * PARAMETERS: Event - The fixed eventto be enabled
150 * Flags - Reserved
151 *
152 * RETURN: Status
153 *
154 * DESCRIPTION: Enable an ACPI event (fixed)
155 *
156 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400157acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Len Brown4be44fc2005-08-05 00:44:28 -0400159 acpi_status status = AE_OK;
160 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Bob Mooreb229cf92006-04-21 17:15:00 -0400162 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 /* Decode the Fixed Event */
165
166 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400167 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169
170 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800171 * Enable the requested fixed event (by writing a one to the enable
172 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 */
Len Brown4be44fc2005-08-05 00:44:28 -0400174 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800175 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800176 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400177 if (ACPI_FAILURE(status)) {
178 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
181 /* Make sure that the hardware responded */
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800184 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
185 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
190 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500191 ACPI_ERROR((AE_INFO,
192 "Could not enable %s event",
193 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400194 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Bob Moore83135242006-10-03 00:00:00 -0400200ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202/*******************************************************************************
203 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100204 * FUNCTION: acpi_set_gpe
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 *
206 * PARAMETERS: gpe_device - Parent GPE Device
207 * gpe_number - GPE level within the GPE block
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100208 * action - Enable or disable
209 * Called from ISR or not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 *
211 * RETURN: Status
212 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100213 * DESCRIPTION: Enable or disable an ACPI event (general purpose)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 *
215 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100216acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Len Brown4be44fc2005-08-05 00:44:28 -0400218 acpi_status status = AE_OK;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100219 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400220 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100222 ACPI_FUNCTION_TRACE(acpi_set_gpe);
223
224 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 /* Ensure that we have a valid GPE number */
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (!gpe_event_info) {
230 status = AE_BAD_PARAMETER;
231 goto unlock_and_exit;
232 }
233
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100234 /* Perform the action */
235
236 switch (action) {
237 case ACPI_GPE_ENABLE:
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100238 status = acpi_ev_enable_gpe(gpe_event_info);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100239 break;
240
241 case ACPI_GPE_DISABLE:
242 status = acpi_ev_disable_gpe(gpe_event_info);
243 break;
244
245 default:
246 ACPI_ERROR((AE_INFO, "Invalid action\n"));
247 status = AE_BAD_PARAMETER;
248 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251 unlock_and_exit:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100252 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400253 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100256ACPI_EXPORT_SYMBOL(acpi_set_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258/*******************************************************************************
259 *
260 * FUNCTION: acpi_enable_gpe
261 *
262 * PARAMETERS: gpe_device - Parent GPE Device
263 * gpe_number - GPE level within the GPE block
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100264 * type - Purpose the GPE will be used for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 *
266 * RETURN: Status
267 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100268 * DESCRIPTION: Take a reference to a GPE and enable it if necessary
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 *
270 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100271acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Len Brown4be44fc2005-08-05 00:44:28 -0400273 acpi_status status = AE_OK;
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400274 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400275 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Bob Mooreb229cf92006-04-21 17:15:00 -0400277 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100279 if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
280 return_ACPI_STATUS(AE_BAD_PARAMETER);
281
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400282 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 /* Ensure that we have a valid GPE number */
285
Len Brown4be44fc2005-08-05 00:44:28 -0400286 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (!gpe_event_info) {
288 status = AE_BAD_PARAMETER;
289 goto unlock_and_exit;
290 }
291
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100292 if (type & ACPI_GPE_TYPE_RUNTIME) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100293 if (++gpe_event_info->runtime_count == 1) {
294 status = acpi_ev_enable_gpe(gpe_event_info);
295 if (ACPI_FAILURE(status))
296 gpe_event_info->runtime_count--;
297 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100300 if (type & ACPI_GPE_TYPE_WAKE) {
301 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
302 status = AE_BAD_PARAMETER;
303 goto unlock_and_exit;
304 }
305
306 /*
307 * Wake-up GPEs are only enabled right prior to putting the
308 * system into a sleep state.
309 */
310 if (++gpe_event_info->wakeup_count == 1)
311 acpi_ev_update_gpe_enable_masks(gpe_event_info);
312 }
313
314unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400315 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400316 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
Bob Moore83135242006-10-03 00:00:00 -0400318ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320/*******************************************************************************
321 *
322 * FUNCTION: acpi_disable_gpe
323 *
324 * PARAMETERS: gpe_device - Parent GPE Device
325 * gpe_number - GPE level within the GPE block
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100326 * type - Purpose the GPE won't be used for any more
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 *
328 * RETURN: Status
329 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100330 * DESCRIPTION: Release a reference to a GPE and disable it if necessary
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 *
332 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100333acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Len Brown4be44fc2005-08-05 00:44:28 -0400335 acpi_status status = AE_OK;
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400336 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400337 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Bob Mooreb229cf92006-04-21 17:15:00 -0400339 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100341 if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
342 return_ACPI_STATUS(AE_BAD_PARAMETER);
343
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400344 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 /* Ensure that we have a valid GPE number */
346
Len Brown4be44fc2005-08-05 00:44:28 -0400347 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (!gpe_event_info) {
349 status = AE_BAD_PARAMETER;
350 goto unlock_and_exit;
351 }
352
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100353 if ((type & ACPI_GPE_TYPE_RUNTIME) && gpe_event_info->runtime_count) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100354 if (--gpe_event_info->runtime_count == 0)
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100355 status = acpi_ev_disable_gpe(gpe_event_info);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100356 }
357
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100358 if ((type & ACPI_GPE_TYPE_WAKE) && gpe_event_info->wakeup_count) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100359 /*
360 * Wake-up GPEs are not enabled after leaving system sleep
361 * states, so we don't need to disable them here.
362 */
363 if (--gpe_event_info->wakeup_count == 0)
364 acpi_ev_update_gpe_enable_masks(gpe_event_info);
365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400367unlock_and_exit:
368 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400369 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
Bob Moore83135242006-10-03 00:00:00 -0400371ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373/*******************************************************************************
374 *
375 * FUNCTION: acpi_disable_event
376 *
377 * PARAMETERS: Event - The fixed eventto be enabled
378 * Flags - Reserved
379 *
380 * RETURN: Status
381 *
382 * DESCRIPTION: Disable an ACPI event (fixed)
383 *
384 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400385acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Len Brown4be44fc2005-08-05 00:44:28 -0400387 acpi_status status = AE_OK;
388 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Bob Mooreb229cf92006-04-21 17:15:00 -0400390 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* Decode the Fixed Event */
393
394 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400395 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
397
398 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800399 * Disable the requested fixed event (by writing a zero to the enable
400 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 */
Len Brown4be44fc2005-08-05 00:44:28 -0400402 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800403 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800404 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400405 if (ACPI_FAILURE(status)) {
406 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
408
Len Brown4be44fc2005-08-05 00:44:28 -0400409 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800410 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
411 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400412 if (ACPI_FAILURE(status)) {
413 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
415
416 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500417 ACPI_ERROR((AE_INFO,
418 "Could not disable %s events",
419 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400420 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
422
Len Brown4be44fc2005-08-05 00:44:28 -0400423 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Bob Moore83135242006-10-03 00:00:00 -0400426ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428/*******************************************************************************
429 *
430 * FUNCTION: acpi_clear_event
431 *
432 * PARAMETERS: Event - The fixed event to be cleared
433 *
434 * RETURN: Status
435 *
436 * DESCRIPTION: Clear an ACPI event (fixed)
437 *
438 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400439acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Len Brown4be44fc2005-08-05 00:44:28 -0400441 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Bob Mooreb229cf92006-04-21 17:15:00 -0400443 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 /* Decode the Fixed Event */
446
447 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400448 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450
451 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800452 * Clear the requested fixed event (By writing a one to the status
453 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 */
Len Brown4be44fc2005-08-05 00:44:28 -0400455 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800456 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800457 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Len Brown4be44fc2005-08-05 00:44:28 -0400459 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Bob Moore83135242006-10-03 00:00:00 -0400462ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464/*******************************************************************************
465 *
466 * FUNCTION: acpi_clear_gpe
467 *
468 * PARAMETERS: gpe_device - Parent GPE Device
469 * gpe_number - GPE level within the GPE block
470 * Flags - Called from an ISR or not
471 *
472 * RETURN: Status
473 *
474 * DESCRIPTION: Clear an ACPI event (general purpose)
475 *
476 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400477acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Len Brown4be44fc2005-08-05 00:44:28 -0400479 acpi_status status = AE_OK;
480 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Bob Mooreb229cf92006-04-21 17:15:00 -0400482 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 /* Use semaphore lock if not executing at interrupt level */
485
486 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400487 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
488 if (ACPI_FAILURE(status)) {
489 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 }
491 }
492
493 /* Ensure that we have a valid GPE number */
494
Len Brown4be44fc2005-08-05 00:44:28 -0400495 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (!gpe_event_info) {
497 status = AE_BAD_PARAMETER;
498 goto unlock_and_exit;
499 }
500
Len Brown4be44fc2005-08-05 00:44:28 -0400501 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Len Brown4be44fc2005-08-05 00:44:28 -0400503 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400505 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
Len Brown4be44fc2005-08-05 00:44:28 -0400507 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508}
509
Bob Moore83135242006-10-03 00:00:00 -0400510ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511/*******************************************************************************
512 *
513 * FUNCTION: acpi_get_event_status
514 *
515 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400516 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 * be returned
518 *
519 * RETURN: Status
520 *
521 * DESCRIPTION: Obtains and returns the current status of the event
522 *
523 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400524acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Len Brown4be44fc2005-08-05 00:44:28 -0400526 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800527 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Bob Mooreb229cf92006-04-21 17:15:00 -0400529 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400532 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
534
535 /* Decode the Fixed Event */
536
537 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400538 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
540
541 /* Get the status of the requested fixed event */
542
Len Brown4be44fc2005-08-05 00:44:28 -0400543 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800544 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800545 enable_register_id, &value);
546 if (ACPI_FAILURE(status))
547 return_ACPI_STATUS(status);
548
549 *event_status = value;
550
551 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800552 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800553 status_register_id, &value);
554 if (ACPI_FAILURE(status))
555 return_ACPI_STATUS(status);
556
557 if (value)
558 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Zhang Ruied206fa2008-10-27 14:01:02 -0700560 if (acpi_gbl_fixed_event_handlers[event].handler)
561 *event_status |= ACPI_EVENT_FLAG_HANDLE;
562
Len Brown4be44fc2005-08-05 00:44:28 -0400563 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
Bob Moore83135242006-10-03 00:00:00 -0400566ACPI_EXPORT_SYMBOL(acpi_get_event_status)
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568/*******************************************************************************
569 *
570 * FUNCTION: acpi_get_gpe_status
571 *
572 * PARAMETERS: gpe_device - Parent GPE Device
573 * gpe_number - GPE level within the GPE block
574 * Flags - Called from an ISR or not
Robert Moore44f6c012005-04-18 22:49:35 -0400575 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 * be returned
577 *
578 * RETURN: Status
579 *
580 * DESCRIPTION: Get status of an event (general purpose)
581 *
582 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400584acpi_get_gpe_status(acpi_handle gpe_device,
585 u32 gpe_number, u32 flags, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586{
Len Brown4be44fc2005-08-05 00:44:28 -0400587 acpi_status status = AE_OK;
588 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Bob Mooreb229cf92006-04-21 17:15:00 -0400590 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 /* Use semaphore lock if not executing at interrupt level */
593
594 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400595 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
596 if (ACPI_FAILURE(status)) {
597 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
599 }
600
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
609 /* Obtain status on the requested GPE number */
610
Len Brown4be44fc2005-08-05 00:44:28 -0400611 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Zhang Ruied206fa2008-10-27 14:01:02 -0700613 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
614 *event_status |= ACPI_EVENT_FLAG_HANDLE;
615
Len Brown4be44fc2005-08-05 00:44:28 -0400616 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400618 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
Len Brown4be44fc2005-08-05 00:44:28 -0400620 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
Bob Moore83135242006-10-03 00:00:00 -0400622
623ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624/*******************************************************************************
625 *
626 * FUNCTION: acpi_install_gpe_block
627 *
628 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
629 * gpe_block_address - Address and space_iD
630 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400631 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 *
633 * RETURN: Status
634 *
635 * DESCRIPTION: Create and Install a block of GPE registers
636 *
637 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400639acpi_install_gpe_block(acpi_handle gpe_device,
640 struct acpi_generic_address *gpe_block_address,
641 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
Len Brown4be44fc2005-08-05 00:44:28 -0400643 acpi_status status;
644 union acpi_operand_object *obj_desc;
645 struct acpi_namespace_node *node;
646 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Bob Mooreb229cf92006-04-21 17:15:00 -0400648 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Len Brown4be44fc2005-08-05 00:44:28 -0400650 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
651 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
Len Brown4be44fc2005-08-05 00:44:28 -0400654 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
655 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 return (status);
657 }
658
Bob Mooref24b6642009-12-11 14:57:00 +0800659 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (!node) {
661 status = AE_BAD_PARAMETER;
662 goto unlock_and_exit;
663 }
664
665 /*
666 * For user-installed GPE Block Devices, the gpe_block_base_number
667 * is always zero
668 */
Len Brown4be44fc2005-08-05 00:44:28 -0400669 status =
670 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
671 interrupt_number, &gpe_block);
672 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 goto unlock_and_exit;
674 }
675
Bob Moore96db2552005-11-02 00:00:00 -0500676 /* Run the _PRW methods and enable the GPEs */
677
678 status = acpi_ev_initialize_gpe_block(node, gpe_block);
679 if (ACPI_FAILURE(status)) {
680 goto unlock_and_exit;
681 }
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 /* Get the device_object attached to the node */
684
Len Brown4be44fc2005-08-05 00:44:28 -0400685 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 /* No object, create a new one */
689
Len Brown4be44fc2005-08-05 00:44:28 -0400690 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 if (!obj_desc) {
692 status = AE_NO_MEMORY;
693 goto unlock_and_exit;
694 }
695
Len Brown4be44fc2005-08-05 00:44:28 -0400696 status =
697 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 /* Remove local reference to the object */
700
Len Brown4be44fc2005-08-05 00:44:28 -0400701 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 goto unlock_and_exit;
705 }
706 }
707
708 /* Install the GPE block in the device_object */
709
710 obj_desc->device.gpe_block = gpe_block;
711
Len Brown4be44fc2005-08-05 00:44:28 -0400712 unlock_and_exit:
713 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
714 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Bob Moore83135242006-10-03 00:00:00 -0400717ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719/*******************************************************************************
720 *
721 * FUNCTION: acpi_remove_gpe_block
722 *
723 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
724 *
725 * RETURN: Status
726 *
727 * DESCRIPTION: Remove a previously installed block of GPE registers
728 *
729 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400730acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
Len Brown4be44fc2005-08-05 00:44:28 -0400732 union acpi_operand_object *obj_desc;
733 acpi_status status;
734 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Bob Mooreb229cf92006-04-21 17:15:00 -0400736 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400739 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741
Len Brown4be44fc2005-08-05 00:44:28 -0400742 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
743 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 return (status);
745 }
746
Bob Mooref24b6642009-12-11 14:57:00 +0800747 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 if (!node) {
749 status = AE_BAD_PARAMETER;
750 goto unlock_and_exit;
751 }
752
753 /* Get the device_object attached to the node */
754
Len Brown4be44fc2005-08-05 00:44:28 -0400755 obj_desc = acpi_ns_get_attached_object(node);
756 if (!obj_desc || !obj_desc->device.gpe_block) {
757 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759
760 /* Delete the GPE block (but not the device_object) */
761
Len Brown4be44fc2005-08-05 00:44:28 -0400762 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
763 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 obj_desc->device.gpe_block = NULL;
765 }
766
Len Brown4be44fc2005-08-05 00:44:28 -0400767 unlock_and_exit:
768 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
769 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
Robert Moore44f6c012005-04-18 22:49:35 -0400771
Bob Moore83135242006-10-03 00:00:00 -0400772ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
Bob Mooree97d6bf2008-12-30 09:45:17 +0800773
774/*******************************************************************************
775 *
776 * FUNCTION: acpi_get_gpe_device
777 *
778 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
779 * gpe_device - Where the parent GPE Device is returned
780 *
781 * RETURN: Status
782 *
783 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
784 * gpe device indicates that the gpe number is contained in one of
785 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
786 *
787 ******************************************************************************/
788acpi_status
789acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
790{
791 struct acpi_gpe_device_info info;
792 acpi_status status;
793
794 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
795
796 if (!gpe_device) {
797 return_ACPI_STATUS(AE_BAD_PARAMETER);
798 }
799
800 if (index >= acpi_current_gpe_count) {
801 return_ACPI_STATUS(AE_NOT_EXIST);
802 }
803
804 /* Setup and walk the GPE list */
805
806 info.index = index;
807 info.status = AE_NOT_EXIST;
808 info.gpe_device = NULL;
809 info.next_block_base_index = 0;
810
811 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
812 if (ACPI_FAILURE(status)) {
813 return_ACPI_STATUS(status);
814 }
815
816 *gpe_device = info.gpe_device;
817 return_ACPI_STATUS(info.status);
818}
819
820ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
821
822/*******************************************************************************
823 *
824 * FUNCTION: acpi_ev_get_gpe_device
825 *
826 * PARAMETERS: GPE_WALK_CALLBACK
827 *
828 * RETURN: Status
829 *
830 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
831 * block device. NULL if the GPE is one of the FADT-defined GPEs.
832 *
833 ******************************************************************************/
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800834static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800835acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
836 struct acpi_gpe_block_info *gpe_block, void *context)
837{
838 struct acpi_gpe_device_info *info = context;
839
840 /* Increment Index by the number of GPEs in this block */
841
842 info->next_block_base_index +=
843 (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
844
845 if (info->index < info->next_block_base_index) {
846 /*
847 * The GPE index is within this block, get the node. Leave the node
848 * NULL for the FADT-defined GPEs
849 */
850 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
851 info->gpe_device = gpe_block->node;
852 }
853
854 info->status = AE_OK;
855 return (AE_CTRL_END);
856 }
857
858 return (AE_OK);
859}
Bob Moore08ac07b2008-12-30 09:55:48 +0800860
861/******************************************************************************
862 *
863 * FUNCTION: acpi_disable_all_gpes
864 *
865 * PARAMETERS: None
866 *
867 * RETURN: Status
868 *
869 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
870 *
871 ******************************************************************************/
872
873acpi_status acpi_disable_all_gpes(void)
874{
875 acpi_status status;
876
877 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
878
879 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
880 if (ACPI_FAILURE(status)) {
881 return_ACPI_STATUS(status);
882 }
883
884 status = acpi_hw_disable_all_gpes();
885 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
886
887 return_ACPI_STATUS(status);
888}
889
890/******************************************************************************
891 *
892 * FUNCTION: acpi_enable_all_runtime_gpes
893 *
894 * PARAMETERS: None
895 *
896 * RETURN: Status
897 *
898 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
899 *
900 ******************************************************************************/
901
902acpi_status acpi_enable_all_runtime_gpes(void)
903{
904 acpi_status status;
905
906 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
907
908 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
909 if (ACPI_FAILURE(status)) {
910 return_ACPI_STATUS(status);
911 }
912
913 status = acpi_hw_enable_all_runtime_gpes();
914 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
915
916 return_ACPI_STATUS(status);
917}