17c478bd9Sstevel@tonic-gate /******************************************************************************
27c478bd9Sstevel@tonic-gate  *
37c478bd9Sstevel@tonic-gate  * Module Name: evgpeblk - GPE block creation and initialization.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  *****************************************************************************/
67c478bd9Sstevel@tonic-gate 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
127c478bd9Sstevel@tonic-gate  * All rights reserved.
137c478bd9Sstevel@tonic-gate  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
11926f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross  * are met:
12226f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross  *    without modification.
12526f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross  *    binary redistribution.
13026f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross  *    from this software without specific prior written permission.
13326f3cdf0SGordon Ross  *
13426f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #include "acpi.h"
153aa2aa9a6SDana Myers #include "accommon.h"
1547c478bd9Sstevel@tonic-gate #include "acevents.h"
1557c478bd9Sstevel@tonic-gate #include "acnamesp.h"
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #define _COMPONENT          ACPI_EVENTS
1587c478bd9Sstevel@tonic-gate         ACPI_MODULE_NAME    ("evgpeblk")
1597c478bd9Sstevel@tonic-gate 
1607b1019a6SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
1617b1019a6SJerry Jelinek 
1627c478bd9Sstevel@tonic-gate /* Local prototypes */
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate static ACPI_STATUS
1657c478bd9Sstevel@tonic-gate AcpiEvInstallGpeBlock (
1667c478bd9Sstevel@tonic-gate     ACPI_GPE_BLOCK_INFO     *GpeBlock,
167450d6964Smyers     UINT32                  InterruptNumber);
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate static ACPI_STATUS
1707c478bd9Sstevel@tonic-gate AcpiEvCreateGpeInfoBlocks (
1717c478bd9Sstevel@tonic-gate     ACPI_GPE_BLOCK_INFO     *GpeBlock);
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*******************************************************************************
1757c478bd9Sstevel@tonic-gate  *
1767c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiEvInstallGpeBlock
1777c478bd9Sstevel@tonic-gate  *
178aa2aa9a6SDana Myers  * PARAMETERS:  GpeBlock                - New GPE block
179aa2aa9a6SDana Myers  *              InterruptNumber         - Xrupt to be associated with this
180aa2aa9a6SDana Myers  *                                        GPE block
1817c478bd9Sstevel@tonic-gate  *
1827c478bd9Sstevel@tonic-gate  * RETURN:      Status
1837c478bd9Sstevel@tonic-gate  *
1847c478bd9Sstevel@tonic-gate  * DESCRIPTION: Install new GPE block with mutex support
1857c478bd9Sstevel@tonic-gate  *
1867c478bd9Sstevel@tonic-gate  ******************************************************************************/
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate static ACPI_STATUS
AcpiEvInstallGpeBlock(ACPI_GPE_BLOCK_INFO * GpeBlock,UINT32 InterruptNumber)1897c478bd9Sstevel@tonic-gate AcpiEvInstallGpeBlock (
1907c478bd9Sstevel@tonic-gate     ACPI_GPE_BLOCK_INFO     *GpeBlock,
191450d6964Smyers     UINT32                  InterruptNumber)
1927c478bd9Sstevel@tonic-gate {
1937c478bd9Sstevel@tonic-gate     ACPI_GPE_BLOCK_INFO     *NextGpeBlock;
1947c478bd9Sstevel@tonic-gate     ACPI_GPE_XRUPT_INFO     *GpeXruptBlock;
1957c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
19630082d0cSmyers     ACPI_CPU_FLAGS          Flags;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 
19927f7c583Smyers     ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
2037c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
2047c478bd9Sstevel@tonic-gate     {
2057c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
2067c478bd9Sstevel@tonic-gate     }
2077c478bd9Sstevel@tonic-gate 
2087b1019a6SJerry Jelinek     Status = AcpiEvGetGpeXruptBlock (InterruptNumber, &GpeXruptBlock);
2097b1019a6SJerry Jelinek     if (ACPI_FAILURE (Status))
2107c478bd9Sstevel@tonic-gate     {
2117c478bd9Sstevel@tonic-gate         goto UnlockAndExit;
2127c478bd9Sstevel@tonic-gate     }
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate     /* Install the new block at the end of the list with lock */
2157c478bd9Sstevel@tonic-gate 
216450d6964Smyers     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
2177c478bd9Sstevel@tonic-gate     if (GpeXruptBlock->GpeBlockListHead)
2187c478bd9Sstevel@tonic-gate     {
2197c478bd9Sstevel@tonic-gate         NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
2207c478bd9Sstevel@tonic-gate         while (NextGpeBlock->Next)
2217c478bd9Sstevel@tonic-gate         {
2227c478bd9Sstevel@tonic-gate             NextGpeBlock = NextGpeBlock->Next;
2237c478bd9Sstevel@tonic-gate         }
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate         NextGpeBlock->Next = GpeBlock;
2267c478bd9Sstevel@tonic-gate         GpeBlock->Previous = NextGpeBlock;
2277c478bd9Sstevel@tonic-gate     }
2287c478bd9Sstevel@tonic-gate     else
2297c478bd9Sstevel@tonic-gate     {
2307c478bd9Sstevel@tonic-gate         GpeXruptBlock->GpeBlockListHead = GpeBlock;
2317c478bd9Sstevel@tonic-gate     }
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate     GpeBlock->XruptBlock = GpeXruptBlock;
234450d6964Smyers     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
2357c478bd9Sstevel@tonic-gate 
23630082d0cSmyers 
2377c478bd9Sstevel@tonic-gate UnlockAndExit:
2387b1019a6SJerry Jelinek     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
2397c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*******************************************************************************
2447c478bd9Sstevel@tonic-gate  *
2457c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiEvDeleteGpeBlock
2467c478bd9Sstevel@tonic-gate  *
247aa2aa9a6SDana Myers  * PARAMETERS:  GpeBlock            - Existing GPE block
2487c478bd9Sstevel@tonic-gate  *
2497c478bd9Sstevel@tonic-gate  * RETURN:      Status
2507c478bd9Sstevel@tonic-gate  *
2517c478bd9Sstevel@tonic-gate  * DESCRIPTION: Remove a GPE block
2527c478bd9Sstevel@tonic-gate  *
2537c478bd9Sstevel@tonic-gate  ******************************************************************************/
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiEvDeleteGpeBlock(ACPI_GPE_BLOCK_INFO * GpeBlock)2567c478bd9Sstevel@tonic-gate AcpiEvDeleteGpeBlock (
2577c478bd9Sstevel@tonic-gate     ACPI_GPE_BLOCK_INFO     *GpeBlock)
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
26030082d0cSmyers     ACPI_CPU_FLAGS          Flags;
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 
26327f7c583Smyers     ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
2677c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
2687c478bd9Sstevel@tonic-gate     {
2697c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
2707c478bd9Sstevel@tonic-gate     }
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate     /* Disable all GPEs in this block */
2737c478bd9Sstevel@tonic-gate 
274aa2aa9a6SDana Myers     Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock, NULL);
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate     if (!GpeBlock->Previous && !GpeBlock->Next)
2777c478bd9Sstevel@tonic-gate     {
2787c478bd9Sstevel@tonic-gate         /* This is the last GpeBlock on this interrupt */
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate         Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
2817c478bd9Sstevel@tonic-gate         if (ACPI_FAILURE (Status))
2827c478bd9Sstevel@tonic-gate         {
2837c478bd9Sstevel@tonic-gate             goto UnlockAndExit;
2847c478bd9Sstevel@tonic-gate         }
2857c478bd9Sstevel@tonic-gate     }
2867c478bd9Sstevel@tonic-gate     else
2877c478bd9Sstevel@tonic-gate     {
2887c478bd9Sstevel@tonic-gate         /* Remove the block on this interrupt with lock */
2897c478bd9Sstevel@tonic-gate 
290450d6964Smyers         Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
2917c478bd9Sstevel@tonic-gate         if (GpeBlock->Previous)
2927c478bd9Sstevel@tonic-gate         {
2937c478bd9Sstevel@tonic-gate             GpeBlock->Previous->Next = GpeBlock->Next;
2947c478bd9Sstevel@tonic-gate         }
2957c478bd9Sstevel@tonic-gate         else
2967c478bd9Sstevel@tonic-gate         {
2977c478bd9Sstevel@tonic-gate             GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
2987c478bd9Sstevel@tonic-gate         }
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate         if (GpeBlock->Next)
3017c478bd9Sstevel@tonic-gate         {
3027c478bd9Sstevel@tonic-gate             GpeBlock->Next->Previous = GpeBlock->Previous;
3037c478bd9Sstevel@tonic-gate         }
3047b1019a6SJerry Jelinek 
305450d6964Smyers         AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
3067c478bd9Sstevel@tonic-gate     }
3077c478bd9Sstevel@tonic-gate 
30826f3cdf0SGordon Ross     AcpiCurrentGpeCount -= GpeBlock->GpeCount;
309aa2aa9a6SDana Myers 
3107c478bd9Sstevel@tonic-gate     /* Free the GpeBlock */
3117c478bd9Sstevel@tonic-gate 
31227f7c583Smyers     ACPI_FREE (GpeBlock->RegisterInfo);
31327f7c583Smyers     ACPI_FREE (GpeBlock->EventInfo);
31427f7c583Smyers     ACPI_FREE (GpeBlock);
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate UnlockAndExit:
3177c478bd9Sstevel@tonic-gate     Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
3187c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*******************************************************************************
3237c478bd9Sstevel@tonic-gate  *
3247c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiEvCreateGpeInfoBlocks
3257c478bd9Sstevel@tonic-gate  *
3267c478bd9Sstevel@tonic-gate  * PARAMETERS:  GpeBlock    - New GPE block
3277c478bd9Sstevel@tonic-gate  *
3287c478bd9Sstevel@tonic-gate  * RETURN:      Status
3297c478bd9Sstevel@tonic-gate  *
3307c478bd9Sstevel@tonic-gate  * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
3317c478bd9Sstevel@tonic-gate  *
3327c478bd9Sstevel@tonic-gate  ******************************************************************************/
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate static ACPI_STATUS
AcpiEvCreateGpeInfoBlocks(ACPI_GPE_BLOCK_INFO * GpeBlock)3357c478bd9Sstevel@tonic-gate AcpiEvCreateGpeInfoBlocks (
3367c478bd9Sstevel@tonic-gate     ACPI_GPE_BLOCK_INFO     *GpeBlock)
3377c478bd9Sstevel@tonic-gate {
3387c478bd9Sstevel@tonic-gate     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo = NULL;
3397c478bd9Sstevel@tonic-gate     ACPI_GPE_EVENT_INFO     *GpeEventInfo = NULL;
3407c478bd9Sstevel@tonic-gate     ACPI_GPE_EVENT_INFO     *ThisEvent;
3417c478bd9Sstevel@tonic-gate     ACPI_GPE_REGISTER_INFO  *ThisRegister;
342db2bae30SDana Myers     UINT32                  i;
343db2bae30SDana Myers     UINT32                  j;
3447c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 
34727f7c583Smyers     ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks);
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate     /* Allocate the GPE register information block */
3517c478bd9Sstevel@tonic-gate 
35227f7c583Smyers     GpeRegisterInfo = ACPI_ALLOCATE_ZEROED (
3537b1019a6SJerry Jelinek         (ACPI_SIZE) GpeBlock->RegisterCount *
3547b1019a6SJerry Jelinek         sizeof (ACPI_GPE_REGISTER_INFO));
3557c478bd9Sstevel@tonic-gate     if (!GpeRegisterInfo)
3567c478bd9Sstevel@tonic-gate     {
35730082d0cSmyers         ACPI_ERROR ((AE_INFO,
35830082d0cSmyers             "Could not allocate the GpeRegisterInfo table"));
3597c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_NO_MEMORY);
3607c478bd9Sstevel@tonic-gate     }
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate     /*
36330082d0cSmyers      * Allocate the GPE EventInfo block. There are eight distinct GPEs
36430082d0cSmyers      * per register. Initialization to zeros is sufficient.
3657c478bd9Sstevel@tonic-gate      */
36626f3cdf0SGordon Ross     GpeEventInfo = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) GpeBlock->GpeCount *
3677b1019a6SJerry Jelinek         sizeof (ACPI_GPE_EVENT_INFO));
3687c478bd9Sstevel@tonic-gate     if (!GpeEventInfo)
3697c478bd9Sstevel@tonic-gate     {
37030082d0cSmyers         ACPI_ERROR ((AE_INFO,
37130082d0cSmyers             "Could not allocate the GpeEventInfo table"));
3727c478bd9Sstevel@tonic-gate         Status = AE_NO_MEMORY;
3737c478bd9Sstevel@tonic-gate         goto ErrorExit;
3747c478bd9Sstevel@tonic-gate     }
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate     /* Save the new Info arrays in the GPE block */
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate     GpeBlock->RegisterInfo = GpeRegisterInfo;
3797b1019a6SJerry Jelinek     GpeBlock->EventInfo = GpeEventInfo;
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate     /*
38230082d0cSmyers      * Initialize the GPE Register and Event structures. A goal of these
383aa2aa9a6SDana Myers      * tables is to hide the fact that there are two separate GPE register
384aa2aa9a6SDana Myers      * sets in a given GPE hardware block, the status registers occupy the
385aa2aa9a6SDana Myers      * first half, and the enable registers occupy the second half.
3867c478bd9Sstevel@tonic-gate      */
3877c478bd9Sstevel@tonic-gate     ThisRegister = GpeRegisterInfo;
3887b1019a6SJerry Jelinek     ThisEvent = GpeEventInfo;
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate     for (i = 0; i < GpeBlock->RegisterCount; i++)
3917c478bd9Sstevel@tonic-gate     {
3927c478bd9Sstevel@tonic-gate         /* Init the RegisterInfo for this GPE register (8 GPEs) */
3937c478bd9Sstevel@tonic-gate 
3947b1019a6SJerry Jelinek         ThisRegister->BaseGpeNumber = (UINT16)
3957b1019a6SJerry Jelinek             (GpeBlock->BlockBaseNumber + (i * ACPI_GPE_REGISTER_WIDTH));
3967c478bd9Sstevel@tonic-gate 
397db2bae30SDana Myers         ThisRegister->StatusAddress.Address =
3987b1019a6SJerry Jelinek             GpeBlock->Address + i;
3997c478bd9Sstevel@tonic-gate 
400db2bae30SDana Myers         ThisRegister->EnableAddress.Address =
4017b1019a6SJerry Jelinek             GpeBlock->Address + i + GpeBlock->RegisterCount;
4027c478bd9Sstevel@tonic-gate 
4037b1019a6SJerry Jelinek         ThisRegister->StatusAddress.SpaceId   = GpeBlock->SpaceId;
4047b1019a6SJerry Jelinek         ThisRegister->EnableAddress.SpaceId   = GpeBlock->SpaceId;
405db2bae30SDana Myers         ThisRegister->StatusAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
406db2bae30SDana Myers         ThisRegister->EnableAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
407aa2aa9a6SDana Myers         ThisRegister->StatusAddress.BitOffset = 0;
408aa2aa9a6SDana Myers         ThisRegister->EnableAddress.BitOffset = 0;
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate         /* Init the EventInfo for each GPE within this register */
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate         for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
4137c478bd9Sstevel@tonic-gate         {
414db2bae30SDana Myers             ThisEvent->GpeNumber = (UINT8) (ThisRegister->BaseGpeNumber + j);
4157c478bd9Sstevel@tonic-gate             ThisEvent->RegisterInfo = ThisRegister;
4167c478bd9Sstevel@tonic-gate             ThisEvent++;
4177c478bd9Sstevel@tonic-gate         }
4187c478bd9Sstevel@tonic-gate 
41930082d0cSmyers         /* Disable all GPEs within this register */
42030082d0cSmyers 
42157190917SDana Myers         Status = AcpiHwWrite (0x00, &ThisRegister->EnableAddress);
4227c478bd9Sstevel@tonic-gate         if (ACPI_FAILURE (Status))
4237c478bd9Sstevel@tonic-gate         {
4247c478bd9Sstevel@tonic-gate             goto ErrorExit;
4257c478bd9Sstevel@tonic-gate         }
4267c478bd9Sstevel@tonic-gate 
42730082d0cSmyers         /* Clear any pending GPE events within this register */
42830082d0cSmyers 
42957190917SDana Myers         Status = AcpiHwWrite (0xFF, &ThisRegister->StatusAddress);
4307c478bd9Sstevel@tonic-gate         if (ACPI_FAILURE (Status))
4317c478bd9Sstevel@tonic-gate         {
4327c478bd9Sstevel@tonic-gate             goto ErrorExit;
4337c478bd9Sstevel@tonic-gate         }
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate         ThisRegister++;
4367c478bd9Sstevel@tonic-gate     }
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (AE_OK);
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate ErrorExit:
4427c478bd9Sstevel@tonic-gate     if (GpeRegisterInfo)
4437c478bd9Sstevel@tonic-gate     {
44427f7c583Smyers         ACPI_FREE (GpeRegisterInfo);
4457c478bd9Sstevel@tonic-gate     }
4467c478bd9Sstevel@tonic-gate     if (GpeEventInfo)
4477c478bd9Sstevel@tonic-gate     {
44827f7c583Smyers         ACPI_FREE (GpeEventInfo);
4497c478bd9Sstevel@tonic-gate     }
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate /*******************************************************************************
4567c478bd9Sstevel@tonic-gate  *
4577c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiEvCreateGpeBlock
4587c478bd9Sstevel@tonic-gate  *
4597c478bd9Sstevel@tonic-gate  * PARAMETERS:  GpeDevice           - Handle to the parent GPE block
4607c478bd9Sstevel@tonic-gate  *              GpeBlockAddress     - Address and SpaceID
4617c478bd9Sstevel@tonic-gate  *              RegisterCount       - Number of GPE register pairs in the block
4627c478bd9Sstevel@tonic-gate  *              GpeBlockBaseNumber  - Starting GPE number for the block
463450d6964Smyers  *              InterruptNumber     - H/W interrupt for the block
4647c478bd9Sstevel@tonic-gate  *              ReturnGpeBlock      - Where the new block descriptor is returned
4657c478bd9Sstevel@tonic-gate  *
4667c478bd9Sstevel@tonic-gate  * RETURN:      Status
4677c478bd9Sstevel@tonic-gate  *
46830082d0cSmyers  * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
46930082d0cSmyers  *              the block are disabled at exit.
47030082d0cSmyers  *              Note: Assumes namespace is locked.
4717c478bd9Sstevel@tonic-gate  *
4727c478bd9Sstevel@tonic-gate  ******************************************************************************/
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiEvCreateGpeBlock(ACPI_NAMESPACE_NODE * GpeDevice,UINT64 Address,UINT8 SpaceId,UINT32 RegisterCount,UINT16 GpeBlockBaseNumber,UINT32 InterruptNumber,ACPI_GPE_BLOCK_INFO ** ReturnGpeBlock)4757c478bd9Sstevel@tonic-gate AcpiEvCreateGpeBlock (
4767c478bd9Sstevel@tonic-gate     ACPI_NAMESPACE_NODE     *GpeDevice,
4777b1019a6SJerry Jelinek     UINT64                  Address,
4787b1019a6SJerry Jelinek     UINT8                   SpaceId,
4797c478bd9Sstevel@tonic-gate     UINT32                  RegisterCount,
4807b1019a6SJerry Jelinek     UINT16                  GpeBlockBaseNumber,
481450d6964Smyers     UINT32                  InterruptNumber,
4827c478bd9Sstevel@tonic-gate     ACPI_GPE_BLOCK_INFO     **ReturnGpeBlock)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
48530082d0cSmyers     ACPI_GPE_BLOCK_INFO     *GpeBlock;
48626f3cdf0SGordon Ross     ACPI_GPE_WALK_INFO      WalkInfo;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 
48927f7c583Smyers     ACPI_FUNCTION_TRACE (EvCreateGpeBlock);
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate     if (!RegisterCount)
4937c478bd9Sstevel@tonic-gate     {
4947c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_OK);
4957c478bd9Sstevel@tonic-gate     }
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate     /* Allocate a new GPE block */
4987c478bd9Sstevel@tonic-gate 
49927f7c583Smyers     GpeBlock = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO));
5007c478bd9Sstevel@tonic-gate     if (!GpeBlock)
5017c478bd9Sstevel@tonic-gate     {
5027c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_NO_MEMORY);
5037c478bd9Sstevel@tonic-gate     }
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate     /* Initialize the new GPE block */
5067c478bd9Sstevel@tonic-gate 
5077b1019a6SJerry Jelinek     GpeBlock->Address = Address;
5087b1019a6SJerry Jelinek     GpeBlock->SpaceId = SpaceId;
50930082d0cSmyers     GpeBlock->Node = GpeDevice;
51026f3cdf0SGordon Ross     GpeBlock->GpeCount = (UINT16) (RegisterCount * ACPI_GPE_REGISTER_WIDTH);
51126f3cdf0SGordon Ross     GpeBlock->Initialized = FALSE;
51230082d0cSmyers     GpeBlock->RegisterCount = RegisterCount;
5137c478bd9Sstevel@tonic-gate     GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
5147c478bd9Sstevel@tonic-gate 
51530082d0cSmyers     /*
51630082d0cSmyers      * Create the RegisterInfo and EventInfo sub-structures
51730082d0cSmyers      * Note: disables and clears all GPEs in the block
51830082d0cSmyers      */
5197c478bd9Sstevel@tonic-gate     Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
5207c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
5217c478bd9Sstevel@tonic-gate     {
52227f7c583Smyers         ACPI_FREE (GpeBlock);
5237c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
5247c478bd9Sstevel@tonic-gate     }
5257c478bd9Sstevel@tonic-gate 
52630082d0cSmyers     /* Install the new block in the global lists */
5277c478bd9Sstevel@tonic-gate 
528450d6964Smyers     Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
5297c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
5307c478bd9Sstevel@tonic-gate     {
5317b1019a6SJerry Jelinek         ACPI_FREE (GpeBlock->RegisterInfo);
5327b1019a6SJerry Jelinek         ACPI_FREE (GpeBlock->EventInfo);
53327f7c583Smyers         ACPI_FREE (GpeBlock);
5347c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
5357c478bd9Sstevel@tonic-gate     }
5367c478bd9Sstevel@tonic-gate 
53726f3cdf0SGordon Ross     AcpiGbl_AllGpesInitialized = FALSE;
53826f3cdf0SGordon Ross 
53926f3cdf0SGordon Ross     /* Find all GPE methods (_Lxx or_Exx) for this block */
54026f3cdf0SGordon Ross 
54126f3cdf0SGordon Ross     WalkInfo.GpeBlock = GpeBlock;
54226f3cdf0SGordon Ross     WalkInfo.GpeDevice = GpeDevice;
54326f3cdf0SGordon Ross     WalkInfo.ExecuteByOwnerId = FALSE;
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate     Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
5467b1019a6SJerry Jelinek         ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
5477b1019a6SJerry Jelinek         AcpiEvMatchGpeMethod, NULL, &WalkInfo, NULL);
54830082d0cSmyers 
54930082d0cSmyers     /* Return the new block */
55030082d0cSmyers 
55130082d0cSmyers     if (ReturnGpeBlock)
55230082d0cSmyers     {
55330082d0cSmyers         (*ReturnGpeBlock) = GpeBlock;
55430082d0cSmyers     }
55530082d0cSmyers 
5567b1019a6SJerry Jelinek     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
5577b1019a6SJerry Jelinek         "    Initialized GPE %02X to %02X [%4.4s] %u regs on interrupt 0x%X%s\n",
55830082d0cSmyers         (UINT32) GpeBlock->BlockBaseNumber,
55926f3cdf0SGordon Ross         (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1)),
5607b1019a6SJerry Jelinek         GpeDevice->Name.Ascii, GpeBlock->RegisterCount, InterruptNumber,
5617b1019a6SJerry Jelinek         InterruptNumber == AcpiGbl_FADT.SciInterrupt ? " (SCI)" : ""));
56230082d0cSmyers 
563aa2aa9a6SDana Myers     /* Update global count of currently available GPEs */
564aa2aa9a6SDana Myers 
56526f3cdf0SGordon Ross     AcpiCurrentGpeCount += GpeBlock->GpeCount;
56630082d0cSmyers     return_ACPI_STATUS (AE_OK);
56730082d0cSmyers }
56830082d0cSmyers 
56930082d0cSmyers 
57030082d0cSmyers /*******************************************************************************
57130082d0cSmyers  *
57230082d0cSmyers  * FUNCTION:    AcpiEvInitializeGpeBlock
57330082d0cSmyers  *
57426f3cdf0SGordon Ross  * PARAMETERS:  ACPI_GPE_CALLBACK
57530082d0cSmyers  *
57630082d0cSmyers  * RETURN:      Status
57730082d0cSmyers  *
57826f3cdf0SGordon Ross  * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
57926f3cdf0SGordon Ross  *              associated methods.
58030082d0cSmyers  *              Note: Assumes namespace is locked.
58130082d0cSmyers  *
58230082d0cSmyers  ******************************************************************************/
58330082d0cSmyers 
58430082d0cSmyers ACPI_STATUS
AcpiEvInitializeGpeBlock(ACPI_GPE_XRUPT_INFO * GpeXruptInfo,ACPI_GPE_BLOCK_INFO * GpeBlock,void * Context)58530082d0cSmyers AcpiEvInitializeGpeBlock (
58626f3cdf0SGordon Ross     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
58726f3cdf0SGordon Ross     ACPI_GPE_BLOCK_INFO     *GpeBlock,
588*35786f68SRobert Mustacchi     void                    *Context)
58930082d0cSmyers {
59030082d0cSmyers     ACPI_STATUS             Status;
59130082d0cSmyers     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
59230082d0cSmyers     UINT32                  GpeEnabledCount;
59326f3cdf0SGordon Ross     UINT32                  GpeIndex;
594db2bae30SDana Myers     UINT32                  i;
595db2bae30SDana Myers     UINT32                  j;
596*35786f68SRobert Mustacchi     BOOLEAN                 *IsPollingNeeded = Context;
597*35786f68SRobert Mustacchi     ACPI_ERROR_ONLY (UINT32 GpeNumber);
59830082d0cSmyers 
59930082d0cSmyers 
60027f7c583Smyers     ACPI_FUNCTION_TRACE (EvInitializeGpeBlock);
60130082d0cSmyers 
60230082d0cSmyers 
6037c478bd9Sstevel@tonic-gate     /*
60426f3cdf0SGordon Ross      * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
60526f3cdf0SGordon Ross      * any GPE blocks that have been initialized already.
6067c478bd9Sstevel@tonic-gate      */
60726f3cdf0SGordon Ross     if (!GpeBlock || GpeBlock->Initialized)
6087c478bd9Sstevel@tonic-gate     {
60926f3cdf0SGordon Ross         return_ACPI_STATUS (AE_OK);
6107c478bd9Sstevel@tonic-gate     }
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate     /*
61326f3cdf0SGordon Ross      * Enable all GPEs that have a corresponding method and have the
61426f3cdf0SGordon Ross      * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
61526f3cdf0SGordon Ross      * must be enabled via the acpi_enable_gpe() interface.
6167c478bd9Sstevel@tonic-gate      */
6177c478bd9Sstevel@tonic-gate     GpeEnabledCount = 0;
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate     for (i = 0; i < GpeBlock->RegisterCount; i++)
6207c478bd9Sstevel@tonic-gate     {
62126f3cdf0SGordon Ross         for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
6227c478bd9Sstevel@tonic-gate         {
6237c478bd9Sstevel@tonic-gate             /* Get the info block for this particular GPE */
6247c478bd9Sstevel@tonic-gate 
62526f3cdf0SGordon Ross             GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
62626f3cdf0SGordon Ross             GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
627*35786f68SRobert Mustacchi             ACPI_ERROR_ONLY(GpeNumber = GpeBlock->BlockBaseNumber + GpeIndex);
628*35786f68SRobert Mustacchi             GpeEventInfo->Flags |= ACPI_GPE_INITIALIZED;
6297c478bd9Sstevel@tonic-gate 
63026f3cdf0SGordon Ross             /*
63126f3cdf0SGordon Ross              * Ignore GPEs that have no corresponding _Lxx/_Exx method
63226f3cdf0SGordon Ross              * and GPEs that are used to wake the system
63326f3cdf0SGordon Ross              */
634*35786f68SRobert Mustacchi             if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) != ACPI_GPE_DISPATCH_METHOD) ||
63526f3cdf0SGordon Ross                 (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
6367c478bd9Sstevel@tonic-gate             {
63726f3cdf0SGordon Ross                 continue;
6387c478bd9Sstevel@tonic-gate             }
6397c478bd9Sstevel@tonic-gate 
64026f3cdf0SGordon Ross             Status = AcpiEvAddGpeReference (GpeEventInfo);
6417c478bd9Sstevel@tonic-gate             if (ACPI_FAILURE (Status))
6427c478bd9Sstevel@tonic-gate             {
64330082d0cSmyers                 ACPI_EXCEPTION ((AE_INFO, Status,
64426f3cdf0SGordon Ross                     "Could not enable GPE 0x%02X",
645*35786f68SRobert Mustacchi                     GpeNumber));
64626f3cdf0SGordon Ross                 continue;
6477c478bd9Sstevel@tonic-gate             }
6487c478bd9Sstevel@tonic-gate 
649*35786f68SRobert Mustacchi             GpeEventInfo->Flags |= ACPI_GPE_AUTO_ENABLED;
650*35786f68SRobert Mustacchi 
651*35786f68SRobert Mustacchi             if (IsPollingNeeded &&
652*35786f68SRobert Mustacchi                 ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
653*35786f68SRobert Mustacchi             {
654*35786f68SRobert Mustacchi                 *IsPollingNeeded = TRUE;
655*35786f68SRobert Mustacchi             }
656*35786f68SRobert Mustacchi 
65726f3cdf0SGordon Ross             GpeEnabledCount++;
6587c478bd9Sstevel@tonic-gate         }
6597c478bd9Sstevel@tonic-gate     }
6607c478bd9Sstevel@tonic-gate 
66126f3cdf0SGordon Ross     if (GpeEnabledCount)
6627c478bd9Sstevel@tonic-gate     {
6637b1019a6SJerry Jelinek         ACPI_INFO ((
6647b1019a6SJerry Jelinek             "Enabled %u GPEs in block %02X to %02X", GpeEnabledCount,
6657b1019a6SJerry Jelinek             (UINT32) GpeBlock->BlockBaseNumber,
6667b1019a6SJerry Jelinek             (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1))));
6677c478bd9Sstevel@tonic-gate     }
6687c478bd9Sstevel@tonic-gate 
66926f3cdf0SGordon Ross     GpeBlock->Initialized = TRUE;
6707c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (AE_OK);
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate 
6737b1019a6SJerry Jelinek #endif /* !ACPI_REDUCED_HARDWARE */
674