Path: blob/main/sys/contrib/dev/acpica/components/events/evxfevnt.c
48525 views
/******************************************************************************1*2* Module Name: evxfevnt - External Interfaces, ACPI event disable/enable3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#define EXPORT_ACPI_INTERFACES152153#include <contrib/dev/acpica/include/acpi.h>154#include <contrib/dev/acpica/include/accommon.h>155#include <contrib/dev/acpica/include/actables.h>156157#define _COMPONENT ACPI_EVENTS158ACPI_MODULE_NAME ("evxfevnt")159160161#if (!ACPI_REDUCED_HARDWARE) /* Entire module */162/*******************************************************************************163*164* FUNCTION: AcpiEnable165*166* PARAMETERS: None167*168* RETURN: Status169*170* DESCRIPTION: Transfers the system into ACPI mode.171*172******************************************************************************/173174ACPI_STATUS175AcpiEnable (176void)177{178ACPI_STATUS Status = AE_OK;179180181ACPI_FUNCTION_TRACE (AcpiEnable);182183184/* ACPI tables must be present */185186if (AcpiGbl_FadtIndex == ACPI_INVALID_TABLE_INDEX)187{188return_ACPI_STATUS (AE_NO_ACPI_TABLES);189}190191/* If the Hardware Reduced flag is set, machine is always in acpi mode */192193if (AcpiGbl_ReducedHardware)194{195return_ACPI_STATUS (AE_OK);196}197198/* Check current mode */199200if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)201{202ACPI_DEBUG_PRINT ((ACPI_DB_INIT,203"System is already in ACPI mode\n"));204}205else206{207/* Transition to ACPI mode */208209Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);210if (ACPI_FAILURE (Status))211{212ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));213return_ACPI_STATUS (Status);214}215216ACPI_DEBUG_PRINT ((ACPI_DB_INIT,217"Transition to ACPI mode successful\n"));218}219220return_ACPI_STATUS (Status);221}222223ACPI_EXPORT_SYMBOL (AcpiEnable)224225226/*******************************************************************************227*228* FUNCTION: AcpiDisable229*230* PARAMETERS: None231*232* RETURN: Status233*234* DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.235*236******************************************************************************/237238ACPI_STATUS239AcpiDisable (240void)241{242ACPI_STATUS Status = AE_OK;243244245ACPI_FUNCTION_TRACE (AcpiDisable);246247248/* If the Hardware Reduced flag is set, machine is always in acpi mode */249250if (AcpiGbl_ReducedHardware)251{252return_ACPI_STATUS (AE_OK);253}254255if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)256{257ACPI_DEBUG_PRINT ((ACPI_DB_INIT,258"System is already in legacy (non-ACPI) mode\n"));259}260else261{262/* Transition to LEGACY mode */263264Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);265266if (ACPI_FAILURE (Status))267{268ACPI_ERROR ((AE_INFO,269"Could not exit ACPI mode to legacy mode"));270return_ACPI_STATUS (Status);271}272273ACPI_DEBUG_PRINT ((ACPI_DB_INIT,274"ACPI mode disabled\n"));275}276277return_ACPI_STATUS (Status);278}279280ACPI_EXPORT_SYMBOL (AcpiDisable)281282283/*******************************************************************************284*285* FUNCTION: AcpiEnableEvent286*287* PARAMETERS: Event - The fixed eventto be enabled288* Flags - Reserved289*290* RETURN: Status291*292* DESCRIPTION: Enable an ACPI event (fixed)293*294******************************************************************************/295296ACPI_STATUS297AcpiEnableEvent (298UINT32 Event,299UINT32 Flags)300{301ACPI_STATUS Status = AE_OK;302UINT32 Value;303304305ACPI_FUNCTION_TRACE (AcpiEnableEvent);306307308/* If Hardware Reduced flag is set, there are no fixed events */309310if (AcpiGbl_ReducedHardware)311{312return_ACPI_STATUS (AE_OK);313}314315/* Decode the Fixed Event */316317if (Event > ACPI_EVENT_MAX)318{319return_ACPI_STATUS (AE_BAD_PARAMETER);320}321322/*323* Enable the requested fixed event (by writing a one to the enable324* register bit)325*/326Status = AcpiWriteBitRegister (327AcpiGbl_FixedEventInfo[Event].EnableRegisterId,328ACPI_ENABLE_EVENT);329if (ACPI_FAILURE (Status))330{331return_ACPI_STATUS (Status);332}333334/* Make sure that the hardware responded */335336Status = AcpiReadBitRegister (337AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);338if (ACPI_FAILURE (Status))339{340return_ACPI_STATUS (Status);341}342343if (Value != 1)344{345ACPI_ERROR ((AE_INFO,346"Could not enable %s event", AcpiUtGetEventName (Event)));347return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);348}349350return_ACPI_STATUS (Status);351}352353ACPI_EXPORT_SYMBOL (AcpiEnableEvent)354355356/*******************************************************************************357*358* FUNCTION: AcpiDisableEvent359*360* PARAMETERS: Event - The fixed event to be disabled361* Flags - Reserved362*363* RETURN: Status364*365* DESCRIPTION: Disable an ACPI event (fixed)366*367******************************************************************************/368369ACPI_STATUS370AcpiDisableEvent (371UINT32 Event,372UINT32 Flags)373{374ACPI_STATUS Status = AE_OK;375UINT32 Value;376377378ACPI_FUNCTION_TRACE (AcpiDisableEvent);379380381/* If Hardware Reduced flag is set, there are no fixed events */382383if (AcpiGbl_ReducedHardware)384{385return_ACPI_STATUS (AE_OK);386}387388/* Decode the Fixed Event */389390if (Event > ACPI_EVENT_MAX)391{392return_ACPI_STATUS (AE_BAD_PARAMETER);393}394395/*396* Disable the requested fixed event (by writing a zero to the enable397* register bit)398*/399Status = AcpiWriteBitRegister (400AcpiGbl_FixedEventInfo[Event].EnableRegisterId,401ACPI_DISABLE_EVENT);402if (ACPI_FAILURE (Status))403{404return_ACPI_STATUS (Status);405}406407Status = AcpiReadBitRegister (408AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);409if (ACPI_FAILURE (Status))410{411return_ACPI_STATUS (Status);412}413414if (Value != 0)415{416ACPI_ERROR ((AE_INFO,417"Could not disable %s events", AcpiUtGetEventName (Event)));418return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);419}420421return_ACPI_STATUS (Status);422}423424ACPI_EXPORT_SYMBOL (AcpiDisableEvent)425426427/*******************************************************************************428*429* FUNCTION: AcpiClearEvent430*431* PARAMETERS: Event - The fixed event to be cleared432*433* RETURN: Status434*435* DESCRIPTION: Clear an ACPI event (fixed)436*437******************************************************************************/438439ACPI_STATUS440AcpiClearEvent (441UINT32 Event)442{443ACPI_STATUS Status = AE_OK;444445446ACPI_FUNCTION_TRACE (AcpiClearEvent);447448449/* If Hardware Reduced flag is set, there are no fixed events */450451if (AcpiGbl_ReducedHardware)452{453return_ACPI_STATUS (AE_OK);454}455456/* Decode the Fixed Event */457458if (Event > ACPI_EVENT_MAX)459{460return_ACPI_STATUS (AE_BAD_PARAMETER);461}462463/*464* Clear the requested fixed event (By writing a one to the status465* register bit)466*/467Status = AcpiWriteBitRegister (468AcpiGbl_FixedEventInfo[Event].StatusRegisterId,469ACPI_CLEAR_STATUS);470471return_ACPI_STATUS (Status);472}473474ACPI_EXPORT_SYMBOL (AcpiClearEvent)475476477/*******************************************************************************478*479* FUNCTION: AcpiGetEventStatus480*481* PARAMETERS: Event - The fixed event482* EventStatus - Where the current status of the event will483* be returned484*485* RETURN: Status486*487* DESCRIPTION: Obtains and returns the current status of the event488*489******************************************************************************/490491ACPI_STATUS492AcpiGetEventStatus (493UINT32 Event,494ACPI_EVENT_STATUS *EventStatus)495{496ACPI_STATUS Status;497ACPI_EVENT_STATUS LocalEventStatus = 0;498UINT32 InByte;499500501ACPI_FUNCTION_TRACE (AcpiGetEventStatus);502503504if (!EventStatus)505{506return_ACPI_STATUS (AE_BAD_PARAMETER);507}508509/* Decode the Fixed Event */510511if (Event > ACPI_EVENT_MAX)512{513return_ACPI_STATUS (AE_BAD_PARAMETER);514}515516/* Fixed event currently can be dispatched? */517518if (AcpiGbl_FixedEventHandlers[Event].Handler)519{520LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;521}522523/* Fixed event currently enabled? */524525Status = AcpiReadBitRegister (526AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &InByte);527if (ACPI_FAILURE (Status))528{529return_ACPI_STATUS (Status);530}531532if (InByte)533{534LocalEventStatus |=535(ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);536}537538/* Fixed event currently active? */539540Status = AcpiReadBitRegister (541AcpiGbl_FixedEventInfo[Event].StatusRegisterId, &InByte);542if (ACPI_FAILURE (Status))543{544return_ACPI_STATUS (Status);545}546547if (InByte)548{549LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;550}551552(*EventStatus) = LocalEventStatus;553return_ACPI_STATUS (AE_OK);554}555556ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)557558#endif /* !ACPI_REDUCED_HARDWARE */559560561