Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/tbutils.c need to be fixed.

0001 /******************************************************************************
0002  *
0003  * Module Name: tbutils   - table utilities
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 #define __TBUTILS_C__
0117 
0118 #include "acpi.h"
0119 #include "accommon.h"
0120 #include "actables.h"
0121 
0122 #define _COMPONENT          ACPI_TABLES
0123         ACPI_MODULE_NAME    ("tbutils")
0124 
0125 /* Local prototypes */
0126 
0127 static void
0128 AcpiTbFixString (
0129     char                    *String,
0130     ACPI_SIZE               Length);
0131 
0132 static void
0133 AcpiTbCleanupTableHeader (
0134     ACPI_TABLE_HEADER       *OutHeader,
0135     ACPI_TABLE_HEADER       *Header);
0136 
0137 static ACPI_PHYSICAL_ADDRESS
0138 AcpiTbGetRootTableEntry (
0139     UINT8                   *TableEntry,
0140     UINT32                  TableEntrySize);
0141 
0142 
0143 /*******************************************************************************
0144  *
0145  * FUNCTION:    AcpiTbInitializeFacs
0146  *
0147  * PARAMETERS:  None
0148  *
0149  * RETURN:      Status
0150  *
0151  * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
0152  *              for accessing the Global Lock and Firmware Waking Vector
0153  *
0154  ******************************************************************************/
0155 
0156 ACPI_STATUS
0157 AcpiTbInitializeFacs (
0158     void)
0159 {
0160     ACPI_STATUS             Status;
0161 
0162 
0163     Status = AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS,
0164                 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &AcpiGbl_FACS));
0165     return (Status);
0166 }
0167 
0168 
0169 /*******************************************************************************
0170  *
0171  * FUNCTION:    AcpiTbTablesLoaded
0172  *
0173  * PARAMETERS:  None
0174  *
0175  * RETURN:      TRUE if required ACPI tables are loaded
0176  *
0177  * DESCRIPTION: Determine if the minimum required ACPI tables are present
0178  *              (FADT, FACS, DSDT)
0179  *
0180  ******************************************************************************/
0181 
0182 BOOLEAN
0183 AcpiTbTablesLoaded (
0184     void)
0185 {
0186 
0187     if (AcpiGbl_RootTableList.Count >= 3)
0188     {
0189         return (TRUE);
0190     }
0191 
0192     return (FALSE);
0193 }
0194 
0195 
0196 /*******************************************************************************
0197  *
0198  * FUNCTION:    AcpiTbFixString
0199  *
0200  * PARAMETERS:  String              - String to be repaired
0201  *              Length              - Maximum length
0202  *
0203  * RETURN:      None
0204  *
0205  * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
0206  *              with a question mark '?'.
0207  *
0208  ******************************************************************************/
0209 
0210 static void
0211 AcpiTbFixString (
0212     char                    *String,
0213     ACPI_SIZE               Length)
0214 {
0215 
0216     while (Length && *String)
0217     {
0218         if (!ACPI_IS_PRINT (*String))
0219         {
0220             *String = '?';
0221         }
0222         String++;
0223         Length--;
0224     }
0225 }
0226 
0227 
0228 /*******************************************************************************
0229  *
0230  * FUNCTION:    AcpiTbCleanupTableHeader
0231  *
0232  * PARAMETERS:  OutHeader           - Where the cleaned header is returned
0233  *              Header              - Input ACPI table header
0234  *
0235  * RETURN:      Returns the cleaned header in OutHeader
0236  *
0237  * DESCRIPTION: Copy the table header and ensure that all "string" fields in
0238  *              the header consist of printable characters.
0239  *
0240  ******************************************************************************/
0241 
0242 static void
0243 AcpiTbCleanupTableHeader (
0244     ACPI_TABLE_HEADER       *OutHeader,
0245     ACPI_TABLE_HEADER       *Header)
0246 {
0247 
0248     ACPI_MEMCPY (OutHeader, Header, sizeof (ACPI_TABLE_HEADER));
0249 
0250     AcpiTbFixString (OutHeader->Signature, ACPI_NAME_SIZE);
0251     AcpiTbFixString (OutHeader->OemId, ACPI_OEM_ID_SIZE);
0252     AcpiTbFixString (OutHeader->OemTableId, ACPI_OEM_TABLE_ID_SIZE);
0253     AcpiTbFixString (OutHeader->AslCompilerId, ACPI_NAME_SIZE);
0254 }
0255 
0256 
0257 /*******************************************************************************
0258  *
0259  * FUNCTION:    AcpiTbPrintTableHeader
0260  *
0261  * PARAMETERS:  Address             - Table physical address
0262  *              Header              - Table header
0263  *
0264  * RETURN:      None
0265  *
0266  * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
0267  *
0268  ******************************************************************************/
0269 
0270 void
0271 AcpiTbPrintTableHeader (
0272     ACPI_PHYSICAL_ADDRESS   Address,
0273     ACPI_TABLE_HEADER       *Header)
0274 {
0275     ACPI_TABLE_HEADER       LocalHeader;
0276 
0277 
0278     /*
0279      * The reason that the Address is cast to a void pointer is so that we
0280      * can use %p which will work properly on both 32-bit and 64-bit hosts.
0281      */
0282     if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_FACS))
0283     {
0284         /* FACS only has signature and length fields */
0285 
0286         ACPI_INFO ((AE_INFO, "%4.4s %p %05X",
0287             Header->Signature, ACPI_CAST_PTR (void, Address),
0288             Header->Length));
0289     }
0290     else if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_RSDP))
0291     {
0292         /* RSDP has no common fields */
0293 
0294         ACPI_MEMCPY (LocalHeader.OemId,
0295             ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->OemId, ACPI_OEM_ID_SIZE);
0296         AcpiTbFixString (LocalHeader.OemId, ACPI_OEM_ID_SIZE);
0297 
0298         ACPI_INFO ((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
0299             ACPI_CAST_PTR (void, Address),
0300             (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ?
0301                 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20,
0302             ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision,
0303             LocalHeader.OemId));
0304     }
0305     else
0306     {
0307         /* Standard ACPI table with full common header */
0308 
0309         AcpiTbCleanupTableHeader (&LocalHeader, Header);
0310 
0311         ACPI_INFO ((AE_INFO,
0312             "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
0313             LocalHeader.Signature, ACPI_CAST_PTR (void, Address),
0314             LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId,
0315             LocalHeader.OemTableId, LocalHeader.OemRevision,
0316             LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision));
0317     }
0318 }
0319 
0320 
0321 /*******************************************************************************
0322  *
0323  * FUNCTION:    AcpiTbValidateChecksum
0324  *
0325  * PARAMETERS:  Table               - ACPI table to verify
0326  *              Length              - Length of entire table
0327  *
0328  * RETURN:      Status
0329  *
0330  * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
0331  *              exception on bad checksum.
0332  *
0333  ******************************************************************************/
0334 
0335 ACPI_STATUS
0336 AcpiTbVerifyChecksum (
0337     ACPI_TABLE_HEADER       *Table,
0338     UINT32                  Length)
0339 {
0340     UINT8                   Checksum;
0341 
0342 
0343     /* Compute the checksum on the table */
0344 
0345     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Length);
0346 
0347     /* Checksum ok? (should be zero) */
0348 
0349     if (Checksum)
0350     {
0351         ACPI_WARNING ((AE_INFO,
0352             "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
0353             Table->Signature, Table->Checksum,
0354             (UINT8) (Table->Checksum - Checksum)));
0355 
0356 #if (ACPI_CHECKSUM_ABORT)
0357         return (AE_BAD_CHECKSUM);
0358 #endif
0359     }
0360 
0361     return (AE_OK);
0362 }
0363 
0364 
0365 /*******************************************************************************
0366  *
0367  * FUNCTION:    AcpiTbChecksum
0368  *
0369  * PARAMETERS:  Buffer          - Pointer to memory region to be checked
0370  *              Length          - Length of this memory region
0371  *
0372  * RETURN:      Checksum (UINT8)
0373  *
0374  * DESCRIPTION: Calculates circular checksum of memory region.
0375  *
0376  ******************************************************************************/
0377 
0378 UINT8
0379 AcpiTbChecksum (
0380     UINT8                   *Buffer,
0381     UINT32                  Length)
0382 {
0383     UINT8                   Sum = 0;
0384     UINT8                   *End = Buffer + Length;
0385 
0386 
0387     while (Buffer < End)
0388     {
0389         Sum = (UINT8) (Sum + *(Buffer++));
0390     }
0391 
0392     return Sum;
0393 }
0394 
0395 
0396 /*******************************************************************************
0397  *
0398  * FUNCTION:    AcpiTbInstallTable
0399  *
0400  * PARAMETERS:  Address                 - Physical address of DSDT or FACS
0401  *              Signature               - Table signature, NULL if no need to
0402  *                                        match
0403  *              TableIndex              - Index into root table array
0404  *
0405  * RETURN:      None
0406  *
0407  * DESCRIPTION: Install an ACPI table into the global data structure. The
0408  *              table override mechanism is implemented here to allow the host
0409  *              OS to replace any table before it is installed in the root
0410  *              table array.
0411  *
0412  ******************************************************************************/
0413 
0414 void
0415 AcpiTbInstallTable (
0416     ACPI_PHYSICAL_ADDRESS   Address,
0417     char                    *Signature,
0418     UINT32                  TableIndex)
0419 {
0420     UINT8                   Flags;
0421     ACPI_STATUS             Status;
0422     ACPI_TABLE_HEADER       *TableToInstall;
0423     ACPI_TABLE_HEADER       *MappedTable;
0424     ACPI_TABLE_HEADER       *OverrideTable = NULL;
0425 
0426 
0427     if (!Address)
0428     {
0429         ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]",
0430             Signature));
0431         return;
0432     }
0433 
0434     /* Map just the table header */
0435 
0436     MappedTable = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
0437     if (!MappedTable)
0438     {
0439         return;
0440     }
0441 
0442     /* If a particular signature is expected (DSDT/FACS), it must match */
0443 
0444     if (Signature &&
0445         !ACPI_COMPARE_NAME (MappedTable->Signature, Signature))
0446     {
0447         ACPI_ERROR ((AE_INFO,
0448             "Invalid signature 0x%X for ACPI table, expected [%s]",
0449             *ACPI_CAST_PTR (UINT32, MappedTable->Signature), Signature));
0450         goto UnmapAndExit;
0451     }
0452 
0453     /*
0454      * ACPI Table Override:
0455      *
0456      * Before we install the table, let the host OS override it with a new
0457      * one if desired. Any table within the RSDT/XSDT can be replaced,
0458      * including the DSDT which is pointed to by the FADT.
0459      */
0460     Status = AcpiOsTableOverride (MappedTable, &OverrideTable);
0461     if (ACPI_SUCCESS (Status) && OverrideTable)
0462     {
0463         ACPI_INFO ((AE_INFO,
0464             "%4.4s @ 0x%p Table override, replaced with:",
0465             MappedTable->Signature, ACPI_CAST_PTR (void, Address)));
0466 
0467         AcpiGbl_RootTableList.Tables[TableIndex].Pointer = OverrideTable;
0468         Address = ACPI_PTR_TO_PHYSADDR (OverrideTable);
0469 
0470         TableToInstall = OverrideTable;
0471         Flags = ACPI_TABLE_ORIGIN_OVERRIDE;
0472     }
0473     else
0474     {
0475         TableToInstall = MappedTable;
0476         Flags = ACPI_TABLE_ORIGIN_MAPPED;
0477     }
0478 
0479     /* Initialize the table entry */
0480 
0481     AcpiGbl_RootTableList.Tables[TableIndex].Address = Address;
0482     AcpiGbl_RootTableList.Tables[TableIndex].Length = TableToInstall->Length;
0483     AcpiGbl_RootTableList.Tables[TableIndex].Flags = Flags;
0484 
0485     ACPI_MOVE_32_TO_32 (
0486         &(AcpiGbl_RootTableList.Tables[TableIndex].Signature),
0487         TableToInstall->Signature);
0488 
0489     AcpiTbPrintTableHeader (Address, TableToInstall);
0490 
0491     if (TableIndex == ACPI_TABLE_INDEX_DSDT)
0492     {
0493         /* Global integer width is based upon revision of the DSDT */
0494 
0495         AcpiUtSetIntegerWidth (TableToInstall->Revision);
0496     }
0497 
0498 UnmapAndExit:
0499     AcpiOsUnmapMemory (MappedTable, sizeof (ACPI_TABLE_HEADER));
0500 }
0501 
0502 
0503 /*******************************************************************************
0504  *
0505  * FUNCTION:    AcpiTbGetRootTableEntry
0506  *
0507  * PARAMETERS:  TableEntry          - Pointer to the RSDT/XSDT table entry
0508  *              TableEntrySize      - sizeof 32 or 64 (RSDT or XSDT)
0509  *
0510  * RETURN:      Physical address extracted from the root table
0511  *
0512  * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
0513  *              both 32-bit and 64-bit platforms
0514  *
0515  * NOTE:        ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on
0516  *              64-bit platforms.
0517  *
0518  ******************************************************************************/
0519 
0520 static ACPI_PHYSICAL_ADDRESS
0521 AcpiTbGetRootTableEntry (
0522     UINT8                   *TableEntry,
0523     UINT32                  TableEntrySize)
0524 {
0525     UINT64                  Address64;
0526 
0527 
0528     /*
0529      * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
0530      * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
0531      */
0532     if (TableEntrySize == sizeof (UINT32))
0533     {
0534         /*
0535          * 32-bit platform, RSDT: Return 32-bit table entry
0536          * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
0537          */
0538         return ((ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST_PTR (UINT32, TableEntry)));
0539     }
0540     else
0541     {
0542         /*
0543          * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
0544          * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
0545          *  return 64-bit
0546          */
0547         ACPI_MOVE_64_TO_64 (&Address64, TableEntry);
0548 
0549 #if ACPI_MACHINE_WIDTH == 32
0550         if (Address64 > ACPI_UINT32_MAX)
0551         {
0552             /* Will truncate 64-bit address to 32 bits, issue warning */
0553 
0554             ACPI_WARNING ((AE_INFO,
0555                 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X),"
0556                 " truncating",
0557                 ACPI_FORMAT_UINT64 (Address64)));
0558         }
0559 #endif
0560         return ((ACPI_PHYSICAL_ADDRESS) (Address64));
0561     }
0562 }
0563 
0564 
0565 /*******************************************************************************
0566  *
0567  * FUNCTION:    AcpiTbParseRootTable
0568  *
0569  * PARAMETERS:  Rsdp                    - Pointer to the RSDP
0570  *
0571  * RETURN:      Status
0572  *
0573  * DESCRIPTION: This function is called to parse the Root System Description
0574  *              Table (RSDT or XSDT)
0575  *
0576  * NOTE:        Tables are mapped (not copied) for efficiency. The FACS must
0577  *              be mapped and cannot be copied because it contains the actual
0578  *              memory location of the ACPI Global Lock.
0579  *
0580  ******************************************************************************/
0581 
0582 ACPI_STATUS
0583 AcpiTbParseRootTable (
0584     ACPI_PHYSICAL_ADDRESS   RsdpAddress)
0585 {
0586     ACPI_TABLE_RSDP         *Rsdp;
0587     UINT32                  TableEntrySize;
0588     UINT32                  i;
0589     UINT32                  TableCount;
0590     ACPI_TABLE_HEADER       *Table;
0591     ACPI_PHYSICAL_ADDRESS   Address;
0592     UINT32                  Length;
0593     UINT8                   *TableEntry;
0594     ACPI_STATUS             Status;
0595 
0596 
0597     ACPI_FUNCTION_TRACE (TbParseRootTable);
0598 
0599 
0600     /*
0601      * Map the entire RSDP and extract the address of the RSDT or XSDT
0602      */
0603     Rsdp = AcpiOsMapMemory (RsdpAddress, sizeof (ACPI_TABLE_RSDP));
0604     if (!Rsdp)
0605     {
0606         return_ACPI_STATUS (AE_NO_MEMORY);
0607     }
0608 
0609     AcpiTbPrintTableHeader (RsdpAddress,
0610         ACPI_CAST_PTR (ACPI_TABLE_HEADER, Rsdp));
0611 
0612     /* Differentiate between RSDT and XSDT root tables */
0613 
0614     if (Rsdp->Revision > 1 && Rsdp->XsdtPhysicalAddress)
0615     {
0616         /*
0617          * Root table is an XSDT (64-bit physical addresses). We must use the
0618          * XSDT if the revision is > 1 and the XSDT pointer is present, as per
0619          * the ACPI specification.
0620          */
0621         Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->XsdtPhysicalAddress;
0622         TableEntrySize = sizeof (UINT64);
0623     }
0624     else
0625     {
0626         /* Root table is an RSDT (32-bit physical addresses) */
0627 
0628         Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->RsdtPhysicalAddress;
0629         TableEntrySize = sizeof (UINT32);
0630     }
0631 
0632     /*
0633      * It is not possible to map more than one entry in some environments,
0634      * so unmap the RSDP here before mapping other tables
0635      */
0636     AcpiOsUnmapMemory (Rsdp, sizeof (ACPI_TABLE_RSDP));
0637 
0638 
0639     /* Map the RSDT/XSDT table header to get the full table length */
0640 
0641     Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
0642     if (!Table)
0643     {
0644         return_ACPI_STATUS (AE_NO_MEMORY);
0645     }
0646 
0647     AcpiTbPrintTableHeader (Address, Table);
0648 
0649     /* Get the length of the full table, verify length and map entire table */
0650 
0651     Length = Table->Length;
0652     AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
0653 
0654     if (Length < sizeof (ACPI_TABLE_HEADER))
0655     {
0656         ACPI_ERROR ((AE_INFO, "Invalid length 0x%X in RSDT/XSDT", Length));
0657         return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
0658     }
0659 
0660     Table = AcpiOsMapMemory (Address, Length);
0661     if (!Table)
0662     {
0663         return_ACPI_STATUS (AE_NO_MEMORY);
0664     }
0665 
0666     /* Validate the root table checksum */
0667 
0668     Status = AcpiTbVerifyChecksum (Table, Length);
0669     if (ACPI_FAILURE (Status))
0670     {
0671         AcpiOsUnmapMemory (Table, Length);
0672         return_ACPI_STATUS (Status);
0673     }
0674 
0675     /* Calculate the number of tables described in the root table */
0676 
0677     TableCount = (UINT32) ((Table->Length - sizeof (ACPI_TABLE_HEADER)) /
0678         TableEntrySize);
0679 
0680     /*
0681      * First two entries in the table array are reserved for the DSDT
0682      * and FACS, which are not actually present in the RSDT/XSDT - they
0683      * come from the FADT
0684      */
0685     TableEntry = ACPI_CAST_PTR (UINT8, Table) + sizeof (ACPI_TABLE_HEADER);
0686     AcpiGbl_RootTableList.Count = 2;
0687 
0688     /*
0689      * Initialize the root table array from the RSDT/XSDT
0690      */
0691     for (i = 0; i < TableCount; i++)
0692     {
0693         if (AcpiGbl_RootTableList.Count >= AcpiGbl_RootTableList.Size)
0694         {
0695             /* There is no more room in the root table array, attempt resize */
0696 
0697             Status = AcpiTbResizeRootTableList ();
0698             if (ACPI_FAILURE (Status))
0699             {
0700                 ACPI_WARNING ((AE_INFO, "Truncating %u table entries!",
0701                     (unsigned) (TableCount -
0702                     (AcpiGbl_RootTableList.Count - 2))));
0703                 break;
0704             }
0705         }
0706 
0707         /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
0708 
0709         AcpiGbl_RootTableList.Tables[AcpiGbl_RootTableList.Count].Address =
0710             AcpiTbGetRootTableEntry (TableEntry, TableEntrySize);
0711 
0712         TableEntry += TableEntrySize;
0713         AcpiGbl_RootTableList.Count++;
0714     }
0715 
0716     /*
0717      * It is not possible to map more than one entry in some environments,
0718      * so unmap the root table here before mapping other tables
0719      */
0720     AcpiOsUnmapMemory (Table, Length);
0721 
0722     /*
0723      * Complete the initialization of the root table array by examining
0724      * the header of each table
0725      */
0726     for (i = 2; i < AcpiGbl_RootTableList.Count; i++)
0727     {
0728         AcpiTbInstallTable (AcpiGbl_RootTableList.Tables[i].Address,
0729             NULL, i);
0730 
0731         /* Special case for FADT - get the DSDT and FACS */
0732 
0733         if (ACPI_COMPARE_NAME (
0734                 &AcpiGbl_RootTableList.Tables[i].Signature, ACPI_SIG_FADT))
0735         {
0736             AcpiTbParseFadt (i);
0737         }
0738     }
0739 
0740     return_ACPI_STATUS (AE_OK);
0741 }