1 /******************************************************************************
3 * Module Name: tbutils - table utilities
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define __TBUTILS_C__
119 #include "accommon.h"
120 #include "actables.h"
122 #define _COMPONENT ACPI_TABLES
123 ACPI_MODULE_NAME ("tbutils")
125 /* Local prototypes */
133 AcpiTbCleanupTableHeader (
134 ACPI_TABLE_HEADER
*OutHeader
,
135 ACPI_TABLE_HEADER
*Header
);
137 static ACPI_PHYSICAL_ADDRESS
138 AcpiTbGetRootTableEntry (
140 UINT32 TableEntrySize
);
143 /*******************************************************************************
145 * FUNCTION: AcpiTbInitializeFacs
151 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
152 * for accessing the Global Lock and Firmware Waking Vector
154 ******************************************************************************/
157 AcpiTbInitializeFacs (
163 Status
= AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS
,
164 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER
, &AcpiGbl_FACS
));
169 /*******************************************************************************
171 * FUNCTION: AcpiTbTablesLoaded
175 * RETURN: TRUE if required ACPI tables are loaded
177 * DESCRIPTION: Determine if the minimum required ACPI tables are present
180 ******************************************************************************/
187 if (AcpiGbl_RootTableList
.Count
>= 3)
196 /*******************************************************************************
198 * FUNCTION: AcpiTbFixString
200 * PARAMETERS: String - String to be repaired
201 * Length - Maximum length
205 * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
206 * with a question mark '?'.
208 ******************************************************************************/
216 while (Length
&& *String
)
218 if (!ACPI_IS_PRINT (*String
))
228 /*******************************************************************************
230 * FUNCTION: AcpiTbCleanupTableHeader
232 * PARAMETERS: OutHeader - Where the cleaned header is returned
233 * Header - Input ACPI table header
235 * RETURN: Returns the cleaned header in OutHeader
237 * DESCRIPTION: Copy the table header and ensure that all "string" fields in
238 * the header consist of printable characters.
240 ******************************************************************************/
243 AcpiTbCleanupTableHeader (
244 ACPI_TABLE_HEADER
*OutHeader
,
245 ACPI_TABLE_HEADER
*Header
)
248 ACPI_MEMCPY (OutHeader
, Header
, sizeof (ACPI_TABLE_HEADER
));
250 AcpiTbFixString (OutHeader
->Signature
, ACPI_NAME_SIZE
);
251 AcpiTbFixString (OutHeader
->OemId
, ACPI_OEM_ID_SIZE
);
252 AcpiTbFixString (OutHeader
->OemTableId
, ACPI_OEM_TABLE_ID_SIZE
);
253 AcpiTbFixString (OutHeader
->AslCompilerId
, ACPI_NAME_SIZE
);
257 /*******************************************************************************
259 * FUNCTION: AcpiTbPrintTableHeader
261 * PARAMETERS: Address - Table physical address
262 * Header - Table header
266 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
268 ******************************************************************************/
271 AcpiTbPrintTableHeader (
272 ACPI_PHYSICAL_ADDRESS Address
,
273 ACPI_TABLE_HEADER
*Header
)
275 ACPI_TABLE_HEADER LocalHeader
;
279 * The reason that the Address is cast to a void pointer is so that we
280 * can use %p which will work properly on both 32-bit and 64-bit hosts.
282 if (ACPI_COMPARE_NAME (Header
->Signature
, ACPI_SIG_FACS
))
284 /* FACS only has signature and length fields */
286 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "%4.4s %p %05X",
287 Header
->Signature
, ACPI_CAST_PTR (void, Address
),
290 else if (ACPI_COMPARE_NAME (Header
->Signature
, ACPI_SIG_RSDP
))
292 /* RSDP has no common fields */
294 ACPI_MEMCPY (LocalHeader
.OemId
,
295 ACPI_CAST_PTR (ACPI_TABLE_RSDP
, Header
)->OemId
, ACPI_OEM_ID_SIZE
);
296 AcpiTbFixString (LocalHeader
.OemId
, ACPI_OEM_ID_SIZE
);
298 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "RSDP %p %05X (v%.2d %6.6s)",
299 ACPI_CAST_PTR (void, Address
),
300 (ACPI_CAST_PTR (ACPI_TABLE_RSDP
, Header
)->Revision
> 0) ?
301 ACPI_CAST_PTR (ACPI_TABLE_RSDP
, Header
)->Length
: 20,
302 ACPI_CAST_PTR (ACPI_TABLE_RSDP
, Header
)->Revision
,
307 /* Standard ACPI table with full common header */
309 AcpiTbCleanupTableHeader (&LocalHeader
, Header
);
311 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
312 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
313 LocalHeader
.Signature
, ACPI_CAST_PTR (void, Address
),
314 LocalHeader
.Length
, LocalHeader
.Revision
, LocalHeader
.OemId
,
315 LocalHeader
.OemTableId
, LocalHeader
.OemRevision
,
316 LocalHeader
.AslCompilerId
, LocalHeader
.AslCompilerRevision
));
321 /*******************************************************************************
323 * FUNCTION: AcpiTbValidateChecksum
325 * PARAMETERS: Table - ACPI table to verify
326 * Length - Length of entire table
330 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
331 * exception on bad checksum.
333 ******************************************************************************/
336 AcpiTbVerifyChecksum (
337 ACPI_TABLE_HEADER
*Table
,
343 /* Compute the checksum on the table */
345 Checksum
= AcpiTbChecksum (ACPI_CAST_PTR (UINT8
, Table
), Length
);
347 /* Checksum ok? (should be zero) */
351 ACPI_WARNING ((AE_INFO
,
352 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
353 Table
->Signature
, Table
->Checksum
,
354 (UINT8
) (Table
->Checksum
- Checksum
)));
356 #if (ACPI_CHECKSUM_ABORT)
357 return (AE_BAD_CHECKSUM
);
365 /*******************************************************************************
367 * FUNCTION: AcpiTbChecksum
369 * PARAMETERS: Buffer - Pointer to memory region to be checked
370 * Length - Length of this memory region
372 * RETURN: Checksum (UINT8)
374 * DESCRIPTION: Calculates circular checksum of memory region.
376 ******************************************************************************/
384 UINT8
*End
= Buffer
+ Length
;
389 Sum
= (UINT8
) (Sum
+ *(Buffer
++));
396 /*******************************************************************************
398 * FUNCTION: AcpiTbInstallTable
400 * PARAMETERS: Address - Physical address of DSDT or FACS
401 * Signature - Table signature, NULL if no need to
403 * TableIndex - Index into root table array
407 * DESCRIPTION: Install an ACPI table into the global data structure. The
408 * table override mechanism is implemented here to allow the host
409 * OS to replace any table before it is installed in the root
412 ******************************************************************************/
416 ACPI_PHYSICAL_ADDRESS Address
,
417 const char *Signature
,
422 ACPI_TABLE_HEADER
*TableToInstall
;
423 ACPI_TABLE_HEADER
*MappedTable
;
424 ACPI_TABLE_HEADER
*OverrideTable
= NULL
;
429 ACPI_ERROR ((AE_INFO
, "Null physical address for ACPI table [%s]",
434 /* Map just the table header */
436 MappedTable
= AcpiOsMapMemory (Address
, sizeof (ACPI_TABLE_HEADER
));
442 /* If a particular signature is expected (DSDT/FACS), it must match */
445 !ACPI_COMPARE_NAME (MappedTable
->Signature
, Signature
))
447 ACPI_ERROR ((AE_INFO
,
448 "Invalid signature 0x%X for ACPI table, expected [%s]",
449 *ACPI_CAST_PTR (UINT32
, MappedTable
->Signature
), Signature
));
454 * ACPI Table Override:
456 * Before we install the table, let the host OS override it with a new
457 * one if desired. Any table within the RSDT/XSDT can be replaced,
458 * including the DSDT which is pointed to by the FADT.
460 Status
= AcpiOsTableOverride (MappedTable
, &OverrideTable
);
461 if (ACPI_SUCCESS (Status
) && OverrideTable
)
464 "%4.4s @ 0x%p Table override, replaced with:",
465 MappedTable
->Signature
, ACPI_CAST_PTR (void, Address
)));
467 AcpiGbl_RootTableList
.Tables
[TableIndex
].Pointer
= OverrideTable
;
468 Address
= ACPI_PTR_TO_PHYSADDR (OverrideTable
);
470 TableToInstall
= OverrideTable
;
471 Flags
= ACPI_TABLE_ORIGIN_OVERRIDE
;
475 TableToInstall
= MappedTable
;
476 Flags
= ACPI_TABLE_ORIGIN_MAPPED
;
479 /* Initialize the table entry */
481 AcpiGbl_RootTableList
.Tables
[TableIndex
].Address
= Address
;
482 AcpiGbl_RootTableList
.Tables
[TableIndex
].Length
= TableToInstall
->Length
;
483 AcpiGbl_RootTableList
.Tables
[TableIndex
].Flags
= Flags
;
486 &(AcpiGbl_RootTableList
.Tables
[TableIndex
].Signature
),
487 TableToInstall
->Signature
);
489 AcpiTbPrintTableHeader (Address
, TableToInstall
);
491 if (TableIndex
== ACPI_TABLE_INDEX_DSDT
)
493 /* Global integer width is based upon revision of the DSDT */
495 AcpiUtSetIntegerWidth (TableToInstall
->Revision
);
499 AcpiOsUnmapMemory (MappedTable
, sizeof (ACPI_TABLE_HEADER
));
503 /*******************************************************************************
505 * FUNCTION: AcpiTbGetRootTableEntry
507 * PARAMETERS: TableEntry - Pointer to the RSDT/XSDT table entry
508 * TableEntrySize - sizeof 32 or 64 (RSDT or XSDT)
510 * RETURN: Physical address extracted from the root table
512 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
513 * both 32-bit and 64-bit platforms
515 * NOTE: ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on
518 ******************************************************************************/
520 static ACPI_PHYSICAL_ADDRESS
521 AcpiTbGetRootTableEntry (
523 UINT32 TableEntrySize
)
529 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
530 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
532 if (TableEntrySize
== sizeof (UINT32
))
535 * 32-bit platform, RSDT: Return 32-bit table entry
536 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
538 return ((ACPI_PHYSICAL_ADDRESS
) (*ACPI_CAST_PTR (UINT32
, TableEntry
)));
543 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
544 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
547 ACPI_MOVE_64_TO_64 (&Address64
, TableEntry
);
549 #if ACPI_MACHINE_WIDTH == 32
550 if (Address64
> ACPI_UINT32_MAX
)
552 /* Will truncate 64-bit address to 32 bits, issue warning */
554 ACPI_WARNING ((AE_INFO
,
555 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X),"
557 ACPI_FORMAT_UINT64 (Address64
)));
560 return ((ACPI_PHYSICAL_ADDRESS
) (Address64
));
565 /*******************************************************************************
567 * FUNCTION: AcpiTbParseRootTable
569 * PARAMETERS: Rsdp - Pointer to the RSDP
573 * DESCRIPTION: This function is called to parse the Root System Description
574 * Table (RSDT or XSDT)
576 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
577 * be mapped and cannot be copied because it contains the actual
578 * memory location of the ACPI Global Lock.
580 ******************************************************************************/
583 AcpiTbParseRootTable (
584 ACPI_PHYSICAL_ADDRESS RsdpAddress
)
586 ACPI_TABLE_RSDP
*Rsdp
;
587 UINT32 TableEntrySize
;
590 ACPI_TABLE_HEADER
*Table
;
591 ACPI_PHYSICAL_ADDRESS Address
;
597 ACPI_FUNCTION_TRACE (TbParseRootTable
);
601 * Map the entire RSDP and extract the address of the RSDT or XSDT
603 Rsdp
= AcpiOsMapMemory (RsdpAddress
, sizeof (ACPI_TABLE_RSDP
));
606 return_ACPI_STATUS (AE_NO_MEMORY
);
609 AcpiTbPrintTableHeader (RsdpAddress
,
610 ACPI_CAST_PTR (ACPI_TABLE_HEADER
, Rsdp
));
612 /* Differentiate between RSDT and XSDT root tables */
614 if (Rsdp
->Revision
> 1 && Rsdp
->XsdtPhysicalAddress
)
617 * Root table is an XSDT (64-bit physical addresses). We must use the
618 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
619 * the ACPI specification.
621 Address
= (ACPI_PHYSICAL_ADDRESS
) Rsdp
->XsdtPhysicalAddress
;
622 TableEntrySize
= sizeof (UINT64
);
626 /* Root table is an RSDT (32-bit physical addresses) */
628 Address
= (ACPI_PHYSICAL_ADDRESS
) Rsdp
->RsdtPhysicalAddress
;
629 TableEntrySize
= sizeof (UINT32
);
633 * It is not possible to map more than one entry in some environments,
634 * so unmap the RSDP here before mapping other tables
636 AcpiOsUnmapMemory (Rsdp
, sizeof (ACPI_TABLE_RSDP
));
639 /* Map the RSDT/XSDT table header to get the full table length */
641 Table
= AcpiOsMapMemory (Address
, sizeof (ACPI_TABLE_HEADER
));
644 return_ACPI_STATUS (AE_NO_MEMORY
);
647 AcpiTbPrintTableHeader (Address
, Table
);
649 /* Get the length of the full table, verify length and map entire table */
651 Length
= Table
->Length
;
652 AcpiOsUnmapMemory (Table
, sizeof (ACPI_TABLE_HEADER
));
654 if (Length
< sizeof (ACPI_TABLE_HEADER
))
656 ACPI_ERROR ((AE_INFO
, "Invalid length 0x%X in RSDT/XSDT", Length
));
657 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH
);
660 Table
= AcpiOsMapMemory (Address
, Length
);
663 return_ACPI_STATUS (AE_NO_MEMORY
);
666 /* Validate the root table checksum */
668 Status
= AcpiTbVerifyChecksum (Table
, Length
);
669 if (ACPI_FAILURE (Status
))
671 AcpiOsUnmapMemory (Table
, Length
);
672 return_ACPI_STATUS (Status
);
675 /* Calculate the number of tables described in the root table */
677 TableCount
= (UINT32
) ((Table
->Length
- sizeof (ACPI_TABLE_HEADER
)) /
681 * First two entries in the table array are reserved for the DSDT
682 * and FACS, which are not actually present in the RSDT/XSDT - they
685 TableEntry
= ACPI_CAST_PTR (UINT8
, Table
) + sizeof (ACPI_TABLE_HEADER
);
686 AcpiGbl_RootTableList
.Count
= 2;
689 * Initialize the root table array from the RSDT/XSDT
691 for (i
= 0; i
< TableCount
; i
++)
693 if (AcpiGbl_RootTableList
.Count
>= AcpiGbl_RootTableList
.Size
)
695 /* There is no more room in the root table array, attempt resize */
697 Status
= AcpiTbResizeRootTableList ();
698 if (ACPI_FAILURE (Status
))
700 ACPI_WARNING ((AE_INFO
, "Truncating %u table entries!",
701 (unsigned) (TableCount
-
702 (AcpiGbl_RootTableList
.Count
- 2))));
707 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
709 AcpiGbl_RootTableList
.Tables
[AcpiGbl_RootTableList
.Count
].Address
=
710 AcpiTbGetRootTableEntry (TableEntry
, TableEntrySize
);
712 TableEntry
+= TableEntrySize
;
713 AcpiGbl_RootTableList
.Count
++;
717 * It is not possible to map more than one entry in some environments,
718 * so unmap the root table here before mapping other tables
720 AcpiOsUnmapMemory (Table
, Length
);
723 * Complete the initialization of the root table array by examining
724 * the header of each table
726 for (i
= 2; i
< AcpiGbl_RootTableList
.Count
; i
++)
728 AcpiTbInstallTable (AcpiGbl_RootTableList
.Tables
[i
].Address
,
731 /* Special case for FADT - get the DSDT and FACS */
733 if (ACPI_COMPARE_NAME (
734 &AcpiGbl_RootTableList
.Tables
[i
].Signature
, ACPI_SIG_FADT
))
740 return_ACPI_STATUS (AE_OK
);