gpio:Initial GPIO driver.(ARM)
[minix.git] / drivers / acpi / events / evxfevnt.c
blobe8a9e9802a66aa6df3c60e02c294ae1b14891972
1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #define __EVXFEVNT_C__
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acevents.h"
122 #include "acnamesp.h"
123 #include "actables.h"
125 #define _COMPONENT ACPI_EVENTS
126 ACPI_MODULE_NAME ("evxfevnt")
128 /* Local prototypes */
130 static ACPI_STATUS
131 AcpiEvGetGpeDevice (
132 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
133 ACPI_GPE_BLOCK_INFO *GpeBlock,
134 void *Context);
137 /*******************************************************************************
139 * FUNCTION: AcpiEnable
141 * PARAMETERS: None
143 * RETURN: Status
145 * DESCRIPTION: Transfers the system into ACPI mode.
147 ******************************************************************************/
149 ACPI_STATUS
150 AcpiEnable (
151 void)
153 ACPI_STATUS Status = AE_OK;
156 ACPI_FUNCTION_TRACE (AcpiEnable);
159 /* ACPI tables must be present */
161 if (!AcpiTbTablesLoaded ())
163 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
166 /* Check current mode */
168 if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
170 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
172 else
174 /* Transition to ACPI mode */
176 Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
177 if (ACPI_FAILURE (Status))
179 ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
180 return_ACPI_STATUS (Status);
183 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
184 "Transition to ACPI mode successful\n"));
187 return_ACPI_STATUS (Status);
190 ACPI_EXPORT_SYMBOL (AcpiEnable)
193 /*******************************************************************************
195 * FUNCTION: AcpiDisable
197 * PARAMETERS: None
199 * RETURN: Status
201 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
203 ******************************************************************************/
205 ACPI_STATUS
206 AcpiDisable (
207 void)
209 ACPI_STATUS Status = AE_OK;
212 ACPI_FUNCTION_TRACE (AcpiDisable);
215 if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
217 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
218 "System is already in legacy (non-ACPI) mode\n"));
220 else
222 /* Transition to LEGACY mode */
224 Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
226 if (ACPI_FAILURE (Status))
228 ACPI_ERROR ((AE_INFO,
229 "Could not exit ACPI mode to legacy mode"));
230 return_ACPI_STATUS (Status);
233 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
236 return_ACPI_STATUS (Status);
239 ACPI_EXPORT_SYMBOL (AcpiDisable)
242 /*******************************************************************************
244 * FUNCTION: AcpiEnableEvent
246 * PARAMETERS: Event - The fixed eventto be enabled
247 * Flags - Reserved
249 * RETURN: Status
251 * DESCRIPTION: Enable an ACPI event (fixed)
253 ******************************************************************************/
255 ACPI_STATUS
256 AcpiEnableEvent (
257 UINT32 Event,
258 UINT32 Flags)
260 ACPI_STATUS Status = AE_OK;
261 UINT32 Value;
264 ACPI_FUNCTION_TRACE (AcpiEnableEvent);
267 /* Decode the Fixed Event */
269 if (Event > ACPI_EVENT_MAX)
271 return_ACPI_STATUS (AE_BAD_PARAMETER);
275 * Enable the requested fixed event (by writing a one to the enable
276 * register bit)
278 Status = AcpiWriteBitRegister (
279 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
280 ACPI_ENABLE_EVENT);
281 if (ACPI_FAILURE (Status))
283 return_ACPI_STATUS (Status);
286 /* Make sure that the hardware responded */
288 Status = AcpiReadBitRegister (
289 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
290 if (ACPI_FAILURE (Status))
292 return_ACPI_STATUS (Status);
295 if (Value != 1)
297 ACPI_ERROR ((AE_INFO,
298 "Could not enable %s event", AcpiUtGetEventName (Event)));
299 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
302 return_ACPI_STATUS (Status);
305 ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
309 /*******************************************************************************
311 * FUNCTION: AcpiGpeWakeup
313 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
314 * GpeNumber - GPE level within the GPE block
315 * Action - Enable or Disable
317 * RETURN: Status
319 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
321 ******************************************************************************/
323 ACPI_STATUS
324 AcpiGpeWakeup (
325 ACPI_HANDLE GpeDevice,
326 UINT32 GpeNumber,
327 UINT8 Action)
329 ACPI_STATUS Status = AE_OK;
330 ACPI_GPE_EVENT_INFO *GpeEventInfo;
331 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
332 ACPI_CPU_FLAGS Flags;
333 UINT32 RegisterBit;
336 ACPI_FUNCTION_TRACE (AcpiGpeWakeup);
339 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
341 /* Ensure that we have a valid GPE number */
343 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
344 if (!GpeEventInfo)
346 Status = AE_BAD_PARAMETER;
347 goto UnlockAndExit;
350 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
351 if (!GpeRegisterInfo)
353 Status = AE_NOT_EXIST;
354 goto UnlockAndExit;
357 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
359 /* Perform the action */
361 switch (Action)
363 case ACPI_GPE_ENABLE:
364 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
365 break;
367 case ACPI_GPE_DISABLE:
368 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
369 break;
371 default:
372 ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
373 Status = AE_BAD_PARAMETER;
374 break;
377 UnlockAndExit:
378 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
379 return_ACPI_STATUS (Status);
382 ACPI_EXPORT_SYMBOL (AcpiGpeWakeup)
385 /*******************************************************************************
387 * FUNCTION: AcpiEnableGpe
389 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
390 * GpeNumber - GPE level within the GPE block
392 * RETURN: Status
394 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
395 * hardware-enabled.
397 ******************************************************************************/
399 ACPI_STATUS
400 AcpiEnableGpe (
401 ACPI_HANDLE GpeDevice,
402 UINT32 GpeNumber)
404 ACPI_STATUS Status = AE_OK;
405 ACPI_GPE_EVENT_INFO *GpeEventInfo;
406 ACPI_CPU_FLAGS Flags;
409 ACPI_FUNCTION_TRACE (AcpiEnableGpe);
412 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
414 /* Ensure that we have a valid GPE number */
416 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
417 if (!GpeEventInfo)
419 Status = AE_BAD_PARAMETER;
420 goto UnlockAndExit;
423 if (GpeEventInfo->RuntimeCount == ACPI_UINT8_MAX)
425 Status = AE_LIMIT; /* Too many references */
426 goto UnlockAndExit;
429 GpeEventInfo->RuntimeCount++;
430 if (GpeEventInfo->RuntimeCount == 1)
432 Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
433 if (ACPI_SUCCESS (Status))
435 Status = AcpiEvEnableGpe (GpeEventInfo);
437 if (ACPI_FAILURE (Status))
439 GpeEventInfo->RuntimeCount--;
443 UnlockAndExit:
444 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
445 return_ACPI_STATUS (Status);
448 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
451 /*******************************************************************************
453 * FUNCTION: AcpiDisableGpe
455 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
456 * GpeNumber - GPE level within the GPE block
458 * RETURN: Status
460 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
461 * removed, only then is the GPE disabled (for runtime GPEs), or
462 * the GPE mask bit disabled (for wake GPEs)
464 ******************************************************************************/
466 ACPI_STATUS
467 AcpiDisableGpe (
468 ACPI_HANDLE GpeDevice,
469 UINT32 GpeNumber)
471 ACPI_STATUS Status = AE_OK;
472 ACPI_GPE_EVENT_INFO *GpeEventInfo;
473 ACPI_CPU_FLAGS Flags;
476 ACPI_FUNCTION_TRACE (AcpiDisableGpe);
479 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
481 /* Ensure that we have a valid GPE number */
483 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
484 if (!GpeEventInfo)
486 Status = AE_BAD_PARAMETER;
487 goto UnlockAndExit;
490 /* Hardware-disable a runtime GPE on removal of the last reference */
492 if (!GpeEventInfo->RuntimeCount)
494 Status = AE_LIMIT; /* There are no references to remove */
495 goto UnlockAndExit;
498 GpeEventInfo->RuntimeCount--;
499 if (!GpeEventInfo->RuntimeCount)
501 Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
502 if (ACPI_SUCCESS (Status))
504 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
506 if (ACPI_FAILURE (Status))
508 GpeEventInfo->RuntimeCount++;
512 UnlockAndExit:
513 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
514 return_ACPI_STATUS (Status);
517 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
520 /*******************************************************************************
522 * FUNCTION: AcpiSetGpe
524 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
525 * GpeNumber - GPE level within the GPE block
526 * Action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
528 * RETURN: Status
530 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
531 * the reference count mechanism used in the AcpiEnableGpe and
532 * AcpiDisableGpe interfaces -- and should be used with care.
534 * Note: Typically used to disable a runtime GPE for short period of time,
535 * then re-enable it, without disturbing the existing reference counts. This
536 * is useful, for example, in the Embedded Controller (EC) driver.
538 ******************************************************************************/
540 ACPI_STATUS
541 AcpiSetGpe (
542 ACPI_HANDLE GpeDevice,
543 UINT32 GpeNumber,
544 UINT8 Action)
546 ACPI_GPE_EVENT_INFO *GpeEventInfo;
547 ACPI_STATUS Status;
548 ACPI_CPU_FLAGS Flags;
551 ACPI_FUNCTION_TRACE (AcpiSetGpe);
554 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
556 /* Ensure that we have a valid GPE number */
558 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
559 if (!GpeEventInfo)
561 Status = AE_BAD_PARAMETER;
562 goto UnlockAndExit;
565 /* Perform the action */
567 switch (Action)
569 case ACPI_GPE_ENABLE:
570 Status = AcpiEvEnableGpe (GpeEventInfo);
571 break;
573 case ACPI_GPE_DISABLE:
574 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
575 break;
577 default:
578 Status = AE_BAD_PARAMETER;
579 break;
582 UnlockAndExit:
583 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
584 return_ACPI_STATUS (Status);
587 ACPI_EXPORT_SYMBOL (AcpiSetGpe)
590 /*******************************************************************************
592 * FUNCTION: AcpiDisableEvent
594 * PARAMETERS: Event - The fixed eventto be enabled
595 * Flags - Reserved
597 * RETURN: Status
599 * DESCRIPTION: Disable an ACPI event (fixed)
601 ******************************************************************************/
603 ACPI_STATUS
604 AcpiDisableEvent (
605 UINT32 Event,
606 UINT32 Flags)
608 ACPI_STATUS Status = AE_OK;
609 UINT32 Value;
612 ACPI_FUNCTION_TRACE (AcpiDisableEvent);
615 /* Decode the Fixed Event */
617 if (Event > ACPI_EVENT_MAX)
619 return_ACPI_STATUS (AE_BAD_PARAMETER);
623 * Disable the requested fixed event (by writing a zero to the enable
624 * register bit)
626 Status = AcpiWriteBitRegister (
627 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
628 ACPI_DISABLE_EVENT);
629 if (ACPI_FAILURE (Status))
631 return_ACPI_STATUS (Status);
634 Status = AcpiReadBitRegister (
635 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
636 if (ACPI_FAILURE (Status))
638 return_ACPI_STATUS (Status);
641 if (Value != 0)
643 ACPI_ERROR ((AE_INFO,
644 "Could not disable %s events", AcpiUtGetEventName (Event)));
645 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
648 return_ACPI_STATUS (Status);
651 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
654 /*******************************************************************************
656 * FUNCTION: AcpiClearEvent
658 * PARAMETERS: Event - The fixed event to be cleared
660 * RETURN: Status
662 * DESCRIPTION: Clear an ACPI event (fixed)
664 ******************************************************************************/
666 ACPI_STATUS
667 AcpiClearEvent (
668 UINT32 Event)
670 ACPI_STATUS Status = AE_OK;
673 ACPI_FUNCTION_TRACE (AcpiClearEvent);
676 /* Decode the Fixed Event */
678 if (Event > ACPI_EVENT_MAX)
680 return_ACPI_STATUS (AE_BAD_PARAMETER);
684 * Clear the requested fixed event (By writing a one to the status
685 * register bit)
687 Status = AcpiWriteBitRegister (
688 AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
689 ACPI_CLEAR_STATUS);
691 return_ACPI_STATUS (Status);
694 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
697 /*******************************************************************************
699 * FUNCTION: AcpiClearGpe
701 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
702 * GpeNumber - GPE level within the GPE block
704 * RETURN: Status
706 * DESCRIPTION: Clear an ACPI event (general purpose)
708 ******************************************************************************/
710 ACPI_STATUS
711 AcpiClearGpe (
712 ACPI_HANDLE GpeDevice,
713 UINT32 GpeNumber)
715 ACPI_STATUS Status = AE_OK;
716 ACPI_GPE_EVENT_INFO *GpeEventInfo;
717 ACPI_CPU_FLAGS Flags;
720 ACPI_FUNCTION_TRACE (AcpiClearGpe);
723 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
725 /* Ensure that we have a valid GPE number */
727 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
728 if (!GpeEventInfo)
730 Status = AE_BAD_PARAMETER;
731 goto UnlockAndExit;
734 Status = AcpiHwClearGpe (GpeEventInfo);
736 UnlockAndExit:
737 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
738 return_ACPI_STATUS (Status);
741 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
744 /*******************************************************************************
746 * FUNCTION: AcpiGetEventStatus
748 * PARAMETERS: Event - The fixed event
749 * EventStatus - Where the current status of the event will
750 * be returned
752 * RETURN: Status
754 * DESCRIPTION: Obtains and returns the current status of the event
756 ******************************************************************************/
758 ACPI_STATUS
759 AcpiGetEventStatus (
760 UINT32 Event,
761 ACPI_EVENT_STATUS *EventStatus)
763 ACPI_STATUS Status = AE_OK;
766 ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
769 if (!EventStatus)
771 return_ACPI_STATUS (AE_BAD_PARAMETER);
774 /* Decode the Fixed Event */
776 if (Event > ACPI_EVENT_MAX)
778 return_ACPI_STATUS (AE_BAD_PARAMETER);
781 /* Get the status of the requested fixed event */
783 Status = AcpiReadBitRegister (
784 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, EventStatus);
786 return_ACPI_STATUS (Status);
789 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
792 /*******************************************************************************
794 * FUNCTION: AcpiGetGpeStatus
796 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
797 * GpeNumber - GPE level within the GPE block
798 * EventStatus - Where the current status of the event will
799 * be returned
801 * RETURN: Status
803 * DESCRIPTION: Get status of an event (general purpose)
805 ******************************************************************************/
807 ACPI_STATUS
808 AcpiGetGpeStatus (
809 ACPI_HANDLE GpeDevice,
810 UINT32 GpeNumber,
811 ACPI_EVENT_STATUS *EventStatus)
813 ACPI_STATUS Status = AE_OK;
814 ACPI_GPE_EVENT_INFO *GpeEventInfo;
815 ACPI_CPU_FLAGS Flags;
818 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
821 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
823 /* Ensure that we have a valid GPE number */
825 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
826 if (!GpeEventInfo)
828 Status = AE_BAD_PARAMETER;
829 goto UnlockAndExit;
832 /* Obtain status on the requested GPE number */
834 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
836 UnlockAndExit:
837 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
838 return_ACPI_STATUS (Status);
841 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
844 /*******************************************************************************
846 * FUNCTION: AcpiInstallGpeBlock
848 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
849 * GpeBlockAddress - Address and SpaceID
850 * RegisterCount - Number of GPE register pairs in the block
851 * InterruptNumber - H/W interrupt for the block
853 * RETURN: Status
855 * DESCRIPTION: Create and Install a block of GPE registers
857 ******************************************************************************/
859 ACPI_STATUS
860 AcpiInstallGpeBlock (
861 ACPI_HANDLE GpeDevice,
862 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
863 UINT32 RegisterCount,
864 UINT32 InterruptNumber)
866 ACPI_STATUS Status;
867 ACPI_OPERAND_OBJECT *ObjDesc;
868 ACPI_NAMESPACE_NODE *Node;
869 ACPI_GPE_BLOCK_INFO *GpeBlock;
872 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
875 if ((!GpeDevice) ||
876 (!GpeBlockAddress) ||
877 (!RegisterCount))
879 return_ACPI_STATUS (AE_BAD_PARAMETER);
882 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
883 if (ACPI_FAILURE (Status))
885 return (Status);
888 Node = AcpiNsValidateHandle (GpeDevice);
889 if (!Node)
891 Status = AE_BAD_PARAMETER;
892 goto UnlockAndExit;
896 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
897 * is always zero
899 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
900 0, InterruptNumber, &GpeBlock);
901 if (ACPI_FAILURE (Status))
903 goto UnlockAndExit;
906 /* Install block in the DeviceObject attached to the node */
908 ObjDesc = AcpiNsGetAttachedObject (Node);
909 if (!ObjDesc)
912 * No object, create a new one (Device nodes do not always have
913 * an attached object)
915 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
916 if (!ObjDesc)
918 Status = AE_NO_MEMORY;
919 goto UnlockAndExit;
922 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
924 /* Remove local reference to the object */
926 AcpiUtRemoveReference (ObjDesc);
927 if (ACPI_FAILURE (Status))
929 goto UnlockAndExit;
933 /* Now install the GPE block in the DeviceObject */
935 ObjDesc->Device.GpeBlock = GpeBlock;
937 /* Run the _PRW methods and enable the runtime GPEs in the new block */
939 Status = AcpiEvInitializeGpeBlock (Node, GpeBlock);
942 UnlockAndExit:
943 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
944 return_ACPI_STATUS (Status);
947 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
950 /*******************************************************************************
952 * FUNCTION: AcpiRemoveGpeBlock
954 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
956 * RETURN: Status
958 * DESCRIPTION: Remove a previously installed block of GPE registers
960 ******************************************************************************/
962 ACPI_STATUS
963 AcpiRemoveGpeBlock (
964 ACPI_HANDLE GpeDevice)
966 ACPI_OPERAND_OBJECT *ObjDesc;
967 ACPI_STATUS Status;
968 ACPI_NAMESPACE_NODE *Node;
971 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
974 if (!GpeDevice)
976 return_ACPI_STATUS (AE_BAD_PARAMETER);
979 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
980 if (ACPI_FAILURE (Status))
982 return (Status);
985 Node = AcpiNsValidateHandle (GpeDevice);
986 if (!Node)
988 Status = AE_BAD_PARAMETER;
989 goto UnlockAndExit;
992 /* Get the DeviceObject attached to the node */
994 ObjDesc = AcpiNsGetAttachedObject (Node);
995 if (!ObjDesc ||
996 !ObjDesc->Device.GpeBlock)
998 return_ACPI_STATUS (AE_NULL_OBJECT);
1001 /* Delete the GPE block (but not the DeviceObject) */
1003 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
1004 if (ACPI_SUCCESS (Status))
1006 ObjDesc->Device.GpeBlock = NULL;
1009 UnlockAndExit:
1010 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1011 return_ACPI_STATUS (Status);
1014 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
1017 /*******************************************************************************
1019 * FUNCTION: AcpiGetGpeDevice
1021 * PARAMETERS: Index - System GPE index (0-CurrentGpeCount)
1022 * GpeDevice - Where the parent GPE Device is returned
1024 * RETURN: Status
1026 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
1027 * gpe device indicates that the gpe number is contained in one of
1028 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
1030 ******************************************************************************/
1032 ACPI_STATUS
1033 AcpiGetGpeDevice (
1034 UINT32 Index,
1035 ACPI_HANDLE *GpeDevice)
1037 ACPI_GPE_DEVICE_INFO Info;
1038 ACPI_STATUS Status;
1041 ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
1044 if (!GpeDevice)
1046 return_ACPI_STATUS (AE_BAD_PARAMETER);
1049 if (Index >= AcpiCurrentGpeCount)
1051 return_ACPI_STATUS (AE_NOT_EXIST);
1054 /* Setup and walk the GPE list */
1056 Info.Index = Index;
1057 Info.Status = AE_NOT_EXIST;
1058 Info.GpeDevice = NULL;
1059 Info.NextBlockBaseIndex = 0;
1061 Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
1062 if (ACPI_FAILURE (Status))
1064 return_ACPI_STATUS (Status);
1067 *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
1068 return_ACPI_STATUS (Info.Status);
1071 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
1074 /*******************************************************************************
1076 * FUNCTION: AcpiEvGetGpeDevice
1078 * PARAMETERS: GPE_WALK_CALLBACK
1080 * RETURN: Status
1082 * DESCRIPTION: Matches the input GPE index (0-CurrentGpeCount) with a GPE
1083 * block device. NULL if the GPE is one of the FADT-defined GPEs.
1085 ******************************************************************************/
1087 static ACPI_STATUS
1088 AcpiEvGetGpeDevice (
1089 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
1090 ACPI_GPE_BLOCK_INFO *GpeBlock,
1091 void *Context)
1093 ACPI_GPE_DEVICE_INFO *Info = Context;
1096 /* Increment Index by the number of GPEs in this block */
1098 Info->NextBlockBaseIndex += GpeBlock->GpeCount;
1100 if (Info->Index < Info->NextBlockBaseIndex)
1103 * The GPE index is within this block, get the node. Leave the node
1104 * NULL for the FADT-defined GPEs
1106 if ((GpeBlock->Node)->Type == ACPI_TYPE_DEVICE)
1108 Info->GpeDevice = GpeBlock->Node;
1111 Info->Status = AE_OK;
1112 return (AE_CTRL_END);
1115 return (AE_OK);
1119 /******************************************************************************
1121 * FUNCTION: AcpiDisableAllGpes
1123 * PARAMETERS: None
1125 * RETURN: Status
1127 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
1129 ******************************************************************************/
1131 ACPI_STATUS
1132 AcpiDisableAllGpes (
1133 void)
1135 ACPI_STATUS Status;
1138 ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
1141 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
1142 if (ACPI_FAILURE (Status))
1144 return_ACPI_STATUS (Status);
1147 Status = AcpiHwDisableAllGpes ();
1148 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1150 return_ACPI_STATUS (Status);
1154 /******************************************************************************
1156 * FUNCTION: AcpiEnableAllRuntimeGpes
1158 * PARAMETERS: None
1160 * RETURN: Status
1162 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
1164 ******************************************************************************/
1166 ACPI_STATUS
1167 AcpiEnableAllRuntimeGpes (
1168 void)
1170 ACPI_STATUS Status;
1173 ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
1176 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
1177 if (ACPI_FAILURE (Status))
1179 return_ACPI_STATUS (Status);
1182 Status = AcpiHwEnableAllRuntimeGpes ();
1183 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1185 return_ACPI_STATUS (Status);