blob: 39db00874a22949dfe9fb525172df0803e715510 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acevents.h>
46#include <acpi/acnamesp.h>
Bob Moore1a666f82007-02-02 19:48:23 +030047#include <acpi/actables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_enable
55 *
56 * PARAMETERS: None
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: Transfers the system into ACPI mode.
61 *
62 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040063acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Len Brown4be44fc2005-08-05 00:44:28 -040065 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Bob Mooreb229cf92006-04-21 17:15:00 -040067 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Bob Moorec8573032007-02-02 19:48:23 +030069 /* ACPI tables must be present */
70
71 if (!acpi_tb_tables_loaded()) {
72 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
73 }
74
75 /* Check current mode */
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 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 Mooreb8e4d892006-01-27 16:43:00 -050085 ACPI_ERROR((AE_INFO,
86 "Could not transition to ACPI mode"));
Len Brown4be44fc2005-08-05 00:44:28 -040087 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
Bob Moore83135242006-10-03 00:00:00 -040097ACPI_EXPORT_SYMBOL(acpi_enable)
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/*******************************************************************************
100 *
101 * FUNCTION: acpi_disable
102 *
103 * PARAMETERS: None
104 *
105 * RETURN: Status
106 *
Robert Moore44f6c012005-04-18 22:49:35 -0400107 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 *
109 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400110acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Len Brown4be44fc2005-08-05 00:44:28 -0400112 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Bob Mooreb229cf92006-04-21 17:15:00 -0400114 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400117 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
118 "System is already in legacy (non-ACPI) mode\n"));
119 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 /* Transition to LEGACY mode */
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Len Brown4be44fc2005-08-05 00:44:28 -0400124 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500125 ACPI_ERROR((AE_INFO,
126 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400127 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129
Len Brown4be44fc2005-08-05 00:44:28 -0400130 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
Len Brown4be44fc2005-08-05 00:44:28 -0400133 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Bob Moore83135242006-10-03 00:00:00 -0400136ACPI_EXPORT_SYMBOL(acpi_disable)
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 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400150acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Len Brown4be44fc2005-08-05 00:44:28 -0400152 acpi_status status = AE_OK;
153 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Bob Mooreb229cf92006-04-21 17:15:00 -0400155 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 /* Decode the Fixed Event */
158
159 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400160 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
163 /*
164 * Enable the requested fixed event (by writing a one to the
165 * enable register bit)
166 */
Len Brown4be44fc2005-08-05 00:44:28 -0400167 status =
168 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300169 enable_register_id, 1);
Len Brown4be44fc2005-08-05 00:44:28 -0400170 if (ACPI_FAILURE(status)) {
171 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173
174 /* Make sure that the hardware responded */
175
Len Brown4be44fc2005-08-05 00:44:28 -0400176 status =
177 acpi_get_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300178 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400179 if (ACPI_FAILURE(status)) {
180 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
182
183 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500184 ACPI_ERROR((AE_INFO,
185 "Could not enable %s event",
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
Bob Moore83135242006-10-03 00:00:00 -0400193ACPI_EXPORT_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 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400208acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Len Brown4be44fc2005-08-05 00:44:28 -0400210 acpi_status status = AE_OK;
211 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Bob Mooreb229cf92006-04-21 17:15:00 -0400213 ACPI_FUNCTION_TRACE(acpi_set_gpe_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 /* Ensure that we have a valid GPE number */
216
Len Brown4be44fc2005-08-05 00:44:28 -0400217 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 if (!gpe_event_info) {
219 status = AE_BAD_PARAMETER;
220 goto unlock_and_exit;
221 }
222
223 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
Len Brown4be44fc2005-08-05 00:44:28 -0400224 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
226
227 /* Set the new type (will disable GPE if currently enabled) */
228
Len Brown4be44fc2005-08-05 00:44:28 -0400229 status = acpi_ev_set_gpe_type(gpe_event_info, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Len Brown4be44fc2005-08-05 00:44:28 -0400231 unlock_and_exit:
232 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Bob Moore83135242006-10-03 00:00:00 -0400235ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237/*******************************************************************************
238 *
239 * FUNCTION: acpi_enable_gpe
240 *
241 * PARAMETERS: gpe_device - Parent GPE Device
242 * gpe_number - GPE level within the GPE block
243 * Flags - Just enable, or also wake enable?
244 * Called from ISR or not
245 *
246 * RETURN: Status
247 *
248 * DESCRIPTION: Enable an ACPI event (general purpose)
249 *
250 ******************************************************************************/
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400251acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Len Brown4be44fc2005-08-05 00:44:28 -0400253 acpi_status status = AE_OK;
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400254 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400255 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Bob Mooreb229cf92006-04-21 17:15:00 -0400257 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400259 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 /* Ensure that we have a valid GPE number */
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 if (!gpe_event_info) {
265 status = AE_BAD_PARAMETER;
266 goto unlock_and_exit;
267 }
268
269 /* Perform the enable */
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271 status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 unlock_and_exit:
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400274 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400275 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Bob Moore83135242006-10-03 00:00:00 -0400278ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280/*******************************************************************************
281 *
282 * FUNCTION: acpi_disable_gpe
283 *
284 * PARAMETERS: gpe_device - Parent GPE Device
285 * gpe_number - GPE level within the GPE block
286 * Flags - Just disable, or also wake disable?
287 * Called from ISR or not
288 *
289 * RETURN: Status
290 *
291 * DESCRIPTION: Disable an ACPI event (general purpose)
292 *
293 ******************************************************************************/
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400294acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Len Brown4be44fc2005-08-05 00:44:28 -0400296 acpi_status status = AE_OK;
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400297 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400298 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Bob Mooreb229cf92006-04-21 17:15:00 -0400300 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400302 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 /* Ensure that we have a valid GPE number */
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (!gpe_event_info) {
307 status = AE_BAD_PARAMETER;
308 goto unlock_and_exit;
309 }
310
Len Brown4be44fc2005-08-05 00:44:28 -0400311 status = acpi_ev_disable_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400313unlock_and_exit:
314 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400315 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Bob Moore83135242006-10-03 00:00:00 -0400318ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320/*******************************************************************************
321 *
322 * FUNCTION: acpi_disable_event
323 *
324 * PARAMETERS: Event - The fixed eventto be enabled
325 * Flags - Reserved
326 *
327 * RETURN: Status
328 *
329 * DESCRIPTION: Disable an ACPI event (fixed)
330 *
331 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400332acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
Len Brown4be44fc2005-08-05 00:44:28 -0400334 acpi_status status = AE_OK;
335 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Bob Mooreb229cf92006-04-21 17:15:00 -0400337 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 /* Decode the Fixed Event */
340
341 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400342 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
344
345 /*
346 * Disable the requested fixed event (by writing a zero to the
347 * enable register bit)
348 */
Len Brown4be44fc2005-08-05 00:44:28 -0400349 status =
350 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300351 enable_register_id, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400352 if (ACPI_FAILURE(status)) {
353 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 status =
357 acpi_get_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300358 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400359 if (ACPI_FAILURE(status)) {
360 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
363 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500364 ACPI_ERROR((AE_INFO,
365 "Could not disable %s events",
366 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400367 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
Len Brown4be44fc2005-08-05 00:44:28 -0400370 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Bob Moore83135242006-10-03 00:00:00 -0400373ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375/*******************************************************************************
376 *
377 * FUNCTION: acpi_clear_event
378 *
379 * PARAMETERS: Event - The fixed event to be cleared
380 *
381 * RETURN: Status
382 *
383 * DESCRIPTION: Clear an ACPI event (fixed)
384 *
385 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400386acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Len Brown4be44fc2005-08-05 00:44:28 -0400388 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Bob Mooreb229cf92006-04-21 17:15:00 -0400390 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* Decode the Fixed Event */
393
394 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400395 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
397
398 /*
399 * Clear the requested fixed event (By writing a one to the
400 * status register bit)
401 */
Len Brown4be44fc2005-08-05 00:44:28 -0400402 status =
403 acpi_set_register(acpi_gbl_fixed_event_info[event].
Bob Moored8c71b62007-02-02 19:48:21 +0300404 status_register_id, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Len Brown4be44fc2005-08-05 00:44:28 -0400406 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Bob Moore83135242006-10-03 00:00:00 -0400409ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411/*******************************************************************************
412 *
413 * FUNCTION: acpi_clear_gpe
414 *
415 * PARAMETERS: gpe_device - Parent GPE Device
416 * gpe_number - GPE level within the GPE block
417 * Flags - Called from an ISR or not
418 *
419 * RETURN: Status
420 *
421 * DESCRIPTION: Clear an ACPI event (general purpose)
422 *
423 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400424acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
Len Brown4be44fc2005-08-05 00:44:28 -0400426 acpi_status status = AE_OK;
427 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Bob Mooreb229cf92006-04-21 17:15:00 -0400429 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 /* Use semaphore lock if not executing at interrupt level */
432
433 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400434 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
435 if (ACPI_FAILURE(status)) {
436 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438 }
439
440 /* Ensure that we have a valid GPE number */
441
Len Brown4be44fc2005-08-05 00:44:28 -0400442 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (!gpe_event_info) {
444 status = AE_BAD_PARAMETER;
445 goto unlock_and_exit;
446 }
447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 status = acpi_hw_clear_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Len Brown4be44fc2005-08-05 00:44:28 -0400450 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400452 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
Len Brown4be44fc2005-08-05 00:44:28 -0400454 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456
Bob Moore83135242006-10-03 00:00:00 -0400457ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458/*******************************************************************************
459 *
460 * FUNCTION: acpi_get_event_status
461 *
462 * PARAMETERS: Event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400463 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 * be returned
465 *
466 * RETURN: Status
467 *
468 * DESCRIPTION: Obtains and returns the current status of the event
469 *
470 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400471acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Len Brown4be44fc2005-08-05 00:44:28 -0400473 acpi_status status = AE_OK;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800474 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Bob Mooreb229cf92006-04-21 17:15:00 -0400476 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400479 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
481
482 /* Decode the Fixed Event */
483
484 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400485 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487
488 /* Get the status of the requested fixed event */
489
Len Brown4be44fc2005-08-05 00:44:28 -0400490 status =
491 acpi_get_register(acpi_gbl_fixed_event_info[event].
Zhang Rui71b58cb2008-06-20 09:42:47 +0800492 enable_register_id, &value);
493 if (ACPI_FAILURE(status))
494 return_ACPI_STATUS(status);
495
496 *event_status = value;
497
498 status =
499 acpi_get_register(acpi_gbl_fixed_event_info[event].
500 status_register_id, &value);
501 if (ACPI_FAILURE(status))
502 return_ACPI_STATUS(status);
503
504 if (value)
505 *event_status |= ACPI_EVENT_FLAG_SET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Len Brown4be44fc2005-08-05 00:44:28 -0400507 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508}
509
Bob Moore83135242006-10-03 00:00:00 -0400510ACPI_EXPORT_SYMBOL(acpi_get_event_status)
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512/*******************************************************************************
513 *
514 * FUNCTION: acpi_get_gpe_status
515 *
516 * PARAMETERS: gpe_device - Parent GPE Device
517 * gpe_number - GPE level within the GPE block
518 * Flags - Called from an ISR or not
Robert Moore44f6c012005-04-18 22:49:35 -0400519 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 * be returned
521 *
522 * RETURN: Status
523 *
524 * DESCRIPTION: Get status of an event (general purpose)
525 *
526 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400528acpi_get_gpe_status(acpi_handle gpe_device,
529 u32 gpe_number, u32 flags, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
Len Brown4be44fc2005-08-05 00:44:28 -0400531 acpi_status status = AE_OK;
532 struct acpi_gpe_event_info *gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Bob Mooreb229cf92006-04-21 17:15:00 -0400534 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 /* Use semaphore lock if not executing at interrupt level */
537
538 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400539 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
540 if (ACPI_FAILURE(status)) {
541 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543 }
544
545 /* Ensure that we have a valid GPE number */
546
Len Brown4be44fc2005-08-05 00:44:28 -0400547 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (!gpe_event_info) {
549 status = AE_BAD_PARAMETER;
550 goto unlock_and_exit;
551 }
552
553 /* Obtain status on the requested GPE number */
554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Len Brown4be44fc2005-08-05 00:44:28 -0400557 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (flags & ACPI_NOT_ISR) {
Len Brown4be44fc2005-08-05 00:44:28 -0400559 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
Len Brown4be44fc2005-08-05 00:44:28 -0400561 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
Bob Moore83135242006-10-03 00:00:00 -0400563
564ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565/*******************************************************************************
566 *
567 * FUNCTION: acpi_install_gpe_block
568 *
569 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
570 * gpe_block_address - Address and space_iD
571 * register_count - Number of GPE register pairs in the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400572 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 *
574 * RETURN: Status
575 *
576 * DESCRIPTION: Create and Install a block of GPE registers
577 *
578 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400580acpi_install_gpe_block(acpi_handle gpe_device,
581 struct acpi_generic_address *gpe_block_address,
582 u32 register_count, u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
Len Brown4be44fc2005-08-05 00:44:28 -0400584 acpi_status status;
585 union acpi_operand_object *obj_desc;
586 struct acpi_namespace_node *node;
587 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Bob Mooreb229cf92006-04-21 17:15:00 -0400589 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Len Brown4be44fc2005-08-05 00:44:28 -0400591 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
592 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
594
Len Brown4be44fc2005-08-05 00:44:28 -0400595 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
596 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 return (status);
598 }
599
Len Brown4be44fc2005-08-05 00:44:28 -0400600 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 if (!node) {
602 status = AE_BAD_PARAMETER;
603 goto unlock_and_exit;
604 }
605
606 /*
607 * For user-installed GPE Block Devices, the gpe_block_base_number
608 * is always zero
609 */
Len Brown4be44fc2005-08-05 00:44:28 -0400610 status =
611 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
612 interrupt_number, &gpe_block);
613 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 goto unlock_and_exit;
615 }
616
Bob Moore96db2552005-11-02 00:00:00 -0500617 /* Run the _PRW methods and enable the GPEs */
618
619 status = acpi_ev_initialize_gpe_block(node, gpe_block);
620 if (ACPI_FAILURE(status)) {
621 goto unlock_and_exit;
622 }
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 /* Get the device_object attached to the node */
625
Len Brown4be44fc2005-08-05 00:44:28 -0400626 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 /* No object, create a new one */
630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 if (!obj_desc) {
633 status = AE_NO_MEMORY;
634 goto unlock_and_exit;
635 }
636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 status =
638 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 /* Remove local reference to the object */
641
Len Brown4be44fc2005-08-05 00:44:28 -0400642 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Len Brown4be44fc2005-08-05 00:44:28 -0400644 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 goto unlock_and_exit;
646 }
647 }
648
649 /* Install the GPE block in the device_object */
650
651 obj_desc->device.gpe_block = gpe_block;
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653 unlock_and_exit:
654 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
655 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Bob Moore83135242006-10-03 00:00:00 -0400658ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660/*******************************************************************************
661 *
662 * FUNCTION: acpi_remove_gpe_block
663 *
664 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
665 *
666 * RETURN: Status
667 *
668 * DESCRIPTION: Remove a previously installed block of GPE registers
669 *
670 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400671acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
Len Brown4be44fc2005-08-05 00:44:28 -0400673 union acpi_operand_object *obj_desc;
674 acpi_status status;
675 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Bob Mooreb229cf92006-04-21 17:15:00 -0400677 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 if (!gpe_device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400680 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682
Len Brown4be44fc2005-08-05 00:44:28 -0400683 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
684 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 return (status);
686 }
687
Len Brown4be44fc2005-08-05 00:44:28 -0400688 node = acpi_ns_map_handle_to_node(gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 if (!node) {
690 status = AE_BAD_PARAMETER;
691 goto unlock_and_exit;
692 }
693
694 /* Get the device_object attached to the node */
695
Len Brown4be44fc2005-08-05 00:44:28 -0400696 obj_desc = acpi_ns_get_attached_object(node);
697 if (!obj_desc || !obj_desc->device.gpe_block) {
698 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700
701 /* Delete the GPE block (but not the device_object) */
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
704 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 obj_desc->device.gpe_block = NULL;
706 }
707
Len Brown4be44fc2005-08-05 00:44:28 -0400708 unlock_and_exit:
709 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
710 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
Robert Moore44f6c012005-04-18 22:49:35 -0400712
Bob Moore83135242006-10-03 00:00:00 -0400713ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)