evxfevnt.c revision 128212
143902Sbrian/******************************************************************************
243902Sbrian *
343948Sbrian * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
443902Sbrian *              $Revision: 75 $
543948Sbrian *
643902Sbrian *****************************************************************************/
750476Speter
843902Sbrian/******************************************************************************
943902Sbrian *
1043902Sbrian * 1. Copyright Notice
1143902Sbrian *
1243902Sbrian * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
1343902Sbrian * All rights reserved.
1443902Sbrian *
1543902Sbrian * 2. License
1643902Sbrian *
1743902Sbrian * 2.1. This is your license from Intel Corp. under its intellectual property
1843902Sbrian * rights.  You may have additional license terms from the party that provided
1943902Sbrian * you this software, covering your right to use that party's intellectual
2043902Sbrian * property rights.
2143948Sbrian *
2243902Sbrian * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2343902Sbrian * copy of the source code appearing in this file ("Covered Code") an
2443948Sbrian * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2543948Sbrian * base code distributed originally by Intel ("Original Intel Code") to copy,
2643902Sbrian * make derivatives, distribute, use and display any portion of the Covered
2743902Sbrian * Code in any form, with the right to sublicense such rights; and
2843902Sbrian *
2943902Sbrian * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3043902Sbrian * license (with the right to sublicense), under only those claims of Intel
3143948Sbrian * patents that are infringed by the Original Intel Code, to make, use, sell,
3243948Sbrian * offer to sell, and import the Covered Code and derivative works thereof
3343902Sbrian * solely to the minimum extent necessary to exercise the above copyright
3443902Sbrian * license, and in no event shall the patent license extend to any additions
3543902Sbrian * to or modifications of the Original Intel Code.  No other license or right
3643902Sbrian * is granted directly or by implication, estoppel or otherwise;
3743948Sbrian *
3843948Sbrian * The above copyright and patent license is granted only if the following
3947634Sbillf * conditions are met:
4043902Sbrian *
4143902Sbrian * 3. Conditions
4243902Sbrian *
4343948Sbrian * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4443948Sbrian * Redistribution of source code of any substantial prton of the Covered
4543948Sbrian * Code or modification with rights to further distribute source must include
4643902Sbrian * the above Copyright Notice, the above License, this list of Conditions,
4743902Sbrian * and the following Disclaimer and Export Compliance provision.  In addition,
4843948Sbrian * Licensee must cause all Covered Code to which Licensee contributes to
4943948Sbrian * contain a file documenting the changes Licensee made to create that Covered
5043902Sbrian * Code and the date of any change.  Licensee must include in that file the
5143902Sbrian * documentation of any changes made by any predecessor Licensee.  Licensee
5243902Sbrian * must include a prominent statement that the modification is derived,
5343948Sbrian * directly or indirectly, from Original Intel Code.
5443902Sbrian *
5543902Sbrian * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5643948Sbrian * Redistribution of source code of any substantial portion of the Covered
5743948Sbrian * Code or modification without rights to further distribute source must
5843902Sbrian * include the following Disclaimer and Export Compliance provision in the
5943902Sbrian * documentation and/or other materials provided with distribution.  In
6043902Sbrian * addition, Licensee may not authorize further sublicense of source of any
6143902Sbrian * portion of the Covered Code, and must include terms to the effect that the
6243902Sbrian * license from Licensee to its licensee is limited to the intellectual
6343902Sbrian * property embodied in the software Licensee provides to its licensee, and
6443948Sbrian * not to intellectual property embodied in modifications its licensee may
6543902Sbrian * make.
6643948Sbrian *
6743948Sbrian * 3.3. Redistribution of Executable. Redistribution in executable form of any
6843902Sbrian * substantial portion of the Covered Code or modification must reproduce the
6943948Sbrian * above Copyright Notice, and the following Disclaimer and Export Compliance
7043948Sbrian * provision in the documentation and/or other materials provided with the
7143948Sbrian * distribution.
7243948Sbrian *
7343948Sbrian * 3.4. Intel retains all right, title, and interest in and to the Original
7443948Sbrian * Intel Code.
7543902Sbrian *
7643902Sbrian * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7743902Sbrian * Intel shall be used in advertising or otherwise to promote the sale, use or
7843902Sbrian * other dealings in products derived from or relating to the Covered Code
7943902Sbrian * without prior written authorization from Intel.
8043902Sbrian *
8143902Sbrian * 4. Disclaimer and Export Compliance
8243902Sbrian *
8343948Sbrian * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8447634Sbillf * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8543902Sbrian * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8643902Sbrian * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8743948Sbrian * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8843948Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8943902Sbrian * PARTICULAR PURPOSE.
9043902Sbrian *
9143902Sbrian * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9243902Sbrian * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9343902Sbrian * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9443902Sbrian * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9543902Sbrian * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9643902Sbrian * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9743902Sbrian * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9843902Sbrian * LIMITED REMEDY.
9943902Sbrian *
10043902Sbrian * 4.3. Licensee shall not export, either directly or indirectly, any of this
10143902Sbrian * software or system incorporating such software without first obtaining any
10243902Sbrian * required license or other approval from the U. S. Department of Commerce or
10343902Sbrian * any other agency or department of the United States Government.  In the
10443902Sbrian * event Licensee exports any such software from the United States or
10543902Sbrian * re-exports any such software from a foreign destination, Licensee shall
10643902Sbrian * ensure that the distribution and export/re-export of the software is in
10743902Sbrian * compliance with all laws, regulations, orders, or other restrictions of the
10843902Sbrian * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10943902Sbrian * any of its subsidiaries will export/re-export any technical data, process,
11043902Sbrian * software, or service, directly or indirectly, to any country for which the
11143902Sbrian * United States government or any agency thereof requires an export license,
11243902Sbrian * other governmental approval, or letter of assurance, without first obtaining
11343902Sbrian * such license, approval or letter.
11443902Sbrian *
11543902Sbrian *****************************************************************************/
11643902Sbrian
11743902Sbrian
11843902Sbrian#define __EVXFEVNT_C__
11943902Sbrian
12043902Sbrian#include "acpi.h"
12143902Sbrian#include "acevents.h"
12243902Sbrian#include "acnamesp.h"
12343902Sbrian
12443902Sbrian#define _COMPONENT          ACPI_EVENTS
12543902Sbrian        ACPI_MODULE_NAME    ("evxfevnt")
12643902Sbrian
12743902Sbrian
12843902Sbrian/*******************************************************************************
12943902Sbrian *
13043902Sbrian * FUNCTION:    AcpiEnable
13143902Sbrian *
13243902Sbrian * PARAMETERS:  None
13343902Sbrian *
13443902Sbrian * RETURN:      Status
13543902Sbrian *
13643902Sbrian * DESCRIPTION: Transfers the system into ACPI mode.
13743902Sbrian *
13843902Sbrian ******************************************************************************/
13943902Sbrian
14043902SbrianACPI_STATUS
14143902SbrianAcpiEnable (void)
14243902Sbrian{
14343902Sbrian    ACPI_STATUS             Status = AE_OK;
14455247Sbrian
14543902Sbrian
14643902Sbrian    ACPI_FUNCTION_TRACE ("AcpiEnable");
14743902Sbrian
14843902Sbrian
14943902Sbrian    /* Make sure we have the FADT*/
15043902Sbrian
15143902Sbrian    if (!AcpiGbl_FADT)
15243902Sbrian    {
15343902Sbrian        ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
15443902Sbrian        return_ACPI_STATUS (AE_NO_ACPI_TABLES);
15543902Sbrian    }
15643902Sbrian
15743902Sbrian    if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
15843902Sbrian    {
15943902Sbrian        ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
16043902Sbrian    }
16143902Sbrian    else
16243902Sbrian    {
16343902Sbrian        /* Transition to ACPI mode */
16443902Sbrian
16543902Sbrian        Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
16643902Sbrian        if (ACPI_FAILURE (Status))
16743902Sbrian        {
16843902Sbrian            ACPI_REPORT_ERROR (("Could not transition to ACPI mode.\n"));
16943902Sbrian            return_ACPI_STATUS (Status);
17043902Sbrian        }
17143902Sbrian
17243902Sbrian        ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Transition to ACPI mode successful\n"));
17343902Sbrian    }
17443902Sbrian
17543902Sbrian    return_ACPI_STATUS (Status);
17643902Sbrian}
17743902Sbrian
17858636Sbrian
17943902Sbrian/*******************************************************************************
18043902Sbrian *
18143902Sbrian * FUNCTION:    AcpiDisable
18243902Sbrian *
18351050Sbrian * PARAMETERS:  None
18451050Sbrian *
18551050Sbrian * RETURN:      Status
18651050Sbrian *
18751049Sbrian * DESCRIPTION: Transfers the system into LEGACY mode.
18843902Sbrian *
18943902Sbrian ******************************************************************************/
19055427Sbrian
19155427SbrianACPI_STATUS
19243902SbrianAcpiDisable (void)
19343902Sbrian{
19443902Sbrian    ACPI_STATUS             Status = AE_OK;
19551049Sbrian
19643902Sbrian
19743902Sbrian    ACPI_FUNCTION_TRACE ("AcpiDisable");
19843902Sbrian
19943902Sbrian
20043902Sbrian    if (!AcpiGbl_FADT)
20143902Sbrian    {
20243902Sbrian        ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
20343902Sbrian        return_ACPI_STATUS (AE_NO_ACPI_TABLES);
20443902Sbrian    }
20543902Sbrian
20643902Sbrian    if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
20743902Sbrian    {
20843902Sbrian        ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in legacy (non-ACPI) mode\n"));
20943902Sbrian    }
21043902Sbrian    else
21143902Sbrian    {
21243902Sbrian        /* Transition to LEGACY mode */
21343902Sbrian
21443902Sbrian        Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
21556704Sbrian
21643902Sbrian        if (ACPI_FAILURE (Status))
21756704Sbrian        {
21856704Sbrian            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not exit ACPI mode to legacy mode"));
21956704Sbrian            return_ACPI_STATUS (Status);
22056704Sbrian        }
22159152Sbrian
22259152Sbrian        ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
22359152Sbrian    }
22459152Sbrian
22559152Sbrian    return_ACPI_STATUS (Status);
22659152Sbrian}
22759152Sbrian
22859152Sbrian
22943902Sbrian/*******************************************************************************
23056704Sbrian *
23143902Sbrian * FUNCTION:    AcpiEnableEvent
23256704Sbrian *
23356704Sbrian * PARAMETERS:  Event           - The fixed eventto be enabled
23456704Sbrian *              Flags           - Reserved
23556704Sbrian *
23656704Sbrian * RETURN:      Status
23756704Sbrian *
23856704Sbrian * DESCRIPTION: Enable an ACPI event (fixed)
23956704Sbrian *
24056704Sbrian ******************************************************************************/
24156704Sbrian
24243902SbrianACPI_STATUS
24356704SbrianAcpiEnableEvent (
24443902Sbrian    UINT32                  Event,
24556704Sbrian    UINT32                  Flags)
24656704Sbrian{
24756704Sbrian    ACPI_STATUS             Status = AE_OK;
24856704Sbrian    UINT32                  Value;
24956704Sbrian
25056704Sbrian
25156704Sbrian    ACPI_FUNCTION_TRACE ("AcpiEnableEvent");
25256704Sbrian
25356704Sbrian
25456704Sbrian    /* Decode the Fixed Event */
25556704Sbrian
25656704Sbrian    if (Event > ACPI_EVENT_MAX)
25756704Sbrian    {
25856704Sbrian        return_ACPI_STATUS (AE_BAD_PARAMETER);
25956704Sbrian    }
26056704Sbrian
26143902Sbrian    /*
26249141Sbrian     * Enable the requested fixed event (by writing a one to the
26349141Sbrian     * enable register bit)
26449141Sbrian     */
26549141Sbrian    Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
26649141Sbrian                1, ACPI_MTX_LOCK);
26749141Sbrian    if (ACPI_FAILURE (Status))
26849141Sbrian    {
26949141Sbrian        return_ACPI_STATUS (Status);
27049141Sbrian    }
27149141Sbrian
27249141Sbrian    /* Make sure that the hardware responded */
27349141Sbrian
27449141Sbrian    Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
27549141Sbrian                    &Value, ACPI_MTX_LOCK);
27649141Sbrian    if (ACPI_FAILURE (Status))
27749141Sbrian    {
27849141Sbrian        return_ACPI_STATUS (Status);
27949141Sbrian    }
28049141Sbrian
28149141Sbrian    if (Value != 1)
28249141Sbrian    {
28349141Sbrian        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
28449141Sbrian            "Could not enable %s event\n", AcpiUtGetEventName (Event)));
28549141Sbrian        return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
28649141Sbrian    }
28749141Sbrian
28849141Sbrian    return_ACPI_STATUS (Status);
28949141Sbrian}
29049141Sbrian
29143902Sbrian
29249141Sbrian/*******************************************************************************
29349141Sbrian *
29449141Sbrian * FUNCTION:    AcpiEnableGpe
29549141Sbrian *
29649141Sbrian * PARAMETERS:  GpeDevice       - Parent GPE Device
29749141Sbrian *              GpeNumber       - GPE level within the GPE block
29849141Sbrian *              Flags           - Just enable, or also wake enable?
29949141Sbrian *                                Called from ISR or not
30049141Sbrian *
30149141Sbrian * RETURN:      Status
30249141Sbrian *
30349141Sbrian * DESCRIPTION: Enable an ACPI event (general purpose)
30449141Sbrian *
30549141Sbrian ******************************************************************************/
30649141Sbrian
30749141SbrianACPI_STATUS
30849141SbrianAcpiEnableGpe (
30949141Sbrian    ACPI_HANDLE             GpeDevice,
31049141Sbrian    UINT32                  GpeNumber,
31149141Sbrian    UINT32                  Flags)
31249141Sbrian{
31349141Sbrian    ACPI_STATUS             Status = AE_OK;
31449141Sbrian    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
31549141Sbrian
31649141Sbrian
31749141Sbrian    ACPI_FUNCTION_TRACE ("AcpiEnableGpe");
31849141Sbrian
31949141Sbrian
32049141Sbrian    /* Use semaphore lock if not executing at interrupt level */
32149141Sbrian
32249141Sbrian    if (Flags & ACPI_NOT_ISR)
32349141Sbrian    {
32449141Sbrian        Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
32549141Sbrian        if (ACPI_FAILURE (Status))
32649141Sbrian        {
32749141Sbrian            return_ACPI_STATUS (Status);
32849141Sbrian        }
32949141Sbrian    }
33049141Sbrian
33149141Sbrian    /* Ensure that we have a valid GPE number */
33249141Sbrian
33349141Sbrian    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
33449141Sbrian    if (!GpeEventInfo)
33549141Sbrian    {
33649141Sbrian        Status = AE_BAD_PARAMETER;
33749141Sbrian        goto UnlockAndExit;
33849141Sbrian    }
33949141Sbrian
34049141Sbrian    /* Check for Wake vs Runtime GPE */
34149141Sbrian
34249141Sbrian    if (Flags & ACPI_EVENT_WAKE_ENABLE)
34349141Sbrian    {
34449141Sbrian        /* Ensure the requested wake GPE is disabled */
34549141Sbrian
34649141Sbrian        Status = AcpiHwDisableGpe (GpeEventInfo);
34749141Sbrian        if (ACPI_FAILURE (Status))
34849141Sbrian        {
34949141Sbrian            goto UnlockAndExit;
35049141Sbrian        }
35143902Sbrian
35243902Sbrian        /* Defer Enable of Wake GPE until sleep time */
35343948Sbrian
35443948Sbrian        AcpiHwEnableGpeForWakeup (GpeEventInfo);
35543948Sbrian    }
35643948Sbrian    else
35743948Sbrian    {
35843948Sbrian        /* Enable the requested runtime GPE  */
35943948Sbrian
36043948Sbrian        Status = AcpiHwEnableGpe (GpeEventInfo);
36143948Sbrian        if (ACPI_FAILURE (Status))
36243948Sbrian        {
36343948Sbrian            goto UnlockAndExit;
36443948Sbrian        }
36543948Sbrian    }
36643948Sbrian
36743948Sbrian
36843948SbrianUnlockAndExit:
36943948Sbrian    if (Flags & ACPI_NOT_ISR)
37043948Sbrian    {
37143948Sbrian        (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
37243948Sbrian    }
37343948Sbrian    return_ACPI_STATUS (Status);
37443948Sbrian}
37543948Sbrian
37643948Sbrian
37743948Sbrian/*******************************************************************************
37843948Sbrian *
37943948Sbrian * FUNCTION:    AcpiDisableEvent
38043948Sbrian *
38143948Sbrian * PARAMETERS:  Event           - The fixed eventto be enabled
38243902Sbrian *              Flags           - Reserved
38343948Sbrian *
38443902Sbrian * RETURN:      Status
38543948Sbrian *
38643902Sbrian * DESCRIPTION: Disable an ACPI event (fixed)
38743902Sbrian *
38843902Sbrian ******************************************************************************/
38943902Sbrian
39043948SbrianACPI_STATUS
39143902SbrianAcpiDisableEvent (
39243902Sbrian    UINT32                  Event,
39343948Sbrian    UINT32                  Flags)
39443948Sbrian{
39543948Sbrian    ACPI_STATUS             Status = AE_OK;
39643948Sbrian    UINT32                  Value;
39743948Sbrian
39843948Sbrian
39943948Sbrian    ACPI_FUNCTION_TRACE ("AcpiDisableEvent");
40043902Sbrian
40143948Sbrian
40243948Sbrian    /* Decode the Fixed Event */
40343948Sbrian
40443948Sbrian    if (Event > ACPI_EVENT_MAX)
40543948Sbrian    {
40643902Sbrian        return_ACPI_STATUS (AE_BAD_PARAMETER);
40743902Sbrian    }
40843902Sbrian
40943902Sbrian    /*
41043902Sbrian     * Disable the requested fixed event (by writing a zero to the
41143902Sbrian     * enable register bit)
41243902Sbrian     */
41343902Sbrian    Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
41443902Sbrian                0, ACPI_MTX_LOCK);
41543902Sbrian    if (ACPI_FAILURE (Status))
41643902Sbrian    {
41743902Sbrian        return_ACPI_STATUS (Status);
41843902Sbrian    }
41946103Sbrian
42043902Sbrian    Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
42143902Sbrian                &Value, ACPI_MTX_LOCK);
42243902Sbrian    if (ACPI_FAILURE (Status))
42343902Sbrian    {
42443902Sbrian        return_ACPI_STATUS (Status);
42543902Sbrian    }
42643902Sbrian
42743902Sbrian    if (Value != 0)
42843902Sbrian    {
42943902Sbrian        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
43043902Sbrian            "Could not disable %s events\n", AcpiUtGetEventName (Event)));
43143902Sbrian        return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
43243902Sbrian    }
43343902Sbrian
43443902Sbrian    return_ACPI_STATUS (Status);
43543902Sbrian}
43643902Sbrian
43743902Sbrian
43843948Sbrian/*******************************************************************************
43943948Sbrian *
44043948Sbrian * FUNCTION:    AcpiDisableGpe
44143902Sbrian *
44243902Sbrian * PARAMETERS:  GpeDevice       - Parent GPE Device
44343902Sbrian *              GpeNumber       - GPE level within the GPE block
44443902Sbrian *              Flags           - Just enable, or also wake enable?
44545070Sbrian *                                Called from ISR or not
44645070Sbrian *
44743902Sbrian * RETURN:      Status
44843902Sbrian *
44943902Sbrian * DESCRIPTION: Disable an ACPI event (general purpose)
45043902Sbrian *
45143902Sbrian ******************************************************************************/
45243902Sbrian
45343902SbrianACPI_STATUS
45443902SbrianAcpiDisableGpe (
45543902Sbrian    ACPI_HANDLE             GpeDevice,
45643902Sbrian    UINT32                  GpeNumber,
45743902Sbrian    UINT32                  Flags)
45843902Sbrian{
45943902Sbrian    ACPI_STATUS             Status = AE_OK;
46043902Sbrian    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
46143902Sbrian
46243902Sbrian
46343902Sbrian    ACPI_FUNCTION_TRACE ("AcpiDisableGpe");
46443902Sbrian
46543902Sbrian
46643902Sbrian    /* Use semaphore lock if not executing at interrupt level */
46743902Sbrian
46843902Sbrian    if (Flags & ACPI_NOT_ISR)
46943902Sbrian    {
47043948Sbrian        Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
47143948Sbrian        if (ACPI_FAILURE (Status))
47243902Sbrian        {
47343948Sbrian            return_ACPI_STATUS (Status);
47443948Sbrian        }
47543902Sbrian    }
47643948Sbrian
47743948Sbrian    /* Ensure that we have a valid GPE number */
47843902Sbrian
47943902Sbrian    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
48043902Sbrian    if (!GpeEventInfo)
48143902Sbrian    {
48243902Sbrian        Status = AE_BAD_PARAMETER;
48343902Sbrian        goto UnlockAndExit;
48443902Sbrian    }
48543902Sbrian
48643902Sbrian    /*
48743902Sbrian     * Only disable the requested GPE number for wake if specified.
48843902Sbrian     * Otherwise, turn it totally off
48943902Sbrian     */
49043902Sbrian    if (Flags & ACPI_EVENT_WAKE_DISABLE)
49143902Sbrian    {
49243902Sbrian        AcpiHwDisableGpeForWakeup (GpeEventInfo);
49343948Sbrian    }
49443948Sbrian    else
49543948Sbrian    {
49643902Sbrian        Status = AcpiHwDisableGpe (GpeEventInfo);
49743948Sbrian    }
49843948Sbrian
49943902SbrianUnlockAndExit:
50043902Sbrian    if (Flags & ACPI_NOT_ISR)
50149977Sbrian    {
50249977Sbrian        (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
50346103Sbrian    }
50443902Sbrian    return_ACPI_STATUS (Status);
50543948Sbrian}
50643948Sbrian
50743948Sbrian
50843948Sbrian/*******************************************************************************
50943902Sbrian *
51043948Sbrian * FUNCTION:    AcpiClearEvent
51143948Sbrian *
51243948Sbrian * PARAMETERS:  Event           - The fixed event to be cleared
51343902Sbrian *
51451700Sbrian * RETURN:      Status
51551700Sbrian *
51651700Sbrian * DESCRIPTION: Clear an ACPI event (fixed)
51743902Sbrian *
51843902Sbrian ******************************************************************************/
51943902Sbrian
52051700SbrianACPI_STATUS
52143902SbrianAcpiClearEvent (
52243902Sbrian    UINT32                  Event)
52343902Sbrian{
52443948Sbrian    ACPI_STATUS             Status = AE_OK;
52543948Sbrian
52643948Sbrian
52743948Sbrian    ACPI_FUNCTION_TRACE ("AcpiClearEvent");
52843948Sbrian
52943948Sbrian
53043948Sbrian    /* Decode the Fixed Event */
53143948Sbrian
53243948Sbrian    if (Event > ACPI_EVENT_MAX)
53343948Sbrian    {
53443902Sbrian        return_ACPI_STATUS (AE_BAD_PARAMETER);
53543948Sbrian    }
53643948Sbrian
53743902Sbrian    /*
53843902Sbrian     * Clear the requested fixed event (By writing a one to the
53943902Sbrian     * status register bit)
54043902Sbrian     */
54143902Sbrian    Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
54243902Sbrian            1, ACPI_MTX_LOCK);
54343948Sbrian
54443948Sbrian    return_ACPI_STATUS (Status);
54543902Sbrian}
54643902Sbrian
54743902Sbrian
54843902Sbrian/*******************************************************************************
54943902Sbrian *
55043902Sbrian * FUNCTION:    AcpiClearGpe
55143902Sbrian *
55243902Sbrian * PARAMETERS:  GpeDevice       - Parent GPE Device
55343902Sbrian *              GpeNumber       - GPE level within the GPE block
55443948Sbrian *              Flags           - Called from an ISR or not
55543902Sbrian *
55643948Sbrian * RETURN:      Status
55743948Sbrian *
55843902Sbrian * DESCRIPTION: Clear an ACPI event (general purpose)
55943902Sbrian *
56043902Sbrian ******************************************************************************/
56143902Sbrian
56243902SbrianACPI_STATUS
56343902SbrianAcpiClearGpe (
56443902Sbrian    ACPI_HANDLE             GpeDevice,
56543902Sbrian    UINT32                  GpeNumber,
56643902Sbrian    UINT32                  Flags)
56743902Sbrian{
56843902Sbrian    ACPI_STATUS             Status = AE_OK;
56943902Sbrian    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
57043902Sbrian
57143902Sbrian
57243902Sbrian    ACPI_FUNCTION_TRACE ("AcpiClearGpe");
57343902Sbrian
57443902Sbrian
57543902Sbrian    /* Use semaphore lock if not executing at interrupt level */
57643902Sbrian
57743902Sbrian    if (Flags & ACPI_NOT_ISR)
57843902Sbrian    {
57943902Sbrian        Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
58043902Sbrian        if (ACPI_FAILURE (Status))
58143902Sbrian        {
58243902Sbrian            return_ACPI_STATUS (Status);
58343902Sbrian        }
58443902Sbrian    }
58543902Sbrian
58643948Sbrian    /* Ensure that we have a valid GPE number */
58743948Sbrian
58843948Sbrian    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
58943948Sbrian    if (!GpeEventInfo)
59043948Sbrian    {
59143948Sbrian        Status = AE_BAD_PARAMETER;
59243948Sbrian        goto UnlockAndExit;
59343948Sbrian    }
59443948Sbrian
59543948Sbrian    Status = AcpiHwClearGpe (GpeEventInfo);
59643948Sbrian
59743948SbrianUnlockAndExit:
59843948Sbrian    if (Flags & ACPI_NOT_ISR)
59943948Sbrian    {
60043948Sbrian        (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
60143948Sbrian    }
60243948Sbrian    return_ACPI_STATUS (Status);
60343948Sbrian}
60443948Sbrian
60543948Sbrian
60643948Sbrian/*******************************************************************************
60743948Sbrian *
60843948Sbrian * FUNCTION:    AcpiGetEventStatus
60943948Sbrian *
61043948Sbrian * PARAMETERS:  Event           - The fixed event
61153540Sbrian *              Event Status    - Where the current status of the event will
61261097Sbrian *                                be returned
61361097Sbrian *
61461097Sbrian * RETURN:      Status
61553540Sbrian *
61653540Sbrian * DESCRIPTION: Obtains and returns the current status of the event
61753540Sbrian *
61853540Sbrian ******************************************************************************/
61953540Sbrian
62053540SbrianACPI_STATUS
62153540SbrianAcpiGetEventStatus (
62253540Sbrian    UINT32                  Event,
62353540Sbrian    ACPI_EVENT_STATUS       *EventStatus)
62453540Sbrian{
62553540Sbrian    ACPI_STATUS             Status = AE_OK;
62653540Sbrian
62753540Sbrian
62853540Sbrian    ACPI_FUNCTION_TRACE ("AcpiGetEventStatus");
62953540Sbrian
63053540Sbrian
63153540Sbrian    if (!EventStatus)
63253540Sbrian    {
63353540Sbrian        return_ACPI_STATUS (AE_BAD_PARAMETER);
63453540Sbrian    }
63553540Sbrian
63653540Sbrian    /* Decode the Fixed Event */
63753540Sbrian
63853540Sbrian    if (Event > ACPI_EVENT_MAX)
63953540Sbrian    {
640        return_ACPI_STATUS (AE_BAD_PARAMETER);
641    }
642
643    /* Get the status of the requested fixed event */
644
645    Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
646                    EventStatus, ACPI_MTX_LOCK);
647
648    return_ACPI_STATUS (Status);
649}
650
651
652/*******************************************************************************
653 *
654 * FUNCTION:    AcpiGetGpeStatus
655 *
656 * PARAMETERS:  GpeDevice       - Parent GPE Device
657 *              GpeNumber       - GPE level within the GPE block
658 *              Flags           - Called from an ISR or not
659 *              Event Status    - Where the current status of the event will
660 *                                be returned
661 *
662 * RETURN:      Status
663 *
664 * DESCRIPTION: Get status of an event (general purpose)
665 *
666 ******************************************************************************/
667
668ACPI_STATUS
669AcpiGetGpeStatus (
670    ACPI_HANDLE             GpeDevice,
671    UINT32                  GpeNumber,
672    UINT32                  Flags,
673    ACPI_EVENT_STATUS       *EventStatus)
674{
675    ACPI_STATUS             Status = AE_OK;
676    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
677
678
679    ACPI_FUNCTION_TRACE ("AcpiGetGpeStatus");
680
681
682    /* Use semaphore lock if not executing at interrupt level */
683
684    if (Flags & ACPI_NOT_ISR)
685    {
686        Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
687        if (ACPI_FAILURE (Status))
688        {
689            return_ACPI_STATUS (Status);
690        }
691    }
692
693    /* Ensure that we have a valid GPE number */
694
695    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
696    if (!GpeEventInfo)
697    {
698        Status = AE_BAD_PARAMETER;
699        goto UnlockAndExit;
700    }
701
702    /* Obtain status on the requested GPE number */
703
704    Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
705
706UnlockAndExit:
707    if (Flags & ACPI_NOT_ISR)
708    {
709        (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
710    }
711    return_ACPI_STATUS (Status);
712}
713
714
715/*******************************************************************************
716 *
717 * FUNCTION:    AcpiInstallGpeBlock
718 *
719 * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
720 *              GpeBlockAddress     - Address and SpaceID
721 *              RegisterCount       - Number of GPE register pairs in the block
722 *              InterruptLevel      - H/W interrupt for the block
723 *
724 * RETURN:      Status
725 *
726 * DESCRIPTION: Create and Install a block of GPE registers
727 *
728 ******************************************************************************/
729
730ACPI_STATUS
731AcpiInstallGpeBlock (
732    ACPI_HANDLE             GpeDevice,
733    ACPI_GENERIC_ADDRESS    *GpeBlockAddress,
734    UINT32                  RegisterCount,
735    UINT32                  InterruptLevel)
736{
737    ACPI_STATUS             Status;
738    ACPI_OPERAND_OBJECT     *ObjDesc;
739    ACPI_NAMESPACE_NODE     *Node;
740    ACPI_GPE_BLOCK_INFO     *GpeBlock;
741
742
743    ACPI_FUNCTION_TRACE ("AcpiInstallGpeBlock");
744
745
746    if ((!GpeDevice)       ||
747        (!GpeBlockAddress) ||
748        (!RegisterCount))
749    {
750        return_ACPI_STATUS (AE_BAD_PARAMETER);
751    }
752
753    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
754    if (ACPI_FAILURE (Status))
755    {
756        return (Status);
757    }
758
759    Node = AcpiNsMapHandleToNode (GpeDevice);
760    if (!Node)
761    {
762        Status = AE_BAD_PARAMETER;
763        goto UnlockAndExit;
764    }
765
766    /*
767     * For user-installed GPE Block Devices, the GpeBlockBaseNumber
768     * is always zero
769     */
770    Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
771                    0, InterruptLevel, &GpeBlock);
772    if (ACPI_FAILURE (Status))
773    {
774        goto UnlockAndExit;
775    }
776
777    /* Get the DeviceObject attached to the node */
778
779    ObjDesc = AcpiNsGetAttachedObject (Node);
780    if (!ObjDesc)
781    {
782        /* No object, create a new one */
783
784        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
785        if (!ObjDesc)
786        {
787            Status = AE_NO_MEMORY;
788            goto UnlockAndExit;
789        }
790
791        Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
792
793        /* Remove local reference to the object */
794
795        AcpiUtRemoveReference (ObjDesc);
796
797        if (ACPI_FAILURE (Status))
798        {
799            goto UnlockAndExit;
800        }
801    }
802
803    /* Install the GPE block in the DeviceObject */
804
805    ObjDesc->Device.GpeBlock = GpeBlock;
806
807
808UnlockAndExit:
809    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
810    return_ACPI_STATUS (Status);
811}
812
813
814/*******************************************************************************
815 *
816 * FUNCTION:    AcpiRemoveGpeBlock
817 *
818 * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
819 *
820 * RETURN:      Status
821 *
822 * DESCRIPTION: Remove a previously installed block of GPE registers
823 *
824 ******************************************************************************/
825
826ACPI_STATUS
827AcpiRemoveGpeBlock (
828    ACPI_HANDLE             GpeDevice)
829{
830    ACPI_OPERAND_OBJECT     *ObjDesc;
831    ACPI_STATUS             Status;
832    ACPI_NAMESPACE_NODE     *Node;
833
834
835    ACPI_FUNCTION_TRACE ("AcpiRemoveGpeBlock");
836
837
838    if (!GpeDevice)
839    {
840        return_ACPI_STATUS (AE_BAD_PARAMETER);
841    }
842
843    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
844    if (ACPI_FAILURE (Status))
845    {
846        return (Status);
847    }
848
849    Node = AcpiNsMapHandleToNode (GpeDevice);
850    if (!Node)
851    {
852        Status = AE_BAD_PARAMETER;
853        goto UnlockAndExit;
854    }
855
856    /* Get the DeviceObject attached to the node */
857
858    ObjDesc = AcpiNsGetAttachedObject (Node);
859    if (!ObjDesc ||
860        !ObjDesc->Device.GpeBlock)
861    {
862        return_ACPI_STATUS (AE_NULL_OBJECT);
863    }
864
865    /* Delete the GPE block (but not the DeviceObject) */
866
867    Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
868    if (ACPI_SUCCESS (Status))
869    {
870        ObjDesc->Device.GpeBlock = NULL;
871    }
872
873UnlockAndExit:
874    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
875    return_ACPI_STATUS (Status);
876}
877
878