Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: tbfadt   - FADT table utilities
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "actables.h"
0013 
0014 #define _COMPONENT          ACPI_TABLES
0015 ACPI_MODULE_NAME("tbfadt")
0016 
0017 /* Local prototypes */
0018 static void
0019 acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
0020                  u8 space_id,
0021                  u8 byte_width,
0022                  u64 address, const char *register_name, u8 flags);
0023 
0024 static void acpi_tb_convert_fadt(void);
0025 
0026 static void acpi_tb_setup_fadt_registers(void);
0027 
0028 static u64
0029 acpi_tb_select_address(char *register_name, u32 address32, u64 address64);
0030 
0031 /* Table for conversion of FADT to common internal format and FADT validation */
0032 
0033 typedef struct acpi_fadt_info {
0034     const char *name;
0035     u16 address64;
0036     u16 address32;
0037     u16 length;
0038     u8 default_length;
0039     u8 flags;
0040 
0041 } acpi_fadt_info;
0042 
0043 #define ACPI_FADT_OPTIONAL          0
0044 #define ACPI_FADT_REQUIRED          1
0045 #define ACPI_FADT_SEPARATE_LENGTH   2
0046 #define ACPI_FADT_GPE_REGISTER      4
0047 
0048 static struct acpi_fadt_info fadt_info_table[] = {
0049     {"Pm1aEventBlock",
0050      ACPI_FADT_OFFSET(xpm1a_event_block),
0051      ACPI_FADT_OFFSET(pm1a_event_block),
0052      ACPI_FADT_OFFSET(pm1_event_length),
0053      ACPI_PM1_REGISTER_WIDTH * 2,   /* Enable + Status register */
0054      ACPI_FADT_REQUIRED},
0055 
0056     {"Pm1bEventBlock",
0057      ACPI_FADT_OFFSET(xpm1b_event_block),
0058      ACPI_FADT_OFFSET(pm1b_event_block),
0059      ACPI_FADT_OFFSET(pm1_event_length),
0060      ACPI_PM1_REGISTER_WIDTH * 2,   /* Enable + Status register */
0061      ACPI_FADT_OPTIONAL},
0062 
0063     {"Pm1aControlBlock",
0064      ACPI_FADT_OFFSET(xpm1a_control_block),
0065      ACPI_FADT_OFFSET(pm1a_control_block),
0066      ACPI_FADT_OFFSET(pm1_control_length),
0067      ACPI_PM1_REGISTER_WIDTH,
0068      ACPI_FADT_REQUIRED},
0069 
0070     {"Pm1bControlBlock",
0071      ACPI_FADT_OFFSET(xpm1b_control_block),
0072      ACPI_FADT_OFFSET(pm1b_control_block),
0073      ACPI_FADT_OFFSET(pm1_control_length),
0074      ACPI_PM1_REGISTER_WIDTH,
0075      ACPI_FADT_OPTIONAL},
0076 
0077     {"Pm2ControlBlock",
0078      ACPI_FADT_OFFSET(xpm2_control_block),
0079      ACPI_FADT_OFFSET(pm2_control_block),
0080      ACPI_FADT_OFFSET(pm2_control_length),
0081      ACPI_PM2_REGISTER_WIDTH,
0082      ACPI_FADT_SEPARATE_LENGTH},
0083 
0084     {"PmTimerBlock",
0085      ACPI_FADT_OFFSET(xpm_timer_block),
0086      ACPI_FADT_OFFSET(pm_timer_block),
0087      ACPI_FADT_OFFSET(pm_timer_length),
0088      ACPI_PM_TIMER_WIDTH,
0089      ACPI_FADT_SEPARATE_LENGTH},    /* ACPI 5.0A: Timer is optional */
0090 
0091     {"Gpe0Block",
0092      ACPI_FADT_OFFSET(xgpe0_block),
0093      ACPI_FADT_OFFSET(gpe0_block),
0094      ACPI_FADT_OFFSET(gpe0_block_length),
0095      0,
0096      ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER},
0097 
0098     {"Gpe1Block",
0099      ACPI_FADT_OFFSET(xgpe1_block),
0100      ACPI_FADT_OFFSET(gpe1_block),
0101      ACPI_FADT_OFFSET(gpe1_block_length),
0102      0,
0103      ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER}
0104 };
0105 
0106 #define ACPI_FADT_INFO_ENTRIES \
0107             (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
0108 
0109 /* Table used to split Event Blocks into separate status/enable registers */
0110 
0111 typedef struct acpi_fadt_pm_info {
0112     struct acpi_generic_address *target;
0113     u16 source;
0114     u8 register_num;
0115 
0116 } acpi_fadt_pm_info;
0117 
0118 static struct acpi_fadt_pm_info fadt_pm_info_table[] = {
0119     {&acpi_gbl_xpm1a_status,
0120      ACPI_FADT_OFFSET(xpm1a_event_block),
0121      0},
0122 
0123     {&acpi_gbl_xpm1a_enable,
0124      ACPI_FADT_OFFSET(xpm1a_event_block),
0125      1},
0126 
0127     {&acpi_gbl_xpm1b_status,
0128      ACPI_FADT_OFFSET(xpm1b_event_block),
0129      0},
0130 
0131     {&acpi_gbl_xpm1b_enable,
0132      ACPI_FADT_OFFSET(xpm1b_event_block),
0133      1}
0134 };
0135 
0136 #define ACPI_FADT_PM_INFO_ENTRIES \
0137             (sizeof (fadt_pm_info_table) / sizeof (struct acpi_fadt_pm_info))
0138 
0139 /*******************************************************************************
0140  *
0141  * FUNCTION:    acpi_tb_init_generic_address
0142  *
0143  * PARAMETERS:  generic_address     - GAS struct to be initialized
0144  *              space_id            - ACPI Space ID for this register
0145  *              byte_width          - Width of this register
0146  *              address             - Address of the register
0147  *              register_name       - ASCII name of the ACPI register
0148  *
0149  * RETURN:      None
0150  *
0151  * DESCRIPTION: Initialize a Generic Address Structure (GAS)
0152  *              See the ACPI specification for a full description and
0153  *              definition of this structure.
0154  *
0155  ******************************************************************************/
0156 
0157 static void
0158 acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
0159                  u8 space_id,
0160                  u8 byte_width,
0161                  u64 address, const char *register_name, u8 flags)
0162 {
0163     u8 bit_width;
0164 
0165     /*
0166      * Bit width field in the GAS is only one byte long, 255 max.
0167      * Check for bit_width overflow in GAS.
0168      */
0169     bit_width = (u8)(byte_width * 8);
0170     if (byte_width > 31) {  /* (31*8)=248, (32*8)=256 */
0171         /*
0172          * No error for GPE blocks, because we do not use the bit_width
0173          * for GPEs, the legacy length (byte_width) is used instead to
0174          * allow for a large number of GPEs.
0175          */
0176         if (!(flags & ACPI_FADT_GPE_REGISTER)) {
0177             ACPI_ERROR((AE_INFO,
0178                     "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
0179                     "to convert to GAS struct - 255 bits max, truncating",
0180                     register_name, byte_width,
0181                     (byte_width * 8)));
0182         }
0183 
0184         bit_width = 255;
0185     }
0186 
0187     /*
0188      * The 64-bit Address field is non-aligned in the byte packed
0189      * GAS struct.
0190      */
0191     ACPI_MOVE_64_TO_64(&generic_address->address, &address);
0192 
0193     /* All other fields are byte-wide */
0194 
0195     generic_address->space_id = space_id;
0196     generic_address->bit_width = bit_width;
0197     generic_address->bit_offset = 0;
0198     generic_address->access_width = 0;  /* Access width ANY */
0199 }
0200 
0201 /*******************************************************************************
0202  *
0203  * FUNCTION:    acpi_tb_select_address
0204  *
0205  * PARAMETERS:  register_name       - ASCII name of the ACPI register
0206  *              address32           - 32-bit address of the register
0207  *              address64           - 64-bit address of the register
0208  *
0209  * RETURN:      The resolved 64-bit address
0210  *
0211  * DESCRIPTION: Select between 32-bit and 64-bit versions of addresses within
0212  *              the FADT. Used for the FACS and DSDT addresses.
0213  *
0214  * NOTES:
0215  *
0216  * Check for FACS and DSDT address mismatches. An address mismatch between
0217  * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
0218  * DSDT/X_DSDT) could be a corrupted address field or it might indicate
0219  * the presence of two FACS or two DSDT tables.
0220  *
0221  * November 2013:
0222  * By default, as per the ACPICA specification, a valid 64-bit address is
0223  * used regardless of the value of the 32-bit address. However, this
0224  * behavior can be overridden via the acpi_gbl_use32_bit_fadt_addresses flag.
0225  *
0226  ******************************************************************************/
0227 
0228 static u64
0229 acpi_tb_select_address(char *register_name, u32 address32, u64 address64)
0230 {
0231 
0232     if (!address64) {
0233 
0234         /* 64-bit address is zero, use 32-bit address */
0235 
0236         return ((u64)address32);
0237     }
0238 
0239     if (address32 && (address64 != (u64)address32)) {
0240 
0241         /* Address mismatch between 32-bit and 64-bit versions */
0242 
0243         ACPI_BIOS_WARNING((AE_INFO,
0244                    "32/64X %s address mismatch in FADT: "
0245                    "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
0246                    register_name, address32,
0247                    ACPI_FORMAT_UINT64(address64),
0248                    acpi_gbl_use32_bit_fadt_addresses ? 32 :
0249                    64));
0250 
0251         /* 32-bit address override */
0252 
0253         if (acpi_gbl_use32_bit_fadt_addresses) {
0254             return ((u64)address32);
0255         }
0256     }
0257 
0258     /* Default is to use the 64-bit address */
0259 
0260     return (address64);
0261 }
0262 
0263 /*******************************************************************************
0264  *
0265  * FUNCTION:    acpi_tb_parse_fadt
0266  *
0267  * PARAMETERS:  None
0268  *
0269  * RETURN:      None
0270  *
0271  * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
0272  *              (FADT contains the addresses of the DSDT and FACS)
0273  *
0274  ******************************************************************************/
0275 
0276 void acpi_tb_parse_fadt(void)
0277 {
0278     u32 length;
0279     struct acpi_table_header *table;
0280     struct acpi_table_desc *fadt_desc;
0281     acpi_status status;
0282 
0283     /*
0284      * The FADT has multiple versions with different lengths,
0285      * and it contains pointers to both the DSDT and FACS tables.
0286      *
0287      * Get a local copy of the FADT and convert it to a common format
0288      * Map entire FADT, assumed to be smaller than one page.
0289      */
0290     fadt_desc = &acpi_gbl_root_table_list.tables[acpi_gbl_fadt_index];
0291     status = acpi_tb_get_table(fadt_desc, &table);
0292     if (ACPI_FAILURE(status)) {
0293         return;
0294     }
0295     length = fadt_desc->length;
0296 
0297     /*
0298      * Validate the FADT checksum before we copy the table. Ignore
0299      * checksum error as we want to try to get the DSDT and FACS.
0300      */
0301     (void)acpi_tb_verify_checksum(table, length);
0302 
0303     /* Create a local copy of the FADT in common ACPI 2.0+ format */
0304 
0305     acpi_tb_create_local_fadt(table, length);
0306 
0307     /* All done with the real FADT, unmap it */
0308 
0309     acpi_tb_put_table(fadt_desc);
0310 
0311     /* Obtain the DSDT and FACS tables via their addresses within the FADT */
0312 
0313     acpi_tb_install_standard_table((acpi_physical_address)acpi_gbl_FADT.
0314                        Xdsdt,
0315                        ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
0316                        NULL, FALSE, TRUE, &acpi_gbl_dsdt_index);
0317 
0318     /* If Hardware Reduced flag is set, there is no FACS */
0319 
0320     if (!acpi_gbl_reduced_hardware) {
0321         if (acpi_gbl_FADT.facs) {
0322             acpi_tb_install_standard_table((acpi_physical_address)
0323                                acpi_gbl_FADT.facs,
0324                                ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
0325                                NULL, FALSE, TRUE,
0326                                &acpi_gbl_facs_index);
0327         }
0328         if (acpi_gbl_FADT.Xfacs) {
0329             acpi_tb_install_standard_table((acpi_physical_address)
0330                                acpi_gbl_FADT.Xfacs,
0331                                ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
0332                                NULL, FALSE, TRUE,
0333                                &acpi_gbl_xfacs_index);
0334         }
0335     }
0336 }
0337 
0338 /*******************************************************************************
0339  *
0340  * FUNCTION:    acpi_tb_create_local_fadt
0341  *
0342  * PARAMETERS:  table               - Pointer to BIOS FADT
0343  *              length              - Length of the table
0344  *
0345  * RETURN:      None
0346  *
0347  * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
0348  *              Performs validation on some important FADT fields.
0349  *
0350  * NOTE:        We create a local copy of the FADT regardless of the version.
0351  *
0352  ******************************************************************************/
0353 
0354 void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
0355 {
0356     /*
0357      * Check if the FADT is larger than the largest table that we expect
0358      * (typically the current ACPI specification version). If so, truncate
0359      * the table, and issue a warning.
0360      */
0361     if (length > sizeof(struct acpi_table_fadt)) {
0362         ACPI_BIOS_WARNING((AE_INFO,
0363                    "FADT (revision %u) is longer than %s length, "
0364                    "truncating length %u to %u",
0365                    table->revision, ACPI_FADT_CONFORMANCE,
0366                    length,
0367                    (u32)sizeof(struct acpi_table_fadt)));
0368     }
0369 
0370     /* Clear the entire local FADT */
0371 
0372     memset(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
0373 
0374     /* Copy the original FADT, up to sizeof (struct acpi_table_fadt) */
0375 
0376     memcpy(&acpi_gbl_FADT, table,
0377            ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
0378 
0379     /* Take a copy of the Hardware Reduced flag */
0380 
0381     acpi_gbl_reduced_hardware = FALSE;
0382     if (acpi_gbl_FADT.flags & ACPI_FADT_HW_REDUCED) {
0383         acpi_gbl_reduced_hardware = TRUE;
0384     }
0385 
0386     /* Convert the local copy of the FADT to the common internal format */
0387 
0388     acpi_tb_convert_fadt();
0389 
0390     /* Initialize the global ACPI register structures */
0391 
0392     acpi_tb_setup_fadt_registers();
0393 }
0394 
0395 /*******************************************************************************
0396  *
0397  * FUNCTION:    acpi_tb_convert_fadt
0398  *
0399  * PARAMETERS:  none - acpi_gbl_FADT is used.
0400  *
0401  * RETURN:      None
0402  *
0403  * DESCRIPTION: Converts all versions of the FADT to a common internal format.
0404  *              Expand 32-bit addresses to 64-bit as necessary. Also validate
0405  *              important fields within the FADT.
0406  *
0407  * NOTE:        acpi_gbl_FADT must be of size (struct acpi_table_fadt), and must
0408  *              contain a copy of the actual BIOS-provided FADT.
0409  *
0410  * Notes on 64-bit register addresses:
0411  *
0412  * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
0413  * fields of the FADT for all ACPI register addresses.
0414  *
0415  * The 64-bit X fields are optional extensions to the original 32-bit FADT
0416  * V1.0 fields. Even if they are present in the FADT, they are optional and
0417  * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
0418  * 32-bit V1.0 fields to the 64-bit X fields if the 64-bit X field is originally
0419  * zero.
0420  *
0421  * For ACPI 1.0 FADTs (that contain no 64-bit addresses), all 32-bit address
0422  * fields are expanded to the corresponding 64-bit X fields in the internal
0423  * common FADT.
0424  *
0425  * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
0426  * to the corresponding 64-bit X fields, if the 64-bit field is originally
0427  * zero. Adhering to the ACPI specification, we completely ignore the 32-bit
0428  * field if the 64-bit field is valid, regardless of whether the host OS is
0429  * 32-bit or 64-bit.
0430  *
0431  * Possible additional checks:
0432  *  (acpi_gbl_FADT.pm1_event_length >= 4)
0433  *  (acpi_gbl_FADT.pm1_control_length >= 2)
0434  *  (acpi_gbl_FADT.pm_timer_length >= 4)
0435  *  Gpe block lengths must be multiple of 2
0436  *
0437  ******************************************************************************/
0438 
0439 static void acpi_tb_convert_fadt(void)
0440 {
0441     const char *name;
0442     struct acpi_generic_address *address64;
0443     u32 address32;
0444     u8 length;
0445     u8 flags;
0446     u32 i;
0447 
0448     /*
0449      * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
0450      * should be zero are indeed zero. This will workaround BIOSs that
0451      * inadvertently place values in these fields.
0452      *
0453      * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
0454      * at offset 45, 55, 95, and the word located at offset 109, 110.
0455      *
0456      * Note: The FADT revision value is unreliable. Only the length can be
0457      * trusted.
0458      */
0459     if (acpi_gbl_FADT.header.length <= ACPI_FADT_V2_SIZE) {
0460         acpi_gbl_FADT.preferred_profile = 0;
0461         acpi_gbl_FADT.pstate_control = 0;
0462         acpi_gbl_FADT.cst_control = 0;
0463         acpi_gbl_FADT.boot_flags = 0;
0464     }
0465 
0466     /*
0467      * Now we can update the local FADT length to the length of the
0468      * current FADT version as defined by the ACPI specification.
0469      * Thus, we will have a common FADT internally.
0470      */
0471     acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
0472 
0473     /*
0474      * Expand the 32-bit DSDT addresses to 64-bit as necessary.
0475      * Later ACPICA code will always use the X 64-bit field.
0476      */
0477     acpi_gbl_FADT.Xdsdt = acpi_tb_select_address("DSDT",
0478                              acpi_gbl_FADT.dsdt,
0479                              acpi_gbl_FADT.Xdsdt);
0480 
0481     /* If Hardware Reduced flag is set, we are all done */
0482 
0483     if (acpi_gbl_reduced_hardware) {
0484         return;
0485     }
0486 
0487     /* Examine all of the 64-bit extended address fields (X fields) */
0488 
0489     for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
0490         /*
0491          * Get the 32-bit and 64-bit addresses, as well as the register
0492          * length and register name.
0493          */
0494         address32 = *ACPI_ADD_PTR(u32,
0495                       &acpi_gbl_FADT,
0496                       fadt_info_table[i].address32);
0497 
0498         address64 = ACPI_ADD_PTR(struct acpi_generic_address,
0499                      &acpi_gbl_FADT,
0500                      fadt_info_table[i].address64);
0501 
0502         length = *ACPI_ADD_PTR(u8,
0503                        &acpi_gbl_FADT,
0504                        fadt_info_table[i].length);
0505 
0506         name = fadt_info_table[i].name;
0507         flags = fadt_info_table[i].flags;
0508 
0509         /*
0510          * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
0511          * generic address structures as necessary. Later code will always use
0512          * the 64-bit address structures.
0513          *
0514          * November 2013:
0515          * Now always use the 64-bit address if it is valid (non-zero), in
0516          * accordance with the ACPI specification which states that a 64-bit
0517          * address supersedes the 32-bit version. This behavior can be
0518          * overridden by the acpi_gbl_use32_bit_fadt_addresses flag.
0519          *
0520          * During 64-bit address construction and verification,
0521          * these cases are handled:
0522          *
0523          * Address32 zero, Address64 [don't care]   - Use Address64
0524          *
0525          * No override: if acpi_gbl_use32_bit_fadt_addresses is FALSE, and:
0526          * Address32 non-zero, Address64 zero       - Copy/use Address32
0527          * Address32 non-zero == Address64 non-zero - Use Address64
0528          * Address32 non-zero != Address64 non-zero - Warning, use Address64
0529          *
0530          * Override: if acpi_gbl_use32_bit_fadt_addresses is TRUE, and:
0531          * Address32 non-zero, Address64 zero       - Copy/use Address32
0532          * Address32 non-zero == Address64 non-zero - Copy/use Address32
0533          * Address32 non-zero != Address64 non-zero - Warning, copy/use Address32
0534          *
0535          * Note: space_id is always I/O for 32-bit legacy address fields
0536          */
0537         if (address32) {
0538             if (address64->address) {
0539                 if (address64->address != (u64)address32) {
0540 
0541                     /* Address mismatch */
0542 
0543                     ACPI_BIOS_WARNING((AE_INFO,
0544                                "32/64X address mismatch in FADT/%s: "
0545                                "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
0546                                name, address32,
0547                                ACPI_FORMAT_UINT64
0548                                (address64->address),
0549                                acpi_gbl_use32_bit_fadt_addresses
0550                                ? 32 : 64));
0551                 }
0552 
0553                 /*
0554                  * For each extended field, check for length mismatch
0555                  * between the legacy length field and the corresponding
0556                  * 64-bit X length field.
0557                  * Note: If the legacy length field is > 0xFF bits, ignore
0558                  * this check. (GPE registers can be larger than the
0559                  * 64-bit GAS structure can accommodate, 0xFF bits).
0560                  */
0561                 if ((ACPI_MUL_8(length) <= ACPI_UINT8_MAX) &&
0562                     (address64->bit_width !=
0563                      ACPI_MUL_8(length))) {
0564                     ACPI_BIOS_WARNING((AE_INFO,
0565                                "32/64X length mismatch in FADT/%s: %u/%u",
0566                                name,
0567                                ACPI_MUL_8(length),
0568                                address64->
0569                                bit_width));
0570                 }
0571             }
0572 
0573             /*
0574              * Hardware register access code always uses the 64-bit fields.
0575              * So if the 64-bit field is zero or is to be overridden,
0576              * initialize it with the 32-bit fields.
0577              * Note that when the 32-bit address favor is specified, the
0578              * 64-bit fields are always re-initialized so that
0579              * access_size/bit_width/bit_offset fields can be correctly
0580              * configured to the values to trigger a 32-bit compatible
0581              * access mode in the hardware register access code.
0582              */
0583             if (!address64->address
0584                 || acpi_gbl_use32_bit_fadt_addresses) {
0585                 acpi_tb_init_generic_address(address64,
0586                                  ACPI_ADR_SPACE_SYSTEM_IO,
0587                                  length,
0588                                  (u64)address32,
0589                                  name, flags);
0590             }
0591         }
0592 
0593         if (fadt_info_table[i].flags & ACPI_FADT_REQUIRED) {
0594             /*
0595              * Field is required (Pm1a_event, Pm1a_control).
0596              * Both the address and length must be non-zero.
0597              */
0598             if (!address64->address || !length) {
0599                 ACPI_BIOS_ERROR((AE_INFO,
0600                          "Required FADT field %s has zero address and/or length: "
0601                          "0x%8.8X%8.8X/0x%X",
0602                          name,
0603                          ACPI_FORMAT_UINT64(address64->
0604                                     address),
0605                          length));
0606             }
0607         } else if (fadt_info_table[i].flags & ACPI_FADT_SEPARATE_LENGTH) {
0608             /*
0609              * Field is optional (Pm2_control, GPE0, GPE1) AND has its own
0610              * length field. If present, both the address and length must
0611              * be valid.
0612              */
0613             if ((address64->address && !length) ||
0614                 (!address64->address && length)) {
0615                 ACPI_BIOS_WARNING((AE_INFO,
0616                            "Optional FADT field %s has valid %s but zero %s: "
0617                            "0x%8.8X%8.8X/0x%X", name,
0618                            (length ? "Length" :
0619                             "Address"),
0620                            (length ? "Address" :
0621                             "Length"),
0622                            ACPI_FORMAT_UINT64
0623                            (address64->address),
0624                            length));
0625             }
0626         }
0627     }
0628 }
0629 
0630 /*******************************************************************************
0631  *
0632  * FUNCTION:    acpi_tb_setup_fadt_registers
0633  *
0634  * PARAMETERS:  None, uses acpi_gbl_FADT.
0635  *
0636  * RETURN:      None
0637  *
0638  * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
0639  *              force FADT register definitions to their default lengths.
0640  *
0641  ******************************************************************************/
0642 
0643 static void acpi_tb_setup_fadt_registers(void)
0644 {
0645     struct acpi_generic_address *target64;
0646     struct acpi_generic_address *source64;
0647     u8 pm1_register_byte_width;
0648     u32 i;
0649 
0650     /*
0651      * Optionally check all register lengths against the default values and
0652      * update them if they are incorrect.
0653      */
0654     if (acpi_gbl_use_default_register_widths) {
0655         for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
0656             target64 =
0657                 ACPI_ADD_PTR(struct acpi_generic_address,
0658                      &acpi_gbl_FADT,
0659                      fadt_info_table[i].address64);
0660 
0661             /*
0662              * If a valid register (Address != 0) and the (default_length > 0)
0663              * (Not a GPE register), then check the width against the default.
0664              */
0665             if ((target64->address) &&
0666                 (fadt_info_table[i].default_length > 0) &&
0667                 (fadt_info_table[i].default_length !=
0668                  target64->bit_width)) {
0669                 ACPI_BIOS_WARNING((AE_INFO,
0670                            "Invalid length for FADT/%s: %u, using default %u",
0671                            fadt_info_table[i].name,
0672                            target64->bit_width,
0673                            fadt_info_table[i].
0674                            default_length));
0675 
0676                 /* Incorrect size, set width to the default */
0677 
0678                 target64->bit_width =
0679                     fadt_info_table[i].default_length;
0680             }
0681         }
0682     }
0683 
0684     /*
0685      * Get the length of the individual PM1 registers (enable and status).
0686      * Each register is defined to be (event block length / 2). Extra divide
0687      * by 8 converts bits to bytes.
0688      */
0689     pm1_register_byte_width = (u8)
0690         ACPI_DIV_16(acpi_gbl_FADT.xpm1a_event_block.bit_width);
0691 
0692     /*
0693      * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
0694      * registers. These addresses do not appear (directly) in the FADT, so it
0695      * is useful to pre-calculate them from the PM1 Event Block definitions.
0696      *
0697      * The PM event blocks are split into two register blocks, first is the
0698      * PM Status Register block, followed immediately by the PM Enable
0699      * Register block. Each is of length (pm1_event_length/2)
0700      *
0701      * Note: The PM1A event block is required by the ACPI specification.
0702      * However, the PM1B event block is optional and is rarely, if ever,
0703      * used.
0704      */
0705 
0706     for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++) {
0707         source64 =
0708             ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
0709                  fadt_pm_info_table[i].source);
0710 
0711         if (source64->address) {
0712             acpi_tb_init_generic_address(fadt_pm_info_table[i].
0713                              target, source64->space_id,
0714                              pm1_register_byte_width,
0715                              source64->address +
0716                              (fadt_pm_info_table[i].
0717                               register_num *
0718                               pm1_register_byte_width),
0719                              "PmRegisters", 0);
0720         }
0721     }
0722 }