ahmain.c revision 1.1.1.3.2.4 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: ahmain - Main module for the acpi help utility
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1 jruoho /*
8 1.1.1.3.2.3 skrll * Copyright (C) 2000 - 2016, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1 jruoho * modification, are permitted provided that the following conditions
13 1.1 jruoho * are met:
14 1.1 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1 jruoho * without modification.
17 1.1 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1 jruoho * binary redistribution.
22 1.1 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1 jruoho * from this software without specific prior written permission.
25 1.1 jruoho *
26 1.1 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 jruoho * Software Foundation.
29 1.1 jruoho *
30 1.1 jruoho * NO WARRANTY
31 1.1 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpihelp.h"
45 1.1 jruoho
46 1.1 jruoho
47 1.1 jruoho /* Local prototypes */
48 1.1 jruoho
49 1.1 jruoho static void
50 1.1 jruoho AhDisplayUsage (
51 1.1 jruoho void);
52 1.1 jruoho
53 1.1.1.2 christos #define AH_UTILITY_NAME "ACPI Help Utility"
54 1.1.1.3.2.4 skrll #define AH_SUPPORTED_OPTIONS "adeghikmopstuv"
55 1.1.1.2 christos
56 1.1 jruoho
57 1.1.1.3.2.4 skrll #if defined ACPI_OPTION
58 1.1.1.3.2.4 skrll #undef ACPI_OPTION
59 1.1.1.3.2.4 skrll #endif
60 1.1.1.3.2.4 skrll
61 1.1.1.3.2.4 skrll #define ACPI_OPTION(Name, Description) \
62 1.1.1.3.2.4 skrll AcpiOsPrintf (" %-24s%s\n", Name, Description);
63 1.1.1.3.2.4 skrll
64 1.1 jruoho /******************************************************************************
65 1.1 jruoho *
66 1.1 jruoho * FUNCTION: AhDisplayUsage
67 1.1 jruoho *
68 1.1 jruoho * DESCRIPTION: Usage message
69 1.1 jruoho *
70 1.1 jruoho ******************************************************************************/
71 1.1 jruoho
72 1.1 jruoho static void
73 1.1 jruoho AhDisplayUsage (
74 1.1 jruoho void)
75 1.1 jruoho {
76 1.1 jruoho
77 1.1.1.3 christos ACPI_USAGE_HEADER ("acpihelp <options> [Name/Prefix | HexValue]");
78 1.1.1.2 christos ACPI_OPTION ("-h", "Display help");
79 1.1.1.2 christos ACPI_OPTION ("-v", "Display version information");
80 1.1.1.2 christos
81 1.1.1.3.2.4 skrll ACPI_USAGE_TEXT ("\nAML Names and Encodings (ACPI Machine Language):\n");
82 1.1.1.3.2.4 skrll ACPI_OPTION ("-a [Name/Prefix | *]", "Display both ASL operator and AML opcode name(s)");
83 1.1.1.3.2.4 skrll ACPI_OPTION ("-g [Name/Prefix | *]", "Display AML grammar elements(s)");
84 1.1.1.3.2.4 skrll ACPI_OPTION ("-m [Name/Prefix | *]", "Display AML opcode name(s)");
85 1.1.1.3 christos
86 1.1.1.3.2.2 skrll ACPI_USAGE_TEXT ("\nACPI Values:\n");
87 1.1.1.3.2.2 skrll ACPI_OPTION ("-e [HexValue]", "Decode ACPICA exception code");
88 1.1.1.3.2.2 skrll ACPI_OPTION ("-o [HexValue]", "Decode hex AML opcode");
89 1.1.1.3.2.2 skrll
90 1.1.1.3.2.4 skrll ACPI_USAGE_TEXT ("\nASL Names and Symbols (ACPI Source Language):\n");
91 1.1.1.3.2.4 skrll ACPI_OPTION ("-k [Name/Prefix | *]", "Display ASL non-operator keyword(s)");
92 1.1.1.3.2.4 skrll ACPI_OPTION ("-p [Name/Prefix | *]", "Display ASL predefined method name(s)");
93 1.1.1.3.2.4 skrll ACPI_OPTION ("-s [Name/Prefix | *]", "Display ASL operator name(s)");
94 1.1.1.3 christos
95 1.1.1.3.2.4 skrll ACPI_USAGE_TEXT ("\nOther miscellaneous ACPI Names:\n");
96 1.1.1.3.2.4 skrll ACPI_OPTION ("-i [Name/Prefix | *]", "Display ACPI/PNP Hardware ID(s)");
97 1.1.1.3.2.2 skrll ACPI_OPTION ("-d", "Display iASL Preprocessor directives");
98 1.1.1.3.2.2 skrll ACPI_OPTION ("-t", "Display supported ACPI tables");
99 1.1.1.3 christos ACPI_OPTION ("-u", "Display ACPI-related UUIDs");
100 1.1.1.2 christos
101 1.1.1.3 christos ACPI_USAGE_TEXT ("\nName/Prefix or HexValue not specified means \"Display All\"\n");
102 1.1.1.3 christos ACPI_USAGE_TEXT ("\nDefault search with valid Name/Prefix and no options:\n");
103 1.1.1.3 christos ACPI_USAGE_TEXT (" Find ASL/AML operator names - if NamePrefix does not start with underscore\n");
104 1.1.1.3 christos ACPI_USAGE_TEXT (" Find ASL predefined method names - if NamePrefix starts with underscore\n");
105 1.1 jruoho }
106 1.1 jruoho
107 1.1 jruoho
108 1.1 jruoho /******************************************************************************
109 1.1 jruoho *
110 1.1 jruoho * FUNCTION: main
111 1.1 jruoho *
112 1.1 jruoho * DESCRIPTION: C main function for AcpiHelp utility.
113 1.1 jruoho *
114 1.1 jruoho ******************************************************************************/
115 1.1 jruoho
116 1.1 jruoho int ACPI_SYSTEM_XFACE
117 1.1 jruoho main (
118 1.1 jruoho int argc,
119 1.1 jruoho char *argv[])
120 1.1 jruoho {
121 1.1 jruoho char *Name;
122 1.1 jruoho UINT32 DecodeType;
123 1.1 jruoho int j;
124 1.1 jruoho
125 1.1 jruoho
126 1.1.1.3 christos AcpiOsInitialize ();
127 1.1.1.2 christos ACPI_DEBUG_INITIALIZE (); /* For debug version only */
128 1.1.1.2 christos printf (ACPI_COMMON_SIGNON (AH_UTILITY_NAME));
129 1.1 jruoho DecodeType = AH_DECODE_DEFAULT;
130 1.1 jruoho
131 1.1 jruoho if (argc < 2)
132 1.1 jruoho {
133 1.1 jruoho AhDisplayUsage ();
134 1.1 jruoho return (0);
135 1.1 jruoho }
136 1.1 jruoho
137 1.1 jruoho /* Command line options */
138 1.1 jruoho
139 1.1.1.3 christos while ((j = AcpiGetopt (argc, argv, AH_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
140 1.1 jruoho {
141 1.1.1.3 christos case 'a':
142 1.1.1.3 christos
143 1.1.1.3 christos DecodeType = AH_DECODE_ASL_AML;
144 1.1.1.3 christos break;
145 1.1.1.3 christos
146 1.1.1.3.2.2 skrll case 'd':
147 1.1.1.3.2.2 skrll
148 1.1.1.3.2.2 skrll DecodeType = AH_DISPLAY_DIRECTIVES;
149 1.1.1.3.2.2 skrll break;
150 1.1.1.3.2.2 skrll
151 1.1.1.2 christos case 'e':
152 1.1.1.2 christos
153 1.1.1.2 christos DecodeType = AH_DECODE_EXCEPTION;
154 1.1.1.2 christos break;
155 1.1.1.2 christos
156 1.1.1.3.2.4 skrll case 'g':
157 1.1.1.3.2.4 skrll
158 1.1.1.3.2.4 skrll DecodeType = AH_DECODE_AML_TYPE;
159 1.1.1.3.2.4 skrll break;
160 1.1.1.3.2.4 skrll
161 1.1.1.2 christos case 'i':
162 1.1.1.2 christos
163 1.1.1.2 christos DecodeType = AH_DISPLAY_DEVICE_IDS;
164 1.1.1.2 christos break;
165 1.1.1.2 christos
166 1.1 jruoho case 'k':
167 1.1.1.2 christos
168 1.1 jruoho DecodeType = AH_DECODE_ASL_KEYWORD;
169 1.1 jruoho break;
170 1.1 jruoho
171 1.1 jruoho case 'm':
172 1.1.1.2 christos
173 1.1 jruoho DecodeType = AH_DECODE_AML;
174 1.1 jruoho break;
175 1.1 jruoho
176 1.1 jruoho case 'o':
177 1.1.1.2 christos
178 1.1 jruoho DecodeType = AH_DECODE_AML_OPCODE;
179 1.1 jruoho break;
180 1.1 jruoho
181 1.1 jruoho case 'p':
182 1.1.1.2 christos
183 1.1 jruoho DecodeType = AH_DECODE_PREDEFINED_NAME;
184 1.1 jruoho break;
185 1.1 jruoho
186 1.1 jruoho case 's':
187 1.1.1.2 christos
188 1.1 jruoho DecodeType = AH_DECODE_ASL;
189 1.1 jruoho break;
190 1.1 jruoho
191 1.1.1.3.2.2 skrll case 't':
192 1.1.1.3.2.2 skrll
193 1.1.1.3.2.2 skrll DecodeType = AH_DISPLAY_TABLES;
194 1.1.1.3.2.2 skrll break;
195 1.1.1.3.2.2 skrll
196 1.1.1.3 christos case 'u':
197 1.1.1.3 christos
198 1.1.1.3 christos DecodeType = AH_DISPLAY_UUIDS;
199 1.1.1.3 christos break;
200 1.1.1.3 christos
201 1.1.1.2 christos case 'v': /* -v: (Version): signon already emitted, just exit */
202 1.1.1.2 christos
203 1.1.1.2 christos return (0);
204 1.1.1.2 christos
205 1.1 jruoho case 'h':
206 1.1 jruoho default:
207 1.1.1.2 christos
208 1.1 jruoho AhDisplayUsage ();
209 1.1 jruoho return (-1);
210 1.1 jruoho }
211 1.1 jruoho
212 1.1 jruoho /* Missing (null) name means "display all" */
213 1.1 jruoho
214 1.1 jruoho Name = argv[AcpiGbl_Optind];
215 1.1 jruoho
216 1.1 jruoho switch (DecodeType)
217 1.1 jruoho {
218 1.1.1.3 christos case AH_DECODE_ASL_AML:
219 1.1.1.3 christos
220 1.1.1.3 christos AhFindAslAndAmlOperators (Name);
221 1.1.1.3 christos break;
222 1.1.1.3 christos
223 1.1 jruoho case AH_DECODE_AML:
224 1.1.1.2 christos
225 1.1 jruoho AhFindAmlOpcode (Name);
226 1.1 jruoho break;
227 1.1 jruoho
228 1.1 jruoho case AH_DECODE_AML_OPCODE:
229 1.1.1.2 christos
230 1.1 jruoho AhDecodeAmlOpcode (Name);
231 1.1 jruoho break;
232 1.1 jruoho
233 1.1.1.3.2.4 skrll case AH_DECODE_AML_TYPE:
234 1.1.1.3.2.4 skrll
235 1.1.1.3.2.4 skrll AhFindAmlTypes (Name);
236 1.1.1.3.2.4 skrll break;
237 1.1.1.3.2.4 skrll
238 1.1 jruoho case AH_DECODE_PREDEFINED_NAME:
239 1.1.1.2 christos
240 1.1 jruoho AhFindPredefinedNames (Name);
241 1.1 jruoho break;
242 1.1 jruoho
243 1.1 jruoho case AH_DECODE_ASL:
244 1.1.1.2 christos
245 1.1 jruoho AhFindAslOperators (Name);
246 1.1 jruoho break;
247 1.1 jruoho
248 1.1 jruoho case AH_DECODE_ASL_KEYWORD:
249 1.1.1.2 christos
250 1.1 jruoho AhFindAslKeywords (Name);
251 1.1 jruoho break;
252 1.1 jruoho
253 1.1.1.2 christos case AH_DISPLAY_DEVICE_IDS:
254 1.1.1.2 christos
255 1.1.1.3 christos AhDisplayDeviceIds (Name);
256 1.1.1.2 christos break;
257 1.1.1.2 christos
258 1.1.1.2 christos case AH_DECODE_EXCEPTION:
259 1.1.1.2 christos
260 1.1.1.2 christos AhDecodeException (Name);
261 1.1.1.2 christos break;
262 1.1.1.2 christos
263 1.1.1.3 christos case AH_DISPLAY_UUIDS:
264 1.1.1.3 christos
265 1.1.1.3 christos AhDisplayUuids ();
266 1.1.1.3 christos break;
267 1.1.1.3 christos
268 1.1.1.3.2.2 skrll case AH_DISPLAY_TABLES:
269 1.1.1.3.2.2 skrll
270 1.1.1.3.2.2 skrll AhDisplayTables ();
271 1.1.1.3.2.2 skrll break;
272 1.1.1.3.2.2 skrll
273 1.1.1.3.2.2 skrll case AH_DISPLAY_DIRECTIVES:
274 1.1.1.3.2.2 skrll
275 1.1.1.3.2.2 skrll AhDisplayDirectives ();
276 1.1.1.3.2.2 skrll break;
277 1.1.1.3.2.2 skrll
278 1.1.1.3.2.2 skrll default:
279 1.1.1.2 christos
280 1.1 jruoho if (!Name)
281 1.1 jruoho {
282 1.1 jruoho AhFindAslOperators (Name);
283 1.1 jruoho break;
284 1.1 jruoho }
285 1.1 jruoho
286 1.1 jruoho if (*Name == '_')
287 1.1 jruoho {
288 1.1 jruoho AhFindPredefinedNames (Name);
289 1.1 jruoho }
290 1.1 jruoho else
291 1.1 jruoho {
292 1.1.1.3 christos AhFindAslAndAmlOperators (Name);
293 1.1 jruoho }
294 1.1 jruoho break;
295 1.1 jruoho }
296 1.1 jruoho
297 1.1 jruoho return (0);
298 1.1 jruoho }
299