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