evxfregn.c revision 193267
1169695Skan/****************************************************************************** 2169695Skan * 3169695Skan * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and 4169695Skan * Address Spaces. 5169695Skan * 6169695Skan *****************************************************************************/ 7169695Skan 8169695Skan/****************************************************************************** 9169695Skan * 10169695Skan * 1. Copyright Notice 11169695Skan * 12169695Skan * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 13169695Skan * All rights reserved. 14169695Skan * 15169695Skan * 2. License 16169695Skan * 17169695Skan * 2.1. This is your license from Intel Corp. under its intellectual property 18169695Skan * rights. You may have additional license terms from the party that provided 19169695Skan * you this software, covering your right to use that party's intellectual 20169695Skan * property rights. 21169695Skan * 22169695Skan * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23169695Skan * copy of the source code appearing in this file ("Covered Code") an 24169695Skan * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25169695Skan * base code distributed originally by Intel ("Original Intel Code") to copy, 26169695Skan * make derivatives, distribute, use and display any portion of the Covered 27169695Skan * Code in any form, with the right to sublicense such rights; and 28169695Skan * 29169695Skan * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30169695Skan * license (with the right to sublicense), under only those claims of Intel 31169695Skan * patents that are infringed by the Original Intel Code, to make, use, sell, 32169695Skan * offer to sell, and import the Covered Code and derivative works thereof 33169695Skan * solely to the minimum extent necessary to exercise the above copyright 34169695Skan * license, and in no event shall the patent license extend to any additions 35169695Skan * to or modifications of the Original Intel Code. No other license or right 36169695Skan * is granted directly or by implication, estoppel or otherwise; 37169695Skan * 38169695Skan * The above copyright and patent license is granted only if the following 39169695Skan * conditions are met: 40169695Skan * 41169695Skan * 3. Conditions 42169695Skan * 43169695Skan * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44169695Skan * Redistribution of source code of any substantial portion of the Covered 45169695Skan * Code or modification with rights to further distribute source must include 46169695Skan * the above Copyright Notice, the above License, this list of Conditions, 47169695Skan * and the following Disclaimer and Export Compliance provision. In addition, 48169695Skan * Licensee must cause all Covered Code to which Licensee contributes to 49169695Skan * contain a file documenting the changes Licensee made to create that Covered 50169695Skan * Code and the date of any change. Licensee must include in that file the 51169695Skan * documentation of any changes made by any predecessor Licensee. Licensee 52169695Skan * must include a prominent statement that the modification is derived, 53169695Skan * directly or indirectly, from Original Intel Code. 54169695Skan * 55169695Skan * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56169695Skan * Redistribution of source code of any substantial portion of the Covered 57169695Skan * Code or modification without rights to further distribute source must 58169695Skan * include the following Disclaimer and Export Compliance provision in the 59169695Skan * documentation and/or other materials provided with distribution. In 60169695Skan * addition, Licensee may not authorize further sublicense of source of any 61169695Skan * portion of the Covered Code, and must include terms to the effect that the 62169695Skan * license from Licensee to its licensee is limited to the intellectual 63169695Skan * property embodied in the software Licensee provides to its licensee, and 64169695Skan * not to intellectual property embodied in modifications its licensee may 65169695Skan * make. 66169695Skan * 67169695Skan * 3.3. Redistribution of Executable. Redistribution in executable form of any 68169695Skan * substantial portion of the Covered Code or modification must reproduce the 69169695Skan * above Copyright Notice, and the following Disclaimer and Export Compliance 70169695Skan * provision in the documentation and/or other materials provided with the 71169695Skan * distribution. 72169695Skan * 73169695Skan * 3.4. Intel retains all right, title, and interest in and to the Original 74169695Skan * Intel Code. 75169695Skan * 76169695Skan * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77169695Skan * Intel shall be used in advertising or otherwise to promote the sale, use or 78169695Skan * other dealings in products derived from or relating to the Covered Code 79169695Skan * without prior written authorization from Intel. 80169695Skan * 81169695Skan * 4. Disclaimer and Export Compliance 82169695Skan * 83169695Skan * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84169695Skan * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85169695Skan * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86169695Skan * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87169695Skan * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88169695Skan * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89169695Skan * PARTICULAR PURPOSE. 90169695Skan * 91169695Skan * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92169695Skan * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93169695Skan * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94169695Skan * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95169695Skan * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96169695Skan * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97169695Skan * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98169695Skan * LIMITED REMEDY. 99169695Skan * 100169695Skan * 4.3. Licensee shall not export, either directly or indirectly, any of this 101169695Skan * software or system incorporating such software without first obtaining any 102169695Skan * required license or other approval from the U. S. Department of Commerce or 103169695Skan * any other agency or department of the United States Government. In the 104169695Skan * event Licensee exports any such software from the United States or 105169695Skan * re-exports any such software from a foreign destination, Licensee shall 106169695Skan * ensure that the distribution and export/re-export of the software is in 107169695Skan * compliance with all laws, regulations, orders, or other restrictions of the 108169695Skan * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109169695Skan * any of its subsidiaries will export/re-export any technical data, process, 110169695Skan * software, or service, directly or indirectly, to any country for which the 111169695Skan * United States government or any agency thereof requires an export license, 112169695Skan * other governmental approval, or letter of assurance, without first obtaining 113169695Skan * such license, approval or letter. 114169695Skan * 115169695Skan *****************************************************************************/ 116169695Skan 117169695Skan#define __EVXFREGN_C__ 118169695Skan 119169695Skan#include "acpi.h" 120169695Skan#include "accommon.h" 121169695Skan#include "acnamesp.h" 122169695Skan#include "acevents.h" 123169695Skan 124169695Skan#define _COMPONENT ACPI_EVENTS 125169695Skan ACPI_MODULE_NAME ("evxfregn") 126169695Skan 127169695Skan 128169695Skan/******************************************************************************* 129169695Skan * 130169695Skan * FUNCTION: AcpiInstallAddressSpaceHandler 131169695Skan * 132169695Skan * PARAMETERS: Device - Handle for the device 133169695Skan * SpaceId - The address space ID 134169695Skan * Handler - Address of the handler 135169695Skan * Setup - Address of the setup function 136169695Skan * Context - Value passed to the handler on each access 137169695Skan * 138169695Skan * RETURN: Status 139169695Skan * 140169695Skan * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId. 141169695Skan * 142169695Skan ******************************************************************************/ 143169695Skan 144169695SkanACPI_STATUS 145169695SkanAcpiInstallAddressSpaceHandler ( 146169695Skan ACPI_HANDLE Device, 147169695Skan ACPI_ADR_SPACE_TYPE SpaceId, 148169695Skan ACPI_ADR_SPACE_HANDLER Handler, 149169695Skan ACPI_ADR_SPACE_SETUP Setup, 150169695Skan void *Context) 151169695Skan{ 152169695Skan ACPI_NAMESPACE_NODE *Node; 153169695Skan ACPI_STATUS Status; 154169695Skan 155169695Skan 156169695Skan ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler); 157169695Skan 158169695Skan 159169695Skan /* Parameter validation */ 160169695Skan 161169695Skan if (!Device) 162169695Skan { 163169695Skan return_ACPI_STATUS (AE_BAD_PARAMETER); 164169695Skan } 165169695Skan 166169695Skan Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 167169695Skan if (ACPI_FAILURE (Status)) 168169695Skan { 169169695Skan return_ACPI_STATUS (Status); 170169695Skan } 171169695Skan 172169695Skan /* Convert and validate the device handle */ 173169695Skan 174169695Skan Node = AcpiNsMapHandleToNode (Device); 175169695Skan if (!Node) 176169695Skan { 177169695Skan Status = AE_BAD_PARAMETER; 178169695Skan goto UnlockAndExit; 179169695Skan } 180169695Skan 181169695Skan /* Install the handler for all Regions for this Space ID */ 182169695Skan 183169695Skan Status = AcpiEvInstallSpaceHandler (Node, SpaceId, Handler, Setup, Context); 184169695Skan if (ACPI_FAILURE (Status)) 185169695Skan { 186169695Skan goto UnlockAndExit; 187169695Skan } 188169695Skan 189169695Skan /* Run all _REG methods for this address space */ 190169695Skan 191169695Skan Status = AcpiEvExecuteRegMethods (Node, SpaceId); 192169695Skan 193169695SkanUnlockAndExit: 194169695Skan (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 195169695Skan return_ACPI_STATUS (Status); 196169695Skan} 197169695Skan 198169695SkanACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler) 199169695Skan 200169695Skan 201169695Skan/******************************************************************************* 202169695Skan * 203169695Skan * FUNCTION: AcpiRemoveAddressSpaceHandler 204169695Skan * 205169695Skan * PARAMETERS: Device - Handle for the device 206169695Skan * SpaceId - The address space ID 207169695Skan * Handler - Address of the handler 208169695Skan * 209169695Skan * RETURN: Status 210169695Skan * 211169695Skan * DESCRIPTION: Remove a previously installed handler. 212169695Skan * 213169695Skan ******************************************************************************/ 214169695Skan 215169695SkanACPI_STATUS 216169695SkanAcpiRemoveAddressSpaceHandler ( 217169695Skan ACPI_HANDLE Device, 218169695Skan ACPI_ADR_SPACE_TYPE SpaceId, 219169695Skan ACPI_ADR_SPACE_HANDLER Handler) 220169695Skan{ 221169695Skan ACPI_OPERAND_OBJECT *ObjDesc; 222169695Skan ACPI_OPERAND_OBJECT *HandlerObj; 223169695Skan ACPI_OPERAND_OBJECT *RegionObj; 224169695Skan ACPI_OPERAND_OBJECT **LastObjPtr; 225169695Skan ACPI_NAMESPACE_NODE *Node; 226169695Skan ACPI_STATUS Status; 227169695Skan 228169695Skan 229169695Skan ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler); 230169695Skan 231169695Skan 232169695Skan /* Parameter validation */ 233169695Skan 234169695Skan if (!Device) 235169695Skan { 236169695Skan return_ACPI_STATUS (AE_BAD_PARAMETER); 237169695Skan } 238169695Skan 239169695Skan Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 240169695Skan if (ACPI_FAILURE (Status)) 241169695Skan { 242169695Skan return_ACPI_STATUS (Status); 243169695Skan } 244169695Skan 245169695Skan /* Convert and validate the device handle */ 246169695Skan 247169695Skan Node = AcpiNsMapHandleToNode (Device); 248169695Skan if (!Node || 249169695Skan ((Node->Type != ACPI_TYPE_DEVICE) && 250169695Skan (Node->Type != ACPI_TYPE_PROCESSOR) && 251169695Skan (Node->Type != ACPI_TYPE_THERMAL) && 252169695Skan (Node != AcpiGbl_RootNode))) 253169695Skan { 254169695Skan Status = AE_BAD_PARAMETER; 255169695Skan goto UnlockAndExit; 256169695Skan } 257169695Skan 258169695Skan /* Make sure the internal object exists */ 259169695Skan 260169695Skan ObjDesc = AcpiNsGetAttachedObject (Node); 261169695Skan if (!ObjDesc) 262169695Skan { 263169695Skan Status = AE_NOT_EXIST; 264169695Skan goto UnlockAndExit; 265169695Skan } 266169695Skan 267169695Skan /* Find the address handler the user requested */ 268169695Skan 269169695Skan HandlerObj = ObjDesc->Device.Handler; 270169695Skan LastObjPtr = &ObjDesc->Device.Handler; 271169695Skan while (HandlerObj) 272169695Skan { 273169695Skan /* We have a handler, see if user requested this one */ 274169695Skan 275169695Skan if (HandlerObj->AddressSpace.SpaceId == SpaceId) 276169695Skan { 277169695Skan /* Handler must be the same as the installed handler */ 278169695Skan 279169695Skan if (HandlerObj->AddressSpace.Handler != Handler) 280169695Skan { 281169695Skan Status = AE_BAD_PARAMETER; 282169695Skan goto UnlockAndExit; 283169695Skan } 284169695Skan 285169695Skan /* Matched SpaceId, first dereference this in the Regions */ 286169695Skan 287169695Skan ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 288169695Skan "Removing address handler %p(%p) for region %s " 289169695Skan "on Device %p(%p)\n", 290169695Skan HandlerObj, Handler, AcpiUtGetRegionName (SpaceId), 291169695Skan Node, ObjDesc)); 292169695Skan 293169695Skan RegionObj = HandlerObj->AddressSpace.RegionList; 294169695Skan 295169695Skan /* Walk the handler's region list */ 296169695Skan 297169695Skan while (RegionObj) 298169695Skan { 299169695Skan /* 300169695Skan * First disassociate the handler from the region. 301169695Skan * 302169695Skan * NOTE: this doesn't mean that the region goes away 303169695Skan * The region is just inaccessible as indicated to 304169695Skan * the _REG method 305169695Skan */ 306169695Skan AcpiEvDetachRegion (RegionObj, TRUE); 307169695Skan 308169695Skan /* 309169695Skan * Walk the list: Just grab the head because the 310169695Skan * DetachRegion removed the previous head. 311169695Skan */ 312169695Skan RegionObj = HandlerObj->AddressSpace.RegionList; 313169695Skan 314169695Skan } 315169695Skan 316169695Skan /* Remove this Handler object from the list */ 317169695Skan 318169695Skan *LastObjPtr = HandlerObj->AddressSpace.Next; 319169695Skan 320169695Skan /* Now we can delete the handler object */ 321169695Skan 322169695Skan AcpiUtRemoveReference (HandlerObj); 323169695Skan goto UnlockAndExit; 324169695Skan } 325169695Skan 326169695Skan /* Walk the linked list of handlers */ 327169695Skan 328169695Skan LastObjPtr = &HandlerObj->AddressSpace.Next; 329169695Skan HandlerObj = HandlerObj->AddressSpace.Next; 330169695Skan } 331169695Skan 332169695Skan /* The handler does not exist */ 333169695Skan 334169695Skan ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 335169695Skan "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n", 336169695Skan Handler, AcpiUtGetRegionName (SpaceId), SpaceId, Node, ObjDesc)); 337169695Skan 338169695Skan Status = AE_NOT_EXIST; 339169695Skan 340169695SkanUnlockAndExit: 341169695Skan (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 342169695Skan return_ACPI_STATUS (Status); 343169695Skan} 344169695Skan 345169695SkanACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler) 346169695Skan 347169695Skan