tbfind.c revision 193267
1167802Sjkim/******************************************************************************
2167802Sjkim *
3167802Sjkim * Module Name: tbfind   - find table
4167802Sjkim *
5167802Sjkim *****************************************************************************/
6167802Sjkim
7167802Sjkim/******************************************************************************
8167802Sjkim *
9167802Sjkim * 1. Copyright Notice
10167802Sjkim *
11193267Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12167802Sjkim * All rights reserved.
13167802Sjkim *
14167802Sjkim * 2. License
15167802Sjkim *
16167802Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17167802Sjkim * rights.  You may have additional license terms from the party that provided
18167802Sjkim * you this software, covering your right to use that party's intellectual
19167802Sjkim * property rights.
20167802Sjkim *
21167802Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22167802Sjkim * copy of the source code appearing in this file ("Covered Code") an
23167802Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24167802Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25167802Sjkim * make derivatives, distribute, use and display any portion of the Covered
26167802Sjkim * Code in any form, with the right to sublicense such rights; and
27167802Sjkim *
28167802Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29167802Sjkim * license (with the right to sublicense), under only those claims of Intel
30167802Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31167802Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32167802Sjkim * solely to the minimum extent necessary to exercise the above copyright
33167802Sjkim * license, and in no event shall the patent license extend to any additions
34167802Sjkim * to or modifications of the Original Intel Code.  No other license or right
35167802Sjkim * is granted directly or by implication, estoppel or otherwise;
36167802Sjkim *
37167802Sjkim * The above copyright and patent license is granted only if the following
38167802Sjkim * conditions are met:
39167802Sjkim *
40167802Sjkim * 3. Conditions
41167802Sjkim *
42167802Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43167802Sjkim * Redistribution of source code of any substantial portion of the Covered
44167802Sjkim * Code or modification with rights to further distribute source must include
45167802Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46167802Sjkim * and the following Disclaimer and Export Compliance provision.  In addition,
47167802Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48167802Sjkim * contain a file documenting the changes Licensee made to create that Covered
49167802Sjkim * Code and the date of any change.  Licensee must include in that file the
50167802Sjkim * documentation of any changes made by any predecessor Licensee.  Licensee
51167802Sjkim * must include a prominent statement that the modification is derived,
52167802Sjkim * directly or indirectly, from Original Intel Code.
53167802Sjkim *
54167802Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55167802Sjkim * Redistribution of source code of any substantial portion of the Covered
56167802Sjkim * Code or modification without rights to further distribute source must
57167802Sjkim * include the following Disclaimer and Export Compliance provision in the
58167802Sjkim * documentation and/or other materials provided with distribution.  In
59167802Sjkim * addition, Licensee may not authorize further sublicense of source of any
60167802Sjkim * portion of the Covered Code, and must include terms to the effect that the
61167802Sjkim * license from Licensee to its licensee is limited to the intellectual
62167802Sjkim * property embodied in the software Licensee provides to its licensee, and
63167802Sjkim * not to intellectual property embodied in modifications its licensee may
64167802Sjkim * make.
65167802Sjkim *
66167802Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67167802Sjkim * substantial portion of the Covered Code or modification must reproduce the
68167802Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69167802Sjkim * provision in the documentation and/or other materials provided with the
70167802Sjkim * distribution.
71167802Sjkim *
72167802Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73167802Sjkim * Intel Code.
74167802Sjkim *
75167802Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76167802Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77167802Sjkim * other dealings in products derived from or relating to the Covered Code
78167802Sjkim * without prior written authorization from Intel.
79167802Sjkim *
80167802Sjkim * 4. Disclaimer and Export Compliance
81167802Sjkim *
82167802Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83167802Sjkim * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84167802Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85167802Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86167802Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87167802Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88167802Sjkim * PARTICULAR PURPOSE.
89167802Sjkim *
90167802Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91167802Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92167802Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93167802Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94167802Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95167802Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96167802Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97167802Sjkim * LIMITED REMEDY.
98167802Sjkim *
99167802Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100167802Sjkim * software or system incorporating such software without first obtaining any
101167802Sjkim * required license or other approval from the U. S. Department of Commerce or
102167802Sjkim * any other agency or department of the United States Government.  In the
103167802Sjkim * event Licensee exports any such software from the United States or
104167802Sjkim * re-exports any such software from a foreign destination, Licensee shall
105167802Sjkim * ensure that the distribution and export/re-export of the software is in
106167802Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107167802Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108167802Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109167802Sjkim * software, or service, directly or indirectly, to any country for which the
110167802Sjkim * United States government or any agency thereof requires an export license,
111167802Sjkim * other governmental approval, or letter of assurance, without first obtaining
112167802Sjkim * such license, approval or letter.
113167802Sjkim *
114167802Sjkim *****************************************************************************/
115167802Sjkim
116167802Sjkim#define __TBFIND_C__
117167802Sjkim
118193251Sjkim#include "acpi.h"
119193267Sjkim#include "accommon.h"
120193251Sjkim#include "actables.h"
121167802Sjkim
122167802Sjkim#define _COMPONENT          ACPI_TABLES
123167802Sjkim        ACPI_MODULE_NAME    ("tbfind")
124167802Sjkim
125167802Sjkim
126167802Sjkim/*******************************************************************************
127167802Sjkim *
128167802Sjkim * FUNCTION:    AcpiTbFindTable
129167802Sjkim *
130167802Sjkim * PARAMETERS:  Signature           - String with ACPI table signature
131167802Sjkim *              OemId               - String with the table OEM ID
132167802Sjkim *              OemTableId          - String with the OEM Table ID
133167802Sjkim *              TableIndex          - Where the table index is returned
134167802Sjkim *
135167802Sjkim * RETURN:      Status and table index
136167802Sjkim *
137167802Sjkim * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
138167802Sjkim *              Signature, OEM ID and OEM Table ID. Returns an index that can
139167802Sjkim *              be used to get the table header or entire table.
140167802Sjkim *
141167802Sjkim ******************************************************************************/
142167802Sjkim
143167802SjkimACPI_STATUS
144167802SjkimAcpiTbFindTable (
145167802Sjkim    char                    *Signature,
146167802Sjkim    char                    *OemId,
147167802Sjkim    char                    *OemTableId,
148193267Sjkim    UINT32                  *TableIndex)
149167802Sjkim{
150193267Sjkim    UINT32                  i;
151167802Sjkim    ACPI_STATUS             Status;
152193267Sjkim    ACPI_TABLE_HEADER       Header;
153167802Sjkim
154167802Sjkim
155167802Sjkim    ACPI_FUNCTION_TRACE (TbFindTable);
156167802Sjkim
157167802Sjkim
158193267Sjkim    /* Normalize the input strings */
159193267Sjkim
160193267Sjkim    ACPI_MEMSET (&Header, 0, sizeof (ACPI_TABLE_HEADER));
161193267Sjkim    ACPI_STRNCPY (Header.Signature, Signature, ACPI_NAME_SIZE);
162193267Sjkim    ACPI_STRNCPY (Header.OemId, OemId, ACPI_OEM_ID_SIZE);
163193267Sjkim    ACPI_STRNCPY (Header.OemTableId, OemTableId, ACPI_OEM_TABLE_ID_SIZE);
164193267Sjkim
165193267Sjkim    /* Search for the table */
166193267Sjkim
167167802Sjkim    for (i = 0; i < AcpiGbl_RootTableList.Count; ++i)
168167802Sjkim    {
169167802Sjkim        if (ACPI_MEMCMP (&(AcpiGbl_RootTableList.Tables[i].Signature),
170193267Sjkim                            Header.Signature, ACPI_NAME_SIZE))
171167802Sjkim        {
172167802Sjkim            /* Not the requested table */
173167802Sjkim
174167802Sjkim            continue;
175167802Sjkim        }
176167802Sjkim
177167802Sjkim        /* Table with matching signature has been found */
178167802Sjkim
179167802Sjkim        if (!AcpiGbl_RootTableList.Tables[i].Pointer)
180167802Sjkim        {
181167802Sjkim            /* Table is not currently mapped, map it */
182167802Sjkim
183167802Sjkim            Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]);
184167802Sjkim            if (ACPI_FAILURE (Status))
185167802Sjkim            {
186167802Sjkim                return_ACPI_STATUS (Status);
187167802Sjkim            }
188167802Sjkim
189167802Sjkim            if (!AcpiGbl_RootTableList.Tables[i].Pointer)
190167802Sjkim            {
191167802Sjkim                continue;
192167802Sjkim            }
193167802Sjkim        }
194167802Sjkim
195167802Sjkim        /* Check for table match on all IDs */
196167802Sjkim
197167802Sjkim        if (!ACPI_MEMCMP (AcpiGbl_RootTableList.Tables[i].Pointer->Signature,
198193267Sjkim                            Header.Signature, ACPI_NAME_SIZE) &&
199167802Sjkim            (!OemId[0] ||
200167802Sjkim             !ACPI_MEMCMP (AcpiGbl_RootTableList.Tables[i].Pointer->OemId,
201193267Sjkim                             Header.OemId, ACPI_OEM_ID_SIZE)) &&
202167802Sjkim            (!OemTableId[0] ||
203167802Sjkim             !ACPI_MEMCMP (AcpiGbl_RootTableList.Tables[i].Pointer->OemTableId,
204193267Sjkim                             Header.OemTableId, ACPI_OEM_TABLE_ID_SIZE)))
205167802Sjkim        {
206167802Sjkim            *TableIndex = i;
207167802Sjkim
208167802Sjkim            ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
209193267Sjkim                Header.Signature));
210167802Sjkim            return_ACPI_STATUS (AE_OK);
211167802Sjkim        }
212167802Sjkim    }
213167802Sjkim
214167802Sjkim    return_ACPI_STATUS (AE_NOT_FOUND);
215167802Sjkim}
216