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.
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 ******************************************************************************/
438 #ifdef ACPI_FUTURE_USAGE
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);
465 #endif /* ACPI_FUTURE_USAGE */
468 /*******************************************************************************
470 * FUNCTION: acpi_clear_gpe
472 * PARAMETERS: gpe_device - Parent GPE Device
473 * gpe_number - GPE level within the GPE block
474 * Flags - Called from an ISR or not
478 * DESCRIPTION: Clear an ACPI event (general purpose)
480 ******************************************************************************/
484 acpi_handle gpe_device,
488 acpi_status status = AE_OK;
489 struct acpi_gpe_event_info *gpe_event_info;
492 ACPI_FUNCTION_TRACE ("acpi_clear_gpe");
495 /* Use semaphore lock if not executing at interrupt level */
497 if (flags & ACPI_NOT_ISR) {
498 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
499 if (ACPI_FAILURE (status)) {
500 return_ACPI_STATUS (status);
504 /* Ensure that we have a valid GPE number */
506 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
507 if (!gpe_event_info) {
508 status = AE_BAD_PARAMETER;
509 goto unlock_and_exit;
512 status = acpi_hw_clear_gpe (gpe_event_info);
515 if (flags & ACPI_NOT_ISR) {
516 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
518 return_ACPI_STATUS (status);
522 #ifdef ACPI_FUTURE_USAGE
524 /*******************************************************************************
526 * FUNCTION: acpi_get_event_status
528 * PARAMETERS: Event - The fixed event
529 * Event Status - Where the current status of the event will
534 * DESCRIPTION: Obtains and returns the current status of the event
536 ******************************************************************************/
539 acpi_get_event_status (
541 acpi_event_status *event_status)
543 acpi_status status = AE_OK;
546 ACPI_FUNCTION_TRACE ("acpi_get_event_status");
550 return_ACPI_STATUS (AE_BAD_PARAMETER);
553 /* Decode the Fixed Event */
555 if (event > ACPI_EVENT_MAX) {
556 return_ACPI_STATUS (AE_BAD_PARAMETER);
559 /* Get the status of the requested fixed event */
561 status = acpi_get_register (acpi_gbl_fixed_event_info[event].status_register_id,
562 event_status, ACPI_MTX_LOCK);
564 return_ACPI_STATUS (status);
568 /*******************************************************************************
570 * FUNCTION: acpi_get_gpe_status
572 * PARAMETERS: gpe_device - Parent GPE Device
573 * gpe_number - GPE level within the GPE block
574 * Flags - Called from an ISR or not
575 * Event Status - Where the current status of the event will
580 * DESCRIPTION: Get status of an event (general purpose)
582 ******************************************************************************/
585 acpi_get_gpe_status (
586 acpi_handle gpe_device,
589 acpi_event_status *event_status)
591 acpi_status status = AE_OK;
592 struct acpi_gpe_event_info *gpe_event_info;
595 ACPI_FUNCTION_TRACE ("acpi_get_gpe_status");
598 /* Use semaphore lock if not executing at interrupt level */
600 if (flags & ACPI_NOT_ISR) {
601 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
602 if (ACPI_FAILURE (status)) {
603 return_ACPI_STATUS (status);
607 /* Ensure that we have a valid GPE number */
609 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
610 if (!gpe_event_info) {
611 status = AE_BAD_PARAMETER;
612 goto unlock_and_exit;
615 /* Obtain status on the requested GPE number */
617 status = acpi_hw_get_gpe_status (gpe_event_info, event_status);
620 if (flags & ACPI_NOT_ISR) {
621 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
623 return_ACPI_STATUS (status);
625 #endif /* ACPI_FUTURE_USAGE */
628 /*******************************************************************************
630 * FUNCTION: acpi_install_gpe_block
632 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
633 * gpe_block_address - Address and space_iD
634 * register_count - Number of GPE register pairs in the block
635 * interrupt_level - H/W interrupt for the block
639 * DESCRIPTION: Create and Install a block of GPE registers
641 ******************************************************************************/
644 acpi_install_gpe_block (
645 acpi_handle gpe_device,
646 struct acpi_generic_address *gpe_block_address,
651 union acpi_operand_object *obj_desc;
652 struct acpi_namespace_node *node;
653 struct acpi_gpe_block_info *gpe_block;
656 ACPI_FUNCTION_TRACE ("acpi_install_gpe_block");
660 (!gpe_block_address) ||
662 return_ACPI_STATUS (AE_BAD_PARAMETER);
665 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
666 if (ACPI_FAILURE (status)) {
670 node = acpi_ns_map_handle_to_node (gpe_device);
672 status = AE_BAD_PARAMETER;
673 goto unlock_and_exit;
677 * For user-installed GPE Block Devices, the gpe_block_base_number
680 status = acpi_ev_create_gpe_block (node, gpe_block_address, register_count,
681 0, interrupt_level, &gpe_block);
682 if (ACPI_FAILURE (status)) {
683 goto unlock_and_exit;
686 /* Get the device_object attached to the node */
688 obj_desc = acpi_ns_get_attached_object (node);
690 /* No object, create a new one */
692 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_DEVICE);
694 status = AE_NO_MEMORY;
695 goto unlock_and_exit;
698 status = acpi_ns_attach_object (node, obj_desc, ACPI_TYPE_DEVICE);
700 /* Remove local reference to the object */
702 acpi_ut_remove_reference (obj_desc);
704 if (ACPI_FAILURE (status)) {
705 goto unlock_and_exit;
709 /* Install the GPE block in the device_object */
711 obj_desc->device.gpe_block = gpe_block;
715 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
716 return_ACPI_STATUS (status);
718 EXPORT_SYMBOL(acpi_install_gpe_block);
721 /*******************************************************************************
723 * FUNCTION: acpi_remove_gpe_block
725 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
729 * DESCRIPTION: Remove a previously installed block of GPE registers
731 ******************************************************************************/
734 acpi_remove_gpe_block (
735 acpi_handle gpe_device)
737 union acpi_operand_object *obj_desc;
739 struct acpi_namespace_node *node;
742 ACPI_FUNCTION_TRACE ("acpi_remove_gpe_block");
746 return_ACPI_STATUS (AE_BAD_PARAMETER);
749 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
750 if (ACPI_FAILURE (status)) {
754 node = acpi_ns_map_handle_to_node (gpe_device);
756 status = AE_BAD_PARAMETER;
757 goto unlock_and_exit;
760 /* Get the device_object attached to the node */
762 obj_desc = acpi_ns_get_attached_object (node);
764 !obj_desc->device.gpe_block) {
765 return_ACPI_STATUS (AE_NULL_OBJECT);
768 /* Delete the GPE block (but not the device_object) */
770 status = acpi_ev_delete_gpe_block (obj_desc->device.gpe_block);
771 if (ACPI_SUCCESS (status)) {
772 obj_desc->device.gpe_block = NULL;
776 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
777 return_ACPI_STATUS (status);
779 EXPORT_SYMBOL(acpi_remove_gpe_block);