1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial prton of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #define __EVXFEVNT_C__
121 #include "acevents.h"
122 #include "acnamesp.h"
124 #define _COMPONENT ACPI_EVENTS
125 ACPI_MODULE_NAME ("evxfevnt")
128 /*******************************************************************************
130 * FUNCTION: AcpiEnable
136 * DESCRIPTION: Transfers the system into ACPI mode.
138 ******************************************************************************/
143 ACPI_STATUS Status = AE_OK;
146 ACPI_FUNCTION_TRACE ("AcpiEnable");
149 /* Make sure we have the FADT*/
153 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
154 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
157 if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
159 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
163 /* Transition to ACPI mode */
165 Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
166 if (ACPI_FAILURE (Status))
168 ACPI_REPORT_ERROR (("Could not transition to ACPI mode.\n"));
169 return_ACPI_STATUS (Status);
172 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Transition to ACPI mode successful\n"));
175 return_ACPI_STATUS (Status);
179 /*******************************************************************************
181 * FUNCTION: AcpiDisable
187 * DESCRIPTION: Transfers the system into LEGACY mode.
189 ******************************************************************************/
194 ACPI_STATUS Status = AE_OK;
197 ACPI_FUNCTION_TRACE ("AcpiDisable");
202 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
203 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
206 if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
208 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in legacy (non-ACPI) mode\n"));
212 /* Transition to LEGACY mode */
214 Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
216 if (ACPI_FAILURE (Status))
218 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not exit ACPI mode to legacy mode"));
219 return_ACPI_STATUS (Status);
222 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
225 return_ACPI_STATUS (Status);
229 /*******************************************************************************
231 * FUNCTION: AcpiEnableEvent
233 * PARAMETERS: Event - The fixed eventto be enabled
238 * DESCRIPTION: Enable an ACPI event (fixed)
240 ******************************************************************************/
247 ACPI_STATUS Status = AE_OK;
251 ACPI_FUNCTION_TRACE ("AcpiEnableEvent");
254 /* Decode the Fixed Event */
256 if (Event > ACPI_EVENT_MAX)
258 return_ACPI_STATUS (AE_BAD_PARAMETER);
262 * Enable the requested fixed event (by writing a one to the
263 * enable register bit)
265 Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
267 if (ACPI_FAILURE (Status))
269 return_ACPI_STATUS (Status);
272 /* Make sure that the hardware responded */
274 Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
275 &Value, ACPI_MTX_LOCK);
276 if (ACPI_FAILURE (Status))
278 return_ACPI_STATUS (Status);
283 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
284 "Could not enable %s event\n", AcpiUtGetEventName (Event)));
285 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
288 return_ACPI_STATUS (Status);
292 /*******************************************************************************
294 * FUNCTION: AcpiSetGpeType
296 * PARAMETERS: GpeDevice - Parent GPE Device
297 * GpeNumber - GPE level within the GPE block
298 * Type - New GPE type
302 * DESCRIPTION: Enable an ACPI event (general purpose)
304 ******************************************************************************/
308 ACPI_HANDLE GpeDevice,
312 ACPI_STATUS Status = AE_OK;
313 ACPI_GPE_EVENT_INFO *GpeEventInfo;
316 ACPI_FUNCTION_TRACE ("AcpiSetGpeType");
319 /* Ensure that we have a valid GPE number */
321 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
324 Status = AE_BAD_PARAMETER;
328 if ((GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK) == Type)
330 return_ACPI_STATUS (AE_OK);
333 /* Set the new type (will disable GPE if currently enabled) */
335 Status = AcpiEvSetGpeType (GpeEventInfo, Type);
338 return_ACPI_STATUS (Status);
342 /*******************************************************************************
344 * FUNCTION: AcpiEnableGpe
346 * PARAMETERS: GpeDevice - Parent GPE Device
347 * GpeNumber - GPE level within the GPE block
348 * Flags - Just enable, or also wake enable?
349 * Called from ISR or not
353 * DESCRIPTION: Enable an ACPI event (general purpose)
355 ******************************************************************************/
359 ACPI_HANDLE GpeDevice,
363 ACPI_STATUS Status = AE_OK;
364 ACPI_GPE_EVENT_INFO *GpeEventInfo;
367 ACPI_FUNCTION_TRACE ("AcpiEnableGpe");
370 /* Use semaphore lock if not executing at interrupt level */
372 if (Flags & ACPI_NOT_ISR)
374 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
375 if (ACPI_FAILURE (Status))
377 return_ACPI_STATUS (Status);
381 /* Ensure that we have a valid GPE number */
383 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
386 Status = AE_BAD_PARAMETER;
390 /* Perform the enable */
392 Status = AcpiEvEnableGpe (GpeEventInfo, TRUE);
395 if (Flags & ACPI_NOT_ISR)
397 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
399 return_ACPI_STATUS (Status);
403 /*******************************************************************************
405 * FUNCTION: AcpiDisableGpe
407 * PARAMETERS: GpeDevice - Parent GPE Device
408 * GpeNumber - GPE level within the GPE block
409 * Flags - Just disable, or also wake disable?
410 * Called from ISR or not
414 * DESCRIPTION: Disable an ACPI event (general purpose)
416 ******************************************************************************/
420 ACPI_HANDLE GpeDevice,
424 ACPI_STATUS Status = AE_OK;
425 ACPI_GPE_EVENT_INFO *GpeEventInfo;
428 ACPI_FUNCTION_TRACE ("AcpiDisableGpe");
431 /* Use semaphore lock if not executing at interrupt level */
433 if (Flags & ACPI_NOT_ISR)
435 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
436 if (ACPI_FAILURE (Status))
438 return_ACPI_STATUS (Status);
442 /* Ensure that we have a valid GPE number */
444 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
447 Status = AE_BAD_PARAMETER;
451 Status = AcpiEvDisableGpe (GpeEventInfo);
454 if (Flags & ACPI_NOT_ISR)
456 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
458 return_ACPI_STATUS (Status);
462 /*******************************************************************************
464 * FUNCTION: AcpiDisableEvent
466 * PARAMETERS: Event - The fixed eventto be enabled
471 * DESCRIPTION: Disable an ACPI event (fixed)
473 ******************************************************************************/
480 ACPI_STATUS Status = AE_OK;
484 ACPI_FUNCTION_TRACE ("AcpiDisableEvent");
487 /* Decode the Fixed Event */
489 if (Event > ACPI_EVENT_MAX)
491 return_ACPI_STATUS (AE_BAD_PARAMETER);
495 * Disable the requested fixed event (by writing a zero to the
496 * enable register bit)
498 Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
500 if (ACPI_FAILURE (Status))
502 return_ACPI_STATUS (Status);
505 Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
506 &Value, ACPI_MTX_LOCK);
507 if (ACPI_FAILURE (Status))
509 return_ACPI_STATUS (Status);
514 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
515 "Could not disable %s events\n", AcpiUtGetEventName (Event)));
516 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
519 return_ACPI_STATUS (Status);
523 /*******************************************************************************
525 * FUNCTION: AcpiClearEvent
527 * PARAMETERS: Event - The fixed event to be cleared
531 * DESCRIPTION: Clear an ACPI event (fixed)
533 ******************************************************************************/
539 ACPI_STATUS Status = AE_OK;
542 ACPI_FUNCTION_TRACE ("AcpiClearEvent");
545 /* Decode the Fixed Event */
547 if (Event > ACPI_EVENT_MAX)
549 return_ACPI_STATUS (AE_BAD_PARAMETER);
553 * Clear the requested fixed event (By writing a one to the
554 * status register bit)
556 Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
559 return_ACPI_STATUS (Status);
563 /*******************************************************************************
565 * FUNCTION: AcpiClearGpe
567 * PARAMETERS: GpeDevice - Parent GPE Device
568 * GpeNumber - GPE level within the GPE block
569 * Flags - Called from an ISR or not
573 * DESCRIPTION: Clear an ACPI event (general purpose)
575 ******************************************************************************/
579 ACPI_HANDLE GpeDevice,
583 ACPI_STATUS Status = AE_OK;
584 ACPI_GPE_EVENT_INFO *GpeEventInfo;
587 ACPI_FUNCTION_TRACE ("AcpiClearGpe");
590 /* Use semaphore lock if not executing at interrupt level */
592 if (Flags & ACPI_NOT_ISR)
594 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
595 if (ACPI_FAILURE (Status))
597 return_ACPI_STATUS (Status);
601 /* Ensure that we have a valid GPE number */
603 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
606 Status = AE_BAD_PARAMETER;
610 Status = AcpiHwClearGpe (GpeEventInfo);
613 if (Flags & ACPI_NOT_ISR)
615 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
617 return_ACPI_STATUS (Status);
621 /*******************************************************************************
623 * FUNCTION: AcpiGetEventStatus
625 * PARAMETERS: Event - The fixed event
626 * Event Status - Where the current status of the event will
631 * DESCRIPTION: Obtains and returns the current status of the event
633 ******************************************************************************/
638 ACPI_EVENT_STATUS *EventStatus)
640 ACPI_STATUS Status = AE_OK;
643 ACPI_FUNCTION_TRACE ("AcpiGetEventStatus");
648 return_ACPI_STATUS (AE_BAD_PARAMETER);
651 /* Decode the Fixed Event */
653 if (Event > ACPI_EVENT_MAX)
655 return_ACPI_STATUS (AE_BAD_PARAMETER);
658 /* Get the status of the requested fixed event */
660 Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
661 EventStatus, ACPI_MTX_LOCK);
663 return_ACPI_STATUS (Status);
667 /*******************************************************************************
669 * FUNCTION: AcpiGetGpeStatus
671 * PARAMETERS: GpeDevice - Parent GPE Device
672 * GpeNumber - GPE level within the GPE block
673 * Flags - Called from an ISR or not
674 * Event Status - Where the current status of the event will
679 * DESCRIPTION: Get status of an event (general purpose)
681 ******************************************************************************/
685 ACPI_HANDLE GpeDevice,
688 ACPI_EVENT_STATUS *EventStatus)
690 ACPI_STATUS Status = AE_OK;
691 ACPI_GPE_EVENT_INFO *GpeEventInfo;
694 ACPI_FUNCTION_TRACE ("AcpiGetGpeStatus");
697 /* Use semaphore lock if not executing at interrupt level */
699 if (Flags & ACPI_NOT_ISR)
701 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
702 if (ACPI_FAILURE (Status))
704 return_ACPI_STATUS (Status);
708 /* Ensure that we have a valid GPE number */
710 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
713 Status = AE_BAD_PARAMETER;
717 /* Obtain status on the requested GPE number */
719 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
722 if (Flags & ACPI_NOT_ISR)
724 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
726 return_ACPI_STATUS (Status);
730 /*******************************************************************************
732 * FUNCTION: AcpiInstallGpeBlock
734 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
735 * GpeBlockAddress - Address and SpaceID
736 * RegisterCount - Number of GPE register pairs in the block
737 * InterruptLevel - H/W interrupt for the block
741 * DESCRIPTION: Create and Install a block of GPE registers
743 ******************************************************************************/
746 AcpiInstallGpeBlock (
747 ACPI_HANDLE GpeDevice,
748 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
749 UINT32 RegisterCount,
750 UINT32 InterruptLevel)
753 ACPI_OPERAND_OBJECT *ObjDesc;
754 ACPI_NAMESPACE_NODE *Node;
755 ACPI_GPE_BLOCK_INFO *GpeBlock;
758 ACPI_FUNCTION_TRACE ("AcpiInstallGpeBlock");
762 (!GpeBlockAddress) ||
765 return_ACPI_STATUS (AE_BAD_PARAMETER);
768 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
769 if (ACPI_FAILURE (Status))
774 Node = AcpiNsMapHandleToNode (GpeDevice);
777 Status = AE_BAD_PARAMETER;
782 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
785 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
786 0, InterruptLevel, &GpeBlock);
787 if (ACPI_FAILURE (Status))
792 /* Get the DeviceObject attached to the node */
794 ObjDesc = AcpiNsGetAttachedObject (Node);
797 /* No object, create a new one */
799 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
802 Status = AE_NO_MEMORY;
806 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
808 /* Remove local reference to the object */
810 AcpiUtRemoveReference (ObjDesc);
812 if (ACPI_FAILURE (Status))
818 /* Install the GPE block in the DeviceObject */
820 ObjDesc->Device.GpeBlock = GpeBlock;
824 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
825 return_ACPI_STATUS (Status);
829 /*******************************************************************************
831 * FUNCTION: AcpiRemoveGpeBlock
833 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
837 * DESCRIPTION: Remove a previously installed block of GPE registers
839 ******************************************************************************/
843 ACPI_HANDLE GpeDevice)
845 ACPI_OPERAND_OBJECT *ObjDesc;
847 ACPI_NAMESPACE_NODE *Node;
850 ACPI_FUNCTION_TRACE ("AcpiRemoveGpeBlock");
855 return_ACPI_STATUS (AE_BAD_PARAMETER);
858 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
859 if (ACPI_FAILURE (Status))
864 Node = AcpiNsMapHandleToNode (GpeDevice);
867 Status = AE_BAD_PARAMETER;
871 /* Get the DeviceObject attached to the node */
873 ObjDesc = AcpiNsGetAttachedObject (Node);
875 !ObjDesc->Device.GpeBlock)
877 return_ACPI_STATUS (AE_NULL_OBJECT);
880 /* Delete the GPE block (but not the DeviceObject) */
882 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
883 if (ACPI_SUCCESS (Status))
885 ObjDesc->Device.GpeBlock = NULL;
889 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
890 return_ACPI_STATUS (Status);