1 /******************************************************************************
3 * Module Name: tbfadt - FADT table utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/actables.h>
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbfadt")
53 /* Local prototypes */
55 static ACPI_INLINE void
56 AcpiTbInitGenericAddress (
57 ACPI_GENERIC_ADDRESS *GenericAddress,
71 AcpiTbSetupFadtRegisters (
75 /* Table for conversion of FADT to common internal format and FADT validation */
77 typedef struct acpi_fadt_info
88 #define ACPI_FADT_REQUIRED 1
89 #define ACPI_FADT_SEPARATE_LENGTH 2
91 static ACPI_FADT_INFO FadtInfoTable[] =
94 ACPI_FADT_OFFSET (XPm1aEventBlock),
95 ACPI_FADT_OFFSET (Pm1aEventBlock),
96 ACPI_FADT_OFFSET (Pm1EventLength),
97 ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
101 ACPI_FADT_OFFSET (XPm1bEventBlock),
102 ACPI_FADT_OFFSET (Pm1bEventBlock),
103 ACPI_FADT_OFFSET (Pm1EventLength),
104 ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
108 ACPI_FADT_OFFSET (XPm1aControlBlock),
109 ACPI_FADT_OFFSET (Pm1aControlBlock),
110 ACPI_FADT_OFFSET (Pm1ControlLength),
111 ACPI_PM1_REGISTER_WIDTH,
115 ACPI_FADT_OFFSET (XPm1bControlBlock),
116 ACPI_FADT_OFFSET (Pm1bControlBlock),
117 ACPI_FADT_OFFSET (Pm1ControlLength),
118 ACPI_PM1_REGISTER_WIDTH,
122 ACPI_FADT_OFFSET (XPm2ControlBlock),
123 ACPI_FADT_OFFSET (Pm2ControlBlock),
124 ACPI_FADT_OFFSET (Pm2ControlLength),
125 ACPI_PM2_REGISTER_WIDTH,
126 ACPI_FADT_SEPARATE_LENGTH},
129 ACPI_FADT_OFFSET (XPmTimerBlock),
130 ACPI_FADT_OFFSET (PmTimerBlock),
131 ACPI_FADT_OFFSET (PmTimerLength),
136 ACPI_FADT_OFFSET (XGpe0Block),
137 ACPI_FADT_OFFSET (Gpe0Block),
138 ACPI_FADT_OFFSET (Gpe0BlockLength),
140 ACPI_FADT_SEPARATE_LENGTH},
143 ACPI_FADT_OFFSET (XGpe1Block),
144 ACPI_FADT_OFFSET (Gpe1Block),
145 ACPI_FADT_OFFSET (Gpe1BlockLength),
147 ACPI_FADT_SEPARATE_LENGTH}
150 #define ACPI_FADT_INFO_ENTRIES \
151 (sizeof (FadtInfoTable) / sizeof (ACPI_FADT_INFO))
154 /* Table used to split Event Blocks into separate status/enable registers */
156 typedef struct acpi_fadt_pm_info
158 ACPI_GENERIC_ADDRESS *Target;
164 static ACPI_FADT_PM_INFO FadtPmInfoTable[] =
166 {&AcpiGbl_XPm1aStatus,
167 ACPI_FADT_OFFSET (XPm1aEventBlock),
170 {&AcpiGbl_XPm1aEnable,
171 ACPI_FADT_OFFSET (XPm1aEventBlock),
174 {&AcpiGbl_XPm1bStatus,
175 ACPI_FADT_OFFSET (XPm1bEventBlock),
178 {&AcpiGbl_XPm1bEnable,
179 ACPI_FADT_OFFSET (XPm1bEventBlock),
183 #define ACPI_FADT_PM_INFO_ENTRIES \
184 (sizeof (FadtPmInfoTable) / sizeof (ACPI_FADT_PM_INFO))
187 /*******************************************************************************
189 * FUNCTION: AcpiTbInitGenericAddress
191 * PARAMETERS: GenericAddress - GAS struct to be initialized
192 * SpaceId - ACPI Space ID for this register
193 * ByteWidth - Width of this register, in bytes
194 * Address - Address of the register
198 * DESCRIPTION: Initialize a Generic Address Structure (GAS)
199 * See the ACPI specification for a full description and
200 * definition of this structure.
202 ******************************************************************************/
204 static ACPI_INLINE void
205 AcpiTbInitGenericAddress (
206 ACPI_GENERIC_ADDRESS *GenericAddress,
213 * The 64-bit Address field is non-aligned in the byte packed
216 ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
218 /* All other fields are byte-wide */
220 GenericAddress->SpaceId = SpaceId;
221 GenericAddress->BitWidth = (UINT8) ACPI_MUL_8 (ByteWidth);
222 GenericAddress->BitOffset = 0;
223 GenericAddress->AccessWidth = 0; /* Access width ANY */
227 /*******************************************************************************
229 * FUNCTION: AcpiTbParseFadt
231 * PARAMETERS: TableIndex - Index for the FADT
235 * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
236 * (FADT contains the addresses of the DSDT and FACS)
238 ******************************************************************************/
245 ACPI_TABLE_HEADER *Table;
249 * The FADT has multiple versions with different lengths,
250 * and it contains pointers to both the DSDT and FACS tables.
252 * Get a local copy of the FADT and convert it to a common format
253 * Map entire FADT, assumed to be smaller than one page.
255 Length = AcpiGbl_RootTableList.Tables[TableIndex].Length;
257 Table = AcpiOsMapMemory (
258 AcpiGbl_RootTableList.Tables[TableIndex].Address, Length);
265 * Validate the FADT checksum before we copy the table. Ignore
266 * checksum error as we want to try to get the DSDT and FACS.
268 (void) AcpiTbVerifyChecksum (Table, Length);
270 /* Create a local copy of the FADT in common ACPI 2.0+ format */
272 AcpiTbCreateLocalFadt (Table, Length);
274 /* All done with the real FADT, unmap it */
276 AcpiOsUnmapMemory (Table, Length);
278 /* Obtain the DSDT and FACS tables via their addresses within the FADT */
280 AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
281 ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
283 AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
284 ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
288 /*******************************************************************************
290 * FUNCTION: AcpiTbCreateLocalFadt
292 * PARAMETERS: Table - Pointer to BIOS FADT
293 * Length - Length of the table
297 * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
298 * Performs validation on some important FADT fields.
300 * NOTE: We create a local copy of the FADT regardless of the version.
302 ******************************************************************************/
305 AcpiTbCreateLocalFadt (
306 ACPI_TABLE_HEADER *Table,
311 * Check if the FADT is larger than the largest table that we expect
312 * (the ACPI 2.0/3.0 version). If so, truncate the table, and issue
315 if (Length > sizeof (ACPI_TABLE_FADT))
317 ACPI_WARNING ((AE_INFO,
318 "FADT (revision %u) is longer than ACPI 2.0 version, "
319 "truncating length %u to %u",
320 Table->Revision, Length, (UINT32) sizeof (ACPI_TABLE_FADT)));
323 /* Clear the entire local FADT */
325 ACPI_MEMSET (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
327 /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
329 ACPI_MEMCPY (&AcpiGbl_FADT, Table,
330 ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
332 /* Convert the local copy of the FADT to the common internal format */
334 AcpiTbConvertFadt ();
336 /* Validate FADT values now, before we make any changes */
338 AcpiTbValidateFadt ();
340 /* Initialize the global ACPI register structures */
342 AcpiTbSetupFadtRegisters ();
346 /*******************************************************************************
348 * FUNCTION: AcpiTbConvertFadt
350 * PARAMETERS: None, uses AcpiGbl_FADT
354 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
355 * Expand 32-bit addresses to 64-bit as necessary.
357 * NOTE: AcpiGbl_FADT must be of size (ACPI_TABLE_FADT),
358 * and must contain a copy of the actual FADT.
360 * Notes on 64-bit register addresses:
362 * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
363 * fields of the FADT for all ACPI register addresses.
365 * The 64-bit "X" fields are optional extensions to the original 32-bit FADT
366 * V1.0 fields. Even if they are present in the FADT, they are optional and
367 * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
368 * 32-bit V1.0 fields if the corresponding X field is zero.
370 * For ACPI 1.0 FADTs, all 32-bit address fields are expanded to the
371 * corresponding "X" fields in the internal FADT.
373 * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
374 * to the corresponding 64-bit X fields. For compatibility with other ACPI
375 * implementations, we ignore the 64-bit field if the 32-bit field is valid,
376 * regardless of whether the host OS is 32-bit or 64-bit.
378 ******************************************************************************/
384 ACPI_GENERIC_ADDRESS *Address64;
389 /* Update the local FADT table header length */
391 AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
394 * Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary.
395 * Later code will always use the X 64-bit field.
397 if (!AcpiGbl_FADT.XFacs)
399 AcpiGbl_FADT.XFacs = (UINT64) AcpiGbl_FADT.Facs;
401 if (!AcpiGbl_FADT.XDsdt)
403 AcpiGbl_FADT.XDsdt = (UINT64) AcpiGbl_FADT.Dsdt;
407 * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
408 * should be zero are indeed zero. This will workaround BIOSs that
409 * inadvertently place values in these fields.
411 * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
412 * at offset 45, 55, 95, and the word located at offset 109, 110.
414 * Note: The FADT revision value is unreliable. Only the length can be
417 if (AcpiGbl_FADT.Header.Length <= ACPI_FADT_V2_SIZE)
419 AcpiGbl_FADT.PreferredProfile = 0;
420 AcpiGbl_FADT.PstateControl = 0;
421 AcpiGbl_FADT.CstControl = 0;
422 AcpiGbl_FADT.BootFlags = 0;
426 * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
427 * generic address structures as necessary. Later code will always use
428 * the 64-bit address structures.
431 * We now always use the 32-bit address if it is valid (non-null). This
432 * is not in accordance with the ACPI specification which states that
433 * the 64-bit address supersedes the 32-bit version, but we do this for
434 * compatibility with other ACPI implementations. Most notably, in the
435 * case where both the 32 and 64 versions are non-null, we use the 32-bit
436 * version. This is the only address that is guaranteed to have been
437 * tested by the BIOS manufacturer.
439 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
441 Address32 = *ACPI_ADD_PTR (UINT32,
442 &AcpiGbl_FADT, FadtInfoTable[i].Address32);
444 Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
445 &AcpiGbl_FADT, FadtInfoTable[i].Address64);
448 * If both 32- and 64-bit addresses are valid (non-zero),
451 if (Address64->Address && Address32 &&
452 (Address64->Address != (UINT64) Address32))
454 ACPI_ERROR ((AE_INFO,
455 "32/64X address mismatch in %s: 0x%8.8X/0x%8.8X%8.8X, using 32",
456 FadtInfoTable[i].Name, Address32,
457 ACPI_FORMAT_UINT64 (Address64->Address)));
460 /* Always use 32-bit address if it is valid (non-null) */
465 * Copy the 32-bit address to the 64-bit GAS structure. The
466 * Space ID is always I/O for 32-bit legacy address fields
468 AcpiTbInitGenericAddress (Address64, ACPI_ADR_SPACE_SYSTEM_IO,
469 *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT, FadtInfoTable[i].Length),
476 /*******************************************************************************
478 * FUNCTION: AcpiTbValidateFadt
480 * PARAMETERS: Table - Pointer to the FADT to be validated
484 * DESCRIPTION: Validate various important fields within the FADT. If a problem
485 * is found, issue a message, but no status is returned.
486 * Used by both the table manager and the disassembler.
488 * Possible additional checks:
489 * (AcpiGbl_FADT.Pm1EventLength >= 4)
490 * (AcpiGbl_FADT.Pm1ControlLength >= 2)
491 * (AcpiGbl_FADT.PmTimerLength >= 4)
492 * Gpe block lengths must be multiple of 2
494 ******************************************************************************/
501 ACPI_GENERIC_ADDRESS *Address64;
507 * Check for FACS and DSDT address mismatches. An address mismatch between
508 * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
509 * DSDT/X_DSDT) would indicate the presence of two FACS or two DSDT tables.
511 if (AcpiGbl_FADT.Facs &&
512 (AcpiGbl_FADT.XFacs != (UINT64) AcpiGbl_FADT.Facs))
514 ACPI_WARNING ((AE_INFO,
515 "32/64X FACS address mismatch in FADT - "
516 "0x%8.8X/0x%8.8X%8.8X, using 32",
517 AcpiGbl_FADT.Facs, ACPI_FORMAT_UINT64 (AcpiGbl_FADT.XFacs)));
519 AcpiGbl_FADT.XFacs = (UINT64) AcpiGbl_FADT.Facs;
522 if (AcpiGbl_FADT.Dsdt &&
523 (AcpiGbl_FADT.XDsdt != (UINT64) AcpiGbl_FADT.Dsdt))
525 ACPI_WARNING ((AE_INFO,
526 "32/64X DSDT address mismatch in FADT - "
527 "0x%8.8X/0x%8.8X%8.8X, using 32",
528 AcpiGbl_FADT.Dsdt, ACPI_FORMAT_UINT64 (AcpiGbl_FADT.XDsdt)));
530 AcpiGbl_FADT.XDsdt = (UINT64) AcpiGbl_FADT.Dsdt;
533 /* Examine all of the 64-bit extended address fields (X fields) */
535 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
538 * Generate pointer to the 64-bit address, get the register
539 * length (width) and the register name
541 Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
542 &AcpiGbl_FADT, FadtInfoTable[i].Address64);
543 Length = *ACPI_ADD_PTR (UINT8,
544 &AcpiGbl_FADT, FadtInfoTable[i].Length);
545 Name = FadtInfoTable[i].Name;
548 * For each extended field, check for length mismatch between the
549 * legacy length field and the corresponding 64-bit X length field.
551 if (Address64->Address &&
552 (Address64->BitWidth != ACPI_MUL_8 (Length)))
554 ACPI_WARNING ((AE_INFO,
555 "32/64X length mismatch in %s: %u/%u",
556 Name, ACPI_MUL_8 (Length), Address64->BitWidth));
559 if (FadtInfoTable[i].Type & ACPI_FADT_REQUIRED)
562 * Field is required (PM1aEvent, PM1aControl, PmTimer).
563 * Both the address and length must be non-zero.
565 if (!Address64->Address || !Length)
567 ACPI_ERROR ((AE_INFO,
568 "Required field %s has zero address and/or length:"
569 " 0x%8.8X%8.8X/0x%X",
570 Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
573 else if (FadtInfoTable[i].Type & ACPI_FADT_SEPARATE_LENGTH)
576 * Field is optional (PM2Control, GPE0, GPE1) AND has its own
577 * length field. If present, both the address and length must
580 if ((Address64->Address && !Length) ||
581 (!Address64->Address && Length))
583 ACPI_WARNING ((AE_INFO,
584 "Optional field %s has zero address or length: "
586 Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
593 /*******************************************************************************
595 * FUNCTION: AcpiTbSetupFadtRegisters
597 * PARAMETERS: None, uses AcpiGbl_FADT.
601 * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
602 * force FADT register definitions to their default lengths.
604 ******************************************************************************/
607 AcpiTbSetupFadtRegisters (
610 ACPI_GENERIC_ADDRESS *Target64;
611 ACPI_GENERIC_ADDRESS *Source64;
612 UINT8 Pm1RegisterByteWidth;
617 * Optionally check all register lengths against the default values and
618 * update them if they are incorrect.
620 if (AcpiGbl_UseDefaultRegisterWidths)
622 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
624 Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
625 FadtInfoTable[i].Address64);
628 * If a valid register (Address != 0) and the (DefaultLength > 0)
629 * (Not a GPE register), then check the width against the default.
631 if ((Target64->Address) &&
632 (FadtInfoTable[i].DefaultLength > 0) &&
633 (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
635 ACPI_WARNING ((AE_INFO,
636 "Invalid length for %s: %u, using default %u",
637 FadtInfoTable[i].Name, Target64->BitWidth,
638 FadtInfoTable[i].DefaultLength));
640 /* Incorrect size, set width to the default */
642 Target64->BitWidth = FadtInfoTable[i].DefaultLength;
648 * Get the length of the individual PM1 registers (enable and status).
649 * Each register is defined to be (event block length / 2). Extra divide
650 * by 8 converts bits to bytes.
652 Pm1RegisterByteWidth = (UINT8)
653 ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
656 * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
657 * registers. These addresses do not appear (directly) in the FADT, so it
658 * is useful to pre-calculate them from the PM1 Event Block definitions.
660 * The PM event blocks are split into two register blocks, first is the
661 * PM Status Register block, followed immediately by the PM Enable
662 * Register block. Each is of length (Pm1EventLength/2)
664 * Note: The PM1A event block is required by the ACPI specification.
665 * However, the PM1B event block is optional and is rarely, if ever,
669 for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
671 Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
672 FadtPmInfoTable[i].Source);
674 if (Source64->Address)
676 AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
677 Source64->SpaceId, Pm1RegisterByteWidth,
679 (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth));