1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2007, 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 portion 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__
120 #include <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/acevents.h>
122 #include <contrib/dev/acpica/acnamesp.h>
123 #include <contrib/dev/acpica/actables.h>
125 #define _COMPONENT ACPI_EVENTS
126 ACPI_MODULE_NAME ("evxfevnt")
129 /*******************************************************************************
131 * FUNCTION: AcpiEnable
137 * DESCRIPTION: Transfers the system into ACPI mode.
139 ******************************************************************************/
145 ACPI_STATUS Status = AE_OK;
148 ACPI_FUNCTION_TRACE (AcpiEnable);
151 /* ACPI tables must be present */
153 if (!AcpiTbTablesLoaded ())
155 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
158 /* Check current mode */
160 if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
162 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
166 /* Transition to ACPI mode */
168 Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
169 if (ACPI_FAILURE (Status))
171 ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
172 return_ACPI_STATUS (Status);
175 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
176 "Transition to ACPI mode successful\n"));
179 return_ACPI_STATUS (Status);
182 ACPI_EXPORT_SYMBOL (AcpiEnable)
185 /*******************************************************************************
187 * FUNCTION: AcpiDisable
193 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
195 ******************************************************************************/
201 ACPI_STATUS Status = AE_OK;
204 ACPI_FUNCTION_TRACE (AcpiDisable);
207 if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
209 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
210 "System is already in legacy (non-ACPI) mode\n"));
214 /* Transition to LEGACY mode */
216 Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
218 if (ACPI_FAILURE (Status))
220 ACPI_ERROR ((AE_INFO,
221 "Could not exit ACPI mode to legacy mode"));
222 return_ACPI_STATUS (Status);
225 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
228 return_ACPI_STATUS (Status);
231 ACPI_EXPORT_SYMBOL (AcpiDisable)
234 /*******************************************************************************
236 * FUNCTION: AcpiEnableEvent
238 * PARAMETERS: Event - The fixed eventto be enabled
243 * DESCRIPTION: Enable an ACPI event (fixed)
245 ******************************************************************************/
252 ACPI_STATUS Status = AE_OK;
256 ACPI_FUNCTION_TRACE (AcpiEnableEvent);
259 /* Decode the Fixed Event */
261 if (Event > ACPI_EVENT_MAX)
263 return_ACPI_STATUS (AE_BAD_PARAMETER);
267 * Enable the requested fixed event (by writing a one to the
268 * enable register bit)
270 Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 1);
271 if (ACPI_FAILURE (Status))
273 return_ACPI_STATUS (Status);
276 /* Make sure that the hardware responded */
278 Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
280 if (ACPI_FAILURE (Status))
282 return_ACPI_STATUS (Status);
287 ACPI_ERROR ((AE_INFO,
288 "Could not enable %s event", AcpiUtGetEventName (Event)));
289 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
292 return_ACPI_STATUS (Status);
295 ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
298 /*******************************************************************************
300 * FUNCTION: AcpiSetGpeType
302 * PARAMETERS: GpeDevice - Parent GPE Device
303 * GpeNumber - GPE level within the GPE block
304 * Type - New GPE type
308 * DESCRIPTION: Set the type of an individual GPE
310 ******************************************************************************/
314 ACPI_HANDLE GpeDevice,
318 ACPI_STATUS Status = AE_OK;
319 ACPI_GPE_EVENT_INFO *GpeEventInfo;
322 ACPI_FUNCTION_TRACE (AcpiSetGpeType);
325 /* Ensure that we have a valid GPE number */
327 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
330 Status = AE_BAD_PARAMETER;
334 if ((GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK) == Type)
336 return_ACPI_STATUS (AE_OK);
339 /* Set the new type (will disable GPE if currently enabled) */
341 Status = AcpiEvSetGpeType (GpeEventInfo, Type);
344 return_ACPI_STATUS (Status);
347 ACPI_EXPORT_SYMBOL (AcpiSetGpeType)
350 /*******************************************************************************
352 * FUNCTION: AcpiEnableGpe
354 * PARAMETERS: GpeDevice - Parent GPE Device
355 * GpeNumber - GPE level within the GPE block
356 * Flags - Just enable, or also wake enable?
357 * Called from ISR or not
361 * DESCRIPTION: Enable an ACPI event (general purpose)
363 ******************************************************************************/
367 ACPI_HANDLE GpeDevice,
371 ACPI_STATUS Status = AE_OK;
372 ACPI_GPE_EVENT_INFO *GpeEventInfo;
375 ACPI_FUNCTION_TRACE (AcpiEnableGpe);
378 /* Use semaphore lock if not executing at interrupt level */
380 if (Flags & ACPI_NOT_ISR)
382 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
383 if (ACPI_FAILURE (Status))
385 return_ACPI_STATUS (Status);
389 /* Ensure that we have a valid GPE number */
391 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
394 Status = AE_BAD_PARAMETER;
398 /* Perform the enable */
400 Status = AcpiEvEnableGpe (GpeEventInfo, TRUE);
403 if (Flags & ACPI_NOT_ISR)
405 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
407 return_ACPI_STATUS (Status);
410 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
413 /*******************************************************************************
415 * FUNCTION: AcpiDisableGpe
417 * PARAMETERS: GpeDevice - Parent GPE Device
418 * GpeNumber - GPE level within the GPE block
419 * Flags - Just disable, or also wake disable?
420 * Called from ISR or not
424 * DESCRIPTION: Disable an ACPI event (general purpose)
426 ******************************************************************************/
430 ACPI_HANDLE GpeDevice,
434 ACPI_STATUS Status = AE_OK;
435 ACPI_GPE_EVENT_INFO *GpeEventInfo;
438 ACPI_FUNCTION_TRACE (AcpiDisableGpe);
441 /* Use semaphore lock if not executing at interrupt level */
443 if (Flags & ACPI_NOT_ISR)
445 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
446 if (ACPI_FAILURE (Status))
448 return_ACPI_STATUS (Status);
452 /* Ensure that we have a valid GPE number */
454 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
457 Status = AE_BAD_PARAMETER;
461 Status = AcpiEvDisableGpe (GpeEventInfo);
464 if (Flags & ACPI_NOT_ISR)
466 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
468 return_ACPI_STATUS (Status);
471 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
474 /*******************************************************************************
476 * FUNCTION: AcpiDisableEvent
478 * PARAMETERS: Event - The fixed eventto be enabled
483 * DESCRIPTION: Disable an ACPI event (fixed)
485 ******************************************************************************/
492 ACPI_STATUS Status = AE_OK;
496 ACPI_FUNCTION_TRACE (AcpiDisableEvent);
499 /* Decode the Fixed Event */
501 if (Event > ACPI_EVENT_MAX)
503 return_ACPI_STATUS (AE_BAD_PARAMETER);
507 * Disable the requested fixed event (by writing a zero to the
508 * enable register bit)
510 Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 0);
511 if (ACPI_FAILURE (Status))
513 return_ACPI_STATUS (Status);
516 Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
518 if (ACPI_FAILURE (Status))
520 return_ACPI_STATUS (Status);
525 ACPI_ERROR ((AE_INFO,
526 "Could not disable %s events", AcpiUtGetEventName (Event)));
527 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
530 return_ACPI_STATUS (Status);
533 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
536 /*******************************************************************************
538 * FUNCTION: AcpiClearEvent
540 * PARAMETERS: Event - The fixed event to be cleared
544 * DESCRIPTION: Clear an ACPI event (fixed)
546 ******************************************************************************/
552 ACPI_STATUS Status = AE_OK;
555 ACPI_FUNCTION_TRACE (AcpiClearEvent);
558 /* Decode the Fixed Event */
560 if (Event > ACPI_EVENT_MAX)
562 return_ACPI_STATUS (AE_BAD_PARAMETER);
566 * Clear the requested fixed event (By writing a one to the
567 * status register bit)
569 Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId, 1);
571 return_ACPI_STATUS (Status);
574 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
577 /*******************************************************************************
579 * FUNCTION: AcpiClearGpe
581 * PARAMETERS: GpeDevice - Parent GPE Device
582 * GpeNumber - GPE level within the GPE block
583 * Flags - Called from an ISR or not
587 * DESCRIPTION: Clear an ACPI event (general purpose)
589 ******************************************************************************/
593 ACPI_HANDLE GpeDevice,
597 ACPI_STATUS Status = AE_OK;
598 ACPI_GPE_EVENT_INFO *GpeEventInfo;
601 ACPI_FUNCTION_TRACE (AcpiClearGpe);
604 /* Use semaphore lock if not executing at interrupt level */
606 if (Flags & ACPI_NOT_ISR)
608 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
609 if (ACPI_FAILURE (Status))
611 return_ACPI_STATUS (Status);
615 /* Ensure that we have a valid GPE number */
617 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
620 Status = AE_BAD_PARAMETER;
624 Status = AcpiHwClearGpe (GpeEventInfo);
627 if (Flags & ACPI_NOT_ISR)
629 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
631 return_ACPI_STATUS (Status);
634 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
637 /*******************************************************************************
639 * FUNCTION: AcpiGetEventStatus
641 * PARAMETERS: Event - The fixed event
642 * EventStatus - Where the current status of the event will
647 * DESCRIPTION: Obtains and returns the current status of the event
649 ******************************************************************************/
654 ACPI_EVENT_STATUS *EventStatus)
656 ACPI_STATUS Status = AE_OK;
659 ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
664 return_ACPI_STATUS (AE_BAD_PARAMETER);
667 /* Decode the Fixed Event */
669 if (Event > ACPI_EVENT_MAX)
671 return_ACPI_STATUS (AE_BAD_PARAMETER);
674 /* Get the status of the requested fixed event */
676 Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
679 return_ACPI_STATUS (Status);
682 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
685 /*******************************************************************************
687 * FUNCTION: AcpiGetGpeStatus
689 * PARAMETERS: GpeDevice - Parent GPE Device
690 * GpeNumber - GPE level within the GPE block
691 * Flags - Called from an ISR or not
692 * EventStatus - Where the current status of the event will
697 * DESCRIPTION: Get status of an event (general purpose)
699 ******************************************************************************/
703 ACPI_HANDLE GpeDevice,
706 ACPI_EVENT_STATUS *EventStatus)
708 ACPI_STATUS Status = AE_OK;
709 ACPI_GPE_EVENT_INFO *GpeEventInfo;
712 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
715 /* Use semaphore lock if not executing at interrupt level */
717 if (Flags & ACPI_NOT_ISR)
719 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
720 if (ACPI_FAILURE (Status))
722 return_ACPI_STATUS (Status);
726 /* Ensure that we have a valid GPE number */
728 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
731 Status = AE_BAD_PARAMETER;
735 /* Obtain status on the requested GPE number */
737 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
740 if (Flags & ACPI_NOT_ISR)
742 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
744 return_ACPI_STATUS (Status);
747 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
750 /*******************************************************************************
752 * FUNCTION: AcpiInstallGpeBlock
754 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
755 * GpeBlockAddress - Address and SpaceID
756 * RegisterCount - Number of GPE register pairs in the block
757 * InterruptNumber - H/W interrupt for the block
761 * DESCRIPTION: Create and Install a block of GPE registers
763 ******************************************************************************/
766 AcpiInstallGpeBlock (
767 ACPI_HANDLE GpeDevice,
768 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
769 UINT32 RegisterCount,
770 UINT32 InterruptNumber)
773 ACPI_OPERAND_OBJECT *ObjDesc;
774 ACPI_NAMESPACE_NODE *Node;
775 ACPI_GPE_BLOCK_INFO *GpeBlock;
778 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
782 (!GpeBlockAddress) ||
785 return_ACPI_STATUS (AE_BAD_PARAMETER);
788 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
789 if (ACPI_FAILURE (Status))
794 Node = AcpiNsMapHandleToNode (GpeDevice);
797 Status = AE_BAD_PARAMETER;
802 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
805 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
806 0, InterruptNumber, &GpeBlock);
807 if (ACPI_FAILURE (Status))
812 /* Run the _PRW methods and enable the GPEs */
814 Status = AcpiEvInitializeGpeBlock (Node, GpeBlock);
815 if (ACPI_FAILURE (Status))
820 /* Get the DeviceObject attached to the node */
822 ObjDesc = AcpiNsGetAttachedObject (Node);
825 /* No object, create a new one */
827 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
830 Status = AE_NO_MEMORY;
834 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
836 /* Remove local reference to the object */
838 AcpiUtRemoveReference (ObjDesc);
840 if (ACPI_FAILURE (Status))
846 /* Install the GPE block in the DeviceObject */
848 ObjDesc->Device.GpeBlock = GpeBlock;
852 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
853 return_ACPI_STATUS (Status);
856 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
859 /*******************************************************************************
861 * FUNCTION: AcpiRemoveGpeBlock
863 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
867 * DESCRIPTION: Remove a previously installed block of GPE registers
869 ******************************************************************************/
873 ACPI_HANDLE GpeDevice)
875 ACPI_OPERAND_OBJECT *ObjDesc;
877 ACPI_NAMESPACE_NODE *Node;
880 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
885 return_ACPI_STATUS (AE_BAD_PARAMETER);
888 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
889 if (ACPI_FAILURE (Status))
894 Node = AcpiNsMapHandleToNode (GpeDevice);
897 Status = AE_BAD_PARAMETER;
901 /* Get the DeviceObject attached to the node */
903 ObjDesc = AcpiNsGetAttachedObject (Node);
905 !ObjDesc->Device.GpeBlock)
907 return_ACPI_STATUS (AE_NULL_OBJECT);
910 /* Delete the GPE block (but not the DeviceObject) */
912 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
913 if (ACPI_SUCCESS (Status))
915 ObjDesc->Device.GpeBlock = NULL;
919 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
920 return_ACPI_STATUS (Status);
923 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)