1 /******************************************************************************
3 * Module Name: anmain - Main routine for the AcpiNames utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2017, 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"
48 #define _COMPONENT ACPI_TOOLS
49 ACPI_MODULE_NAME ("anmain")
52 /* Local prototypes */
55 AnDumpEntireNamespace (
56 ACPI_NEW_TABLE_DESC *ListHead);
60 * Main routine for the ACPI user-space namespace utility.
62 * Portability note: The utility depends upon the host for command-line
63 * wildcard support - it is not implemented locally. For example:
65 * Linux/Unix systems: Shell expands wildcards automatically.
67 * Windows: The setargv.obj module must be linked in to automatically
70 BOOLEAN AcpiGbl_NsLoadOnly = FALSE;
73 #define AN_UTILITY_NAME "ACPI Namespace Dump Utility"
74 #define AN_SUPPORTED_OPTIONS "?hlvx:"
77 /******************************************************************************
85 * DESCRIPTION: Print a usage message
87 *****************************************************************************/
94 ACPI_USAGE_HEADER ("AcpiNames [options] AMLfile");
95 ACPI_OPTION ("-?", "Display this message");
96 ACPI_OPTION ("-l", "Load namespace only, no display");
97 ACPI_OPTION ("-v", "Display version information");
98 ACPI_OPTION ("-x <DebugLevel>", "Debug output level");
102 /******************************************************************************
106 * PARAMETERS: argc, argv
108 * RETURN: Status (pass/fail)
110 * DESCRIPTION: Main routine for NsDump utility
112 *****************************************************************************/
114 int ACPI_SYSTEM_XFACE
119 ACPI_NEW_TABLE_DESC *ListHead = NULL;
124 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
126 /* Init debug globals and ACPICA */
128 AcpiDbgLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
129 AcpiDbgLayer = 0xFFFFFFFF;
131 Status = AcpiInitializeSubsystem ();
132 ACPI_CHECK_OK (AcpiInitializeSubsystem, Status);
133 if (ACPI_FAILURE (Status))
138 printf (ACPI_COMMON_SIGNON (AN_UTILITY_NAME));
145 /* Get the command line options */
147 while ((j = AcpiGetopt (argc, argv, AN_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch(j)
151 AcpiGbl_NsLoadOnly = TRUE;
154 case 'v': /* -v: (Version): signon already emitted, just exit */
160 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0);
161 printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
172 /* Get each of the ACPI table files on the command line */
174 while (argv[AcpiGbl_Optind])
176 /* Get all ACPI AML tables in this file */
178 Status = AcGetAllTablesFromFile (argv[AcpiGbl_Optind],
179 ACPI_GET_ALL_TABLES, &ListHead);
180 if (ACPI_FAILURE (Status))
191 * The next argument is the filename for the DSDT or SSDT.
192 * Open the file, build namespace and dump it.
194 return (AnDumpEntireNamespace (ListHead));
198 /******************************************************************************
200 * FUNCTION: AnDumpEntireNamespace
202 * PARAMETERS: AmlFilename - Filename for DSDT or SSDT AML table
204 * RETURN: Status (pass/fail)
206 * DESCRIPTION: Build an ACPI namespace for the input AML table, and dump the
207 * formatted namespace contents.
209 *****************************************************************************/
212 AnDumpEntireNamespace (
213 ACPI_NEW_TABLE_DESC *ListHead)
220 * Build a local XSDT with all tables. Normally, here is where the
221 * RSDP search is performed to find the ACPI tables
223 Status = AnBuildLocalTables (ListHead);
224 if (ACPI_FAILURE (Status))
229 /* Initialize table manager, get XSDT */
231 Status = AcpiInitializeTables (NULL, ACPI_MAX_INIT_TABLES, TRUE);
232 if (ACPI_FAILURE (Status))
234 printf ("**** Could not initialize ACPI table manager, %s\n",
235 AcpiFormatException (Status));
239 /* Load the ACPI namespace */
241 Status = AcpiTbLoadNamespace ();
242 if (Status == AE_CTRL_TERMINATE)
244 /* At least one table load failed -- terminate with error */
249 if (ACPI_FAILURE (Status))
251 printf ("**** While creating namespace, %s\n",
252 AcpiFormatException (Status));
256 if (AcpiGbl_NsLoadOnly)
258 printf ("**** Namespace successfully loaded\n");
263 * Enable ACPICA. These calls don't do much for this
264 * utility, since we only dump the namespace. There is no
265 * hardware or event manager code underneath.
267 Status = AcpiEnableSubsystem (
268 ACPI_NO_ACPI_ENABLE |
269 ACPI_NO_ADDRESS_SPACE_INIT |
271 ACPI_NO_HANDLER_INIT);
272 if (ACPI_FAILURE (Status))
274 printf ("**** Could not EnableSubsystem, %s\n",
275 AcpiFormatException (Status));
279 Status = AcpiInitializeObjects (
280 ACPI_NO_ADDRESS_SPACE_INIT |
281 ACPI_NO_DEVICE_INIT |
283 if (ACPI_FAILURE (Status))
285 printf ("**** Could not InitializeObjects, %s\n",
286 AcpiFormatException (Status));
291 * Perform a namespace walk to dump the contents
293 AcpiOsPrintf ("\nACPI Namespace:\n");
295 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY,
296 ACPI_UINT32_MAX, ACPI_OWNER_ID_MAX, AcpiGbl_RootNode);
299 /* Example: get a handle to the _GPE scope */
301 Status = AcpiGetHandle (NULL, "\\_GPE", &Handle);
302 ACPI_CHECK_OK (AcpiGetHandle, Status);