blob: 4eab4f5a10044399652118595ad5f91cc3b5a7c8 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acevents.h>
46#include <acpi/acnamesp.h>
47
48#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_enable
54 *
55 * PARAMETERS: None
56 *
57 * RETURN: Status
58 *
59 * DESCRIPTION: Transfers the system into ACPI mode.
60 *
61 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040062acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Len Brown4be44fc2005-08-05 00:44:28 -040064 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Bob Mooreb229cf92006-04-21 17:15:00 -040066 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Bob Moorec8573032007-02-02 19:48:23 +030068 /* ACPI tables must be present */
69
70 if (!acpi_tb_tables_loaded()) {
71 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
72 }
73
74 /* Check current mode */
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040077 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
78 "System is already in ACPI mode\n"));
79 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 /* Transition to ACPI mode */
81
Len Brown4be44fc2005-08-05 00:44:28 -040082 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
83 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050084 ACPI_ERROR((AE_INFO,
85 "Could not transition to ACPI mode"));
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
Bob Moore83135242006-10-03 00:00:00 -040096ACPI_EXPORT_SYMBOL(acpi_enable)
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098/*******************************************************************************
99 *
100 * FUNCTION: acpi_disable
101 *
102 * PARAMETERS: None
103 *
104 * RETURN: Status
105 *
Robert Moore44f6c012005-04-18 22:49:35 -0400106 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 *
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
Bob Mooreb229cf92006-04-21 17:15:00 -0400113 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400116 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
117 "System is already in legacy (non-ACPI) mode\n"));
118 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 /* Transition to LEGACY mode */
120
Len Brown4be44fc2005-08-05 00:44:28 -0400121 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Len Brown4be44fc2005-08-05 00:44:28 -0400123 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500124 ACPI_ERROR((AE_INFO,
125 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400126 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
Bob Moore83135242006-10-03 00:00:00 -0400135ACPI_EXPORT_SYMBOL(acpi_disable)
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/*******************************************************************************
138 *
139 * FUNCTION: acpi_enable_event
140 *
141 * PARAMETERS: Event - The fixed eventto be enabled
142 * Flags - Reserved
143 *
144 * RETURN: Status
145 *
146 * DESCRIPTION: Enable an ACPI event (fixed)
147 *
148 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400149acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Len Brown4be44fc2005-08-05 00:44:28 -0400151 acpi_status status = AE_OK;
152 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Bob Mooreb229cf92006-04-21 17:15:00 -0400154 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 /* Decode the Fixed Event */
157
158 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400159 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 }
161
162 /*
163 * Enable the requested fixed event (by writing a one to the
164 * enable register bit)
165 */
Len Brown4be44fc2005-08-05 00:44:28 -0400166 status =
167 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300168 enable_register_id, 1);
Len Brown4be44fc2005-08-05 00:44:28 -0400169 if (ACPI_FAILURE(status)) {
170 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172
173 /* Make sure that the hardware responded */
174
Len Brown4be44fc2005-08-05 00:44:28 -0400175 status =
176 acpi_get_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300177 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400178 if (ACPI_FAILURE(status)) {
179 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
181
182 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500183 ACPI_ERROR((AE_INFO,
184 "Could not enable %s event",
185 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400186 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
Len Brown4be44fc2005-08-05 00:44:28 -0400189 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Bob Moore83135242006-10-03 00:00:00 -0400192ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194/*******************************************************************************
195 *
196 * FUNCTION: acpi_set_gpe_type
197 *
198 * PARAMETERS: gpe_device - Parent GPE Device
199 * gpe_number - GPE level within the GPE block
200 * Type - New GPE type
201 *
202 * RETURN: Status
203 *
Robert Moore44f6c012005-04-18 22:49:35 -0400204 * DESCRIPTION: Set the type of an individual GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 *
206 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400207acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Len Brown4be44fc2005-08-05 00:44:28 -0400209 acpi_status status = AE_OK;
210 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Bob Mooreb229cf92006-04-21 17:15:00 -0400212 ACPI_FUNCTION_TRACE(acpi_set_gpe_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 /* Ensure that we have a valid GPE number */
215
Len Brown4be44fc2005-08-05 00:44:28 -0400216 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 if (!gpe_event_info) {
218 status = AE_BAD_PARAMETER;
219 goto unlock_and_exit;
220 }
221
222 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
Len Brown4be44fc2005-08-05 00:44:28 -0400223 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
226 /* Set the new type (will disable GPE if currently enabled) */
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228 status = acpi_ev_set_gpe_type(gpe_event_info, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 unlock_and_exit:
231 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Bob Moore83135242006-10-03 00:00:00 -0400234ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236/*******************************************************************************
237 *
238 * FUNCTION: acpi_enable_gpe
239 *
240 * PARAMETERS: gpe_device - Parent GPE Device
241 * gpe_number - GPE level within the GPE block
242 * Flags - Just enable, or also wake enable?
243 * Called from ISR or not
244 *
245 * RETURN: Status
246 *
247 * DESCRIPTION: Enable an ACPI event (general purpose)
248 *
249 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400250acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Len Brown4be44fc2005-08-05 00:44:28 -0400252 acpi_status status = AE_OK;
253 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Bob Mooreb229cf92006-04-21 17:15:00 -0400255 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /* Use semaphore lock if not executing at interrupt level */
258
259 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400260 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
261 if (ACPI_FAILURE(status)) {
262 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
264 }
265
266 /* Ensure that we have a valid GPE number */
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if (!gpe_event_info) {
270 status = AE_BAD_PARAMETER;
271 goto unlock_and_exit;
272 }
273
274 /* Perform the enable */
275
Len Brown4be44fc2005-08-05 00:44:28 -0400276 status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Len Brown4be44fc2005-08-05 00:44:28 -0400278 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400280 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
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 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400301acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Len Brown4be44fc2005-08-05 00:44:28 -0400303 acpi_status status = AE_OK;
304 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Bob Mooreb229cf92006-04-21 17:15:00 -0400306 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 /* Use semaphore lock if not executing at interrupt level */
309
310 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400311 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
312 if (ACPI_FAILURE(status)) {
313 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315 }
316
317 /* Ensure that we have a valid GPE number */
318
Len Brown4be44fc2005-08-05 00:44:28 -0400319 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (!gpe_event_info) {
321 status = AE_BAD_PARAMETER;
322 goto unlock_and_exit;
323 }
324
Len Brown4be44fc2005-08-05 00:44:28 -0400325 status = acpi_ev_disable_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Len Brown4be44fc2005-08-05 00:44:28 -0400327 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400329 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
Len Brown4be44fc2005-08-05 00:44:28 -0400331 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Bob Moore83135242006-10-03 00:00:00 -0400334ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336/*******************************************************************************
337 *
338 * FUNCTION: acpi_disable_event
339 *
340 * PARAMETERS: Event - The fixed eventto be enabled
341 * Flags - Reserved
342 *
343 * RETURN: Status
344 *
345 * DESCRIPTION: Disable an ACPI event (fixed)
346 *
347 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400348acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Len Brown4be44fc2005-08-05 00:44:28 -0400350 acpi_status status = AE_OK;
351 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Bob Mooreb229cf92006-04-21 17:15:00 -0400353 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 /* Decode the Fixed Event */
356
357 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400358 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
360
361 /*
362 * Disable the requested fixed event (by writing a zero to the
363 * enable register bit)
364 */
Len Brown4be44fc2005-08-05 00:44:28 -0400365 status =
366 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300367 enable_register_id, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400368 if (ACPI_FAILURE(status)) {
369 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
371
Len Brown4be44fc2005-08-05 00:44:28 -0400372 status =
373 acpi_get_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300374 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400375 if (ACPI_FAILURE(status)) {
376 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378
379 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500380 ACPI_ERROR((AE_INFO,
381 "Could not disable %s events",
382 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400383 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
385
Len Brown4be44fc2005-08-05 00:44:28 -0400386 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Bob Moore83135242006-10-03 00:00:00 -0400389ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391/*******************************************************************************
392 *
393 * FUNCTION: acpi_clear_event
394 *
395 * PARAMETERS: Event - The fixed event to be cleared
396 *
397 * RETURN: Status
398 *
399 * DESCRIPTION: Clear an ACPI event (fixed)
400 *
401 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400402acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Len Brown4be44fc2005-08-05 00:44:28 -0400404 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Bob Mooreb229cf92006-04-21 17:15:00 -0400406 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 /* Decode the Fixed Event */
409
410 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400411 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
413
414 /*
415 * Clear the requested fixed event (By writing a one to the
416 * status register bit)
417 */
Len Brown4be44fc2005-08-05 00:44:28 -0400418 status =
419 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300420 status_register_id, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Bob Moore83135242006-10-03 00:00:00 -0400425ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427/*******************************************************************************
428 *
429 * FUNCTION: acpi_clear_gpe
430 *
431 * PARAMETERS: gpe_device - Parent GPE Device
432 * gpe_number - GPE level within the GPE block
433 * Flags - Called from an ISR or not
434 *
435 * RETURN: Status
436 *
437 * DESCRIPTION: Clear an ACPI event (general purpose)
438 *
439 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400440acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Len Brown4be44fc2005-08-05 00:44:28 -0400442 acpi_status status = AE_OK;
443 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Bob Mooreb229cf92006-04-21 17:15:00 -0400445 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 /* Use semaphore lock if not executing at interrupt level */
448
449 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400450 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
451 if (ACPI_FAILURE(status)) {
452 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454 }
455
456 /* Ensure that we have a valid GPE number */
457
Len Brown4be44fc2005-08-05 00:44:28 -0400458 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (!gpe_event_info) {
460 status = AE_BAD_PARAMETER;
461 goto unlock_and_exit;
462 }
463
Len Brown4be44fc2005-08-05 00:44:28 -0400464 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Len Brown4be44fc2005-08-05 00:44:28 -0400466 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400468 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
Len Brown4be44fc2005-08-05 00:44:28 -0400470 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
472
Bob Moore83135242006-10-03 00:00:00 -0400473ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475#ifdef ACPI_FUTURE_USAGE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476/*******************************************************************************
477 *
478 * FUNCTION: acpi_get_event_status
479 *
480 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400481 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 * be returned
483 *
484 * RETURN: Status
485 *
486 * DESCRIPTION: Obtains and returns the current status of the event
487 *
488 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400489acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Len Brown4be44fc2005-08-05 00:44:28 -0400491 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Bob Mooreb229cf92006-04-21 17:15:00 -0400493 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400496 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498
499 /* Decode the Fixed Event */
500
501 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400502 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504
505 /* Get the status of the requested fixed event */
506
Len Brown4be44fc2005-08-05 00:44:28 -0400507 status =
508 acpi_get_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300509 status_register_id, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Len Brown4be44fc2005-08-05 00:44:28 -0400511 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512}
513
Bob Moore83135242006-10-03 00:00:00 -0400514ACPI_EXPORT_SYMBOL(acpi_get_event_status)
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516/*******************************************************************************
517 *
518 * FUNCTION: acpi_get_gpe_status
519 *
520 * PARAMETERS: gpe_device - Parent GPE Device
521 * gpe_number - GPE level within the GPE block
522 * Flags - Called from an ISR or not
Robert Moore44f6c012005-04-18 22:49:35 -0400523 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 * be returned
525 *
526 * RETURN: Status
527 *
528 * DESCRIPTION: Get status of an event (general purpose)
529 *
530 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400532acpi_get_gpe_status(acpi_handle gpe_device,
533 u32 gpe_number, u32 flags, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
Len Brown4be44fc2005-08-05 00:44:28 -0400535 acpi_status status = AE_OK;
536 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Bob Mooreb229cf92006-04-21 17:15:00 -0400538 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 /* Use semaphore lock if not executing at interrupt level */
541
542 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400543 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
544 if (ACPI_FAILURE(status)) {
545 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
547 }
548
549 /* Ensure that we have a valid GPE number */
550
Len Brown4be44fc2005-08-05 00:44:28 -0400551 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (!gpe_event_info) {
553 status = AE_BAD_PARAMETER;
554 goto unlock_and_exit;
555 }
556
557 /* Obtain status on the requested GPE number */
558
Len Brown4be44fc2005-08-05 00:44:28 -0400559 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400563 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
Len Brown4be44fc2005-08-05 00:44:28 -0400565 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
Bob Moore83135242006-10-03 00:00:00 -0400567
568ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
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 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400586acpi_install_gpe_block(acpi_handle gpe_device,
587 struct acpi_generic_address *gpe_block_address,
588 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Len Brown4be44fc2005-08-05 00:44:28 -0400590 acpi_status status;
591 union acpi_operand_object *obj_desc;
592 struct acpi_namespace_node *node;
593 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Bob Mooreb229cf92006-04-21 17:15:00 -0400595 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Len Brown4be44fc2005-08-05 00:44:28 -0400597 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
598 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600
Len Brown4be44fc2005-08-05 00:44:28 -0400601 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
602 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 return (status);
604 }
605
Len Brown4be44fc2005-08-05 00:44:28 -0400606 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 if (!node) {
608 status = AE_BAD_PARAMETER;
609 goto unlock_and_exit;
610 }
611
612 /*
613 * For user-installed GPE Block Devices, the gpe_block_base_number
614 * is always zero
615 */
Len Brown4be44fc2005-08-05 00:44:28 -0400616 status =
617 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
618 interrupt_number, &gpe_block);
619 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 goto unlock_and_exit;
621 }
622
Bob Moore96db2552005-11-02 00:00:00 -0500623 /* Run the _PRW methods and enable the GPEs */
624
625 status = acpi_ev_initialize_gpe_block(node, gpe_block);
626 if (ACPI_FAILURE(status)) {
627 goto unlock_and_exit;
628 }
629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /* Get the device_object attached to the node */
631
Len Brown4be44fc2005-08-05 00:44:28 -0400632 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* 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
Bob Moore83135242006-10-03 00:00:00 -0400664ACPI_EXPORT_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 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400677acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Len Brown4be44fc2005-08-05 00:44:28 -0400679 union acpi_operand_object *obj_desc;
680 acpi_status status;
681 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Bob Mooreb229cf92006-04-21 17:15:00 -0400683 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
685 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400686 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
690 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 return (status);
692 }
693
Len Brown4be44fc2005-08-05 00:44:28 -0400694 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (!node) {
696 status = AE_BAD_PARAMETER;
697 goto unlock_and_exit;
698 }
699
700 /* Get the device_object attached to the node */
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 obj_desc = acpi_ns_get_attached_object(node);
703 if (!obj_desc || !obj_desc->device.gpe_block) {
704 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 }
706
707 /* Delete the GPE block (but not the device_object) */
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
710 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 obj_desc->device.gpe_block = NULL;
712 }
713
Len Brown4be44fc2005-08-05 00:44:28 -0400714 unlock_and_exit:
715 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
716 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717}
Robert Moore44f6c012005-04-18 22:49:35 -0400718
Bob Moore83135242006-10-03 00:00:00 -0400719ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)