]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/contrib/dev/acpica/components/tables/tbfadt.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / contrib / dev / acpica / components / tables / tbfadt.c
1 /******************************************************************************
2  *
3  * Module Name: tbfadt   - FADT table utilities
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2013, 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 <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/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 AcpiTbValidateFadt (
69     void);
70
71 static void
72 AcpiTbSetupFadtRegisters (
73     void);
74
75
76 /* Table for conversion of FADT to common internal format and FADT validation */
77
78 typedef struct acpi_fadt_info
79 {
80     char                    *Name;
81     UINT16                  Address64;
82     UINT16                  Address32;
83     UINT16                  Length;
84     UINT8                   DefaultLength;
85     UINT8                   Type;
86
87 } ACPI_FADT_INFO;
88
89 #define ACPI_FADT_OPTIONAL          0
90 #define ACPI_FADT_REQUIRED          1
91 #define ACPI_FADT_SEPARATE_LENGTH   2
92
93 static ACPI_FADT_INFO     FadtInfoTable[] =
94 {
95     {"Pm1aEventBlock",
96         ACPI_FADT_OFFSET (XPm1aEventBlock),
97         ACPI_FADT_OFFSET (Pm1aEventBlock),
98         ACPI_FADT_OFFSET (Pm1EventLength),
99         ACPI_PM1_REGISTER_WIDTH * 2,        /* Enable + Status register */
100         ACPI_FADT_REQUIRED},
101
102     {"Pm1bEventBlock",
103         ACPI_FADT_OFFSET (XPm1bEventBlock),
104         ACPI_FADT_OFFSET (Pm1bEventBlock),
105         ACPI_FADT_OFFSET (Pm1EventLength),
106         ACPI_PM1_REGISTER_WIDTH * 2,        /* Enable + Status register */
107         ACPI_FADT_OPTIONAL},
108
109     {"Pm1aControlBlock",
110         ACPI_FADT_OFFSET (XPm1aControlBlock),
111         ACPI_FADT_OFFSET (Pm1aControlBlock),
112         ACPI_FADT_OFFSET (Pm1ControlLength),
113         ACPI_PM1_REGISTER_WIDTH,
114         ACPI_FADT_REQUIRED},
115
116     {"Pm1bControlBlock",
117         ACPI_FADT_OFFSET (XPm1bControlBlock),
118         ACPI_FADT_OFFSET (Pm1bControlBlock),
119         ACPI_FADT_OFFSET (Pm1ControlLength),
120         ACPI_PM1_REGISTER_WIDTH,
121         ACPI_FADT_OPTIONAL},
122
123     {"Pm2ControlBlock",
124         ACPI_FADT_OFFSET (XPm2ControlBlock),
125         ACPI_FADT_OFFSET (Pm2ControlBlock),
126         ACPI_FADT_OFFSET (Pm2ControlLength),
127         ACPI_PM2_REGISTER_WIDTH,
128         ACPI_FADT_SEPARATE_LENGTH},
129
130     {"PmTimerBlock",
131         ACPI_FADT_OFFSET (XPmTimerBlock),
132         ACPI_FADT_OFFSET (PmTimerBlock),
133         ACPI_FADT_OFFSET (PmTimerLength),
134         ACPI_PM_TIMER_WIDTH,
135         ACPI_FADT_SEPARATE_LENGTH},         /* ACPI 5.0A: Timer is optional */
136
137     {"Gpe0Block",
138         ACPI_FADT_OFFSET (XGpe0Block),
139         ACPI_FADT_OFFSET (Gpe0Block),
140         ACPI_FADT_OFFSET (Gpe0BlockLength),
141         0,
142         ACPI_FADT_SEPARATE_LENGTH},
143
144     {"Gpe1Block",
145         ACPI_FADT_OFFSET (XGpe1Block),
146         ACPI_FADT_OFFSET (Gpe1Block),
147         ACPI_FADT_OFFSET (Gpe1BlockLength),
148         0,
149         ACPI_FADT_SEPARATE_LENGTH}
150 };
151
152 #define ACPI_FADT_INFO_ENTRIES \
153             (sizeof (FadtInfoTable) / sizeof (ACPI_FADT_INFO))
154
155
156 /* Table used to split Event Blocks into separate status/enable registers */
157
158 typedef struct acpi_fadt_pm_info
159 {
160     ACPI_GENERIC_ADDRESS    *Target;
161     UINT16                  Source;
162     UINT8                   RegisterNum;
163
164 } ACPI_FADT_PM_INFO;
165
166 static ACPI_FADT_PM_INFO    FadtPmInfoTable[] =
167 {
168     {&AcpiGbl_XPm1aStatus,
169         ACPI_FADT_OFFSET (XPm1aEventBlock),
170         0},
171
172     {&AcpiGbl_XPm1aEnable,
173         ACPI_FADT_OFFSET (XPm1aEventBlock),
174         1},
175
176     {&AcpiGbl_XPm1bStatus,
177         ACPI_FADT_OFFSET (XPm1bEventBlock),
178         0},
179
180     {&AcpiGbl_XPm1bEnable,
181         ACPI_FADT_OFFSET (XPm1bEventBlock),
182         1}
183 };
184
185 #define ACPI_FADT_PM_INFO_ENTRIES \
186             (sizeof (FadtPmInfoTable) / sizeof (ACPI_FADT_PM_INFO))
187
188
189 /*******************************************************************************
190  *
191  * FUNCTION:    AcpiTbInitGenericAddress
192  *
193  * PARAMETERS:  GenericAddress      - GAS struct to be initialized
194  *              SpaceId             - ACPI Space ID for this register
195  *              ByteWidth           - Width of this register
196  *              Address             - Address of the register
197  *
198  * RETURN:      None
199  *
200  * DESCRIPTION: Initialize a Generic Address Structure (GAS)
201  *              See the ACPI specification for a full description and
202  *              definition of this structure.
203  *
204  ******************************************************************************/
205
206 static void
207 AcpiTbInitGenericAddress (
208     ACPI_GENERIC_ADDRESS    *GenericAddress,
209     UINT8                   SpaceId,
210     UINT8                   ByteWidth,
211     UINT64                  Address,
212     char                    *RegisterName)
213 {
214     UINT8                   BitWidth;
215
216
217     /* Bit width field in the GAS is only one byte long, 255 max */
218
219     BitWidth = (UINT8) (ByteWidth * 8);
220
221     if (ByteWidth > 31) /* (31*8)=248 */
222     {
223         ACPI_ERROR ((AE_INFO,
224             "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
225             "to convert to GAS struct - 255 bits max, truncating",
226             RegisterName, ByteWidth, (ByteWidth * 8)));
227
228         BitWidth = 255;
229     }
230
231     /*
232      * The 64-bit Address field is non-aligned in the byte packed
233      * GAS struct.
234      */
235     ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
236
237     /* All other fields are byte-wide */
238
239     GenericAddress->SpaceId = SpaceId;
240     GenericAddress->BitWidth = BitWidth;
241     GenericAddress->BitOffset = 0;
242     GenericAddress->AccessWidth = 0; /* Access width ANY */
243 }
244
245
246 /*******************************************************************************
247  *
248  * FUNCTION:    AcpiTbParseFadt
249  *
250  * PARAMETERS:  TableIndex          - Index for the FADT
251  *
252  * RETURN:      None
253  *
254  * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
255  *              (FADT contains the addresses of the DSDT and FACS)
256  *
257  ******************************************************************************/
258
259 void
260 AcpiTbParseFadt (
261     UINT32                  TableIndex)
262 {
263     UINT32                  Length;
264     ACPI_TABLE_HEADER       *Table;
265
266
267     /*
268      * The FADT has multiple versions with different lengths,
269      * and it contains pointers to both the DSDT and FACS tables.
270      *
271      * Get a local copy of the FADT and convert it to a common format
272      * Map entire FADT, assumed to be smaller than one page.
273      */
274     Length = AcpiGbl_RootTableList.Tables[TableIndex].Length;
275
276     Table = AcpiOsMapMemory (
277                 AcpiGbl_RootTableList.Tables[TableIndex].Address, Length);
278     if (!Table)
279     {
280         return;
281     }
282
283     /*
284      * Validate the FADT checksum before we copy the table. Ignore
285      * checksum error as we want to try to get the DSDT and FACS.
286      */
287     (void) AcpiTbVerifyChecksum (Table, Length);
288
289     /* Create a local copy of the FADT in common ACPI 2.0+ format */
290
291     AcpiTbCreateLocalFadt (Table, Length);
292
293     /* All done with the real FADT, unmap it */
294
295     AcpiOsUnmapMemory (Table, Length);
296
297     /* Obtain the DSDT and FACS tables via their addresses within the FADT */
298
299     AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
300         ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
301
302     /* If Hardware Reduced flag is set, there is no FACS */
303
304     if (!AcpiGbl_ReducedHardware)
305     {
306         AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
307             ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
308     }
309 }
310
311
312 /*******************************************************************************
313  *
314  * FUNCTION:    AcpiTbCreateLocalFadt
315  *
316  * PARAMETERS:  Table               - Pointer to BIOS FADT
317  *              Length              - Length of the table
318  *
319  * RETURN:      None
320  *
321  * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
322  *              Performs validation on some important FADT fields.
323  *
324  * NOTE:        We create a local copy of the FADT regardless of the version.
325  *
326  ******************************************************************************/
327
328 void
329 AcpiTbCreateLocalFadt (
330     ACPI_TABLE_HEADER       *Table,
331     UINT32                  Length)
332 {
333
334     /*
335      * Check if the FADT is larger than the largest table that we expect
336      * (the ACPI 5.0 version). If so, truncate the table, and issue
337      * a warning.
338      */
339     if (Length > sizeof (ACPI_TABLE_FADT))
340     {
341         ACPI_BIOS_WARNING ((AE_INFO,
342             "FADT (revision %u) is longer than ACPI 5.0 version, "
343             "truncating length %u to %u",
344             Table->Revision, Length, (UINT32) sizeof (ACPI_TABLE_FADT)));
345     }
346
347     /* Clear the entire local FADT */
348
349     ACPI_MEMSET (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
350
351     /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
352
353     ACPI_MEMCPY (&AcpiGbl_FADT, Table,
354         ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
355
356     /* Take a copy of the Hardware Reduced flag */
357
358     AcpiGbl_ReducedHardware = FALSE;
359     if (AcpiGbl_FADT.Flags & ACPI_FADT_HW_REDUCED)
360     {
361         AcpiGbl_ReducedHardware = TRUE;
362     }
363
364     /* Convert the local copy of the FADT to the common internal format */
365
366     AcpiTbConvertFadt ();
367
368     /* Validate FADT values now, before we make any changes */
369
370     AcpiTbValidateFadt ();
371
372     /* Initialize the global ACPI register structures */
373
374     AcpiTbSetupFadtRegisters ();
375 }
376
377
378 /*******************************************************************************
379  *
380  * FUNCTION:    AcpiTbConvertFadt
381  *
382  * PARAMETERS:  None, uses AcpiGbl_FADT
383  *
384  * RETURN:      None
385  *
386  * DESCRIPTION: Converts all versions of the FADT to a common internal format.
387  *              Expand 32-bit addresses to 64-bit as necessary.
388  *
389  * NOTE:        AcpiGbl_FADT must be of size (ACPI_TABLE_FADT),
390  *              and must contain a copy of the actual FADT.
391  *
392  * Notes on 64-bit register addresses:
393  *
394  * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
395  * fields of the FADT for all ACPI register addresses.
396  *
397  * The 64-bit "X" fields are optional extensions to the original 32-bit FADT
398  * V1.0 fields. Even if they are present in the FADT, they are optional and
399  * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
400  * 32-bit V1.0 fields if the corresponding X field is zero.
401  *
402  * For ACPI 1.0 FADTs, all 32-bit address fields are expanded to the
403  * corresponding "X" fields in the internal FADT.
404  *
405  * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
406  * to the corresponding 64-bit X fields. For compatibility with other ACPI
407  * implementations, we ignore the 64-bit field if the 32-bit field is valid,
408  * regardless of whether the host OS is 32-bit or 64-bit.
409  *
410  ******************************************************************************/
411
412 static void
413 AcpiTbConvertFadt (
414     void)
415 {
416     ACPI_GENERIC_ADDRESS    *Address64;
417     UINT32                  Address32;
418     UINT32                  i;
419
420
421     /*
422      * Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary.
423      * Later code will always use the X 64-bit field.
424      */
425     if (!AcpiGbl_FADT.XFacs)
426     {
427         AcpiGbl_FADT.XFacs = (UINT64) AcpiGbl_FADT.Facs;
428     }
429     if (!AcpiGbl_FADT.XDsdt)
430     {
431         AcpiGbl_FADT.XDsdt = (UINT64) AcpiGbl_FADT.Dsdt;
432     }
433
434     /*
435      * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
436      * should be zero are indeed zero. This will workaround BIOSs that
437      * inadvertently place values in these fields.
438      *
439      * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
440      * at offset 45, 55, 95, and the word located at offset 109, 110.
441      *
442      * Note: The FADT revision value is unreliable. Only the length can be
443      * trusted.
444      */
445     if (AcpiGbl_FADT.Header.Length <= ACPI_FADT_V2_SIZE)
446     {
447         AcpiGbl_FADT.PreferredProfile = 0;
448         AcpiGbl_FADT.PstateControl = 0;
449         AcpiGbl_FADT.CstControl = 0;
450         AcpiGbl_FADT.BootFlags = 0;
451     }
452
453     /*
454      * Now we can update the local FADT length to the length of the
455      * current FADT version as defined by the ACPI specification.
456      * Thus, we will have a common FADT internally.
457      */
458     AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
459
460     /*
461      * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
462      * generic address structures as necessary. Later code will always use
463      * the 64-bit address structures.
464      *
465      * March 2009:
466      * We now always use the 32-bit address if it is valid (non-null). This
467      * is not in accordance with the ACPI specification which states that
468      * the 64-bit address supersedes the 32-bit version, but we do this for
469      * compatibility with other ACPI implementations. Most notably, in the
470      * case where both the 32 and 64 versions are non-null, we use the 32-bit
471      * version. This is the only address that is guaranteed to have been
472      * tested by the BIOS manufacturer.
473      */
474     for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
475     {
476         Address32 = *ACPI_ADD_PTR (UINT32,
477             &AcpiGbl_FADT, FadtInfoTable[i].Address32);
478
479         Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
480             &AcpiGbl_FADT, FadtInfoTable[i].Address64);
481
482         /*
483          * If both 32- and 64-bit addresses are valid (non-zero),
484          * they must match.
485          */
486         if (Address64->Address && Address32 &&
487            (Address64->Address != (UINT64) Address32))
488         {
489             ACPI_BIOS_ERROR ((AE_INFO,
490                 "32/64X address mismatch in FADT/%s: "
491                 "0x%8.8X/0x%8.8X%8.8X, using 32",
492                 FadtInfoTable[i].Name, Address32,
493                 ACPI_FORMAT_UINT64 (Address64->Address)));
494         }
495
496         /* Always use 32-bit address if it is valid (non-null) */
497
498         if (Address32)
499         {
500             /*
501              * Copy the 32-bit address to the 64-bit GAS structure. The
502              * Space ID is always I/O for 32-bit legacy address fields
503              */
504             AcpiTbInitGenericAddress (Address64, ACPI_ADR_SPACE_SYSTEM_IO,
505                 *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT, FadtInfoTable[i].Length),
506                 (UINT64) Address32, FadtInfoTable[i].Name);
507         }
508     }
509 }
510
511
512 /*******************************************************************************
513  *
514  * FUNCTION:    AcpiTbValidateFadt
515  *
516  * PARAMETERS:  Table           - Pointer to the FADT to be validated
517  *
518  * RETURN:      None
519  *
520  * DESCRIPTION: Validate various important fields within the FADT. If a problem
521  *              is found, issue a message, but no status is returned.
522  *              Used by both the table manager and the disassembler.
523  *
524  * Possible additional checks:
525  * (AcpiGbl_FADT.Pm1EventLength >= 4)
526  * (AcpiGbl_FADT.Pm1ControlLength >= 2)
527  * (AcpiGbl_FADT.PmTimerLength >= 4)
528  * Gpe block lengths must be multiple of 2
529  *
530  ******************************************************************************/
531
532 static void
533 AcpiTbValidateFadt (
534     void)
535 {
536     char                    *Name;
537     ACPI_GENERIC_ADDRESS    *Address64;
538     UINT8                   Length;
539     UINT32                  i;
540
541
542     /*
543      * Check for FACS and DSDT address mismatches. An address mismatch between
544      * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
545      * DSDT/X_DSDT) would indicate the presence of two FACS or two DSDT tables.
546      */
547     if (AcpiGbl_FADT.Facs &&
548         (AcpiGbl_FADT.XFacs != (UINT64) AcpiGbl_FADT.Facs))
549     {
550         ACPI_BIOS_WARNING ((AE_INFO,
551             "32/64X FACS address mismatch in FADT - "
552             "0x%8.8X/0x%8.8X%8.8X, using 32",
553             AcpiGbl_FADT.Facs, ACPI_FORMAT_UINT64 (AcpiGbl_FADT.XFacs)));
554
555         AcpiGbl_FADT.XFacs = (UINT64) AcpiGbl_FADT.Facs;
556     }
557
558     if (AcpiGbl_FADT.Dsdt &&
559         (AcpiGbl_FADT.XDsdt != (UINT64) AcpiGbl_FADT.Dsdt))
560     {
561         ACPI_BIOS_WARNING ((AE_INFO,
562             "32/64X DSDT address mismatch in FADT - "
563             "0x%8.8X/0x%8.8X%8.8X, using 32",
564             AcpiGbl_FADT.Dsdt, ACPI_FORMAT_UINT64 (AcpiGbl_FADT.XDsdt)));
565
566         AcpiGbl_FADT.XDsdt = (UINT64) AcpiGbl_FADT.Dsdt;
567     }
568
569     /* If Hardware Reduced flag is set, we are all done */
570
571     if (AcpiGbl_ReducedHardware)
572     {
573         return;
574     }
575
576     /* Examine all of the 64-bit extended address fields (X fields) */
577
578     for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
579     {
580         /*
581          * Generate pointer to the 64-bit address, get the register
582          * length (width) and the register name
583          */
584         Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
585                         &AcpiGbl_FADT, FadtInfoTable[i].Address64);
586         Length = *ACPI_ADD_PTR (UINT8,
587                         &AcpiGbl_FADT, FadtInfoTable[i].Length);
588         Name = FadtInfoTable[i].Name;
589
590         /*
591          * For each extended field, check for length mismatch between the
592          * legacy length field and the corresponding 64-bit X length field.
593          * Note: If the legacy length field is > 0xFF bits, ignore this
594          * check. (GPE registers can be larger than the 64-bit GAS structure
595          * can accomodate, 0xFF bits).
596          */
597         if (Address64->Address &&
598            (ACPI_MUL_8 (Length) <= ACPI_UINT8_MAX) &&
599            (Address64->BitWidth != ACPI_MUL_8 (Length)))
600         {
601             ACPI_BIOS_WARNING ((AE_INFO,
602                 "32/64X length mismatch in FADT/%s: %u/%u",
603                 Name, ACPI_MUL_8 (Length), Address64->BitWidth));
604         }
605
606         if (FadtInfoTable[i].Type & ACPI_FADT_REQUIRED)
607         {
608             /*
609              * Field is required (PM1aEvent, PM1aControl).
610              * Both the address and length must be non-zero.
611              */
612             if (!Address64->Address || !Length)
613             {
614                 ACPI_BIOS_ERROR ((AE_INFO,
615                     "Required FADT field %s has zero address and/or length: "
616                     "0x%8.8X%8.8X/0x%X",
617                     Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
618             }
619         }
620         else if (FadtInfoTable[i].Type & ACPI_FADT_SEPARATE_LENGTH)
621         {
622             /*
623              * Field is optional (PM2Control, GPE0, GPE1) AND has its own
624              * length field. If present, both the address and length must
625              * be valid.
626              */
627             if ((Address64->Address && !Length) ||
628                 (!Address64->Address && Length))
629             {
630                 ACPI_BIOS_WARNING ((AE_INFO,
631                     "Optional FADT field %s has zero address or length: "
632                     "0x%8.8X%8.8X/0x%X",
633                     Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
634             }
635         }
636     }
637 }
638
639
640 /*******************************************************************************
641  *
642  * FUNCTION:    AcpiTbSetupFadtRegisters
643  *
644  * PARAMETERS:  None, uses AcpiGbl_FADT.
645  *
646  * RETURN:      None
647  *
648  * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
649  *              force FADT register definitions to their default lengths.
650  *
651  ******************************************************************************/
652
653 static void
654 AcpiTbSetupFadtRegisters (
655     void)
656 {
657     ACPI_GENERIC_ADDRESS    *Target64;
658     ACPI_GENERIC_ADDRESS    *Source64;
659     UINT8                   Pm1RegisterByteWidth;
660     UINT32                  i;
661
662
663     /*
664      * Optionally check all register lengths against the default values and
665      * update them if they are incorrect.
666      */
667     if (AcpiGbl_UseDefaultRegisterWidths)
668     {
669         for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
670         {
671             Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
672                 FadtInfoTable[i].Address64);
673
674             /*
675              * If a valid register (Address != 0) and the (DefaultLength > 0)
676              * (Not a GPE register), then check the width against the default.
677              */
678             if ((Target64->Address) &&
679                 (FadtInfoTable[i].DefaultLength > 0) &&
680                 (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
681             {
682                 ACPI_BIOS_WARNING ((AE_INFO,
683                     "Invalid length for FADT/%s: %u, using default %u",
684                     FadtInfoTable[i].Name, Target64->BitWidth,
685                     FadtInfoTable[i].DefaultLength));
686
687                 /* Incorrect size, set width to the default */
688
689                 Target64->BitWidth = FadtInfoTable[i].DefaultLength;
690             }
691         }
692     }
693
694     /*
695      * Get the length of the individual PM1 registers (enable and status).
696      * Each register is defined to be (event block length / 2). Extra divide
697      * by 8 converts bits to bytes.
698      */
699     Pm1RegisterByteWidth = (UINT8)
700         ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
701
702     /*
703      * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
704      * registers. These addresses do not appear (directly) in the FADT, so it
705      * is useful to pre-calculate them from the PM1 Event Block definitions.
706      *
707      * The PM event blocks are split into two register blocks, first is the
708      * PM Status Register block, followed immediately by the PM Enable
709      * Register block. Each is of length (Pm1EventLength/2)
710      *
711      * Note: The PM1A event block is required by the ACPI specification.
712      * However, the PM1B event block is optional and is rarely, if ever,
713      * used.
714      */
715
716     for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
717     {
718         Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
719             FadtPmInfoTable[i].Source);
720
721         if (Source64->Address)
722         {
723             AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
724                 Source64->SpaceId, Pm1RegisterByteWidth,
725                 Source64->Address +
726                     (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth),
727                 "PmRegisters");
728         }
729     }
730 }