1 /******************************************************************************
3 * Module Name: evevent - Fixed and General Purpose Even handling and dispatch
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #include "acevents.h"
119 #include "acnamesp.h"
121 #define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evevent")
125 /*******************************************************************************
127 * FUNCTION: AcpiEvInitialize
133 * DESCRIPTION: Initialize global data structures for events.
135 ******************************************************************************/
144 ACPI_FUNCTION_TRACE ("EvInitialize");
147 /* Make sure we have ACPI tables */
151 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No ACPI tables present!\n"));
152 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
156 * Initialize the Fixed and General Purpose AcpiEvents prior. This is
157 * done prior to enabling SCIs to prevent interrupts from occuring
158 * before handers are installed.
160 Status = AcpiEvFixedEventInitialize ();
161 if (ACPI_FAILURE (Status))
163 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL,
164 "Unable to initialize fixed events, %s\n",
165 AcpiFormatException (Status)));
166 return_ACPI_STATUS (Status);
169 Status = AcpiEvGpeInitialize ();
170 if (ACPI_FAILURE (Status))
172 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL,
173 "Unable to initialize general purpose events, %s\n",
174 AcpiFormatException (Status)));
175 return_ACPI_STATUS (Status);
178 return_ACPI_STATUS (Status);
182 /*******************************************************************************
184 * FUNCTION: AcpiEvHandlerInitialize
190 * DESCRIPTION: Install handlers for the SCI, Global Lock, and GPEs.
192 ******************************************************************************/
195 AcpiEvHandlerInitialize (
201 ACPI_FUNCTION_TRACE ("EvHandlerInitialize");
204 /* Install the SCI handler */
206 Status = AcpiEvInstallSciHandler ();
207 if (ACPI_FAILURE (Status))
209 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL,
210 "Unable to install System Control Interrupt Handler, %s\n",
211 AcpiFormatException (Status)));
212 return_ACPI_STATUS (Status);
215 /* Install handlers for control method GPE handlers (_Lxx, _Exx) */
217 Status = AcpiEvInitGpeControlMethods ();
218 if (ACPI_FAILURE (Status))
220 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL,
221 "Unable to initialize GPE control methods, %s\n",
222 AcpiFormatException (Status)));
223 return_ACPI_STATUS (Status);
226 /* Install the handler for the Global Lock */
228 Status = AcpiEvInitGlobalLockHandler ();
229 if (ACPI_FAILURE (Status))
231 ACPI_DEBUG_PRINT ((ACPI_DB_FATAL,
232 "Unable to initialize Global Lock handler, %s\n",
233 AcpiFormatException (Status)));
234 return_ACPI_STATUS (Status);
237 AcpiGbl_EventsInitialized = TRUE;
238 return_ACPI_STATUS (Status);
242 /*******************************************************************************
244 * FUNCTION: AcpiEvFixedEventInitialize
250 * DESCRIPTION: Install the fixed event handlers and enable the fixed events.
252 ******************************************************************************/
255 AcpiEvFixedEventInitialize (
263 * Initialize the structure that keeps track of fixed event handlers
264 * and enable the fixed events.
266 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
268 AcpiGbl_FixedEventHandlers[i].Handler = NULL;
269 AcpiGbl_FixedEventHandlers[i].Context = NULL;
271 /* Enable the fixed event */
273 if (AcpiGbl_FixedEventInfo[i].EnableRegisterId != 0xFF)
275 Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[i].EnableRegisterId,
277 if (ACPI_FAILURE (Status))
288 /*******************************************************************************
290 * FUNCTION: AcpiEvFixedEventDetect
294 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
296 * DESCRIPTION: Checks the PM status register for fixed events
298 ******************************************************************************/
301 AcpiEvFixedEventDetect (
304 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
310 ACPI_FUNCTION_NAME ("EvFixedEventDetect");
314 * Read the fixed feature status and enable registers, as all the cases
315 * depend on their values. Ignore errors here.
317 (void) AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS, &FixedStatus);
318 (void) AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE, &FixedEnable);
320 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
321 "Fixed AcpiEvent Block: Enable %08X Status %08X\n",
322 FixedEnable, FixedStatus));
325 * Check for all possible Fixed Events and dispatch those that are active
327 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
329 /* Both the status and enable bits must be on for this event */
331 if ((FixedStatus & AcpiGbl_FixedEventInfo[i].StatusBitMask) &&
332 (FixedEnable & AcpiGbl_FixedEventInfo[i].EnableBitMask))
334 /* Found an active (signalled) event */
336 IntStatus |= AcpiEvFixedEventDispatch (i);
344 /*******************************************************************************
346 * FUNCTION: AcpiEvFixedEventDispatch
348 * PARAMETERS: Event - Event type
350 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
352 * DESCRIPTION: Clears the status bit for the requested event, calls the
353 * handler that previously registered for the event.
355 ******************************************************************************/
358 AcpiEvFixedEventDispatch (
363 ACPI_FUNCTION_ENTRY ();
366 /* Clear the status bit */
368 (void) AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
369 1, ACPI_MTX_DO_NOT_LOCK);
372 * Make sure we've got a handler. If not, report an error.
373 * The event is disabled to prevent further interrupts.
375 if (NULL == AcpiGbl_FixedEventHandlers[Event].Handler)
377 (void) AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
378 0, ACPI_MTX_DO_NOT_LOCK);
381 ("EvGpeDispatch: No installed handler for fixed event [%08X]\n",
384 return (ACPI_INTERRUPT_NOT_HANDLED);
387 /* Invoke the Fixed Event handler */
389 return ((AcpiGbl_FixedEventHandlers[Event].Handler)(
390 AcpiGbl_FixedEventHandlers[Event].Context));
394 /*******************************************************************************
396 * FUNCTION: AcpiEvGpeInitialize
402 * DESCRIPTION: Initialize the GPE data structures
404 ******************************************************************************/
407 AcpiEvGpeInitialize (void)
413 UINT32 GpeNumberIndex;
415 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
419 ACPI_FUNCTION_TRACE ("EvGpeInitialize");
423 * Initialize the GPE Block globals
425 * Why the GPE register block lengths divided by 2: From the ACPI Spec,
426 * section "General-Purpose Event Registers", we have:
428 * "Each register block contains two registers of equal length
429 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
430 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
431 * The length of the GPE1_STS and GPE1_EN registers is equal to
432 * half the GPE1_LEN. If a generic register block is not supported
433 * then its respective block pointer and block length values in the
434 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
435 * to be the same size."
437 AcpiGbl_GpeBlockInfo[0].AddressSpaceId = AcpiGbl_FADT->XGpe0Blk.AddressSpaceId;
438 AcpiGbl_GpeBlockInfo[1].AddressSpaceId = AcpiGbl_FADT->XGpe1Blk.AddressSpaceId;
440 AcpiGbl_GpeBlockInfo[0].RegisterCount = (UINT16) ACPI_DIV_16 (AcpiGbl_FADT->XGpe0Blk.RegisterBitWidth);
441 AcpiGbl_GpeBlockInfo[1].RegisterCount = (UINT16) ACPI_DIV_16 (AcpiGbl_FADT->XGpe1Blk.RegisterBitWidth);
443 AcpiGbl_GpeBlockInfo[0].BlockAddress = &AcpiGbl_FADT->XGpe0Blk;
444 AcpiGbl_GpeBlockInfo[1].BlockAddress = &AcpiGbl_FADT->XGpe1Blk;
446 AcpiGbl_GpeBlockInfo[0].BlockBaseNumber = 0;
447 AcpiGbl_GpeBlockInfo[1].BlockBaseNumber = AcpiGbl_FADT->Gpe1Base;
449 /* Warn and exit if there are no GPE registers */
451 AcpiGbl_GpeRegisterCount = AcpiGbl_GpeBlockInfo[0].RegisterCount +
452 AcpiGbl_GpeBlockInfo[1].RegisterCount;
453 if (!AcpiGbl_GpeRegisterCount)
455 ACPI_REPORT_WARNING (("There are no GPE blocks defined in the FADT\n"));
456 return_ACPI_STATUS (AE_OK);
460 * Determine the maximum GPE number for this machine.
461 * Note: both GPE0 and GPE1 are optional, and either can exist without
464 if (AcpiGbl_GpeBlockInfo[0].RegisterCount)
466 /* GPE block 0 exists */
468 AcpiGbl_GpeNumberMax = ACPI_MUL_8 (AcpiGbl_GpeBlockInfo[0].RegisterCount) - 1;
471 if (AcpiGbl_GpeBlockInfo[1].RegisterCount)
473 /* GPE block 1 exists */
475 /* Check for GPE0/GPE1 overlap (if both banks exist) */
477 if ((AcpiGbl_GpeBlockInfo[0].RegisterCount) &&
478 (AcpiGbl_GpeNumberMax >= AcpiGbl_FADT->Gpe1Base))
481 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d)\n",
482 AcpiGbl_GpeNumberMax, AcpiGbl_FADT->Gpe1Base,
483 AcpiGbl_FADT->Gpe1Base + (ACPI_MUL_8 (AcpiGbl_GpeBlockInfo[1].RegisterCount) - 1)));
484 return_ACPI_STATUS (AE_BAD_VALUE);
488 * GPE0 and GPE1 do not have to be contiguous in the GPE number space,
489 * But, GPE0 always starts at zero.
491 AcpiGbl_GpeNumberMax = AcpiGbl_FADT->Gpe1Base +
492 (ACPI_MUL_8 (AcpiGbl_GpeBlockInfo[1].RegisterCount) - 1);
495 /* Check for Max GPE number out-of-range */
497 if (AcpiGbl_GpeNumberMax > ACPI_GPE_MAX)
499 ACPI_REPORT_ERROR (("Maximum GPE number from FADT is too large: 0x%X\n",
500 AcpiGbl_GpeNumberMax));
501 return_ACPI_STATUS (AE_BAD_VALUE);
504 /* Allocate the GPE number-to-index translation table */
506 AcpiGbl_GpeNumberToIndex = ACPI_MEM_CALLOCATE (
507 sizeof (ACPI_GPE_INDEX_INFO) *
508 ((ACPI_SIZE) AcpiGbl_GpeNumberMax + 1));
509 if (!AcpiGbl_GpeNumberToIndex)
511 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
512 "Could not allocate the GpeNumberToIndex table\n"));
513 return_ACPI_STATUS (AE_NO_MEMORY);
516 /* Set the Gpe index table to GPE_INVALID */
518 ACPI_MEMSET (AcpiGbl_GpeNumberToIndex, (int) ACPI_GPE_INVALID,
519 sizeof (ACPI_GPE_INDEX_INFO) * ((ACPI_SIZE) AcpiGbl_GpeNumberMax + 1));
521 /* Allocate the GPE register information block */
523 AcpiGbl_GpeRegisterInfo = ACPI_MEM_CALLOCATE (
524 (ACPI_SIZE) AcpiGbl_GpeRegisterCount *
525 sizeof (ACPI_GPE_REGISTER_INFO));
526 if (!AcpiGbl_GpeRegisterInfo)
528 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
529 "Could not allocate the GpeRegisterInfo table\n"));
534 * Allocate the GPE dispatch handler block. There are eight distinct GPEs
535 * per register. Initialization to zeros is sufficient.
537 AcpiGbl_GpeNumberInfo = ACPI_MEM_CALLOCATE (
538 (ACPI_SIZE) ACPI_MUL_8 (AcpiGbl_GpeRegisterCount) *
539 sizeof (ACPI_GPE_NUMBER_INFO));
540 if (!AcpiGbl_GpeNumberInfo)
542 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the GpeNumberInfo table\n"));
547 * Initialize the GPE information and validation tables. A goal of these
548 * tables is to hide the fact that there are two separate GPE register sets
549 * in a given gpe hardware block, the status registers occupy the first half,
550 * and the enable registers occupy the second half. Another goal is to hide
551 * the fact that there may be multiple GPE hardware blocks.
556 for (GpeBlock = 0; GpeBlock < ACPI_MAX_GPE_BLOCKS; GpeBlock++)
558 for (i = 0; i < AcpiGbl_GpeBlockInfo[GpeBlock].RegisterCount; i++)
560 GpeRegisterInfo = &AcpiGbl_GpeRegisterInfo[GpeRegister];
562 /* Init the Register info for this entire GPE register (8 GPEs) */
564 GpeRegisterInfo->BaseGpeNumber = (UINT8) (AcpiGbl_GpeBlockInfo[GpeBlock].BlockBaseNumber
567 ACPI_STORE_ADDRESS (GpeRegisterInfo->StatusAddress.Address,
568 (ACPI_GET_ADDRESS (AcpiGbl_GpeBlockInfo[GpeBlock].BlockAddress->Address)
571 ACPI_STORE_ADDRESS (GpeRegisterInfo->EnableAddress.Address,
572 (ACPI_GET_ADDRESS (AcpiGbl_GpeBlockInfo[GpeBlock].BlockAddress->Address)
574 + AcpiGbl_GpeBlockInfo[GpeBlock].RegisterCount));
576 GpeRegisterInfo->StatusAddress.AddressSpaceId = AcpiGbl_GpeBlockInfo[GpeBlock].AddressSpaceId;
577 GpeRegisterInfo->EnableAddress.AddressSpaceId = AcpiGbl_GpeBlockInfo[GpeBlock].AddressSpaceId;
578 GpeRegisterInfo->StatusAddress.RegisterBitWidth = 8;
579 GpeRegisterInfo->EnableAddress.RegisterBitWidth = 8;
580 GpeRegisterInfo->StatusAddress.RegisterBitOffset = 8;
581 GpeRegisterInfo->EnableAddress.RegisterBitOffset = 8;
583 /* Init the Index mapping info for each GPE number within this register */
585 for (j = 0; j < 8; j++)
587 GpeNumber = GpeRegisterInfo->BaseGpeNumber + j;
588 AcpiGbl_GpeNumberToIndex[GpeNumber].NumberIndex = (UINT8) GpeNumberIndex;
590 AcpiGbl_GpeNumberInfo[GpeNumberIndex].BitMask = AcpiGbl_DecodeTo8bit[j];
595 * Clear the status/enable registers. Note that status registers
596 * are cleared by writing a '1', while enable registers are cleared
599 Status = AcpiHwLowLevelWrite (8, 0x00, &GpeRegisterInfo->EnableAddress, 0);
600 if (ACPI_FAILURE (Status))
602 return_ACPI_STATUS (Status);
605 Status = AcpiHwLowLevelWrite (8, 0xFF, &GpeRegisterInfo->StatusAddress, 0);
606 if (ACPI_FAILURE (Status))
608 return_ACPI_STATUS (Status);
616 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "GPE Block%d: %X registers at %8.8X%8.8X\n",
617 (INT32) GpeBlock, AcpiGbl_GpeBlockInfo[0].RegisterCount,
618 ACPI_HIDWORD (ACPI_GET_ADDRESS (AcpiGbl_GpeBlockInfo[GpeBlock].BlockAddress->Address)),
619 ACPI_LODWORD (ACPI_GET_ADDRESS (AcpiGbl_GpeBlockInfo[GpeBlock].BlockAddress->Address))));
621 ACPI_REPORT_INFO (("GPE Block%d defined as GPE%d to GPE%d\n",
623 (UINT32) AcpiGbl_GpeBlockInfo[GpeBlock].BlockBaseNumber,
624 (UINT32) (AcpiGbl_GpeBlockInfo[GpeBlock].BlockBaseNumber +
625 ((AcpiGbl_GpeBlockInfo[GpeBlock].RegisterCount * 8) -1))));
629 return_ACPI_STATUS (AE_OK);
635 ACPI_MEM_FREE (AcpiGbl_GpeRegisterInfo);
638 ACPI_MEM_FREE (AcpiGbl_GpeNumberToIndex);
639 return_ACPI_STATUS (AE_NO_MEMORY);
643 /*******************************************************************************
645 * FUNCTION: AcpiEvSaveMethodInfo
651 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
652 * control method under the _GPE portion of the namespace.
653 * Extract the name and GPE type from the object, saving this
654 * information for quick lookup during GPE dispatch
656 * The name of each GPE control method is of the form:
659 * L - means that the GPE is level triggered
660 * E - means that the GPE is edge triggered
661 * nn - is the GPE number [in HEX]
663 ******************************************************************************/
666 AcpiEvSaveMethodInfo (
667 ACPI_HANDLE ObjHandle,
673 UINT32 GpeNumberIndex;
674 NATIVE_CHAR Name[ACPI_NAME_SIZE + 1];
679 ACPI_FUNCTION_NAME ("EvSaveMethodInfo");
682 /* Extract the name from the object and convert to a string */
684 ACPI_MOVE_UNALIGNED32_TO_32 (Name,
685 &((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Integer);
686 Name[ACPI_NAME_SIZE] = 0;
689 * Edge/Level determination is based on the 2nd character of the method name
694 Type = ACPI_EVENT_LEVEL_TRIGGERED;
698 Type = ACPI_EVENT_EDGE_TRIGGERED;
702 /* Unknown method type, just ignore it! */
704 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
705 "Unknown GPE method type: %s (name not of form _Lnn or _Enn)\n",
710 /* Convert the last two characters of the name to the GPE Number */
712 GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
713 if (GpeNumber == ACPI_UINT32_MAX)
715 /* Conversion failed; invalid method, just ignore it */
717 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
718 "Could not extract GPE number from name: %s (name not of form _Lnn or _Enn)\n",
723 /* Get GPE index and ensure that we have a valid GPE number */
725 GpeNumberIndex = AcpiEvGetGpeNumberIndex (GpeNumber);
726 if (GpeNumberIndex == ACPI_GPE_INVALID)
728 /* Not valid, all we can do here is ignore it */
734 * Now we can add this information to the GpeInfo block
735 * for use during dispatch of this GPE.
737 AcpiGbl_GpeNumberInfo [GpeNumberIndex].Type = Type;
738 AcpiGbl_GpeNumberInfo [GpeNumberIndex].MethodHandle = ObjHandle;
741 * Enable the GPE (SCIs should be disabled at this point)
743 Status = AcpiHwEnableGpe (GpeNumber);
744 if (ACPI_FAILURE (Status))
749 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Registered GPE method %s as GPE number %X\n",
755 /*******************************************************************************
757 * FUNCTION: AcpiEvInitGpeControlMethods
763 * DESCRIPTION: Obtain the control methods associated with the GPEs.
764 * NOTE: Must be called AFTER namespace initialization!
766 ******************************************************************************/
769 AcpiEvInitGpeControlMethods (void)
774 ACPI_FUNCTION_TRACE ("EvInitGpeControlMethods");
777 /* Get a permanent handle to the _GPE object */
779 Status = AcpiGetHandle (NULL, "\\_GPE", &AcpiGbl_GpeObjHandle);
780 if (ACPI_FAILURE (Status))
782 return_ACPI_STATUS (Status);
785 /* Traverse the namespace under \_GPE to find all methods there */
787 Status = AcpiWalkNamespace (ACPI_TYPE_METHOD, AcpiGbl_GpeObjHandle,
788 ACPI_UINT32_MAX, AcpiEvSaveMethodInfo,
791 return_ACPI_STATUS (Status);
795 /*******************************************************************************
797 * FUNCTION: AcpiEvGpeDetect
801 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
803 * DESCRIPTION: Detect if any GP events have occurred. This function is
804 * executed at interrupt level.
806 ******************************************************************************/
809 AcpiEvGpeDetect (void)
811 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
814 UINT8 EnabledStatusByte;
816 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
821 ACPI_FUNCTION_NAME ("EvGpeDetect");
825 * Read all of the 8-bit GPE status and enable registers
826 * in both of the register blocks, saving all of it.
827 * Find all currently active GP events.
829 for (i = 0; i < AcpiGbl_GpeRegisterCount; i++)
831 GpeRegisterInfo = &AcpiGbl_GpeRegisterInfo[i];
833 Status = AcpiHwLowLevelRead (8, &InValue, &GpeRegisterInfo->StatusAddress, 0);
834 GpeRegisterInfo->Status = (UINT8) InValue;
835 if (ACPI_FAILURE (Status))
837 return (ACPI_INTERRUPT_NOT_HANDLED);
840 Status = AcpiHwLowLevelRead (8, &InValue, &GpeRegisterInfo->EnableAddress, 0);
841 GpeRegisterInfo->Enable = (UINT8) InValue;
842 if (ACPI_FAILURE (Status))
844 return (ACPI_INTERRUPT_NOT_HANDLED);
847 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
848 "GPE block at %8.8X%8.8X - Values: Enable %02X Status %02X\n",
849 ACPI_HIDWORD (ACPI_GET_ADDRESS (GpeRegisterInfo->EnableAddress.Address)),
850 ACPI_LODWORD (ACPI_GET_ADDRESS (GpeRegisterInfo->EnableAddress.Address)),
851 GpeRegisterInfo->Enable,
852 GpeRegisterInfo->Status));
854 /* First check if there is anything active at all in this register */
856 EnabledStatusByte = (UINT8) (GpeRegisterInfo->Status &
857 GpeRegisterInfo->Enable);
858 if (!EnabledStatusByte)
860 /* No active GPEs in this register, move on */
865 /* Now look at the individual GPEs in this byte register */
867 for (j = 0, BitMask = 1; j < 8; j++, BitMask <<= 1)
869 /* Examine one GPE bit */
871 if (EnabledStatusByte & BitMask)
874 * Found an active GPE. Dispatch the event to a handler
877 IntStatus |= AcpiEvGpeDispatch (
878 GpeRegisterInfo->BaseGpeNumber + j);
887 /*******************************************************************************
889 * FUNCTION: AcpiEvAsynchExecuteGpeMethod
891 * PARAMETERS: GpeNumber - The 0-based GPE number
895 * DESCRIPTION: Perform the actual execution of a GPE control method. This
896 * function is called from an invocation of AcpiOsQueueForExecution
897 * (and therefore does NOT execute at interrupt level) so that
898 * the control method itself is not executed in the context of
899 * the SCI interrupt handler.
901 ******************************************************************************/
903 static void ACPI_SYSTEM_XFACE
904 AcpiEvAsynchExecuteGpeMethod (
907 UINT32 GpeNumber = (UINT32) ACPI_TO_INTEGER (Context);
908 UINT32 GpeNumberIndex;
909 ACPI_GPE_NUMBER_INFO GpeInfo;
913 ACPI_FUNCTION_TRACE ("EvAsynchExecuteGpeMethod");
916 GpeNumberIndex = AcpiEvGetGpeNumberIndex (GpeNumber);
917 if (GpeNumberIndex == ACPI_GPE_INVALID)
923 * Take a snapshot of the GPE info for this level - we copy the
924 * info to prevent a race condition with RemoveHandler.
926 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
927 if (ACPI_FAILURE (Status))
932 GpeInfo = AcpiGbl_GpeNumberInfo [GpeNumberIndex];
933 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
934 if (ACPI_FAILURE (Status))
939 if (GpeInfo.MethodHandle)
942 * Invoke the GPE Method (_Lxx, _Exx):
943 * (Evaluate the _Lxx/_Exx control method that corresponds to this GPE.)
945 Status = AcpiNsEvaluateByHandle (GpeInfo.MethodHandle, NULL, NULL);
946 if (ACPI_FAILURE (Status))
948 ACPI_REPORT_ERROR (("%s while evaluating GPE%X method\n",
949 AcpiFormatException (Status), GpeNumber));
953 if (GpeInfo.Type & ACPI_EVENT_LEVEL_TRIGGERED)
956 * GPE is level-triggered, we clear the GPE status bit after handling
959 Status = AcpiHwClearGpe (GpeNumber);
960 if (ACPI_FAILURE (Status))
969 (void) AcpiHwEnableGpe (GpeNumber);
974 /*******************************************************************************
976 * FUNCTION: AcpiEvGpeDispatch
978 * PARAMETERS: GpeNumber - The 0-based GPE number
980 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
982 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
983 * or method (e.g. _Lxx/_Exx) handler. This function executes
984 * at interrupt level.
986 ******************************************************************************/
992 UINT32 GpeNumberIndex;
993 ACPI_GPE_NUMBER_INFO *GpeInfo;
997 ACPI_FUNCTION_TRACE ("EvGpeDispatch");
1000 GpeNumberIndex = AcpiEvGetGpeNumberIndex (GpeNumber);
1001 if (GpeNumberIndex == ACPI_GPE_INVALID)
1003 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "GPE[%X] is not a valid event\n", GpeNumber));
1004 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
1008 * We don't have to worry about mutex on GpeInfo because we are
1009 * executing at interrupt level.
1011 GpeInfo = &AcpiGbl_GpeNumberInfo [GpeNumberIndex];
1014 * If edge-triggered, clear the GPE status bit now. Note that
1015 * level-triggered events are cleared after the GPE is serviced.
1017 if (GpeInfo->Type & ACPI_EVENT_EDGE_TRIGGERED)
1019 Status = AcpiHwClearGpe (GpeNumber);
1020 if (ACPI_FAILURE (Status))
1022 ACPI_REPORT_ERROR (("AcpiEvGpeDispatch: Unable to clear GPE[%X]\n", GpeNumber));
1023 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
1028 * Dispatch the GPE to either an installed handler, or the control
1029 * method associated with this GPE (_Lxx or _Exx).
1030 * If a handler exists, we invoke it and do not attempt to run the method.
1031 * If there is neither a handler nor a method, we disable the level to
1032 * prevent further events from coming in here.
1034 if (GpeInfo->Handler)
1036 /* Invoke the installed handler (at interrupt level) */
1038 GpeInfo->Handler (GpeInfo->Context);
1040 else if (GpeInfo->MethodHandle)
1043 * Disable GPE, so it doesn't keep firing before the method has a
1046 Status = AcpiHwDisableGpe (GpeNumber);
1047 if (ACPI_FAILURE (Status))
1049 ACPI_REPORT_ERROR (("AcpiEvGpeDispatch: Unable to disable GPE[%X]\n", GpeNumber));
1050 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
1054 * Execute the method associated with the GPE.
1056 if (ACPI_FAILURE (AcpiOsQueueForExecution (OSD_PRIORITY_GPE,
1057 AcpiEvAsynchExecuteGpeMethod,
1058 ACPI_TO_POINTER (GpeNumber))))
1060 ACPI_REPORT_ERROR (("AcpiEvGpeDispatch: Unable to queue handler for GPE[%X], event is disabled\n", GpeNumber));
1065 /* No handler or method to run! */
1067 ACPI_REPORT_ERROR (("AcpiEvGpeDispatch: No handler or method for GPE[%X], disabling event\n", GpeNumber));
1070 * Disable the GPE. The GPE will remain disabled until the ACPI
1071 * Core Subsystem is restarted, or the handler is reinstalled.
1073 Status = AcpiHwDisableGpe (GpeNumber);
1074 if (ACPI_FAILURE (Status))
1076 ACPI_REPORT_ERROR (("AcpiEvGpeDispatch: Unable to disable GPE[%X]\n", GpeNumber));
1077 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
1082 * It is now safe to clear level-triggered evnets.
1084 if (GpeInfo->Type & ACPI_EVENT_LEVEL_TRIGGERED)
1086 Status = AcpiHwClearGpe (GpeNumber);
1087 if (ACPI_FAILURE (Status))
1089 ACPI_REPORT_ERROR (("AcpiEvGpeDispatch: Unable to clear GPE[%X]\n", GpeNumber));
1090 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
1094 return_VALUE (ACPI_INTERRUPT_HANDLED);