xref: /titanic_51/usr/src/cmd/acpi/acpidump/apmain.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1*385cc6b4SJerry Jelinek /******************************************************************************
2*385cc6b4SJerry Jelinek  *
3*385cc6b4SJerry Jelinek  * Module Name: apmain - Main module for the acpidump utility
4*385cc6b4SJerry Jelinek  *
5*385cc6b4SJerry Jelinek  *****************************************************************************/
6*385cc6b4SJerry Jelinek 
7*385cc6b4SJerry Jelinek /*
8*385cc6b4SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9*385cc6b4SJerry Jelinek  * All rights reserved.
10*385cc6b4SJerry Jelinek  *
11*385cc6b4SJerry Jelinek  * Redistribution and use in source and binary forms, with or without
12*385cc6b4SJerry Jelinek  * modification, are permitted provided that the following conditions
13*385cc6b4SJerry Jelinek  * are met:
14*385cc6b4SJerry Jelinek  * 1. Redistributions of source code must retain the above copyright
15*385cc6b4SJerry Jelinek  *    notice, this list of conditions, and the following disclaimer,
16*385cc6b4SJerry Jelinek  *    without modification.
17*385cc6b4SJerry Jelinek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*385cc6b4SJerry Jelinek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*385cc6b4SJerry Jelinek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*385cc6b4SJerry Jelinek  *    including a substantially similar Disclaimer requirement for further
21*385cc6b4SJerry Jelinek  *    binary redistribution.
22*385cc6b4SJerry Jelinek  * 3. Neither the names of the above-listed copyright holders nor the names
23*385cc6b4SJerry Jelinek  *    of any contributors may be used to endorse or promote products derived
24*385cc6b4SJerry Jelinek  *    from this software without specific prior written permission.
25*385cc6b4SJerry Jelinek  *
26*385cc6b4SJerry Jelinek  * Alternatively, this software may be distributed under the terms of the
27*385cc6b4SJerry Jelinek  * GNU General Public License ("GPL") version 2 as published by the Free
28*385cc6b4SJerry Jelinek  * Software Foundation.
29*385cc6b4SJerry Jelinek  *
30*385cc6b4SJerry Jelinek  * NO WARRANTY
31*385cc6b4SJerry Jelinek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*385cc6b4SJerry Jelinek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*385cc6b4SJerry Jelinek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*385cc6b4SJerry Jelinek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*385cc6b4SJerry Jelinek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*385cc6b4SJerry Jelinek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*385cc6b4SJerry Jelinek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*385cc6b4SJerry Jelinek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*385cc6b4SJerry Jelinek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*385cc6b4SJerry Jelinek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*385cc6b4SJerry Jelinek  * POSSIBILITY OF SUCH DAMAGES.
42*385cc6b4SJerry Jelinek  */
43*385cc6b4SJerry Jelinek 
44*385cc6b4SJerry Jelinek #define _DECLARE_GLOBALS
45*385cc6b4SJerry Jelinek #include "acpidump.h"
46*385cc6b4SJerry Jelinek #include "acapps.h"
47*385cc6b4SJerry Jelinek 
48*385cc6b4SJerry Jelinek 
49*385cc6b4SJerry Jelinek /*
50*385cc6b4SJerry Jelinek  * acpidump - A portable utility for obtaining system ACPI tables and dumping
51*385cc6b4SJerry Jelinek  * them in an ASCII hex format suitable for binary extraction via acpixtract.
52*385cc6b4SJerry Jelinek  *
53*385cc6b4SJerry Jelinek  * Obtaining the system ACPI tables is an OS-specific operation.
54*385cc6b4SJerry Jelinek  *
55*385cc6b4SJerry Jelinek  * This utility can be ported to any host operating system by providing a
56*385cc6b4SJerry Jelinek  * module containing system-specific versions of these interfaces:
57*385cc6b4SJerry Jelinek  *
58*385cc6b4SJerry Jelinek  *      AcpiOsGetTableByAddress
59*385cc6b4SJerry Jelinek  *      AcpiOsGetTableByIndex
60*385cc6b4SJerry Jelinek  *      AcpiOsGetTableByName
61*385cc6b4SJerry Jelinek  *
62*385cc6b4SJerry Jelinek  * See the ACPICA Reference Guide for the exact definitions of these
63*385cc6b4SJerry Jelinek  * interfaces. Also, see these ACPICA source code modules for example
64*385cc6b4SJerry Jelinek  * implementations:
65*385cc6b4SJerry Jelinek  *
66*385cc6b4SJerry Jelinek  *      source/os_specific/service_layers/oswintbl.c
67*385cc6b4SJerry Jelinek  *      source/os_specific/service_layers/oslinuxtbl.c
68*385cc6b4SJerry Jelinek  */
69*385cc6b4SJerry Jelinek 
70*385cc6b4SJerry Jelinek 
71*385cc6b4SJerry Jelinek /* Local prototypes */
72*385cc6b4SJerry Jelinek 
73*385cc6b4SJerry Jelinek static void
74*385cc6b4SJerry Jelinek ApDisplayUsage (
75*385cc6b4SJerry Jelinek     void);
76*385cc6b4SJerry Jelinek 
77*385cc6b4SJerry Jelinek static int
78*385cc6b4SJerry Jelinek ApDoOptions (
79*385cc6b4SJerry Jelinek     int                     argc,
80*385cc6b4SJerry Jelinek     char                    **argv);
81*385cc6b4SJerry Jelinek 
82*385cc6b4SJerry Jelinek static int
83*385cc6b4SJerry Jelinek ApInsertAction (
84*385cc6b4SJerry Jelinek     char                    *Argument,
85*385cc6b4SJerry Jelinek     UINT32                  ToBeDone);
86*385cc6b4SJerry Jelinek 
87*385cc6b4SJerry Jelinek 
88*385cc6b4SJerry Jelinek /* Table for deferred actions from command line options */
89*385cc6b4SJerry Jelinek 
90*385cc6b4SJerry Jelinek AP_DUMP_ACTION              ActionTable [AP_MAX_ACTIONS];
91*385cc6b4SJerry Jelinek UINT32                      CurrentAction = 0;
92*385cc6b4SJerry Jelinek 
93*385cc6b4SJerry Jelinek 
94*385cc6b4SJerry Jelinek #define AP_UTILITY_NAME             "ACPI Binary Table Dump Utility"
95*385cc6b4SJerry Jelinek #define AP_SUPPORTED_OPTIONS        "?a:bc:f:hn:o:r:svxz"
96*385cc6b4SJerry Jelinek 
97*385cc6b4SJerry Jelinek 
98*385cc6b4SJerry Jelinek /******************************************************************************
99*385cc6b4SJerry Jelinek  *
100*385cc6b4SJerry Jelinek  * FUNCTION:    ApDisplayUsage
101*385cc6b4SJerry Jelinek  *
102*385cc6b4SJerry Jelinek  * DESCRIPTION: Usage message for the AcpiDump utility
103*385cc6b4SJerry Jelinek  *
104*385cc6b4SJerry Jelinek  ******************************************************************************/
105*385cc6b4SJerry Jelinek 
106*385cc6b4SJerry Jelinek static void
107*385cc6b4SJerry Jelinek ApDisplayUsage (
108*385cc6b4SJerry Jelinek     void)
109*385cc6b4SJerry Jelinek {
110*385cc6b4SJerry Jelinek 
111*385cc6b4SJerry Jelinek     ACPI_USAGE_HEADER ("acpidump [options]");
112*385cc6b4SJerry Jelinek 
113*385cc6b4SJerry Jelinek     ACPI_OPTION ("-b",                      "Dump tables to binary files");
114*385cc6b4SJerry Jelinek     ACPI_OPTION ("-h -?",                   "This help message");
115*385cc6b4SJerry Jelinek     ACPI_OPTION ("-o <File>",               "Redirect output to file");
116*385cc6b4SJerry Jelinek     ACPI_OPTION ("-r <Address>",            "Dump tables from specified RSDP");
117*385cc6b4SJerry Jelinek     ACPI_OPTION ("-s",                      "Print table summaries only");
118*385cc6b4SJerry Jelinek     ACPI_OPTION ("-v",                      "Display version information");
119*385cc6b4SJerry Jelinek     ACPI_OPTION ("-z",                      "Verbose mode");
120*385cc6b4SJerry Jelinek 
121*385cc6b4SJerry Jelinek     ACPI_USAGE_TEXT ("\nTable Options:\n");
122*385cc6b4SJerry Jelinek 
123*385cc6b4SJerry Jelinek     ACPI_OPTION ("-a <Address>",            "Get table via a physical address");
124*385cc6b4SJerry Jelinek     ACPI_OPTION ("-c <on|off>",             "Turning on/off customized table dumping");
125*385cc6b4SJerry Jelinek     ACPI_OPTION ("-f <BinaryFile>",         "Get table via a binary file");
126*385cc6b4SJerry Jelinek     ACPI_OPTION ("-n <Signature>",          "Get table via a name/signature");
127*385cc6b4SJerry Jelinek     ACPI_OPTION ("-x",                      "Do not use but dump XSDT");
128*385cc6b4SJerry Jelinek     ACPI_OPTION ("-x -x",                   "Do not use or dump XSDT");
129*385cc6b4SJerry Jelinek 
130*385cc6b4SJerry Jelinek     ACPI_USAGE_TEXT (
131*385cc6b4SJerry Jelinek         "\n"
132*385cc6b4SJerry Jelinek         "Invocation without parameters dumps all available tables\n"
133*385cc6b4SJerry Jelinek         "Multiple mixed instances of -a, -f, and -n are supported\n\n");
134*385cc6b4SJerry Jelinek }
135*385cc6b4SJerry Jelinek 
136*385cc6b4SJerry Jelinek 
137*385cc6b4SJerry Jelinek /******************************************************************************
138*385cc6b4SJerry Jelinek  *
139*385cc6b4SJerry Jelinek  * FUNCTION:    ApInsertAction
140*385cc6b4SJerry Jelinek  *
141*385cc6b4SJerry Jelinek  * PARAMETERS:  Argument            - Pointer to the argument for this action
142*385cc6b4SJerry Jelinek  *              ToBeDone            - What to do to process this action
143*385cc6b4SJerry Jelinek  *
144*385cc6b4SJerry Jelinek  * RETURN:      Status
145*385cc6b4SJerry Jelinek  *
146*385cc6b4SJerry Jelinek  * DESCRIPTION: Add an action item to the action table
147*385cc6b4SJerry Jelinek  *
148*385cc6b4SJerry Jelinek  ******************************************************************************/
149*385cc6b4SJerry Jelinek 
150*385cc6b4SJerry Jelinek static int
151*385cc6b4SJerry Jelinek ApInsertAction (
152*385cc6b4SJerry Jelinek     char                    *Argument,
153*385cc6b4SJerry Jelinek     UINT32                  ToBeDone)
154*385cc6b4SJerry Jelinek {
155*385cc6b4SJerry Jelinek 
156*385cc6b4SJerry Jelinek     /* Insert action and check for table overflow */
157*385cc6b4SJerry Jelinek 
158*385cc6b4SJerry Jelinek     ActionTable [CurrentAction].Argument = Argument;
159*385cc6b4SJerry Jelinek     ActionTable [CurrentAction].ToBeDone = ToBeDone;
160*385cc6b4SJerry Jelinek 
161*385cc6b4SJerry Jelinek     CurrentAction++;
162*385cc6b4SJerry Jelinek     if (CurrentAction > AP_MAX_ACTIONS)
163*385cc6b4SJerry Jelinek     {
164*385cc6b4SJerry Jelinek         AcpiLogError ("Too many table options (max %u)\n", AP_MAX_ACTIONS);
165*385cc6b4SJerry Jelinek         return (-1);
166*385cc6b4SJerry Jelinek     }
167*385cc6b4SJerry Jelinek 
168*385cc6b4SJerry Jelinek     return (0);
169*385cc6b4SJerry Jelinek }
170*385cc6b4SJerry Jelinek 
171*385cc6b4SJerry Jelinek 
172*385cc6b4SJerry Jelinek /******************************************************************************
173*385cc6b4SJerry Jelinek  *
174*385cc6b4SJerry Jelinek  * FUNCTION:    ApDoOptions
175*385cc6b4SJerry Jelinek  *
176*385cc6b4SJerry Jelinek  * PARAMETERS:  argc/argv           - Standard argc/argv
177*385cc6b4SJerry Jelinek  *
178*385cc6b4SJerry Jelinek  * RETURN:      Status
179*385cc6b4SJerry Jelinek  *
180*385cc6b4SJerry Jelinek  * DESCRIPTION: Command line option processing. The main actions for getting
181*385cc6b4SJerry Jelinek  *              and dumping tables are deferred via the action table.
182*385cc6b4SJerry Jelinek  *
183*385cc6b4SJerry Jelinek  *****************************************************************************/
184*385cc6b4SJerry Jelinek 
185*385cc6b4SJerry Jelinek static int
186*385cc6b4SJerry Jelinek ApDoOptions (
187*385cc6b4SJerry Jelinek     int                     argc,
188*385cc6b4SJerry Jelinek     char                    **argv)
189*385cc6b4SJerry Jelinek {
190*385cc6b4SJerry Jelinek     int                     j;
191*385cc6b4SJerry Jelinek     ACPI_STATUS             Status;
192*385cc6b4SJerry Jelinek 
193*385cc6b4SJerry Jelinek 
194*385cc6b4SJerry Jelinek     /* Command line options */
195*385cc6b4SJerry Jelinek 
196*385cc6b4SJerry Jelinek     while ((j = AcpiGetopt (argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
197*385cc6b4SJerry Jelinek     {
198*385cc6b4SJerry Jelinek     /*
199*385cc6b4SJerry Jelinek      * Global options
200*385cc6b4SJerry Jelinek      */
201*385cc6b4SJerry Jelinek     case 'b':   /* Dump all input tables to binary files */
202*385cc6b4SJerry Jelinek 
203*385cc6b4SJerry Jelinek         Gbl_BinaryMode = TRUE;
204*385cc6b4SJerry Jelinek         continue;
205*385cc6b4SJerry Jelinek 
206*385cc6b4SJerry Jelinek     case 'c':   /* Dump customized tables */
207*385cc6b4SJerry Jelinek 
208*385cc6b4SJerry Jelinek         if (!strcmp (AcpiGbl_Optarg, "on"))
209*385cc6b4SJerry Jelinek         {
210*385cc6b4SJerry Jelinek             Gbl_DumpCustomizedTables = TRUE;
211*385cc6b4SJerry Jelinek         }
212*385cc6b4SJerry Jelinek         else if (!strcmp (AcpiGbl_Optarg, "off"))
213*385cc6b4SJerry Jelinek         {
214*385cc6b4SJerry Jelinek             Gbl_DumpCustomizedTables = FALSE;
215*385cc6b4SJerry Jelinek         }
216*385cc6b4SJerry Jelinek         else
217*385cc6b4SJerry Jelinek         {
218*385cc6b4SJerry Jelinek             AcpiLogError ("%s: Cannot handle this switch, please use on|off\n",
219*385cc6b4SJerry Jelinek                 AcpiGbl_Optarg);
220*385cc6b4SJerry Jelinek             return (-1);
221*385cc6b4SJerry Jelinek         }
222*385cc6b4SJerry Jelinek         continue;
223*385cc6b4SJerry Jelinek 
224*385cc6b4SJerry Jelinek     case 'h':
225*385cc6b4SJerry Jelinek     case '?':
226*385cc6b4SJerry Jelinek 
227*385cc6b4SJerry Jelinek         ApDisplayUsage ();
228*385cc6b4SJerry Jelinek         return (1);
229*385cc6b4SJerry Jelinek 
230*385cc6b4SJerry Jelinek     case 'o':   /* Redirect output to a single file */
231*385cc6b4SJerry Jelinek 
232*385cc6b4SJerry Jelinek         if (ApOpenOutputFile (AcpiGbl_Optarg))
233*385cc6b4SJerry Jelinek         {
234*385cc6b4SJerry Jelinek             return (-1);
235*385cc6b4SJerry Jelinek         }
236*385cc6b4SJerry Jelinek         continue;
237*385cc6b4SJerry Jelinek 
238*385cc6b4SJerry Jelinek     case 'r':   /* Dump tables from specified RSDP */
239*385cc6b4SJerry Jelinek 
240*385cc6b4SJerry Jelinek         Status = AcpiUtStrtoul64 (AcpiGbl_Optarg, ACPI_ANY_BASE,
241*385cc6b4SJerry Jelinek             ACPI_MAX64_BYTE_WIDTH, &Gbl_RsdpBase);
242*385cc6b4SJerry Jelinek         if (ACPI_FAILURE (Status))
243*385cc6b4SJerry Jelinek         {
244*385cc6b4SJerry Jelinek             AcpiLogError ("%s: Could not convert to a physical address\n",
245*385cc6b4SJerry Jelinek                 AcpiGbl_Optarg);
246*385cc6b4SJerry Jelinek             return (-1);
247*385cc6b4SJerry Jelinek         }
248*385cc6b4SJerry Jelinek         continue;
249*385cc6b4SJerry Jelinek 
250*385cc6b4SJerry Jelinek     case 's':   /* Print table summaries only */
251*385cc6b4SJerry Jelinek 
252*385cc6b4SJerry Jelinek         Gbl_SummaryMode = TRUE;
253*385cc6b4SJerry Jelinek         continue;
254*385cc6b4SJerry Jelinek 
255*385cc6b4SJerry Jelinek     case 'x':   /* Do not use XSDT */
256*385cc6b4SJerry Jelinek 
257*385cc6b4SJerry Jelinek         if (!AcpiGbl_DoNotUseXsdt)
258*385cc6b4SJerry Jelinek         {
259*385cc6b4SJerry Jelinek             AcpiGbl_DoNotUseXsdt = TRUE;
260*385cc6b4SJerry Jelinek         }
261*385cc6b4SJerry Jelinek         else
262*385cc6b4SJerry Jelinek         {
263*385cc6b4SJerry Jelinek             Gbl_DoNotDumpXsdt = TRUE;
264*385cc6b4SJerry Jelinek         }
265*385cc6b4SJerry Jelinek         continue;
266*385cc6b4SJerry Jelinek 
267*385cc6b4SJerry Jelinek     case 'v':   /* Revision/version */
268*385cc6b4SJerry Jelinek 
269*385cc6b4SJerry Jelinek         AcpiOsPrintf (ACPI_COMMON_SIGNON (AP_UTILITY_NAME));
270*385cc6b4SJerry Jelinek         return (1);
271*385cc6b4SJerry Jelinek 
272*385cc6b4SJerry Jelinek     case 'z':   /* Verbose mode */
273*385cc6b4SJerry Jelinek 
274*385cc6b4SJerry Jelinek         Gbl_VerboseMode = TRUE;
275*385cc6b4SJerry Jelinek         AcpiLogError (ACPI_COMMON_SIGNON (AP_UTILITY_NAME));
276*385cc6b4SJerry Jelinek         continue;
277*385cc6b4SJerry Jelinek 
278*385cc6b4SJerry Jelinek     /*
279*385cc6b4SJerry Jelinek      * Table options
280*385cc6b4SJerry Jelinek      */
281*385cc6b4SJerry Jelinek     case 'a':   /* Get table by physical address */
282*385cc6b4SJerry Jelinek 
283*385cc6b4SJerry Jelinek         if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_ADDRESS))
284*385cc6b4SJerry Jelinek         {
285*385cc6b4SJerry Jelinek             return (-1);
286*385cc6b4SJerry Jelinek         }
287*385cc6b4SJerry Jelinek         break;
288*385cc6b4SJerry Jelinek 
289*385cc6b4SJerry Jelinek     case 'f':   /* Get table from a file */
290*385cc6b4SJerry Jelinek 
291*385cc6b4SJerry Jelinek         if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_FILE))
292*385cc6b4SJerry Jelinek         {
293*385cc6b4SJerry Jelinek             return (-1);
294*385cc6b4SJerry Jelinek         }
295*385cc6b4SJerry Jelinek         break;
296*385cc6b4SJerry Jelinek 
297*385cc6b4SJerry Jelinek     case 'n':   /* Get table by input name (signature) */
298*385cc6b4SJerry Jelinek 
299*385cc6b4SJerry Jelinek         if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_NAME))
300*385cc6b4SJerry Jelinek         {
301*385cc6b4SJerry Jelinek             return (-1);
302*385cc6b4SJerry Jelinek         }
303*385cc6b4SJerry Jelinek         break;
304*385cc6b4SJerry Jelinek 
305*385cc6b4SJerry Jelinek     default:
306*385cc6b4SJerry Jelinek 
307*385cc6b4SJerry Jelinek         ApDisplayUsage ();
308*385cc6b4SJerry Jelinek         return (-1);
309*385cc6b4SJerry Jelinek     }
310*385cc6b4SJerry Jelinek 
311*385cc6b4SJerry Jelinek     /* If there are no actions, this means "get/dump all tables" */
312*385cc6b4SJerry Jelinek 
313*385cc6b4SJerry Jelinek     if (CurrentAction == 0)
314*385cc6b4SJerry Jelinek     {
315*385cc6b4SJerry Jelinek         if (ApInsertAction (NULL, AP_DUMP_ALL_TABLES))
316*385cc6b4SJerry Jelinek         {
317*385cc6b4SJerry Jelinek             return (-1);
318*385cc6b4SJerry Jelinek         }
319*385cc6b4SJerry Jelinek     }
320*385cc6b4SJerry Jelinek 
321*385cc6b4SJerry Jelinek     return (0);
322*385cc6b4SJerry Jelinek }
323*385cc6b4SJerry Jelinek 
324*385cc6b4SJerry Jelinek 
325*385cc6b4SJerry Jelinek /******************************************************************************
326*385cc6b4SJerry Jelinek  *
327*385cc6b4SJerry Jelinek  * FUNCTION:    main
328*385cc6b4SJerry Jelinek  *
329*385cc6b4SJerry Jelinek  * PARAMETERS:  argc/argv           - Standard argc/argv
330*385cc6b4SJerry Jelinek  *
331*385cc6b4SJerry Jelinek  * RETURN:      Status
332*385cc6b4SJerry Jelinek  *
333*385cc6b4SJerry Jelinek  * DESCRIPTION: C main function for acpidump utility
334*385cc6b4SJerry Jelinek  *
335*385cc6b4SJerry Jelinek  ******************************************************************************/
336*385cc6b4SJerry Jelinek 
337*385cc6b4SJerry Jelinek #ifndef _GNU_EFI
338*385cc6b4SJerry Jelinek int ACPI_SYSTEM_XFACE
339*385cc6b4SJerry Jelinek main (
340*385cc6b4SJerry Jelinek     int                     argc,
341*385cc6b4SJerry Jelinek     char                    *argv[])
342*385cc6b4SJerry Jelinek #else
343*385cc6b4SJerry Jelinek int ACPI_SYSTEM_XFACE
344*385cc6b4SJerry Jelinek acpi_main (
345*385cc6b4SJerry Jelinek     int                     argc,
346*385cc6b4SJerry Jelinek     char                    *argv[])
347*385cc6b4SJerry Jelinek #endif
348*385cc6b4SJerry Jelinek {
349*385cc6b4SJerry Jelinek     int                     Status = 0;
350*385cc6b4SJerry Jelinek     AP_DUMP_ACTION          *Action;
351*385cc6b4SJerry Jelinek     UINT32                  FileSize;
352*385cc6b4SJerry Jelinek     UINT32                  i;
353*385cc6b4SJerry Jelinek 
354*385cc6b4SJerry Jelinek 
355*385cc6b4SJerry Jelinek     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
356*385cc6b4SJerry Jelinek     AcpiOsInitialize ();
357*385cc6b4SJerry Jelinek     Gbl_OutputFile = ACPI_FILE_OUT;
358*385cc6b4SJerry Jelinek 
359*385cc6b4SJerry Jelinek     /* Process command line options */
360*385cc6b4SJerry Jelinek 
361*385cc6b4SJerry Jelinek     Status = ApDoOptions (argc, argv);
362*385cc6b4SJerry Jelinek     if (Status > 0)
363*385cc6b4SJerry Jelinek     {
364*385cc6b4SJerry Jelinek         return (0);
365*385cc6b4SJerry Jelinek     }
366*385cc6b4SJerry Jelinek     if (Status < 0)
367*385cc6b4SJerry Jelinek     {
368*385cc6b4SJerry Jelinek         return (Status);
369*385cc6b4SJerry Jelinek     }
370*385cc6b4SJerry Jelinek 
371*385cc6b4SJerry Jelinek     /* Get/dump ACPI table(s) as requested */
372*385cc6b4SJerry Jelinek 
373*385cc6b4SJerry Jelinek     for (i = 0; i < CurrentAction; i++)
374*385cc6b4SJerry Jelinek     {
375*385cc6b4SJerry Jelinek         Action = &ActionTable[i];
376*385cc6b4SJerry Jelinek         switch (Action->ToBeDone)
377*385cc6b4SJerry Jelinek         {
378*385cc6b4SJerry Jelinek         case AP_DUMP_ALL_TABLES:
379*385cc6b4SJerry Jelinek 
380*385cc6b4SJerry Jelinek             Status = ApDumpAllTables ();
381*385cc6b4SJerry Jelinek             break;
382*385cc6b4SJerry Jelinek 
383*385cc6b4SJerry Jelinek         case AP_DUMP_TABLE_BY_ADDRESS:
384*385cc6b4SJerry Jelinek 
385*385cc6b4SJerry Jelinek             Status = ApDumpTableByAddress (Action->Argument);
386*385cc6b4SJerry Jelinek             break;
387*385cc6b4SJerry Jelinek 
388*385cc6b4SJerry Jelinek         case AP_DUMP_TABLE_BY_NAME:
389*385cc6b4SJerry Jelinek 
390*385cc6b4SJerry Jelinek             Status = ApDumpTableByName (Action->Argument);
391*385cc6b4SJerry Jelinek             break;
392*385cc6b4SJerry Jelinek 
393*385cc6b4SJerry Jelinek         case AP_DUMP_TABLE_BY_FILE:
394*385cc6b4SJerry Jelinek 
395*385cc6b4SJerry Jelinek             Status = ApDumpTableFromFile (Action->Argument);
396*385cc6b4SJerry Jelinek             break;
397*385cc6b4SJerry Jelinek 
398*385cc6b4SJerry Jelinek         default:
399*385cc6b4SJerry Jelinek 
400*385cc6b4SJerry Jelinek             AcpiLogError ("Internal error, invalid action: 0x%X\n",
401*385cc6b4SJerry Jelinek                 Action->ToBeDone);
402*385cc6b4SJerry Jelinek             return (-1);
403*385cc6b4SJerry Jelinek         }
404*385cc6b4SJerry Jelinek 
405*385cc6b4SJerry Jelinek         if (Status)
406*385cc6b4SJerry Jelinek         {
407*385cc6b4SJerry Jelinek             return (Status);
408*385cc6b4SJerry Jelinek         }
409*385cc6b4SJerry Jelinek     }
410*385cc6b4SJerry Jelinek 
411*385cc6b4SJerry Jelinek     if (Gbl_OutputFilename)
412*385cc6b4SJerry Jelinek     {
413*385cc6b4SJerry Jelinek         if (Gbl_VerboseMode)
414*385cc6b4SJerry Jelinek         {
415*385cc6b4SJerry Jelinek             /* Summary for the output file */
416*385cc6b4SJerry Jelinek 
417*385cc6b4SJerry Jelinek             FileSize = CmGetFileSize (Gbl_OutputFile);
418*385cc6b4SJerry Jelinek             AcpiLogError ("Output file %s contains 0x%X (%u) bytes\n\n",
419*385cc6b4SJerry Jelinek                 Gbl_OutputFilename, FileSize, FileSize);
420*385cc6b4SJerry Jelinek         }
421*385cc6b4SJerry Jelinek 
422*385cc6b4SJerry Jelinek         AcpiOsCloseFile (Gbl_OutputFile);
423*385cc6b4SJerry Jelinek     }
424*385cc6b4SJerry Jelinek 
425*385cc6b4SJerry Jelinek     return (Status);
426*385cc6b4SJerry Jelinek }
427