1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2004, 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.
45 #include <acpi/acpi.h>
46 #include <acpi/acevents.h>
47 #include <acpi/acnamesp.h>
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME ("evxfevnt")
53 /*******************************************************************************
55 * FUNCTION: acpi_enable
61 * DESCRIPTION: Transfers the system into ACPI mode.
63 ******************************************************************************/
68 acpi_status status = AE_OK;
71 ACPI_FUNCTION_TRACE ("acpi_enable");
74 /* Make sure we have the FADT*/
77 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
78 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
81 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
82 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
85 /* Transition to ACPI mode */
87 status = acpi_hw_set_mode (ACPI_SYS_MODE_ACPI);
88 if (ACPI_FAILURE (status)) {
89 ACPI_REPORT_ERROR (("Could not transition to ACPI mode.\n"));
90 return_ACPI_STATUS (status);
93 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Transition to ACPI mode successful\n"));
96 return_ACPI_STATUS (status);
100 /*******************************************************************************
102 * FUNCTION: acpi_disable
108 * DESCRIPTION: Transfers the system into LEGACY mode.
110 ******************************************************************************/
115 acpi_status status = AE_OK;
118 ACPI_FUNCTION_TRACE ("acpi_disable");
121 if (!acpi_gbl_FADT) {
122 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
123 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
126 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
127 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in legacy (non-ACPI) mode\n"));
130 /* Transition to LEGACY mode */
132 status = acpi_hw_set_mode (ACPI_SYS_MODE_LEGACY);
134 if (ACPI_FAILURE (status)) {
135 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not exit ACPI mode to legacy mode"));
136 return_ACPI_STATUS (status);
139 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
142 return_ACPI_STATUS (status);
146 /*******************************************************************************
148 * FUNCTION: acpi_enable_event
150 * PARAMETERS: Event - The fixed eventto be enabled
155 * DESCRIPTION: Enable an ACPI event (fixed)
157 ******************************************************************************/
164 acpi_status status = AE_OK;
168 ACPI_FUNCTION_TRACE ("acpi_enable_event");
171 /* Decode the Fixed Event */
173 if (event > ACPI_EVENT_MAX) {
174 return_ACPI_STATUS (AE_BAD_PARAMETER);
178 * Enable the requested fixed event (by writing a one to the
179 * enable register bit)
181 status = acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id,
183 if (ACPI_FAILURE (status)) {
184 return_ACPI_STATUS (status);
187 /* Make sure that the hardware responded */
189 status = acpi_get_register (acpi_gbl_fixed_event_info[event].enable_register_id,
190 &value, ACPI_MTX_LOCK);
191 if (ACPI_FAILURE (status)) {
192 return_ACPI_STATUS (status);
196 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
197 "Could not enable %s event\n", acpi_ut_get_event_name (event)));
198 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
201 return_ACPI_STATUS (status);
205 /*******************************************************************************
207 * FUNCTION: acpi_enable_gpe
209 * PARAMETERS: gpe_device - Parent GPE Device
210 * gpe_number - GPE level within the GPE block
211 * Flags - Just enable, or also wake enable?
212 * Called from ISR or not
216 * DESCRIPTION: Enable an ACPI event (general purpose)
218 ******************************************************************************/
222 acpi_handle gpe_device,
226 acpi_status status = AE_OK;
227 struct acpi_gpe_event_info *gpe_event_info;
230 ACPI_FUNCTION_TRACE ("acpi_enable_gpe");
233 /* Use semaphore lock if not executing at interrupt level */
235 if (flags & ACPI_NOT_ISR) {
236 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
237 if (ACPI_FAILURE (status)) {
238 return_ACPI_STATUS (status);
242 /* Ensure that we have a valid GPE number */
244 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
245 if (!gpe_event_info) {
246 status = AE_BAD_PARAMETER;
247 goto unlock_and_exit;
250 /* Check for Wake vs Runtime GPE */
252 if (flags & ACPI_EVENT_WAKE_ENABLE) {
253 /* Ensure the requested wake GPE is disabled */
255 status = acpi_hw_disable_gpe (gpe_event_info);
256 if (ACPI_FAILURE (status)) {
257 goto unlock_and_exit;
260 /* Defer Enable of Wake GPE until sleep time */
262 acpi_hw_enable_gpe_for_wakeup (gpe_event_info);
265 /* Enable the requested runtime GPE */
267 status = acpi_hw_enable_gpe (gpe_event_info);
268 if (ACPI_FAILURE (status)) {
269 goto unlock_and_exit;
275 if (flags & ACPI_NOT_ISR) {
276 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
278 return_ACPI_STATUS (status);
282 /*******************************************************************************
284 * FUNCTION: acpi_disable_event
286 * PARAMETERS: Event - The fixed eventto be enabled
291 * DESCRIPTION: Disable an ACPI event (fixed)
293 ******************************************************************************/
300 acpi_status status = AE_OK;
304 ACPI_FUNCTION_TRACE ("acpi_disable_event");
307 /* Decode the Fixed Event */
309 if (event > ACPI_EVENT_MAX) {
310 return_ACPI_STATUS (AE_BAD_PARAMETER);
314 * Disable the requested fixed event (by writing a zero to the
315 * enable register bit)
317 status = acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id,
319 if (ACPI_FAILURE (status)) {
320 return_ACPI_STATUS (status);
323 status = acpi_get_register (acpi_gbl_fixed_event_info[event].enable_register_id,
324 &value, ACPI_MTX_LOCK);
325 if (ACPI_FAILURE (status)) {
326 return_ACPI_STATUS (status);
330 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
331 "Could not disable %s events\n", acpi_ut_get_event_name (event)));
332 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
335 return_ACPI_STATUS (status);
339 /*******************************************************************************
341 * FUNCTION: acpi_disable_gpe
343 * PARAMETERS: gpe_device - Parent GPE Device
344 * gpe_number - GPE level within the GPE block
345 * Flags - Just enable, or also wake enable?
346 * Called from ISR or not
350 * DESCRIPTION: Disable an ACPI event (general purpose)
352 ******************************************************************************/
356 acpi_handle gpe_device,
360 acpi_status status = AE_OK;
361 struct acpi_gpe_event_info *gpe_event_info;
364 ACPI_FUNCTION_TRACE ("acpi_disable_gpe");
367 /* Use semaphore lock if not executing at interrupt level */
369 if (flags & ACPI_NOT_ISR) {
370 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
371 if (ACPI_FAILURE (status)) {
372 return_ACPI_STATUS (status);
376 /* Ensure that we have a valid GPE number */
378 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
379 if (!gpe_event_info) {
380 status = AE_BAD_PARAMETER;
381 goto unlock_and_exit;
385 * Only disable the requested GPE number for wake if specified.
386 * Otherwise, turn it totally off
388 if (flags & ACPI_EVENT_WAKE_DISABLE) {
389 acpi_hw_disable_gpe_for_wakeup (gpe_event_info);
392 status = acpi_hw_disable_gpe (gpe_event_info);
396 if (flags & ACPI_NOT_ISR) {
397 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
399 return_ACPI_STATUS (status);
403 /*******************************************************************************
405 * FUNCTION: acpi_clear_event
407 * PARAMETERS: Event - The fixed event to be cleared
411 * DESCRIPTION: Clear an ACPI event (fixed)
413 ******************************************************************************/
419 acpi_status status = AE_OK;
422 ACPI_FUNCTION_TRACE ("acpi_clear_event");
425 /* Decode the Fixed Event */
427 if (event > ACPI_EVENT_MAX) {
428 return_ACPI_STATUS (AE_BAD_PARAMETER);
432 * Clear the requested fixed event (By writing a one to the
433 * status register bit)
435 status = acpi_set_register (acpi_gbl_fixed_event_info[event].status_register_id,
438 return_ACPI_STATUS (status);
442 /*******************************************************************************
444 * FUNCTION: acpi_clear_gpe
446 * PARAMETERS: gpe_device - Parent GPE Device
447 * gpe_number - GPE level within the GPE block
448 * Flags - Called from an ISR or not
452 * DESCRIPTION: Clear an ACPI event (general purpose)
454 ******************************************************************************/
458 acpi_handle gpe_device,
462 acpi_status status = AE_OK;
463 struct acpi_gpe_event_info *gpe_event_info;
466 ACPI_FUNCTION_TRACE ("acpi_clear_gpe");
469 /* Use semaphore lock if not executing at interrupt level */
471 if (flags & ACPI_NOT_ISR) {
472 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
473 if (ACPI_FAILURE (status)) {
474 return_ACPI_STATUS (status);
478 /* Ensure that we have a valid GPE number */
480 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
481 if (!gpe_event_info) {
482 status = AE_BAD_PARAMETER;
483 goto unlock_and_exit;
486 status = acpi_hw_clear_gpe (gpe_event_info);
489 if (flags & ACPI_NOT_ISR) {
490 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
492 return_ACPI_STATUS (status);
496 /*******************************************************************************
498 * FUNCTION: acpi_get_event_status
500 * PARAMETERS: Event - The fixed event
501 * Event Status - Where the current status of the event will
506 * DESCRIPTION: Obtains and returns the current status of the event
508 ******************************************************************************/
511 acpi_get_event_status (
513 acpi_event_status *event_status)
515 acpi_status status = AE_OK;
518 ACPI_FUNCTION_TRACE ("acpi_get_event_status");
522 return_ACPI_STATUS (AE_BAD_PARAMETER);
525 /* Decode the Fixed Event */
527 if (event > ACPI_EVENT_MAX) {
528 return_ACPI_STATUS (AE_BAD_PARAMETER);
531 /* Get the status of the requested fixed event */
533 status = acpi_get_register (acpi_gbl_fixed_event_info[event].status_register_id,
534 event_status, ACPI_MTX_LOCK);
536 return_ACPI_STATUS (status);
540 /*******************************************************************************
542 * FUNCTION: acpi_get_gpe_status
544 * PARAMETERS: gpe_device - Parent GPE Device
545 * gpe_number - GPE level within the GPE block
546 * Flags - Called from an ISR or not
547 * Event Status - Where the current status of the event will
552 * DESCRIPTION: Get status of an event (general purpose)
554 ******************************************************************************/
557 acpi_get_gpe_status (
558 acpi_handle gpe_device,
561 acpi_event_status *event_status)
563 acpi_status status = AE_OK;
564 struct acpi_gpe_event_info *gpe_event_info;
567 ACPI_FUNCTION_TRACE ("acpi_get_gpe_status");
570 /* Use semaphore lock if not executing at interrupt level */
572 if (flags & ACPI_NOT_ISR) {
573 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
574 if (ACPI_FAILURE (status)) {
575 return_ACPI_STATUS (status);
579 /* Ensure that we have a valid GPE number */
581 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
582 if (!gpe_event_info) {
583 status = AE_BAD_PARAMETER;
584 goto unlock_and_exit;
587 /* Obtain status on the requested GPE number */
589 status = acpi_hw_get_gpe_status (gpe_event_info, event_status);
592 if (flags & ACPI_NOT_ISR) {
593 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
595 return_ACPI_STATUS (status);
599 /*******************************************************************************
601 * FUNCTION: acpi_install_gpe_block
603 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
604 * gpe_block_address - Address and space_iD
605 * register_count - Number of GPE register pairs in the block
606 * interrupt_level - H/W interrupt for the block
610 * DESCRIPTION: Create and Install a block of GPE registers
612 ******************************************************************************/
615 acpi_install_gpe_block (
616 acpi_handle gpe_device,
617 struct acpi_generic_address *gpe_block_address,
622 union acpi_operand_object *obj_desc;
623 struct acpi_namespace_node *node;
624 struct acpi_gpe_block_info *gpe_block;
627 ACPI_FUNCTION_TRACE ("acpi_install_gpe_block");
631 (!gpe_block_address) ||
633 return_ACPI_STATUS (AE_BAD_PARAMETER);
636 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
637 if (ACPI_FAILURE (status)) {
641 node = acpi_ns_map_handle_to_node (gpe_device);
643 status = AE_BAD_PARAMETER;
644 goto unlock_and_exit;
648 * For user-installed GPE Block Devices, the gpe_block_base_number
651 status = acpi_ev_create_gpe_block (node, gpe_block_address, register_count,
652 0, interrupt_level, &gpe_block);
653 if (ACPI_FAILURE (status)) {
654 goto unlock_and_exit;
657 /* Get the device_object attached to the node */
659 obj_desc = acpi_ns_get_attached_object (node);
661 /* No object, create a new one */
663 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_DEVICE);
665 status = AE_NO_MEMORY;
666 goto unlock_and_exit;
669 status = acpi_ns_attach_object (node, obj_desc, ACPI_TYPE_DEVICE);
671 /* Remove local reference to the object */
673 acpi_ut_remove_reference (obj_desc);
675 if (ACPI_FAILURE (status)) {
676 goto unlock_and_exit;
680 /* Install the GPE block in the device_object */
682 obj_desc->device.gpe_block = gpe_block;
686 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
687 return_ACPI_STATUS (status);
691 /*******************************************************************************
693 * FUNCTION: acpi_remove_gpe_block
695 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
699 * DESCRIPTION: Remove a previously installed block of GPE registers
701 ******************************************************************************/
704 acpi_remove_gpe_block (
705 acpi_handle gpe_device)
707 union acpi_operand_object *obj_desc;
709 struct acpi_namespace_node *node;
712 ACPI_FUNCTION_TRACE ("acpi_remove_gpe_block");
716 return_ACPI_STATUS (AE_BAD_PARAMETER);
719 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
720 if (ACPI_FAILURE (status)) {
724 node = acpi_ns_map_handle_to_node (gpe_device);
726 status = AE_BAD_PARAMETER;
727 goto unlock_and_exit;
730 /* Get the device_object attached to the node */
732 obj_desc = acpi_ns_get_attached_object (node);
734 !obj_desc->device.gpe_block) {
735 return_ACPI_STATUS (AE_NULL_OBJECT);
738 /* Delete the GPE block (but not the device_object) */
740 status = acpi_ev_delete_gpe_block (obj_desc->device.gpe_block);
741 if (ACPI_SUCCESS (status)) {
742 obj_desc->device.gpe_block = NULL;
746 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
747 return_ACPI_STATUS (status);