1 /******************************************************************************
3 * Module Name: anmain - Main routine for the AcpiNames utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "acpinames.h"
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("anmain")
50 extern ACPI_TABLE_DESC Tables[];
52 FILE *AcpiGbl_DebugFile;
53 static AE_TABLE_DESC *AeTableListHead = NULL;
56 #define AE_SUPPORTED_OPTIONS "?h"
59 /******************************************************************************
67 * DESCRIPTION: Print a usage message
69 *****************************************************************************/
76 ACPI_USAGE_HEADER ("AcpiNames [options] AMLfile");
77 ACPI_OPTION ("-?", "Display this message");
81 /******************************************************************************
83 * FUNCTION: NsDumpEntireNamespace
85 * PARAMETERS: AmlFilename - Filename for DSDT or SSDT AML table
87 * RETURN: Status (pass/fail)
89 * DESCRIPTION: Build an ACPI namespace for the input AML table, and dump the
90 * formatted namespace contents.
92 *****************************************************************************/
95 NsDumpEntireNamespace (
99 ACPI_TABLE_HEADER *Table = NULL;
100 UINT32 TableCount = 0;
101 AE_TABLE_DESC *TableDesc;
105 /* Open the binary AML file and read the entire table */
107 Status = AcpiDbReadTableFromFile (AmlFilename, &Table);
108 if (ACPI_FAILURE (Status))
110 printf ("**** Could not get input table %s, %s\n", AmlFilename,
111 AcpiFormatException (Status));
115 /* Table must be a DSDT. SSDTs are not currently supported */
117 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
119 printf ("**** Input table signature is [%4.4s], must be [DSDT]\n",
125 * Allocate and link a table descriptor (allows for future expansion to
126 * multiple input files)
128 TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC));
129 TableDesc->Table = Table;
130 TableDesc->Next = AeTableListHead;
131 AeTableListHead = TableDesc;
136 * Build a local XSDT with all tables. Normally, here is where the
137 * RSDP search is performed to find the ACPI tables
139 Status = AeBuildLocalTables (TableCount, AeTableListHead);
140 if (ACPI_FAILURE (Status))
145 /* Initialize table manager, get XSDT */
147 Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE);
148 if (ACPI_FAILURE (Status))
150 printf ("**** Could not initialize ACPI table manager, %s\n",
151 AcpiFormatException (Status));
155 /* Reallocate root table to dynamic memory */
157 Status = AcpiReallocateRootTable ();
158 if (ACPI_FAILURE (Status))
160 printf ("**** Could not reallocate root table, %s\n",
161 AcpiFormatException (Status));
165 /* Load the ACPI namespace */
167 Status = AcpiLoadTables ();
168 if (ACPI_FAILURE (Status))
170 printf ("**** Could not load ACPI tables, %s\n",
171 AcpiFormatException (Status));
176 * Enable ACPICA. These calls don't do much for this
177 * utility, since we only dump the namespace. There is no
178 * hardware or event manager code underneath.
180 Status = AcpiEnableSubsystem (
181 ACPI_NO_ACPI_ENABLE |
182 ACPI_NO_ADDRESS_SPACE_INIT |
184 ACPI_NO_HANDLER_INIT);
185 if (ACPI_FAILURE (Status))
187 printf ("**** Could not EnableSubsystem, %s\n",
188 AcpiFormatException (Status));
192 Status = AcpiInitializeObjects (
193 ACPI_NO_ADDRESS_SPACE_INIT |
194 ACPI_NO_DEVICE_INIT |
196 if (ACPI_FAILURE (Status))
198 printf ("**** Could not InitializeObjects, %s\n",
199 AcpiFormatException (Status));
204 * Perform a namespace walk to dump the contents
206 AcpiOsPrintf ("\nACPI Namespace:\n");
208 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, ACPI_UINT32_MAX,
209 ACPI_OWNER_ID_MAX, AcpiGbl_RootNode);
212 /* Example: get a handle to the _GPE scope */
214 Status = AcpiGetHandle (NULL, "\\_GPE", &Handle);
215 AE_CHECK_OK (AcpiGetHandle, Status);
221 /******************************************************************************
225 * PARAMETERS: argc, argv
227 * RETURN: Status (pass/fail)
229 * DESCRIPTION: Main routine for NsDump utility
231 *****************************************************************************/
233 int ACPI_SYSTEM_XFACE
242 printf (ACPI_COMMON_SIGNON ("ACPI Namespace Dump Utility"));
250 /* Init globals and ACPICA */
252 AcpiDbgLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
253 AcpiDbgLayer = 0xFFFFFFFF;
255 Status = AcpiInitializeSubsystem ();
256 AE_CHECK_OK (AcpiInitializeSubsystem, Status);
258 /* Get the command line options */
260 while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch(j)
270 * The next argument is the filename for the DSDT or SSDT.
271 * Open the file, build namespace and dump it.
273 return (NsDumpEntireNamespace (argv[AcpiGbl_Optind]));