1 /******************************************************************************
3 * Module Name: anmain - Main routine for the AcpiNames utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 AN_UTILITY_NAME "ACPI Namespace Dump Utility"
57 #define AN_SUPPORTED_OPTIONS "?hv"
60 /******************************************************************************
68 * DESCRIPTION: Print a usage message
70 *****************************************************************************/
77 ACPI_USAGE_HEADER ("AcpiNames [options] AMLfile");
78 ACPI_OPTION ("-?", "Display this message");
79 ACPI_OPTION ("-v", "Display version information");
83 /******************************************************************************
85 * FUNCTION: NsDumpEntireNamespace
87 * PARAMETERS: AmlFilename - Filename for DSDT or SSDT AML table
89 * RETURN: Status (pass/fail)
91 * DESCRIPTION: Build an ACPI namespace for the input AML table, and dump the
92 * formatted namespace contents.
94 *****************************************************************************/
97 NsDumpEntireNamespace (
101 ACPI_TABLE_HEADER
*Table
= NULL
;
102 UINT32 TableCount
= 0;
103 AE_TABLE_DESC
*TableDesc
;
107 /* Open the binary AML file and read the entire table */
109 Status
= AcpiDbReadTableFromFile (AmlFilename
, &Table
);
110 if (ACPI_FAILURE (Status
))
112 printf ("**** Could not get input table %s, %s\n", AmlFilename
,
113 AcpiFormatException (Status
));
117 /* Table must be a DSDT. SSDTs are not currently supported */
119 if (!ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_DSDT
))
121 printf ("**** Input table signature is [%4.4s], must be [DSDT]\n",
127 * Allocate and link a table descriptor (allows for future expansion to
128 * multiple input files)
130 TableDesc
= AcpiOsAllocate (sizeof (AE_TABLE_DESC
));
131 TableDesc
->Table
= Table
;
132 TableDesc
->Next
= AeTableListHead
;
133 AeTableListHead
= TableDesc
;
138 * Build a local XSDT with all tables. Normally, here is where the
139 * RSDP search is performed to find the ACPI tables
141 Status
= AeBuildLocalTables (TableCount
, AeTableListHead
);
142 if (ACPI_FAILURE (Status
))
147 /* Initialize table manager, get XSDT */
149 Status
= AcpiInitializeTables (Tables
, ACPI_MAX_INIT_TABLES
, TRUE
);
150 if (ACPI_FAILURE (Status
))
152 printf ("**** Could not initialize ACPI table manager, %s\n",
153 AcpiFormatException (Status
));
157 /* Reallocate root table to dynamic memory */
159 Status
= AcpiReallocateRootTable ();
160 if (ACPI_FAILURE (Status
))
162 printf ("**** Could not reallocate root table, %s\n",
163 AcpiFormatException (Status
));
167 /* Load the ACPI namespace */
169 Status
= AcpiLoadTables ();
170 if (ACPI_FAILURE (Status
))
172 printf ("**** Could not load ACPI tables, %s\n",
173 AcpiFormatException (Status
));
178 * Enable ACPICA. These calls don't do much for this
179 * utility, since we only dump the namespace. There is no
180 * hardware or event manager code underneath.
182 Status
= AcpiEnableSubsystem (
183 ACPI_NO_ACPI_ENABLE
|
184 ACPI_NO_ADDRESS_SPACE_INIT
|
186 ACPI_NO_HANDLER_INIT
);
187 if (ACPI_FAILURE (Status
))
189 printf ("**** Could not EnableSubsystem, %s\n",
190 AcpiFormatException (Status
));
194 Status
= AcpiInitializeObjects (
195 ACPI_NO_ADDRESS_SPACE_INIT
|
196 ACPI_NO_DEVICE_INIT
|
198 if (ACPI_FAILURE (Status
))
200 printf ("**** Could not InitializeObjects, %s\n",
201 AcpiFormatException (Status
));
206 * Perform a namespace walk to dump the contents
208 AcpiOsPrintf ("\nACPI Namespace:\n");
210 AcpiNsDumpObjects (ACPI_TYPE_ANY
, ACPI_DISPLAY_SUMMARY
, ACPI_UINT32_MAX
,
211 ACPI_OWNER_ID_MAX
, AcpiGbl_RootNode
);
214 /* Example: get a handle to the _GPE scope */
216 Status
= AcpiGetHandle (NULL
, "\\_GPE", &Handle
);
217 AE_CHECK_OK (AcpiGetHandle
, Status
);
223 /******************************************************************************
227 * PARAMETERS: argc, argv
229 * RETURN: Status (pass/fail)
231 * DESCRIPTION: Main routine for NsDump utility
233 *****************************************************************************/
235 int ACPI_SYSTEM_XFACE
244 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
245 printf (ACPI_COMMON_SIGNON (AN_UTILITY_NAME
));
253 /* Init globals and ACPICA */
255 AcpiDbgLevel
= ACPI_NORMAL_DEFAULT
| ACPI_LV_TABLES
;
256 AcpiDbgLayer
= 0xFFFFFFFF;
258 Status
= AcpiInitializeSubsystem ();
259 AE_CHECK_OK (AcpiInitializeSubsystem
, Status
);
261 /* Get the command line options */
263 while ((j
= AcpiGetopt (argc
, argv
, AN_SUPPORTED_OPTIONS
)) != EOF
) switch(j
)
265 case 'v': /* -v: (Version): signon already emitted, just exit */
278 * The next argument is the filename for the DSDT or SSDT.
279 * Open the file, build namespace and dump it.
281 return (NsDumpEntireNamespace (argv
[AcpiGbl_Optind
]));