Sync ACPICA with Intel's version 20161222.
[dragonfly.git] / sys / contrib / dev / acpica / source / tools / acpihelp / ahasl.c
blobc9fd3a672e85fc1269d9bd8e542e5d1053a23f94
1 /******************************************************************************
3 * Module Name: ahasl - ASL operator decoding for acpihelp 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 #include "acpihelp.h"
47 /* Local prototypes */
49 static void
50 AhDisplayAslOperator (
51 const AH_ASL_OPERATOR *Op);
53 static void
54 AhDisplayOperatorKeywords (
55 const AH_ASL_OPERATOR *Op);
57 static void
58 AhDisplayAslKeyword (
59 const AH_ASL_KEYWORD *Op);
62 /*******************************************************************************
64 * FUNCTION: AhFindAslKeywords (entry point for ASL keyword search)
66 * PARAMETERS: Name - Name or prefix for an ASL keyword.
67 * NULL means "find all"
69 * RETURN: None
71 * DESCRIPTION: Find all ASL keywords that match the input Name or name
72 * prefix.
74 ******************************************************************************/
76 void
77 AhFindAslKeywords (
78 char *Name)
80 const AH_ASL_KEYWORD *Keyword;
81 BOOLEAN Found = FALSE;
84 AcpiUtStrupr (Name);
86 for (Keyword = Gbl_AslKeywordInfo; Keyword->Name; Keyword++)
88 if (!Name || (Name[0] == '*'))
90 AhDisplayAslKeyword (Keyword);
91 Found = TRUE;
92 continue;
95 /* Upper case the operator name before substring compare */
97 strcpy (Gbl_Buffer, Keyword->Name);
98 AcpiUtStrupr (Gbl_Buffer);
100 if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
102 AhDisplayAslKeyword (Keyword);
103 Found = TRUE;
107 if (!Found)
109 printf ("%s, no matching ASL keywords\n", Name);
114 /*******************************************************************************
116 * FUNCTION: AhDisplayAslKeyword
118 * PARAMETERS: Op - Pointer to ASL keyword with syntax info
120 * RETURN: None
122 * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits
123 * long lines appropriately for reading.
125 ******************************************************************************/
127 static void
128 AhDisplayAslKeyword (
129 const AH_ASL_KEYWORD *Op)
132 /* ASL keyword name and description */
134 printf ("%22s: %s\n", Op->Name, Op->Description);
135 if (!Op->KeywordList)
137 return;
140 /* List of actual keywords */
142 AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH, Op->KeywordList);
143 printf ("\n");
147 /*******************************************************************************
149 * FUNCTION: AhFindAslAndAmlOperators
151 * PARAMETERS: Name - Name or prefix for an ASL operator.
152 * NULL means "find all"
154 * RETURN: None
156 * DESCRIPTION: Find all ASL operators that match the input Name or name
157 * prefix. Also displays the AML information if only one entry
158 * matches.
160 ******************************************************************************/
162 void
163 AhFindAslAndAmlOperators (
164 char *Name)
166 UINT32 MatchCount;
169 MatchCount = AhFindAslOperators (Name);
170 if (MatchCount == 1)
172 AhFindAmlOpcode (Name);
177 /*******************************************************************************
179 * FUNCTION: AhFindAslOperators (entry point for ASL operator search)
181 * PARAMETERS: Name - Name or prefix for an ASL operator.
182 * NULL means "find all"
184 * RETURN: Number of operators that matched the name prefix.
186 * DESCRIPTION: Find all ASL operators that match the input Name or name
187 * prefix.
189 ******************************************************************************/
191 UINT32
192 AhFindAslOperators (
193 char *Name)
195 const AH_ASL_OPERATOR *Operator;
196 BOOLEAN MatchCount = 0;
199 AcpiUtStrupr (Name);
201 /* Find/display all names that match the input name prefix */
203 for (Operator = Gbl_AslOperatorInfo; Operator->Name; Operator++)
205 if (!Name || (Name[0] == '*'))
207 AhDisplayAslOperator (Operator);
208 MatchCount++;
209 continue;
212 /* Upper case the operator name before substring compare */
214 strcpy (Gbl_Buffer, Operator->Name);
215 AcpiUtStrupr (Gbl_Buffer);
217 if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
219 AhDisplayAslOperator (Operator);
220 MatchCount++;
224 if (!MatchCount)
226 printf ("%s, no matching ASL operators\n", Name);
229 return (MatchCount);
233 /*******************************************************************************
235 * FUNCTION: AhDisplayAslOperator
237 * PARAMETERS: Op - Pointer to ASL operator with syntax info
239 * RETURN: None
241 * DESCRIPTION: Format and display syntax info for an ASL operator. Splits
242 * long lines appropriately for reading.
244 ******************************************************************************/
246 static void
247 AhDisplayAslOperator (
248 const AH_ASL_OPERATOR *Op)
251 /* ASL operator name and description */
253 printf ("%16s: %s\n", Op->Name, Op->Description);
254 if (!Op->Syntax)
256 return;
259 /* Syntax for the operator */
261 AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH, Op->Syntax);
262 printf ("\n");
264 AhDisplayOperatorKeywords (Op);
265 printf ("\n");
269 /*******************************************************************************
271 * FUNCTION: AhDisplayOperatorKeywords
273 * PARAMETERS: Op - Pointer to ASL keyword with syntax info
275 * RETURN: None
277 * DESCRIPTION: Display any/all keywords that are associated with the ASL
278 * operator.
280 ******************************************************************************/
282 static void
283 AhDisplayOperatorKeywords (
284 const AH_ASL_OPERATOR *Op)
286 char *Token;
287 char *Separators = "(){}, ";
288 BOOLEAN FirstKeyword = TRUE;
291 if (!Op || !Op->Syntax)
293 return;
297 * Find all parameters that have the word "keyword" within, and then
298 * display the info about that keyword
300 strcpy (Gbl_LineBuffer, Op->Syntax);
301 Token = strtok (Gbl_LineBuffer, Separators);
302 while (Token)
304 if (strstr (Token, "Keyword"))
306 if (FirstKeyword)
308 printf ("\n");
309 FirstKeyword = FALSE;
312 /* Found a keyword, display keyword information */
314 AhFindAslKeywords (Token);
317 Token = strtok (NULL, Separators);