Home | History | Annotate | Line # | Download | only in tables
tbfind.c revision 1.1.1.10.12.1
      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.10.12.1  pgoyette  * Copyright (C) 2000 - 2018, 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.1.9  christos     ACPI_STATUS             Status = AE_OK;
     77            1.1    jruoho     ACPI_TABLE_HEADER       Header;
     78        1.1.1.7  christos     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.7  christos     /* Validate the input table signature */
     85        1.1.1.7  christos 
     86        1.1.1.8  christos     if (!AcpiUtValidNameseg (Signature))
     87        1.1.1.7  christos     {
     88        1.1.1.7  christos         return_ACPI_STATUS (AE_BAD_SIGNATURE);
     89        1.1.1.7  christos     }
     90        1.1.1.7  christos 
     91        1.1.1.7  christos     /* Don't allow the OEM strings to be too long */
     92        1.1.1.7  christos 
     93        1.1.1.7  christos     if ((strlen (OemId) > ACPI_OEM_ID_SIZE) ||
     94        1.1.1.7  christos         (strlen (OemTableId) > ACPI_OEM_TABLE_ID_SIZE))
     95        1.1.1.7  christos     {
     96        1.1.1.7  christos         return_ACPI_STATUS (AE_AML_STRING_LIMIT);
     97        1.1.1.7  christos     }
     98        1.1.1.7  christos 
     99            1.1    jruoho     /* Normalize the input strings */
    100            1.1    jruoho 
    101        1.1.1.6  christos     memset (&Header, 0, sizeof (ACPI_TABLE_HEADER));
    102        1.1.1.3  christos     ACPI_MOVE_NAME (Header.Signature, Signature);
    103        1.1.1.6  christos     strncpy (Header.OemId, OemId, ACPI_OEM_ID_SIZE);
    104        1.1.1.6  christos     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.1.9  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    109            1.1    jruoho     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    110            1.1    jruoho     {
    111        1.1.1.6  christos         if (memcmp (&(AcpiGbl_RootTableList.Tables[i].Signature),
    112        1.1.1.7  christos             Header.Signature, ACPI_NAME_SIZE))
    113            1.1    jruoho         {
    114            1.1    jruoho             /* Not the requested table */
    115            1.1    jruoho 
    116            1.1    jruoho             continue;
    117            1.1    jruoho         }
    118            1.1    jruoho 
    119            1.1    jruoho         /* Table with matching signature has been found */
    120            1.1    jruoho 
    121            1.1    jruoho         if (!AcpiGbl_RootTableList.Tables[i].Pointer)
    122            1.1    jruoho         {
    123            1.1    jruoho             /* Table is not currently mapped, map it */
    124            1.1    jruoho 
    125        1.1.1.4  christos             Status = AcpiTbValidateTable (&AcpiGbl_RootTableList.Tables[i]);
    126            1.1    jruoho             if (ACPI_FAILURE (Status))
    127            1.1    jruoho             {
    128        1.1.1.9  christos                 goto UnlockAndExit;
    129            1.1    jruoho             }
    130            1.1    jruoho 
    131            1.1    jruoho             if (!AcpiGbl_RootTableList.Tables[i].Pointer)
    132            1.1    jruoho             {
    133            1.1    jruoho                 continue;
    134            1.1    jruoho             }
    135            1.1    jruoho         }
    136            1.1    jruoho 
    137            1.1    jruoho         /* Check for table match on all IDs */
    138            1.1    jruoho 
    139        1.1.1.6  christos         if (!memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->Signature,
    140        1.1.1.7  christos                 Header.Signature, ACPI_NAME_SIZE) &&
    141            1.1    jruoho             (!OemId[0] ||
    142        1.1.1.6  christos              !memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->OemId,
    143        1.1.1.7  christos                  Header.OemId, ACPI_OEM_ID_SIZE)) &&
    144            1.1    jruoho             (!OemTableId[0] ||
    145        1.1.1.6  christos              !memcmp (AcpiGbl_RootTableList.Tables[i].Pointer->OemTableId,
    146        1.1.1.7  christos                  Header.OemTableId, ACPI_OEM_TABLE_ID_SIZE)))
    147            1.1    jruoho         {
    148            1.1    jruoho             *TableIndex = i;
    149            1.1    jruoho 
    150            1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
    151            1.1    jruoho                 Header.Signature));
    152        1.1.1.9  christos             goto UnlockAndExit;
    153            1.1    jruoho         }
    154            1.1    jruoho     }
    155        1.1.1.9  christos     Status = AE_NOT_FOUND;
    156            1.1    jruoho 
    157        1.1.1.9  christos UnlockAndExit:
    158        1.1.1.9  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    159        1.1.1.9  christos     return_ACPI_STATUS (Status);
    160            1.1    jruoho }
    161