Home | History | Annotate | Line # | Download | only in executer
exprep.c revision 1.1.1.4.2.1
      1 /******************************************************************************
      2  *
      3  * Module Name: exprep - ACPI AML (p-code) execution - field prep utilities
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2015, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "acpi.h"
     45 #include "accommon.h"
     46 #include "acinterp.h"
     47 #include "amlcode.h"
     48 #include "acnamesp.h"
     49 #include "acdispat.h"
     50 
     51 
     52 #define _COMPONENT          ACPI_EXECUTER
     53         ACPI_MODULE_NAME    ("exprep")
     54 
     55 /* Local prototypes */
     56 
     57 static UINT32
     58 AcpiExDecodeFieldAccess (
     59     ACPI_OPERAND_OBJECT     *ObjDesc,
     60     UINT8                   FieldFlags,
     61     UINT32                  *ReturnByteAlignment);
     62 
     63 
     64 #ifdef ACPI_UNDER_DEVELOPMENT
     65 
     66 static UINT32
     67 AcpiExGenerateAccess (
     68     UINT32                  FieldBitOffset,
     69     UINT32                  FieldBitLength,
     70     UINT32                  RegionLength);
     71 
     72 /*******************************************************************************
     73  *
     74  * FUNCTION:    AcpiExGenerateAccess
     75  *
     76  * PARAMETERS:  FieldBitOffset      - Start of field within parent region/buffer
     77  *              FieldBitLength      - Length of field in bits
     78  *              RegionLength        - Length of parent in bytes
     79  *
     80  * RETURN:      Field granularity (8, 16, 32 or 64) and
     81  *              ByteAlignment (1, 2, 3, or 4)
     82  *
     83  * DESCRIPTION: Generate an optimal access width for fields defined with the
     84  *              AnyAcc keyword.
     85  *
     86  * NOTE: Need to have the RegionLength in order to check for boundary
     87  *       conditions (end-of-region). However, the RegionLength is a deferred
     88  *       operation. Therefore, to complete this implementation, the generation
     89  *       of this access width must be deferred until the region length has
     90  *       been evaluated.
     91  *
     92  ******************************************************************************/
     93 
     94 static UINT32
     95 AcpiExGenerateAccess (
     96     UINT32                  FieldBitOffset,
     97     UINT32                  FieldBitLength,
     98     UINT32                  RegionLength)
     99 {
    100     UINT32                  FieldByteLength;
    101     UINT32                  FieldByteOffset;
    102     UINT32                  FieldByteEndOffset;
    103     UINT32                  AccessByteWidth;
    104     UINT32                  FieldStartOffset;
    105     UINT32                  FieldEndOffset;
    106     UINT32                  MinimumAccessWidth = 0xFFFFFFFF;
    107     UINT32                  MinimumAccesses = 0xFFFFFFFF;
    108     UINT32                  Accesses;
    109 
    110 
    111     ACPI_FUNCTION_TRACE (ExGenerateAccess);
    112 
    113 
    114     /* Round Field start offset and length to "minimal" byte boundaries */
    115 
    116     FieldByteOffset    = ACPI_DIV_8 (ACPI_ROUND_DOWN (FieldBitOffset, 8));
    117     FieldByteEndOffset = ACPI_DIV_8 (ACPI_ROUND_UP   (FieldBitLength +
    118                                                       FieldBitOffset, 8));
    119     FieldByteLength    = FieldByteEndOffset - FieldByteOffset;
    120 
    121     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    122         "Bit length %u, Bit offset %u\n",
    123         FieldBitLength, FieldBitOffset));
    124 
    125     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    126         "Byte Length %u, Byte Offset %u, End Offset %u\n",
    127         FieldByteLength, FieldByteOffset, FieldByteEndOffset));
    128 
    129     /*
    130      * Iterative search for the maximum access width that is both aligned
    131      * and does not go beyond the end of the region
    132      *
    133      * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes)
    134      */
    135     for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1)
    136     {
    137         /*
    138          * 1) Round end offset up to next access boundary and make sure that
    139          *    this does not go beyond the end of the parent region.
    140          * 2) When the Access width is greater than the FieldByteLength, we
    141          *    are done. (This does not optimize for the perfectly aligned
    142          *    case yet).
    143          */
    144         if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <= RegionLength)
    145         {
    146             FieldStartOffset =
    147                 ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) /
    148                 AccessByteWidth;
    149 
    150             FieldEndOffset =
    151                 ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset),
    152                     AccessByteWidth) / AccessByteWidth;
    153 
    154             Accesses = FieldEndOffset - FieldStartOffset;
    155 
    156             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    157                 "AccessWidth %u end is within region\n", AccessByteWidth));
    158 
    159             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    160                 "Field Start %u, Field End %u -- requires %u accesses\n",
    161                 FieldStartOffset, FieldEndOffset, Accesses));
    162 
    163             /* Single access is optimal */
    164 
    165             if (Accesses <= 1)
    166             {
    167                 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    168                     "Entire field can be accessed with one operation of size %u\n",
    169                     AccessByteWidth));
    170                 return_VALUE (AccessByteWidth);
    171             }
    172 
    173             /*
    174              * Fits in the region, but requires more than one read/write.
    175              * try the next wider access on next iteration
    176              */
    177             if (Accesses < MinimumAccesses)
    178             {
    179                 MinimumAccesses    = Accesses;
    180                 MinimumAccessWidth = AccessByteWidth;
    181             }
    182         }
    183         else
    184         {
    185             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    186                 "AccessWidth %u end is NOT within region\n", AccessByteWidth));
    187             if (AccessByteWidth == 1)
    188             {
    189                 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    190                     "Field goes beyond end-of-region!\n"));
    191 
    192                 /* Field does not fit in the region at all */
    193 
    194                 return_VALUE (0);
    195             }
    196 
    197             /*
    198              * This width goes beyond the end-of-region, back off to
    199              * previous access
    200              */
    201             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    202                 "Backing off to previous optimal access width of %u\n",
    203                 MinimumAccessWidth));
    204             return_VALUE (MinimumAccessWidth);
    205         }
    206     }
    207 
    208     /*
    209      * Could not read/write field with one operation,
    210      * just use max access width
    211      */
    212     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    213         "Cannot access field in one operation, using width 8\n"));
    214     return_VALUE (8);
    215 }
    216 #endif /* ACPI_UNDER_DEVELOPMENT */
    217 
    218 
    219 /*******************************************************************************
    220  *
    221  * FUNCTION:    AcpiExDecodeFieldAccess
    222  *
    223  * PARAMETERS:  ObjDesc             - Field object
    224  *              FieldFlags          - Encoded fieldflags (contains access bits)
    225  *              ReturnByteAlignment - Where the byte alignment is returned
    226  *
    227  * RETURN:      Field granularity (8, 16, 32 or 64) and
    228  *              ByteAlignment (1, 2, 3, or 4)
    229  *
    230  * DESCRIPTION: Decode the AccessType bits of a field definition.
    231  *
    232  ******************************************************************************/
    233 
    234 static UINT32
    235 AcpiExDecodeFieldAccess (
    236     ACPI_OPERAND_OBJECT     *ObjDesc,
    237     UINT8                   FieldFlags,
    238     UINT32                  *ReturnByteAlignment)
    239 {
    240     UINT32                  Access;
    241     UINT32                  ByteAlignment;
    242     UINT32                  BitLength;
    243 
    244 
    245     ACPI_FUNCTION_TRACE (ExDecodeFieldAccess);
    246 
    247 
    248     Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK);
    249 
    250     switch (Access)
    251     {
    252     case AML_FIELD_ACCESS_ANY:
    253 
    254 #ifdef ACPI_UNDER_DEVELOPMENT
    255         ByteAlignment =
    256             AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset,
    257                 ObjDesc->CommonField.BitLength,
    258                 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */);
    259         BitLength = ByteAlignment * 8;
    260 #endif
    261 
    262         ByteAlignment = 1;
    263         BitLength = 8;
    264         break;
    265 
    266     case AML_FIELD_ACCESS_BYTE:
    267     case AML_FIELD_ACCESS_BUFFER:   /* ACPI 2.0 (SMBus Buffer) */
    268 
    269         ByteAlignment = 1;
    270         BitLength     = 8;
    271         break;
    272 
    273     case AML_FIELD_ACCESS_WORD:
    274 
    275         ByteAlignment = 2;
    276         BitLength     = 16;
    277         break;
    278 
    279     case AML_FIELD_ACCESS_DWORD:
    280 
    281         ByteAlignment = 4;
    282         BitLength     = 32;
    283         break;
    284 
    285     case AML_FIELD_ACCESS_QWORD:    /* ACPI 2.0 */
    286 
    287         ByteAlignment = 8;
    288         BitLength     = 64;
    289         break;
    290 
    291     default:
    292 
    293         /* Invalid field access type */
    294 
    295         ACPI_ERROR ((AE_INFO,
    296             "Unknown field access type 0x%X",
    297             Access));
    298         return_UINT32 (0);
    299     }
    300 
    301     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
    302     {
    303         /*
    304          * BufferField access can be on any byte boundary, so the
    305          * ByteAlignment is always 1 byte -- regardless of any ByteAlignment
    306          * implied by the field access type.
    307          */
    308         ByteAlignment = 1;
    309     }
    310 
    311     *ReturnByteAlignment = ByteAlignment;
    312     return_UINT32 (BitLength);
    313 }
    314 
    315 
    316 /*******************************************************************************
    317  *
    318  * FUNCTION:    AcpiExPrepCommonFieldObject
    319  *
    320  * PARAMETERS:  ObjDesc             - The field object
    321  *              FieldFlags          - Access, LockRule, and UpdateRule.
    322  *                                    The format of a FieldFlag is described
    323  *                                    in the ACPI specification
    324  *              FieldAttribute      - Special attributes (not used)
    325  *              FieldBitPosition    - Field start position
    326  *              FieldBitLength      - Field length in number of bits
    327  *
    328  * RETURN:      Status
    329  *
    330  * DESCRIPTION: Initialize the areas of the field object that are common
    331  *              to the various types of fields. Note: This is very "sensitive"
    332  *              code because we are solving the general case for field
    333  *              alignment.
    334  *
    335  ******************************************************************************/
    336 
    337 ACPI_STATUS
    338 AcpiExPrepCommonFieldObject (
    339     ACPI_OPERAND_OBJECT     *ObjDesc,
    340     UINT8                   FieldFlags,
    341     UINT8                   FieldAttribute,
    342     UINT32                  FieldBitPosition,
    343     UINT32                  FieldBitLength)
    344 {
    345     UINT32                  AccessBitWidth;
    346     UINT32                  ByteAlignment;
    347     UINT32                  NearestByteAddress;
    348 
    349 
    350     ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject);
    351 
    352 
    353     /*
    354      * Note: the structure being initialized is the
    355      * ACPI_COMMON_FIELD_INFO;  No structure fields outside of the common
    356      * area are initialized by this procedure.
    357      */
    358     ObjDesc->CommonField.FieldFlags = FieldFlags;
    359     ObjDesc->CommonField.Attribute  = FieldAttribute;
    360     ObjDesc->CommonField.BitLength  = FieldBitLength;
    361 
    362     /*
    363      * Decode the access type so we can compute offsets. The access type gives
    364      * two pieces of information - the width of each field access and the
    365      * necessary ByteAlignment (address granularity) of the access.
    366      *
    367      * For AnyAcc, the AccessBitWidth is the largest width that is both
    368      * necessary and possible in an attempt to access the whole field in one
    369      * I/O operation. However, for AnyAcc, the ByteAlignment is always one
    370      * byte.
    371      *
    372      * For all Buffer Fields, the ByteAlignment is always one byte.
    373      *
    374      * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
    375      * the same (equivalent) as the ByteAlignment.
    376      */
    377     AccessBitWidth = AcpiExDecodeFieldAccess (ObjDesc, FieldFlags,
    378                         &ByteAlignment);
    379     if (!AccessBitWidth)
    380     {
    381         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
    382     }
    383 
    384     /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */
    385 
    386     ObjDesc->CommonField.AccessByteWidth = (UINT8)
    387         ACPI_DIV_8 (AccessBitWidth);
    388 
    389     /*
    390      * BaseByteOffset is the address of the start of the field within the
    391      * region. It is the byte address of the first *datum* (field-width data
    392      * unit) of the field. (i.e., the first datum that contains at least the
    393      * first *bit* of the field.)
    394      *
    395      * Note: ByteAlignment is always either equal to the AccessBitWidth or 8
    396      * (Byte access), and it defines the addressing granularity of the parent
    397      * region or buffer.
    398      */
    399     NearestByteAddress =
    400         ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);
    401     ObjDesc->CommonField.BaseByteOffset = (UINT32)
    402         ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment);
    403 
    404     /*
    405      * StartFieldBitOffset is the offset of the first bit of the field within
    406      * a field datum.
    407      */
    408     ObjDesc->CommonField.StartFieldBitOffset = (UINT8)
    409         (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset));
    410 
    411     return_ACPI_STATUS (AE_OK);
    412 }
    413 
    414 
    415 /*******************************************************************************
    416  *
    417  * FUNCTION:    AcpiExPrepFieldValue
    418  *
    419  * PARAMETERS:  Info    - Contains all field creation info
    420  *
    421  * RETURN:      Status
    422  *
    423  * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a
    424  *              subtype of DefField and connect it to the parent Node.
    425  *
    426  ******************************************************************************/
    427 
    428 ACPI_STATUS
    429 AcpiExPrepFieldValue (
    430     ACPI_CREATE_FIELD_INFO  *Info)
    431 {
    432     ACPI_OPERAND_OBJECT     *ObjDesc;
    433     ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
    434     ACPI_STATUS             Status;
    435     UINT32                  AccessByteWidth;
    436     UINT32                  Type;
    437 
    438 
    439     ACPI_FUNCTION_TRACE (ExPrepFieldValue);
    440 
    441 
    442     /* Parameter validation */
    443 
    444     if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)
    445     {
    446         if (!Info->RegionNode)
    447         {
    448             ACPI_ERROR ((AE_INFO, "Null RegionNode"));
    449             return_ACPI_STATUS (AE_AML_NO_OPERAND);
    450         }
    451 
    452         Type = AcpiNsGetType (Info->RegionNode);
    453         if (Type != ACPI_TYPE_REGION)
    454         {
    455             ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",
    456                 Type, AcpiUtGetTypeName (Type)));
    457 
    458             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    459         }
    460     }
    461 
    462     /* Allocate a new field object */
    463 
    464     ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);
    465     if (!ObjDesc)
    466     {
    467         return_ACPI_STATUS (AE_NO_MEMORY);
    468     }
    469 
    470     /* Initialize areas of the object that are common to all fields */
    471 
    472     ObjDesc->CommonField.Node = Info->FieldNode;
    473     Status = AcpiExPrepCommonFieldObject (ObjDesc,
    474                 Info->FieldFlags, Info->Attribute,
    475                 Info->FieldBitPosition, Info->FieldBitLength);
    476     if (ACPI_FAILURE (Status))
    477     {
    478         AcpiUtDeleteObjectDesc (ObjDesc);
    479         return_ACPI_STATUS (Status);
    480     }
    481 
    482     /* Initialize areas of the object that are specific to the field type */
    483 
    484     switch (Info->FieldType)
    485     {
    486     case ACPI_TYPE_LOCAL_REGION_FIELD:
    487 
    488         ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);
    489 
    490         /* Fields specific to GenericSerialBus fields */
    491 
    492         ObjDesc->Field.AccessLength = Info->AccessLength;
    493 
    494         if (Info->ConnectionNode)
    495         {
    496             SecondDesc = Info->ConnectionNode->Object;
    497             if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID))
    498             {
    499                 Status = AcpiDsGetBufferArguments (SecondDesc);
    500                 if (ACPI_FAILURE (Status))
    501                 {
    502                     AcpiUtDeleteObjectDesc (ObjDesc);
    503                     return_ACPI_STATUS (Status);
    504                 }
    505             }
    506 
    507             ObjDesc->Field.ResourceBuffer = SecondDesc->Buffer.Pointer;
    508             ObjDesc->Field.ResourceLength = (UINT16) SecondDesc->Buffer.Length;
    509         }
    510         else if (Info->ResourceBuffer)
    511         {
    512             ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer;
    513             ObjDesc->Field.ResourceLength = Info->ResourceLength;
    514         }
    515 
    516         ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex;
    517 
    518         /* Allow full data read from EC address space */
    519 
    520         if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
    521             (ObjDesc->CommonField.BitLength > 8))
    522         {
    523             AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (
    524                 ObjDesc->CommonField.BitLength);
    525 
    526             /* Maximum byte width supported is 255 */
    527 
    528             if (AccessByteWidth < 256)
    529             {
    530                 ObjDesc->CommonField.AccessByteWidth = (UINT8) AccessByteWidth;
    531             }
    532         }
    533 
    534         /* An additional reference for the container */
    535 
    536         AcpiUtAddReference (ObjDesc->Field.RegionObj);
    537 
    538         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    539             "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
    540             ObjDesc->Field.StartFieldBitOffset, ObjDesc->Field.BaseByteOffset,
    541             ObjDesc->Field.AccessByteWidth, ObjDesc->Field.RegionObj));
    542         break;
    543 
    544     case ACPI_TYPE_LOCAL_BANK_FIELD:
    545 
    546         ObjDesc->BankField.Value = Info->BankValue;
    547         ObjDesc->BankField.RegionObj =
    548             AcpiNsGetAttachedObject (Info->RegionNode);
    549         ObjDesc->BankField.BankObj =
    550             AcpiNsGetAttachedObject (Info->RegisterNode);
    551 
    552         /* An additional reference for the attached objects */
    553 
    554         AcpiUtAddReference (ObjDesc->BankField.RegionObj);
    555         AcpiUtAddReference (ObjDesc->BankField.BankObj);
    556 
    557         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    558             "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
    559             ObjDesc->BankField.StartFieldBitOffset,
    560             ObjDesc->BankField.BaseByteOffset,
    561             ObjDesc->Field.AccessByteWidth,
    562             ObjDesc->BankField.RegionObj,
    563             ObjDesc->BankField.BankObj));
    564 
    565         /*
    566          * Remember location in AML stream of the field unit
    567          * opcode and operands -- since the BankValue
    568          * operands must be evaluated.
    569          */
    570         SecondDesc = ObjDesc->Common.NextObject;
    571         SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
    572             Info->DataRegisterNode)->Named.Data;
    573         SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
    574             Info->DataRegisterNode)->Named.Length;
    575 
    576         break;
    577 
    578     case ACPI_TYPE_LOCAL_INDEX_FIELD:
    579 
    580         /* Get the Index and Data registers */
    581 
    582         ObjDesc->IndexField.IndexObj =
    583             AcpiNsGetAttachedObject (Info->RegisterNode);
    584         ObjDesc->IndexField.DataObj =
    585             AcpiNsGetAttachedObject (Info->DataRegisterNode);
    586 
    587         if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)
    588         {
    589             ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));
    590             AcpiUtDeleteObjectDesc (ObjDesc);
    591             return_ACPI_STATUS (AE_AML_INTERNAL);
    592         }
    593 
    594         /* An additional reference for the attached objects */
    595 
    596         AcpiUtAddReference (ObjDesc->IndexField.DataObj);
    597         AcpiUtAddReference (ObjDesc->IndexField.IndexObj);
    598 
    599         /*
    600          * April 2006: Changed to match MS behavior
    601          *
    602          * The value written to the Index register is the byte offset of the
    603          * target field in units of the granularity of the IndexField
    604          *
    605          * Previously, the value was calculated as an index in terms of the
    606          * width of the Data register, as below:
    607          *
    608          *      ObjDesc->IndexField.Value = (UINT32)
    609          *          (Info->FieldBitPosition / ACPI_MUL_8 (
    610          *              ObjDesc->Field.AccessByteWidth));
    611          *
    612          * February 2006: Tried value as a byte offset:
    613          *      ObjDesc->IndexField.Value = (UINT32)
    614          *          ACPI_DIV_8 (Info->FieldBitPosition);
    615          */
    616         ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (
    617             ACPI_DIV_8 (Info->FieldBitPosition),
    618             ObjDesc->IndexField.AccessByteWidth);
    619 
    620         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
    621             "IndexField: BitOff %X, Off %X, Value %X, Gran %X, Index %p, Data %p\n",
    622             ObjDesc->IndexField.StartFieldBitOffset,
    623             ObjDesc->IndexField.BaseByteOffset,
    624             ObjDesc->IndexField.Value,
    625             ObjDesc->Field.AccessByteWidth,
    626             ObjDesc->IndexField.IndexObj,
    627             ObjDesc->IndexField.DataObj));
    628         break;
    629 
    630     default:
    631 
    632         /* No other types should get here */
    633 
    634         break;
    635     }
    636 
    637     /*
    638      * Store the constructed descriptor (ObjDesc) into the parent Node,
    639      * preserving the current type of that NamedObj.
    640      */
    641     Status = AcpiNsAttachObject (Info->FieldNode, ObjDesc,
    642                 AcpiNsGetType (Info->FieldNode));
    643 
    644     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Set NamedObj %p [%4.4s], ObjDesc %p\n",
    645         Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));
    646 
    647     /* Remove local reference to the object */
    648 
    649     AcpiUtRemoveReference (ObjDesc);
    650     return_ACPI_STATUS (Status);
    651 }
    652