Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:02

0001 /******************************************************************************
0002  *
0003  * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
0004  *                         Address Spaces.
0005  *
0006  *****************************************************************************/
0007 
0008 /******************************************************************************
0009  *
0010  * 1. Copyright Notice
0011  *
0012  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0013  * All rights reserved.
0014  *
0015  * 2. License
0016  *
0017  * 2.1. This is your license from Intel Corp. under its intellectual property
0018  * rights. You may have additional license terms from the party that provided
0019  * you this software, covering your right to use that party's intellectual
0020  * property rights.
0021  *
0022  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0023  * copy of the source code appearing in this file ("Covered Code") an
0024  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0025  * base code distributed originally by Intel ("Original Intel Code") to copy,
0026  * make derivatives, distribute, use and display any portion of the Covered
0027  * Code in any form, with the right to sublicense such rights; and
0028  *
0029  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0030  * license (with the right to sublicense), under only those claims of Intel
0031  * patents that are infringed by the Original Intel Code, to make, use, sell,
0032  * offer to sell, and import the Covered Code and derivative works thereof
0033  * solely to the minimum extent necessary to exercise the above copyright
0034  * license, and in no event shall the patent license extend to any additions
0035  * to or modifications of the Original Intel Code. No other license or right
0036  * is granted directly or by implication, estoppel or otherwise;
0037  *
0038  * The above copyright and patent license is granted only if the following
0039  * conditions are met:
0040  *
0041  * 3. Conditions
0042  *
0043  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0044  * Redistribution of source code of any substantial portion of the Covered
0045  * Code or modification with rights to further distribute source must include
0046  * the above Copyright Notice, the above License, this list of Conditions,
0047  * and the following Disclaimer and Export Compliance provision. In addition,
0048  * Licensee must cause all Covered Code to which Licensee contributes to
0049  * contain a file documenting the changes Licensee made to create that Covered
0050  * Code and the date of any change. Licensee must include in that file the
0051  * documentation of any changes made by any predecessor Licensee. Licensee
0052  * must include a prominent statement that the modification is derived,
0053  * directly or indirectly, from Original Intel Code.
0054  *
0055  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0056  * Redistribution of source code of any substantial portion of the Covered
0057  * Code or modification without rights to further distribute source must
0058  * include the following Disclaimer and Export Compliance provision in the
0059  * documentation and/or other materials provided with distribution. In
0060  * addition, Licensee may not authorize further sublicense of source of any
0061  * portion of the Covered Code, and must include terms to the effect that the
0062  * license from Licensee to its licensee is limited to the intellectual
0063  * property embodied in the software Licensee provides to its licensee, and
0064  * not to intellectual property embodied in modifications its licensee may
0065  * make.
0066  *
0067  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0068  * substantial portion of the Covered Code or modification must reproduce the
0069  * above Copyright Notice, and the following Disclaimer and Export Compliance
0070  * provision in the documentation and/or other materials provided with the
0071  * distribution.
0072  *
0073  * 3.4. Intel retains all right, title, and interest in and to the Original
0074  * Intel Code.
0075  *
0076  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0077  * Intel shall be used in advertising or otherwise to promote the sale, use or
0078  * other dealings in products derived from or relating to the Covered Code
0079  * without prior written authorization from Intel.
0080  *
0081  * 4. Disclaimer and Export Compliance
0082  *
0083  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0084  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0085  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0086  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0087  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0088  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0089  * PARTICULAR PURPOSE.
0090  *
0091  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0092  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0093  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0094  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0095  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0096  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0097  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0098  * LIMITED REMEDY.
0099  *
0100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0101  * software or system incorporating such software without first obtaining any
0102  * required license or other approval from the U. S. Department of Commerce or
0103  * any other agency or department of the United States Government. In the
0104  * event Licensee exports any such software from the United States or
0105  * re-exports any such software from a foreign destination, Licensee shall
0106  * ensure that the distribution and export/re-export of the software is in
0107  * compliance with all laws, regulations, orders, or other restrictions of the
0108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0109  * any of its subsidiaries will export/re-export any technical data, process,
0110  * software, or service, directly or indirectly, to any country for which the
0111  * United States government or any agency thereof requires an export license,
0112  * other governmental approval, or letter of assurance, without first obtaining
0113  * such license, approval or letter.
0114  *
0115  *****************************************************************************
0116  *
0117  * Alternatively, you may choose to be licensed under the terms of the
0118  * following license:
0119  *
0120  * Redistribution and use in source and binary forms, with or without
0121  * modification, are permitted provided that the following conditions
0122  * are met:
0123  * 1. Redistributions of source code must retain the above copyright
0124  *    notice, this list of conditions, and the following disclaimer,
0125  *    without modification.
0126  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0127  *    substantially similar to the "NO WARRANTY" disclaimer below
0128  *    ("Disclaimer") and any redistribution must be conditioned upon
0129  *    including a substantially similar Disclaimer requirement for further
0130  *    binary redistribution.
0131  * 3. Neither the names of the above-listed copyright holders nor the names
0132  *    of any contributors may be used to endorse or promote products derived
0133  *    from this software without specific prior written permission.
0134  *
0135  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0136  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0137  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0138  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0139  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0140  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0141  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0142  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0143  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0144  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0145  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0146  *
0147  * Alternatively, you may choose to be licensed under the terms of the
0148  * GNU General Public License ("GPL") version 2 as published by the Free
0149  * Software Foundation.
0150  *
0151  *****************************************************************************/
0152 
0153 #define EXPORT_ACPI_INTERFACES
0154 
0155 #include "acpi.h"
0156 #include "accommon.h"
0157 #include "acnamesp.h"
0158 #include "acevents.h"
0159 
0160 #define _COMPONENT          ACPI_EVENTS
0161         ACPI_MODULE_NAME    ("evxfregn")
0162 
0163 
0164 /*******************************************************************************
0165  *
0166  * FUNCTION:    AcpiInstallAddressSpaceHandlerInternal
0167  *
0168  * PARAMETERS:  Device          - Handle for the device
0169  *              SpaceId         - The address space ID
0170  *              Handler         - Address of the handler
0171  *              Setup           - Address of the setup function
0172  *              Context         - Value passed to the handler on each access
0173  *              Run_Reg         - Run _REG methods for this address space?
0174  *
0175  * RETURN:      Status
0176  *
0177  * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
0178  *
0179  * NOTE: This function should only be called after AcpiEnableSubsystem has
0180  * been called. This is because any _REG methods associated with the Space ID
0181  * are executed here, and these methods can only be safely executed after
0182  * the default handlers have been installed and the hardware has been
0183  * initialized (via AcpiEnableSubsystem.)
0184  * To avoid this problem pass FALSE for Run_Reg and later on call
0185  * AcpiExecuteRegMethods() to execute _REG.
0186  *
0187  ******************************************************************************/
0188 
0189 static ACPI_STATUS
0190 AcpiInstallAddressSpaceHandlerInternal (
0191     ACPI_HANDLE             Device,
0192     ACPI_ADR_SPACE_TYPE     SpaceId,
0193     ACPI_ADR_SPACE_HANDLER  Handler,
0194     ACPI_ADR_SPACE_SETUP    Setup,
0195     void                    *Context,
0196     BOOLEAN                 Run_Reg)
0197 {
0198     ACPI_NAMESPACE_NODE     *Node;
0199     ACPI_STATUS             Status;
0200 
0201 
0202     ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler);
0203 
0204 
0205     /* Parameter validation */
0206 
0207     if (!Device)
0208     {
0209         return_ACPI_STATUS (AE_BAD_PARAMETER);
0210     }
0211 
0212     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
0213     if (ACPI_FAILURE (Status))
0214     {
0215         return_ACPI_STATUS (Status);
0216     }
0217 
0218     /* Convert and validate the device handle */
0219 
0220     Node = AcpiNsValidateHandle (Device);
0221     if (!Node)
0222     {
0223         Status = AE_BAD_PARAMETER;
0224         goto UnlockAndExit;
0225     }
0226 
0227     /* Install the handler for all Regions for this Space ID */
0228 
0229     Status = AcpiEvInstallSpaceHandler (
0230         Node, SpaceId, Handler, Setup, Context);
0231     if (ACPI_FAILURE (Status))
0232     {
0233         goto UnlockAndExit;
0234     }
0235 
0236     /* Run all _REG methods for this address space */
0237 
0238     if (Run_Reg)
0239     {
0240         AcpiEvExecuteRegMethods (Node, SpaceId, ACPI_REG_CONNECT);
0241     }
0242 
0243 UnlockAndExit:
0244     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
0245     return_ACPI_STATUS (Status);
0246 }
0247 
0248 ACPI_STATUS
0249 AcpiInstallAddressSpaceHandler (
0250     ACPI_HANDLE             Device,
0251     ACPI_ADR_SPACE_TYPE     SpaceId,
0252     ACPI_ADR_SPACE_HANDLER  Handler,
0253     ACPI_ADR_SPACE_SETUP    Setup,
0254     void                    *Context)
0255 {
0256     return AcpiInstallAddressSpaceHandlerInternal (Device, SpaceId, Handler, Setup, Context, TRUE);
0257 }
0258 
0259 ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler)
0260 
0261 ACPI_STATUS
0262 AcpiInstallAddressSpaceHandlerNo_Reg (
0263     ACPI_HANDLE             Device,
0264     ACPI_ADR_SPACE_TYPE     SpaceId,
0265     ACPI_ADR_SPACE_HANDLER  Handler,
0266     ACPI_ADR_SPACE_SETUP    Setup,
0267     void                    *Context)
0268 {
0269     return AcpiInstallAddressSpaceHandlerInternal (Device, SpaceId, Handler, Setup, Context, FALSE);
0270 }
0271 
0272 ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandlerNo_Reg)
0273 
0274 
0275 /*******************************************************************************
0276  *
0277  * FUNCTION:    AcpiRemoveAddressSpaceHandler
0278  *
0279  * PARAMETERS:  Device          - Handle for the device
0280  *              SpaceId         - The address space ID
0281  *              Handler         - Address of the handler
0282  *
0283  * RETURN:      Status
0284  *
0285  * DESCRIPTION: Remove a previously installed handler.
0286  *
0287  ******************************************************************************/
0288 
0289 ACPI_STATUS
0290 AcpiRemoveAddressSpaceHandler (
0291     ACPI_HANDLE             Device,
0292     ACPI_ADR_SPACE_TYPE     SpaceId,
0293     ACPI_ADR_SPACE_HANDLER  Handler)
0294 {
0295     ACPI_OPERAND_OBJECT     *ObjDesc;
0296     ACPI_OPERAND_OBJECT     *HandlerObj;
0297     ACPI_OPERAND_OBJECT     *RegionObj;
0298     ACPI_OPERAND_OBJECT     **LastObjPtr;
0299     ACPI_NAMESPACE_NODE     *Node;
0300     ACPI_STATUS             Status;
0301 
0302 
0303     ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler);
0304 
0305 
0306     /* Parameter validation */
0307 
0308     if (!Device)
0309     {
0310         return_ACPI_STATUS (AE_BAD_PARAMETER);
0311     }
0312 
0313     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
0314     if (ACPI_FAILURE (Status))
0315     {
0316         return_ACPI_STATUS (Status);
0317     }
0318 
0319     /* Convert and validate the device handle */
0320 
0321     Node = AcpiNsValidateHandle (Device);
0322     if (!Node ||
0323         ((Node->Type != ACPI_TYPE_DEVICE)    &&
0324          (Node->Type != ACPI_TYPE_PROCESSOR) &&
0325          (Node->Type != ACPI_TYPE_THERMAL)   &&
0326          (Node != AcpiGbl_RootNode)))
0327     {
0328         Status = AE_BAD_PARAMETER;
0329         goto UnlockAndExit;
0330     }
0331 
0332     /* Make sure the internal object exists */
0333 
0334     ObjDesc = AcpiNsGetAttachedObject (Node);
0335     if (!ObjDesc)
0336     {
0337         Status = AE_NOT_EXIST;
0338         goto UnlockAndExit;
0339     }
0340 
0341     /* Find the address handler the user requested */
0342 
0343     HandlerObj = ObjDesc->CommonNotify.Handler;
0344     LastObjPtr = &ObjDesc->CommonNotify.Handler;
0345     while (HandlerObj)
0346     {
0347         /* We have a handler, see if user requested this one */
0348 
0349         if (HandlerObj->AddressSpace.SpaceId == SpaceId)
0350         {
0351             /* Handler must be the same as the installed handler */
0352 
0353             if (HandlerObj->AddressSpace.Handler != Handler)
0354             {
0355                 Status = AE_BAD_PARAMETER;
0356                 goto UnlockAndExit;
0357             }
0358 
0359             /* Matched SpaceId, first dereference this in the Regions */
0360 
0361             ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
0362                 "Removing address handler %p(%p) for region %s "
0363                 "on Device %p(%p)\n",
0364                 HandlerObj, Handler, AcpiUtGetRegionName (SpaceId),
0365                 Node, ObjDesc));
0366 
0367             RegionObj = HandlerObj->AddressSpace.RegionList;
0368 
0369             /* Walk the handler's region list */
0370 
0371             while (RegionObj)
0372             {
0373                 /*
0374                  * First disassociate the handler from the region.
0375                  *
0376                  * NOTE: this doesn't mean that the region goes away
0377                  * The region is just inaccessible as indicated to
0378                  * the _REG method
0379                  */
0380                 AcpiEvDetachRegion (RegionObj, TRUE);
0381 
0382                 /*
0383                  * Walk the list: Just grab the head because the
0384                  * DetachRegion removed the previous head.
0385                  */
0386                 RegionObj = HandlerObj->AddressSpace.RegionList;
0387             }
0388 
0389             /* Remove this Handler object from the list */
0390 
0391             *LastObjPtr = HandlerObj->AddressSpace.Next;
0392 
0393             /* Now we can delete the handler object */
0394 
0395             AcpiOsReleaseMutex (HandlerObj->AddressSpace.ContextMutex);
0396             AcpiUtRemoveReference (HandlerObj);
0397             goto UnlockAndExit;
0398         }
0399 
0400         /* Walk the linked list of handlers */
0401 
0402         LastObjPtr = &HandlerObj->AddressSpace.Next;
0403         HandlerObj = HandlerObj->AddressSpace.Next;
0404     }
0405 
0406     /* The handler does not exist */
0407 
0408     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
0409         "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
0410         Handler, AcpiUtGetRegionName (SpaceId), SpaceId, Node, ObjDesc));
0411 
0412     Status = AE_NOT_EXIST;
0413 
0414 UnlockAndExit:
0415     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
0416     return_ACPI_STATUS (Status);
0417 }
0418 
0419 ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler)
0420 
0421 
0422 /*******************************************************************************
0423  *
0424  * FUNCTION:    AcpiExecuteRegMethods
0425  *
0426  * PARAMETERS:  Device          - Handle for the device
0427  *              SpaceId         - The address space ID
0428  *
0429  * RETURN:      Status
0430  *
0431  * DESCRIPTION: Execute _REG for all OpRegions of a given SpaceId.
0432  *
0433  ******************************************************************************/
0434 
0435 ACPI_STATUS
0436 AcpiExecuteRegMethods (
0437     ACPI_HANDLE             Device,
0438     ACPI_ADR_SPACE_TYPE     SpaceId)
0439 {
0440     ACPI_NAMESPACE_NODE     *Node;
0441     ACPI_STATUS             Status;
0442 
0443 
0444     ACPI_FUNCTION_TRACE (AcpiExecuteRegMethods);
0445 
0446 
0447     /* Parameter validation */
0448 
0449     if (!Device)
0450     {
0451         return_ACPI_STATUS (AE_BAD_PARAMETER);
0452     }
0453 
0454     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
0455     if (ACPI_FAILURE (Status))
0456     {
0457         return_ACPI_STATUS (Status);
0458     }
0459 
0460     /* Convert and validate the device handle */
0461 
0462     Node = AcpiNsValidateHandle (Device);
0463     if (Node)
0464     {
0465         /* Run all _REG methods for this address space */
0466 
0467         AcpiEvExecuteRegMethods (Node, SpaceId, ACPI_REG_CONNECT);
0468     }
0469     else
0470     {
0471         Status = AE_BAD_PARAMETER;
0472     }
0473 
0474     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
0475     return_ACPI_STATUS (Status);
0476 }
0477 
0478 ACPI_EXPORT_SYMBOL (AcpiExecuteRegMethods)