aslpredef.c revision 206117
1204766Sjkim/****************************************************************************** 2204766Sjkim * 3204766Sjkim * Module Name: aslpredef - support for ACPI predefined names 4204766Sjkim * 5204766Sjkim *****************************************************************************/ 6204766Sjkim 7204766Sjkim/****************************************************************************** 8204766Sjkim * 9204766Sjkim * 1. Copyright Notice 10204766Sjkim * 11204766Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 12204766Sjkim * All rights reserved. 13204766Sjkim * 14204766Sjkim * 2. License 15204766Sjkim * 16204766Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17204766Sjkim * rights. You may have additional license terms from the party that provided 18204766Sjkim * you this software, covering your right to use that party's intellectual 19204766Sjkim * property rights. 20204766Sjkim * 21204766Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22204766Sjkim * copy of the source code appearing in this file ("Covered Code") an 23204766Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24204766Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25204766Sjkim * make derivatives, distribute, use and display any portion of the Covered 26204766Sjkim * Code in any form, with the right to sublicense such rights; and 27204766Sjkim * 28204766Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29204766Sjkim * license (with the right to sublicense), under only those claims of Intel 30204766Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31204766Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32204766Sjkim * solely to the minimum extent necessary to exercise the above copyright 33204766Sjkim * license, and in no event shall the patent license extend to any additions 34204766Sjkim * to or modifications of the Original Intel Code. No other license or right 35204766Sjkim * is granted directly or by implication, estoppel or otherwise; 36204766Sjkim * 37204766Sjkim * The above copyright and patent license is granted only if the following 38204766Sjkim * conditions are met: 39204766Sjkim * 40204766Sjkim * 3. Conditions 41204766Sjkim * 42204766Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43204766Sjkim * Redistribution of source code of any substantial portion of the Covered 44204766Sjkim * Code or modification with rights to further distribute source must include 45204766Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46204766Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47204766Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48204766Sjkim * contain a file documenting the changes Licensee made to create that Covered 49204766Sjkim * Code and the date of any change. Licensee must include in that file the 50204766Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51204766Sjkim * must include a prominent statement that the modification is derived, 52204766Sjkim * directly or indirectly, from Original Intel Code. 53204766Sjkim * 54204766Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55204766Sjkim * Redistribution of source code of any substantial portion of the Covered 56204766Sjkim * Code or modification without rights to further distribute source must 57204766Sjkim * include the following Disclaimer and Export Compliance provision in the 58204766Sjkim * documentation and/or other materials provided with distribution. In 59204766Sjkim * addition, Licensee may not authorize further sublicense of source of any 60204766Sjkim * portion of the Covered Code, and must include terms to the effect that the 61204766Sjkim * license from Licensee to its licensee is limited to the intellectual 62204766Sjkim * property embodied in the software Licensee provides to its licensee, and 63204766Sjkim * not to intellectual property embodied in modifications its licensee may 64204766Sjkim * make. 65204766Sjkim * 66204766Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67204766Sjkim * substantial portion of the Covered Code or modification must reproduce the 68204766Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69204766Sjkim * provision in the documentation and/or other materials provided with the 70204766Sjkim * distribution. 71204766Sjkim * 72204766Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73204766Sjkim * Intel Code. 74204766Sjkim * 75204766Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76204766Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77204766Sjkim * other dealings in products derived from or relating to the Covered Code 78204766Sjkim * without prior written authorization from Intel. 79204766Sjkim * 80204766Sjkim * 4. Disclaimer and Export Compliance 81204766Sjkim * 82204766Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83204766Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84204766Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85204766Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86204766Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87204766Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88204766Sjkim * PARTICULAR PURPOSE. 89204766Sjkim * 90204766Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91204766Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92204766Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93204766Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94204766Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95204766Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96204766Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97204766Sjkim * LIMITED REMEDY. 98204766Sjkim * 99204766Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100204766Sjkim * software or system incorporating such software without first obtaining any 101204766Sjkim * required license or other approval from the U. S. Department of Commerce or 102204766Sjkim * any other agency or department of the United States Government. In the 103204766Sjkim * event Licensee exports any such software from the United States or 104204766Sjkim * re-exports any such software from a foreign destination, Licensee shall 105204766Sjkim * ensure that the distribution and export/re-export of the software is in 106204766Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107204766Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108204766Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109204766Sjkim * software, or service, directly or indirectly, to any country for which the 110204766Sjkim * United States government or any agency thereof requires an export license, 111204766Sjkim * other governmental approval, or letter of assurance, without first obtaining 112204766Sjkim * such license, approval or letter. 113204766Sjkim * 114204766Sjkim *****************************************************************************/ 115204766Sjkim 116204766Sjkim#define ACPI_CREATE_PREDEFINED_TABLE 117204766Sjkim 118204773Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 119204766Sjkim#include "aslcompiler.y.h" 120204773Sjkim#include <contrib/dev/acpica/include/amlcode.h> 121204773Sjkim#include <contrib/dev/acpica/include/acparser.h> 122204773Sjkim#include <contrib/dev/acpica/include/acpredef.h> 123204766Sjkim 124204766Sjkim 125204766Sjkim#define _COMPONENT ACPI_COMPILER 126204766Sjkim ACPI_MODULE_NAME ("aslpredef") 127204766Sjkim 128204766Sjkim 129204766Sjkim/* Local prototypes */ 130204766Sjkim 131204766Sjkimstatic UINT32 132204766SjkimApCheckForSpecialName ( 133204766Sjkim ACPI_PARSE_OBJECT *Op, 134204766Sjkim char *Name); 135204766Sjkim 136204766Sjkimstatic void 137204766SjkimApCheckObjectType ( 138204766Sjkim ACPI_PARSE_OBJECT *Op, 139204766Sjkim UINT32 ExpectedBtypes); 140204766Sjkim 141204766Sjkimstatic void 142204766SjkimApGetExpectedTypes ( 143204766Sjkim char *Buffer, 144204766Sjkim UINT32 ExpectedBtypes); 145204766Sjkim 146204766Sjkim 147204766Sjkim/* 148204766Sjkim * Names for the types that can be returned by the predefined objects. 149204766Sjkim * Used for warning messages. Must be in the same order as the ACPI_RTYPEs 150204766Sjkim */ 151204766Sjkimstatic const char *AcpiRtypeNames[] = 152204766Sjkim{ 153204766Sjkim "/Integer", 154204766Sjkim "/String", 155204766Sjkim "/Buffer", 156204766Sjkim "/Package", 157204766Sjkim "/Reference", 158204766Sjkim}; 159204766Sjkim 160204766Sjkim/* 161204766Sjkim * Predefined names for use in Resource Descriptors. These names do not 162204766Sjkim * appear in the global Predefined Name table (since these names never 163204766Sjkim * appear in actual AML byte code, only in the original ASL) 164204766Sjkim */ 165204766Sjkimstatic const ACPI_PREDEFINED_INFO ResourceNames[] = { 166204766Sjkim {{"_ALN", 0, 0}}, 167204766Sjkim {{"_ASI", 0, 0}}, 168204766Sjkim {{"_ASZ", 0, 0}}, 169204766Sjkim {{"_ATT", 0, 0}}, 170204766Sjkim {{"_BAS", 0, 0}}, 171204766Sjkim {{"_BM_", 0, 0}}, 172204766Sjkim {{"_DEC", 0, 0}}, 173204766Sjkim {{"_GRA", 0, 0}}, 174204766Sjkim {{"_HE_", 0, 0}}, 175204766Sjkim {{"_INT", 0, 0}}, 176204766Sjkim {{"_LEN", 0, 0}}, 177204766Sjkim {{"_LL_", 0, 0}}, 178204766Sjkim {{"_MAF", 0, 0}}, 179204766Sjkim {{"_MAX", 0, 0}}, 180204766Sjkim {{"_MEM", 0, 0}}, 181204766Sjkim {{"_MIF", 0, 0}}, 182204766Sjkim {{"_MIN", 0, 0}}, 183204766Sjkim {{"_MTP", 0, 0}}, 184204766Sjkim {{"_RBO", 0, 0}}, 185204766Sjkim {{"_RBW", 0, 0}}, 186204766Sjkim {{"_RNG", 0, 0}}, 187204766Sjkim {{"_RT_", 0, 0}}, /* Acpi 3.0 */ 188204766Sjkim {{"_RW_", 0, 0}}, 189204766Sjkim {{"_SHR", 0, 0}}, 190204766Sjkim {{"_SIZ", 0, 0}}, 191204766Sjkim {{"_TRA", 0, 0}}, 192204766Sjkim {{"_TRS", 0, 0}}, 193204766Sjkim {{"_TSF", 0, 0}}, /* Acpi 3.0 */ 194204766Sjkim {{"_TTP", 0, 0}}, 195204766Sjkim {{"_TYP", 0, 0}}, 196204766Sjkim {{{0,0,0,0}, 0, 0}} /* Table terminator */ 197204766Sjkim}; 198204766Sjkim 199204766Sjkimstatic const ACPI_PREDEFINED_INFO ScopeNames[] = { 200204766Sjkim {{"_SB_", 0, 0}}, 201204766Sjkim {{"_SI_", 0, 0}}, 202204766Sjkim {{"_TZ_", 0, 0}}, 203204766Sjkim {{{0,0,0,0}, 0, 0}} /* Table terminator */ 204204766Sjkim}; 205204766Sjkim 206204766Sjkim 207204766Sjkim/******************************************************************************* 208204766Sjkim * 209204766Sjkim * FUNCTION: ApCheckForPredefinedMethod 210204766Sjkim * 211204766Sjkim * PARAMETERS: Op - A parse node of type "METHOD". 212204766Sjkim * MethodInfo - Saved info about this method 213204766Sjkim * 214204766Sjkim * RETURN: None 215204766Sjkim * 216204766Sjkim * DESCRIPTION: If method is a predefined name, check that the number of 217204766Sjkim * arguments and the return type (returns a value or not) 218204766Sjkim * is correct. 219204766Sjkim * 220204766Sjkim ******************************************************************************/ 221204766Sjkim 222204766Sjkimvoid 223204766SjkimApCheckForPredefinedMethod ( 224204766Sjkim ACPI_PARSE_OBJECT *Op, 225204766Sjkim ASL_METHOD_INFO *MethodInfo) 226204766Sjkim{ 227204766Sjkim UINT32 Index; 228204766Sjkim UINT32 RequiredArgsCurrent; 229204766Sjkim UINT32 RequiredArgsOld; 230204766Sjkim 231204766Sjkim 232204766Sjkim /* Check for a match against the predefined name list */ 233204766Sjkim 234204766Sjkim Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg); 235204766Sjkim 236204766Sjkim switch (Index) 237204766Sjkim { 238204766Sjkim case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */ 239204766Sjkim case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */ 240204766Sjkim case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */ 241204766Sjkim 242204766Sjkim /* Just return, nothing to do */ 243204766Sjkim break; 244204766Sjkim 245204766Sjkim 246204766Sjkim case ACPI_EVENT_RESERVED_NAME: /* _Lxx, _Exx, and _Qxx methods */ 247204766Sjkim 248204766Sjkim Gbl_ReservedMethods++; 249204766Sjkim 250204766Sjkim /* NumArguments must be zero for all _Lxx, _Exx, and _Qxx methods */ 251204766Sjkim 252204766Sjkim if (MethodInfo->NumArguments != 0) 253204766Sjkim { 254204766Sjkim sprintf (MsgBuffer, "%s requires %d", Op->Asl.ExternalName, 0); 255204766Sjkim 256204766Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op, 257204766Sjkim MsgBuffer); 258204766Sjkim } 259204766Sjkim break; 260204766Sjkim 261204766Sjkim 262204766Sjkim default: 263204766Sjkim /* 264204766Sjkim * Matched a predefined method name 265204766Sjkim * 266204766Sjkim * Validate the ASL-defined argument count. Allow two different legal 267204766Sjkim * arg counts. 268204766Sjkim */ 269204766Sjkim Gbl_ReservedMethods++; 270204766Sjkim 271204766Sjkim RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F; 272204766Sjkim RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4; 273204766Sjkim 274204766Sjkim if ((MethodInfo->NumArguments != RequiredArgsCurrent) && 275204766Sjkim (MethodInfo->NumArguments != RequiredArgsOld)) 276204766Sjkim { 277204766Sjkim sprintf (MsgBuffer, "%4.4s requires %d", 278204766Sjkim PredefinedNames[Index].Info.Name, RequiredArgsCurrent); 279204766Sjkim 280204766Sjkim if (MethodInfo->NumArguments > RequiredArgsCurrent) 281204766Sjkim { 282204766Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op, 283204766Sjkim MsgBuffer); 284204766Sjkim } 285204766Sjkim else 286204766Sjkim { 287204766Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op, 288204766Sjkim MsgBuffer); 289204766Sjkim } 290204766Sjkim } 291204766Sjkim 292204766Sjkim /* 293204766Sjkim * Check if method returns no value, but the predefined name is 294204766Sjkim * required to return a value 295204766Sjkim */ 296204766Sjkim if (MethodInfo->NumReturnNoValue && 297204766Sjkim PredefinedNames[Index].Info.ExpectedBtypes) 298204766Sjkim { 299206117Sjkim ApGetExpectedTypes (StringBuffer, 300206117Sjkim PredefinedNames[Index].Info.ExpectedBtypes); 301204766Sjkim 302206117Sjkim sprintf (MsgBuffer, "%s required for %4.4s", 303206117Sjkim StringBuffer, PredefinedNames[Index].Info.Name); 304206117Sjkim 305204766Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op, 306204766Sjkim MsgBuffer); 307204766Sjkim } 308204766Sjkim break; 309204766Sjkim } 310204766Sjkim} 311204766Sjkim 312204766Sjkim 313204766Sjkim/******************************************************************************* 314204766Sjkim * 315206117Sjkim * FUNCTION: ApCheckPredefinedReturnValue 316206117Sjkim * 317206117Sjkim * PARAMETERS: Op - A parse node of type "RETURN". 318206117Sjkim * MethodInfo - Saved info about this method 319206117Sjkim * 320206117Sjkim * RETURN: None 321206117Sjkim * 322206117Sjkim * DESCRIPTION: If method is a predefined name, attempt to validate the return 323206117Sjkim * value. Only "static" types can be validated - a simple return 324206117Sjkim * of an integer/string/buffer/package or a named reference to 325206117Sjkim * a static object. Values such as a Localx or Argx or a control 326206117Sjkim * method invocation are not checked. 327206117Sjkim * 328206117Sjkim ******************************************************************************/ 329206117Sjkim 330206117Sjkimvoid 331206117SjkimApCheckPredefinedReturnValue ( 332206117Sjkim ACPI_PARSE_OBJECT *Op, 333206117Sjkim ASL_METHOD_INFO *MethodInfo) 334206117Sjkim{ 335206117Sjkim UINT32 Index; 336206117Sjkim ACPI_PARSE_OBJECT *ReturnValueOp; 337206117Sjkim 338206117Sjkim 339206117Sjkim /* Check parent method for a match against the predefined name list */ 340206117Sjkim 341206117Sjkim Index = ApCheckForPredefinedName (MethodInfo->Op, 342206117Sjkim MethodInfo->Op->Asl.NameSeg); 343206117Sjkim 344206117Sjkim switch (Index) 345206117Sjkim { 346206117Sjkim case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */ 347206117Sjkim case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */ 348206117Sjkim case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */ 349206117Sjkim case ACPI_EVENT_RESERVED_NAME: /* _Lxx, _Exx, and _Qxx methods */ 350206117Sjkim 351206117Sjkim /* Just return, nothing to do */ 352206117Sjkim return; 353206117Sjkim 354206117Sjkim default: /* a real predefined ACPI name */ 355206117Sjkim 356206117Sjkim /* Exit if no return value expected */ 357206117Sjkim 358206117Sjkim if (!PredefinedNames[Index].Info.ExpectedBtypes) 359206117Sjkim { 360206117Sjkim return; 361206117Sjkim } 362206117Sjkim 363206117Sjkim /* Get the object returned, it is the next argument */ 364206117Sjkim 365206117Sjkim ReturnValueOp = Op->Asl.Child; 366206117Sjkim switch (ReturnValueOp->Asl.ParseOpcode) 367206117Sjkim { 368206117Sjkim case PARSEOP_ZERO: 369206117Sjkim case PARSEOP_ONE: 370206117Sjkim case PARSEOP_ONES: 371206117Sjkim case PARSEOP_INTEGER: 372206117Sjkim case PARSEOP_STRING_LITERAL: 373206117Sjkim case PARSEOP_BUFFER: 374206117Sjkim case PARSEOP_PACKAGE: 375206117Sjkim 376206117Sjkim /* Static data return object - check against expected type */ 377206117Sjkim 378206117Sjkim ApCheckObjectType (ReturnValueOp, 379206117Sjkim PredefinedNames[Index].Info.ExpectedBtypes); 380206117Sjkim break; 381206117Sjkim 382206117Sjkim default: 383206117Sjkim 384206117Sjkim /* 385206117Sjkim * All other ops are very difficult or impossible to typecheck at 386206117Sjkim * compile time. These include all Localx, Argx, and method 387206117Sjkim * invocations. Also, NAMESEG and NAMESTRING because the type of 388206117Sjkim * any named object can be changed at runtime (for example, 389206117Sjkim * CopyObject will change the type of the target object.) 390206117Sjkim */ 391206117Sjkim break; 392206117Sjkim } 393206117Sjkim } 394206117Sjkim} 395206117Sjkim 396206117Sjkim 397206117Sjkim/******************************************************************************* 398206117Sjkim * 399204766Sjkim * FUNCTION: ApCheckForPredefinedObject 400204766Sjkim * 401204766Sjkim * PARAMETERS: Op - A parse node 402204766Sjkim * Name - The ACPI name to be checked 403204766Sjkim * 404204766Sjkim * RETURN: None 405204766Sjkim * 406204766Sjkim * DESCRIPTION: Check for a predefined name for a static object (created via 407204766Sjkim * the ASL Name operator). If it is a predefined ACPI name, ensure 408204766Sjkim * that the name does not require any arguments (which would 409204766Sjkim * require a control method implemenation of the name), and that 410204766Sjkim * the type of the object is one of the expected types for the 411204766Sjkim * predefined name. 412204766Sjkim * 413204766Sjkim ******************************************************************************/ 414204766Sjkim 415204766Sjkimvoid 416204766SjkimApCheckForPredefinedObject ( 417204766Sjkim ACPI_PARSE_OBJECT *Op, 418204766Sjkim char *Name) 419204766Sjkim{ 420204766Sjkim UINT32 Index; 421204766Sjkim 422204766Sjkim 423204766Sjkim /* 424204766Sjkim * Check for a real predefined name -- not a resource descriptor name 425204766Sjkim * or a predefined scope name 426204766Sjkim */ 427204766Sjkim Index = ApCheckForPredefinedName (Op, Name); 428204766Sjkim if (Index > ACPI_VALID_RESERVED_NAME_MAX) 429204766Sjkim { 430204766Sjkim return; 431204766Sjkim } 432204766Sjkim 433204766Sjkim /* 434204766Sjkim * We found a matching predefind name. 435204766Sjkim * Check if this predefined name requires input arguments 436204766Sjkim */ 437204766Sjkim if (PredefinedNames[Index].Info.ParamCount > 0) 438204766Sjkim { 439204766Sjkim /* 440204766Sjkim * This predefined name must always be defined as a control 441204766Sjkim * method because it is required to have input arguments. 442204766Sjkim */ 443204766Sjkim AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op, 444204766Sjkim "with arguments"); 445204766Sjkim } 446204766Sjkim 447204766Sjkim /* Typecheck the actual object, it is the next argument */ 448204766Sjkim 449204766Sjkim ApCheckObjectType (Op->Asl.Child->Asl.Next, 450204766Sjkim PredefinedNames[Index].Info.ExpectedBtypes); 451204766Sjkim} 452204766Sjkim 453204766Sjkim 454204766Sjkim/******************************************************************************* 455204766Sjkim * 456204766Sjkim * FUNCTION: ApCheckForPredefinedName 457204766Sjkim * 458204766Sjkim * PARAMETERS: Op - A parse node 459204766Sjkim * Name - NameSeg to check 460204766Sjkim * 461204766Sjkim * RETURN: None 462204766Sjkim * 463204766Sjkim * DESCRIPTION: Check a NameSeg against the reserved list. 464204766Sjkim * 465204766Sjkim ******************************************************************************/ 466204766Sjkim 467204766SjkimUINT32 468204766SjkimApCheckForPredefinedName ( 469204766Sjkim ACPI_PARSE_OBJECT *Op, 470204766Sjkim char *Name) 471204766Sjkim{ 472204766Sjkim UINT32 i; 473204766Sjkim 474204766Sjkim 475204766Sjkim if (Name[0] == 0) 476204766Sjkim { 477204766Sjkim AcpiOsPrintf ("Found a null name, external = %s\n", 478204766Sjkim Op->Asl.ExternalName); 479204766Sjkim } 480204766Sjkim 481204766Sjkim /* All reserved names are prefixed with a single underscore */ 482204766Sjkim 483204766Sjkim if (Name[0] != '_') 484204766Sjkim { 485204766Sjkim return (ACPI_NOT_RESERVED_NAME); 486204766Sjkim } 487204766Sjkim 488204766Sjkim /* Check for a standard predefined method name */ 489204766Sjkim 490204766Sjkim for (i = 0; PredefinedNames[i].Info.Name[0]; i++) 491204766Sjkim { 492204766Sjkim if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name)) 493204766Sjkim { 494204766Sjkim /* Return index into predefined array */ 495204766Sjkim return (i); 496204766Sjkim } 497204766Sjkim } 498204766Sjkim 499204766Sjkim /* Check for resource names and predefined scope names */ 500204766Sjkim 501204766Sjkim for (i = 0; ResourceNames[i].Info.Name[0]; i++) 502204766Sjkim { 503204766Sjkim if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name)) 504204766Sjkim { 505204766Sjkim return (ACPI_PREDEFINED_NAME); 506204766Sjkim } 507204766Sjkim } 508204766Sjkim 509204766Sjkim for (i = 0; ScopeNames[i].Info.Name[0]; i++) 510204766Sjkim { 511204766Sjkim if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name)) 512204766Sjkim { 513204766Sjkim return (ACPI_PREDEFINED_NAME); 514204766Sjkim } 515204766Sjkim } 516204766Sjkim 517204766Sjkim /* Check for _Lxx, _Exx, _Qxx, _T_x. Warning if unknown predefined name */ 518204766Sjkim 519204766Sjkim return (ApCheckForSpecialName (Op, Name)); 520204766Sjkim} 521204766Sjkim 522204766Sjkim 523204766Sjkim/******************************************************************************* 524204766Sjkim * 525204766Sjkim * FUNCTION: ApCheckForSpecialName 526204766Sjkim * 527204766Sjkim * PARAMETERS: Op - A parse node 528204766Sjkim * Name - NameSeg to check 529204766Sjkim * 530204766Sjkim * RETURN: None 531204766Sjkim * 532206117Sjkim * DESCRIPTION: Check for the "special" predefined names - 533204766Sjkim * _Lxx, _Exx, _Qxx, and _T_x 534204766Sjkim * 535204766Sjkim ******************************************************************************/ 536204766Sjkim 537204766Sjkimstatic UINT32 538204766SjkimApCheckForSpecialName ( 539204766Sjkim ACPI_PARSE_OBJECT *Op, 540204766Sjkim char *Name) 541204766Sjkim{ 542204766Sjkim 543204766Sjkim /* 544204766Sjkim * Check for the "special" predefined names. We know the first char is an 545204766Sjkim * underscore already. 546204766Sjkim * GPE: _Lxx 547204766Sjkim * GPE: _Exx 548204766Sjkim * EC: _Qxx 549204766Sjkim */ 550204766Sjkim if ((Name[1] == 'L') || 551204766Sjkim (Name[1] == 'E') || 552204766Sjkim (Name[1] == 'Q')) 553204766Sjkim { 554204766Sjkim /* The next two characters must be hex digits */ 555204766Sjkim 556204766Sjkim if ((isxdigit ((int) Name[2])) && 557204766Sjkim (isxdigit ((int) Name[3]))) 558204766Sjkim { 559204766Sjkim return (ACPI_EVENT_RESERVED_NAME); 560204766Sjkim } 561204766Sjkim } 562204766Sjkim 563204766Sjkim /* Check for the names reserved for the compiler itself: _T_x */ 564204766Sjkim 565204766Sjkim else if ((Op->Asl.ExternalName[1] == 'T') && 566204766Sjkim (Op->Asl.ExternalName[2] == '_')) 567204766Sjkim { 568204766Sjkim /* Ignore if actually emitted by the compiler */ 569204766Sjkim 570204766Sjkim if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED) 571204766Sjkim { 572204766Sjkim return (ACPI_NOT_RESERVED_NAME); 573204766Sjkim } 574204766Sjkim 575204766Sjkim /* 576204766Sjkim * Was not actually emitted by the compiler. This is a special case, 577204766Sjkim * however. If the ASL code being compiled was the result of a 578204766Sjkim * dissasembly, it may possibly contain valid compiler-emitted names 579204766Sjkim * of the form "_T_x". We don't want to issue an error or even a 580204766Sjkim * warning and force the user to manually change the names. So, we 581204766Sjkim * will issue a remark instead. 582204766Sjkim */ 583204766Sjkim AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName); 584204766Sjkim return (ACPI_COMPILER_RESERVED_NAME); 585204766Sjkim } 586204766Sjkim 587204766Sjkim /* 588204766Sjkim * The name didn't match any of the known predefined names. Flag it as a 589204766Sjkim * warning, since the entire namespace starting with an underscore is 590204766Sjkim * reserved by the ACPI spec. 591204766Sjkim */ 592204766Sjkim AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op, 593204766Sjkim Op->Asl.ExternalName); 594204766Sjkim 595204766Sjkim return (ACPI_NOT_RESERVED_NAME); 596204766Sjkim} 597204766Sjkim 598204766Sjkim 599204766Sjkim/******************************************************************************* 600204766Sjkim * 601204766Sjkim * FUNCTION: ApCheckObjectType 602204766Sjkim * 603206117Sjkim * PARAMETERS: Op - Current parse node 604204766Sjkim * ExpectedBtypes - Bitmap of expected return type(s) 605204766Sjkim * 606204766Sjkim * RETURN: None 607204766Sjkim * 608204766Sjkim * DESCRIPTION: Check if the object type is one of the types that is expected 609204766Sjkim * by the predefined name. Only a limited number of object types 610204766Sjkim * can be returned by the predefined names. 611204766Sjkim * 612204766Sjkim ******************************************************************************/ 613204766Sjkim 614204766Sjkimstatic void 615204766SjkimApCheckObjectType ( 616204766Sjkim ACPI_PARSE_OBJECT *Op, 617204766Sjkim UINT32 ExpectedBtypes) 618204766Sjkim{ 619204766Sjkim UINT32 ReturnBtype; 620204766Sjkim 621204766Sjkim 622204766Sjkim switch (Op->Asl.ParseOpcode) 623204766Sjkim { 624206117Sjkim case PARSEOP_ZERO: 625206117Sjkim case PARSEOP_ONE: 626206117Sjkim case PARSEOP_ONES: 627204766Sjkim case PARSEOP_INTEGER: 628204766Sjkim ReturnBtype = ACPI_RTYPE_INTEGER; 629204766Sjkim break; 630204766Sjkim 631204766Sjkim case PARSEOP_BUFFER: 632204766Sjkim ReturnBtype = ACPI_RTYPE_BUFFER; 633204766Sjkim break; 634204766Sjkim 635204766Sjkim case PARSEOP_STRING_LITERAL: 636204766Sjkim ReturnBtype = ACPI_RTYPE_STRING; 637204766Sjkim break; 638204766Sjkim 639204766Sjkim case PARSEOP_PACKAGE: 640204766Sjkim ReturnBtype = ACPI_RTYPE_PACKAGE; 641204766Sjkim break; 642204766Sjkim 643204766Sjkim default: 644204766Sjkim /* Not one of the supported object types */ 645206117Sjkim 646204766Sjkim goto TypeErrorExit; 647204766Sjkim } 648204766Sjkim 649206117Sjkim /* Exit if the object is one of the expected types */ 650204766Sjkim 651204766Sjkim if (ReturnBtype & ExpectedBtypes) 652204766Sjkim { 653204766Sjkim return; 654204766Sjkim } 655204766Sjkim 656204766Sjkim 657204766SjkimTypeErrorExit: 658204766Sjkim 659204766Sjkim /* Format the expected types and emit an error message */ 660204766Sjkim 661206117Sjkim ApGetExpectedTypes (StringBuffer, ExpectedBtypes); 662204766Sjkim 663206117Sjkim sprintf (MsgBuffer, "found %s, requires %s", 664206117Sjkim UtGetOpName (Op->Asl.ParseOpcode), StringBuffer); 665206117Sjkim 666204766Sjkim AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, 667206117Sjkim MsgBuffer); 668204766Sjkim} 669204766Sjkim 670204766Sjkim 671204766Sjkim/******************************************************************************* 672204766Sjkim * 673204766Sjkim * FUNCTION: ApDisplayReservedNames 674204766Sjkim * 675204766Sjkim * PARAMETERS: None 676204766Sjkim * 677204766Sjkim * RETURN: None 678204766Sjkim * 679204766Sjkim * DESCRIPTION: Dump information about the ACPI predefined names and predefined 680204766Sjkim * resource descriptor names. 681204766Sjkim * 682204766Sjkim ******************************************************************************/ 683204766Sjkim 684204766Sjkimvoid 685204766SjkimApDisplayReservedNames ( 686204766Sjkim void) 687204766Sjkim{ 688204766Sjkim const ACPI_PREDEFINED_INFO *ThisName; 689204766Sjkim char TypeBuffer[48]; /* Room for 5 types */ 690204766Sjkim UINT32 Count; 691204766Sjkim 692204766Sjkim 693204766Sjkim /* 694204766Sjkim * Predefined names/methods 695204766Sjkim */ 696204766Sjkim printf ("\nPredefined Name Information\n\n"); 697204766Sjkim 698204766Sjkim Count = 0; 699204766Sjkim ThisName = PredefinedNames; 700204766Sjkim while (ThisName->Info.Name[0]) 701204766Sjkim { 702204766Sjkim printf ("%4.4s Requires %d arguments, ", 703204766Sjkim ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F); 704204766Sjkim 705204766Sjkim if (ThisName->Info.ExpectedBtypes) 706204766Sjkim { 707204766Sjkim ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes); 708204766Sjkim printf ("Must return: %s\n", TypeBuffer); 709204766Sjkim } 710204766Sjkim else 711204766Sjkim { 712204766Sjkim printf ("No return value\n"); 713204766Sjkim } 714204766Sjkim 715204766Sjkim /* 716204766Sjkim * Skip next entry in the table if this name returns a Package 717204766Sjkim * (next entry contains the package info) 718204766Sjkim */ 719204766Sjkim if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE) 720204766Sjkim { 721204766Sjkim ThisName++; 722204766Sjkim } 723204766Sjkim 724204766Sjkim Count++; 725204766Sjkim ThisName++; 726204766Sjkim } 727204766Sjkim 728204766Sjkim printf ("%u Predefined Names are recognized\n", Count); 729204766Sjkim 730204766Sjkim /* 731204766Sjkim * Resource Descriptor names 732204766Sjkim */ 733204766Sjkim printf ("\nResource Descriptor Predefined Names\n\n"); 734204766Sjkim 735204766Sjkim Count = 0; 736204766Sjkim ThisName = ResourceNames; 737204766Sjkim while (ThisName->Info.Name[0]) 738204766Sjkim { 739204766Sjkim printf ("%4.4s Resource Descriptor\n", ThisName->Info.Name); 740204766Sjkim Count++; 741204766Sjkim ThisName++; 742204766Sjkim } 743204766Sjkim 744204766Sjkim printf ("%u Resource Descriptor Names are recognized\n", Count); 745204766Sjkim 746204766Sjkim /* 747204766Sjkim * Predefined scope names 748204766Sjkim */ 749204766Sjkim printf ("\nPredefined Scope Names\n\n"); 750204766Sjkim 751204766Sjkim ThisName = ScopeNames; 752204766Sjkim while (ThisName->Info.Name[0]) 753204766Sjkim { 754204766Sjkim printf ("%4.4s Scope\n", ThisName->Info.Name); 755204766Sjkim ThisName++; 756204766Sjkim } 757204766Sjkim} 758204766Sjkim 759204766Sjkim 760204766Sjkim/******************************************************************************* 761204766Sjkim * 762204766Sjkim * FUNCTION: ApGetExpectedTypes 763204766Sjkim * 764204766Sjkim * PARAMETERS: Buffer - Where the formatted string is returned 765204766Sjkim * ExpectedBTypes - Bitfield of expected data types 766204766Sjkim * 767204766Sjkim * RETURN: None, formatted string 768204766Sjkim * 769204766Sjkim * DESCRIPTION: Format the expected object types into a printable string. 770204766Sjkim * 771204766Sjkim ******************************************************************************/ 772204766Sjkim 773204766Sjkimstatic void 774204766SjkimApGetExpectedTypes ( 775204766Sjkim char *Buffer, 776204766Sjkim UINT32 ExpectedBtypes) 777204766Sjkim{ 778204766Sjkim UINT32 ThisRtype; 779204766Sjkim UINT32 i; 780204766Sjkim UINT32 j; 781204766Sjkim 782204766Sjkim 783204766Sjkim j = 1; 784204766Sjkim Buffer[0] = 0; 785204766Sjkim ThisRtype = ACPI_RTYPE_INTEGER; 786204766Sjkim 787204766Sjkim for (i = 0; i < ACPI_NUM_RTYPES; i++) 788204766Sjkim { 789204766Sjkim /* If one of the expected types, concatenate the name of this type */ 790204766Sjkim 791204766Sjkim if (ExpectedBtypes & ThisRtype) 792204766Sjkim { 793204766Sjkim ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]); 794204766Sjkim j = 0; /* Use name separator from now on */ 795204766Sjkim } 796204766Sjkim ThisRtype <<= 1; /* Next Rtype */ 797204766Sjkim } 798204766Sjkim} 799204766Sjkim 800