hwregs.c revision 138287
167754Smsmith
267754Smsmith/*******************************************************************************
367754Smsmith *
467754Smsmith * Module Name: hwregs - Read/write access functions for the various ACPI
567754Smsmith *                       control and status registers.
671867Smsmith *              $Revision: 162 $
767754Smsmith *
867754Smsmith ******************************************************************************/
967754Smsmith
1067754Smsmith/******************************************************************************
1167754Smsmith *
1267754Smsmith * 1. Copyright Notice
1367754Smsmith *
1471867Smsmith * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
1570243Smsmith * All rights reserved.
1667754Smsmith *
1767754Smsmith * 2. License
1867754Smsmith *
1967754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
2067754Smsmith * rights.  You may have additional license terms from the party that provided
2167754Smsmith * you this software, covering your right to use that party's intellectual
2267754Smsmith * property rights.
2367754Smsmith *
2467754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2567754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2667754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2767754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2867754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2967754Smsmith * Code in any form, with the right to sublicense such rights; and
3067754Smsmith *
3167754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3267754Smsmith * license (with the right to sublicense), under only those claims of Intel
3367754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3467754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3567754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3667754Smsmith * license, and in no event shall the patent license extend to any additions
3767754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3867754Smsmith * is granted directly or by implication, estoppel or otherwise;
3967754Smsmith *
4067754Smsmith * The above copyright and patent license is granted only if the following
4167754Smsmith * conditions are met:
4267754Smsmith *
4367754Smsmith * 3. Conditions
4467754Smsmith *
4567754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4667754Smsmith * Redistribution of source code of any substantial portion of the Covered
4767754Smsmith * Code or modification with rights to further distribute source must include
4867754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4967754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
5067754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
5167754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5267754Smsmith * Code and the date of any change.  Licensee must include in that file the
5367754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5467754Smsmith * must include a prominent statement that the modification is derived,
5567754Smsmith * directly or indirectly, from Original Intel Code.
5667754Smsmith *
5767754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5867754Smsmith * Redistribution of source code of any substantial portion of the Covered
5967754Smsmith * Code or modification without rights to further distribute source must
6067754Smsmith * include the following Disclaimer and Export Compliance provision in the
6167754Smsmith * documentation and/or other materials provided with distribution.  In
6267754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6367754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6467754Smsmith * license from Licensee to its licensee is limited to the intellectual
6567754Smsmith * property embodied in the software Licensee provides to its licensee, and
6667754Smsmith * not to intellectual property embodied in modifications its licensee may
6767754Smsmith * make.
6867754Smsmith *
6967754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
7067754Smsmith * substantial portion of the Covered Code or modification must reproduce the
7167754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7267754Smsmith * provision in the documentation and/or other materials provided with the
7367754Smsmith * distribution.
7467754Smsmith *
7567754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7667754Smsmith * Intel Code.
7767754Smsmith *
7867754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7967754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
8067754Smsmith * other dealings in products derived from or relating to the Covered Code
8167754Smsmith * without prior written authorization from Intel.
8267754Smsmith *
8367754Smsmith * 4. Disclaimer and Export Compliance
8467754Smsmith *
8567754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8667754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8767754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8867754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8967754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
9067754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9167754Smsmith * PARTICULAR PURPOSE.
9267754Smsmith *
9367754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9467754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9567754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9667754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9767754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9867754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9967754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
10067754Smsmith * LIMITED REMEDY.
10167754Smsmith *
10267754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10367754Smsmith * software or system incorporating such software without first obtaining any
10467754Smsmith * required license or other approval from the U. S. Department of Commerce or
10567754Smsmith * any other agency or department of the United States Government.  In the
10667754Smsmith * event Licensee exports any such software from the United States or
10767754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10867754Smsmith * ensure that the distribution and export/re-export of the software is in
10967754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
11067754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11167754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11267754Smsmith * software, or service, directly or indirectly, to any country for which the
11367754Smsmith * United States government or any agency thereof requires an export license,
11467754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11567754Smsmith * such license, approval or letter.
11667754Smsmith *
11767754Smsmith *****************************************************************************/
11867754Smsmith
11967754Smsmith#define __HWREGS_C__
12067754Smsmith
12167754Smsmith#include "acpi.h"
12267754Smsmith#include "acnamesp.h"
12367754Smsmith#include "acevents.h"
12467754Smsmith
12567754Smsmith#define _COMPONENT          ACPI_HARDWARE
12667754Smsmith        ACPI_MODULE_NAME    ("hwregs")
12767754Smsmith
12867754Smsmith
12967754Smsmith/*******************************************************************************
13067754Smsmith *
13169450Smsmith * FUNCTION:    AcpiHwClearAcpiStatus
13271867Smsmith *
13367754Smsmith * PARAMETERS:  Flags           - Lock the hardware or not
13467754Smsmith *
13567754Smsmith * RETURN:      none
13667754Smsmith *
13767754Smsmith * DESCRIPTION: Clears all fixed and general purpose status bits
13867754Smsmith *              THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
13967754Smsmith *
14067754Smsmith ******************************************************************************/
14167754Smsmith
14267754SmsmithACPI_STATUS
14367754SmsmithAcpiHwClearAcpiStatus (
14467754Smsmith    UINT32                  Flags)
14567754Smsmith{
14667754Smsmith    ACPI_STATUS             Status;
14767754Smsmith
14871867Smsmith
14967754Smsmith    ACPI_FUNCTION_TRACE ("HwClearAcpiStatus");
15067754Smsmith
15167754Smsmith
15267754Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %04X to %04X\n",
15367754Smsmith        ACPI_BITMASK_ALL_FIXED_STATUS,
15467754Smsmith        (UINT16) ACPI_GET_ADDRESS (AcpiGbl_FADT->XPm1aEvtBlk.Address)));
15567754Smsmith
15667754Smsmith    if (Flags & ACPI_MTX_LOCK)
15767754Smsmith    {
15867754Smsmith        Status = AcpiUtAcquireMutex (ACPI_MTX_HARDWARE);
15967754Smsmith        if (ACPI_FAILURE (Status))
16067754Smsmith        {
16167754Smsmith            return_ACPI_STATUS (Status);
16267754Smsmith        }
16367754Smsmith    }
16467754Smsmith
16567754Smsmith    Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
16667754Smsmith                    ACPI_BITMASK_ALL_FIXED_STATUS);
16767754Smsmith    if (ACPI_FAILURE (Status))
16867754Smsmith    {
16967754Smsmith        goto UnlockAndExit;
17067754Smsmith    }
17167754Smsmith
17267754Smsmith    /* Clear the fixed events */
17367754Smsmith
17467754Smsmith    if (ACPI_VALID_ADDRESS (AcpiGbl_FADT->XPm1bEvtBlk.Address))
17567754Smsmith    {
17667754Smsmith        Status = AcpiHwLowLevelWrite (16, ACPI_BITMASK_ALL_FIXED_STATUS,
17767754Smsmith                    &AcpiGbl_FADT->XPm1bEvtBlk);
17867754Smsmith        if (ACPI_FAILURE (Status))
17967754Smsmith        {
18067754Smsmith            goto UnlockAndExit;
18167754Smsmith        }
18267754Smsmith    }
18367754Smsmith
18467754Smsmith    /* Clear the GPE Bits in all GPE registers in all GPE blocks */
18567754Smsmith
18667754Smsmith    Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, ACPI_ISR);
18767754Smsmith
18869450SmsmithUnlockAndExit:
18970243Smsmith    if (Flags & ACPI_MTX_LOCK)
19067754Smsmith    {
19167754Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_HARDWARE);
19267754Smsmith    }
19367754Smsmith    return_ACPI_STATUS (Status);
19469450Smsmith}
19567754Smsmith
19669450Smsmith
19770243Smsmith/*******************************************************************************
19867754Smsmith *
19970243Smsmith * FUNCTION:    AcpiGetSleepTypeData
20067754Smsmith *
20167754Smsmith * PARAMETERS:  SleepState          - Numeric sleep state
20267754Smsmith *              *SleepTypeA         - Where SLP_TYPa is returned
20367754Smsmith *              *SleepTypeB         - Where SLP_TYPb is returned
20467754Smsmith *
20569450Smsmith * RETURN:      Status - ACPI status
20667754Smsmith *
20769450Smsmith * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
20867754Smsmith *              state.
20967754Smsmith *
21067754Smsmith ******************************************************************************/
21170243Smsmith
21269450SmsmithACPI_STATUS
21367754SmsmithAcpiGetSleepTypeData (
21467754Smsmith    UINT8                   SleepState,
21567754Smsmith    UINT8                   *SleepTypeA,
21669450Smsmith    UINT8                   *SleepTypeB)
21767754Smsmith{
21869450Smsmith    ACPI_STATUS             Status = AE_OK;
21967754Smsmith    ACPI_PARAMETER_INFO     Info;
22067754Smsmith
22167754Smsmith
22270243Smsmith    ACPI_FUNCTION_TRACE ("AcpiGetSleepTypeData");
22369450Smsmith
22467754Smsmith
22567754Smsmith    /*
22667754Smsmith     * Validate parameters
22767754Smsmith     */
22867754Smsmith    if ((SleepState > ACPI_S_STATES_MAX) ||
22967754Smsmith        !SleepTypeA || !SleepTypeB)
23067754Smsmith    {
23167754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
23267754Smsmith    }
23367754Smsmith
23467754Smsmith    /*
23567754Smsmith     * Evaluate the namespace object containing the values for this state
23667754Smsmith     */
23767754Smsmith    Info.Parameters = NULL;
23867754Smsmith    Status = AcpiNsEvaluateByName ((char *) AcpiGbl_SleepStateNames[SleepState],
23967754Smsmith                    &Info);
24067754Smsmith    if (ACPI_FAILURE (Status))
24167754Smsmith    {
24267754Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s while evaluating SleepState [%s]\n",
24367754Smsmith            AcpiFormatException (Status), AcpiGbl_SleepStateNames[SleepState]));
24467754Smsmith
24567754Smsmith        return_ACPI_STATUS (Status);
24667754Smsmith    }
24767754Smsmith
24867754Smsmith    /* Must have a return object */
24967754Smsmith
25067754Smsmith    if (!Info.ReturnObject)
25167754Smsmith    {
25267754Smsmith        ACPI_REPORT_ERROR (("Missing Sleep State object\n"));
25367754Smsmith        Status = AE_NOT_EXIST;
25467754Smsmith    }
25567754Smsmith
25667754Smsmith    /* It must be of type Package */
25767754Smsmith
25867754Smsmith    else if (ACPI_GET_OBJECT_TYPE (Info.ReturnObject) != ACPI_TYPE_PACKAGE)
25967754Smsmith    {
26067754Smsmith        ACPI_REPORT_ERROR (("Sleep State object not a Package\n"));
26167754Smsmith        Status = AE_AML_OPERAND_TYPE;
26267754Smsmith    }
26367754Smsmith
26467754Smsmith    /* The package must have at least two elements */
26567754Smsmith
26667754Smsmith    else if (Info.ReturnObject->Package.Count < 2)
26767754Smsmith    {
26867754Smsmith        ACPI_REPORT_ERROR (("Sleep State package does not have at least two elements\n"));
26967754Smsmith        Status = AE_AML_NO_OPERAND;
27067754Smsmith    }
27167754Smsmith
27267754Smsmith    /* The first two elements must both be of type Integer */
27367754Smsmith
27467754Smsmith    else if ((ACPI_GET_OBJECT_TYPE (Info.ReturnObject->Package.Elements[0]) != ACPI_TYPE_INTEGER) ||
27567754Smsmith             (ACPI_GET_OBJECT_TYPE (Info.ReturnObject->Package.Elements[1]) != ACPI_TYPE_INTEGER))
27667754Smsmith    {
27767754Smsmith        ACPI_REPORT_ERROR (("Sleep State package elements are not both Integers (%s, %s)\n",
27867754Smsmith            AcpiUtGetObjectTypeName (Info.ReturnObject->Package.Elements[0]),
27967754Smsmith            AcpiUtGetObjectTypeName (Info.ReturnObject->Package.Elements[1])));
28067754Smsmith        Status = AE_AML_OPERAND_TYPE;
28167754Smsmith    }
28267754Smsmith    else
28367754Smsmith    {
28467754Smsmith        /*
28567754Smsmith         * Valid _Sx_ package size, type, and value
28667754Smsmith         */
28767754Smsmith        *SleepTypeA = (UINT8) (Info.ReturnObject->Package.Elements[0])->Integer.Value;
28867754Smsmith        *SleepTypeB = (UINT8) (Info.ReturnObject->Package.Elements[1])->Integer.Value;
28967754Smsmith    }
29067754Smsmith
29167754Smsmith    if (ACPI_FAILURE (Status))
29267754Smsmith    {
29367754Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
29467754Smsmith            "While evaluating SleepState [%s], bad Sleep object %p type %s\n",
29567754Smsmith            AcpiGbl_SleepStateNames[SleepState], Info.ReturnObject,
29667754Smsmith            AcpiUtGetObjectTypeName (Info.ReturnObject)));
29767754Smsmith    }
29867754Smsmith
29967754Smsmith    AcpiUtRemoveReference (Info.ReturnObject);
30067754Smsmith    return_ACPI_STATUS (Status);
30167754Smsmith}
30267754Smsmith
30371867Smsmith
30467754Smsmith/*******************************************************************************
30571867Smsmith *
30667754Smsmith * FUNCTION:    AcpiHwGetRegisterBitMask
30767754Smsmith *
30867754Smsmith * PARAMETERS:  RegisterId          - Index of ACPI Register to access
30967754Smsmith *
31067754Smsmith * RETURN:      The bit mask to be used when accessing the register
31167754Smsmith *
31267754Smsmith * DESCRIPTION: Map RegisterId into a register bit mask.
31367754Smsmith *
31467754Smsmith ******************************************************************************/
31567754Smsmith
31667754SmsmithACPI_BIT_REGISTER_INFO *
31767754SmsmithAcpiHwGetBitRegisterInfo (
31871867Smsmith    UINT32                  RegisterId)
31967754Smsmith{
32071867Smsmith    ACPI_FUNCTION_NAME ("HwGetBitRegisterInfo");
32167754Smsmith
32267754Smsmith
32367754Smsmith    if (RegisterId > ACPI_BITREG_MAX)
32467754Smsmith    {
32567754Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid BitRegister ID: %X\n", RegisterId));
32667754Smsmith        return (NULL);
32767754Smsmith    }
32867754Smsmith
32967754Smsmith    return (&AcpiGbl_BitRegisterInfo[RegisterId]);
33067754Smsmith}
33167754Smsmith
33267754Smsmith
33367754Smsmith/*******************************************************************************
33467754Smsmith *
33567754Smsmith * FUNCTION:    AcpiGetRegister
33667754Smsmith *
33767754Smsmith * PARAMETERS:  RegisterId      - ID of ACPI BitRegister to access
33867754Smsmith *              ReturnValue     - Value that was read from the register
33969450Smsmith *              Flags           - Lock the hardware or not
34067754Smsmith *
34167754Smsmith * RETURN:      Status and the value read from specified Register.  Value
34267754Smsmith *              returned is normalized to bit0 (is shifted all the way right)
34369450Smsmith *
34467754Smsmith * DESCRIPTION: ACPI BitRegister read function.
34569450Smsmith *
34667754Smsmith ******************************************************************************/
34769450Smsmith
34867754SmsmithACPI_STATUS
34967754SmsmithAcpiGetRegister (
35069450Smsmith    UINT32                  RegisterId,
35167754Smsmith    UINT32                  *ReturnValue,
35267754Smsmith    UINT32                  Flags)
35367754Smsmith{
35467754Smsmith    UINT32                  RegisterValue = 0;
35569450Smsmith    ACPI_BIT_REGISTER_INFO  *BitRegInfo;
35667754Smsmith    ACPI_STATUS             Status;
35767754Smsmith
35867754Smsmith
35967754Smsmith    ACPI_FUNCTION_TRACE ("AcpiGetRegister");
36067754Smsmith
36167754Smsmith
36267754Smsmith    /* Get the info structure corresponding to the requested ACPI Register */
36367754Smsmith
36467754Smsmith    BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
36569450Smsmith    if (!BitRegInfo)
36667754Smsmith    {
36767754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
36867754Smsmith    }
36967754Smsmith
37067754Smsmith    if (Flags & ACPI_MTX_LOCK)
37167754Smsmith    {
37267754Smsmith        Status = AcpiUtAcquireMutex (ACPI_MTX_HARDWARE);
37367754Smsmith        if (ACPI_FAILURE (Status))
37467754Smsmith        {
37567754Smsmith            return_ACPI_STATUS (Status);
37667754Smsmith        }
37769450Smsmith    }
37869450Smsmith
37969450Smsmith    /* Read from the register */
38067754Smsmith
38167754Smsmith    Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK,
38267754Smsmith                    BitRegInfo->ParentRegister, &RegisterValue);
38369450Smsmith
38469450Smsmith    if (Flags & ACPI_MTX_LOCK)
38569450Smsmith    {
38669450Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_HARDWARE);
38767754Smsmith    }
38867754Smsmith
38969450Smsmith    if (ACPI_SUCCESS (Status))
39067754Smsmith    {
39169450Smsmith        /* Normalize the value that was read */
39267754Smsmith
39369450Smsmith        RegisterValue = ((RegisterValue & BitRegInfo->AccessBitMask)
39467754Smsmith                            >> BitRegInfo->BitPosition);
39569450Smsmith
39669450Smsmith        *ReturnValue = RegisterValue;
39769450Smsmith
39867754Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read value %8.8X register %X\n",
39969450Smsmith                RegisterValue, BitRegInfo->ParentRegister));
40069450Smsmith    }
40169450Smsmith
40267754Smsmith    return_ACPI_STATUS (Status);
40369450Smsmith}
40469450Smsmith
40569450Smsmith
40667754Smsmith/*******************************************************************************
40769450Smsmith *
40869450Smsmith * FUNCTION:    AcpiSetRegister
40969450Smsmith *
41067754Smsmith * PARAMETERS:  RegisterId      - ID of ACPI BitRegister to access
41169450Smsmith *              Value           - (only used on write) value to write to the
41269450Smsmith *                                Register, NOT pre-normalized to the bit pos
41369450Smsmith *              Flags           - Lock the hardware or not
41467754Smsmith *
41569450Smsmith * RETURN:      Status
41669450Smsmith *
41769450Smsmith * DESCRIPTION: ACPI Bit Register write function.
41867754Smsmith *
41969450Smsmith ******************************************************************************/
42069450Smsmith
42169450SmsmithACPI_STATUS
42267754SmsmithAcpiSetRegister (
42369450Smsmith    UINT32                  RegisterId,
42469450Smsmith    UINT32                  Value,
42569450Smsmith    UINT32                  Flags)
42669450Smsmith{
42767754Smsmith    UINT32                  RegisterValue = 0;
42869450Smsmith    ACPI_BIT_REGISTER_INFO  *BitRegInfo;
42967754Smsmith    ACPI_STATUS             Status;
43069450Smsmith
43169450Smsmith
43269450Smsmith    ACPI_FUNCTION_TRACE_U32 ("AcpiSetRegister", RegisterId);
43369450Smsmith
43469450Smsmith
43569450Smsmith    /* Get the info structure corresponding to the requested ACPI Register */
43669450Smsmith
43769450Smsmith    BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
43869450Smsmith    if (!BitRegInfo)
43967754Smsmith    {
44069450Smsmith        ACPI_REPORT_ERROR (("Bad ACPI HW RegisterId: %X\n", RegisterId));
44169450Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
44267754Smsmith    }
44369450Smsmith
44467754Smsmith    if (Flags & ACPI_MTX_LOCK)
44569450Smsmith    {
44667754Smsmith        Status = AcpiUtAcquireMutex (ACPI_MTX_HARDWARE);
44769450Smsmith        if (ACPI_FAILURE (Status))
44867754Smsmith        {
44967754Smsmith            return_ACPI_STATUS (Status);
45067754Smsmith        }
45169450Smsmith    }
45267754Smsmith
45367754Smsmith    /* Always do a register read first so we can insert the new bits  */
45469450Smsmith
45567754Smsmith    Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK,
45669450Smsmith                    BitRegInfo->ParentRegister, &RegisterValue);
45769450Smsmith    if (ACPI_FAILURE (Status))
45869450Smsmith    {
45969450Smsmith        goto UnlockAndExit;
46069450Smsmith    }
46167754Smsmith
46269450Smsmith    /*
46369450Smsmith     * Decode the Register ID
46469450Smsmith     * Register ID = [Register block ID] | [bit ID]
46567754Smsmith     *
46669450Smsmith     * Check bit ID to fine locate Register offset.
46769450Smsmith     * Check Mask to determine Register offset, and then read-write.
46869450Smsmith     */
46967754Smsmith    switch (BitRegInfo->ParentRegister)
47069450Smsmith    {
47169450Smsmith    case ACPI_REGISTER_PM1_STATUS:
47269450Smsmith
47367754Smsmith        /*
47469450Smsmith         * Status Registers are different from the rest.  Clear by
47569450Smsmith         * writing 1, and writing 0 has no effect.  So, the only relevant
47669450Smsmith         * information is the single bit we're interested in, all others should
47767754Smsmith         * be written as 0 so they will be left unchanged.
47869450Smsmith         */
47969450Smsmith        Value = ACPI_REGISTER_PREPARE_BITS (Value,
48069450Smsmith                    BitRegInfo->BitPosition, BitRegInfo->AccessBitMask);
48169450Smsmith        if (Value)
48267754Smsmith        {
48369450Smsmith            Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
48467754Smsmith                        ACPI_REGISTER_PM1_STATUS, (UINT16) Value);
48569450Smsmith            RegisterValue = 0;
48669450Smsmith        }
48769450Smsmith        break;
48869450Smsmith
48969450Smsmith
49069450Smsmith    case ACPI_REGISTER_PM1_ENABLE:
49167754Smsmith
49269450Smsmith        ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
49369450Smsmith                BitRegInfo->AccessBitMask, Value);
49467754Smsmith
49567754Smsmith        Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
49667754Smsmith                        ACPI_REGISTER_PM1_ENABLE, (UINT16) RegisterValue);
49767754Smsmith        break;
49867754Smsmith
49967754Smsmith
50067754Smsmith    case ACPI_REGISTER_PM1_CONTROL:
50167754Smsmith
50267754Smsmith        /*
50367754Smsmith         * Write the PM1 Control register.
50467754Smsmith         * Note that at this level, the fact that there are actually TWO
50567754Smsmith         * registers (A and B - and B may not exist) is abstracted.
50667754Smsmith         */
50767754Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM1 control: Read %X\n", RegisterValue));
50867754Smsmith
50967754Smsmith        ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
51067754Smsmith                BitRegInfo->AccessBitMask, Value);
51167754Smsmith
51267754Smsmith        Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
51367754Smsmith                        ACPI_REGISTER_PM1_CONTROL, (UINT16) RegisterValue);
51467754Smsmith        break;
51567754Smsmith
51667754Smsmith
51767754Smsmith    case ACPI_REGISTER_PM2_CONTROL:
51867754Smsmith
51967754Smsmith        Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK,
52067754Smsmith                    ACPI_REGISTER_PM2_CONTROL, &RegisterValue);
52167754Smsmith        if (ACPI_FAILURE (Status))
52267754Smsmith        {
52367754Smsmith            goto UnlockAndExit;
52467754Smsmith        }
52567754Smsmith
52667754Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n",
52767754Smsmith            RegisterValue,
52869450Smsmith            ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (AcpiGbl_FADT->XPm2CntBlk.Address))));
52969450Smsmith
53069450Smsmith        ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
53169450Smsmith                BitRegInfo->AccessBitMask, Value);
53269450Smsmith
53369450Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n",
53469450Smsmith            RegisterValue,
53569450Smsmith            ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (AcpiGbl_FADT->XPm2CntBlk.Address))));
53669746Smsmith
53769450Smsmith        Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
53867754Smsmith                            ACPI_REGISTER_PM2_CONTROL, (UINT8) (RegisterValue));
53967754Smsmith        break;
54067754Smsmith
54167754Smsmith
54267754Smsmith    default:
54367754Smsmith        break;
54467754Smsmith    }
54567754Smsmith
54669450Smsmith
54769450SmsmithUnlockAndExit:
54869450Smsmith
54967754Smsmith    if (Flags & ACPI_MTX_LOCK)
55069746Smsmith    {
55169746Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_HARDWARE);
55269746Smsmith    }
55367754Smsmith
55467754Smsmith    /* Normalize the value that was read */
55569450Smsmith
55669746Smsmith    ACPI_DEBUG_EXEC (RegisterValue = ((RegisterValue & BitRegInfo->AccessBitMask) >> BitRegInfo->BitPosition));
55767754Smsmith
55867754Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n",
55967754Smsmith            Value, RegisterValue, BitRegInfo->ParentRegister));
56067754Smsmith    return_ACPI_STATUS (Status);
56167754Smsmith}
56267754Smsmith
56367754Smsmith
56467754Smsmith/******************************************************************************
56567754Smsmith *
56667754Smsmith * FUNCTION:    AcpiHwRegisterRead
56767754Smsmith *
56867754Smsmith * PARAMETERS:  UseLock             - Mutex hw access
56967754Smsmith *              RegisterId          - RegisterID + Offset
57067754Smsmith *              ReturnValue         - Value that was read from the register
57167754Smsmith *
57267754Smsmith * RETURN:      Status and the value read.
57367754Smsmith *
57469450Smsmith * DESCRIPTION: Acpi register read function.  Registers are read at the
57569450Smsmith *              given offset.
57669746Smsmith *
57770243Smsmith ******************************************************************************/
57869450Smsmith
57967754SmsmithACPI_STATUS
58067754SmsmithAcpiHwRegisterRead (
58167754Smsmith    BOOLEAN                 UseLock,
58267754Smsmith    UINT32                  RegisterId,
58367754Smsmith    UINT32                  *ReturnValue)
58467754Smsmith{
58567754Smsmith    UINT32                  Value1 = 0;
58667754Smsmith    UINT32                  Value2 = 0;
58769746Smsmith    ACPI_STATUS             Status;
58869450Smsmith
58967754Smsmith
59069450Smsmith    ACPI_FUNCTION_TRACE ("HwRegisterRead");
59169450Smsmith
59267754Smsmith
59367754Smsmith    if (ACPI_MTX_LOCK == UseLock)
59467754Smsmith    {
59567754Smsmith        Status = AcpiUtAcquireMutex (ACPI_MTX_HARDWARE);
59667754Smsmith        if (ACPI_FAILURE (Status))
59767754Smsmith        {
59869450Smsmith            return_ACPI_STATUS (Status);
59969450Smsmith        }
60069450Smsmith    }
60169746Smsmith
60270243Smsmith    switch (RegisterId)
60367754Smsmith    {
60467754Smsmith    case ACPI_REGISTER_PM1_STATUS:           /* 16-bit access */
60567754Smsmith
60667754Smsmith        Status = AcpiHwLowLevelRead (16, &Value1, &AcpiGbl_FADT->XPm1aEvtBlk);
60767754Smsmith        if (ACPI_FAILURE (Status))
60867754Smsmith        {
60967754Smsmith            goto UnlockAndExit;
61067754Smsmith        }
61167754Smsmith
61269450Smsmith        /* PM1B is optional */
61369450Smsmith
61469450Smsmith        Status = AcpiHwLowLevelRead (16, &Value2, &AcpiGbl_FADT->XPm1bEvtBlk);
61569450Smsmith        Value1 |= Value2;
61669450Smsmith        break;
61769450Smsmith
61869450Smsmith
61969450Smsmith    case ACPI_REGISTER_PM1_ENABLE:           /* 16-bit access */
62069450Smsmith
62169450Smsmith        Status = AcpiHwLowLevelRead (16, &Value1, &AcpiGbl_XPm1aEnable);
62269450Smsmith        if (ACPI_FAILURE (Status))
62367754Smsmith        {
62469450Smsmith            goto UnlockAndExit;
62569450Smsmith        }
62669450Smsmith
62767754Smsmith        /* PM1B is optional */
62867754Smsmith
62967754Smsmith        Status = AcpiHwLowLevelRead (16, &Value2, &AcpiGbl_XPm1bEnable);
63067754Smsmith        Value1 |= Value2;
63169450Smsmith        break;
63269450Smsmith
63367754Smsmith
63467754Smsmith    case ACPI_REGISTER_PM1_CONTROL:          /* 16-bit access */
63567754Smsmith
63667754Smsmith        Status = AcpiHwLowLevelRead (16, &Value1, &AcpiGbl_FADT->XPm1aCntBlk);
63769450Smsmith        if (ACPI_FAILURE (Status))
63867754Smsmith        {
63967754Smsmith            goto UnlockAndExit;
64067754Smsmith        }
64167754Smsmith
64269450Smsmith        Status = AcpiHwLowLevelRead (16, &Value2, &AcpiGbl_FADT->XPm1bCntBlk);
64369746Smsmith        Value1 |= Value2;
64469450Smsmith        break;
64567754Smsmith
64667754Smsmith
64767754Smsmith    case ACPI_REGISTER_PM2_CONTROL:          /* 8-bit access */
64867754Smsmith
64967754Smsmith        Status = AcpiHwLowLevelRead (8, &Value1, &AcpiGbl_FADT->XPm2CntBlk);
65067754Smsmith        break;
65167754Smsmith
65267754Smsmith
65367754Smsmith    case ACPI_REGISTER_PM_TIMER:             /* 32-bit access */
65467754Smsmith
65567754Smsmith        Status = AcpiHwLowLevelRead (32, &Value1, &AcpiGbl_FADT->XPmTmrBlk);
65667754Smsmith        break;
65769450Smsmith
65869450Smsmith    case ACPI_REGISTER_SMI_COMMAND_BLOCK:    /* 8-bit access */
65969450Smsmith
66069450Smsmith        Status = AcpiOsReadPort (AcpiGbl_FADT->SmiCmd, &Value1, 8);
66167754Smsmith        break;
66267754Smsmith
66367754Smsmith    default:
66467754Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n", RegisterId));
66569450Smsmith        Status = AE_BAD_PARAMETER;
66667754Smsmith        break;
66769450Smsmith    }
66867754Smsmith
66967754SmsmithUnlockAndExit:
67067754Smsmith    if (ACPI_MTX_LOCK == UseLock)
67167754Smsmith    {
67267754Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_HARDWARE);
67367754Smsmith    }
67469450Smsmith
67569450Smsmith    if (ACPI_SUCCESS (Status))
67669450Smsmith    {
67767754Smsmith        *ReturnValue = Value1;
67869450Smsmith    }
67967754Smsmith
68067754Smsmith    return_ACPI_STATUS (Status);
68167754Smsmith}
68269746Smsmith
68367754Smsmith
68467754Smsmith/******************************************************************************
68569450Smsmith *
68669450Smsmith * FUNCTION:    AcpiHwRegisterWrite
68769450Smsmith *
68869450Smsmith * PARAMETERS:  UseLock             - Mutex hw access
68969450Smsmith *              RegisterId          - RegisterID + Offset
69069450Smsmith *              Value               - The value to write
69169450Smsmith *
69269450Smsmith * RETURN:      Status
69369450Smsmith *
69469450Smsmith * DESCRIPTION: Acpi register Write function.  Registers are written at the
69569450Smsmith *              given offset.
69669450Smsmith *
69769450Smsmith ******************************************************************************/
69869450Smsmith
69969450SmsmithACPI_STATUS
70069450SmsmithAcpiHwRegisterWrite (
70169450Smsmith    BOOLEAN                 UseLock,
70269450Smsmith    UINT32                  RegisterId,
70369450Smsmith    UINT32                  Value)
70469450Smsmith{
70569450Smsmith    ACPI_STATUS             Status;
70669450Smsmith
70769450Smsmith
70869450Smsmith    ACPI_FUNCTION_TRACE ("HwRegisterWrite");
70969450Smsmith
71069450Smsmith
71169450Smsmith    if (ACPI_MTX_LOCK == UseLock)
71269450Smsmith    {
71369450Smsmith        Status = AcpiUtAcquireMutex (ACPI_MTX_HARDWARE);
71469450Smsmith        if (ACPI_FAILURE (Status))
71569450Smsmith        {
71669450Smsmith            return_ACPI_STATUS (Status);
71769450Smsmith        }
71869450Smsmith    }
71969450Smsmith
72069450Smsmith    switch (RegisterId)
72169746Smsmith    {
72269746Smsmith    case ACPI_REGISTER_PM1_STATUS:           /* 16-bit access */
72369450Smsmith
72469450Smsmith        Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1aEvtBlk);
72569450Smsmith        if (ACPI_FAILURE (Status))
72669450Smsmith        {
72769450Smsmith            goto UnlockAndExit;
72869450Smsmith        }
72969746Smsmith
73069746Smsmith        /* PM1B is optional */
73169450Smsmith
73269450Smsmith        Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1bEvtBlk);
73369450Smsmith        break;
73469450Smsmith
73569450Smsmith
73671867Smsmith    case ACPI_REGISTER_PM1_ENABLE:           /* 16-bit access*/
73771867Smsmith
73869450Smsmith        Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_XPm1aEnable);
73969450Smsmith        if (ACPI_FAILURE (Status))
74069450Smsmith        {
74169450Smsmith            goto UnlockAndExit;
74269450Smsmith        }
74369746Smsmith
74469450Smsmith        /* PM1B is optional */
74569450Smsmith
74669450Smsmith        Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_XPm1bEnable);
74769450Smsmith        break;
74869450Smsmith
74969746Smsmith
75069450Smsmith    case ACPI_REGISTER_PM1_CONTROL:          /* 16-bit access */
75169450Smsmith
75269450Smsmith        Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1aCntBlk);
75369450Smsmith        if (ACPI_FAILURE (Status))
75469450Smsmith        {
75569746Smsmith            goto UnlockAndExit;
75669450Smsmith        }
75769450Smsmith
75869450Smsmith        Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1bCntBlk);
75969450Smsmith        break;
76069450Smsmith
76169450Smsmith
76269746Smsmith    case ACPI_REGISTER_PM1A_CONTROL:         /* 16-bit access */
76369450Smsmith
76469450Smsmith        Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1aCntBlk);
76569450Smsmith        break;
76669450Smsmith
76769450Smsmith
76869746Smsmith    case ACPI_REGISTER_PM1B_CONTROL:         /* 16-bit access */
76969450Smsmith
77069450Smsmith        Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1bCntBlk);
77169450Smsmith        break;
77269450Smsmith
77369450Smsmith
77469450Smsmith    case ACPI_REGISTER_PM2_CONTROL:          /* 8-bit access */
77569746Smsmith
77669450Smsmith        Status = AcpiHwLowLevelWrite (8, Value, &AcpiGbl_FADT->XPm2CntBlk);
77769450Smsmith        break;
77869450Smsmith
77969450Smsmith
78069450Smsmith    case ACPI_REGISTER_PM_TIMER:             /* 32-bit access */
78169450Smsmith
78269450Smsmith        Status = AcpiHwLowLevelWrite (32, Value, &AcpiGbl_FADT->XPmTmrBlk);
78369450Smsmith        break;
78469450Smsmith
78569450Smsmith
78669450Smsmith    case ACPI_REGISTER_SMI_COMMAND_BLOCK:    /* 8-bit access */
78769450Smsmith
78869450Smsmith        /* SMI_CMD is currently always in IO space */
78969450Smsmith
79069450Smsmith        Status = AcpiOsWritePort (AcpiGbl_FADT->SmiCmd, Value, 8);
79169450Smsmith        break;
79269450Smsmith
79369450Smsmith
79469450Smsmith    default:
79569450Smsmith        Status = AE_BAD_PARAMETER;
79669450Smsmith        break;
79769450Smsmith    }
79869450Smsmith
79969450SmsmithUnlockAndExit:
80069450Smsmith    if (ACPI_MTX_LOCK == UseLock)
80169450Smsmith    {
80269450Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_HARDWARE);
80369450Smsmith    }
80469450Smsmith
80569450Smsmith    return_ACPI_STATUS (Status);
80669450Smsmith}
80769450Smsmith
80869450Smsmith
80969450Smsmith/******************************************************************************
81069450Smsmith *
81169450Smsmith * FUNCTION:    AcpiHwLowLevelRead
81269450Smsmith *
81369450Smsmith * PARAMETERS:  Width               - 8, 16, or 32
81469450Smsmith *              Value               - Where the value is returned
81569450Smsmith *              Reg                 - GAS register structure
81669450Smsmith *
81769450Smsmith * RETURN:      Status
81869450Smsmith *
81969450Smsmith * DESCRIPTION: Read from either memory or IO space.
82069450Smsmith *
82169450Smsmith ******************************************************************************/
82269450Smsmith
82369450SmsmithACPI_STATUS
82469450SmsmithAcpiHwLowLevelRead (
82569450Smsmith    UINT32                  Width,
82669450Smsmith    UINT32                  *Value,
82769450Smsmith    ACPI_GENERIC_ADDRESS    *Reg)
82869450Smsmith{
82969450Smsmith    UINT64                  Address;
83069450Smsmith    ACPI_STATUS             Status;
83169450Smsmith
83269450Smsmith
83369450Smsmith    ACPI_FUNCTION_NAME ("HwLowLevelRead");
83469450Smsmith
83569746Smsmith
83669746Smsmith    /*
83769450Smsmith     * Must have a valid pointer to a GAS structure, and
83869450Smsmith     * a non-zero address within. However, don't return an error
83969450Smsmith     * because the PM1A/B code must not fail if B isn't present.
84069450Smsmith     */
84169450Smsmith    if (!Reg)
84269450Smsmith    {
84369746Smsmith        return (AE_OK);
84469746Smsmith    }
84569450Smsmith
84669450Smsmith    /* Get a local copy of the address.  Handles possible alignment issues */
84769450Smsmith
84869450Smsmith    ACPI_MOVE_64_TO_64 (&Address, &Reg->Address);
84969450Smsmith    if (!ACPI_VALID_ADDRESS (Address))
85071867Smsmith    {
85171867Smsmith        return (AE_OK);
85271867Smsmith    }
85369450Smsmith    *Value = 0;
85469450Smsmith
85571867Smsmith    /*
85669450Smsmith     * Two address spaces supported: Memory or IO.
85771867Smsmith     * PCI_Config is not supported here because the GAS struct is insufficient
85869450Smsmith     */
85969450Smsmith    switch (Reg->AddressSpaceId)
86069450Smsmith    {
86171867Smsmith    case ACPI_ADR_SPACE_SYSTEM_MEMORY:
86271867Smsmith
86371867Smsmith        Status = AcpiOsReadMemory (
86471867Smsmith                    (ACPI_PHYSICAL_ADDRESS) ACPI_GET_ADDRESS (Address),
86571867Smsmith                    Value, Width);
86671867Smsmith        break;
86769450Smsmith
86869450Smsmith
86969746Smsmith    case ACPI_ADR_SPACE_SYSTEM_IO:
87069450Smsmith
87169450Smsmith        Status = AcpiOsReadPort ((ACPI_IO_ADDRESS) ACPI_GET_ADDRESS (Address),
87269450Smsmith                    Value, Width);
87369450Smsmith        break;
87469450Smsmith
87569746Smsmith
87669450Smsmith    default:
87769450Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
87869450Smsmith            "Unsupported address space: %X\n", Reg->AddressSpaceId));
87969450Smsmith        return (AE_BAD_PARAMETER);
88069450Smsmith    }
88169746Smsmith
88269450Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read:  %8.8X width %2d from %8.8X%8.8X (%s)\n",
88369450Smsmith            *Value, Width,
88469450Smsmith            ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (Address)),
88569450Smsmith            AcpiUtGetRegionName (Reg->AddressSpaceId)));
88669450Smsmith
88769450Smsmith    return (Status);
88869746Smsmith}
88969450Smsmith
89069450Smsmith
89169450Smsmith/******************************************************************************
89269450Smsmith *
89369450Smsmith * FUNCTION:    AcpiHwLowLevelWrite
89469746Smsmith *
89569450Smsmith * PARAMETERS:  Width               - 8, 16, or 32
89669450Smsmith *              Value               - To be written
89769450Smsmith *              Reg                 - GAS register structure
89869450Smsmith *
89969450Smsmith * RETURN:      Status
90069450Smsmith *
90169746Smsmith * DESCRIPTION: Write to either memory or IO space.
90269450Smsmith *
90369450Smsmith ******************************************************************************/
90469450Smsmith
90569450SmsmithACPI_STATUS
90669450SmsmithAcpiHwLowLevelWrite (
90769450Smsmith    UINT32                  Width,
90869450Smsmith    UINT32                  Value,
90969450Smsmith    ACPI_GENERIC_ADDRESS    *Reg)
91069450Smsmith{
91169450Smsmith    UINT64                  Address;
91269450Smsmith    ACPI_STATUS             Status;
91369450Smsmith
91469450Smsmith
91569450Smsmith    ACPI_FUNCTION_NAME ("HwLowLevelWrite");
91669450Smsmith
91769450Smsmith
91869450Smsmith    /*
91969450Smsmith     * Must have a valid pointer to a GAS structure, and
92069450Smsmith     * a non-zero address within. However, don't return an error
92169450Smsmith     * because the PM1A/B code must not fail if B isn't present.
92269450Smsmith     */
92369450Smsmith    if (!Reg)
92469450Smsmith    {
92569450Smsmith        return (AE_OK);
92669450Smsmith    }
92769450Smsmith
92869450Smsmith    /* Get a local copy of the address.  Handles possible alignment issues */
92969450Smsmith
93069450Smsmith    ACPI_MOVE_64_TO_64 (&Address, &Reg->Address);
93169450Smsmith    if (!ACPI_VALID_ADDRESS (Address))
93269450Smsmith    {
93369450Smsmith        return (AE_OK);
93469450Smsmith    }
93569450Smsmith
93669450Smsmith    /*
93769450Smsmith     * Two address spaces supported: Memory or IO.
93869450Smsmith     * PCI_Config is not supported here because the GAS struct is insufficient
93969450Smsmith     */
94069450Smsmith    switch (Reg->AddressSpaceId)
94169450Smsmith    {
94269450Smsmith    case ACPI_ADR_SPACE_SYSTEM_MEMORY:
94369450Smsmith
94469450Smsmith        Status = AcpiOsWriteMemory (
94569450Smsmith                    (ACPI_PHYSICAL_ADDRESS) ACPI_GET_ADDRESS (Address),
94669450Smsmith                    Value, Width);
94769450Smsmith        break;
94869450Smsmith
94969450Smsmith
95069450Smsmith    case ACPI_ADR_SPACE_SYSTEM_IO:
95169450Smsmith
95269450Smsmith        Status = AcpiOsWritePort ((ACPI_IO_ADDRESS) ACPI_GET_ADDRESS (Address),
95369450Smsmith                    Value, Width);
95469450Smsmith        break;
95569450Smsmith
95669450Smsmith
95769450Smsmith    default:
95869450Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
95969450Smsmith            "Unsupported address space: %X\n", Reg->AddressSpaceId));
96069450Smsmith        return (AE_BAD_PARAMETER);
96170243Smsmith    }
96269450Smsmith
96369450Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X width %2d   to %8.8X%8.8X (%s)\n",
96469450Smsmith            Value, Width,
96569450Smsmith            ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (Address)),
96669450Smsmith            AcpiUtGetRegionName (Reg->AddressSpaceId)));
96769450Smsmith
96869450Smsmith    return (Status);
96969450Smsmith}
97069450Smsmith