1208625Sjkim/****************************************************************************** 2208625Sjkim * 3208625Sjkim * Module Name: dtfield.c - Code generation for individual source fields 4208625Sjkim * 5208625Sjkim *****************************************************************************/ 6208625Sjkim 7217365Sjkim/* 8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp. 9208625Sjkim * All rights reserved. 10208625Sjkim * 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. 25208625Sjkim * 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. 29208625Sjkim * 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 */ 43208625Sjkim 44209746Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 45209746Sjkim#include <contrib/dev/acpica/compiler/dtcompiler.h> 46208625Sjkim 47208625Sjkim#define _COMPONENT DT_COMPILER 48208625Sjkim ACPI_MODULE_NAME ("dtfield") 49208625Sjkim 50208625Sjkim 51208625Sjkim/* Local prototypes */ 52208625Sjkim 53208625Sjkimstatic void 54208625SjkimDtCompileString ( 55208625Sjkim UINT8 *Buffer, 56208625Sjkim DT_FIELD *Field, 57208625Sjkim UINT32 ByteLength); 58208625Sjkim 59217365Sjkimstatic void 60217365SjkimDtCompileUnicode ( 61217365Sjkim UINT8 *Buffer, 62217365Sjkim DT_FIELD *Field, 63217365Sjkim UINT32 ByteLength); 64217365Sjkim 65217365Sjkimstatic ACPI_STATUS 66217365SjkimDtCompileUuid ( 67217365Sjkim UINT8 *Buffer, 68217365Sjkim DT_FIELD *Field, 69217365Sjkim UINT32 ByteLength); 70217365Sjkim 71208625Sjkimstatic char * 72209734SjkimDtNormalizeBuffer ( 73209734Sjkim char *Buffer, 74209734Sjkim UINT32 *Count); 75208625Sjkim 76208625Sjkim 77208625Sjkim/****************************************************************************** 78208625Sjkim * 79208625Sjkim * FUNCTION: DtCompileOneField 80208625Sjkim * 81208625Sjkim * PARAMETERS: Buffer - Output buffer 82208625Sjkim * Field - Field to be compiled 83208625Sjkim * ByteLength - Byte length of the field 84208625Sjkim * Type - Field type 85208625Sjkim * 86208625Sjkim * RETURN: None 87208625Sjkim * 88208625Sjkim * DESCRIPTION: Compile a field value to binary 89208625Sjkim * 90208625Sjkim *****************************************************************************/ 91208625Sjkim 92208625Sjkimvoid 93208625SjkimDtCompileOneField ( 94208625Sjkim UINT8 *Buffer, 95208625Sjkim DT_FIELD *Field, 96208625Sjkim UINT32 ByteLength, 97208625Sjkim UINT8 Type, 98208625Sjkim UINT8 Flags) 99208625Sjkim{ 100217365Sjkim ACPI_STATUS Status; 101208625Sjkim 102306536Sjkim 103208625Sjkim switch (Type) 104208625Sjkim { 105208625Sjkim case DT_FIELD_TYPE_INTEGER: 106250838Sjkim 107208625Sjkim DtCompileInteger (Buffer, Field, ByteLength, Flags); 108208625Sjkim break; 109208625Sjkim 110208625Sjkim case DT_FIELD_TYPE_STRING: 111250838Sjkim 112208625Sjkim DtCompileString (Buffer, Field, ByteLength); 113208625Sjkim break; 114208625Sjkim 115217365Sjkim case DT_FIELD_TYPE_UUID: 116250838Sjkim 117217365Sjkim Status = DtCompileUuid (Buffer, Field, ByteLength); 118217365Sjkim if (ACPI_SUCCESS (Status)) 119217365Sjkim { 120217365Sjkim break; 121217365Sjkim } 122217365Sjkim 123217365Sjkim /* Fall through. */ 124217365Sjkim 125208625Sjkim case DT_FIELD_TYPE_BUFFER: 126250838Sjkim 127208625Sjkim DtCompileBuffer (Buffer, Field->Value, Field, ByteLength); 128208625Sjkim break; 129208625Sjkim 130217365Sjkim case DT_FIELD_TYPE_UNICODE: 131250838Sjkim 132217365Sjkim DtCompileUnicode (Buffer, Field, ByteLength); 133217365Sjkim break; 134217365Sjkim 135217365Sjkim case DT_FIELD_TYPE_DEVICE_PATH: 136250838Sjkim 137217365Sjkim break; 138217365Sjkim 139208625Sjkim default: 140250838Sjkim 141208625Sjkim DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid field type"); 142208625Sjkim break; 143208625Sjkim } 144208625Sjkim} 145208625Sjkim 146208625Sjkim 147208625Sjkim/****************************************************************************** 148208625Sjkim * 149208625Sjkim * FUNCTION: DtCompileString 150208625Sjkim * 151208625Sjkim * PARAMETERS: Buffer - Output buffer 152208625Sjkim * Field - String to be copied to buffer 153208625Sjkim * ByteLength - Maximum length of string 154208625Sjkim * 155208625Sjkim * RETURN: None 156208625Sjkim * 157208625Sjkim * DESCRIPTION: Copy string to the buffer 158208625Sjkim * 159208625Sjkim *****************************************************************************/ 160208625Sjkim 161208625Sjkimstatic void 162208625SjkimDtCompileString ( 163208625Sjkim UINT8 *Buffer, 164208625Sjkim DT_FIELD *Field, 165208625Sjkim UINT32 ByteLength) 166208625Sjkim{ 167208625Sjkim UINT32 Length; 168208625Sjkim 169208625Sjkim 170306536Sjkim Length = strlen (Field->Value); 171208625Sjkim 172208625Sjkim /* Check if the string is too long for the field */ 173208625Sjkim 174208625Sjkim if (Length > ByteLength) 175208625Sjkim { 176208625Sjkim sprintf (MsgBuffer, "Maximum %u characters", ByteLength); 177208625Sjkim DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer); 178208625Sjkim Length = ByteLength; 179208625Sjkim } 180208625Sjkim 181306536Sjkim memcpy (Buffer, Field->Value, Length); 182208625Sjkim} 183208625Sjkim 184208625Sjkim 185208625Sjkim/****************************************************************************** 186208625Sjkim * 187217365Sjkim * FUNCTION: DtCompileUnicode 188217365Sjkim * 189217365Sjkim * PARAMETERS: Buffer - Output buffer 190217365Sjkim * Field - String to be copied to buffer 191217365Sjkim * ByteLength - Maximum length of string 192217365Sjkim * 193217365Sjkim * RETURN: None 194217365Sjkim * 195217365Sjkim * DESCRIPTION: Convert ASCII string to Unicode string 196217365Sjkim * 197217365Sjkim * Note: The Unicode string is 16 bits per character, no leading signature, 198217365Sjkim * with a 16-bit terminating NULL. 199217365Sjkim * 200217365Sjkim *****************************************************************************/ 201217365Sjkim 202217365Sjkimstatic void 203217365SjkimDtCompileUnicode ( 204217365Sjkim UINT8 *Buffer, 205217365Sjkim DT_FIELD *Field, 206217365Sjkim UINT32 ByteLength) 207217365Sjkim{ 208217365Sjkim UINT32 Count; 209217365Sjkim UINT32 i; 210217365Sjkim char *AsciiString; 211217365Sjkim UINT16 *UnicodeString; 212217365Sjkim 213217365Sjkim 214217365Sjkim AsciiString = Field->Value; 215217365Sjkim UnicodeString = (UINT16 *) Buffer; 216306536Sjkim Count = strlen (AsciiString) + 1; 217217365Sjkim 218217365Sjkim /* Convert to Unicode string (including null terminator) */ 219217365Sjkim 220217365Sjkim for (i = 0; i < Count; i++) 221217365Sjkim { 222217365Sjkim UnicodeString[i] = (UINT16) AsciiString[i]; 223217365Sjkim } 224217365Sjkim} 225217365Sjkim 226217365Sjkim 227217365Sjkim/******************************************************************************* 228217365Sjkim * 229217365Sjkim * FUNCTION: DtCompileUuid 230217365Sjkim * 231217365Sjkim * PARAMETERS: Buffer - Output buffer 232217365Sjkim * Field - String to be copied to buffer 233217365Sjkim * ByteLength - Maximum length of string 234217365Sjkim * 235217365Sjkim * RETURN: None 236217365Sjkim * 237217365Sjkim * DESCRIPTION: Convert UUID string to 16-byte buffer 238217365Sjkim * 239217365Sjkim ******************************************************************************/ 240217365Sjkim 241217365Sjkimstatic ACPI_STATUS 242217365SjkimDtCompileUuid ( 243217365Sjkim UINT8 *Buffer, 244217365Sjkim DT_FIELD *Field, 245217365Sjkim UINT32 ByteLength) 246217365Sjkim{ 247217365Sjkim char *InString; 248217365Sjkim ACPI_STATUS Status; 249217365Sjkim 250217365Sjkim 251217365Sjkim InString = Field->Value; 252217365Sjkim 253217365Sjkim Status = AuValidateUuid (InString); 254217365Sjkim if (ACPI_FAILURE (Status)) 255217365Sjkim { 256217365Sjkim sprintf (MsgBuffer, "%s", Field->Value); 257217365Sjkim DtNameError (ASL_ERROR, ASL_MSG_INVALID_UUID, Field, MsgBuffer); 258217365Sjkim } 259217365Sjkim else 260217365Sjkim { 261281075Sdim AcpiUtConvertStringToUuid (InString, Buffer); 262217365Sjkim } 263217365Sjkim 264217365Sjkim return (Status); 265217365Sjkim} 266217365Sjkim 267217365Sjkim 268217365Sjkim/****************************************************************************** 269217365Sjkim * 270208625Sjkim * FUNCTION: DtCompileInteger 271208625Sjkim * 272208625Sjkim * PARAMETERS: Buffer - Output buffer 273208625Sjkim * Field - Field obj with Integer to be compiled 274208625Sjkim * ByteLength - Byte length of the integer 275218590Sjkim * Flags - Additional compile info 276208625Sjkim * 277208625Sjkim * RETURN: None 278208625Sjkim * 279218590Sjkim * DESCRIPTION: Compile an integer. Supports integer expressions with C-style 280218590Sjkim * operators. 281208625Sjkim * 282208625Sjkim *****************************************************************************/ 283208625Sjkim 284208625Sjkimvoid 285208625SjkimDtCompileInteger ( 286208625Sjkim UINT8 *Buffer, 287208625Sjkim DT_FIELD *Field, 288208625Sjkim UINT32 ByteLength, 289208625Sjkim UINT8 Flags) 290208625Sjkim{ 291218590Sjkim UINT64 Value; 292208625Sjkim UINT64 MaxValue; 293220663Sjkim ACPI_STATUS Status; 294208625Sjkim 295208625Sjkim 296218590Sjkim /* Output buffer byte length must be in range 1-8 */ 297208625Sjkim 298208625Sjkim if ((ByteLength > 8) || (ByteLength == 0)) 299208625Sjkim { 300208625Sjkim DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, 301208625Sjkim "Invalid internal Byte length"); 302208625Sjkim return; 303208625Sjkim } 304208625Sjkim 305218590Sjkim /* Resolve integer expression to a single integer value */ 306208625Sjkim 307220663Sjkim Status = DtResolveIntegerExpression (Field, &Value); 308220663Sjkim if (ACPI_FAILURE (Status)) 309220663Sjkim { 310220663Sjkim return; 311220663Sjkim } 312208625Sjkim 313281075Sdim /* 314281075Sdim * Ensure that reserved fields are set properly. Note: uses 315281075Sdim * the DT_NON_ZERO flag to indicate that the reserved value 316281075Sdim * must be exactly one. Otherwise, the value must be zero. 317281075Sdim * This is sufficient for now. 318281075Sdim */ 319208625Sjkim 320281075Sdim /* TBD: Should use a flag rather than compare "Reserved" */ 321281075Sdim 322306536Sjkim if (!strcmp (Field->Name, "Reserved")) 323208625Sjkim { 324281075Sdim if (Flags & DT_NON_ZERO) 325281075Sdim { 326281075Sdim if (Value != 1) 327281075Sdim { 328281075Sdim DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field, 329281075Sdim "Must be one, setting to one"); 330281075Sdim Value = 1; 331281075Sdim } 332281075Sdim } 333281075Sdim else if (Value != 0) 334281075Sdim { 335281075Sdim DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field, 336281075Sdim "Must be zero, setting to zero"); 337281075Sdim Value = 0; 338281075Sdim } 339208625Sjkim } 340208625Sjkim 341208625Sjkim /* Check if the value must be non-zero */ 342208625Sjkim 343281075Sdim else if ((Flags & DT_NON_ZERO) && (Value == 0)) 344208625Sjkim { 345208625Sjkim DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL); 346208625Sjkim } 347208625Sjkim 348208625Sjkim /* 349208625Sjkim * Generate the maximum value for the data type (ByteLength) 350208625Sjkim * Note: construct chosen for maximum portability 351208625Sjkim */ 352208625Sjkim MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8)); 353208625Sjkim 354208625Sjkim /* Validate that the input value is within range of the target */ 355208625Sjkim 356208625Sjkim if (Value > MaxValue) 357208625Sjkim { 358281075Sdim sprintf (MsgBuffer, "%8.8X%8.8X - max %u bytes", 359281075Sdim ACPI_FORMAT_UINT64 (Value), ByteLength); 360208625Sjkim DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer); 361208625Sjkim } 362208625Sjkim 363306536Sjkim memcpy (Buffer, &Value, ByteLength); 364208625Sjkim return; 365208625Sjkim} 366208625Sjkim 367208625Sjkim 368208625Sjkim/****************************************************************************** 369208625Sjkim * 370209734Sjkim * FUNCTION: DtNormalizeBuffer 371208625Sjkim * 372209734Sjkim * PARAMETERS: Buffer - Input buffer 373209734Sjkim * Count - Output the count of hex number in 374209734Sjkim * the Buffer 375208625Sjkim * 376209734Sjkim * RETURN: The normalized buffer, freed by caller 377208625Sjkim * 378209734Sjkim * DESCRIPTION: [1A,2B,3C,4D] or 1A, 2B, 3C, 4D will be normalized 379209734Sjkim * to 1A 2B 3C 4D 380208625Sjkim * 381208625Sjkim *****************************************************************************/ 382208625Sjkim 383208625Sjkimstatic char * 384209734SjkimDtNormalizeBuffer ( 385209734Sjkim char *Buffer, 386209734Sjkim UINT32 *Count) 387208625Sjkim{ 388209734Sjkim char *NewBuffer; 389209734Sjkim char *TmpBuffer; 390209734Sjkim UINT32 BufferCount = 0; 391209734Sjkim BOOLEAN Separator = TRUE; 392209734Sjkim char c; 393208625Sjkim 394208625Sjkim 395306536Sjkim NewBuffer = UtLocalCalloc (strlen (Buffer) + 1); 396209734Sjkim TmpBuffer = NewBuffer; 397208625Sjkim 398209734Sjkim while ((c = *Buffer++)) 399209734Sjkim { 400209734Sjkim switch (c) 401209734Sjkim { 402209734Sjkim /* Valid separators */ 403208625Sjkim 404209734Sjkim case '[': 405209734Sjkim case ']': 406209734Sjkim case ' ': 407209734Sjkim case ',': 408250838Sjkim 409209734Sjkim Separator = TRUE; 410209734Sjkim break; 411209734Sjkim 412209734Sjkim default: 413250838Sjkim 414209734Sjkim if (Separator) 415209734Sjkim { 416209734Sjkim /* Insert blank as the standard separator */ 417209734Sjkim 418209734Sjkim if (NewBuffer[0]) 419209734Sjkim { 420209734Sjkim *TmpBuffer++ = ' '; 421209734Sjkim BufferCount++; 422209734Sjkim } 423209734Sjkim 424209734Sjkim Separator = FALSE; 425209734Sjkim } 426209734Sjkim 427209734Sjkim *TmpBuffer++ = c; 428209734Sjkim break; 429209734Sjkim } 430209734Sjkim } 431209734Sjkim 432209734Sjkim *Count = BufferCount + 1; 433209734Sjkim return (NewBuffer); 434208625Sjkim} 435208625Sjkim 436208625Sjkim 437208625Sjkim/****************************************************************************** 438208625Sjkim * 439208625Sjkim * FUNCTION: DtCompileBuffer 440208625Sjkim * 441208625Sjkim * PARAMETERS: Buffer - Output buffer 442208625Sjkim * StringValue - Integer list to be compiled 443208625Sjkim * Field - Current field object 444208625Sjkim * ByteLength - Byte length of the integer list 445208625Sjkim * 446208625Sjkim * RETURN: Count of remaining data in the input list 447208625Sjkim * 448208625Sjkim * DESCRIPTION: Compile and pack an integer list, for example 449208625Sjkim * "AA 1F 20 3B" ==> Buffer[] = {0xAA,0x1F,0x20,0x3B} 450208625Sjkim * 451208625Sjkim *****************************************************************************/ 452208625Sjkim 453208625SjkimUINT32 454208625SjkimDtCompileBuffer ( 455208625Sjkim UINT8 *Buffer, 456208625Sjkim char *StringValue, 457208625Sjkim DT_FIELD *Field, 458208625Sjkim UINT32 ByteLength) 459208625Sjkim{ 460208625Sjkim ACPI_STATUS Status; 461208625Sjkim char Hex[3]; 462208625Sjkim UINT64 Value; 463208625Sjkim UINT32 i; 464208625Sjkim UINT32 Count; 465208625Sjkim 466208625Sjkim 467209734Sjkim /* Allow several different types of value separators */ 468208625Sjkim 469209734Sjkim StringValue = DtNormalizeBuffer (StringValue, &Count); 470209734Sjkim 471208625Sjkim Hex[2] = 0; 472208625Sjkim for (i = 0; i < Count; i++) 473208625Sjkim { 474209734Sjkim /* Each element of StringValue is three chars */ 475208625Sjkim 476209734Sjkim Hex[0] = StringValue[(3 * i)]; 477209734Sjkim Hex[1] = StringValue[(3 * i) + 1]; 478209734Sjkim 479208625Sjkim /* Convert one hex byte */ 480208625Sjkim 481208625Sjkim Value = 0; 482208625Sjkim Status = DtStrtoul64 (Hex, &Value); 483208625Sjkim if (ACPI_FAILURE (Status)) 484208625Sjkim { 485208625Sjkim DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, MsgBuffer); 486252279Sjkim goto Exit; 487208625Sjkim } 488208625Sjkim 489208625Sjkim Buffer[i] = (UINT8) Value; 490208625Sjkim } 491208625Sjkim 492252279SjkimExit: 493209734Sjkim ACPI_FREE (StringValue); 494208625Sjkim return (ByteLength - Count); 495208625Sjkim} 496208625Sjkim 497208625Sjkim 498208625Sjkim/****************************************************************************** 499208625Sjkim * 500208625Sjkim * FUNCTION: DtCompileFlag 501208625Sjkim * 502208625Sjkim * PARAMETERS: Buffer - Output buffer 503208625Sjkim * Field - Field to be compiled 504208625Sjkim * Info - Flag info 505208625Sjkim * 506209734Sjkim * RETURN: 507208625Sjkim * 508208625Sjkim * DESCRIPTION: Compile a flag 509208625Sjkim * 510208625Sjkim *****************************************************************************/ 511208625Sjkim 512209734Sjkimvoid 513208625SjkimDtCompileFlag ( 514208625Sjkim UINT8 *Buffer, 515208625Sjkim DT_FIELD *Field, 516209734Sjkim ACPI_DMTABLE_INFO *Info) 517208625Sjkim{ 518208625Sjkim UINT64 Value = 0; 519208625Sjkim UINT32 BitLength = 1; 520209734Sjkim UINT8 BitPosition = 0; 521208625Sjkim ACPI_STATUS Status; 522208625Sjkim 523208625Sjkim 524208625Sjkim Status = DtStrtoul64 (Field->Value, &Value); 525208625Sjkim if (ACPI_FAILURE (Status)) 526208625Sjkim { 527208625Sjkim DtError (ASL_ERROR, ASL_MSG_INVALID_HEX_INTEGER, Field, NULL); 528208625Sjkim } 529208625Sjkim 530208625Sjkim switch (Info->Opcode) 531208625Sjkim { 532208625Sjkim case ACPI_DMT_FLAG0: 533208625Sjkim case ACPI_DMT_FLAG1: 534208625Sjkim case ACPI_DMT_FLAG2: 535208625Sjkim case ACPI_DMT_FLAG3: 536208625Sjkim case ACPI_DMT_FLAG4: 537208625Sjkim case ACPI_DMT_FLAG5: 538208625Sjkim case ACPI_DMT_FLAG6: 539208625Sjkim case ACPI_DMT_FLAG7: 540208625Sjkim 541209734Sjkim BitPosition = Info->Opcode; 542208625Sjkim BitLength = 1; 543208625Sjkim break; 544208625Sjkim 545208625Sjkim case ACPI_DMT_FLAGS0: 546209734Sjkim 547209734Sjkim BitPosition = 0; 548209734Sjkim BitLength = 2; 549209734Sjkim break; 550209734Sjkim 551209734Sjkim 552228110Sjkim case ACPI_DMT_FLAGS1: 553228110Sjkim 554228110Sjkim BitPosition = 1; 555228110Sjkim BitLength = 2; 556228110Sjkim break; 557228110Sjkim 558228110Sjkim 559208625Sjkim case ACPI_DMT_FLAGS2: 560208625Sjkim 561209734Sjkim BitPosition = 2; 562208625Sjkim BitLength = 2; 563208625Sjkim break; 564208625Sjkim 565228110Sjkim case ACPI_DMT_FLAGS4: 566228110Sjkim 567228110Sjkim BitPosition = 4; 568228110Sjkim BitLength = 2; 569228110Sjkim break; 570228110Sjkim 571208625Sjkim default: 572208625Sjkim 573208625Sjkim DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode"); 574208625Sjkim break; 575208625Sjkim } 576208625Sjkim 577208625Sjkim /* Check range of the input flag value */ 578208625Sjkim 579208625Sjkim if (Value >= ((UINT64) 1 << BitLength)) 580208625Sjkim { 581208625Sjkim sprintf (MsgBuffer, "Maximum %u bit", BitLength); 582208625Sjkim DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer); 583208625Sjkim Value = 0; 584208625Sjkim } 585208625Sjkim 586209734Sjkim *Buffer |= (UINT8) (Value << BitPosition); 587208625Sjkim} 588