Home | History | Annotate | Line # | Download | only in tables
tbfadt.c revision 1.3
      1  1.1  jruoho /******************************************************************************
      2  1.1  jruoho  *
      3  1.1  jruoho  * Module Name: tbfadt   - FADT table utilities
      4  1.1  jruoho  *
      5  1.1  jruoho  *****************************************************************************/
      6  1.1  jruoho 
      7  1.3  jruoho /*
      8  1.3  jruoho  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1  jruoho  * All rights reserved.
     10  1.1  jruoho  *
     11  1.3  jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.3  jruoho  * modification, are permitted provided that the following conditions
     13  1.3  jruoho  * are met:
     14  1.3  jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.3  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.3  jruoho  *    without modification.
     17  1.3  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.3  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.3  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.3  jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.3  jruoho  *    binary redistribution.
     22  1.3  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.3  jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.3  jruoho  *    from this software without specific prior written permission.
     25  1.3  jruoho  *
     26  1.3  jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.3  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.3  jruoho  * Software Foundation.
     29  1.3  jruoho  *
     30  1.3  jruoho  * NO WARRANTY
     31  1.3  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.3  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.3  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.3  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.3  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.3  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.3  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.3  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.3  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.3  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.3  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.3  jruoho  */
     43  1.1  jruoho 
     44  1.1  jruoho #define __TBFADT_C__
     45  1.1  jruoho 
     46  1.1  jruoho #include "acpi.h"
     47  1.1  jruoho #include "accommon.h"
     48  1.1  jruoho #include "actables.h"
     49  1.1  jruoho 
     50  1.1  jruoho #define _COMPONENT          ACPI_TABLES
     51  1.1  jruoho         ACPI_MODULE_NAME    ("tbfadt")
     52  1.1  jruoho 
     53  1.1  jruoho /* Local prototypes */
     54  1.1  jruoho 
     55  1.3  jruoho static ACPI_INLINE void
     56  1.1  jruoho AcpiTbInitGenericAddress (
     57  1.1  jruoho     ACPI_GENERIC_ADDRESS    *GenericAddress,
     58  1.1  jruoho     UINT8                   SpaceId,
     59  1.1  jruoho     UINT8                   ByteWidth,
     60  1.1  jruoho     UINT64                  Address);
     61  1.1  jruoho 
     62  1.1  jruoho static void
     63  1.1  jruoho AcpiTbConvertFadt (
     64  1.1  jruoho     void);
     65  1.1  jruoho 
     66  1.1  jruoho static void
     67  1.1  jruoho AcpiTbValidateFadt (
     68  1.1  jruoho     void);
     69  1.1  jruoho 
     70  1.1  jruoho static void
     71  1.1  jruoho AcpiTbSetupFadtRegisters (
     72  1.1  jruoho     void);
     73  1.1  jruoho 
     74  1.1  jruoho 
     75  1.1  jruoho /* Table for conversion of FADT to common internal format and FADT validation */
     76  1.1  jruoho 
     77  1.1  jruoho typedef struct acpi_fadt_info
     78  1.1  jruoho {
     79  1.2  jruoho     const char              *Name;
     80  1.1  jruoho     UINT8                   Address64;
     81  1.1  jruoho     UINT8                   Address32;
     82  1.1  jruoho     UINT8                   Length;
     83  1.1  jruoho     UINT8                   DefaultLength;
     84  1.1  jruoho     UINT8                   Type;
     85  1.1  jruoho 
     86  1.1  jruoho } ACPI_FADT_INFO;
     87  1.1  jruoho 
     88  1.1  jruoho #define ACPI_FADT_REQUIRED          1
     89  1.1  jruoho #define ACPI_FADT_SEPARATE_LENGTH   2
     90  1.1  jruoho 
     91  1.1  jruoho static ACPI_FADT_INFO     FadtInfoTable[] =
     92  1.1  jruoho {
     93  1.1  jruoho     {"Pm1aEventBlock",
     94  1.1  jruoho         ACPI_FADT_OFFSET (XPm1aEventBlock),
     95  1.1  jruoho         ACPI_FADT_OFFSET (Pm1aEventBlock),
     96  1.1  jruoho         ACPI_FADT_OFFSET (Pm1EventLength),
     97  1.1  jruoho         ACPI_PM1_REGISTER_WIDTH * 2,        /* Enable + Status register */
     98  1.1  jruoho         ACPI_FADT_REQUIRED},
     99  1.1  jruoho 
    100  1.1  jruoho     {"Pm1bEventBlock",
    101  1.1  jruoho         ACPI_FADT_OFFSET (XPm1bEventBlock),
    102  1.1  jruoho         ACPI_FADT_OFFSET (Pm1bEventBlock),
    103  1.1  jruoho         ACPI_FADT_OFFSET (Pm1EventLength),
    104  1.1  jruoho         ACPI_PM1_REGISTER_WIDTH * 2,        /* Enable + Status register */
    105  1.1  jruoho         0},
    106  1.1  jruoho 
    107  1.1  jruoho     {"Pm1aControlBlock",
    108  1.1  jruoho         ACPI_FADT_OFFSET (XPm1aControlBlock),
    109  1.1  jruoho         ACPI_FADT_OFFSET (Pm1aControlBlock),
    110  1.1  jruoho         ACPI_FADT_OFFSET (Pm1ControlLength),
    111  1.1  jruoho         ACPI_PM1_REGISTER_WIDTH,
    112  1.1  jruoho         ACPI_FADT_REQUIRED},
    113  1.1  jruoho 
    114  1.1  jruoho     {"Pm1bControlBlock",
    115  1.1  jruoho         ACPI_FADT_OFFSET (XPm1bControlBlock),
    116  1.1  jruoho         ACPI_FADT_OFFSET (Pm1bControlBlock),
    117  1.1  jruoho         ACPI_FADT_OFFSET (Pm1ControlLength),
    118  1.1  jruoho         ACPI_PM1_REGISTER_WIDTH,
    119  1.1  jruoho         0},
    120  1.1  jruoho 
    121  1.1  jruoho     {"Pm2ControlBlock",
    122  1.1  jruoho         ACPI_FADT_OFFSET (XPm2ControlBlock),
    123  1.1  jruoho         ACPI_FADT_OFFSET (Pm2ControlBlock),
    124  1.1  jruoho         ACPI_FADT_OFFSET (Pm2ControlLength),
    125  1.1  jruoho         ACPI_PM2_REGISTER_WIDTH,
    126  1.1  jruoho         ACPI_FADT_SEPARATE_LENGTH},
    127  1.1  jruoho 
    128  1.1  jruoho     {"PmTimerBlock",
    129  1.1  jruoho         ACPI_FADT_OFFSET (XPmTimerBlock),
    130  1.1  jruoho         ACPI_FADT_OFFSET (PmTimerBlock),
    131  1.1  jruoho         ACPI_FADT_OFFSET (PmTimerLength),
    132  1.1  jruoho         ACPI_PM_TIMER_WIDTH,
    133  1.1  jruoho         ACPI_FADT_REQUIRED},
    134  1.1  jruoho 
    135  1.1  jruoho     {"Gpe0Block",
    136  1.1  jruoho         ACPI_FADT_OFFSET (XGpe0Block),
    137  1.1  jruoho         ACPI_FADT_OFFSET (Gpe0Block),
    138  1.1  jruoho         ACPI_FADT_OFFSET (Gpe0BlockLength),
    139  1.1  jruoho         0,
    140  1.1  jruoho         ACPI_FADT_SEPARATE_LENGTH},
    141  1.1  jruoho 
    142  1.1  jruoho     {"Gpe1Block",
    143  1.1  jruoho         ACPI_FADT_OFFSET (XGpe1Block),
    144  1.1  jruoho         ACPI_FADT_OFFSET (Gpe1Block),
    145  1.1  jruoho         ACPI_FADT_OFFSET (Gpe1BlockLength),
    146  1.1  jruoho         0,
    147  1.1  jruoho         ACPI_FADT_SEPARATE_LENGTH}
    148  1.1  jruoho };
    149  1.1  jruoho 
    150  1.1  jruoho #define ACPI_FADT_INFO_ENTRIES \
    151  1.1  jruoho             (sizeof (FadtInfoTable) / sizeof (ACPI_FADT_INFO))
    152  1.1  jruoho 
    153  1.1  jruoho 
    154  1.1  jruoho /* Table used to split Event Blocks into separate status/enable registers */
    155  1.1  jruoho 
    156  1.1  jruoho typedef struct acpi_fadt_pm_info
    157  1.1  jruoho {
    158  1.1  jruoho     ACPI_GENERIC_ADDRESS    *Target;
    159  1.1  jruoho     UINT8                   Source;
    160  1.1  jruoho     UINT8                   RegisterNum;
    161  1.1  jruoho 
    162  1.1  jruoho } ACPI_FADT_PM_INFO;
    163  1.1  jruoho 
    164  1.1  jruoho static ACPI_FADT_PM_INFO    FadtPmInfoTable[] =
    165  1.1  jruoho {
    166  1.1  jruoho     {&AcpiGbl_XPm1aStatus,
    167  1.1  jruoho         ACPI_FADT_OFFSET (XPm1aEventBlock),
    168  1.1  jruoho         0},
    169  1.1  jruoho 
    170  1.1  jruoho     {&AcpiGbl_XPm1aEnable,
    171  1.1  jruoho         ACPI_FADT_OFFSET (XPm1aEventBlock),
    172  1.1  jruoho         1},
    173  1.1  jruoho 
    174  1.1  jruoho     {&AcpiGbl_XPm1bStatus,
    175  1.1  jruoho         ACPI_FADT_OFFSET (XPm1bEventBlock),
    176  1.1  jruoho         0},
    177  1.1  jruoho 
    178  1.1  jruoho     {&AcpiGbl_XPm1bEnable,
    179  1.1  jruoho         ACPI_FADT_OFFSET (XPm1bEventBlock),
    180  1.1  jruoho         1}
    181  1.1  jruoho };
    182  1.1  jruoho 
    183  1.1  jruoho #define ACPI_FADT_PM_INFO_ENTRIES \
    184  1.1  jruoho             (sizeof (FadtPmInfoTable) / sizeof (ACPI_FADT_PM_INFO))
    185  1.1  jruoho 
    186  1.1  jruoho 
    187  1.1  jruoho /*******************************************************************************
    188  1.1  jruoho  *
    189  1.1  jruoho  * FUNCTION:    AcpiTbInitGenericAddress
    190  1.1  jruoho  *
    191  1.1  jruoho  * PARAMETERS:  GenericAddress      - GAS struct to be initialized
    192  1.1  jruoho  *              SpaceId             - ACPI Space ID for this register
    193  1.1  jruoho  *              ByteWidth           - Width of this register, in bytes
    194  1.1  jruoho  *              Address             - Address of the register
    195  1.1  jruoho  *
    196  1.1  jruoho  * RETURN:      None
    197  1.1  jruoho  *
    198  1.1  jruoho  * DESCRIPTION: Initialize a Generic Address Structure (GAS)
    199  1.1  jruoho  *              See the ACPI specification for a full description and
    200  1.1  jruoho  *              definition of this structure.
    201  1.1  jruoho  *
    202  1.1  jruoho  ******************************************************************************/
    203  1.1  jruoho 
    204  1.3  jruoho static ACPI_INLINE void
    205  1.1  jruoho AcpiTbInitGenericAddress (
    206  1.1  jruoho     ACPI_GENERIC_ADDRESS    *GenericAddress,
    207  1.1  jruoho     UINT8                   SpaceId,
    208  1.1  jruoho     UINT8                   ByteWidth,
    209  1.1  jruoho     UINT64                  Address)
    210  1.1  jruoho {
    211  1.1  jruoho 
    212  1.1  jruoho     /*
    213  1.1  jruoho      * The 64-bit Address field is non-aligned in the byte packed
    214  1.1  jruoho      * GAS struct.
    215  1.1  jruoho      */
    216  1.1  jruoho     ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
    217  1.1  jruoho 
    218  1.1  jruoho     /* All other fields are byte-wide */
    219  1.1  jruoho 
    220  1.1  jruoho     GenericAddress->SpaceId = SpaceId;
    221  1.1  jruoho     GenericAddress->BitWidth = (UINT8) ACPI_MUL_8 (ByteWidth);
    222  1.1  jruoho     GenericAddress->BitOffset = 0;
    223  1.1  jruoho     GenericAddress->AccessWidth = 0; /* Access width ANY */
    224  1.1  jruoho }
    225  1.1  jruoho 
    226  1.1  jruoho 
    227  1.1  jruoho /*******************************************************************************
    228  1.1  jruoho  *
    229  1.1  jruoho  * FUNCTION:    AcpiTbParseFadt
    230  1.1  jruoho  *
    231  1.1  jruoho  * PARAMETERS:  TableIndex          - Index for the FADT
    232  1.1  jruoho  *
    233  1.1  jruoho  * RETURN:      None
    234  1.1  jruoho  *
    235  1.1  jruoho  * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
    236  1.1  jruoho  *              (FADT contains the addresses of the DSDT and FACS)
    237  1.1  jruoho  *
    238  1.1  jruoho  ******************************************************************************/
    239  1.1  jruoho 
    240  1.1  jruoho void
    241  1.1  jruoho AcpiTbParseFadt (
    242  1.1  jruoho     UINT32                  TableIndex)
    243  1.1  jruoho {
    244  1.1  jruoho     UINT32                  Length;
    245  1.1  jruoho     ACPI_TABLE_HEADER       *Table;
    246  1.1  jruoho 
    247  1.1  jruoho 
    248  1.1  jruoho     /*
    249  1.1  jruoho      * The FADT has multiple versions with different lengths,
    250  1.1  jruoho      * and it contains pointers to both the DSDT and FACS tables.
    251  1.1  jruoho      *
    252  1.1  jruoho      * Get a local copy of the FADT and convert it to a common format
    253  1.1  jruoho      * Map entire FADT, assumed to be smaller than one page.
    254  1.1  jruoho      */
    255  1.1  jruoho     Length = AcpiGbl_RootTableList.Tables[TableIndex].Length;
    256  1.1  jruoho 
    257  1.1  jruoho     Table = AcpiOsMapMemory (
    258  1.1  jruoho                 AcpiGbl_RootTableList.Tables[TableIndex].Address, Length);
    259  1.1  jruoho     if (!Table)
    260  1.1  jruoho     {
    261  1.1  jruoho         return;
    262  1.1  jruoho     }
    263  1.1  jruoho 
    264  1.1  jruoho     /*
    265  1.1  jruoho      * Validate the FADT checksum before we copy the table. Ignore
    266  1.1  jruoho      * checksum error as we want to try to get the DSDT and FACS.
    267  1.1  jruoho      */
    268  1.1  jruoho     (void) AcpiTbVerifyChecksum (Table, Length);
    269  1.1  jruoho 
    270  1.1  jruoho     /* Create a local copy of the FADT in common ACPI 2.0+ format */
    271  1.1  jruoho 
    272  1.1  jruoho     AcpiTbCreateLocalFadt (Table, Length);
    273  1.1  jruoho 
    274  1.1  jruoho     /* All done with the real FADT, unmap it */
    275  1.1  jruoho 
    276  1.1  jruoho     AcpiOsUnmapMemory (Table, Length);
    277  1.1  jruoho 
    278  1.1  jruoho     /* Obtain the DSDT and FACS tables via their addresses within the FADT */
    279  1.1  jruoho 
    280  1.1  jruoho     AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
    281  1.1  jruoho         ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
    282  1.1  jruoho 
    283  1.1  jruoho     AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
    284  1.1  jruoho         ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
    285  1.1  jruoho }
    286  1.1  jruoho 
    287  1.1  jruoho 
    288  1.1  jruoho /*******************************************************************************
    289  1.1  jruoho  *
    290  1.1  jruoho  * FUNCTION:    AcpiTbCreateLocalFadt
    291  1.1  jruoho  *
    292  1.1  jruoho  * PARAMETERS:  Table               - Pointer to BIOS FADT
    293  1.1  jruoho  *              Length              - Length of the table
    294  1.1  jruoho  *
    295  1.1  jruoho  * RETURN:      None
    296  1.1  jruoho  *
    297  1.1  jruoho  * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
    298  1.1  jruoho  *              Performs validation on some important FADT fields.
    299  1.1  jruoho  *
    300  1.1  jruoho  * NOTE:        We create a local copy of the FADT regardless of the version.
    301  1.1  jruoho  *
    302  1.1  jruoho  ******************************************************************************/
    303  1.1  jruoho 
    304  1.1  jruoho void
    305  1.1  jruoho AcpiTbCreateLocalFadt (
    306  1.1  jruoho     ACPI_TABLE_HEADER       *Table,
    307  1.1  jruoho     UINT32                  Length)
    308  1.1  jruoho {
    309  1.1  jruoho 
    310  1.1  jruoho     /*
    311  1.1  jruoho      * Check if the FADT is larger than the largest table that we expect
    312  1.1  jruoho      * (the ACPI 2.0/3.0 version). If so, truncate the table, and issue
    313  1.1  jruoho      * a warning.
    314  1.1  jruoho      */
    315  1.1  jruoho     if (Length > sizeof (ACPI_TABLE_FADT))
    316  1.1  jruoho     {
    317  1.1  jruoho         ACPI_WARNING ((AE_INFO,
    318  1.1  jruoho             "FADT (revision %u) is longer than ACPI 2.0 version, "
    319  1.1  jruoho             "truncating length %u to %u",
    320  1.1  jruoho             Table->Revision, Length, (UINT32) sizeof (ACPI_TABLE_FADT)));
    321  1.1  jruoho     }
    322  1.1  jruoho 
    323  1.1  jruoho     /* Clear the entire local FADT */
    324  1.1  jruoho 
    325  1.1  jruoho     ACPI_MEMSET (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
    326  1.1  jruoho 
    327  1.1  jruoho     /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
    328  1.1  jruoho 
    329  1.1  jruoho     ACPI_MEMCPY (&AcpiGbl_FADT, Table,
    330  1.1  jruoho         ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
    331  1.1  jruoho 
    332  1.1  jruoho     /* Convert the local copy of the FADT to the common internal format */
    333  1.1  jruoho 
    334  1.1  jruoho     AcpiTbConvertFadt ();
    335  1.1  jruoho 
    336  1.1  jruoho     /* Validate FADT values now, before we make any changes */
    337  1.1  jruoho 
    338  1.1  jruoho     AcpiTbValidateFadt ();
    339  1.1  jruoho 
    340  1.1  jruoho     /* Initialize the global ACPI register structures */
    341  1.1  jruoho 
    342  1.1  jruoho     AcpiTbSetupFadtRegisters ();
    343  1.1  jruoho }
    344  1.1  jruoho 
    345  1.1  jruoho 
    346  1.1  jruoho /*******************************************************************************
    347  1.1  jruoho  *
    348  1.1  jruoho  * FUNCTION:    AcpiTbConvertFadt
    349  1.1  jruoho  *
    350  1.1  jruoho  * PARAMETERS:  None, uses AcpiGbl_FADT
    351  1.1  jruoho  *
    352  1.1  jruoho  * RETURN:      None
    353  1.1  jruoho  *
    354  1.1  jruoho  * DESCRIPTION: Converts all versions of the FADT to a common internal format.
    355  1.1  jruoho  *              Expand 32-bit addresses to 64-bit as necessary.
    356  1.1  jruoho  *
    357  1.1  jruoho  * NOTE:        AcpiGbl_FADT must be of size (ACPI_TABLE_FADT),
    358  1.1  jruoho  *              and must contain a copy of the actual FADT.
    359  1.1  jruoho  *
    360  1.1  jruoho  * Notes on 64-bit register addresses:
    361  1.1  jruoho  *
    362  1.1  jruoho  * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
    363  1.1  jruoho  * fields of the FADT for all ACPI register addresses.
    364  1.1  jruoho  *
    365  1.1  jruoho  * The 64-bit "X" fields are optional extensions to the original 32-bit FADT
    366  1.1  jruoho  * V1.0 fields. Even if they are present in the FADT, they are optional and
    367  1.1  jruoho  * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
    368  1.1  jruoho  * 32-bit V1.0 fields if the corresponding X field is zero.
    369  1.1  jruoho  *
    370  1.1  jruoho  * For ACPI 1.0 FADTs, all 32-bit address fields are expanded to the
    371  1.1  jruoho  * corresponding "X" fields in the internal FADT.
    372  1.1  jruoho  *
    373  1.1  jruoho  * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
    374  1.1  jruoho  * to the corresponding 64-bit X fields. For compatibility with other ACPI
    375  1.1  jruoho  * implementations, we ignore the 64-bit field if the 32-bit field is valid,
    376  1.1  jruoho  * regardless of whether the host OS is 32-bit or 64-bit.
    377  1.1  jruoho  *
    378  1.1  jruoho  ******************************************************************************/
    379  1.1  jruoho 
    380  1.1  jruoho static void
    381  1.1  jruoho AcpiTbConvertFadt (
    382  1.1  jruoho     void)
    383  1.1  jruoho {
    384  1.1  jruoho     ACPI_GENERIC_ADDRESS    *Address64;
    385  1.1  jruoho     UINT32                  Address32;
    386  1.1  jruoho     UINT32                  i;
    387  1.1  jruoho 
    388  1.1  jruoho 
    389  1.1  jruoho     /* Update the local FADT table header length */
    390  1.1  jruoho 
    391  1.1  jruoho     AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
    392  1.1  jruoho 
    393  1.1  jruoho     /*
    394  1.1  jruoho      * Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary.
    395  1.1  jruoho      * Later code will always use the X 64-bit field.
    396  1.1  jruoho      */
    397  1.1  jruoho     if (!AcpiGbl_FADT.XFacs)
    398  1.1  jruoho     {
    399  1.1  jruoho         AcpiGbl_FADT.XFacs = (UINT64) AcpiGbl_FADT.Facs;
    400  1.1  jruoho     }
    401  1.1  jruoho     if (!AcpiGbl_FADT.XDsdt)
    402  1.1  jruoho     {
    403  1.1  jruoho         AcpiGbl_FADT.XDsdt = (UINT64) AcpiGbl_FADT.Dsdt;
    404  1.1  jruoho     }
    405  1.1  jruoho 
    406  1.1  jruoho     /*
    407  1.1  jruoho      * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
    408  1.1  jruoho      * should be zero are indeed zero. This will workaround BIOSs that
    409  1.1  jruoho      * inadvertently place values in these fields.
    410  1.1  jruoho      *
    411  1.1  jruoho      * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
    412  1.1  jruoho      * at offset 45, 55, 95, and the word located at offset 109, 110.
    413  1.3  jruoho      *
    414  1.3  jruoho      * Note: The FADT revision value is unreliable. Only the length can be
    415  1.3  jruoho      * trusted.
    416  1.1  jruoho      */
    417  1.3  jruoho     if (AcpiGbl_FADT.Header.Length <= ACPI_FADT_V2_SIZE)
    418  1.1  jruoho     {
    419  1.1  jruoho         AcpiGbl_FADT.PreferredProfile = 0;
    420  1.1  jruoho         AcpiGbl_FADT.PstateControl = 0;
    421  1.1  jruoho         AcpiGbl_FADT.CstControl = 0;
    422  1.1  jruoho         AcpiGbl_FADT.BootFlags = 0;
    423  1.1  jruoho     }
    424  1.1  jruoho 
    425  1.1  jruoho     /*
    426  1.1  jruoho      * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
    427  1.1  jruoho      * generic address structures as necessary. Later code will always use
    428  1.1  jruoho      * the 64-bit address structures.
    429  1.1  jruoho      *
    430  1.1  jruoho      * March 2009:
    431  1.1  jruoho      * We now always use the 32-bit address if it is valid (non-null). This
    432  1.1  jruoho      * is not in accordance with the ACPI specification which states that
    433  1.1  jruoho      * the 64-bit address supersedes the 32-bit version, but we do this for
    434  1.1  jruoho      * compatibility with other ACPI implementations. Most notably, in the
    435  1.1  jruoho      * case where both the 32 and 64 versions are non-null, we use the 32-bit
    436  1.1  jruoho      * version. This is the only address that is guaranteed to have been
    437  1.1  jruoho      * tested by the BIOS manufacturer.
    438  1.1  jruoho      */
    439  1.1  jruoho     for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
    440  1.1  jruoho     {
    441  1.1  jruoho         Address32 = *ACPI_ADD_PTR (UINT32,
    442  1.1  jruoho             &AcpiGbl_FADT, FadtInfoTable[i].Address32);
    443  1.1  jruoho 
    444  1.1  jruoho         Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
    445  1.1  jruoho             &AcpiGbl_FADT, FadtInfoTable[i].Address64);
    446  1.1  jruoho 
    447  1.1  jruoho         /*
    448  1.1  jruoho          * If both 32- and 64-bit addresses are valid (non-zero),
    449  1.1  jruoho          * they must match.
    450  1.1  jruoho          */
    451  1.1  jruoho         if (Address64->Address && Address32 &&
    452  1.1  jruoho            (Address64->Address != (UINT64) Address32))
    453  1.1  jruoho         {
    454  1.1  jruoho             ACPI_ERROR ((AE_INFO,
    455  1.1  jruoho                 "32/64X address mismatch in %s: 0x%8.8X/0x%8.8X%8.8X, using 32",
    456  1.1  jruoho                 FadtInfoTable[i].Name, Address32,
    457  1.1  jruoho                 ACPI_FORMAT_UINT64 (Address64->Address)));
    458  1.1  jruoho         }
    459  1.1  jruoho 
    460  1.1  jruoho         /* Always use 32-bit address if it is valid (non-null) */
    461  1.1  jruoho 
    462  1.1  jruoho         if (Address32)
    463  1.1  jruoho         {
    464  1.1  jruoho             /*
    465  1.1  jruoho              * Copy the 32-bit address to the 64-bit GAS structure. The
    466  1.1  jruoho              * Space ID is always I/O for 32-bit legacy address fields
    467  1.1  jruoho              */
    468  1.1  jruoho             AcpiTbInitGenericAddress (Address64, ACPI_ADR_SPACE_SYSTEM_IO,
    469  1.1  jruoho                 *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT, FadtInfoTable[i].Length),
    470  1.1  jruoho                 (UINT64) Address32);
    471  1.1  jruoho         }
    472  1.1  jruoho     }
    473  1.1  jruoho }
    474  1.1  jruoho 
    475  1.1  jruoho 
    476  1.1  jruoho /*******************************************************************************
    477  1.1  jruoho  *
    478  1.1  jruoho  * FUNCTION:    AcpiTbValidateFadt
    479  1.1  jruoho  *
    480  1.1  jruoho  * PARAMETERS:  Table           - Pointer to the FADT to be validated
    481  1.1  jruoho  *
    482  1.1  jruoho  * RETURN:      None
    483  1.1  jruoho  *
    484  1.1  jruoho  * DESCRIPTION: Validate various important fields within the FADT. If a problem
    485  1.1  jruoho  *              is found, issue a message, but no status is returned.
    486  1.1  jruoho  *              Used by both the table manager and the disassembler.
    487  1.1  jruoho  *
    488  1.1  jruoho  * Possible additional checks:
    489  1.1  jruoho  * (AcpiGbl_FADT.Pm1EventLength >= 4)
    490  1.1  jruoho  * (AcpiGbl_FADT.Pm1ControlLength >= 2)
    491  1.1  jruoho  * (AcpiGbl_FADT.PmTimerLength >= 4)
    492  1.1  jruoho  * Gpe block lengths must be multiple of 2
    493  1.1  jruoho  *
    494  1.1  jruoho  ******************************************************************************/
    495  1.1  jruoho 
    496  1.1  jruoho static void
    497  1.1  jruoho AcpiTbValidateFadt (
    498  1.1  jruoho     void)
    499  1.1  jruoho {
    500  1.2  jruoho     const char              *Name;
    501  1.1  jruoho     ACPI_GENERIC_ADDRESS    *Address64;
    502  1.1  jruoho     UINT8                   Length;
    503  1.1  jruoho     UINT32                  i;
    504  1.1  jruoho 
    505  1.1  jruoho 
    506  1.1  jruoho     /*
    507  1.1  jruoho      * Check for FACS and DSDT address mismatches. An address mismatch between
    508  1.1  jruoho      * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
    509  1.1  jruoho      * DSDT/X_DSDT) would indicate the presence of two FACS or two DSDT tables.
    510  1.1  jruoho      */
    511  1.1  jruoho     if (AcpiGbl_FADT.Facs &&
    512  1.1  jruoho         (AcpiGbl_FADT.XFacs != (UINT64) AcpiGbl_FADT.Facs))
    513  1.1  jruoho     {
    514  1.1  jruoho         ACPI_WARNING ((AE_INFO,
    515  1.1  jruoho             "32/64X FACS address mismatch in FADT - "
    516  1.1  jruoho             "0x%8.8X/0x%8.8X%8.8X, using 32",
    517  1.1  jruoho             AcpiGbl_FADT.Facs, ACPI_FORMAT_UINT64 (AcpiGbl_FADT.XFacs)));
    518  1.1  jruoho 
    519  1.1  jruoho         AcpiGbl_FADT.XFacs = (UINT64) AcpiGbl_FADT.Facs;
    520  1.1  jruoho     }
    521  1.1  jruoho 
    522  1.1  jruoho     if (AcpiGbl_FADT.Dsdt &&
    523  1.1  jruoho         (AcpiGbl_FADT.XDsdt != (UINT64) AcpiGbl_FADT.Dsdt))
    524  1.1  jruoho     {
    525  1.1  jruoho         ACPI_WARNING ((AE_INFO,
    526  1.1  jruoho             "32/64X DSDT address mismatch in FADT - "
    527  1.1  jruoho             "0x%8.8X/0x%8.8X%8.8X, using 32",
    528  1.1  jruoho             AcpiGbl_FADT.Dsdt, ACPI_FORMAT_UINT64 (AcpiGbl_FADT.XDsdt)));
    529  1.1  jruoho 
    530  1.1  jruoho         AcpiGbl_FADT.XDsdt = (UINT64) AcpiGbl_FADT.Dsdt;
    531  1.1  jruoho     }
    532  1.1  jruoho 
    533  1.1  jruoho     /* Examine all of the 64-bit extended address fields (X fields) */
    534  1.1  jruoho 
    535  1.1  jruoho     for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
    536  1.1  jruoho     {
    537  1.1  jruoho         /*
    538  1.1  jruoho          * Generate pointer to the 64-bit address, get the register
    539  1.1  jruoho          * length (width) and the register name
    540  1.1  jruoho          */
    541  1.1  jruoho         Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
    542  1.1  jruoho                         &AcpiGbl_FADT, FadtInfoTable[i].Address64);
    543  1.1  jruoho         Length = *ACPI_ADD_PTR (UINT8,
    544  1.1  jruoho                         &AcpiGbl_FADT, FadtInfoTable[i].Length);
    545  1.1  jruoho         Name = FadtInfoTable[i].Name;
    546  1.1  jruoho 
    547  1.1  jruoho         /*
    548  1.1  jruoho          * For each extended field, check for length mismatch between the
    549  1.1  jruoho          * legacy length field and the corresponding 64-bit X length field.
    550  1.1  jruoho          */
    551  1.1  jruoho         if (Address64->Address &&
    552  1.1  jruoho            (Address64->BitWidth != ACPI_MUL_8 (Length)))
    553  1.1  jruoho         {
    554  1.1  jruoho             ACPI_WARNING ((AE_INFO,
    555  1.1  jruoho                 "32/64X length mismatch in %s: %u/%u",
    556  1.1  jruoho                 Name, ACPI_MUL_8 (Length), Address64->BitWidth));
    557  1.1  jruoho         }
    558  1.1  jruoho 
    559  1.1  jruoho         if (FadtInfoTable[i].Type & ACPI_FADT_REQUIRED)
    560  1.1  jruoho         {
    561  1.1  jruoho             /*
    562  1.1  jruoho              * Field is required (PM1aEvent, PM1aControl, PmTimer).
    563  1.1  jruoho              * Both the address and length must be non-zero.
    564  1.1  jruoho              */
    565  1.1  jruoho             if (!Address64->Address || !Length)
    566  1.1  jruoho             {
    567  1.1  jruoho                 ACPI_ERROR ((AE_INFO,
    568  1.1  jruoho                     "Required field %s has zero address and/or length:"
    569  1.1  jruoho                     " 0x%8.8X%8.8X/0x%X",
    570  1.1  jruoho                     Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
    571  1.1  jruoho             }
    572  1.1  jruoho         }
    573  1.1  jruoho         else if (FadtInfoTable[i].Type & ACPI_FADT_SEPARATE_LENGTH)
    574  1.1  jruoho         {
    575  1.1  jruoho             /*
    576  1.1  jruoho              * Field is optional (PM2Control, GPE0, GPE1) AND has its own
    577  1.1  jruoho              * length field. If present, both the address and length must
    578  1.1  jruoho              * be valid.
    579  1.1  jruoho              */
    580  1.1  jruoho             if ((Address64->Address && !Length) ||
    581  1.1  jruoho                 (!Address64->Address && Length))
    582  1.1  jruoho             {
    583  1.1  jruoho                 ACPI_WARNING ((AE_INFO,
    584  1.1  jruoho                     "Optional field %s has zero address or length: "
    585  1.1  jruoho                     "0x%8.8X%8.8X/0x%X",
    586  1.1  jruoho                     Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
    587  1.1  jruoho             }
    588  1.1  jruoho         }
    589  1.1  jruoho     }
    590  1.1  jruoho }
    591  1.1  jruoho 
    592  1.1  jruoho 
    593  1.1  jruoho /*******************************************************************************
    594  1.1  jruoho  *
    595  1.1  jruoho  * FUNCTION:    AcpiTbSetupFadtRegisters
    596  1.1  jruoho  *
    597  1.1  jruoho  * PARAMETERS:  None, uses AcpiGbl_FADT.
    598  1.1  jruoho  *
    599  1.1  jruoho  * RETURN:      None
    600  1.1  jruoho  *
    601  1.1  jruoho  * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
    602  1.1  jruoho  *              force FADT register definitions to their default lengths.
    603  1.1  jruoho  *
    604  1.1  jruoho  ******************************************************************************/
    605  1.1  jruoho 
    606  1.1  jruoho static void
    607  1.1  jruoho AcpiTbSetupFadtRegisters (
    608  1.1  jruoho     void)
    609  1.1  jruoho {
    610  1.1  jruoho     ACPI_GENERIC_ADDRESS    *Target64;
    611  1.1  jruoho     ACPI_GENERIC_ADDRESS    *Source64;
    612  1.1  jruoho     UINT8                   Pm1RegisterByteWidth;
    613  1.1  jruoho     UINT32                  i;
    614  1.1  jruoho 
    615  1.1  jruoho 
    616  1.1  jruoho     /*
    617  1.1  jruoho      * Optionally check all register lengths against the default values and
    618  1.1  jruoho      * update them if they are incorrect.
    619  1.1  jruoho      */
    620  1.1  jruoho     if (AcpiGbl_UseDefaultRegisterWidths)
    621  1.1  jruoho     {
    622  1.1  jruoho         for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
    623  1.1  jruoho         {
    624  1.1  jruoho             Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
    625  1.1  jruoho                 FadtInfoTable[i].Address64);
    626  1.1  jruoho 
    627  1.1  jruoho             /*
    628  1.1  jruoho              * If a valid register (Address != 0) and the (DefaultLength > 0)
    629  1.1  jruoho              * (Not a GPE register), then check the width against the default.
    630  1.1  jruoho              */
    631  1.1  jruoho             if ((Target64->Address) &&
    632  1.1  jruoho                 (FadtInfoTable[i].DefaultLength > 0) &&
    633  1.1  jruoho                 (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
    634  1.1  jruoho             {
    635  1.1  jruoho                 ACPI_WARNING ((AE_INFO,
    636  1.1  jruoho                     "Invalid length for %s: %u, using default %u",
    637  1.1  jruoho                     FadtInfoTable[i].Name, Target64->BitWidth,
    638  1.1  jruoho                     FadtInfoTable[i].DefaultLength));
    639  1.1  jruoho 
    640  1.1  jruoho                 /* Incorrect size, set width to the default */
    641  1.1  jruoho 
    642  1.1  jruoho                 Target64->BitWidth = FadtInfoTable[i].DefaultLength;
    643  1.1  jruoho             }
    644  1.1  jruoho         }
    645  1.1  jruoho     }
    646  1.1  jruoho 
    647  1.1  jruoho     /*
    648  1.1  jruoho      * Get the length of the individual PM1 registers (enable and status).
    649  1.1  jruoho      * Each register is defined to be (event block length / 2). Extra divide
    650  1.1  jruoho      * by 8 converts bits to bytes.
    651  1.1  jruoho      */
    652  1.1  jruoho     Pm1RegisterByteWidth = (UINT8)
    653  1.1  jruoho         ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
    654  1.1  jruoho 
    655  1.1  jruoho     /*
    656  1.1  jruoho      * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
    657  1.1  jruoho      * registers. These addresses do not appear (directly) in the FADT, so it
    658  1.1  jruoho      * is useful to pre-calculate them from the PM1 Event Block definitions.
    659  1.1  jruoho      *
    660  1.1  jruoho      * The PM event blocks are split into two register blocks, first is the
    661  1.1  jruoho      * PM Status Register block, followed immediately by the PM Enable
    662  1.1  jruoho      * Register block. Each is of length (Pm1EventLength/2)
    663  1.1  jruoho      *
    664  1.1  jruoho      * Note: The PM1A event block is required by the ACPI specification.
    665  1.1  jruoho      * However, the PM1B event block is optional and is rarely, if ever,
    666  1.1  jruoho      * used.
    667  1.1  jruoho      */
    668  1.1  jruoho 
    669  1.1  jruoho     for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
    670  1.1  jruoho     {
    671  1.1  jruoho         Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
    672  1.1  jruoho             FadtPmInfoTable[i].Source);
    673  1.1  jruoho 
    674  1.1  jruoho         if (Source64->Address)
    675  1.1  jruoho         {
    676  1.1  jruoho             AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
    677  1.1  jruoho                 Source64->SpaceId, Pm1RegisterByteWidth,
    678  1.1  jruoho                 Source64->Address +
    679  1.1  jruoho                     (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth));
    680  1.1  jruoho         }
    681  1.1  jruoho     }
    682  1.1  jruoho }
    683  1.1  jruoho 
    684