Home | History | Annotate | Line # | Download | only in hardware
hwregs.c revision 1.1.1.2
      1      1.1  jruoho 
      2      1.1  jruoho /*******************************************************************************
      3      1.1  jruoho  *
      4      1.1  jruoho  * Module Name: hwregs - Read/write access functions for the various ACPI
      5      1.1  jruoho  *                       control and status registers.
      6      1.1  jruoho  *
      7      1.1  jruoho  ******************************************************************************/
      8      1.1  jruoho 
      9  1.1.1.2  jruoho /*
     10  1.1.1.2  jruoho  * Copyright (C) 2000 - 2011, Intel Corp.
     11      1.1  jruoho  * All rights reserved.
     12      1.1  jruoho  *
     13  1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     14  1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     15  1.1.1.2  jruoho  * are met:
     16  1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     17  1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     18  1.1.1.2  jruoho  *    without modification.
     19  1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     20  1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     21  1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     22  1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     23  1.1.1.2  jruoho  *    binary redistribution.
     24  1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     25  1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     26  1.1.1.2  jruoho  *    from this software without specific prior written permission.
     27  1.1.1.2  jruoho  *
     28  1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     29  1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     30  1.1.1.2  jruoho  * Software Foundation.
     31  1.1.1.2  jruoho  *
     32  1.1.1.2  jruoho  * NO WARRANTY
     33  1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     34  1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     35  1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     36  1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     37  1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     38  1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     39  1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     40  1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     41  1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     42  1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     43  1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     44  1.1.1.2  jruoho  */
     45      1.1  jruoho 
     46      1.1  jruoho #define __HWREGS_C__
     47      1.1  jruoho 
     48      1.1  jruoho #include "acpi.h"
     49      1.1  jruoho #include "accommon.h"
     50      1.1  jruoho #include "acevents.h"
     51      1.1  jruoho 
     52      1.1  jruoho #define _COMPONENT          ACPI_HARDWARE
     53      1.1  jruoho         ACPI_MODULE_NAME    ("hwregs")
     54      1.1  jruoho 
     55      1.1  jruoho 
     56      1.1  jruoho /* Local Prototypes */
     57      1.1  jruoho 
     58      1.1  jruoho static ACPI_STATUS
     59      1.1  jruoho AcpiHwReadMultiple (
     60      1.1  jruoho     UINT32                  *Value,
     61      1.1  jruoho     ACPI_GENERIC_ADDRESS    *RegisterA,
     62      1.1  jruoho     ACPI_GENERIC_ADDRESS    *RegisterB);
     63      1.1  jruoho 
     64      1.1  jruoho static ACPI_STATUS
     65      1.1  jruoho AcpiHwWriteMultiple (
     66      1.1  jruoho     UINT32                  Value,
     67      1.1  jruoho     ACPI_GENERIC_ADDRESS    *RegisterA,
     68      1.1  jruoho     ACPI_GENERIC_ADDRESS    *RegisterB);
     69      1.1  jruoho 
     70      1.1  jruoho 
     71      1.1  jruoho /******************************************************************************
     72      1.1  jruoho  *
     73      1.1  jruoho  * FUNCTION:    AcpiHwValidateRegister
     74      1.1  jruoho  *
     75      1.1  jruoho  * PARAMETERS:  Reg                 - GAS register structure
     76      1.1  jruoho  *              MaxBitWidth         - Max BitWidth supported (32 or 64)
     77      1.1  jruoho  *              Address             - Pointer to where the gas->address
     78      1.1  jruoho  *                                    is returned
     79      1.1  jruoho  *
     80      1.1  jruoho  * RETURN:      Status
     81      1.1  jruoho  *
     82      1.1  jruoho  * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS
     83      1.1  jruoho  *              pointer, Address, SpaceId, BitWidth, and BitOffset.
     84      1.1  jruoho  *
     85      1.1  jruoho  ******************************************************************************/
     86      1.1  jruoho 
     87      1.1  jruoho ACPI_STATUS
     88      1.1  jruoho AcpiHwValidateRegister (
     89      1.1  jruoho     ACPI_GENERIC_ADDRESS    *Reg,
     90      1.1  jruoho     UINT8                   MaxBitWidth,
     91      1.1  jruoho     UINT64                  *Address)
     92      1.1  jruoho {
     93      1.1  jruoho 
     94      1.1  jruoho     /* Must have a valid pointer to a GAS structure */
     95      1.1  jruoho 
     96      1.1  jruoho     if (!Reg)
     97      1.1  jruoho     {
     98      1.1  jruoho         return (AE_BAD_PARAMETER);
     99      1.1  jruoho     }
    100      1.1  jruoho 
    101      1.1  jruoho     /*
    102      1.1  jruoho      * Copy the target address. This handles possible alignment issues.
    103      1.1  jruoho      * Address must not be null. A null address also indicates an optional
    104      1.1  jruoho      * ACPI register that is not supported, so no error message.
    105      1.1  jruoho      */
    106      1.1  jruoho     ACPI_MOVE_64_TO_64 (Address, &Reg->Address);
    107      1.1  jruoho     if (!(*Address))
    108      1.1  jruoho     {
    109      1.1  jruoho         return (AE_BAD_ADDRESS);
    110      1.1  jruoho     }
    111      1.1  jruoho 
    112      1.1  jruoho     /* Validate the SpaceID */
    113      1.1  jruoho 
    114      1.1  jruoho     if ((Reg->SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
    115      1.1  jruoho         (Reg->SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
    116      1.1  jruoho     {
    117      1.1  jruoho         ACPI_ERROR ((AE_INFO,
    118      1.1  jruoho             "Unsupported address space: 0x%X", Reg->SpaceId));
    119      1.1  jruoho         return (AE_SUPPORT);
    120      1.1  jruoho     }
    121      1.1  jruoho 
    122      1.1  jruoho     /* Validate the BitWidth */
    123      1.1  jruoho 
    124      1.1  jruoho     if ((Reg->BitWidth != 8) &&
    125      1.1  jruoho         (Reg->BitWidth != 16) &&
    126      1.1  jruoho         (Reg->BitWidth != 32) &&
    127      1.1  jruoho         (Reg->BitWidth != MaxBitWidth))
    128      1.1  jruoho     {
    129      1.1  jruoho         ACPI_ERROR ((AE_INFO,
    130      1.1  jruoho             "Unsupported register bit width: 0x%X", Reg->BitWidth));
    131      1.1  jruoho         return (AE_SUPPORT);
    132      1.1  jruoho     }
    133      1.1  jruoho 
    134      1.1  jruoho     /* Validate the BitOffset. Just a warning for now. */
    135      1.1  jruoho 
    136      1.1  jruoho     if (Reg->BitOffset != 0)
    137      1.1  jruoho     {
    138      1.1  jruoho         ACPI_WARNING ((AE_INFO,
    139      1.1  jruoho             "Unsupported register bit offset: 0x%X", Reg->BitOffset));
    140      1.1  jruoho     }
    141      1.1  jruoho 
    142      1.1  jruoho     return (AE_OK);
    143      1.1  jruoho }
    144      1.1  jruoho 
    145      1.1  jruoho 
    146      1.1  jruoho /******************************************************************************
    147      1.1  jruoho  *
    148      1.1  jruoho  * FUNCTION:    AcpiHwRead
    149      1.1  jruoho  *
    150      1.1  jruoho  * PARAMETERS:  Value               - Where the value is returned
    151      1.1  jruoho  *              Reg                 - GAS register structure
    152      1.1  jruoho  *
    153      1.1  jruoho  * RETURN:      Status
    154      1.1  jruoho  *
    155      1.1  jruoho  * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max
    156      1.1  jruoho  *              version of AcpiRead, used internally since the overhead of
    157      1.1  jruoho  *              64-bit values is not needed.
    158      1.1  jruoho  *
    159      1.1  jruoho  * LIMITATIONS: <These limitations also apply to AcpiHwWrite>
    160      1.1  jruoho  *      BitWidth must be exactly 8, 16, or 32.
    161      1.1  jruoho  *      SpaceID must be SystemMemory or SystemIO.
    162      1.1  jruoho  *      BitOffset and AccessWidth are currently ignored, as there has
    163      1.1  jruoho  *          not been a need to implement these.
    164      1.1  jruoho  *
    165      1.1  jruoho  ******************************************************************************/
    166      1.1  jruoho 
    167      1.1  jruoho ACPI_STATUS
    168      1.1  jruoho AcpiHwRead (
    169      1.1  jruoho     UINT32                  *Value,
    170      1.1  jruoho     ACPI_GENERIC_ADDRESS    *Reg)
    171      1.1  jruoho {
    172      1.1  jruoho     UINT64                  Address;
    173      1.1  jruoho     ACPI_STATUS             Status;
    174      1.1  jruoho 
    175      1.1  jruoho 
    176      1.1  jruoho     ACPI_FUNCTION_NAME (HwRead);
    177      1.1  jruoho 
    178      1.1  jruoho 
    179      1.1  jruoho     /* Validate contents of the GAS register */
    180      1.1  jruoho 
    181      1.1  jruoho     Status = AcpiHwValidateRegister (Reg, 32, &Address);
    182      1.1  jruoho     if (ACPI_FAILURE (Status))
    183      1.1  jruoho     {
    184      1.1  jruoho         return (Status);
    185      1.1  jruoho     }
    186      1.1  jruoho 
    187      1.1  jruoho     /* Initialize entire 32-bit return value to zero */
    188      1.1  jruoho 
    189      1.1  jruoho     *Value = 0;
    190      1.1  jruoho 
    191      1.1  jruoho     /*
    192      1.1  jruoho      * Two address spaces supported: Memory or IO. PCI_Config is
    193      1.1  jruoho      * not supported here because the GAS structure is insufficient
    194      1.1  jruoho      */
    195      1.1  jruoho     if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
    196      1.1  jruoho     {
    197      1.1  jruoho         Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
    198      1.1  jruoho                     Address, Value, Reg->BitWidth);
    199      1.1  jruoho     }
    200      1.1  jruoho     else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
    201      1.1  jruoho     {
    202      1.1  jruoho         Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
    203      1.1  jruoho                     Address, Value, Reg->BitWidth);
    204      1.1  jruoho     }
    205      1.1  jruoho 
    206      1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_IO,
    207      1.1  jruoho         "Read:  %8.8X width %2d from %8.8X%8.8X (%s)\n",
    208      1.1  jruoho         *Value, Reg->BitWidth, ACPI_FORMAT_UINT64 (Address),
    209      1.1  jruoho         AcpiUtGetRegionName (Reg->SpaceId)));
    210      1.1  jruoho 
    211      1.1  jruoho     return (Status);
    212      1.1  jruoho }
    213      1.1  jruoho 
    214      1.1  jruoho 
    215      1.1  jruoho /******************************************************************************
    216      1.1  jruoho  *
    217      1.1  jruoho  * FUNCTION:    AcpiHwWrite
    218      1.1  jruoho  *
    219      1.1  jruoho  * PARAMETERS:  Value               - Value to be written
    220      1.1  jruoho  *              Reg                 - GAS register structure
    221      1.1  jruoho  *
    222      1.1  jruoho  * RETURN:      Status
    223      1.1  jruoho  *
    224      1.1  jruoho  * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max
    225      1.1  jruoho  *              version of AcpiWrite, used internally since the overhead of
    226      1.1  jruoho  *              64-bit values is not needed.
    227      1.1  jruoho  *
    228      1.1  jruoho  ******************************************************************************/
    229      1.1  jruoho 
    230      1.1  jruoho ACPI_STATUS
    231      1.1  jruoho AcpiHwWrite (
    232      1.1  jruoho     UINT32                  Value,
    233      1.1  jruoho     ACPI_GENERIC_ADDRESS    *Reg)
    234      1.1  jruoho {
    235      1.1  jruoho     UINT64                  Address;
    236      1.1  jruoho     ACPI_STATUS             Status;
    237      1.1  jruoho 
    238      1.1  jruoho 
    239      1.1  jruoho     ACPI_FUNCTION_NAME (HwWrite);
    240      1.1  jruoho 
    241      1.1  jruoho 
    242      1.1  jruoho     /* Validate contents of the GAS register */
    243      1.1  jruoho 
    244      1.1  jruoho     Status = AcpiHwValidateRegister (Reg, 32, &Address);
    245      1.1  jruoho     if (ACPI_FAILURE (Status))
    246      1.1  jruoho     {
    247      1.1  jruoho         return (Status);
    248      1.1  jruoho     }
    249      1.1  jruoho 
    250      1.1  jruoho     /*
    251      1.1  jruoho      * Two address spaces supported: Memory or IO. PCI_Config is
    252      1.1  jruoho      * not supported here because the GAS structure is insufficient
    253      1.1  jruoho      */
    254      1.1  jruoho     if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
    255      1.1  jruoho     {
    256      1.1  jruoho         Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
    257      1.1  jruoho                     Address, Value, Reg->BitWidth);
    258      1.1  jruoho     }
    259      1.1  jruoho     else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
    260      1.1  jruoho     {
    261      1.1  jruoho         Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
    262      1.1  jruoho                     Address, Value, Reg->BitWidth);
    263      1.1  jruoho     }
    264      1.1  jruoho 
    265      1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_IO,
    266      1.1  jruoho         "Wrote: %8.8X width %2d   to %8.8X%8.8X (%s)\n",
    267      1.1  jruoho         Value, Reg->BitWidth, ACPI_FORMAT_UINT64 (Address),
    268      1.1  jruoho         AcpiUtGetRegionName (Reg->SpaceId)));
    269      1.1  jruoho 
    270      1.1  jruoho     return (Status);
    271      1.1  jruoho }
    272      1.1  jruoho 
    273      1.1  jruoho 
    274      1.1  jruoho /*******************************************************************************
    275      1.1  jruoho  *
    276      1.1  jruoho  * FUNCTION:    AcpiHwClearAcpiStatus
    277      1.1  jruoho  *
    278      1.1  jruoho  * PARAMETERS:  None
    279      1.1  jruoho  *
    280      1.1  jruoho  * RETURN:      Status
    281      1.1  jruoho  *
    282      1.1  jruoho  * DESCRIPTION: Clears all fixed and general purpose status bits
    283      1.1  jruoho  *
    284      1.1  jruoho  ******************************************************************************/
    285      1.1  jruoho 
    286      1.1  jruoho ACPI_STATUS
    287      1.1  jruoho AcpiHwClearAcpiStatus (
    288      1.1  jruoho     void)
    289      1.1  jruoho {
    290      1.1  jruoho     ACPI_STATUS             Status;
    291      1.1  jruoho     ACPI_CPU_FLAGS          LockFlags = 0;
    292      1.1  jruoho 
    293      1.1  jruoho 
    294      1.1  jruoho     ACPI_FUNCTION_TRACE (HwClearAcpiStatus);
    295      1.1  jruoho 
    296      1.1  jruoho 
    297      1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n",
    298      1.1  jruoho         ACPI_BITMASK_ALL_FIXED_STATUS,
    299      1.1  jruoho         ACPI_FORMAT_UINT64 (AcpiGbl_XPm1aStatus.Address)));
    300      1.1  jruoho 
    301      1.1  jruoho     LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock);
    302      1.1  jruoho 
    303      1.1  jruoho     /* Clear the fixed events in PM1 A/B */
    304      1.1  jruoho 
    305      1.1  jruoho     Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS,
    306      1.1  jruoho                 ACPI_BITMASK_ALL_FIXED_STATUS);
    307      1.1  jruoho     if (ACPI_FAILURE (Status))
    308      1.1  jruoho     {
    309      1.1  jruoho         goto UnlockAndExit;
    310      1.1  jruoho     }
    311      1.1  jruoho 
    312      1.1  jruoho     /* Clear the GPE Bits in all GPE registers in all GPE blocks */
    313      1.1  jruoho 
    314      1.1  jruoho     Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
    315      1.1  jruoho 
    316      1.1  jruoho UnlockAndExit:
    317      1.1  jruoho     AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags);
    318      1.1  jruoho     return_ACPI_STATUS (Status);
    319      1.1  jruoho }
    320      1.1  jruoho 
    321      1.1  jruoho 
    322      1.1  jruoho /*******************************************************************************
    323      1.1  jruoho  *
    324      1.1  jruoho  * FUNCTION:    AcpiHwGetRegisterBitMask
    325      1.1  jruoho  *
    326      1.1  jruoho  * PARAMETERS:  RegisterId          - Index of ACPI Register to access
    327      1.1  jruoho  *
    328      1.1  jruoho  * RETURN:      The bitmask to be used when accessing the register
    329      1.1  jruoho  *
    330      1.1  jruoho  * DESCRIPTION: Map RegisterId into a register bitmask.
    331      1.1  jruoho  *
    332      1.1  jruoho  ******************************************************************************/
    333      1.1  jruoho 
    334      1.1  jruoho ACPI_BIT_REGISTER_INFO *
    335      1.1  jruoho AcpiHwGetBitRegisterInfo (
    336      1.1  jruoho     UINT32                  RegisterId)
    337      1.1  jruoho {
    338      1.1  jruoho     ACPI_FUNCTION_ENTRY ();
    339      1.1  jruoho 
    340      1.1  jruoho 
    341      1.1  jruoho     if (RegisterId > ACPI_BITREG_MAX)
    342      1.1  jruoho     {
    343      1.1  jruoho         ACPI_ERROR ((AE_INFO, "Invalid BitRegister ID: 0x%X", RegisterId));
    344      1.1  jruoho         return (NULL);
    345      1.1  jruoho     }
    346      1.1  jruoho 
    347      1.1  jruoho     return (&AcpiGbl_BitRegisterInfo[RegisterId]);
    348      1.1  jruoho }
    349      1.1  jruoho 
    350      1.1  jruoho 
    351      1.1  jruoho /******************************************************************************
    352      1.1  jruoho  *
    353      1.1  jruoho  * FUNCTION:    AcpiHwWritePm1Control
    354      1.1  jruoho  *
    355      1.1  jruoho  * PARAMETERS:  Pm1aControl         - Value to be written to PM1A control
    356      1.1  jruoho  *              Pm1bControl         - Value to be written to PM1B control
    357      1.1  jruoho  *
    358      1.1  jruoho  * RETURN:      Status
    359      1.1  jruoho  *
    360      1.1  jruoho  * DESCRIPTION: Write the PM1 A/B control registers. These registers are
    361      1.1  jruoho  *              different than than the PM1 A/B status and enable registers
    362      1.1  jruoho  *              in that different values can be written to the A/B registers.
    363      1.1  jruoho  *              Most notably, the SLP_TYP bits can be different, as per the
    364      1.1  jruoho  *              values returned from the _Sx predefined methods.
    365      1.1  jruoho  *
    366      1.1  jruoho  ******************************************************************************/
    367      1.1  jruoho 
    368      1.1  jruoho ACPI_STATUS
    369      1.1  jruoho AcpiHwWritePm1Control (
    370      1.1  jruoho     UINT32                  Pm1aControl,
    371      1.1  jruoho     UINT32                  Pm1bControl)
    372      1.1  jruoho {
    373      1.1  jruoho     ACPI_STATUS             Status;
    374      1.1  jruoho 
    375      1.1  jruoho 
    376      1.1  jruoho     ACPI_FUNCTION_TRACE (HwWritePm1Control);
    377      1.1  jruoho 
    378      1.1  jruoho 
    379      1.1  jruoho     Status = AcpiHwWrite (Pm1aControl, &AcpiGbl_FADT.XPm1aControlBlock);
    380      1.1  jruoho     if (ACPI_FAILURE (Status))
    381      1.1  jruoho     {
    382      1.1  jruoho         return_ACPI_STATUS (Status);
    383      1.1  jruoho     }
    384      1.1  jruoho 
    385      1.1  jruoho     if (AcpiGbl_FADT.XPm1bControlBlock.Address)
    386      1.1  jruoho     {
    387      1.1  jruoho         Status = AcpiHwWrite (Pm1bControl, &AcpiGbl_FADT.XPm1bControlBlock);
    388      1.1  jruoho     }
    389      1.1  jruoho     return_ACPI_STATUS (Status);
    390      1.1  jruoho }
    391      1.1  jruoho 
    392      1.1  jruoho 
    393      1.1  jruoho /******************************************************************************
    394      1.1  jruoho  *
    395      1.1  jruoho  * FUNCTION:    AcpiHwRegisterRead
    396      1.1  jruoho  *
    397      1.1  jruoho  * PARAMETERS:  RegisterId          - ACPI Register ID
    398      1.1  jruoho  *              ReturnValue         - Where the register value is returned
    399      1.1  jruoho  *
    400      1.1  jruoho  * RETURN:      Status and the value read.
    401      1.1  jruoho  *
    402      1.1  jruoho  * DESCRIPTION: Read from the specified ACPI register
    403      1.1  jruoho  *
    404      1.1  jruoho  ******************************************************************************/
    405      1.1  jruoho 
    406      1.1  jruoho ACPI_STATUS
    407      1.1  jruoho AcpiHwRegisterRead (
    408      1.1  jruoho     UINT32                  RegisterId,
    409      1.1  jruoho     UINT32                  *ReturnValue)
    410      1.1  jruoho {
    411      1.1  jruoho     UINT32                  Value = 0;
    412      1.1  jruoho     ACPI_STATUS             Status;
    413      1.1  jruoho 
    414      1.1  jruoho 
    415      1.1  jruoho     ACPI_FUNCTION_TRACE (HwRegisterRead);
    416      1.1  jruoho 
    417      1.1  jruoho 
    418      1.1  jruoho     switch (RegisterId)
    419      1.1  jruoho     {
    420      1.1  jruoho     case ACPI_REGISTER_PM1_STATUS:           /* PM1 A/B: 16-bit access each */
    421      1.1  jruoho 
    422      1.1  jruoho         Status = AcpiHwReadMultiple (&Value,
    423      1.1  jruoho                     &AcpiGbl_XPm1aStatus,
    424      1.1  jruoho                     &AcpiGbl_XPm1bStatus);
    425      1.1  jruoho         break;
    426      1.1  jruoho 
    427      1.1  jruoho 
    428      1.1  jruoho     case ACPI_REGISTER_PM1_ENABLE:           /* PM1 A/B: 16-bit access each */
    429      1.1  jruoho 
    430      1.1  jruoho         Status = AcpiHwReadMultiple (&Value,
    431      1.1  jruoho                     &AcpiGbl_XPm1aEnable,
    432      1.1  jruoho                     &AcpiGbl_XPm1bEnable);
    433      1.1  jruoho         break;
    434      1.1  jruoho 
    435      1.1  jruoho 
    436      1.1  jruoho     case ACPI_REGISTER_PM1_CONTROL:          /* PM1 A/B: 16-bit access each */
    437      1.1  jruoho 
    438      1.1  jruoho         Status = AcpiHwReadMultiple (&Value,
    439      1.1  jruoho                     &AcpiGbl_FADT.XPm1aControlBlock,
    440      1.1  jruoho                     &AcpiGbl_FADT.XPm1bControlBlock);
    441      1.1  jruoho 
    442      1.1  jruoho         /*
    443      1.1  jruoho          * Zero the write-only bits. From the ACPI specification, "Hardware
    444      1.1  jruoho          * Write-Only Bits": "Upon reads to registers with write-only bits,
    445      1.1  jruoho          * software masks out all write-only bits."
    446      1.1  jruoho          */
    447      1.1  jruoho         Value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS;
    448      1.1  jruoho         break;
    449      1.1  jruoho 
    450      1.1  jruoho 
    451      1.1  jruoho     case ACPI_REGISTER_PM2_CONTROL:          /* 8-bit access */
    452      1.1  jruoho 
    453      1.1  jruoho         Status = AcpiHwRead (&Value, &AcpiGbl_FADT.XPm2ControlBlock);
    454      1.1  jruoho         break;
    455      1.1  jruoho 
    456      1.1  jruoho 
    457      1.1  jruoho     case ACPI_REGISTER_PM_TIMER:             /* 32-bit access */
    458      1.1  jruoho 
    459      1.1  jruoho         Status = AcpiHwRead (&Value, &AcpiGbl_FADT.XPmTimerBlock);
    460      1.1  jruoho         break;
    461      1.1  jruoho 
    462      1.1  jruoho 
    463      1.1  jruoho     case ACPI_REGISTER_SMI_COMMAND_BLOCK:    /* 8-bit access */
    464      1.1  jruoho 
    465      1.1  jruoho         Status = AcpiHwReadPort (AcpiGbl_FADT.SmiCommand, &Value, 8);
    466      1.1  jruoho         break;
    467      1.1  jruoho 
    468      1.1  jruoho 
    469      1.1  jruoho     default:
    470      1.1  jruoho         ACPI_ERROR ((AE_INFO, "Unknown Register ID: 0x%X",
    471      1.1  jruoho             RegisterId));
    472      1.1  jruoho         Status = AE_BAD_PARAMETER;
    473      1.1  jruoho         break;
    474      1.1  jruoho     }
    475      1.1  jruoho 
    476      1.1  jruoho     if (ACPI_SUCCESS (Status))
    477      1.1  jruoho     {
    478      1.1  jruoho         *ReturnValue = Value;
    479      1.1  jruoho     }
    480      1.1  jruoho 
    481      1.1  jruoho     return_ACPI_STATUS (Status);
    482      1.1  jruoho }
    483      1.1  jruoho 
    484      1.1  jruoho 
    485      1.1  jruoho /******************************************************************************
    486      1.1  jruoho  *
    487      1.1  jruoho  * FUNCTION:    AcpiHwRegisterWrite
    488      1.1  jruoho  *
    489      1.1  jruoho  * PARAMETERS:  RegisterId          - ACPI Register ID
    490      1.1  jruoho  *              Value               - The value to write
    491      1.1  jruoho  *
    492      1.1  jruoho  * RETURN:      Status
    493      1.1  jruoho  *
    494      1.1  jruoho  * DESCRIPTION: Write to the specified ACPI register
    495      1.1  jruoho  *
    496      1.1  jruoho  * NOTE: In accordance with the ACPI specification, this function automatically
    497      1.1  jruoho  * preserves the value of the following bits, meaning that these bits cannot be
    498      1.1  jruoho  * changed via this interface:
    499      1.1  jruoho  *
    500      1.1  jruoho  * PM1_CONTROL[0] = SCI_EN
    501      1.1  jruoho  * PM1_CONTROL[9]
    502      1.1  jruoho  * PM1_STATUS[11]
    503      1.1  jruoho  *
    504      1.1  jruoho  * ACPI References:
    505      1.1  jruoho  * 1) Hardware Ignored Bits: When software writes to a register with ignored
    506      1.1  jruoho  *      bit fields, it preserves the ignored bit fields
    507      1.1  jruoho  * 2) SCI_EN: OSPM always preserves this bit position
    508      1.1  jruoho  *
    509      1.1  jruoho  ******************************************************************************/
    510      1.1  jruoho 
    511      1.1  jruoho ACPI_STATUS
    512      1.1  jruoho AcpiHwRegisterWrite (
    513      1.1  jruoho     UINT32                  RegisterId,
    514      1.1  jruoho     UINT32                  Value)
    515      1.1  jruoho {
    516      1.1  jruoho     ACPI_STATUS             Status;
    517      1.1  jruoho     UINT32                  ReadValue;
    518      1.1  jruoho 
    519      1.1  jruoho 
    520      1.1  jruoho     ACPI_FUNCTION_TRACE (HwRegisterWrite);
    521      1.1  jruoho 
    522      1.1  jruoho 
    523      1.1  jruoho     switch (RegisterId)
    524      1.1  jruoho     {
    525      1.1  jruoho     case ACPI_REGISTER_PM1_STATUS:           /* PM1 A/B: 16-bit access each */
    526      1.1  jruoho         /*
    527      1.1  jruoho          * Handle the "ignored" bit in PM1 Status. According to the ACPI
    528      1.1  jruoho          * specification, ignored bits are to be preserved when writing.
    529      1.1  jruoho          * Normally, this would mean a read/modify/write sequence. However,
    530      1.1  jruoho          * preserving a bit in the status register is different. Writing a
    531      1.1  jruoho          * one clears the status, and writing a zero preserves the status.
    532      1.1  jruoho          * Therefore, we must always write zero to the ignored bit.
    533      1.1  jruoho          *
    534      1.1  jruoho          * This behavior is clarified in the ACPI 4.0 specification.
    535      1.1  jruoho          */
    536      1.1  jruoho         Value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
    537      1.1  jruoho 
    538      1.1  jruoho         Status = AcpiHwWriteMultiple (Value,
    539      1.1  jruoho                     &AcpiGbl_XPm1aStatus,
    540      1.1  jruoho                     &AcpiGbl_XPm1bStatus);
    541      1.1  jruoho         break;
    542      1.1  jruoho 
    543      1.1  jruoho 
    544      1.1  jruoho     case ACPI_REGISTER_PM1_ENABLE:           /* PM1 A/B: 16-bit access each */
    545      1.1  jruoho 
    546      1.1  jruoho         Status = AcpiHwWriteMultiple (Value,
    547      1.1  jruoho                     &AcpiGbl_XPm1aEnable,
    548      1.1  jruoho                     &AcpiGbl_XPm1bEnable);
    549      1.1  jruoho         break;
    550      1.1  jruoho 
    551      1.1  jruoho 
    552      1.1  jruoho     case ACPI_REGISTER_PM1_CONTROL:          /* PM1 A/B: 16-bit access each */
    553      1.1  jruoho 
    554      1.1  jruoho         /*
    555      1.1  jruoho          * Perform a read first to preserve certain bits (per ACPI spec)
    556      1.1  jruoho          * Note: This includes SCI_EN, we never want to change this bit
    557      1.1  jruoho          */
    558      1.1  jruoho         Status = AcpiHwReadMultiple (&ReadValue,
    559      1.1  jruoho                     &AcpiGbl_FADT.XPm1aControlBlock,
    560      1.1  jruoho                     &AcpiGbl_FADT.XPm1bControlBlock);
    561      1.1  jruoho         if (ACPI_FAILURE (Status))
    562      1.1  jruoho         {
    563      1.1  jruoho             goto Exit;
    564      1.1  jruoho         }
    565      1.1  jruoho 
    566      1.1  jruoho         /* Insert the bits to be preserved */
    567      1.1  jruoho 
    568      1.1  jruoho         ACPI_INSERT_BITS (Value, ACPI_PM1_CONTROL_PRESERVED_BITS, ReadValue);
    569      1.1  jruoho 
    570      1.1  jruoho         /* Now we can write the data */
    571      1.1  jruoho 
    572      1.1  jruoho         Status = AcpiHwWriteMultiple (Value,
    573      1.1  jruoho                     &AcpiGbl_FADT.XPm1aControlBlock,
    574      1.1  jruoho                     &AcpiGbl_FADT.XPm1bControlBlock);
    575      1.1  jruoho         break;
    576      1.1  jruoho 
    577      1.1  jruoho 
    578      1.1  jruoho     case ACPI_REGISTER_PM2_CONTROL:          /* 8-bit access */
    579      1.1  jruoho 
    580      1.1  jruoho         /*
    581      1.1  jruoho          * For control registers, all reserved bits must be preserved,
    582      1.1  jruoho          * as per the ACPI spec.
    583      1.1  jruoho          */
    584      1.1  jruoho         Status = AcpiHwRead (&ReadValue, &AcpiGbl_FADT.XPm2ControlBlock);
    585      1.1  jruoho         if (ACPI_FAILURE (Status))
    586      1.1  jruoho         {
    587      1.1  jruoho             goto Exit;
    588      1.1  jruoho         }
    589      1.1  jruoho 
    590      1.1  jruoho         /* Insert the bits to be preserved */
    591      1.1  jruoho 
    592      1.1  jruoho         ACPI_INSERT_BITS (Value, ACPI_PM2_CONTROL_PRESERVED_BITS, ReadValue);
    593      1.1  jruoho 
    594      1.1  jruoho         Status = AcpiHwWrite (Value, &AcpiGbl_FADT.XPm2ControlBlock);
    595      1.1  jruoho         break;
    596      1.1  jruoho 
    597      1.1  jruoho 
    598      1.1  jruoho     case ACPI_REGISTER_PM_TIMER:             /* 32-bit access */
    599      1.1  jruoho 
    600      1.1  jruoho         Status = AcpiHwWrite (Value, &AcpiGbl_FADT.XPmTimerBlock);
    601      1.1  jruoho         break;
    602      1.1  jruoho 
    603      1.1  jruoho 
    604      1.1  jruoho     case ACPI_REGISTER_SMI_COMMAND_BLOCK:    /* 8-bit access */
    605      1.1  jruoho 
    606      1.1  jruoho         /* SMI_CMD is currently always in IO space */
    607      1.1  jruoho 
    608      1.1  jruoho         Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, Value, 8);
    609      1.1  jruoho         break;
    610      1.1  jruoho 
    611      1.1  jruoho 
    612      1.1  jruoho     default:
    613      1.1  jruoho         ACPI_ERROR ((AE_INFO, "Unknown Register ID: 0x%X",
    614      1.1  jruoho             RegisterId));
    615      1.1  jruoho         Status = AE_BAD_PARAMETER;
    616      1.1  jruoho         break;
    617      1.1  jruoho     }
    618      1.1  jruoho 
    619      1.1  jruoho Exit:
    620      1.1  jruoho     return_ACPI_STATUS (Status);
    621      1.1  jruoho }
    622      1.1  jruoho 
    623      1.1  jruoho 
    624      1.1  jruoho /******************************************************************************
    625      1.1  jruoho  *
    626      1.1  jruoho  * FUNCTION:    AcpiHwReadMultiple
    627      1.1  jruoho  *
    628      1.1  jruoho  * PARAMETERS:  Value               - Where the register value is returned
    629      1.1  jruoho  *              RegisterA           - First ACPI register (required)
    630      1.1  jruoho  *              RegisterB           - Second ACPI register (optional)
    631      1.1  jruoho  *
    632      1.1  jruoho  * RETURN:      Status
    633      1.1  jruoho  *
    634      1.1  jruoho  * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
    635      1.1  jruoho  *
    636      1.1  jruoho  ******************************************************************************/
    637      1.1  jruoho 
    638      1.1  jruoho static ACPI_STATUS
    639      1.1  jruoho AcpiHwReadMultiple (
    640      1.1  jruoho     UINT32                  *Value,
    641      1.1  jruoho     ACPI_GENERIC_ADDRESS    *RegisterA,
    642      1.1  jruoho     ACPI_GENERIC_ADDRESS    *RegisterB)
    643      1.1  jruoho {
    644      1.1  jruoho     UINT32                  ValueA = 0;
    645      1.1  jruoho     UINT32                  ValueB = 0;
    646      1.1  jruoho     ACPI_STATUS             Status;
    647      1.1  jruoho 
    648      1.1  jruoho 
    649      1.1  jruoho     /* The first register is always required */
    650      1.1  jruoho 
    651      1.1  jruoho     Status = AcpiHwRead (&ValueA, RegisterA);
    652      1.1  jruoho     if (ACPI_FAILURE (Status))
    653      1.1  jruoho     {
    654      1.1  jruoho         return (Status);
    655      1.1  jruoho     }
    656      1.1  jruoho 
    657      1.1  jruoho     /* Second register is optional */
    658      1.1  jruoho 
    659      1.1  jruoho     if (RegisterB->Address)
    660      1.1  jruoho     {
    661      1.1  jruoho         Status = AcpiHwRead (&ValueB, RegisterB);
    662      1.1  jruoho         if (ACPI_FAILURE (Status))
    663      1.1  jruoho         {
    664      1.1  jruoho             return (Status);
    665      1.1  jruoho         }
    666      1.1  jruoho     }
    667      1.1  jruoho 
    668      1.1  jruoho     /*
    669      1.1  jruoho      * OR the two return values together. No shifting or masking is necessary,
    670      1.1  jruoho      * because of how the PM1 registers are defined in the ACPI specification:
    671      1.1  jruoho      *
    672      1.1  jruoho      * "Although the bits can be split between the two register blocks (each
    673      1.1  jruoho      * register block has a unique pointer within the FADT), the bit positions
    674      1.1  jruoho      * are maintained. The register block with unimplemented bits (that is,
    675      1.1  jruoho      * those implemented in the other register block) always returns zeros,
    676      1.1  jruoho      * and writes have no side effects"
    677      1.1  jruoho      */
    678      1.1  jruoho     *Value = (ValueA | ValueB);
    679      1.1  jruoho     return (AE_OK);
    680      1.1  jruoho }
    681      1.1  jruoho 
    682      1.1  jruoho 
    683      1.1  jruoho /******************************************************************************
    684      1.1  jruoho  *
    685      1.1  jruoho  * FUNCTION:    AcpiHwWriteMultiple
    686      1.1  jruoho  *
    687      1.1  jruoho  * PARAMETERS:  Value               - The value to write
    688      1.1  jruoho  *              RegisterA           - First ACPI register (required)
    689      1.1  jruoho  *              RegisterB           - Second ACPI register (optional)
    690      1.1  jruoho  *
    691      1.1  jruoho  * RETURN:      Status
    692      1.1  jruoho  *
    693      1.1  jruoho  * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
    694      1.1  jruoho  *
    695      1.1  jruoho  ******************************************************************************/
    696      1.1  jruoho 
    697      1.1  jruoho static ACPI_STATUS
    698      1.1  jruoho AcpiHwWriteMultiple (
    699      1.1  jruoho     UINT32                  Value,
    700      1.1  jruoho     ACPI_GENERIC_ADDRESS    *RegisterA,
    701      1.1  jruoho     ACPI_GENERIC_ADDRESS    *RegisterB)
    702      1.1  jruoho {
    703      1.1  jruoho     ACPI_STATUS             Status;
    704      1.1  jruoho 
    705      1.1  jruoho 
    706      1.1  jruoho     /* The first register is always required */
    707      1.1  jruoho 
    708      1.1  jruoho     Status = AcpiHwWrite (Value, RegisterA);
    709      1.1  jruoho     if (ACPI_FAILURE (Status))
    710      1.1  jruoho     {
    711      1.1  jruoho         return (Status);
    712      1.1  jruoho     }
    713      1.1  jruoho 
    714      1.1  jruoho     /*
    715      1.1  jruoho      * Second register is optional
    716      1.1  jruoho      *
    717      1.1  jruoho      * No bit shifting or clearing is necessary, because of how the PM1
    718      1.1  jruoho      * registers are defined in the ACPI specification:
    719      1.1  jruoho      *
    720      1.1  jruoho      * "Although the bits can be split between the two register blocks (each
    721      1.1  jruoho      * register block has a unique pointer within the FADT), the bit positions
    722      1.1  jruoho      * are maintained. The register block with unimplemented bits (that is,
    723      1.1  jruoho      * those implemented in the other register block) always returns zeros,
    724      1.1  jruoho      * and writes have no side effects"
    725      1.1  jruoho      */
    726      1.1  jruoho     if (RegisterB->Address)
    727      1.1  jruoho     {
    728      1.1  jruoho         Status = AcpiHwWrite (Value, RegisterB);
    729      1.1  jruoho     }
    730      1.1  jruoho 
    731      1.1  jruoho     return (Status);
    732      1.1  jruoho }
    733      1.1  jruoho 
    734