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