Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / tools / acpinames / anmain.c
blobc30ae7ae2b50ac77f310337596200c7951b1168c
1 /******************************************************************************
3 * Module Name: anmain - Main routine for the AcpiNames utility
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 /******************************************************************************
62 * FUNCTION: usage
64 * PARAMETERS: None
66 * RETURN: None
68 * DESCRIPTION: Print a usage message
70 *****************************************************************************/
72 static void
73 usage (
74 void)
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 *****************************************************************************/
96 static int
97 NsDumpEntireNamespace (
98 char *AmlFilename)
100 ACPI_STATUS Status;
101 ACPI_TABLE_HEADER *Table = NULL;
102 UINT32 TableCount = 0;
103 AE_TABLE_DESC *TableDesc;
104 ACPI_HANDLE Handle;
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));
114 return (-1);
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",
122 Table->Signature);
123 return (-1);
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;
135 TableCount++;
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))
144 return (-1);
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));
154 return (-1);
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));
164 return (-1);
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));
174 return (-1);
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 |
185 ACPI_NO_EVENT_INIT |
186 ACPI_NO_HANDLER_INIT);
187 if (ACPI_FAILURE (Status))
189 printf ("**** Could not EnableSubsystem, %s\n",
190 AcpiFormatException (Status));
191 return (-1);
194 Status = AcpiInitializeObjects (
195 ACPI_NO_ADDRESS_SPACE_INIT |
196 ACPI_NO_DEVICE_INIT |
197 ACPI_NO_EVENT_INIT);
198 if (ACPI_FAILURE (Status))
200 printf ("**** Could not InitializeObjects, %s\n",
201 AcpiFormatException (Status));
202 return (-1);
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);
219 return (0);
223 /******************************************************************************
225 * FUNCTION: main
227 * PARAMETERS: argc, argv
229 * RETURN: Status (pass/fail)
231 * DESCRIPTION: Main routine for NsDump utility
233 *****************************************************************************/
235 int ACPI_SYSTEM_XFACE
236 main (
237 int argc,
238 char **argv)
240 ACPI_STATUS Status;
241 int j;
244 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
245 printf (ACPI_COMMON_SIGNON (AN_UTILITY_NAME));
247 if (argc < 2)
249 usage ();
250 return (0);
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 */
267 return (0);
269 case '?':
270 case 'h':
271 default:
273 usage();
274 return (0);
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]));