1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <linux/module.h>
46 #include <acpi/acpi.h>
47 #include <acpi/acevents.h>
48 #include <acpi/acnamesp.h>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME("evxfevnt")
53 /*******************************************************************************
55 * FUNCTION: acpi_enable
61 * DESCRIPTION: Transfers the system into ACPI mode.
63 ******************************************************************************/
64 acpi_status
acpi_enable(void)
66 acpi_status status
= AE_OK
;
68 ACPI_FUNCTION_TRACE("acpi_enable");
70 /* Make sure we have the FADT */
73 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
74 "No FADT information present!\n"));
75 return_ACPI_STATUS(AE_NO_ACPI_TABLES
);
78 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI
) {
79 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
80 "System is already in ACPI mode\n"));
82 /* Transition to ACPI mode */
84 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
);
90 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
91 "Transition to ACPI mode successful\n"));
94 return_ACPI_STATUS(status
);
97 /*******************************************************************************
99 * FUNCTION: acpi_disable
105 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
107 ******************************************************************************/
109 acpi_status
acpi_disable(void)
111 acpi_status status
= AE_OK
;
113 ACPI_FUNCTION_TRACE("acpi_disable");
115 if (!acpi_gbl_FADT
) {
116 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
117 "No FADT information present!\n"));
118 return_ACPI_STATUS(AE_NO_ACPI_TABLES
);
121 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY
) {
122 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
123 "System is already in legacy (non-ACPI) mode\n"));
125 /* Transition to LEGACY mode */
127 status
= acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY
);
129 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
);
135 ACPI_DEBUG_PRINT((ACPI_DB_INIT
, "ACPI mode disabled\n"));
138 return_ACPI_STATUS(status
);
141 /*******************************************************************************
143 * FUNCTION: acpi_enable_event
145 * PARAMETERS: Event - The fixed eventto be enabled
150 * DESCRIPTION: Enable an ACPI event (fixed)
152 ******************************************************************************/
154 acpi_status
acpi_enable_event(u32 event
, u32 flags
)
156 acpi_status status
= AE_OK
;
159 ACPI_FUNCTION_TRACE("acpi_enable_event");
161 /* Decode the Fixed Event */
163 if (event
> ACPI_EVENT_MAX
) {
164 return_ACPI_STATUS(AE_BAD_PARAMETER
);
168 * Enable the requested fixed event (by writing a one to the
169 * enable register bit)
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
);
178 /* Make sure that the hardware responded */
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
);
188 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
);
194 return_ACPI_STATUS(status
);
197 EXPORT_SYMBOL(acpi_enable_event
);
199 /*******************************************************************************
201 * FUNCTION: acpi_set_gpe_type
203 * PARAMETERS: gpe_device - Parent GPE Device
204 * gpe_number - GPE level within the GPE block
205 * Type - New GPE type
209 * DESCRIPTION: Set the type of an individual GPE
211 ******************************************************************************/
213 acpi_status
acpi_set_gpe_type(acpi_handle gpe_device
, u32 gpe_number
, u8 type
)
215 acpi_status status
= AE_OK
;
216 struct acpi_gpe_event_info
*gpe_event_info
;
218 ACPI_FUNCTION_TRACE("acpi_set_gpe_type");
220 /* Ensure that we have a valid GPE number */
222 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
223 if (!gpe_event_info
) {
224 status
= AE_BAD_PARAMETER
;
225 goto unlock_and_exit
;
228 if ((gpe_event_info
->flags
& ACPI_GPE_TYPE_MASK
) == type
) {
229 return_ACPI_STATUS(AE_OK
);
232 /* Set the new type (will disable GPE if currently enabled) */
234 status
= acpi_ev_set_gpe_type(gpe_event_info
, type
);
237 return_ACPI_STATUS(status
);
240 EXPORT_SYMBOL(acpi_set_gpe_type
);
242 /*******************************************************************************
244 * FUNCTION: acpi_enable_gpe
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
253 * DESCRIPTION: Enable an ACPI event (general purpose)
255 ******************************************************************************/
257 acpi_status
acpi_enable_gpe(acpi_handle gpe_device
, u32 gpe_number
, u32 flags
)
259 acpi_status status
= AE_OK
;
260 struct acpi_gpe_event_info
*gpe_event_info
;
262 ACPI_FUNCTION_TRACE("acpi_enable_gpe");
264 /* Use semaphore lock if not executing at interrupt level */
266 if (flags
& ACPI_NOT_ISR
) {
267 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
268 if (ACPI_FAILURE(status
)) {
269 return_ACPI_STATUS(status
);
273 /* Ensure that we have a valid GPE number */
275 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
276 if (!gpe_event_info
) {
277 status
= AE_BAD_PARAMETER
;
278 goto unlock_and_exit
;
281 /* Perform the enable */
283 status
= acpi_ev_enable_gpe(gpe_event_info
, TRUE
);
286 if (flags
& ACPI_NOT_ISR
) {
287 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
289 return_ACPI_STATUS(status
);
292 EXPORT_SYMBOL(acpi_enable_gpe
);
294 /*******************************************************************************
296 * FUNCTION: acpi_disable_gpe
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
305 * DESCRIPTION: Disable an ACPI event (general purpose)
307 ******************************************************************************/
309 acpi_status
acpi_disable_gpe(acpi_handle gpe_device
, u32 gpe_number
, u32 flags
)
311 acpi_status status
= AE_OK
;
312 struct acpi_gpe_event_info
*gpe_event_info
;
314 ACPI_FUNCTION_TRACE("acpi_disable_gpe");
316 /* Use semaphore lock if not executing at interrupt level */
318 if (flags
& ACPI_NOT_ISR
) {
319 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
320 if (ACPI_FAILURE(status
)) {
321 return_ACPI_STATUS(status
);
325 /* Ensure that we have a valid GPE number */
327 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
328 if (!gpe_event_info
) {
329 status
= AE_BAD_PARAMETER
;
330 goto unlock_and_exit
;
333 status
= acpi_ev_disable_gpe(gpe_event_info
);
336 if (flags
& ACPI_NOT_ISR
) {
337 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
339 return_ACPI_STATUS(status
);
342 /*******************************************************************************
344 * FUNCTION: acpi_disable_event
346 * PARAMETERS: Event - The fixed eventto be enabled
351 * DESCRIPTION: Disable an ACPI event (fixed)
353 ******************************************************************************/
355 acpi_status
acpi_disable_event(u32 event
, u32 flags
)
357 acpi_status status
= AE_OK
;
360 ACPI_FUNCTION_TRACE("acpi_disable_event");
362 /* Decode the Fixed Event */
364 if (event
> ACPI_EVENT_MAX
) {
365 return_ACPI_STATUS(AE_BAD_PARAMETER
);
369 * Disable the requested fixed event (by writing a zero to the
370 * enable register bit)
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
);
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
);
387 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
);
393 return_ACPI_STATUS(status
);
396 EXPORT_SYMBOL(acpi_disable_event
);
398 /*******************************************************************************
400 * FUNCTION: acpi_clear_event
402 * PARAMETERS: Event - The fixed event to be cleared
406 * DESCRIPTION: Clear an ACPI event (fixed)
408 ******************************************************************************/
410 acpi_status
acpi_clear_event(u32 event
)
412 acpi_status status
= AE_OK
;
414 ACPI_FUNCTION_TRACE("acpi_clear_event");
416 /* Decode the Fixed Event */
418 if (event
> ACPI_EVENT_MAX
) {
419 return_ACPI_STATUS(AE_BAD_PARAMETER
);
423 * Clear the requested fixed event (By writing a one to the
424 * status register bit)
427 acpi_set_register(acpi_gbl_fixed_event_info
[event
].
428 status_register_id
, 1, ACPI_MTX_LOCK
);
430 return_ACPI_STATUS(status
);
433 EXPORT_SYMBOL(acpi_clear_event
);
435 /*******************************************************************************
437 * FUNCTION: acpi_clear_gpe
439 * PARAMETERS: gpe_device - Parent GPE Device
440 * gpe_number - GPE level within the GPE block
441 * Flags - Called from an ISR or not
445 * DESCRIPTION: Clear an ACPI event (general purpose)
447 ******************************************************************************/
449 acpi_status
acpi_clear_gpe(acpi_handle gpe_device
, u32 gpe_number
, u32 flags
)
451 acpi_status status
= AE_OK
;
452 struct acpi_gpe_event_info
*gpe_event_info
;
454 ACPI_FUNCTION_TRACE("acpi_clear_gpe");
456 /* Use semaphore lock if not executing at interrupt level */
458 if (flags
& ACPI_NOT_ISR
) {
459 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
460 if (ACPI_FAILURE(status
)) {
461 return_ACPI_STATUS(status
);
465 /* Ensure that we have a valid GPE number */
467 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
468 if (!gpe_event_info
) {
469 status
= AE_BAD_PARAMETER
;
470 goto unlock_and_exit
;
473 status
= acpi_hw_clear_gpe(gpe_event_info
);
476 if (flags
& ACPI_NOT_ISR
) {
477 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
479 return_ACPI_STATUS(status
);
482 #ifdef ACPI_FUTURE_USAGE
483 /*******************************************************************************
485 * FUNCTION: acpi_get_event_status
487 * PARAMETERS: Event - The fixed event
488 * event_status - Where the current status of the event will
493 * DESCRIPTION: Obtains and returns the current status of the event
495 ******************************************************************************/
497 acpi_status
acpi_get_event_status(u32 event
, acpi_event_status
* event_status
)
499 acpi_status status
= AE_OK
;
501 ACPI_FUNCTION_TRACE("acpi_get_event_status");
504 return_ACPI_STATUS(AE_BAD_PARAMETER
);
507 /* Decode the Fixed Event */
509 if (event
> ACPI_EVENT_MAX
) {
510 return_ACPI_STATUS(AE_BAD_PARAMETER
);
513 /* Get the status of the requested fixed event */
516 acpi_get_register(acpi_gbl_fixed_event_info
[event
].
517 status_register_id
, event_status
, ACPI_MTX_LOCK
);
519 return_ACPI_STATUS(status
);
522 /*******************************************************************************
524 * FUNCTION: acpi_get_gpe_status
526 * PARAMETERS: gpe_device - Parent GPE Device
527 * gpe_number - GPE level within the GPE block
528 * Flags - Called from an ISR or not
529 * event_status - Where the current status of the event will
534 * DESCRIPTION: Get status of an event (general purpose)
536 ******************************************************************************/
539 acpi_get_gpe_status(acpi_handle gpe_device
,
540 u32 gpe_number
, u32 flags
, acpi_event_status
* event_status
)
542 acpi_status status
= AE_OK
;
543 struct acpi_gpe_event_info
*gpe_event_info
;
545 ACPI_FUNCTION_TRACE("acpi_get_gpe_status");
547 /* Use semaphore lock if not executing at interrupt level */
549 if (flags
& ACPI_NOT_ISR
) {
550 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
551 if (ACPI_FAILURE(status
)) {
552 return_ACPI_STATUS(status
);
556 /* Ensure that we have a valid GPE number */
558 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
559 if (!gpe_event_info
) {
560 status
= AE_BAD_PARAMETER
;
561 goto unlock_and_exit
;
564 /* Obtain status on the requested GPE number */
566 status
= acpi_hw_get_gpe_status(gpe_event_info
, event_status
);
569 if (flags
& ACPI_NOT_ISR
) {
570 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
572 return_ACPI_STATUS(status
);
574 #endif /* ACPI_FUTURE_USAGE */
576 /*******************************************************************************
578 * FUNCTION: acpi_install_gpe_block
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
583 * interrupt_number - H/W interrupt for the block
587 * DESCRIPTION: Create and Install a block of GPE registers
589 ******************************************************************************/
592 acpi_install_gpe_block(acpi_handle gpe_device
,
593 struct acpi_generic_address
*gpe_block_address
,
594 u32 register_count
, u32 interrupt_number
)
597 union acpi_operand_object
*obj_desc
;
598 struct acpi_namespace_node
*node
;
599 struct acpi_gpe_block_info
*gpe_block
;
601 ACPI_FUNCTION_TRACE("acpi_install_gpe_block");
603 if ((!gpe_device
) || (!gpe_block_address
) || (!register_count
)) {
604 return_ACPI_STATUS(AE_BAD_PARAMETER
);
607 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
608 if (ACPI_FAILURE(status
)) {
612 node
= acpi_ns_map_handle_to_node(gpe_device
);
614 status
= AE_BAD_PARAMETER
;
615 goto unlock_and_exit
;
619 * For user-installed GPE Block Devices, the gpe_block_base_number
623 acpi_ev_create_gpe_block(node
, gpe_block_address
, register_count
, 0,
624 interrupt_number
, &gpe_block
);
625 if (ACPI_FAILURE(status
)) {
626 goto unlock_and_exit
;
629 /* Get the device_object attached to the node */
631 obj_desc
= acpi_ns_get_attached_object(node
);
633 /* No object, create a new one */
635 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_DEVICE
);
637 status
= AE_NO_MEMORY
;
638 goto unlock_and_exit
;
642 acpi_ns_attach_object(node
, obj_desc
, ACPI_TYPE_DEVICE
);
644 /* Remove local reference to the object */
646 acpi_ut_remove_reference(obj_desc
);
648 if (ACPI_FAILURE(status
)) {
649 goto unlock_and_exit
;
653 /* Install the GPE block in the device_object */
655 obj_desc
->device
.gpe_block
= gpe_block
;
658 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
659 return_ACPI_STATUS(status
);
662 EXPORT_SYMBOL(acpi_install_gpe_block
);
664 /*******************************************************************************
666 * FUNCTION: acpi_remove_gpe_block
668 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
672 * DESCRIPTION: Remove a previously installed block of GPE registers
674 ******************************************************************************/
676 acpi_status
acpi_remove_gpe_block(acpi_handle gpe_device
)
678 union acpi_operand_object
*obj_desc
;
680 struct acpi_namespace_node
*node
;
682 ACPI_FUNCTION_TRACE("acpi_remove_gpe_block");
685 return_ACPI_STATUS(AE_BAD_PARAMETER
);
688 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
689 if (ACPI_FAILURE(status
)) {
693 node
= acpi_ns_map_handle_to_node(gpe_device
);
695 status
= AE_BAD_PARAMETER
;
696 goto unlock_and_exit
;
699 /* Get the device_object attached to the node */
701 obj_desc
= acpi_ns_get_attached_object(node
);
702 if (!obj_desc
|| !obj_desc
->device
.gpe_block
) {
703 return_ACPI_STATUS(AE_NULL_OBJECT
);
706 /* Delete the GPE block (but not the device_object) */
708 status
= acpi_ev_delete_gpe_block(obj_desc
->device
.gpe_block
);
709 if (ACPI_SUCCESS(status
)) {
710 obj_desc
->device
.gpe_block
= NULL
;
714 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
715 return_ACPI_STATUS(status
);
718 EXPORT_SYMBOL(acpi_remove_gpe_block
);