1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, 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 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
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.
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.
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.
150 *****************************************************************************/
153 #include "accommon.h"
154 #include "acevents.h"
155 #include "acnamesp.h"
157 #define _COMPONENT ACPI_EVENTS
158 ACPI_MODULE_NAME ("evgpeblk")
160 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
162 /* Local prototypes */
165 AcpiEvInstallGpeBlock (
166 ACPI_GPE_BLOCK_INFO
*GpeBlock
,
167 UINT32 InterruptNumber
);
170 AcpiEvCreateGpeInfoBlocks (
171 ACPI_GPE_BLOCK_INFO
*GpeBlock
);
174 /*******************************************************************************
176 * FUNCTION: AcpiEvInstallGpeBlock
178 * PARAMETERS: GpeBlock - New GPE block
179 * InterruptNumber - Xrupt to be associated with this
184 * DESCRIPTION: Install new GPE block with mutex support
186 ******************************************************************************/
189 AcpiEvInstallGpeBlock (
190 ACPI_GPE_BLOCK_INFO
*GpeBlock
,
191 UINT32 InterruptNumber
)
193 ACPI_GPE_BLOCK_INFO
*NextGpeBlock
;
194 ACPI_GPE_XRUPT_INFO
*GpeXruptBlock
;
196 ACPI_CPU_FLAGS Flags
;
199 ACPI_FUNCTION_TRACE (EvInstallGpeBlock
);
202 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
203 if (ACPI_FAILURE (Status
))
205 return_ACPI_STATUS (Status
);
208 Status
= AcpiEvGetGpeXruptBlock (InterruptNumber
, &GpeXruptBlock
);
209 if (ACPI_FAILURE (Status
))
214 /* Install the new block at the end of the list with lock */
216 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
217 if (GpeXruptBlock
->GpeBlockListHead
)
219 NextGpeBlock
= GpeXruptBlock
->GpeBlockListHead
;
220 while (NextGpeBlock
->Next
)
222 NextGpeBlock
= NextGpeBlock
->Next
;
225 NextGpeBlock
->Next
= GpeBlock
;
226 GpeBlock
->Previous
= NextGpeBlock
;
230 GpeXruptBlock
->GpeBlockListHead
= GpeBlock
;
233 GpeBlock
->XruptBlock
= GpeXruptBlock
;
234 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
238 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
239 return_ACPI_STATUS (Status
);
243 /*******************************************************************************
245 * FUNCTION: AcpiEvDeleteGpeBlock
247 * PARAMETERS: GpeBlock - Existing GPE block
251 * DESCRIPTION: Remove a GPE block
253 ******************************************************************************/
256 AcpiEvDeleteGpeBlock (
257 ACPI_GPE_BLOCK_INFO
*GpeBlock
)
260 ACPI_CPU_FLAGS Flags
;
263 ACPI_FUNCTION_TRACE (EvInstallGpeBlock
);
266 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
267 if (ACPI_FAILURE (Status
))
269 return_ACPI_STATUS (Status
);
272 /* Disable all GPEs in this block */
274 Status
= AcpiHwDisableGpeBlock (GpeBlock
->XruptBlock
, GpeBlock
, NULL
);
276 if (!GpeBlock
->Previous
&& !GpeBlock
->Next
)
278 /* This is the last GpeBlock on this interrupt */
280 Status
= AcpiEvDeleteGpeXrupt (GpeBlock
->XruptBlock
);
281 if (ACPI_FAILURE (Status
))
288 /* Remove the block on this interrupt with lock */
290 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
291 if (GpeBlock
->Previous
)
293 GpeBlock
->Previous
->Next
= GpeBlock
->Next
;
297 GpeBlock
->XruptBlock
->GpeBlockListHead
= GpeBlock
->Next
;
302 GpeBlock
->Next
->Previous
= GpeBlock
->Previous
;
305 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
308 AcpiCurrentGpeCount
-= GpeBlock
->GpeCount
;
310 /* Free the GpeBlock */
312 ACPI_FREE (GpeBlock
->RegisterInfo
);
313 ACPI_FREE (GpeBlock
->EventInfo
);
314 ACPI_FREE (GpeBlock
);
317 Status
= AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
318 return_ACPI_STATUS (Status
);
322 /*******************************************************************************
324 * FUNCTION: AcpiEvCreateGpeInfoBlocks
326 * PARAMETERS: GpeBlock - New GPE block
330 * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
332 ******************************************************************************/
335 AcpiEvCreateGpeInfoBlocks (
336 ACPI_GPE_BLOCK_INFO
*GpeBlock
)
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
;
347 ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks
);
350 /* Allocate the GPE register information block */
352 GpeRegisterInfo
= ACPI_ALLOCATE_ZEROED (
353 (ACPI_SIZE
) GpeBlock
->RegisterCount
*
354 sizeof (ACPI_GPE_REGISTER_INFO
));
355 if (!GpeRegisterInfo
)
357 ACPI_ERROR ((AE_INFO
,
358 "Could not allocate the GpeRegisterInfo table"));
359 return_ACPI_STATUS (AE_NO_MEMORY
);
363 * Allocate the GPE EventInfo block. There are eight distinct GPEs
364 * per register. Initialization to zeros is sufficient.
366 GpeEventInfo
= ACPI_ALLOCATE_ZEROED ((ACPI_SIZE
) GpeBlock
->GpeCount
*
367 sizeof (ACPI_GPE_EVENT_INFO
));
370 ACPI_ERROR ((AE_INFO
,
371 "Could not allocate the GpeEventInfo table"));
372 Status
= AE_NO_MEMORY
;
376 /* Save the new Info arrays in the GPE block */
378 GpeBlock
->RegisterInfo
= GpeRegisterInfo
;
379 GpeBlock
->EventInfo
= GpeEventInfo
;
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.
387 ThisRegister
= GpeRegisterInfo
;
388 ThisEvent
= GpeEventInfo
;
390 for (i
= 0; i
< GpeBlock
->RegisterCount
; i
++)
392 /* Init the RegisterInfo for this GPE register (8 GPEs) */
394 ThisRegister
->BaseGpeNumber
= (UINT16
)
395 (GpeBlock
->BlockBaseNumber
+ (i
* ACPI_GPE_REGISTER_WIDTH
));
397 ThisRegister
->StatusAddress
.Address
=
398 GpeBlock
->Address
+ i
;
400 ThisRegister
->EnableAddress
.Address
=
401 GpeBlock
->Address
+ i
+ GpeBlock
->RegisterCount
;
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;
410 /* Init the EventInfo for each GPE within this register */
412 for (j
= 0; j
< ACPI_GPE_REGISTER_WIDTH
; j
++)
414 ThisEvent
->GpeNumber
= (UINT8
) (ThisRegister
->BaseGpeNumber
+ j
);
415 ThisEvent
->RegisterInfo
= ThisRegister
;
419 /* Disable all GPEs within this register */
421 Status
= AcpiHwWrite (0x00, &ThisRegister
->EnableAddress
);
422 if (ACPI_FAILURE (Status
))
427 /* Clear any pending GPE events within this register */
429 Status
= AcpiHwWrite (0xFF, &ThisRegister
->StatusAddress
);
430 if (ACPI_FAILURE (Status
))
438 return_ACPI_STATUS (AE_OK
);
444 ACPI_FREE (GpeRegisterInfo
);
448 ACPI_FREE (GpeEventInfo
);
451 return_ACPI_STATUS (Status
);
455 /*******************************************************************************
457 * FUNCTION: AcpiEvCreateGpeBlock
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
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.
472 ******************************************************************************/
475 AcpiEvCreateGpeBlock (
476 ACPI_NAMESPACE_NODE
*GpeDevice
,
479 UINT32 RegisterCount
,
480 UINT16 GpeBlockBaseNumber
,
481 UINT32 InterruptNumber
,
482 ACPI_GPE_BLOCK_INFO
**ReturnGpeBlock
)
485 ACPI_GPE_BLOCK_INFO
*GpeBlock
;
486 ACPI_GPE_WALK_INFO WalkInfo
;
489 ACPI_FUNCTION_TRACE (EvCreateGpeBlock
);
494 return_ACPI_STATUS (AE_OK
);
497 /* Allocate a new GPE block */
499 GpeBlock
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO
));
502 return_ACPI_STATUS (AE_NO_MEMORY
);
505 /* Initialize the new GPE block */
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
;
516 * Create the RegisterInfo and EventInfo sub-structures
517 * Note: disables and clears all GPEs in the block
519 Status
= AcpiEvCreateGpeInfoBlocks (GpeBlock
);
520 if (ACPI_FAILURE (Status
))
522 ACPI_FREE (GpeBlock
);
523 return_ACPI_STATUS (Status
);
526 /* Install the new block in the global lists */
528 Status
= AcpiEvInstallGpeBlock (GpeBlock
, InterruptNumber
);
529 if (ACPI_FAILURE (Status
))
531 ACPI_FREE (GpeBlock
->RegisterInfo
);
532 ACPI_FREE (GpeBlock
->EventInfo
);
533 ACPI_FREE (GpeBlock
);
534 return_ACPI_STATUS (Status
);
537 AcpiGbl_AllGpesInitialized
= FALSE
;
539 /* Find all GPE methods (_Lxx or_Exx) for this block */
541 WalkInfo
.GpeBlock
= GpeBlock
;
542 WalkInfo
.GpeDevice
= GpeDevice
;
543 WalkInfo
.ExecuteByOwnerId
= FALSE
;
545 Status
= AcpiNsWalkNamespace (ACPI_TYPE_METHOD
, GpeDevice
,
546 ACPI_UINT32_MAX
, ACPI_NS_WALK_NO_UNLOCK
,
547 AcpiEvMatchGpeMethod
, NULL
, &WalkInfo
, NULL
);
549 /* Return the new block */
553 (*ReturnGpeBlock
) = GpeBlock
;
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)" : ""));
563 /* Update global count of currently available GPEs */
565 AcpiCurrentGpeCount
+= GpeBlock
->GpeCount
;
566 return_ACPI_STATUS (AE_OK
);
570 /*******************************************************************************
572 * FUNCTION: AcpiEvInitializeGpeBlock
574 * PARAMETERS: ACPI_GPE_CALLBACK
578 * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
579 * associated methods.
580 * Note: Assumes namespace is locked.
582 ******************************************************************************/
585 AcpiEvInitializeGpeBlock (
586 ACPI_GPE_XRUPT_INFO
*GpeXruptInfo
,
587 ACPI_GPE_BLOCK_INFO
*GpeBlock
,
591 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
592 UINT32 GpeEnabledCount
;
596 BOOLEAN
*IsPollingNeeded
= Context
;
597 ACPI_ERROR_ONLY (UINT32 GpeNumber
);
600 ACPI_FUNCTION_TRACE (EvInitializeGpeBlock
);
604 * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
605 * any GPE blocks that have been initialized already.
607 if (!GpeBlock
|| GpeBlock
->Initialized
)
609 return_ACPI_STATUS (AE_OK
);
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.
619 for (i
= 0; i
< GpeBlock
->RegisterCount
; i
++)
621 for (j
= 0; j
< ACPI_GPE_REGISTER_WIDTH
; j
++)
623 /* Get the info block for this particular GPE */
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
;
631 * Ignore GPEs that have no corresponding _Lxx/_Exx method
632 * and GPEs that are used to wake the system
634 if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo
->Flags
) != ACPI_GPE_DISPATCH_METHOD
) ||
635 (GpeEventInfo
->Flags
& ACPI_GPE_CAN_WAKE
))
640 Status
= AcpiEvAddGpeReference (GpeEventInfo
);
641 if (ACPI_FAILURE (Status
))
643 ACPI_EXCEPTION ((AE_INFO
, Status
,
644 "Could not enable GPE 0x%02X",
649 GpeEventInfo
->Flags
|= ACPI_GPE_AUTO_ENABLED
;
651 if (IsPollingNeeded
&&
652 ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo
))
654 *IsPollingNeeded
= TRUE
;
664 "Enabled %u GPEs in block %02X to %02X", GpeEnabledCount
,
665 (UINT32
) GpeBlock
->BlockBaseNumber
,
666 (UINT32
) (GpeBlock
->BlockBaseNumber
+ (GpeBlock
->GpeCount
- 1))));
669 GpeBlock
->Initialized
= TRUE
;
670 return_ACPI_STATUS (AE_OK
);
673 #endif /* !ACPI_REDUCED_HARDWARE */