blob: 90eb7939e98621361a518895e0e2cf5f1adee2ea [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 Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
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
44#include <linux/module.h>
45
46#include <acpi/acpi.h>
47#include <acpi/acevents.h>
48#include <acpi/acnamesp.h>
49
50#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_enable
56 *
57 * PARAMETERS: None
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Transfers the system into ACPI mode.
62 *
63 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040064acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Len Brown4be44fc2005-08-05 00:44:28 -040066 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Len Brown4be44fc2005-08-05 00:44:28 -040068 ACPI_FUNCTION_TRACE("acpi_enable");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Len Brown4be44fc2005-08-05 00:44:28 -040070 /* Make sure we have the FADT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 if (!acpi_gbl_FADT) {
Bob Moore4a90c7e2006-01-13 16:22:00 -050073 ACPI_REPORT_WARNING(("No FADT information present!\n"));
Len Brown4be44fc2005-08-05 00:44:28 -040074 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
76
77 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040078 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
79 "System is already in ACPI mode\n"));
80 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 /* Transition to ACPI mode */
82
Len Brown4be44fc2005-08-05 00:44:28 -040083 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
84 if (ACPI_FAILURE(status)) {
Bob Moore4a90c7e2006-01-13 16:22:00 -050085 ACPI_REPORT_ERROR(("Could not transition to ACPI mode\n"));
Len Brown4be44fc2005-08-05 00:44:28 -040086 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88
Len Brown4be44fc2005-08-05 00:44:28 -040089 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
90 "Transition to ACPI mode successful\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }
92
Len Brown4be44fc2005-08-05 00:44:28 -040093 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/*******************************************************************************
97 *
98 * FUNCTION: acpi_disable
99 *
100 * PARAMETERS: None
101 *
102 * RETURN: Status
103 *
Robert Moore44f6c012005-04-18 22:49:35 -0400104 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 *
106 ******************************************************************************/
107
Len Brown4be44fc2005-08-05 00:44:28 -0400108acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Len Brown4be44fc2005-08-05 00:44:28 -0400110 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Len Brown4be44fc2005-08-05 00:44:28 -0400112 ACPI_FUNCTION_TRACE("acpi_disable");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 if (!acpi_gbl_FADT) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500115 ACPI_REPORT_WARNING(("No FADT information present!\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400116 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
119 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400120 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
121 "System is already in legacy (non-ACPI) mode\n"));
122 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 /* Transition to LEGACY mode */
124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Len Brown4be44fc2005-08-05 00:44:28 -0400127 if (ACPI_FAILURE(status)) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500128 ACPI_REPORT_ERROR(("Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400129 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134
Len Brown4be44fc2005-08-05 00:44:28 -0400135 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/*******************************************************************************
139 *
140 * FUNCTION: acpi_enable_event
141 *
142 * PARAMETERS: Event - The fixed eventto be enabled
143 * Flags - Reserved
144 *
145 * RETURN: Status
146 *
147 * DESCRIPTION: Enable an ACPI event (fixed)
148 *
149 ******************************************************************************/
150
Len Brown4be44fc2005-08-05 00:44:28 -0400151acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Len Brown4be44fc2005-08-05 00:44:28 -0400153 acpi_status status = AE_OK;
154 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 ACPI_FUNCTION_TRACE("acpi_enable_event");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 /* Decode the Fixed Event */
159
160 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400161 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163
164 /*
165 * Enable the requested fixed event (by writing a one to the
166 * enable register bit)
167 */
Len Brown4be44fc2005-08-05 00:44:28 -0400168 status =
169 acpi_set_register(acpi_gbl_fixed_event_info[event].
170 enable_register_id, 1, ACPI_MTX_LOCK);
171 if (ACPI_FAILURE(status)) {
172 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
175 /* Make sure that the hardware responded */
176
Len Brown4be44fc2005-08-05 00:44:28 -0400177 status =
178 acpi_get_register(acpi_gbl_fixed_event_info[event].
179 enable_register_id, &value, ACPI_MTX_LOCK);
180 if (ACPI_FAILURE(status)) {
181 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
183
184 if (value != 1) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500185 ACPI_REPORT_ERROR(("Could not enable %s event\n",
186 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400187 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
Len Brown4be44fc2005-08-05 00:44:28 -0400190 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Len Brown4be44fc2005-08-05 00:44:28 -0400193EXPORT_SYMBOL(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195/*******************************************************************************
196 *
197 * FUNCTION: acpi_set_gpe_type
198 *
199 * PARAMETERS: gpe_device - Parent GPE Device
200 * gpe_number - GPE level within the GPE block
201 * Type - New GPE type
202 *
203 * RETURN: Status
204 *
Robert Moore44f6c012005-04-18 22:49:35 -0400205 * DESCRIPTION: Set the type of an individual GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 *
207 ******************************************************************************/
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Len Brown4be44fc2005-08-05 00:44:28 -0400211 acpi_status status = AE_OK;
212 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Len Brown4be44fc2005-08-05 00:44:28 -0400214 ACPI_FUNCTION_TRACE("acpi_set_gpe_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 /* Ensure that we have a valid GPE number */
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 if (!gpe_event_info) {
220 status = AE_BAD_PARAMETER;
221 goto unlock_and_exit;
222 }
223
224 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
Len Brown4be44fc2005-08-05 00:44:28 -0400225 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227
228 /* Set the new type (will disable GPE if currently enabled) */
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 status = acpi_ev_set_gpe_type(gpe_event_info, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Len Brown4be44fc2005-08-05 00:44:28 -0400232 unlock_and_exit:
233 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Len Brown4be44fc2005-08-05 00:44:28 -0400236EXPORT_SYMBOL(acpi_set_gpe_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238/*******************************************************************************
239 *
240 * FUNCTION: acpi_enable_gpe
241 *
242 * PARAMETERS: gpe_device - Parent GPE Device
243 * gpe_number - GPE level within the GPE block
244 * Flags - Just enable, or also wake enable?
245 * Called from ISR or not
246 *
247 * RETURN: Status
248 *
249 * DESCRIPTION: Enable an ACPI event (general purpose)
250 *
251 ******************************************************************************/
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Len Brown4be44fc2005-08-05 00:44:28 -0400255 acpi_status status = AE_OK;
256 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 ACPI_FUNCTION_TRACE("acpi_enable_gpe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 /* Use semaphore lock if not executing at interrupt level */
261
262 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400263 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
264 if (ACPI_FAILURE(status)) {
265 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267 }
268
269 /* Ensure that we have a valid GPE number */
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (!gpe_event_info) {
273 status = AE_BAD_PARAMETER;
274 goto unlock_and_exit;
275 }
276
277 /* Perform the enable */
278
Len Brown4be44fc2005-08-05 00:44:28 -0400279 status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Len Brown4be44fc2005-08-05 00:44:28 -0400281 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400283 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
Len Brown4be44fc2005-08-05 00:44:28 -0400285 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Len Brown4be44fc2005-08-05 00:44:28 -0400288EXPORT_SYMBOL(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290/*******************************************************************************
291 *
292 * FUNCTION: acpi_disable_gpe
293 *
294 * PARAMETERS: gpe_device - Parent GPE Device
295 * gpe_number - GPE level within the GPE block
296 * Flags - Just disable, or also wake disable?
297 * Called from ISR or not
298 *
299 * RETURN: Status
300 *
301 * DESCRIPTION: Disable an ACPI event (general purpose)
302 *
303 ******************************************************************************/
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Len Brown4be44fc2005-08-05 00:44:28 -0400307 acpi_status status = AE_OK;
308 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Len Brown4be44fc2005-08-05 00:44:28 -0400310 ACPI_FUNCTION_TRACE("acpi_disable_gpe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 /* Use semaphore lock if not executing at interrupt level */
313
314 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400315 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
316 if (ACPI_FAILURE(status)) {
317 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 }
319 }
320
321 /* Ensure that we have a valid GPE number */
322
Len Brown4be44fc2005-08-05 00:44:28 -0400323 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 if (!gpe_event_info) {
325 status = AE_BAD_PARAMETER;
326 goto unlock_and_exit;
327 }
328
Len Brown4be44fc2005-08-05 00:44:28 -0400329 status = acpi_ev_disable_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400333 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 }
Len Brown4be44fc2005-08-05 00:44:28 -0400335 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338/*******************************************************************************
339 *
340 * FUNCTION: acpi_disable_event
341 *
342 * PARAMETERS: Event - The fixed eventto be enabled
343 * Flags - Reserved
344 *
345 * RETURN: Status
346 *
347 * DESCRIPTION: Disable an ACPI event (fixed)
348 *
349 ******************************************************************************/
350
Len Brown4be44fc2005-08-05 00:44:28 -0400351acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Len Brown4be44fc2005-08-05 00:44:28 -0400353 acpi_status status = AE_OK;
354 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 ACPI_FUNCTION_TRACE("acpi_disable_event");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /* Decode the Fixed Event */
359
360 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400361 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
363
364 /*
365 * Disable the requested fixed event (by writing a zero to the
366 * enable register bit)
367 */
Len Brown4be44fc2005-08-05 00:44:28 -0400368 status =
369 acpi_set_register(acpi_gbl_fixed_event_info[event].
370 enable_register_id, 0, ACPI_MTX_LOCK);
371 if (ACPI_FAILURE(status)) {
372 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 status =
376 acpi_get_register(acpi_gbl_fixed_event_info[event].
377 enable_register_id, &value, ACPI_MTX_LOCK);
378 if (ACPI_FAILURE(status)) {
379 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
381
382 if (value != 0) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500383 ACPI_REPORT_ERROR(("Could not disable %s events\n",
384 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400385 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Len Brown4be44fc2005-08-05 00:44:28 -0400391EXPORT_SYMBOL(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393/*******************************************************************************
394 *
395 * FUNCTION: acpi_clear_event
396 *
397 * PARAMETERS: Event - The fixed event to be cleared
398 *
399 * RETURN: Status
400 *
401 * DESCRIPTION: Clear an ACPI event (fixed)
402 *
403 ******************************************************************************/
404
Len Brown4be44fc2005-08-05 00:44:28 -0400405acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Len Brown4be44fc2005-08-05 00:44:28 -0400407 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Len Brown4be44fc2005-08-05 00:44:28 -0400409 ACPI_FUNCTION_TRACE("acpi_clear_event");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 /* Decode the Fixed Event */
412
413 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400414 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
417 /*
418 * Clear the requested fixed event (By writing a one to the
419 * status register bit)
420 */
Len Brown4be44fc2005-08-05 00:44:28 -0400421 status =
422 acpi_set_register(acpi_gbl_fixed_event_info[event].
423 status_register_id, 1, ACPI_MTX_LOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Len Brown4be44fc2005-08-05 00:44:28 -0400425 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Len Brown4be44fc2005-08-05 00:44:28 -0400428EXPORT_SYMBOL(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430/*******************************************************************************
431 *
432 * FUNCTION: acpi_clear_gpe
433 *
434 * PARAMETERS: gpe_device - Parent GPE Device
435 * gpe_number - GPE level within the GPE block
436 * Flags - Called from an ISR or not
437 *
438 * RETURN: Status
439 *
440 * DESCRIPTION: Clear an ACPI event (general purpose)
441 *
442 ******************************************************************************/
443
Len Brown4be44fc2005-08-05 00:44:28 -0400444acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Len Brown4be44fc2005-08-05 00:44:28 -0400446 acpi_status status = AE_OK;
447 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Len Brown4be44fc2005-08-05 00:44:28 -0400449 ACPI_FUNCTION_TRACE("acpi_clear_gpe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 /* Use semaphore lock if not executing at interrupt level */
452
453 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400454 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
455 if (ACPI_FAILURE(status)) {
456 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458 }
459
460 /* Ensure that we have a valid GPE number */
461
Len Brown4be44fc2005-08-05 00:44:28 -0400462 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (!gpe_event_info) {
464 status = AE_BAD_PARAMETER;
465 goto unlock_and_exit;
466 }
467
Len Brown4be44fc2005-08-05 00:44:28 -0400468 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Len Brown4be44fc2005-08-05 00:44:28 -0400470 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400472 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 }
Len Brown4be44fc2005-08-05 00:44:28 -0400474 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#ifdef ACPI_FUTURE_USAGE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478/*******************************************************************************
479 *
480 * FUNCTION: acpi_get_event_status
481 *
482 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400483 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 * be returned
485 *
486 * RETURN: Status
487 *
488 * DESCRIPTION: Obtains and returns the current status of the event
489 *
490 ******************************************************************************/
491
Len Brown4be44fc2005-08-05 00:44:28 -0400492acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Len Brown4be44fc2005-08-05 00:44:28 -0400494 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Len Brown4be44fc2005-08-05 00:44:28 -0400496 ACPI_FUNCTION_TRACE("acpi_get_event_status");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400499 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501
502 /* Decode the Fixed Event */
503
504 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400505 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507
508 /* Get the status of the requested fixed event */
509
Len Brown4be44fc2005-08-05 00:44:28 -0400510 status =
511 acpi_get_register(acpi_gbl_fixed_event_info[event].
512 status_register_id, event_status, ACPI_MTX_LOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Len Brown4be44fc2005-08-05 00:44:28 -0400514 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517/*******************************************************************************
518 *
519 * FUNCTION: acpi_get_gpe_status
520 *
521 * PARAMETERS: gpe_device - Parent GPE Device
522 * gpe_number - GPE level within the GPE block
523 * Flags - Called from an ISR or not
Robert Moore44f6c012005-04-18 22:49:35 -0400524 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 * be returned
526 *
527 * RETURN: Status
528 *
529 * DESCRIPTION: Get status of an event (general purpose)
530 *
531 ******************************************************************************/
532
533acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400534acpi_get_gpe_status(acpi_handle gpe_device,
535 u32 gpe_number, u32 flags, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
Len Brown4be44fc2005-08-05 00:44:28 -0400537 acpi_status status = AE_OK;
538 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Len Brown4be44fc2005-08-05 00:44:28 -0400540 ACPI_FUNCTION_TRACE("acpi_get_gpe_status");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 /* Use semaphore lock if not executing at interrupt level */
543
544 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400545 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
546 if (ACPI_FAILURE(status)) {
547 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549 }
550
551 /* Ensure that we have a valid GPE number */
552
Len Brown4be44fc2005-08-05 00:44:28 -0400553 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 if (!gpe_event_info) {
555 status = AE_BAD_PARAMETER;
556 goto unlock_and_exit;
557 }
558
559 /* Obtain status on the requested GPE number */
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Len Brown4be44fc2005-08-05 00:44:28 -0400563 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400565 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 }
Len Brown4be44fc2005-08-05 00:44:28 -0400567 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
Len Brown4be44fc2005-08-05 00:44:28 -0400569#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571/*******************************************************************************
572 *
573 * FUNCTION: acpi_install_gpe_block
574 *
575 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
576 * gpe_block_address - Address and space_iD
577 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400578 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 *
580 * RETURN: Status
581 *
582 * DESCRIPTION: Create and Install a block of GPE registers
583 *
584 ******************************************************************************/
585
586acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400587acpi_install_gpe_block(acpi_handle gpe_device,
588 struct acpi_generic_address *gpe_block_address,
589 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
Len Brown4be44fc2005-08-05 00:44:28 -0400591 acpi_status status;
592 union acpi_operand_object *obj_desc;
593 struct acpi_namespace_node *node;
594 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Len Brown4be44fc2005-08-05 00:44:28 -0400596 ACPI_FUNCTION_TRACE("acpi_install_gpe_block");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Len Brown4be44fc2005-08-05 00:44:28 -0400598 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
599 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
601
Len Brown4be44fc2005-08-05 00:44:28 -0400602 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
603 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 return (status);
605 }
606
Len Brown4be44fc2005-08-05 00:44:28 -0400607 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 if (!node) {
609 status = AE_BAD_PARAMETER;
610 goto unlock_and_exit;
611 }
612
613 /*
614 * For user-installed GPE Block Devices, the gpe_block_base_number
615 * is always zero
616 */
Len Brown4be44fc2005-08-05 00:44:28 -0400617 status =
618 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
619 interrupt_number, &gpe_block);
620 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 goto unlock_and_exit;
622 }
623
Bob Moore96db2552005-11-02 00:00:00 -0500624 /* Run the _PRW methods and enable the GPEs */
625
626 status = acpi_ev_initialize_gpe_block(node, gpe_block);
627 if (ACPI_FAILURE(status)) {
628 goto unlock_and_exit;
629 }
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* Get the device_object attached to the node */
632
Len Brown4be44fc2005-08-05 00:44:28 -0400633 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 if (!obj_desc) {
635 /* No object, create a new one */
636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 if (!obj_desc) {
639 status = AE_NO_MEMORY;
640 goto unlock_and_exit;
641 }
642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 status =
644 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 /* Remove local reference to the object */
647
Len Brown4be44fc2005-08-05 00:44:28 -0400648 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Len Brown4be44fc2005-08-05 00:44:28 -0400650 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 goto unlock_and_exit;
652 }
653 }
654
655 /* Install the GPE block in the device_object */
656
657 obj_desc->device.gpe_block = gpe_block;
658
Len Brown4be44fc2005-08-05 00:44:28 -0400659 unlock_and_exit:
660 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
661 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Len Brown4be44fc2005-08-05 00:44:28 -0400664EXPORT_SYMBOL(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666/*******************************************************************************
667 *
668 * FUNCTION: acpi_remove_gpe_block
669 *
670 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
671 *
672 * RETURN: Status
673 *
674 * DESCRIPTION: Remove a previously installed block of GPE registers
675 *
676 ******************************************************************************/
677
Len Brown4be44fc2005-08-05 00:44:28 -0400678acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
Len Brown4be44fc2005-08-05 00:44:28 -0400680 union acpi_operand_object *obj_desc;
681 acpi_status status;
682 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 ACPI_FUNCTION_TRACE("acpi_remove_gpe_block");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400687 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
689
Len Brown4be44fc2005-08-05 00:44:28 -0400690 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
691 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 return (status);
693 }
694
Len Brown4be44fc2005-08-05 00:44:28 -0400695 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (!node) {
697 status = AE_BAD_PARAMETER;
698 goto unlock_and_exit;
699 }
700
701 /* Get the device_object attached to the node */
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 obj_desc = acpi_ns_get_attached_object(node);
704 if (!obj_desc || !obj_desc->device.gpe_block) {
705 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 }
707
708 /* Delete the GPE block (but not the device_object) */
709
Len Brown4be44fc2005-08-05 00:44:28 -0400710 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
711 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 obj_desc->device.gpe_block = NULL;
713 }
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 unlock_and_exit:
716 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
717 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718}
Robert Moore44f6c012005-04-18 22:49:35 -0400719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720EXPORT_SYMBOL(acpi_remove_gpe_block);