8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / acpi / acpidump / apmain.c
blob65d7b157815fe9bd3099224d389cb0f2d6b931a4
1 /******************************************************************************
3 * Module Name: apmain - Main module for the acpidump utility
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, 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 #define _DECLARE_GLOBALS
45 #include "acpidump.h"
46 #include "acapps.h"
50 * acpidump - A portable utility for obtaining system ACPI tables and dumping
51 * them in an ASCII hex format suitable for binary extraction via acpixtract.
53 * Obtaining the system ACPI tables is an OS-specific operation.
55 * This utility can be ported to any host operating system by providing a
56 * module containing system-specific versions of these interfaces:
58 * AcpiOsGetTableByAddress
59 * AcpiOsGetTableByIndex
60 * AcpiOsGetTableByName
62 * See the ACPICA Reference Guide for the exact definitions of these
63 * interfaces. Also, see these ACPICA source code modules for example
64 * implementations:
66 * source/os_specific/service_layers/oswintbl.c
67 * source/os_specific/service_layers/oslinuxtbl.c
71 /* Local prototypes */
73 static void
74 ApDisplayUsage (
75 void);
77 static int
78 ApDoOptions (
79 int argc,
80 char **argv);
82 static int
83 ApInsertAction (
84 char *Argument,
85 UINT32 ToBeDone);
88 /* Table for deferred actions from command line options */
90 AP_DUMP_ACTION ActionTable [AP_MAX_ACTIONS];
91 UINT32 CurrentAction = 0;
94 #define AP_UTILITY_NAME "ACPI Binary Table Dump Utility"
95 #define AP_SUPPORTED_OPTIONS "?a:bc:f:hn:o:r:svxz"
98 /******************************************************************************
100 * FUNCTION: ApDisplayUsage
102 * DESCRIPTION: Usage message for the AcpiDump utility
104 ******************************************************************************/
106 static void
107 ApDisplayUsage (
108 void)
111 ACPI_USAGE_HEADER ("acpidump [options]");
113 ACPI_OPTION ("-b", "Dump tables to binary files");
114 ACPI_OPTION ("-h -?", "This help message");
115 ACPI_OPTION ("-o <File>", "Redirect output to file");
116 ACPI_OPTION ("-r <Address>", "Dump tables from specified RSDP");
117 ACPI_OPTION ("-s", "Print table summaries only");
118 ACPI_OPTION ("-v", "Display version information");
119 ACPI_OPTION ("-z", "Verbose mode");
121 ACPI_USAGE_TEXT ("\nTable Options:\n");
123 ACPI_OPTION ("-a <Address>", "Get table via a physical address");
124 ACPI_OPTION ("-c <on|off>", "Turning on/off customized table dumping");
125 ACPI_OPTION ("-f <BinaryFile>", "Get table via a binary file");
126 ACPI_OPTION ("-n <Signature>", "Get table via a name/signature");
127 ACPI_OPTION ("-x", "Do not use but dump XSDT");
128 ACPI_OPTION ("-x -x", "Do not use or dump XSDT");
130 ACPI_USAGE_TEXT (
131 "\n"
132 "Invocation without parameters dumps all available tables\n"
133 "Multiple mixed instances of -a, -f, and -n are supported\n\n");
137 /******************************************************************************
139 * FUNCTION: ApInsertAction
141 * PARAMETERS: Argument - Pointer to the argument for this action
142 * ToBeDone - What to do to process this action
144 * RETURN: Status
146 * DESCRIPTION: Add an action item to the action table
148 ******************************************************************************/
150 static int
151 ApInsertAction (
152 char *Argument,
153 UINT32 ToBeDone)
156 /* Insert action and check for table overflow */
158 ActionTable [CurrentAction].Argument = Argument;
159 ActionTable [CurrentAction].ToBeDone = ToBeDone;
161 CurrentAction++;
162 if (CurrentAction > AP_MAX_ACTIONS)
164 AcpiLogError ("Too many table options (max %u)\n", AP_MAX_ACTIONS);
165 return (-1);
168 return (0);
172 /******************************************************************************
174 * FUNCTION: ApDoOptions
176 * PARAMETERS: argc/argv - Standard argc/argv
178 * RETURN: Status
180 * DESCRIPTION: Command line option processing. The main actions for getting
181 * and dumping tables are deferred via the action table.
183 *****************************************************************************/
185 static int
186 ApDoOptions (
187 int argc,
188 char **argv)
190 int j;
191 ACPI_STATUS Status;
194 /* Command line options */
196 while ((j = AcpiGetopt (argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
199 * Global options
201 case 'b': /* Dump all input tables to binary files */
203 Gbl_BinaryMode = TRUE;
204 continue;
206 case 'c': /* Dump customized tables */
208 if (!strcmp (AcpiGbl_Optarg, "on"))
210 Gbl_DumpCustomizedTables = TRUE;
212 else if (!strcmp (AcpiGbl_Optarg, "off"))
214 Gbl_DumpCustomizedTables = FALSE;
216 else
218 AcpiLogError ("%s: Cannot handle this switch, please use on|off\n",
219 AcpiGbl_Optarg);
220 return (-1);
222 continue;
224 case 'h':
225 case '?':
227 ApDisplayUsage ();
228 return (1);
230 case 'o': /* Redirect output to a single file */
232 if (ApOpenOutputFile (AcpiGbl_Optarg))
234 return (-1);
236 continue;
238 case 'r': /* Dump tables from specified RSDP */
240 Status = AcpiUtStrtoul64 (AcpiGbl_Optarg, ACPI_ANY_BASE,
241 ACPI_MAX64_BYTE_WIDTH, &Gbl_RsdpBase);
242 if (ACPI_FAILURE (Status))
244 AcpiLogError ("%s: Could not convert to a physical address\n",
245 AcpiGbl_Optarg);
246 return (-1);
248 continue;
250 case 's': /* Print table summaries only */
252 Gbl_SummaryMode = TRUE;
253 continue;
255 case 'x': /* Do not use XSDT */
257 if (!AcpiGbl_DoNotUseXsdt)
259 AcpiGbl_DoNotUseXsdt = TRUE;
261 else
263 Gbl_DoNotDumpXsdt = TRUE;
265 continue;
267 case 'v': /* Revision/version */
269 AcpiOsPrintf (ACPI_COMMON_SIGNON (AP_UTILITY_NAME));
270 return (1);
272 case 'z': /* Verbose mode */
274 Gbl_VerboseMode = TRUE;
275 AcpiLogError (ACPI_COMMON_SIGNON (AP_UTILITY_NAME));
276 continue;
279 * Table options
281 case 'a': /* Get table by physical address */
283 if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_ADDRESS))
285 return (-1);
287 break;
289 case 'f': /* Get table from a file */
291 if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_FILE))
293 return (-1);
295 break;
297 case 'n': /* Get table by input name (signature) */
299 if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_NAME))
301 return (-1);
303 break;
305 default:
307 ApDisplayUsage ();
308 return (-1);
311 /* If there are no actions, this means "get/dump all tables" */
313 if (CurrentAction == 0)
315 if (ApInsertAction (NULL, AP_DUMP_ALL_TABLES))
317 return (-1);
321 return (0);
325 /******************************************************************************
327 * FUNCTION: main
329 * PARAMETERS: argc/argv - Standard argc/argv
331 * RETURN: Status
333 * DESCRIPTION: C main function for acpidump utility
335 ******************************************************************************/
337 #ifndef _GNU_EFI
338 int ACPI_SYSTEM_XFACE
339 main (
340 int argc,
341 char *argv[])
342 #else
343 int ACPI_SYSTEM_XFACE
344 acpi_main (
345 int argc,
346 char *argv[])
347 #endif
349 int Status = 0;
350 AP_DUMP_ACTION *Action;
351 UINT32 FileSize;
352 UINT32 i;
355 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
356 AcpiOsInitialize ();
357 Gbl_OutputFile = ACPI_FILE_OUT;
359 /* Process command line options */
361 Status = ApDoOptions (argc, argv);
362 if (Status > 0)
364 return (0);
366 if (Status < 0)
368 return (Status);
371 /* Get/dump ACPI table(s) as requested */
373 for (i = 0; i < CurrentAction; i++)
375 Action = &ActionTable[i];
376 switch (Action->ToBeDone)
378 case AP_DUMP_ALL_TABLES:
380 Status = ApDumpAllTables ();
381 break;
383 case AP_DUMP_TABLE_BY_ADDRESS:
385 Status = ApDumpTableByAddress (Action->Argument);
386 break;
388 case AP_DUMP_TABLE_BY_NAME:
390 Status = ApDumpTableByName (Action->Argument);
391 break;
393 case AP_DUMP_TABLE_BY_FILE:
395 Status = ApDumpTableFromFile (Action->Argument);
396 break;
398 default:
400 AcpiLogError ("Internal error, invalid action: 0x%X\n",
401 Action->ToBeDone);
402 return (-1);
405 if (Status)
407 return (Status);
411 if (Gbl_OutputFilename)
413 if (Gbl_VerboseMode)
415 /* Summary for the output file */
417 FileSize = CmGetFileSize (Gbl_OutputFile);
418 AcpiLogError ("Output file %s contains 0x%X (%u) bytes\n\n",
419 Gbl_OutputFilename, FileSize, FileSize);
422 AcpiOsCloseFile (Gbl_OutputFile);
425 return (Status);