xref: /illumos-gate/usr/src/common/acpica/tables/tbdata.c (revision 35786f6866ae52207d0f1a25fe7ca5f652f32ce0)
1bc36eafdSMike Gerdts /******************************************************************************
2bc36eafdSMike Gerdts  *
3bc36eafdSMike Gerdts  * Module Name: tbdata - Table manager data structure functions
4bc36eafdSMike Gerdts  *
5bc36eafdSMike Gerdts  *****************************************************************************/
6bc36eafdSMike Gerdts 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12bc36eafdSMike Gerdts  * All rights reserved.
13bc36eafdSMike Gerdts  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
119bc36eafdSMike Gerdts  * Redistribution and use in source and binary forms, with or without
120bc36eafdSMike Gerdts  * modification, are permitted provided that the following conditions
121bc36eafdSMike Gerdts  * are met:
122bc36eafdSMike Gerdts  * 1. Redistributions of source code must retain the above copyright
123bc36eafdSMike Gerdts  *    notice, this list of conditions, and the following disclaimer,
124bc36eafdSMike Gerdts  *    without modification.
125bc36eafdSMike Gerdts  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126bc36eafdSMike Gerdts  *    substantially similar to the "NO WARRANTY" disclaimer below
127bc36eafdSMike Gerdts  *    ("Disclaimer") and any redistribution must be conditioned upon
128bc36eafdSMike Gerdts  *    including a substantially similar Disclaimer requirement for further
129bc36eafdSMike Gerdts  *    binary redistribution.
130bc36eafdSMike Gerdts  * 3. Neither the names of the above-listed copyright holders nor the names
131bc36eafdSMike Gerdts  *    of any contributors may be used to endorse or promote products derived
132bc36eafdSMike Gerdts  *    from this software without specific prior written permission.
133bc36eafdSMike Gerdts  *
134*35786f68SRobert Mustacchi  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135*35786f68SRobert Mustacchi  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137*35786f68SRobert Mustacchi  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147bc36eafdSMike Gerdts  * GNU General Public License ("GPL") version 2 as published by the Free
148bc36eafdSMike Gerdts  * Software Foundation.
149bc36eafdSMike Gerdts  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
151bc36eafdSMike Gerdts 
152bc36eafdSMike Gerdts #include "acpi.h"
153bc36eafdSMike Gerdts #include "accommon.h"
154bc36eafdSMike Gerdts #include "acnamesp.h"
155bc36eafdSMike Gerdts #include "actables.h"
156*35786f68SRobert Mustacchi #include "acevents.h"
157bc36eafdSMike Gerdts 
158bc36eafdSMike Gerdts #define _COMPONENT          ACPI_TABLES
159bc36eafdSMike Gerdts         ACPI_MODULE_NAME    ("tbdata")
160bc36eafdSMike Gerdts 
161*35786f68SRobert Mustacchi /* Local prototypes */
162*35786f68SRobert Mustacchi 
163*35786f68SRobert Mustacchi static ACPI_STATUS
164*35786f68SRobert Mustacchi AcpiTbCheckDuplication (
165*35786f68SRobert Mustacchi     ACPI_TABLE_DESC         *TableDesc,
166*35786f68SRobert Mustacchi     UINT32                  *TableIndex);
167*35786f68SRobert Mustacchi 
168*35786f68SRobert Mustacchi static BOOLEAN
169*35786f68SRobert Mustacchi AcpiTbCompareTables (
170*35786f68SRobert Mustacchi     ACPI_TABLE_DESC         *TableDesc,
171*35786f68SRobert Mustacchi     UINT32                  TableIndex);
172*35786f68SRobert Mustacchi 
173*35786f68SRobert Mustacchi 
174*35786f68SRobert Mustacchi /*******************************************************************************
175*35786f68SRobert Mustacchi  *
176*35786f68SRobert Mustacchi  * FUNCTION:    AcpiTbCompareTables
177*35786f68SRobert Mustacchi  *
178*35786f68SRobert Mustacchi  * PARAMETERS:  TableDesc           - Table 1 descriptor to be compared
179*35786f68SRobert Mustacchi  *              TableIndex          - Index of table 2 to be compared
180*35786f68SRobert Mustacchi  *
181*35786f68SRobert Mustacchi  * RETURN:      TRUE if both tables are identical.
182*35786f68SRobert Mustacchi  *
183*35786f68SRobert Mustacchi  * DESCRIPTION: This function compares a table with another table that has
184*35786f68SRobert Mustacchi  *              already been installed in the root table list.
185*35786f68SRobert Mustacchi  *
186*35786f68SRobert Mustacchi  ******************************************************************************/
187*35786f68SRobert Mustacchi 
188*35786f68SRobert Mustacchi static BOOLEAN
AcpiTbCompareTables(ACPI_TABLE_DESC * TableDesc,UINT32 TableIndex)189*35786f68SRobert Mustacchi AcpiTbCompareTables (
190*35786f68SRobert Mustacchi     ACPI_TABLE_DESC         *TableDesc,
191*35786f68SRobert Mustacchi     UINT32                  TableIndex)
192*35786f68SRobert Mustacchi {
193*35786f68SRobert Mustacchi     ACPI_STATUS             Status = AE_OK;
194*35786f68SRobert Mustacchi     BOOLEAN                 IsIdentical;
195*35786f68SRobert Mustacchi     ACPI_TABLE_HEADER       *Table;
196*35786f68SRobert Mustacchi     UINT32                  TableLength;
197*35786f68SRobert Mustacchi     UINT8                   TableFlags;
198*35786f68SRobert Mustacchi 
199*35786f68SRobert Mustacchi 
200*35786f68SRobert Mustacchi     Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],
201*35786f68SRobert Mustacchi         &Table, &TableLength, &TableFlags);
202*35786f68SRobert Mustacchi     if (ACPI_FAILURE (Status))
203*35786f68SRobert Mustacchi     {
204*35786f68SRobert Mustacchi         return (FALSE);
205*35786f68SRobert Mustacchi     }
206*35786f68SRobert Mustacchi 
207*35786f68SRobert Mustacchi     /*
208*35786f68SRobert Mustacchi      * Check for a table match on the entire table length,
209*35786f68SRobert Mustacchi      * not just the header.
210*35786f68SRobert Mustacchi      */
211*35786f68SRobert Mustacchi     IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||
212*35786f68SRobert Mustacchi         memcmp (TableDesc->Pointer, Table, TableLength)) ?
213*35786f68SRobert Mustacchi         FALSE : TRUE);
214*35786f68SRobert Mustacchi 
215*35786f68SRobert Mustacchi     /* Release the acquired table */
216*35786f68SRobert Mustacchi 
217*35786f68SRobert Mustacchi     AcpiTbReleaseTable (Table, TableLength, TableFlags);
218*35786f68SRobert Mustacchi     return (IsIdentical);
219*35786f68SRobert Mustacchi }
220*35786f68SRobert Mustacchi 
221bc36eafdSMike Gerdts 
222bc36eafdSMike Gerdts /*******************************************************************************
223bc36eafdSMike Gerdts  *
224bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbInitTableDescriptor
225bc36eafdSMike Gerdts  *
226bc36eafdSMike Gerdts  * PARAMETERS:  TableDesc               - Table descriptor
227bc36eafdSMike Gerdts  *              Address                 - Physical address of the table
228bc36eafdSMike Gerdts  *              Flags                   - Allocation flags of the table
229bc36eafdSMike Gerdts  *              Table                   - Pointer to the table
230bc36eafdSMike Gerdts  *
231bc36eafdSMike Gerdts  * RETURN:      None
232bc36eafdSMike Gerdts  *
233bc36eafdSMike Gerdts  * DESCRIPTION: Initialize a new table descriptor
234bc36eafdSMike Gerdts  *
235bc36eafdSMike Gerdts  ******************************************************************************/
236bc36eafdSMike Gerdts 
237bc36eafdSMike Gerdts void
AcpiTbInitTableDescriptor(ACPI_TABLE_DESC * TableDesc,ACPI_PHYSICAL_ADDRESS Address,UINT8 Flags,ACPI_TABLE_HEADER * Table)238bc36eafdSMike Gerdts AcpiTbInitTableDescriptor (
239bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *TableDesc,
240bc36eafdSMike Gerdts     ACPI_PHYSICAL_ADDRESS   Address,
241bc36eafdSMike Gerdts     UINT8                   Flags,
242bc36eafdSMike Gerdts     ACPI_TABLE_HEADER       *Table)
243bc36eafdSMike Gerdts {
244bc36eafdSMike Gerdts 
245bc36eafdSMike Gerdts     /*
246bc36eafdSMike Gerdts      * Initialize the table descriptor. Set the pointer to NULL, since the
247bc36eafdSMike Gerdts      * table is not fully mapped at this time.
248bc36eafdSMike Gerdts      */
249bc36eafdSMike Gerdts     memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
250bc36eafdSMike Gerdts     TableDesc->Address = Address;
251bc36eafdSMike Gerdts     TableDesc->Length = Table->Length;
252bc36eafdSMike Gerdts     TableDesc->Flags = Flags;
253bc36eafdSMike Gerdts     ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
254bc36eafdSMike Gerdts }
255bc36eafdSMike Gerdts 
256bc36eafdSMike Gerdts 
257bc36eafdSMike Gerdts /*******************************************************************************
258bc36eafdSMike Gerdts  *
259bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbAcquireTable
260bc36eafdSMike Gerdts  *
261bc36eafdSMike Gerdts  * PARAMETERS:  TableDesc           - Table descriptor
262bc36eafdSMike Gerdts  *              TablePtr            - Where table is returned
263bc36eafdSMike Gerdts  *              TableLength         - Where table length is returned
264bc36eafdSMike Gerdts  *              TableFlags          - Where table allocation flags are returned
265bc36eafdSMike Gerdts  *
266bc36eafdSMike Gerdts  * RETURN:      Status
267bc36eafdSMike Gerdts  *
268bc36eafdSMike Gerdts  * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
269bc36eafdSMike Gerdts  *              maintained in the AcpiGbl_RootTableList.
270bc36eafdSMike Gerdts  *
271bc36eafdSMike Gerdts  ******************************************************************************/
272bc36eafdSMike Gerdts 
273bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbAcquireTable(ACPI_TABLE_DESC * TableDesc,ACPI_TABLE_HEADER ** TablePtr,UINT32 * TableLength,UINT8 * TableFlags)274bc36eafdSMike Gerdts AcpiTbAcquireTable (
275bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *TableDesc,
276bc36eafdSMike Gerdts     ACPI_TABLE_HEADER       **TablePtr,
277bc36eafdSMike Gerdts     UINT32                  *TableLength,
278bc36eafdSMike Gerdts     UINT8                   *TableFlags)
279bc36eafdSMike Gerdts {
280bc36eafdSMike Gerdts     ACPI_TABLE_HEADER       *Table = NULL;
281bc36eafdSMike Gerdts 
282bc36eafdSMike Gerdts 
283bc36eafdSMike Gerdts     switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
284bc36eafdSMike Gerdts     {
285bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
286bc36eafdSMike Gerdts 
287bc36eafdSMike Gerdts         Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
288bc36eafdSMike Gerdts         break;
289bc36eafdSMike Gerdts 
290bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
291bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
292bc36eafdSMike Gerdts 
293bc36eafdSMike Gerdts         Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
294bc36eafdSMike Gerdts             ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
295bc36eafdSMike Gerdts         break;
296bc36eafdSMike Gerdts 
297bc36eafdSMike Gerdts     default:
298bc36eafdSMike Gerdts 
299bc36eafdSMike Gerdts         break;
300bc36eafdSMike Gerdts     }
301bc36eafdSMike Gerdts 
302bc36eafdSMike Gerdts     /* Table is not valid yet */
303bc36eafdSMike Gerdts 
304bc36eafdSMike Gerdts     if (!Table)
305bc36eafdSMike Gerdts     {
306bc36eafdSMike Gerdts         return (AE_NO_MEMORY);
307bc36eafdSMike Gerdts     }
308bc36eafdSMike Gerdts 
309bc36eafdSMike Gerdts     /* Fill the return values */
310bc36eafdSMike Gerdts 
311bc36eafdSMike Gerdts     *TablePtr = Table;
312bc36eafdSMike Gerdts     *TableLength = TableDesc->Length;
313bc36eafdSMike Gerdts     *TableFlags = TableDesc->Flags;
314bc36eafdSMike Gerdts     return (AE_OK);
315bc36eafdSMike Gerdts }
316bc36eafdSMike Gerdts 
317bc36eafdSMike Gerdts 
318bc36eafdSMike Gerdts /*******************************************************************************
319bc36eafdSMike Gerdts  *
320bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbReleaseTable
321bc36eafdSMike Gerdts  *
322bc36eafdSMike Gerdts  * PARAMETERS:  Table               - Pointer for the table
323bc36eafdSMike Gerdts  *              TableLength         - Length for the table
324bc36eafdSMike Gerdts  *              TableFlags          - Allocation flags for the table
325bc36eafdSMike Gerdts  *
326bc36eafdSMike Gerdts  * RETURN:      None
327bc36eafdSMike Gerdts  *
328bc36eafdSMike Gerdts  * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
329bc36eafdSMike Gerdts  *
330bc36eafdSMike Gerdts  ******************************************************************************/
331bc36eafdSMike Gerdts 
332bc36eafdSMike Gerdts void
AcpiTbReleaseTable(ACPI_TABLE_HEADER * Table,UINT32 TableLength,UINT8 TableFlags)333bc36eafdSMike Gerdts AcpiTbReleaseTable (
334bc36eafdSMike Gerdts     ACPI_TABLE_HEADER       *Table,
335bc36eafdSMike Gerdts     UINT32                  TableLength,
336bc36eafdSMike Gerdts     UINT8                   TableFlags)
337bc36eafdSMike Gerdts {
338bc36eafdSMike Gerdts 
339bc36eafdSMike Gerdts     switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
340bc36eafdSMike Gerdts     {
341bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
342bc36eafdSMike Gerdts 
343bc36eafdSMike Gerdts         AcpiOsUnmapMemory (Table, TableLength);
344bc36eafdSMike Gerdts         break;
345bc36eafdSMike Gerdts 
346bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
347bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
348bc36eafdSMike Gerdts     default:
349bc36eafdSMike Gerdts 
350bc36eafdSMike Gerdts         break;
351bc36eafdSMike Gerdts     }
352bc36eafdSMike Gerdts }
353bc36eafdSMike Gerdts 
354bc36eafdSMike Gerdts 
355bc36eafdSMike Gerdts /*******************************************************************************
356bc36eafdSMike Gerdts  *
357bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbAcquireTempTable
358bc36eafdSMike Gerdts  *
359bc36eafdSMike Gerdts  * PARAMETERS:  TableDesc           - Table descriptor to be acquired
360bc36eafdSMike Gerdts  *              Address             - Address of the table
361bc36eafdSMike Gerdts  *              Flags               - Allocation flags of the table
362bc36eafdSMike Gerdts  *
363bc36eafdSMike Gerdts  * RETURN:      Status
364bc36eafdSMike Gerdts  *
365bc36eafdSMike Gerdts  * DESCRIPTION: This function validates the table header to obtain the length
366bc36eafdSMike Gerdts  *              of a table and fills the table descriptor to make its state as
367bc36eafdSMike Gerdts  *              "INSTALLED". Such a table descriptor is only used for verified
368bc36eafdSMike Gerdts  *              installation.
369bc36eafdSMike Gerdts  *
370bc36eafdSMike Gerdts  ******************************************************************************/
371bc36eafdSMike Gerdts 
372bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbAcquireTempTable(ACPI_TABLE_DESC * TableDesc,ACPI_PHYSICAL_ADDRESS Address,UINT8 Flags)373bc36eafdSMike Gerdts AcpiTbAcquireTempTable (
374bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *TableDesc,
375bc36eafdSMike Gerdts     ACPI_PHYSICAL_ADDRESS   Address,
376bc36eafdSMike Gerdts     UINT8                   Flags)
377bc36eafdSMike Gerdts {
378bc36eafdSMike Gerdts     ACPI_TABLE_HEADER       *TableHeader;
379bc36eafdSMike Gerdts 
380bc36eafdSMike Gerdts 
381bc36eafdSMike Gerdts     switch (Flags & ACPI_TABLE_ORIGIN_MASK)
382bc36eafdSMike Gerdts     {
383bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
384bc36eafdSMike Gerdts 
385bc36eafdSMike Gerdts         /* Get the length of the full table from the header */
386bc36eafdSMike Gerdts 
387bc36eafdSMike Gerdts         TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
388bc36eafdSMike Gerdts         if (!TableHeader)
389bc36eafdSMike Gerdts         {
390bc36eafdSMike Gerdts             return (AE_NO_MEMORY);
391bc36eafdSMike Gerdts         }
392bc36eafdSMike Gerdts 
393bc36eafdSMike Gerdts         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
394bc36eafdSMike Gerdts         AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
395bc36eafdSMike Gerdts         return (AE_OK);
396bc36eafdSMike Gerdts 
397bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
398bc36eafdSMike Gerdts     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
399bc36eafdSMike Gerdts 
400bc36eafdSMike Gerdts         TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
401bc36eafdSMike Gerdts             ACPI_PHYSADDR_TO_PTR (Address));
402bc36eafdSMike Gerdts         if (!TableHeader)
403bc36eafdSMike Gerdts         {
404bc36eafdSMike Gerdts             return (AE_NO_MEMORY);
405bc36eafdSMike Gerdts         }
406bc36eafdSMike Gerdts 
407bc36eafdSMike Gerdts         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
408bc36eafdSMike Gerdts         return (AE_OK);
409bc36eafdSMike Gerdts 
410bc36eafdSMike Gerdts     default:
411bc36eafdSMike Gerdts 
412bc36eafdSMike Gerdts         break;
413bc36eafdSMike Gerdts     }
414bc36eafdSMike Gerdts 
415bc36eafdSMike Gerdts     /* Table is not valid yet */
416bc36eafdSMike Gerdts 
417bc36eafdSMike Gerdts     return (AE_NO_MEMORY);
418bc36eafdSMike Gerdts }
419bc36eafdSMike Gerdts 
420bc36eafdSMike Gerdts 
421bc36eafdSMike Gerdts /*******************************************************************************
422bc36eafdSMike Gerdts  *
423bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbReleaseTempTable
424bc36eafdSMike Gerdts  *
425bc36eafdSMike Gerdts  * PARAMETERS:  TableDesc           - Table descriptor to be released
426bc36eafdSMike Gerdts  *
427bc36eafdSMike Gerdts  * RETURN:      Status
428bc36eafdSMike Gerdts  *
429bc36eafdSMike Gerdts  * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
430bc36eafdSMike Gerdts  *
431bc36eafdSMike Gerdts  *****************************************************************************/
432bc36eafdSMike Gerdts 
433bc36eafdSMike Gerdts void
AcpiTbReleaseTempTable(ACPI_TABLE_DESC * TableDesc)434bc36eafdSMike Gerdts AcpiTbReleaseTempTable (
435bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *TableDesc)
436bc36eafdSMike Gerdts {
437bc36eafdSMike Gerdts 
438bc36eafdSMike Gerdts     /*
439bc36eafdSMike Gerdts      * Note that the .Address is maintained by the callers of
440bc36eafdSMike Gerdts      * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
441bc36eafdSMike Gerdts      * where .Address will be freed.
442bc36eafdSMike Gerdts      */
443bc36eafdSMike Gerdts     AcpiTbInvalidateTable (TableDesc);
444bc36eafdSMike Gerdts }
445bc36eafdSMike Gerdts 
446bc36eafdSMike Gerdts 
447bc36eafdSMike Gerdts /******************************************************************************
448bc36eafdSMike Gerdts  *
449bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbValidateTable
450bc36eafdSMike Gerdts  *
451bc36eafdSMike Gerdts  * PARAMETERS:  TableDesc           - Table descriptor
452bc36eafdSMike Gerdts  *
453bc36eafdSMike Gerdts  * RETURN:      Status
454bc36eafdSMike Gerdts  *
455bc36eafdSMike Gerdts  * DESCRIPTION: This function is called to validate the table, the returned
456bc36eafdSMike Gerdts  *              table descriptor is in "VALIDATED" state.
457bc36eafdSMike Gerdts  *
458bc36eafdSMike Gerdts  *****************************************************************************/
459bc36eafdSMike Gerdts 
460bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbValidateTable(ACPI_TABLE_DESC * TableDesc)461bc36eafdSMike Gerdts AcpiTbValidateTable (
462bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *TableDesc)
463bc36eafdSMike Gerdts {
464bc36eafdSMike Gerdts     ACPI_STATUS             Status = AE_OK;
465bc36eafdSMike Gerdts 
466bc36eafdSMike Gerdts 
467bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbValidateTable);
468bc36eafdSMike Gerdts 
469bc36eafdSMike Gerdts 
470bc36eafdSMike Gerdts     /* Validate the table if necessary */
471bc36eafdSMike Gerdts 
472bc36eafdSMike Gerdts     if (!TableDesc->Pointer)
473bc36eafdSMike Gerdts     {
474bc36eafdSMike Gerdts         Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
475bc36eafdSMike Gerdts             &TableDesc->Length, &TableDesc->Flags);
476bc36eafdSMike Gerdts         if (!TableDesc->Pointer)
477bc36eafdSMike Gerdts         {
478bc36eafdSMike Gerdts             Status = AE_NO_MEMORY;
479bc36eafdSMike Gerdts         }
480bc36eafdSMike Gerdts     }
481bc36eafdSMike Gerdts 
482bc36eafdSMike Gerdts     return_ACPI_STATUS (Status);
483bc36eafdSMike Gerdts }
484bc36eafdSMike Gerdts 
485bc36eafdSMike Gerdts 
486bc36eafdSMike Gerdts /*******************************************************************************
487bc36eafdSMike Gerdts  *
488bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbInvalidateTable
489bc36eafdSMike Gerdts  *
490bc36eafdSMike Gerdts  * PARAMETERS:  TableDesc           - Table descriptor
491bc36eafdSMike Gerdts  *
492bc36eafdSMike Gerdts  * RETURN:      None
493bc36eafdSMike Gerdts  *
494bc36eafdSMike Gerdts  * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
495bc36eafdSMike Gerdts  *              AcpiTbValidateTable().
496bc36eafdSMike Gerdts  *
497bc36eafdSMike Gerdts  ******************************************************************************/
498bc36eafdSMike Gerdts 
499bc36eafdSMike Gerdts void
AcpiTbInvalidateTable(ACPI_TABLE_DESC * TableDesc)500bc36eafdSMike Gerdts AcpiTbInvalidateTable (
501bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *TableDesc)
502bc36eafdSMike Gerdts {
503bc36eafdSMike Gerdts 
504bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbInvalidateTable);
505bc36eafdSMike Gerdts 
506bc36eafdSMike Gerdts 
507bc36eafdSMike Gerdts     /* Table must be validated */
508bc36eafdSMike Gerdts 
509bc36eafdSMike Gerdts     if (!TableDesc->Pointer)
510bc36eafdSMike Gerdts     {
511bc36eafdSMike Gerdts         return_VOID;
512bc36eafdSMike Gerdts     }
513bc36eafdSMike Gerdts 
514bc36eafdSMike Gerdts     AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
515bc36eafdSMike Gerdts         TableDesc->Flags);
516bc36eafdSMike Gerdts     TableDesc->Pointer = NULL;
517bc36eafdSMike Gerdts 
518bc36eafdSMike Gerdts     return_VOID;
519bc36eafdSMike Gerdts }
520bc36eafdSMike Gerdts 
521bc36eafdSMike Gerdts 
522bc36eafdSMike Gerdts /******************************************************************************
523bc36eafdSMike Gerdts  *
524bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbValidateTempTable
525bc36eafdSMike Gerdts  *
526bc36eafdSMike Gerdts  * PARAMETERS:  TableDesc           - Table descriptor
527bc36eafdSMike Gerdts  *
528bc36eafdSMike Gerdts  * RETURN:      Status
529bc36eafdSMike Gerdts  *
530bc36eafdSMike Gerdts  * DESCRIPTION: This function is called to validate the table, the returned
531bc36eafdSMike Gerdts  *              table descriptor is in "VALIDATED" state.
532bc36eafdSMike Gerdts  *
533bc36eafdSMike Gerdts  *****************************************************************************/
534bc36eafdSMike Gerdts 
535bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbValidateTempTable(ACPI_TABLE_DESC * TableDesc)536bc36eafdSMike Gerdts AcpiTbValidateTempTable (
537bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *TableDesc)
538bc36eafdSMike Gerdts {
539bc36eafdSMike Gerdts 
540*35786f68SRobert Mustacchi     if (!TableDesc->Pointer && !AcpiGbl_EnableTableValidation)
541bc36eafdSMike Gerdts     {
542bc36eafdSMike Gerdts         /*
543bc36eafdSMike Gerdts          * Only validates the header of the table.
544bc36eafdSMike Gerdts          * Note that Length contains the size of the mapping after invoking
545bc36eafdSMike Gerdts          * this work around, this value is required by
546bc36eafdSMike Gerdts          * AcpiTbReleaseTempTable().
547bc36eafdSMike Gerdts          * We can do this because in AcpiInitTableDescriptor(), the Length
548bc36eafdSMike Gerdts          * field of the installed descriptor is filled with the actual
549bc36eafdSMike Gerdts          * table length obtaining from the table header.
550bc36eafdSMike Gerdts          */
551bc36eafdSMike Gerdts         TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
552bc36eafdSMike Gerdts     }
553bc36eafdSMike Gerdts 
554bc36eafdSMike Gerdts     return (AcpiTbValidateTable (TableDesc));
555bc36eafdSMike Gerdts }
556bc36eafdSMike Gerdts 
557bc36eafdSMike Gerdts 
558*35786f68SRobert Mustacchi /*******************************************************************************
559*35786f68SRobert Mustacchi  *
560*35786f68SRobert Mustacchi  * FUNCTION:    AcpiTbCheckDuplication
561*35786f68SRobert Mustacchi  *
562*35786f68SRobert Mustacchi  * PARAMETERS:  TableDesc           - Table descriptor
563*35786f68SRobert Mustacchi  *              TableIndex          - Where the table index is returned
564*35786f68SRobert Mustacchi  *
565*35786f68SRobert Mustacchi  * RETURN:      Status
566*35786f68SRobert Mustacchi  *
567*35786f68SRobert Mustacchi  * DESCRIPTION: Avoid installing duplicated tables. However table override and
568*35786f68SRobert Mustacchi  *              user aided dynamic table load is allowed, thus comparing the
569*35786f68SRobert Mustacchi  *              address of the table is not sufficient, and checking the entire
570*35786f68SRobert Mustacchi  *              table content is required.
571*35786f68SRobert Mustacchi  *
572*35786f68SRobert Mustacchi  ******************************************************************************/
573*35786f68SRobert Mustacchi 
574*35786f68SRobert Mustacchi static ACPI_STATUS
AcpiTbCheckDuplication(ACPI_TABLE_DESC * TableDesc,UINT32 * TableIndex)575*35786f68SRobert Mustacchi AcpiTbCheckDuplication (
576*35786f68SRobert Mustacchi     ACPI_TABLE_DESC         *TableDesc,
577*35786f68SRobert Mustacchi     UINT32                  *TableIndex)
578*35786f68SRobert Mustacchi {
579*35786f68SRobert Mustacchi     UINT32                  i;
580*35786f68SRobert Mustacchi 
581*35786f68SRobert Mustacchi 
582*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (TbCheckDuplication);
583*35786f68SRobert Mustacchi 
584*35786f68SRobert Mustacchi 
585*35786f68SRobert Mustacchi     /* Check if table is already registered */
586*35786f68SRobert Mustacchi 
587*35786f68SRobert Mustacchi     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
588*35786f68SRobert Mustacchi     {
589*35786f68SRobert Mustacchi         /* Do not compare with unverified tables */
590*35786f68SRobert Mustacchi 
591*35786f68SRobert Mustacchi         if (!(AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_VERIFIED))
592*35786f68SRobert Mustacchi         {
593*35786f68SRobert Mustacchi             continue;
594*35786f68SRobert Mustacchi         }
595*35786f68SRobert Mustacchi 
596*35786f68SRobert Mustacchi         /*
597*35786f68SRobert Mustacchi          * Check for a table match on the entire table length,
598*35786f68SRobert Mustacchi          * not just the header.
599*35786f68SRobert Mustacchi          */
600*35786f68SRobert Mustacchi         if (!AcpiTbCompareTables (TableDesc, i))
601*35786f68SRobert Mustacchi         {
602*35786f68SRobert Mustacchi             continue;
603*35786f68SRobert Mustacchi         }
604*35786f68SRobert Mustacchi 
605*35786f68SRobert Mustacchi         /*
606*35786f68SRobert Mustacchi          * Note: the current mechanism does not unregister a table if it is
607*35786f68SRobert Mustacchi          * dynamically unloaded. The related namespace entries are deleted,
608*35786f68SRobert Mustacchi          * but the table remains in the root table list.
609*35786f68SRobert Mustacchi          *
610*35786f68SRobert Mustacchi          * The assumption here is that the number of different tables that
611*35786f68SRobert Mustacchi          * will be loaded is actually small, and there is minimal overhead
612*35786f68SRobert Mustacchi          * in just keeping the table in case it is needed again.
613*35786f68SRobert Mustacchi          *
614*35786f68SRobert Mustacchi          * If this assumption changes in the future (perhaps on large
615*35786f68SRobert Mustacchi          * machines with many table load/unload operations), tables will
616*35786f68SRobert Mustacchi          * need to be unregistered when they are unloaded, and slots in the
617*35786f68SRobert Mustacchi          * root table list should be reused when empty.
618*35786f68SRobert Mustacchi          */
619*35786f68SRobert Mustacchi         if (AcpiGbl_RootTableList.Tables[i].Flags &
620*35786f68SRobert Mustacchi             ACPI_TABLE_IS_LOADED)
621*35786f68SRobert Mustacchi         {
622*35786f68SRobert Mustacchi             /* Table is still loaded, this is an error */
623*35786f68SRobert Mustacchi 
624*35786f68SRobert Mustacchi             return_ACPI_STATUS (AE_ALREADY_EXISTS);
625*35786f68SRobert Mustacchi         }
626*35786f68SRobert Mustacchi         else
627*35786f68SRobert Mustacchi         {
628*35786f68SRobert Mustacchi             *TableIndex = i;
629*35786f68SRobert Mustacchi             return_ACPI_STATUS (AE_CTRL_TERMINATE);
630*35786f68SRobert Mustacchi         }
631*35786f68SRobert Mustacchi     }
632*35786f68SRobert Mustacchi 
633*35786f68SRobert Mustacchi     /* Indicate no duplication to the caller */
634*35786f68SRobert Mustacchi 
635*35786f68SRobert Mustacchi     return_ACPI_STATUS (AE_OK);
636*35786f68SRobert Mustacchi }
637*35786f68SRobert Mustacchi 
638*35786f68SRobert Mustacchi 
639bc36eafdSMike Gerdts /******************************************************************************
640bc36eafdSMike Gerdts  *
641bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbVerifyTempTable
642bc36eafdSMike Gerdts  *
643bc36eafdSMike Gerdts  * PARAMETERS:  TableDesc           - Table descriptor
644bc36eafdSMike Gerdts  *              Signature           - Table signature to verify
645*35786f68SRobert Mustacchi  *              TableIndex          - Where the table index is returned
646bc36eafdSMike Gerdts  *
647bc36eafdSMike Gerdts  * RETURN:      Status
648bc36eafdSMike Gerdts  *
649bc36eafdSMike Gerdts  * DESCRIPTION: This function is called to validate and verify the table, the
650bc36eafdSMike Gerdts  *              returned table descriptor is in "VALIDATED" state.
651*35786f68SRobert Mustacchi  *              Note that 'TableIndex' is required to be set to !NULL to
652*35786f68SRobert Mustacchi  *              enable duplication check.
653bc36eafdSMike Gerdts  *
654bc36eafdSMike Gerdts  *****************************************************************************/
655bc36eafdSMike Gerdts 
656bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbVerifyTempTable(ACPI_TABLE_DESC * TableDesc,char * Signature,UINT32 * TableIndex)657bc36eafdSMike Gerdts AcpiTbVerifyTempTable (
658bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *TableDesc,
659*35786f68SRobert Mustacchi     char                    *Signature,
660*35786f68SRobert Mustacchi     UINT32                  *TableIndex)
661bc36eafdSMike Gerdts {
662bc36eafdSMike Gerdts     ACPI_STATUS             Status = AE_OK;
663bc36eafdSMike Gerdts 
664bc36eafdSMike Gerdts 
665bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbVerifyTempTable);
666bc36eafdSMike Gerdts 
667bc36eafdSMike Gerdts 
668bc36eafdSMike Gerdts     /* Validate the table */
669bc36eafdSMike Gerdts 
670bc36eafdSMike Gerdts     Status = AcpiTbValidateTempTable (TableDesc);
671bc36eafdSMike Gerdts     if (ACPI_FAILURE (Status))
672bc36eafdSMike Gerdts     {
673bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_NO_MEMORY);
674bc36eafdSMike Gerdts     }
675bc36eafdSMike Gerdts 
676bc36eafdSMike Gerdts     /* If a particular signature is expected (DSDT/FACS), it must match */
677bc36eafdSMike Gerdts 
678bc36eafdSMike Gerdts     if (Signature &&
679bc36eafdSMike Gerdts         !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
680bc36eafdSMike Gerdts     {
681bc36eafdSMike Gerdts         ACPI_BIOS_ERROR ((AE_INFO,
682bc36eafdSMike Gerdts             "Invalid signature 0x%X for ACPI table, expected [%s]",
683bc36eafdSMike Gerdts             TableDesc->Signature.Integer, Signature));
684bc36eafdSMike Gerdts         Status = AE_BAD_SIGNATURE;
685bc36eafdSMike Gerdts         goto InvalidateAndExit;
686bc36eafdSMike Gerdts     }
687bc36eafdSMike Gerdts 
688*35786f68SRobert Mustacchi     if (AcpiGbl_EnableTableValidation)
689*35786f68SRobert Mustacchi     {
690bc36eafdSMike Gerdts         /* Verify the checksum */
691bc36eafdSMike Gerdts 
692bc36eafdSMike Gerdts         Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
693bc36eafdSMike Gerdts         if (ACPI_FAILURE (Status))
694bc36eafdSMike Gerdts         {
695bc36eafdSMike Gerdts             ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
696bc36eafdSMike Gerdts                 "%4.4s 0x%8.8X%8.8X"
697bc36eafdSMike Gerdts                 " Attempted table install failed",
698bc36eafdSMike Gerdts                 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
699bc36eafdSMike Gerdts                     TableDesc->Signature.Ascii : "????",
700bc36eafdSMike Gerdts                 ACPI_FORMAT_UINT64 (TableDesc->Address)));
701bc36eafdSMike Gerdts 
702bc36eafdSMike Gerdts             goto InvalidateAndExit;
703bc36eafdSMike Gerdts         }
704*35786f68SRobert Mustacchi 
705*35786f68SRobert Mustacchi         /* Avoid duplications */
706*35786f68SRobert Mustacchi 
707*35786f68SRobert Mustacchi         if (TableIndex)
708*35786f68SRobert Mustacchi         {
709*35786f68SRobert Mustacchi             Status = AcpiTbCheckDuplication (TableDesc, TableIndex);
710*35786f68SRobert Mustacchi             if (ACPI_FAILURE (Status))
711*35786f68SRobert Mustacchi             {
712*35786f68SRobert Mustacchi                 if (Status != AE_CTRL_TERMINATE)
713*35786f68SRobert Mustacchi                 {
714*35786f68SRobert Mustacchi                     ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
715*35786f68SRobert Mustacchi                         "%4.4s 0x%8.8X%8.8X"
716*35786f68SRobert Mustacchi                         " Table is duplicated",
717*35786f68SRobert Mustacchi                         AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
718*35786f68SRobert Mustacchi                             TableDesc->Signature.Ascii : "????",
719*35786f68SRobert Mustacchi                         ACPI_FORMAT_UINT64 (TableDesc->Address)));
720bc36eafdSMike Gerdts                 }
721bc36eafdSMike Gerdts 
722*35786f68SRobert Mustacchi                 goto InvalidateAndExit;
723*35786f68SRobert Mustacchi             }
724*35786f68SRobert Mustacchi         }
725*35786f68SRobert Mustacchi 
726*35786f68SRobert Mustacchi         TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED;
727*35786f68SRobert Mustacchi     }
728*35786f68SRobert Mustacchi 
729*35786f68SRobert Mustacchi     return_ACPI_STATUS (Status);
730bc36eafdSMike Gerdts 
731bc36eafdSMike Gerdts InvalidateAndExit:
732bc36eafdSMike Gerdts     AcpiTbInvalidateTable (TableDesc);
733bc36eafdSMike Gerdts     return_ACPI_STATUS (Status);
734bc36eafdSMike Gerdts }
735bc36eafdSMike Gerdts 
736bc36eafdSMike Gerdts 
737bc36eafdSMike Gerdts /*******************************************************************************
738bc36eafdSMike Gerdts  *
739bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbResizeRootTableList
740bc36eafdSMike Gerdts  *
741bc36eafdSMike Gerdts  * PARAMETERS:  None
742bc36eafdSMike Gerdts  *
743bc36eafdSMike Gerdts  * RETURN:      Status
744bc36eafdSMike Gerdts  *
745bc36eafdSMike Gerdts  * DESCRIPTION: Expand the size of global table array
746bc36eafdSMike Gerdts  *
747bc36eafdSMike Gerdts  ******************************************************************************/
748bc36eafdSMike Gerdts 
749bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbResizeRootTableList(void)750bc36eafdSMike Gerdts AcpiTbResizeRootTableList (
751bc36eafdSMike Gerdts     void)
752bc36eafdSMike Gerdts {
753bc36eafdSMike Gerdts     ACPI_TABLE_DESC         *Tables;
754bc36eafdSMike Gerdts     UINT32                  TableCount;
755*35786f68SRobert Mustacchi     UINT32                  CurrentTableCount, MaxTableCount;
756*35786f68SRobert Mustacchi     UINT32                  i;
757bc36eafdSMike Gerdts 
758bc36eafdSMike Gerdts 
759bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbResizeRootTableList);
760bc36eafdSMike Gerdts 
761bc36eafdSMike Gerdts 
762bc36eafdSMike Gerdts     /* AllowResize flag is a parameter to AcpiInitializeTables */
763bc36eafdSMike Gerdts 
764bc36eafdSMike Gerdts     if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
765bc36eafdSMike Gerdts     {
766bc36eafdSMike Gerdts         ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
767bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_SUPPORT);
768bc36eafdSMike Gerdts     }
769bc36eafdSMike Gerdts 
770bc36eafdSMike Gerdts     /* Increase the Table Array size */
771bc36eafdSMike Gerdts 
772bc36eafdSMike Gerdts     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
773bc36eafdSMike Gerdts     {
774bc36eafdSMike Gerdts         TableCount = AcpiGbl_RootTableList.MaxTableCount;
775bc36eafdSMike Gerdts     }
776bc36eafdSMike Gerdts     else
777bc36eafdSMike Gerdts     {
778bc36eafdSMike Gerdts         TableCount = AcpiGbl_RootTableList.CurrentTableCount;
779bc36eafdSMike Gerdts     }
780bc36eafdSMike Gerdts 
781*35786f68SRobert Mustacchi     MaxTableCount = TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
782bc36eafdSMike Gerdts     Tables = ACPI_ALLOCATE_ZEROED (
783*35786f68SRobert Mustacchi         ((ACPI_SIZE) MaxTableCount) * sizeof (ACPI_TABLE_DESC));
784bc36eafdSMike Gerdts     if (!Tables)
785bc36eafdSMike Gerdts     {
786bc36eafdSMike Gerdts         ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
787bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_NO_MEMORY);
788bc36eafdSMike Gerdts     }
789bc36eafdSMike Gerdts 
790bc36eafdSMike Gerdts     /* Copy and free the previous table array */
791bc36eafdSMike Gerdts 
792*35786f68SRobert Mustacchi     CurrentTableCount = 0;
793bc36eafdSMike Gerdts     if (AcpiGbl_RootTableList.Tables)
794bc36eafdSMike Gerdts     {
795*35786f68SRobert Mustacchi         for (i = 0; i < TableCount; i++)
796*35786f68SRobert Mustacchi         {
797*35786f68SRobert Mustacchi             if (AcpiGbl_RootTableList.Tables[i].Address)
798*35786f68SRobert Mustacchi             {
799*35786f68SRobert Mustacchi                 memcpy (Tables + CurrentTableCount,
800*35786f68SRobert Mustacchi                     AcpiGbl_RootTableList.Tables + i,
801*35786f68SRobert Mustacchi                     sizeof (ACPI_TABLE_DESC));
802*35786f68SRobert Mustacchi                 CurrentTableCount++;
803*35786f68SRobert Mustacchi             }
804*35786f68SRobert Mustacchi         }
805bc36eafdSMike Gerdts 
806bc36eafdSMike Gerdts         if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
807bc36eafdSMike Gerdts         {
808bc36eafdSMike Gerdts             ACPI_FREE (AcpiGbl_RootTableList.Tables);
809bc36eafdSMike Gerdts         }
810bc36eafdSMike Gerdts     }
811bc36eafdSMike Gerdts 
812bc36eafdSMike Gerdts     AcpiGbl_RootTableList.Tables = Tables;
813*35786f68SRobert Mustacchi     AcpiGbl_RootTableList.MaxTableCount = MaxTableCount;
814*35786f68SRobert Mustacchi     AcpiGbl_RootTableList.CurrentTableCount = CurrentTableCount;
815bc36eafdSMike Gerdts     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
816bc36eafdSMike Gerdts 
817bc36eafdSMike Gerdts     return_ACPI_STATUS (AE_OK);
818bc36eafdSMike Gerdts }
819bc36eafdSMike Gerdts 
820bc36eafdSMike Gerdts 
821bc36eafdSMike Gerdts /*******************************************************************************
822bc36eafdSMike Gerdts  *
823bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbGetNextTableDescriptor
824bc36eafdSMike Gerdts  *
825bc36eafdSMike Gerdts  * PARAMETERS:  TableIndex          - Where table index is returned
826bc36eafdSMike Gerdts  *              TableDesc           - Where table descriptor is returned
827bc36eafdSMike Gerdts  *
828bc36eafdSMike Gerdts  * RETURN:      Status and table index/descriptor.
829bc36eafdSMike Gerdts  *
830bc36eafdSMike Gerdts  * DESCRIPTION: Allocate a new ACPI table entry to the global table list
831bc36eafdSMike Gerdts  *
832bc36eafdSMike Gerdts  ******************************************************************************/
833bc36eafdSMike Gerdts 
834bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbGetNextTableDescriptor(UINT32 * TableIndex,ACPI_TABLE_DESC ** TableDesc)835bc36eafdSMike Gerdts AcpiTbGetNextTableDescriptor (
836bc36eafdSMike Gerdts     UINT32                  *TableIndex,
837bc36eafdSMike Gerdts     ACPI_TABLE_DESC         **TableDesc)
838bc36eafdSMike Gerdts {
839bc36eafdSMike Gerdts     ACPI_STATUS             Status;
840bc36eafdSMike Gerdts     UINT32                  i;
841bc36eafdSMike Gerdts 
842bc36eafdSMike Gerdts 
843bc36eafdSMike Gerdts     /* Ensure that there is room for the table in the Root Table List */
844bc36eafdSMike Gerdts 
845bc36eafdSMike Gerdts     if (AcpiGbl_RootTableList.CurrentTableCount >=
846bc36eafdSMike Gerdts         AcpiGbl_RootTableList.MaxTableCount)
847bc36eafdSMike Gerdts     {
848bc36eafdSMike Gerdts         Status = AcpiTbResizeRootTableList();
849bc36eafdSMike Gerdts         if (ACPI_FAILURE (Status))
850bc36eafdSMike Gerdts         {
851bc36eafdSMike Gerdts             return (Status);
852bc36eafdSMike Gerdts         }
853bc36eafdSMike Gerdts     }
854bc36eafdSMike Gerdts 
855bc36eafdSMike Gerdts     i = AcpiGbl_RootTableList.CurrentTableCount;
856bc36eafdSMike Gerdts     AcpiGbl_RootTableList.CurrentTableCount++;
857bc36eafdSMike Gerdts 
858bc36eafdSMike Gerdts     if (TableIndex)
859bc36eafdSMike Gerdts     {
860bc36eafdSMike Gerdts         *TableIndex = i;
861bc36eafdSMike Gerdts     }
862bc36eafdSMike Gerdts     if (TableDesc)
863bc36eafdSMike Gerdts     {
864bc36eafdSMike Gerdts         *TableDesc = &AcpiGbl_RootTableList.Tables[i];
865bc36eafdSMike Gerdts     }
866bc36eafdSMike Gerdts 
867bc36eafdSMike Gerdts     return (AE_OK);
868bc36eafdSMike Gerdts }
869bc36eafdSMike Gerdts 
870bc36eafdSMike Gerdts 
871bc36eafdSMike Gerdts /*******************************************************************************
872bc36eafdSMike Gerdts  *
873bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbTerminate
874bc36eafdSMike Gerdts  *
875bc36eafdSMike Gerdts  * PARAMETERS:  None
876bc36eafdSMike Gerdts  *
877bc36eafdSMike Gerdts  * RETURN:      None
878bc36eafdSMike Gerdts  *
879bc36eafdSMike Gerdts  * DESCRIPTION: Delete all internal ACPI tables
880bc36eafdSMike Gerdts  *
881bc36eafdSMike Gerdts  ******************************************************************************/
882bc36eafdSMike Gerdts 
883bc36eafdSMike Gerdts void
AcpiTbTerminate(void)884bc36eafdSMike Gerdts AcpiTbTerminate (
885bc36eafdSMike Gerdts     void)
886bc36eafdSMike Gerdts {
887bc36eafdSMike Gerdts     UINT32                  i;
888bc36eafdSMike Gerdts 
889bc36eafdSMike Gerdts 
890bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbTerminate);
891bc36eafdSMike Gerdts 
892bc36eafdSMike Gerdts 
893bc36eafdSMike Gerdts     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
894bc36eafdSMike Gerdts 
895bc36eafdSMike Gerdts     /* Delete the individual tables */
896bc36eafdSMike Gerdts 
897bc36eafdSMike Gerdts     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
898bc36eafdSMike Gerdts     {
899bc36eafdSMike Gerdts         AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
900bc36eafdSMike Gerdts     }
901bc36eafdSMike Gerdts 
902bc36eafdSMike Gerdts     /*
903bc36eafdSMike Gerdts      * Delete the root table array if allocated locally. Array cannot be
904bc36eafdSMike Gerdts      * mapped, so we don't need to check for that flag.
905bc36eafdSMike Gerdts      */
906bc36eafdSMike Gerdts     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
907bc36eafdSMike Gerdts     {
908bc36eafdSMike Gerdts         ACPI_FREE (AcpiGbl_RootTableList.Tables);
909bc36eafdSMike Gerdts     }
910bc36eafdSMike Gerdts 
911bc36eafdSMike Gerdts     AcpiGbl_RootTableList.Tables = NULL;
912bc36eafdSMike Gerdts     AcpiGbl_RootTableList.Flags = 0;
913bc36eafdSMike Gerdts     AcpiGbl_RootTableList.CurrentTableCount = 0;
914bc36eafdSMike Gerdts 
915bc36eafdSMike Gerdts     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
916bc36eafdSMike Gerdts 
917bc36eafdSMike Gerdts     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
918bc36eafdSMike Gerdts     return_VOID;
919bc36eafdSMike Gerdts }
920bc36eafdSMike Gerdts 
921bc36eafdSMike Gerdts 
922bc36eafdSMike Gerdts /*******************************************************************************
923bc36eafdSMike Gerdts  *
924bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbDeleteNamespaceByOwner
925bc36eafdSMike Gerdts  *
926bc36eafdSMike Gerdts  * PARAMETERS:  TableIndex          - Table index
927bc36eafdSMike Gerdts  *
928bc36eafdSMike Gerdts  * RETURN:      Status
929bc36eafdSMike Gerdts  *
930bc36eafdSMike Gerdts  * DESCRIPTION: Delete all namespace objects created when this table was loaded.
931bc36eafdSMike Gerdts  *
932bc36eafdSMike Gerdts  ******************************************************************************/
933bc36eafdSMike Gerdts 
934bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbDeleteNamespaceByOwner(UINT32 TableIndex)935bc36eafdSMike Gerdts AcpiTbDeleteNamespaceByOwner (
936bc36eafdSMike Gerdts     UINT32                  TableIndex)
937bc36eafdSMike Gerdts {
938bc36eafdSMike Gerdts     ACPI_OWNER_ID           OwnerId;
939bc36eafdSMike Gerdts     ACPI_STATUS             Status;
940bc36eafdSMike Gerdts 
941bc36eafdSMike Gerdts 
942bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
943bc36eafdSMike Gerdts 
944bc36eafdSMike Gerdts 
945bc36eafdSMike Gerdts     Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
946bc36eafdSMike Gerdts     if (ACPI_FAILURE (Status))
947bc36eafdSMike Gerdts     {
948bc36eafdSMike Gerdts         return_ACPI_STATUS (Status);
949bc36eafdSMike Gerdts     }
950bc36eafdSMike Gerdts 
951bc36eafdSMike Gerdts     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
952bc36eafdSMike Gerdts     {
953bc36eafdSMike Gerdts         /* The table index does not exist */
954bc36eafdSMike Gerdts 
955bc36eafdSMike Gerdts         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
956bc36eafdSMike Gerdts         return_ACPI_STATUS (AE_NOT_EXIST);
957bc36eafdSMike Gerdts     }
958bc36eafdSMike Gerdts 
959bc36eafdSMike Gerdts     /* Get the owner ID for this table, used to delete namespace nodes */
960bc36eafdSMike Gerdts 
961bc36eafdSMike Gerdts     OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
962bc36eafdSMike Gerdts     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
963bc36eafdSMike Gerdts 
964bc36eafdSMike Gerdts     /*
965bc36eafdSMike Gerdts      * Need to acquire the namespace writer lock to prevent interference
966bc36eafdSMike Gerdts      * with any concurrent namespace walks. The interpreter must be
967bc36eafdSMike Gerdts      * released during the deletion since the acquisition of the deletion
968bc36eafdSMike Gerdts      * lock may block, and also since the execution of a namespace walk
969bc36eafdSMike Gerdts      * must be allowed to use the interpreter.
970bc36eafdSMike Gerdts      */
971bc36eafdSMike Gerdts     Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
972bc36eafdSMike Gerdts     if (ACPI_FAILURE (Status))
973bc36eafdSMike Gerdts     {
974bc36eafdSMike Gerdts         return_ACPI_STATUS (Status);
975bc36eafdSMike Gerdts     }
976*35786f68SRobert Mustacchi     AcpiNsDeleteNamespaceByOwner (OwnerId);
977bc36eafdSMike Gerdts     AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
978bc36eafdSMike Gerdts     return_ACPI_STATUS (Status);
979bc36eafdSMike Gerdts }
980bc36eafdSMike Gerdts 
981bc36eafdSMike Gerdts 
982bc36eafdSMike Gerdts /*******************************************************************************
983bc36eafdSMike Gerdts  *
984bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbAllocateOwnerId
985bc36eafdSMike Gerdts  *
986bc36eafdSMike Gerdts  * PARAMETERS:  TableIndex          - Table index
987bc36eafdSMike Gerdts  *
988bc36eafdSMike Gerdts  * RETURN:      Status
989bc36eafdSMike Gerdts  *
990bc36eafdSMike Gerdts  * DESCRIPTION: Allocates OwnerId in TableDesc
991bc36eafdSMike Gerdts  *
992bc36eafdSMike Gerdts  ******************************************************************************/
993bc36eafdSMike Gerdts 
994bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbAllocateOwnerId(UINT32 TableIndex)995bc36eafdSMike Gerdts AcpiTbAllocateOwnerId (
996bc36eafdSMike Gerdts     UINT32                  TableIndex)
997bc36eafdSMike Gerdts {
998bc36eafdSMike Gerdts     ACPI_STATUS             Status = AE_BAD_PARAMETER;
999bc36eafdSMike Gerdts 
1000bc36eafdSMike Gerdts 
1001bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
1002bc36eafdSMike Gerdts 
1003bc36eafdSMike Gerdts 
1004bc36eafdSMike Gerdts     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1005bc36eafdSMike Gerdts     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1006bc36eafdSMike Gerdts     {
1007bc36eafdSMike Gerdts         Status = AcpiUtAllocateOwnerId (
1008bc36eafdSMike Gerdts             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
1009bc36eafdSMike Gerdts     }
1010bc36eafdSMike Gerdts 
1011bc36eafdSMike Gerdts     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1012bc36eafdSMike Gerdts     return_ACPI_STATUS (Status);
1013bc36eafdSMike Gerdts }
1014bc36eafdSMike Gerdts 
1015bc36eafdSMike Gerdts 
1016bc36eafdSMike Gerdts /*******************************************************************************
1017bc36eafdSMike Gerdts  *
1018bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbReleaseOwnerId
1019bc36eafdSMike Gerdts  *
1020bc36eafdSMike Gerdts  * PARAMETERS:  TableIndex          - Table index
1021bc36eafdSMike Gerdts  *
1022bc36eafdSMike Gerdts  * RETURN:      Status
1023bc36eafdSMike Gerdts  *
1024bc36eafdSMike Gerdts  * DESCRIPTION: Releases OwnerId in TableDesc
1025bc36eafdSMike Gerdts  *
1026bc36eafdSMike Gerdts  ******************************************************************************/
1027bc36eafdSMike Gerdts 
1028bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbReleaseOwnerId(UINT32 TableIndex)1029bc36eafdSMike Gerdts AcpiTbReleaseOwnerId (
1030bc36eafdSMike Gerdts     UINT32                  TableIndex)
1031bc36eafdSMike Gerdts {
1032bc36eafdSMike Gerdts     ACPI_STATUS             Status = AE_BAD_PARAMETER;
1033bc36eafdSMike Gerdts 
1034bc36eafdSMike Gerdts 
1035bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
1036bc36eafdSMike Gerdts 
1037bc36eafdSMike Gerdts 
1038bc36eafdSMike Gerdts     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1039bc36eafdSMike Gerdts     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1040bc36eafdSMike Gerdts     {
1041bc36eafdSMike Gerdts         AcpiUtReleaseOwnerId (
1042bc36eafdSMike Gerdts             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
1043bc36eafdSMike Gerdts         Status = AE_OK;
1044bc36eafdSMike Gerdts     }
1045bc36eafdSMike Gerdts 
1046bc36eafdSMike Gerdts     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1047bc36eafdSMike Gerdts     return_ACPI_STATUS (Status);
1048bc36eafdSMike Gerdts }
1049bc36eafdSMike Gerdts 
1050bc36eafdSMike Gerdts 
1051bc36eafdSMike Gerdts /*******************************************************************************
1052bc36eafdSMike Gerdts  *
1053bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbGetOwnerId
1054bc36eafdSMike Gerdts  *
1055bc36eafdSMike Gerdts  * PARAMETERS:  TableIndex          - Table index
1056bc36eafdSMike Gerdts  *              OwnerId             - Where the table OwnerId is returned
1057bc36eafdSMike Gerdts  *
1058bc36eafdSMike Gerdts  * RETURN:      Status
1059bc36eafdSMike Gerdts  *
1060bc36eafdSMike Gerdts  * DESCRIPTION: returns OwnerId for the ACPI table
1061bc36eafdSMike Gerdts  *
1062bc36eafdSMike Gerdts  ******************************************************************************/
1063bc36eafdSMike Gerdts 
1064bc36eafdSMike Gerdts ACPI_STATUS
AcpiTbGetOwnerId(UINT32 TableIndex,ACPI_OWNER_ID * OwnerId)1065bc36eafdSMike Gerdts AcpiTbGetOwnerId (
1066bc36eafdSMike Gerdts     UINT32                  TableIndex,
1067bc36eafdSMike Gerdts     ACPI_OWNER_ID           *OwnerId)
1068bc36eafdSMike Gerdts {
1069bc36eafdSMike Gerdts     ACPI_STATUS             Status = AE_BAD_PARAMETER;
1070bc36eafdSMike Gerdts 
1071bc36eafdSMike Gerdts 
1072bc36eafdSMike Gerdts     ACPI_FUNCTION_TRACE (TbGetOwnerId);
1073bc36eafdSMike Gerdts 
1074bc36eafdSMike Gerdts 
1075bc36eafdSMike Gerdts     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1076bc36eafdSMike Gerdts     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1077bc36eafdSMike Gerdts     {
1078bc36eafdSMike Gerdts         *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
1079bc36eafdSMike Gerdts         Status = AE_OK;
1080bc36eafdSMike Gerdts     }
1081bc36eafdSMike Gerdts 
1082bc36eafdSMike Gerdts     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1083bc36eafdSMike Gerdts     return_ACPI_STATUS (Status);
1084bc36eafdSMike Gerdts }
1085bc36eafdSMike Gerdts 
1086bc36eafdSMike Gerdts 
1087bc36eafdSMike Gerdts /*******************************************************************************
1088bc36eafdSMike Gerdts  *
1089bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbIsTableLoaded
1090bc36eafdSMike Gerdts  *
1091bc36eafdSMike Gerdts  * PARAMETERS:  TableIndex          - Index into the root table
1092bc36eafdSMike Gerdts  *
1093bc36eafdSMike Gerdts  * RETURN:      Table Loaded Flag
1094bc36eafdSMike Gerdts  *
1095bc36eafdSMike Gerdts  ******************************************************************************/
1096bc36eafdSMike Gerdts 
1097bc36eafdSMike Gerdts BOOLEAN
AcpiTbIsTableLoaded(UINT32 TableIndex)1098bc36eafdSMike Gerdts AcpiTbIsTableLoaded (
1099bc36eafdSMike Gerdts     UINT32                  TableIndex)
1100bc36eafdSMike Gerdts {
1101bc36eafdSMike Gerdts     BOOLEAN                 IsLoaded = FALSE;
1102bc36eafdSMike Gerdts 
1103bc36eafdSMike Gerdts 
1104bc36eafdSMike Gerdts     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1105bc36eafdSMike Gerdts     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1106bc36eafdSMike Gerdts     {
1107bc36eafdSMike Gerdts         IsLoaded = (BOOLEAN)
1108bc36eafdSMike Gerdts             (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
1109bc36eafdSMike Gerdts             ACPI_TABLE_IS_LOADED);
1110bc36eafdSMike Gerdts     }
1111bc36eafdSMike Gerdts 
1112bc36eafdSMike Gerdts     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1113bc36eafdSMike Gerdts     return (IsLoaded);
1114bc36eafdSMike Gerdts }
1115bc36eafdSMike Gerdts 
1116bc36eafdSMike Gerdts 
1117bc36eafdSMike Gerdts /*******************************************************************************
1118bc36eafdSMike Gerdts  *
1119bc36eafdSMike Gerdts  * FUNCTION:    AcpiTbSetTableLoadedFlag
1120bc36eafdSMike Gerdts  *
1121bc36eafdSMike Gerdts  * PARAMETERS:  TableIndex          - Table index
1122bc36eafdSMike Gerdts  *              IsLoaded            - TRUE if table is loaded, FALSE otherwise
1123bc36eafdSMike Gerdts  *
1124bc36eafdSMike Gerdts  * RETURN:      None
1125bc36eafdSMike Gerdts  *
1126bc36eafdSMike Gerdts  * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
1127bc36eafdSMike Gerdts  *
1128bc36eafdSMike Gerdts  ******************************************************************************/
1129bc36eafdSMike Gerdts 
1130bc36eafdSMike Gerdts void
AcpiTbSetTableLoadedFlag(UINT32 TableIndex,BOOLEAN IsLoaded)1131bc36eafdSMike Gerdts AcpiTbSetTableLoadedFlag (
1132bc36eafdSMike Gerdts     UINT32                  TableIndex,
1133bc36eafdSMike Gerdts     BOOLEAN                 IsLoaded)
1134bc36eafdSMike Gerdts {
1135bc36eafdSMike Gerdts 
1136bc36eafdSMike Gerdts     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1137bc36eafdSMike Gerdts     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1138bc36eafdSMike Gerdts     {
1139bc36eafdSMike Gerdts         if (IsLoaded)
1140bc36eafdSMike Gerdts         {
1141bc36eafdSMike Gerdts             AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
1142bc36eafdSMike Gerdts                 ACPI_TABLE_IS_LOADED;
1143bc36eafdSMike Gerdts         }
1144bc36eafdSMike Gerdts         else
1145bc36eafdSMike Gerdts         {
1146bc36eafdSMike Gerdts             AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
1147bc36eafdSMike Gerdts                 ~ACPI_TABLE_IS_LOADED;
1148bc36eafdSMike Gerdts         }
1149bc36eafdSMike Gerdts     }
1150bc36eafdSMike Gerdts 
1151bc36eafdSMike Gerdts     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1152bc36eafdSMike Gerdts }
1153*35786f68SRobert Mustacchi 
1154*35786f68SRobert Mustacchi 
1155*35786f68SRobert Mustacchi /*******************************************************************************
1156*35786f68SRobert Mustacchi  *
1157*35786f68SRobert Mustacchi  * FUNCTION:    AcpiTbLoadTable
1158*35786f68SRobert Mustacchi  *
1159*35786f68SRobert Mustacchi  * PARAMETERS:  TableIndex              - Table index
1160*35786f68SRobert Mustacchi  *              ParentNode              - Where table index is returned
1161*35786f68SRobert Mustacchi  *
1162*35786f68SRobert Mustacchi  * RETURN:      Status
1163*35786f68SRobert Mustacchi  *
1164*35786f68SRobert Mustacchi  * DESCRIPTION: Load an ACPI table
1165*35786f68SRobert Mustacchi  *
1166*35786f68SRobert Mustacchi  ******************************************************************************/
1167*35786f68SRobert Mustacchi 
1168*35786f68SRobert Mustacchi ACPI_STATUS
AcpiTbLoadTable(UINT32 TableIndex,ACPI_NAMESPACE_NODE * ParentNode)1169*35786f68SRobert Mustacchi AcpiTbLoadTable (
1170*35786f68SRobert Mustacchi     UINT32                  TableIndex,
1171*35786f68SRobert Mustacchi     ACPI_NAMESPACE_NODE     *ParentNode)
1172*35786f68SRobert Mustacchi {
1173*35786f68SRobert Mustacchi     ACPI_TABLE_HEADER       *Table;
1174*35786f68SRobert Mustacchi     ACPI_STATUS             Status;
1175*35786f68SRobert Mustacchi     ACPI_OWNER_ID           OwnerId;
1176*35786f68SRobert Mustacchi 
1177*35786f68SRobert Mustacchi 
1178*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (TbLoadTable);
1179*35786f68SRobert Mustacchi 
1180*35786f68SRobert Mustacchi 
1181*35786f68SRobert Mustacchi     /*
1182*35786f68SRobert Mustacchi      * Note: Now table is "INSTALLED", it must be validated before
1183*35786f68SRobert Mustacchi      * using.
1184*35786f68SRobert Mustacchi      */
1185*35786f68SRobert Mustacchi     Status = AcpiGetTableByIndex (TableIndex, &Table);
1186*35786f68SRobert Mustacchi     if (ACPI_FAILURE (Status))
1187*35786f68SRobert Mustacchi     {
1188*35786f68SRobert Mustacchi         return_ACPI_STATUS (Status);
1189*35786f68SRobert Mustacchi     }
1190*35786f68SRobert Mustacchi 
1191*35786f68SRobert Mustacchi     Status = AcpiNsLoadTable (TableIndex, ParentNode);
1192*35786f68SRobert Mustacchi 
1193*35786f68SRobert Mustacchi     /*
1194*35786f68SRobert Mustacchi      * This case handles the legacy option that groups all module-level
1195*35786f68SRobert Mustacchi      * code blocks together and defers execution until all of the tables
1196*35786f68SRobert Mustacchi      * are loaded. Execute all of these blocks at this time.
1197*35786f68SRobert Mustacchi      * Execute any module-level code that was detected during the table
1198*35786f68SRobert Mustacchi      * load phase.
1199*35786f68SRobert Mustacchi      *
1200*35786f68SRobert Mustacchi      * Note: this option is deprecated and will be eliminated in the
1201*35786f68SRobert Mustacchi      * future. Use of this option can cause problems with AML code that
1202*35786f68SRobert Mustacchi      * depends upon in-order immediate execution of module-level code.
1203*35786f68SRobert Mustacchi      */
1204*35786f68SRobert Mustacchi     AcpiNsExecModuleCodeList ();
1205*35786f68SRobert Mustacchi 
1206*35786f68SRobert Mustacchi     /*
1207*35786f68SRobert Mustacchi      * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
1208*35786f68SRobert Mustacchi      * responsible for discovering any new wake GPEs by running _PRW methods
1209*35786f68SRobert Mustacchi      * that may have been loaded by this table.
1210*35786f68SRobert Mustacchi      */
1211*35786f68SRobert Mustacchi     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
1212*35786f68SRobert Mustacchi     if (ACPI_SUCCESS (Status))
1213*35786f68SRobert Mustacchi     {
1214*35786f68SRobert Mustacchi         AcpiEvUpdateGpes (OwnerId);
1215*35786f68SRobert Mustacchi     }
1216*35786f68SRobert Mustacchi 
1217*35786f68SRobert Mustacchi     /* Invoke table handler */
1218*35786f68SRobert Mustacchi 
1219*35786f68SRobert Mustacchi     AcpiTbNotifyTable (ACPI_TABLE_EVENT_LOAD, Table);
1220*35786f68SRobert Mustacchi     return_ACPI_STATUS (Status);
1221*35786f68SRobert Mustacchi }
1222*35786f68SRobert Mustacchi 
1223*35786f68SRobert Mustacchi 
1224*35786f68SRobert Mustacchi /*******************************************************************************
1225*35786f68SRobert Mustacchi  *
1226*35786f68SRobert Mustacchi  * FUNCTION:    AcpiTbInstallAndLoadTable
1227*35786f68SRobert Mustacchi  *
1228*35786f68SRobert Mustacchi  * PARAMETERS:  Address                 - Physical address of the table
1229*35786f68SRobert Mustacchi  *              Flags                   - Allocation flags of the table
1230*35786f68SRobert Mustacchi  *              Override                - Whether override should be performed
1231*35786f68SRobert Mustacchi  *              TableIndex              - Where table index is returned
1232*35786f68SRobert Mustacchi  *
1233*35786f68SRobert Mustacchi  * RETURN:      Status
1234*35786f68SRobert Mustacchi  *
1235*35786f68SRobert Mustacchi  * DESCRIPTION: Install and load an ACPI table
1236*35786f68SRobert Mustacchi  *
1237*35786f68SRobert Mustacchi  ******************************************************************************/
1238*35786f68SRobert Mustacchi 
1239*35786f68SRobert Mustacchi ACPI_STATUS
AcpiTbInstallAndLoadTable(ACPI_PHYSICAL_ADDRESS Address,UINT8 Flags,BOOLEAN Override,UINT32 * TableIndex)1240*35786f68SRobert Mustacchi AcpiTbInstallAndLoadTable (
1241*35786f68SRobert Mustacchi     ACPI_PHYSICAL_ADDRESS   Address,
1242*35786f68SRobert Mustacchi     UINT8                   Flags,
1243*35786f68SRobert Mustacchi     BOOLEAN                 Override,
1244*35786f68SRobert Mustacchi     UINT32                  *TableIndex)
1245*35786f68SRobert Mustacchi {
1246*35786f68SRobert Mustacchi     ACPI_STATUS             Status;
1247*35786f68SRobert Mustacchi     UINT32                  i;
1248*35786f68SRobert Mustacchi 
1249*35786f68SRobert Mustacchi 
1250*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (TbInstallAndLoadTable);
1251*35786f68SRobert Mustacchi 
1252*35786f68SRobert Mustacchi 
1253*35786f68SRobert Mustacchi     /* Install the table and load it into the namespace */
1254*35786f68SRobert Mustacchi 
1255*35786f68SRobert Mustacchi     Status = AcpiTbInstallStandardTable (Address, Flags, TRUE,
1256*35786f68SRobert Mustacchi         Override, &i);
1257*35786f68SRobert Mustacchi     if (ACPI_FAILURE (Status))
1258*35786f68SRobert Mustacchi     {
1259*35786f68SRobert Mustacchi         goto Exit;
1260*35786f68SRobert Mustacchi     }
1261*35786f68SRobert Mustacchi 
1262*35786f68SRobert Mustacchi     Status = AcpiTbLoadTable (i, AcpiGbl_RootNode);
1263*35786f68SRobert Mustacchi 
1264*35786f68SRobert Mustacchi Exit:
1265*35786f68SRobert Mustacchi     *TableIndex = i;
1266*35786f68SRobert Mustacchi     return_ACPI_STATUS (Status);
1267*35786f68SRobert Mustacchi }
1268*35786f68SRobert Mustacchi 
1269*35786f68SRobert Mustacchi 
1270*35786f68SRobert Mustacchi /*******************************************************************************
1271*35786f68SRobert Mustacchi  *
1272*35786f68SRobert Mustacchi  * FUNCTION:    AcpiTbUnloadTable
1273*35786f68SRobert Mustacchi  *
1274*35786f68SRobert Mustacchi  * PARAMETERS:  TableIndex              - Table index
1275*35786f68SRobert Mustacchi  *
1276*35786f68SRobert Mustacchi  * RETURN:      Status
1277*35786f68SRobert Mustacchi  *
1278*35786f68SRobert Mustacchi  * DESCRIPTION: Unload an ACPI table
1279*35786f68SRobert Mustacchi  *
1280*35786f68SRobert Mustacchi  ******************************************************************************/
1281*35786f68SRobert Mustacchi 
1282*35786f68SRobert Mustacchi ACPI_STATUS
AcpiTbUnloadTable(UINT32 TableIndex)1283*35786f68SRobert Mustacchi AcpiTbUnloadTable (
1284*35786f68SRobert Mustacchi     UINT32                  TableIndex)
1285*35786f68SRobert Mustacchi {
1286*35786f68SRobert Mustacchi     ACPI_STATUS             Status = AE_OK;
1287*35786f68SRobert Mustacchi     ACPI_TABLE_HEADER       *Table;
1288*35786f68SRobert Mustacchi 
1289*35786f68SRobert Mustacchi 
1290*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (TbUnloadTable);
1291*35786f68SRobert Mustacchi 
1292*35786f68SRobert Mustacchi 
1293*35786f68SRobert Mustacchi     /* Ensure the table is still loaded */
1294*35786f68SRobert Mustacchi 
1295*35786f68SRobert Mustacchi     if (!AcpiTbIsTableLoaded (TableIndex))
1296*35786f68SRobert Mustacchi     {
1297*35786f68SRobert Mustacchi         return_ACPI_STATUS (AE_NOT_EXIST);
1298*35786f68SRobert Mustacchi     }
1299*35786f68SRobert Mustacchi 
1300*35786f68SRobert Mustacchi     /* Invoke table handler */
1301*35786f68SRobert Mustacchi 
1302*35786f68SRobert Mustacchi     Status = AcpiGetTableByIndex (TableIndex, &Table);
1303*35786f68SRobert Mustacchi     if (ACPI_SUCCESS (Status))
1304*35786f68SRobert Mustacchi     {
1305*35786f68SRobert Mustacchi         AcpiTbNotifyTable (ACPI_TABLE_EVENT_UNLOAD, Table);
1306*35786f68SRobert Mustacchi     }
1307*35786f68SRobert Mustacchi 
1308*35786f68SRobert Mustacchi     /* Delete the portion of the namespace owned by this table */
1309*35786f68SRobert Mustacchi 
1310*35786f68SRobert Mustacchi     Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
1311*35786f68SRobert Mustacchi     if (ACPI_FAILURE (Status))
1312*35786f68SRobert Mustacchi     {
1313*35786f68SRobert Mustacchi         return_ACPI_STATUS (Status);
1314*35786f68SRobert Mustacchi     }
1315*35786f68SRobert Mustacchi 
1316*35786f68SRobert Mustacchi     (void) AcpiTbReleaseOwnerId (TableIndex);
1317*35786f68SRobert Mustacchi     AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
1318*35786f68SRobert Mustacchi     return_ACPI_STATUS (Status);
1319*35786f68SRobert Mustacchi }
1320*35786f68SRobert Mustacchi 
1321*35786f68SRobert Mustacchi 
1322*35786f68SRobert Mustacchi /*******************************************************************************
1323*35786f68SRobert Mustacchi  *
1324*35786f68SRobert Mustacchi  * FUNCTION:    AcpiTbNotifyTable
1325*35786f68SRobert Mustacchi  *
1326*35786f68SRobert Mustacchi  * PARAMETERS:  Event               - Table event
1327*35786f68SRobert Mustacchi  *              Table               - Validated table pointer
1328*35786f68SRobert Mustacchi  *
1329*35786f68SRobert Mustacchi  * RETURN:      None
1330*35786f68SRobert Mustacchi  *
1331*35786f68SRobert Mustacchi  * DESCRIPTION: Notify a table event to the users.
1332*35786f68SRobert Mustacchi  *
1333*35786f68SRobert Mustacchi  ******************************************************************************/
1334*35786f68SRobert Mustacchi 
1335*35786f68SRobert Mustacchi void
AcpiTbNotifyTable(UINT32 Event,void * Table)1336*35786f68SRobert Mustacchi AcpiTbNotifyTable (
1337*35786f68SRobert Mustacchi     UINT32                          Event,
1338*35786f68SRobert Mustacchi     void                            *Table)
1339*35786f68SRobert Mustacchi {
1340*35786f68SRobert Mustacchi     /* Invoke table handler if present */
1341*35786f68SRobert Mustacchi 
1342*35786f68SRobert Mustacchi     if (AcpiGbl_TableHandler)
1343*35786f68SRobert Mustacchi     {
1344*35786f68SRobert Mustacchi         (void) AcpiGbl_TableHandler (Event, Table,
1345*35786f68SRobert Mustacchi             AcpiGbl_TableHandlerContext);
1346*35786f68SRobert Mustacchi     }
1347*35786f68SRobert Mustacchi }
1348