13446Smrj /******************************************************************************
23446Smrj *
33446Smrj * Module Name: evevent - Fixed Event handling and dispatch
43446Smrj *
53446Smrj *****************************************************************************/
63446Smrj
73446Smrj /******************************************************************************
83446Smrj *
93446Smrj * 1. Copyright Notice
103446Smrj *
11*9980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj * All rights reserved.
133446Smrj *
143446Smrj * 2. License
153446Smrj *
163446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj * rights. You may have additional license terms from the party that provided
183446Smrj * you this software, covering your right to use that party's intellectual
193446Smrj * property rights.
203446Smrj *
213446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj * copy of the source code appearing in this file ("Covered Code") an
233446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj * make derivatives, distribute, use and display any portion of the Covered
263446Smrj * Code in any form, with the right to sublicense such rights; and
273446Smrj *
283446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj * license (with the right to sublicense), under only those claims of Intel
303446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj * solely to the minimum extent necessary to exercise the above copyright
333446Smrj * license, and in no event shall the patent license extend to any additions
343446Smrj * to or modifications of the Original Intel Code. No other license or right
353446Smrj * is granted directly or by implication, estoppel or otherwise;
363446Smrj *
373446Smrj * The above copyright and patent license is granted only if the following
383446Smrj * conditions are met:
393446Smrj *
403446Smrj * 3. Conditions
413446Smrj *
423446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj * Redistribution of source code of any substantial portion of the Covered
443446Smrj * Code or modification with rights to further distribute source must include
453446Smrj * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj * and the following Disclaimer and Export Compliance provision. In addition,
473446Smrj * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj * contain a file documenting the changes Licensee made to create that Covered
493446Smrj * Code and the date of any change. Licensee must include in that file the
503446Smrj * documentation of any changes made by any predecessor Licensee. Licensee
513446Smrj * must include a prominent statement that the modification is derived,
523446Smrj * directly or indirectly, from Original Intel Code.
533446Smrj *
543446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj * Redistribution of source code of any substantial portion of the Covered
563446Smrj * Code or modification without rights to further distribute source must
573446Smrj * include the following Disclaimer and Export Compliance provision in the
583446Smrj * documentation and/or other materials provided with distribution. In
593446Smrj * addition, Licensee may not authorize further sublicense of source of any
603446Smrj * portion of the Covered Code, and must include terms to the effect that the
613446Smrj * license from Licensee to its licensee is limited to the intellectual
623446Smrj * property embodied in the software Licensee provides to its licensee, and
633446Smrj * not to intellectual property embodied in modifications its licensee may
643446Smrj * make.
653446Smrj *
663446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj * substantial portion of the Covered Code or modification must reproduce the
683446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj * provision in the documentation and/or other materials provided with the
703446Smrj * distribution.
713446Smrj *
723446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj * Intel Code.
743446Smrj *
753446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj * other dealings in products derived from or relating to the Covered Code
783446Smrj * without prior written authorization from Intel.
793446Smrj *
803446Smrj * 4. Disclaimer and Export Compliance
813446Smrj *
823446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
853446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
863446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj * PARTICULAR PURPOSE.
893446Smrj *
903446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
963446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj * LIMITED REMEDY.
983446Smrj *
993446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj * software or system incorporating such software without first obtaining any
1013446Smrj * required license or other approval from the U. S. Department of Commerce or
1023446Smrj * any other agency or department of the United States Government. In the
1033446Smrj * event Licensee exports any such software from the United States or
1043446Smrj * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj * ensure that the distribution and export/re-export of the software is in
1063446Smrj * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj * software, or service, directly or indirectly, to any country for which the
1103446Smrj * United States government or any agency thereof requires an export license,
1113446Smrj * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj * such license, approval or letter.
1133446Smrj *
1143446Smrj *****************************************************************************/
1153446Smrj
1163446Smrj #include "acpi.h"
117*9980SDana.Myers@Sun.COM #include "accommon.h"
1183446Smrj #include "acevents.h"
1193446Smrj
1203446Smrj #define _COMPONENT ACPI_EVENTS
1213446Smrj ACPI_MODULE_NAME ("evevent")
1223446Smrj
1233446Smrj /* Local prototypes */
1243446Smrj
1253446Smrj static ACPI_STATUS
1263446Smrj AcpiEvFixedEventInitialize (
1273446Smrj void);
1283446Smrj
1293446Smrj static UINT32
1303446Smrj AcpiEvFixedEventDispatch (
1313446Smrj UINT32 Event);
1323446Smrj
1333446Smrj
1343446Smrj /*******************************************************************************
1353446Smrj *
1363446Smrj * FUNCTION: AcpiEvInitializeEvents
1373446Smrj *
1383446Smrj * PARAMETERS: None
1393446Smrj *
1403446Smrj * RETURN: Status
1413446Smrj *
1423446Smrj * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
1433446Smrj *
1443446Smrj ******************************************************************************/
1453446Smrj
1463446Smrj ACPI_STATUS
AcpiEvInitializeEvents(void)1473446Smrj AcpiEvInitializeEvents (
1483446Smrj void)
1493446Smrj {
1503446Smrj ACPI_STATUS Status;
1513446Smrj
1523446Smrj
1533446Smrj ACPI_FUNCTION_TRACE (EvInitializeEvents);
1543446Smrj
1553446Smrj
1563446Smrj /*
1573446Smrj * Initialize the Fixed and General Purpose Events. This is done prior to
158*9980SDana.Myers@Sun.COM * enabling SCIs to prevent interrupts from occurring before the handlers
159*9980SDana.Myers@Sun.COM * are installed.
1603446Smrj */
1613446Smrj Status = AcpiEvFixedEventInitialize ();
1623446Smrj if (ACPI_FAILURE (Status))
1633446Smrj {
1643446Smrj ACPI_EXCEPTION ((AE_INFO, Status,
1653446Smrj "Unable to initialize fixed events"));
1663446Smrj return_ACPI_STATUS (Status);
1673446Smrj }
1683446Smrj
1693446Smrj Status = AcpiEvGpeInitialize ();
1703446Smrj if (ACPI_FAILURE (Status))
1713446Smrj {
1723446Smrj ACPI_EXCEPTION ((AE_INFO, Status,
1733446Smrj "Unable to initialize general purpose events"));
1743446Smrj return_ACPI_STATUS (Status);
1753446Smrj }
1763446Smrj
1773446Smrj return_ACPI_STATUS (Status);
1783446Smrj }
1793446Smrj
1803446Smrj
1813446Smrj /*******************************************************************************
1823446Smrj *
1833446Smrj * FUNCTION: AcpiEvInstallFadtGpes
1843446Smrj *
1853446Smrj * PARAMETERS: None
1863446Smrj *
1873446Smrj * RETURN: Status
1883446Smrj *
1893446Smrj * DESCRIPTION: Completes initialization of the FADT-defined GPE blocks
1903446Smrj * (0 and 1). This causes the _PRW methods to be run, so the HW
1913446Smrj * must be fully initialized at this point, including global lock
1923446Smrj * support.
1933446Smrj *
1943446Smrj ******************************************************************************/
1953446Smrj
1963446Smrj ACPI_STATUS
AcpiEvInstallFadtGpes(void)1973446Smrj AcpiEvInstallFadtGpes (
1983446Smrj void)
1993446Smrj {
2003446Smrj ACPI_STATUS Status;
2013446Smrj
2023446Smrj
2033446Smrj ACPI_FUNCTION_TRACE (EvInstallFadtGpes);
2043446Smrj
2053446Smrj
2063446Smrj /* Namespace must be locked */
2073446Smrj
2083446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
2093446Smrj if (ACPI_FAILURE (Status))
2103446Smrj {
2113446Smrj return (Status);
2123446Smrj }
2133446Smrj
2143446Smrj /* FADT GPE Block 0 */
2153446Smrj
2163446Smrj (void) AcpiEvInitializeGpeBlock (
2173446Smrj AcpiGbl_FadtGpeDevice, AcpiGbl_GpeFadtBlocks[0]);
2183446Smrj
2193446Smrj /* FADT GPE Block 1 */
2203446Smrj
2213446Smrj (void) AcpiEvInitializeGpeBlock (
2223446Smrj AcpiGbl_FadtGpeDevice, AcpiGbl_GpeFadtBlocks[1]);
2233446Smrj
2243446Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
2253446Smrj return_ACPI_STATUS (AE_OK);
2263446Smrj }
2273446Smrj
2283446Smrj
2293446Smrj /*******************************************************************************
2303446Smrj *
2313446Smrj * FUNCTION: AcpiEvInstallXruptHandlers
2323446Smrj *
2333446Smrj * PARAMETERS: None
2343446Smrj *
2353446Smrj * RETURN: Status
2363446Smrj *
2373446Smrj * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
2383446Smrj *
2393446Smrj ******************************************************************************/
2403446Smrj
2413446Smrj ACPI_STATUS
AcpiEvInstallXruptHandlers(void)2423446Smrj AcpiEvInstallXruptHandlers (
2433446Smrj void)
2443446Smrj {
2453446Smrj ACPI_STATUS Status;
2463446Smrj
2473446Smrj
2483446Smrj ACPI_FUNCTION_TRACE (EvInstallXruptHandlers);
2493446Smrj
2503446Smrj
2513446Smrj /* Install the SCI handler */
2523446Smrj
2533446Smrj Status = AcpiEvInstallSciHandler ();
2543446Smrj if (ACPI_FAILURE (Status))
2553446Smrj {
2563446Smrj ACPI_EXCEPTION ((AE_INFO, Status,
2573446Smrj "Unable to install System Control Interrupt handler"));
2583446Smrj return_ACPI_STATUS (Status);
2593446Smrj }
2603446Smrj
2613446Smrj /* Install the handler for the Global Lock */
2623446Smrj
2633446Smrj Status = AcpiEvInitGlobalLockHandler ();
2643446Smrj if (ACPI_FAILURE (Status))
2653446Smrj {
2663446Smrj ACPI_EXCEPTION ((AE_INFO, Status,
2673446Smrj "Unable to initialize Global Lock handler"));
2683446Smrj return_ACPI_STATUS (Status);
2693446Smrj }
2703446Smrj
2713446Smrj AcpiGbl_EventsInitialized = TRUE;
2723446Smrj return_ACPI_STATUS (Status);
2733446Smrj }
2743446Smrj
2753446Smrj
2763446Smrj /*******************************************************************************
2773446Smrj *
2783446Smrj * FUNCTION: AcpiEvFixedEventInitialize
2793446Smrj *
2803446Smrj * PARAMETERS: None
2813446Smrj *
2823446Smrj * RETURN: Status
2833446Smrj *
284*9980SDana.Myers@Sun.COM * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
2853446Smrj *
2863446Smrj ******************************************************************************/
2873446Smrj
2883446Smrj static ACPI_STATUS
AcpiEvFixedEventInitialize(void)2893446Smrj AcpiEvFixedEventInitialize (
2903446Smrj void)
2913446Smrj {
2927851SDana.Myers@Sun.COM UINT32 i;
2933446Smrj ACPI_STATUS Status;
2943446Smrj
2953446Smrj
2963446Smrj /*
297*9980SDana.Myers@Sun.COM * Initialize the structure that keeps track of fixed event handlers and
298*9980SDana.Myers@Sun.COM * enable the fixed events.
2993446Smrj */
3003446Smrj for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
3013446Smrj {
3023446Smrj AcpiGbl_FixedEventHandlers[i].Handler = NULL;
3033446Smrj AcpiGbl_FixedEventHandlers[i].Context = NULL;
3043446Smrj
305*9980SDana.Myers@Sun.COM /* Disable the fixed event */
3063446Smrj
3073446Smrj if (AcpiGbl_FixedEventInfo[i].EnableRegisterId != 0xFF)
3083446Smrj {
309*9980SDana.Myers@Sun.COM Status = AcpiWriteBitRegister (
310*9980SDana.Myers@Sun.COM AcpiGbl_FixedEventInfo[i].EnableRegisterId,
311*9980SDana.Myers@Sun.COM ACPI_DISABLE_EVENT);
3123446Smrj if (ACPI_FAILURE (Status))
3133446Smrj {
3143446Smrj return (Status);
3153446Smrj }
3163446Smrj }
3173446Smrj }
3183446Smrj
3193446Smrj return (AE_OK);
3203446Smrj }
3213446Smrj
3223446Smrj
3233446Smrj /*******************************************************************************
3243446Smrj *
3253446Smrj * FUNCTION: AcpiEvFixedEventDetect
3263446Smrj *
3273446Smrj * PARAMETERS: None
3283446Smrj *
3293446Smrj * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
3303446Smrj *
3313446Smrj * DESCRIPTION: Checks the PM status register for active fixed events
3323446Smrj *
3333446Smrj ******************************************************************************/
3343446Smrj
3353446Smrj UINT32
AcpiEvFixedEventDetect(void)3363446Smrj AcpiEvFixedEventDetect (
3373446Smrj void)
3383446Smrj {
3393446Smrj UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
3403446Smrj UINT32 FixedStatus;
3413446Smrj UINT32 FixedEnable;
3427851SDana.Myers@Sun.COM UINT32 i;
3433446Smrj
3443446Smrj
3453446Smrj ACPI_FUNCTION_NAME (EvFixedEventDetect);
3463446Smrj
3473446Smrj
3483446Smrj /*
3493446Smrj * Read the fixed feature status and enable registers, as all the cases
350*9980SDana.Myers@Sun.COM * depend on their values. Ignore errors here.
3513446Smrj */
3527851SDana.Myers@Sun.COM (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_STATUS, &FixedStatus);
3537851SDana.Myers@Sun.COM (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_ENABLE, &FixedEnable);
3543446Smrj
3553446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
3563446Smrj "Fixed Event Block: Enable %08X Status %08X\n",
3573446Smrj FixedEnable, FixedStatus));
3583446Smrj
3593446Smrj /*
3603446Smrj * Check for all possible Fixed Events and dispatch those that are active
3613446Smrj */
3623446Smrj for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
3633446Smrj {
3643446Smrj /* Both the status and enable bits must be on for this event */
3653446Smrj
3663446Smrj if ((FixedStatus & AcpiGbl_FixedEventInfo[i].StatusBitMask) &&
3673446Smrj (FixedEnable & AcpiGbl_FixedEventInfo[i].EnableBitMask))
3683446Smrj {
3693446Smrj /* Found an active (signalled) event */
3703446Smrj
3717851SDana.Myers@Sun.COM AcpiFixedEventCount[i]++;
3727851SDana.Myers@Sun.COM IntStatus |= AcpiEvFixedEventDispatch (i);
3733446Smrj }
3743446Smrj }
3753446Smrj
3763446Smrj return (IntStatus);
3773446Smrj }
3783446Smrj
3793446Smrj
3803446Smrj /*******************************************************************************
3813446Smrj *
3823446Smrj * FUNCTION: AcpiEvFixedEventDispatch
3833446Smrj *
3843446Smrj * PARAMETERS: Event - Event type
3853446Smrj *
3863446Smrj * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
3873446Smrj *
3883446Smrj * DESCRIPTION: Clears the status bit for the requested event, calls the
3893446Smrj * handler that previously registered for the event.
3903446Smrj *
3913446Smrj ******************************************************************************/
3923446Smrj
3933446Smrj static UINT32
AcpiEvFixedEventDispatch(UINT32 Event)3943446Smrj AcpiEvFixedEventDispatch (
3953446Smrj UINT32 Event)
3963446Smrj {
3973446Smrj
3983446Smrj ACPI_FUNCTION_ENTRY ();
3993446Smrj
4003446Smrj
4013446Smrj /* Clear the status bit */
4023446Smrj
403*9980SDana.Myers@Sun.COM (void) AcpiWriteBitRegister (
404*9980SDana.Myers@Sun.COM AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
405*9980SDana.Myers@Sun.COM ACPI_CLEAR_STATUS);
4063446Smrj
4073446Smrj /*
408*9980SDana.Myers@Sun.COM * Make sure we've got a handler. If not, report an error. The event is
409*9980SDana.Myers@Sun.COM * disabled to prevent further interrupts.
4103446Smrj */
4113446Smrj if (NULL == AcpiGbl_FixedEventHandlers[Event].Handler)
4123446Smrj {
413*9980SDana.Myers@Sun.COM (void) AcpiWriteBitRegister (
414*9980SDana.Myers@Sun.COM AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
415*9980SDana.Myers@Sun.COM ACPI_DISABLE_EVENT);
4163446Smrj
4173446Smrj ACPI_ERROR ((AE_INFO,
4183446Smrj "No installed handler for fixed event [%08X]",
4193446Smrj Event));
4203446Smrj
4213446Smrj return (ACPI_INTERRUPT_NOT_HANDLED);
4223446Smrj }
4233446Smrj
4243446Smrj /* Invoke the Fixed Event handler */
4253446Smrj
4263446Smrj return ((AcpiGbl_FixedEventHandlers[Event].Handler)(
427*9980SDana.Myers@Sun.COM AcpiGbl_FixedEventHandlers[Event].Context));
4283446Smrj }
4293446Smrj
4303446Smrj
431