1ae115bc7Smrj /****************************************************************************** 2ae115bc7Smrj * 3ae115bc7Smrj * Module Name: evevent - Fixed Event handling and dispatch 4ae115bc7Smrj * 5ae115bc7Smrj *****************************************************************************/ 6ae115bc7Smrj 726f3cdf0SGordon Ross /* 8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp. 9ae115bc7Smrj * All rights reserved. 10ae115bc7Smrj * 1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without 1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions 1326f3cdf0SGordon Ross * are met: 1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright 1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer, 1626f3cdf0SGordon Ross * without modification. 1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below 1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon 2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further 2126f3cdf0SGordon Ross * binary redistribution. 2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names 2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived 2426f3cdf0SGordon Ross * from this software without specific prior written permission. 25ae115bc7Smrj * 2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the 2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free 2826f3cdf0SGordon Ross * Software Foundation. 29ae115bc7Smrj * 3026f3cdf0SGordon Ross * NO WARRANTY 3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES. 4226f3cdf0SGordon Ross */ 43ae115bc7Smrj 44ae115bc7Smrj #include "acpi.h" 45aa2aa9a6SDana Myers #include "accommon.h" 46ae115bc7Smrj #include "acevents.h" 47ae115bc7Smrj 48ae115bc7Smrj #define _COMPONENT ACPI_EVENTS 49ae115bc7Smrj ACPI_MODULE_NAME ("evevent") 50ae115bc7Smrj 51*385cc6b4SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ 52*385cc6b4SJerry Jelinek 53ae115bc7Smrj /* Local prototypes */ 54ae115bc7Smrj 55ae115bc7Smrj static ACPI_STATUS 56ae115bc7Smrj AcpiEvFixedEventInitialize ( 57ae115bc7Smrj void); 58ae115bc7Smrj 59ae115bc7Smrj static UINT32 60ae115bc7Smrj AcpiEvFixedEventDispatch ( 61ae115bc7Smrj UINT32 Event); 62ae115bc7Smrj 63ae115bc7Smrj 64ae115bc7Smrj /******************************************************************************* 65ae115bc7Smrj * 66ae115bc7Smrj * FUNCTION: AcpiEvInitializeEvents 67ae115bc7Smrj * 68ae115bc7Smrj * PARAMETERS: None 69ae115bc7Smrj * 70ae115bc7Smrj * RETURN: Status 71ae115bc7Smrj * 72ae115bc7Smrj * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE) 73ae115bc7Smrj * 74ae115bc7Smrj ******************************************************************************/ 75ae115bc7Smrj 76ae115bc7Smrj ACPI_STATUS 77ae115bc7Smrj AcpiEvInitializeEvents ( 78ae115bc7Smrj void) 79ae115bc7Smrj { 80ae115bc7Smrj ACPI_STATUS Status; 81ae115bc7Smrj 82ae115bc7Smrj 83ae115bc7Smrj ACPI_FUNCTION_TRACE (EvInitializeEvents); 84ae115bc7Smrj 85ae115bc7Smrj 86*385cc6b4SJerry Jelinek /* If Hardware Reduced flag is set, there are no fixed events */ 87*385cc6b4SJerry Jelinek 88*385cc6b4SJerry Jelinek if (AcpiGbl_ReducedHardware) 89*385cc6b4SJerry Jelinek { 90*385cc6b4SJerry Jelinek return_ACPI_STATUS (AE_OK); 91*385cc6b4SJerry Jelinek } 92*385cc6b4SJerry Jelinek 93ae115bc7Smrj /* 94ae115bc7Smrj * Initialize the Fixed and General Purpose Events. This is done prior to 95aa2aa9a6SDana Myers * enabling SCIs to prevent interrupts from occurring before the handlers 96aa2aa9a6SDana Myers * are installed. 97ae115bc7Smrj */ 98ae115bc7Smrj Status = AcpiEvFixedEventInitialize (); 99ae115bc7Smrj if (ACPI_FAILURE (Status)) 100ae115bc7Smrj { 101ae115bc7Smrj ACPI_EXCEPTION ((AE_INFO, Status, 102ae115bc7Smrj "Unable to initialize fixed events")); 103ae115bc7Smrj return_ACPI_STATUS (Status); 104ae115bc7Smrj } 105ae115bc7Smrj 106ae115bc7Smrj Status = AcpiEvGpeInitialize (); 107ae115bc7Smrj if (ACPI_FAILURE (Status)) 108ae115bc7Smrj { 109ae115bc7Smrj ACPI_EXCEPTION ((AE_INFO, Status, 110ae115bc7Smrj "Unable to initialize general purpose events")); 111ae115bc7Smrj return_ACPI_STATUS (Status); 112ae115bc7Smrj } 113ae115bc7Smrj 114ae115bc7Smrj return_ACPI_STATUS (Status); 115ae115bc7Smrj } 116ae115bc7Smrj 117ae115bc7Smrj 118ae115bc7Smrj /******************************************************************************* 119ae115bc7Smrj * 120ae115bc7Smrj * FUNCTION: AcpiEvInstallXruptHandlers 121ae115bc7Smrj * 122ae115bc7Smrj * PARAMETERS: None 123ae115bc7Smrj * 124ae115bc7Smrj * RETURN: Status 125ae115bc7Smrj * 126ae115bc7Smrj * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock 127ae115bc7Smrj * 128ae115bc7Smrj ******************************************************************************/ 129ae115bc7Smrj 130ae115bc7Smrj ACPI_STATUS 131ae115bc7Smrj AcpiEvInstallXruptHandlers ( 132ae115bc7Smrj void) 133ae115bc7Smrj { 134ae115bc7Smrj ACPI_STATUS Status; 135ae115bc7Smrj 136ae115bc7Smrj 137ae115bc7Smrj ACPI_FUNCTION_TRACE (EvInstallXruptHandlers); 138ae115bc7Smrj 139ae115bc7Smrj 140*385cc6b4SJerry Jelinek /* If Hardware Reduced flag is set, there is no ACPI h/w */ 141*385cc6b4SJerry Jelinek 142*385cc6b4SJerry Jelinek if (AcpiGbl_ReducedHardware) 143*385cc6b4SJerry Jelinek { 144*385cc6b4SJerry Jelinek return_ACPI_STATUS (AE_OK); 145*385cc6b4SJerry Jelinek } 146*385cc6b4SJerry Jelinek 147ae115bc7Smrj /* Install the SCI handler */ 148ae115bc7Smrj 149ae115bc7Smrj Status = AcpiEvInstallSciHandler (); 150ae115bc7Smrj if (ACPI_FAILURE (Status)) 151ae115bc7Smrj { 152ae115bc7Smrj ACPI_EXCEPTION ((AE_INFO, Status, 153ae115bc7Smrj "Unable to install System Control Interrupt handler")); 154ae115bc7Smrj return_ACPI_STATUS (Status); 155ae115bc7Smrj } 156ae115bc7Smrj 157ae115bc7Smrj /* Install the handler for the Global Lock */ 158ae115bc7Smrj 159ae115bc7Smrj Status = AcpiEvInitGlobalLockHandler (); 160ae115bc7Smrj if (ACPI_FAILURE (Status)) 161ae115bc7Smrj { 162ae115bc7Smrj ACPI_EXCEPTION ((AE_INFO, Status, 163ae115bc7Smrj "Unable to initialize Global Lock handler")); 164ae115bc7Smrj return_ACPI_STATUS (Status); 165ae115bc7Smrj } 166ae115bc7Smrj 167ae115bc7Smrj AcpiGbl_EventsInitialized = TRUE; 168ae115bc7Smrj return_ACPI_STATUS (Status); 169ae115bc7Smrj } 170ae115bc7Smrj 171ae115bc7Smrj 172ae115bc7Smrj /******************************************************************************* 173ae115bc7Smrj * 174ae115bc7Smrj * FUNCTION: AcpiEvFixedEventInitialize 175ae115bc7Smrj * 176ae115bc7Smrj * PARAMETERS: None 177ae115bc7Smrj * 178ae115bc7Smrj * RETURN: Status 179ae115bc7Smrj * 180aa2aa9a6SDana Myers * DESCRIPTION: Install the fixed event handlers and disable all fixed events. 181ae115bc7Smrj * 182ae115bc7Smrj ******************************************************************************/ 183ae115bc7Smrj 184ae115bc7Smrj static ACPI_STATUS 185ae115bc7Smrj AcpiEvFixedEventInitialize ( 186ae115bc7Smrj void) 187ae115bc7Smrj { 188db2bae30SDana Myers UINT32 i; 189ae115bc7Smrj ACPI_STATUS Status; 190ae115bc7Smrj 191ae115bc7Smrj 192ae115bc7Smrj /* 193aa2aa9a6SDana Myers * Initialize the structure that keeps track of fixed event handlers and 194aa2aa9a6SDana Myers * enable the fixed events. 195ae115bc7Smrj */ 196ae115bc7Smrj for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) 197ae115bc7Smrj { 198ae115bc7Smrj AcpiGbl_FixedEventHandlers[i].Handler = NULL; 199ae115bc7Smrj AcpiGbl_FixedEventHandlers[i].Context = NULL; 200ae115bc7Smrj 201aa2aa9a6SDana Myers /* Disable the fixed event */ 202ae115bc7Smrj 203ae115bc7Smrj if (AcpiGbl_FixedEventInfo[i].EnableRegisterId != 0xFF) 204ae115bc7Smrj { 205aa2aa9a6SDana Myers Status = AcpiWriteBitRegister ( 206aa2aa9a6SDana Myers AcpiGbl_FixedEventInfo[i].EnableRegisterId, 207aa2aa9a6SDana Myers ACPI_DISABLE_EVENT); 208ae115bc7Smrj if (ACPI_FAILURE (Status)) 209ae115bc7Smrj { 210ae115bc7Smrj return (Status); 211ae115bc7Smrj } 212ae115bc7Smrj } 213ae115bc7Smrj } 214ae115bc7Smrj 215ae115bc7Smrj return (AE_OK); 216ae115bc7Smrj } 217ae115bc7Smrj 218ae115bc7Smrj 219ae115bc7Smrj /******************************************************************************* 220ae115bc7Smrj * 221ae115bc7Smrj * FUNCTION: AcpiEvFixedEventDetect 222ae115bc7Smrj * 223ae115bc7Smrj * PARAMETERS: None 224ae115bc7Smrj * 225ae115bc7Smrj * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 226ae115bc7Smrj * 227ae115bc7Smrj * DESCRIPTION: Checks the PM status register for active fixed events 228ae115bc7Smrj * 229ae115bc7Smrj ******************************************************************************/ 230ae115bc7Smrj 231ae115bc7Smrj UINT32 232ae115bc7Smrj AcpiEvFixedEventDetect ( 233ae115bc7Smrj void) 234ae115bc7Smrj { 235ae115bc7Smrj UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED; 236ae115bc7Smrj UINT32 FixedStatus; 237ae115bc7Smrj UINT32 FixedEnable; 238db2bae30SDana Myers UINT32 i; 239ae115bc7Smrj 240ae115bc7Smrj 241ae115bc7Smrj ACPI_FUNCTION_NAME (EvFixedEventDetect); 242ae115bc7Smrj 243ae115bc7Smrj 244ae115bc7Smrj /* 245ae115bc7Smrj * Read the fixed feature status and enable registers, as all the cases 246ae115bc7Smrj * depend on their values. Ignore errors here. 247ae115bc7Smrj */ 248db2bae30SDana Myers (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_STATUS, &FixedStatus); 249db2bae30SDana Myers (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_ENABLE, &FixedEnable); 250ae115bc7Smrj 251ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS, 252ae115bc7Smrj "Fixed Event Block: Enable %08X Status %08X\n", 253ae115bc7Smrj FixedEnable, FixedStatus)); 254ae115bc7Smrj 255ae115bc7Smrj /* 256ae115bc7Smrj * Check for all possible Fixed Events and dispatch those that are active 257ae115bc7Smrj */ 258ae115bc7Smrj for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) 259ae115bc7Smrj { 260ae115bc7Smrj /* Both the status and enable bits must be on for this event */ 261ae115bc7Smrj 262ae115bc7Smrj if ((FixedStatus & AcpiGbl_FixedEventInfo[i].StatusBitMask) && 263ae115bc7Smrj (FixedEnable & AcpiGbl_FixedEventInfo[i].EnableBitMask)) 264ae115bc7Smrj { 26526f3cdf0SGordon Ross /* 26626f3cdf0SGordon Ross * Found an active (signalled) event. Invoke global event 26726f3cdf0SGordon Ross * handler if present. 26826f3cdf0SGordon Ross */ 269db2bae30SDana Myers AcpiFixedEventCount[i]++; 27026f3cdf0SGordon Ross if (AcpiGbl_GlobalEventHandler) 27126f3cdf0SGordon Ross { 27226f3cdf0SGordon Ross AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_FIXED, NULL, 27326f3cdf0SGordon Ross i, AcpiGbl_GlobalEventHandlerContext); 27426f3cdf0SGordon Ross } 27526f3cdf0SGordon Ross 276db2bae30SDana Myers IntStatus |= AcpiEvFixedEventDispatch (i); 277ae115bc7Smrj } 278ae115bc7Smrj } 279ae115bc7Smrj 280ae115bc7Smrj return (IntStatus); 281ae115bc7Smrj } 282ae115bc7Smrj 283ae115bc7Smrj 284ae115bc7Smrj /******************************************************************************* 285ae115bc7Smrj * 286ae115bc7Smrj * FUNCTION: AcpiEvFixedEventDispatch 287ae115bc7Smrj * 288ae115bc7Smrj * PARAMETERS: Event - Event type 289ae115bc7Smrj * 290ae115bc7Smrj * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 291ae115bc7Smrj * 292ae115bc7Smrj * DESCRIPTION: Clears the status bit for the requested event, calls the 293ae115bc7Smrj * handler that previously registered for the event. 294*385cc6b4SJerry Jelinek * NOTE: If there is no handler for the event, the event is 295*385cc6b4SJerry Jelinek * disabled to prevent further interrupts. 296ae115bc7Smrj * 297ae115bc7Smrj ******************************************************************************/ 298ae115bc7Smrj 299ae115bc7Smrj static UINT32 300ae115bc7Smrj AcpiEvFixedEventDispatch ( 301ae115bc7Smrj UINT32 Event) 302ae115bc7Smrj { 303ae115bc7Smrj 304ae115bc7Smrj ACPI_FUNCTION_ENTRY (); 305ae115bc7Smrj 306ae115bc7Smrj 307ae115bc7Smrj /* Clear the status bit */ 308ae115bc7Smrj 309aa2aa9a6SDana Myers (void) AcpiWriteBitRegister ( 310aa2aa9a6SDana Myers AcpiGbl_FixedEventInfo[Event].StatusRegisterId, 311aa2aa9a6SDana Myers ACPI_CLEAR_STATUS); 312ae115bc7Smrj 313ae115bc7Smrj /* 314*385cc6b4SJerry Jelinek * Make sure that a handler exists. If not, report an error 315*385cc6b4SJerry Jelinek * and disable the event to prevent further interrupts. 316ae115bc7Smrj */ 317*385cc6b4SJerry Jelinek if (!AcpiGbl_FixedEventHandlers[Event].Handler) 318ae115bc7Smrj { 319aa2aa9a6SDana Myers (void) AcpiWriteBitRegister ( 320aa2aa9a6SDana Myers AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 321aa2aa9a6SDana Myers ACPI_DISABLE_EVENT); 322ae115bc7Smrj 323ae115bc7Smrj ACPI_ERROR ((AE_INFO, 324*385cc6b4SJerry Jelinek "No installed handler for fixed event - %s (%u), disabling", 325*385cc6b4SJerry Jelinek AcpiUtGetEventName (Event), Event)); 326ae115bc7Smrj 327ae115bc7Smrj return (ACPI_INTERRUPT_NOT_HANDLED); 328ae115bc7Smrj } 329ae115bc7Smrj 330ae115bc7Smrj /* Invoke the Fixed Event handler */ 331ae115bc7Smrj 332ae115bc7Smrj return ((AcpiGbl_FixedEventHandlers[Event].Handler)( 333ae115bc7Smrj AcpiGbl_FixedEventHandlers[Event].Context)); 334ae115bc7Smrj } 335ae115bc7Smrj 336*385cc6b4SJerry Jelinek #endif /* !ACPI_REDUCED_HARDWARE */ 337