Home | History | Annotate | Line # | Download | only in tables
tbfind.c revision 1.1.1.4.2.3
      1          1.1    jruoho /******************************************************************************
      2          1.1    jruoho  *
      3          1.1    jruoho  * Module Name: tbfind   - find table
      4          1.1    jruoho  *
      5          1.1    jruoho  *****************************************************************************/
      6          1.1    jruoho 
      7      1.1.1.2    jruoho /*
      8  1.1.1.4.2.3     skrll  * Copyright (C) 2000 - 2016, Intel Corp.
      9          1.1    jruoho  * All rights reserved.
     10          1.1    jruoho  *
     11      1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13      1.1.1.2    jruoho  * are met:
     14      1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1.1.2    jruoho  *    without modification.
     17      1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1.1.2    jruoho  *    binary redistribution.
     22      1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25      1.1.1.2    jruoho  *
     26      1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1.1.2    jruoho  * Software Foundation.
     29      1.1.1.2    jruoho  *
     30      1.1.1.2    jruoho  * NO WARRANTY
     31      1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1.1.2    jruoho  */
     43          1.1    jruoho 
     44          1.1    jruoho #include "acpi.h"
     45          1.1    jruoho #include "accommon.h"
     46          1.1    jruoho #include "actables.h"
     47          1.1    jruoho 
     48          1.1    jruoho #define _COMPONENT          ACPI_TABLES
     49          1.1    jruoho         ACPI_MODULE_NAME    ("tbfind")
     50          1.1    jruoho 
     51          1.1    jruoho 
     52          1.1    jruoho /*******************************************************************************
     53          1.1    jruoho  *
     54          1.1    jruoho  * FUNCTION:    AcpiTbFindTable
     55          1.1    jruoho  *
     56          1.1    jruoho  * PARAMETERS:  Signature           - String with ACPI table signature
     57          1.1    jruoho  *              OemId               - String with the table OEM ID
     58          1.1    jruoho  *              OemTableId          - String with the OEM Table ID
     59          1.1    jruoho  *              TableIndex          - Where the table index is returned
     60          1.1    jruoho  *
     61          1.1    jruoho  * RETURN:      Status and table index
     62          1.1    jruoho  *
     63          1.1    jruoho  * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
     64          1.1    jruoho  *              Signature, OEM ID and OEM Table ID. Returns an index that can
     65          1.1    jruoho  *              be used to get the table header or entire table.
     66          1.1    jruoho  *
     67          1.1    jruoho  ******************************************************************************/
     68          1.1    jruoho 
     69          1.1    jruoho ACPI_STATUS
     70          1.1    jruoho AcpiTbFindTable (
     71          1.1    jruoho     char                    *Signature,
     72          1.1    jruoho     char                    *OemId,
     73          1.1    jruoho     char                    *OemTableId,
     74          1.1    jruoho     UINT32                  *TableIndex)
     75          1.1    jruoho {
     76          1.1    jruoho     ACPI_STATUS             Status;
     77          1.1    jruoho     ACPI_TABLE_HEADER       Header;
     78  1.1.1.4.2.3     skrll     UINT32                  i;
     79          1.1    jruoho 
     80          1.1    jruoho 
     81          1.1    jruoho     ACPI_FUNCTION_TRACE (TbFindTable);
     82          1.1    jruoho 
     83          1.1    jruoho 
     84  1.1.1.4.2.3     skrll     /* Validate the input table signature */
     85  1.1.1.4.2.3     skrll 
     86  1.1.1.4.2.3     skrll     if (!AcpiIsValidSignature (Signature))
     87  1.1.1.4.2.3     skrll     {
     88  1.1.1.4.2.3     skrll         return_ACPI_STATUS (AE_BAD_SIGNATURE);
     89  1.1.1.4.2.3     skrll     }
     90  1.1.1.4.2.3     skrll 
     91  1.1.1.4.2.3     skrll     /* Don't allow the OEM strings to be too long */
     92  1.1.1.4.2.3     skrll 
     93  1.1.1.4.2.3     skrll     if ((strlen (OemId) > ACPI_OEM_ID_SIZE) ||
     94  1.1.1.4.2.3     skrll         (strlen (OemTableId) > ACPI_OEM_TABLE_ID_SIZE))
     95  1.1.1.4.2.3     skrll     {
     96  1.1.1.4.2.3     skrll         return_ACPI_STATUS (AE_AML_STRING_LIMIT);
     97  1.1.1.4.2.3     skrll     }
     98  1.1.1.4.2.3     skrll 
     99          1.1    jruoho     /* Normalize the input strings */
    100          1.1    jruoho 
    101  1.1.1.4.2.2     skrll     memset (&Header, 0, sizeof (ACPI_TABLE_HEADER));
    102      1.1.1.3  christos     ACPI_MOVE_NAME (Header.Signature, Signature);
    103  1.1.1.4.2.2     skrll     strncpy (Header.OemId, OemId, ACPI_OEM_ID_SIZE);
    104  1.1.1.4.2.2     skrll     strncpy (Header.OemTableId, OemTableId, ACPI_OEM_TABLE_ID_SIZE);
    105          1.1    jruoho 
    106          1.1    jruoho     /* Search for the table */
    107          1.1    jruoho 
    108          1.1    jruoho     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    109          1.1    jruoho     {
    110  1.1.1.4.2.2     skrll         if (memcmp (&(AcpiGbl_RootTableList.Tables[i].Signature),
    111  1.1.1.4.2.3     skrll             Header.Signature, ACPI_NAME_SIZE))
    112          1.1    jruoho         {
    113          1.1    jruoho             /* Not the requested table */
    114          1.1    jruoho 
    115          1.1    jruoho             continue;
    116          1.1    jruoho         }
    117          1.1    jruoho 
    118          1.1    jruoho         /* Table with matching signature has been found */
    119          1.1    jruoho 
    120          1.1    jruoho         if (!AcpiGbl_RootTableList.Tables[i].Pointer)
    121          1.1    jruoho         {
    122          1.1    jruoho             /* Table is not currently mapped, map it */
    123          1.1    jruoho 
    124      1.1.1.4  christos             Status = AcpiTbValidateTable (&AcpiGbl_RootTableList.Tables[i]);
    125          1.1    jruoho             if (ACPI_FAILURE (Status))
    126          1.1    jruoho             {
    127          1.1    jruoho                 return_ACPI_STATUS (Status);
    128          1.1    jruoho             }
    129          1.1    jruoho 
    130          1.1    jruoho             if (!AcpiGbl_RootTableList.Tables[i].Pointer)
    131          1.1    jruoho             {
    132          1.1    jruoho                 continue;
    133          1.1    jruoho             }
    134          1.1    jruoho         }
    135          1.1    jruoho 
    136          1.1    jruoho         /* Check for table match on all IDs */
    137          1.1    jruoho 
    138  1.1.1.4.2.2     skrll         if (!memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->Signature,
    139  1.1.1.4.2.3     skrll                 Header.Signature, ACPI_NAME_SIZE) &&
    140          1.1    jruoho             (!OemId[0] ||
    141  1.1.1.4.2.2     skrll              !memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->OemId,
    142  1.1.1.4.2.3     skrll                  Header.OemId, ACPI_OEM_ID_SIZE)) &&
    143          1.1    jruoho             (!OemTableId[0] ||
    144  1.1.1.4.2.2     skrll              !memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->OemTableId,
    145  1.1.1.4.2.3     skrll                  Header.OemTableId, ACPI_OEM_TABLE_ID_SIZE)))
    146          1.1    jruoho         {
    147          1.1    jruoho             *TableIndex = i;
    148          1.1    jruoho 
    149          1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
    150          1.1    jruoho                 Header.Signature));
    151          1.1    jruoho             return_ACPI_STATUS (AE_OK);
    152          1.1    jruoho         }
    153          1.1    jruoho     }
    154          1.1    jruoho 
    155          1.1    jruoho     return_ACPI_STATUS (AE_NOT_FOUND);
    156          1.1    jruoho }
    157