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_set_gpe_type
209 * PARAMETERS: gpe_device - Parent GPE Device
210 * gpe_number - GPE level within the GPE block
211 * Type - New GPE type
215 * DESCRIPTION: Enable an ACPI event (general purpose)
217 ******************************************************************************/
221 acpi_handle gpe_device,
225 acpi_status status = AE_OK;
226 struct acpi_gpe_event_info *gpe_event_info;
229 ACPI_FUNCTION_TRACE ("acpi_set_gpe_type");
232 /* Ensure that we have a valid GPE number */
234 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
235 if (!gpe_event_info) {
236 status = AE_BAD_PARAMETER;
237 goto unlock_and_exit;
240 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
241 return_ACPI_STATUS (AE_OK);
244 /* Set the new type (will disable GPE if currently enabled) */
246 status = acpi_ev_set_gpe_type (gpe_event_info, type);
249 return_ACPI_STATUS (status);
253 /*******************************************************************************
255 * FUNCTION: acpi_enable_gpe
257 * PARAMETERS: gpe_device - Parent GPE Device
258 * gpe_number - GPE level within the GPE block
259 * Flags - Just enable, or also wake enable?
260 * Called from ISR or not
264 * DESCRIPTION: Enable an ACPI event (general purpose)
266 ******************************************************************************/
270 acpi_handle gpe_device,
274 acpi_status status = AE_OK;
275 struct acpi_gpe_event_info *gpe_event_info;
278 ACPI_FUNCTION_TRACE ("acpi_enable_gpe");
281 /* Use semaphore lock if not executing at interrupt level */
283 if (flags & ACPI_NOT_ISR) {
284 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
285 if (ACPI_FAILURE (status)) {
286 return_ACPI_STATUS (status);
290 /* Ensure that we have a valid GPE number */
292 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
293 if (!gpe_event_info) {
294 status = AE_BAD_PARAMETER;
295 goto unlock_and_exit;
298 /* Perform the enable */
300 status = acpi_ev_enable_gpe (gpe_event_info, TRUE);
303 if (flags & ACPI_NOT_ISR) {
304 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
306 return_ACPI_STATUS (status);
310 /*******************************************************************************
312 * FUNCTION: acpi_disable_gpe
314 * PARAMETERS: gpe_device - Parent GPE Device
315 * gpe_number - GPE level within the GPE block
316 * Flags - Just disable, or also wake disable?
317 * Called from ISR or not
321 * DESCRIPTION: Disable an ACPI event (general purpose)
323 ******************************************************************************/
327 acpi_handle gpe_device,
331 acpi_status status = AE_OK;
332 struct acpi_gpe_event_info *gpe_event_info;
335 ACPI_FUNCTION_TRACE ("acpi_disable_gpe");
338 /* Use semaphore lock if not executing at interrupt level */
340 if (flags & ACPI_NOT_ISR) {
341 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
342 if (ACPI_FAILURE (status)) {
343 return_ACPI_STATUS (status);
347 /* Ensure that we have a valid GPE number */
349 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
350 if (!gpe_event_info) {
351 status = AE_BAD_PARAMETER;
352 goto unlock_and_exit;
355 status = acpi_ev_disable_gpe (gpe_event_info);
358 if (flags & ACPI_NOT_ISR) {
359 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
361 return_ACPI_STATUS (status);
365 /*******************************************************************************
367 * FUNCTION: acpi_disable_event
369 * PARAMETERS: Event - The fixed eventto be enabled
374 * DESCRIPTION: Disable an ACPI event (fixed)
376 ******************************************************************************/
383 acpi_status status = AE_OK;
387 ACPI_FUNCTION_TRACE ("acpi_disable_event");
390 /* Decode the Fixed Event */
392 if (event > ACPI_EVENT_MAX) {
393 return_ACPI_STATUS (AE_BAD_PARAMETER);
397 * Disable the requested fixed event (by writing a zero to the
398 * enable register bit)
400 status = acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id,
402 if (ACPI_FAILURE (status)) {
403 return_ACPI_STATUS (status);
406 status = acpi_get_register (acpi_gbl_fixed_event_info[event].enable_register_id,
407 &value, ACPI_MTX_LOCK);
408 if (ACPI_FAILURE (status)) {
409 return_ACPI_STATUS (status);
413 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
414 "Could not disable %s events\n", acpi_ut_get_event_name (event)));
415 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
418 return_ACPI_STATUS (status);
422 /*******************************************************************************
424 * FUNCTION: acpi_clear_event
426 * PARAMETERS: Event - The fixed event to be cleared
430 * DESCRIPTION: Clear an ACPI event (fixed)
432 ******************************************************************************/
438 acpi_status status = AE_OK;
441 ACPI_FUNCTION_TRACE ("acpi_clear_event");
444 /* Decode the Fixed Event */
446 if (event > ACPI_EVENT_MAX) {
447 return_ACPI_STATUS (AE_BAD_PARAMETER);
451 * Clear the requested fixed event (By writing a one to the
452 * status register bit)
454 status = acpi_set_register (acpi_gbl_fixed_event_info[event].status_register_id,
457 return_ACPI_STATUS (status);
461 /*******************************************************************************
463 * FUNCTION: acpi_clear_gpe
465 * PARAMETERS: gpe_device - Parent GPE Device
466 * gpe_number - GPE level within the GPE block
467 * Flags - Called from an ISR or not
471 * DESCRIPTION: Clear an ACPI event (general purpose)
473 ******************************************************************************/
477 acpi_handle gpe_device,
481 acpi_status status = AE_OK;
482 struct acpi_gpe_event_info *gpe_event_info;
485 ACPI_FUNCTION_TRACE ("acpi_clear_gpe");
488 /* Use semaphore lock if not executing at interrupt level */
490 if (flags & ACPI_NOT_ISR) {
491 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
492 if (ACPI_FAILURE (status)) {
493 return_ACPI_STATUS (status);
497 /* Ensure that we have a valid GPE number */
499 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
500 if (!gpe_event_info) {
501 status = AE_BAD_PARAMETER;
502 goto unlock_and_exit;
505 status = acpi_hw_clear_gpe (gpe_event_info);
508 if (flags & ACPI_NOT_ISR) {
509 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
511 return_ACPI_STATUS (status);
515 /*******************************************************************************
517 * FUNCTION: acpi_get_event_status
519 * PARAMETERS: Event - The fixed event
520 * Event Status - Where the current status of the event will
525 * DESCRIPTION: Obtains and returns the current status of the event
527 ******************************************************************************/
530 acpi_get_event_status (
532 acpi_event_status *event_status)
534 acpi_status status = AE_OK;
537 ACPI_FUNCTION_TRACE ("acpi_get_event_status");
541 return_ACPI_STATUS (AE_BAD_PARAMETER);
544 /* Decode the Fixed Event */
546 if (event > ACPI_EVENT_MAX) {
547 return_ACPI_STATUS (AE_BAD_PARAMETER);
550 /* Get the status of the requested fixed event */
552 status = acpi_get_register (acpi_gbl_fixed_event_info[event].status_register_id,
553 event_status, ACPI_MTX_LOCK);
555 return_ACPI_STATUS (status);
559 /*******************************************************************************
561 * FUNCTION: acpi_get_gpe_status
563 * PARAMETERS: gpe_device - Parent GPE Device
564 * gpe_number - GPE level within the GPE block
565 * Flags - Called from an ISR or not
566 * Event Status - Where the current status of the event will
571 * DESCRIPTION: Get status of an event (general purpose)
573 ******************************************************************************/
576 acpi_get_gpe_status (
577 acpi_handle gpe_device,
580 acpi_event_status *event_status)
582 acpi_status status = AE_OK;
583 struct acpi_gpe_event_info *gpe_event_info;
586 ACPI_FUNCTION_TRACE ("acpi_get_gpe_status");
589 /* Use semaphore lock if not executing at interrupt level */
591 if (flags & ACPI_NOT_ISR) {
592 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
593 if (ACPI_FAILURE (status)) {
594 return_ACPI_STATUS (status);
598 /* Ensure that we have a valid GPE number */
600 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
601 if (!gpe_event_info) {
602 status = AE_BAD_PARAMETER;
603 goto unlock_and_exit;
606 /* Obtain status on the requested GPE number */
608 status = acpi_hw_get_gpe_status (gpe_event_info, event_status);
611 if (flags & ACPI_NOT_ISR) {
612 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
614 return_ACPI_STATUS (status);
618 /*******************************************************************************
620 * FUNCTION: acpi_install_gpe_block
622 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
623 * gpe_block_address - Address and space_iD
624 * register_count - Number of GPE register pairs in the block
625 * interrupt_level - H/W interrupt for the block
629 * DESCRIPTION: Create and Install a block of GPE registers
631 ******************************************************************************/
634 acpi_install_gpe_block (
635 acpi_handle gpe_device,
636 struct acpi_generic_address *gpe_block_address,
641 union acpi_operand_object *obj_desc;
642 struct acpi_namespace_node *node;
643 struct acpi_gpe_block_info *gpe_block;
646 ACPI_FUNCTION_TRACE ("acpi_install_gpe_block");
650 (!gpe_block_address) ||
652 return_ACPI_STATUS (AE_BAD_PARAMETER);
655 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
656 if (ACPI_FAILURE (status)) {
660 node = acpi_ns_map_handle_to_node (gpe_device);
662 status = AE_BAD_PARAMETER;
663 goto unlock_and_exit;
667 * For user-installed GPE Block Devices, the gpe_block_base_number
670 status = acpi_ev_create_gpe_block (node, gpe_block_address, register_count,
671 0, interrupt_level, &gpe_block);
672 if (ACPI_FAILURE (status)) {
673 goto unlock_and_exit;
676 /* Get the device_object attached to the node */
678 obj_desc = acpi_ns_get_attached_object (node);
680 /* No object, create a new one */
682 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_DEVICE);
684 status = AE_NO_MEMORY;
685 goto unlock_and_exit;
688 status = acpi_ns_attach_object (node, obj_desc, ACPI_TYPE_DEVICE);
690 /* Remove local reference to the object */
692 acpi_ut_remove_reference (obj_desc);
694 if (ACPI_FAILURE (status)) {
695 goto unlock_and_exit;
699 /* Install the GPE block in the device_object */
701 obj_desc->device.gpe_block = gpe_block;
705 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
706 return_ACPI_STATUS (status);
710 /*******************************************************************************
712 * FUNCTION: acpi_remove_gpe_block
714 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
718 * DESCRIPTION: Remove a previously installed block of GPE registers
720 ******************************************************************************/
723 acpi_remove_gpe_block (
724 acpi_handle gpe_device)
726 union acpi_operand_object *obj_desc;
728 struct acpi_namespace_node *node;
731 ACPI_FUNCTION_TRACE ("acpi_remove_gpe_block");
735 return_ACPI_STATUS (AE_BAD_PARAMETER);
738 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
739 if (ACPI_FAILURE (status)) {
743 node = acpi_ns_map_handle_to_node (gpe_device);
745 status = AE_BAD_PARAMETER;
746 goto unlock_and_exit;
749 /* Get the device_object attached to the node */
751 obj_desc = acpi_ns_get_attached_object (node);
753 !obj_desc->device.gpe_block) {
754 return_ACPI_STATUS (AE_NULL_OBJECT);
757 /* Delete the GPE block (but not the device_object) */
759 status = acpi_ev_delete_gpe_block (obj_desc->device.gpe_block);
760 if (ACPI_SUCCESS (status)) {
761 obj_desc->device.gpe_block = NULL;
765 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
766 return_ACPI_STATUS (status);