Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / source / components / tables / tbfadt.c
blobf352803291ece5acd5a4b10d727e924bffd858aa
1 /******************************************************************************
3 * Module Name: tbfadt - FADT table utilities
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "actables.h"
156 #define _COMPONENT ACPI_TABLES
157 ACPI_MODULE_NAME ("tbfadt")
159 /* Local prototypes */
161 static void
162 AcpiTbInitGenericAddress (
163 ACPI_GENERIC_ADDRESS *GenericAddress,
164 UINT8 SpaceId,
165 UINT8 ByteWidth,
166 UINT64 Address,
167 const char *RegisterName,
168 UINT8 Flags);
170 static void
171 AcpiTbConvertFadt (
172 void);
174 static void
175 AcpiTbSetupFadtRegisters (
176 void);
178 static UINT64
179 AcpiTbSelectAddress (
180 char *RegisterName,
181 UINT32 Address32,
182 UINT64 Address64);
185 /* Table for conversion of FADT to common internal format and FADT validation */
187 typedef struct acpi_fadt_info
189 const char *Name;
190 UINT16 Address64;
191 UINT16 Address32;
192 UINT16 Length;
193 UINT8 DefaultLength;
194 UINT8 Flags;
196 } ACPI_FADT_INFO;
198 #define ACPI_FADT_OPTIONAL 0
199 #define ACPI_FADT_REQUIRED 1
200 #define ACPI_FADT_SEPARATE_LENGTH 2
201 #define ACPI_FADT_GPE_REGISTER 4
203 static ACPI_FADT_INFO FadtInfoTable[] =
205 {"Pm1aEventBlock",
206 ACPI_FADT_OFFSET (XPm1aEventBlock),
207 ACPI_FADT_OFFSET (Pm1aEventBlock),
208 ACPI_FADT_OFFSET (Pm1EventLength),
209 ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
210 ACPI_FADT_REQUIRED},
212 {"Pm1bEventBlock",
213 ACPI_FADT_OFFSET (XPm1bEventBlock),
214 ACPI_FADT_OFFSET (Pm1bEventBlock),
215 ACPI_FADT_OFFSET (Pm1EventLength),
216 ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
217 ACPI_FADT_OPTIONAL},
219 {"Pm1aControlBlock",
220 ACPI_FADT_OFFSET (XPm1aControlBlock),
221 ACPI_FADT_OFFSET (Pm1aControlBlock),
222 ACPI_FADT_OFFSET (Pm1ControlLength),
223 ACPI_PM1_REGISTER_WIDTH,
224 ACPI_FADT_REQUIRED},
226 {"Pm1bControlBlock",
227 ACPI_FADT_OFFSET (XPm1bControlBlock),
228 ACPI_FADT_OFFSET (Pm1bControlBlock),
229 ACPI_FADT_OFFSET (Pm1ControlLength),
230 ACPI_PM1_REGISTER_WIDTH,
231 ACPI_FADT_OPTIONAL},
233 {"Pm2ControlBlock",
234 ACPI_FADT_OFFSET (XPm2ControlBlock),
235 ACPI_FADT_OFFSET (Pm2ControlBlock),
236 ACPI_FADT_OFFSET (Pm2ControlLength),
237 ACPI_PM2_REGISTER_WIDTH,
238 ACPI_FADT_SEPARATE_LENGTH},
240 {"PmTimerBlock",
241 ACPI_FADT_OFFSET (XPmTimerBlock),
242 ACPI_FADT_OFFSET (PmTimerBlock),
243 ACPI_FADT_OFFSET (PmTimerLength),
244 ACPI_PM_TIMER_WIDTH,
245 ACPI_FADT_SEPARATE_LENGTH}, /* ACPI 5.0A: Timer is optional */
247 {"Gpe0Block",
248 ACPI_FADT_OFFSET (XGpe0Block),
249 ACPI_FADT_OFFSET (Gpe0Block),
250 ACPI_FADT_OFFSET (Gpe0BlockLength),
252 ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER},
254 {"Gpe1Block",
255 ACPI_FADT_OFFSET (XGpe1Block),
256 ACPI_FADT_OFFSET (Gpe1Block),
257 ACPI_FADT_OFFSET (Gpe1BlockLength),
259 ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER}
262 #define ACPI_FADT_INFO_ENTRIES \
263 (sizeof (FadtInfoTable) / sizeof (ACPI_FADT_INFO))
266 /* Table used to split Event Blocks into separate status/enable registers */
268 typedef struct acpi_fadt_pm_info
270 ACPI_GENERIC_ADDRESS *Target;
271 UINT16 Source;
272 UINT8 RegisterNum;
274 } ACPI_FADT_PM_INFO;
276 static ACPI_FADT_PM_INFO FadtPmInfoTable[] =
278 {&AcpiGbl_XPm1aStatus,
279 ACPI_FADT_OFFSET (XPm1aEventBlock),
282 {&AcpiGbl_XPm1aEnable,
283 ACPI_FADT_OFFSET (XPm1aEventBlock),
286 {&AcpiGbl_XPm1bStatus,
287 ACPI_FADT_OFFSET (XPm1bEventBlock),
290 {&AcpiGbl_XPm1bEnable,
291 ACPI_FADT_OFFSET (XPm1bEventBlock),
295 #define ACPI_FADT_PM_INFO_ENTRIES \
296 (sizeof (FadtPmInfoTable) / sizeof (ACPI_FADT_PM_INFO))
299 /*******************************************************************************
301 * FUNCTION: AcpiTbInitGenericAddress
303 * PARAMETERS: GenericAddress - GAS struct to be initialized
304 * SpaceId - ACPI Space ID for this register
305 * ByteWidth - Width of this register
306 * Address - Address of the register
307 * RegisterName - ASCII name of the ACPI register
309 * RETURN: None
311 * DESCRIPTION: Initialize a Generic Address Structure (GAS)
312 * See the ACPI specification for a full description and
313 * definition of this structure.
315 ******************************************************************************/
317 static void
318 AcpiTbInitGenericAddress (
319 ACPI_GENERIC_ADDRESS *GenericAddress,
320 UINT8 SpaceId,
321 UINT8 ByteWidth,
322 UINT64 Address,
323 const char *RegisterName,
324 UINT8 Flags)
326 UINT8 BitWidth;
330 * Bit width field in the GAS is only one byte long, 255 max.
331 * Check for BitWidth overflow in GAS.
333 BitWidth = (UINT8) (ByteWidth * 8);
334 if (ByteWidth > 31) /* (31*8)=248, (32*8)=256 */
337 * No error for GPE blocks, because we do not use the BitWidth
338 * for GPEs, the legacy length (ByteWidth) is used instead to
339 * allow for a large number of GPEs.
341 if (!(Flags & ACPI_FADT_GPE_REGISTER))
343 ACPI_ERROR ((AE_INFO,
344 "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
345 "to convert to GAS struct - 255 bits max, truncating",
346 RegisterName, ByteWidth, (ByteWidth * 8)));
349 BitWidth = 255;
353 * The 64-bit Address field is non-aligned in the byte packed
354 * GAS struct.
356 ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
358 /* All other fields are byte-wide */
360 GenericAddress->SpaceId = SpaceId;
361 GenericAddress->BitWidth = BitWidth;
362 GenericAddress->BitOffset = 0;
363 GenericAddress->AccessWidth = 0; /* Access width ANY */
367 /*******************************************************************************
369 * FUNCTION: AcpiTbSelectAddress
371 * PARAMETERS: RegisterName - ASCII name of the ACPI register
372 * Address32 - 32-bit address of the register
373 * Address64 - 64-bit address of the register
375 * RETURN: The resolved 64-bit address
377 * DESCRIPTION: Select between 32-bit and 64-bit versions of addresses within
378 * the FADT. Used for the FACS and DSDT addresses.
380 * NOTES:
382 * Check for FACS and DSDT address mismatches. An address mismatch between
383 * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
384 * DSDT/X_DSDT) could be a corrupted address field or it might indicate
385 * the presence of two FACS or two DSDT tables.
387 * November 2013:
388 * By default, as per the ACPICA specification, a valid 64-bit address is
389 * used regardless of the value of the 32-bit address. However, this
390 * behavior can be overridden via the AcpiGbl_Use32BitFadtAddresses flag.
392 ******************************************************************************/
394 static UINT64
395 AcpiTbSelectAddress (
396 char *RegisterName,
397 UINT32 Address32,
398 UINT64 Address64)
401 if (!Address64)
403 /* 64-bit address is zero, use 32-bit address */
405 return ((UINT64) Address32);
408 if (Address32 &&
409 (Address64 != (UINT64) Address32))
411 /* Address mismatch between 32-bit and 64-bit versions */
413 ACPI_BIOS_WARNING ((AE_INFO,
414 "32/64X %s address mismatch in FADT: "
415 "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
416 RegisterName, Address32, ACPI_FORMAT_UINT64 (Address64),
417 AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
419 /* 32-bit address override */
421 if (AcpiGbl_Use32BitFadtAddresses)
423 return ((UINT64) Address32);
427 /* Default is to use the 64-bit address */
429 return (Address64);
433 /*******************************************************************************
435 * FUNCTION: AcpiTbParseFadt
437 * PARAMETERS: None
439 * RETURN: None
441 * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
442 * (FADT contains the addresses of the DSDT and FACS)
444 ******************************************************************************/
446 void
447 AcpiTbParseFadt (
448 void)
450 UINT32 Length;
451 ACPI_TABLE_HEADER *Table;
452 ACPI_TABLE_DESC *FadtDesc;
453 ACPI_STATUS Status;
457 * The FADT has multiple versions with different lengths,
458 * and it contains pointers to both the DSDT and FACS tables.
460 * Get a local copy of the FADT and convert it to a common format
461 * Map entire FADT, assumed to be smaller than one page.
463 FadtDesc = &AcpiGbl_RootTableList.Tables[AcpiGbl_FadtIndex];
464 Status = AcpiTbGetTable (FadtDesc, &Table);
465 if (ACPI_FAILURE (Status))
467 return;
469 Length = FadtDesc->Length;
472 * Validate the FADT checksum before we copy the table. Ignore
473 * checksum error as we want to try to get the DSDT and FACS.
475 (void) AcpiTbVerifyChecksum (Table, Length);
477 /* Create a local copy of the FADT in common ACPI 2.0+ format */
479 AcpiTbCreateLocalFadt (Table, Length);
481 /* All done with the real FADT, unmap it */
483 AcpiTbPutTable (FadtDesc);
485 /* Obtain the DSDT and FACS tables via their addresses within the FADT */
487 AcpiTbInstallStandardTable (
488 (ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
489 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, FALSE, TRUE,
490 &AcpiGbl_DsdtIndex);
492 /* If Hardware Reduced flag is set, there is no FACS */
494 if (!AcpiGbl_ReducedHardware)
496 if (AcpiGbl_FADT.Facs)
498 AcpiTbInstallStandardTable (
499 (ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.Facs,
500 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, FALSE, TRUE,
501 &AcpiGbl_FacsIndex);
503 if (AcpiGbl_FADT.XFacs)
505 AcpiTbInstallStandardTable (
506 (ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
507 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, FALSE, TRUE,
508 &AcpiGbl_XFacsIndex);
514 /*******************************************************************************
516 * FUNCTION: AcpiTbCreateLocalFadt
518 * PARAMETERS: Table - Pointer to BIOS FADT
519 * Length - Length of the table
521 * RETURN: None
523 * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
524 * Performs validation on some important FADT fields.
526 * NOTE: We create a local copy of the FADT regardless of the version.
528 ******************************************************************************/
530 void
531 AcpiTbCreateLocalFadt (
532 ACPI_TABLE_HEADER *Table,
533 UINT32 Length)
537 * Check if the FADT is larger than the largest table that we expect
538 * (typically the current ACPI specification version). If so, truncate
539 * the table, and issue a warning.
541 if (Length > sizeof (ACPI_TABLE_FADT))
543 ACPI_BIOS_WARNING ((AE_INFO,
544 "FADT (revision %u) is longer than %s length, "
545 "truncating length %u to %u",
546 Table->Revision, ACPI_FADT_CONFORMANCE, Length,
547 (UINT32) sizeof (ACPI_TABLE_FADT)));
550 /* Clear the entire local FADT */
552 memset (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
554 /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
556 memcpy (&AcpiGbl_FADT, Table,
557 ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
559 /* Take a copy of the Hardware Reduced flag */
561 AcpiGbl_ReducedHardware = FALSE;
562 if (AcpiGbl_FADT.Flags & ACPI_FADT_HW_REDUCED)
564 AcpiGbl_ReducedHardware = TRUE;
567 /* Convert the local copy of the FADT to the common internal format */
569 AcpiTbConvertFadt ();
571 /* Initialize the global ACPI register structures */
573 AcpiTbSetupFadtRegisters ();
577 /*******************************************************************************
579 * FUNCTION: AcpiTbConvertFadt
581 * PARAMETERS: None - AcpiGbl_FADT is used.
583 * RETURN: None
585 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
586 * Expand 32-bit addresses to 64-bit as necessary. Also validate
587 * important fields within the FADT.
589 * NOTE: AcpiGbl_FADT must be of size (ACPI_TABLE_FADT), and must
590 * contain a copy of the actual BIOS-provided FADT.
592 * Notes on 64-bit register addresses:
594 * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
595 * fields of the FADT for all ACPI register addresses.
597 * The 64-bit X fields are optional extensions to the original 32-bit FADT
598 * V1.0 fields. Even if they are present in the FADT, they are optional and
599 * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
600 * 32-bit V1.0 fields to the 64-bit X fields if the 64-bit X field is originally
601 * zero.
603 * For ACPI 1.0 FADTs (that contain no 64-bit addresses), all 32-bit address
604 * fields are expanded to the corresponding 64-bit X fields in the internal
605 * common FADT.
607 * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
608 * to the corresponding 64-bit X fields, if the 64-bit field is originally
609 * zero. Adhering to the ACPI specification, we completely ignore the 32-bit
610 * field if the 64-bit field is valid, regardless of whether the host OS is
611 * 32-bit or 64-bit.
613 * Possible additional checks:
614 * (AcpiGbl_FADT.Pm1EventLength >= 4)
615 * (AcpiGbl_FADT.Pm1ControlLength >= 2)
616 * (AcpiGbl_FADT.PmTimerLength >= 4)
617 * Gpe block lengths must be multiple of 2
619 ******************************************************************************/
621 static void
622 AcpiTbConvertFadt (
623 void)
625 const char *Name;
626 ACPI_GENERIC_ADDRESS *Address64;
627 UINT32 Address32;
628 UINT8 Length;
629 UINT8 Flags;
630 UINT32 i;
634 * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
635 * should be zero are indeed zero. This will workaround BIOSs that
636 * inadvertently place values in these fields.
638 * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
639 * at offset 45, 55, 95, and the word located at offset 109, 110.
641 * Note: The FADT revision value is unreliable. Only the length can be
642 * trusted.
644 if (AcpiGbl_FADT.Header.Length <= ACPI_FADT_V2_SIZE)
646 AcpiGbl_FADT.PreferredProfile = 0;
647 AcpiGbl_FADT.PstateControl = 0;
648 AcpiGbl_FADT.CstControl = 0;
649 AcpiGbl_FADT.BootFlags = 0;
653 * Now we can update the local FADT length to the length of the
654 * current FADT version as defined by the ACPI specification.
655 * Thus, we will have a common FADT internally.
657 AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
660 * Expand the 32-bit DSDT addresses to 64-bit as necessary.
661 * Later ACPICA code will always use the X 64-bit field.
663 AcpiGbl_FADT.XDsdt = AcpiTbSelectAddress ("DSDT",
664 AcpiGbl_FADT.Dsdt, AcpiGbl_FADT.XDsdt);
666 /* If Hardware Reduced flag is set, we are all done */
668 if (AcpiGbl_ReducedHardware)
670 return;
673 /* Examine all of the 64-bit extended address fields (X fields) */
675 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
678 * Get the 32-bit and 64-bit addresses, as well as the register
679 * length and register name.
681 Address32 = *ACPI_ADD_PTR (UINT32,
682 &AcpiGbl_FADT, FadtInfoTable[i].Address32);
684 Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
685 &AcpiGbl_FADT, FadtInfoTable[i].Address64);
687 Length = *ACPI_ADD_PTR (UINT8,
688 &AcpiGbl_FADT, FadtInfoTable[i].Length);
690 Name = FadtInfoTable[i].Name;
691 Flags = FadtInfoTable[i].Flags;
694 * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
695 * generic address structures as necessary. Later code will always use
696 * the 64-bit address structures.
698 * November 2013:
699 * Now always use the 64-bit address if it is valid (non-zero), in
700 * accordance with the ACPI specification which states that a 64-bit
701 * address supersedes the 32-bit version. This behavior can be
702 * overridden by the AcpiGbl_Use32BitFadtAddresses flag.
704 * During 64-bit address construction and verification,
705 * these cases are handled:
707 * Address32 zero, Address64 [don't care] - Use Address64
709 * No override: if AcpiGbl_Use32BitFadtAddresses is FALSE, and:
710 * Address32 non-zero, Address64 zero - Copy/use Address32
711 * Address32 non-zero == Address64 non-zero - Use Address64
712 * Address32 non-zero != Address64 non-zero - Warning, use Address64
714 * Override: if AcpiGbl_Use32BitFadtAddresses is TRUE, and:
715 * Address32 non-zero, Address64 zero - Copy/use Address32
716 * Address32 non-zero == Address64 non-zero - Copy/use Address32
717 * Address32 non-zero != Address64 non-zero - Warning, copy/use Address32
719 * Note: SpaceId is always I/O for 32-bit legacy address fields
721 if (Address32)
723 if (Address64->Address)
725 if (Address64->Address != (UINT64) Address32)
727 /* Address mismatch */
729 ACPI_BIOS_WARNING ((AE_INFO,
730 "32/64X address mismatch in FADT/%s: "
731 "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
732 Name, Address32,
733 ACPI_FORMAT_UINT64 (Address64->Address),
734 AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
738 * For each extended field, check for length mismatch
739 * between the legacy length field and the corresponding
740 * 64-bit X length field.
741 * Note: If the legacy length field is > 0xFF bits, ignore
742 * this check. (GPE registers can be larger than the
743 * 64-bit GAS structure can accomodate, 0xFF bits).
745 if ((ACPI_MUL_8 (Length) <= ACPI_UINT8_MAX) &&
746 (Address64->BitWidth != ACPI_MUL_8 (Length)))
748 ACPI_BIOS_WARNING ((AE_INFO,
749 "32/64X length mismatch in FADT/%s: %u/%u",
750 Name, ACPI_MUL_8 (Length), Address64->BitWidth));
755 * Hardware register access code always uses the 64-bit fields.
756 * So if the 64-bit field is zero or is to be overridden,
757 * initialize it with the 32-bit fields.
758 * Note that when the 32-bit address favor is specified, the
759 * 64-bit fields are always re-initialized so that
760 * AccessSize/BitWidth/BitOffset fields can be correctly
761 * configured to the values to trigger a 32-bit compatible
762 * access mode in the hardware register access code.
764 if (!Address64->Address || AcpiGbl_Use32BitFadtAddresses)
766 AcpiTbInitGenericAddress (Address64,
767 ACPI_ADR_SPACE_SYSTEM_IO, Length,
768 (UINT64) Address32, Name, Flags);
772 if (FadtInfoTable[i].Flags & ACPI_FADT_REQUIRED)
775 * Field is required (PM1aEvent, PM1aControl).
776 * Both the address and length must be non-zero.
778 if (!Address64->Address || !Length)
780 ACPI_BIOS_ERROR ((AE_INFO,
781 "Required FADT field %s has zero address and/or length: "
782 "0x%8.8X%8.8X/0x%X",
783 Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
786 else if (FadtInfoTable[i].Flags & ACPI_FADT_SEPARATE_LENGTH)
789 * Field is optional (PM2Control, GPE0, GPE1) AND has its own
790 * length field. If present, both the address and length must
791 * be valid.
793 if ((Address64->Address && !Length) ||
794 (!Address64->Address && Length))
796 ACPI_BIOS_WARNING ((AE_INFO,
797 "Optional FADT field %s has valid %s but zero %s: "
798 "0x%8.8X%8.8X/0x%X", Name,
799 (Length ? "Length" : "Address"),
800 (Length ? "Address": "Length"),
801 ACPI_FORMAT_UINT64 (Address64->Address), Length));
808 /*******************************************************************************
810 * FUNCTION: AcpiTbSetupFadtRegisters
812 * PARAMETERS: None, uses AcpiGbl_FADT.
814 * RETURN: None
816 * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
817 * force FADT register definitions to their default lengths.
819 ******************************************************************************/
821 static void
822 AcpiTbSetupFadtRegisters (
823 void)
825 ACPI_GENERIC_ADDRESS *Target64;
826 ACPI_GENERIC_ADDRESS *Source64;
827 UINT8 Pm1RegisterByteWidth;
828 UINT32 i;
832 * Optionally check all register lengths against the default values and
833 * update them if they are incorrect.
835 if (AcpiGbl_UseDefaultRegisterWidths)
837 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
839 Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
840 FadtInfoTable[i].Address64);
843 * If a valid register (Address != 0) and the (DefaultLength > 0)
844 * (Not a GPE register), then check the width against the default.
846 if ((Target64->Address) &&
847 (FadtInfoTable[i].DefaultLength > 0) &&
848 (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
850 ACPI_BIOS_WARNING ((AE_INFO,
851 "Invalid length for FADT/%s: %u, using default %u",
852 FadtInfoTable[i].Name, Target64->BitWidth,
853 FadtInfoTable[i].DefaultLength));
855 /* Incorrect size, set width to the default */
857 Target64->BitWidth = FadtInfoTable[i].DefaultLength;
863 * Get the length of the individual PM1 registers (enable and status).
864 * Each register is defined to be (event block length / 2). Extra divide
865 * by 8 converts bits to bytes.
867 Pm1RegisterByteWidth = (UINT8)
868 ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
871 * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
872 * registers. These addresses do not appear (directly) in the FADT, so it
873 * is useful to pre-calculate them from the PM1 Event Block definitions.
875 * The PM event blocks are split into two register blocks, first is the
876 * PM Status Register block, followed immediately by the PM Enable
877 * Register block. Each is of length (Pm1EventLength/2)
879 * Note: The PM1A event block is required by the ACPI specification.
880 * However, the PM1B event block is optional and is rarely, if ever,
881 * used.
884 for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
886 Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
887 FadtPmInfoTable[i].Source);
889 if (Source64->Address)
891 AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
892 Source64->SpaceId, Pm1RegisterByteWidth,
893 Source64->Address +
894 (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth),
895 "PmRegisters", 0);