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")
54 /*******************************************************************************
56 * FUNCTION: acpi_enable
62 * DESCRIPTION: Transfers the system into ACPI mode.
64 ******************************************************************************/
69 acpi_status status
= AE_OK
;
72 ACPI_FUNCTION_TRACE ("acpi_enable");
75 /* Make sure we have the FADT*/
78 ACPI_DEBUG_PRINT ((ACPI_DB_WARN
, "No FADT information present!\n"));
79 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
82 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI
) {
83 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
, "System is already in ACPI mode\n"));
86 /* Transition to ACPI mode */
88 status
= acpi_hw_set_mode (ACPI_SYS_MODE_ACPI
);
89 if (ACPI_FAILURE (status
)) {
90 ACPI_REPORT_ERROR (("Could not transition to ACPI mode.\n"));
91 return_ACPI_STATUS (status
);
94 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
, "Transition to ACPI mode successful\n"));
97 return_ACPI_STATUS (status
);
101 /*******************************************************************************
103 * FUNCTION: acpi_disable
109 * DESCRIPTION: Transfers the system into LEGACY mode.
111 ******************************************************************************/
116 acpi_status status
= AE_OK
;
119 ACPI_FUNCTION_TRACE ("acpi_disable");
122 if (!acpi_gbl_FADT
) {
123 ACPI_DEBUG_PRINT ((ACPI_DB_WARN
, "No FADT information present!\n"));
124 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
127 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY
) {
128 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
, "System is already in legacy (non-ACPI) mode\n"));
131 /* Transition to LEGACY mode */
133 status
= acpi_hw_set_mode (ACPI_SYS_MODE_LEGACY
);
135 if (ACPI_FAILURE (status
)) {
136 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Could not exit ACPI mode to legacy mode"));
137 return_ACPI_STATUS (status
);
140 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
, "ACPI mode disabled\n"));
143 return_ACPI_STATUS (status
);
147 /*******************************************************************************
149 * FUNCTION: acpi_enable_event
151 * PARAMETERS: Event - The fixed eventto be enabled
156 * DESCRIPTION: Enable an ACPI event (fixed)
158 ******************************************************************************/
165 acpi_status status
= AE_OK
;
169 ACPI_FUNCTION_TRACE ("acpi_enable_event");
172 /* Decode the Fixed Event */
174 if (event
> ACPI_EVENT_MAX
) {
175 return_ACPI_STATUS (AE_BAD_PARAMETER
);
179 * Enable the requested fixed event (by writing a one to the
180 * enable register bit)
182 status
= acpi_set_register (acpi_gbl_fixed_event_info
[event
].enable_register_id
,
184 if (ACPI_FAILURE (status
)) {
185 return_ACPI_STATUS (status
);
188 /* Make sure that the hardware responded */
190 status
= acpi_get_register (acpi_gbl_fixed_event_info
[event
].enable_register_id
,
191 &value
, ACPI_MTX_LOCK
);
192 if (ACPI_FAILURE (status
)) {
193 return_ACPI_STATUS (status
);
197 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
198 "Could not enable %s event\n", acpi_ut_get_event_name (event
)));
199 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE
);
202 return_ACPI_STATUS (status
);
204 EXPORT_SYMBOL(acpi_enable_event
);
207 /*******************************************************************************
209 * FUNCTION: acpi_set_gpe_type
211 * PARAMETERS: gpe_device - Parent GPE Device
212 * gpe_number - GPE level within the GPE block
213 * Type - New GPE type
217 * DESCRIPTION: Enable an ACPI event (general purpose)
219 ******************************************************************************/
223 acpi_handle gpe_device
,
227 acpi_status status
= AE_OK
;
228 struct acpi_gpe_event_info
*gpe_event_info
;
231 ACPI_FUNCTION_TRACE ("acpi_set_gpe_type");
234 /* Ensure that we have a valid GPE number */
236 gpe_event_info
= acpi_ev_get_gpe_event_info (gpe_device
, gpe_number
);
237 if (!gpe_event_info
) {
238 status
= AE_BAD_PARAMETER
;
239 goto unlock_and_exit
;
242 if ((gpe_event_info
->flags
& ACPI_GPE_TYPE_MASK
) == type
) {
243 return_ACPI_STATUS (AE_OK
);
246 /* Set the new type (will disable GPE if currently enabled) */
248 status
= acpi_ev_set_gpe_type (gpe_event_info
, type
);
251 return_ACPI_STATUS (status
);
253 EXPORT_SYMBOL(acpi_set_gpe_type
);
256 /*******************************************************************************
258 * FUNCTION: acpi_enable_gpe
260 * PARAMETERS: gpe_device - Parent GPE Device
261 * gpe_number - GPE level within the GPE block
262 * Flags - Just enable, or also wake enable?
263 * Called from ISR or not
267 * DESCRIPTION: Enable an ACPI event (general purpose)
269 ******************************************************************************/
273 acpi_handle gpe_device
,
277 acpi_status status
= AE_OK
;
278 struct acpi_gpe_event_info
*gpe_event_info
;
281 ACPI_FUNCTION_TRACE ("acpi_enable_gpe");
284 /* Use semaphore lock if not executing at interrupt level */
286 if (flags
& ACPI_NOT_ISR
) {
287 status
= acpi_ut_acquire_mutex (ACPI_MTX_EVENTS
);
288 if (ACPI_FAILURE (status
)) {
289 return_ACPI_STATUS (status
);
293 /* Ensure that we have a valid GPE number */
295 gpe_event_info
= acpi_ev_get_gpe_event_info (gpe_device
, gpe_number
);
296 if (!gpe_event_info
) {
297 status
= AE_BAD_PARAMETER
;
298 goto unlock_and_exit
;
301 /* Perform the enable */
303 status
= acpi_ev_enable_gpe (gpe_event_info
, TRUE
);
306 if (flags
& ACPI_NOT_ISR
) {
307 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS
);
309 return_ACPI_STATUS (status
);
311 EXPORT_SYMBOL(acpi_enable_gpe
);
314 /*******************************************************************************
316 * FUNCTION: acpi_disable_gpe
318 * PARAMETERS: gpe_device - Parent GPE Device
319 * gpe_number - GPE level within the GPE block
320 * Flags - Just disable, or also wake disable?
321 * Called from ISR or not
325 * DESCRIPTION: Disable an ACPI event (general purpose)
327 ******************************************************************************/
331 acpi_handle gpe_device
,
335 acpi_status status
= AE_OK
;
336 struct acpi_gpe_event_info
*gpe_event_info
;
339 ACPI_FUNCTION_TRACE ("acpi_disable_gpe");
342 /* Use semaphore lock if not executing at interrupt level */
344 if (flags
& ACPI_NOT_ISR
) {
345 status
= acpi_ut_acquire_mutex (ACPI_MTX_EVENTS
);
346 if (ACPI_FAILURE (status
)) {
347 return_ACPI_STATUS (status
);
351 /* Ensure that we have a valid GPE number */
353 gpe_event_info
= acpi_ev_get_gpe_event_info (gpe_device
, gpe_number
);
354 if (!gpe_event_info
) {
355 status
= AE_BAD_PARAMETER
;
356 goto unlock_and_exit
;
359 status
= acpi_ev_disable_gpe (gpe_event_info
);
362 if (flags
& ACPI_NOT_ISR
) {
363 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS
);
365 return_ACPI_STATUS (status
);
369 /*******************************************************************************
371 * FUNCTION: acpi_disable_event
373 * PARAMETERS: Event - The fixed eventto be enabled
378 * DESCRIPTION: Disable an ACPI event (fixed)
380 ******************************************************************************/
387 acpi_status status
= AE_OK
;
391 ACPI_FUNCTION_TRACE ("acpi_disable_event");
394 /* Decode the Fixed Event */
396 if (event
> ACPI_EVENT_MAX
) {
397 return_ACPI_STATUS (AE_BAD_PARAMETER
);
401 * Disable the requested fixed event (by writing a zero to the
402 * enable register bit)
404 status
= acpi_set_register (acpi_gbl_fixed_event_info
[event
].enable_register_id
,
406 if (ACPI_FAILURE (status
)) {
407 return_ACPI_STATUS (status
);
410 status
= acpi_get_register (acpi_gbl_fixed_event_info
[event
].enable_register_id
,
411 &value
, ACPI_MTX_LOCK
);
412 if (ACPI_FAILURE (status
)) {
413 return_ACPI_STATUS (status
);
417 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
418 "Could not disable %s events\n", acpi_ut_get_event_name (event
)));
419 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE
);
422 return_ACPI_STATUS (status
);
424 EXPORT_SYMBOL(acpi_disable_event
);
427 /*******************************************************************************
429 * FUNCTION: acpi_clear_event
431 * PARAMETERS: Event - The fixed event to be cleared
435 * DESCRIPTION: Clear an ACPI event (fixed)
437 ******************************************************************************/
443 acpi_status status
= AE_OK
;
446 ACPI_FUNCTION_TRACE ("acpi_clear_event");
449 /* Decode the Fixed Event */
451 if (event
> ACPI_EVENT_MAX
) {
452 return_ACPI_STATUS (AE_BAD_PARAMETER
);
456 * Clear the requested fixed event (By writing a one to the
457 * status register bit)
459 status
= acpi_set_register (acpi_gbl_fixed_event_info
[event
].status_register_id
,
462 return_ACPI_STATUS (status
);
464 EXPORT_SYMBOL(acpi_clear_event
);
467 /*******************************************************************************
469 * FUNCTION: acpi_clear_gpe
471 * PARAMETERS: gpe_device - Parent GPE Device
472 * gpe_number - GPE level within the GPE block
473 * Flags - Called from an ISR or not
477 * DESCRIPTION: Clear an ACPI event (general purpose)
479 ******************************************************************************/
483 acpi_handle gpe_device
,
487 acpi_status status
= AE_OK
;
488 struct acpi_gpe_event_info
*gpe_event_info
;
491 ACPI_FUNCTION_TRACE ("acpi_clear_gpe");
494 /* Use semaphore lock if not executing at interrupt level */
496 if (flags
& ACPI_NOT_ISR
) {
497 status
= acpi_ut_acquire_mutex (ACPI_MTX_EVENTS
);
498 if (ACPI_FAILURE (status
)) {
499 return_ACPI_STATUS (status
);
503 /* Ensure that we have a valid GPE number */
505 gpe_event_info
= acpi_ev_get_gpe_event_info (gpe_device
, gpe_number
);
506 if (!gpe_event_info
) {
507 status
= AE_BAD_PARAMETER
;
508 goto unlock_and_exit
;
511 status
= acpi_hw_clear_gpe (gpe_event_info
);
514 if (flags
& ACPI_NOT_ISR
) {
515 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS
);
517 return_ACPI_STATUS (status
);
521 #ifdef ACPI_FUTURE_USAGE
523 /*******************************************************************************
525 * FUNCTION: acpi_get_event_status
527 * PARAMETERS: Event - The fixed event
528 * Event Status - Where the current status of the event will
533 * DESCRIPTION: Obtains and returns the current status of the event
535 ******************************************************************************/
538 acpi_get_event_status (
540 acpi_event_status
*event_status
)
542 acpi_status status
= AE_OK
;
545 ACPI_FUNCTION_TRACE ("acpi_get_event_status");
549 return_ACPI_STATUS (AE_BAD_PARAMETER
);
552 /* Decode the Fixed Event */
554 if (event
> ACPI_EVENT_MAX
) {
555 return_ACPI_STATUS (AE_BAD_PARAMETER
);
558 /* Get the status of the requested fixed event */
560 status
= acpi_get_register (acpi_gbl_fixed_event_info
[event
].status_register_id
,
561 event_status
, ACPI_MTX_LOCK
);
563 return_ACPI_STATUS (status
);
567 /*******************************************************************************
569 * FUNCTION: acpi_get_gpe_status
571 * PARAMETERS: gpe_device - Parent GPE Device
572 * gpe_number - GPE level within the GPE block
573 * Flags - Called from an ISR or not
574 * Event Status - Where the current status of the event will
579 * DESCRIPTION: Get status of an event (general purpose)
581 ******************************************************************************/
584 acpi_get_gpe_status (
585 acpi_handle gpe_device
,
588 acpi_event_status
*event_status
)
590 acpi_status status
= AE_OK
;
591 struct acpi_gpe_event_info
*gpe_event_info
;
594 ACPI_FUNCTION_TRACE ("acpi_get_gpe_status");
597 /* Use semaphore lock if not executing at interrupt level */
599 if (flags
& ACPI_NOT_ISR
) {
600 status
= acpi_ut_acquire_mutex (ACPI_MTX_EVENTS
);
601 if (ACPI_FAILURE (status
)) {
602 return_ACPI_STATUS (status
);
606 /* Ensure that we have a valid GPE number */
608 gpe_event_info
= acpi_ev_get_gpe_event_info (gpe_device
, gpe_number
);
609 if (!gpe_event_info
) {
610 status
= AE_BAD_PARAMETER
;
611 goto unlock_and_exit
;
614 /* Obtain status on the requested GPE number */
616 status
= acpi_hw_get_gpe_status (gpe_event_info
, event_status
);
619 if (flags
& ACPI_NOT_ISR
) {
620 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS
);
622 return_ACPI_STATUS (status
);
624 #endif /* ACPI_FUTURE_USAGE */
627 /*******************************************************************************
629 * FUNCTION: acpi_install_gpe_block
631 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
632 * gpe_block_address - Address and space_iD
633 * register_count - Number of GPE register pairs in the block
634 * interrupt_level - H/W interrupt for the block
638 * DESCRIPTION: Create and Install a block of GPE registers
640 ******************************************************************************/
643 acpi_install_gpe_block (
644 acpi_handle gpe_device
,
645 struct acpi_generic_address
*gpe_block_address
,
650 union acpi_operand_object
*obj_desc
;
651 struct acpi_namespace_node
*node
;
652 struct acpi_gpe_block_info
*gpe_block
;
655 ACPI_FUNCTION_TRACE ("acpi_install_gpe_block");
659 (!gpe_block_address
) ||
661 return_ACPI_STATUS (AE_BAD_PARAMETER
);
664 status
= acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE
);
665 if (ACPI_FAILURE (status
)) {
669 node
= acpi_ns_map_handle_to_node (gpe_device
);
671 status
= AE_BAD_PARAMETER
;
672 goto unlock_and_exit
;
676 * For user-installed GPE Block Devices, the gpe_block_base_number
679 status
= acpi_ev_create_gpe_block (node
, gpe_block_address
, register_count
,
680 0, interrupt_level
, &gpe_block
);
681 if (ACPI_FAILURE (status
)) {
682 goto unlock_and_exit
;
685 /* Get the device_object attached to the node */
687 obj_desc
= acpi_ns_get_attached_object (node
);
689 /* No object, create a new one */
691 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_DEVICE
);
693 status
= AE_NO_MEMORY
;
694 goto unlock_and_exit
;
697 status
= acpi_ns_attach_object (node
, obj_desc
, ACPI_TYPE_DEVICE
);
699 /* Remove local reference to the object */
701 acpi_ut_remove_reference (obj_desc
);
703 if (ACPI_FAILURE (status
)) {
704 goto unlock_and_exit
;
708 /* Install the GPE block in the device_object */
710 obj_desc
->device
.gpe_block
= gpe_block
;
714 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE
);
715 return_ACPI_STATUS (status
);
717 EXPORT_SYMBOL(acpi_install_gpe_block
);
720 /*******************************************************************************
722 * FUNCTION: acpi_remove_gpe_block
724 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
728 * DESCRIPTION: Remove a previously installed block of GPE registers
730 ******************************************************************************/
733 acpi_remove_gpe_block (
734 acpi_handle gpe_device
)
736 union acpi_operand_object
*obj_desc
;
738 struct acpi_namespace_node
*node
;
741 ACPI_FUNCTION_TRACE ("acpi_remove_gpe_block");
745 return_ACPI_STATUS (AE_BAD_PARAMETER
);
748 status
= acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE
);
749 if (ACPI_FAILURE (status
)) {
753 node
= acpi_ns_map_handle_to_node (gpe_device
);
755 status
= AE_BAD_PARAMETER
;
756 goto unlock_and_exit
;
759 /* Get the device_object attached to the node */
761 obj_desc
= acpi_ns_get_attached_object (node
);
763 !obj_desc
->device
.gpe_block
) {
764 return_ACPI_STATUS (AE_NULL_OBJECT
);
767 /* Delete the GPE block (but not the device_object) */
769 status
= acpi_ev_delete_gpe_block (obj_desc
->device
.gpe_block
);
770 if (ACPI_SUCCESS (status
)) {
771 obj_desc
->device
.gpe_block
= NULL
;
775 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE
);
776 return_ACPI_STATUS (status
);
778 EXPORT_SYMBOL(acpi_remove_gpe_block
);