| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: ahasl - ASL operator decoding for acpihelp utility |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2026, Intel Corp. |
| 9 | * All rights reserved. |
| 10 | * |
| 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. |
| 25 | * |
| 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. |
| 29 | * |
| 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 MERCHANTABILITY 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. |
| 42 | */ |
| 43 | |
| 44 | #include "acpihelp.h" |
| 45 | |
| 46 | |
| 47 | /* Local prototypes */ |
| 48 | |
| 49 | static void |
| 50 | AhDisplayAslOperator ( |
| 51 | const AH_ASL_OPERATOR *Op); |
| 52 | |
| 53 | static void |
| 54 | AhDisplayOperatorKeywords ( |
| 55 | const AH_ASL_OPERATOR *Op); |
| 56 | |
| 57 | static void |
| 58 | AhDisplayAslKeyword ( |
| 59 | const AH_ASL_KEYWORD *Op); |
| 60 | |
| 61 | |
| 62 | /******************************************************************************* |
| 63 | * |
| 64 | * FUNCTION: AhFindAslKeywords (entry point for ASL keyword search) |
| 65 | * |
| 66 | * PARAMETERS: Name - Name or prefix for an ASL keyword. |
| 67 | * NULL means "find all" |
| 68 | * |
| 69 | * RETURN: None |
| 70 | * |
| 71 | * DESCRIPTION: Find all ASL keywords that match the input Name or name |
| 72 | * prefix. |
| 73 | * |
| 74 | ******************************************************************************/ |
| 75 | |
| 76 | void |
| 77 | AhFindAslKeywords ( |
| 78 | char *Name) |
| 79 | { |
| 80 | const AH_ASL_KEYWORD *Keyword; |
| 81 | BOOLEAN Found = FALSE; |
| 82 | |
| 83 | |
| 84 | AcpiUtStrupr (Name); |
| 85 | |
| 86 | for (Keyword = Gbl_AslKeywordInfo; Keyword->Name; Keyword++) |
| 87 | { |
| 88 | if (!Name || (Name[0] == '*')) |
| 89 | { |
| 90 | AhDisplayAslKeyword (Keyword); |
| 91 | Found = TRUE; |
| 92 | continue; |
| 93 | } |
| 94 | |
| 95 | /* Upper case the operator name before substring compare */ |
| 96 | |
| 97 | strcpy (Gbl_Buffer, Keyword->Name); |
| 98 | AcpiUtStrupr (Gbl_Buffer); |
| 99 | |
| 100 | if (strstr (Gbl_Buffer, Name) == Gbl_Buffer) |
| 101 | { |
| 102 | AhDisplayAslKeyword (Keyword); |
| 103 | Found = TRUE; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if (!Found) |
| 108 | { |
| 109 | printf ("%s, no matching ASL keywords\n", Name); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /******************************************************************************* |
| 115 | * |
| 116 | * FUNCTION: AhDisplayAslKeyword |
| 117 | * |
| 118 | * PARAMETERS: Op - Pointer to ASL keyword with syntax info |
| 119 | * |
| 120 | * RETURN: None |
| 121 | * |
| 122 | * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits |
| 123 | * long lines appropriately for reading. |
| 124 | * |
| 125 | ******************************************************************************/ |
| 126 | |
| 127 | static void |
| 128 | AhDisplayAslKeyword ( |
| 129 | const AH_ASL_KEYWORD *Op) |
| 130 | { |
| 131 | |
| 132 | /* ASL keyword name and description */ |
| 133 | |
| 134 | printf ("%22s: %s\n", Op->Name, Op->Description); |
| 135 | if (!Op->KeywordList) |
| 136 | { |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | /* List of actual keywords */ |
| 141 | |
| 142 | AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH, Op->KeywordList); |
| 143 | printf ("\n"); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | /******************************************************************************* |
| 148 | * |
| 149 | * FUNCTION: AhFindAslAndAmlOperators |
| 150 | * |
| 151 | * PARAMETERS: Name - Name or prefix for an ASL operator. |
| 152 | * NULL means "find all" |
| 153 | * |
| 154 | * RETURN: None |
| 155 | * |
| 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. |
| 159 | * |
| 160 | ******************************************************************************/ |
| 161 | |
| 162 | void |
| 163 | AhFindAslAndAmlOperators ( |
| 164 | char *Name) |
| 165 | { |
| 166 | UINT32 MatchCount; |
| 167 | |
| 168 | |
| 169 | MatchCount = AhFindAslOperators (Name); |
| 170 | if (MatchCount == 1) |
| 171 | { |
| 172 | AhFindAmlOpcode (Name); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | /******************************************************************************* |
| 178 | * |
| 179 | * FUNCTION: AhFindAslOperators (entry point for ASL operator search) |
| 180 | * |
| 181 | * PARAMETERS: Name - Name or prefix for an ASL operator. |
| 182 | * NULL means "find all" |
| 183 | * |
| 184 | * RETURN: Number of operators that matched the name prefix. |
| 185 | * |
| 186 | * DESCRIPTION: Find all ASL operators that match the input Name or name |
| 187 | * prefix. |
| 188 | * |
| 189 | ******************************************************************************/ |
| 190 | |
| 191 | UINT32 |
| 192 | AhFindAslOperators ( |
| 193 | char *Name) |
| 194 | { |
| 195 | const AH_ASL_OPERATOR *Operator; |
| 196 | BOOLEAN MatchCount = 0; |
| 197 | |
| 198 | |
| 199 | AcpiUtStrupr (Name); |
| 200 | |
| 201 | /* Find/display all names that match the input name prefix */ |
| 202 | |
| 203 | for (Operator = Gbl_AslOperatorInfo; Operator->Name; Operator++) |
| 204 | { |
| 205 | if (!Name || (Name[0] == '*')) |
| 206 | { |
| 207 | AhDisplayAslOperator (Operator); |
| 208 | MatchCount++; |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | /* Upper case the operator name before substring compare */ |
| 213 | |
| 214 | strcpy (Gbl_Buffer, Operator->Name); |
| 215 | AcpiUtStrupr (Gbl_Buffer); |
| 216 | |
| 217 | if (strstr (Gbl_Buffer, Name) == Gbl_Buffer) |
| 218 | { |
| 219 | AhDisplayAslOperator (Operator); |
| 220 | MatchCount++; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if (!MatchCount) |
| 225 | { |
| 226 | printf ("%s, no matching ASL operators\n", Name); |
| 227 | } |
| 228 | |
| 229 | return (MatchCount); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /******************************************************************************* |
| 234 | * |
| 235 | * FUNCTION: AhDisplayAslOperator |
| 236 | * |
| 237 | * PARAMETERS: Op - Pointer to ASL operator with syntax info |
| 238 | * |
| 239 | * RETURN: None |
| 240 | * |
| 241 | * DESCRIPTION: Format and display syntax info for an ASL operator. Splits |
| 242 | * long lines appropriately for reading. |
| 243 | * |
| 244 | ******************************************************************************/ |
| 245 | |
| 246 | static void |
| 247 | AhDisplayAslOperator ( |
| 248 | const AH_ASL_OPERATOR *Op) |
| 249 | { |
| 250 | |
| 251 | /* ASL operator name and description */ |
| 252 | |
| 253 | printf ("%16s: %s\n", Op->Name, Op->Description); |
| 254 | if (!Op->Syntax) |
| 255 | { |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | /* Syntax for the operator */ |
| 260 | |
| 261 | AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH, Op->Syntax); |
| 262 | printf ("\n"); |
| 263 | |
| 264 | AhDisplayOperatorKeywords (Op); |
| 265 | printf ("\n"); |
| 266 | } |
| 267 | |
| 268 | |
| 269 | /******************************************************************************* |
| 270 | * |
| 271 | * FUNCTION: AhDisplayOperatorKeywords |
| 272 | * |
| 273 | * PARAMETERS: Op - Pointer to ASL keyword with syntax info |
| 274 | * |
| 275 | * RETURN: None |
| 276 | * |
| 277 | * DESCRIPTION: Display any/all keywords that are associated with the ASL |
| 278 | * operator. |
| 279 | * |
| 280 | ******************************************************************************/ |
| 281 | |
| 282 | static void |
| 283 | AhDisplayOperatorKeywords ( |
| 284 | const AH_ASL_OPERATOR *Op) |
| 285 | { |
| 286 | char *Token; |
| 287 | char *Separators = "(){}, "; |
| 288 | BOOLEAN FirstKeyword = TRUE; |
| 289 | |
| 290 | |
| 291 | if (!Op || !Op->Syntax) |
| 292 | { |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * Find all parameters that have the word "keyword" within, and then |
| 298 | * display the info about that keyword |
| 299 | */ |
| 300 | strcpy (Gbl_LineBuffer, Op->Syntax); |
| 301 | Token = strtok (Gbl_LineBuffer, Separators); |
| 302 | while (Token) |
| 303 | { |
| 304 | if (strstr (Token, "Keyword")) |
| 305 | { |
| 306 | if (FirstKeyword) |
| 307 | { |
| 308 | printf ("\n"); |
| 309 | FirstKeyword = FALSE; |
| 310 | } |
| 311 | |
| 312 | /* Found a keyword, display keyword information */ |
| 313 | |
| 314 | AhFindAslKeywords (Token); |
| 315 | } |
| 316 | |
| 317 | Token = strtok (NULL, Separators); |
| 318 | } |
| 319 | } |