evregion.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/******************************************************************************
*
* Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
* $Revision: 156 $
*
*****************************************************************************/
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
#define __EVREGION_C__
#include "acpi.h"
#include "acevents.h"
#include "acnamesp.h"
#include "acinterp.h"
#define _COMPONENT ACPI_EVENTS
ACPI_MODULE_NAME ("evregion")
#define ACPI_NUM_DEFAULT_SPACES 4
/* Local prototypes */
static ACPI_STATUS
void *Context,
void **ReturnValue);
static ACPI_STATUS
void *Context,
void **ReturnValue);
/*******************************************************************************
*
* FUNCTION: AcpiEvInstallRegionHandlers
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Installs the core subsystem default address space handlers.
*
******************************************************************************/
void)
{
ACPI_FUNCTION_TRACE ("EvInstallRegionHandlers");
if (ACPI_FAILURE (Status))
{
}
/*
* All address spaces (PCI Config, EC, SMBus) are scope dependent
* and registration must occur for a specific device.
*
* In the case of the system memory and IO address spaces there is currently
* no device associated with the address space. For these we use the root.
*
* We install the default PCI config space handler at the root so
* that this space is immediately available even though the we have
* not enumerated all the PCI Root Buses yet. This is to conform
* to the ACPI specification which states that the PCI config
* space must be always available -- even though we are nowhere
* near ready to find the PCI root buses at this point.
*
* NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
* has already been installed (via AcpiInstallAddressSpaceHandler).
* Similar for AE_SAME_HANDLER.
*/
for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
{
switch (Status)
{
case AE_OK:
case AE_SAME_HANDLER:
case AE_ALREADY_EXISTS:
/* These exceptions are all OK */
break;
default:
goto UnlockAndExit;
}
}
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvInitializeOpRegions
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Execute _REG methods for all Operation Regions that have
* an installed default region handler.
*
******************************************************************************/
void)
{
ACPI_FUNCTION_TRACE ("EvInitializeOpRegions");
if (ACPI_FAILURE (Status))
{
}
/*
* Run the _REG methods for OpRegions in each default address space
*/
for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
{
/* TBD: Make sure handler is the DEFAULT handler, otherwise
* _REG will have already been run.
*/
}
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvExecuteRegMethod
*
* PARAMETERS: RegionObj - Region object
* Function - Passed to _REG: On (1) or Off (0)
*
* RETURN: Status
*
* DESCRIPTION: Execute _REG method for a region
*
******************************************************************************/
{
ACPI_FUNCTION_TRACE ("EvExecuteRegMethod");
if (!RegionObj2)
{
}
{
}
/*
* The _REG method has two arguments:
*
* Arg0, Integer: Operation region space ID
* Same value as RegionObj->Region.SpaceId
* Arg1, Integer: connection status
* 1 for connecting the handler,
* 0 for disconnecting the handler
* Passed as a parameter
*/
if (!Params[0])
{
}
if (!Params[1])
{
goto Cleanup;
}
/* Setup the parameter objects */
/* Execute the method, no return value */
AcpiUtRemoveReference (Params[0]);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvAddressSpaceDispatch
*
* PARAMETERS: RegionObj - Internal region object
* Function - Read or Write operation
* Address - Where in the space to read or write
* BitWidth - Field width in bits (8, 16, 32, or 64)
* Value - Pointer to in or out value
*
* RETURN: Status
*
* DESCRIPTION: Dispatch an address space or operation region access to
* a previously installed handler.
*
******************************************************************************/
void *Value)
{
void *RegionContext = NULL;
ACPI_FUNCTION_TRACE ("EvAddressSpaceDispatch");
if (!RegionObj2)
{
}
/* Ensure that there is a handler associated with this region */
if (!HandlerDesc)
{
"No handler for Region [%4.4s] (%p) [%s]\n",
}
/*
* It may be the case that the region has never been initialized
* Some types of regions require special init code
*/
{
/*
* This region has not been initialized yet, do it
*/
if (!RegionSetup)
{
/* No initialization routine, exit with error */
"No init routine for region(%p) [%s]\n",
}
/*
* We must exit the interpreter because the region
* setup will potentially execute control methods
* (e.g., _REG method for this region)
*/
/* Re-enter the interpreter */
if (ACPI_FAILURE (Status2))
{
}
/* Check for failure of the Region Setup */
if (ACPI_FAILURE (Status))
{
}
/*
* Region initialization may have been completed by RegionSetup
*/
{
{
/* The handler for this region was already installed */
}
else
{
/*
* Save the returned context for use in all accesses to
* this particular region
*/
}
}
}
/* We have everything we need, we can invoke the address space handler */
"Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
{
/*
* For handlers other than the default (supplied) handlers, we must
* exit the interpreter because the handler *might* block -- we don't
* know what it will do, so we can't hold the lock on the intepreter.
*/
}
/* Call the handler */
if (ACPI_FAILURE (Status))
{
ACPI_REPORT_ERROR (("Handler for [%s] returned %s\n",
}
{
/*
* We just returned from a non-default handler, we must re-enter the
* interpreter
*/
if (ACPI_FAILURE (Status2))
{
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiEvDetachRegion
*
* PARAMETERS: RegionObj - Region Object
* AcpiNsIsLocked - Namespace Region Already Locked?
*
* RETURN: None
*
* DESCRIPTION: Break the association between the handler and the region
* this is a two way association.
*
******************************************************************************/
void
{
void **RegionContext;
ACPI_FUNCTION_TRACE ("EvDetachRegion");
if (!RegionObj2)
{
}
/* Get the address handler from the region object */
if (!HandlerObj)
{
/* This region has no handler, all done */
}
/* Find this region in the handler's list */
while (ObjDesc)
{
/* Is this the correct Region? */
{
"Removing Region %p from address handler %p\n",
RegionObj, HandlerObj));
/* This is it, remove it from the handler's list */
if (AcpiNsIsLocked)
{
if (ACPI_FAILURE (Status))
{
}
}
/* Now stop region accesses by executing the _REG method */
if (ACPI_FAILURE (Status))
{
}
if (AcpiNsIsLocked)
{
if (ACPI_FAILURE (Status))
{
}
}
/* Call the setup handler with the deactivate notification */
/* Init routine may fail, Just ignore errors */
if (ACPI_FAILURE (Status))
{
}
/*
* Remove handler reference in the region
*
* NOTE: this doesn't mean that the region goes away
* The region is just inaccessible as indicated to
* the _REG method
*
* If the region is on the handler's list
* this better be the region's handler
*/
}
/* Walk the linked list of handlers */
}
/* If we get here, the region was not in the handler's region list */
"Cannot remove region %p from address handler %p\n",
RegionObj, HandlerObj));
}
/*******************************************************************************
*
* FUNCTION: AcpiEvAttachRegion
*
* PARAMETERS: HandlerObj - Handler Object
* RegionObj - Region Object
* AcpiNsIsLocked - Namespace Region Already Locked?
*
* RETURN: None
*
* DESCRIPTION: Create the association between the handler and the region
* this is a two way association.
*
******************************************************************************/
{
ACPI_FUNCTION_TRACE ("EvAttachRegion");
"Adding Region [%4.4s] %p to address handler %p [%s]\n",
/* Link this region to the front of the handler's list */
/* Install the region's handler */
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiEvInstallHandler
*
* PARAMETERS: WalkNamespace callback
*
* DESCRIPTION: This routine installs an address handler into objects that are
* of type Region or Device.
*
* If the Object is a Device, and the device has a handler of
* the same type then the search is terminated in that branch.
*
* This is because the existing handler is closer in proximity
* to any more regions than the one we are trying to install.
*
******************************************************************************/
static ACPI_STATUS
void *Context,
void **ReturnValue)
{
ACPI_FUNCTION_NAME ("EvInstallHandler");
/* Parameter validation */
if (!HandlerObj)
{
return (AE_OK);
}
/* Convert and validate the device handle */
if (!Node)
{
return (AE_BAD_PARAMETER);
}
/*
* We only care about regions.and objects
* that are allowed to have address space handlers
*/
(Node != AcpiGbl_RootNode))
{
return (AE_OK);
}
/* Check for an existing internal object */
if (!ObjDesc)
{
/* No object, just exit */
return (AE_OK);
}
/* Devices are handled different than regions */
{
/* Check if this Device already has a handler for this address space */
while (NextHandlerObj)
{
/* Found a handler, is it for the same address space? */
{
"Found handler for region [%s] in device %p(%p) handler %p\n",
/*
* Since the object we found it on was a device, then it
* means that someone has already installed a handler for
* the branch of the namespace from this device on. Just
* bail out telling the walk routine to not traverse this
* branch. This preserves the scoping rule for handlers.
*/
return (AE_CTRL_DEPTH);
}
/* Walk the linked list of handlers attached to this device */
}
/*
* As long as the device didn't have a handler for this
* space we don't care about it. We just ignore it and
* proceed.
*/
return (AE_OK);
}
/* Object is a Region */
{
/*
* This region is for a different address space
* -- just ignore it
*/
return (AE_OK);
}
/*
* Now we have a region and it is for the handler's address
* space type.
*
* First disconnect region for any previous handler (if any)
*/
/* Connect the region to the new handler */
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvInstallSpaceHandler
*
* PARAMETERS: Node - Namespace node for the device
* SpaceId - The address space ID
* Handler - Address of the handler
* Setup - Address of the setup function
* Context - Value passed to the handler on each access
*
* RETURN: Status
*
* DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
* Assumes namespace is locked
*
******************************************************************************/
void *Context)
{
ACPI_FUNCTION_TRACE ("EvInstallSpaceHandler");
/*
* This registration is valid for only the types below
* and the root. This is where the default handlers
* get placed.
*/
(Node != AcpiGbl_RootNode))
{
goto UnlockAndExit;
}
if (Handler == ACPI_DEFAULT_HANDLER)
{
switch (SpaceId)
{
break;
case ACPI_ADR_SPACE_SYSTEM_IO:
break;
break;
case ACPI_ADR_SPACE_CMOS:
break;
break;
break;
default:
goto UnlockAndExit;
}
}
/* If the caller hasn't specified a setup routine, use the default */
if (!Setup)
{
}
/* Check for an existing internal object */
if (ObjDesc)
{
/*
* The attached device object already exists.
* Make sure the handler is not already installed.
*/
/* Walk the handler list for this device */
while (HandlerObj)
{
/* Same SpaceId indicates a handler already installed */
{
{
/*
* It is (relatively) OK to attempt to install the SAME
* handler twice. This can easily happen
* with PCI_Config space.
*/
goto UnlockAndExit;
}
else
{
/* A handler is already installed */
}
goto UnlockAndExit;
}
/* Walk the linked list of handlers */
}
}
else
{
"Creating object on Device %p while installing handler\n", Node));
/* ObjDesc does not exist, create one */
{
}
else
{
}
if (!ObjDesc)
{
goto UnlockAndExit;
}
/* Init new descriptor */
/* Attach the new object to the Node */
/* Remove local reference to the object */
if (ACPI_FAILURE (Status))
{
goto UnlockAndExit;
}
}
"Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
/*
* Install the handler
*
* At this point there is no existing handler.
* Just allocate the object for the handler and link it
* into the list.
*/
if (!HandlerObj)
{
goto UnlockAndExit;
}
/* Init handler obj */
/* Install at head of Device.AddressSpace list */
/*
* The Device object is the first reference on the HandlerObj.
* Each region that uses the handler adds a reference.
*/
/*
* Walk the namespace finding all of the regions this
* handler will manage.
*
* Start at the device and search the branch toward
* the leaf nodes until either the leaf is encountered or
* a device is detected that has an address handler of the
* same type.
*
* In either case, back up and search down the remainder
* of the branch
*/
HandlerObj, NULL);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvExecuteRegMethods
*
* PARAMETERS: Node - Namespace node for the device
* SpaceId - The address space ID
*
* RETURN: Status
*
* DESCRIPTION: Run all _REG methods for the input Space ID;
* Note: assumes namespace is locked, or system init time.
*
******************************************************************************/
{
ACPI_FUNCTION_TRACE ("EvExecuteRegMethods");
/*
* Run all _REG methods for all Operation Regions for this
* space ID. This is a separate walk in order to handle any
* interdependencies between regions and _REG methods. (i.e. handlers
* must be installed for all regions of this Space ID before we
* can run any _REG methods)
*/
}
/*******************************************************************************
*
* FUNCTION: AcpiEvRegRun
*
* PARAMETERS: WalkNamespace callback
*
* DESCRIPTION: Run _REG method for region objects of the requested spaceID
*
******************************************************************************/
static ACPI_STATUS
void *Context,
void **ReturnValue)
{
/* Convert and validate the device handle */
if (!Node)
{
return (AE_BAD_PARAMETER);
}
/*
* We only care about regions.and objects
* that are allowed to have address space handlers
*/
(Node != AcpiGbl_RootNode))
{
return (AE_OK);
}
/* Check for an existing internal object */
if (!ObjDesc)
{
/* No object, just exit */
return (AE_OK);
}
/* Object is a Region */
{
/*
* This region is for a different address space
* -- just ignore it
*/
return (AE_OK);
}
return (Status);
}