1 /******************************************************************************
3 * Module Name: tbfadt - FADT table utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
48 #define _COMPONENT ACPI_TABLES
49 ACPI_MODULE_NAME ("tbfadt")
51 /* Local prototypes */
54 AcpiTbInitGenericAddress (
55 ACPI_GENERIC_ADDRESS *GenericAddress,
67 AcpiTbSetupFadtRegisters (
77 /* Table for conversion of FADT to common internal format and FADT validation */
79 typedef struct acpi_fadt_info
90 #define ACPI_FADT_OPTIONAL 0
91 #define ACPI_FADT_REQUIRED 1
92 #define ACPI_FADT_SEPARATE_LENGTH 2
93 #define ACPI_FADT_GPE_REGISTER 4
95 static ACPI_FADT_INFO FadtInfoTable[] =
98 ACPI_FADT_OFFSET (XPm1aEventBlock),
99 ACPI_FADT_OFFSET (Pm1aEventBlock),
100 ACPI_FADT_OFFSET (Pm1EventLength),
101 ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
105 ACPI_FADT_OFFSET (XPm1bEventBlock),
106 ACPI_FADT_OFFSET (Pm1bEventBlock),
107 ACPI_FADT_OFFSET (Pm1EventLength),
108 ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
112 ACPI_FADT_OFFSET (XPm1aControlBlock),
113 ACPI_FADT_OFFSET (Pm1aControlBlock),
114 ACPI_FADT_OFFSET (Pm1ControlLength),
115 ACPI_PM1_REGISTER_WIDTH,
119 ACPI_FADT_OFFSET (XPm1bControlBlock),
120 ACPI_FADT_OFFSET (Pm1bControlBlock),
121 ACPI_FADT_OFFSET (Pm1ControlLength),
122 ACPI_PM1_REGISTER_WIDTH,
126 ACPI_FADT_OFFSET (XPm2ControlBlock),
127 ACPI_FADT_OFFSET (Pm2ControlBlock),
128 ACPI_FADT_OFFSET (Pm2ControlLength),
129 ACPI_PM2_REGISTER_WIDTH,
130 ACPI_FADT_SEPARATE_LENGTH},
133 ACPI_FADT_OFFSET (XPmTimerBlock),
134 ACPI_FADT_OFFSET (PmTimerBlock),
135 ACPI_FADT_OFFSET (PmTimerLength),
137 ACPI_FADT_SEPARATE_LENGTH}, /* ACPI 5.0A: Timer is optional */
140 ACPI_FADT_OFFSET (XGpe0Block),
141 ACPI_FADT_OFFSET (Gpe0Block),
142 ACPI_FADT_OFFSET (Gpe0BlockLength),
144 ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER},
147 ACPI_FADT_OFFSET (XGpe1Block),
148 ACPI_FADT_OFFSET (Gpe1Block),
149 ACPI_FADT_OFFSET (Gpe1BlockLength),
151 ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER}
154 #define ACPI_FADT_INFO_ENTRIES \
155 (sizeof (FadtInfoTable) / sizeof (ACPI_FADT_INFO))
158 /* Table used to split Event Blocks into separate status/enable registers */
160 typedef struct acpi_fadt_pm_info
162 ACPI_GENERIC_ADDRESS *Target;
168 static ACPI_FADT_PM_INFO FadtPmInfoTable[] =
170 {&AcpiGbl_XPm1aStatus,
171 ACPI_FADT_OFFSET (XPm1aEventBlock),
174 {&AcpiGbl_XPm1aEnable,
175 ACPI_FADT_OFFSET (XPm1aEventBlock),
178 {&AcpiGbl_XPm1bStatus,
179 ACPI_FADT_OFFSET (XPm1bEventBlock),
182 {&AcpiGbl_XPm1bEnable,
183 ACPI_FADT_OFFSET (XPm1bEventBlock),
187 #define ACPI_FADT_PM_INFO_ENTRIES \
188 (sizeof (FadtPmInfoTable) / sizeof (ACPI_FADT_PM_INFO))
191 /*******************************************************************************
193 * FUNCTION: AcpiTbInitGenericAddress
195 * PARAMETERS: GenericAddress - GAS struct to be initialized
196 * SpaceId - ACPI Space ID for this register
197 * ByteWidth - Width of this register
198 * Address - Address of the register
199 * RegisterName - ASCII name of the ACPI register
203 * DESCRIPTION: Initialize a Generic Address Structure (GAS)
204 * See the ACPI specification for a full description and
205 * definition of this structure.
207 ******************************************************************************/
210 AcpiTbInitGenericAddress (
211 ACPI_GENERIC_ADDRESS *GenericAddress,
222 * Bit width field in the GAS is only one byte long, 255 max.
223 * Check for BitWidth overflow in GAS.
225 BitWidth = (UINT8) (ByteWidth * 8);
226 if (ByteWidth > 31) /* (31*8)=248, (32*8)=256 */
229 * No error for GPE blocks, because we do not use the BitWidth
230 * for GPEs, the legacy length (ByteWidth) is used instead to
231 * allow for a large number of GPEs.
233 if (!(Flags & ACPI_FADT_GPE_REGISTER))
235 ACPI_ERROR ((AE_INFO,
236 "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
237 "to convert to GAS struct - 255 bits max, truncating",
238 RegisterName, ByteWidth, (ByteWidth * 8)));
245 * The 64-bit Address field is non-aligned in the byte packed
248 ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
250 /* All other fields are byte-wide */
252 GenericAddress->SpaceId = SpaceId;
253 GenericAddress->BitWidth = BitWidth;
254 GenericAddress->BitOffset = 0;
255 GenericAddress->AccessWidth = 0; /* Access width ANY */
259 /*******************************************************************************
261 * FUNCTION: AcpiTbSelectAddress
263 * PARAMETERS: RegisterName - ASCII name of the ACPI register
264 * Address32 - 32-bit address of the register
265 * Address64 - 64-bit address of the register
267 * RETURN: The resolved 64-bit address
269 * DESCRIPTION: Select between 32-bit and 64-bit versions of addresses within
270 * the FADT. Used for the FACS and DSDT addresses.
274 * Check for FACS and DSDT address mismatches. An address mismatch between
275 * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
276 * DSDT/X_DSDT) could be a corrupted address field or it might indicate
277 * the presence of two FACS or two DSDT tables.
280 * By default, as per the ACPICA specification, a valid 64-bit address is
281 * used regardless of the value of the 32-bit address. However, this
282 * behavior can be overridden via the AcpiGbl_Use32BitFadtAddresses flag.
284 ******************************************************************************/
287 AcpiTbSelectAddress (
295 /* 64-bit address is zero, use 32-bit address */
297 return ((UINT64) Address32);
301 (Address64 != (UINT64) Address32))
303 /* Address mismatch between 32-bit and 64-bit versions */
305 ACPI_BIOS_WARNING ((AE_INFO,
306 "32/64X %s address mismatch in FADT: "
307 "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
308 RegisterName, Address32, ACPI_FORMAT_UINT64 (Address64),
309 AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
311 /* 32-bit address override */
313 if (AcpiGbl_Use32BitFadtAddresses)
315 return ((UINT64) Address32);
319 /* Default is to use the 64-bit address */
325 /*******************************************************************************
327 * FUNCTION: AcpiTbParseFadt
329 * PARAMETERS: TableIndex - Index for the FADT
333 * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
334 * (FADT contains the addresses of the DSDT and FACS)
336 ******************************************************************************/
343 ACPI_TABLE_HEADER *Table;
347 * The FADT has multiple versions with different lengths,
348 * and it contains pointers to both the DSDT and FACS tables.
350 * Get a local copy of the FADT and convert it to a common format
351 * Map entire FADT, assumed to be smaller than one page.
353 Length = AcpiGbl_RootTableList.Tables[TableIndex].Length;
355 Table = AcpiOsMapMemory (
356 AcpiGbl_RootTableList.Tables[TableIndex].Address, Length);
363 * Validate the FADT checksum before we copy the table. Ignore
364 * checksum error as we want to try to get the DSDT and FACS.
366 (void) AcpiTbVerifyChecksum (Table, Length);
368 /* Create a local copy of the FADT in common ACPI 2.0+ format */
370 AcpiTbCreateLocalFadt (Table, Length);
372 /* All done with the real FADT, unmap it */
374 AcpiOsUnmapMemory (Table, Length);
376 /* Obtain the DSDT and FACS tables via their addresses within the FADT */
378 AcpiTbInstallFixedTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
379 ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
381 /* If Hardware Reduced flag is set, there is no FACS */
383 if (!AcpiGbl_ReducedHardware)
385 if (AcpiGbl_FADT.Facs)
387 AcpiTbInstallFixedTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.Facs,
388 ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
390 if (AcpiGbl_FADT.XFacs)
392 AcpiTbInstallFixedTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
393 ACPI_SIG_FACS, ACPI_TABLE_INDEX_X_FACS);
399 /*******************************************************************************
401 * FUNCTION: AcpiTbCreateLocalFadt
403 * PARAMETERS: Table - Pointer to BIOS FADT
404 * Length - Length of the table
408 * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
409 * Performs validation on some important FADT fields.
411 * NOTE: We create a local copy of the FADT regardless of the version.
413 ******************************************************************************/
416 AcpiTbCreateLocalFadt (
417 ACPI_TABLE_HEADER *Table,
422 * Check if the FADT is larger than the largest table that we expect
423 * (the ACPI 5.0 version). If so, truncate the table, and issue
426 if (Length > sizeof (ACPI_TABLE_FADT))
428 ACPI_BIOS_WARNING ((AE_INFO,
429 "FADT (revision %u) is longer than ACPI 5.0 version, "
430 "truncating length %u to %u",
431 Table->Revision, Length, (UINT32) sizeof (ACPI_TABLE_FADT)));
434 /* Clear the entire local FADT */
436 memset (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
438 /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
440 memcpy (&AcpiGbl_FADT, Table,
441 ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
443 /* Take a copy of the Hardware Reduced flag */
445 AcpiGbl_ReducedHardware = FALSE;
446 if (AcpiGbl_FADT.Flags & ACPI_FADT_HW_REDUCED)
448 AcpiGbl_ReducedHardware = TRUE;
451 /* Convert the local copy of the FADT to the common internal format */
453 AcpiTbConvertFadt ();
455 /* Initialize the global ACPI register structures */
457 AcpiTbSetupFadtRegisters ();
461 /*******************************************************************************
463 * FUNCTION: AcpiTbConvertFadt
465 * PARAMETERS: None - AcpiGbl_FADT is used.
469 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
470 * Expand 32-bit addresses to 64-bit as necessary. Also validate
471 * important fields within the FADT.
473 * NOTE: AcpiGbl_FADT must be of size (ACPI_TABLE_FADT), and must
474 * contain a copy of the actual BIOS-provided FADT.
476 * Notes on 64-bit register addresses:
478 * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
479 * fields of the FADT for all ACPI register addresses.
481 * The 64-bit X fields are optional extensions to the original 32-bit FADT
482 * V1.0 fields. Even if they are present in the FADT, they are optional and
483 * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
484 * 32-bit V1.0 fields to the 64-bit X fields if the the 64-bit X field is
487 * For ACPI 1.0 FADTs (that contain no 64-bit addresses), all 32-bit address
488 * fields are expanded to the corresponding 64-bit X fields in the internal
491 * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
492 * to the corresponding 64-bit X fields, if the 64-bit field is originally
493 * zero. Adhering to the ACPI specification, we completely ignore the 32-bit
494 * field if the 64-bit field is valid, regardless of whether the host OS is
497 * Possible additional checks:
498 * (AcpiGbl_FADT.Pm1EventLength >= 4)
499 * (AcpiGbl_FADT.Pm1ControlLength >= 2)
500 * (AcpiGbl_FADT.PmTimerLength >= 4)
501 * Gpe block lengths must be multiple of 2
503 ******************************************************************************/
510 ACPI_GENERIC_ADDRESS *Address64;
518 * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
519 * should be zero are indeed zero. This will workaround BIOSs that
520 * inadvertently place values in these fields.
522 * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
523 * at offset 45, 55, 95, and the word located at offset 109, 110.
525 * Note: The FADT revision value is unreliable. Only the length can be
528 if (AcpiGbl_FADT.Header.Length <= ACPI_FADT_V2_SIZE)
530 AcpiGbl_FADT.PreferredProfile = 0;
531 AcpiGbl_FADT.PstateControl = 0;
532 AcpiGbl_FADT.CstControl = 0;
533 AcpiGbl_FADT.BootFlags = 0;
537 * Now we can update the local FADT length to the length of the
538 * current FADT version as defined by the ACPI specification.
539 * Thus, we will have a common FADT internally.
541 AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
544 * Expand the 32-bit DSDT addresses to 64-bit as necessary.
545 * Later ACPICA code will always use the X 64-bit field.
547 AcpiGbl_FADT.XDsdt = AcpiTbSelectAddress ("DSDT",
548 AcpiGbl_FADT.Dsdt, AcpiGbl_FADT.XDsdt);
550 /* If Hardware Reduced flag is set, we are all done */
552 if (AcpiGbl_ReducedHardware)
557 /* Examine all of the 64-bit extended address fields (X fields) */
559 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
562 * Get the 32-bit and 64-bit addresses, as well as the register
563 * length and register name.
565 Address32 = *ACPI_ADD_PTR (UINT32,
566 &AcpiGbl_FADT, FadtInfoTable[i].Address32);
568 Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
569 &AcpiGbl_FADT, FadtInfoTable[i].Address64);
571 Length = *ACPI_ADD_PTR (UINT8,
572 &AcpiGbl_FADT, FadtInfoTable[i].Length);
574 Name = FadtInfoTable[i].Name;
575 Flags = FadtInfoTable[i].Flags;
578 * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
579 * generic address structures as necessary. Later code will always use
580 * the 64-bit address structures.
583 * Now always use the 64-bit address if it is valid (non-zero), in
584 * accordance with the ACPI specification which states that a 64-bit
585 * address supersedes the 32-bit version. This behavior can be
586 * overridden by the AcpiGbl_Use32BitFadtAddresses flag.
588 * During 64-bit address construction and verification,
589 * these cases are handled:
591 * Address32 zero, Address64 [don't care] - Use Address64
593 * Address32 non-zero, Address64 zero - Copy/use Address32
594 * Address32 non-zero == Address64 non-zero - Use Address64
595 * Address32 non-zero != Address64 non-zero - Warning, use Address64
597 * Override: if AcpiGbl_Use32BitFadtAddresses is TRUE, and:
598 * Address32 non-zero != Address64 non-zero - Warning, copy/use Address32
600 * Note: SpaceId is always I/O for 32-bit legacy address fields
604 if (!Address64->Address)
606 /* 64-bit address is zero, use 32-bit address */
608 AcpiTbInitGenericAddress (Address64,
609 ACPI_ADR_SPACE_SYSTEM_IO,
610 *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT,
611 FadtInfoTable[i].Length),
612 (UINT64) Address32, Name, Flags);
614 else if (Address64->Address != (UINT64) Address32)
616 /* Address mismatch */
618 ACPI_BIOS_WARNING ((AE_INFO,
619 "32/64X address mismatch in FADT/%s: "
620 "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
622 ACPI_FORMAT_UINT64 (Address64->Address),
623 AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
625 if (AcpiGbl_Use32BitFadtAddresses)
627 /* 32-bit address override */
629 AcpiTbInitGenericAddress (Address64,
630 ACPI_ADR_SPACE_SYSTEM_IO,
631 *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT,
632 FadtInfoTable[i].Length),
633 (UINT64) Address32, Name, Flags);
639 * For each extended field, check for length mismatch between the
640 * legacy length field and the corresponding 64-bit X length field.
641 * Note: If the legacy length field is > 0xFF bits, ignore this
642 * check. (GPE registers can be larger than the 64-bit GAS structure
643 * can accomodate, 0xFF bits).
645 if (Address64->Address &&
646 (ACPI_MUL_8 (Length) <= ACPI_UINT8_MAX) &&
647 (Address64->BitWidth != ACPI_MUL_8 (Length)))
649 ACPI_BIOS_WARNING ((AE_INFO,
650 "32/64X length mismatch in FADT/%s: %u/%u",
651 Name, ACPI_MUL_8 (Length), Address64->BitWidth));
654 if (FadtInfoTable[i].Flags & ACPI_FADT_REQUIRED)
657 * Field is required (PM1aEvent, PM1aControl).
658 * Both the address and length must be non-zero.
660 if (!Address64->Address || !Length)
662 ACPI_BIOS_ERROR ((AE_INFO,
663 "Required FADT field %s has zero address and/or length: "
665 Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
668 else if (FadtInfoTable[i].Flags & ACPI_FADT_SEPARATE_LENGTH)
671 * Field is optional (PM2Control, GPE0, GPE1) AND has its own
672 * length field. If present, both the address and length must
675 if ((Address64->Address && !Length) ||
676 (!Address64->Address && Length))
678 ACPI_BIOS_WARNING ((AE_INFO,
679 "Optional FADT field %s has zero address or length: "
681 Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
688 /*******************************************************************************
690 * FUNCTION: AcpiTbSetupFadtRegisters
692 * PARAMETERS: None, uses AcpiGbl_FADT.
696 * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
697 * force FADT register definitions to their default lengths.
699 ******************************************************************************/
702 AcpiTbSetupFadtRegisters (
705 ACPI_GENERIC_ADDRESS *Target64;
706 ACPI_GENERIC_ADDRESS *Source64;
707 UINT8 Pm1RegisterByteWidth;
712 * Optionally check all register lengths against the default values and
713 * update them if they are incorrect.
715 if (AcpiGbl_UseDefaultRegisterWidths)
717 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
719 Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
720 FadtInfoTable[i].Address64);
723 * If a valid register (Address != 0) and the (DefaultLength > 0)
724 * (Not a GPE register), then check the width against the default.
726 if ((Target64->Address) &&
727 (FadtInfoTable[i].DefaultLength > 0) &&
728 (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
730 ACPI_BIOS_WARNING ((AE_INFO,
731 "Invalid length for FADT/%s: %u, using default %u",
732 FadtInfoTable[i].Name, Target64->BitWidth,
733 FadtInfoTable[i].DefaultLength));
735 /* Incorrect size, set width to the default */
737 Target64->BitWidth = FadtInfoTable[i].DefaultLength;
743 * Get the length of the individual PM1 registers (enable and status).
744 * Each register is defined to be (event block length / 2). Extra divide
745 * by 8 converts bits to bytes.
747 Pm1RegisterByteWidth = (UINT8)
748 ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
751 * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
752 * registers. These addresses do not appear (directly) in the FADT, so it
753 * is useful to pre-calculate them from the PM1 Event Block definitions.
755 * The PM event blocks are split into two register blocks, first is the
756 * PM Status Register block, followed immediately by the PM Enable
757 * Register block. Each is of length (Pm1EventLength/2)
759 * Note: The PM1A event block is required by the ACPI specification.
760 * However, the PM1B event block is optional and is rarely, if ever,
764 for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
766 Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
767 FadtPmInfoTable[i].Source);
769 if (Source64->Address)
771 AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
772 Source64->SpaceId, Pm1RegisterByteWidth,
774 (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth),