/******************************************************************************
*
* Module Name: evhandler - Support for Address Space handlers
*
*****************************************************************************/
/*
* 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 ("evhandler")
/* Local prototypes */
static ACPI_STATUS
void *Context,
void **ReturnValue);
/* These are the address spaces that will get default handlers */
{
};
/*******************************************************************************
*
* 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.
*
******************************************************************************/
{
/* Must have an existing internal object */
if (ObjDesc)
{
/* Walk the linked list of handlers for this object */
while (HandlerObj)
{
{
{
return (TRUE);
}
}
}
}
return (FALSE);
}
/*******************************************************************************
*
* 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 */
if (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);
}
/*
* 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: AcpiEvFindRegionHandler
*
* PARAMETERS: SpaceId - The address space ID
* HandlerObj - Head of the handler object list
*
* RETURN: Matching handler object. NULL if space ID not matched
*
* DESCRIPTION: Search a handler object list for a match on the address
* space ID.
*
******************************************************************************/
{
/* Walk the handler list for this device */
while (HandlerObj)
{
/* Same SpaceId indicates a handler is installed */
{
return (HandlerObj);
}
/* Next handler object */
}
return (NULL);
}
/*******************************************************************************
*
* 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.
* The root node is where the default handlers get installed.
*/
(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. Now make sure
* the handler is not already installed.
*/
if (HandlerObj)
{
{
/*
* 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;
}
}
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
*/
}