Home | History | Annotate | Line # | Download | only in tables
tbfadt.c revision 1.8
      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.8  christos  * Copyright (C) 2000 - 2016, 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 #include "acpi.h"
     45  1.1    jruoho #include "accommon.h"
     46  1.1    jruoho #include "actables.h"
     47  1.1    jruoho 
     48  1.1    jruoho #define _COMPONENT          ACPI_TABLES
     49  1.1    jruoho         ACPI_MODULE_NAME    ("tbfadt")
     50  1.1    jruoho 
     51  1.1    jruoho /* Local prototypes */
     52  1.1    jruoho 
     53  1.4  christos static void
     54  1.1    jruoho AcpiTbInitGenericAddress (
     55  1.1    jruoho     ACPI_GENERIC_ADDRESS    *GenericAddress,
     56  1.1    jruoho     UINT8                   SpaceId,
     57  1.1    jruoho     UINT8                   ByteWidth,
     58  1.4  christos     UINT64                  Address,
     59  1.5  christos     char                    *RegisterName,
     60  1.5  christos     UINT8                   Flags);
     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.4  christos AcpiTbSetupFadtRegisters (
     68  1.1    jruoho     void);
     69  1.1    jruoho 
     70  1.4  christos static UINT64
     71  1.4  christos AcpiTbSelectAddress (
     72  1.4  christos     char                    *RegisterName,
     73  1.4  christos     UINT32                  Address32,
     74  1.4  christos     UINT64                  Address64);
     75  1.1    jruoho 
     76  1.1    jruoho 
     77  1.1    jruoho /* Table for conversion of FADT to common internal format and FADT validation */
     78  1.1    jruoho 
     79  1.1    jruoho typedef struct acpi_fadt_info
     80  1.1    jruoho {
     81  1.2    jruoho     const char              *Name;
     82  1.4  christos     UINT16                  Address64;
     83  1.4  christos     UINT16                  Address32;
     84  1.4  christos     UINT16                  Length;
     85  1.1    jruoho     UINT8                   DefaultLength;
     86  1.5  christos     UINT8                   Flags;
     87  1.1    jruoho 
     88  1.1    jruoho } ACPI_FADT_INFO;
     89  1.1    jruoho 
     90  1.4  christos #define ACPI_FADT_OPTIONAL          0
     91  1.1    jruoho #define ACPI_FADT_REQUIRED          1
     92  1.1    jruoho #define ACPI_FADT_SEPARATE_LENGTH   2
     93  1.5  christos #define ACPI_FADT_GPE_REGISTER      4
     94  1.1    jruoho 
     95  1.1    jruoho static ACPI_FADT_INFO     FadtInfoTable[] =
     96  1.1    jruoho {
     97  1.1    jruoho     {"Pm1aEventBlock",
     98  1.1    jruoho         ACPI_FADT_OFFSET (XPm1aEventBlock),
     99  1.1    jruoho         ACPI_FADT_OFFSET (Pm1aEventBlock),
    100  1.1    jruoho         ACPI_FADT_OFFSET (Pm1EventLength),
    101  1.1    jruoho         ACPI_PM1_REGISTER_WIDTH * 2,        /* Enable + Status register */
    102  1.1    jruoho         ACPI_FADT_REQUIRED},
    103  1.1    jruoho 
    104  1.1    jruoho     {"Pm1bEventBlock",
    105  1.1    jruoho         ACPI_FADT_OFFSET (XPm1bEventBlock),
    106  1.1    jruoho         ACPI_FADT_OFFSET (Pm1bEventBlock),
    107  1.1    jruoho         ACPI_FADT_OFFSET (Pm1EventLength),
    108  1.1    jruoho         ACPI_PM1_REGISTER_WIDTH * 2,        /* Enable + Status register */
    109  1.4  christos         ACPI_FADT_OPTIONAL},
    110  1.1    jruoho 
    111  1.1    jruoho     {"Pm1aControlBlock",
    112  1.1    jruoho         ACPI_FADT_OFFSET (XPm1aControlBlock),
    113  1.1    jruoho         ACPI_FADT_OFFSET (Pm1aControlBlock),
    114  1.1    jruoho         ACPI_FADT_OFFSET (Pm1ControlLength),
    115  1.1    jruoho         ACPI_PM1_REGISTER_WIDTH,
    116  1.1    jruoho         ACPI_FADT_REQUIRED},
    117  1.1    jruoho 
    118  1.1    jruoho     {"Pm1bControlBlock",
    119  1.1    jruoho         ACPI_FADT_OFFSET (XPm1bControlBlock),
    120  1.1    jruoho         ACPI_FADT_OFFSET (Pm1bControlBlock),
    121  1.1    jruoho         ACPI_FADT_OFFSET (Pm1ControlLength),
    122  1.1    jruoho         ACPI_PM1_REGISTER_WIDTH,
    123  1.4  christos         ACPI_FADT_OPTIONAL},
    124  1.1    jruoho 
    125  1.1    jruoho     {"Pm2ControlBlock",
    126  1.1    jruoho         ACPI_FADT_OFFSET (XPm2ControlBlock),
    127  1.1    jruoho         ACPI_FADT_OFFSET (Pm2ControlBlock),
    128  1.1    jruoho         ACPI_FADT_OFFSET (Pm2ControlLength),
    129  1.1    jruoho         ACPI_PM2_REGISTER_WIDTH,
    130  1.1    jruoho         ACPI_FADT_SEPARATE_LENGTH},
    131  1.1    jruoho 
    132  1.1    jruoho     {"PmTimerBlock",
    133  1.1    jruoho         ACPI_FADT_OFFSET (XPmTimerBlock),
    134  1.1    jruoho         ACPI_FADT_OFFSET (PmTimerBlock),
    135  1.1    jruoho         ACPI_FADT_OFFSET (PmTimerLength),
    136  1.1    jruoho         ACPI_PM_TIMER_WIDTH,
    137  1.4  christos         ACPI_FADT_SEPARATE_LENGTH},         /* ACPI 5.0A: Timer is optional */
    138  1.1    jruoho 
    139  1.1    jruoho     {"Gpe0Block",
    140  1.1    jruoho         ACPI_FADT_OFFSET (XGpe0Block),
    141  1.1    jruoho         ACPI_FADT_OFFSET (Gpe0Block),
    142  1.1    jruoho         ACPI_FADT_OFFSET (Gpe0BlockLength),
    143  1.1    jruoho         0,
    144  1.5  christos         ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER},
    145  1.1    jruoho 
    146  1.1    jruoho     {"Gpe1Block",
    147  1.1    jruoho         ACPI_FADT_OFFSET (XGpe1Block),
    148  1.1    jruoho         ACPI_FADT_OFFSET (Gpe1Block),
    149  1.1    jruoho         ACPI_FADT_OFFSET (Gpe1BlockLength),
    150  1.1    jruoho         0,
    151  1.5  christos         ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER}
    152  1.1    jruoho };
    153  1.1    jruoho 
    154  1.1    jruoho #define ACPI_FADT_INFO_ENTRIES \
    155  1.1    jruoho             (sizeof (FadtInfoTable) / sizeof (ACPI_FADT_INFO))
    156  1.1    jruoho 
    157  1.1    jruoho 
    158  1.1    jruoho /* Table used to split Event Blocks into separate status/enable registers */
    159  1.1    jruoho 
    160  1.1    jruoho typedef struct acpi_fadt_pm_info
    161  1.1    jruoho {
    162  1.1    jruoho     ACPI_GENERIC_ADDRESS    *Target;
    163  1.4  christos     UINT16                  Source;
    164  1.1    jruoho     UINT8                   RegisterNum;
    165  1.1    jruoho 
    166  1.1    jruoho } ACPI_FADT_PM_INFO;
    167  1.1    jruoho 
    168  1.1    jruoho static ACPI_FADT_PM_INFO    FadtPmInfoTable[] =
    169  1.1    jruoho {
    170  1.1    jruoho     {&AcpiGbl_XPm1aStatus,
    171  1.1    jruoho         ACPI_FADT_OFFSET (XPm1aEventBlock),
    172  1.1    jruoho         0},
    173  1.1    jruoho 
    174  1.1    jruoho     {&AcpiGbl_XPm1aEnable,
    175  1.1    jruoho         ACPI_FADT_OFFSET (XPm1aEventBlock),
    176  1.1    jruoho         1},
    177  1.1    jruoho 
    178  1.1    jruoho     {&AcpiGbl_XPm1bStatus,
    179  1.1    jruoho         ACPI_FADT_OFFSET (XPm1bEventBlock),
    180  1.1    jruoho         0},
    181  1.1    jruoho 
    182  1.1    jruoho     {&AcpiGbl_XPm1bEnable,
    183  1.1    jruoho         ACPI_FADT_OFFSET (XPm1bEventBlock),
    184  1.1    jruoho         1}
    185  1.1    jruoho };
    186  1.1    jruoho 
    187  1.1    jruoho #define ACPI_FADT_PM_INFO_ENTRIES \
    188  1.1    jruoho             (sizeof (FadtPmInfoTable) / sizeof (ACPI_FADT_PM_INFO))
    189  1.1    jruoho 
    190  1.1    jruoho 
    191  1.1    jruoho /*******************************************************************************
    192  1.1    jruoho  *
    193  1.1    jruoho  * FUNCTION:    AcpiTbInitGenericAddress
    194  1.1    jruoho  *
    195  1.1    jruoho  * PARAMETERS:  GenericAddress      - GAS struct to be initialized
    196  1.1    jruoho  *              SpaceId             - ACPI Space ID for this register
    197  1.4  christos  *              ByteWidth           - Width of this register
    198  1.1    jruoho  *              Address             - Address of the register
    199  1.4  christos  *              RegisterName        - ASCII name of the ACPI register
    200  1.1    jruoho  *
    201  1.1    jruoho  * RETURN:      None
    202  1.1    jruoho  *
    203  1.1    jruoho  * DESCRIPTION: Initialize a Generic Address Structure (GAS)
    204  1.1    jruoho  *              See the ACPI specification for a full description and
    205  1.1    jruoho  *              definition of this structure.
    206  1.1    jruoho  *
    207  1.1    jruoho  ******************************************************************************/
    208  1.1    jruoho 
    209  1.4  christos static void
    210  1.1    jruoho AcpiTbInitGenericAddress (
    211  1.1    jruoho     ACPI_GENERIC_ADDRESS    *GenericAddress,
    212  1.1    jruoho     UINT8                   SpaceId,
    213  1.1    jruoho     UINT8                   ByteWidth,
    214  1.4  christos     UINT64                  Address,
    215  1.5  christos     char                    *RegisterName,
    216  1.5  christos     UINT8                   Flags)
    217  1.1    jruoho {
    218  1.4  christos     UINT8                   BitWidth;
    219  1.4  christos 
    220  1.4  christos 
    221  1.5  christos     /*
    222  1.5  christos      * Bit width field in the GAS is only one byte long, 255 max.
    223  1.5  christos      * Check for BitWidth overflow in GAS.
    224  1.5  christos      */
    225  1.4  christos     BitWidth = (UINT8) (ByteWidth * 8);
    226  1.5  christos     if (ByteWidth > 31)     /* (31*8)=248, (32*8)=256 */
    227  1.4  christos     {
    228  1.5  christos         /*
    229  1.5  christos          * No error for GPE blocks, because we do not use the BitWidth
    230  1.5  christos          * for GPEs, the legacy length (ByteWidth) is used instead to
    231  1.5  christos          * allow for a large number of GPEs.
    232  1.5  christos          */
    233  1.5  christos         if (!(Flags & ACPI_FADT_GPE_REGISTER))
    234  1.5  christos         {
    235  1.5  christos             ACPI_ERROR ((AE_INFO,
    236  1.5  christos                 "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
    237  1.5  christos                 "to convert to GAS struct - 255 bits max, truncating",
    238  1.5  christos                 RegisterName, ByteWidth, (ByteWidth * 8)));
    239  1.5  christos         }
    240  1.4  christos 
    241  1.4  christos         BitWidth = 255;
    242  1.4  christos     }
    243  1.1    jruoho 
    244  1.1    jruoho     /*
    245  1.1    jruoho      * The 64-bit Address field is non-aligned in the byte packed
    246  1.1    jruoho      * GAS struct.
    247  1.1    jruoho      */
    248  1.1    jruoho     ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
    249  1.1    jruoho 
    250  1.1    jruoho     /* All other fields are byte-wide */
    251  1.1    jruoho 
    252  1.1    jruoho     GenericAddress->SpaceId = SpaceId;
    253  1.4  christos     GenericAddress->BitWidth = BitWidth;
    254  1.1    jruoho     GenericAddress->BitOffset = 0;
    255  1.1    jruoho     GenericAddress->AccessWidth = 0; /* Access width ANY */
    256  1.1    jruoho }
    257  1.1    jruoho 
    258  1.1    jruoho 
    259  1.1    jruoho /*******************************************************************************
    260  1.1    jruoho  *
    261  1.4  christos  * FUNCTION:    AcpiTbSelectAddress
    262  1.4  christos  *
    263  1.4  christos  * PARAMETERS:  RegisterName        - ASCII name of the ACPI register
    264  1.4  christos  *              Address32           - 32-bit address of the register
    265  1.4  christos  *              Address64           - 64-bit address of the register
    266  1.4  christos  *
    267  1.4  christos  * RETURN:      The resolved 64-bit address
    268  1.4  christos  *
    269  1.4  christos  * DESCRIPTION: Select between 32-bit and 64-bit versions of addresses within
    270  1.4  christos  *              the FADT. Used for the FACS and DSDT addresses.
    271  1.4  christos  *
    272  1.4  christos  * NOTES:
    273  1.4  christos  *
    274  1.4  christos  * Check for FACS and DSDT address mismatches. An address mismatch between
    275  1.4  christos  * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
    276  1.4  christos  * DSDT/X_DSDT) could be a corrupted address field or it might indicate
    277  1.4  christos  * the presence of two FACS or two DSDT tables.
    278  1.4  christos  *
    279  1.4  christos  * November 2013:
    280  1.4  christos  * By default, as per the ACPICA specification, a valid 64-bit address is
    281  1.4  christos  * used regardless of the value of the 32-bit address. However, this
    282  1.4  christos  * behavior can be overridden via the AcpiGbl_Use32BitFadtAddresses flag.
    283  1.4  christos  *
    284  1.4  christos  ******************************************************************************/
    285  1.4  christos 
    286  1.4  christos static UINT64
    287  1.4  christos AcpiTbSelectAddress (
    288  1.4  christos     char                    *RegisterName,
    289  1.4  christos     UINT32                  Address32,
    290  1.4  christos     UINT64                  Address64)
    291  1.4  christos {
    292  1.4  christos 
    293  1.4  christos     if (!Address64)
    294  1.4  christos     {
    295  1.4  christos         /* 64-bit address is zero, use 32-bit address */
    296  1.4  christos 
    297  1.4  christos         return ((UINT64) Address32);
    298  1.4  christos     }
    299  1.4  christos 
    300  1.4  christos     if (Address32 &&
    301  1.4  christos        (Address64 != (UINT64) Address32))
    302  1.4  christos     {
    303  1.4  christos         /* Address mismatch between 32-bit and 64-bit versions */
    304  1.4  christos 
    305  1.4  christos         ACPI_BIOS_WARNING ((AE_INFO,
    306  1.4  christos             "32/64X %s address mismatch in FADT: "
    307  1.4  christos             "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
    308  1.4  christos             RegisterName, Address32, ACPI_FORMAT_UINT64 (Address64),
    309  1.4  christos             AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
    310  1.4  christos 
    311  1.4  christos         /* 32-bit address override */
    312  1.4  christos 
    313  1.4  christos         if (AcpiGbl_Use32BitFadtAddresses)
    314  1.4  christos         {
    315  1.4  christos             return ((UINT64) Address32);
    316  1.4  christos         }
    317  1.4  christos     }
    318  1.4  christos 
    319  1.4  christos     /* Default is to use the 64-bit address */
    320  1.4  christos 
    321  1.4  christos     return (Address64);
    322  1.4  christos }
    323  1.4  christos 
    324  1.4  christos 
    325  1.4  christos /*******************************************************************************
    326  1.4  christos  *
    327  1.1    jruoho  * FUNCTION:    AcpiTbParseFadt
    328  1.1    jruoho  *
    329  1.8  christos  * PARAMETERS:  None
    330  1.1    jruoho  *
    331  1.1    jruoho  * RETURN:      None
    332  1.1    jruoho  *
    333  1.1    jruoho  * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
    334  1.1    jruoho  *              (FADT contains the addresses of the DSDT and FACS)
    335  1.1    jruoho  *
    336  1.1    jruoho  ******************************************************************************/
    337  1.1    jruoho 
    338  1.1    jruoho void
    339  1.1    jruoho AcpiTbParseFadt (
    340  1.8  christos     void)
    341  1.1    jruoho {
    342  1.1    jruoho     UINT32                  Length;
    343  1.1    jruoho     ACPI_TABLE_HEADER       *Table;
    344  1.1    jruoho 
    345  1.1    jruoho 
    346  1.1    jruoho     /*
    347  1.1    jruoho      * The FADT has multiple versions with different lengths,
    348  1.1    jruoho      * and it contains pointers to both the DSDT and FACS tables.
    349  1.1    jruoho      *
    350  1.1    jruoho      * Get a local copy of the FADT and convert it to a common format
    351  1.1    jruoho      * Map entire FADT, assumed to be smaller than one page.
    352  1.1    jruoho      */
    353  1.8  christos     Length = AcpiGbl_RootTableList.Tables[AcpiGbl_FadtIndex].Length;
    354  1.1    jruoho 
    355  1.1    jruoho     Table = AcpiOsMapMemory (
    356  1.8  christos         AcpiGbl_RootTableList.Tables[AcpiGbl_FadtIndex].Address, Length);
    357  1.1    jruoho     if (!Table)
    358  1.1    jruoho     {
    359  1.1    jruoho         return;
    360  1.1    jruoho     }
    361  1.1    jruoho 
    362  1.1    jruoho     /*
    363  1.1    jruoho      * Validate the FADT checksum before we copy the table. Ignore
    364  1.1    jruoho      * checksum error as we want to try to get the DSDT and FACS.
    365  1.1    jruoho      */
    366  1.1    jruoho     (void) AcpiTbVerifyChecksum (Table, Length);
    367  1.1    jruoho 
    368  1.1    jruoho     /* Create a local copy of the FADT in common ACPI 2.0+ format */
    369  1.1    jruoho 
    370  1.1    jruoho     AcpiTbCreateLocalFadt (Table, Length);
    371  1.1    jruoho 
    372  1.1    jruoho     /* All done with the real FADT, unmap it */
    373  1.1    jruoho 
    374  1.1    jruoho     AcpiOsUnmapMemory (Table, Length);
    375  1.1    jruoho 
    376  1.1    jruoho     /* Obtain the DSDT and FACS tables via their addresses within the FADT */
    377  1.1    jruoho 
    378  1.5  christos     AcpiTbInstallFixedTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
    379  1.8  christos         ACPI_SIG_DSDT, &AcpiGbl_DsdtIndex);
    380  1.1    jruoho 
    381  1.4  christos     /* If Hardware Reduced flag is set, there is no FACS */
    382  1.4  christos 
    383  1.4  christos     if (!AcpiGbl_ReducedHardware)
    384  1.4  christos     {
    385  1.7  christos         if (AcpiGbl_FADT.Facs)
    386  1.7  christos         {
    387  1.7  christos             AcpiTbInstallFixedTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.Facs,
    388  1.8  christos                 ACPI_SIG_FACS, &AcpiGbl_FacsIndex);
    389  1.7  christos         }
    390  1.7  christos         if (AcpiGbl_FADT.XFacs)
    391  1.7  christos         {
    392  1.7  christos             AcpiTbInstallFixedTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
    393  1.8  christos                 ACPI_SIG_FACS, &AcpiGbl_XFacsIndex);
    394  1.7  christos         }
    395  1.4  christos     }
    396  1.1    jruoho }
    397  1.1    jruoho 
    398  1.1    jruoho 
    399  1.1    jruoho /*******************************************************************************
    400  1.1    jruoho  *
    401  1.1    jruoho  * FUNCTION:    AcpiTbCreateLocalFadt
    402  1.1    jruoho  *
    403  1.1    jruoho  * PARAMETERS:  Table               - Pointer to BIOS FADT
    404  1.1    jruoho  *              Length              - Length of the table
    405  1.1    jruoho  *
    406  1.1    jruoho  * RETURN:      None
    407  1.1    jruoho  *
    408  1.1    jruoho  * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
    409  1.1    jruoho  *              Performs validation on some important FADT fields.
    410  1.1    jruoho  *
    411  1.1    jruoho  * NOTE:        We create a local copy of the FADT regardless of the version.
    412  1.1    jruoho  *
    413  1.1    jruoho  ******************************************************************************/
    414  1.1    jruoho 
    415  1.1    jruoho void
    416  1.1    jruoho AcpiTbCreateLocalFadt (
    417  1.1    jruoho     ACPI_TABLE_HEADER       *Table,
    418  1.1    jruoho     UINT32                  Length)
    419  1.1    jruoho {
    420  1.1    jruoho 
    421  1.1    jruoho     /*
    422  1.1    jruoho      * Check if the FADT is larger than the largest table that we expect
    423  1.4  christos      * (the ACPI 5.0 version). If so, truncate the table, and issue
    424  1.1    jruoho      * a warning.
    425  1.1    jruoho      */
    426  1.1    jruoho     if (Length > sizeof (ACPI_TABLE_FADT))
    427  1.1    jruoho     {
    428  1.4  christos         ACPI_BIOS_WARNING ((AE_INFO,
    429  1.4  christos             "FADT (revision %u) is longer than ACPI 5.0 version, "
    430  1.1    jruoho             "truncating length %u to %u",
    431  1.1    jruoho             Table->Revision, Length, (UINT32) sizeof (ACPI_TABLE_FADT)));
    432  1.1    jruoho     }
    433  1.1    jruoho 
    434  1.1    jruoho     /* Clear the entire local FADT */
    435  1.1    jruoho 
    436  1.7  christos     memset (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
    437  1.1    jruoho 
    438  1.1    jruoho     /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
    439  1.1    jruoho 
    440  1.7  christos     memcpy (&AcpiGbl_FADT, Table,
    441  1.1    jruoho         ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
    442  1.1    jruoho 
    443  1.4  christos     /* Take a copy of the Hardware Reduced flag */
    444  1.4  christos 
    445  1.4  christos     AcpiGbl_ReducedHardware = FALSE;
    446  1.4  christos     if (AcpiGbl_FADT.Flags & ACPI_FADT_HW_REDUCED)
    447  1.4  christos     {
    448  1.4  christos         AcpiGbl_ReducedHardware = TRUE;
    449  1.4  christos     }
    450  1.4  christos 
    451  1.1    jruoho     /* Convert the local copy of the FADT to the common internal format */
    452  1.1    jruoho 
    453  1.1    jruoho     AcpiTbConvertFadt ();
    454  1.1    jruoho 
    455  1.1    jruoho     /* Initialize the global ACPI register structures */
    456  1.1    jruoho 
    457  1.1    jruoho     AcpiTbSetupFadtRegisters ();
    458  1.1    jruoho }
    459  1.1    jruoho 
    460  1.1    jruoho 
    461  1.1    jruoho /*******************************************************************************
    462  1.1    jruoho  *
    463  1.1    jruoho  * FUNCTION:    AcpiTbConvertFadt
    464  1.1    jruoho  *
    465  1.4  christos  * PARAMETERS:  None - AcpiGbl_FADT is used.
    466  1.1    jruoho  *
    467  1.1    jruoho  * RETURN:      None
    468  1.1    jruoho  *
    469  1.1    jruoho  * DESCRIPTION: Converts all versions of the FADT to a common internal format.
    470  1.4  christos  *              Expand 32-bit addresses to 64-bit as necessary. Also validate
    471  1.4  christos  *              important fields within the FADT.
    472  1.1    jruoho  *
    473  1.4  christos  * NOTE:        AcpiGbl_FADT must be of size (ACPI_TABLE_FADT), and must
    474  1.4  christos  *              contain a copy of the actual BIOS-provided FADT.
    475  1.1    jruoho  *
    476  1.1    jruoho  * Notes on 64-bit register addresses:
    477  1.1    jruoho  *
    478  1.1    jruoho  * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
    479  1.1    jruoho  * fields of the FADT for all ACPI register addresses.
    480  1.1    jruoho  *
    481  1.4  christos  * The 64-bit X fields are optional extensions to the original 32-bit FADT
    482  1.1    jruoho  * V1.0 fields. Even if they are present in the FADT, they are optional and
    483  1.1    jruoho  * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
    484  1.4  christos  * 32-bit V1.0 fields to the 64-bit X fields if the the 64-bit X field is
    485  1.4  christos  * originally zero.
    486  1.1    jruoho  *
    487  1.4  christos  * For ACPI 1.0 FADTs (that contain no 64-bit addresses), all 32-bit address
    488  1.4  christos  * fields are expanded to the corresponding 64-bit X fields in the internal
    489  1.4  christos  * common FADT.
    490  1.1    jruoho  *
    491  1.1    jruoho  * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
    492  1.4  christos  * to the corresponding 64-bit X fields, if the 64-bit field is originally
    493  1.4  christos  * zero. Adhering to the ACPI specification, we completely ignore the 32-bit
    494  1.4  christos  * field if the 64-bit field is valid, regardless of whether the host OS is
    495  1.4  christos  * 32-bit or 64-bit.
    496  1.4  christos  *
    497  1.4  christos  * Possible additional checks:
    498  1.4  christos  *  (AcpiGbl_FADT.Pm1EventLength >= 4)
    499  1.4  christos  *  (AcpiGbl_FADT.Pm1ControlLength >= 2)
    500  1.4  christos  *  (AcpiGbl_FADT.PmTimerLength >= 4)
    501  1.4  christos  *  Gpe block lengths must be multiple of 2
    502  1.1    jruoho  *
    503  1.1    jruoho  ******************************************************************************/
    504  1.1    jruoho 
    505  1.1    jruoho static void
    506  1.1    jruoho AcpiTbConvertFadt (
    507  1.1    jruoho     void)
    508  1.1    jruoho {
    509  1.4  christos     char                    *Name;
    510  1.1    jruoho     ACPI_GENERIC_ADDRESS    *Address64;
    511  1.1    jruoho     UINT32                  Address32;
    512  1.4  christos     UINT8                   Length;
    513  1.5  christos     UINT8                   Flags;
    514  1.1    jruoho     UINT32                  i;
    515  1.1    jruoho 
    516  1.1    jruoho 
    517  1.1    jruoho     /*
    518  1.1    jruoho      * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
    519  1.1    jruoho      * should be zero are indeed zero. This will workaround BIOSs that
    520  1.1    jruoho      * inadvertently place values in these fields.
    521  1.1    jruoho      *
    522  1.1    jruoho      * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
    523  1.1    jruoho      * at offset 45, 55, 95, and the word located at offset 109, 110.
    524  1.3    jruoho      *
    525  1.3    jruoho      * Note: The FADT revision value is unreliable. Only the length can be
    526  1.3    jruoho      * trusted.
    527  1.1    jruoho      */
    528  1.3    jruoho     if (AcpiGbl_FADT.Header.Length <= ACPI_FADT_V2_SIZE)
    529  1.1    jruoho     {
    530  1.1    jruoho         AcpiGbl_FADT.PreferredProfile = 0;
    531  1.1    jruoho         AcpiGbl_FADT.PstateControl = 0;
    532  1.1    jruoho         AcpiGbl_FADT.CstControl = 0;
    533  1.1    jruoho         AcpiGbl_FADT.BootFlags = 0;
    534  1.1    jruoho     }
    535  1.1    jruoho 
    536  1.1    jruoho     /*
    537  1.4  christos      * Now we can update the local FADT length to the length of the
    538  1.4  christos      * current FADT version as defined by the ACPI specification.
    539  1.4  christos      * Thus, we will have a common FADT internally.
    540  1.1    jruoho      */
    541  1.4  christos     AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
    542  1.1    jruoho 
    543  1.1    jruoho     /*
    544  1.7  christos      * Expand the 32-bit DSDT addresses to 64-bit as necessary.
    545  1.4  christos      * Later ACPICA code will always use the X 64-bit field.
    546  1.1    jruoho      */
    547  1.4  christos     AcpiGbl_FADT.XDsdt = AcpiTbSelectAddress (__UNCONST("DSDT"),
    548  1.4  christos         AcpiGbl_FADT.Dsdt, AcpiGbl_FADT.XDsdt);
    549  1.1    jruoho 
    550  1.4  christos     /* If Hardware Reduced flag is set, we are all done */
    551  1.1    jruoho 
    552  1.4  christos     if (AcpiGbl_ReducedHardware)
    553  1.1    jruoho     {
    554  1.4  christos         return;
    555  1.1    jruoho     }
    556  1.1    jruoho 
    557  1.1    jruoho     /* Examine all of the 64-bit extended address fields (X fields) */
    558  1.1    jruoho 
    559  1.1    jruoho     for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
    560  1.1    jruoho     {
    561  1.1    jruoho         /*
    562  1.4  christos          * Get the 32-bit and 64-bit addresses, as well as the register
    563  1.4  christos          * length and register name.
    564  1.1    jruoho          */
    565  1.4  christos         Address32 = *ACPI_ADD_PTR (UINT32,
    566  1.4  christos             &AcpiGbl_FADT, FadtInfoTable[i].Address32);
    567  1.4  christos 
    568  1.1    jruoho         Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
    569  1.4  christos             &AcpiGbl_FADT, FadtInfoTable[i].Address64);
    570  1.4  christos 
    571  1.1    jruoho         Length = *ACPI_ADD_PTR (UINT8,
    572  1.4  christos             &AcpiGbl_FADT, FadtInfoTable[i].Length);
    573  1.4  christos 
    574  1.4  christos         Name = __UNCONST(FadtInfoTable[i].Name);
    575  1.5  christos         Flags = FadtInfoTable[i].Flags;
    576  1.4  christos 
    577  1.4  christos         /*
    578  1.4  christos          * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
    579  1.4  christos          * generic address structures as necessary. Later code will always use
    580  1.4  christos          * the 64-bit address structures.
    581  1.4  christos          *
    582  1.4  christos          * November 2013:
    583  1.4  christos          * Now always use the 64-bit address if it is valid (non-zero), in
    584  1.4  christos          * accordance with the ACPI specification which states that a 64-bit
    585  1.4  christos          * address supersedes the 32-bit version. This behavior can be
    586  1.4  christos          * overridden by the AcpiGbl_Use32BitFadtAddresses flag.
    587  1.4  christos          *
    588  1.4  christos          * During 64-bit address construction and verification,
    589  1.4  christos          * these cases are handled:
    590  1.4  christos          *
    591  1.4  christos          * Address32 zero, Address64 [don't care]   - Use Address64
    592  1.4  christos          *
    593  1.4  christos          * Address32 non-zero, Address64 zero       - Copy/use Address32
    594  1.4  christos          * Address32 non-zero == Address64 non-zero - Use Address64
    595  1.4  christos          * Address32 non-zero != Address64 non-zero - Warning, use Address64
    596  1.4  christos          *
    597  1.4  christos          * Override: if AcpiGbl_Use32BitFadtAddresses is TRUE, and:
    598  1.4  christos          * Address32 non-zero != Address64 non-zero - Warning, copy/use Address32
    599  1.4  christos          *
    600  1.4  christos          * Note: SpaceId is always I/O for 32-bit legacy address fields
    601  1.4  christos          */
    602  1.4  christos         if (Address32)
    603  1.4  christos         {
    604  1.4  christos             if (!Address64->Address)
    605  1.4  christos             {
    606  1.4  christos                 /* 64-bit address is zero, use 32-bit address */
    607  1.4  christos 
    608  1.4  christos                 AcpiTbInitGenericAddress (Address64,
    609  1.4  christos                     ACPI_ADR_SPACE_SYSTEM_IO,
    610  1.4  christos                     *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT,
    611  1.4  christos                         FadtInfoTable[i].Length),
    612  1.5  christos                     (UINT64) Address32, Name, Flags);
    613  1.4  christos             }
    614  1.4  christos             else if (Address64->Address != (UINT64) Address32)
    615  1.4  christos             {
    616  1.4  christos                 /* Address mismatch */
    617  1.4  christos 
    618  1.4  christos                 ACPI_BIOS_WARNING ((AE_INFO,
    619  1.4  christos                     "32/64X address mismatch in FADT/%s: "
    620  1.4  christos                     "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
    621  1.4  christos                     Name, Address32,
    622  1.4  christos                     ACPI_FORMAT_UINT64 (Address64->Address),
    623  1.4  christos                     AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
    624  1.4  christos 
    625  1.4  christos                 if (AcpiGbl_Use32BitFadtAddresses)
    626  1.4  christos                 {
    627  1.4  christos                     /* 32-bit address override */
    628  1.4  christos 
    629  1.4  christos                     AcpiTbInitGenericAddress (Address64,
    630  1.4  christos                         ACPI_ADR_SPACE_SYSTEM_IO,
    631  1.4  christos                         *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT,
    632  1.4  christos                             FadtInfoTable[i].Length),
    633  1.5  christos                         (UINT64) Address32, Name, Flags);
    634  1.4  christos                 }
    635  1.4  christos             }
    636  1.4  christos         }
    637  1.1    jruoho 
    638  1.1    jruoho         /*
    639  1.1    jruoho          * For each extended field, check for length mismatch between the
    640  1.1    jruoho          * legacy length field and the corresponding 64-bit X length field.
    641  1.4  christos          * Note: If the legacy length field is > 0xFF bits, ignore this
    642  1.4  christos          * check. (GPE registers can be larger than the 64-bit GAS structure
    643  1.4  christos          * can accomodate, 0xFF bits).
    644  1.1    jruoho          */
    645  1.1    jruoho         if (Address64->Address &&
    646  1.4  christos            (ACPI_MUL_8 (Length) <= ACPI_UINT8_MAX) &&
    647  1.1    jruoho            (Address64->BitWidth != ACPI_MUL_8 (Length)))
    648  1.1    jruoho         {
    649  1.4  christos             ACPI_BIOS_WARNING ((AE_INFO,
    650  1.4  christos                 "32/64X length mismatch in FADT/%s: %u/%u",
    651  1.1    jruoho                 Name, ACPI_MUL_8 (Length), Address64->BitWidth));
    652  1.1    jruoho         }
    653  1.1    jruoho 
    654  1.5  christos         if (FadtInfoTable[i].Flags & ACPI_FADT_REQUIRED)
    655  1.1    jruoho         {
    656  1.1    jruoho             /*
    657  1.4  christos              * Field is required (PM1aEvent, PM1aControl).
    658  1.1    jruoho              * Both the address and length must be non-zero.
    659  1.1    jruoho              */
    660  1.1    jruoho             if (!Address64->Address || !Length)
    661  1.1    jruoho             {
    662  1.4  christos                 ACPI_BIOS_ERROR ((AE_INFO,
    663  1.4  christos                     "Required FADT field %s has zero address and/or length: "
    664  1.4  christos                     "0x%8.8X%8.8X/0x%X",
    665  1.1    jruoho                     Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
    666  1.1    jruoho             }
    667  1.1    jruoho         }
    668  1.5  christos         else if (FadtInfoTable[i].Flags & ACPI_FADT_SEPARATE_LENGTH)
    669  1.1    jruoho         {
    670  1.1    jruoho             /*
    671  1.1    jruoho              * Field is optional (PM2Control, GPE0, GPE1) AND has its own
    672  1.1    jruoho              * length field. If present, both the address and length must
    673  1.1    jruoho              * be valid.
    674  1.1    jruoho              */
    675  1.1    jruoho             if ((Address64->Address && !Length) ||
    676  1.1    jruoho                 (!Address64->Address && Length))
    677  1.1    jruoho             {
    678  1.4  christos                 ACPI_BIOS_WARNING ((AE_INFO,
    679  1.4  christos                     "Optional FADT field %s has zero address or length: "
    680  1.1    jruoho                     "0x%8.8X%8.8X/0x%X",
    681  1.1    jruoho                     Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
    682  1.1    jruoho             }
    683  1.1    jruoho         }
    684  1.1    jruoho     }
    685  1.1    jruoho }
    686  1.1    jruoho 
    687  1.1    jruoho 
    688  1.1    jruoho /*******************************************************************************
    689  1.1    jruoho  *
    690  1.1    jruoho  * FUNCTION:    AcpiTbSetupFadtRegisters
    691  1.1    jruoho  *
    692  1.1    jruoho  * PARAMETERS:  None, uses AcpiGbl_FADT.
    693  1.1    jruoho  *
    694  1.1    jruoho  * RETURN:      None
    695  1.1    jruoho  *
    696  1.1    jruoho  * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
    697  1.1    jruoho  *              force FADT register definitions to their default lengths.
    698  1.1    jruoho  *
    699  1.1    jruoho  ******************************************************************************/
    700  1.1    jruoho 
    701  1.1    jruoho static void
    702  1.1    jruoho AcpiTbSetupFadtRegisters (
    703  1.1    jruoho     void)
    704  1.1    jruoho {
    705  1.1    jruoho     ACPI_GENERIC_ADDRESS    *Target64;
    706  1.1    jruoho     ACPI_GENERIC_ADDRESS    *Source64;
    707  1.1    jruoho     UINT8                   Pm1RegisterByteWidth;
    708  1.1    jruoho     UINT32                  i;
    709  1.1    jruoho 
    710  1.1    jruoho 
    711  1.1    jruoho     /*
    712  1.1    jruoho      * Optionally check all register lengths against the default values and
    713  1.1    jruoho      * update them if they are incorrect.
    714  1.1    jruoho      */
    715  1.1    jruoho     if (AcpiGbl_UseDefaultRegisterWidths)
    716  1.1    jruoho     {
    717  1.1    jruoho         for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
    718  1.1    jruoho         {
    719  1.1    jruoho             Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
    720  1.1    jruoho                 FadtInfoTable[i].Address64);
    721  1.1    jruoho 
    722  1.1    jruoho             /*
    723  1.1    jruoho              * If a valid register (Address != 0) and the (DefaultLength > 0)
    724  1.1    jruoho              * (Not a GPE register), then check the width against the default.
    725  1.1    jruoho              */
    726  1.1    jruoho             if ((Target64->Address) &&
    727  1.1    jruoho                 (FadtInfoTable[i].DefaultLength > 0) &&
    728  1.1    jruoho                 (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
    729  1.1    jruoho             {
    730  1.4  christos                 ACPI_BIOS_WARNING ((AE_INFO,
    731  1.4  christos                     "Invalid length for FADT/%s: %u, using default %u",
    732  1.1    jruoho                     FadtInfoTable[i].Name, Target64->BitWidth,
    733  1.1    jruoho                     FadtInfoTable[i].DefaultLength));
    734  1.1    jruoho 
    735  1.1    jruoho                 /* Incorrect size, set width to the default */
    736  1.1    jruoho 
    737  1.1    jruoho                 Target64->BitWidth = FadtInfoTable[i].DefaultLength;
    738  1.1    jruoho             }
    739  1.1    jruoho         }
    740  1.1    jruoho     }
    741  1.1    jruoho 
    742  1.1    jruoho     /*
    743  1.1    jruoho      * Get the length of the individual PM1 registers (enable and status).
    744  1.1    jruoho      * Each register is defined to be (event block length / 2). Extra divide
    745  1.1    jruoho      * by 8 converts bits to bytes.
    746  1.1    jruoho      */
    747  1.1    jruoho     Pm1RegisterByteWidth = (UINT8)
    748  1.1    jruoho         ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
    749  1.1    jruoho 
    750  1.1    jruoho     /*
    751  1.1    jruoho      * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
    752  1.1    jruoho      * registers. These addresses do not appear (directly) in the FADT, so it
    753  1.1    jruoho      * is useful to pre-calculate them from the PM1 Event Block definitions.
    754  1.1    jruoho      *
    755  1.1    jruoho      * The PM event blocks are split into two register blocks, first is the
    756  1.1    jruoho      * PM Status Register block, followed immediately by the PM Enable
    757  1.1    jruoho      * Register block. Each is of length (Pm1EventLength/2)
    758  1.1    jruoho      *
    759  1.1    jruoho      * Note: The PM1A event block is required by the ACPI specification.
    760  1.1    jruoho      * However, the PM1B event block is optional and is rarely, if ever,
    761  1.1    jruoho      * used.
    762  1.1    jruoho      */
    763  1.1    jruoho 
    764  1.1    jruoho     for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
    765  1.1    jruoho     {
    766  1.1    jruoho         Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
    767  1.1    jruoho             FadtPmInfoTable[i].Source);
    768  1.1    jruoho 
    769  1.1    jruoho         if (Source64->Address)
    770  1.1    jruoho         {
    771  1.1    jruoho             AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
    772  1.1    jruoho                 Source64->SpaceId, Pm1RegisterByteWidth,
    773  1.1    jruoho                 Source64->Address +
    774  1.4  christos                     (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth),
    775  1.5  christos                 __UNCONST("PmRegisters"), 0);
    776  1.1    jruoho         }
    777  1.1    jruoho     }
    778  1.1    jruoho }
    779