xref: /minix3/minix/drivers/power/acpi/events/evgpeutil.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: evgpeutil - GPE utilities
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  *****************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acevents.h"
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc #define _COMPONENT          ACPI_EVENTS
49433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("evgpeutil")
50433d6423SLionel Sambuc 
51433d6423SLionel Sambuc 
52*29492bb7SDavid van Moolenbroek #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53433d6423SLionel Sambuc /*******************************************************************************
54433d6423SLionel Sambuc  *
55433d6423SLionel Sambuc  * FUNCTION:    AcpiEvWalkGpeList
56433d6423SLionel Sambuc  *
57433d6423SLionel Sambuc  * PARAMETERS:  GpeWalkCallback     - Routine called for each GPE block
58433d6423SLionel Sambuc  *              Context             - Value passed to callback
59433d6423SLionel Sambuc  *
60433d6423SLionel Sambuc  * RETURN:      Status
61433d6423SLionel Sambuc  *
62433d6423SLionel Sambuc  * DESCRIPTION: Walk the GPE lists.
63433d6423SLionel Sambuc  *
64433d6423SLionel Sambuc  ******************************************************************************/
65433d6423SLionel Sambuc 
66433d6423SLionel Sambuc ACPI_STATUS
AcpiEvWalkGpeList(ACPI_GPE_CALLBACK GpeWalkCallback,void * Context)67433d6423SLionel Sambuc AcpiEvWalkGpeList (
68433d6423SLionel Sambuc     ACPI_GPE_CALLBACK       GpeWalkCallback,
69433d6423SLionel Sambuc     void                    *Context)
70433d6423SLionel Sambuc {
71433d6423SLionel Sambuc     ACPI_GPE_BLOCK_INFO     *GpeBlock;
72433d6423SLionel Sambuc     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
73433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
74433d6423SLionel Sambuc     ACPI_CPU_FLAGS          Flags;
75433d6423SLionel Sambuc 
76433d6423SLionel Sambuc 
77433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (EvWalkGpeList);
78433d6423SLionel Sambuc 
79433d6423SLionel Sambuc 
80433d6423SLionel Sambuc     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
81433d6423SLionel Sambuc 
82433d6423SLionel Sambuc     /* Walk the interrupt level descriptor list */
83433d6423SLionel Sambuc 
84433d6423SLionel Sambuc     GpeXruptInfo = AcpiGbl_GpeXruptListHead;
85433d6423SLionel Sambuc     while (GpeXruptInfo)
86433d6423SLionel Sambuc     {
87433d6423SLionel Sambuc         /* Walk all Gpe Blocks attached to this interrupt level */
88433d6423SLionel Sambuc 
89433d6423SLionel Sambuc         GpeBlock = GpeXruptInfo->GpeBlockListHead;
90433d6423SLionel Sambuc         while (GpeBlock)
91433d6423SLionel Sambuc         {
92433d6423SLionel Sambuc             /* One callback per GPE block */
93433d6423SLionel Sambuc 
94433d6423SLionel Sambuc             Status = GpeWalkCallback (GpeXruptInfo, GpeBlock, Context);
95433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
96433d6423SLionel Sambuc             {
97433d6423SLionel Sambuc                 if (Status == AE_CTRL_END) /* Callback abort */
98433d6423SLionel Sambuc                 {
99433d6423SLionel Sambuc                     Status = AE_OK;
100433d6423SLionel Sambuc                 }
101433d6423SLionel Sambuc                 goto UnlockAndExit;
102433d6423SLionel Sambuc             }
103433d6423SLionel Sambuc 
104433d6423SLionel Sambuc             GpeBlock = GpeBlock->Next;
105433d6423SLionel Sambuc         }
106433d6423SLionel Sambuc 
107433d6423SLionel Sambuc         GpeXruptInfo = GpeXruptInfo->Next;
108433d6423SLionel Sambuc     }
109433d6423SLionel Sambuc 
110433d6423SLionel Sambuc UnlockAndExit:
111433d6423SLionel Sambuc     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
112433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
113433d6423SLionel Sambuc }
114433d6423SLionel Sambuc 
115433d6423SLionel Sambuc 
116433d6423SLionel Sambuc /*******************************************************************************
117433d6423SLionel Sambuc  *
118433d6423SLionel Sambuc  * FUNCTION:    AcpiEvValidGpeEvent
119433d6423SLionel Sambuc  *
120433d6423SLionel Sambuc  * PARAMETERS:  GpeEventInfo                - Info for this GPE
121433d6423SLionel Sambuc  *
122433d6423SLionel Sambuc  * RETURN:      TRUE if the GpeEvent is valid
123433d6423SLionel Sambuc  *
124433d6423SLionel Sambuc  * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
125433d6423SLionel Sambuc  *              Should be called only when the GPE lists are semaphore locked
126433d6423SLionel Sambuc  *              and not subject to change.
127433d6423SLionel Sambuc  *
128433d6423SLionel Sambuc  ******************************************************************************/
129433d6423SLionel Sambuc 
130433d6423SLionel Sambuc BOOLEAN
AcpiEvValidGpeEvent(ACPI_GPE_EVENT_INFO * GpeEventInfo)131433d6423SLionel Sambuc AcpiEvValidGpeEvent (
132433d6423SLionel Sambuc     ACPI_GPE_EVENT_INFO     *GpeEventInfo)
133433d6423SLionel Sambuc {
134433d6423SLionel Sambuc     ACPI_GPE_XRUPT_INFO     *GpeXruptBlock;
135433d6423SLionel Sambuc     ACPI_GPE_BLOCK_INFO     *GpeBlock;
136433d6423SLionel Sambuc 
137433d6423SLionel Sambuc 
138433d6423SLionel Sambuc     ACPI_FUNCTION_ENTRY ();
139433d6423SLionel Sambuc 
140433d6423SLionel Sambuc 
141433d6423SLionel Sambuc     /* No need for spin lock since we are not changing any list elements */
142433d6423SLionel Sambuc 
143433d6423SLionel Sambuc     /* Walk the GPE interrupt levels */
144433d6423SLionel Sambuc 
145433d6423SLionel Sambuc     GpeXruptBlock = AcpiGbl_GpeXruptListHead;
146433d6423SLionel Sambuc     while (GpeXruptBlock)
147433d6423SLionel Sambuc     {
148433d6423SLionel Sambuc         GpeBlock = GpeXruptBlock->GpeBlockListHead;
149433d6423SLionel Sambuc 
150433d6423SLionel Sambuc         /* Walk the GPE blocks on this interrupt level */
151433d6423SLionel Sambuc 
152433d6423SLionel Sambuc         while (GpeBlock)
153433d6423SLionel Sambuc         {
154433d6423SLionel Sambuc             if ((&GpeBlock->EventInfo[0] <= GpeEventInfo) &&
155433d6423SLionel Sambuc                 (&GpeBlock->EventInfo[GpeBlock->GpeCount] > GpeEventInfo))
156433d6423SLionel Sambuc             {
157433d6423SLionel Sambuc                 return (TRUE);
158433d6423SLionel Sambuc             }
159433d6423SLionel Sambuc 
160433d6423SLionel Sambuc             GpeBlock = GpeBlock->Next;
161433d6423SLionel Sambuc         }
162433d6423SLionel Sambuc 
163433d6423SLionel Sambuc         GpeXruptBlock = GpeXruptBlock->Next;
164433d6423SLionel Sambuc     }
165433d6423SLionel Sambuc 
166433d6423SLionel Sambuc     return (FALSE);
167433d6423SLionel Sambuc }
168433d6423SLionel Sambuc 
169433d6423SLionel Sambuc 
170433d6423SLionel Sambuc /*******************************************************************************
171433d6423SLionel Sambuc  *
172*29492bb7SDavid van Moolenbroek  * FUNCTION:    AcpiEvGetGpeDevice
173*29492bb7SDavid van Moolenbroek  *
174*29492bb7SDavid van Moolenbroek  * PARAMETERS:  GPE_WALK_CALLBACK
175*29492bb7SDavid van Moolenbroek  *
176*29492bb7SDavid van Moolenbroek  * RETURN:      Status
177*29492bb7SDavid van Moolenbroek  *
178*29492bb7SDavid van Moolenbroek  * DESCRIPTION: Matches the input GPE index (0-CurrentGpeCount) with a GPE
179*29492bb7SDavid van Moolenbroek  *              block device. NULL if the GPE is one of the FADT-defined GPEs.
180*29492bb7SDavid van Moolenbroek  *
181*29492bb7SDavid van Moolenbroek  ******************************************************************************/
182*29492bb7SDavid van Moolenbroek 
183*29492bb7SDavid van Moolenbroek ACPI_STATUS
AcpiEvGetGpeDevice(ACPI_GPE_XRUPT_INFO * GpeXruptInfo,ACPI_GPE_BLOCK_INFO * GpeBlock,void * Context)184*29492bb7SDavid van Moolenbroek AcpiEvGetGpeDevice (
185*29492bb7SDavid van Moolenbroek     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
186*29492bb7SDavid van Moolenbroek     ACPI_GPE_BLOCK_INFO     *GpeBlock,
187*29492bb7SDavid van Moolenbroek     void                    *Context)
188*29492bb7SDavid van Moolenbroek {
189*29492bb7SDavid van Moolenbroek     ACPI_GPE_DEVICE_INFO    *Info = Context;
190*29492bb7SDavid van Moolenbroek 
191*29492bb7SDavid van Moolenbroek 
192*29492bb7SDavid van Moolenbroek     /* Increment Index by the number of GPEs in this block */
193*29492bb7SDavid van Moolenbroek 
194*29492bb7SDavid van Moolenbroek     Info->NextBlockBaseIndex += GpeBlock->GpeCount;
195*29492bb7SDavid van Moolenbroek 
196*29492bb7SDavid van Moolenbroek     if (Info->Index < Info->NextBlockBaseIndex)
197*29492bb7SDavid van Moolenbroek     {
198*29492bb7SDavid van Moolenbroek         /*
199*29492bb7SDavid van Moolenbroek          * The GPE index is within this block, get the node. Leave the node
200*29492bb7SDavid van Moolenbroek          * NULL for the FADT-defined GPEs
201*29492bb7SDavid van Moolenbroek          */
202*29492bb7SDavid van Moolenbroek         if ((GpeBlock->Node)->Type == ACPI_TYPE_DEVICE)
203*29492bb7SDavid van Moolenbroek         {
204*29492bb7SDavid van Moolenbroek             Info->GpeDevice = GpeBlock->Node;
205*29492bb7SDavid van Moolenbroek         }
206*29492bb7SDavid van Moolenbroek 
207*29492bb7SDavid van Moolenbroek         Info->Status = AE_OK;
208*29492bb7SDavid van Moolenbroek         return (AE_CTRL_END);
209*29492bb7SDavid van Moolenbroek     }
210*29492bb7SDavid van Moolenbroek 
211*29492bb7SDavid van Moolenbroek     return (AE_OK);
212*29492bb7SDavid van Moolenbroek }
213*29492bb7SDavid van Moolenbroek 
214*29492bb7SDavid van Moolenbroek 
215*29492bb7SDavid van Moolenbroek /*******************************************************************************
216*29492bb7SDavid van Moolenbroek  *
217433d6423SLionel Sambuc  * FUNCTION:    AcpiEvGetGpeXruptBlock
218433d6423SLionel Sambuc  *
219433d6423SLionel Sambuc  * PARAMETERS:  InterruptNumber             - Interrupt for a GPE block
220*29492bb7SDavid van Moolenbroek  *              GpeXruptBlock               - Where the block is returned
221433d6423SLionel Sambuc  *
222*29492bb7SDavid van Moolenbroek  * RETURN:      Status
223433d6423SLionel Sambuc  *
224433d6423SLionel Sambuc  * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
225433d6423SLionel Sambuc  *              block per unique interrupt level used for GPEs. Should be
226433d6423SLionel Sambuc  *              called only when the GPE lists are semaphore locked and not
227433d6423SLionel Sambuc  *              subject to change.
228433d6423SLionel Sambuc  *
229433d6423SLionel Sambuc  ******************************************************************************/
230433d6423SLionel Sambuc 
231*29492bb7SDavid van Moolenbroek ACPI_STATUS
AcpiEvGetGpeXruptBlock(UINT32 InterruptNumber,ACPI_GPE_XRUPT_INFO ** GpeXruptBlock)232433d6423SLionel Sambuc AcpiEvGetGpeXruptBlock (
233*29492bb7SDavid van Moolenbroek     UINT32                  InterruptNumber,
234*29492bb7SDavid van Moolenbroek     ACPI_GPE_XRUPT_INFO     **GpeXruptBlock)
235433d6423SLionel Sambuc {
236433d6423SLionel Sambuc     ACPI_GPE_XRUPT_INFO     *NextGpeXrupt;
237433d6423SLionel Sambuc     ACPI_GPE_XRUPT_INFO     *GpeXrupt;
238433d6423SLionel Sambuc     ACPI_STATUS             Status;
239433d6423SLionel Sambuc     ACPI_CPU_FLAGS          Flags;
240433d6423SLionel Sambuc 
241433d6423SLionel Sambuc 
242433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (EvGetGpeXruptBlock);
243433d6423SLionel Sambuc 
244433d6423SLionel Sambuc 
245433d6423SLionel Sambuc     /* No need for lock since we are not changing any list elements here */
246433d6423SLionel Sambuc 
247433d6423SLionel Sambuc     NextGpeXrupt = AcpiGbl_GpeXruptListHead;
248433d6423SLionel Sambuc     while (NextGpeXrupt)
249433d6423SLionel Sambuc     {
250433d6423SLionel Sambuc         if (NextGpeXrupt->InterruptNumber == InterruptNumber)
251433d6423SLionel Sambuc         {
252*29492bb7SDavid van Moolenbroek             *GpeXruptBlock = NextGpeXrupt;
253*29492bb7SDavid van Moolenbroek             return_ACPI_STATUS (AE_OK);
254433d6423SLionel Sambuc         }
255433d6423SLionel Sambuc 
256433d6423SLionel Sambuc         NextGpeXrupt = NextGpeXrupt->Next;
257433d6423SLionel Sambuc     }
258433d6423SLionel Sambuc 
259433d6423SLionel Sambuc     /* Not found, must allocate a new xrupt descriptor */
260433d6423SLionel Sambuc 
261433d6423SLionel Sambuc     GpeXrupt = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_XRUPT_INFO));
262433d6423SLionel Sambuc     if (!GpeXrupt)
263433d6423SLionel Sambuc     {
264*29492bb7SDavid van Moolenbroek         return_ACPI_STATUS (AE_NO_MEMORY);
265433d6423SLionel Sambuc     }
266433d6423SLionel Sambuc 
267433d6423SLionel Sambuc     GpeXrupt->InterruptNumber = InterruptNumber;
268433d6423SLionel Sambuc 
269433d6423SLionel Sambuc     /* Install new interrupt descriptor with spin lock */
270433d6423SLionel Sambuc 
271433d6423SLionel Sambuc     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
272433d6423SLionel Sambuc     if (AcpiGbl_GpeXruptListHead)
273433d6423SLionel Sambuc     {
274433d6423SLionel Sambuc         NextGpeXrupt = AcpiGbl_GpeXruptListHead;
275433d6423SLionel Sambuc         while (NextGpeXrupt->Next)
276433d6423SLionel Sambuc         {
277433d6423SLionel Sambuc             NextGpeXrupt = NextGpeXrupt->Next;
278433d6423SLionel Sambuc         }
279433d6423SLionel Sambuc 
280433d6423SLionel Sambuc         NextGpeXrupt->Next = GpeXrupt;
281433d6423SLionel Sambuc         GpeXrupt->Previous = NextGpeXrupt;
282433d6423SLionel Sambuc     }
283433d6423SLionel Sambuc     else
284433d6423SLionel Sambuc     {
285433d6423SLionel Sambuc         AcpiGbl_GpeXruptListHead = GpeXrupt;
286433d6423SLionel Sambuc     }
287*29492bb7SDavid van Moolenbroek 
288433d6423SLionel Sambuc     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
289433d6423SLionel Sambuc 
290433d6423SLionel Sambuc     /* Install new interrupt handler if not SCI_INT */
291433d6423SLionel Sambuc 
292433d6423SLionel Sambuc     if (InterruptNumber != AcpiGbl_FADT.SciInterrupt)
293433d6423SLionel Sambuc     {
294433d6423SLionel Sambuc         Status = AcpiOsInstallInterruptHandler (InterruptNumber,
295433d6423SLionel Sambuc                     AcpiEvGpeXruptHandler, GpeXrupt);
296433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
297433d6423SLionel Sambuc         {
298*29492bb7SDavid van Moolenbroek             ACPI_EXCEPTION ((AE_INFO, Status,
299433d6423SLionel Sambuc                 "Could not install GPE interrupt handler at level 0x%X",
300433d6423SLionel Sambuc                 InterruptNumber));
301*29492bb7SDavid van Moolenbroek             return_ACPI_STATUS (Status);
302433d6423SLionel Sambuc         }
303433d6423SLionel Sambuc     }
304433d6423SLionel Sambuc 
305*29492bb7SDavid van Moolenbroek     *GpeXruptBlock = GpeXrupt;
306*29492bb7SDavid van Moolenbroek     return_ACPI_STATUS (AE_OK);
307433d6423SLionel Sambuc }
308433d6423SLionel Sambuc 
309433d6423SLionel Sambuc 
310433d6423SLionel Sambuc /*******************************************************************************
311433d6423SLionel Sambuc  *
312433d6423SLionel Sambuc  * FUNCTION:    AcpiEvDeleteGpeXrupt
313433d6423SLionel Sambuc  *
314433d6423SLionel Sambuc  * PARAMETERS:  GpeXrupt        - A GPE interrupt info block
315433d6423SLionel Sambuc  *
316433d6423SLionel Sambuc  * RETURN:      Status
317433d6423SLionel Sambuc  *
318433d6423SLionel Sambuc  * DESCRIPTION: Remove and free a GpeXrupt block. Remove an associated
319433d6423SLionel Sambuc  *              interrupt handler if not the SCI interrupt.
320433d6423SLionel Sambuc  *
321433d6423SLionel Sambuc  ******************************************************************************/
322433d6423SLionel Sambuc 
323433d6423SLionel Sambuc ACPI_STATUS
AcpiEvDeleteGpeXrupt(ACPI_GPE_XRUPT_INFO * GpeXrupt)324433d6423SLionel Sambuc AcpiEvDeleteGpeXrupt (
325433d6423SLionel Sambuc     ACPI_GPE_XRUPT_INFO     *GpeXrupt)
326433d6423SLionel Sambuc {
327433d6423SLionel Sambuc     ACPI_STATUS             Status;
328433d6423SLionel Sambuc     ACPI_CPU_FLAGS          Flags;
329433d6423SLionel Sambuc 
330433d6423SLionel Sambuc 
331433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (EvDeleteGpeXrupt);
332433d6423SLionel Sambuc 
333433d6423SLionel Sambuc 
334433d6423SLionel Sambuc     /* We never want to remove the SCI interrupt handler */
335433d6423SLionel Sambuc 
336433d6423SLionel Sambuc     if (GpeXrupt->InterruptNumber == AcpiGbl_FADT.SciInterrupt)
337433d6423SLionel Sambuc     {
338433d6423SLionel Sambuc         GpeXrupt->GpeBlockListHead = NULL;
339433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
340433d6423SLionel Sambuc     }
341433d6423SLionel Sambuc 
342433d6423SLionel Sambuc     /* Disable this interrupt */
343433d6423SLionel Sambuc 
344433d6423SLionel Sambuc     Status = AcpiOsRemoveInterruptHandler (
345433d6423SLionel Sambuc                 GpeXrupt->InterruptNumber, AcpiEvGpeXruptHandler);
346433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
347433d6423SLionel Sambuc     {
348433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
349433d6423SLionel Sambuc     }
350433d6423SLionel Sambuc 
351433d6423SLionel Sambuc     /* Unlink the interrupt block with lock */
352433d6423SLionel Sambuc 
353433d6423SLionel Sambuc     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
354433d6423SLionel Sambuc     if (GpeXrupt->Previous)
355433d6423SLionel Sambuc     {
356433d6423SLionel Sambuc         GpeXrupt->Previous->Next = GpeXrupt->Next;
357433d6423SLionel Sambuc     }
358433d6423SLionel Sambuc     else
359433d6423SLionel Sambuc     {
360433d6423SLionel Sambuc         /* No previous, update list head */
361433d6423SLionel Sambuc 
362433d6423SLionel Sambuc         AcpiGbl_GpeXruptListHead = GpeXrupt->Next;
363433d6423SLionel Sambuc     }
364433d6423SLionel Sambuc 
365433d6423SLionel Sambuc     if (GpeXrupt->Next)
366433d6423SLionel Sambuc     {
367433d6423SLionel Sambuc         GpeXrupt->Next->Previous = GpeXrupt->Previous;
368433d6423SLionel Sambuc     }
369433d6423SLionel Sambuc     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
370433d6423SLionel Sambuc 
371433d6423SLionel Sambuc     /* Free the block */
372433d6423SLionel Sambuc 
373433d6423SLionel Sambuc     ACPI_FREE (GpeXrupt);
374433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
375433d6423SLionel Sambuc }
376433d6423SLionel Sambuc 
377433d6423SLionel Sambuc 
378433d6423SLionel Sambuc /*******************************************************************************
379433d6423SLionel Sambuc  *
380433d6423SLionel Sambuc  * FUNCTION:    AcpiEvDeleteGpeHandlers
381433d6423SLionel Sambuc  *
382433d6423SLionel Sambuc  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
383433d6423SLionel Sambuc  *              GpeBlock            - Gpe Block info
384433d6423SLionel Sambuc  *
385433d6423SLionel Sambuc  * RETURN:      Status
386433d6423SLionel Sambuc  *
387433d6423SLionel Sambuc  * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
388433d6423SLionel Sambuc  *              Used only prior to termination.
389433d6423SLionel Sambuc  *
390433d6423SLionel Sambuc  ******************************************************************************/
391433d6423SLionel Sambuc 
392433d6423SLionel Sambuc ACPI_STATUS
AcpiEvDeleteGpeHandlers(ACPI_GPE_XRUPT_INFO * GpeXruptInfo,ACPI_GPE_BLOCK_INFO * GpeBlock,void * Context)393433d6423SLionel Sambuc AcpiEvDeleteGpeHandlers (
394433d6423SLionel Sambuc     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
395433d6423SLionel Sambuc     ACPI_GPE_BLOCK_INFO     *GpeBlock,
396433d6423SLionel Sambuc     void                    *Context)
397433d6423SLionel Sambuc {
398433d6423SLionel Sambuc     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
399*29492bb7SDavid van Moolenbroek     ACPI_GPE_NOTIFY_INFO    *Notify;
400*29492bb7SDavid van Moolenbroek     ACPI_GPE_NOTIFY_INFO    *Next;
401433d6423SLionel Sambuc     UINT32                  i;
402433d6423SLionel Sambuc     UINT32                  j;
403433d6423SLionel Sambuc 
404433d6423SLionel Sambuc 
405433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (EvDeleteGpeHandlers);
406433d6423SLionel Sambuc 
407433d6423SLionel Sambuc 
408433d6423SLionel Sambuc     /* Examine each GPE Register within the block */
409433d6423SLionel Sambuc 
410433d6423SLionel Sambuc     for (i = 0; i < GpeBlock->RegisterCount; i++)
411433d6423SLionel Sambuc     {
412433d6423SLionel Sambuc         /* Now look at the individual GPEs in this byte register */
413433d6423SLionel Sambuc 
414433d6423SLionel Sambuc         for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
415433d6423SLionel Sambuc         {
416433d6423SLionel Sambuc             GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
417433d6423SLionel Sambuc                 ACPI_GPE_REGISTER_WIDTH) + j];
418433d6423SLionel Sambuc 
419433d6423SLionel Sambuc             if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
420433d6423SLionel Sambuc                     ACPI_GPE_DISPATCH_HANDLER)
421433d6423SLionel Sambuc             {
422*29492bb7SDavid van Moolenbroek                 /* Delete an installed handler block */
423*29492bb7SDavid van Moolenbroek 
424433d6423SLionel Sambuc                 ACPI_FREE (GpeEventInfo->Dispatch.Handler);
425433d6423SLionel Sambuc                 GpeEventInfo->Dispatch.Handler = NULL;
426433d6423SLionel Sambuc                 GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;
427433d6423SLionel Sambuc             }
428*29492bb7SDavid van Moolenbroek             else if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
429*29492bb7SDavid van Moolenbroek                     ACPI_GPE_DISPATCH_NOTIFY)
430*29492bb7SDavid van Moolenbroek             {
431*29492bb7SDavid van Moolenbroek                 /* Delete the implicit notification device list */
432*29492bb7SDavid van Moolenbroek 
433*29492bb7SDavid van Moolenbroek                 Notify = GpeEventInfo->Dispatch.NotifyList;
434*29492bb7SDavid van Moolenbroek                 while (Notify)
435*29492bb7SDavid van Moolenbroek                 {
436*29492bb7SDavid van Moolenbroek                     Next = Notify->Next;
437*29492bb7SDavid van Moolenbroek                     ACPI_FREE (Notify);
438*29492bb7SDavid van Moolenbroek                     Notify = Next;
439*29492bb7SDavid van Moolenbroek                 }
440*29492bb7SDavid van Moolenbroek                 GpeEventInfo->Dispatch.NotifyList = NULL;
441*29492bb7SDavid van Moolenbroek                 GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;
442*29492bb7SDavid van Moolenbroek             }
443433d6423SLionel Sambuc         }
444433d6423SLionel Sambuc     }
445433d6423SLionel Sambuc 
446433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
447433d6423SLionel Sambuc }
448433d6423SLionel Sambuc 
449*29492bb7SDavid van Moolenbroek #endif /* !ACPI_REDUCED_HARDWARE */
450