xref: /freebsd/sys/contrib/dev/acpica/common/dmtables.c (revision 493deb390baef09f40125589cbdb714cb274ab04)
1f8146b88SJung-uk Kim /******************************************************************************
2f8146b88SJung-uk Kim  *
3f8146b88SJung-uk Kim  * Module Name: dmtables - disassembler ACPI table support
4f8146b88SJung-uk Kim  *
5f8146b88SJung-uk Kim  *****************************************************************************/
6f8146b88SJung-uk Kim 
7f8146b88SJung-uk Kim /*
8f8146b88SJung-uk Kim  * Copyright (C) 2000 - 2016, Intel Corp.
9f8146b88SJung-uk Kim  * All rights reserved.
10f8146b88SJung-uk Kim  *
11f8146b88SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
12f8146b88SJung-uk Kim  * modification, are permitted provided that the following conditions
13f8146b88SJung-uk Kim  * are met:
14f8146b88SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
15f8146b88SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
16f8146b88SJung-uk Kim  *    without modification.
17f8146b88SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18f8146b88SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
19f8146b88SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
20f8146b88SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
21f8146b88SJung-uk Kim  *    binary redistribution.
22f8146b88SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
23f8146b88SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
24f8146b88SJung-uk Kim  *    from this software without specific prior written permission.
25f8146b88SJung-uk Kim  *
26f8146b88SJung-uk Kim  * Alternatively, this software may be distributed under the terms of the
27f8146b88SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
28f8146b88SJung-uk Kim  * Software Foundation.
29f8146b88SJung-uk Kim  *
30f8146b88SJung-uk Kim  * NO WARRANTY
31f8146b88SJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32f8146b88SJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33f8146b88SJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34f8146b88SJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35f8146b88SJung-uk Kim  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36f8146b88SJung-uk Kim  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37f8146b88SJung-uk Kim  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38f8146b88SJung-uk Kim  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39f8146b88SJung-uk Kim  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40f8146b88SJung-uk Kim  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41f8146b88SJung-uk Kim  * POSSIBILITY OF SUCH DAMAGES.
42f8146b88SJung-uk Kim  */
43f8146b88SJung-uk Kim 
44f8146b88SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
45f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
46f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
47f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/actables.h>
48f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
49*493deb39SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
50f8146b88SJung-uk Kim 
51f8146b88SJung-uk Kim 
52f8146b88SJung-uk Kim #define _COMPONENT          ACPI_TOOLS
53f8146b88SJung-uk Kim         ACPI_MODULE_NAME    ("dmtables")
54f8146b88SJung-uk Kim 
55f8146b88SJung-uk Kim 
56f8146b88SJung-uk Kim /* Local prototypes */
57f8146b88SJung-uk Kim 
58f8146b88SJung-uk Kim static void
59f8146b88SJung-uk Kim AdCreateTableHeader (
60f8146b88SJung-uk Kim     char                    *Filename,
61f8146b88SJung-uk Kim     ACPI_TABLE_HEADER       *Table);
62f8146b88SJung-uk Kim 
63f8146b88SJung-uk Kim static ACPI_STATUS
64f8146b88SJung-uk Kim AdStoreTable (
65f8146b88SJung-uk Kim     ACPI_TABLE_HEADER       *Table,
66f8146b88SJung-uk Kim     UINT32                  *TableIndex);
67f8146b88SJung-uk Kim 
68f8146b88SJung-uk Kim 
69f8146b88SJung-uk Kim extern ACPI_TABLE_DESC      LocalTables[1];
70f8146b88SJung-uk Kim extern ACPI_PARSE_OBJECT    *AcpiGbl_ParseOpRoot;
71f8146b88SJung-uk Kim 
72f8146b88SJung-uk Kim 
73f8146b88SJung-uk Kim /******************************************************************************
74f8146b88SJung-uk Kim  *
75f8146b88SJung-uk Kim  * FUNCTION:    AdDisassemblerHeader
76f8146b88SJung-uk Kim  *
77f8146b88SJung-uk Kim  * PARAMETERS:  Filename            - Input file for the table
78f8146b88SJung-uk Kim  *              TableType           - Either AML or DataTable
79f8146b88SJung-uk Kim  *
80f8146b88SJung-uk Kim  * RETURN:      None
81f8146b88SJung-uk Kim  *
82f8146b88SJung-uk Kim  * DESCRIPTION: Create the disassembler header, including ACPICA signon with
83f8146b88SJung-uk Kim  *              current time and date.
84f8146b88SJung-uk Kim  *
85f8146b88SJung-uk Kim  *****************************************************************************/
86f8146b88SJung-uk Kim 
87f8146b88SJung-uk Kim void
88f8146b88SJung-uk Kim AdDisassemblerHeader (
89f8146b88SJung-uk Kim     char                    *Filename,
90f8146b88SJung-uk Kim     UINT8                   TableType)
91f8146b88SJung-uk Kim {
92f8146b88SJung-uk Kim     time_t                  Timer;
93f8146b88SJung-uk Kim 
94f8146b88SJung-uk Kim 
95f8146b88SJung-uk Kim     time (&Timer);
96f8146b88SJung-uk Kim 
97f8146b88SJung-uk Kim     /* Header and input table info */
98f8146b88SJung-uk Kim 
99f8146b88SJung-uk Kim     AcpiOsPrintf ("/*\n");
100f8146b88SJung-uk Kim     AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * "));
101f8146b88SJung-uk Kim 
102f8146b88SJung-uk Kim     if (TableType == ACPI_IS_AML_TABLE)
103f8146b88SJung-uk Kim     {
104f8146b88SJung-uk Kim         if (AcpiGbl_CstyleDisassembly)
105f8146b88SJung-uk Kim         {
106f8146b88SJung-uk Kim             AcpiOsPrintf (
107f8146b88SJung-uk Kim                 " * Disassembling to symbolic ASL+ operators\n"
108f8146b88SJung-uk Kim                 " *\n");
109f8146b88SJung-uk Kim         }
110f8146b88SJung-uk Kim         else
111f8146b88SJung-uk Kim         {
112f8146b88SJung-uk Kim             AcpiOsPrintf (
113f8146b88SJung-uk Kim                 " * Disassembling to non-symbolic legacy ASL operators\n"
114f8146b88SJung-uk Kim                 " *\n");
115f8146b88SJung-uk Kim         }
116f8146b88SJung-uk Kim     }
117f8146b88SJung-uk Kim 
118f8146b88SJung-uk Kim     AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
119f8146b88SJung-uk Kim     AcpiOsPrintf (" *\n");
120f8146b88SJung-uk Kim }
121f8146b88SJung-uk Kim 
122f8146b88SJung-uk Kim 
123f8146b88SJung-uk Kim /******************************************************************************
124f8146b88SJung-uk Kim  *
125f8146b88SJung-uk Kim  * FUNCTION:    AdCreateTableHeader
126f8146b88SJung-uk Kim  *
127f8146b88SJung-uk Kim  * PARAMETERS:  Filename            - Input file for the table
128f8146b88SJung-uk Kim  *              Table               - Pointer to the raw table
129f8146b88SJung-uk Kim  *
130f8146b88SJung-uk Kim  * RETURN:      None
131f8146b88SJung-uk Kim  *
132f8146b88SJung-uk Kim  * DESCRIPTION: Create the ASL table header, including ACPICA signon with
133f8146b88SJung-uk Kim  *              current time and date.
134f8146b88SJung-uk Kim  *
135f8146b88SJung-uk Kim  *****************************************************************************/
136f8146b88SJung-uk Kim 
137f8146b88SJung-uk Kim static void
138f8146b88SJung-uk Kim AdCreateTableHeader (
139f8146b88SJung-uk Kim     char                    *Filename,
140f8146b88SJung-uk Kim     ACPI_TABLE_HEADER       *Table)
141f8146b88SJung-uk Kim {
142f8146b88SJung-uk Kim     UINT8                   Checksum;
143f8146b88SJung-uk Kim 
144f8146b88SJung-uk Kim 
145f8146b88SJung-uk Kim     /* Reset globals for External statements */
146f8146b88SJung-uk Kim 
147f8146b88SJung-uk Kim     AcpiGbl_NumExternalMethods = 0;
148f8146b88SJung-uk Kim     AcpiGbl_ResolvedExternalMethods = 0;
149f8146b88SJung-uk Kim 
150f8146b88SJung-uk Kim     /*
151f8146b88SJung-uk Kim      * Print file header and dump original table header
152f8146b88SJung-uk Kim      */
153f8146b88SJung-uk Kim     AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE);
154f8146b88SJung-uk Kim 
155f8146b88SJung-uk Kim     AcpiOsPrintf (" * Original Table Header:\n");
156f8146b88SJung-uk Kim     AcpiOsPrintf (" *     Signature        \"%4.4s\"\n",    Table->Signature);
157f8146b88SJung-uk Kim     AcpiOsPrintf (" *     Length           0x%8.8X (%u)\n", Table->Length, Table->Length);
158f8146b88SJung-uk Kim 
159f8146b88SJung-uk Kim     /* Print and validate the revision */
160f8146b88SJung-uk Kim 
161f8146b88SJung-uk Kim     AcpiOsPrintf (" *     Revision         0x%2.2X",      Table->Revision);
162f8146b88SJung-uk Kim 
163f8146b88SJung-uk Kim     switch (Table->Revision)
164f8146b88SJung-uk Kim     {
165f8146b88SJung-uk Kim     case 0:
166f8146b88SJung-uk Kim 
167f8146b88SJung-uk Kim         AcpiOsPrintf (" **** Invalid Revision");
168f8146b88SJung-uk Kim         break;
169f8146b88SJung-uk Kim 
170f8146b88SJung-uk Kim     case 1:
171f8146b88SJung-uk Kim 
172f8146b88SJung-uk Kim         /* Revision of DSDT controls the ACPI integer width */
173f8146b88SJung-uk Kim 
174f8146b88SJung-uk Kim         if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
175f8146b88SJung-uk Kim         {
176f8146b88SJung-uk Kim             AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
177f8146b88SJung-uk Kim         }
178f8146b88SJung-uk Kim         break;
179f8146b88SJung-uk Kim 
180f8146b88SJung-uk Kim     default:
181f8146b88SJung-uk Kim 
182f8146b88SJung-uk Kim         break;
183f8146b88SJung-uk Kim     }
184f8146b88SJung-uk Kim 
185f8146b88SJung-uk Kim     /* Print and validate the table checksum */
186f8146b88SJung-uk Kim 
187f8146b88SJung-uk Kim     AcpiOsPrintf ("\n *     Checksum         0x%2.2X",        Table->Checksum);
188f8146b88SJung-uk Kim 
189f8146b88SJung-uk Kim     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
190f8146b88SJung-uk Kim     if (Checksum)
191f8146b88SJung-uk Kim     {
192f8146b88SJung-uk Kim         AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
193f8146b88SJung-uk Kim             (UINT8) (Table->Checksum - Checksum));
194f8146b88SJung-uk Kim     }
195f8146b88SJung-uk Kim 
196f8146b88SJung-uk Kim     AcpiOsPrintf ("\n");
197f8146b88SJung-uk Kim     AcpiOsPrintf (" *     OEM ID           \"%.6s\"\n",     Table->OemId);
198f8146b88SJung-uk Kim     AcpiOsPrintf (" *     OEM Table ID     \"%.8s\"\n",     Table->OemTableId);
199f8146b88SJung-uk Kim     AcpiOsPrintf (" *     OEM Revision     0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
200f8146b88SJung-uk Kim     AcpiOsPrintf (" *     Compiler ID      \"%.4s\"\n",     Table->AslCompilerId);
201f8146b88SJung-uk Kim     AcpiOsPrintf (" *     Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
202f8146b88SJung-uk Kim     AcpiOsPrintf (" */\n");
203f8146b88SJung-uk Kim 
204f8146b88SJung-uk Kim     /*
205f8146b88SJung-uk Kim      * Open the ASL definition block.
206f8146b88SJung-uk Kim      *
207f8146b88SJung-uk Kim      * Note: the AMLFilename string is left zero-length in order to just let
208f8146b88SJung-uk Kim      * the compiler create it when the disassembled file is compiled. This
209f8146b88SJung-uk Kim      * makes it easier to rename the disassembled ASL file if needed.
210f8146b88SJung-uk Kim      */
211f8146b88SJung-uk Kim     AcpiOsPrintf (
212f8146b88SJung-uk Kim         "DefinitionBlock (\"\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
213f8146b88SJung-uk Kim         Table->Signature, Table->Revision,
214f8146b88SJung-uk Kim         Table->OemId, Table->OemTableId, Table->OemRevision);
215f8146b88SJung-uk Kim }
216f8146b88SJung-uk Kim 
217f8146b88SJung-uk Kim 
218f8146b88SJung-uk Kim /******************************************************************************
219f8146b88SJung-uk Kim  *
220f8146b88SJung-uk Kim  * FUNCTION:    AdDisplayTables
221f8146b88SJung-uk Kim  *
222f8146b88SJung-uk Kim  * PARAMETERS:  Filename            - Input file for the table
223f8146b88SJung-uk Kim  *              Table               - Pointer to the raw table
224f8146b88SJung-uk Kim  *
225f8146b88SJung-uk Kim  * RETURN:      Status
226f8146b88SJung-uk Kim  *
227f8146b88SJung-uk Kim  * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
228f8146b88SJung-uk Kim  *
229f8146b88SJung-uk Kim  *****************************************************************************/
230f8146b88SJung-uk Kim 
231f8146b88SJung-uk Kim ACPI_STATUS
232f8146b88SJung-uk Kim AdDisplayTables (
233f8146b88SJung-uk Kim     char                    *Filename,
234f8146b88SJung-uk Kim     ACPI_TABLE_HEADER       *Table)
235f8146b88SJung-uk Kim {
236f8146b88SJung-uk Kim 
237f8146b88SJung-uk Kim 
238f8146b88SJung-uk Kim     if (!AcpiGbl_ParseOpRoot)
239f8146b88SJung-uk Kim     {
240f8146b88SJung-uk Kim         return (AE_NOT_EXIST);
241f8146b88SJung-uk Kim     }
242f8146b88SJung-uk Kim 
243f8146b88SJung-uk Kim     if (!AcpiGbl_DmOpt_Listing)
244f8146b88SJung-uk Kim     {
245f8146b88SJung-uk Kim         AdCreateTableHeader (Filename, Table);
246f8146b88SJung-uk Kim     }
247f8146b88SJung-uk Kim 
248f8146b88SJung-uk Kim     AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
249f8146b88SJung-uk Kim     MpEmitMappingInfo ();
250f8146b88SJung-uk Kim 
251f8146b88SJung-uk Kim     if (AcpiGbl_DmOpt_Listing)
252f8146b88SJung-uk Kim     {
253f8146b88SJung-uk Kim         AcpiOsPrintf ("\n\nTable Header:\n");
254f8146b88SJung-uk Kim         AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
255f8146b88SJung-uk Kim             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
256f8146b88SJung-uk Kim 
257f8146b88SJung-uk Kim         AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
258f8146b88SJung-uk Kim         AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
259f8146b88SJung-uk Kim             Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
260f8146b88SJung-uk Kim     }
261f8146b88SJung-uk Kim 
262f8146b88SJung-uk Kim     return (AE_OK);
263f8146b88SJung-uk Kim }
264f8146b88SJung-uk Kim 
265f8146b88SJung-uk Kim 
266f8146b88SJung-uk Kim /*******************************************************************************
267f8146b88SJung-uk Kim  *
268f8146b88SJung-uk Kim  * FUNCTION:    AdStoreTable
269f8146b88SJung-uk Kim  *
270f8146b88SJung-uk Kim  * PARAMETERS:  Table               - Table header
271f8146b88SJung-uk Kim  *              TableIndex          - Where the table index is returned
272f8146b88SJung-uk Kim  *
273f8146b88SJung-uk Kim  * RETURN:      Status and table index.
274f8146b88SJung-uk Kim  *
275f8146b88SJung-uk Kim  * DESCRIPTION: Add an ACPI table to the global table list
276f8146b88SJung-uk Kim  *
277f8146b88SJung-uk Kim  ******************************************************************************/
278f8146b88SJung-uk Kim 
279f8146b88SJung-uk Kim static ACPI_STATUS
280f8146b88SJung-uk Kim AdStoreTable (
281f8146b88SJung-uk Kim     ACPI_TABLE_HEADER       *Table,
282f8146b88SJung-uk Kim     UINT32                  *TableIndex)
283f8146b88SJung-uk Kim {
284f8146b88SJung-uk Kim     ACPI_STATUS             Status;
285f8146b88SJung-uk Kim     ACPI_TABLE_DESC         *TableDesc;
286f8146b88SJung-uk Kim 
287f8146b88SJung-uk Kim 
288f8146b88SJung-uk Kim     Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
289f8146b88SJung-uk Kim     if (ACPI_FAILURE (Status))
290f8146b88SJung-uk Kim     {
291f8146b88SJung-uk Kim         return (Status);
292f8146b88SJung-uk Kim     }
293f8146b88SJung-uk Kim 
294f8146b88SJung-uk Kim     /* Initialize added table */
295f8146b88SJung-uk Kim 
296f8146b88SJung-uk Kim     AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
297f8146b88SJung-uk Kim         ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
298f8146b88SJung-uk Kim     Status = AcpiTbValidateTable (TableDesc);
299f8146b88SJung-uk Kim     return (Status);
300f8146b88SJung-uk Kim }
301f8146b88SJung-uk Kim 
302f8146b88SJung-uk Kim 
303f8146b88SJung-uk Kim /******************************************************************************
304f8146b88SJung-uk Kim  *
305f8146b88SJung-uk Kim  * FUNCTION:    AdGetLocalTables
306f8146b88SJung-uk Kim  *
307f8146b88SJung-uk Kim  * PARAMETERS:  None
308f8146b88SJung-uk Kim  *
309f8146b88SJung-uk Kim  * RETURN:      Status
310f8146b88SJung-uk Kim  *
311f8146b88SJung-uk Kim  * DESCRIPTION: Get the ACPI tables from either memory or a file
312f8146b88SJung-uk Kim  *
313f8146b88SJung-uk Kim  *****************************************************************************/
314f8146b88SJung-uk Kim 
315f8146b88SJung-uk Kim ACPI_STATUS
316f8146b88SJung-uk Kim AdGetLocalTables (
317f8146b88SJung-uk Kim     void)
318f8146b88SJung-uk Kim {
319f8146b88SJung-uk Kim     ACPI_STATUS             Status;
320f8146b88SJung-uk Kim     ACPI_TABLE_HEADER       TableHeader;
321f8146b88SJung-uk Kim     ACPI_TABLE_HEADER       *NewTable;
322f8146b88SJung-uk Kim     UINT32                  TableIndex;
323f8146b88SJung-uk Kim 
324f8146b88SJung-uk Kim 
325f8146b88SJung-uk Kim     /* Get the DSDT via table override */
326f8146b88SJung-uk Kim 
327f8146b88SJung-uk Kim     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
328f8146b88SJung-uk Kim     AcpiOsTableOverride (&TableHeader, &NewTable);
329f8146b88SJung-uk Kim     if (!NewTable)
330f8146b88SJung-uk Kim     {
331f8146b88SJung-uk Kim         fprintf (stderr, "Could not obtain DSDT\n");
332f8146b88SJung-uk Kim         return (AE_NO_ACPI_TABLES);
333f8146b88SJung-uk Kim     }
334f8146b88SJung-uk Kim 
335f8146b88SJung-uk Kim     AdWriteTable (NewTable, NewTable->Length,
336f8146b88SJung-uk Kim         ACPI_SIG_DSDT, NewTable->OemTableId);
337f8146b88SJung-uk Kim 
338f8146b88SJung-uk Kim     /* Store DSDT in the Table Manager */
339f8146b88SJung-uk Kim 
340f8146b88SJung-uk Kim     Status = AdStoreTable (NewTable, &TableIndex);
341f8146b88SJung-uk Kim     if (ACPI_FAILURE (Status))
342f8146b88SJung-uk Kim     {
343f8146b88SJung-uk Kim         fprintf (stderr, "Could not store DSDT\n");
344f8146b88SJung-uk Kim         return (AE_NO_ACPI_TABLES);
345f8146b88SJung-uk Kim     }
346f8146b88SJung-uk Kim 
347f8146b88SJung-uk Kim     return (AE_OK);
348f8146b88SJung-uk Kim }
349f8146b88SJung-uk Kim 
350f8146b88SJung-uk Kim 
351f8146b88SJung-uk Kim /******************************************************************************
352f8146b88SJung-uk Kim  *
353f8146b88SJung-uk Kim  * FUNCTION:    AdParseTable
354f8146b88SJung-uk Kim  *
355f8146b88SJung-uk Kim  * PARAMETERS:  Table               - Pointer to the raw table
356f8146b88SJung-uk Kim  *              OwnerId             - Returned OwnerId of the table
357f8146b88SJung-uk Kim  *              LoadTable           - If add table to the global table list
358f8146b88SJung-uk Kim  *              External            - If this is an external table
359f8146b88SJung-uk Kim  *
360f8146b88SJung-uk Kim  * RETURN:      Status
361f8146b88SJung-uk Kim  *
362f8146b88SJung-uk Kim  * DESCRIPTION: Parse an ACPI AML table
363f8146b88SJung-uk Kim  *
364f8146b88SJung-uk Kim  *****************************************************************************/
365f8146b88SJung-uk Kim 
366f8146b88SJung-uk Kim ACPI_STATUS
367f8146b88SJung-uk Kim AdParseTable (
368f8146b88SJung-uk Kim     ACPI_TABLE_HEADER       *Table,
369f8146b88SJung-uk Kim     ACPI_OWNER_ID           *OwnerId,
370f8146b88SJung-uk Kim     BOOLEAN                 LoadTable,
371f8146b88SJung-uk Kim     BOOLEAN                 External)
372f8146b88SJung-uk Kim {
373f8146b88SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
374f8146b88SJung-uk Kim     ACPI_WALK_STATE         *WalkState;
375f8146b88SJung-uk Kim     UINT8                   *AmlStart;
376f8146b88SJung-uk Kim     UINT32                  AmlLength;
377f8146b88SJung-uk Kim     UINT32                  TableIndex;
378f8146b88SJung-uk Kim 
379f8146b88SJung-uk Kim 
380f8146b88SJung-uk Kim     if (!Table)
381f8146b88SJung-uk Kim     {
382f8146b88SJung-uk Kim         return (AE_NOT_EXIST);
383f8146b88SJung-uk Kim     }
384f8146b88SJung-uk Kim 
385f8146b88SJung-uk Kim     /* Pass 1:  Parse everything except control method bodies */
386f8146b88SJung-uk Kim 
387f8146b88SJung-uk Kim     fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
388f8146b88SJung-uk Kim 
389f8146b88SJung-uk Kim     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
390f8146b88SJung-uk Kim     AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
391f8146b88SJung-uk Kim 
392f8146b88SJung-uk Kim     /* Create the root object */
393f8146b88SJung-uk Kim 
394f8146b88SJung-uk Kim     AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
395f8146b88SJung-uk Kim     if (!AcpiGbl_ParseOpRoot)
396f8146b88SJung-uk Kim     {
397f8146b88SJung-uk Kim         return (AE_NO_MEMORY);
398f8146b88SJung-uk Kim     }
399f8146b88SJung-uk Kim 
400f8146b88SJung-uk Kim     /* Create and initialize a new walk state */
401f8146b88SJung-uk Kim 
402f8146b88SJung-uk Kim     WalkState = AcpiDsCreateWalkState (0, AcpiGbl_ParseOpRoot, NULL, NULL);
403f8146b88SJung-uk Kim     if (!WalkState)
404f8146b88SJung-uk Kim     {
405f8146b88SJung-uk Kim         return (AE_NO_MEMORY);
406f8146b88SJung-uk Kim     }
407f8146b88SJung-uk Kim 
408f8146b88SJung-uk Kim     Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
409f8146b88SJung-uk Kim         NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
410f8146b88SJung-uk Kim     if (ACPI_FAILURE (Status))
411f8146b88SJung-uk Kim     {
412f8146b88SJung-uk Kim         return (Status);
413f8146b88SJung-uk Kim     }
414f8146b88SJung-uk Kim 
415f8146b88SJung-uk Kim     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
416f8146b88SJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
417f8146b88SJung-uk Kim 
418f8146b88SJung-uk Kim     Status = AcpiPsParseAml (WalkState);
419f8146b88SJung-uk Kim     if (ACPI_FAILURE (Status))
420f8146b88SJung-uk Kim     {
421f8146b88SJung-uk Kim         return (Status);
422f8146b88SJung-uk Kim     }
423f8146b88SJung-uk Kim 
424f8146b88SJung-uk Kim     /* If LoadTable is FALSE, we are parsing the last loaded table */
425f8146b88SJung-uk Kim 
426f8146b88SJung-uk Kim     TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
427f8146b88SJung-uk Kim 
428f8146b88SJung-uk Kim     /* Pass 2 */
429f8146b88SJung-uk Kim 
430f8146b88SJung-uk Kim     if (LoadTable)
431f8146b88SJung-uk Kim     {
432f8146b88SJung-uk Kim         Status = AdStoreTable (Table, &TableIndex);
433f8146b88SJung-uk Kim         if (ACPI_FAILURE (Status))
434f8146b88SJung-uk Kim         {
435f8146b88SJung-uk Kim             return (Status);
436f8146b88SJung-uk Kim         }
437f8146b88SJung-uk Kim         Status = AcpiTbAllocateOwnerId (TableIndex);
438f8146b88SJung-uk Kim         if (ACPI_FAILURE (Status))
439f8146b88SJung-uk Kim         {
440f8146b88SJung-uk Kim             return (Status);
441f8146b88SJung-uk Kim         }
442f8146b88SJung-uk Kim         if (OwnerId)
443f8146b88SJung-uk Kim         {
444f8146b88SJung-uk Kim             Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
445f8146b88SJung-uk Kim             if (ACPI_FAILURE (Status))
446f8146b88SJung-uk Kim             {
447f8146b88SJung-uk Kim                 return (Status);
448f8146b88SJung-uk Kim             }
449f8146b88SJung-uk Kim         }
450f8146b88SJung-uk Kim     }
451f8146b88SJung-uk Kim 
452f8146b88SJung-uk Kim     fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
453f8146b88SJung-uk Kim 
454f8146b88SJung-uk Kim     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
455f8146b88SJung-uk Kim     if (ACPI_FAILURE (Status))
456f8146b88SJung-uk Kim     {
457f8146b88SJung-uk Kim         return (Status);
458f8146b88SJung-uk Kim     }
459f8146b88SJung-uk Kim 
460f8146b88SJung-uk Kim     /* No need to parse control methods of external table */
461f8146b88SJung-uk Kim 
462f8146b88SJung-uk Kim     if (External)
463f8146b88SJung-uk Kim     {
464f8146b88SJung-uk Kim         return (AE_OK);
465f8146b88SJung-uk Kim     }
466f8146b88SJung-uk Kim 
467f8146b88SJung-uk Kim     /*
468f8146b88SJung-uk Kim      * Pass 3: Parse control methods and link their parse trees
469f8146b88SJung-uk Kim      * into the main parse tree
470f8146b88SJung-uk Kim      */
471f8146b88SJung-uk Kim     fprintf (stderr,
472f8146b88SJung-uk Kim         "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
473f8146b88SJung-uk Kim 
474f8146b88SJung-uk Kim     Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
475f8146b88SJung-uk Kim     fprintf (stderr, "\n");
476f8146b88SJung-uk Kim 
477f8146b88SJung-uk Kim     /* Process Resource Templates */
478f8146b88SJung-uk Kim 
479f8146b88SJung-uk Kim     AcpiDmFindResources (AcpiGbl_ParseOpRoot);
480f8146b88SJung-uk Kim 
481f8146b88SJung-uk Kim     fprintf (stderr, "Parsing completed\n");
482f8146b88SJung-uk Kim     return (AE_OK);
483f8146b88SJung-uk Kim }
484