evxface.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: evxface - External interfaces for ACPI events
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2015, 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 EXPORT_ACPI_INTERFACES
#define _COMPONENT ACPI_EVENTS
ACPI_MODULE_NAME ("evxface")
#if (!ACPI_REDUCED_HARDWARE)
/* Local prototypes */
static ACPI_STATUS
void *Context);
#endif
/*******************************************************************************
*
* FUNCTION: AcpiInstallNotifyHandler
*
* PARAMETERS: Device - The device for which notifies will be handled
* HandlerType - The type of handler:
* ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
* ACPI_DEVICE_NOTIFY: Device Handler (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 notifications on an ACPI Device,
* ThermalZone, or Processor object.
*
* NOTES: The Root namespace object may have only one handler for each
* may have one device notify handler, and multiple system notify
* handlers.
*
******************************************************************************/
void *Context)
{
UINT32 i;
/* Parameter validation */
{
}
if (ACPI_FAILURE (Status))
{
}
/*
* 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 global handler can be registered per notify type.
* Ensure that a handler is not already installed.
*/
if (Device == ACPI_ROOT_OBJECT)
{
for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
{
if (HandlerType & (i+1))
{
if (AcpiGbl_GlobalNotify[i].Handler)
{
goto UnlockAndExit;
}
}
}
goto UnlockAndExit; /* Global notify handler installed, all done */
}
/*
* All Other Objects:
* Caller will only receive notifications specific to the target
* object. Note that only certain object types are allowed to
* receive notifications.
*/
/* Are Notifies allowed on this object? */
if (!AcpiEvIsNotifyObject (Node))
{
goto UnlockAndExit;
}
/* Check for an existing internal object, might not exist */
if (!ObjDesc)
{
/* Create a new object */
if (!ObjDesc)
{
goto UnlockAndExit;
}
/* Attach new object to the Node, remove local reference */
if (ACPI_FAILURE (Status))
{
goto UnlockAndExit;
}
}
/* Ensure that the handler is not already installed in the lists */
for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
{
if (HandlerType & (i+1))
{
while (HandlerObj)
{
{
goto UnlockAndExit;
}
}
}
}
/* Create and populate a new notify handler object */
if (!HandlerObj)
{
goto UnlockAndExit;
}
/* Install the handler at the list head(s) */
for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
{
if (HandlerType & (i+1))
{
}
}
/* Add an extra reference if handler was installed in both lists */
if (HandlerType == ACPI_ALL_NOTIFY)
{
}
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
}
/*******************************************************************************
*
* FUNCTION: AcpiRemoveNotifyHandler
*
* PARAMETERS: Device - The device for which the handler is installed
* HandlerType - The type of handler:
* ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
* ACPI_DEVICE_NOTIFY: Device Handler (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
*
******************************************************************************/
{
UINT32 i;
/* Parameter validation */
{
}
/* Root Object. Global handlers are removed here */
if (Device == ACPI_ROOT_OBJECT)
{
for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
{
if (HandlerType & (i+1))
{
if (ACPI_FAILURE (Status))
{
}
if (!AcpiGbl_GlobalNotify[i].Handler ||
{
goto UnlockAndExit;
}
"Removing global notify handler\n"));
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
/* Make sure all deferred notify tasks are completed */
}
}
}
/* All other objects: Are Notifies allowed on this object? */
if (!AcpiEvIsNotifyObject (Node))
{
}
/* Must have an existing internal object */
if (!ObjDesc)
{
}
/* Internal object exists. Find the handler and remove it */
for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
{
if (HandlerType & (i+1))
{
if (ACPI_FAILURE (Status))
{
}
/* Attempt to find the handler in the handler list */
while (HandlerObj &&
{
}
if (!HandlerObj)
{
goto UnlockAndExit;
}
/* Remove the handler object from the list */
if (PreviousHandlerObj) /* Handler is not at the list head */
{
}
else /* Handler is at the list head */
{
}
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
/* Make sure all deferred notify tasks are completed */
}
}
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
}
/*******************************************************************************
*
* 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);
}
#if (!ACPI_REDUCED_HARDWARE)
/*******************************************************************************
*
* FUNCTION: AcpiInstallSciHandler
*
* PARAMETERS: Address - Address of the handler
* Context - Value passed to the handler on each SCI
*
* RETURN: Status
*
* DESCRIPTION: Install a handler for a System Control Interrupt.
*
******************************************************************************/
void *Context)
{
if (!Address)
{
}
/* Allocate and init a handler object */
if (!NewSciHandler)
{
}
if (ACPI_FAILURE (Status))
{
goto Exit;
}
/* Lock list during installation */
/* Ensure handler does not already exist */
while (SciHandler)
{
{
goto UnlockAndExit;
}
}
/* Install the new handler into the global list (at head) */
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
Exit:
if (ACPI_FAILURE (Status))
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiRemoveSciHandler
*
* PARAMETERS: Address - Address of the handler
*
* RETURN: Status
*
* DESCRIPTION: Remove a handler for a System Control Interrupt.
*
******************************************************************************/
{
if (!Address)
{
}
if (ACPI_FAILURE (Status))
{
}
/* Remove the SCI handler with lock */
while (NextSciHandler)
{
{
/* Unlink and free the SCI handler info block */
if (PrevSciHandler)
{
}
else
{
}
goto UnlockAndExit;
}
}
(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))
{
}
/* Do not allow multiple handlers */
{
goto Cleanup;
}
/* Install the handler before enabling the event */
if (ACPI_FAILURE (Status))
{
"Could not enable fixed event - %s (%u)",
/* Remove the handler */
}
else
{
"Enabled fixed event %s (%X), Handler=%p\n",
}
(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 disable fixed event - %s (%u)",
}
else
{
"Disabled fixed event - %s (%X)\n",
}
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
}
/*******************************************************************************
*
* FUNCTION: AcpiEvInstallGpeHandler
*
* 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.
* IsRawHandler - Whether this GPE should be handled using
* the special GPE handler mode.
* Address - Address of the handler
* Context - Value passed to the handler on each GPE
*
* RETURN: Status
*
* DESCRIPTION: Internal function to install a handler for a General Purpose
* Event.
*
******************************************************************************/
static ACPI_STATUS
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: 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)
{
}
/*******************************************************************************
*
* FUNCTION: AcpiInstallGpeRawHandler
*
* 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)
{
}
/*******************************************************************************
*
* 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);
}
(void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
/* Make sure all deferred GPE tasks are completed */
/* 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);
}
#endif /* !ACPI_REDUCED_HARDWARE */