159db4265SNate Lawson /****************************************************************************** 259db4265SNate Lawson * 359db4265SNate Lawson * Module Name: adisasm - Application-level disassembler routines 459db4265SNate Lawson * 559db4265SNate Lawson *****************************************************************************/ 659db4265SNate Lawson 7d244b227SJung-uk Kim /* 81c0e1b6dSJung-uk Kim * Copyright (C) 2000 - 2015, 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 44313a0c13SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 45ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h> 46ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h> 47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h> 48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h> 49ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h> 50ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h> 51ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h> 5259db4265SNate Lawson 5359db4265SNate Lawson #include <stdio.h> 5459db4265SNate Lawson #include <time.h> 5559db4265SNate Lawson 5659db4265SNate Lawson 5759db4265SNate Lawson #define _COMPONENT ACPI_TOOLS 5859db4265SNate Lawson ACPI_MODULE_NAME ("adisasm") 5959db4265SNate Lawson 601a39cfb0SJung-uk Kim /* Local prototypes */ 611a39cfb0SJung-uk Kim 6242fecd12SJung-uk Kim static void 631a39cfb0SJung-uk Kim AdCreateTableHeader ( 641a39cfb0SJung-uk Kim char *Filename, 651a39cfb0SJung-uk Kim ACPI_TABLE_HEADER *Table); 661a39cfb0SJung-uk Kim 677cf3e94aSJung-uk Kim static ACPI_STATUS 687cf3e94aSJung-uk Kim AdStoreTable ( 697cf3e94aSJung-uk Kim ACPI_TABLE_HEADER *Table, 707cf3e94aSJung-uk Kim UINT32 *TableIndex); 717cf3e94aSJung-uk Kim 721a39cfb0SJung-uk Kim /* Stubs for ASL compiler */ 7359db4265SNate Lawson 74fba7fc7eSJung-uk Kim #ifndef ACPI_ASL_COMPILER 7559db4265SNate Lawson BOOLEAN 7659db4265SNate Lawson AcpiDsIsResultUsed ( 7759db4265SNate Lawson ACPI_PARSE_OBJECT *Op, 7859db4265SNate Lawson ACPI_WALK_STATE *WalkState) 7959db4265SNate Lawson { 8059db4265SNate Lawson return TRUE; 8159db4265SNate Lawson } 821a39cfb0SJung-uk Kim 831a39cfb0SJung-uk Kim ACPI_STATUS 841a39cfb0SJung-uk Kim AcpiDsMethodError ( 851a39cfb0SJung-uk Kim ACPI_STATUS Status, 861a39cfb0SJung-uk Kim ACPI_WALK_STATE *WalkState) 871a39cfb0SJung-uk Kim { 881a39cfb0SJung-uk Kim return (Status); 891a39cfb0SJung-uk Kim } 9059db4265SNate Lawson #endif 9159db4265SNate Lawson 9259db4265SNate Lawson ACPI_STATUS 931a39cfb0SJung-uk Kim AcpiNsLoadTable ( 94a9f12690SJung-uk Kim UINT32 TableIndex, 951a39cfb0SJung-uk Kim ACPI_NAMESPACE_NODE *Node) 961a39cfb0SJung-uk Kim { 971a39cfb0SJung-uk Kim return (AE_NOT_IMPLEMENTED); 981a39cfb0SJung-uk Kim } 991a39cfb0SJung-uk Kim 1001a39cfb0SJung-uk Kim ACPI_STATUS 10159db4265SNate Lawson AcpiDsRestartControlMethod ( 10259db4265SNate Lawson ACPI_WALK_STATE *WalkState, 10359db4265SNate Lawson ACPI_OPERAND_OBJECT *ReturnDesc) 10459db4265SNate Lawson { 10559db4265SNate Lawson return (AE_OK); 10659db4265SNate Lawson } 10759db4265SNate Lawson 108fba7fc7eSJung-uk Kim void 10959db4265SNate Lawson AcpiDsTerminateControlMethod ( 1101a39cfb0SJung-uk Kim ACPI_OPERAND_OBJECT *MethodDesc, 11159db4265SNate Lawson ACPI_WALK_STATE *WalkState) 11259db4265SNate Lawson { 113fba7fc7eSJung-uk Kim return; 11459db4265SNate Lawson } 11559db4265SNate Lawson 11659db4265SNate Lawson ACPI_STATUS 11759db4265SNate Lawson AcpiDsCallControlMethod ( 11859db4265SNate Lawson ACPI_THREAD_STATE *Thread, 11959db4265SNate Lawson ACPI_WALK_STATE *WalkState, 12059db4265SNate Lawson ACPI_PARSE_OBJECT *Op) 12159db4265SNate Lawson { 12259db4265SNate Lawson return (AE_OK); 12359db4265SNate Lawson } 12459db4265SNate Lawson 12559db4265SNate Lawson ACPI_STATUS 12659db4265SNate Lawson AcpiDsMethodDataInitArgs ( 12759db4265SNate Lawson ACPI_OPERAND_OBJECT **Params, 12859db4265SNate Lawson UINT32 MaxParamCount, 12959db4265SNate Lawson ACPI_WALK_STATE *WalkState) 13059db4265SNate Lawson { 13159db4265SNate Lawson return (AE_OK); 13259db4265SNate Lawson } 13359db4265SNate Lawson 13459db4265SNate Lawson 135f556842eSJung-uk Kim static ACPI_TABLE_DESC LocalTables[1]; 136*70e6ab8fSJung-uk Kim static ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot; 1374c52cad2SJung-uk Kim 1384c52cad2SJung-uk Kim 1394c52cad2SJung-uk Kim /******************************************************************************* 1404c52cad2SJung-uk Kim * 14159db4265SNate Lawson * FUNCTION: AdInitialize 14259db4265SNate Lawson * 143f556842eSJung-uk Kim * PARAMETERS: None 14459db4265SNate Lawson * 14559db4265SNate Lawson * RETURN: Status 14659db4265SNate Lawson * 147f556842eSJung-uk Kim * DESCRIPTION: ACPICA and local initialization 14859db4265SNate Lawson * 14959db4265SNate Lawson ******************************************************************************/ 15059db4265SNate Lawson 15159db4265SNate Lawson ACPI_STATUS 15259db4265SNate Lawson AdInitialize ( 15359db4265SNate Lawson void) 15459db4265SNate Lawson { 15559db4265SNate Lawson ACPI_STATUS Status; 15659db4265SNate Lawson 15759db4265SNate Lawson 15859db4265SNate Lawson /* ACPICA subsystem initialization */ 15959db4265SNate Lawson 1601a39cfb0SJung-uk Kim Status = AcpiOsInitialize (); 161a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 162a9f12690SJung-uk Kim { 163a9f12690SJung-uk Kim return (Status); 164a9f12690SJung-uk Kim } 165a9f12690SJung-uk Kim 166a9f12690SJung-uk Kim Status = AcpiUtInitGlobals (); 167a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 168a9f12690SJung-uk Kim { 169a9f12690SJung-uk Kim return (Status); 170a9f12690SJung-uk Kim } 1711a39cfb0SJung-uk Kim 17259db4265SNate Lawson Status = AcpiUtMutexInitialize (); 17359db4265SNate Lawson if (ACPI_FAILURE (Status)) 17459db4265SNate Lawson { 175a9f12690SJung-uk Kim return (Status); 17659db4265SNate Lawson } 17759db4265SNate Lawson 17859db4265SNate Lawson Status = AcpiNsRootInitialize (); 1791a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 1801a39cfb0SJung-uk Kim { 181a9f12690SJung-uk Kim return (Status); 1821a39cfb0SJung-uk Kim } 1831a39cfb0SJung-uk Kim 1841a39cfb0SJung-uk Kim /* Setup the Table Manager (cheat - there is no RSDT) */ 1851a39cfb0SJung-uk Kim 1863f5e024cSJung-uk Kim AcpiGbl_RootTableList.MaxTableCount = 1; 1873f5e024cSJung-uk Kim AcpiGbl_RootTableList.CurrentTableCount = 0; 1881a39cfb0SJung-uk Kim AcpiGbl_RootTableList.Tables = LocalTables; 1891a39cfb0SJung-uk Kim 190a9f12690SJung-uk Kim return (Status); 19159db4265SNate Lawson } 19259db4265SNate Lawson 19359db4265SNate Lawson 19459db4265SNate Lawson /****************************************************************************** 19559db4265SNate Lawson * 19659db4265SNate Lawson * FUNCTION: AdAmlDisassemble 19759db4265SNate Lawson * 198fba7fc7eSJung-uk Kim * PARAMETERS: Filename - AML input filename 199fba7fc7eSJung-uk Kim * OutToFile - TRUE if output should go to a file 200fba7fc7eSJung-uk Kim * Prefix - Path prefix for output 201fba7fc7eSJung-uk Kim * OutFilename - where the filename is returned 20259db4265SNate Lawson * 20359db4265SNate Lawson * RETURN: Status 20459db4265SNate Lawson * 20559db4265SNate Lawson * DESCRIPTION: Disassemble an entire ACPI table 20659db4265SNate Lawson * 20759db4265SNate Lawson *****************************************************************************/ 20859db4265SNate Lawson 20959db4265SNate Lawson ACPI_STATUS 21059db4265SNate Lawson AdAmlDisassemble ( 21159db4265SNate Lawson BOOLEAN OutToFile, 21259db4265SNate Lawson char *Filename, 21359db4265SNate Lawson char *Prefix, 214313a0c13SJung-uk Kim char **OutFilename) 21559db4265SNate Lawson { 21659db4265SNate Lawson ACPI_STATUS Status; 217a371a5fdSJung-uk Kim ACPI_STATUS GlobalStatus = AE_OK; 21859db4265SNate Lawson char *DisasmFilename = NULL; 219a9f12690SJung-uk Kim char *ExternalFilename; 220709fac06SJung-uk Kim ACPI_EXTERNAL_FILE *ExternalFileList = AcpiGbl_ExternalFileList; 22159db4265SNate Lawson FILE *File = NULL; 222a9f12690SJung-uk Kim ACPI_TABLE_HEADER *Table = NULL; 2231a39cfb0SJung-uk Kim ACPI_TABLE_HEADER *ExternalTable; 224a9f12690SJung-uk Kim ACPI_OWNER_ID OwnerId; 22559db4265SNate Lawson 22659db4265SNate Lawson 22759db4265SNate Lawson /* 228f556842eSJung-uk Kim * Input: AML code from either a file or via GetTables (memory or 229f556842eSJung-uk Kim * registry) 23059db4265SNate Lawson */ 23159db4265SNate Lawson if (Filename) 23259db4265SNate Lawson { 233a371a5fdSJung-uk Kim Status = AcpiDbGetTableFromFile (Filename, &Table, FALSE); 23459db4265SNate Lawson if (ACPI_FAILURE (Status)) 23559db4265SNate Lawson { 2368ef1a331SJung-uk Kim return (Status); 23759db4265SNate Lawson } 2381a39cfb0SJung-uk Kim 239a9f12690SJung-uk Kim /* 240a9f12690SJung-uk Kim * External filenames separated by commas 241a9f12690SJung-uk Kim * Example: iasl -e file1,file2,file3 -d xxx.aml 242a9f12690SJung-uk Kim */ 243709fac06SJung-uk Kim while (ExternalFileList) 2441a39cfb0SJung-uk Kim { 245709fac06SJung-uk Kim ExternalFilename = ExternalFileList->Path; 2465ef50723SJung-uk Kim if (!strcmp (ExternalFilename, Filename)) 247709fac06SJung-uk Kim { 248709fac06SJung-uk Kim /* Next external file */ 249a9f12690SJung-uk Kim 250709fac06SJung-uk Kim ExternalFileList = ExternalFileList->Next; 251709fac06SJung-uk Kim continue; 252709fac06SJung-uk Kim } 253709fac06SJung-uk Kim 254a371a5fdSJung-uk Kim Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable, TRUE); 2551a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 2561a39cfb0SJung-uk Kim { 257a371a5fdSJung-uk Kim if (Status == AE_TYPE) 258a371a5fdSJung-uk Kim { 259a371a5fdSJung-uk Kim ExternalFileList = ExternalFileList->Next; 260a371a5fdSJung-uk Kim GlobalStatus = AE_TYPE; 261a371a5fdSJung-uk Kim Status = AE_OK; 262a371a5fdSJung-uk Kim continue; 263a371a5fdSJung-uk Kim } 2648ef1a331SJung-uk Kim return (Status); 2651a39cfb0SJung-uk Kim } 266a9f12690SJung-uk Kim 267a9f12690SJung-uk Kim /* Load external table for symbol resolution */ 268a9f12690SJung-uk Kim 269a9f12690SJung-uk Kim if (ExternalTable) 270a9f12690SJung-uk Kim { 271a9f12690SJung-uk Kim Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE); 272a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 273a9f12690SJung-uk Kim { 274a9f12690SJung-uk Kim AcpiOsPrintf ("Could not parse external ACPI tables, %s\n", 275a9f12690SJung-uk Kim AcpiFormatException (Status)); 2768ef1a331SJung-uk Kim return (Status); 277a9f12690SJung-uk Kim } 278a9f12690SJung-uk Kim 279a9f12690SJung-uk Kim /* 280a9f12690SJung-uk Kim * Load namespace from names created within control methods 281a9f12690SJung-uk Kim * Set owner id of nodes in external table 282a9f12690SJung-uk Kim */ 283a9f12690SJung-uk Kim AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, 284a9f12690SJung-uk Kim AcpiGbl_RootNode, OwnerId); 285a9f12690SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 286a9f12690SJung-uk Kim } 287a9f12690SJung-uk Kim 288709fac06SJung-uk Kim /* Next external file */ 289a9f12690SJung-uk Kim 290709fac06SJung-uk Kim ExternalFileList = ExternalFileList->Next; 291a9f12690SJung-uk Kim } 292a9f12690SJung-uk Kim 293a371a5fdSJung-uk Kim if (ACPI_FAILURE (GlobalStatus)) 294a371a5fdSJung-uk Kim { 295a371a5fdSJung-uk Kim return (GlobalStatus); 296a371a5fdSJung-uk Kim } 297a371a5fdSJung-uk Kim 298a9f12690SJung-uk Kim /* Clear external list generated by Scope in external tables */ 299a9f12690SJung-uk Kim 300709fac06SJung-uk Kim if (AcpiGbl_ExternalFileList) 301709fac06SJung-uk Kim { 302f556842eSJung-uk Kim AcpiDmClearExternalList (); 3031a39cfb0SJung-uk Kim } 30479c6d946SJung-uk Kim 30579c6d946SJung-uk Kim /* Load any externals defined in the optional external ref file */ 30679c6d946SJung-uk Kim 30779c6d946SJung-uk Kim AcpiDmGetExternalsFromFile (); 30859db4265SNate Lawson } 30959db4265SNate Lawson else 31059db4265SNate Lawson { 311313a0c13SJung-uk Kim Status = AdGetLocalTables (); 31259db4265SNate Lawson if (ACPI_FAILURE (Status)) 31359db4265SNate Lawson { 31459db4265SNate Lawson AcpiOsPrintf ("Could not get ACPI tables, %s\n", 31559db4265SNate Lawson AcpiFormatException (Status)); 3168ef1a331SJung-uk Kim return (Status); 31759db4265SNate Lawson } 31859db4265SNate Lawson 319*70e6ab8fSJung-uk Kim if (!AcpiGbl_DmOpt_Disasm) 32059db4265SNate Lawson { 3218ef1a331SJung-uk Kim return (AE_OK); 32259db4265SNate Lawson } 32359db4265SNate Lawson 3241a39cfb0SJung-uk Kim /* Obtained the local tables, just disassemble the DSDT */ 32559db4265SNate Lawson 3261a39cfb0SJung-uk Kim Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table); 3271a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 3281a39cfb0SJung-uk Kim { 3291a39cfb0SJung-uk Kim AcpiOsPrintf ("Could not get DSDT, %s\n", 3301a39cfb0SJung-uk Kim AcpiFormatException (Status)); 3318ef1a331SJung-uk Kim return (Status); 3321a39cfb0SJung-uk Kim } 3331a39cfb0SJung-uk Kim 33459db4265SNate Lawson AcpiOsPrintf ("\nDisassembly of DSDT\n"); 3351a39cfb0SJung-uk Kim Prefix = AdGenerateFilename ("dsdt", Table->OemTableId); 33659db4265SNate Lawson } 33759db4265SNate Lawson 33859db4265SNate Lawson /* 339f556842eSJung-uk Kim * Output: ASL code. Redirect to a file if requested 34059db4265SNate Lawson */ 34159db4265SNate Lawson if (OutToFile) 34259db4265SNate Lawson { 34359db4265SNate Lawson /* Create/Open a disassembly output file */ 34459db4265SNate Lawson 34559db4265SNate Lawson DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY); 346313a0c13SJung-uk Kim if (!DisasmFilename) 34759db4265SNate Lawson { 34859db4265SNate Lawson fprintf (stderr, "Could not generate output filename\n"); 349e50beb51SNate Lawson Status = AE_ERROR; 350e50beb51SNate Lawson goto Cleanup; 35159db4265SNate Lawson } 35259db4265SNate Lawson 35359db4265SNate Lawson File = fopen (DisasmFilename, "w+"); 35459db4265SNate Lawson if (!File) 35559db4265SNate Lawson { 3561a39cfb0SJung-uk Kim fprintf (stderr, "Could not open output file %s\n", DisasmFilename); 357e50beb51SNate Lawson Status = AE_ERROR; 358e50beb51SNate Lawson goto Cleanup; 35959db4265SNate Lawson } 36059db4265SNate Lawson 36159db4265SNate Lawson AcpiOsRedirectOutput (File); 36259db4265SNate Lawson } 36359db4265SNate Lawson 36459db4265SNate Lawson *OutFilename = DisasmFilename; 36559db4265SNate Lawson 3667cf3e94aSJung-uk Kim /* ForceAmlDisassembly means to assume the table contains valid AML */ 3677cf3e94aSJung-uk Kim 3687cf3e94aSJung-uk Kim if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table)) 3691a39cfb0SJung-uk Kim { 3707cf3e94aSJung-uk Kim AdDisassemblerHeader (Filename, ACPI_IS_DATA_TABLE); 3711a39cfb0SJung-uk Kim AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n", 3721a39cfb0SJung-uk Kim Table->Signature); 373ec3fc72fSJung-uk Kim AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] " 374ec3fc72fSJung-uk Kim "FieldName : FieldValue\n */\n\n"); 3751a39cfb0SJung-uk Kim 3761a39cfb0SJung-uk Kim AcpiDmDumpDataTable (Table); 3774c52cad2SJung-uk Kim fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n", 3784c52cad2SJung-uk Kim Table->Signature); 3791c0e1b6dSJung-uk Kim 3801c0e1b6dSJung-uk Kim if (File) 3811c0e1b6dSJung-uk Kim { 3824c52cad2SJung-uk Kim fprintf (stderr, "Formatted output: %s - %u bytes\n", 383313a0c13SJung-uk Kim DisasmFilename, CmGetFileSize (File)); 3841a39cfb0SJung-uk Kim } 3851c0e1b6dSJung-uk Kim } 3861a39cfb0SJung-uk Kim else 3871a39cfb0SJung-uk Kim { 38859db4265SNate Lawson /* Always parse the tables, only option is what to display */ 38959db4265SNate Lawson 390a9f12690SJung-uk Kim Status = AdParseTable (Table, &OwnerId, TRUE, FALSE); 39159db4265SNate Lawson if (ACPI_FAILURE (Status)) 39259db4265SNate Lawson { 39359db4265SNate Lawson AcpiOsPrintf ("Could not parse ACPI tables, %s\n", 39459db4265SNate Lawson AcpiFormatException (Status)); 39559db4265SNate Lawson goto Cleanup; 39659db4265SNate Lawson } 39759db4265SNate Lawson 3981a39cfb0SJung-uk Kim if (AslCompilerdebug) 3991a39cfb0SJung-uk Kim { 4001a39cfb0SJung-uk Kim AcpiOsPrintf ("/**** Before second load\n"); 4011a39cfb0SJung-uk Kim 4021c0e1b6dSJung-uk Kim if (File) 4031c0e1b6dSJung-uk Kim { 404efcc2a30SJung-uk Kim NsSetupNamespaceListing (File); 405efcc2a30SJung-uk Kim NsDisplayNamespace (); 4061c0e1b6dSJung-uk Kim } 4071a39cfb0SJung-uk Kim AcpiOsPrintf ("*****/\n"); 4081a39cfb0SJung-uk Kim } 4091a39cfb0SJung-uk Kim 410ec3fc72fSJung-uk Kim /* Load namespace from names created within control methods */ 411ec3fc72fSJung-uk Kim 412ec3fc72fSJung-uk Kim AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, 413ec3fc72fSJung-uk Kim AcpiGbl_RootNode, OwnerId); 4141a39cfb0SJung-uk Kim 4151a39cfb0SJung-uk Kim /* 416ec3fc72fSJung-uk Kim * Cross reference the namespace here, in order to 417ec3fc72fSJung-uk Kim * generate External() statements 4181a39cfb0SJung-uk Kim */ 419ec3fc72fSJung-uk Kim AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, 420ec3fc72fSJung-uk Kim AcpiGbl_RootNode, OwnerId); 4211a39cfb0SJung-uk Kim 4221a39cfb0SJung-uk Kim if (AslCompilerdebug) 4231a39cfb0SJung-uk Kim { 4241a39cfb0SJung-uk Kim AcpiDmDumpTree (AcpiGbl_ParseOpRoot); 4251a39cfb0SJung-uk Kim } 4261a39cfb0SJung-uk Kim 4271a39cfb0SJung-uk Kim /* Find possible calls to external control methods */ 4281a39cfb0SJung-uk Kim 4291a39cfb0SJung-uk Kim AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot); 4301a39cfb0SJung-uk Kim 4311a39cfb0SJung-uk Kim /* 432ec3fc72fSJung-uk Kim * If we found any external control methods, we must reparse 433ec3fc72fSJung-uk Kim * the entire tree with the new information (namely, the 434ec3fc72fSJung-uk Kim * number of arguments per method) 4351a39cfb0SJung-uk Kim */ 436f556842eSJung-uk Kim if (AcpiDmGetExternalMethodCount ()) 4371a39cfb0SJung-uk Kim { 4381a39cfb0SJung-uk Kim fprintf (stderr, 439ec3fc72fSJung-uk Kim "\nFound %u external control methods, " 440ec3fc72fSJung-uk Kim "reparsing with new information\n", 441f556842eSJung-uk Kim AcpiDmGetExternalMethodCount ()); 4421a39cfb0SJung-uk Kim 443313a0c13SJung-uk Kim /* Reparse, rebuild namespace */ 444ec3fc72fSJung-uk Kim 4451a39cfb0SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 446313a0c13SJung-uk Kim AcpiGbl_ParseOpRoot = NULL; 4471a39cfb0SJung-uk Kim AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode); 4481a39cfb0SJung-uk Kim 4491a39cfb0SJung-uk Kim AcpiGbl_RootNode = NULL; 4501a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME; 4511a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED; 4521a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE; 453a88e22b7SJung-uk Kim AcpiGbl_RootNodeStruct.Parent = NULL; 4541a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Child = NULL; 4551a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Peer = NULL; 4561a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Object = NULL; 457a88e22b7SJung-uk Kim AcpiGbl_RootNodeStruct.Flags = 0; 4581a39cfb0SJung-uk Kim 4591a39cfb0SJung-uk Kim Status = AcpiNsRootInitialize (); 460313a0c13SJung-uk Kim 461313a0c13SJung-uk Kim /* New namespace, add the external definitions first */ 462313a0c13SJung-uk Kim 463f556842eSJung-uk Kim AcpiDmAddExternalsToNamespace (); 4641a39cfb0SJung-uk Kim 465ec3fc72fSJung-uk Kim /* Parse the table again. No need to reload it, however */ 466a9f12690SJung-uk Kim 467a9f12690SJung-uk Kim Status = AdParseTable (Table, NULL, FALSE, FALSE); 4681a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 4691a39cfb0SJung-uk Kim { 4701a39cfb0SJung-uk Kim AcpiOsPrintf ("Could not parse ACPI tables, %s\n", 4711a39cfb0SJung-uk Kim AcpiFormatException (Status)); 4721a39cfb0SJung-uk Kim goto Cleanup; 4731a39cfb0SJung-uk Kim } 4741a39cfb0SJung-uk Kim 475313a0c13SJung-uk Kim /* Cross reference the namespace again */ 476313a0c13SJung-uk Kim 477313a0c13SJung-uk Kim AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, 478313a0c13SJung-uk Kim AcpiGbl_RootNode, OwnerId); 479313a0c13SJung-uk Kim 480313a0c13SJung-uk Kim AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, 481313a0c13SJung-uk Kim AcpiGbl_RootNode, OwnerId); 482313a0c13SJung-uk Kim 4831a39cfb0SJung-uk Kim if (AslCompilerdebug) 4841a39cfb0SJung-uk Kim { 485a9f12690SJung-uk Kim AcpiOsPrintf ("/**** After second load and resource conversion\n"); 4861c0e1b6dSJung-uk Kim if (File) 4871c0e1b6dSJung-uk Kim { 488efcc2a30SJung-uk Kim NsSetupNamespaceListing (File); 489efcc2a30SJung-uk Kim NsDisplayNamespace (); 4901c0e1b6dSJung-uk Kim } 491a9f12690SJung-uk Kim AcpiOsPrintf ("*****/\n"); 492a9f12690SJung-uk Kim 4931a39cfb0SJung-uk Kim AcpiDmDumpTree (AcpiGbl_ParseOpRoot); 4941a39cfb0SJung-uk Kim } 4951a39cfb0SJung-uk Kim } 496e0ef747bSNate Lawson 497ec3fc72fSJung-uk Kim /* 498ec3fc72fSJung-uk Kim * Now that the namespace is finalized, we can perform namespace 499ec3fc72fSJung-uk Kim * transforms. 500ec3fc72fSJung-uk Kim * 501ec3fc72fSJung-uk Kim * 1) Convert fixed-offset references to resource descriptors 502ec3fc72fSJung-uk Kim * to symbolic references (Note: modifies namespace) 503ec3fc72fSJung-uk Kim */ 504ec3fc72fSJung-uk Kim AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode); 505ec3fc72fSJung-uk Kim 50659db4265SNate Lawson /* Optional displays */ 50759db4265SNate Lawson 508*70e6ab8fSJung-uk Kim if (AcpiGbl_DmOpt_Disasm) 50959db4265SNate Lawson { 5108ef1a331SJung-uk Kim /* This is the real disassembly */ 5118ef1a331SJung-uk Kim 51259db4265SNate Lawson AdDisplayTables (Filename, Table); 5138ef1a331SJung-uk Kim 5148ef1a331SJung-uk Kim /* Dump hex table if requested (-vt) */ 5158ef1a331SJung-uk Kim 5168ef1a331SJung-uk Kim AcpiDmDumpDataTable (Table); 5178ef1a331SJung-uk Kim 5184c52cad2SJung-uk Kim fprintf (stderr, "Disassembly completed\n"); 5191c0e1b6dSJung-uk Kim if (File) 5201c0e1b6dSJung-uk Kim { 5214c52cad2SJung-uk Kim fprintf (stderr, "ASL Output: %s - %u bytes\n", 522313a0c13SJung-uk Kim DisasmFilename, CmGetFileSize (File)); 5231c0e1b6dSJung-uk Kim } 524313a0c13SJung-uk Kim 525313a0c13SJung-uk Kim if (Gbl_MapfileFlag) 526313a0c13SJung-uk Kim { 527313a0c13SJung-uk Kim fprintf (stderr, "%14s %s - %u bytes\n", 528313a0c13SJung-uk Kim Gbl_Files[ASL_FILE_MAP_OUTPUT].ShortDescription, 529313a0c13SJung-uk Kim Gbl_Files[ASL_FILE_MAP_OUTPUT].Filename, 530313a0c13SJung-uk Kim FlGetFileSize (ASL_FILE_MAP_OUTPUT)); 531313a0c13SJung-uk Kim } 5321a39cfb0SJung-uk Kim } 53359db4265SNate Lawson } 53459db4265SNate Lawson 53559db4265SNate Lawson Cleanup: 536a9f12690SJung-uk Kim 5377cf3e94aSJung-uk Kim if (Table && !AcpiGbl_ForceAmlDisassembly &&!AcpiUtIsAmlTable (Table)) 538a9f12690SJung-uk Kim { 539a9f12690SJung-uk Kim ACPI_FREE (Table); 540a9f12690SJung-uk Kim } 541a9f12690SJung-uk Kim 5421c0e1b6dSJung-uk Kim if (File) 54359db4265SNate Lawson { 544ec3fc72fSJung-uk Kim if (AslCompilerdebug) /* Display final namespace, with transforms */ 545ec3fc72fSJung-uk Kim { 546efcc2a30SJung-uk Kim NsSetupNamespaceListing (File); 547efcc2a30SJung-uk Kim NsDisplayNamespace (); 548ec3fc72fSJung-uk Kim } 549ec3fc72fSJung-uk Kim 55059db4265SNate Lawson fclose (File); 55159db4265SNate Lawson AcpiOsRedirectOutput (stdout); 55259db4265SNate Lawson } 55359db4265SNate Lawson 5541a39cfb0SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 555a9f12690SJung-uk Kim AcpiGbl_ParseOpRoot = NULL; 556a9f12690SJung-uk Kim return (Status); 55759db4265SNate Lawson } 55859db4265SNate Lawson 55959db4265SNate Lawson 56059db4265SNate Lawson /****************************************************************************** 56159db4265SNate Lawson * 5621a39cfb0SJung-uk Kim * FUNCTION: AdDisassemblerHeader 5631a39cfb0SJung-uk Kim * 5641a39cfb0SJung-uk Kim * PARAMETERS: Filename - Input file for the table 5657cf3e94aSJung-uk Kim * TableType - Either AML or DataTable 5661a39cfb0SJung-uk Kim * 5671a39cfb0SJung-uk Kim * RETURN: None 5681a39cfb0SJung-uk Kim * 5691a39cfb0SJung-uk Kim * DESCRIPTION: Create the disassembler header, including ACPICA signon with 5701a39cfb0SJung-uk Kim * current time and date. 5711a39cfb0SJung-uk Kim * 5721a39cfb0SJung-uk Kim *****************************************************************************/ 5731a39cfb0SJung-uk Kim 5741a39cfb0SJung-uk Kim void 5751a39cfb0SJung-uk Kim AdDisassemblerHeader ( 5767cf3e94aSJung-uk Kim char *Filename, 5777cf3e94aSJung-uk Kim UINT8 TableType) 5781a39cfb0SJung-uk Kim { 5791a39cfb0SJung-uk Kim time_t Timer; 5801a39cfb0SJung-uk Kim 5811c0e1b6dSJung-uk Kim 5821a39cfb0SJung-uk Kim time (&Timer); 5831a39cfb0SJung-uk Kim 5841a39cfb0SJung-uk Kim /* Header and input table info */ 5851a39cfb0SJung-uk Kim 5863c1812acSJung-uk Kim AcpiOsPrintf ("/*\n"); 5871c0e1b6dSJung-uk Kim AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * ")); 5881c0e1b6dSJung-uk Kim 5897cf3e94aSJung-uk Kim if (TableType == ACPI_IS_AML_TABLE) 5907cf3e94aSJung-uk Kim { 5911c0e1b6dSJung-uk Kim if (AcpiGbl_CstyleDisassembly) 5921c0e1b6dSJung-uk Kim { 5931c0e1b6dSJung-uk Kim AcpiOsPrintf ( 5941c0e1b6dSJung-uk Kim " * Disassembling to symbolic ASL+ operators\n" 5951c0e1b6dSJung-uk Kim " *\n"); 5961c0e1b6dSJung-uk Kim } 5971c0e1b6dSJung-uk Kim else 5981c0e1b6dSJung-uk Kim { 5991c0e1b6dSJung-uk Kim AcpiOsPrintf ( 6001c0e1b6dSJung-uk Kim " * Disassembling to non-symbolic legacy ASL operators\n" 6011c0e1b6dSJung-uk Kim " *\n"); 6021c0e1b6dSJung-uk Kim } 6037cf3e94aSJung-uk Kim } 6041a39cfb0SJung-uk Kim 6053c1812acSJung-uk Kim AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer)); 6061a39cfb0SJung-uk Kim AcpiOsPrintf (" *\n"); 6071a39cfb0SJung-uk Kim } 6081a39cfb0SJung-uk Kim 6091a39cfb0SJung-uk Kim 6101a39cfb0SJung-uk Kim /****************************************************************************** 6111a39cfb0SJung-uk Kim * 61259db4265SNate Lawson * FUNCTION: AdCreateTableHeader 61359db4265SNate Lawson * 61459db4265SNate Lawson * PARAMETERS: Filename - Input file for the table 61559db4265SNate Lawson * Table - Pointer to the raw table 61659db4265SNate Lawson * 61759db4265SNate Lawson * RETURN: None 61859db4265SNate Lawson * 61959db4265SNate Lawson * DESCRIPTION: Create the ASL table header, including ACPICA signon with 62059db4265SNate Lawson * current time and date. 62159db4265SNate Lawson * 62259db4265SNate Lawson *****************************************************************************/ 62359db4265SNate Lawson 62442fecd12SJung-uk Kim static void 62559db4265SNate Lawson AdCreateTableHeader ( 62659db4265SNate Lawson char *Filename, 62759db4265SNate Lawson ACPI_TABLE_HEADER *Table) 62859db4265SNate Lawson { 6291a39cfb0SJung-uk Kim char *NewFilename; 630a9f12690SJung-uk Kim UINT8 Checksum; 63159db4265SNate Lawson 63259db4265SNate Lawson 633a9f12690SJung-uk Kim /* 634a9f12690SJung-uk Kim * Print file header and dump original table header 635a9f12690SJung-uk Kim */ 6367cf3e94aSJung-uk Kim AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE); 63759db4265SNate Lawson 638a88e22b7SJung-uk Kim AcpiOsPrintf (" * Original Table Header:\n"); 6391a39cfb0SJung-uk Kim AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature); 6401a39cfb0SJung-uk Kim AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length); 641a9f12690SJung-uk Kim 642a9f12690SJung-uk Kim /* Print and validate the revision */ 643a9f12690SJung-uk Kim 644a9f12690SJung-uk Kim AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision); 645a9f12690SJung-uk Kim 646a9f12690SJung-uk Kim switch (Table->Revision) 647a9f12690SJung-uk Kim { 648a9f12690SJung-uk Kim case 0: 649a9d8d09cSJung-uk Kim 650a9f12690SJung-uk Kim AcpiOsPrintf (" **** Invalid Revision"); 651a9f12690SJung-uk Kim break; 652a9f12690SJung-uk Kim 653a9f12690SJung-uk Kim case 1: 654a9d8d09cSJung-uk Kim 655a9f12690SJung-uk Kim /* Revision of DSDT controls the ACPI integer width */ 656a9f12690SJung-uk Kim 657a9f12690SJung-uk Kim if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT)) 658a9f12690SJung-uk Kim { 659d244b227SJung-uk Kim AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support"); 660a9f12690SJung-uk Kim } 661a9f12690SJung-uk Kim break; 662a9f12690SJung-uk Kim 663a9f12690SJung-uk Kim default: 664a9d8d09cSJung-uk Kim 665a9f12690SJung-uk Kim break; 666a9f12690SJung-uk Kim } 667a9f12690SJung-uk Kim AcpiOsPrintf ("\n"); 668a9f12690SJung-uk Kim 669a9f12690SJung-uk Kim /* Print and validate the table checksum */ 670a9f12690SJung-uk Kim 671a9f12690SJung-uk Kim AcpiOsPrintf (" * Checksum 0x%2.2X", Table->Checksum); 672a9f12690SJung-uk Kim 673a9f12690SJung-uk Kim Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length); 674a9f12690SJung-uk Kim if (Checksum) 675a9f12690SJung-uk Kim { 676a9f12690SJung-uk Kim AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X", 677a9f12690SJung-uk Kim (UINT8) (Table->Checksum - Checksum)); 678a9f12690SJung-uk Kim } 679a9f12690SJung-uk Kim AcpiOsPrintf ("\n"); 680a9f12690SJung-uk Kim 6811a39cfb0SJung-uk Kim AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId); 6821a39cfb0SJung-uk Kim AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId); 6831a39cfb0SJung-uk Kim AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision); 684a9f12690SJung-uk Kim AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId); 685a9f12690SJung-uk Kim AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision); 6869c48c75eSJung-uk Kim AcpiOsPrintf (" */\n"); 6871a39cfb0SJung-uk Kim 6881a39cfb0SJung-uk Kim /* Create AML output filename based on input filename */ 6891a39cfb0SJung-uk Kim 6901a39cfb0SJung-uk Kim if (Filename) 6911a39cfb0SJung-uk Kim { 6921a39cfb0SJung-uk Kim NewFilename = FlGenerateFilename (Filename, "aml"); 6931a39cfb0SJung-uk Kim } 6941a39cfb0SJung-uk Kim else 6951a39cfb0SJung-uk Kim { 696313a0c13SJung-uk Kim NewFilename = UtStringCacheCalloc (9); 697313a0c13SJung-uk Kim if (NewFilename) 698313a0c13SJung-uk Kim { 6991a39cfb0SJung-uk Kim strncat (NewFilename, Table->Signature, 4); 7001a39cfb0SJung-uk Kim strcat (NewFilename, ".aml"); 7011a39cfb0SJung-uk Kim } 702313a0c13SJung-uk Kim } 703313a0c13SJung-uk Kim 704313a0c13SJung-uk Kim if (!NewFilename) 705313a0c13SJung-uk Kim { 706313a0c13SJung-uk Kim AcpiOsPrintf (" **** Could not generate AML output filename\n"); 707313a0c13SJung-uk Kim return; 708313a0c13SJung-uk Kim } 7091a39cfb0SJung-uk Kim 7101a39cfb0SJung-uk Kim /* Open the ASL definition block */ 71159db4265SNate Lawson 71259db4265SNate Lawson AcpiOsPrintf ( 713a88e22b7SJung-uk Kim "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n", 7141a39cfb0SJung-uk Kim NewFilename, Table->Signature, Table->Revision, 71559db4265SNate Lawson Table->OemId, Table->OemTableId, Table->OemRevision); 71659db4265SNate Lawson } 71759db4265SNate Lawson 71859db4265SNate Lawson 71959db4265SNate Lawson /****************************************************************************** 72059db4265SNate Lawson * 72159db4265SNate Lawson * FUNCTION: AdDisplayTables 72259db4265SNate Lawson * 72359db4265SNate Lawson * PARAMETERS: Filename - Input file for the table 724fba7fc7eSJung-uk Kim * Table - Pointer to the raw table 72559db4265SNate Lawson * 72659db4265SNate Lawson * RETURN: Status 72759db4265SNate Lawson * 72859db4265SNate Lawson * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables 72959db4265SNate Lawson * 73059db4265SNate Lawson *****************************************************************************/ 73159db4265SNate Lawson 73259db4265SNate Lawson ACPI_STATUS 73359db4265SNate Lawson AdDisplayTables ( 73459db4265SNate Lawson char *Filename, 73559db4265SNate Lawson ACPI_TABLE_HEADER *Table) 73659db4265SNate Lawson { 73759db4265SNate Lawson 73859db4265SNate Lawson 7391a39cfb0SJung-uk Kim if (!AcpiGbl_ParseOpRoot) 74059db4265SNate Lawson { 7418ef1a331SJung-uk Kim return (AE_NOT_EXIST); 74259db4265SNate Lawson } 74359db4265SNate Lawson 744*70e6ab8fSJung-uk Kim if (!AcpiGbl_DmOpt_Listing) 74559db4265SNate Lawson { 74659db4265SNate Lawson AdCreateTableHeader (Filename, Table); 74759db4265SNate Lawson } 74859db4265SNate Lawson 7491a39cfb0SJung-uk Kim AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX); 750313a0c13SJung-uk Kim MpEmitMappingInfo (); 75159db4265SNate Lawson 752*70e6ab8fSJung-uk Kim if (AcpiGbl_DmOpt_Listing) 75359db4265SNate Lawson { 75459db4265SNate Lawson AcpiOsPrintf ("\n\nTable Header:\n"); 7558ef1a331SJung-uk Kim AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER), 75659db4265SNate Lawson DB_BYTE_DISPLAY, ACPI_UINT32_MAX); 75759db4265SNate Lawson 75859db4265SNate Lawson AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length); 7598ef1a331SJung-uk Kim AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), 7608ef1a331SJung-uk Kim Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX); 76159db4265SNate Lawson } 76259db4265SNate Lawson 7638ef1a331SJung-uk Kim return (AE_OK); 76459db4265SNate Lawson } 76559db4265SNate Lawson 76659db4265SNate Lawson 7677cf3e94aSJung-uk Kim /******************************************************************************* 7687cf3e94aSJung-uk Kim * 7697cf3e94aSJung-uk Kim * FUNCTION: AdStoreTable 7707cf3e94aSJung-uk Kim * 7717cf3e94aSJung-uk Kim * PARAMETERS: Table - Table header 7727cf3e94aSJung-uk Kim * TableIndex - Where the table index is returned 7737cf3e94aSJung-uk Kim * 7747cf3e94aSJung-uk Kim * RETURN: Status and table index. 7757cf3e94aSJung-uk Kim * 7767cf3e94aSJung-uk Kim * DESCRIPTION: Add an ACPI table to the global table list 7777cf3e94aSJung-uk Kim * 7787cf3e94aSJung-uk Kim ******************************************************************************/ 7797cf3e94aSJung-uk Kim 7807cf3e94aSJung-uk Kim static ACPI_STATUS 7817cf3e94aSJung-uk Kim AdStoreTable ( 7827cf3e94aSJung-uk Kim ACPI_TABLE_HEADER *Table, 7837cf3e94aSJung-uk Kim UINT32 *TableIndex) 7847cf3e94aSJung-uk Kim { 7857cf3e94aSJung-uk Kim ACPI_STATUS Status; 7867cf3e94aSJung-uk Kim ACPI_TABLE_DESC *TableDesc; 7877cf3e94aSJung-uk Kim 7887cf3e94aSJung-uk Kim 7897cf3e94aSJung-uk Kim Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc); 7907cf3e94aSJung-uk Kim if (ACPI_FAILURE (Status)) 7917cf3e94aSJung-uk Kim { 7927cf3e94aSJung-uk Kim return (Status); 7937cf3e94aSJung-uk Kim } 7947cf3e94aSJung-uk Kim 7957cf3e94aSJung-uk Kim /* Initialize added table */ 7967cf3e94aSJung-uk Kim 7977cf3e94aSJung-uk Kim AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table), 7987cf3e94aSJung-uk Kim ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table); 799fe0f0bbbSJung-uk Kim Status = AcpiTbValidateTable (TableDesc); 800fe0f0bbbSJung-uk Kim return (Status); 8017cf3e94aSJung-uk Kim } 8027cf3e94aSJung-uk Kim 8037cf3e94aSJung-uk Kim 80459db4265SNate Lawson /****************************************************************************** 80559db4265SNate Lawson * 80659db4265SNate Lawson * FUNCTION: AdGetLocalTables 80759db4265SNate Lawson * 808313a0c13SJung-uk Kim * PARAMETERS: None 80959db4265SNate Lawson * 810fba7fc7eSJung-uk Kim * RETURN: Status 81159db4265SNate Lawson * 81259db4265SNate Lawson * DESCRIPTION: Get the ACPI tables from either memory or a file 81359db4265SNate Lawson * 81459db4265SNate Lawson *****************************************************************************/ 81559db4265SNate Lawson 81659db4265SNate Lawson ACPI_STATUS 81759db4265SNate Lawson AdGetLocalTables ( 818313a0c13SJung-uk Kim void) 81959db4265SNate Lawson { 82059db4265SNate Lawson ACPI_STATUS Status; 82159db4265SNate Lawson ACPI_TABLE_HEADER TableHeader; 82259db4265SNate Lawson ACPI_TABLE_HEADER *NewTable; 823a9f12690SJung-uk Kim UINT32 TableIndex; 82459db4265SNate Lawson 82559db4265SNate Lawson 826313a0c13SJung-uk Kim /* Get the DSDT via table override */ 82759db4265SNate Lawson 8281a39cfb0SJung-uk Kim ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT); 82959db4265SNate Lawson AcpiOsTableOverride (&TableHeader, &NewTable); 830313a0c13SJung-uk Kim if (!NewTable) 83159db4265SNate Lawson { 832313a0c13SJung-uk Kim fprintf (stderr, "Could not obtain DSDT\n"); 833313a0c13SJung-uk Kim return (AE_NO_ACPI_TABLES); 834313a0c13SJung-uk Kim } 835313a0c13SJung-uk Kim 8361a39cfb0SJung-uk Kim AdWriteTable (NewTable, NewTable->Length, 8371a39cfb0SJung-uk Kim ACPI_SIG_DSDT, NewTable->OemTableId); 8381a39cfb0SJung-uk Kim 8391a39cfb0SJung-uk Kim /* Store DSDT in the Table Manager */ 8401a39cfb0SJung-uk Kim 8417cf3e94aSJung-uk Kim Status = AdStoreTable (NewTable, &TableIndex); 842f556842eSJung-uk Kim if (ACPI_FAILURE (Status)) 843f556842eSJung-uk Kim { 844f556842eSJung-uk Kim fprintf (stderr, "Could not store DSDT\n"); 8458ef1a331SJung-uk Kim return (AE_NO_ACPI_TABLES); 846f556842eSJung-uk Kim } 84759db4265SNate Lawson 8488ef1a331SJung-uk Kim return (AE_OK); 84959db4265SNate Lawson } 85059db4265SNate Lawson 8511a39cfb0SJung-uk Kim 85259db4265SNate Lawson /****************************************************************************** 85359db4265SNate Lawson * 85459db4265SNate Lawson * FUNCTION: AdParseTable 85559db4265SNate Lawson * 856fba7fc7eSJung-uk Kim * PARAMETERS: Table - Pointer to the raw table 857a9f12690SJung-uk Kim * OwnerId - Returned OwnerId of the table 858a9f12690SJung-uk Kim * LoadTable - If add table to the global table list 859a9f12690SJung-uk Kim * External - If this is an external table 86059db4265SNate Lawson * 86159db4265SNate Lawson * RETURN: Status 86259db4265SNate Lawson * 86359db4265SNate Lawson * DESCRIPTION: Parse the DSDT. 86459db4265SNate Lawson * 86559db4265SNate Lawson *****************************************************************************/ 86659db4265SNate Lawson 86759db4265SNate Lawson ACPI_STATUS 86859db4265SNate Lawson AdParseTable ( 869a9f12690SJung-uk Kim ACPI_TABLE_HEADER *Table, 870a9f12690SJung-uk Kim ACPI_OWNER_ID *OwnerId, 871a9f12690SJung-uk Kim BOOLEAN LoadTable, 872a9f12690SJung-uk Kim BOOLEAN External) 87359db4265SNate Lawson { 87459db4265SNate Lawson ACPI_STATUS Status = AE_OK; 87559db4265SNate Lawson ACPI_WALK_STATE *WalkState; 87659db4265SNate Lawson UINT8 *AmlStart; 87759db4265SNate Lawson UINT32 AmlLength; 878a9f12690SJung-uk Kim UINT32 TableIndex; 87959db4265SNate Lawson 88059db4265SNate Lawson 88159db4265SNate Lawson if (!Table) 88259db4265SNate Lawson { 8838ef1a331SJung-uk Kim return (AE_NOT_EXIST); 88459db4265SNate Lawson } 88559db4265SNate Lawson 88659db4265SNate Lawson /* Pass 1: Parse everything except control method bodies */ 88759db4265SNate Lawson 88859db4265SNate Lawson fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature); 88959db4265SNate Lawson 89059db4265SNate Lawson AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER); 89159db4265SNate Lawson AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)); 89259db4265SNate Lawson 89359db4265SNate Lawson /* Create the root object */ 89459db4265SNate Lawson 895fe0f0bbbSJung-uk Kim AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart); 8961a39cfb0SJung-uk Kim if (!AcpiGbl_ParseOpRoot) 89759db4265SNate Lawson { 8988ef1a331SJung-uk Kim return (AE_NO_MEMORY); 89959db4265SNate Lawson } 90059db4265SNate Lawson 90159db4265SNate Lawson /* Create and initialize a new walk state */ 90259db4265SNate Lawson 90359db4265SNate Lawson WalkState = AcpiDsCreateWalkState (0, 9041a39cfb0SJung-uk Kim AcpiGbl_ParseOpRoot, NULL, NULL); 90559db4265SNate Lawson if (!WalkState) 90659db4265SNate Lawson { 90759db4265SNate Lawson return (AE_NO_MEMORY); 90859db4265SNate Lawson } 90959db4265SNate Lawson 9101a39cfb0SJung-uk Kim Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot, 9111a39cfb0SJung-uk Kim NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1); 91259db4265SNate Lawson if (ACPI_FAILURE (Status)) 91359db4265SNate Lawson { 91459db4265SNate Lawson return (Status); 91559db4265SNate Lawson } 91659db4265SNate Lawson 91759db4265SNate Lawson WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE; 918fba7fc7eSJung-uk Kim WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE; 91959db4265SNate Lawson 92059db4265SNate Lawson Status = AcpiPsParseAml (WalkState); 92159db4265SNate Lawson if (ACPI_FAILURE (Status)) 92259db4265SNate Lawson { 9238ef1a331SJung-uk Kim return (Status); 92459db4265SNate Lawson } 92559db4265SNate Lawson 926a9f12690SJung-uk Kim /* If LoadTable is FALSE, we are parsing the last loaded table */ 927a9f12690SJung-uk Kim 9283f5e024cSJung-uk Kim TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1; 929a9f12690SJung-uk Kim 93059db4265SNate Lawson /* Pass 2 */ 93159db4265SNate Lawson 932a9f12690SJung-uk Kim if (LoadTable) 933a9f12690SJung-uk Kim { 9347cf3e94aSJung-uk Kim Status = AdStoreTable (Table, &TableIndex); 9351a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 9361a39cfb0SJung-uk Kim { 9378ef1a331SJung-uk Kim return (Status); 9381a39cfb0SJung-uk Kim } 939a9f12690SJung-uk Kim Status = AcpiTbAllocateOwnerId (TableIndex); 940a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 941a9f12690SJung-uk Kim { 9428ef1a331SJung-uk Kim return (Status); 943a9f12690SJung-uk Kim } 944a9f12690SJung-uk Kim if (OwnerId) 945a9f12690SJung-uk Kim { 946a9f12690SJung-uk Kim Status = AcpiTbGetOwnerId (TableIndex, OwnerId); 947a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 948a9f12690SJung-uk Kim { 9498ef1a331SJung-uk Kim return (Status); 950a9f12690SJung-uk Kim } 951a9f12690SJung-uk Kim } 952a9f12690SJung-uk Kim } 95359db4265SNate Lawson 9541a39cfb0SJung-uk Kim fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature); 9551a39cfb0SJung-uk Kim 956a9f12690SJung-uk Kim Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL); 95759db4265SNate Lawson if (ACPI_FAILURE (Status)) 95859db4265SNate Lawson { 95959db4265SNate Lawson return (Status); 96059db4265SNate Lawson } 96159db4265SNate Lawson 962a9f12690SJung-uk Kim /* No need to parse control methods of external table */ 963a9f12690SJung-uk Kim 964a9f12690SJung-uk Kim if (External) 965a9f12690SJung-uk Kim { 9668ef1a331SJung-uk Kim return (AE_OK); 967a9f12690SJung-uk Kim } 968a9f12690SJung-uk Kim 969313a0c13SJung-uk Kim /* 970313a0c13SJung-uk Kim * Pass 3: Parse control methods and link their parse trees 971313a0c13SJung-uk Kim * into the main parse tree 972313a0c13SJung-uk Kim */ 973313a0c13SJung-uk Kim fprintf (stderr, 974313a0c13SJung-uk Kim "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n"); 975ed17e06eSJung-uk Kim Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot); 976ed17e06eSJung-uk Kim fprintf (stderr, "\n"); 9771a39cfb0SJung-uk Kim 9781a39cfb0SJung-uk Kim /* Process Resource Templates */ 9791a39cfb0SJung-uk Kim 9801a39cfb0SJung-uk Kim AcpiDmFindResources (AcpiGbl_ParseOpRoot); 98159db4265SNate Lawson 98259db4265SNate Lawson fprintf (stderr, "Parsing completed\n"); 9838ef1a331SJung-uk Kim return (AE_OK); 98459db4265SNate Lawson } 985