]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/tbconvrt.c
This commit was generated by cvs2svn to compensate for changes in r151208,
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / tbconvrt.c
1 /******************************************************************************
2  *
3  * Module Name: tbconvrt - ACPI Table conversion utilities
4  *              $Revision: 57 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117 #define __TBCONVRT_C__
118
119 #include "acpi.h"
120 #include "actables.h"
121
122
123 #define _COMPONENT          ACPI_TABLES
124         ACPI_MODULE_NAME    ("tbconvrt")
125
126
127 /*******************************************************************************
128  *
129  * FUNCTION:    AcpiTbGetTableCount
130  *
131  * PARAMETERS:  RSDP            - Pointer to the RSDP
132  *              RSDT            - Pointer to the RSDT/XSDT
133  *
134  * RETURN:      The number of tables pointed to by the RSDT or XSDT.
135  *
136  * DESCRIPTION: Calculate the number of tables.  Automatically handles either
137  *              an RSDT or XSDT.
138  *
139  ******************************************************************************/
140
141 UINT32
142 AcpiTbGetTableCount (
143     RSDP_DESCRIPTOR         *RSDP,
144     ACPI_TABLE_HEADER       *RSDT)
145 {
146     UINT32                  PointerSize;
147
148
149     ACPI_FUNCTION_ENTRY ();
150
151
152     if (RSDP->Revision < 2)
153     {
154         PointerSize = sizeof (UINT32);
155     }
156     else
157     {
158         PointerSize = sizeof (UINT64);
159     }
160
161     /*
162      * Determine the number of tables pointed to by the RSDT/XSDT.
163      * This is defined by the ACPI Specification to be the number of
164      * pointers contained within the RSDT/XSDT.  The size of the pointers
165      * is architecture-dependent.
166      */
167     return ((RSDT->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize);
168 }
169
170
171 /*******************************************************************************
172  *
173  * FUNCTION:    AcpiTbConvertToXsdt
174  *
175  * PARAMETERS:  TableInfo       - Info about the RSDT
176  *
177  * RETURN:      Status
178  *
179  * DESCRIPTION: Convert an RSDT to an XSDT (internal common format)
180  *
181  ******************************************************************************/
182
183 ACPI_STATUS
184 AcpiTbConvertToXsdt (
185     ACPI_TABLE_DESC         *TableInfo)
186 {
187     ACPI_SIZE               TableSize;
188     UINT32                  i;
189     XSDT_DESCRIPTOR         *NewTable;
190
191
192     ACPI_FUNCTION_ENTRY ();
193
194
195     /* Compute size of the converted XSDT */
196
197     TableSize = ((ACPI_SIZE) AcpiGbl_RsdtTableCount * sizeof (UINT64)) +
198                     sizeof (ACPI_TABLE_HEADER);
199
200     /* Allocate an XSDT */
201
202     NewTable = ACPI_MEM_CALLOCATE (TableSize);
203     if (!NewTable)
204     {
205         return (AE_NO_MEMORY);
206     }
207
208     /* Copy the header and set the length */
209
210     ACPI_MEMCPY (NewTable, TableInfo->Pointer, sizeof (ACPI_TABLE_HEADER));
211     NewTable->Length = (UINT32) TableSize;
212
213     /* Copy the table pointers */
214
215     for (i = 0; i < AcpiGbl_RsdtTableCount; i++)
216     {
217         if (AcpiGbl_RSDP->Revision < 2)
218         {
219             ACPI_STORE_ADDRESS (NewTable->TableOffsetEntry[i],
220                 (ACPI_CAST_PTR (RSDT_DESCRIPTOR_REV1, TableInfo->Pointer))->TableOffsetEntry[i]);
221         }
222         else
223         {
224             NewTable->TableOffsetEntry[i] =
225                 (ACPI_CAST_PTR (XSDT_DESCRIPTOR, TableInfo->Pointer))->TableOffsetEntry[i];
226         }
227     }
228
229     /* Delete the original table (either mapped or in a buffer) */
230
231     AcpiTbDeleteSingleTable (TableInfo);
232
233     /* Point the table descriptor to the new table */
234
235     TableInfo->Pointer      = ACPI_CAST_PTR (ACPI_TABLE_HEADER, NewTable);
236     TableInfo->Length       = TableSize;
237     TableInfo->Allocation   = ACPI_MEM_ALLOCATED;
238
239     return (AE_OK);
240 }
241
242
243 /******************************************************************************
244  *
245  * FUNCTION:    AcpiTbInitGenericAddress
246  *
247  * PARAMETERS:  NewGasStruct        - GAS struct to be initialized
248  *              RegisterBitWidth    - Width of this register
249  *              Address             - Address of the register
250  *
251  * RETURN:      None
252  *
253  * DESCRIPTION: Initialize a GAS structure.
254  *
255  ******************************************************************************/
256
257 static void
258 AcpiTbInitGenericAddress (
259     ACPI_GENERIC_ADDRESS    *NewGasStruct,
260     UINT8                   RegisterBitWidth,
261     ACPI_PHYSICAL_ADDRESS   Address)
262 {
263
264     ACPI_STORE_ADDRESS (NewGasStruct->Address, Address);
265
266     NewGasStruct->AddressSpaceId    = ACPI_ADR_SPACE_SYSTEM_IO;
267     NewGasStruct->RegisterBitWidth  = RegisterBitWidth;
268     NewGasStruct->RegisterBitOffset = 0;
269     NewGasStruct->Reserved          = 0;
270 }
271
272
273 /*******************************************************************************
274  *
275  * FUNCTION:    AcpiTbConvertFadt1
276  *
277  * PARAMETERS:  LocalFadt       - Pointer to new FADT
278  *              OriginalFadt    - Pointer to old FADT
279  *
280  * RETURN:      Populates LocalFadt
281  *
282  * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
283  *
284  ******************************************************************************/
285
286 static void
287 AcpiTbConvertFadt1 (
288     FADT_DESCRIPTOR_REV2   *LocalFadt,
289     FADT_DESCRIPTOR_REV1   *OriginalFadt)
290 {
291
292
293     /* ACPI 1.0 FACS */
294     /* The BIOS stored FADT should agree with Revision 1.0 */
295
296     /*
297      * Copy the table header and the common part of the tables.
298      *
299      * The 2.0 table is an extension of the 1.0 table, so the entire 1.0
300      * table can be copied first, then expand some fields to 64 bits.
301      */
302     ACPI_MEMCPY (LocalFadt, OriginalFadt, sizeof (FADT_DESCRIPTOR_REV1));
303
304     /* Convert table pointers to 64-bit fields */
305
306     ACPI_STORE_ADDRESS (LocalFadt->XFirmwareCtrl, LocalFadt->V1_FirmwareCtrl);
307     ACPI_STORE_ADDRESS (LocalFadt->XDsdt, LocalFadt->V1_Dsdt);
308
309     /*
310      * System Interrupt Model isn't used in ACPI 2.0 (LocalFadt->Reserved1 = 0;)
311      */
312
313     /*
314      * This field is set by the OEM to convey the preferred power management
315      * profile to OSPM. It doesn't have any 1.0 equivalence.  Since we don't
316      * know what kind of 32-bit system this is, we will use "unspecified".
317      */
318     LocalFadt->Prefer_PM_Profile = PM_UNSPECIFIED;
319
320     /*
321      * Processor Performance State Control. This is the value OSPM writes to
322      * the SMI_CMD register to assume processor performance state control
323      * responsibility. There isn't any equivalence in 1.0, leave it zeroed.
324      */
325     LocalFadt->PstateCnt = 0;
326
327     /*
328      * Support for the _CST object and C States change notification.
329      * This data item hasn't any 1.0 equivalence so leave it zero.
330      */
331     LocalFadt->CstCnt = 0;
332
333     /*
334      * FADT Rev 2 was an interim FADT released between ACPI 1.0 and ACPI 2.0.
335      * It primarily adds the FADT reset mechanism.
336      */
337     if ((OriginalFadt->Revision == 2) &&
338         (OriginalFadt->Length == sizeof (FADT_DESCRIPTOR_REV2_MINUS)))
339     {
340         /*
341          * Grab the entire generic address struct, plus the 1-byte reset value
342          * that immediately follows.
343          */
344         ACPI_MEMCPY (&LocalFadt->ResetRegister,
345             &((FADT_DESCRIPTOR_REV2_MINUS *) OriginalFadt)->ResetRegister,
346             sizeof (ACPI_GENERIC_ADDRESS) + 1);
347     }
348     else
349     {
350         /*
351          * Since there isn't any equivalence in 1.0 and since it is highly
352          * likely that a 1.0 system has legacy support.
353          */
354         LocalFadt->IapcBootArch = BAF_LEGACY_DEVICES;
355     }
356
357     /*
358      * Convert the V1.0 block addresses to V2.0 GAS structures
359      */
360     AcpiTbInitGenericAddress (&LocalFadt->XPm1aEvtBlk, LocalFadt->Pm1EvtLen,
361                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm1aEvtBlk);
362     AcpiTbInitGenericAddress (&LocalFadt->XPm1bEvtBlk, LocalFadt->Pm1EvtLen,
363                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm1bEvtBlk);
364     AcpiTbInitGenericAddress (&LocalFadt->XPm1aCntBlk, LocalFadt->Pm1CntLen,
365                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm1aCntBlk);
366     AcpiTbInitGenericAddress (&LocalFadt->XPm1bCntBlk, LocalFadt->Pm1CntLen,
367                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm1bCntBlk);
368     AcpiTbInitGenericAddress (&LocalFadt->XPm2CntBlk,  LocalFadt->Pm2CntLen,
369                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm2CntBlk);
370     AcpiTbInitGenericAddress (&LocalFadt->XPmTmrBlk,   LocalFadt->PmTmLen,
371                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_PmTmrBlk);
372     AcpiTbInitGenericAddress (&LocalFadt->XGpe0Blk,    0,
373                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Gpe0Blk);
374     AcpiTbInitGenericAddress (&LocalFadt->XGpe1Blk,    0,
375                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Gpe1Blk);
376
377     /* Create separate GAS structs for the PM1 Enable registers */
378
379     AcpiTbInitGenericAddress (&AcpiGbl_XPm1aEnable,
380          (UINT8) ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen),
381          (ACPI_PHYSICAL_ADDRESS) (ACPI_GET_ADDRESS (LocalFadt->XPm1aEvtBlk.Address) +
382             ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen)));
383
384     /* PM1B is optional; leave null if not present */
385
386     if (ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address))
387     {
388         AcpiTbInitGenericAddress (&AcpiGbl_XPm1bEnable,
389              (UINT8) ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen),
390              (ACPI_PHYSICAL_ADDRESS) (ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address) +
391                 ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen)));
392     }
393 }
394
395
396 /*******************************************************************************
397  *
398  * FUNCTION:    AcpiTbConvertFadt2
399  *
400  * PARAMETERS:  LocalFadt       - Pointer to new FADT
401  *              OriginalFadt    - Pointer to old FADT
402  *
403  * RETURN:      Populates LocalFadt
404  *
405  * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
406  *              Handles optional "X" fields.
407  *
408  ******************************************************************************/
409
410 static void
411 AcpiTbConvertFadt2 (
412     FADT_DESCRIPTOR_REV2   *LocalFadt,
413     FADT_DESCRIPTOR_REV2   *OriginalFadt)
414 {
415
416     /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */
417
418     ACPI_MEMCPY (LocalFadt, OriginalFadt, sizeof (FADT_DESCRIPTOR_REV2));
419
420     /*
421      * "X" fields are optional extensions to the original V1.0 fields, so
422      * we must selectively expand V1.0 fields if the corresponding X field
423      * is zero.
424      */
425     if (!(ACPI_GET_ADDRESS (LocalFadt->XFirmwareCtrl)))
426     {
427         ACPI_STORE_ADDRESS (LocalFadt->XFirmwareCtrl, LocalFadt->V1_FirmwareCtrl);
428     }
429
430     if (!(ACPI_GET_ADDRESS (LocalFadt->XDsdt)))
431     {
432         ACPI_STORE_ADDRESS (LocalFadt->XDsdt, LocalFadt->V1_Dsdt);
433     }
434
435     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm1aEvtBlk.Address)))
436     {
437         AcpiTbInitGenericAddress (&LocalFadt->XPm1aEvtBlk,
438             LocalFadt->Pm1EvtLen, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm1aEvtBlk);
439     }
440
441     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address)))
442     {
443         AcpiTbInitGenericAddress (&LocalFadt->XPm1bEvtBlk,
444             LocalFadt->Pm1EvtLen, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm1bEvtBlk);
445     }
446
447     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm1aCntBlk.Address)))
448     {
449         AcpiTbInitGenericAddress (&LocalFadt->XPm1aCntBlk,
450             LocalFadt->Pm1CntLen, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm1aCntBlk);
451     }
452
453     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm1bCntBlk.Address)))
454     {
455         AcpiTbInitGenericAddress (&LocalFadt->XPm1bCntBlk,
456             LocalFadt->Pm1CntLen, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm1bCntBlk);
457     }
458
459     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm2CntBlk.Address)))
460     {
461         AcpiTbInitGenericAddress (&LocalFadt->XPm2CntBlk,
462             LocalFadt->Pm2CntLen, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm2CntBlk);
463     }
464
465     if (!(ACPI_GET_ADDRESS (LocalFadt->XPmTmrBlk.Address)))
466     {
467         AcpiTbInitGenericAddress (&LocalFadt->XPmTmrBlk,
468             LocalFadt->PmTmLen, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_PmTmrBlk);
469     }
470
471     if (!(ACPI_GET_ADDRESS (LocalFadt->XGpe0Blk.Address)))
472     {
473         AcpiTbInitGenericAddress (&LocalFadt->XGpe0Blk,
474             0, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Gpe0Blk);
475     }
476
477     if (!(ACPI_GET_ADDRESS (LocalFadt->XGpe1Blk.Address)))
478     {
479         AcpiTbInitGenericAddress (&LocalFadt->XGpe1Blk,
480             0, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Gpe1Blk);
481     }
482
483     /* Create separate GAS structs for the PM1 Enable registers */
484
485     AcpiTbInitGenericAddress (&AcpiGbl_XPm1aEnable,
486         (UINT8) ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen),
487         (ACPI_PHYSICAL_ADDRESS) (ACPI_GET_ADDRESS (LocalFadt->XPm1aEvtBlk.Address) +
488             ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen)));
489     AcpiGbl_XPm1aEnable.AddressSpaceId  = LocalFadt->XPm1aEvtBlk.AddressSpaceId;
490
491     /* PM1B is optional; leave null if not present */
492
493     if (ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address))
494     {
495         AcpiTbInitGenericAddress (&AcpiGbl_XPm1bEnable,
496             (UINT8) ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen),
497             (ACPI_PHYSICAL_ADDRESS) (ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address) +
498                 ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen)));
499         AcpiGbl_XPm1bEnable.AddressSpaceId  = LocalFadt->XPm1bEvtBlk.AddressSpaceId;
500     }
501 }
502
503
504 /*******************************************************************************
505  *
506  * FUNCTION:    AcpiTbConvertTableFadt
507  *
508  * PARAMETERS:  None
509  *
510  * RETURN:      Status
511  *
512  * DESCRIPTION: Converts a BIOS supplied ACPI 1.0 FADT to a local
513  *              ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply
514  *              copied to the local FADT.  The ACPI CA software uses this
515  *              local FADT. Thus a significant amount of special #ifdef
516  *              type codeing is saved.
517  *
518  ******************************************************************************/
519
520 ACPI_STATUS
521 AcpiTbConvertTableFadt (void)
522 {
523     FADT_DESCRIPTOR_REV2   *LocalFadt;
524     ACPI_TABLE_DESC        *TableDesc;
525
526
527     ACPI_FUNCTION_TRACE ("TbConvertTableFadt");
528
529
530     /*
531      * AcpiGbl_FADT is valid. Validate the FADT length. The table must be
532      * at least as long as the version 1.0 FADT
533      */
534     if (AcpiGbl_FADT->Length < sizeof (FADT_DESCRIPTOR_REV1))
535     {
536         ACPI_REPORT_ERROR (("FADT is invalid, too short: 0x%X\n", AcpiGbl_FADT->Length));
537         return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
538     }
539
540     /* Allocate buffer for the ACPI 2.0(+) FADT */
541
542     LocalFadt = ACPI_MEM_CALLOCATE (sizeof (FADT_DESCRIPTOR_REV2));
543     if (!LocalFadt)
544     {
545         return_ACPI_STATUS (AE_NO_MEMORY);
546     }
547
548     if (AcpiGbl_FADT->Revision >= FADT2_REVISION_ID)
549     {
550         if (AcpiGbl_FADT->Length < sizeof (FADT_DESCRIPTOR_REV2))
551         {
552             /* Length is too short to be a V2.0 table */
553
554             ACPI_REPORT_WARNING (("Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table\n",
555                         AcpiGbl_FADT->Length, AcpiGbl_FADT->Revision));
556
557             AcpiTbConvertFadt1 (LocalFadt, (void *) AcpiGbl_FADT);
558         }
559         else
560         {
561             /* Valid V2.0 table */
562
563             AcpiTbConvertFadt2 (LocalFadt, AcpiGbl_FADT);
564         }
565     }
566     else
567     {
568         /* Valid V1.0 table */
569
570         AcpiTbConvertFadt1 (LocalFadt, (void *) AcpiGbl_FADT);
571     }
572
573     /*
574      * Global FADT pointer will point to the new common V2.0 FADT
575      */
576     AcpiGbl_FADT = LocalFadt;
577     AcpiGbl_FADT->Length = sizeof (FADT_DESCRIPTOR);
578
579     /* Free the original table */
580
581     TableDesc = AcpiGbl_TableLists[ACPI_TABLE_FADT].Next;
582     AcpiTbDeleteSingleTable (TableDesc);
583
584     /* Install the new table */
585
586     TableDesc->Pointer      = ACPI_CAST_PTR (ACPI_TABLE_HEADER, AcpiGbl_FADT);
587     TableDesc->Allocation   = ACPI_MEM_ALLOCATED;
588     TableDesc->Length       = sizeof (FADT_DESCRIPTOR_REV2);
589
590     /* Dump the entire FADT */
591
592     ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
593         "Hex dump of common internal FADT, size %d (%X)\n",
594         AcpiGbl_FADT->Length, AcpiGbl_FADT->Length));
595     ACPI_DUMP_BUFFER ((UINT8 *) (AcpiGbl_FADT), AcpiGbl_FADT->Length);
596
597     return_ACPI_STATUS (AE_OK);
598 }
599
600
601 /*******************************************************************************
602  *
603  * FUNCTION:    AcpiTbConvertTableFacs
604  *
605  * PARAMETERS:  TableInfo       - Info for currently installad FACS
606  *
607  * RETURN:      Status
608  *
609  * DESCRIPTION: Convert ACPI 1.0 and ACPI 2.0 FACS to a common internal
610  *              table format.
611  *
612  ******************************************************************************/
613
614 ACPI_STATUS
615 AcpiTbBuildCommonFacs (
616     ACPI_TABLE_DESC         *TableInfo)
617 {
618
619     ACPI_FUNCTION_TRACE ("TbBuildCommonFacs");
620
621
622     /* Absolute minimum length is 24, but the ACPI spec says 64 */
623
624     if (AcpiGbl_FACS->Length < 24)
625     {
626         ACPI_REPORT_ERROR (("Invalid FACS table length: 0x%X\n", AcpiGbl_FACS->Length));
627         return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
628     }
629
630     if (AcpiGbl_FACS->Length < 64)
631     {
632         ACPI_REPORT_WARNING (("FACS is shorter than the ACPI specification allows: 0x%X, using anyway\n",
633             AcpiGbl_FACS->Length));
634     }
635
636     /* Copy fields to the new FACS */
637
638     AcpiGbl_CommonFACS.GlobalLock = &(AcpiGbl_FACS->GlobalLock);
639
640     if ((AcpiGbl_RSDP->Revision < 2) ||
641         (AcpiGbl_FACS->Length < 32)  ||
642         (!(ACPI_GET_ADDRESS (AcpiGbl_FACS->XFirmwareWakingVector))))
643     {
644         /* ACPI 1.0 FACS or short table or optional X_ field is zero */
645
646         AcpiGbl_CommonFACS.FirmwareWakingVector = ACPI_CAST_PTR (UINT64, &(AcpiGbl_FACS->FirmwareWakingVector));
647         AcpiGbl_CommonFACS.VectorWidth = 32;
648     }
649     else
650     {
651         /* ACPI 2.0 FACS with valid X_ field */
652
653         AcpiGbl_CommonFACS.FirmwareWakingVector = &AcpiGbl_FACS->XFirmwareWakingVector;
654         AcpiGbl_CommonFACS.VectorWidth = 64;
655     }
656
657     return_ACPI_STATUS (AE_OK);
658 }
659
660