1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
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
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
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
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #include "accommon.h"
118 #include "acevents.h"
119 #include "acnamesp.h"
121 #define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evgpeblk")
124 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
126 /* Local prototypes */
129 AcpiEvInstallGpeBlock (
130 ACPI_GPE_BLOCK_INFO *GpeBlock,
131 UINT32 InterruptNumber);
134 AcpiEvCreateGpeInfoBlocks (
135 ACPI_GPE_BLOCK_INFO *GpeBlock);
138 /*******************************************************************************
140 * FUNCTION: AcpiEvInstallGpeBlock
142 * PARAMETERS: GpeBlock - New GPE block
143 * InterruptNumber - Xrupt to be associated with this
148 * DESCRIPTION: Install new GPE block with mutex support
150 ******************************************************************************/
153 AcpiEvInstallGpeBlock (
154 ACPI_GPE_BLOCK_INFO *GpeBlock,
155 UINT32 InterruptNumber)
157 ACPI_GPE_BLOCK_INFO *NextGpeBlock;
158 ACPI_GPE_XRUPT_INFO *GpeXruptBlock;
160 ACPI_CPU_FLAGS Flags;
163 ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
166 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
167 if (ACPI_FAILURE (Status))
169 return_ACPI_STATUS (Status);
172 Status = AcpiEvGetGpeXruptBlock (InterruptNumber, &GpeXruptBlock);
173 if (ACPI_FAILURE (Status))
178 /* Install the new block at the end of the list with lock */
180 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
181 if (GpeXruptBlock->GpeBlockListHead)
183 NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
184 while (NextGpeBlock->Next)
186 NextGpeBlock = NextGpeBlock->Next;
189 NextGpeBlock->Next = GpeBlock;
190 GpeBlock->Previous = NextGpeBlock;
194 GpeXruptBlock->GpeBlockListHead = GpeBlock;
197 GpeBlock->XruptBlock = GpeXruptBlock;
198 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
202 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
203 return_ACPI_STATUS (Status);
207 /*******************************************************************************
209 * FUNCTION: AcpiEvDeleteGpeBlock
211 * PARAMETERS: GpeBlock - Existing GPE block
215 * DESCRIPTION: Remove a GPE block
217 ******************************************************************************/
220 AcpiEvDeleteGpeBlock (
221 ACPI_GPE_BLOCK_INFO *GpeBlock)
224 ACPI_CPU_FLAGS Flags;
227 ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
230 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
231 if (ACPI_FAILURE (Status))
233 return_ACPI_STATUS (Status);
236 /* Disable all GPEs in this block */
238 Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock, NULL);
240 if (!GpeBlock->Previous && !GpeBlock->Next)
242 /* This is the last GpeBlock on this interrupt */
244 Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
245 if (ACPI_FAILURE (Status))
252 /* Remove the block on this interrupt with lock */
254 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
255 if (GpeBlock->Previous)
257 GpeBlock->Previous->Next = GpeBlock->Next;
261 GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
266 GpeBlock->Next->Previous = GpeBlock->Previous;
268 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
271 AcpiCurrentGpeCount -= GpeBlock->GpeCount;
273 /* Free the GpeBlock */
275 ACPI_FREE (GpeBlock->RegisterInfo);
276 ACPI_FREE (GpeBlock->EventInfo);
277 ACPI_FREE (GpeBlock);
280 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
281 return_ACPI_STATUS (Status);
285 /*******************************************************************************
287 * FUNCTION: AcpiEvCreateGpeInfoBlocks
289 * PARAMETERS: GpeBlock - New GPE block
293 * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
295 ******************************************************************************/
298 AcpiEvCreateGpeInfoBlocks (
299 ACPI_GPE_BLOCK_INFO *GpeBlock)
301 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo = NULL;
302 ACPI_GPE_EVENT_INFO *GpeEventInfo = NULL;
303 ACPI_GPE_EVENT_INFO *ThisEvent;
304 ACPI_GPE_REGISTER_INFO *ThisRegister;
310 ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks);
313 /* Allocate the GPE register information block */
315 GpeRegisterInfo = ACPI_ALLOCATE_ZEROED (
316 (ACPI_SIZE) GpeBlock->RegisterCount *
317 sizeof (ACPI_GPE_REGISTER_INFO));
318 if (!GpeRegisterInfo)
320 ACPI_ERROR ((AE_INFO,
321 "Could not allocate the GpeRegisterInfo table"));
322 return_ACPI_STATUS (AE_NO_MEMORY);
326 * Allocate the GPE EventInfo block. There are eight distinct GPEs
327 * per register. Initialization to zeros is sufficient.
329 GpeEventInfo = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) GpeBlock->GpeCount *
330 sizeof (ACPI_GPE_EVENT_INFO));
333 ACPI_ERROR ((AE_INFO,
334 "Could not allocate the GpeEventInfo table"));
335 Status = AE_NO_MEMORY;
339 /* Save the new Info arrays in the GPE block */
341 GpeBlock->RegisterInfo = GpeRegisterInfo;
342 GpeBlock->EventInfo = GpeEventInfo;
345 * Initialize the GPE Register and Event structures. A goal of these
346 * tables is to hide the fact that there are two separate GPE register
347 * sets in a given GPE hardware block, the status registers occupy the
348 * first half, and the enable registers occupy the second half.
350 ThisRegister = GpeRegisterInfo;
351 ThisEvent = GpeEventInfo;
353 for (i = 0; i < GpeBlock->RegisterCount; i++)
355 /* Init the RegisterInfo for this GPE register (8 GPEs) */
357 ThisRegister->BaseGpeNumber = (UINT16)
358 (GpeBlock->BlockBaseNumber + (i * ACPI_GPE_REGISTER_WIDTH));
360 ThisRegister->StatusAddress.Address =
361 GpeBlock->Address + i;
363 ThisRegister->EnableAddress.Address =
364 GpeBlock->Address + i + GpeBlock->RegisterCount;
366 ThisRegister->StatusAddress.SpaceId = GpeBlock->SpaceId;
367 ThisRegister->EnableAddress.SpaceId = GpeBlock->SpaceId;
368 ThisRegister->StatusAddress.BitWidth = ACPI_GPE_REGISTER_WIDTH;
369 ThisRegister->EnableAddress.BitWidth = ACPI_GPE_REGISTER_WIDTH;
370 ThisRegister->StatusAddress.BitOffset = 0;
371 ThisRegister->EnableAddress.BitOffset = 0;
373 /* Init the EventInfo for each GPE within this register */
375 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
377 ThisEvent->GpeNumber = (UINT8) (ThisRegister->BaseGpeNumber + j);
378 ThisEvent->RegisterInfo = ThisRegister;
382 /* Disable all GPEs within this register */
384 Status = AcpiHwWrite (0x00, &ThisRegister->EnableAddress);
385 if (ACPI_FAILURE (Status))
390 /* Clear any pending GPE events within this register */
392 Status = AcpiHwWrite (0xFF, &ThisRegister->StatusAddress);
393 if (ACPI_FAILURE (Status))
401 return_ACPI_STATUS (AE_OK);
407 ACPI_FREE (GpeRegisterInfo);
411 ACPI_FREE (GpeEventInfo);
414 return_ACPI_STATUS (Status);
418 /*******************************************************************************
420 * FUNCTION: AcpiEvCreateGpeBlock
422 * PARAMETERS: GpeDevice - Handle to the parent GPE block
423 * GpeBlockAddress - Address and SpaceID
424 * RegisterCount - Number of GPE register pairs in the block
425 * GpeBlockBaseNumber - Starting GPE number for the block
426 * InterruptNumber - H/W interrupt for the block
427 * ReturnGpeBlock - Where the new block descriptor is returned
431 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
432 * the block are disabled at exit.
433 * Note: Assumes namespace is locked.
435 ******************************************************************************/
438 AcpiEvCreateGpeBlock (
439 ACPI_NAMESPACE_NODE *GpeDevice,
442 UINT32 RegisterCount,
443 UINT16 GpeBlockBaseNumber,
444 UINT32 InterruptNumber,
445 ACPI_GPE_BLOCK_INFO **ReturnGpeBlock)
448 ACPI_GPE_BLOCK_INFO *GpeBlock;
449 ACPI_GPE_WALK_INFO WalkInfo;
452 ACPI_FUNCTION_TRACE (EvCreateGpeBlock);
457 return_ACPI_STATUS (AE_OK);
460 /* Allocate a new GPE block */
462 GpeBlock = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO));
465 return_ACPI_STATUS (AE_NO_MEMORY);
468 /* Initialize the new GPE block */
470 GpeBlock->Address = Address;
471 GpeBlock->SpaceId = SpaceId;
472 GpeBlock->Node = GpeDevice;
473 GpeBlock->GpeCount = (UINT16) (RegisterCount * ACPI_GPE_REGISTER_WIDTH);
474 GpeBlock->Initialized = FALSE;
475 GpeBlock->RegisterCount = RegisterCount;
476 GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
479 * Create the RegisterInfo and EventInfo sub-structures
480 * Note: disables and clears all GPEs in the block
482 Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
483 if (ACPI_FAILURE (Status))
485 ACPI_FREE (GpeBlock);
486 return_ACPI_STATUS (Status);
489 /* Install the new block in the global lists */
491 Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
492 if (ACPI_FAILURE (Status))
494 ACPI_FREE (GpeBlock->RegisterInfo);
495 ACPI_FREE (GpeBlock->EventInfo);
496 ACPI_FREE (GpeBlock);
497 return_ACPI_STATUS (Status);
500 AcpiGbl_AllGpesInitialized = FALSE;
502 /* Find all GPE methods (_Lxx or_Exx) for this block */
504 WalkInfo.GpeBlock = GpeBlock;
505 WalkInfo.GpeDevice = GpeDevice;
506 WalkInfo.ExecuteByOwnerId = FALSE;
508 Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
509 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
510 AcpiEvMatchGpeMethod, NULL, &WalkInfo, NULL);
512 /* Return the new block */
516 (*ReturnGpeBlock) = GpeBlock;
519 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
520 " Initialized GPE %02X to %02X [%4.4s] %u regs on interrupt 0x%X%s\n",
521 (UINT32) GpeBlock->BlockBaseNumber,
522 (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1)),
523 GpeDevice->Name.Ascii, GpeBlock->RegisterCount, InterruptNumber,
524 InterruptNumber == AcpiGbl_FADT.SciInterrupt ? " (SCI)" : ""));
526 /* Update global count of currently available GPEs */
528 AcpiCurrentGpeCount += GpeBlock->GpeCount;
529 return_ACPI_STATUS (AE_OK);
533 /*******************************************************************************
535 * FUNCTION: AcpiEvInitializeGpeBlock
537 * PARAMETERS: ACPI_GPE_CALLBACK
541 * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
542 * associated methods.
543 * Note: Assumes namespace is locked.
545 ******************************************************************************/
548 AcpiEvInitializeGpeBlock (
549 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
550 ACPI_GPE_BLOCK_INFO *GpeBlock,
554 ACPI_GPE_EVENT_INFO *GpeEventInfo;
555 UINT32 GpeEnabledCount;
561 ACPI_FUNCTION_TRACE (EvInitializeGpeBlock);
565 * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
566 * any GPE blocks that have been initialized already.
568 if (!GpeBlock || GpeBlock->Initialized)
570 return_ACPI_STATUS (AE_OK);
574 * Enable all GPEs that have a corresponding method and have the
575 * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
576 * must be enabled via the acpi_enable_gpe() interface.
580 for (i = 0; i < GpeBlock->RegisterCount; i++)
582 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
584 /* Get the info block for this particular GPE */
586 GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
587 GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
590 * Ignore GPEs that have no corresponding _Lxx/_Exx method
591 * and GPEs that are used to wake the system
593 if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_NONE) ||
594 (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_HANDLER) ||
595 (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_RAW_HANDLER) ||
596 (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
601 Status = AcpiEvAddGpeReference (GpeEventInfo);
602 if (ACPI_FAILURE (Status))
604 ACPI_EXCEPTION ((AE_INFO, Status,
605 "Could not enable GPE 0x%02X",
606 GpeIndex + GpeBlock->BlockBaseNumber));
617 "Enabled %u GPEs in block %02X to %02X", GpeEnabledCount,
618 (UINT32) GpeBlock->BlockBaseNumber,
619 (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1))));
622 GpeBlock->Initialized = TRUE;
623 return_ACPI_STATUS (AE_OK);
626 #endif /* !ACPI_REDUCED_HARDWARE */