]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/tbconvrt.c
This commit was generated by cvs2svn to compensate for changes in r159952,
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / tbconvrt.c
1 /******************************************************************************
2  *
3  * Module Name: tbconvrt - ACPI Table conversion utilities
4  *              $Revision: 1.64 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2005, 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 <contrib/dev/acpica/acpi.h>
120 #include <contrib/dev/acpica/actables.h>
121
122
123 #define _COMPONENT          ACPI_TABLES
124         ACPI_MODULE_NAME    ("tbconvrt")
125
126 /* Local prototypes */
127
128 static void
129 AcpiTbInitGenericAddress (
130     ACPI_GENERIC_ADDRESS    *NewGasStruct,
131     UINT8                   RegisterBitWidth,
132     ACPI_PHYSICAL_ADDRESS   Address);
133
134 static void
135 AcpiTbConvertFadt1 (
136     FADT_DESCRIPTOR_REV2   *LocalFadt,
137     FADT_DESCRIPTOR_REV1   *OriginalFadt);
138
139 static void
140 AcpiTbConvertFadt2 (
141     FADT_DESCRIPTOR_REV2   *LocalFadt,
142     FADT_DESCRIPTOR_REV2   *OriginalFadt);
143
144
145 /*******************************************************************************
146  *
147  * FUNCTION:    AcpiTbGetTableCount
148  *
149  * PARAMETERS:  RSDP            - Pointer to the RSDP
150  *              RSDT            - Pointer to the RSDT/XSDT
151  *
152  * RETURN:      The number of tables pointed to by the RSDT or XSDT.
153  *
154  * DESCRIPTION: Calculate the number of tables.  Automatically handles either
155  *              an RSDT or XSDT.
156  *
157  ******************************************************************************/
158
159 UINT32
160 AcpiTbGetTableCount (
161     RSDP_DESCRIPTOR         *RSDP,
162     ACPI_TABLE_HEADER       *RSDT)
163 {
164     UINT32                  PointerSize;
165
166
167     ACPI_FUNCTION_ENTRY ();
168
169
170     /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
171
172     if (AcpiGbl_RootTableType == ACPI_TABLE_TYPE_RSDT)
173     {
174         PointerSize = sizeof (UINT32);
175     }
176     else
177     {
178         PointerSize = sizeof (UINT64);
179     }
180
181     /*
182      * Determine the number of tables pointed to by the RSDT/XSDT.
183      * This is defined by the ACPI Specification to be the number of
184      * pointers contained within the RSDT/XSDT.  The size of the pointers
185      * is architecture-dependent.
186      */
187     return ((RSDT->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize);
188 }
189
190
191 /*******************************************************************************
192  *
193  * FUNCTION:    AcpiTbConvertToXsdt
194  *
195  * PARAMETERS:  TableInfo       - Info about the RSDT
196  *
197  * RETURN:      Status
198  *
199  * DESCRIPTION: Convert an RSDT to an XSDT (internal common format)
200  *
201  ******************************************************************************/
202
203 ACPI_STATUS
204 AcpiTbConvertToXsdt (
205     ACPI_TABLE_DESC         *TableInfo)
206 {
207     ACPI_SIZE               TableSize;
208     UINT32                  i;
209     XSDT_DESCRIPTOR         *NewTable;
210
211
212     ACPI_FUNCTION_ENTRY ();
213
214
215     /* Compute size of the converted XSDT */
216
217     TableSize = ((ACPI_SIZE) AcpiGbl_RsdtTableCount * sizeof (UINT64)) +
218                     sizeof (ACPI_TABLE_HEADER);
219
220     /* Allocate an XSDT */
221
222     NewTable = ACPI_MEM_CALLOCATE (TableSize);
223     if (!NewTable)
224     {
225         return (AE_NO_MEMORY);
226     }
227
228     /* Copy the header and set the length */
229
230     ACPI_MEMCPY (NewTable, TableInfo->Pointer, sizeof (ACPI_TABLE_HEADER));
231     NewTable->Length = (UINT32) TableSize;
232
233     /* Copy the table pointers */
234
235     for (i = 0; i < AcpiGbl_RsdtTableCount; i++)
236     {
237         /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
238
239         if (AcpiGbl_RootTableType == ACPI_TABLE_TYPE_RSDT)
240         {
241             ACPI_STORE_ADDRESS (NewTable->TableOffsetEntry[i],
242                 (ACPI_CAST_PTR (RSDT_DESCRIPTOR_REV1,
243                     TableInfo->Pointer))->TableOffsetEntry[i]);
244         }
245         else
246         {
247             NewTable->TableOffsetEntry[i] =
248                 (ACPI_CAST_PTR (XSDT_DESCRIPTOR,
249                     TableInfo->Pointer))->TableOffsetEntry[i];
250         }
251     }
252
253     /* Delete the original table (either mapped or in a buffer) */
254
255     AcpiTbDeleteSingleTable (TableInfo);
256
257     /* Point the table descriptor to the new table */
258
259     TableInfo->Pointer      = ACPI_CAST_PTR (ACPI_TABLE_HEADER, NewTable);
260     TableInfo->Length       = TableSize;
261     TableInfo->Allocation   = ACPI_MEM_ALLOCATED;
262
263     return (AE_OK);
264 }
265
266
267 /*******************************************************************************
268  *
269  * FUNCTION:    AcpiTbInitGenericAddress
270  *
271  * PARAMETERS:  NewGasStruct        - GAS struct to be initialized
272  *              RegisterBitWidth    - Width of this register
273  *              Address             - Address of the register
274  *
275  * RETURN:      None
276  *
277  * DESCRIPTION: Initialize a GAS structure.
278  *
279  ******************************************************************************/
280
281 static void
282 AcpiTbInitGenericAddress (
283     ACPI_GENERIC_ADDRESS    *NewGasStruct,
284     UINT8                   RegisterBitWidth,
285     ACPI_PHYSICAL_ADDRESS   Address)
286 {
287
288     ACPI_STORE_ADDRESS (NewGasStruct->Address, Address);
289
290     NewGasStruct->AddressSpaceId    = ACPI_ADR_SPACE_SYSTEM_IO;
291     NewGasStruct->RegisterBitWidth  = RegisterBitWidth;
292     NewGasStruct->RegisterBitOffset = 0;
293     NewGasStruct->AccessWidth       = 0;
294 }
295
296
297 /*******************************************************************************
298  *
299  * FUNCTION:    AcpiTbConvertFadt1
300  *
301  * PARAMETERS:  LocalFadt       - Pointer to new FADT
302  *              OriginalFadt    - Pointer to old FADT
303  *
304  * RETURN:      None, populates LocalFadt
305  *
306  * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
307  *
308  ******************************************************************************/
309
310 static void
311 AcpiTbConvertFadt1 (
312     FADT_DESCRIPTOR_REV2   *LocalFadt,
313     FADT_DESCRIPTOR_REV1   *OriginalFadt)
314 {
315
316     /* ACPI 1.0 FACS */
317     /* The BIOS stored FADT should agree with Revision 1.0 */
318
319     /*
320      * Copy the table header and the common part of the tables.
321      *
322      * The 2.0 table is an extension of the 1.0 table, so the entire 1.0
323      * table can be copied first, then expand some fields to 64 bits.
324      */
325     ACPI_MEMCPY (LocalFadt, OriginalFadt, sizeof (FADT_DESCRIPTOR_REV1));
326
327     /* Convert table pointers to 64-bit fields */
328
329     ACPI_STORE_ADDRESS (LocalFadt->XFirmwareCtrl, LocalFadt->V1_FirmwareCtrl);
330     ACPI_STORE_ADDRESS (LocalFadt->XDsdt, LocalFadt->V1_Dsdt);
331
332     /*
333      * System Interrupt Model isn't used in ACPI 2.0
334      * (LocalFadt->Reserved1 = 0;)
335      */
336
337     /*
338      * This field is set by the OEM to convey the preferred power management
339      * profile to OSPM. It doesn't have any 1.0 equivalence.  Since we don't
340      * know what kind of 32-bit system this is, we will use "unspecified".
341      */
342     LocalFadt->Prefer_PM_Profile = PM_UNSPECIFIED;
343
344     /*
345      * Processor Performance State Control. This is the value OSPM writes to
346      * the SMI_CMD register to assume processor performance state control
347      * responsibility. There isn't any equivalence in 1.0, leave it zeroed.
348      */
349     LocalFadt->PstateCnt = 0;
350
351     /*
352      * Support for the _CST object and C States change notification.
353      * This data item hasn't any 1.0 equivalence so leave it zero.
354      */
355     LocalFadt->CstCnt = 0;
356
357     /*
358      * FADT Rev 2 was an interim FADT released between ACPI 1.0 and ACPI 2.0.
359      * It primarily adds the FADT reset mechanism.
360      */
361     if ((OriginalFadt->Revision == 2) &&
362         (OriginalFadt->Length == sizeof (FADT_DESCRIPTOR_REV2_MINUS)))
363     {
364         /*
365          * Grab the entire generic address struct, plus the 1-byte reset value
366          * that immediately follows.
367          */
368         ACPI_MEMCPY (&LocalFadt->ResetRegister,
369             &(ACPI_CAST_PTR (FADT_DESCRIPTOR_REV2_MINUS,
370                 OriginalFadt))->ResetRegister,
371             sizeof (ACPI_GENERIC_ADDRESS) + 1);
372     }
373     else
374     {
375         /*
376          * Since there isn't any equivalence in 1.0 and since it is highly
377          * likely that a 1.0 system has legacy support.
378          */
379         LocalFadt->IapcBootArch = BAF_LEGACY_DEVICES;
380     }
381
382     /*
383      * Convert the V1.0 block addresses to V2.0 GAS structures
384      */
385     AcpiTbInitGenericAddress (&LocalFadt->XPm1aEvtBlk, LocalFadt->Pm1EvtLen,
386                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm1aEvtBlk);
387     AcpiTbInitGenericAddress (&LocalFadt->XPm1bEvtBlk, LocalFadt->Pm1EvtLen,
388                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm1bEvtBlk);
389     AcpiTbInitGenericAddress (&LocalFadt->XPm1aCntBlk, LocalFadt->Pm1CntLen,
390                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm1aCntBlk);
391     AcpiTbInitGenericAddress (&LocalFadt->XPm1bCntBlk, LocalFadt->Pm1CntLen,
392                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm1bCntBlk);
393     AcpiTbInitGenericAddress (&LocalFadt->XPm2CntBlk,  LocalFadt->Pm2CntLen,
394                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Pm2CntBlk);
395     AcpiTbInitGenericAddress (&LocalFadt->XPmTmrBlk,   LocalFadt->PmTmLen,
396                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_PmTmrBlk);
397     AcpiTbInitGenericAddress (&LocalFadt->XGpe0Blk,    0,
398                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Gpe0Blk);
399     AcpiTbInitGenericAddress (&LocalFadt->XGpe1Blk,    0,
400                              (ACPI_PHYSICAL_ADDRESS)   LocalFadt->V1_Gpe1Blk);
401
402     /* Create separate GAS structs for the PM1 Enable registers */
403
404     AcpiTbInitGenericAddress (&AcpiGbl_XPm1aEnable,
405          (UINT8) ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen),
406          (ACPI_PHYSICAL_ADDRESS)
407             (ACPI_GET_ADDRESS (LocalFadt->XPm1aEvtBlk.Address) +
408             ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen)));
409
410     /* PM1B is optional; leave null if not present */
411
412     if (ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address))
413     {
414         AcpiTbInitGenericAddress (&AcpiGbl_XPm1bEnable,
415              (UINT8) ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen),
416              (ACPI_PHYSICAL_ADDRESS)
417                 (ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address) +
418                 ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen)));
419     }
420 }
421
422
423 /*******************************************************************************
424  *
425  * FUNCTION:    AcpiTbConvertFadt2
426  *
427  * PARAMETERS:  LocalFadt       - Pointer to new FADT
428  *              OriginalFadt    - Pointer to old FADT
429  *
430  * RETURN:      None, populates LocalFadt
431  *
432  * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
433  *              Handles optional "X" fields.
434  *
435  ******************************************************************************/
436
437 static void
438 AcpiTbConvertFadt2 (
439     FADT_DESCRIPTOR_REV2   *LocalFadt,
440     FADT_DESCRIPTOR_REV2   *OriginalFadt)
441 {
442
443     /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */
444
445     ACPI_MEMCPY (LocalFadt, OriginalFadt, sizeof (FADT_DESCRIPTOR_REV2));
446
447     /*
448      * "X" fields are optional extensions to the original V1.0 fields, so
449      * we must selectively expand V1.0 fields if the corresponding X field
450      * is zero.
451      */
452     if (!(ACPI_GET_ADDRESS (LocalFadt->XFirmwareCtrl)))
453     {
454         ACPI_STORE_ADDRESS (LocalFadt->XFirmwareCtrl,
455             LocalFadt->V1_FirmwareCtrl);
456     }
457
458     if (!(ACPI_GET_ADDRESS (LocalFadt->XDsdt)))
459     {
460         ACPI_STORE_ADDRESS (LocalFadt->XDsdt, LocalFadt->V1_Dsdt);
461     }
462
463     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm1aEvtBlk.Address)))
464     {
465         AcpiTbInitGenericAddress (&LocalFadt->XPm1aEvtBlk,
466             LocalFadt->Pm1EvtLen,
467             (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm1aEvtBlk);
468     }
469
470     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address)))
471     {
472         AcpiTbInitGenericAddress (&LocalFadt->XPm1bEvtBlk,
473             LocalFadt->Pm1EvtLen,
474             (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm1bEvtBlk);
475     }
476
477     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm1aCntBlk.Address)))
478     {
479         AcpiTbInitGenericAddress (&LocalFadt->XPm1aCntBlk,
480             LocalFadt->Pm1CntLen,
481             (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm1aCntBlk);
482     }
483
484     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm1bCntBlk.Address)))
485     {
486         AcpiTbInitGenericAddress (&LocalFadt->XPm1bCntBlk,
487             LocalFadt->Pm1CntLen,
488             (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm1bCntBlk);
489     }
490
491     if (!(ACPI_GET_ADDRESS (LocalFadt->XPm2CntBlk.Address)))
492     {
493         AcpiTbInitGenericAddress (&LocalFadt->XPm2CntBlk,
494             LocalFadt->Pm2CntLen,
495             (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Pm2CntBlk);
496     }
497
498     if (!(ACPI_GET_ADDRESS (LocalFadt->XPmTmrBlk.Address)))
499     {
500         AcpiTbInitGenericAddress (&LocalFadt->XPmTmrBlk,
501             LocalFadt->PmTmLen,
502             (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_PmTmrBlk);
503     }
504
505     if (!(ACPI_GET_ADDRESS (LocalFadt->XGpe0Blk.Address)))
506     {
507         AcpiTbInitGenericAddress (&LocalFadt->XGpe0Blk,
508             0, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Gpe0Blk);
509     }
510
511     if (!(ACPI_GET_ADDRESS (LocalFadt->XGpe1Blk.Address)))
512     {
513         AcpiTbInitGenericAddress (&LocalFadt->XGpe1Blk,
514             0, (ACPI_PHYSICAL_ADDRESS) LocalFadt->V1_Gpe1Blk);
515     }
516
517     /* Create separate GAS structs for the PM1 Enable registers */
518
519     AcpiTbInitGenericAddress (&AcpiGbl_XPm1aEnable,
520         (UINT8) ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen),
521         (ACPI_PHYSICAL_ADDRESS)
522             (ACPI_GET_ADDRESS (LocalFadt->XPm1aEvtBlk.Address) +
523             ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen)));
524
525     AcpiGbl_XPm1aEnable.AddressSpaceId =
526         LocalFadt->XPm1aEvtBlk.AddressSpaceId;
527
528     /* PM1B is optional; leave null if not present */
529
530     if (ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address))
531     {
532         AcpiTbInitGenericAddress (&AcpiGbl_XPm1bEnable,
533             (UINT8) ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen),
534             (ACPI_PHYSICAL_ADDRESS)
535                 (ACPI_GET_ADDRESS (LocalFadt->XPm1bEvtBlk.Address) +
536                 ACPI_DIV_2 (AcpiGbl_FADT->Pm1EvtLen)));
537
538         AcpiGbl_XPm1bEnable.AddressSpaceId =
539             LocalFadt->XPm1bEvtBlk.AddressSpaceId;
540     }
541 }
542
543
544 /*******************************************************************************
545  *
546  * FUNCTION:    AcpiTbConvertTableFadt
547  *
548  * PARAMETERS:  None
549  *
550  * RETURN:      Status
551  *
552  * DESCRIPTION: Converts a BIOS supplied ACPI 1.0 FADT to a local
553  *              ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply
554  *              copied to the local FADT.  The ACPI CA software uses this
555  *              local FADT. Thus a significant amount of special #ifdef
556  *              type codeing is saved.
557  *
558  ******************************************************************************/
559
560 ACPI_STATUS
561 AcpiTbConvertTableFadt (
562     void)
563 {
564     FADT_DESCRIPTOR_REV2   *LocalFadt;
565     ACPI_TABLE_DESC        *TableDesc;
566
567
568     ACPI_FUNCTION_TRACE ("TbConvertTableFadt");
569
570
571     /*
572      * AcpiGbl_FADT is valid. Validate the FADT length. The table must be
573      * at least as long as the version 1.0 FADT
574      */
575     if (AcpiGbl_FADT->Length < sizeof (FADT_DESCRIPTOR_REV1))
576     {
577         ACPI_REPORT_ERROR (("FADT is invalid, too short: 0x%X\n",
578             AcpiGbl_FADT->Length));
579         return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
580     }
581
582     /* Allocate buffer for the ACPI 2.0(+) FADT */
583
584     LocalFadt = ACPI_MEM_CALLOCATE (sizeof (FADT_DESCRIPTOR_REV2));
585     if (!LocalFadt)
586     {
587         return_ACPI_STATUS (AE_NO_MEMORY);
588     }
589
590     if (AcpiGbl_FADT->Revision >= FADT2_REVISION_ID)
591     {
592         if (AcpiGbl_FADT->Length < sizeof (FADT_DESCRIPTOR_REV2))
593         {
594             /* Length is too short to be a V2.0 table */
595
596             ACPI_REPORT_WARNING ((
597                 "Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table\n",
598                 AcpiGbl_FADT->Length, AcpiGbl_FADT->Revision));
599
600             AcpiTbConvertFadt1 (LocalFadt, (void *) AcpiGbl_FADT);
601         }
602         else
603         {
604             /* Valid V2.0 table */
605
606             AcpiTbConvertFadt2 (LocalFadt, AcpiGbl_FADT);
607         }
608     }
609     else
610     {
611         /* Valid V1.0 table */
612
613         AcpiTbConvertFadt1 (LocalFadt, (void *) AcpiGbl_FADT);
614     }
615
616     /* Global FADT pointer will point to the new common V2.0 FADT */
617
618     AcpiGbl_FADT = LocalFadt;
619     AcpiGbl_FADT->Length = sizeof (FADT_DESCRIPTOR);
620
621     /* Free the original table */
622
623     TableDesc = AcpiGbl_TableLists[ACPI_TABLE_FADT].Next;
624     AcpiTbDeleteSingleTable (TableDesc);
625
626     /* Install the new table */
627
628     TableDesc->Pointer      = ACPI_CAST_PTR (ACPI_TABLE_HEADER, AcpiGbl_FADT);
629     TableDesc->Allocation   = ACPI_MEM_ALLOCATED;
630     TableDesc->Length       = sizeof (FADT_DESCRIPTOR_REV2);
631
632     /* Dump the entire FADT */
633
634     ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
635         "Hex dump of common internal FADT, size %d (%X)\n",
636         AcpiGbl_FADT->Length, AcpiGbl_FADT->Length));
637     ACPI_DUMP_BUFFER ((UINT8 *) (AcpiGbl_FADT), AcpiGbl_FADT->Length);
638
639     return_ACPI_STATUS (AE_OK);
640 }
641
642
643 /*******************************************************************************
644  *
645  * FUNCTION:    AcpiTbBuildCommonFacs
646  *
647  * PARAMETERS:  TableInfo       - Info for currently installed FACS
648  *
649  * RETURN:      Status
650  *
651  * DESCRIPTION: Convert ACPI 1.0 and ACPI 2.0 FACS to a common internal
652  *              table format.
653  *
654  ******************************************************************************/
655
656 ACPI_STATUS
657 AcpiTbBuildCommonFacs (
658     ACPI_TABLE_DESC         *TableInfo)
659 {
660
661     ACPI_FUNCTION_TRACE ("TbBuildCommonFacs");
662
663
664     /* Absolute minimum length is 24, but the ACPI spec says 64 */
665
666     if (AcpiGbl_FACS->Length < 24)
667     {
668         ACPI_REPORT_ERROR (("Invalid FACS table length: 0x%X\n",
669             AcpiGbl_FACS->Length));
670         return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
671     }
672
673     if (AcpiGbl_FACS->Length < 64)
674     {
675         ACPI_REPORT_WARNING ((
676             "FACS is shorter than the ACPI specification allows: 0x%X, using anyway\n",
677             AcpiGbl_FACS->Length));
678     }
679
680     /* Copy fields to the new FACS */
681
682     AcpiGbl_CommonFACS.GlobalLock = &(AcpiGbl_FACS->GlobalLock);
683
684     if ((AcpiGbl_RSDP->Revision < 2) ||
685         (AcpiGbl_FACS->Length < 32)  ||
686         (!(ACPI_GET_ADDRESS (AcpiGbl_FACS->XFirmwareWakingVector))))
687     {
688         /* ACPI 1.0 FACS or short table or optional X_ field is zero */
689
690         AcpiGbl_CommonFACS.FirmwareWakingVector = ACPI_CAST_PTR (UINT64,
691                 &(AcpiGbl_FACS->FirmwareWakingVector));
692         AcpiGbl_CommonFACS.VectorWidth = 32;
693     }
694     else
695     {
696         /* ACPI 2.0 FACS with valid X_ field */
697
698         AcpiGbl_CommonFACS.FirmwareWakingVector = &AcpiGbl_FACS->XFirmwareWakingVector;
699         AcpiGbl_CommonFACS.VectorWidth = 64;
700     }
701
702     return_ACPI_STATUS (AE_OK);
703 }
704
705