Path: blob/main/sys/contrib/dev/acpica/components/events/evsci.c
48525 views
/*******************************************************************************1*2* Module Name: evsci - System Control Interrupt configuration and3* legacy to ACPI mode state transition functions4*5******************************************************************************/67/******************************************************************************8*9* 1. Copyright Notice10*11* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.12* All rights reserved.13*14* 2. License15*16* 2.1. This is your license from Intel Corp. under its intellectual property17* rights. You may have additional license terms from the party that provided18* you this software, covering your right to use that party's intellectual19* property rights.20*21* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a22* copy of the source code appearing in this file ("Covered Code") an23* irrevocable, perpetual, worldwide license under Intel's copyrights in the24* base code distributed originally by Intel ("Original Intel Code") to copy,25* make derivatives, distribute, use and display any portion of the Covered26* Code in any form, with the right to sublicense such rights; and27*28* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent29* license (with the right to sublicense), under only those claims of Intel30* 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 thereof32* solely to the minimum extent necessary to exercise the above copyright33* license, and in no event shall the patent license extend to any additions34* to or modifications of the Original Intel Code. No other license or right35* is granted directly or by implication, estoppel or otherwise;36*37* The above copyright and patent license is granted only if the following38* conditions are met:39*40* 3. Conditions41*42* 3.1. Redistribution of Source with Rights to Further Distribute Source.43* Redistribution of source code of any substantial portion of the Covered44* Code or modification with rights to further distribute source must include45* 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 to48* contain a file documenting the changes Licensee made to create that Covered49* Code and the date of any change. Licensee must include in that file the50* documentation of any changes made by any predecessor Licensee. Licensee51* must include a prominent statement that the modification is derived,52* directly or indirectly, from Original Intel Code.53*54* 3.2. Redistribution of Source with no Rights to Further Distribute Source.55* Redistribution of source code of any substantial portion of the Covered56* Code or modification without rights to further distribute source must57* include the following Disclaimer and Export Compliance provision in the58* documentation and/or other materials provided with distribution. In59* addition, Licensee may not authorize further sublicense of source of any60* portion of the Covered Code, and must include terms to the effect that the61* license from Licensee to its licensee is limited to the intellectual62* property embodied in the software Licensee provides to its licensee, and63* not to intellectual property embodied in modifications its licensee may6465* make.66*67* 3.3. Redistribution of Executable. Redistribution in executable form of any68* substantial portion of the Covered Code or modification must reproduce the69* above Copyright Notice, and the following Disclaimer and Export Compliance70* provision in the documentation and/or other materials provided with the71* distribution.72*73* 3.4. Intel retains all right, title, and interest in and to the Original74* Intel Code.75*76* 3.5. Neither the name Intel nor any other trademark owned or controlled by77* Intel shall be used in advertising or otherwise to promote the sale, use or78* other dealings in products derived from or relating to the Covered Code79* without prior written authorization from Intel.80*81* 4. Disclaimer and Export Compliance82*83* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED84* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE85* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,86* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY87* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY88* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A89* PARTICULAR PURPOSE.90*91* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES92* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR93* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,94* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY95* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL96* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS97* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY98* LIMITED REMEDY.99*100* 4.3. Licensee shall not export, either directly or indirectly, any of this101* software or system incorporating such software without first obtaining any102* required license or other approval from the U. S. Department of Commerce or103* any other agency or department of the United States Government. In the104* event Licensee exports any such software from the United States or105* re-exports any such software from a foreign destination, Licensee shall106* ensure that the distribution and export/re-export of the software is in107* compliance with all laws, regulations, orders, or other restrictions of the108* U.S. Export Administration Regulations. Licensee agrees that neither it nor109* any of its subsidiaries will export/re-export any technical data, process,110* software, or service, directly or indirectly, to any country for which the111* United States government or any agency thereof requires an export license,112* other governmental approval, or letter of assurance, without first obtaining113* such license, approval or letter.114*115*****************************************************************************116*117* Alternatively, you may choose to be licensed under the terms of the118* following license:119*120* Redistribution and use in source and binary forms, with or without121* modification, are permitted provided that the following conditions122* are met:123* 1. Redistributions of source code must retain the above copyright124* notice, this list of conditions, and the following disclaimer,125* without modification.126* 2. Redistributions in binary form must reproduce at minimum a disclaimer127* substantially similar to the "NO WARRANTY" disclaimer below128* ("Disclaimer") and any redistribution must be conditioned upon129* including a substantially similar Disclaimer requirement for further130* binary redistribution.131* 3. Neither the names of the above-listed copyright holders nor the names132* of any contributors may be used to endorse or promote products derived133* from this software without specific prior written permission.134*135* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS136* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT137* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR138* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT139* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,140* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT141* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,142* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY143* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT144* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE145* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.146*147* Alternatively, you may choose to be licensed under the terms of the148* GNU General Public License ("GPL") version 2 as published by the Free149* Software Foundation.150*151*****************************************************************************/152153#include <contrib/dev/acpica/include/acpi.h>154#include <contrib/dev/acpica/include/accommon.h>155#include <contrib/dev/acpica/include/acevents.h>156157158#define _COMPONENT ACPI_EVENTS159ACPI_MODULE_NAME ("evsci")160161#if (!ACPI_REDUCED_HARDWARE) /* Entire module */162163/* Local prototypes */164165static UINT32 ACPI_SYSTEM_XFACE166AcpiEvSciXruptHandler (167void *Context);168169170/*******************************************************************************171*172* FUNCTION: AcpiEvSciDispatch173*174* PARAMETERS: None175*176* RETURN: Status code indicates whether interrupt was handled.177*178* DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers.179*180******************************************************************************/181182UINT32183AcpiEvSciDispatch (184void)185{186ACPI_SCI_HANDLER_INFO *SciHandler;187ACPI_CPU_FLAGS Flags;188UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;189190191ACPI_FUNCTION_NAME (EvSciDispatch);192193194/* Are there any host-installed SCI handlers? */195196if (!AcpiGbl_SciHandlerList)197{198return (IntStatus);199}200201Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);202203/* Invoke all host-installed SCI handlers */204205SciHandler = AcpiGbl_SciHandlerList;206while (SciHandler)207{208/* Invoke the installed handler (at interrupt level) */209210IntStatus |= SciHandler->Address (211SciHandler->Context);212213SciHandler = SciHandler->Next;214}215216AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);217return (IntStatus);218}219220221/*******************************************************************************222*223* FUNCTION: AcpiEvSciXruptHandler224*225* PARAMETERS: Context - Calling Context226*227* RETURN: Status code indicates whether interrupt was handled.228*229* DESCRIPTION: Interrupt handler that will figure out what function or230* control method to call to deal with a SCI.231*232******************************************************************************/233234static UINT32 ACPI_SYSTEM_XFACE235AcpiEvSciXruptHandler (236void *Context)237{238ACPI_GPE_XRUPT_INFO *GpeXruptList = Context;239UINT32 InterruptHandled = ACPI_INTERRUPT_NOT_HANDLED;240241242ACPI_FUNCTION_TRACE (EvSciXruptHandler);243244245/*246* We are guaranteed by the ACPICA initialization/shutdown code that247* if this interrupt handler is installed, ACPI is enabled.248*/249250/*251* Fixed Events:252* Check for and dispatch any Fixed Events that have occurred253*/254InterruptHandled |= AcpiEvFixedEventDetect ();255256/*257* General Purpose Events:258* Check for and dispatch any GPEs that have occurred259*/260InterruptHandled |= AcpiEvGpeDetect (GpeXruptList);261262/* Invoke all host-installed SCI handlers */263264InterruptHandled |= AcpiEvSciDispatch ();265266AcpiSciCount++;267return_UINT32 (InterruptHandled);268}269270271/*******************************************************************************272*273* FUNCTION: AcpiEvGpeXruptHandler274*275* PARAMETERS: Context - Calling Context276*277* RETURN: Status code indicates whether interrupt was handled.278*279* DESCRIPTION: Handler for GPE Block Device interrupts280*281******************************************************************************/282283UINT32 ACPI_SYSTEM_XFACE284AcpiEvGpeXruptHandler (285void *Context)286{287ACPI_GPE_XRUPT_INFO *GpeXruptList = Context;288UINT32 InterruptHandled = ACPI_INTERRUPT_NOT_HANDLED;289290291ACPI_FUNCTION_TRACE (EvGpeXruptHandler);292293294/*295* We are guaranteed by the ACPICA initialization/shutdown code that296* if this interrupt handler is installed, ACPI is enabled.297*/298299/* GPEs: Check for and dispatch any GPEs that have occurred */300301InterruptHandled |= AcpiEvGpeDetect (GpeXruptList);302return_UINT32 (InterruptHandled);303}304305306/******************************************************************************307*308* FUNCTION: AcpiEvInstallSciHandler309*310* PARAMETERS: none311*312* RETURN: Status313*314* DESCRIPTION: Installs SCI handler.315*316******************************************************************************/317318UINT32319AcpiEvInstallSciHandler (320void)321{322UINT32 Status = AE_OK;323324325ACPI_FUNCTION_TRACE (EvInstallSciHandler);326327328Status = AcpiOsInstallInterruptHandler ((UINT32) AcpiGbl_FADT.SciInterrupt,329AcpiEvSciXruptHandler, AcpiGbl_GpeXruptListHead);330return_ACPI_STATUS (Status);331}332333334/******************************************************************************335*336* FUNCTION: AcpiEvRemoveAllSciHandlers337*338* PARAMETERS: none339*340* RETURN: AE_OK if handler uninstalled, AE_ERROR if handler was not341* installed to begin with342*343* DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be344* taken. Remove all host-installed SCI handlers.345*346* Note: It doesn't seem important to disable all events or set the event347* enable registers to their original values. The OS should disable348* the SCI interrupt level when the handler is removed, so no more349* events will come in.350*351******************************************************************************/352353ACPI_STATUS354AcpiEvRemoveAllSciHandlers (355void)356{357ACPI_SCI_HANDLER_INFO *SciHandler;358ACPI_CPU_FLAGS Flags;359ACPI_STATUS Status;360361362ACPI_FUNCTION_TRACE (EvRemoveAllSciHandlers);363364365/* Just let the OS remove the handler and disable the level */366367Status = AcpiOsRemoveInterruptHandler ((UINT32) AcpiGbl_FADT.SciInterrupt,368AcpiEvSciXruptHandler);369370if (!AcpiGbl_SciHandlerList)371{372return (Status);373}374375Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);376377/* Free all host-installed SCI handlers */378379while (AcpiGbl_SciHandlerList)380{381SciHandler = AcpiGbl_SciHandlerList;382AcpiGbl_SciHandlerList = SciHandler->Next;383ACPI_FREE (SciHandler);384}385386AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);387return_ACPI_STATUS (Status);388}389390#endif /* !ACPI_REDUCED_HARDWARE */391392393