Home | History | Annotate | Line # | Download | only in tables
tbxfroot.c revision 1.5
      1 /******************************************************************************
      2  *
      3  * Module Name: tbxfroot - Find the root ACPI table (RSDT)
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2014, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #define __TBXFROOT_C__
     45 
     46 #include "acpi.h"
     47 #include "accommon.h"
     48 #include "actables.h"
     49 
     50 
     51 #define _COMPONENT          ACPI_TABLES
     52         ACPI_MODULE_NAME    ("tbxfroot")
     53 
     54 
     55 /*******************************************************************************
     56  *
     57  * FUNCTION:    AcpiTbGetRsdpLength
     58  *
     59  * PARAMETERS:  Rsdp                - Pointer to RSDP
     60  *
     61  * RETURN:      Table length
     62  *
     63  * DESCRIPTION: Get the length of the RSDP
     64  *
     65  ******************************************************************************/
     66 
     67 UINT32
     68 AcpiTbGetRsdpLength (
     69     ACPI_TABLE_RSDP         *Rsdp)
     70 {
     71 
     72     if (!ACPI_VALIDATE_RSDP_SIG (Rsdp->Signature))
     73     {
     74         /* BAD Signature */
     75 
     76         return (0);
     77     }
     78 
     79     /* "Length" field is available if table version >= 2 */
     80 
     81     if (Rsdp->Revision >= 2)
     82     {
     83         return (Rsdp->Length);
     84     }
     85     else
     86     {
     87         return (ACPI_RSDP_CHECKSUM_LENGTH);
     88     }
     89 }
     90 
     91 
     92 /*******************************************************************************
     93  *
     94  * FUNCTION:    AcpiTbValidateRsdp
     95  *
     96  * PARAMETERS:  Rsdp                - Pointer to unvalidated RSDP
     97  *
     98  * RETURN:      Status
     99  *
    100  * DESCRIPTION: Validate the RSDP (ptr)
    101  *
    102  ******************************************************************************/
    103 
    104 ACPI_STATUS
    105 AcpiTbValidateRsdp (
    106     ACPI_TABLE_RSDP         *Rsdp)
    107 {
    108 
    109     /*
    110      * The signature and checksum must both be correct
    111      *
    112      * Note: Sometimes there exists more than one RSDP in memory; the valid
    113      * RSDP has a valid checksum, all others have an invalid checksum.
    114      */
    115     if (!ACPI_VALIDATE_RSDP_SIG (Rsdp->Signature))
    116     {
    117         /* Nope, BAD Signature */
    118 
    119         return (AE_BAD_SIGNATURE);
    120     }
    121 
    122     /* Check the standard checksum */
    123 
    124     if (AcpiTbChecksum ((UINT8 *) Rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
    125     {
    126         return (AE_BAD_CHECKSUM);
    127     }
    128 
    129     /* Check extended checksum if table version >= 2 */
    130 
    131     if ((Rsdp->Revision >= 2) &&
    132         (AcpiTbChecksum ((UINT8 *) Rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0))
    133     {
    134         return (AE_BAD_CHECKSUM);
    135     }
    136 
    137     return (AE_OK);
    138 }
    139 
    140 
    141 /*******************************************************************************
    142  *
    143  * FUNCTION:    AcpiFindRootPointer
    144  *
    145  * PARAMETERS:  TableAddress            - Where the table pointer is returned
    146  *
    147  * RETURN:      Status, RSDP physical address
    148  *
    149  * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
    150  *              pointer structure. If it is found, set *RSDP to point to it.
    151  *
    152  * NOTE1:       The RSDP must be either in the first 1K of the Extended
    153  *              BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
    154  *              Only a 32-bit physical address is necessary.
    155  *
    156  * NOTE2:       This function is always available, regardless of the
    157  *              initialization state of the rest of ACPI.
    158  *
    159  ******************************************************************************/
    160 
    161 ACPI_STATUS
    162 AcpiFindRootPointer (
    163     ACPI_SIZE               *TableAddress)
    164 {
    165     UINT8                   *TablePtr;
    166     UINT8                   *MemRover;
    167     UINT32                  PhysicalAddress;
    168 
    169 
    170     ACPI_FUNCTION_TRACE (AcpiFindRootPointer);
    171 
    172 
    173     /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
    174 
    175     TablePtr = AcpiOsMapMemory (
    176                 (ACPI_PHYSICAL_ADDRESS) ACPI_EBDA_PTR_LOCATION,
    177                 ACPI_EBDA_PTR_LENGTH);
    178     if (!TablePtr)
    179     {
    180         ACPI_ERROR ((AE_INFO,
    181             "Could not map memory at 0x%8.8X for length %u",
    182             ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
    183 
    184         return_ACPI_STATUS (AE_NO_MEMORY);
    185     }
    186 
    187     ACPI_MOVE_16_TO_32 (&PhysicalAddress, TablePtr);
    188 
    189     /* Convert segment part to physical address */
    190 
    191     PhysicalAddress <<= 4;
    192     AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_PTR_LENGTH);
    193 
    194     /* EBDA present? */
    195 
    196     if (PhysicalAddress > 0x400)
    197     {
    198         /*
    199          * 1b) Search EBDA paragraphs (EBDA is required to be a
    200          *     minimum of 1K length)
    201          */
    202         TablePtr = AcpiOsMapMemory (
    203                     (ACPI_PHYSICAL_ADDRESS) PhysicalAddress,
    204                     ACPI_EBDA_WINDOW_SIZE);
    205         if (!TablePtr)
    206         {
    207             ACPI_ERROR ((AE_INFO,
    208                 "Could not map memory at 0x%8.8X for length %u",
    209                 PhysicalAddress, ACPI_EBDA_WINDOW_SIZE));
    210 
    211             return_ACPI_STATUS (AE_NO_MEMORY);
    212         }
    213 
    214         MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_EBDA_WINDOW_SIZE);
    215         AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_WINDOW_SIZE);
    216 
    217         if (MemRover)
    218         {
    219             /* Return the physical address */
    220 
    221             PhysicalAddress += (UINT32) ACPI_PTR_DIFF (MemRover, TablePtr);
    222 
    223             *TableAddress = PhysicalAddress;
    224             return_ACPI_STATUS (AE_OK);
    225         }
    226     }
    227 
    228     /*
    229      * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
    230      */
    231     TablePtr = AcpiOsMapMemory (
    232                 (ACPI_PHYSICAL_ADDRESS) ACPI_HI_RSDP_WINDOW_BASE,
    233                 ACPI_HI_RSDP_WINDOW_SIZE);
    234 
    235     if (!TablePtr)
    236     {
    237         ACPI_ERROR ((AE_INFO,
    238             "Could not map memory at 0x%8.8X for length %u",
    239             ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
    240 
    241         return_ACPI_STATUS (AE_NO_MEMORY);
    242     }
    243 
    244     MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
    245     AcpiOsUnmapMemory (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
    246 
    247     if (MemRover)
    248     {
    249         /* Return the physical address */
    250 
    251         PhysicalAddress = (UINT32)
    252             (ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (MemRover, TablePtr));
    253 
    254         *TableAddress = PhysicalAddress;
    255         return_ACPI_STATUS (AE_OK);
    256     }
    257 
    258     /* A valid RSDP was not found */
    259 
    260     ACPI_BIOS_ERROR ((AE_INFO, "A valid RSDP was not found"));
    261     return_ACPI_STATUS (AE_NOT_FOUND);
    262 }
    263 
    264 ACPI_EXPORT_SYMBOL (AcpiFindRootPointer)
    265 
    266 
    267 /*******************************************************************************
    268  *
    269  * FUNCTION:    AcpiTbScanMemoryForRsdp
    270  *
    271  * PARAMETERS:  StartAddress        - Starting pointer for search
    272  *              Length              - Maximum length to search
    273  *
    274  * RETURN:      Pointer to the RSDP if found, otherwise NULL.
    275  *
    276  * DESCRIPTION: Search a block of memory for the RSDP signature
    277  *
    278  ******************************************************************************/
    279 
    280 UINT8 *
    281 AcpiTbScanMemoryForRsdp (
    282     UINT8                   *StartAddress,
    283     UINT32                  Length)
    284 {
    285     ACPI_STATUS             Status;
    286     UINT8                   *MemRover;
    287     UINT8                   *EndAddress;
    288 
    289 
    290     ACPI_FUNCTION_TRACE (TbScanMemoryForRsdp);
    291 
    292 
    293     EndAddress = StartAddress + Length;
    294 
    295     /* Search from given start address for the requested length */
    296 
    297     for (MemRover = StartAddress; MemRover < EndAddress;
    298          MemRover += ACPI_RSDP_SCAN_STEP)
    299     {
    300         /* The RSDP signature and checksum must both be correct */
    301 
    302         Status = AcpiTbValidateRsdp (ACPI_CAST_PTR (ACPI_TABLE_RSDP, MemRover));
    303         if (ACPI_SUCCESS (Status))
    304         {
    305             /* Sig and checksum valid, we have found a real RSDP */
    306 
    307             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    308                 "RSDP located at physical address %p\n", MemRover));
    309             return_PTR (MemRover);
    310         }
    311 
    312         /* No sig match or bad checksum, keep searching */
    313     }
    314 
    315     /* Searched entire block, no RSDP was found */
    316 
    317     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    318         "Searched entire block from %p, valid RSDP was not found\n",
    319         StartAddress));
    320     return_PTR (NULL);
    321 }
    322