Skip to content

Commit

Permalink
Events: Introduce ACPI_GPE_DISPATCH_RAW_HANDLER to fix 2 issues for t…
Browse files Browse the repository at this point in the history
…he current GPE APIs.

Since whether the GPE should be disabled/enabled/cleared should only be
determined by the GPE driver's state machine:
1. GPE should be disabled if the driver wants to switch to the GPE polling
   mode when a GPE storm condition is indicated and should be enabled if
   the driver wants to switch back to the GPE interrupt mode when all of
   the storm conditions are cleared. The conditions should be protected by
   the driver's specific lock.
2. GPE should be enabled if the driver has accepted more than one request
   and should be disabled if the driver has completed all of the requests.
   The request count should be protected by the driver's specific lock.
3. GPE should be cleared either when the driver is about to handle an edge
   triggered GPE or when the driver has completed to handle a level
   triggered GPE. The handling code should be protected by the driver's
   specific lock.
Thus the GPE enabling/disabling/clearing operations are likely to be
performed with the driver's specific lock held while we currently cannot do
this. This is because:
1. We have the AcpiGbl_GpeLock held before invoking the GPE driver's
   handler. Driver's specific lock is likely to be held inside of the
   handler, thus we can see some dead lock issues due to the reversed
   locking order or recursive locking. In order to solve such dead lock
   issues, we need to unlock the AcpiGbl_GpeLock before invoking the
   handler. BZ 1100.
2. Since GPE disabling/enabling/clearing should be determined by the GPE
   driver's state machine, we shouldn't perform such operations inside of
   ACPICA for a GPE handler to mess up the driver's state machine. BZ 1101.

Originally this patch includes a logic to flush GPE handlers, it is dropped
due to the following reasons:
1. This is a different issue;
2. Linux OSL has fixed this by flushing SCI in AcpiOsWaitEventsComplete().
We will pick up this topic when the Linux OSL fix turns out to be not
sufficient.

Note that currently the internal operations and the AcpiGbl_GpeLock are
also used by ACPI_GPE_DISPATCH_METHOD and ACPI_GPE_DISPATCH_NOTIFY. In
order not to introduce regressions, we add one
ACPI_GPE_DISPATCH_RAW_HANDLER type to be distiguished from
ACPI_GPE_DISPATCH_HANDLER. For which the AcpiGbl_GpeLock is unlocked before
invoking the GPE handler and the internal enabling/disabling operations are
bypassed to allow drivers to perform them at a proper position using the
GPE APIs and ACPI_GPE_DISPATCH_RAW_HANDLER users should invoke AcpiSetGpe()
instead of AcpiEnableGpe()/AcpiDisableGpe() to bypass the internal GPE
clearing code in AcpiEnableGpe(). Lv Zheng.

Known issues:
1. Edge-triggered GPE lost for frequent enablings
   On some buggy silicon platforms, GPE enable line may not be directly
   wired to the GPE trigger line. In that case, when GPE enabling is
   frequently performed for edge-triggered GPEs, GPE status may stay set
   without being triggered.
   This patch may maginify this problem as it allows GPE enabling to be
   parallel performed during the process the GPEs are handled.
   This is an existing issue, because:
   1. For task context:
      Current ACPI_GPE_DISPATCH_METHOD practices have proven that this
      isn't a real issue - we can re-enable edge-triggered GPE in a work
      queue where the GPE status bit might already be set.
   2. For IRQ context:
      This can even happen when the GPE enabling occurs before returning
      from the GPE handler and after unlocking the GPE lock.
   Thus currently no code is included to protect this.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Lv Zheng committed Dec 11, 2014
1 parent 7926d5c commit 199cad1
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 25 deletions.
5 changes: 5 additions & 0 deletions source/components/debugger/dbdisply.c
Expand Up @@ -1034,6 +1034,11 @@ AcpiDbDisplayGpes (
AcpiOsPrintf ("Implicit Notify on %u devices", Count);
break;

case ACPI_GPE_DISPATCH_RAW_HANDLER:

AcpiOsPrintf ("RawHandler");
break;

default:

AcpiOsPrintf ("UNKNOWN: %X",
Expand Down
40 changes: 34 additions & 6 deletions source/components/events/evgpe.c
Expand Up @@ -447,6 +447,7 @@ AcpiEvGpeDetect (
ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
ACPI_GPE_EVENT_INFO *GpeEventInfo;
UINT32 GpeNumber;
ACPI_GPE_HANDLER_INFO *GpeHandlerInfo;
UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
UINT8 EnabledStatusByte;
UINT32 StatusReg;
Expand Down Expand Up @@ -563,12 +564,39 @@ AcpiEvGpeDetect (
AcpiGbl_GlobalEventHandlerContext);
}

/*
* Found an active GPE. Dispatch the event to a handler
* or method.
*/
IntStatus |= AcpiEvGpeDispatch (GpeDevice,
GpeEventInfo, GpeNumber);
/* Found an active GPE */

if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_RAW_HANDLER)
{
/* Dispatch the event to a raw handler */

GpeHandlerInfo = GpeEventInfo->Dispatch.Handler;

/*
* There is no protection around the namespace node
* and the GPE handler to ensure a safe destruction
* because:
* 1. The namespace node is expected to always
* exist after loading a table.
* 2. The GPE handler is expected to be flushed by
* AcpiOsWaitEventsComplete() before the
* destruction.
*/
AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
IntStatus |= GpeHandlerInfo->Address (
GpeDevice, GpeNumber, GpeHandlerInfo->Context);
Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
}
else
{
/*
* Dispatch the event to a standard handler or
* method.
*/
IntStatus |= AcpiEvGpeDispatch (GpeDevice,
GpeEventInfo, GpeNumber);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions source/components/events/evgpeblk.c
Expand Up @@ -592,6 +592,7 @@ AcpiEvInitializeGpeBlock (
*/
if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_NONE) ||
(ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_HANDLER) ||
(ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_RAW_HANDLER) ||
(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
{
continue;
Expand Down
6 changes: 4 additions & 2 deletions source/components/events/evgpeinit.c
Expand Up @@ -491,8 +491,10 @@ AcpiEvMatchGpeMethod (
return_ACPI_STATUS (AE_OK);
}

if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_HANDLER)
if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_HANDLER) ||
(ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_RAW_HANDLER))
{
/* If there is already a handler, ignore this GPE method */

Expand Down
6 changes: 4 additions & 2 deletions source/components/events/evgpeutil.c
Expand Up @@ -434,8 +434,10 @@ AcpiEvDeleteGpeHandlers (
GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
ACPI_GPE_REGISTER_WIDTH) + j];

if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_HANDLER)
if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_HANDLER) ||
(ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_RAW_HANDLER))
{
/* Delete an installed handler block */

Expand Down
124 changes: 114 additions & 10 deletions source/components/events/evxface.c
Expand Up @@ -124,6 +124,21 @@
#define _COMPONENT ACPI_EVENTS
ACPI_MODULE_NAME ("evxface")

#if (!ACPI_REDUCED_HARDWARE)

/* Local prototypes */

static ACPI_STATUS
AcpiEvInstallGpeHandler (
ACPI_HANDLE GpeDevice,
UINT32 GpeNumber,
UINT32 Type,
BOOLEAN IsRawHandler,
ACPI_GPE_HANDLER Address,
void *Context);

#endif


/*******************************************************************************
*
Expand Down Expand Up @@ -894,27 +909,31 @@ ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler)

/*******************************************************************************
*
* FUNCTION: AcpiInstallGpeHandler
* 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: Install a handler for a General Purpose Event.
* DESCRIPTION: Internal function to install a handler for a General Purpose
* Event.
*
******************************************************************************/

ACPI_STATUS
AcpiInstallGpeHandler (
static ACPI_STATUS
AcpiEvInstallGpeHandler (
ACPI_HANDLE GpeDevice,
UINT32 GpeNumber,
UINT32 Type,
BOOLEAN IsRawHandler,
ACPI_GPE_HANDLER Address,
void *Context)
{
Expand All @@ -924,7 +943,7 @@ AcpiInstallGpeHandler (
ACPI_CPU_FLAGS Flags;


ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);
ACPI_FUNCTION_TRACE (EvInstallGpeHandler);


/* Parameter validation */
Expand Down Expand Up @@ -962,8 +981,10 @@ AcpiInstallGpeHandler (

/* Make sure that there isn't a handler there already */

if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_HANDLER)
if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_HANDLER) ||
(ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
ACPI_GPE_DISPATCH_RAW_HANDLER))
{
Status = AE_ALREADY_EXISTS;
goto FreeAndExit;
Expand Down Expand Up @@ -1004,7 +1025,8 @@ AcpiInstallGpeHandler (
/* Setup up dispatch flags to indicate handler (vs. method/notify) */

GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_HANDLER);
GpeEventInfo->Flags |= (UINT8) (Type | (IsRawHandler ?
ACPI_GPE_DISPATCH_RAW_HANDLER : ACPI_GPE_DISPATCH_HANDLER));

AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);

Expand All @@ -1019,9 +1041,89 @@ AcpiInstallGpeHandler (
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.
*
******************************************************************************/

ACPI_STATUS
AcpiInstallGpeHandler (
ACPI_HANDLE GpeDevice,
UINT32 GpeNumber,
UINT32 Type,
ACPI_GPE_HANDLER Address,
void *Context)
{
ACPI_STATUS Status;


ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);


Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type, FALSE,
Address, Context);

return_ACPI_STATUS (Status);
}

ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)


/*******************************************************************************
*
* 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.
*
******************************************************************************/

ACPI_STATUS
AcpiInstallGpeRawHandler (
ACPI_HANDLE GpeDevice,
UINT32 GpeNumber,
UINT32 Type,
ACPI_GPE_HANDLER Address,
void *Context)
{
ACPI_STATUS Status;


ACPI_FUNCTION_TRACE (AcpiInstallGpeRawHandler);


Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type, TRUE,
Address, Context);

return_ACPI_STATUS (Status);
}

ACPI_EXPORT_SYMBOL (AcpiInstallGpeRawHandler)


/*******************************************************************************
*
* FUNCTION: AcpiRemoveGpeHandler
Expand Down Expand Up @@ -1078,8 +1180,10 @@ AcpiRemoveGpeHandler (

/* Make sure that a handler is indeed installed */

if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
ACPI_GPE_DISPATCH_HANDLER)
if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
ACPI_GPE_DISPATCH_HANDLER) &&
(ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
ACPI_GPE_DISPATCH_RAW_HANDLER))
{
Status = AE_NOT_EXIST;
goto UnlockAndExit;
Expand Down
9 changes: 9 additions & 0 deletions source/include/acpixf.h
Expand Up @@ -774,6 +774,15 @@ AcpiInstallGpeHandler (
ACPI_GPE_HANDLER Address,
void *Context))

ACPI_HW_DEPENDENT_RETURN_STATUS (
ACPI_STATUS
AcpiInstallGpeRawHandler (
ACPI_HANDLE GpeDevice,
UINT32 GpeNumber,
UINT32 Type,
ACPI_GPE_HANDLER Address,
void *Context))

ACPI_HW_DEPENDENT_RETURN_STATUS (
ACPI_STATUS
AcpiRemoveGpeHandler (
Expand Down
11 changes: 6 additions & 5 deletions source/include/actypes.h
Expand Up @@ -823,7 +823,7 @@ typedef UINT32 ACPI_EVENT_STATUS;
/*
* GPE info flags - Per GPE
* +-------+-+-+---+
* | 7:4 |3|2|1:0|
* | 7:5 |4|3|2:0|
* +-------+-+-+---+
* | | | |
* | | | +-- Type of dispatch:to method, handler, notify, or none
Expand All @@ -835,14 +835,15 @@ typedef UINT32 ACPI_EVENT_STATUS;
#define ACPI_GPE_DISPATCH_METHOD (UINT8) 0x01
#define ACPI_GPE_DISPATCH_HANDLER (UINT8) 0x02
#define ACPI_GPE_DISPATCH_NOTIFY (UINT8) 0x03
#define ACPI_GPE_DISPATCH_MASK (UINT8) 0x03
#define ACPI_GPE_DISPATCH_RAW_HANDLER (UINT8) 0x04
#define ACPI_GPE_DISPATCH_MASK (UINT8) 0x07
#define ACPI_GPE_DISPATCH_TYPE(flags) ((UINT8) ((flags) & ACPI_GPE_DISPATCH_MASK))

#define ACPI_GPE_LEVEL_TRIGGERED (UINT8) 0x04
#define ACPI_GPE_LEVEL_TRIGGERED (UINT8) 0x08
#define ACPI_GPE_EDGE_TRIGGERED (UINT8) 0x00
#define ACPI_GPE_XRUPT_TYPE_MASK (UINT8) 0x04
#define ACPI_GPE_XRUPT_TYPE_MASK (UINT8) 0x08

#define ACPI_GPE_CAN_WAKE (UINT8) 0x08
#define ACPI_GPE_CAN_WAKE (UINT8) 0x10

/*
* Flags for GPE and Lock interfaces
Expand Down

0 comments on commit 199cad1

Please sign in to comment.