xref: /freebsd/sys/contrib/dev/acpica/common/adisasm.c (revision 4c52cad2f9c8cd2b25d156455f9263616da1fb79)
159db4265SNate Lawson /******************************************************************************
259db4265SNate Lawson  *
359db4265SNate Lawson  * Module Name: adisasm - Application-level disassembler routines
459db4265SNate Lawson  *
559db4265SNate Lawson  *****************************************************************************/
659db4265SNate Lawson 
7d244b227SJung-uk Kim /*
8ec3fc72fSJung-uk Kim  * Copyright (C) 2000 - 2012, Intel Corp.
959db4265SNate Lawson  * All rights reserved.
1059db4265SNate Lawson  *
11d244b227SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
12d244b227SJung-uk Kim  * modification, are permitted provided that the following conditions
13d244b227SJung-uk Kim  * are met:
14d244b227SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
15d244b227SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
16d244b227SJung-uk Kim  *    without modification.
17d244b227SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18d244b227SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
19d244b227SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
20d244b227SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
21d244b227SJung-uk Kim  *    binary redistribution.
22d244b227SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
23d244b227SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
24d244b227SJung-uk Kim  *    from this software without specific prior written permission.
2559db4265SNate Lawson  *
26d244b227SJung-uk Kim  * Alternatively, this software may be distributed under the terms of the
27d244b227SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
28d244b227SJung-uk Kim  * Software Foundation.
2959db4265SNate Lawson  *
30d244b227SJung-uk Kim  * NO WARRANTY
31d244b227SJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32d244b227SJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33d244b227SJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34d244b227SJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35d244b227SJung-uk Kim  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36d244b227SJung-uk Kim  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37d244b227SJung-uk Kim  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38d244b227SJung-uk Kim  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39d244b227SJung-uk Kim  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40d244b227SJung-uk Kim  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41d244b227SJung-uk Kim  * POSSIBILITY OF SUCH DAMAGES.
42d244b227SJung-uk Kim  */
4359db4265SNate Lawson 
4459db4265SNate Lawson 
45ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
46ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
49ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdebug.h>
50ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h>
51ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
52ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
53ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h>
54ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
5559db4265SNate Lawson 
5659db4265SNate Lawson #include <stdio.h>
5759db4265SNate Lawson #include <time.h>
5859db4265SNate Lawson 
5959db4265SNate Lawson 
6059db4265SNate Lawson #define _COMPONENT          ACPI_TOOLS
6159db4265SNate Lawson         ACPI_MODULE_NAME    ("adisasm")
6259db4265SNate Lawson 
63f556842eSJung-uk Kim 
641a39cfb0SJung-uk Kim extern int                  AslCompilerdebug;
65f556842eSJung-uk Kim 
6659db4265SNate Lawson 
671a39cfb0SJung-uk Kim ACPI_STATUS
681a39cfb0SJung-uk Kim LsDisplayNamespace (
691a39cfb0SJung-uk Kim     void);
7059db4265SNate Lawson 
711a39cfb0SJung-uk Kim void
72f556842eSJung-uk Kim LsSetupNsList (
73f556842eSJung-uk Kim     void                    *Handle);
741a39cfb0SJung-uk Kim 
751a39cfb0SJung-uk Kim 
761a39cfb0SJung-uk Kim /* Local prototypes */
771a39cfb0SJung-uk Kim 
78*4c52cad2SJung-uk Kim static UINT32
79*4c52cad2SJung-uk Kim AdGetFileSize (
80*4c52cad2SJung-uk Kim     FILE                    *File);
81*4c52cad2SJung-uk Kim 
8242fecd12SJung-uk Kim static void
831a39cfb0SJung-uk Kim AdCreateTableHeader (
841a39cfb0SJung-uk Kim     char                    *Filename,
851a39cfb0SJung-uk Kim     ACPI_TABLE_HEADER       *Table);
861a39cfb0SJung-uk Kim 
8742fecd12SJung-uk Kim static ACPI_STATUS
88a9f12690SJung-uk Kim AdDeferredParse (
89a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
90a9f12690SJung-uk Kim     UINT8                   *Aml,
91a9f12690SJung-uk Kim     UINT32                  AmlLength);
92a9f12690SJung-uk Kim 
9342fecd12SJung-uk Kim static ACPI_STATUS
94a9f12690SJung-uk Kim AdParseDeferredOps (
95a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Root);
96a9f12690SJung-uk Kim 
971a39cfb0SJung-uk Kim 
981a39cfb0SJung-uk Kim /* Stubs for ASL compiler */
9959db4265SNate Lawson 
100fba7fc7eSJung-uk Kim #ifndef ACPI_ASL_COMPILER
10159db4265SNate Lawson BOOLEAN
10259db4265SNate Lawson AcpiDsIsResultUsed (
10359db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op,
10459db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
10559db4265SNate Lawson {
10659db4265SNate Lawson     return TRUE;
10759db4265SNate Lawson }
1081a39cfb0SJung-uk Kim 
1091a39cfb0SJung-uk Kim ACPI_STATUS
1101a39cfb0SJung-uk Kim AcpiDsMethodError (
1111a39cfb0SJung-uk Kim     ACPI_STATUS             Status,
1121a39cfb0SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
1131a39cfb0SJung-uk Kim {
1141a39cfb0SJung-uk Kim     return (Status);
1151a39cfb0SJung-uk Kim }
11659db4265SNate Lawson #endif
11759db4265SNate Lawson 
11859db4265SNate Lawson ACPI_STATUS
1191a39cfb0SJung-uk Kim AcpiNsLoadTable (
120a9f12690SJung-uk Kim     UINT32                  TableIndex,
1211a39cfb0SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node)
1221a39cfb0SJung-uk Kim {
1231a39cfb0SJung-uk Kim     return (AE_NOT_IMPLEMENTED);
1241a39cfb0SJung-uk Kim }
1251a39cfb0SJung-uk Kim 
1261a39cfb0SJung-uk Kim ACPI_STATUS
12759db4265SNate Lawson AcpiDsRestartControlMethod (
12859db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
12959db4265SNate Lawson     ACPI_OPERAND_OBJECT     *ReturnDesc)
13059db4265SNate Lawson {
13159db4265SNate Lawson     return (AE_OK);
13259db4265SNate Lawson }
13359db4265SNate Lawson 
134fba7fc7eSJung-uk Kim void
13559db4265SNate Lawson AcpiDsTerminateControlMethod (
1361a39cfb0SJung-uk Kim     ACPI_OPERAND_OBJECT     *MethodDesc,
13759db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
13859db4265SNate Lawson {
139fba7fc7eSJung-uk Kim     return;
14059db4265SNate Lawson }
14159db4265SNate Lawson 
14259db4265SNate Lawson ACPI_STATUS
14359db4265SNate Lawson AcpiDsCallControlMethod (
14459db4265SNate Lawson     ACPI_THREAD_STATE       *Thread,
14559db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
14659db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op)
14759db4265SNate Lawson {
14859db4265SNate Lawson     return (AE_OK);
14959db4265SNate Lawson }
15059db4265SNate Lawson 
15159db4265SNate Lawson ACPI_STATUS
15259db4265SNate Lawson AcpiDsMethodDataInitArgs (
15359db4265SNate Lawson     ACPI_OPERAND_OBJECT     **Params,
15459db4265SNate Lawson     UINT32                  MaxParamCount,
15559db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
15659db4265SNate Lawson {
15759db4265SNate Lawson     return (AE_OK);
15859db4265SNate Lawson }
15959db4265SNate Lawson 
16059db4265SNate Lawson 
161f556842eSJung-uk Kim static ACPI_TABLE_DESC      LocalTables[1];
162f556842eSJung-uk Kim static ACPI_PARSE_OBJECT    *AcpiGbl_ParseOpRoot;
16359db4265SNate Lawson 
16459db4265SNate Lawson 
16559db4265SNate Lawson /*******************************************************************************
16659db4265SNate Lawson  *
167*4c52cad2SJung-uk Kim  * FUNCTION:    AdGetFileSize
168*4c52cad2SJung-uk Kim  *
169*4c52cad2SJung-uk Kim  * PARAMETERS:  File                - Open file handle
170*4c52cad2SJung-uk Kim  *
171*4c52cad2SJung-uk Kim  * RETURN:      File Size
172*4c52cad2SJung-uk Kim  *
173*4c52cad2SJung-uk Kim  * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open.
174*4c52cad2SJung-uk Kim  *
175*4c52cad2SJung-uk Kim  ******************************************************************************/
176*4c52cad2SJung-uk Kim 
177*4c52cad2SJung-uk Kim static UINT32
178*4c52cad2SJung-uk Kim AdGetFileSize (
179*4c52cad2SJung-uk Kim     FILE                    *File)
180*4c52cad2SJung-uk Kim {
181*4c52cad2SJung-uk Kim     UINT32                  FileSize;
182*4c52cad2SJung-uk Kim     long                    Offset;
183*4c52cad2SJung-uk Kim 
184*4c52cad2SJung-uk Kim 
185*4c52cad2SJung-uk Kim     Offset = ftell (File);
186*4c52cad2SJung-uk Kim 
187*4c52cad2SJung-uk Kim     fseek (File, 0, SEEK_END);
188*4c52cad2SJung-uk Kim     FileSize = (UINT32) ftell (File);
189*4c52cad2SJung-uk Kim 
190*4c52cad2SJung-uk Kim     /* Restore file pointer */
191*4c52cad2SJung-uk Kim 
192*4c52cad2SJung-uk Kim     fseek (File, Offset, SEEK_SET);
193*4c52cad2SJung-uk Kim     return (FileSize);
194*4c52cad2SJung-uk Kim }
195*4c52cad2SJung-uk Kim 
196*4c52cad2SJung-uk Kim 
197*4c52cad2SJung-uk Kim /*******************************************************************************
198*4c52cad2SJung-uk Kim  *
19959db4265SNate Lawson  * FUNCTION:    AdInitialize
20059db4265SNate Lawson  *
201f556842eSJung-uk Kim  * PARAMETERS:  None
20259db4265SNate Lawson  *
20359db4265SNate Lawson  * RETURN:      Status
20459db4265SNate Lawson  *
205f556842eSJung-uk Kim  * DESCRIPTION: ACPICA and local initialization
20659db4265SNate Lawson  *
20759db4265SNate Lawson  ******************************************************************************/
20859db4265SNate Lawson 
20959db4265SNate Lawson ACPI_STATUS
21059db4265SNate Lawson AdInitialize (
21159db4265SNate Lawson     void)
21259db4265SNate Lawson {
21359db4265SNate Lawson     ACPI_STATUS             Status;
21459db4265SNate Lawson 
21559db4265SNate Lawson 
21659db4265SNate Lawson     /* ACPI CA subsystem initialization */
21759db4265SNate Lawson 
2181a39cfb0SJung-uk Kim     Status = AcpiOsInitialize ();
219a9f12690SJung-uk Kim     if (ACPI_FAILURE (Status))
220a9f12690SJung-uk Kim     {
221a9f12690SJung-uk Kim         return (Status);
222a9f12690SJung-uk Kim     }
223a9f12690SJung-uk Kim 
224a9f12690SJung-uk Kim     Status = AcpiUtInitGlobals ();
225a9f12690SJung-uk Kim     if (ACPI_FAILURE (Status))
226a9f12690SJung-uk Kim     {
227a9f12690SJung-uk Kim         return (Status);
228a9f12690SJung-uk Kim     }
2291a39cfb0SJung-uk Kim 
23059db4265SNate Lawson     Status = AcpiUtMutexInitialize ();
23159db4265SNate Lawson     if (ACPI_FAILURE (Status))
23259db4265SNate Lawson     {
233a9f12690SJung-uk Kim         return (Status);
23459db4265SNate Lawson     }
23559db4265SNate Lawson 
23659db4265SNate Lawson     Status = AcpiNsRootInitialize ();
2371a39cfb0SJung-uk Kim     if (ACPI_FAILURE (Status))
2381a39cfb0SJung-uk Kim     {
239a9f12690SJung-uk Kim         return (Status);
2401a39cfb0SJung-uk Kim     }
2411a39cfb0SJung-uk Kim 
2421a39cfb0SJung-uk Kim     /* Setup the Table Manager (cheat - there is no RSDT) */
2431a39cfb0SJung-uk Kim 
2443f5e024cSJung-uk Kim     AcpiGbl_RootTableList.MaxTableCount = 1;
2453f5e024cSJung-uk Kim     AcpiGbl_RootTableList.CurrentTableCount = 0;
2461a39cfb0SJung-uk Kim     AcpiGbl_RootTableList.Tables = LocalTables;
2471a39cfb0SJung-uk Kim 
248a9f12690SJung-uk Kim     return (Status);
24959db4265SNate Lawson }
25059db4265SNate Lawson 
25159db4265SNate Lawson 
25259db4265SNate Lawson /******************************************************************************
25359db4265SNate Lawson  *
25459db4265SNate Lawson  * FUNCTION:    AdAmlDisassemble
25559db4265SNate Lawson  *
256fba7fc7eSJung-uk Kim  * PARAMETERS:  Filename            - AML input filename
257fba7fc7eSJung-uk Kim  *              OutToFile           - TRUE if output should go to a file
258fba7fc7eSJung-uk Kim  *              Prefix              - Path prefix for output
259fba7fc7eSJung-uk Kim  *              OutFilename         - where the filename is returned
260fba7fc7eSJung-uk Kim  *              GetAllTables        - TRUE if all tables are desired
26159db4265SNate Lawson  *
26259db4265SNate Lawson  * RETURN:      Status
26359db4265SNate Lawson  *
26459db4265SNate Lawson  * DESCRIPTION: Disassemble an entire ACPI table
26559db4265SNate Lawson  *
26659db4265SNate Lawson  *****************************************************************************/
26759db4265SNate Lawson 
26859db4265SNate Lawson ACPI_STATUS
26959db4265SNate Lawson AdAmlDisassemble (
27059db4265SNate Lawson     BOOLEAN                 OutToFile,
27159db4265SNate Lawson     char                    *Filename,
27259db4265SNate Lawson     char                    *Prefix,
27359db4265SNate Lawson     char                    **OutFilename,
27459db4265SNate Lawson     BOOLEAN                 GetAllTables)
27559db4265SNate Lawson {
27659db4265SNate Lawson     ACPI_STATUS             Status;
27759db4265SNate Lawson     char                    *DisasmFilename = NULL;
278a9f12690SJung-uk Kim     char                    *ExternalFilename;
279709fac06SJung-uk Kim     ACPI_EXTERNAL_FILE      *ExternalFileList = AcpiGbl_ExternalFileList;
28059db4265SNate Lawson     FILE                    *File = NULL;
281a9f12690SJung-uk Kim     ACPI_TABLE_HEADER       *Table = NULL;
2821a39cfb0SJung-uk Kim     ACPI_TABLE_HEADER       *ExternalTable;
283a9f12690SJung-uk Kim     ACPI_OWNER_ID           OwnerId;
28459db4265SNate Lawson 
28559db4265SNate Lawson 
28659db4265SNate Lawson     /*
287f556842eSJung-uk Kim      * Input: AML code from either a file or via GetTables (memory or
288f556842eSJung-uk Kim      * registry)
28959db4265SNate Lawson      */
29059db4265SNate Lawson     if (Filename)
29159db4265SNate Lawson     {
29259db4265SNate Lawson         Status = AcpiDbGetTableFromFile (Filename, &Table);
29359db4265SNate Lawson         if (ACPI_FAILURE (Status))
29459db4265SNate Lawson         {
29559db4265SNate Lawson             return Status;
29659db4265SNate Lawson         }
2971a39cfb0SJung-uk Kim 
298a9f12690SJung-uk Kim         /*
299a9f12690SJung-uk Kim          * External filenames separated by commas
300a9f12690SJung-uk Kim          * Example: iasl -e file1,file2,file3 -d xxx.aml
301a9f12690SJung-uk Kim          */
302709fac06SJung-uk Kim         while (ExternalFileList)
3031a39cfb0SJung-uk Kim         {
304709fac06SJung-uk Kim             ExternalFilename = ExternalFileList->Path;
305709fac06SJung-uk Kim             if (!ACPI_STRCMP (ExternalFilename, Filename))
306709fac06SJung-uk Kim             {
307709fac06SJung-uk Kim                 /* Next external file */
308a9f12690SJung-uk Kim 
309709fac06SJung-uk Kim                 ExternalFileList = ExternalFileList->Next;
310709fac06SJung-uk Kim 
311709fac06SJung-uk Kim                 continue;
312709fac06SJung-uk Kim             }
313709fac06SJung-uk Kim 
314a9f12690SJung-uk Kim             Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
3151a39cfb0SJung-uk Kim             if (ACPI_FAILURE (Status))
3161a39cfb0SJung-uk Kim             {
3171a39cfb0SJung-uk Kim                 return Status;
3181a39cfb0SJung-uk Kim             }
319a9f12690SJung-uk Kim 
320a9f12690SJung-uk Kim             /* Load external table for symbol resolution */
321a9f12690SJung-uk Kim 
322a9f12690SJung-uk Kim             if (ExternalTable)
323a9f12690SJung-uk Kim             {
324a9f12690SJung-uk Kim                 Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
325a9f12690SJung-uk Kim                 if (ACPI_FAILURE (Status))
326a9f12690SJung-uk Kim                 {
327a9f12690SJung-uk Kim                     AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
328a9f12690SJung-uk Kim                         AcpiFormatException (Status));
329a9f12690SJung-uk Kim                     return Status;
330a9f12690SJung-uk Kim                 }
331a9f12690SJung-uk Kim 
332a9f12690SJung-uk Kim                 /*
333a9f12690SJung-uk Kim                  * Load namespace from names created within control methods
334a9f12690SJung-uk Kim                  * Set owner id of nodes in external table
335a9f12690SJung-uk Kim                  */
336a9f12690SJung-uk Kim                 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
337a9f12690SJung-uk Kim                     AcpiGbl_RootNode, OwnerId);
338a9f12690SJung-uk Kim                 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
339a9f12690SJung-uk Kim             }
340a9f12690SJung-uk Kim 
341709fac06SJung-uk Kim             /* Next external file */
342a9f12690SJung-uk Kim 
343709fac06SJung-uk Kim             ExternalFileList = ExternalFileList->Next;
344a9f12690SJung-uk Kim         }
345a9f12690SJung-uk Kim 
346a9f12690SJung-uk Kim         /* Clear external list generated by Scope in external tables */
347a9f12690SJung-uk Kim 
348709fac06SJung-uk Kim         if (AcpiGbl_ExternalFileList)
349709fac06SJung-uk Kim         {
350f556842eSJung-uk Kim             AcpiDmClearExternalList ();
3511a39cfb0SJung-uk Kim         }
35259db4265SNate Lawson     }
35359db4265SNate Lawson     else
35459db4265SNate Lawson     {
35559db4265SNate Lawson         Status = AdGetLocalTables (Filename, GetAllTables);
35659db4265SNate Lawson         if (ACPI_FAILURE (Status))
35759db4265SNate Lawson         {
35859db4265SNate Lawson             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
35959db4265SNate Lawson                 AcpiFormatException (Status));
36059db4265SNate Lawson             return Status;
36159db4265SNate Lawson         }
36259db4265SNate Lawson 
36359db4265SNate Lawson         if (!AcpiGbl_DbOpt_disasm)
36459db4265SNate Lawson         {
36559db4265SNate Lawson             return AE_OK;
36659db4265SNate Lawson         }
36759db4265SNate Lawson 
3681a39cfb0SJung-uk Kim         /* Obtained the local tables, just disassemble the DSDT */
36959db4265SNate Lawson 
3701a39cfb0SJung-uk Kim         Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
3711a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
3721a39cfb0SJung-uk Kim         {
3731a39cfb0SJung-uk Kim             AcpiOsPrintf ("Could not get DSDT, %s\n",
3741a39cfb0SJung-uk Kim                 AcpiFormatException (Status));
3751a39cfb0SJung-uk Kim             return Status;
3761a39cfb0SJung-uk Kim         }
3771a39cfb0SJung-uk Kim 
37859db4265SNate Lawson         AcpiOsPrintf ("\nDisassembly of DSDT\n");
3791a39cfb0SJung-uk Kim         Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
38059db4265SNate Lawson     }
38159db4265SNate Lawson 
38259db4265SNate Lawson     /*
383f556842eSJung-uk Kim      * Output:  ASL code. Redirect to a file if requested
38459db4265SNate Lawson      */
38559db4265SNate Lawson     if (OutToFile)
38659db4265SNate Lawson     {
38759db4265SNate Lawson         /* Create/Open a disassembly output file */
38859db4265SNate Lawson 
38959db4265SNate Lawson         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
39059db4265SNate Lawson         if (!OutFilename)
39159db4265SNate Lawson         {
39259db4265SNate Lawson             fprintf (stderr, "Could not generate output filename\n");
393e50beb51SNate Lawson             Status = AE_ERROR;
394e50beb51SNate Lawson             goto Cleanup;
39559db4265SNate Lawson         }
39659db4265SNate Lawson 
39759db4265SNate Lawson         File = fopen (DisasmFilename, "w+");
39859db4265SNate Lawson         if (!File)
39959db4265SNate Lawson         {
4001a39cfb0SJung-uk Kim             fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
401e50beb51SNate Lawson             Status = AE_ERROR;
402e50beb51SNate Lawson             goto Cleanup;
40359db4265SNate Lawson         }
40459db4265SNate Lawson 
40559db4265SNate Lawson         AcpiOsRedirectOutput (File);
40659db4265SNate Lawson     }
40759db4265SNate Lawson 
40859db4265SNate Lawson     *OutFilename = DisasmFilename;
40959db4265SNate Lawson 
4101a39cfb0SJung-uk Kim     if (!AcpiUtIsAmlTable (Table))
4111a39cfb0SJung-uk Kim     {
4121a39cfb0SJung-uk Kim         AdDisassemblerHeader (Filename);
4131a39cfb0SJung-uk Kim         AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
4141a39cfb0SJung-uk Kim             Table->Signature);
415ec3fc72fSJung-uk Kim         AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]  "
416ec3fc72fSJung-uk Kim             "FieldName : FieldValue\n */\n\n");
4171a39cfb0SJung-uk Kim 
4181a39cfb0SJung-uk Kim         AcpiDmDumpDataTable (Table);
419*4c52cad2SJung-uk Kim         fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
420*4c52cad2SJung-uk Kim             Table->Signature);
421*4c52cad2SJung-uk Kim         fprintf (stderr, "Formatted output:  %s - %u bytes\n",
422*4c52cad2SJung-uk Kim             DisasmFilename, AdGetFileSize (File));
4231a39cfb0SJung-uk Kim     }
4241a39cfb0SJung-uk Kim     else
4251a39cfb0SJung-uk Kim     {
42659db4265SNate Lawson         /* Always parse the tables, only option is what to display */
42759db4265SNate Lawson 
428a9f12690SJung-uk Kim         Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
42959db4265SNate Lawson         if (ACPI_FAILURE (Status))
43059db4265SNate Lawson         {
43159db4265SNate Lawson             AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
43259db4265SNate Lawson                 AcpiFormatException (Status));
43359db4265SNate Lawson             goto Cleanup;
43459db4265SNate Lawson         }
43559db4265SNate Lawson 
4361a39cfb0SJung-uk Kim         if (AslCompilerdebug)
4371a39cfb0SJung-uk Kim         {
4381a39cfb0SJung-uk Kim             AcpiOsPrintf ("/**** Before second load\n");
4391a39cfb0SJung-uk Kim 
4401a39cfb0SJung-uk Kim             LsSetupNsList (File);
4411a39cfb0SJung-uk Kim             LsDisplayNamespace ();
4421a39cfb0SJung-uk Kim             AcpiOsPrintf ("*****/\n");
4431a39cfb0SJung-uk Kim         }
4441a39cfb0SJung-uk Kim 
445ec3fc72fSJung-uk Kim         /* Load namespace from names created within control methods */
446ec3fc72fSJung-uk Kim 
447ec3fc72fSJung-uk Kim         AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
448ec3fc72fSJung-uk Kim             AcpiGbl_RootNode, OwnerId);
4491a39cfb0SJung-uk Kim 
4501a39cfb0SJung-uk Kim         /*
451ec3fc72fSJung-uk Kim          * Cross reference the namespace here, in order to
452ec3fc72fSJung-uk Kim          * generate External() statements
4531a39cfb0SJung-uk Kim          */
454ec3fc72fSJung-uk Kim         AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
455ec3fc72fSJung-uk Kim             AcpiGbl_RootNode, OwnerId);
4561a39cfb0SJung-uk Kim 
4571a39cfb0SJung-uk Kim         if (AslCompilerdebug)
4581a39cfb0SJung-uk Kim         {
4591a39cfb0SJung-uk Kim             AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
4601a39cfb0SJung-uk Kim         }
4611a39cfb0SJung-uk Kim 
4621a39cfb0SJung-uk Kim         /* Find possible calls to external control methods */
4631a39cfb0SJung-uk Kim 
4641a39cfb0SJung-uk Kim         AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
4651a39cfb0SJung-uk Kim 
4661a39cfb0SJung-uk Kim         /*
467ec3fc72fSJung-uk Kim          * If we found any external control methods, we must reparse
468ec3fc72fSJung-uk Kim          * the entire tree with the new information (namely, the
469ec3fc72fSJung-uk Kim          * number of arguments per method)
4701a39cfb0SJung-uk Kim          */
471f556842eSJung-uk Kim         if (AcpiDmGetExternalMethodCount ())
4721a39cfb0SJung-uk Kim         {
4731a39cfb0SJung-uk Kim             fprintf (stderr,
474ec3fc72fSJung-uk Kim                 "\nFound %u external control methods, "
475ec3fc72fSJung-uk Kim                 "reparsing with new information\n",
476f556842eSJung-uk Kim                 AcpiDmGetExternalMethodCount ());
4771a39cfb0SJung-uk Kim 
478ec3fc72fSJung-uk Kim             /* Reparse, rebuild namespace. no need to xref namespace */
479ec3fc72fSJung-uk Kim 
4801a39cfb0SJung-uk Kim             AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
4811a39cfb0SJung-uk Kim             AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
4821a39cfb0SJung-uk Kim 
4831a39cfb0SJung-uk Kim             AcpiGbl_RootNode                    = NULL;
4841a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
4851a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
4861a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
487a88e22b7SJung-uk Kim             AcpiGbl_RootNodeStruct.Parent       = NULL;
4881a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Child        = NULL;
4891a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Peer         = NULL;
4901a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Object       = NULL;
491a88e22b7SJung-uk Kim             AcpiGbl_RootNodeStruct.Flags        = 0;
4921a39cfb0SJung-uk Kim 
4931a39cfb0SJung-uk Kim             Status = AcpiNsRootInitialize ();
494f556842eSJung-uk Kim             AcpiDmAddExternalsToNamespace ();
4951a39cfb0SJung-uk Kim 
496ec3fc72fSJung-uk Kim             /* Parse the table again. No need to reload it, however */
497a9f12690SJung-uk Kim 
498a9f12690SJung-uk Kim             Status = AdParseTable (Table, NULL, FALSE, FALSE);
4991a39cfb0SJung-uk Kim             if (ACPI_FAILURE (Status))
5001a39cfb0SJung-uk Kim             {
5011a39cfb0SJung-uk Kim                 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
5021a39cfb0SJung-uk Kim                     AcpiFormatException (Status));
5031a39cfb0SJung-uk Kim                 goto Cleanup;
5041a39cfb0SJung-uk Kim             }
5051a39cfb0SJung-uk Kim 
5061a39cfb0SJung-uk Kim             if (AslCompilerdebug)
5071a39cfb0SJung-uk Kim             {
508a9f12690SJung-uk Kim                 AcpiOsPrintf ("/**** After second load and resource conversion\n");
509a9f12690SJung-uk Kim                 LsSetupNsList (File);
510a9f12690SJung-uk Kim                 LsDisplayNamespace ();
511a9f12690SJung-uk Kim                 AcpiOsPrintf ("*****/\n");
512a9f12690SJung-uk Kim 
5131a39cfb0SJung-uk Kim                 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
5141a39cfb0SJung-uk Kim             }
5151a39cfb0SJung-uk Kim         }
516e0ef747bSNate Lawson 
517ec3fc72fSJung-uk Kim         /*
518ec3fc72fSJung-uk Kim          * Now that the namespace is finalized, we can perform namespace
519ec3fc72fSJung-uk Kim          * transforms.
520ec3fc72fSJung-uk Kim          *
521ec3fc72fSJung-uk Kim          * 1) Convert fixed-offset references to resource descriptors
522ec3fc72fSJung-uk Kim          *    to symbolic references (Note: modifies namespace)
523ec3fc72fSJung-uk Kim          */
524ec3fc72fSJung-uk Kim         AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
525ec3fc72fSJung-uk Kim 
52659db4265SNate Lawson         /* Optional displays */
52759db4265SNate Lawson 
52859db4265SNate Lawson         if (AcpiGbl_DbOpt_disasm)
52959db4265SNate Lawson         {
53059db4265SNate Lawson             AdDisplayTables (Filename, Table);
531*4c52cad2SJung-uk Kim             fprintf (stderr, "Disassembly completed\n");
532*4c52cad2SJung-uk Kim             fprintf (stderr, "ASL Output:    %s - %u bytes\n",
533*4c52cad2SJung-uk Kim                 DisasmFilename, AdGetFileSize (File));
5341a39cfb0SJung-uk Kim         }
53559db4265SNate Lawson     }
53659db4265SNate Lawson 
53759db4265SNate Lawson Cleanup:
538a9f12690SJung-uk Kim 
539a9f12690SJung-uk Kim     if (Table && !AcpiUtIsAmlTable (Table))
540a9f12690SJung-uk Kim     {
541a9f12690SJung-uk Kim         ACPI_FREE (Table);
542a9f12690SJung-uk Kim     }
543a9f12690SJung-uk Kim 
544a9f12690SJung-uk Kim     if (DisasmFilename)
545a9f12690SJung-uk Kim     {
546a9f12690SJung-uk Kim         ACPI_FREE (DisasmFilename);
547a9f12690SJung-uk Kim     }
548a9f12690SJung-uk Kim 
5491a39cfb0SJung-uk Kim     if (OutToFile && File)
55059db4265SNate Lawson     {
551ec3fc72fSJung-uk Kim         if (AslCompilerdebug) /* Display final namespace, with transforms */
552ec3fc72fSJung-uk Kim         {
5531a39cfb0SJung-uk Kim             LsSetupNsList (File);
5541a39cfb0SJung-uk Kim             LsDisplayNamespace ();
555ec3fc72fSJung-uk Kim         }
556ec3fc72fSJung-uk Kim 
55759db4265SNate Lawson         fclose (File);
55859db4265SNate Lawson         AcpiOsRedirectOutput (stdout);
55959db4265SNate Lawson     }
56059db4265SNate Lawson 
5611a39cfb0SJung-uk Kim     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
562a9f12690SJung-uk Kim     AcpiGbl_ParseOpRoot = NULL;
563a9f12690SJung-uk Kim     return (Status);
56459db4265SNate Lawson }
56559db4265SNate Lawson 
56659db4265SNate Lawson 
56759db4265SNate Lawson /******************************************************************************
56859db4265SNate Lawson  *
5691a39cfb0SJung-uk Kim  * FUNCTION:    AdDisassemblerHeader
5701a39cfb0SJung-uk Kim  *
5711a39cfb0SJung-uk Kim  * PARAMETERS:  Filename            - Input file for the table
5721a39cfb0SJung-uk Kim  *
5731a39cfb0SJung-uk Kim  * RETURN:      None
5741a39cfb0SJung-uk Kim  *
5751a39cfb0SJung-uk Kim  * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
5761a39cfb0SJung-uk Kim  *              current time and date.
5771a39cfb0SJung-uk Kim  *
5781a39cfb0SJung-uk Kim  *****************************************************************************/
5791a39cfb0SJung-uk Kim 
5801a39cfb0SJung-uk Kim void
5811a39cfb0SJung-uk Kim AdDisassemblerHeader (
5821a39cfb0SJung-uk Kim     char                    *Filename)
5831a39cfb0SJung-uk Kim {
5841a39cfb0SJung-uk Kim     time_t                  Timer;
5851a39cfb0SJung-uk Kim 
5861a39cfb0SJung-uk Kim     time (&Timer);
5871a39cfb0SJung-uk Kim 
5881a39cfb0SJung-uk Kim     /* Header and input table info */
5891a39cfb0SJung-uk Kim 
5903c1812acSJung-uk Kim     AcpiOsPrintf ("/*\n");
5913c1812acSJung-uk Kim     AcpiOsPrintf (ACPI_COMMON_HEADER ("AML Disassembler", " * "));
5921a39cfb0SJung-uk Kim 
5933c1812acSJung-uk Kim     AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
5941a39cfb0SJung-uk Kim     AcpiOsPrintf (" *\n");
5951a39cfb0SJung-uk Kim }
5961a39cfb0SJung-uk Kim 
5971a39cfb0SJung-uk Kim 
5981a39cfb0SJung-uk Kim /******************************************************************************
5991a39cfb0SJung-uk Kim  *
60059db4265SNate Lawson  * FUNCTION:    AdCreateTableHeader
60159db4265SNate Lawson  *
60259db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
60359db4265SNate Lawson  *              Table               - Pointer to the raw table
60459db4265SNate Lawson  *
60559db4265SNate Lawson  * RETURN:      None
60659db4265SNate Lawson  *
60759db4265SNate Lawson  * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
60859db4265SNate Lawson  *              current time and date.
60959db4265SNate Lawson  *
61059db4265SNate Lawson  *****************************************************************************/
61159db4265SNate Lawson 
61242fecd12SJung-uk Kim static void
61359db4265SNate Lawson AdCreateTableHeader (
61459db4265SNate Lawson     char                    *Filename,
61559db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
61659db4265SNate Lawson {
6171a39cfb0SJung-uk Kim     char                    *NewFilename;
618a9f12690SJung-uk Kim     UINT8                   Checksum;
61959db4265SNate Lawson 
62059db4265SNate Lawson 
621a9f12690SJung-uk Kim     /*
622a9f12690SJung-uk Kim      * Print file header and dump original table header
623a9f12690SJung-uk Kim      */
6241a39cfb0SJung-uk Kim     AdDisassemblerHeader (Filename);
62559db4265SNate Lawson 
626a88e22b7SJung-uk Kim     AcpiOsPrintf (" * Original Table Header:\n");
6271a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     Signature        \"%4.4s\"\n",    Table->Signature);
6281a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     Length           0x%8.8X (%u)\n", Table->Length, Table->Length);
629a9f12690SJung-uk Kim 
630a9f12690SJung-uk Kim     /* Print and validate the revision */
631a9f12690SJung-uk Kim 
632a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Revision         0x%2.2X",      Table->Revision);
633a9f12690SJung-uk Kim 
634a9f12690SJung-uk Kim     switch (Table->Revision)
635a9f12690SJung-uk Kim     {
636a9f12690SJung-uk Kim     case 0:
637a9f12690SJung-uk Kim         AcpiOsPrintf (" **** Invalid Revision");
638a9f12690SJung-uk Kim         break;
639a9f12690SJung-uk Kim 
640a9f12690SJung-uk Kim     case 1:
641a9f12690SJung-uk Kim         /* Revision of DSDT controls the ACPI integer width */
642a9f12690SJung-uk Kim 
643a9f12690SJung-uk Kim         if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
644a9f12690SJung-uk Kim         {
645d244b227SJung-uk Kim             AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
646a9f12690SJung-uk Kim         }
647a9f12690SJung-uk Kim         break;
648a9f12690SJung-uk Kim 
649a9f12690SJung-uk Kim     default:
650a9f12690SJung-uk Kim         break;
651a9f12690SJung-uk Kim     }
652a9f12690SJung-uk Kim     AcpiOsPrintf ("\n");
653a9f12690SJung-uk Kim 
654a9f12690SJung-uk Kim     /* Print and validate the table checksum */
655a9f12690SJung-uk Kim 
656a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Checksum         0x%2.2X",        Table->Checksum);
657a9f12690SJung-uk Kim 
658a9f12690SJung-uk Kim     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
659a9f12690SJung-uk Kim     if (Checksum)
660a9f12690SJung-uk Kim     {
661a9f12690SJung-uk Kim         AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
662a9f12690SJung-uk Kim             (UINT8) (Table->Checksum - Checksum));
663a9f12690SJung-uk Kim     }
664a9f12690SJung-uk Kim     AcpiOsPrintf ("\n");
665a9f12690SJung-uk Kim 
6661a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM ID           \"%.6s\"\n",     Table->OemId);
6671a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM Table ID     \"%.8s\"\n",     Table->OemTableId);
6681a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM Revision     0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
669a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Compiler ID      \"%.4s\"\n",     Table->AslCompilerId);
670a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
671a88e22b7SJung-uk Kim     AcpiOsPrintf (" */\n\n");
6721a39cfb0SJung-uk Kim 
6731a39cfb0SJung-uk Kim     /* Create AML output filename based on input filename */
6741a39cfb0SJung-uk Kim 
6751a39cfb0SJung-uk Kim     if (Filename)
6761a39cfb0SJung-uk Kim     {
6771a39cfb0SJung-uk Kim         NewFilename = FlGenerateFilename (Filename, "aml");
6781a39cfb0SJung-uk Kim     }
6791a39cfb0SJung-uk Kim     else
6801a39cfb0SJung-uk Kim     {
6811a39cfb0SJung-uk Kim         NewFilename = ACPI_ALLOCATE_ZEROED (9);
6821a39cfb0SJung-uk Kim         strncat (NewFilename, Table->Signature, 4);
6831a39cfb0SJung-uk Kim         strcat (NewFilename, ".aml");
6841a39cfb0SJung-uk Kim     }
6851a39cfb0SJung-uk Kim 
6861a39cfb0SJung-uk Kim     /* Open the ASL definition block */
68759db4265SNate Lawson 
68859db4265SNate Lawson     AcpiOsPrintf (
689a88e22b7SJung-uk Kim         "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
6901a39cfb0SJung-uk Kim         NewFilename, Table->Signature, Table->Revision,
69159db4265SNate Lawson         Table->OemId, Table->OemTableId, Table->OemRevision);
692a9f12690SJung-uk Kim 
693a9f12690SJung-uk Kim     ACPI_FREE (NewFilename);
69459db4265SNate Lawson }
69559db4265SNate Lawson 
69659db4265SNate Lawson 
69759db4265SNate Lawson /******************************************************************************
69859db4265SNate Lawson  *
69959db4265SNate Lawson  * FUNCTION:    AdDisplayTables
70059db4265SNate Lawson  *
70159db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
702fba7fc7eSJung-uk Kim  *              Table               - Pointer to the raw table
70359db4265SNate Lawson  *
70459db4265SNate Lawson  * RETURN:      Status
70559db4265SNate Lawson  *
70659db4265SNate Lawson  * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
70759db4265SNate Lawson  *
70859db4265SNate Lawson  *****************************************************************************/
70959db4265SNate Lawson 
71059db4265SNate Lawson ACPI_STATUS
71159db4265SNate Lawson AdDisplayTables (
71259db4265SNate Lawson     char                    *Filename,
71359db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
71459db4265SNate Lawson {
71559db4265SNate Lawson 
71659db4265SNate Lawson 
7171a39cfb0SJung-uk Kim     if (!AcpiGbl_ParseOpRoot)
71859db4265SNate Lawson     {
71959db4265SNate Lawson         return AE_NOT_EXIST;
72059db4265SNate Lawson     }
72159db4265SNate Lawson 
72259db4265SNate Lawson     if (!AcpiGbl_DbOpt_verbose)
72359db4265SNate Lawson     {
72459db4265SNate Lawson         AdCreateTableHeader (Filename, Table);
72559db4265SNate Lawson     }
72659db4265SNate Lawson 
7271a39cfb0SJung-uk Kim     AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
72859db4265SNate Lawson 
72959db4265SNate Lawson     if (AcpiGbl_DbOpt_verbose)
73059db4265SNate Lawson     {
73159db4265SNate Lawson         AcpiOsPrintf ("\n\nTable Header:\n");
73259db4265SNate Lawson         AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
73359db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
73459db4265SNate Lawson 
73559db4265SNate Lawson         AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
73659db4265SNate Lawson         AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
73759db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
73859db4265SNate Lawson     }
73959db4265SNate Lawson 
74059db4265SNate Lawson     return AE_OK;
74159db4265SNate Lawson }
74259db4265SNate Lawson 
74359db4265SNate Lawson 
74459db4265SNate Lawson /******************************************************************************
74559db4265SNate Lawson  *
74659db4265SNate Lawson  * FUNCTION:    AdDeferredParse
74759db4265SNate Lawson  *
74859db4265SNate Lawson  * PARAMETERS:  Op                  - Root Op of the deferred opcode
74959db4265SNate Lawson  *              Aml                 - Pointer to the raw AML
75059db4265SNate Lawson  *              AmlLength           - Length of the AML
75159db4265SNate Lawson  *
75259db4265SNate Lawson  * RETURN:      Status
75359db4265SNate Lawson  *
75459db4265SNate Lawson  * DESCRIPTION: Parse one deferred opcode
75559db4265SNate Lawson  *              (Methods, operation regions, etc.)
75659db4265SNate Lawson  *
75759db4265SNate Lawson  *****************************************************************************/
75859db4265SNate Lawson 
75942fecd12SJung-uk Kim static ACPI_STATUS
76059db4265SNate Lawson AdDeferredParse (
76159db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op,
76259db4265SNate Lawson     UINT8                   *Aml,
76359db4265SNate Lawson     UINT32                  AmlLength)
76459db4265SNate Lawson {
76559db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
76659db4265SNate Lawson     ACPI_STATUS             Status;
76759db4265SNate Lawson     ACPI_PARSE_OBJECT       *SearchOp;
76859db4265SNate Lawson     ACPI_PARSE_OBJECT       *StartOp;
76959db4265SNate Lawson     UINT32                  BaseAmlOffset;
77059db4265SNate Lawson     ACPI_PARSE_OBJECT       *ExtraOp;
77159db4265SNate Lawson 
77259db4265SNate Lawson 
7731a39cfb0SJung-uk Kim     ACPI_FUNCTION_TRACE (AdDeferredParse);
77459db4265SNate Lawson 
77559db4265SNate Lawson 
77659db4265SNate Lawson     fprintf (stderr, ".");
77759db4265SNate Lawson 
77859db4265SNate Lawson     if (!Aml || !AmlLength)
77959db4265SNate Lawson     {
78059db4265SNate Lawson         return_ACPI_STATUS (AE_OK);
78159db4265SNate Lawson     }
78259db4265SNate Lawson 
78359db4265SNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
78459db4265SNate Lawson         Op->Common.AmlOpName, (char *) &Op->Named.Name));
78559db4265SNate Lawson 
78659db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
78759db4265SNate Lawson     if (!WalkState)
78859db4265SNate Lawson     {
78959db4265SNate Lawson         return_ACPI_STATUS (AE_NO_MEMORY);
79059db4265SNate Lawson     }
79159db4265SNate Lawson 
79259db4265SNate Lawson     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
7931a39cfb0SJung-uk Kim                     AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
79459db4265SNate Lawson     if (ACPI_FAILURE (Status))
79559db4265SNate Lawson     {
79659db4265SNate Lawson         return_ACPI_STATUS (Status);
79759db4265SNate Lawson     }
79859db4265SNate Lawson 
79959db4265SNate Lawson     /* Parse the method */
80059db4265SNate Lawson 
80159db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
802fba7fc7eSJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
80359db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
80459db4265SNate Lawson 
80559db4265SNate Lawson     /*
80659db4265SNate Lawson      * We need to update all of the Aml offsets, since the parser thought
80759db4265SNate Lawson      * that the method began at offset zero.  In reality, it began somewhere
80859db4265SNate Lawson      * within the ACPI table, at the BaseAmlOffset.  Walk the entire tree that
80959db4265SNate Lawson      * was just created and update the AmlOffset in each Op
81059db4265SNate Lawson      */
81159db4265SNate Lawson     BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
81259db4265SNate Lawson     StartOp = (Op->Common.Value.Arg)->Common.Next;
81359db4265SNate Lawson     SearchOp = StartOp;
81459db4265SNate Lawson 
81559db4265SNate Lawson     /* Walk the parse tree */
81659db4265SNate Lawson 
81759db4265SNate Lawson     while (SearchOp)
81859db4265SNate Lawson     {
81959db4265SNate Lawson         SearchOp->Common.AmlOffset += BaseAmlOffset;
82059db4265SNate Lawson         SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
82159db4265SNate Lawson     }
82259db4265SNate Lawson 
82359db4265SNate Lawson     /*
82459db4265SNate Lawson      * Link the newly parsed subtree into the main parse tree
82559db4265SNate Lawson      */
82659db4265SNate Lawson     switch (Op->Common.AmlOpcode)
82759db4265SNate Lawson     {
82859db4265SNate Lawson     case AML_BUFFER_OP:
82959db4265SNate Lawson     case AML_PACKAGE_OP:
83059db4265SNate Lawson     case AML_VAR_PACKAGE_OP:
83159db4265SNate Lawson 
83259db4265SNate Lawson         switch (Op->Common.AmlOpcode)
83359db4265SNate Lawson         {
83459db4265SNate Lawson         case AML_PACKAGE_OP:
83559db4265SNate Lawson             ExtraOp = Op->Common.Value.Arg;
83659db4265SNate Lawson             ExtraOp = ExtraOp->Common.Next;
83759db4265SNate Lawson             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
83859db4265SNate Lawson             break;
83959db4265SNate Lawson 
840fba7fc7eSJung-uk Kim         case AML_VAR_PACKAGE_OP:
84159db4265SNate Lawson         case AML_BUFFER_OP:
84259db4265SNate Lawson         default:
84359db4265SNate Lawson             ExtraOp = Op->Common.Value.Arg;
84459db4265SNate Lawson             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
84559db4265SNate Lawson             break;
84659db4265SNate Lawson         }
84759db4265SNate Lawson 
84859db4265SNate Lawson         /* Must point all parents to the main tree */
84959db4265SNate Lawson 
85059db4265SNate Lawson         StartOp = Op;
85159db4265SNate Lawson         SearchOp = StartOp;
85259db4265SNate Lawson         while (SearchOp)
85359db4265SNate Lawson         {
85459db4265SNate Lawson             if (SearchOp->Common.Parent == ExtraOp)
85559db4265SNate Lawson             {
85659db4265SNate Lawson                 SearchOp->Common.Parent = Op;
85759db4265SNate Lawson             }
85859db4265SNate Lawson             SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
85959db4265SNate Lawson         }
86059db4265SNate Lawson         break;
86159db4265SNate Lawson 
86259db4265SNate Lawson     default:
86359db4265SNate Lawson         break;
86459db4265SNate Lawson     }
86559db4265SNate Lawson 
86659db4265SNate Lawson     return_ACPI_STATUS (AE_OK);
86759db4265SNate Lawson }
86859db4265SNate Lawson 
86959db4265SNate Lawson 
87059db4265SNate Lawson /******************************************************************************
87159db4265SNate Lawson  *
87259db4265SNate Lawson  * FUNCTION:    AdParseDeferredOps
87359db4265SNate Lawson  *
87459db4265SNate Lawson  * PARAMETERS:  Root                - Root of the parse tree
87559db4265SNate Lawson  *
87659db4265SNate Lawson  * RETURN:      Status
87759db4265SNate Lawson  *
87859db4265SNate Lawson  * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
87959db4265SNate Lawson  *
88059db4265SNate Lawson  *****************************************************************************/
88159db4265SNate Lawson 
88242fecd12SJung-uk Kim static ACPI_STATUS
88359db4265SNate Lawson AdParseDeferredOps (
88459db4265SNate Lawson     ACPI_PARSE_OBJECT       *Root)
88559db4265SNate Lawson {
88659db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op = Root;
88759db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
88859db4265SNate Lawson     const ACPI_OPCODE_INFO  *OpInfo;
88959db4265SNate Lawson 
89059db4265SNate Lawson 
8911a39cfb0SJung-uk Kim     ACPI_FUNCTION_NAME (AdParseDeferredOps);
89259db4265SNate Lawson     fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
89359db4265SNate Lawson 
89459db4265SNate Lawson     while (Op)
89559db4265SNate Lawson     {
89659db4265SNate Lawson         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
89759db4265SNate Lawson         if (!(OpInfo->Flags & AML_DEFER))
89859db4265SNate Lawson         {
89959db4265SNate Lawson             Op = AcpiPsGetDepthNext (Root, Op);
90059db4265SNate Lawson             continue;
90159db4265SNate Lawson         }
90259db4265SNate Lawson 
90359db4265SNate Lawson         switch (Op->Common.AmlOpcode)
90459db4265SNate Lawson         {
90559db4265SNate Lawson         case AML_METHOD_OP:
90659db4265SNate Lawson         case AML_BUFFER_OP:
90759db4265SNate Lawson         case AML_PACKAGE_OP:
90859db4265SNate Lawson         case AML_VAR_PACKAGE_OP:
90959db4265SNate Lawson 
91059db4265SNate Lawson             Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
91159db4265SNate Lawson             if (ACPI_FAILURE (Status))
91259db4265SNate Lawson             {
91359db4265SNate Lawson                 return_ACPI_STATUS (Status);
91459db4265SNate Lawson             }
91559db4265SNate Lawson             break;
91659db4265SNate Lawson 
91759db4265SNate Lawson         case AML_REGION_OP:
9183f0275a0SJung-uk Kim         case AML_DATA_REGION_OP:
91959db4265SNate Lawson         case AML_CREATE_QWORD_FIELD_OP:
92059db4265SNate Lawson         case AML_CREATE_DWORD_FIELD_OP:
92159db4265SNate Lawson         case AML_CREATE_WORD_FIELD_OP:
92259db4265SNate Lawson         case AML_CREATE_BYTE_FIELD_OP:
92359db4265SNate Lawson         case AML_CREATE_BIT_FIELD_OP:
92459db4265SNate Lawson         case AML_CREATE_FIELD_OP:
925a9f12690SJung-uk Kim         case AML_BANK_FIELD_OP:
92659db4265SNate Lawson 
92759db4265SNate Lawson             /* Nothing to do in these cases */
92859db4265SNate Lawson 
92959db4265SNate Lawson             break;
93059db4265SNate Lawson 
93159db4265SNate Lawson         default:
9321a39cfb0SJung-uk Kim             ACPI_ERROR ((AE_INFO, "Unhandled deferred opcode [%s]",
93359db4265SNate Lawson                 Op->Common.AmlOpName));
93459db4265SNate Lawson             break;
93559db4265SNate Lawson         }
93659db4265SNate Lawson 
93759db4265SNate Lawson         Op = AcpiPsGetDepthNext (Root, Op);
93859db4265SNate Lawson     }
93959db4265SNate Lawson 
94059db4265SNate Lawson     fprintf (stderr, "\n");
94159db4265SNate Lawson     return Status;
94259db4265SNate Lawson }
94359db4265SNate Lawson 
94459db4265SNate Lawson 
94559db4265SNate Lawson /******************************************************************************
94659db4265SNate Lawson  *
94759db4265SNate Lawson  * FUNCTION:    AdGetLocalTables
94859db4265SNate Lawson  *
949fba7fc7eSJung-uk Kim  * PARAMETERS:  Filename            - Not used
950fba7fc7eSJung-uk Kim  *              GetAllTables        - TRUE if all tables are desired
95159db4265SNate Lawson  *
952fba7fc7eSJung-uk Kim  * RETURN:      Status
95359db4265SNate Lawson  *
95459db4265SNate Lawson  * DESCRIPTION: Get the ACPI tables from either memory or a file
95559db4265SNate Lawson  *
95659db4265SNate Lawson  *****************************************************************************/
95759db4265SNate Lawson 
95859db4265SNate Lawson ACPI_STATUS
95959db4265SNate Lawson AdGetLocalTables (
96059db4265SNate Lawson     char                    *Filename,
96159db4265SNate Lawson     BOOLEAN                 GetAllTables)
96259db4265SNate Lawson {
96359db4265SNate Lawson     ACPI_STATUS             Status;
96459db4265SNate Lawson     ACPI_TABLE_HEADER       TableHeader;
96559db4265SNate Lawson     ACPI_TABLE_HEADER       *NewTable;
96659db4265SNate Lawson     UINT32                  NumTables;
96759db4265SNate Lawson     UINT32                  PointerSize;
968a9f12690SJung-uk Kim     UINT32                  TableIndex;
96959db4265SNate Lawson 
97059db4265SNate Lawson 
97159db4265SNate Lawson     if (GetAllTables)
97259db4265SNate Lawson     {
9731a39cfb0SJung-uk Kim         ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
97459db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
975e50beb51SNate Lawson         if (!NewTable)
976e50beb51SNate Lawson         {
977e50beb51SNate Lawson             fprintf (stderr, "Could not obtain RSDT\n");
978e50beb51SNate Lawson             return AE_NO_ACPI_TABLES;
979e50beb51SNate Lawson         }
980a9f12690SJung-uk Kim         else
981a9f12690SJung-uk Kim         {
982a9f12690SJung-uk Kim             AdWriteTable (NewTable, NewTable->Length,
983a9f12690SJung-uk Kim                 ACPI_SIG_RSDT, NewTable->OemTableId);
984a9f12690SJung-uk Kim         }
98559db4265SNate Lawson 
9861a39cfb0SJung-uk Kim         if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT))
98759db4265SNate Lawson         {
98859db4265SNate Lawson             PointerSize = sizeof (UINT32);
98959db4265SNate Lawson         }
99059db4265SNate Lawson         else
99159db4265SNate Lawson         {
99259db4265SNate Lawson             PointerSize = sizeof (UINT64);
99359db4265SNate Lawson         }
99459db4265SNate Lawson 
99559db4265SNate Lawson         /*
99659db4265SNate Lawson          * Determine the number of tables pointed to by the RSDT/XSDT.
99759db4265SNate Lawson          * This is defined by the ACPI Specification to be the number of
99859db4265SNate Lawson          * pointers contained within the RSDT/XSDT.  The size of the pointers
99959db4265SNate Lawson          * is architecture-dependent.
100059db4265SNate Lawson          */
100159db4265SNate Lawson         NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
1002a88e22b7SJung-uk Kim         AcpiOsPrintf ("There are %u tables defined in the %4.4s\n\n",
100359db4265SNate Lawson             NumTables, NewTable->Signature);
100459db4265SNate Lawson 
100559db4265SNate Lawson         /* Get the FADT */
100659db4265SNate Lawson 
10071a39cfb0SJung-uk Kim         ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
100859db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
100959db4265SNate Lawson         if (NewTable)
101059db4265SNate Lawson         {
101159db4265SNate Lawson             AdWriteTable (NewTable, NewTable->Length,
10121a39cfb0SJung-uk Kim                 ACPI_SIG_FADT, NewTable->OemTableId);
101359db4265SNate Lawson         }
101459db4265SNate Lawson         AcpiOsPrintf ("\n");
101559db4265SNate Lawson 
10161a39cfb0SJung-uk Kim         /* Don't bother with FACS, it is usually all zeros */
101759db4265SNate Lawson     }
101859db4265SNate Lawson 
101959db4265SNate Lawson     /* Always get the DSDT */
102059db4265SNate Lawson 
10211a39cfb0SJung-uk Kim     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
102259db4265SNate Lawson     AcpiOsTableOverride (&TableHeader, &NewTable);
102359db4265SNate Lawson     if (NewTable)
102459db4265SNate Lawson     {
10251a39cfb0SJung-uk Kim         AdWriteTable (NewTable, NewTable->Length,
10261a39cfb0SJung-uk Kim             ACPI_SIG_DSDT, NewTable->OemTableId);
10271a39cfb0SJung-uk Kim 
10281a39cfb0SJung-uk Kim         /* Store DSDT in the Table Manager */
10291a39cfb0SJung-uk Kim 
10301a39cfb0SJung-uk Kim         Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
10311a39cfb0SJung-uk Kim                     0, &TableIndex);
1032f556842eSJung-uk Kim         if (ACPI_FAILURE (Status))
1033f556842eSJung-uk Kim         {
1034f556842eSJung-uk Kim             fprintf (stderr, "Could not store DSDT\n");
1035f556842eSJung-uk Kim             return AE_NO_ACPI_TABLES;
1036f556842eSJung-uk Kim         }
103759db4265SNate Lawson     }
103859db4265SNate Lawson     else
103959db4265SNate Lawson     {
104059db4265SNate Lawson         fprintf (stderr, "Could not obtain DSDT\n");
1041e50beb51SNate Lawson         return AE_NO_ACPI_TABLES;
104259db4265SNate Lawson     }
104359db4265SNate Lawson 
10441a39cfb0SJung-uk Kim #if 0
10451a39cfb0SJung-uk Kim     /* TBD: Future implementation */
10461a39cfb0SJung-uk Kim 
104759db4265SNate Lawson     AcpiOsPrintf ("\n");
104859db4265SNate Lawson 
104959db4265SNate Lawson     /* Get all SSDTs */
105059db4265SNate Lawson 
10511a39cfb0SJung-uk Kim     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
10521a39cfb0SJung-uk Kim     do
105359db4265SNate Lawson     {
10541a39cfb0SJung-uk Kim         NewTable = NULL;
105559db4265SNate Lawson         Status = AcpiOsTableOverride (&TableHeader, &NewTable);
10561a39cfb0SJung-uk Kim 
10571a39cfb0SJung-uk Kim     } while (NewTable);
10581a39cfb0SJung-uk Kim #endif
105959db4265SNate Lawson 
106059db4265SNate Lawson     return AE_OK;
106159db4265SNate Lawson }
106259db4265SNate Lawson 
10631a39cfb0SJung-uk Kim 
106459db4265SNate Lawson /******************************************************************************
106559db4265SNate Lawson  *
106659db4265SNate Lawson  * FUNCTION:    AdParseTable
106759db4265SNate Lawson  *
1068fba7fc7eSJung-uk Kim  * PARAMETERS:  Table               - Pointer to the raw table
1069a9f12690SJung-uk Kim  *              OwnerId             - Returned OwnerId of the table
1070a9f12690SJung-uk Kim  *              LoadTable           - If add table to the global table list
1071a9f12690SJung-uk Kim  *              External            - If this is an external table
107259db4265SNate Lawson  *
107359db4265SNate Lawson  * RETURN:      Status
107459db4265SNate Lawson  *
107559db4265SNate Lawson  * DESCRIPTION: Parse the DSDT.
107659db4265SNate Lawson  *
107759db4265SNate Lawson  *****************************************************************************/
107859db4265SNate Lawson 
107959db4265SNate Lawson ACPI_STATUS
108059db4265SNate Lawson AdParseTable (
1081a9f12690SJung-uk Kim     ACPI_TABLE_HEADER       *Table,
1082a9f12690SJung-uk Kim     ACPI_OWNER_ID           *OwnerId,
1083a9f12690SJung-uk Kim     BOOLEAN                 LoadTable,
1084a9f12690SJung-uk Kim     BOOLEAN                 External)
108559db4265SNate Lawson {
108659db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
108759db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
108859db4265SNate Lawson     UINT8                   *AmlStart;
108959db4265SNate Lawson     UINT32                  AmlLength;
1090a9f12690SJung-uk Kim     UINT32                  TableIndex;
109159db4265SNate Lawson 
109259db4265SNate Lawson 
109359db4265SNate Lawson     if (!Table)
109459db4265SNate Lawson     {
109559db4265SNate Lawson         return AE_NOT_EXIST;
109659db4265SNate Lawson     }
109759db4265SNate Lawson 
109859db4265SNate Lawson     /* Pass 1:  Parse everything except control method bodies */
109959db4265SNate Lawson 
110059db4265SNate Lawson     fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
110159db4265SNate Lawson 
110259db4265SNate Lawson     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
110359db4265SNate Lawson     AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
110459db4265SNate Lawson 
110559db4265SNate Lawson     /* Create the root object */
110659db4265SNate Lawson 
11071a39cfb0SJung-uk Kim     AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
11081a39cfb0SJung-uk Kim     if (!AcpiGbl_ParseOpRoot)
110959db4265SNate Lawson     {
111059db4265SNate Lawson         return AE_NO_MEMORY;
111159db4265SNate Lawson     }
111259db4265SNate Lawson 
111359db4265SNate Lawson     /* Create and initialize a new walk state */
111459db4265SNate Lawson 
111559db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0,
11161a39cfb0SJung-uk Kim                         AcpiGbl_ParseOpRoot, NULL, NULL);
111759db4265SNate Lawson     if (!WalkState)
111859db4265SNate Lawson     {
111959db4265SNate Lawson         return (AE_NO_MEMORY);
112059db4265SNate Lawson     }
112159db4265SNate Lawson 
11221a39cfb0SJung-uk Kim     Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
11231a39cfb0SJung-uk Kim                 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
112459db4265SNate Lawson     if (ACPI_FAILURE (Status))
112559db4265SNate Lawson     {
112659db4265SNate Lawson         return (Status);
112759db4265SNate Lawson     }
112859db4265SNate Lawson 
112959db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
1130fba7fc7eSJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
113159db4265SNate Lawson 
113259db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
113359db4265SNate Lawson     if (ACPI_FAILURE (Status))
113459db4265SNate Lawson     {
113559db4265SNate Lawson         return Status;
113659db4265SNate Lawson     }
113759db4265SNate Lawson 
1138a9f12690SJung-uk Kim     /* If LoadTable is FALSE, we are parsing the last loaded table */
1139a9f12690SJung-uk Kim 
11403f5e024cSJung-uk Kim     TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
1141a9f12690SJung-uk Kim 
114259db4265SNate Lawson     /* Pass 2 */
114359db4265SNate Lawson 
1144a9f12690SJung-uk Kim     if (LoadTable)
1145a9f12690SJung-uk Kim     {
1146a9f12690SJung-uk Kim         Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
11471a39cfb0SJung-uk Kim                     Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
11481a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
11491a39cfb0SJung-uk Kim         {
11501a39cfb0SJung-uk Kim             return Status;
11511a39cfb0SJung-uk Kim         }
1152a9f12690SJung-uk Kim         Status = AcpiTbAllocateOwnerId (TableIndex);
1153a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
1154a9f12690SJung-uk Kim         {
1155a9f12690SJung-uk Kim             return Status;
1156a9f12690SJung-uk Kim         }
1157a9f12690SJung-uk Kim         if (OwnerId)
1158a9f12690SJung-uk Kim         {
1159a9f12690SJung-uk Kim             Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
1160a9f12690SJung-uk Kim             if (ACPI_FAILURE (Status))
1161a9f12690SJung-uk Kim             {
1162a9f12690SJung-uk Kim                 return Status;
1163a9f12690SJung-uk Kim             }
1164a9f12690SJung-uk Kim         }
1165a9f12690SJung-uk Kim     }
116659db4265SNate Lawson 
11671a39cfb0SJung-uk Kim     fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
11681a39cfb0SJung-uk Kim 
1169a9f12690SJung-uk Kim     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
117059db4265SNate Lawson     if (ACPI_FAILURE (Status))
117159db4265SNate Lawson     {
117259db4265SNate Lawson         return (Status);
117359db4265SNate Lawson     }
117459db4265SNate Lawson 
1175a9f12690SJung-uk Kim     /* No need to parse control methods of external table */
1176a9f12690SJung-uk Kim 
1177a9f12690SJung-uk Kim     if (External)
1178a9f12690SJung-uk Kim     {
1179a9f12690SJung-uk Kim         return AE_OK;
1180a9f12690SJung-uk Kim     }
1181a9f12690SJung-uk Kim 
118259db4265SNate Lawson     /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
118359db4265SNate Lawson 
11841a39cfb0SJung-uk Kim     Status = AdParseDeferredOps (AcpiGbl_ParseOpRoot);
11851a39cfb0SJung-uk Kim 
11861a39cfb0SJung-uk Kim     /* Process Resource Templates */
11871a39cfb0SJung-uk Kim 
11881a39cfb0SJung-uk Kim     AcpiDmFindResources (AcpiGbl_ParseOpRoot);
118959db4265SNate Lawson 
119059db4265SNate Lawson     fprintf (stderr, "Parsing completed\n");
119159db4265SNate Lawson     return AE_OK;
119259db4265SNate Lawson }
119359db4265SNate Lawson 
119459db4265SNate Lawson 
1195