1 /****************************************************************************** 2 * 3 * Module Name: exprep - ACPI AML field prep utilities 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/include/acpi.h> 153 #include <contrib/dev/acpica/include/accommon.h> 154 #include <contrib/dev/acpica/include/acinterp.h> 155 #include <contrib/dev/acpica/include/amlcode.h> 156 #include <contrib/dev/acpica/include/acnamesp.h> 157 #include <contrib/dev/acpica/include/acdispat.h> 158 159 160 #define _COMPONENT ACPI_EXECUTER 161 ACPI_MODULE_NAME ("exprep") 162 163 /* Local prototypes */ 164 165 static UINT32 166 AcpiExDecodeFieldAccess ( 167 ACPI_OPERAND_OBJECT *ObjDesc, 168 UINT8 FieldFlags, 169 UINT32 *ReturnByteAlignment); 170 171 172 #ifdef ACPI_UNDER_DEVELOPMENT 173 174 static UINT32 175 AcpiExGenerateAccess ( 176 UINT32 FieldBitOffset, 177 UINT32 FieldBitLength, 178 UINT32 RegionLength); 179 180 181 /******************************************************************************* 182 * 183 * FUNCTION: AcpiExGenerateAccess 184 * 185 * PARAMETERS: FieldBitOffset - Start of field within parent region/buffer 186 * FieldBitLength - Length of field in bits 187 * RegionLength - Length of parent in bytes 188 * 189 * RETURN: Field granularity (8, 16, 32 or 64) and 190 * ByteAlignment (1, 2, 3, or 4) 191 * 192 * DESCRIPTION: Generate an optimal access width for fields defined with the 193 * AnyAcc keyword. 194 * 195 * NOTE: Need to have the RegionLength in order to check for boundary 196 * conditions (end-of-region). However, the RegionLength is a deferred 197 * operation. Therefore, to complete this implementation, the generation 198 * of this access width must be deferred until the region length has 199 * been evaluated. 200 * 201 ******************************************************************************/ 202 203 static UINT32 204 AcpiExGenerateAccess ( 205 UINT32 FieldBitOffset, 206 UINT32 FieldBitLength, 207 UINT32 RegionLength) 208 { 209 UINT32 FieldByteLength; 210 UINT32 FieldByteOffset; 211 UINT32 FieldByteEndOffset; 212 UINT32 AccessByteWidth; 213 UINT32 FieldStartOffset; 214 UINT32 FieldEndOffset; 215 UINT32 MinimumAccessWidth = 0xFFFFFFFF; 216 UINT32 MinimumAccesses = 0xFFFFFFFF; 217 UINT32 Accesses; 218 219 220 ACPI_FUNCTION_TRACE (ExGenerateAccess); 221 222 223 /* Round Field start offset and length to "minimal" byte boundaries */ 224 225 FieldByteOffset = ACPI_DIV_8 ( 226 ACPI_ROUND_DOWN (FieldBitOffset, 8)); 227 228 FieldByteEndOffset = ACPI_DIV_8 ( 229 ACPI_ROUND_UP (FieldBitLength + FieldBitOffset, 8)); 230 231 FieldByteLength = FieldByteEndOffset - FieldByteOffset; 232 233 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 234 "Bit length %u, Bit offset %u\n", 235 FieldBitLength, FieldBitOffset)); 236 237 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 238 "Byte Length %u, Byte Offset %u, End Offset %u\n", 239 FieldByteLength, FieldByteOffset, FieldByteEndOffset)); 240 241 /* 242 * Iterative search for the maximum access width that is both aligned 243 * and does not go beyond the end of the region 244 * 245 * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes) 246 */ 247 for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1) 248 { 249 /* 250 * 1) Round end offset up to next access boundary and make sure that 251 * this does not go beyond the end of the parent region. 252 * 2) When the Access width is greater than the FieldByteLength, we 253 * are done. (This does not optimize for the perfectly aligned 254 * case yet). 255 */ 256 if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <= 257 RegionLength) 258 { 259 FieldStartOffset = 260 ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) / 261 AccessByteWidth; 262 263 FieldEndOffset = 264 ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset), 265 AccessByteWidth) / AccessByteWidth; 266 267 Accesses = FieldEndOffset - FieldStartOffset; 268 269 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 270 "AccessWidth %u end is within region\n", AccessByteWidth)); 271 272 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 273 "Field Start %u, Field End %u -- requires %u accesses\n", 274 FieldStartOffset, FieldEndOffset, Accesses)); 275 276 /* Single access is optimal */ 277 278 if (Accesses <= 1) 279 { 280 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 281 "Entire field can be accessed " 282 "with one operation of size %u\n", 283 AccessByteWidth)); 284 return_VALUE (AccessByteWidth); 285 } 286 287 /* 288 * Fits in the region, but requires more than one read/write. 289 * try the next wider access on next iteration 290 */ 291 if (Accesses < MinimumAccesses) 292 { 293 MinimumAccesses = Accesses; 294 MinimumAccessWidth = AccessByteWidth; 295 } 296 } 297 else 298 { 299 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 300 "AccessWidth %u end is NOT within region\n", 301 AccessByteWidth)); 302 if (AccessByteWidth == 1) 303 { 304 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 305 "Field goes beyond end-of-region!\n")); 306 307 /* Field does not fit in the region at all */ 308 309 return_VALUE (0); 310 } 311 312 /* 313 * This width goes beyond the end-of-region, back off to 314 * previous access 315 */ 316 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 317 "Backing off to previous optimal access width of %u\n", 318 MinimumAccessWidth)); 319 return_VALUE (MinimumAccessWidth); 320 } 321 } 322 323 /* 324 * Could not read/write field with one operation, 325 * just use max access width 326 */ 327 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 328 "Cannot access field in one operation, using width 8\n")); 329 330 return_VALUE (8); 331 } 332 #endif /* ACPI_UNDER_DEVELOPMENT */ 333 334 335 /******************************************************************************* 336 * 337 * FUNCTION: AcpiExDecodeFieldAccess 338 * 339 * PARAMETERS: ObjDesc - Field object 340 * FieldFlags - Encoded fieldflags (contains access bits) 341 * ReturnByteAlignment - Where the byte alignment is returned 342 * 343 * RETURN: Field granularity (8, 16, 32 or 64) and 344 * ByteAlignment (1, 2, 3, or 4) 345 * 346 * DESCRIPTION: Decode the AccessType bits of a field definition. 347 * 348 ******************************************************************************/ 349 350 static UINT32 351 AcpiExDecodeFieldAccess ( 352 ACPI_OPERAND_OBJECT *ObjDesc, 353 UINT8 FieldFlags, 354 UINT32 *ReturnByteAlignment) 355 { 356 UINT32 Access; 357 UINT32 ByteAlignment; 358 UINT32 BitLength; 359 360 361 ACPI_FUNCTION_TRACE (ExDecodeFieldAccess); 362 363 364 Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK); 365 366 switch (Access) 367 { 368 case AML_FIELD_ACCESS_ANY: 369 370 #ifdef ACPI_UNDER_DEVELOPMENT 371 ByteAlignment = 372 AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset, 373 ObjDesc->CommonField.BitLength, 374 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */); 375 BitLength = ByteAlignment * 8; 376 #endif 377 378 ByteAlignment = 1; 379 BitLength = 8; 380 break; 381 382 case AML_FIELD_ACCESS_BYTE: 383 case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */ 384 385 ByteAlignment = 1; 386 BitLength = 8; 387 break; 388 389 case AML_FIELD_ACCESS_WORD: 390 391 ByteAlignment = 2; 392 BitLength = 16; 393 break; 394 395 case AML_FIELD_ACCESS_DWORD: 396 397 ByteAlignment = 4; 398 BitLength = 32; 399 break; 400 401 case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */ 402 403 ByteAlignment = 8; 404 BitLength = 64; 405 break; 406 407 default: 408 409 /* Invalid field access type */ 410 411 ACPI_ERROR ((AE_INFO, 412 "Unknown field access type 0x%X", 413 Access)); 414 415 return_UINT32 (0); 416 } 417 418 if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD) 419 { 420 /* 421 * BufferField access can be on any byte boundary, so the 422 * ByteAlignment is always 1 byte -- regardless of any ByteAlignment 423 * implied by the field access type. 424 */ 425 ByteAlignment = 1; 426 } 427 428 *ReturnByteAlignment = ByteAlignment; 429 return_UINT32 (BitLength); 430 } 431 432 433 /******************************************************************************* 434 * 435 * FUNCTION: AcpiExPrepCommonFieldObject 436 * 437 * PARAMETERS: ObjDesc - The field object 438 * FieldFlags - Access, LockRule, and UpdateRule. 439 * The format of a FieldFlag is described 440 * in the ACPI specification 441 * FieldAttribute - Special attributes (not used) 442 * FieldBitPosition - Field start position 443 * FieldBitLength - Field length in number of bits 444 * 445 * RETURN: Status 446 * 447 * DESCRIPTION: Initialize the areas of the field object that are common 448 * to the various types of fields. Note: This is very "sensitive" 449 * code because we are solving the general case for field 450 * alignment. 451 * 452 ******************************************************************************/ 453 454 ACPI_STATUS 455 AcpiExPrepCommonFieldObject ( 456 ACPI_OPERAND_OBJECT *ObjDesc, 457 UINT8 FieldFlags, 458 UINT8 FieldAttribute, 459 UINT32 FieldBitPosition, 460 UINT32 FieldBitLength) 461 { 462 UINT32 AccessBitWidth; 463 UINT32 ByteAlignment; 464 UINT32 NearestByteAddress; 465 466 467 ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject); 468 469 470 /* 471 * Note: the structure being initialized is the 472 * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common 473 * area are initialized by this procedure. 474 */ 475 ObjDesc->CommonField.FieldFlags = FieldFlags; 476 ObjDesc->CommonField.Attribute = FieldAttribute; 477 ObjDesc->CommonField.BitLength = FieldBitLength; 478 479 /* 480 * Decode the access type so we can compute offsets. The access type gives 481 * two pieces of information - the width of each field access and the 482 * necessary ByteAlignment (address granularity) of the access. 483 * 484 * For AnyAcc, the AccessBitWidth is the largest width that is both 485 * necessary and possible in an attempt to access the whole field in one 486 * I/O operation. However, for AnyAcc, the ByteAlignment is always one 487 * byte. 488 * 489 * For all Buffer Fields, the ByteAlignment is always one byte. 490 * 491 * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is 492 * the same (equivalent) as the ByteAlignment. 493 */ 494 AccessBitWidth = AcpiExDecodeFieldAccess ( 495 ObjDesc, FieldFlags, &ByteAlignment); 496 if (!AccessBitWidth) 497 { 498 return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 499 } 500 501 /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */ 502 503 ObjDesc->CommonField.AccessByteWidth = (UINT8) 504 ACPI_DIV_8 (AccessBitWidth); 505 506 /* 507 * BaseByteOffset is the address of the start of the field within the 508 * region. It is the byte address of the first *datum* (field-width data 509 * unit) of the field. (i.e., the first datum that contains at least the 510 * first *bit* of the field.) 511 * 512 * Note: ByteAlignment is always either equal to the AccessBitWidth or 8 513 * (Byte access), and it defines the addressing granularity of the parent 514 * region or buffer. 515 */ 516 NearestByteAddress = 517 ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition); 518 ObjDesc->CommonField.BaseByteOffset = (UINT32) 519 ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment); 520 521 /* 522 * StartFieldBitOffset is the offset of the first bit of the field within 523 * a field datum. 524 */ 525 ObjDesc->CommonField.StartFieldBitOffset = (UINT8) 526 (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset)); 527 528 return_ACPI_STATUS (AE_OK); 529 } 530 531 532 /******************************************************************************* 533 * 534 * FUNCTION: AcpiExPrepFieldValue 535 * 536 * PARAMETERS: Info - Contains all field creation info 537 * 538 * RETURN: Status 539 * 540 * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a 541 * subtype of DefField and connect it to the parent Node. 542 * 543 ******************************************************************************/ 544 545 ACPI_STATUS 546 AcpiExPrepFieldValue ( 547 ACPI_CREATE_FIELD_INFO *Info) 548 { 549 ACPI_OPERAND_OBJECT *ObjDesc; 550 ACPI_OPERAND_OBJECT *SecondDesc = NULL; 551 ACPI_STATUS Status; 552 UINT32 AccessByteWidth; 553 UINT32 Type; 554 555 556 ACPI_FUNCTION_TRACE (ExPrepFieldValue); 557 558 559 /* Parameter validation */ 560 561 if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD) 562 { 563 if (!Info->RegionNode) 564 { 565 ACPI_ERROR ((AE_INFO, "Null RegionNode")); 566 return_ACPI_STATUS (AE_AML_NO_OPERAND); 567 } 568 569 Type = AcpiNsGetType (Info->RegionNode); 570 if (Type != ACPI_TYPE_REGION) 571 { 572 ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)", 573 Type, AcpiUtGetTypeName (Type))); 574 575 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 576 } 577 } 578 579 /* Allocate a new field object */ 580 581 ObjDesc = AcpiUtCreateInternalObject (Info->FieldType); 582 if (!ObjDesc) 583 { 584 return_ACPI_STATUS (AE_NO_MEMORY); 585 } 586 587 /* Initialize areas of the object that are common to all fields */ 588 589 ObjDesc->CommonField.Node = Info->FieldNode; 590 Status = AcpiExPrepCommonFieldObject (ObjDesc, 591 Info->FieldFlags, Info->Attribute, 592 Info->FieldBitPosition, Info->FieldBitLength); 593 if (ACPI_FAILURE (Status)) 594 { 595 AcpiUtDeleteObjectDesc (ObjDesc); 596 return_ACPI_STATUS (Status); 597 } 598 599 /* Initialize areas of the object that are specific to the field type */ 600 601 switch (Info->FieldType) 602 { 603 case ACPI_TYPE_LOCAL_REGION_FIELD: 604 605 ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode); 606 607 /* Fields specific to GenericSerialBus fields */ 608 609 ObjDesc->Field.AccessLength = Info->AccessLength; 610 611 if (Info->ConnectionNode) 612 { 613 SecondDesc = Info->ConnectionNode->Object; 614 if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID)) 615 { 616 Status = AcpiDsGetBufferArguments (SecondDesc); 617 if (ACPI_FAILURE (Status)) 618 { 619 AcpiUtDeleteObjectDesc (ObjDesc); 620 return_ACPI_STATUS (Status); 621 } 622 } 623 624 ObjDesc->Field.ResourceBuffer = 625 SecondDesc->Buffer.Pointer; 626 ObjDesc->Field.ResourceLength = 627 (UINT16) SecondDesc->Buffer.Length; 628 } 629 else if (Info->ResourceBuffer) 630 { 631 ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer; 632 ObjDesc->Field.ResourceLength = Info->ResourceLength; 633 } 634 635 ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex; 636 637 /* Allow full data read from EC address space */ 638 639 if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) && 640 (ObjDesc->CommonField.BitLength > 8)) 641 { 642 AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES ( 643 ObjDesc->CommonField.BitLength); 644 645 /* Maximum byte width supported is 255 */ 646 647 if (AccessByteWidth < 256) 648 { 649 ObjDesc->CommonField.AccessByteWidth = 650 (UINT8) AccessByteWidth; 651 } 652 } 653 654 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 655 "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n", 656 ObjDesc->Field.StartFieldBitOffset, 657 ObjDesc->Field.BaseByteOffset, 658 ObjDesc->Field.AccessByteWidth, 659 ObjDesc->Field.RegionObj)); 660 break; 661 662 case ACPI_TYPE_LOCAL_BANK_FIELD: 663 664 ObjDesc->BankField.Value = Info->BankValue; 665 ObjDesc->BankField.RegionObj = 666 AcpiNsGetAttachedObject (Info->RegionNode); 667 ObjDesc->BankField.BankObj = 668 AcpiNsGetAttachedObject (Info->RegisterNode); 669 670 /* An additional reference for the attached objects */ 671 672 AcpiUtAddReference (ObjDesc->BankField.RegionObj); 673 AcpiUtAddReference (ObjDesc->BankField.BankObj); 674 675 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 676 "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n", 677 ObjDesc->BankField.StartFieldBitOffset, 678 ObjDesc->BankField.BaseByteOffset, 679 ObjDesc->Field.AccessByteWidth, 680 ObjDesc->BankField.RegionObj, 681 ObjDesc->BankField.BankObj)); 682 683 /* 684 * Remember location in AML stream of the field unit 685 * opcode and operands -- since the BankValue 686 * operands must be evaluated. 687 */ 688 SecondDesc = ObjDesc->Common.NextObject; 689 SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, 690 Info->DataRegisterNode)->Named.Data; 691 SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, 692 Info->DataRegisterNode)->Named.Length; 693 694 break; 695 696 case ACPI_TYPE_LOCAL_INDEX_FIELD: 697 698 /* Get the Index and Data registers */ 699 700 ObjDesc->IndexField.IndexObj = 701 AcpiNsGetAttachedObject (Info->RegisterNode); 702 ObjDesc->IndexField.DataObj = 703 AcpiNsGetAttachedObject (Info->DataRegisterNode); 704 705 if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj) 706 { 707 ACPI_ERROR ((AE_INFO, "Null Index Object during field prep")); 708 AcpiUtDeleteObjectDesc (ObjDesc); 709 return_ACPI_STATUS (AE_AML_INTERNAL); 710 } 711 712 /* An additional reference for the attached objects */ 713 714 AcpiUtAddReference (ObjDesc->IndexField.DataObj); 715 AcpiUtAddReference (ObjDesc->IndexField.IndexObj); 716 717 /* 718 * April 2006: Changed to match MS behavior 719 * 720 * The value written to the Index register is the byte offset of the 721 * target field in units of the granularity of the IndexField 722 * 723 * Previously, the value was calculated as an index in terms of the 724 * width of the Data register, as below: 725 * 726 * ObjDesc->IndexField.Value = (UINT32) 727 * (Info->FieldBitPosition / ACPI_MUL_8 ( 728 * ObjDesc->Field.AccessByteWidth)); 729 * 730 * February 2006: Tried value as a byte offset: 731 * ObjDesc->IndexField.Value = (UINT32) 732 * ACPI_DIV_8 (Info->FieldBitPosition); 733 */ 734 ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN ( 735 ACPI_DIV_8 (Info->FieldBitPosition), 736 ObjDesc->IndexField.AccessByteWidth); 737 738 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 739 "IndexField: BitOff %X, Off %X, Value %X, " 740 "Gran %X, Index %p, Data %p\n", 741 ObjDesc->IndexField.StartFieldBitOffset, 742 ObjDesc->IndexField.BaseByteOffset, 743 ObjDesc->IndexField.Value, 744 ObjDesc->Field.AccessByteWidth, 745 ObjDesc->IndexField.IndexObj, 746 ObjDesc->IndexField.DataObj)); 747 break; 748 749 default: 750 751 /* No other types should get here */ 752 753 break; 754 } 755 756 /* 757 * Store the constructed descriptor (ObjDesc) into the parent Node, 758 * preserving the current type of that NamedObj. 759 */ 760 Status = AcpiNsAttachObject ( 761 Info->FieldNode, ObjDesc, AcpiNsGetType (Info->FieldNode)); 762 763 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 764 "Set NamedObj %p [%4.4s], ObjDesc %p\n", 765 Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc)); 766 767 /* Remove local reference to the object */ 768 769 AcpiUtRemoveReference (ObjDesc); 770 return_ACPI_STATUS (Status); 771 } 772