blob: 35485e4b60a67df4d5a09e8cd8aa1e2cbe3b1000 [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, 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 */
54acpi_status
55acpi_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 =
175 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300176 enable_register_id, 1);
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 =
184 acpi_get_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300185 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 *
204 * FUNCTION: acpi_set_gpe_type
205 *
206 * PARAMETERS: gpe_device - Parent GPE Device
207 * gpe_number - GPE level within the GPE block
208 * Type - New GPE type
209 *
210 * RETURN: Status
211 *
Robert Moore44f6c012005-04-18 22:49:35 -0400212 * DESCRIPTION: Set the type of an individual GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 *
214 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400215acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Len Brown4be44fc2005-08-05 00:44:28 -0400217 acpi_status status = AE_OK;
218 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Bob Mooreb229cf92006-04-21 17:15:00 -0400220 ACPI_FUNCTION_TRACE(acpi_set_gpe_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /* Ensure that we have a valid GPE number */
223
Len Brown4be44fc2005-08-05 00:44:28 -0400224 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (!gpe_event_info) {
226 status = AE_BAD_PARAMETER;
227 goto unlock_and_exit;
228 }
229
230 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
Len Brown4be44fc2005-08-05 00:44:28 -0400231 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233
234 /* Set the new type (will disable GPE if currently enabled) */
235
Len Brown4be44fc2005-08-05 00:44:28 -0400236 status = acpi_ev_set_gpe_type(gpe_event_info, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Len Brown4be44fc2005-08-05 00:44:28 -0400238 unlock_and_exit:
239 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Bob Moore83135242006-10-03 00:00:00 -0400242ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244/*******************************************************************************
245 *
246 * FUNCTION: acpi_enable_gpe
247 *
248 * PARAMETERS: gpe_device - Parent GPE Device
249 * gpe_number - GPE level within the GPE block
250 * Flags - Just enable, or also wake enable?
251 * Called from ISR or not
252 *
253 * RETURN: Status
254 *
255 * DESCRIPTION: Enable an ACPI event (general purpose)
256 *
257 ******************************************************************************/
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400258acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Len Brown4be44fc2005-08-05 00:44:28 -0400260 acpi_status status = AE_OK;
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400261 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400262 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Bob Mooreb229cf92006-04-21 17:15:00 -0400264 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400266 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 /* Ensure that we have a valid GPE number */
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 if (!gpe_event_info) {
272 status = AE_BAD_PARAMETER;
273 goto unlock_and_exit;
274 }
275
276 /* Perform the enable */
277
Len Brown4be44fc2005-08-05 00:44:28 -0400278 status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Len Brown4be44fc2005-08-05 00:44:28 -0400280 unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400281 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400282 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Bob Moore83135242006-10-03 00:00:00 -0400285ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287/*******************************************************************************
288 *
289 * FUNCTION: acpi_disable_gpe
290 *
291 * PARAMETERS: gpe_device - Parent GPE Device
292 * gpe_number - GPE level within the GPE block
293 * Flags - Just disable, or also wake disable?
294 * Called from ISR or not
295 *
296 * RETURN: Status
297 *
298 * DESCRIPTION: Disable an ACPI event (general purpose)
299 *
300 ******************************************************************************/
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400301acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Len Brown4be44fc2005-08-05 00:44:28 -0400303 acpi_status status = AE_OK;
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400304 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400305 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Bob Mooreb229cf92006-04-21 17:15:00 -0400307 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400309 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 /* Ensure that we have a valid GPE number */
311
Len Brown4be44fc2005-08-05 00:44:28 -0400312 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 if (!gpe_event_info) {
314 status = AE_BAD_PARAMETER;
315 goto unlock_and_exit;
316 }
317
Len Brown4be44fc2005-08-05 00:44:28 -0400318 status = acpi_ev_disable_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400320unlock_and_exit:
321 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400322 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323}
324
Bob Moore83135242006-10-03 00:00:00 -0400325ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/*******************************************************************************
328 *
329 * FUNCTION: acpi_disable_event
330 *
331 * PARAMETERS: Event - The fixed eventto be enabled
332 * Flags - Reserved
333 *
334 * RETURN: Status
335 *
336 * DESCRIPTION: Disable an ACPI event (fixed)
337 *
338 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400339acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Len Brown4be44fc2005-08-05 00:44:28 -0400341 acpi_status status = AE_OK;
342 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Bob Mooreb229cf92006-04-21 17:15:00 -0400344 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 /* Decode the Fixed Event */
347
348 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400349 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
352 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800353 * Disable the requested fixed event (by writing a zero to the enable
354 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 */
Len Brown4be44fc2005-08-05 00:44:28 -0400356 status =
357 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300358 enable_register_id, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400359 if (ACPI_FAILURE(status)) {
360 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
Len Brown4be44fc2005-08-05 00:44:28 -0400363 status =
364 acpi_get_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300365 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400366 if (ACPI_FAILURE(status)) {
367 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
370 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500371 ACPI_ERROR((AE_INFO,
372 "Could not disable %s events",
373 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400374 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
376
Len Brown4be44fc2005-08-05 00:44:28 -0400377 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Bob Moore83135242006-10-03 00:00:00 -0400380ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382/*******************************************************************************
383 *
384 * FUNCTION: acpi_clear_event
385 *
386 * PARAMETERS: Event - The fixed event to be cleared
387 *
388 * RETURN: Status
389 *
390 * DESCRIPTION: Clear an ACPI event (fixed)
391 *
392 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400393acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Len Brown4be44fc2005-08-05 00:44:28 -0400395 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Bob Mooreb229cf92006-04-21 17:15:00 -0400397 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 /* Decode the Fixed Event */
400
401 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400402 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404
405 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800406 * Clear the requested fixed event (By writing a one to the status
407 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 */
Len Brown4be44fc2005-08-05 00:44:28 -0400409 status =
410 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300411 status_register_id, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Len Brown4be44fc2005-08-05 00:44:28 -0400413 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Bob Moore83135242006-10-03 00:00:00 -0400416ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418/*******************************************************************************
419 *
420 * FUNCTION: acpi_clear_gpe
421 *
422 * PARAMETERS: gpe_device - Parent GPE Device
423 * gpe_number - GPE level within the GPE block
424 * Flags - Called from an ISR or not
425 *
426 * RETURN: Status
427 *
428 * DESCRIPTION: Clear an ACPI event (general purpose)
429 *
430 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400431acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Len Brown4be44fc2005-08-05 00:44:28 -0400433 acpi_status status = AE_OK;
434 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Bob Mooreb229cf92006-04-21 17:15:00 -0400436 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 /* Use semaphore lock if not executing at interrupt level */
439
440 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400441 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
442 if (ACPI_FAILURE(status)) {
443 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
445 }
446
447 /* Ensure that we have a valid GPE number */
448
Len Brown4be44fc2005-08-05 00:44:28 -0400449 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (!gpe_event_info) {
451 status = AE_BAD_PARAMETER;
452 goto unlock_and_exit;
453 }
454
Len Brown4be44fc2005-08-05 00:44:28 -0400455 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Len Brown4be44fc2005-08-05 00:44:28 -0400457 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400459 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
Len Brown4be44fc2005-08-05 00:44:28 -0400461 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
Bob Moore83135242006-10-03 00:00:00 -0400464ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465/*******************************************************************************
466 *
467 * FUNCTION: acpi_get_event_status
468 *
469 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400470 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 * be returned
472 *
473 * RETURN: Status
474 *
475 * DESCRIPTION: Obtains and returns the current status of the event
476 *
477 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400478acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Len Brown4be44fc2005-08-05 00:44:28 -0400480 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800481 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Bob Mooreb229cf92006-04-21 17:15:00 -0400483 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400486 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
488
489 /* Decode the Fixed Event */
490
491 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400492 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
494
495 /* Get the status of the requested fixed event */
496
Len Brown4be44fc2005-08-05 00:44:28 -0400497 status =
498 acpi_get_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800499 enable_register_id, &value);
500 if (ACPI_FAILURE(status))
501 return_ACPI_STATUS(status);
502
503 *event_status = value;
504
505 status =
506 acpi_get_register(acpi_gbl_fixed_event_info[event].
507 status_register_id, &value);
508 if (ACPI_FAILURE(status))
509 return_ACPI_STATUS(status);
510
511 if (value)
512 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Zhang Ruied206fa2008-10-27 14:01:02 -0700514 if (acpi_gbl_fixed_event_handlers[event].handler)
515 *event_status |= ACPI_EVENT_FLAG_HANDLE;
516
Len Brown4be44fc2005-08-05 00:44:28 -0400517 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518}
519
Bob Moore83135242006-10-03 00:00:00 -0400520ACPI_EXPORT_SYMBOL(acpi_get_event_status)
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522/*******************************************************************************
523 *
524 * FUNCTION: acpi_get_gpe_status
525 *
526 * PARAMETERS: gpe_device - Parent GPE Device
527 * gpe_number - GPE level within the GPE block
528 * Flags - Called from an ISR or not
Robert Moore44f6c012005-04-18 22:49:35 -0400529 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 * be returned
531 *
532 * RETURN: Status
533 *
534 * DESCRIPTION: Get status of an event (general purpose)
535 *
536 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400538acpi_get_gpe_status(acpi_handle gpe_device,
539 u32 gpe_number, u32 flags, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
Len Brown4be44fc2005-08-05 00:44:28 -0400541 acpi_status status = AE_OK;
542 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Bob Mooreb229cf92006-04-21 17:15:00 -0400544 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 /* Use semaphore lock if not executing at interrupt level */
547
548 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400549 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
550 if (ACPI_FAILURE(status)) {
551 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
553 }
554
555 /* Ensure that we have a valid GPE number */
556
Len Brown4be44fc2005-08-05 00:44:28 -0400557 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (!gpe_event_info) {
559 status = AE_BAD_PARAMETER;
560 goto unlock_and_exit;
561 }
562
563 /* Obtain status on the requested GPE number */
564
Len Brown4be44fc2005-08-05 00:44:28 -0400565 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Zhang Ruied206fa2008-10-27 14:01:02 -0700567 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
568 *event_status |= ACPI_EVENT_FLAG_HANDLE;
569
Len Brown4be44fc2005-08-05 00:44:28 -0400570 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400572 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 }
Len Brown4be44fc2005-08-05 00:44:28 -0400574 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
Bob Moore83135242006-10-03 00:00:00 -0400576
577ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578/*******************************************************************************
579 *
580 * FUNCTION: acpi_install_gpe_block
581 *
582 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
583 * gpe_block_address - Address and space_iD
584 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400585 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 *
587 * RETURN: Status
588 *
589 * DESCRIPTION: Create and Install a block of GPE registers
590 *
591 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400593acpi_install_gpe_block(acpi_handle gpe_device,
594 struct acpi_generic_address *gpe_block_address,
595 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Len Brown4be44fc2005-08-05 00:44:28 -0400597 acpi_status status;
598 union acpi_operand_object *obj_desc;
599 struct acpi_namespace_node *node;
600 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Bob Mooreb229cf92006-04-21 17:15:00 -0400602 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Len Brown4be44fc2005-08-05 00:44:28 -0400604 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
605 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 }
607
Len Brown4be44fc2005-08-05 00:44:28 -0400608 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
609 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 return (status);
611 }
612
Len Brown4be44fc2005-08-05 00:44:28 -0400613 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 if (!node) {
615 status = AE_BAD_PARAMETER;
616 goto unlock_and_exit;
617 }
618
619 /*
620 * For user-installed GPE Block Devices, the gpe_block_base_number
621 * is always zero
622 */
Len Brown4be44fc2005-08-05 00:44:28 -0400623 status =
624 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
625 interrupt_number, &gpe_block);
626 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 goto unlock_and_exit;
628 }
629
Bob Moore96db2552005-11-02 00:00:00 -0500630 /* Run the _PRW methods and enable the GPEs */
631
632 status = acpi_ev_initialize_gpe_block(node, gpe_block);
633 if (ACPI_FAILURE(status)) {
634 goto unlock_and_exit;
635 }
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 /* Get the device_object attached to the node */
638
Len Brown4be44fc2005-08-05 00:44:28 -0400639 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 /* No object, create a new one */
643
Len Brown4be44fc2005-08-05 00:44:28 -0400644 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (!obj_desc) {
646 status = AE_NO_MEMORY;
647 goto unlock_and_exit;
648 }
649
Len Brown4be44fc2005-08-05 00:44:28 -0400650 status =
651 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 /* Remove local reference to the object */
654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Len Brown4be44fc2005-08-05 00:44:28 -0400657 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 goto unlock_and_exit;
659 }
660 }
661
662 /* Install the GPE block in the device_object */
663
664 obj_desc->device.gpe_block = gpe_block;
665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 unlock_and_exit:
667 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
668 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Bob Moore83135242006-10-03 00:00:00 -0400671ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673/*******************************************************************************
674 *
675 * FUNCTION: acpi_remove_gpe_block
676 *
677 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
678 *
679 * RETURN: Status
680 *
681 * DESCRIPTION: Remove a previously installed block of GPE registers
682 *
683 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400684acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
Len Brown4be44fc2005-08-05 00:44:28 -0400686 union acpi_operand_object *obj_desc;
687 acpi_status status;
688 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Bob Mooreb229cf92006-04-21 17:15:00 -0400690 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400693 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
695
Len Brown4be44fc2005-08-05 00:44:28 -0400696 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
697 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 return (status);
699 }
700
Len Brown4be44fc2005-08-05 00:44:28 -0400701 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 if (!node) {
703 status = AE_BAD_PARAMETER;
704 goto unlock_and_exit;
705 }
706
707 /* Get the device_object attached to the node */
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709 obj_desc = acpi_ns_get_attached_object(node);
710 if (!obj_desc || !obj_desc->device.gpe_block) {
711 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713
714 /* Delete the GPE block (but not the device_object) */
715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
717 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 obj_desc->device.gpe_block = NULL;
719 }
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}
Robert Moore44f6c012005-04-18 22:49:35 -0400725
Bob Moore83135242006-10-03 00:00:00 -0400726ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
Bob Mooree97d6bf2008-12-30 09:45:17 +0800727
728/*******************************************************************************
729 *
730 * FUNCTION: acpi_get_gpe_device
731 *
732 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
733 * gpe_device - Where the parent GPE Device is returned
734 *
735 * RETURN: Status
736 *
737 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
738 * gpe device indicates that the gpe number is contained in one of
739 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
740 *
741 ******************************************************************************/
742acpi_status
743acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
744{
745 struct acpi_gpe_device_info info;
746 acpi_status status;
747
748 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
749
750 if (!gpe_device) {
751 return_ACPI_STATUS(AE_BAD_PARAMETER);
752 }
753
754 if (index >= acpi_current_gpe_count) {
755 return_ACPI_STATUS(AE_NOT_EXIST);
756 }
757
758 /* Setup and walk the GPE list */
759
760 info.index = index;
761 info.status = AE_NOT_EXIST;
762 info.gpe_device = NULL;
763 info.next_block_base_index = 0;
764
765 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
766 if (ACPI_FAILURE(status)) {
767 return_ACPI_STATUS(status);
768 }
769
770 *gpe_device = info.gpe_device;
771 return_ACPI_STATUS(info.status);
772}
773
774ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
775
776/*******************************************************************************
777 *
778 * FUNCTION: acpi_ev_get_gpe_device
779 *
780 * PARAMETERS: GPE_WALK_CALLBACK
781 *
782 * RETURN: Status
783 *
784 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
785 * block device. NULL if the GPE is one of the FADT-defined GPEs.
786 *
787 ******************************************************************************/
788acpi_status
789acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
790 struct acpi_gpe_block_info *gpe_block, void *context)
791{
792 struct acpi_gpe_device_info *info = context;
793
794 /* Increment Index by the number of GPEs in this block */
795
796 info->next_block_base_index +=
797 (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
798
799 if (info->index < info->next_block_base_index) {
800 /*
801 * The GPE index is within this block, get the node. Leave the node
802 * NULL for the FADT-defined GPEs
803 */
804 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
805 info->gpe_device = gpe_block->node;
806 }
807
808 info->status = AE_OK;
809 return (AE_CTRL_END);
810 }
811
812 return (AE_OK);
813}
Bob Moore08ac07b2008-12-30 09:55:48 +0800814
815/******************************************************************************
816 *
817 * FUNCTION: acpi_disable_all_gpes
818 *
819 * PARAMETERS: None
820 *
821 * RETURN: Status
822 *
823 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
824 *
825 ******************************************************************************/
826
827acpi_status acpi_disable_all_gpes(void)
828{
829 acpi_status status;
830
831 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
832
833 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
834 if (ACPI_FAILURE(status)) {
835 return_ACPI_STATUS(status);
836 }
837
838 status = acpi_hw_disable_all_gpes();
839 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
840
841 return_ACPI_STATUS(status);
842}
843
844/******************************************************************************
845 *
846 * FUNCTION: acpi_enable_all_runtime_gpes
847 *
848 * PARAMETERS: None
849 *
850 * RETURN: Status
851 *
852 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
853 *
854 ******************************************************************************/
855
856acpi_status acpi_enable_all_runtime_gpes(void)
857{
858 acpi_status status;
859
860 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
861
862 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
863 if (ACPI_FAILURE(status)) {
864 return_ACPI_STATUS(status);
865 }
866
867 status = acpi_hw_enable_all_runtime_gpes();
868 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
869
870 return_ACPI_STATUS(status);
871}