Path: blob/main/sys/contrib/dev/acpica/components/events/evxfregn.c
48525 views
/******************************************************************************1*2* Module Name: evxfregn - External Interfaces, ACPI Operation Regions and3* Address Spaces.4*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 may64* make.65*66* 3.3. Redistribution of Executable. Redistribution in executable form of any67* substantial portion of the Covered Code or modification must reproduce the68* above Copyright Notice, and the following Disclaimer and Export Compliance69* provision in the documentation and/or other materials provided with the70* distribution.71*72* 3.4. Intel retains all right, title, and interest in and to the Original73* Intel Code.74*75* 3.5. Neither the name Intel nor any other trademark owned or controlled by76* Intel shall be used in advertising or otherwise to promote the sale, use or77* other dealings in products derived from or relating to the Covered Code78* without prior written authorization from Intel.79*80* 4. Disclaimer and Export Compliance81*82* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED83* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE84* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,85* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY86* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY87* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A88* PARTICULAR PURPOSE.89*90* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES91* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR92* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,93* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY94* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL95* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS96* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY97* LIMITED REMEDY.98*99* 4.3. Licensee shall not export, either directly or indirectly, any of this100* software or system incorporating such software without first obtaining any101* required license or other approval from the U. S. Department of Commerce or102* any other agency or department of the United States Government. In the103* event Licensee exports any such software from the United States or104* re-exports any such software from a foreign destination, Licensee shall105* ensure that the distribution and export/re-export of the software is in106* compliance with all laws, regulations, orders, or other restrictions of the107* U.S. Export Administration Regulations. Licensee agrees that neither it nor108* any of its subsidiaries will export/re-export any technical data, process,109* software, or service, directly or indirectly, to any country for which the110* United States government or any agency thereof requires an export license,111* other governmental approval, or letter of assurance, without first obtaining112* such license, approval or letter.113*114*****************************************************************************115*116* Alternatively, you may choose to be licensed under the terms of the117* following license:118*119* Redistribution and use in source and binary forms, with or without120* modification, are permitted provided that the following conditions121* are met:122* 1. Redistributions of source code must retain the above copyright123* notice, this list of conditions, and the following disclaimer,124* without modification.125* 2. Redistributions in binary form must reproduce at minimum a disclaimer126* substantially similar to the "NO WARRANTY" disclaimer below127* ("Disclaimer") and any redistribution must be conditioned upon128* including a substantially similar Disclaimer requirement for further129* binary redistribution.130* 3. Neither the names of the above-listed copyright holders nor the names131* of any contributors may be used to endorse or promote products derived132* from this software without specific prior written permission.133*134* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS135* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT136* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR137* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT138* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,139* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT140* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,141* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY142* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT143* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE144* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.145*146* Alternatively, you may choose to be licensed under the terms of the147* GNU General Public License ("GPL") version 2 as published by the Free148* Software Foundation.149*150*****************************************************************************/151152#define EXPORT_ACPI_INTERFACES153154#include <contrib/dev/acpica/include/acpi.h>155#include <contrib/dev/acpica/include/accommon.h>156#include <contrib/dev/acpica/include/acnamesp.h>157#include <contrib/dev/acpica/include/acevents.h>158159#define _COMPONENT ACPI_EVENTS160ACPI_MODULE_NAME ("evxfregn")161162163/*******************************************************************************164*165* FUNCTION: AcpiInstallAddressSpaceHandlerInternal166*167* PARAMETERS: Device - Handle for the device168* SpaceId - The address space ID169* Handler - Address of the handler170* Setup - Address of the setup function171* Context - Value passed to the handler on each access172* Run_Reg - Run _REG methods for this address space?173*174* RETURN: Status175*176* DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.177*178* NOTE: This function should only be called after AcpiEnableSubsystem has179* been called. This is because any _REG methods associated with the Space ID180* are executed here, and these methods can only be safely executed after181* the default handlers have been installed and the hardware has been182* initialized (via AcpiEnableSubsystem.)183* To avoid this problem pass FALSE for Run_Reg and later on call184* AcpiExecuteRegMethods() to execute _REG.185*186******************************************************************************/187188static ACPI_STATUS189AcpiInstallAddressSpaceHandlerInternal (190ACPI_HANDLE Device,191ACPI_ADR_SPACE_TYPE SpaceId,192ACPI_ADR_SPACE_HANDLER Handler,193ACPI_ADR_SPACE_SETUP Setup,194void *Context,195BOOLEAN Run_Reg)196{197ACPI_NAMESPACE_NODE *Node;198ACPI_STATUS Status;199200201ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler);202203204/* Parameter validation */205206if (!Device)207{208return_ACPI_STATUS (AE_BAD_PARAMETER);209}210211Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);212if (ACPI_FAILURE (Status))213{214return_ACPI_STATUS (Status);215}216217/* Convert and validate the device handle */218219Node = AcpiNsValidateHandle (Device);220if (!Node)221{222Status = AE_BAD_PARAMETER;223goto UnlockAndExit;224}225226/* Install the handler for all Regions for this Space ID */227228Status = AcpiEvInstallSpaceHandler (229Node, SpaceId, Handler, Setup, Context);230if (ACPI_FAILURE (Status))231{232goto UnlockAndExit;233}234235/* Run all _REG methods for this address space */236237if (Run_Reg)238{239AcpiEvExecuteRegMethods (Node, SpaceId, ACPI_REG_CONNECT);240}241242UnlockAndExit:243(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);244return_ACPI_STATUS (Status);245}246247ACPI_STATUS248AcpiInstallAddressSpaceHandler (249ACPI_HANDLE Device,250ACPI_ADR_SPACE_TYPE SpaceId,251ACPI_ADR_SPACE_HANDLER Handler,252ACPI_ADR_SPACE_SETUP Setup,253void *Context)254{255return AcpiInstallAddressSpaceHandlerInternal (Device, SpaceId, Handler, Setup, Context, TRUE);256}257258ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler)259260ACPI_STATUS261AcpiInstallAddressSpaceHandlerNo_Reg (262ACPI_HANDLE Device,263ACPI_ADR_SPACE_TYPE SpaceId,264ACPI_ADR_SPACE_HANDLER Handler,265ACPI_ADR_SPACE_SETUP Setup,266void *Context)267{268return AcpiInstallAddressSpaceHandlerInternal (Device, SpaceId, Handler, Setup, Context, FALSE);269}270271ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandlerNo_Reg)272273274/*******************************************************************************275*276* FUNCTION: AcpiRemoveAddressSpaceHandler277*278* PARAMETERS: Device - Handle for the device279* SpaceId - The address space ID280* Handler - Address of the handler281*282* RETURN: Status283*284* DESCRIPTION: Remove a previously installed handler.285*286******************************************************************************/287288ACPI_STATUS289AcpiRemoveAddressSpaceHandler (290ACPI_HANDLE Device,291ACPI_ADR_SPACE_TYPE SpaceId,292ACPI_ADR_SPACE_HANDLER Handler)293{294ACPI_OPERAND_OBJECT *ObjDesc;295ACPI_OPERAND_OBJECT *HandlerObj;296ACPI_OPERAND_OBJECT *RegionObj;297ACPI_OPERAND_OBJECT **LastObjPtr;298ACPI_NAMESPACE_NODE *Node;299ACPI_STATUS Status;300301302ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler);303304305/* Parameter validation */306307if (!Device)308{309return_ACPI_STATUS (AE_BAD_PARAMETER);310}311312Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);313if (ACPI_FAILURE (Status))314{315return_ACPI_STATUS (Status);316}317318/* Convert and validate the device handle */319320Node = AcpiNsValidateHandle (Device);321if (!Node ||322((Node->Type != ACPI_TYPE_DEVICE) &&323(Node->Type != ACPI_TYPE_PROCESSOR) &&324(Node->Type != ACPI_TYPE_THERMAL) &&325(Node != AcpiGbl_RootNode)))326{327Status = AE_BAD_PARAMETER;328goto UnlockAndExit;329}330331/* Make sure the internal object exists */332333ObjDesc = AcpiNsGetAttachedObject (Node);334if (!ObjDesc)335{336Status = AE_NOT_EXIST;337goto UnlockAndExit;338}339340/* Find the address handler the user requested */341342HandlerObj = ObjDesc->CommonNotify.Handler;343LastObjPtr = &ObjDesc->CommonNotify.Handler;344while (HandlerObj)345{346/* We have a handler, see if user requested this one */347348if (HandlerObj->AddressSpace.SpaceId == SpaceId)349{350/* Handler must be the same as the installed handler */351352if (HandlerObj->AddressSpace.Handler != Handler)353{354Status = AE_BAD_PARAMETER;355goto UnlockAndExit;356}357358/* Matched SpaceId, first dereference this in the Regions */359360ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,361"Removing address handler %p(%p) for region %s "362"on Device %p(%p)\n",363HandlerObj, Handler, AcpiUtGetRegionName (SpaceId),364Node, ObjDesc));365366RegionObj = HandlerObj->AddressSpace.RegionList;367368/* Walk the handler's region list */369370while (RegionObj)371{372/*373* First disassociate the handler from the region.374*375* NOTE: this doesn't mean that the region goes away376* The region is just inaccessible as indicated to377* the _REG method378*/379AcpiEvDetachRegion (RegionObj, TRUE);380381/*382* Walk the list: Just grab the head because the383* DetachRegion removed the previous head.384*/385RegionObj = HandlerObj->AddressSpace.RegionList;386}387388/* Remove this Handler object from the list */389390*LastObjPtr = HandlerObj->AddressSpace.Next;391392/* Now we can delete the handler object */393394AcpiUtRemoveReference (HandlerObj);395goto UnlockAndExit;396}397398/* Walk the linked list of handlers */399400LastObjPtr = &HandlerObj->AddressSpace.Next;401HandlerObj = HandlerObj->AddressSpace.Next;402}403404/* The handler does not exist */405406ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,407"Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",408Handler, AcpiUtGetRegionName (SpaceId), SpaceId, Node, ObjDesc));409410Status = AE_NOT_EXIST;411412UnlockAndExit:413(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);414return_ACPI_STATUS (Status);415}416417ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler)418419420/*******************************************************************************421*422* FUNCTION: AcpiExecuteRegMethods423*424* PARAMETERS: Device - Handle for the device425* SpaceId - The address space ID426*427* RETURN: Status428*429* DESCRIPTION: Execute _REG for all OpRegions of a given SpaceId.430*431******************************************************************************/432433ACPI_STATUS434AcpiExecuteRegMethods (435ACPI_HANDLE Device,436ACPI_ADR_SPACE_TYPE SpaceId)437{438ACPI_NAMESPACE_NODE *Node;439ACPI_STATUS Status;440441442ACPI_FUNCTION_TRACE (AcpiExecuteRegMethods);443444445/* Parameter validation */446447if (!Device)448{449return_ACPI_STATUS (AE_BAD_PARAMETER);450}451452Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);453if (ACPI_FAILURE (Status))454{455return_ACPI_STATUS (Status);456}457458/* Convert and validate the device handle */459460Node = AcpiNsValidateHandle (Device);461if (Node)462{463/* Run all _REG methods for this address space */464465AcpiEvExecuteRegMethods (Node, SpaceId, ACPI_REG_CONNECT);466}467else468{469Status = AE_BAD_PARAMETER;470}471472(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);473return_ACPI_STATUS (Status);474}475476ACPI_EXPORT_SYMBOL (AcpiExecuteRegMethods)477478479