blob: c1b8989282568c5b72b362ec20aeb2612bfe8d52 [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/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * 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) {
Len Brown4be44fc2005-08-05 00:44:28 -040073 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
74 "No FADT information present!\n"));
75 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 }
77
78 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040079 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
80 "System is already in ACPI mode\n"));
81 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 /* Transition to ACPI mode */
83
Len Brown4be44fc2005-08-05 00:44:28 -040084 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
85 if (ACPI_FAILURE(status)) {
86 ACPI_REPORT_ERROR(("Could not transition to ACPI mode.\n"));
87 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
Len Brown4be44fc2005-08-05 00:44:28 -040090 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
91 "Transition to ACPI mode successful\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 }
93
Len Brown4be44fc2005-08-05 00:44:28 -040094 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/*******************************************************************************
98 *
99 * FUNCTION: acpi_disable
100 *
101 * PARAMETERS: None
102 *
103 * RETURN: Status
104 *
Robert Moore44f6c012005-04-18 22:49:35 -0400105 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 *
107 ******************************************************************************/
108
Len Brown4be44fc2005-08-05 00:44:28 -0400109acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Len Brown4be44fc2005-08-05 00:44:28 -0400111 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Len Brown4be44fc2005-08-05 00:44:28 -0400113 ACPI_FUNCTION_TRACE("acpi_disable");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 if (!acpi_gbl_FADT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400116 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
117 "No FADT information present!\n"));
118 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
120
121 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400122 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
123 "System is already in legacy (non-ACPI) mode\n"));
124 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 /* Transition to LEGACY mode */
126
Len Brown4be44fc2005-08-05 00:44:28 -0400127 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 if (ACPI_FAILURE(status)) {
130 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
131 "Could not exit ACPI mode to legacy mode"));
132 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134
Len Brown4be44fc2005-08-05 00:44:28 -0400135 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 }
137
Len Brown4be44fc2005-08-05 00:44:28 -0400138 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/*******************************************************************************
142 *
143 * FUNCTION: acpi_enable_event
144 *
145 * PARAMETERS: Event - The fixed eventto be enabled
146 * Flags - Reserved
147 *
148 * RETURN: Status
149 *
150 * DESCRIPTION: Enable an ACPI event (fixed)
151 *
152 ******************************************************************************/
153
Len Brown4be44fc2005-08-05 00:44:28 -0400154acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Len Brown4be44fc2005-08-05 00:44:28 -0400156 acpi_status status = AE_OK;
157 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 ACPI_FUNCTION_TRACE("acpi_enable_event");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 /* Decode the Fixed Event */
162
163 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400164 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
167 /*
168 * Enable the requested fixed event (by writing a one to the
169 * enable register bit)
170 */
Len Brown4be44fc2005-08-05 00:44:28 -0400171 status =
172 acpi_set_register(acpi_gbl_fixed_event_info[event].
173 enable_register_id, 1, ACPI_MTX_LOCK);
174 if (ACPI_FAILURE(status)) {
175 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
177
178 /* Make sure that the hardware responded */
179
Len Brown4be44fc2005-08-05 00:44:28 -0400180 status =
181 acpi_get_register(acpi_gbl_fixed_event_info[event].
182 enable_register_id, &value, ACPI_MTX_LOCK);
183 if (ACPI_FAILURE(status)) {
184 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
187 if (value != 1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400188 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
189 "Could not enable %s event\n",
190 acpi_ut_get_event_name(event)));
191 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193
Len Brown4be44fc2005-08-05 00:44:28 -0400194 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Len Brown4be44fc2005-08-05 00:44:28 -0400197EXPORT_SYMBOL(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199/*******************************************************************************
200 *
201 * FUNCTION: acpi_set_gpe_type
202 *
203 * PARAMETERS: gpe_device - Parent GPE Device
204 * gpe_number - GPE level within the GPE block
205 * Type - New GPE type
206 *
207 * RETURN: Status
208 *
Robert Moore44f6c012005-04-18 22:49:35 -0400209 * DESCRIPTION: Set the type of an individual GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 *
211 ******************************************************************************/
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Len Brown4be44fc2005-08-05 00:44:28 -0400215 acpi_status status = AE_OK;
216 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Len Brown4be44fc2005-08-05 00:44:28 -0400218 ACPI_FUNCTION_TRACE("acpi_set_gpe_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 /* Ensure that we have a valid GPE number */
221
Len Brown4be44fc2005-08-05 00:44:28 -0400222 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 if (!gpe_event_info) {
224 status = AE_BAD_PARAMETER;
225 goto unlock_and_exit;
226 }
227
228 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
Len Brown4be44fc2005-08-05 00:44:28 -0400229 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
231
232 /* Set the new type (will disable GPE if currently enabled) */
233
Len Brown4be44fc2005-08-05 00:44:28 -0400234 status = acpi_ev_set_gpe_type(gpe_event_info, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Len Brown4be44fc2005-08-05 00:44:28 -0400236 unlock_and_exit:
237 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Len Brown4be44fc2005-08-05 00:44:28 -0400240EXPORT_SYMBOL(acpi_set_gpe_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242/*******************************************************************************
243 *
244 * FUNCTION: acpi_enable_gpe
245 *
246 * PARAMETERS: gpe_device - Parent GPE Device
247 * gpe_number - GPE level within the GPE block
248 * Flags - Just enable, or also wake enable?
249 * Called from ISR or not
250 *
251 * RETURN: Status
252 *
253 * DESCRIPTION: Enable an ACPI event (general purpose)
254 *
255 ******************************************************************************/
256
Len Brown4be44fc2005-08-05 00:44:28 -0400257acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Len Brown4be44fc2005-08-05 00:44:28 -0400259 acpi_status status = AE_OK;
260 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Len Brown4be44fc2005-08-05 00:44:28 -0400262 ACPI_FUNCTION_TRACE("acpi_enable_gpe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 /* Use semaphore lock if not executing at interrupt level */
265
266 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400267 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
268 if (ACPI_FAILURE(status)) {
269 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271 }
272
273 /* Ensure that we have a valid GPE number */
274
Len Brown4be44fc2005-08-05 00:44:28 -0400275 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (!gpe_event_info) {
277 status = AE_BAD_PARAMETER;
278 goto unlock_and_exit;
279 }
280
281 /* Perform the enable */
282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Len Brown4be44fc2005-08-05 00:44:28 -0400285 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400287 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
Len Brown4be44fc2005-08-05 00:44:28 -0400289 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Len Brown4be44fc2005-08-05 00:44:28 -0400292EXPORT_SYMBOL(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294/*******************************************************************************
295 *
296 * FUNCTION: acpi_disable_gpe
297 *
298 * PARAMETERS: gpe_device - Parent GPE Device
299 * gpe_number - GPE level within the GPE block
300 * Flags - Just disable, or also wake disable?
301 * Called from ISR or not
302 *
303 * RETURN: Status
304 *
305 * DESCRIPTION: Disable an ACPI event (general purpose)
306 *
307 ******************************************************************************/
308
Len Brown4be44fc2005-08-05 00:44:28 -0400309acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Len Brown4be44fc2005-08-05 00:44:28 -0400311 acpi_status status = AE_OK;
312 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 ACPI_FUNCTION_TRACE("acpi_disable_gpe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 /* Use semaphore lock if not executing at interrupt level */
317
318 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400319 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
320 if (ACPI_FAILURE(status)) {
321 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323 }
324
325 /* Ensure that we have a valid GPE number */
326
Len Brown4be44fc2005-08-05 00:44:28 -0400327 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 if (!gpe_event_info) {
329 status = AE_BAD_PARAMETER;
330 goto unlock_and_exit;
331 }
332
Len Brown4be44fc2005-08-05 00:44:28 -0400333 status = acpi_ev_disable_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Len Brown4be44fc2005-08-05 00:44:28 -0400335 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400337 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 }
Len Brown4be44fc2005-08-05 00:44:28 -0400339 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342/*******************************************************************************
343 *
344 * FUNCTION: acpi_disable_event
345 *
346 * PARAMETERS: Event - The fixed eventto be enabled
347 * Flags - Reserved
348 *
349 * RETURN: Status
350 *
351 * DESCRIPTION: Disable an ACPI event (fixed)
352 *
353 ******************************************************************************/
354
Len Brown4be44fc2005-08-05 00:44:28 -0400355acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Len Brown4be44fc2005-08-05 00:44:28 -0400357 acpi_status status = AE_OK;
358 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Len Brown4be44fc2005-08-05 00:44:28 -0400360 ACPI_FUNCTION_TRACE("acpi_disable_event");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /* Decode the Fixed Event */
363
364 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400365 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367
368 /*
369 * Disable the requested fixed event (by writing a zero to the
370 * enable register bit)
371 */
Len Brown4be44fc2005-08-05 00:44:28 -0400372 status =
373 acpi_set_register(acpi_gbl_fixed_event_info[event].
374 enable_register_id, 0, ACPI_MTX_LOCK);
375 if (ACPI_FAILURE(status)) {
376 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 status =
380 acpi_get_register(acpi_gbl_fixed_event_info[event].
381 enable_register_id, &value, ACPI_MTX_LOCK);
382 if (ACPI_FAILURE(status)) {
383 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
385
386 if (value != 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400387 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
388 "Could not disable %s events\n",
389 acpi_ut_get_event_name(event)));
390 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 }
392
Len Brown4be44fc2005-08-05 00:44:28 -0400393 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Len Brown4be44fc2005-08-05 00:44:28 -0400396EXPORT_SYMBOL(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398/*******************************************************************************
399 *
400 * FUNCTION: acpi_clear_event
401 *
402 * PARAMETERS: Event - The fixed event to be cleared
403 *
404 * RETURN: Status
405 *
406 * DESCRIPTION: Clear an ACPI event (fixed)
407 *
408 ******************************************************************************/
409
Len Brown4be44fc2005-08-05 00:44:28 -0400410acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Len Brown4be44fc2005-08-05 00:44:28 -0400412 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 ACPI_FUNCTION_TRACE("acpi_clear_event");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 /* Decode the Fixed Event */
417
418 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400419 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
421
422 /*
423 * Clear the requested fixed event (By writing a one to the
424 * status register bit)
425 */
Len Brown4be44fc2005-08-05 00:44:28 -0400426 status =
427 acpi_set_register(acpi_gbl_fixed_event_info[event].
428 status_register_id, 1, ACPI_MTX_LOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Len Brown4be44fc2005-08-05 00:44:28 -0400430 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Len Brown4be44fc2005-08-05 00:44:28 -0400433EXPORT_SYMBOL(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435/*******************************************************************************
436 *
437 * FUNCTION: acpi_clear_gpe
438 *
439 * PARAMETERS: gpe_device - Parent GPE Device
440 * gpe_number - GPE level within the GPE block
441 * Flags - Called from an ISR or not
442 *
443 * RETURN: Status
444 *
445 * DESCRIPTION: Clear an ACPI event (general purpose)
446 *
447 ******************************************************************************/
448
Len Brown4be44fc2005-08-05 00:44:28 -0400449acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Len Brown4be44fc2005-08-05 00:44:28 -0400451 acpi_status status = AE_OK;
452 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Len Brown4be44fc2005-08-05 00:44:28 -0400454 ACPI_FUNCTION_TRACE("acpi_clear_gpe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456 /* Use semaphore lock if not executing at interrupt level */
457
458 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400459 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
460 if (ACPI_FAILURE(status)) {
461 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
463 }
464
465 /* Ensure that we have a valid GPE number */
466
Len Brown4be44fc2005-08-05 00:44:28 -0400467 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (!gpe_event_info) {
469 status = AE_BAD_PARAMETER;
470 goto unlock_and_exit;
471 }
472
Len Brown4be44fc2005-08-05 00:44:28 -0400473 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400477 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 }
Len Brown4be44fc2005-08-05 00:44:28 -0400479 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#ifdef ACPI_FUTURE_USAGE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483/*******************************************************************************
484 *
485 * FUNCTION: acpi_get_event_status
486 *
487 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400488 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 * be returned
490 *
491 * RETURN: Status
492 *
493 * DESCRIPTION: Obtains and returns the current status of the event
494 *
495 ******************************************************************************/
496
Len Brown4be44fc2005-08-05 00:44:28 -0400497acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
Len Brown4be44fc2005-08-05 00:44:28 -0400499 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Len Brown4be44fc2005-08-05 00:44:28 -0400501 ACPI_FUNCTION_TRACE("acpi_get_event_status");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400504 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506
507 /* Decode the Fixed Event */
508
509 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400510 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512
513 /* Get the status of the requested fixed event */
514
Len Brown4be44fc2005-08-05 00:44:28 -0400515 status =
516 acpi_get_register(acpi_gbl_fixed_event_info[event].
517 status_register_id, event_status, ACPI_MTX_LOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Len Brown4be44fc2005-08-05 00:44:28 -0400519 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
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 ******************************************************************************/
537
538acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400539acpi_get_gpe_status(acpi_handle gpe_device,
540 u32 gpe_number, u32 flags, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Len Brown4be44fc2005-08-05 00:44:28 -0400542 acpi_status status = AE_OK;
543 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Len Brown4be44fc2005-08-05 00:44:28 -0400545 ACPI_FUNCTION_TRACE("acpi_get_gpe_status");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 /* Use semaphore lock if not executing at interrupt level */
548
549 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400550 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
551 if (ACPI_FAILURE(status)) {
552 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
554 }
555
556 /* Ensure that we have a valid GPE number */
557
Len Brown4be44fc2005-08-05 00:44:28 -0400558 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 if (!gpe_event_info) {
560 status = AE_BAD_PARAMETER;
561 goto unlock_and_exit;
562 }
563
564 /* Obtain status on the requested GPE number */
565
Len Brown4be44fc2005-08-05 00:44:28 -0400566 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Len Brown4be44fc2005-08-05 00:44:28 -0400568 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400570 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
Len Brown4be44fc2005-08-05 00:44:28 -0400572 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
Len Brown4be44fc2005-08-05 00:44:28 -0400574#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576/*******************************************************************************
577 *
578 * FUNCTION: acpi_install_gpe_block
579 *
580 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
581 * gpe_block_address - Address and space_iD
582 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400583 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 *
585 * RETURN: Status
586 *
587 * DESCRIPTION: Create and Install a block of GPE registers
588 *
589 ******************************************************************************/
590
591acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400592acpi_install_gpe_block(acpi_handle gpe_device,
593 struct acpi_generic_address *gpe_block_address,
594 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Len Brown4be44fc2005-08-05 00:44:28 -0400596 acpi_status status;
597 union acpi_operand_object *obj_desc;
598 struct acpi_namespace_node *node;
599 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Len Brown4be44fc2005-08-05 00:44:28 -0400601 ACPI_FUNCTION_TRACE("acpi_install_gpe_block");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Len Brown4be44fc2005-08-05 00:44:28 -0400603 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
604 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
606
Len Brown4be44fc2005-08-05 00:44:28 -0400607 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
608 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 return (status);
610 }
611
Len Brown4be44fc2005-08-05 00:44:28 -0400612 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 if (!node) {
614 status = AE_BAD_PARAMETER;
615 goto unlock_and_exit;
616 }
617
618 /*
619 * For user-installed GPE Block Devices, the gpe_block_base_number
620 * is always zero
621 */
Len Brown4be44fc2005-08-05 00:44:28 -0400622 status =
623 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
624 interrupt_number, &gpe_block);
625 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 goto unlock_and_exit;
627 }
628
Bob Moore96db2552005-11-02 00:00:00 -0500629 /* Run the _PRW methods and enable the GPEs */
630
631 status = acpi_ev_initialize_gpe_block(node, gpe_block);
632 if (ACPI_FAILURE(status)) {
633 goto unlock_and_exit;
634 }
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 /* Get the device_object attached to the node */
637
Len Brown4be44fc2005-08-05 00:44:28 -0400638 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if (!obj_desc) {
640 /* No object, create a new one */
641
Len Brown4be44fc2005-08-05 00:44:28 -0400642 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 if (!obj_desc) {
644 status = AE_NO_MEMORY;
645 goto unlock_and_exit;
646 }
647
Len Brown4be44fc2005-08-05 00:44:28 -0400648 status =
649 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 /* Remove local reference to the object */
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 goto unlock_and_exit;
657 }
658 }
659
660 /* Install the GPE block in the device_object */
661
662 obj_desc->device.gpe_block = gpe_block;
663
Len Brown4be44fc2005-08-05 00:44:28 -0400664 unlock_and_exit:
665 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
666 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Len Brown4be44fc2005-08-05 00:44:28 -0400669EXPORT_SYMBOL(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671/*******************************************************************************
672 *
673 * FUNCTION: acpi_remove_gpe_block
674 *
675 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
676 *
677 * RETURN: Status
678 *
679 * DESCRIPTION: Remove a previously installed block of GPE registers
680 *
681 ******************************************************************************/
682
Len Brown4be44fc2005-08-05 00:44:28 -0400683acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Len Brown4be44fc2005-08-05 00:44:28 -0400685 union acpi_operand_object *obj_desc;
686 acpi_status status;
687 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 ACPI_FUNCTION_TRACE("acpi_remove_gpe_block");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400692 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 }
694
Len Brown4be44fc2005-08-05 00:44:28 -0400695 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
696 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 return (status);
698 }
699
Len Brown4be44fc2005-08-05 00:44:28 -0400700 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 if (!node) {
702 status = AE_BAD_PARAMETER;
703 goto unlock_and_exit;
704 }
705
706 /* Get the device_object attached to the node */
707
Len Brown4be44fc2005-08-05 00:44:28 -0400708 obj_desc = acpi_ns_get_attached_object(node);
709 if (!obj_desc || !obj_desc->device.gpe_block) {
710 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 }
712
713 /* Delete the GPE block (but not the device_object) */
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
716 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 obj_desc->device.gpe_block = NULL;
718 }
719
Len Brown4be44fc2005-08-05 00:44:28 -0400720 unlock_and_exit:
721 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
722 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723}
Robert Moore44f6c012005-04-18 22:49:35 -0400724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725EXPORT_SYMBOL(acpi_remove_gpe_block);