1204766Sjkim/****************************************************************************** 2204766Sjkim * 3204766Sjkim * Module Name: aslpredef - support for ACPI predefined names 4204766Sjkim * 5204766Sjkim *****************************************************************************/ 6204766Sjkim 7217365Sjkim/* 8298714Sjkim * Copyright (C) 2000 - 2016, Intel Corp. 9204766Sjkim * All rights reserved. 10204766Sjkim * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 25204766Sjkim * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 29204766Sjkim * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 43204766Sjkim 44204766Sjkim#define ACPI_CREATE_PREDEFINED_TABLE 45249112Sjkim#define ACPI_CREATE_RESOURCE_TABLE 46204766Sjkim 47204773Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 48204766Sjkim#include "aslcompiler.y.h" 49204773Sjkim#include <contrib/dev/acpica/include/acpredef.h> 50246849Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 51204766Sjkim 52204766Sjkim 53204766Sjkim#define _COMPONENT ACPI_COMPILER 54204766Sjkim ACPI_MODULE_NAME ("aslpredef") 55204766Sjkim 56204766Sjkim 57204766Sjkim/* Local prototypes */ 58204766Sjkim 59218590Sjkimstatic void 60218590SjkimApCheckForUnexpectedReturnValue ( 61218590Sjkim ACPI_PARSE_OBJECT *Op, 62218590Sjkim ASL_METHOD_INFO *MethodInfo); 63218590Sjkim 64204766Sjkimstatic UINT32 65204766SjkimApCheckForSpecialName ( 66204766Sjkim ACPI_PARSE_OBJECT *Op, 67204766Sjkim char *Name); 68204766Sjkim 69204766Sjkim 70204766Sjkim/******************************************************************************* 71204766Sjkim * 72204766Sjkim * FUNCTION: ApCheckForPredefinedMethod 73204766Sjkim * 74204766Sjkim * PARAMETERS: Op - A parse node of type "METHOD". 75204766Sjkim * MethodInfo - Saved info about this method 76204766Sjkim * 77204766Sjkim * RETURN: None 78204766Sjkim * 79204766Sjkim * DESCRIPTION: If method is a predefined name, check that the number of 80204766Sjkim * arguments and the return type (returns a value or not) 81204766Sjkim * is correct. 82204766Sjkim * 83204766Sjkim ******************************************************************************/ 84204766Sjkim 85220663SjkimBOOLEAN 86204766SjkimApCheckForPredefinedMethod ( 87204766Sjkim ACPI_PARSE_OBJECT *Op, 88204766Sjkim ASL_METHOD_INFO *MethodInfo) 89204766Sjkim{ 90249112Sjkim UINT32 Index; 91249112Sjkim UINT32 RequiredArgCount; 92249112Sjkim const ACPI_PREDEFINED_INFO *ThisName; 93204766Sjkim 94204766Sjkim 95204766Sjkim /* Check for a match against the predefined name list */ 96204766Sjkim 97204766Sjkim Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg); 98204766Sjkim 99204766Sjkim switch (Index) 100204766Sjkim { 101204766Sjkim case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */ 102204766Sjkim case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */ 103204766Sjkim case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */ 104204766Sjkim 105204766Sjkim /* Just return, nothing to do */ 106220663Sjkim return (FALSE); 107204766Sjkim 108204766Sjkim 109207344Sjkim case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */ 110204766Sjkim 111204766Sjkim Gbl_ReservedMethods++; 112204766Sjkim 113207344Sjkim /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */ 114204766Sjkim 115204766Sjkim if (MethodInfo->NumArguments != 0) 116204766Sjkim { 117209746Sjkim sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0); 118204766Sjkim 119204766Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op, 120204766Sjkim MsgBuffer); 121204766Sjkim } 122204766Sjkim break; 123204766Sjkim 124204766Sjkim 125204766Sjkim default: 126204766Sjkim /* 127249663Sjkim * Matched a predefined method name - validate the ASL-defined 128249663Sjkim * argument count against the ACPI specification. 129204766Sjkim * 130249663Sjkim * Some methods are allowed to have a "minimum" number of args 131249663Sjkim * (_SCP) because their definition in ACPI has changed over time. 132204766Sjkim */ 133204766Sjkim Gbl_ReservedMethods++; 134249112Sjkim ThisName = &AcpiGbl_PredefinedMethods[Index]; 135249663Sjkim RequiredArgCount = METHOD_GET_ARG_COUNT (ThisName->Info.ArgumentList); 136204766Sjkim 137249112Sjkim if (MethodInfo->NumArguments != RequiredArgCount) 138204766Sjkim { 139209746Sjkim sprintf (MsgBuffer, "%4.4s requires %u", 140249112Sjkim ThisName->Info.Name, RequiredArgCount); 141204766Sjkim 142249663Sjkim if (MethodInfo->NumArguments < RequiredArgCount) 143204766Sjkim { 144249663Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op, 145204766Sjkim MsgBuffer); 146204766Sjkim } 147249663Sjkim else if ((MethodInfo->NumArguments > RequiredArgCount) && 148249663Sjkim !(ThisName->Info.ArgumentList & ARG_COUNT_IS_MINIMUM)) 149204766Sjkim { 150249663Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op, 151204766Sjkim MsgBuffer); 152204766Sjkim } 153204766Sjkim } 154204766Sjkim 155204766Sjkim /* 156204766Sjkim * Check if method returns no value, but the predefined name is 157204766Sjkim * required to return a value 158204766Sjkim */ 159204766Sjkim if (MethodInfo->NumReturnNoValue && 160249112Sjkim ThisName->Info.ExpectedBtypes) 161204766Sjkim { 162249112Sjkim AcpiUtGetExpectedReturnTypes (StringBuffer, 163249112Sjkim ThisName->Info.ExpectedBtypes); 164204766Sjkim 165206117Sjkim sprintf (MsgBuffer, "%s required for %4.4s", 166249112Sjkim StringBuffer, ThisName->Info.Name); 167206117Sjkim 168204766Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op, 169204766Sjkim MsgBuffer); 170204766Sjkim } 171204766Sjkim break; 172204766Sjkim } 173220663Sjkim 174220663Sjkim return (TRUE); 175204766Sjkim} 176204766Sjkim 177204766Sjkim 178204766Sjkim/******************************************************************************* 179204766Sjkim * 180218590Sjkim * FUNCTION: ApCheckForUnexpectedReturnValue 181218590Sjkim * 182218590Sjkim * PARAMETERS: Op - A parse node of type "RETURN". 183218590Sjkim * MethodInfo - Saved info about this method 184218590Sjkim * 185218590Sjkim * RETURN: None 186218590Sjkim * 187218590Sjkim * DESCRIPTION: Check for an unexpected return value from a predefined method. 188218590Sjkim * Invoked for predefined methods that are defined to not return 189218590Sjkim * any value. If there is a return value, issue a remark, since 190218590Sjkim * the ASL writer may be confused as to the method definition 191218590Sjkim * and/or functionality. 192218590Sjkim * 193218590Sjkim * Note: We ignore all return values of "Zero", since this is what a standalone 194218590Sjkim * Return() statement will always generate -- so we ignore it here -- 195218590Sjkim * i.e., there is no difference between Return() and Return(Zero). 196218590Sjkim * Also, a null Return() will be disassembled to return(Zero) -- so, we 197218590Sjkim * don't want to generate extraneous remarks/warnings for a disassembled 198218590Sjkim * ASL file. 199218590Sjkim * 200218590Sjkim ******************************************************************************/ 201218590Sjkim 202218590Sjkimstatic void 203218590SjkimApCheckForUnexpectedReturnValue ( 204218590Sjkim ACPI_PARSE_OBJECT *Op, 205218590Sjkim ASL_METHOD_INFO *MethodInfo) 206218590Sjkim{ 207218590Sjkim ACPI_PARSE_OBJECT *ReturnValueOp; 208218590Sjkim 209218590Sjkim 210218590Sjkim /* Ignore Return() and Return(Zero) (they are the same) */ 211218590Sjkim 212218590Sjkim ReturnValueOp = Op->Asl.Child; 213218590Sjkim if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO) 214218590Sjkim { 215218590Sjkim return; 216218590Sjkim } 217218590Sjkim 218218590Sjkim /* We have a valid return value, but the reserved name did not expect it */ 219218590Sjkim 220218590Sjkim AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL, 221218590Sjkim Op, MethodInfo->Op->Asl.ExternalName); 222218590Sjkim} 223218590Sjkim 224218590Sjkim 225218590Sjkim/******************************************************************************* 226218590Sjkim * 227206117Sjkim * FUNCTION: ApCheckPredefinedReturnValue 228206117Sjkim * 229206117Sjkim * PARAMETERS: Op - A parse node of type "RETURN". 230206117Sjkim * MethodInfo - Saved info about this method 231206117Sjkim * 232206117Sjkim * RETURN: None 233206117Sjkim * 234206117Sjkim * DESCRIPTION: If method is a predefined name, attempt to validate the return 235206117Sjkim * value. Only "static" types can be validated - a simple return 236206117Sjkim * of an integer/string/buffer/package or a named reference to 237206117Sjkim * a static object. Values such as a Localx or Argx or a control 238218590Sjkim * method invocation are not checked. Issue a warning if there is 239218590Sjkim * a valid return value, but the reserved method defines no 240218590Sjkim * return value. 241206117Sjkim * 242206117Sjkim ******************************************************************************/ 243206117Sjkim 244206117Sjkimvoid 245206117SjkimApCheckPredefinedReturnValue ( 246206117Sjkim ACPI_PARSE_OBJECT *Op, 247206117Sjkim ASL_METHOD_INFO *MethodInfo) 248206117Sjkim{ 249249112Sjkim UINT32 Index; 250249112Sjkim ACPI_PARSE_OBJECT *ReturnValueOp; 251249112Sjkim const ACPI_PREDEFINED_INFO *ThisName; 252206117Sjkim 253206117Sjkim 254272444Sjkim /* 255272444Sjkim * Check parent method for a match against the predefined name list. 256272444Sjkim * 257272444Sjkim * Note: Disable compiler errors/warnings because any errors will be 258272444Sjkim * caught when analyzing the parent method. Eliminates duplicate errors. 259272444Sjkim */ 260272444Sjkim Gbl_AllExceptionsDisabled = TRUE; 261206117Sjkim Index = ApCheckForPredefinedName (MethodInfo->Op, 262298714Sjkim MethodInfo->Op->Asl.NameSeg); 263272444Sjkim Gbl_AllExceptionsDisabled = FALSE; 264206117Sjkim 265206117Sjkim switch (Index) 266206117Sjkim { 267218590Sjkim case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */ 268218590Sjkim 269218590Sjkim /* No return value expected, warn if there is one */ 270218590Sjkim 271218590Sjkim ApCheckForUnexpectedReturnValue (Op, MethodInfo); 272218590Sjkim return; 273218590Sjkim 274206117Sjkim case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */ 275206117Sjkim case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */ 276206117Sjkim case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */ 277206117Sjkim 278206117Sjkim /* Just return, nothing to do */ 279206117Sjkim return; 280206117Sjkim 281207344Sjkim default: /* A standard predefined ACPI name */ 282206117Sjkim 283249112Sjkim ThisName = &AcpiGbl_PredefinedMethods[Index]; 284249112Sjkim if (!ThisName->Info.ExpectedBtypes) 285206117Sjkim { 286218590Sjkim /* No return value expected, warn if there is one */ 287218590Sjkim 288218590Sjkim ApCheckForUnexpectedReturnValue (Op, MethodInfo); 289206117Sjkim return; 290206117Sjkim } 291206117Sjkim 292206117Sjkim /* Get the object returned, it is the next argument */ 293206117Sjkim 294206117Sjkim ReturnValueOp = Op->Asl.Child; 295206117Sjkim switch (ReturnValueOp->Asl.ParseOpcode) 296206117Sjkim { 297206117Sjkim case PARSEOP_ZERO: 298206117Sjkim case PARSEOP_ONE: 299206117Sjkim case PARSEOP_ONES: 300206117Sjkim case PARSEOP_INTEGER: 301206117Sjkim case PARSEOP_STRING_LITERAL: 302206117Sjkim case PARSEOP_BUFFER: 303206117Sjkim case PARSEOP_PACKAGE: 304206117Sjkim 305206117Sjkim /* Static data return object - check against expected type */ 306206117Sjkim 307249112Sjkim ApCheckObjectType (ThisName->Info.Name, ReturnValueOp, 308249112Sjkim ThisName->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT); 309246849Sjkim 310246849Sjkim /* For packages, check the individual package elements */ 311246849Sjkim 312246849Sjkim if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_PACKAGE) 313246849Sjkim { 314249112Sjkim ApCheckPackage (ReturnValueOp, ThisName); 315246849Sjkim } 316206117Sjkim break; 317206117Sjkim 318206117Sjkim default: 319206117Sjkim /* 320206117Sjkim * All other ops are very difficult or impossible to typecheck at 321206117Sjkim * compile time. These include all Localx, Argx, and method 322206117Sjkim * invocations. Also, NAMESEG and NAMESTRING because the type of 323206117Sjkim * any named object can be changed at runtime (for example, 324206117Sjkim * CopyObject will change the type of the target object.) 325206117Sjkim */ 326206117Sjkim break; 327206117Sjkim } 328206117Sjkim } 329206117Sjkim} 330206117Sjkim 331206117Sjkim 332206117Sjkim/******************************************************************************* 333206117Sjkim * 334204766Sjkim * FUNCTION: ApCheckForPredefinedObject 335204766Sjkim * 336204766Sjkim * PARAMETERS: Op - A parse node 337204766Sjkim * Name - The ACPI name to be checked 338204766Sjkim * 339204766Sjkim * RETURN: None 340204766Sjkim * 341204766Sjkim * DESCRIPTION: Check for a predefined name for a static object (created via 342204766Sjkim * the ASL Name operator). If it is a predefined ACPI name, ensure 343204766Sjkim * that the name does not require any arguments (which would 344204766Sjkim * require a control method implemenation of the name), and that 345204766Sjkim * the type of the object is one of the expected types for the 346204766Sjkim * predefined name. 347204766Sjkim * 348204766Sjkim ******************************************************************************/ 349204766Sjkim 350204766Sjkimvoid 351204766SjkimApCheckForPredefinedObject ( 352204766Sjkim ACPI_PARSE_OBJECT *Op, 353204766Sjkim char *Name) 354204766Sjkim{ 355249112Sjkim UINT32 Index; 356249112Sjkim ACPI_PARSE_OBJECT *ObjectOp; 357249112Sjkim const ACPI_PREDEFINED_INFO *ThisName; 358204766Sjkim 359204766Sjkim 360204766Sjkim /* 361204766Sjkim * Check for a real predefined name -- not a resource descriptor name 362204766Sjkim * or a predefined scope name 363204766Sjkim */ 364204766Sjkim Index = ApCheckForPredefinedName (Op, Name); 365207344Sjkim 366207344Sjkim switch (Index) 367204766Sjkim { 368207344Sjkim case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */ 369207344Sjkim case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */ 370207344Sjkim case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */ 371207344Sjkim 372207344Sjkim /* Nothing to do */ 373204766Sjkim return; 374204766Sjkim 375207344Sjkim case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */ 376207344Sjkim 377204766Sjkim /* 378207344Sjkim * These names must be control methods, by definition in ACPI spec. 379207344Sjkim * Also because they are defined to return no value. None of them 380207344Sjkim * require any arguments. 381204766Sjkim */ 382204766Sjkim AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op, 383207344Sjkim "with zero arguments"); 384207344Sjkim return; 385204766Sjkim 386246849Sjkim default: 387250838Sjkim 388246849Sjkim break; 389246849Sjkim } 390204766Sjkim 391246849Sjkim /* A standard predefined ACPI name */ 392207344Sjkim 393246849Sjkim /* 394246849Sjkim * If this predefined name requires input arguments, then 395246849Sjkim * it must be implemented as a control method 396246849Sjkim */ 397249112Sjkim ThisName = &AcpiGbl_PredefinedMethods[Index]; 398249663Sjkim if (METHOD_GET_ARG_COUNT (ThisName->Info.ArgumentList) > 0) 399246849Sjkim { 400246849Sjkim AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op, 401246849Sjkim "with arguments"); 402246849Sjkim return; 403246849Sjkim } 404207344Sjkim 405246849Sjkim /* 406246849Sjkim * If no return value is expected from this predefined name, then 407246849Sjkim * it follows that it must be implemented as a control method 408246849Sjkim * (with zero args, because the args > 0 case was handled above) 409246849Sjkim * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx 410246849Sjkim */ 411249112Sjkim if (!ThisName->Info.ExpectedBtypes) 412246849Sjkim { 413246849Sjkim AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op, 414246849Sjkim "with zero arguments"); 415207344Sjkim return; 416207344Sjkim } 417246849Sjkim 418246849Sjkim /* Typecheck the actual object, it is the next argument */ 419246849Sjkim 420246849Sjkim ObjectOp = Op->Asl.Child->Asl.Next; 421249112Sjkim ApCheckObjectType (ThisName->Info.Name, Op->Asl.Child->Asl.Next, 422249112Sjkim ThisName->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT); 423246849Sjkim 424246849Sjkim /* For packages, check the individual package elements */ 425246849Sjkim 426246849Sjkim if (ObjectOp->Asl.ParseOpcode == PARSEOP_PACKAGE) 427246849Sjkim { 428249112Sjkim ApCheckPackage (ObjectOp, ThisName); 429246849Sjkim } 430204766Sjkim} 431204766Sjkim 432204766Sjkim 433204766Sjkim/******************************************************************************* 434204766Sjkim * 435204766Sjkim * FUNCTION: ApCheckForPredefinedName 436204766Sjkim * 437204766Sjkim * PARAMETERS: Op - A parse node 438204766Sjkim * Name - NameSeg to check 439204766Sjkim * 440204766Sjkim * RETURN: None 441204766Sjkim * 442204766Sjkim * DESCRIPTION: Check a NameSeg against the reserved list. 443204766Sjkim * 444204766Sjkim ******************************************************************************/ 445204766Sjkim 446204766SjkimUINT32 447204766SjkimApCheckForPredefinedName ( 448204766Sjkim ACPI_PARSE_OBJECT *Op, 449204766Sjkim char *Name) 450204766Sjkim{ 451249112Sjkim UINT32 i; 452249112Sjkim const ACPI_PREDEFINED_INFO *ThisName; 453204766Sjkim 454204766Sjkim 455204766Sjkim if (Name[0] == 0) 456204766Sjkim { 457298714Sjkim AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, 458298714Sjkim "zero length name found"); 459204766Sjkim } 460204766Sjkim 461204766Sjkim /* All reserved names are prefixed with a single underscore */ 462204766Sjkim 463204766Sjkim if (Name[0] != '_') 464204766Sjkim { 465204766Sjkim return (ACPI_NOT_RESERVED_NAME); 466204766Sjkim } 467204766Sjkim 468204766Sjkim /* Check for a standard predefined method name */ 469204766Sjkim 470249112Sjkim ThisName = AcpiGbl_PredefinedMethods; 471249112Sjkim for (i = 0; ThisName->Info.Name[0]; i++) 472204766Sjkim { 473249112Sjkim if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name)) 474204766Sjkim { 475204766Sjkim /* Return index into predefined array */ 476204766Sjkim return (i); 477204766Sjkim } 478249112Sjkim 479249112Sjkim ThisName++; /* Does not account for extra package data, but is OK */ 480204766Sjkim } 481204766Sjkim 482204766Sjkim /* Check for resource names and predefined scope names */ 483204766Sjkim 484249112Sjkim ThisName = AcpiGbl_ResourceNames; 485249112Sjkim while (ThisName->Info.Name[0]) 486204766Sjkim { 487249112Sjkim if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name)) 488204766Sjkim { 489204766Sjkim return (ACPI_PREDEFINED_NAME); 490204766Sjkim } 491249112Sjkim 492249112Sjkim ThisName++; 493204766Sjkim } 494204766Sjkim 495249112Sjkim ThisName = AcpiGbl_ScopeNames; 496249112Sjkim while (ThisName->Info.Name[0]) 497204766Sjkim { 498249112Sjkim if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name)) 499204766Sjkim { 500204766Sjkim return (ACPI_PREDEFINED_NAME); 501204766Sjkim } 502249112Sjkim 503249112Sjkim ThisName++; 504204766Sjkim } 505204766Sjkim 506207344Sjkim /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */ 507204766Sjkim 508204766Sjkim return (ApCheckForSpecialName (Op, Name)); 509204766Sjkim} 510204766Sjkim 511204766Sjkim 512204766Sjkim/******************************************************************************* 513204766Sjkim * 514204766Sjkim * FUNCTION: ApCheckForSpecialName 515204766Sjkim * 516204766Sjkim * PARAMETERS: Op - A parse node 517204766Sjkim * Name - NameSeg to check 518204766Sjkim * 519204766Sjkim * RETURN: None 520204766Sjkim * 521206117Sjkim * DESCRIPTION: Check for the "special" predefined names - 522207344Sjkim * _Lxx, _Exx, _Qxx, _Wxx, and _T_x 523204766Sjkim * 524204766Sjkim ******************************************************************************/ 525204766Sjkim 526204766Sjkimstatic UINT32 527204766SjkimApCheckForSpecialName ( 528204766Sjkim ACPI_PARSE_OBJECT *Op, 529204766Sjkim char *Name) 530204766Sjkim{ 531204766Sjkim 532204766Sjkim /* 533207344Sjkim * Check for the "special" predefined names. We already know that the 534207344Sjkim * first character is an underscore. 535204766Sjkim * GPE: _Lxx 536204766Sjkim * GPE: _Exx 537207344Sjkim * GPE: _Wxx 538204766Sjkim * EC: _Qxx 539204766Sjkim */ 540204766Sjkim if ((Name[1] == 'L') || 541204766Sjkim (Name[1] == 'E') || 542207344Sjkim (Name[1] == 'W') || 543204766Sjkim (Name[1] == 'Q')) 544204766Sjkim { 545204766Sjkim /* The next two characters must be hex digits */ 546204766Sjkim 547204766Sjkim if ((isxdigit ((int) Name[2])) && 548204766Sjkim (isxdigit ((int) Name[3]))) 549204766Sjkim { 550204766Sjkim return (ACPI_EVENT_RESERVED_NAME); 551204766Sjkim } 552204766Sjkim } 553204766Sjkim 554204766Sjkim /* Check for the names reserved for the compiler itself: _T_x */ 555204766Sjkim 556204766Sjkim else if ((Op->Asl.ExternalName[1] == 'T') && 557204766Sjkim (Op->Asl.ExternalName[2] == '_')) 558204766Sjkim { 559204766Sjkim /* Ignore if actually emitted by the compiler */ 560204766Sjkim 561204766Sjkim if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED) 562204766Sjkim { 563204766Sjkim return (ACPI_NOT_RESERVED_NAME); 564204766Sjkim } 565204766Sjkim 566204766Sjkim /* 567204766Sjkim * Was not actually emitted by the compiler. This is a special case, 568204766Sjkim * however. If the ASL code being compiled was the result of a 569204766Sjkim * dissasembly, it may possibly contain valid compiler-emitted names 570204766Sjkim * of the form "_T_x". We don't want to issue an error or even a 571204766Sjkim * warning and force the user to manually change the names. So, we 572204766Sjkim * will issue a remark instead. 573204766Sjkim */ 574298714Sjkim AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, 575298714Sjkim Op, Op->Asl.ExternalName); 576204766Sjkim return (ACPI_COMPILER_RESERVED_NAME); 577204766Sjkim } 578204766Sjkim 579204766Sjkim /* 580204766Sjkim * The name didn't match any of the known predefined names. Flag it as a 581204766Sjkim * warning, since the entire namespace starting with an underscore is 582204766Sjkim * reserved by the ACPI spec. 583204766Sjkim */ 584298714Sjkim AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, 585298714Sjkim Op, Op->Asl.ExternalName); 586204766Sjkim 587204766Sjkim return (ACPI_NOT_RESERVED_NAME); 588204766Sjkim} 589204766Sjkim 590204766Sjkim 591204766Sjkim/******************************************************************************* 592204766Sjkim * 593204766Sjkim * FUNCTION: ApCheckObjectType 594204766Sjkim * 595245582Sjkim * PARAMETERS: PredefinedName - Name of the predefined object we are checking 596245582Sjkim * Op - Current parse node 597204766Sjkim * ExpectedBtypes - Bitmap of expected return type(s) 598246849Sjkim * PackageIndex - Index of object within parent package (if 599246849Sjkim * applicable - ACPI_NOT_PACKAGE_ELEMENT 600246849Sjkim * otherwise) 601204766Sjkim * 602204766Sjkim * RETURN: None 603204766Sjkim * 604204766Sjkim * DESCRIPTION: Check if the object type is one of the types that is expected 605204766Sjkim * by the predefined name. Only a limited number of object types 606204766Sjkim * can be returned by the predefined names. 607204766Sjkim * 608204766Sjkim ******************************************************************************/ 609204766Sjkim 610246849SjkimACPI_STATUS 611204766SjkimApCheckObjectType ( 612245582Sjkim const char *PredefinedName, 613204766Sjkim ACPI_PARSE_OBJECT *Op, 614246849Sjkim UINT32 ExpectedBtypes, 615246849Sjkim UINT32 PackageIndex) 616204766Sjkim{ 617204766Sjkim UINT32 ReturnBtype; 618246849Sjkim char *TypeName; 619204766Sjkim 620204766Sjkim 621246849Sjkim if (!Op) 622246849Sjkim { 623246849Sjkim return (AE_TYPE); 624246849Sjkim } 625246849Sjkim 626246849Sjkim /* Map the parse opcode to a bitmapped return type (RTYPE) */ 627246849Sjkim 628204766Sjkim switch (Op->Asl.ParseOpcode) 629204766Sjkim { 630206117Sjkim case PARSEOP_ZERO: 631206117Sjkim case PARSEOP_ONE: 632206117Sjkim case PARSEOP_ONES: 633204766Sjkim case PARSEOP_INTEGER: 634250838Sjkim 635204766Sjkim ReturnBtype = ACPI_RTYPE_INTEGER; 636246849Sjkim TypeName = "Integer"; 637204766Sjkim break; 638204766Sjkim 639246849Sjkim case PARSEOP_STRING_LITERAL: 640250838Sjkim 641246849Sjkim ReturnBtype = ACPI_RTYPE_STRING; 642246849Sjkim TypeName = "String"; 643246849Sjkim break; 644246849Sjkim 645204766Sjkim case PARSEOP_BUFFER: 646250838Sjkim 647204766Sjkim ReturnBtype = ACPI_RTYPE_BUFFER; 648246849Sjkim TypeName = "Buffer"; 649204766Sjkim break; 650204766Sjkim 651204766Sjkim case PARSEOP_PACKAGE: 652228110Sjkim case PARSEOP_VAR_PACKAGE: 653250838Sjkim 654204766Sjkim ReturnBtype = ACPI_RTYPE_PACKAGE; 655246849Sjkim TypeName = "Package"; 656204766Sjkim break; 657204766Sjkim 658246849Sjkim case PARSEOP_NAMESEG: 659246849Sjkim case PARSEOP_NAMESTRING: 660250838Sjkim /* 661250838Sjkim * Ignore any named references within a package object. 662250838Sjkim * 663250838Sjkim * For Package objects, references are allowed instead of any of the 664250838Sjkim * standard data types (Integer/String/Buffer/Package). These 665250838Sjkim * references are resolved at runtime. NAMESEG and NAMESTRING are 666250838Sjkim * impossible to typecheck at compile time because the type of 667250838Sjkim * any named object can be changed at runtime (for example, 668250838Sjkim * CopyObject will change the type of the target object). 669250838Sjkim */ 670250838Sjkim if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT) 671250838Sjkim { 672250838Sjkim return (AE_OK); 673250838Sjkim } 674250838Sjkim 675246849Sjkim ReturnBtype = ACPI_RTYPE_REFERENCE; 676246849Sjkim TypeName = "Reference"; 677246849Sjkim break; 678246849Sjkim 679204766Sjkim default: 680250838Sjkim 681204766Sjkim /* Not one of the supported object types */ 682206117Sjkim 683246849Sjkim TypeName = UtGetOpName (Op->Asl.ParseOpcode); 684204766Sjkim goto TypeErrorExit; 685204766Sjkim } 686204766Sjkim 687206117Sjkim /* Exit if the object is one of the expected types */ 688204766Sjkim 689204766Sjkim if (ReturnBtype & ExpectedBtypes) 690204766Sjkim { 691246849Sjkim return (AE_OK); 692204766Sjkim } 693204766Sjkim 694204766Sjkim 695204766SjkimTypeErrorExit: 696204766Sjkim 697204766Sjkim /* Format the expected types and emit an error message */ 698204766Sjkim 699249112Sjkim AcpiUtGetExpectedReturnTypes (StringBuffer, ExpectedBtypes); 700204766Sjkim 701246849Sjkim if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT) 702246849Sjkim { 703249112Sjkim sprintf (MsgBuffer, "%4.4s: found %s, %s required", 704246849Sjkim PredefinedName, TypeName, StringBuffer); 705246849Sjkim } 706246849Sjkim else 707246849Sjkim { 708249112Sjkim sprintf (MsgBuffer, "%4.4s: found %s at index %u, %s required", 709246849Sjkim PredefinedName, TypeName, PackageIndex, StringBuffer); 710246849Sjkim } 711206117Sjkim 712246849Sjkim AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, MsgBuffer); 713246849Sjkim return (AE_TYPE); 714204766Sjkim} 715204766Sjkim 716204766Sjkim 717204766Sjkim/******************************************************************************* 718204766Sjkim * 719204766Sjkim * FUNCTION: ApDisplayReservedNames 720204766Sjkim * 721204766Sjkim * PARAMETERS: None 722204766Sjkim * 723204766Sjkim * RETURN: None 724204766Sjkim * 725204766Sjkim * DESCRIPTION: Dump information about the ACPI predefined names and predefined 726204766Sjkim * resource descriptor names. 727204766Sjkim * 728204766Sjkim ******************************************************************************/ 729204766Sjkim 730204766Sjkimvoid 731204766SjkimApDisplayReservedNames ( 732204766Sjkim void) 733204766Sjkim{ 734204766Sjkim const ACPI_PREDEFINED_INFO *ThisName; 735204766Sjkim UINT32 Count; 736249112Sjkim UINT32 NumTypes; 737204766Sjkim 738204766Sjkim 739204766Sjkim /* 740204766Sjkim * Predefined names/methods 741204766Sjkim */ 742204766Sjkim printf ("\nPredefined Name Information\n\n"); 743204766Sjkim 744204766Sjkim Count = 0; 745249112Sjkim ThisName = AcpiGbl_PredefinedMethods; 746204766Sjkim while (ThisName->Info.Name[0]) 747204766Sjkim { 748249112Sjkim AcpiUtDisplayPredefinedMethod (MsgBuffer, ThisName, FALSE); 749204766Sjkim Count++; 750249112Sjkim ThisName = AcpiUtGetNextPredefinedMethod (ThisName); 751204766Sjkim } 752204766Sjkim 753204766Sjkim printf ("%u Predefined Names are recognized\n", Count); 754204766Sjkim 755204766Sjkim /* 756204766Sjkim * Resource Descriptor names 757204766Sjkim */ 758249112Sjkim printf ("\nPredefined Names for Resource Descriptor Fields\n\n"); 759204766Sjkim 760204766Sjkim Count = 0; 761249112Sjkim ThisName = AcpiGbl_ResourceNames; 762204766Sjkim while (ThisName->Info.Name[0]) 763204766Sjkim { 764249112Sjkim NumTypes = AcpiUtGetResourceBitWidth (MsgBuffer, 765249112Sjkim ThisName->Info.ArgumentList); 766249112Sjkim 767249112Sjkim printf ("%4.4s Field is %s bits wide%s\n", 768249112Sjkim ThisName->Info.Name, MsgBuffer, 769249112Sjkim (NumTypes > 1) ? " (depending on descriptor type)" : ""); 770249112Sjkim 771204766Sjkim Count++; 772204766Sjkim ThisName++; 773204766Sjkim } 774204766Sjkim 775249112Sjkim printf ("%u Resource Descriptor Field Names are recognized\n", Count); 776204766Sjkim 777204766Sjkim /* 778204766Sjkim * Predefined scope names 779204766Sjkim */ 780249112Sjkim printf ("\nPredefined Scope/Device Names (automatically created at root)\n\n"); 781204766Sjkim 782249112Sjkim ThisName = AcpiGbl_ScopeNames; 783204766Sjkim while (ThisName->Info.Name[0]) 784204766Sjkim { 785249112Sjkim printf ("%4.4s Scope/Device\n", ThisName->Info.Name); 786204766Sjkim ThisName++; 787204766Sjkim } 788204766Sjkim} 789