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