1118611Snjl/****************************************************************************** 2118611Snjl * 3118611Snjl * Module Name: aslfold - Constant folding 4118611Snjl * 5118611Snjl *****************************************************************************/ 6118611Snjl 7217365Sjkim/* 8245582Sjkim * Copyright (C) 2000 - 2013, Intel Corp. 9118611Snjl * All rights reserved. 10118611Snjl * 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. 25118611Snjl * 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. 29118611Snjl * 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 */ 43118611Snjl 44118611Snjl 45151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 46118611Snjl#include "aslcompiler.y.h" 47193529Sjkim#include <contrib/dev/acpica/include/amlcode.h> 48118611Snjl 49193529Sjkim#include <contrib/dev/acpica/include/acdispat.h> 50193529Sjkim#include <contrib/dev/acpica/include/acparser.h> 51118611Snjl 52118611Snjl#define _COMPONENT ACPI_COMPILER 53118611Snjl ACPI_MODULE_NAME ("aslfold") 54118611Snjl 55151937Sjkim/* Local prototypes */ 56118611Snjl 57151937Sjkimstatic ACPI_STATUS 58151937SjkimOpcAmlEvaluationWalk1 ( 59151937Sjkim ACPI_PARSE_OBJECT *Op, 60151937Sjkim UINT32 Level, 61151937Sjkim void *Context); 62151937Sjkim 63151937Sjkimstatic ACPI_STATUS 64151937SjkimOpcAmlEvaluationWalk2 ( 65151937Sjkim ACPI_PARSE_OBJECT *Op, 66151937Sjkim UINT32 Level, 67151937Sjkim void *Context); 68151937Sjkim 69151937Sjkimstatic ACPI_STATUS 70151937SjkimOpcAmlCheckForConstant ( 71151937Sjkim ACPI_PARSE_OBJECT *Op, 72151937Sjkim UINT32 Level, 73151937Sjkim void *Context); 74151937Sjkim 75239340Sjkimstatic void 76239340SjkimOpcUpdateIntegerNode ( 77239340Sjkim ACPI_PARSE_OBJECT *Op, 78239340Sjkim UINT64 Value); 79151937Sjkim 80239340Sjkim 81118611Snjl/******************************************************************************* 82118611Snjl * 83118611Snjl * FUNCTION: OpcAmlEvaluationWalk1 84118611Snjl * 85118611Snjl * PARAMETERS: ASL_WALK_CALLBACK 86118611Snjl * 87118611Snjl * RETURN: Status 88118611Snjl * 89118611Snjl * DESCRIPTION: Descending callback for AML execution of constant subtrees 90118611Snjl * 91118611Snjl ******************************************************************************/ 92118611Snjl 93151937Sjkimstatic ACPI_STATUS 94118611SnjlOpcAmlEvaluationWalk1 ( 95118611Snjl ACPI_PARSE_OBJECT *Op, 96118611Snjl UINT32 Level, 97118611Snjl void *Context) 98118611Snjl{ 99118611Snjl ACPI_WALK_STATE *WalkState = Context; 100118611Snjl ACPI_STATUS Status; 101118611Snjl ACPI_PARSE_OBJECT *OutOp; 102118611Snjl 103118611Snjl 104118611Snjl WalkState->Op = Op; 105118611Snjl WalkState->Opcode = Op->Common.AmlOpcode; 106118611Snjl WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 107118611Snjl 108118611Snjl /* Copy child pointer to Arg for compatibility with Interpreter */ 109118611Snjl 110118611Snjl if (Op->Asl.Child) 111118611Snjl { 112118611Snjl Op->Common.Value.Arg = Op->Asl.Child; 113118611Snjl } 114118611Snjl 115118611Snjl /* Call AML dispatcher */ 116118611Snjl 117118611Snjl Status = AcpiDsExecBeginOp (WalkState, &OutOp); 118118611Snjl if (ACPI_FAILURE (Status)) 119118611Snjl { 120118611Snjl AcpiOsPrintf ("Constant interpretation failed - %s\n", 121118611Snjl AcpiFormatException (Status)); 122118611Snjl } 123118611Snjl 124118611Snjl return (Status); 125118611Snjl} 126118611Snjl 127118611Snjl 128118611Snjl/******************************************************************************* 129118611Snjl * 130118611Snjl * FUNCTION: OpcAmlEvaluationWalk2 131118611Snjl * 132118611Snjl * PARAMETERS: ASL_WALK_CALLBACK 133118611Snjl * 134118611Snjl * RETURN: Status 135118611Snjl * 136118611Snjl * DESCRIPTION: Ascending callback for AML execution of constant subtrees 137118611Snjl * 138118611Snjl ******************************************************************************/ 139118611Snjl 140151937Sjkimstatic ACPI_STATUS 141118611SnjlOpcAmlEvaluationWalk2 ( 142118611Snjl ACPI_PARSE_OBJECT *Op, 143118611Snjl UINT32 Level, 144118611Snjl void *Context) 145118611Snjl{ 146118611Snjl ACPI_WALK_STATE *WalkState = Context; 147118611Snjl ACPI_STATUS Status; 148118611Snjl 149118611Snjl 150118611Snjl WalkState->Op = Op; 151118611Snjl WalkState->Opcode = Op->Common.AmlOpcode; 152118611Snjl WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 153118611Snjl 154118611Snjl /* Copy child pointer to Arg for compatibility with Interpreter */ 155118611Snjl 156118611Snjl if (Op->Asl.Child) 157118611Snjl { 158118611Snjl Op->Common.Value.Arg = Op->Asl.Child; 159118611Snjl } 160118611Snjl 161118611Snjl /* Call AML dispatcher */ 162118611Snjl 163118611Snjl Status = AcpiDsExecEndOp (WalkState); 164118611Snjl if (ACPI_FAILURE (Status)) 165118611Snjl { 166118611Snjl AcpiOsPrintf ("Constant interpretation failed - %s\n", 167118611Snjl AcpiFormatException (Status)); 168118611Snjl } 169118611Snjl 170118611Snjl return (Status); 171118611Snjl} 172118611Snjl 173118611Snjl 174118611Snjl/******************************************************************************* 175118611Snjl * 176118611Snjl * FUNCTION: OpcAmlCheckForConstant 177118611Snjl * 178118611Snjl * PARAMETERS: ASL_WALK_CALLBACK 179118611Snjl * 180118611Snjl * RETURN: Status 181118611Snjl * 182118611Snjl * DESCRIPTION: Check one Op for a type 3/4/5 AML opcode 183118611Snjl * 184118611Snjl ******************************************************************************/ 185118611Snjl 186151937Sjkimstatic ACPI_STATUS 187118611SnjlOpcAmlCheckForConstant ( 188118611Snjl ACPI_PARSE_OBJECT *Op, 189118611Snjl UINT32 Level, 190118611Snjl void *Context) 191118611Snjl{ 192118611Snjl ACPI_WALK_STATE *WalkState = Context; 193118611Snjl 194118611Snjl 195118611Snjl WalkState->Op = Op; 196118611Snjl WalkState->Opcode = Op->Common.AmlOpcode; 197118611Snjl WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 198118611Snjl 199118611Snjl DbgPrint (ASL_PARSE_OUTPUT, "[%.4d] Opcode: %12.12s ", 200118611Snjl Op->Asl.LogicalLineNumber, Op->Asl.ParseOpName); 201118611Snjl 202240716Sjkim /* 203240716Sjkim * These opcodes do not appear in the OpcodeInfo table, but 204240716Sjkim * they represent constants, so abort the constant walk now. 205240716Sjkim */ 206240716Sjkim if ((WalkState->Opcode == AML_RAW_DATA_BYTE) || 207240716Sjkim (WalkState->Opcode == AML_RAW_DATA_WORD) || 208240716Sjkim (WalkState->Opcode == AML_RAW_DATA_DWORD) || 209240716Sjkim (WalkState->Opcode == AML_RAW_DATA_QWORD)) 210240716Sjkim { 211240716Sjkim WalkState->WalkType = ACPI_WALK_CONST_OPTIONAL; 212240716Sjkim return (AE_TYPE); 213240716Sjkim } 214240716Sjkim 215118611Snjl if (!(WalkState->OpInfo->Flags & AML_CONSTANT)) 216118611Snjl { 217118611Snjl /* The opcode is not a Type 3/4/5 opcode */ 218118611Snjl 219118611Snjl if (Op->Asl.CompileFlags & NODE_IS_TARGET) 220118611Snjl { 221151937Sjkim DbgPrint (ASL_PARSE_OUTPUT, 222151937Sjkim "**** Valid Target, cannot reduce ****\n"); 223118611Snjl } 224118611Snjl else 225118611Snjl { 226151937Sjkim DbgPrint (ASL_PARSE_OUTPUT, 227151937Sjkim "**** Not a Type 3/4/5 opcode ****\n"); 228118611Snjl } 229118611Snjl 230118611Snjl if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL) 231118611Snjl { 232118611Snjl /* 233118611Snjl * We are looking at at normal expression to see if it can be 234239340Sjkim * reduced. It can't. No error 235118611Snjl */ 236118611Snjl return (AE_TYPE); 237118611Snjl } 238118611Snjl 239118611Snjl /* 240118611Snjl * This is an expression that MUST reduce to a constant, and it 241239340Sjkim * can't be reduced. This is an error 242118611Snjl */ 243118611Snjl if (Op->Asl.CompileFlags & NODE_IS_TARGET) 244118611Snjl { 245151937Sjkim AslError (ASL_ERROR, ASL_MSG_INVALID_TARGET, Op, 246151937Sjkim Op->Asl.ParseOpName); 247118611Snjl } 248118611Snjl else 249118611Snjl { 250151937Sjkim AslError (ASL_ERROR, ASL_MSG_INVALID_CONSTANT_OP, Op, 251151937Sjkim Op->Asl.ParseOpName); 252118611Snjl } 253118611Snjl 254118611Snjl return (AE_TYPE); 255118611Snjl } 256118611Snjl 257118611Snjl /* Debug output */ 258118611Snjl 259118611Snjl DbgPrint (ASL_PARSE_OUTPUT, "TYPE_345"); 260118611Snjl 261118611Snjl if (Op->Asl.CompileFlags & NODE_IS_TARGET) 262118611Snjl { 263118611Snjl DbgPrint (ASL_PARSE_OUTPUT, " TARGET"); 264118611Snjl } 265118611Snjl if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG) 266118611Snjl { 267118611Snjl DbgPrint (ASL_PARSE_OUTPUT, " TERMARG"); 268118611Snjl } 269240716Sjkim 270118611Snjl DbgPrint (ASL_PARSE_OUTPUT, "\n"); 271118611Snjl return (AE_OK); 272118611Snjl} 273118611Snjl 274118611Snjl 275118611Snjl/******************************************************************************* 276118611Snjl * 277118611Snjl * FUNCTION: OpcAmlConstantWalk 278118611Snjl * 279118611Snjl * PARAMETERS: ASL_WALK_CALLBACK 280118611Snjl * 281118611Snjl * RETURN: Status 282118611Snjl * 283118611Snjl * DESCRIPTION: Reduce an Op and its subtree to a constant if possible 284118611Snjl * 285118611Snjl ******************************************************************************/ 286118611Snjl 287118611SnjlACPI_STATUS 288118611SnjlOpcAmlConstantWalk ( 289118611Snjl ACPI_PARSE_OBJECT *Op, 290118611Snjl UINT32 Level, 291118611Snjl void *Context) 292118611Snjl{ 293118611Snjl ACPI_WALK_STATE *WalkState; 294118611Snjl ACPI_STATUS Status = AE_OK; 295118611Snjl ACPI_OPERAND_OBJECT *ObjDesc; 296118611Snjl ACPI_PARSE_OBJECT *RootOp; 297118611Snjl ACPI_PARSE_OBJECT *OriginalParentOp; 298118611Snjl UINT8 WalkType; 299118611Snjl 300118611Snjl 301118611Snjl /* 302118611Snjl * Only interested in subtrees that could possibly contain 303118611Snjl * expressions that can be evaluated at this time 304118611Snjl */ 305118611Snjl if ((!(Op->Asl.CompileFlags & NODE_COMPILE_TIME_CONST)) || 306118611Snjl (Op->Asl.CompileFlags & NODE_IS_TARGET)) 307118611Snjl { 308118611Snjl return (AE_OK); 309118611Snjl } 310118611Snjl 311151937Sjkim /* Set the walk type based on the reduction used for this op */ 312151937Sjkim 313118611Snjl if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG) 314118611Snjl { 315118611Snjl /* Op is a TermArg, constant folding is merely optional */ 316118611Snjl 317118611Snjl if (!Gbl_FoldConstants) 318118611Snjl { 319118611Snjl return (AE_CTRL_DEPTH); 320118611Snjl } 321118611Snjl 322118611Snjl WalkType = ACPI_WALK_CONST_OPTIONAL; 323118611Snjl } 324118611Snjl else 325118611Snjl { 326118611Snjl /* Op is a DataObject, the expression MUST reduced to a constant */ 327118611Snjl 328118611Snjl WalkType = ACPI_WALK_CONST_REQUIRED; 329118611Snjl } 330118611Snjl 331118611Snjl /* Create a new walk state */ 332118611Snjl 333118611Snjl WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); 334118611Snjl if (!WalkState) 335118611Snjl { 336241973Sjkim return (AE_NO_MEMORY); 337118611Snjl } 338118611Snjl 339239340Sjkim WalkState->NextOp = NULL; 340239340Sjkim WalkState->Params = NULL; 341239340Sjkim WalkState->WalkType = WalkType; 342239340Sjkim WalkState->CallerReturnDesc = &ObjDesc; 343118611Snjl 344151937Sjkim /* 345151937Sjkim * Examine the entire subtree -- all nodes must be constants 346151937Sjkim * or type 3/4/5 opcodes 347151937Sjkim */ 348118611Snjl Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD, 349239340Sjkim OpcAmlCheckForConstant, NULL, WalkState); 350118611Snjl 351118611Snjl /* 352118611Snjl * Did we find an entire subtree that contains all constants and type 3/4/5 353118611Snjl * opcodes? (Only AE_OK or AE_TYPE returned from above) 354118611Snjl */ 355118611Snjl if (Status == AE_TYPE) 356118611Snjl { 357118611Snjl /* Subtree cannot be reduced to a constant */ 358118611Snjl 359118611Snjl if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL) 360118611Snjl { 361118611Snjl AcpiDsDeleteWalkState (WalkState); 362118611Snjl return (AE_OK); 363118611Snjl } 364118611Snjl 365118611Snjl /* Don't descend any further, and use a default "constant" value */ 366118611Snjl 367118611Snjl Status = AE_CTRL_DEPTH; 368118611Snjl } 369118611Snjl else 370118611Snjl { 371118611Snjl /* Subtree can be reduced */ 372118611Snjl 373118611Snjl /* Allocate a new temporary root for this subtree */ 374118611Snjl 375118611Snjl RootOp = TrAllocateNode (PARSEOP_INTEGER); 376118611Snjl if (!RootOp) 377118611Snjl { 378118611Snjl return (AE_NO_MEMORY); 379118611Snjl } 380118611Snjl 381118611Snjl RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP; 382118611Snjl 383118611Snjl OriginalParentOp = Op->Common.Parent; 384118611Snjl Op->Common.Parent = RootOp; 385118611Snjl 386151937Sjkim /* Hand off the subtree to the AML interpreter */ 387151937Sjkim 388151937Sjkim Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE, 389239340Sjkim OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState); 390118611Snjl Op->Common.Parent = OriginalParentOp; 391118611Snjl 392118611Snjl /* TBD: we really *should* release the RootOp node */ 393118611Snjl 394118611Snjl if (ACPI_SUCCESS (Status)) 395118611Snjl { 396118611Snjl TotalFolds++; 397118611Snjl 398118611Snjl /* Get the final result */ 399118611Snjl 400118611Snjl Status = AcpiDsResultPop (&ObjDesc, WalkState); 401118611Snjl } 402239340Sjkim 403239340Sjkim /* Check for error from the ACPICA core */ 404239340Sjkim 405239340Sjkim if (ACPI_FAILURE (Status)) 406239340Sjkim { 407239340Sjkim AslCoreSubsystemError (Op, Status, 408239340Sjkim "Failure during constant evaluation", FALSE); 409239340Sjkim } 410118611Snjl } 411118611Snjl 412118611Snjl if (ACPI_FAILURE (Status)) 413118611Snjl { 414118611Snjl /* We could not resolve the subtree for some reason */ 415118611Snjl 416151937Sjkim AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op, 417151937Sjkim Op->Asl.ParseOpName); 418118611Snjl 419239340Sjkim /* Set the subtree value to ZERO anyway. Eliminates further errors */ 420118611Snjl 421239340Sjkim OpcUpdateIntegerNode (Op, 0); 422118611Snjl } 423118611Snjl else 424118611Snjl { 425151937Sjkim AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op, 426151937Sjkim Op->Asl.ParseOpName); 427118611Snjl 428118611Snjl /* 429118611Snjl * Because we know we executed type 3/4/5 opcodes above, we know that 430118611Snjl * the result must be either an Integer, String, or Buffer. 431118611Snjl */ 432193529Sjkim switch (ObjDesc->Common.Type) 433118611Snjl { 434118611Snjl case ACPI_TYPE_INTEGER: 435118611Snjl 436239340Sjkim OpcUpdateIntegerNode (Op, ObjDesc->Integer.Value); 437118611Snjl 438151937Sjkim DbgPrint (ASL_PARSE_OUTPUT, 439239340Sjkim "Constant expression reduced to (%s) %8.8X%8.8X\n", 440239340Sjkim Op->Asl.ParseOpName, 441239340Sjkim ACPI_FORMAT_UINT64 (Op->Common.Value.Integer)); 442118611Snjl break; 443118611Snjl 444118611Snjl case ACPI_TYPE_STRING: 445118611Snjl 446239340Sjkim Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL; 447239340Sjkim Op->Common.AmlOpcode = AML_STRING_OP; 448239340Sjkim Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1; 449118611Snjl Op->Common.Value.String = ObjDesc->String.Pointer; 450118611Snjl 451151937Sjkim DbgPrint (ASL_PARSE_OUTPUT, 452151937Sjkim "Constant expression reduced to (STRING) %s\n", 453118611Snjl Op->Common.Value.String); 454118611Snjl 455118611Snjl break; 456118611Snjl 457118611Snjl case ACPI_TYPE_BUFFER: 458118611Snjl 459239340Sjkim Op->Asl.ParseOpcode = PARSEOP_BUFFER; 460239340Sjkim Op->Common.AmlOpcode = AML_BUFFER_OP; 461239340Sjkim Op->Asl.CompileFlags = NODE_AML_PACKAGE; 462118611Snjl UtSetParseOpName (Op); 463118611Snjl 464118611Snjl /* Child node is the buffer length */ 465118611Snjl 466118611Snjl RootOp = TrAllocateNode (PARSEOP_INTEGER); 467118611Snjl 468239340Sjkim RootOp->Asl.AmlOpcode = AML_DWORD_OP; 469118611Snjl RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length; 470239340Sjkim RootOp->Asl.Parent = Op; 471118611Snjl 472118611Snjl (void) OpcSetOptimalIntegerSize (RootOp); 473118611Snjl 474118611Snjl Op->Asl.Child = RootOp; 475118611Snjl Op = RootOp; 476118611Snjl UtSetParseOpName (Op); 477118611Snjl 478118611Snjl /* Peer to the child is the raw buffer data */ 479118611Snjl 480118611Snjl RootOp = TrAllocateNode (PARSEOP_RAW_DATA); 481239340Sjkim RootOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; 482239340Sjkim RootOp->Asl.AmlLength = ObjDesc->Buffer.Length; 483239340Sjkim RootOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer; 484239340Sjkim RootOp->Asl.Parent = Op->Asl.Parent; 485118611Snjl 486118611Snjl Op->Asl.Next = RootOp; 487118611Snjl Op = RootOp; 488118611Snjl 489151937Sjkim DbgPrint (ASL_PARSE_OUTPUT, 490151937Sjkim "Constant expression reduced to (BUFFER) length %X\n", 491118611Snjl ObjDesc->Buffer.Length); 492118611Snjl break; 493118611Snjl 494250838Sjkim default: 495118611Snjl 496118611Snjl printf ("Unsupported return type: %s\n", 497239340Sjkim AcpiUtGetObjectTypeName (ObjDesc)); 498118611Snjl break; 499118611Snjl } 500118611Snjl } 501118611Snjl 502118611Snjl UtSetParseOpName (Op); 503118611Snjl Op->Asl.Child = NULL; 504118611Snjl 505118611Snjl AcpiDsDeleteWalkState (WalkState); 506118611Snjl return (AE_CTRL_DEPTH); 507118611Snjl} 508118611Snjl 509239340Sjkim 510239340Sjkim/******************************************************************************* 511239340Sjkim * 512239340Sjkim * FUNCTION: OpcUpdateIntegerNode 513239340Sjkim * 514239340Sjkim * PARAMETERS: Op - Current parse object 515239340Sjkim * 516239340Sjkim * RETURN: None 517239340Sjkim * 518239340Sjkim * DESCRIPTION: Update node to the correct integer type. 519239340Sjkim * 520239340Sjkim ******************************************************************************/ 521239340Sjkim 522239340Sjkimstatic void 523239340SjkimOpcUpdateIntegerNode ( 524239340Sjkim ACPI_PARSE_OBJECT *Op, 525239340Sjkim UINT64 Value) 526239340Sjkim{ 527239340Sjkim 528239340Sjkim Op->Common.Value.Integer = Value; 529239340Sjkim 530239340Sjkim /* 531239340Sjkim * The AmlLength is used by the parser to indicate a constant, 532239340Sjkim * (if non-zero). Length is either (1/2/4/8) 533239340Sjkim */ 534239340Sjkim switch (Op->Asl.AmlLength) 535239340Sjkim { 536239340Sjkim case 1: 537250838Sjkim 538239340Sjkim TrUpdateNode (PARSEOP_BYTECONST, Op); 539239340Sjkim Op->Asl.AmlOpcode = AML_RAW_DATA_BYTE; 540239340Sjkim break; 541239340Sjkim 542239340Sjkim case 2: 543250838Sjkim 544239340Sjkim TrUpdateNode (PARSEOP_WORDCONST, Op); 545239340Sjkim Op->Asl.AmlOpcode = AML_RAW_DATA_WORD; 546239340Sjkim break; 547239340Sjkim 548239340Sjkim case 4: 549250838Sjkim 550239340Sjkim TrUpdateNode (PARSEOP_DWORDCONST, Op); 551239340Sjkim Op->Asl.AmlOpcode = AML_RAW_DATA_DWORD; 552239340Sjkim break; 553239340Sjkim 554239340Sjkim case 8: 555250838Sjkim 556239340Sjkim TrUpdateNode (PARSEOP_QWORDCONST, Op); 557239340Sjkim Op->Asl.AmlOpcode = AML_RAW_DATA_QWORD; 558239340Sjkim break; 559239340Sjkim 560239340Sjkim case 0: 561239340Sjkim default: 562250838Sjkim 563239340Sjkim OpcSetOptimalIntegerSize (Op); 564239340Sjkim TrUpdateNode (PARSEOP_INTEGER, Op); 565239340Sjkim break; 566239340Sjkim } 567239340Sjkim 568239340Sjkim Op->Asl.AmlLength = 0; 569239340Sjkim} 570