evxface.c revision 26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0
/******************************************************************************
*
* Module Name: evxface - External interfaces for ACPI events
*
*****************************************************************************/
/*
* 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 __EVXFACE_C__
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acevents.h"
#include "acinterp.h"
#define _COMPONENT ACPI_EVENTS
ACPI_MODULE_NAME ("evxface")
/*******************************************************************************
*
* FUNCTION: AcpiInstallExceptionHandler
*
* PARAMETERS: Handler - Pointer to the handler function for the
* event
*
* RETURN: Status
*
* DESCRIPTION: Saves the pointer to the handler function
*
******************************************************************************/
{
if (ACPI_FAILURE (Status))
{
}
/* Don't allow two handlers. */
{
goto Cleanup;
}
/* Install the handler */
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
}
/*******************************************************************************
*
* FUNCTION: AcpiInstallGlobalEventHandler
*
* PARAMETERS: Handler - Pointer to the global event handler function
* Context - Value passed to the handler on each event
*
* RETURN: Status
*
* DESCRIPTION: Saves the pointer to the handler function. The global handler
* is invoked upon each incoming GPE and Fixed Event. It is
* invoked at interrupt level at the time of the event dispatch.
* Can be used to update event counters, etc.
*
******************************************************************************/
void *Context)
{
/* Parameter validation */
if (!Handler)
{
}
if (ACPI_FAILURE (Status))
{
}
/* Don't allow two handlers. */
{
goto Cleanup;
}
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
}
/*******************************************************************************
*
* FUNCTION: AcpiInstallFixedEventHandler
*
* PARAMETERS: Event - Event type to enable.
* Handler - Pointer to the handler function for the
* event
* Context - Value passed to the handler on each GPE
*
* RETURN: Status
*
* DESCRIPTION: Saves the pointer to the handler function and then enables the
* event.
*
******************************************************************************/
void *Context)
{
/* Parameter validation */
if (Event > ACPI_EVENT_MAX)
{
}
if (ACPI_FAILURE (Status))
{
}
/* Don't allow two handlers. */
{
goto Cleanup;
}
/* Install the handler before enabling the event */
if (ACPI_FAILURE (Status))
{
/* Remove the handler */
}
else
{
}
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
}
/*******************************************************************************
*
* FUNCTION: AcpiRemoveFixedEventHandler
*
* PARAMETERS: Event - Event type to disable.
* Handler - Address of the handler
*
* RETURN: Status
*
* DESCRIPTION: Disables the event and unregisters the event handler.
*
******************************************************************************/
{
/* Parameter validation */
if (Event > ACPI_EVENT_MAX)
{
}
if (ACPI_FAILURE (Status))
{
}
/* Disable the event before removing the handler */
/* Always Remove the handler */
if (ACPI_FAILURE (Status))
{
"Could not write to fixed event enable register 0x%X", Event));
}
else
{
}
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
}
/*******************************************************************************
*
* FUNCTION: AcpiInstallNotifyHandler
*
* PARAMETERS: Device - The device for which notifies will be handled
* HandlerType - The type of handler:
* ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
* ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
* ACPI_ALL_NOTIFY: both system and device
* Handler - Address of the handler
* Context - Value passed to the handler on each GPE
*
* RETURN: Status
*
* DESCRIPTION: Install a handler for notifies on an ACPI device
*
******************************************************************************/
void *Context)
{
/* Parameter validation */
if ((!Device) ||
(!Handler) ||
{
}
if (ACPI_FAILURE (Status))
{
}
/* Convert and validate the device handle */
if (!Node)
{
goto UnlockAndExit;
}
/*
* Root Object:
* Registering a notify handler on the root object indicates that the
* caller wishes to receive notifications for all objects. Note that
* only one <external> global handler can be regsitered (per notify type).
*/
if (Device == ACPI_ROOT_OBJECT)
{
/* Make sure the handler is not already installed */
if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
((HandlerType & ACPI_DEVICE_NOTIFY) &&
{
goto UnlockAndExit;
}
if (HandlerType & ACPI_SYSTEM_NOTIFY)
{
}
if (HandlerType & ACPI_DEVICE_NOTIFY)
{
}
/* Global notify handler installed */
}
/*
* All Other Objects:
* Caller will only receive notifications specific to the target object.
* Note that only certain object types can receive notifications.
*/
else
{
/* Notifies allowed on this object? */
if (!AcpiEvIsNotifyObject (Node))
{
goto UnlockAndExit;
}
/* Check for an existing internal object */
if (ObjDesc)
{
/* Object exists - make sure there's no handler */
if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
((HandlerType & ACPI_DEVICE_NOTIFY) &&
{
goto UnlockAndExit;
}
}
else
{
/* Create a new object */
if (!ObjDesc)
{
goto UnlockAndExit;
}
/* Attach new object to the Node */
/* Remove local reference to the object */
if (ACPI_FAILURE (Status))
{
goto UnlockAndExit;
}
}
/* Install the handler */
if (!NotifyObj)
{
goto UnlockAndExit;
}
if (HandlerType & ACPI_SYSTEM_NOTIFY)
{
}
if (HandlerType & ACPI_DEVICE_NOTIFY)
{
}
if (HandlerType == ACPI_ALL_NOTIFY)
{
/* Extra ref if installed in both */
}
}
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
}
/*******************************************************************************
*
* FUNCTION: AcpiRemoveNotifyHandler
*
* PARAMETERS: Device - The device for which notifies will be handled
* HandlerType - The type of handler:
* ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
* ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
* ACPI_ALL_NOTIFY: both system and device
* Handler - Address of the handler
*
* RETURN: Status
*
* DESCRIPTION: Remove a handler for notifies on an ACPI device
*
******************************************************************************/
{
/* Parameter validation */
if ((!Device) ||
(!Handler) ||
{
}
if (ACPI_FAILURE (Status))
{
}
/* Convert and validate the device handle */
if (!Node)
{
goto UnlockAndExit;
}
/* Root Object */
if (Device == ACPI_ROOT_OBJECT)
{
"Removing notify handler for namespace root object\n"));
if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
((HandlerType & ACPI_DEVICE_NOTIFY) &&
{
goto UnlockAndExit;
}
if (HandlerType & ACPI_SYSTEM_NOTIFY)
{
}
if (HandlerType & ACPI_DEVICE_NOTIFY)
{
}
}
/* All Other Objects */
else
{
/* Notifies allowed on this object? */
if (!AcpiEvIsNotifyObject (Node))
{
goto UnlockAndExit;
}
/* Check for an existing internal object */
if (!ObjDesc)
{
goto UnlockAndExit;
}
/* Object exists - make sure there's an existing handler */
if (HandlerType & ACPI_SYSTEM_NOTIFY)
{
if (!NotifyObj)
{
goto UnlockAndExit;
}
{
goto UnlockAndExit;
}
/* Remove the handler */
}
if (HandlerType & ACPI_DEVICE_NOTIFY)
{
if (!NotifyObj)
{
goto UnlockAndExit;
}
{
goto UnlockAndExit;
}
/* Remove the handler */
}
}
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
}
/*******************************************************************************
*
* FUNCTION: AcpiInstallGpeHandler
*
* PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
* defined GPEs)
* GpeNumber - The GPE number within the GPE block
* Type - Whether this GPE should be treated as an
* edge- or level-triggered interrupt.
* Address - Address of the handler
* Context - Value passed to the handler on each GPE
*
* RETURN: Status
*
* DESCRIPTION: Install a handler for a General Purpose Event.
*
******************************************************************************/
void *Context)
{
/* Parameter validation */
{
}
if (ACPI_FAILURE (Status))
{
}
/* Allocate and init handler object (before lock) */
if (!Handler)
{
goto UnlockAndExit;
}
/* Ensure that we have a valid GPE number */
if (!GpeEventInfo)
{
goto FreeAndExit;
}
/* Make sure that there isn't a handler there already */
{
goto FreeAndExit;
}
/*
* If the GPE is associated with a method, it may have been enabled
* automatically during initialization, in which case it has to be
* disabled now to avoid spurious execution of the handler.
*/
{
(void) AcpiEvRemoveGpeReference (GpeEventInfo);
/* Sanity check of original type against new type */
{
}
}
/* Install the handler */
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
goto UnlockAndExit;
}
/*******************************************************************************
*
* FUNCTION: AcpiRemoveGpeHandler
*
* PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
* defined GPEs)
* GpeNumber - The event to remove a handler
* Address - Address of the handler
*
* RETURN: Status
*
* DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
*
******************************************************************************/
{
/* Parameter validation */
if (!Address)
{
}
if (ACPI_FAILURE (Status))
{
}
/* Ensure that we have a valid GPE number */
if (!GpeEventInfo)
{
goto UnlockAndExit;
}
/* Make sure that a handler is indeed installed */
{
goto UnlockAndExit;
}
/* Make sure that the installed handler is the same */
{
goto UnlockAndExit;
}
/* Remove the handler */
/* Restore Method node (if any), set dispatch flags */
GpeEventInfo->Flags &=
/*
* If the GPE was previously associated with a method and it was
* enabled, it should be enabled at this point to restore the
* post-initialization configuration.
*/
{
(void) AcpiEvAddGpeReference (GpeEventInfo);
}
/* Now we can free the handler object */
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
}
/*******************************************************************************
*
* FUNCTION: AcpiAcquireGlobalLock
*
* PARAMETERS: Timeout - How long the caller is willing to wait
* Handle - Where the handle to the lock is returned
* (if acquired)
*
* RETURN: Status
*
* DESCRIPTION: Acquire the ACPI Global Lock
*
* Note: Allows callers with the same thread ID to acquire the global lock
* multiple times. In other words, externally, the behavior of the global lock
* is identical to an AML mutex. On the first acquire, a new handle is
* returned. On any subsequent calls to acquire by the same thread, the same
* handle is returned.
*
******************************************************************************/
{
if (!Handle)
{
return (AE_BAD_PARAMETER);
}
/* Must lock interpreter to prevent race conditions */
if (ACPI_SUCCESS (Status))
{
/* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
}
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiReleaseGlobalLock
*
* PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
*
* RETURN: Status
*
* DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
*
******************************************************************************/
{
{
return (AE_NOT_ACQUIRED);
}
return (Status);
}