1 /******************************************************************************
3 * Module Name: tbutils - table utilities
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13 * All rights reserved.
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
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
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;
38 * The above copyright and patent license is granted only if the following
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.
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
81 * 4. Disclaimer and Export Compliance
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
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
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.
115 *****************************************************************************/
117 #define __TBUTILS_C__
119 #include <contrib/dev/acpica/acpi.h>
120 #include <contrib/dev/acpica/actables.h>
122 #define _COMPONENT ACPI_TABLES
123 ACPI_MODULE_NAME ("tbutils")
125 /* Local prototypes */
127 static ACPI_PHYSICAL_ADDRESS
128 AcpiTbGetRootTableEntry (
130 ACPI_NATIVE_UINT TableEntrySize);
133 /*******************************************************************************
135 * FUNCTION: AcpiTbTablesLoaded
139 * RETURN: TRUE if required ACPI tables are loaded
141 * DESCRIPTION: Determine if the minimum required ACPI tables are present
144 ******************************************************************************/
151 if (AcpiGbl_RootTableList.Count >= 3)
160 /*******************************************************************************
162 * FUNCTION: AcpiTbPrintTableHeader
164 * PARAMETERS: Address - Table physical address
165 * Header - Table header
169 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
171 ******************************************************************************/
174 AcpiTbPrintTableHeader (
175 ACPI_PHYSICAL_ADDRESS Address,
176 ACPI_TABLE_HEADER *Header)
179 if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_FACS))
181 /* FACS only has signature and length fields of common table header */
183 ACPI_INFO ((AE_INFO, "%4.4s @ 0x%p/0x%04X",
184 Header->Signature, ACPI_CAST_PTR (void, Address), Header->Length));
186 else if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_RSDP))
188 /* RSDP has no common fields */
190 ACPI_INFO ((AE_INFO, "RSDP @ 0x%p/0x%04X (v%3.3d %6.6s)",
191 ACPI_CAST_PTR (void, Address),
192 (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ?
193 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20,
194 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision,
195 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->OemId));
199 /* Standard ACPI table with full common header */
202 "%4.4s @ 0x%p/0x%04X (v%3.3d %6.6s %8.8s 0x%08X %4.4s 0x%08X)",
203 Header->Signature, ACPI_CAST_PTR (void, Address),
204 Header->Length, Header->Revision, Header->OemId,
205 Header->OemTableId, Header->OemRevision, Header->AslCompilerId,
206 Header->AslCompilerRevision));
211 /*******************************************************************************
213 * FUNCTION: AcpiTbValidateChecksum
215 * PARAMETERS: Table - ACPI table to verify
216 * Length - Length of entire table
220 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
221 * exception on bad checksum.
223 ******************************************************************************/
226 AcpiTbVerifyChecksum (
227 ACPI_TABLE_HEADER *Table,
233 /* Compute the checksum on the table */
235 Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Length);
237 /* Checksum ok? (should be zero) */
241 ACPI_WARNING ((AE_INFO,
242 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
243 Table->Signature, Table->Checksum, (UINT8) (Table->Checksum - Checksum)));
245 #if (ACPI_CHECKSUM_ABORT)
246 return (AE_BAD_CHECKSUM);
254 /*******************************************************************************
256 * FUNCTION: AcpiTbChecksum
258 * PARAMETERS: Buffer - Pointer to memory region to be checked
259 * Length - Length of this memory region
261 * RETURN: Checksum (UINT8)
263 * DESCRIPTION: Calculates circular checksum of memory region.
265 ******************************************************************************/
270 ACPI_NATIVE_UINT Length)
273 UINT8 *End = Buffer + Length;
278 Sum = (UINT8) (Sum + *(Buffer++));
285 /*******************************************************************************
287 * FUNCTION: AcpiTbInstallTable
289 * PARAMETERS: Address - Physical address of DSDT or FACS
291 * Signature - Table signature, NULL if no need to
293 * TableIndex - Index into root table array
297 * DESCRIPTION: Install an ACPI table into the global data structure.
299 ******************************************************************************/
303 ACPI_PHYSICAL_ADDRESS Address,
306 ACPI_NATIVE_UINT TableIndex)
308 ACPI_TABLE_HEADER *Table;
313 ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]",
318 /* Map just the table header */
320 Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
326 /* If a particular signature is expected, signature must match */
329 !ACPI_COMPARE_NAME (Table->Signature, Signature))
331 ACPI_ERROR ((AE_INFO, "Invalid signature 0x%X for ACPI table [%s]",
332 *ACPI_CAST_PTR (UINT32, Table->Signature), Signature));
336 /* Initialize the table entry */
338 AcpiGbl_RootTableList.Tables[TableIndex].Address = Address;
339 AcpiGbl_RootTableList.Tables[TableIndex].Length = Table->Length;
340 AcpiGbl_RootTableList.Tables[TableIndex].Flags = Flags;
343 &(AcpiGbl_RootTableList.Tables[TableIndex].Signature),
346 AcpiTbPrintTableHeader (Address, Table);
348 if (TableIndex == ACPI_TABLE_INDEX_DSDT)
350 /* Global integer width is based upon revision of the DSDT */
352 AcpiUtSetIntegerWidth (Table->Revision);
356 AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
360 /*******************************************************************************
362 * FUNCTION: AcpiTbGetRootTableEntry
364 * PARAMETERS: TableEntry - Pointer to the RSDT/XSDT table entry
365 * TableEntrySize - sizeof 32 or 64 (RSDT or XSDT)
367 * RETURN: Physical address extracted from the root table
369 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
370 * both 32-bit and 64-bit platforms
372 * NOTE: ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on
375 ******************************************************************************/
377 static ACPI_PHYSICAL_ADDRESS
378 AcpiTbGetRootTableEntry (
380 ACPI_NATIVE_UINT TableEntrySize)
386 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
387 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
389 if (TableEntrySize == sizeof (UINT32))
392 * 32-bit platform, RSDT: Return 32-bit table entry
393 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
395 return ((ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST_PTR (UINT32, TableEntry)));
400 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
401 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, return 64-bit
403 ACPI_MOVE_64_TO_64 (&Address64, TableEntry);
405 #if ACPI_MACHINE_WIDTH == 32
406 if (Address64 > ACPI_UINT32_MAX)
408 /* Will truncate 64-bit address to 32 bits, issue warning */
410 ACPI_WARNING ((AE_INFO,
411 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X), truncating",
412 ACPI_FORMAT_UINT64 (Address64)));
415 return ((ACPI_PHYSICAL_ADDRESS) (Address64));
420 /*******************************************************************************
422 * FUNCTION: AcpiTbParseRootTable
424 * PARAMETERS: Rsdp - Pointer to the RSDP
429 * DESCRIPTION: This function is called to parse the Root System Description
430 * Table (RSDT or XSDT)
432 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
433 * be mapped and cannot be copied because it contains the actual
434 * memory location of the ACPI Global Lock.
436 ******************************************************************************/
439 AcpiTbParseRootTable (
440 ACPI_PHYSICAL_ADDRESS RsdpAddress,
443 ACPI_TABLE_RSDP *Rsdp;
444 ACPI_NATIVE_UINT TableEntrySize;
447 ACPI_TABLE_HEADER *Table;
448 ACPI_PHYSICAL_ADDRESS Address;
454 ACPI_FUNCTION_TRACE (TbParseRootTable);
458 * Map the entire RSDP and extract the address of the RSDT or XSDT
460 Rsdp = AcpiOsMapMemory (RsdpAddress, sizeof (ACPI_TABLE_RSDP));
463 return_ACPI_STATUS (AE_NO_MEMORY);
466 AcpiTbPrintTableHeader (RsdpAddress, ACPI_CAST_PTR (ACPI_TABLE_HEADER, Rsdp));
468 /* Differentiate between RSDT and XSDT root tables */
470 if (Rsdp->Revision > 1 && Rsdp->XsdtPhysicalAddress)
473 * Root table is an XSDT (64-bit physical addresses). We must use the
474 * XSDT if the revision is > 1 and the XSDT pointer is present, as per
475 * the ACPI specification.
477 Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->XsdtPhysicalAddress;
478 TableEntrySize = sizeof (UINT64);
482 /* Root table is an RSDT (32-bit physical addresses) */
484 Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->RsdtPhysicalAddress;
485 TableEntrySize = sizeof (UINT32);
489 * It is not possible to map more than one entry in some environments,
490 * so unmap the RSDP here before mapping other tables
492 AcpiOsUnmapMemory (Rsdp, sizeof (ACPI_TABLE_RSDP));
495 /* Map the RSDT/XSDT table header to get the full table length */
497 Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
500 return_ACPI_STATUS (AE_NO_MEMORY);
503 AcpiTbPrintTableHeader (Address, Table);
505 /* Get the length of the full table, verify length and map entire table */
507 Length = Table->Length;
508 AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
510 if (Length < sizeof (ACPI_TABLE_HEADER))
512 ACPI_ERROR ((AE_INFO, "Invalid length 0x%X in RSDT/XSDT", Length));
513 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
516 Table = AcpiOsMapMemory (Address, Length);
519 return_ACPI_STATUS (AE_NO_MEMORY);
522 /* Validate the root table checksum */
524 Status = AcpiTbVerifyChecksum (Table, Length);
525 if (ACPI_FAILURE (Status))
527 AcpiOsUnmapMemory (Table, Length);
528 return_ACPI_STATUS (Status);
531 /* Calculate the number of tables described in the root table */
533 TableCount = (UINT32) ((Table->Length - sizeof (ACPI_TABLE_HEADER)) / TableEntrySize);
536 * First two entries in the table array are reserved for the DSDT and FACS,
537 * which are not actually present in the RSDT/XSDT - they come from the FADT
539 TableEntry = ACPI_CAST_PTR (UINT8, Table) + sizeof (ACPI_TABLE_HEADER);
540 AcpiGbl_RootTableList.Count = 2;
543 * Initialize the root table array from the RSDT/XSDT
545 for (i = 0; i < TableCount; i++)
547 if (AcpiGbl_RootTableList.Count >= AcpiGbl_RootTableList.Size)
549 /* There is no more room in the root table array, attempt resize */
551 Status = AcpiTbResizeRootTableList ();
552 if (ACPI_FAILURE (Status))
554 ACPI_WARNING ((AE_INFO, "Truncating %u table entries!",
555 (unsigned) (AcpiGbl_RootTableList.Size - AcpiGbl_RootTableList.Count)));
560 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
562 AcpiGbl_RootTableList.Tables[AcpiGbl_RootTableList.Count].Address =
563 AcpiTbGetRootTableEntry (TableEntry, TableEntrySize);
565 TableEntry += TableEntrySize;
566 AcpiGbl_RootTableList.Count++;
570 * It is not possible to map more than one entry in some environments,
571 * so unmap the root table here before mapping other tables
573 AcpiOsUnmapMemory (Table, Length);
576 * Complete the initialization of the root table array by examining
577 * the header of each table
579 for (i = 2; i < AcpiGbl_RootTableList.Count; i++)
581 AcpiTbInstallTable (AcpiGbl_RootTableList.Tables[i].Address,
584 /* Special case for FADT - get the DSDT and FACS */
586 if (ACPI_COMPARE_NAME (
587 &AcpiGbl_RootTableList.Tables[i].Signature, ACPI_SIG_FADT))
589 AcpiTbParseFadt (i, Flags);
593 return_ACPI_STATUS (AE_OK);