blob: bfbe291d572e82402a6522f78a04a095dba4f2c8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
48#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Bob Mooree97d6bf2008-12-30 09:45:17 +080053/* Local prototypes */
Bob Mooree4c1ebf2009-04-22 13:02:06 +080054static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +080055acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
56 struct acpi_gpe_block_info *gpe_block, void *context);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*******************************************************************************
59 *
60 * FUNCTION: acpi_enable
61 *
62 * PARAMETERS: None
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Transfers the system into ACPI mode.
67 *
68 ******************************************************************************/
Bob Mooree97d6bf2008-12-30 09:45:17 +080069
Len Brown4be44fc2005-08-05 00:44:28 -040070acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Len Brownb430acb2010-05-06 17:41:08 -040072 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bob Mooreb229cf92006-04-21 17:15:00 -040074 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bob Moorec8573032007-02-02 19:48:23 +030076 /* ACPI tables must be present */
77
78 if (!acpi_tb_tables_loaded()) {
79 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
80 }
81
82 /* Check current mode */
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040085 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
86 "System is already in ACPI mode\n"));
Len Brownb430acb2010-05-06 17:41:08 -040087 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
Len Brownb430acb2010-05-06 17:41:08 -040090 /* Transition to ACPI mode */
91
92 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
93 if (ACPI_FAILURE(status)) {
94 ACPI_ERROR((AE_INFO,
95 "Could not transition to ACPI mode"));
96 return_ACPI_STATUS(status);
97 }
98
99 /* Sanity check that transition succeeded */
100
101 if (acpi_hw_get_mode() != ACPI_SYS_MODE_ACPI) {
102 ACPI_ERROR((AE_INFO,
103 "Hardware did not enter ACPI mode"));
104 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
105 }
106
107 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
108 "Transition to ACPI mode successful\n"));
109
110 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Bob Moore83135242006-10-03 00:00:00 -0400113ACPI_EXPORT_SYMBOL(acpi_enable)
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/*******************************************************************************
116 *
117 * FUNCTION: acpi_disable
118 *
119 * PARAMETERS: None
120 *
121 * RETURN: Status
122 *
Robert Moore44f6c012005-04-18 22:49:35 -0400123 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 *
125 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400126acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Len Brown4be44fc2005-08-05 00:44:28 -0400128 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Bob Mooreb229cf92006-04-21 17:15:00 -0400130 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400133 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
134 "System is already in legacy (non-ACPI) mode\n"));
135 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* Transition to LEGACY mode */
137
Len Brown4be44fc2005-08-05 00:44:28 -0400138 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Len Brown4be44fc2005-08-05 00:44:28 -0400140 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500141 ACPI_ERROR((AE_INFO,
142 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400143 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145
Len Brown4be44fc2005-08-05 00:44:28 -0400146 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Bob Moore83135242006-10-03 00:00:00 -0400152ACPI_EXPORT_SYMBOL(acpi_disable)
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154/*******************************************************************************
155 *
156 * FUNCTION: acpi_enable_event
157 *
158 * PARAMETERS: Event - The fixed eventto be enabled
159 * Flags - Reserved
160 *
161 * RETURN: Status
162 *
163 * DESCRIPTION: Enable an ACPI event (fixed)
164 *
165 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400166acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Len Brown4be44fc2005-08-05 00:44:28 -0400168 acpi_status status = AE_OK;
169 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Bob Mooreb229cf92006-04-21 17:15:00 -0400171 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* Decode the Fixed Event */
174
175 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400176 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178
179 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800180 * Enable the requested fixed event (by writing a one to the enable
181 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 */
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800184 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800185 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
190 /* Make sure that the hardware responded */
191
Len Brown4be44fc2005-08-05 00:44:28 -0400192 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800193 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
194 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400195 if (ACPI_FAILURE(status)) {
196 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198
199 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500200 ACPI_ERROR((AE_INFO,
201 "Could not enable %s event",
202 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400203 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
205
Len Brown4be44fc2005-08-05 00:44:28 -0400206 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Bob Moore83135242006-10-03 00:00:00 -0400209ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211/*******************************************************************************
212 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100213 * FUNCTION: acpi_set_gpe
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 *
215 * PARAMETERS: gpe_device - Parent GPE Device
216 * gpe_number - GPE level within the GPE block
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100217 * action - Enable or disable
218 * Called from ISR or not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 *
220 * RETURN: Status
221 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100222 * DESCRIPTION: Enable or disable an ACPI event (general purpose)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 *
224 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100225acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Len Brown4be44fc2005-08-05 00:44:28 -0400227 acpi_status status = AE_OK;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100228 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400229 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100231 ACPI_FUNCTION_TRACE(acpi_set_gpe);
232
233 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /* Ensure that we have a valid GPE number */
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (!gpe_event_info) {
239 status = AE_BAD_PARAMETER;
240 goto unlock_and_exit;
241 }
242
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100243 /* Perform the action */
244
245 switch (action) {
246 case ACPI_GPE_ENABLE:
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100247 status = acpi_ev_enable_gpe(gpe_event_info);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100248 break;
249
250 case ACPI_GPE_DISABLE:
251 status = acpi_ev_disable_gpe(gpe_event_info);
252 break;
253
254 default:
255 ACPI_ERROR((AE_INFO, "Invalid action\n"));
256 status = AE_BAD_PARAMETER;
257 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
259
Len Brown4be44fc2005-08-05 00:44:28 -0400260 unlock_and_exit:
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100261 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400262 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100265ACPI_EXPORT_SYMBOL(acpi_set_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267/*******************************************************************************
268 *
269 * FUNCTION: acpi_enable_gpe
270 *
271 * PARAMETERS: gpe_device - Parent GPE Device
272 * gpe_number - GPE level within the GPE block
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100273 * type - Purpose the GPE will be used for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 *
275 * RETURN: Status
276 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100277 * DESCRIPTION: Take a reference to a GPE and enable it if necessary
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 *
279 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100280acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Len Brown4be44fc2005-08-05 00:44:28 -0400282 acpi_status status = AE_OK;
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400283 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400284 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Bob Mooreb229cf92006-04-21 17:15:00 -0400286 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100288 if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
289 return_ACPI_STATUS(AE_BAD_PARAMETER);
290
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400291 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 /* Ensure that we have a valid GPE number */
294
Len Brown4be44fc2005-08-05 00:44:28 -0400295 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (!gpe_event_info) {
297 status = AE_BAD_PARAMETER;
298 goto unlock_and_exit;
299 }
300
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100301 if (type & ACPI_GPE_TYPE_RUNTIME) {
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100302 if (++gpe_event_info->runtime_count == 1) {
303 status = acpi_ev_enable_gpe(gpe_event_info);
304 if (ACPI_FAILURE(status))
305 gpe_event_info->runtime_count--;
306 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100309 if (type & ACPI_GPE_TYPE_WAKE) {
310 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
311 status = AE_BAD_PARAMETER;
312 goto unlock_and_exit;
313 }
314
315 /*
316 * Wake-up GPEs are only enabled right prior to putting the
317 * system into a sleep state.
318 */
319 if (++gpe_event_info->wakeup_count == 1)
320 acpi_ev_update_gpe_enable_masks(gpe_event_info);
321 }
322
323unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400324 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400325 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}
Bob Moore83135242006-10-03 00:00:00 -0400327ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329/*******************************************************************************
330 *
331 * FUNCTION: acpi_disable_gpe
332 *
333 * PARAMETERS: gpe_device - Parent GPE Device
334 * gpe_number - GPE level within the GPE block
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100335 * type - Purpose the GPE won't be used for any more
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 *
337 * RETURN: Status
338 *
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100339 * DESCRIPTION: Release a reference to a GPE and disable it if necessary
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 *
341 ******************************************************************************/
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100342acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Len Brown4be44fc2005-08-05 00:44:28 -0400344 acpi_status status = AE_OK;
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400345 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400346 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Bob Mooreb229cf92006-04-21 17:15:00 -0400348 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100350 if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
351 return_ACPI_STATUS(AE_BAD_PARAMETER);
352
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400353 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 /* Ensure that we have a valid GPE number */
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 if (!gpe_event_info) {
358 status = AE_BAD_PARAMETER;
359 goto unlock_and_exit;
360 }
361
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100362 if ((type & ACPI_GPE_TYPE_RUNTIME) && gpe_event_info->runtime_count) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100363 if (--gpe_event_info->runtime_count == 0)
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100364 status = acpi_ev_disable_gpe(gpe_event_info);
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100365 }
366
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100367 if ((type & ACPI_GPE_TYPE_WAKE) && gpe_event_info->wakeup_count) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100368 /*
369 * Wake-up GPEs are not enabled after leaving system sleep
370 * states, so we don't need to disable them here.
371 */
372 if (--gpe_event_info->wakeup_count == 0)
373 acpi_ev_update_gpe_enable_masks(gpe_event_info);
374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400376unlock_and_exit:
377 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400378 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
Bob Moore83135242006-10-03 00:00:00 -0400380ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382/*******************************************************************************
383 *
384 * FUNCTION: acpi_disable_event
385 *
386 * PARAMETERS: Event - The fixed eventto be enabled
387 * Flags - Reserved
388 *
389 * RETURN: Status
390 *
391 * DESCRIPTION: Disable an ACPI event (fixed)
392 *
393 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400394acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Len Brown4be44fc2005-08-05 00:44:28 -0400396 acpi_status status = AE_OK;
397 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Bob Mooreb229cf92006-04-21 17:15:00 -0400399 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 /* Decode the Fixed Event */
402
403 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400404 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 }
406
407 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800408 * Disable the requested fixed event (by writing a zero to the enable
409 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 */
Len Brown4be44fc2005-08-05 00:44:28 -0400411 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800412 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800413 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400414 if (ACPI_FAILURE(status)) {
415 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800419 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
420 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400421 if (ACPI_FAILURE(status)) {
422 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424
425 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500426 ACPI_ERROR((AE_INFO,
427 "Could not disable %s events",
428 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400429 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
431
Len Brown4be44fc2005-08-05 00:44:28 -0400432 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Bob Moore83135242006-10-03 00:00:00 -0400435ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437/*******************************************************************************
438 *
439 * FUNCTION: acpi_clear_event
440 *
441 * PARAMETERS: Event - The fixed event to be cleared
442 *
443 * RETURN: Status
444 *
445 * DESCRIPTION: Clear an ACPI event (fixed)
446 *
447 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400448acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Len Brown4be44fc2005-08-05 00:44:28 -0400450 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Bob Mooreb229cf92006-04-21 17:15:00 -0400452 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 /* Decode the Fixed Event */
455
456 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400457 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459
460 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800461 * Clear the requested fixed event (By writing a one to the status
462 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 */
Len Brown4be44fc2005-08-05 00:44:28 -0400464 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800465 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800466 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Len Brown4be44fc2005-08-05 00:44:28 -0400468 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Bob Moore83135242006-10-03 00:00:00 -0400471ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473/*******************************************************************************
474 *
475 * FUNCTION: acpi_clear_gpe
476 *
477 * PARAMETERS: gpe_device - Parent GPE Device
478 * gpe_number - GPE level within the GPE block
479 * Flags - Called from an ISR or not
480 *
481 * RETURN: Status
482 *
483 * DESCRIPTION: Clear an ACPI event (general purpose)
484 *
485 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400486acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
Len Brown4be44fc2005-08-05 00:44:28 -0400488 acpi_status status = AE_OK;
489 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Bob Mooreb229cf92006-04-21 17:15:00 -0400491 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 /* Use semaphore lock if not executing at interrupt level */
494
495 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400496 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
497 if (ACPI_FAILURE(status)) {
498 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500 }
501
502 /* Ensure that we have a valid GPE number */
503
Len Brown4be44fc2005-08-05 00:44:28 -0400504 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (!gpe_event_info) {
506 status = AE_BAD_PARAMETER;
507 goto unlock_and_exit;
508 }
509
Len Brown4be44fc2005-08-05 00:44:28 -0400510 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Len Brown4be44fc2005-08-05 00:44:28 -0400512 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400514 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
Len Brown4be44fc2005-08-05 00:44:28 -0400516 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
Bob Moore83135242006-10-03 00:00:00 -0400519ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520/*******************************************************************************
521 *
522 * FUNCTION: acpi_get_event_status
523 *
524 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400525 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 * be returned
527 *
528 * RETURN: Status
529 *
530 * DESCRIPTION: Obtains and returns the current status of the event
531 *
532 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400533acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
Len Brown4be44fc2005-08-05 00:44:28 -0400535 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800536 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Bob Mooreb229cf92006-04-21 17:15:00 -0400538 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400541 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543
544 /* Decode the Fixed Event */
545
546 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400547 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549
550 /* Get the status of the requested fixed event */
551
Len Brown4be44fc2005-08-05 00:44:28 -0400552 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800553 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800554 enable_register_id, &value);
555 if (ACPI_FAILURE(status))
556 return_ACPI_STATUS(status);
557
558 *event_status = value;
559
560 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800561 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800562 status_register_id, &value);
563 if (ACPI_FAILURE(status))
564 return_ACPI_STATUS(status);
565
566 if (value)
567 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Zhang Ruied206fa2008-10-27 14:01:02 -0700569 if (acpi_gbl_fixed_event_handlers[event].handler)
570 *event_status |= ACPI_EVENT_FLAG_HANDLE;
571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
574
Bob Moore83135242006-10-03 00:00:00 -0400575ACPI_EXPORT_SYMBOL(acpi_get_event_status)
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577/*******************************************************************************
578 *
579 * FUNCTION: acpi_get_gpe_status
580 *
581 * PARAMETERS: gpe_device - Parent GPE Device
582 * gpe_number - GPE level within the GPE block
583 * Flags - Called from an ISR or not
Robert Moore44f6c012005-04-18 22:49:35 -0400584 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 * be returned
586 *
587 * RETURN: Status
588 *
589 * DESCRIPTION: Get status of an event (general purpose)
590 *
591 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400593acpi_get_gpe_status(acpi_handle gpe_device,
594 u32 gpe_number, u32 flags, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Len Brown4be44fc2005-08-05 00:44:28 -0400596 acpi_status status = AE_OK;
597 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Bob Mooreb229cf92006-04-21 17:15:00 -0400599 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 /* Use semaphore lock if not executing at interrupt level */
602
603 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400604 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
605 if (ACPI_FAILURE(status)) {
606 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608 }
609
610 /* Ensure that we have a valid GPE number */
611
Len Brown4be44fc2005-08-05 00:44:28 -0400612 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 if (!gpe_event_info) {
614 status = AE_BAD_PARAMETER;
615 goto unlock_and_exit;
616 }
617
618 /* Obtain status on the requested GPE number */
619
Len Brown4be44fc2005-08-05 00:44:28 -0400620 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Zhang Ruied206fa2008-10-27 14:01:02 -0700622 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
623 *event_status |= ACPI_EVENT_FLAG_HANDLE;
624
Len Brown4be44fc2005-08-05 00:44:28 -0400625 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400627 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
Len Brown4be44fc2005-08-05 00:44:28 -0400629 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630}
Bob Moore83135242006-10-03 00:00:00 -0400631
632ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633/*******************************************************************************
634 *
635 * FUNCTION: acpi_install_gpe_block
636 *
637 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
638 * gpe_block_address - Address and space_iD
639 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400640 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 *
642 * RETURN: Status
643 *
644 * DESCRIPTION: Create and Install a block of GPE registers
645 *
646 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400648acpi_install_gpe_block(acpi_handle gpe_device,
649 struct acpi_generic_address *gpe_block_address,
650 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Len Brown4be44fc2005-08-05 00:44:28 -0400652 acpi_status status;
653 union acpi_operand_object *obj_desc;
654 struct acpi_namespace_node *node;
655 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Bob Mooreb229cf92006-04-21 17:15:00 -0400657 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Len Brown4be44fc2005-08-05 00:44:28 -0400659 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
660 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
662
Len Brown4be44fc2005-08-05 00:44:28 -0400663 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
664 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 return (status);
666 }
667
Bob Mooref24b6642009-12-11 14:57:00 +0800668 node = acpi_ns_validate_handle(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (!node) {
670 status = AE_BAD_PARAMETER;
671 goto unlock_and_exit;
672 }
673
674 /*
675 * For user-installed GPE Block Devices, the gpe_block_base_number
676 * is always zero
677 */
Len Brown4be44fc2005-08-05 00:44:28 -0400678 status =
679 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
680 interrupt_number, &gpe_block);
681 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 goto unlock_and_exit;
683 }
684
Bob Moore96db2552005-11-02 00:00:00 -0500685 /* Run the _PRW methods and enable the GPEs */
686
687 status = acpi_ev_initialize_gpe_block(node, gpe_block);
688 if (ACPI_FAILURE(status)) {
689 goto unlock_and_exit;
690 }
691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 /* Get the device_object attached to the node */
693
Len Brown4be44fc2005-08-05 00:44:28 -0400694 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 /* No object, create a new one */
698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 if (!obj_desc) {
701 status = AE_NO_MEMORY;
702 goto unlock_and_exit;
703 }
704
Len Brown4be44fc2005-08-05 00:44:28 -0400705 status =
706 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
708 /* Remove local reference to the object */
709
Len Brown4be44fc2005-08-05 00:44:28 -0400710 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Len Brown4be44fc2005-08-05 00:44:28 -0400712 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 goto unlock_and_exit;
714 }
715 }
716
717 /* Install the GPE block in the device_object */
718
719 obj_desc->device.gpe_block = gpe_block;
720
Len Brown4be44fc2005-08-05 00:44:28 -0400721 unlock_and_exit:
722 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
723 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Bob Moore83135242006-10-03 00:00:00 -0400726ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728/*******************************************************************************
729 *
730 * FUNCTION: acpi_remove_gpe_block
731 *
732 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
733 *
734 * RETURN: Status
735 *
736 * DESCRIPTION: Remove a previously installed block of GPE registers
737 *
738 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400739acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740{
Len Brown4be44fc2005-08-05 00:44:28 -0400741 union acpi_operand_object *obj_desc;
742 acpi_status status;
743 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Bob Mooreb229cf92006-04-21 17:15:00 -0400745 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400748 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 /* Get the device_object attached to the node */
763
Len Brown4be44fc2005-08-05 00:44:28 -0400764 obj_desc = acpi_ns_get_attached_object(node);
765 if (!obj_desc || !obj_desc->device.gpe_block) {
766 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
768
769 /* Delete the GPE block (but not the device_object) */
770
Len Brown4be44fc2005-08-05 00:44:28 -0400771 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
772 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 obj_desc->device.gpe_block = NULL;
774 }
775
Len Brown4be44fc2005-08-05 00:44:28 -0400776 unlock_and_exit:
777 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
778 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
Robert Moore44f6c012005-04-18 22:49:35 -0400780
Bob Moore83135242006-10-03 00:00:00 -0400781ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
Bob Mooree97d6bf2008-12-30 09:45:17 +0800782
783/*******************************************************************************
784 *
785 * FUNCTION: acpi_get_gpe_device
786 *
787 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
788 * gpe_device - Where the parent GPE Device is returned
789 *
790 * RETURN: Status
791 *
792 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
793 * gpe device indicates that the gpe number is contained in one of
794 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
795 *
796 ******************************************************************************/
797acpi_status
798acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
799{
800 struct acpi_gpe_device_info info;
801 acpi_status status;
802
803 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
804
805 if (!gpe_device) {
806 return_ACPI_STATUS(AE_BAD_PARAMETER);
807 }
808
809 if (index >= acpi_current_gpe_count) {
810 return_ACPI_STATUS(AE_NOT_EXIST);
811 }
812
813 /* Setup and walk the GPE list */
814
815 info.index = index;
816 info.status = AE_NOT_EXIST;
817 info.gpe_device = NULL;
818 info.next_block_base_index = 0;
819
820 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
821 if (ACPI_FAILURE(status)) {
822 return_ACPI_STATUS(status);
823 }
824
825 *gpe_device = info.gpe_device;
826 return_ACPI_STATUS(info.status);
827}
828
829ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
830
831/*******************************************************************************
832 *
833 * FUNCTION: acpi_ev_get_gpe_device
834 *
835 * PARAMETERS: GPE_WALK_CALLBACK
836 *
837 * RETURN: Status
838 *
839 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
840 * block device. NULL if the GPE is one of the FADT-defined GPEs.
841 *
842 ******************************************************************************/
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800843static acpi_status
Bob Mooree97d6bf2008-12-30 09:45:17 +0800844acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
845 struct acpi_gpe_block_info *gpe_block, void *context)
846{
847 struct acpi_gpe_device_info *info = context;
848
849 /* Increment Index by the number of GPEs in this block */
850
851 info->next_block_base_index +=
852 (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
853
854 if (info->index < info->next_block_base_index) {
855 /*
856 * The GPE index is within this block, get the node. Leave the node
857 * NULL for the FADT-defined GPEs
858 */
859 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
860 info->gpe_device = gpe_block->node;
861 }
862
863 info->status = AE_OK;
864 return (AE_CTRL_END);
865 }
866
867 return (AE_OK);
868}
Bob Moore08ac07b2008-12-30 09:55:48 +0800869
870/******************************************************************************
871 *
872 * FUNCTION: acpi_disable_all_gpes
873 *
874 * PARAMETERS: None
875 *
876 * RETURN: Status
877 *
878 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
879 *
880 ******************************************************************************/
881
882acpi_status acpi_disable_all_gpes(void)
883{
884 acpi_status status;
885
886 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
887
888 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
889 if (ACPI_FAILURE(status)) {
890 return_ACPI_STATUS(status);
891 }
892
893 status = acpi_hw_disable_all_gpes();
894 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
895
896 return_ACPI_STATUS(status);
897}
898
899/******************************************************************************
900 *
901 * FUNCTION: acpi_enable_all_runtime_gpes
902 *
903 * PARAMETERS: None
904 *
905 * RETURN: Status
906 *
907 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
908 *
909 ******************************************************************************/
910
911acpi_status acpi_enable_all_runtime_gpes(void)
912{
913 acpi_status status;
914
915 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
916
917 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
918 if (ACPI_FAILURE(status)) {
919 return_ACPI_STATUS(status);
920 }
921
922 status = acpi_hw_enable_all_runtime_gpes();
923 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
924
925 return_ACPI_STATUS(status);
926}