/******************************************************************************
*
* Module Name: evregion - Operation Region support
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, 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.
*/
#include "acpi.h"
#include "accommon.h"
#include "acevents.h"
#include "acnamesp.h"
#include "acinterp.h"
ACPI_MODULE_NAME ("evregion")
extern UINT8 AcpiGbl_DefaultAddressSpaces[];
/* Local prototypes */
static void
static ACPI_STATUS
void *Context,
void **ReturnValue);
/*******************************************************************************
*
* 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: AcpiEvAddressSpaceDispatch
*
* PARAMETERS: RegionObj - Internal region object
* FieldObj - Corresponding field. Can be NULL.
* 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.
*
* NOTE: During early initialization, we always install the default region
* handlers for Memory, I/O and PCI_Config. This ensures that these operation
* region address spaces are always available as per the ACPI specification.
* This is especially needed in order to support the execution of
* module-level AML code during loading of the ACPI tables.
*
******************************************************************************/
{
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)
*/
Context, &RegionContext);
/* 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 */
{
/*
* Save the returned context for use in all accesses to
* the handler for this particular region
*/
{
}
}
}
/* We have everything we need, we can invoke the address space handler */
/*
* Special handling for GenericSerialBus and GeneralPurposeIo:
* There are three extra parameters that must be passed to the
* handler via the context:
* 1) Connection buffer, a resource template from Connection() op
* 2) Length of the above buffer
* 3) Actual access length from the AccessAs() op
*
* In addition, for GeneralPurposeIo, the Address and BitWidth fields
* are defined as follows:
* 1) Address is the pin number index of the field (bit offset from
* the previous Connection)
* 2) BitWidth is the actual bit length of the field (number of pins)
*/
Context &&
{
/* Get the Connection (ResourceTemplate) buffer */
}
Context &&
{
/* Get the Connection (ResourceTemplate) buffer */
}
"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
*/
{
/*
* RegionContext should have been released by the deactivate
* operation. We don't need access to it anymore here.
*/
if (RegionContext)
{
*RegionContext = NULL;
}
/* 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 */
/* Prevent infinite loop if list is corrupted */
{
"Circular handler list in region object %p",
RegionObj));
}
}
/* 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.
*
******************************************************************************/
{
/* Install the region's handler */
{
}
"Adding Region [%4.4s] %p to address handler %p [%s]\n",
/* Link this region to the front of the handler's list */
}
/*******************************************************************************
*
* 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 (!AcpiGbl_NamespaceInitialized ||
{
}
if (!RegionObj2)
{
}
/*
* Find any "_REG" method associated with this region definition.
* The method should always be updated as this function may be
* invoked after a namespace change.
*/
if (ACPI_SUCCESS (Status))
{
/*
* The _REG method is optional and there can be only one per
* region definition. This will be executed when the handler is
* attached or removed.
*/
}
{
}
/* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
if ((Function == ACPI_REG_CONNECT &&
(Function == ACPI_REG_DISCONNECT &&
{
}
/* 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 */
if (ACPI_FAILURE (Status))
{
goto Cleanup2;
}
if (Function == ACPI_REG_CONNECT)
{
}
else
{
}
AcpiUtRemoveReference (Args[0]);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvExecuteRegMethods
*
* PARAMETERS: Node - Namespace node for the device
* SpaceId - The address space ID
* Function - Passed to _REG: On (1) or Off (0)
*
* RETURN: None
*
* DESCRIPTION: Run all _REG methods for the input Space ID;
* Note: assumes namespace is locked, or system init time.
*
******************************************************************************/
void
{
Info.RegRunCount = 0;
" Running _REG methods for SpaceId %s\n",
/*
* 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)
{
}
" Executed %u _REG methods for SpaceId %s\n",
}
/*******************************************************************************
*
* 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);
}
Info->RegRunCount++;
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvOrphanEcRegMethod
*
* PARAMETERS: EcDeviceNode - Namespace node for an EC device
*
* 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 EcDeviceNode used
* during EC handler installation. Otherwise, we would need to
* perform a time consuming namespace walk, executing _HID
* methods to find the EC device.
*
* MUTEX: Assumes the namespace is locked
*
******************************************************************************/
static void
{
if (!EcDeviceNode)
{
}
/* Namespace is currently locked, must release */
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
/* Get a handle to a _REG method immediately under the EC device */
if (ACPI_FAILURE (Status))
{
goto Exit; /* There is no _REG method present */
}
/*
* 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 EmbeddedControl SpaceID argument.
*/
while (NextNode)
{
{
goto Exit; /* Do not execute the _REG */
}
}
/* Evaluate the _REG(EmbeddedControl,Connect) method */
Exit:
/* We ignore all errors from above, don't care */
}