xref: /netbsd-src/sys/external/bsd/acpica/dist/tools/acpihelp/ahmain.c (revision 046a29855e04359424fd074e8313af6b6be8cfb6)
1a8e4c046Sjruoho /******************************************************************************
2a8e4c046Sjruoho  *
3a8e4c046Sjruoho  * Module Name: ahmain - Main module for the acpi help utility
4a8e4c046Sjruoho  *
5a8e4c046Sjruoho  *****************************************************************************/
6a8e4c046Sjruoho 
7a8e4c046Sjruoho /*
8*046a2985Schristos  * Copyright (C) 2000 - 2023, Intel Corp.
9a8e4c046Sjruoho  * All rights reserved.
10a8e4c046Sjruoho  *
11a8e4c046Sjruoho  * Redistribution and use in source and binary forms, with or without
12a8e4c046Sjruoho  * modification, are permitted provided that the following conditions
13a8e4c046Sjruoho  * are met:
14a8e4c046Sjruoho  * 1. Redistributions of source code must retain the above copyright
15a8e4c046Sjruoho  *    notice, this list of conditions, and the following disclaimer,
16a8e4c046Sjruoho  *    without modification.
17a8e4c046Sjruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18a8e4c046Sjruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
19a8e4c046Sjruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
20a8e4c046Sjruoho  *    including a substantially similar Disclaimer requirement for further
21a8e4c046Sjruoho  *    binary redistribution.
22a8e4c046Sjruoho  * 3. Neither the names of the above-listed copyright holders nor the names
23a8e4c046Sjruoho  *    of any contributors may be used to endorse or promote products derived
24a8e4c046Sjruoho  *    from this software without specific prior written permission.
25a8e4c046Sjruoho  *
26a8e4c046Sjruoho  * Alternatively, this software may be distributed under the terms of the
27a8e4c046Sjruoho  * GNU General Public License ("GPL") version 2 as published by the Free
28a8e4c046Sjruoho  * Software Foundation.
29a8e4c046Sjruoho  *
30a8e4c046Sjruoho  * NO WARRANTY
31a8e4c046Sjruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32a8e4c046Sjruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3346a330b4Schristos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34a8e4c046Sjruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35a8e4c046Sjruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36a8e4c046Sjruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37a8e4c046Sjruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38a8e4c046Sjruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39a8e4c046Sjruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40a8e4c046Sjruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41a8e4c046Sjruoho  * POSSIBILITY OF SUCH DAMAGES.
42a8e4c046Sjruoho  */
43a8e4c046Sjruoho 
440b89cdedSchristos #define DEFINE_AHELP_GLOBALS
45a8e4c046Sjruoho #include "acpihelp.h"
46a8e4c046Sjruoho 
47a8e4c046Sjruoho 
48a8e4c046Sjruoho /* Local prototypes */
49a8e4c046Sjruoho 
50a8e4c046Sjruoho static void
51a8e4c046Sjruoho AhDisplayUsage (
52a8e4c046Sjruoho     void);
53a8e4c046Sjruoho 
54ff4a156dSchristos #define AH_UTILITY_NAME             "ACPI Help Utility"
5582065f3bSchristos #define AH_SUPPORTED_OPTIONS        "adeghikmopstuv^x"
56ff4a156dSchristos 
57a8e4c046Sjruoho 
58d0e1da26Schristos #if defined ACPI_OPTION
59d0e1da26Schristos #undef ACPI_OPTION
60d0e1da26Schristos #endif
61d0e1da26Schristos 
62d0e1da26Schristos #define ACPI_OPTION(Name, Description) \
63d0e1da26Schristos     AcpiOsPrintf ("  %-24s%s\n", Name, Description);
64d0e1da26Schristos 
650b89cdedSchristos 
66a8e4c046Sjruoho /******************************************************************************
67a8e4c046Sjruoho  *
68a8e4c046Sjruoho  * FUNCTION:    AhDisplayUsage
69a8e4c046Sjruoho  *
70a8e4c046Sjruoho  * DESCRIPTION: Usage message
71a8e4c046Sjruoho  *
72a8e4c046Sjruoho  ******************************************************************************/
73a8e4c046Sjruoho 
74a8e4c046Sjruoho static void
AhDisplayUsage(void)75a8e4c046Sjruoho AhDisplayUsage (
76a8e4c046Sjruoho     void)
77a8e4c046Sjruoho {
78a8e4c046Sjruoho 
79460301d4Schristos     ACPI_USAGE_HEADER ("acpihelp <options> [Name/Prefix | HexValue]");
80ff4a156dSchristos     ACPI_OPTION ("-h",                      "Display help");
81ff4a156dSchristos     ACPI_OPTION ("-v",                      "Display version information");
82b406f703Schristos     ACPI_OPTION ("-vd",                     "Display build date and time");
83ff4a156dSchristos 
84d0e1da26Schristos     ACPI_USAGE_TEXT ("\nAML Names and Encodings (ACPI Machine Language):\n");
85d0e1da26Schristos     ACPI_OPTION ("-a [Name/Prefix | *]",    "Display both ASL operator and AML opcode name(s)");
86d0e1da26Schristos     ACPI_OPTION ("-g [Name/Prefix | *]",    "Display AML grammar elements(s)");
87d0e1da26Schristos     ACPI_OPTION ("-m [Name/Prefix | *]",    "Display AML opcode name(s)");
88ff4a156dSchristos 
89c72da027Schristos     ACPI_USAGE_TEXT ("\nACPI Values:\n");
90c72da027Schristos     ACPI_OPTION ("-e [HexValue]",           "Decode ACPICA exception code");
91c72da027Schristos     ACPI_OPTION ("-o [HexValue]",           "Decode hex AML opcode");
92360a9019Schristos     ACPI_OPTION ("-x [HexValue]",           "Decode iASL exception code");
93c72da027Schristos 
94d0e1da26Schristos     ACPI_USAGE_TEXT ("\nASL Names and Symbols (ACPI Source Language):\n");
95d0e1da26Schristos     ACPI_OPTION ("-k [Name/Prefix | *]",    "Display ASL non-operator keyword(s)");
96d0e1da26Schristos     ACPI_OPTION ("-p [Name/Prefix | *]",    "Display ASL predefined method name(s)");
97d0e1da26Schristos     ACPI_OPTION ("-s [Name/Prefix | *]",    "Display ASL operator name(s)");
98460301d4Schristos 
99d0e1da26Schristos     ACPI_USAGE_TEXT ("\nOther miscellaneous ACPI Names:\n");
100d0e1da26Schristos     ACPI_OPTION ("-i [Name/Prefix | *]",    "Display ACPI/PNP Hardware ID(s)");
101c72da027Schristos     ACPI_OPTION ("-d",                      "Display iASL Preprocessor directives");
102c72da027Schristos     ACPI_OPTION ("-t",                      "Display supported ACPI tables");
103460301d4Schristos     ACPI_OPTION ("-u",                      "Display ACPI-related UUIDs");
104460301d4Schristos 
105460301d4Schristos     ACPI_USAGE_TEXT ("\nName/Prefix or HexValue not specified means \"Display All\"\n");
106460301d4Schristos     ACPI_USAGE_TEXT ("\nDefault search with valid Name/Prefix and no options:\n");
107460301d4Schristos     ACPI_USAGE_TEXT ("    Find ASL/AML operator names - if NamePrefix does not start with underscore\n");
108460301d4Schristos     ACPI_USAGE_TEXT ("    Find ASL predefined method names - if NamePrefix starts with underscore\n");
109a8e4c046Sjruoho }
110a8e4c046Sjruoho 
111a8e4c046Sjruoho 
112a8e4c046Sjruoho /******************************************************************************
113a8e4c046Sjruoho  *
114a8e4c046Sjruoho  * FUNCTION:    main
115a8e4c046Sjruoho  *
116a8e4c046Sjruoho  * DESCRIPTION: C main function for AcpiHelp utility.
117a8e4c046Sjruoho  *
118a8e4c046Sjruoho  ******************************************************************************/
119a8e4c046Sjruoho 
120a8e4c046Sjruoho int ACPI_SYSTEM_XFACE
main(int argc,char * argv[])121a8e4c046Sjruoho main (
122a8e4c046Sjruoho     int                     argc,
123a8e4c046Sjruoho     char                    *argv[])
124a8e4c046Sjruoho {
125a8e4c046Sjruoho     char                    *Name;
126a8e4c046Sjruoho     UINT32                  DecodeType;
127a8e4c046Sjruoho     int                     j;
128a8e4c046Sjruoho 
129a8e4c046Sjruoho 
130460301d4Schristos     AcpiOsInitialize ();
131ff4a156dSchristos     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
132ff4a156dSchristos     printf (ACPI_COMMON_SIGNON (AH_UTILITY_NAME));
133a8e4c046Sjruoho     DecodeType = AH_DECODE_DEFAULT;
134a8e4c046Sjruoho 
135a8e4c046Sjruoho     if (argc < 2)
136a8e4c046Sjruoho     {
137a8e4c046Sjruoho         AhDisplayUsage ();
138a8e4c046Sjruoho         return (0);
139a8e4c046Sjruoho     }
140a8e4c046Sjruoho 
141a8e4c046Sjruoho     /* Command line options */
142a8e4c046Sjruoho 
143460301d4Schristos     while ((j = AcpiGetopt (argc, argv, AH_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
144a8e4c046Sjruoho     {
145460301d4Schristos     case 'a':
146460301d4Schristos 
147460301d4Schristos         DecodeType = AH_DECODE_ASL_AML;
148460301d4Schristos         break;
149460301d4Schristos 
150c72da027Schristos     case 'd':
151c72da027Schristos 
152c72da027Schristos         DecodeType = AH_DISPLAY_DIRECTIVES;
153c72da027Schristos         break;
154c72da027Schristos 
155ff4a156dSchristos     case 'e':
156ff4a156dSchristos 
157ff4a156dSchristos         DecodeType = AH_DECODE_EXCEPTION;
158ff4a156dSchristos         break;
159ff4a156dSchristos 
160d0e1da26Schristos     case 'g':
161d0e1da26Schristos 
162d0e1da26Schristos         DecodeType = AH_DECODE_AML_TYPE;
163d0e1da26Schristos         break;
164d0e1da26Schristos 
165ff4a156dSchristos     case 'i':
166ff4a156dSchristos 
167ff4a156dSchristos         DecodeType = AH_DISPLAY_DEVICE_IDS;
168ff4a156dSchristos         break;
169ff4a156dSchristos 
170a8e4c046Sjruoho     case 'k':
171ff4a156dSchristos 
172a8e4c046Sjruoho         DecodeType = AH_DECODE_ASL_KEYWORD;
173a8e4c046Sjruoho         break;
174a8e4c046Sjruoho 
175a8e4c046Sjruoho     case 'm':
176ff4a156dSchristos 
177a8e4c046Sjruoho         DecodeType = AH_DECODE_AML;
178a8e4c046Sjruoho         break;
179a8e4c046Sjruoho 
180a8e4c046Sjruoho     case 'o':
181ff4a156dSchristos 
182a8e4c046Sjruoho         DecodeType = AH_DECODE_AML_OPCODE;
183a8e4c046Sjruoho         break;
184a8e4c046Sjruoho 
185a8e4c046Sjruoho     case 'p':
186ff4a156dSchristos 
187a8e4c046Sjruoho         DecodeType = AH_DECODE_PREDEFINED_NAME;
188a8e4c046Sjruoho         break;
189a8e4c046Sjruoho 
190a8e4c046Sjruoho     case 's':
191ff4a156dSchristos 
192a8e4c046Sjruoho         DecodeType = AH_DECODE_ASL;
193a8e4c046Sjruoho         break;
194a8e4c046Sjruoho 
195c72da027Schristos     case 't':
196c72da027Schristos 
197c72da027Schristos         DecodeType = AH_DISPLAY_TABLES;
198c72da027Schristos         break;
199c72da027Schristos 
200460301d4Schristos     case 'u':
201460301d4Schristos 
202460301d4Schristos         DecodeType = AH_DISPLAY_UUIDS;
203460301d4Schristos         break;
204460301d4Schristos 
205360a9019Schristos     case 'x':
206360a9019Schristos 
207360a9019Schristos         DecodeType = AH_DECODE_ASL_EXCEPTION;
208360a9019Schristos         break;
209360a9019Schristos 
210ff4a156dSchristos     case 'v': /* -v: (Version): signon already emitted, just exit */
211ff4a156dSchristos 
212b406f703Schristos         switch (AcpiGbl_Optarg[0])
213b406f703Schristos         {
214b406f703Schristos         case '^':  /* -v: (Version) */
215b406f703Schristos 
216b406f703Schristos             return (1);
217b406f703Schristos 
218b406f703Schristos         case 'd':
219b406f703Schristos 
220b406f703Schristos             printf (ACPI_COMMON_BUILD_TIME);
221b406f703Schristos             return (1);
222b406f703Schristos 
223b406f703Schristos         default:
224b406f703Schristos 
225b406f703Schristos             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
226b406f703Schristos             return (-1);
227b406f703Schristos         }
228b406f703Schristos         break;
229ff4a156dSchristos 
230a8e4c046Sjruoho     case 'h':
231a8e4c046Sjruoho     default:
232ff4a156dSchristos 
233a8e4c046Sjruoho         AhDisplayUsage ();
234a8e4c046Sjruoho         return (-1);
235a8e4c046Sjruoho     }
236a8e4c046Sjruoho 
237a8e4c046Sjruoho     /* Missing (null) name means "display all" */
238a8e4c046Sjruoho 
239a8e4c046Sjruoho     Name = argv[AcpiGbl_Optind];
240a8e4c046Sjruoho 
241a8e4c046Sjruoho     switch (DecodeType)
242a8e4c046Sjruoho     {
243460301d4Schristos     case AH_DECODE_ASL_AML:
244460301d4Schristos 
245460301d4Schristos         AhFindAslAndAmlOperators (Name);
246460301d4Schristos         break;
247460301d4Schristos 
248a8e4c046Sjruoho     case AH_DECODE_AML:
249ff4a156dSchristos 
250a8e4c046Sjruoho         AhFindAmlOpcode (Name);
251a8e4c046Sjruoho         break;
252a8e4c046Sjruoho 
253a8e4c046Sjruoho     case AH_DECODE_AML_OPCODE:
254ff4a156dSchristos 
255a8e4c046Sjruoho         AhDecodeAmlOpcode (Name);
256a8e4c046Sjruoho         break;
257a8e4c046Sjruoho 
258d0e1da26Schristos     case AH_DECODE_AML_TYPE:
259d0e1da26Schristos 
260d0e1da26Schristos         AhFindAmlTypes (Name);
261d0e1da26Schristos         break;
262d0e1da26Schristos 
263a8e4c046Sjruoho     case AH_DECODE_PREDEFINED_NAME:
264ff4a156dSchristos 
265a8e4c046Sjruoho         AhFindPredefinedNames (Name);
266a8e4c046Sjruoho         break;
267a8e4c046Sjruoho 
268a8e4c046Sjruoho     case AH_DECODE_ASL:
269ff4a156dSchristos 
270a8e4c046Sjruoho         AhFindAslOperators (Name);
271a8e4c046Sjruoho         break;
272a8e4c046Sjruoho 
273a8e4c046Sjruoho     case AH_DECODE_ASL_KEYWORD:
274ff4a156dSchristos 
275a8e4c046Sjruoho         AhFindAslKeywords (Name);
276a8e4c046Sjruoho         break;
277a8e4c046Sjruoho 
278ff4a156dSchristos     case AH_DISPLAY_DEVICE_IDS:
279ff4a156dSchristos 
280460301d4Schristos         AhDisplayDeviceIds (Name);
281ff4a156dSchristos         break;
282ff4a156dSchristos 
283ff4a156dSchristos     case AH_DECODE_EXCEPTION:
284ff4a156dSchristos 
285ff4a156dSchristos         AhDecodeException (Name);
286ff4a156dSchristos         break;
287ff4a156dSchristos 
288460301d4Schristos     case AH_DISPLAY_UUIDS:
289460301d4Schristos 
290460301d4Schristos         AhDisplayUuids ();
291460301d4Schristos         break;
292460301d4Schristos 
293c72da027Schristos     case AH_DISPLAY_TABLES:
294c72da027Schristos 
295c72da027Schristos         AhDisplayTables ();
296c72da027Schristos         break;
297c72da027Schristos 
298c72da027Schristos     case AH_DISPLAY_DIRECTIVES:
299c72da027Schristos 
300c72da027Schristos         AhDisplayDirectives ();
301c72da027Schristos         break;
302c72da027Schristos 
303360a9019Schristos     case AH_DECODE_ASL_EXCEPTION:
304360a9019Schristos 
305360a9019Schristos         AhDecodeAslException (Name);
306360a9019Schristos         break;
307360a9019Schristos 
308a8e4c046Sjruoho    default:
309ff4a156dSchristos 
310a8e4c046Sjruoho         if (!Name)
311a8e4c046Sjruoho         {
312a8e4c046Sjruoho             AhFindAslOperators (Name);
313a8e4c046Sjruoho             break;
314a8e4c046Sjruoho         }
315a8e4c046Sjruoho 
316a8e4c046Sjruoho         if (*Name == '_')
317a8e4c046Sjruoho         {
318a8e4c046Sjruoho             AhFindPredefinedNames (Name);
319a8e4c046Sjruoho         }
320a8e4c046Sjruoho         else
321a8e4c046Sjruoho         {
322460301d4Schristos             AhFindAslAndAmlOperators (Name);
323a8e4c046Sjruoho         }
324a8e4c046Sjruoho         break;
325a8e4c046Sjruoho     }
326a8e4c046Sjruoho 
327a8e4c046Sjruoho     return (0);
328a8e4c046Sjruoho }
329