1 /******************************************************************************
2  *
3  * Module Name: evgpeblk - GPE block creation and initialization.
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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.
65  *
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.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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.
89  *
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.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acevents.h"
155 #include "acnamesp.h"
156 
157 #define _COMPONENT          ACPI_EVENTS
158         ACPI_MODULE_NAME    ("evgpeblk")
159 
160 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
161 
162 /* Local prototypes */
163 
164 static ACPI_STATUS
165 AcpiEvInstallGpeBlock (
166     ACPI_GPE_BLOCK_INFO     *GpeBlock,
167     UINT32                  InterruptNumber);
168 
169 static ACPI_STATUS
170 AcpiEvCreateGpeInfoBlocks (
171     ACPI_GPE_BLOCK_INFO     *GpeBlock);
172 
173 
174 /*******************************************************************************
175  *
176  * FUNCTION:    AcpiEvInstallGpeBlock
177  *
178  * PARAMETERS:  GpeBlock                - New GPE block
179  *              InterruptNumber         - Xrupt to be associated with this
180  *                                        GPE block
181  *
182  * RETURN:      Status
183  *
184  * DESCRIPTION: Install new GPE block with mutex support
185  *
186  ******************************************************************************/
187 
188 static ACPI_STATUS
AcpiEvInstallGpeBlock(ACPI_GPE_BLOCK_INFO * GpeBlock,UINT32 InterruptNumber)189 AcpiEvInstallGpeBlock (
190     ACPI_GPE_BLOCK_INFO     *GpeBlock,
191     UINT32                  InterruptNumber)
192 {
193     ACPI_GPE_BLOCK_INFO     *NextGpeBlock;
194     ACPI_GPE_XRUPT_INFO     *GpeXruptBlock;
195     ACPI_STATUS             Status;
196     ACPI_CPU_FLAGS          Flags;
197 
198 
199     ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
200 
201 
202     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
203     if (ACPI_FAILURE (Status))
204     {
205         return_ACPI_STATUS (Status);
206     }
207 
208     Status = AcpiEvGetGpeXruptBlock (InterruptNumber, &GpeXruptBlock);
209     if (ACPI_FAILURE (Status))
210     {
211         goto UnlockAndExit;
212     }
213 
214     /* Install the new block at the end of the list with lock */
215 
216     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
217     if (GpeXruptBlock->GpeBlockListHead)
218     {
219         NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
220         while (NextGpeBlock->Next)
221         {
222             NextGpeBlock = NextGpeBlock->Next;
223         }
224 
225         NextGpeBlock->Next = GpeBlock;
226         GpeBlock->Previous = NextGpeBlock;
227     }
228     else
229     {
230         GpeXruptBlock->GpeBlockListHead = GpeBlock;
231     }
232 
233     GpeBlock->XruptBlock = GpeXruptBlock;
234     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
235 
236 
237 UnlockAndExit:
238     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
239     return_ACPI_STATUS (Status);
240 }
241 
242 
243 /*******************************************************************************
244  *
245  * FUNCTION:    AcpiEvDeleteGpeBlock
246  *
247  * PARAMETERS:  GpeBlock            - Existing GPE block
248  *
249  * RETURN:      Status
250  *
251  * DESCRIPTION: Remove a GPE block
252  *
253  ******************************************************************************/
254 
255 ACPI_STATUS
AcpiEvDeleteGpeBlock(ACPI_GPE_BLOCK_INFO * GpeBlock)256 AcpiEvDeleteGpeBlock (
257     ACPI_GPE_BLOCK_INFO     *GpeBlock)
258 {
259     ACPI_STATUS             Status;
260     ACPI_CPU_FLAGS          Flags;
261 
262 
263     ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
264 
265 
266     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
267     if (ACPI_FAILURE (Status))
268     {
269         return_ACPI_STATUS (Status);
270     }
271 
272     /* Disable all GPEs in this block */
273 
274     Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock, NULL);
275 
276     if (!GpeBlock->Previous && !GpeBlock->Next)
277     {
278         /* This is the last GpeBlock on this interrupt */
279 
280         Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
281         if (ACPI_FAILURE (Status))
282         {
283             goto UnlockAndExit;
284         }
285     }
286     else
287     {
288         /* Remove the block on this interrupt with lock */
289 
290         Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
291         if (GpeBlock->Previous)
292         {
293             GpeBlock->Previous->Next = GpeBlock->Next;
294         }
295         else
296         {
297             GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
298         }
299 
300         if (GpeBlock->Next)
301         {
302             GpeBlock->Next->Previous = GpeBlock->Previous;
303         }
304 
305         AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
306     }
307 
308     AcpiCurrentGpeCount -= GpeBlock->GpeCount;
309 
310     /* Free the GpeBlock */
311 
312     ACPI_FREE (GpeBlock->RegisterInfo);
313     ACPI_FREE (GpeBlock->EventInfo);
314     ACPI_FREE (GpeBlock);
315 
316 UnlockAndExit:
317     Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
318     return_ACPI_STATUS (Status);
319 }
320 
321 
322 /*******************************************************************************
323  *
324  * FUNCTION:    AcpiEvCreateGpeInfoBlocks
325  *
326  * PARAMETERS:  GpeBlock    - New GPE block
327  *
328  * RETURN:      Status
329  *
330  * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
331  *
332  ******************************************************************************/
333 
334 static ACPI_STATUS
AcpiEvCreateGpeInfoBlocks(ACPI_GPE_BLOCK_INFO * GpeBlock)335 AcpiEvCreateGpeInfoBlocks (
336     ACPI_GPE_BLOCK_INFO     *GpeBlock)
337 {
338     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo = NULL;
339     ACPI_GPE_EVENT_INFO     *GpeEventInfo = NULL;
340     ACPI_GPE_EVENT_INFO     *ThisEvent;
341     ACPI_GPE_REGISTER_INFO  *ThisRegister;
342     UINT32                  i;
343     UINT32                  j;
344     ACPI_STATUS             Status;
345 
346 
347     ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks);
348 
349 
350     /* Allocate the GPE register information block */
351 
352     GpeRegisterInfo = ACPI_ALLOCATE_ZEROED (
353         (ACPI_SIZE) GpeBlock->RegisterCount *
354         sizeof (ACPI_GPE_REGISTER_INFO));
355     if (!GpeRegisterInfo)
356     {
357         ACPI_ERROR ((AE_INFO,
358             "Could not allocate the GpeRegisterInfo table"));
359         return_ACPI_STATUS (AE_NO_MEMORY);
360     }
361 
362     /*
363      * Allocate the GPE EventInfo block. There are eight distinct GPEs
364      * per register. Initialization to zeros is sufficient.
365      */
366     GpeEventInfo = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) GpeBlock->GpeCount *
367         sizeof (ACPI_GPE_EVENT_INFO));
368     if (!GpeEventInfo)
369     {
370         ACPI_ERROR ((AE_INFO,
371             "Could not allocate the GpeEventInfo table"));
372         Status = AE_NO_MEMORY;
373         goto ErrorExit;
374     }
375 
376     /* Save the new Info arrays in the GPE block */
377 
378     GpeBlock->RegisterInfo = GpeRegisterInfo;
379     GpeBlock->EventInfo = GpeEventInfo;
380 
381     /*
382      * Initialize the GPE Register and Event structures. A goal of these
383      * tables is to hide the fact that there are two separate GPE register
384      * sets in a given GPE hardware block, the status registers occupy the
385      * first half, and the enable registers occupy the second half.
386      */
387     ThisRegister = GpeRegisterInfo;
388     ThisEvent = GpeEventInfo;
389 
390     for (i = 0; i < GpeBlock->RegisterCount; i++)
391     {
392         /* Init the RegisterInfo for this GPE register (8 GPEs) */
393 
394         ThisRegister->BaseGpeNumber = (UINT16)
395             (GpeBlock->BlockBaseNumber + (i * ACPI_GPE_REGISTER_WIDTH));
396 
397         ThisRegister->StatusAddress.Address =
398             GpeBlock->Address + i;
399 
400         ThisRegister->EnableAddress.Address =
401             GpeBlock->Address + i + GpeBlock->RegisterCount;
402 
403         ThisRegister->StatusAddress.SpaceId   = GpeBlock->SpaceId;
404         ThisRegister->EnableAddress.SpaceId   = GpeBlock->SpaceId;
405         ThisRegister->StatusAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
406         ThisRegister->EnableAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
407         ThisRegister->StatusAddress.BitOffset = 0;
408         ThisRegister->EnableAddress.BitOffset = 0;
409 
410         /* Init the EventInfo for each GPE within this register */
411 
412         for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
413         {
414             ThisEvent->GpeNumber = (UINT8) (ThisRegister->BaseGpeNumber + j);
415             ThisEvent->RegisterInfo = ThisRegister;
416             ThisEvent++;
417         }
418 
419         /* Disable all GPEs within this register */
420 
421         Status = AcpiHwWrite (0x00, &ThisRegister->EnableAddress);
422         if (ACPI_FAILURE (Status))
423         {
424             goto ErrorExit;
425         }
426 
427         /* Clear any pending GPE events within this register */
428 
429         Status = AcpiHwWrite (0xFF, &ThisRegister->StatusAddress);
430         if (ACPI_FAILURE (Status))
431         {
432             goto ErrorExit;
433         }
434 
435         ThisRegister++;
436     }
437 
438     return_ACPI_STATUS (AE_OK);
439 
440 
441 ErrorExit:
442     if (GpeRegisterInfo)
443     {
444         ACPI_FREE (GpeRegisterInfo);
445     }
446     if (GpeEventInfo)
447     {
448         ACPI_FREE (GpeEventInfo);
449     }
450 
451     return_ACPI_STATUS (Status);
452 }
453 
454 
455 /*******************************************************************************
456  *
457  * FUNCTION:    AcpiEvCreateGpeBlock
458  *
459  * PARAMETERS:  GpeDevice           - Handle to the parent GPE block
460  *              GpeBlockAddress     - Address and SpaceID
461  *              RegisterCount       - Number of GPE register pairs in the block
462  *              GpeBlockBaseNumber  - Starting GPE number for the block
463  *              InterruptNumber     - H/W interrupt for the block
464  *              ReturnGpeBlock      - Where the new block descriptor is returned
465  *
466  * RETURN:      Status
467  *
468  * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
469  *              the block are disabled at exit.
470  *              Note: Assumes namespace is locked.
471  *
472  ******************************************************************************/
473 
474 ACPI_STATUS
AcpiEvCreateGpeBlock(ACPI_NAMESPACE_NODE * GpeDevice,UINT64 Address,UINT8 SpaceId,UINT32 RegisterCount,UINT16 GpeBlockBaseNumber,UINT32 InterruptNumber,ACPI_GPE_BLOCK_INFO ** ReturnGpeBlock)475 AcpiEvCreateGpeBlock (
476     ACPI_NAMESPACE_NODE     *GpeDevice,
477     UINT64                  Address,
478     UINT8                   SpaceId,
479     UINT32                  RegisterCount,
480     UINT16                  GpeBlockBaseNumber,
481     UINT32                  InterruptNumber,
482     ACPI_GPE_BLOCK_INFO     **ReturnGpeBlock)
483 {
484     ACPI_STATUS             Status;
485     ACPI_GPE_BLOCK_INFO     *GpeBlock;
486     ACPI_GPE_WALK_INFO      WalkInfo;
487 
488 
489     ACPI_FUNCTION_TRACE (EvCreateGpeBlock);
490 
491 
492     if (!RegisterCount)
493     {
494         return_ACPI_STATUS (AE_OK);
495     }
496 
497     /* Allocate a new GPE block */
498 
499     GpeBlock = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO));
500     if (!GpeBlock)
501     {
502         return_ACPI_STATUS (AE_NO_MEMORY);
503     }
504 
505     /* Initialize the new GPE block */
506 
507     GpeBlock->Address = Address;
508     GpeBlock->SpaceId = SpaceId;
509     GpeBlock->Node = GpeDevice;
510     GpeBlock->GpeCount = (UINT16) (RegisterCount * ACPI_GPE_REGISTER_WIDTH);
511     GpeBlock->Initialized = FALSE;
512     GpeBlock->RegisterCount = RegisterCount;
513     GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
514 
515     /*
516      * Create the RegisterInfo and EventInfo sub-structures
517      * Note: disables and clears all GPEs in the block
518      */
519     Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
520     if (ACPI_FAILURE (Status))
521     {
522         ACPI_FREE (GpeBlock);
523         return_ACPI_STATUS (Status);
524     }
525 
526     /* Install the new block in the global lists */
527 
528     Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
529     if (ACPI_FAILURE (Status))
530     {
531         ACPI_FREE (GpeBlock->RegisterInfo);
532         ACPI_FREE (GpeBlock->EventInfo);
533         ACPI_FREE (GpeBlock);
534         return_ACPI_STATUS (Status);
535     }
536 
537     AcpiGbl_AllGpesInitialized = FALSE;
538 
539     /* Find all GPE methods (_Lxx or_Exx) for this block */
540 
541     WalkInfo.GpeBlock = GpeBlock;
542     WalkInfo.GpeDevice = GpeDevice;
543     WalkInfo.ExecuteByOwnerId = FALSE;
544 
545     Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
546         ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
547         AcpiEvMatchGpeMethod, NULL, &WalkInfo, NULL);
548 
549     /* Return the new block */
550 
551     if (ReturnGpeBlock)
552     {
553         (*ReturnGpeBlock) = GpeBlock;
554     }
555 
556     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
557         "    Initialized GPE %02X to %02X [%4.4s] %u regs on interrupt 0x%X%s\n",
558         (UINT32) GpeBlock->BlockBaseNumber,
559         (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1)),
560         GpeDevice->Name.Ascii, GpeBlock->RegisterCount, InterruptNumber,
561         InterruptNumber == AcpiGbl_FADT.SciInterrupt ? " (SCI)" : ""));
562 
563     /* Update global count of currently available GPEs */
564 
565     AcpiCurrentGpeCount += GpeBlock->GpeCount;
566     return_ACPI_STATUS (AE_OK);
567 }
568 
569 
570 /*******************************************************************************
571  *
572  * FUNCTION:    AcpiEvInitializeGpeBlock
573  *
574  * PARAMETERS:  ACPI_GPE_CALLBACK
575  *
576  * RETURN:      Status
577  *
578  * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
579  *              associated methods.
580  *              Note: Assumes namespace is locked.
581  *
582  ******************************************************************************/
583 
584 ACPI_STATUS
AcpiEvInitializeGpeBlock(ACPI_GPE_XRUPT_INFO * GpeXruptInfo,ACPI_GPE_BLOCK_INFO * GpeBlock,void * Context)585 AcpiEvInitializeGpeBlock (
586     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
587     ACPI_GPE_BLOCK_INFO     *GpeBlock,
588     void                    *Context)
589 {
590     ACPI_STATUS             Status;
591     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
592     UINT32                  GpeEnabledCount;
593     UINT32                  GpeIndex;
594     UINT32                  i;
595     UINT32                  j;
596     BOOLEAN                 *IsPollingNeeded = Context;
597     ACPI_ERROR_ONLY (UINT32 GpeNumber);
598 
599 
600     ACPI_FUNCTION_TRACE (EvInitializeGpeBlock);
601 
602 
603     /*
604      * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
605      * any GPE blocks that have been initialized already.
606      */
607     if (!GpeBlock || GpeBlock->Initialized)
608     {
609         return_ACPI_STATUS (AE_OK);
610     }
611 
612     /*
613      * Enable all GPEs that have a corresponding method and have the
614      * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
615      * must be enabled via the acpi_enable_gpe() interface.
616      */
617     GpeEnabledCount = 0;
618 
619     for (i = 0; i < GpeBlock->RegisterCount; i++)
620     {
621         for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
622         {
623             /* Get the info block for this particular GPE */
624 
625             GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
626             GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
627             ACPI_ERROR_ONLY(GpeNumber = GpeBlock->BlockBaseNumber + GpeIndex);
628             GpeEventInfo->Flags |= ACPI_GPE_INITIALIZED;
629 
630             /*
631              * Ignore GPEs that have no corresponding _Lxx/_Exx method
632              * and GPEs that are used to wake the system
633              */
634             if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) != ACPI_GPE_DISPATCH_METHOD) ||
635                 (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
636             {
637                 continue;
638             }
639 
640             Status = AcpiEvAddGpeReference (GpeEventInfo);
641             if (ACPI_FAILURE (Status))
642             {
643                 ACPI_EXCEPTION ((AE_INFO, Status,
644                     "Could not enable GPE 0x%02X",
645                     GpeNumber));
646                 continue;
647             }
648 
649             GpeEventInfo->Flags |= ACPI_GPE_AUTO_ENABLED;
650 
651             if (IsPollingNeeded &&
652                 ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
653             {
654                 *IsPollingNeeded = TRUE;
655             }
656 
657             GpeEnabledCount++;
658         }
659     }
660 
661     if (GpeEnabledCount)
662     {
663         ACPI_INFO ((
664             "Enabled %u GPEs in block %02X to %02X", GpeEnabledCount,
665             (UINT32) GpeBlock->BlockBaseNumber,
666             (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1))));
667     }
668 
669     GpeBlock->Initialized = TRUE;
670     return_ACPI_STATUS (AE_OK);
671 }
672 
673 #endif /* !ACPI_REDUCED_HARDWARE */
674