1 /******************************************************************************
3 * Module Name: anmain - Main routine for the AcpiNames utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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 static AE_TABLE_DESC *AeTableListHead = NULL;
55 #define AN_UTILITY_NAME "ACPI Namespace Dump Utility"
56 #define AN_SUPPORTED_OPTIONS "?hv"
59 /******************************************************************************
67 * DESCRIPTION: Print a usage message
69 *****************************************************************************/
76 ACPI_USAGE_HEADER ("AcpiNames [options] AMLfile");
77 ACPI_OPTION ("-?", "Display this message");
78 ACPI_OPTION ("-v", "Display version information");
82 /******************************************************************************
84 * FUNCTION: NsDumpEntireNamespace
86 * PARAMETERS: AmlFilename - Filename for DSDT or SSDT AML table
88 * RETURN: Status (pass/fail)
90 * DESCRIPTION: Build an ACPI namespace for the input AML table, and dump the
91 * formatted namespace contents.
93 *****************************************************************************/
96 NsDumpEntireNamespace (
100 ACPI_TABLE_HEADER *Table = NULL;
101 UINT32 TableCount = 0;
102 AE_TABLE_DESC *TableDesc;
106 /* Open the binary AML file and read the entire table */
108 Status = AcpiDbReadTableFromFile (AmlFilename, &Table);
109 if (ACPI_FAILURE (Status))
111 printf ("**** Could not get input table %s, %s\n", AmlFilename,
112 AcpiFormatException (Status));
116 /* Table must be a DSDT. SSDTs are not currently supported */
118 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
120 printf ("**** Input table signature is [%4.4s], must be [DSDT]\n",
126 * Allocate and link a table descriptor (allows for future expansion to
127 * multiple input files)
129 TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC));
130 TableDesc->Table = Table;
131 TableDesc->Next = AeTableListHead;
132 AeTableListHead = TableDesc;
137 * Build a local XSDT with all tables. Normally, here is where the
138 * RSDP search is performed to find the ACPI tables
140 Status = AeBuildLocalTables (TableCount, AeTableListHead);
141 if (ACPI_FAILURE (Status))
146 /* Initialize table manager, get XSDT */
148 Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE);
149 if (ACPI_FAILURE (Status))
151 printf ("**** Could not initialize ACPI table manager, %s\n",
152 AcpiFormatException (Status));
156 /* Reallocate root table to dynamic memory */
158 Status = AcpiReallocateRootTable ();
159 if (ACPI_FAILURE (Status))
161 printf ("**** Could not reallocate root table, %s\n",
162 AcpiFormatException (Status));
166 /* Load the ACPI namespace */
168 Status = AcpiLoadTables ();
169 if (ACPI_FAILURE (Status))
171 printf ("**** Could not load ACPI tables, %s\n",
172 AcpiFormatException (Status));
177 * Enable ACPICA. These calls don't do much for this
178 * utility, since we only dump the namespace. There is no
179 * hardware or event manager code underneath.
181 Status = AcpiEnableSubsystem (
182 ACPI_NO_ACPI_ENABLE |
183 ACPI_NO_ADDRESS_SPACE_INIT |
185 ACPI_NO_HANDLER_INIT);
186 if (ACPI_FAILURE (Status))
188 printf ("**** Could not EnableSubsystem, %s\n",
189 AcpiFormatException (Status));
193 Status = AcpiInitializeObjects (
194 ACPI_NO_ADDRESS_SPACE_INIT |
195 ACPI_NO_DEVICE_INIT |
197 if (ACPI_FAILURE (Status))
199 printf ("**** Could not InitializeObjects, %s\n",
200 AcpiFormatException (Status));
205 * Perform a namespace walk to dump the contents
207 AcpiOsPrintf ("\nACPI Namespace:\n");
209 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, ACPI_UINT32_MAX,
210 ACPI_OWNER_ID_MAX, AcpiGbl_RootNode);
213 /* Example: get a handle to the _GPE scope */
215 Status = AcpiGetHandle (NULL, "\\_GPE", &Handle);
216 AE_CHECK_OK (AcpiGetHandle, Status);
222 /******************************************************************************
226 * PARAMETERS: argc, argv
228 * RETURN: Status (pass/fail)
230 * DESCRIPTION: Main routine for NsDump utility
232 *****************************************************************************/
234 int ACPI_SYSTEM_XFACE
243 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
244 printf (ACPI_COMMON_SIGNON (AN_UTILITY_NAME));
252 /* Init globals and ACPICA */
254 AcpiDbgLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
255 AcpiDbgLayer = 0xFFFFFFFF;
257 Status = AcpiInitializeSubsystem ();
258 AE_CHECK_OK (AcpiInitializeSubsystem, Status);
260 /* Get the command line options */
262 while ((j = AcpiGetopt (argc, argv, AN_SUPPORTED_OPTIONS)) != EOF) switch(j)
264 case 'v': /* -v: (Version): signon already emitted, just exit */
277 * The next argument is the filename for the DSDT or SSDT.
278 * Open the file, build namespace and dump it.
280 return (NsDumpEntireNamespace (argv[AcpiGbl_Optind]));