No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / events / evxfevnt.c
blobbc24f18c51e247ae64aee8b408d907baa3bd589a
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 - 2009, 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)
308 /*******************************************************************************
310 * FUNCTION: AcpiSetGpeType
312 * PARAMETERS: GpeDevice - Parent GPE Device
313 * GpeNumber - GPE level within the GPE block
314 * Type - New GPE type
316 * RETURN: Status
318 * DESCRIPTION: Set the type of an individual GPE
320 ******************************************************************************/
322 ACPI_STATUS
323 AcpiSetGpeType (
324 ACPI_HANDLE GpeDevice,
325 UINT32 GpeNumber,
326 UINT8 Type)
328 ACPI_STATUS Status = AE_OK;
329 ACPI_GPE_EVENT_INFO *GpeEventInfo;
332 ACPI_FUNCTION_TRACE (AcpiSetGpeType);
335 /* Ensure that we have a valid GPE number */
337 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
338 if (!GpeEventInfo)
340 Status = AE_BAD_PARAMETER;
341 goto UnlockAndExit;
344 if ((GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK) == Type)
346 return_ACPI_STATUS (AE_OK);
349 /* Set the new type (will disable GPE if currently enabled) */
351 Status = AcpiEvSetGpeType (GpeEventInfo, Type);
353 UnlockAndExit:
354 return_ACPI_STATUS (Status);
357 ACPI_EXPORT_SYMBOL (AcpiSetGpeType)
360 /*******************************************************************************
362 * FUNCTION: AcpiEnableGpe
364 * PARAMETERS: GpeDevice - Parent GPE Device
365 * GpeNumber - GPE level within the GPE block
366 * Flags - Just enable, or also wake enable?
367 * Called from ISR or not
369 * RETURN: Status
371 * DESCRIPTION: Enable an ACPI event (general purpose)
373 ******************************************************************************/
375 ACPI_STATUS
376 AcpiEnableGpe (
377 ACPI_HANDLE GpeDevice,
378 UINT32 GpeNumber,
379 UINT32 Flags)
381 ACPI_STATUS Status = AE_OK;
382 ACPI_GPE_EVENT_INFO *GpeEventInfo;
385 ACPI_FUNCTION_TRACE (AcpiEnableGpe);
388 /* Use semaphore lock if not executing at interrupt level */
390 if (Flags & ACPI_NOT_ISR)
392 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
393 if (ACPI_FAILURE (Status))
395 return_ACPI_STATUS (Status);
399 /* Ensure that we have a valid GPE number */
401 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
402 if (!GpeEventInfo)
404 Status = AE_BAD_PARAMETER;
405 goto UnlockAndExit;
408 /* Perform the enable */
410 Status = AcpiEvEnableGpe (GpeEventInfo, TRUE);
412 UnlockAndExit:
413 if (Flags & ACPI_NOT_ISR)
415 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
417 return_ACPI_STATUS (Status);
420 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
423 /*******************************************************************************
425 * FUNCTION: AcpiDisableGpe
427 * PARAMETERS: GpeDevice - Parent GPE Device
428 * GpeNumber - GPE level within the GPE block
429 * Flags - Just disable, or also wake disable?
430 * Called from ISR or not
432 * RETURN: Status
434 * DESCRIPTION: Disable an ACPI event (general purpose)
436 ******************************************************************************/
438 ACPI_STATUS
439 AcpiDisableGpe (
440 ACPI_HANDLE GpeDevice,
441 UINT32 GpeNumber,
442 UINT32 Flags)
444 ACPI_STATUS Status = AE_OK;
445 ACPI_GPE_EVENT_INFO *GpeEventInfo;
448 ACPI_FUNCTION_TRACE (AcpiDisableGpe);
451 /* Use semaphore lock if not executing at interrupt level */
453 if (Flags & ACPI_NOT_ISR)
455 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
456 if (ACPI_FAILURE (Status))
458 return_ACPI_STATUS (Status);
462 /* Ensure that we have a valid GPE number */
464 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
465 if (!GpeEventInfo)
467 Status = AE_BAD_PARAMETER;
468 goto UnlockAndExit;
471 Status = AcpiEvDisableGpe (GpeEventInfo);
473 UnlockAndExit:
474 if (Flags & ACPI_NOT_ISR)
476 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
478 return_ACPI_STATUS (Status);
481 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
484 /*******************************************************************************
486 * FUNCTION: AcpiDisableEvent
488 * PARAMETERS: Event - The fixed eventto be enabled
489 * Flags - Reserved
491 * RETURN: Status
493 * DESCRIPTION: Disable an ACPI event (fixed)
495 ******************************************************************************/
497 ACPI_STATUS
498 AcpiDisableEvent (
499 UINT32 Event,
500 UINT32 Flags)
502 ACPI_STATUS Status = AE_OK;
503 UINT32 Value;
506 ACPI_FUNCTION_TRACE (AcpiDisableEvent);
509 /* Decode the Fixed Event */
511 if (Event > ACPI_EVENT_MAX)
513 return_ACPI_STATUS (AE_BAD_PARAMETER);
517 * Disable the requested fixed event (by writing a zero to the enable
518 * register bit)
520 Status = AcpiWriteBitRegister (
521 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
522 ACPI_DISABLE_EVENT);
523 if (ACPI_FAILURE (Status))
525 return_ACPI_STATUS (Status);
528 Status = AcpiReadBitRegister (
529 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
530 if (ACPI_FAILURE (Status))
532 return_ACPI_STATUS (Status);
535 if (Value != 0)
537 ACPI_ERROR ((AE_INFO,
538 "Could not disable %s events", AcpiUtGetEventName (Event)));
539 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
542 return_ACPI_STATUS (Status);
545 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
548 /*******************************************************************************
550 * FUNCTION: AcpiClearEvent
552 * PARAMETERS: Event - The fixed event to be cleared
554 * RETURN: Status
556 * DESCRIPTION: Clear an ACPI event (fixed)
558 ******************************************************************************/
560 ACPI_STATUS
561 AcpiClearEvent (
562 UINT32 Event)
564 ACPI_STATUS Status = AE_OK;
567 ACPI_FUNCTION_TRACE (AcpiClearEvent);
570 /* Decode the Fixed Event */
572 if (Event > ACPI_EVENT_MAX)
574 return_ACPI_STATUS (AE_BAD_PARAMETER);
578 * Clear the requested fixed event (By writing a one to the status
579 * register bit)
581 Status = AcpiWriteBitRegister (
582 AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
583 ACPI_CLEAR_STATUS);
585 return_ACPI_STATUS (Status);
588 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
591 /*******************************************************************************
593 * FUNCTION: AcpiClearGpe
595 * PARAMETERS: GpeDevice - Parent GPE Device
596 * GpeNumber - GPE level within the GPE block
597 * Flags - Called from an ISR or not
599 * RETURN: Status
601 * DESCRIPTION: Clear an ACPI event (general purpose)
603 ******************************************************************************/
605 ACPI_STATUS
606 AcpiClearGpe (
607 ACPI_HANDLE GpeDevice,
608 UINT32 GpeNumber,
609 UINT32 Flags)
611 ACPI_STATUS Status = AE_OK;
612 ACPI_GPE_EVENT_INFO *GpeEventInfo;
615 ACPI_FUNCTION_TRACE (AcpiClearGpe);
618 /* Use semaphore lock if not executing at interrupt level */
620 if (Flags & ACPI_NOT_ISR)
622 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
623 if (ACPI_FAILURE (Status))
625 return_ACPI_STATUS (Status);
629 /* Ensure that we have a valid GPE number */
631 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
632 if (!GpeEventInfo)
634 Status = AE_BAD_PARAMETER;
635 goto UnlockAndExit;
638 Status = AcpiHwClearGpe (GpeEventInfo);
640 UnlockAndExit:
641 if (Flags & ACPI_NOT_ISR)
643 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
645 return_ACPI_STATUS (Status);
648 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
651 /*******************************************************************************
653 * FUNCTION: AcpiGetEventStatus
655 * PARAMETERS: Event - The fixed event
656 * EventStatus - Where the current status of the event will
657 * be returned
659 * RETURN: Status
661 * DESCRIPTION: Obtains and returns the current status of the event
663 ******************************************************************************/
665 ACPI_STATUS
666 AcpiGetEventStatus (
667 UINT32 Event,
668 ACPI_EVENT_STATUS *EventStatus)
670 ACPI_STATUS Status = AE_OK;
673 ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
676 if (!EventStatus)
678 return_ACPI_STATUS (AE_BAD_PARAMETER);
681 /* Decode the Fixed Event */
683 if (Event > ACPI_EVENT_MAX)
685 return_ACPI_STATUS (AE_BAD_PARAMETER);
688 /* Get the status of the requested fixed event */
690 Status = AcpiReadBitRegister (
691 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, EventStatus);
693 return_ACPI_STATUS (Status);
696 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
699 /*******************************************************************************
701 * FUNCTION: AcpiGetGpeStatus
703 * PARAMETERS: GpeDevice - Parent GPE Device
704 * GpeNumber - GPE level within the GPE block
705 * Flags - Called from an ISR or not
706 * EventStatus - Where the current status of the event will
707 * be returned
709 * RETURN: Status
711 * DESCRIPTION: Get status of an event (general purpose)
713 ******************************************************************************/
715 ACPI_STATUS
716 AcpiGetGpeStatus (
717 ACPI_HANDLE GpeDevice,
718 UINT32 GpeNumber,
719 UINT32 Flags,
720 ACPI_EVENT_STATUS *EventStatus)
722 ACPI_STATUS Status = AE_OK;
723 ACPI_GPE_EVENT_INFO *GpeEventInfo;
726 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
729 /* Use semaphore lock if not executing at interrupt level */
731 if (Flags & ACPI_NOT_ISR)
733 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
734 if (ACPI_FAILURE (Status))
736 return_ACPI_STATUS (Status);
740 /* Ensure that we have a valid GPE number */
742 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
743 if (!GpeEventInfo)
745 Status = AE_BAD_PARAMETER;
746 goto UnlockAndExit;
749 /* Obtain status on the requested GPE number */
751 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
753 UnlockAndExit:
754 if (Flags & ACPI_NOT_ISR)
756 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
758 return_ACPI_STATUS (Status);
761 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
764 /*******************************************************************************
766 * FUNCTION: AcpiInstallGpeBlock
768 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
769 * GpeBlockAddress - Address and SpaceID
770 * RegisterCount - Number of GPE register pairs in the block
771 * InterruptNumber - H/W interrupt for the block
773 * RETURN: Status
775 * DESCRIPTION: Create and Install a block of GPE registers
777 ******************************************************************************/
779 ACPI_STATUS
780 AcpiInstallGpeBlock (
781 ACPI_HANDLE GpeDevice,
782 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
783 UINT32 RegisterCount,
784 UINT32 InterruptNumber)
786 ACPI_STATUS Status;
787 ACPI_OPERAND_OBJECT *ObjDesc;
788 ACPI_NAMESPACE_NODE *Node;
789 ACPI_GPE_BLOCK_INFO *GpeBlock;
792 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
795 if ((!GpeDevice) ||
796 (!GpeBlockAddress) ||
797 (!RegisterCount))
799 return_ACPI_STATUS (AE_BAD_PARAMETER);
802 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
803 if (ACPI_FAILURE (Status))
805 return (Status);
808 Node = AcpiNsMapHandleToNode (GpeDevice);
809 if (!Node)
811 Status = AE_BAD_PARAMETER;
812 goto UnlockAndExit;
816 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
817 * is always zero
819 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
820 0, InterruptNumber, &GpeBlock);
821 if (ACPI_FAILURE (Status))
823 goto UnlockAndExit;
826 /* Run the _PRW methods and enable the GPEs */
828 Status = AcpiEvInitializeGpeBlock (Node, GpeBlock);
829 if (ACPI_FAILURE (Status))
831 goto UnlockAndExit;
834 /* Get the DeviceObject attached to the node */
836 ObjDesc = AcpiNsGetAttachedObject (Node);
837 if (!ObjDesc)
839 /* No object, create a new one */
841 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
842 if (!ObjDesc)
844 Status = AE_NO_MEMORY;
845 goto UnlockAndExit;
848 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
850 /* Remove local reference to the object */
852 AcpiUtRemoveReference (ObjDesc);
854 if (ACPI_FAILURE (Status))
856 goto UnlockAndExit;
860 /* Install the GPE block in the DeviceObject */
862 ObjDesc->Device.GpeBlock = GpeBlock;
865 UnlockAndExit:
866 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
867 return_ACPI_STATUS (Status);
870 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
873 /*******************************************************************************
875 * FUNCTION: AcpiRemoveGpeBlock
877 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
879 * RETURN: Status
881 * DESCRIPTION: Remove a previously installed block of GPE registers
883 ******************************************************************************/
885 ACPI_STATUS
886 AcpiRemoveGpeBlock (
887 ACPI_HANDLE GpeDevice)
889 ACPI_OPERAND_OBJECT *ObjDesc;
890 ACPI_STATUS Status;
891 ACPI_NAMESPACE_NODE *Node;
894 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
897 if (!GpeDevice)
899 return_ACPI_STATUS (AE_BAD_PARAMETER);
902 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
903 if (ACPI_FAILURE (Status))
905 return (Status);
908 Node = AcpiNsMapHandleToNode (GpeDevice);
909 if (!Node)
911 Status = AE_BAD_PARAMETER;
912 goto UnlockAndExit;
915 /* Get the DeviceObject attached to the node */
917 ObjDesc = AcpiNsGetAttachedObject (Node);
918 if (!ObjDesc ||
919 !ObjDesc->Device.GpeBlock)
921 return_ACPI_STATUS (AE_NULL_OBJECT);
924 /* Delete the GPE block (but not the DeviceObject) */
926 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
927 if (ACPI_SUCCESS (Status))
929 ObjDesc->Device.GpeBlock = NULL;
932 UnlockAndExit:
933 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
934 return_ACPI_STATUS (Status);
937 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
940 /*******************************************************************************
942 * FUNCTION: AcpiGetGpeDevice
944 * PARAMETERS: Index - System GPE index (0-CurrentGpeCount)
945 * GpeDevice - Where the parent GPE Device is returned
947 * RETURN: Status
949 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
950 * gpe device indicates that the gpe number is contained in one of
951 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
953 ******************************************************************************/
955 ACPI_STATUS
956 AcpiGetGpeDevice (
957 UINT32 Index,
958 ACPI_HANDLE *GpeDevice)
960 ACPI_GPE_DEVICE_INFO Info;
961 ACPI_STATUS Status;
964 ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
967 if (!GpeDevice)
969 return_ACPI_STATUS (AE_BAD_PARAMETER);
972 if (Index >= AcpiCurrentGpeCount)
974 return_ACPI_STATUS (AE_NOT_EXIST);
977 /* Setup and walk the GPE list */
979 Info.Index = Index;
980 Info.Status = AE_NOT_EXIST;
981 Info.GpeDevice = NULL;
982 Info.NextBlockBaseIndex = 0;
984 Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
985 if (ACPI_FAILURE (Status))
987 return_ACPI_STATUS (Status);
990 *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
991 return_ACPI_STATUS (Info.Status);
994 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
997 /*******************************************************************************
999 * FUNCTION: AcpiEvGetGpeDevice
1001 * PARAMETERS: GPE_WALK_CALLBACK
1003 * RETURN: Status
1005 * DESCRIPTION: Matches the input GPE index (0-CurrentGpeCount) with a GPE
1006 * block device. NULL if the GPE is one of the FADT-defined GPEs.
1008 ******************************************************************************/
1010 static ACPI_STATUS
1011 AcpiEvGetGpeDevice (
1012 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
1013 ACPI_GPE_BLOCK_INFO *GpeBlock,
1014 void *Context)
1016 ACPI_GPE_DEVICE_INFO *Info = Context;
1019 /* Increment Index by the number of GPEs in this block */
1021 Info->NextBlockBaseIndex +=
1022 (GpeBlock->RegisterCount * ACPI_GPE_REGISTER_WIDTH);
1024 if (Info->Index < Info->NextBlockBaseIndex)
1027 * The GPE index is within this block, get the node. Leave the node
1028 * NULL for the FADT-defined GPEs
1030 if ((GpeBlock->Node)->Type == ACPI_TYPE_DEVICE)
1032 Info->GpeDevice = GpeBlock->Node;
1035 Info->Status = AE_OK;
1036 return (AE_CTRL_END);
1039 return (AE_OK);
1043 /******************************************************************************
1045 * FUNCTION: AcpiDisableAllGpes
1047 * PARAMETERS: None
1049 * RETURN: Status
1051 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
1053 ******************************************************************************/
1055 ACPI_STATUS
1056 AcpiDisableAllGpes (
1057 void)
1059 ACPI_STATUS Status;
1062 ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
1065 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
1066 if (ACPI_FAILURE (Status))
1068 return_ACPI_STATUS (Status);
1071 Status = AcpiHwDisableAllGpes ();
1072 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1074 return_ACPI_STATUS (Status);
1078 /******************************************************************************
1080 * FUNCTION: AcpiEnableAllRuntimeGpes
1082 * PARAMETERS: None
1084 * RETURN: Status
1086 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
1088 ******************************************************************************/
1090 ACPI_STATUS
1091 AcpiEnableAllRuntimeGpes (
1092 void)
1094 ACPI_STATUS Status;
1097 ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
1100 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
1101 if (ACPI_FAILURE (Status))
1103 return_ACPI_STATUS (Status);
1106 Status = AcpiHwEnableAllRuntimeGpes ();
1107 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1109 return_ACPI_STATUS (Status);