psutils.c revision 82367
1/****************************************************************************** 2 * 3 * Module Name: psutils - Parser miscellaneous utilities (Parser only) 4 * $Revision: 40 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117 118#include "acpi.h" 119#include "acparser.h" 120#include "amlcode.h" 121 122#define _COMPONENT ACPI_PARSER 123 MODULE_NAME ("psutils") 124 125 126#define PARSEOP_GENERIC 0x01 127#define PARSEOP_NAMED 0x02 128#define PARSEOP_DEFERRED 0x03 129#define PARSEOP_BYTELIST 0x04 130#define PARSEOP_IN_CACHE 0x80 131 132 133/******************************************************************************* 134 * 135 * FUNCTION: AcpiPsInitOp 136 * 137 * PARAMETERS: Op - A newly allocated Op object 138 * Opcode - Opcode to store in the Op 139 * 140 * RETURN: Status 141 * 142 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on 143 * opcode 144 * 145 ******************************************************************************/ 146 147void 148AcpiPsInitOp ( 149 ACPI_PARSE_OBJECT *Op, 150 UINT16 Opcode) 151{ 152 ACPI_OPCODE_INFO *AmlOp; 153 154 155 Op->DataType = ACPI_DESC_TYPE_PARSER; 156 Op->Opcode = Opcode; 157 158 AmlOp = AcpiPsGetOpcodeInfo (Opcode); 159 160 DEBUG_ONLY_MEMBERS (STRNCPY (Op->OpName, AmlOp->Name, 161 sizeof (Op->OpName))); 162} 163 164 165/******************************************************************************* 166 * 167 * FUNCTION: AcpiPsAllocOp 168 * 169 * PARAMETERS: Opcode - Opcode that will be stored in the new Op 170 * 171 * RETURN: Pointer to the new Op. 172 * 173 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on 174 * opcode. A cache of opcodes is available for the pure 175 * GENERIC_OP, since this is by far the most commonly used. 176 * 177 ******************************************************************************/ 178 179ACPI_PARSE_OBJECT* 180AcpiPsAllocOp ( 181 UINT16 Opcode) 182{ 183 ACPI_PARSE_OBJECT *Op = NULL; 184 UINT32 Size; 185 UINT8 Flags; 186 187 188 189 /* Allocate the minimum required size object */ 190 191 if (AcpiPsIsDeferredOp (Opcode)) 192 { 193 Size = sizeof (ACPI_PARSE2_OBJECT); 194 Flags = PARSEOP_DEFERRED; 195 } 196 197 else if (AcpiPsIsNamedOp (Opcode)) 198 { 199 Size = sizeof (ACPI_PARSE2_OBJECT); 200 Flags = PARSEOP_NAMED; 201 } 202 203 else if (AcpiPsIsBytelistOp (Opcode)) 204 { 205 Size = sizeof (ACPI_PARSE2_OBJECT); 206 Flags = PARSEOP_BYTELIST; 207 } 208 209 else 210 { 211 Size = sizeof (ACPI_PARSE_OBJECT); 212 Flags = PARSEOP_GENERIC; 213 } 214 215 216 217 if (Size == sizeof (ACPI_PARSE_OBJECT)) 218 { 219 /* 220 * The generic op is by far the most common (16 to 1) 221 */ 222 Op = AcpiUtAcquireFromCache (ACPI_MEM_LIST_PSNODE); 223 } 224 225 else 226 { 227 Op = AcpiUtAcquireFromCache (ACPI_MEM_LIST_PSNODE_EXT); 228 } 229 230 231 /* Initialize the Op */ 232 233 if (Op) 234 { 235 AcpiPsInitOp (Op, Opcode); 236 Op->Flags = Flags; 237 } 238 239 return (Op); 240} 241 242 243/******************************************************************************* 244 * 245 * FUNCTION: AcpiPsFreeOp 246 * 247 * PARAMETERS: Op - Op to be freed 248 * 249 * RETURN: None. 250 * 251 * DESCRIPTION: Free an Op object. Either put it on the GENERIC_OP cache list 252 * or actually free it. 253 * 254 ******************************************************************************/ 255 256void 257AcpiPsFreeOp ( 258 ACPI_PARSE_OBJECT *Op) 259{ 260 PROC_NAME ("PsFreeOp"); 261 262 263 if (Op->Opcode == AML_INT_RETURN_VALUE_OP) 264 { 265 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Free retval op: %p\n", Op)); 266 } 267 268 if (Op->Flags == PARSEOP_GENERIC) 269 { 270 AcpiUtReleaseToCache (ACPI_MEM_LIST_PSNODE, Op); 271 } 272 273 else 274 { 275 AcpiUtReleaseToCache (ACPI_MEM_LIST_PSNODE_EXT, Op); 276 } 277} 278 279 280/******************************************************************************* 281 * 282 * FUNCTION: AcpiPsDeleteParseCache 283 * 284 * PARAMETERS: None 285 * 286 * RETURN: None 287 * 288 * DESCRIPTION: Free all objects that are on the parse cache list. 289 * 290 ******************************************************************************/ 291 292void 293AcpiPsDeleteParseCache ( 294 void) 295{ 296 FUNCTION_TRACE ("PsDeleteParseCache"); 297 298 299 AcpiUtDeleteGenericCache (ACPI_MEM_LIST_PSNODE); 300 AcpiUtDeleteGenericCache (ACPI_MEM_LIST_PSNODE_EXT); 301 return_VOID; 302} 303 304 305/******************************************************************************* 306 * 307 * FUNCTION: Utility functions 308 * 309 * DESCRIPTION: Low level functions 310 * 311 * TBD: [Restructure] 312 * 1) Some of these functions should be macros 313 * 2) Some can be simplified 314 * 315 ******************************************************************************/ 316 317 318/* 319 * Is "c" a namestring lead character? 320 */ 321 322 323BOOLEAN 324AcpiPsIsLeadingChar ( 325 UINT32 c) 326{ 327 return ((BOOLEAN) (c == '_' || (c >= 'A' && c <= 'Z'))); 328} 329 330 331/* 332 * Is "c" a namestring prefix character? 333 */ 334BOOLEAN 335AcpiPsIsPrefixChar ( 336 UINT32 c) 337{ 338 return ((BOOLEAN) (c == '\\' || c == '^')); 339} 340 341 342BOOLEAN 343AcpiPsIsNamespaceObjectOp ( 344 UINT16 Opcode) 345{ 346 return ((BOOLEAN) 347 (Opcode == AML_SCOPE_OP || 348 Opcode == AML_DEVICE_OP || 349 Opcode == AML_THERMAL_ZONE_OP || 350 Opcode == AML_METHOD_OP || 351 Opcode == AML_POWER_RES_OP || 352 Opcode == AML_PROCESSOR_OP || 353 Opcode == AML_FIELD_OP || 354 Opcode == AML_INDEX_FIELD_OP || 355 Opcode == AML_BANK_FIELD_OP || 356 Opcode == AML_INT_NAMEDFIELD_OP || 357 Opcode == AML_NAME_OP || 358 Opcode == AML_ALIAS_OP || 359 Opcode == AML_MUTEX_OP || 360 Opcode == AML_EVENT_OP || 361 Opcode == AML_REGION_OP || 362 Opcode == AML_CREATE_FIELD_OP || 363 Opcode == AML_CREATE_BIT_FIELD_OP || 364 Opcode == AML_CREATE_BYTE_FIELD_OP || 365 Opcode == AML_CREATE_WORD_FIELD_OP || 366 Opcode == AML_CREATE_DWORD_FIELD_OP || 367 Opcode == AML_CREATE_QWORD_FIELD_OP || 368 Opcode == AML_INT_METHODCALL_OP || 369 Opcode == AML_INT_NAMEPATH_OP)); 370} 371 372BOOLEAN 373AcpiPsIsNamespaceOp ( 374 UINT16 Opcode) 375{ 376 return ((BOOLEAN) 377 (Opcode == AML_SCOPE_OP || 378 Opcode == AML_DEVICE_OP || 379 Opcode == AML_THERMAL_ZONE_OP || 380 Opcode == AML_METHOD_OP || 381 Opcode == AML_POWER_RES_OP || 382 Opcode == AML_PROCESSOR_OP || 383 Opcode == AML_FIELD_OP || 384 Opcode == AML_INDEX_FIELD_OP || 385 Opcode == AML_BANK_FIELD_OP || 386 Opcode == AML_NAME_OP || 387 Opcode == AML_ALIAS_OP || 388 Opcode == AML_MUTEX_OP || 389 Opcode == AML_EVENT_OP || 390 Opcode == AML_REGION_OP || 391 Opcode == AML_INT_NAMEDFIELD_OP)); 392} 393 394 395/* 396 * Is opcode for a named object Op? 397 * (Includes all named object opcodes) 398 * 399 * TBD: [Restructure] Need a better way than this brute force approach! 400 */ 401BOOLEAN 402AcpiPsIsNodeOp ( 403 UINT16 Opcode) 404{ 405 return ((BOOLEAN) 406 (Opcode == AML_SCOPE_OP || 407 Opcode == AML_DEVICE_OP || 408 Opcode == AML_THERMAL_ZONE_OP || 409 Opcode == AML_METHOD_OP || 410 Opcode == AML_POWER_RES_OP || 411 Opcode == AML_PROCESSOR_OP || 412 Opcode == AML_INT_NAMEDFIELD_OP || 413 Opcode == AML_NAME_OP || 414 Opcode == AML_ALIAS_OP || 415 Opcode == AML_MUTEX_OP || 416 Opcode == AML_EVENT_OP || 417 Opcode == AML_REGION_OP || 418 419 420 Opcode == AML_CREATE_FIELD_OP || 421 Opcode == AML_CREATE_BIT_FIELD_OP || 422 Opcode == AML_CREATE_BYTE_FIELD_OP || 423 Opcode == AML_CREATE_WORD_FIELD_OP || 424 Opcode == AML_CREATE_DWORD_FIELD_OP || 425 Opcode == AML_CREATE_QWORD_FIELD_OP || 426 Opcode == AML_INT_METHODCALL_OP || 427 Opcode == AML_INT_NAMEPATH_OP)); 428} 429 430 431/* 432 * Is opcode for a named Op? 433 */ 434BOOLEAN 435AcpiPsIsNamedOp ( 436 UINT16 Opcode) 437{ 438 return ((BOOLEAN) 439 (Opcode == AML_SCOPE_OP || 440 Opcode == AML_DEVICE_OP || 441 Opcode == AML_THERMAL_ZONE_OP || 442 Opcode == AML_METHOD_OP || 443 Opcode == AML_POWER_RES_OP || 444 Opcode == AML_PROCESSOR_OP || 445 Opcode == AML_NAME_OP || 446 Opcode == AML_ALIAS_OP || 447 Opcode == AML_MUTEX_OP || 448 Opcode == AML_EVENT_OP || 449 Opcode == AML_REGION_OP || 450 Opcode == AML_INT_NAMEDFIELD_OP)); 451} 452 453 454BOOLEAN 455AcpiPsIsDeferredOp ( 456 UINT16 Opcode) 457{ 458 return ((BOOLEAN) 459 (Opcode == AML_METHOD_OP || 460 Opcode == AML_VAR_PACKAGE_OP || 461 Opcode == AML_CREATE_FIELD_OP || 462 Opcode == AML_CREATE_BIT_FIELD_OP || 463 Opcode == AML_CREATE_BYTE_FIELD_OP || 464 Opcode == AML_CREATE_WORD_FIELD_OP || 465 Opcode == AML_CREATE_DWORD_FIELD_OP || 466 Opcode == AML_CREATE_QWORD_FIELD_OP || 467 Opcode == AML_REGION_OP)); 468} 469 470 471/* 472 * Is opcode for a bytelist? 473 */ 474BOOLEAN 475AcpiPsIsBytelistOp ( 476 UINT16 Opcode) 477{ 478 return ((BOOLEAN) (Opcode == AML_INT_BYTELIST_OP)); 479} 480 481 482/* 483 * Is opcode for a Field, IndexField, or BankField 484 */ 485BOOLEAN 486AcpiPsIsFieldOp ( 487 UINT16 Opcode) 488{ 489 return ((BOOLEAN) 490 (Opcode == AML_CREATE_FIELD_OP 491 || Opcode == AML_FIELD_OP 492 || Opcode == AML_INDEX_FIELD_OP 493 || Opcode == AML_BANK_FIELD_OP)); 494} 495 496 497/* 498 * Is field creation op 499 */ 500BOOLEAN 501AcpiPsIsCreateFieldOp ( 502 UINT16 Opcode) 503{ 504 return ((BOOLEAN) 505 (Opcode == AML_CREATE_FIELD_OP || 506 Opcode == AML_CREATE_BIT_FIELD_OP || 507 Opcode == AML_CREATE_BYTE_FIELD_OP || 508 Opcode == AML_CREATE_WORD_FIELD_OP || 509 Opcode == AML_CREATE_DWORD_FIELD_OP || 510 Opcode == AML_CREATE_QWORD_FIELD_OP)); 511} 512 513 514/* 515 * Cast an acpi_op to an acpi_extended_op if possible 516 */ 517 518/* TBD: This is very inefficient, fix */ 519ACPI_PARSE2_OBJECT * 520AcpiPsToExtendedOp ( 521 ACPI_PARSE_OBJECT *Op) 522{ 523 return ((AcpiPsIsDeferredOp (Op->Opcode) || AcpiPsIsNamedOp (Op->Opcode) || AcpiPsIsBytelistOp (Op->Opcode)) 524 ? ( (ACPI_PARSE2_OBJECT *) Op) : NULL); 525} 526 527 528/* 529 * Get op's name (4-byte name segment) or 0 if unnamed 530 */ 531UINT32 532AcpiPsGetName ( 533 ACPI_PARSE_OBJECT *Op) 534{ 535 ACPI_PARSE2_OBJECT *Named = AcpiPsToExtendedOp (Op); 536 537 return (Named ? Named->Name : 0); 538} 539 540 541/* 542 * Set op's name 543 */ 544void 545AcpiPsSetName ( 546 ACPI_PARSE_OBJECT *Op, 547 UINT32 name) 548{ 549 ACPI_PARSE2_OBJECT *Named = AcpiPsToExtendedOp (Op); 550 551 if (Named) 552 { 553 Named->Name = name; 554 } 555} 556 557