evregion.c revision 26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0
/******************************************************************************
*
* Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2011, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#define __EVREGION_C__
#include "acpi.h"
#include "accommon.h"
#include "acevents.h"
#include "acnamesp.h"
#include "acinterp.h"
#define _COMPONENT ACPI_EVENTS
ACPI_MODULE_NAME ("evregion")
/* Local prototypes */
static BOOLEAN
static void
void);
static ACPI_STATUS
void *Context,
void **ReturnValue);
static ACPI_STATUS
void *Context,
void **ReturnValue);
/* These are the address spaces that will get default handlers */
#define ACPI_NUM_DEFAULT_SPACES 4
{
};
/*******************************************************************************
*
* FUNCTION: AcpiEvInstallRegionHandlers
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Installs the core subsystem default address space handlers.
*
******************************************************************************/
void)
{
UINT32 i;
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: AcpiEvHasDefaultHandler
*
* PARAMETERS: Node - Namespace node for the device
* SpaceId - The address space ID
*
* RETURN: TRUE if default handler is installed, FALSE otherwise
*
* DESCRIPTION: Check if the default handler is installed for the requested
* space ID.
*
******************************************************************************/
static BOOLEAN
{
/* Must have an existing internal object */
if (ObjDesc)
{
/* Walk the linked list of handlers for this object */
while (HandlerObj)
{
{
{
return (TRUE);
}
}
}
}
return (FALSE);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvInitializeOpRegions
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Execute _REG methods for all Operation Regions that have
* an installed default region handler.
*
******************************************************************************/
void)
{
UINT32 i;
if (ACPI_FAILURE (Status))
{
}
/* Run the _REG methods for OpRegions in each default address space */
for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
{
/*
* Make sure the installed handler is the DEFAULT handler. If not the
* default, the _REG methods will have already been run (when the
* handler was installed)
*/
{
}
}
(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
*
******************************************************************************/
{
if (!RegionObj2)
{
}
{
}
/* Allocate and initialize the evaluation information block */
if (!Info)
{
}
/*
* 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 (!Args[0])
{
goto Cleanup1;
}
if (!Args[1])
{
goto Cleanup2;
}
/* Execute the method, no return value */
AcpiUtRemoveReference (Args[0]);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvAddressSpaceDispatch
*
* PARAMETERS: RegionObj - Internal region object
* Function - Read or Write operation
* RegionOffset - Where in the region to read or write
* BitWidth - Field width in bits (8, 16, 32, or 64)
* Value - Pointer to in or out value, must be
* a full 64-bit integer
*
* RETURN: Status
*
* DESCRIPTION: Dispatch an address space or operation region access to
* a previously installed handler.
*
******************************************************************************/
{
void *RegionContext = NULL;
if (!RegionObj2)
{
}
/* Ensure that there is a handler associated with this region */
if (!HandlerDesc)
{
"No handler for Region [%4.4s] (%p) [%s]",
}
/*
* 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]",
}
/*
* We must exit the interpreter because the region setup will
* potentially execute control methods (for example, the _REG method
* for this region)
*/
/* Re-enter the interpreter */
/* Check for failure of the Region Setup */
if (ACPI_FAILURE (Status))
{
"During region initialization: [%s]",
}
/* 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))
{
}
{
/*
* We just returned from a non-default handler, we must re-enter the
* interpreter
*/
}
}
/*******************************************************************************
*
* 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;
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))
{
}
}
/*
* If the region has been activated, call the setup handler with
* the deactivate notification
*/
{
/* Init routine may fail, Just ignore errors */
if (ACPI_FAILURE (Status))
{
"from region handler - deactivate, [%s]",
}
}
/*
* 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 must 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.
*
******************************************************************************/
{
"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)
{
/* 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)
{
/*
* 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 the
* 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.
*
******************************************************************************/
{
/*
* 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)
*/
/* Special case for EC: handle "orphan" _REG methods with no region */
if (SpaceId == ACPI_ADR_SPACE_EC)
{
}
}
/*******************************************************************************
*
* 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);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvOrphanEcRegMethod
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Execute an "orphan" _REG method that appears under the EC
* device. This is a _REG method that has no corresponding region
* within the EC device scope. The orphan _REG method appears to
* have been enabled by the description of the ECDT in the ACPI
* specification: "The availability of the region space can be
* detected by providing a _REG method object underneath the
* Embedded Controller device."
*
* To quickly access the EC device, we use the EC_ID that appears
* within the ECDT. Otherwise, we would need to perform a time-
* consuming namespace walk, executing _HID methods to find the
* EC device.
*
******************************************************************************/
static void
void)
{
/* Get the ECDT (if present in system) */
if (ACPI_FAILURE (Status))
{
}
/* We need a valid EC_ID string */
{
}
/* Namespace is currently locked, must release */
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
/* Get a handle to the EC device referenced in the ECDT */
if (ACPI_FAILURE (Status))
{
goto Exit;
}
/* Get a handle to a _REG method immediately under the EC device */
if (ACPI_FAILURE (Status))
{
goto Exit;
}
/*
* Execute the _REG method only if there is no Operation Region in
* this scope with the Embedded Controller space ID. Otherwise, it
* will already have been executed. Note, this allows for Regions
* with other space IDs to be present; but the code below will then
* execute the _REG method with the EC space ID argument.
*/
while (NextNode)
{
{
goto Exit; /* Do not execute _REG */
}
}
/* Evaluate the _REG(EC,Connect) method */
Exit:
/* We ignore all errors from above, don't care */
}