]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/acpinames/anmain.c
Import ACPICA 20120111.
[FreeBSD/FreeBSD.git] / tools / acpinames / anmain.c
1 /******************************************************************************
2  *
3  * Module Name: anmain - Main routine for the AcpiNames utility
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2012, Intel Corp.
9  * All rights reserved.
10  *
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.
25  *
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.
29  *
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.
42  */
43
44 #include "acpinames.h"
45
46 #define _COMPONENT          ACPI_TOOLS
47         ACPI_MODULE_NAME    ("anmain")
48
49
50 extern ACPI_TABLE_DESC  Tables[];
51
52 FILE                    *AcpiGbl_DebugFile;
53 static AE_TABLE_DESC    *AeTableListHead = NULL;
54
55
56 #define AE_SUPPORTED_OPTIONS    "?h"
57
58
59 /******************************************************************************
60  *
61  * FUNCTION:    usage
62  *
63  * PARAMETERS:  None
64  *
65  * RETURN:      None
66  *
67  * DESCRIPTION: Print a usage message
68  *
69  *****************************************************************************/
70
71 static void
72 usage (
73     void)
74 {
75
76     ACPI_USAGE_HEADER ("AcpiNames [options] AMLfile");
77     ACPI_OPTION ("-?",                  "Display this message");
78 }
79
80
81 /******************************************************************************
82  *
83  * FUNCTION:    NsDumpEntireNamespace
84  *
85  * PARAMETERS:  AmlFilename         - Filename for DSDT or SSDT AML table
86  *
87  * RETURN:      Status (pass/fail)
88  *
89  * DESCRIPTION: Build an ACPI namespace for the input AML table, and dump the
90  *              formatted namespace contents.
91  *
92  *****************************************************************************/
93
94 static int
95 NsDumpEntireNamespace (
96     char                    *AmlFilename)
97 {
98     ACPI_STATUS             Status;
99     ACPI_TABLE_HEADER       *Table = NULL;
100     UINT32                  TableCount = 0;
101     AE_TABLE_DESC           *TableDesc;
102     ACPI_HANDLE             Handle;
103
104
105     /* Open the binary AML file and read the entire table */
106
107     Status = AcpiDbReadTableFromFile (AmlFilename, &Table);
108     if (ACPI_FAILURE (Status))
109     {
110         printf ("**** Could not get input table %s, %s\n", AmlFilename,
111             AcpiFormatException (Status));
112         return (-1);
113     }
114
115     /* Table must be a DSDT. SSDTs are not currently supported */
116
117     if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
118     {
119         printf ("**** Input table signature is [%4.4s], must be [DSDT]\n",
120             Table->Signature);
121         return (-1);
122     }
123
124     /*
125      * Allocate and link a table descriptor (allows for future expansion to
126      * multiple input files)
127      */
128     TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC));
129     TableDesc->Table = Table;
130     TableDesc->Next = AeTableListHead;
131     AeTableListHead = TableDesc;
132
133     TableCount++;
134
135     /*
136      * Build a local XSDT with all tables. Normally, here is where the
137      * RSDP search is performed to find the ACPI tables
138      */
139     Status = AeBuildLocalTables (TableCount, AeTableListHead);
140     if (ACPI_FAILURE (Status))
141     {
142         return (-1);
143     }
144
145     /* Initialize table manager, get XSDT */
146
147     Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE);
148     if (ACPI_FAILURE (Status))
149     {
150         printf ("**** Could not initialize ACPI table manager, %s\n",
151             AcpiFormatException (Status));
152         return (-1);
153     }
154
155     /* Reallocate root table to dynamic memory */
156
157     Status = AcpiReallocateRootTable ();
158     if (ACPI_FAILURE (Status))
159     {
160         printf ("**** Could not reallocate root table, %s\n",
161             AcpiFormatException (Status));
162         return (-1);
163     }
164
165     /* Load the ACPI namespace */
166
167     Status = AcpiLoadTables ();
168     if (ACPI_FAILURE (Status))
169     {
170         printf ("**** Could not load ACPI tables, %s\n",
171             AcpiFormatException (Status));
172         return (-1);
173     }
174
175     /*
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.
179      */
180     Status = AcpiEnableSubsystem (
181                 ACPI_NO_ACPI_ENABLE |
182                 ACPI_NO_ADDRESS_SPACE_INIT |
183                 ACPI_NO_EVENT_INIT |
184                 ACPI_NO_HANDLER_INIT);
185     if (ACPI_FAILURE (Status))
186     {
187         printf ("**** Could not EnableSubsystem, %s\n",
188             AcpiFormatException (Status));
189         return (-1);
190     }
191
192     Status = AcpiInitializeObjects (
193                 ACPI_NO_ADDRESS_SPACE_INIT |
194                 ACPI_NO_DEVICE_INIT |
195                 ACPI_NO_EVENT_INIT);
196     if (ACPI_FAILURE (Status))
197     {
198         printf ("**** Could not InitializeObjects, %s\n",
199             AcpiFormatException (Status));
200         return (-1);
201     }
202
203     /*
204      * Perform a namespace walk to dump the contents
205      */
206     AcpiOsPrintf ("\nACPI Namespace:\n");
207
208     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, ACPI_UINT32_MAX,
209         ACPI_OWNER_ID_MAX, AcpiGbl_RootNode);
210
211
212     /* Example: get a handle to the _GPE scope */
213
214     Status = AcpiGetHandle (NULL, "\\_GPE", &Handle);
215     AE_CHECK_OK (AcpiGetHandle, Status);
216
217     return (0);
218 }
219
220
221 /******************************************************************************
222  *
223  * FUNCTION:    main
224  *
225  * PARAMETERS:  argc, argv
226  *
227  * RETURN:      Status (pass/fail)
228  *
229  * DESCRIPTION: Main routine for NsDump utility
230  *
231  *****************************************************************************/
232
233 int ACPI_SYSTEM_XFACE
234 main (
235     int                     argc,
236     char                    **argv)
237 {
238     ACPI_STATUS             Status;
239     int                     j;
240
241
242     printf (ACPI_COMMON_SIGNON ("ACPI Namespace Dump Utility"));
243
244     if (argc < 2)
245     {
246         usage ();
247         return (0);
248     }
249
250     /* Init globals and ACPICA */
251
252     AcpiDbgLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
253     AcpiDbgLayer = 0xFFFFFFFF;
254
255     Status = AcpiInitializeSubsystem ();
256     AE_CHECK_OK (AcpiInitializeSubsystem, Status);
257
258     /* Get the command line options */
259
260     while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch(j)
261     {
262     case '?':
263     case 'h':
264     default:
265         usage();
266         return (0);
267     }
268
269     /*
270      * The next argument is the filename for the DSDT or SSDT.
271      * Open the file, build namespace and dump it.
272      */
273     return (NsDumpEntireNamespace (argv[AcpiGbl_Optind]));
274 }
275