Path: blob/main/sys/contrib/dev/acpica/components/executer/exprep.c
48521 views
/******************************************************************************1*2* Module Name: exprep - ACPI AML field prep utilities3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acinterp.h>154#include <contrib/dev/acpica/include/amlcode.h>155#include <contrib/dev/acpica/include/acnamesp.h>156#include <contrib/dev/acpica/include/acdispat.h>157158159#define _COMPONENT ACPI_EXECUTER160ACPI_MODULE_NAME ("exprep")161162/* Local prototypes */163164static UINT32165AcpiExDecodeFieldAccess (166ACPI_OPERAND_OBJECT *ObjDesc,167UINT8 FieldFlags,168UINT32 *ReturnByteAlignment);169170171#ifdef ACPI_UNDER_DEVELOPMENT172173static UINT32174AcpiExGenerateAccess (175UINT32 FieldBitOffset,176UINT32 FieldBitLength,177UINT32 RegionLength);178179180/*******************************************************************************181*182* FUNCTION: AcpiExGenerateAccess183*184* PARAMETERS: FieldBitOffset - Start of field within parent region/buffer185* FieldBitLength - Length of field in bits186* RegionLength - Length of parent in bytes187*188* RETURN: Field granularity (8, 16, 32 or 64) and189* ByteAlignment (1, 2, 3, or 4)190*191* DESCRIPTION: Generate an optimal access width for fields defined with the192* AnyAcc keyword.193*194* NOTE: Need to have the RegionLength in order to check for boundary195* conditions (end-of-region). However, the RegionLength is a deferred196* operation. Therefore, to complete this implementation, the generation197* of this access width must be deferred until the region length has198* been evaluated.199*200******************************************************************************/201202static UINT32203AcpiExGenerateAccess (204UINT32 FieldBitOffset,205UINT32 FieldBitLength,206UINT32 RegionLength)207{208UINT32 FieldByteLength;209UINT32 FieldByteOffset;210UINT32 FieldByteEndOffset;211UINT32 AccessByteWidth;212UINT32 FieldStartOffset;213UINT32 FieldEndOffset;214UINT32 MinimumAccessWidth = 0xFFFFFFFF;215UINT32 MinimumAccesses = 0xFFFFFFFF;216UINT32 Accesses;217218219ACPI_FUNCTION_TRACE (ExGenerateAccess);220221222/* Round Field start offset and length to "minimal" byte boundaries */223224FieldByteOffset = ACPI_DIV_8 (225ACPI_ROUND_DOWN (FieldBitOffset, 8));226227FieldByteEndOffset = ACPI_DIV_8 (228ACPI_ROUND_UP (FieldBitLength + FieldBitOffset, 8));229230FieldByteLength = FieldByteEndOffset - FieldByteOffset;231232ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,233"Bit length %u, Bit offset %u\n",234FieldBitLength, FieldBitOffset));235236ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,237"Byte Length %u, Byte Offset %u, End Offset %u\n",238FieldByteLength, FieldByteOffset, FieldByteEndOffset));239240/*241* Iterative search for the maximum access width that is both aligned242* and does not go beyond the end of the region243*244* Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes)245*/246for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1)247{248/*249* 1) Round end offset up to next access boundary and make sure that250* this does not go beyond the end of the parent region.251* 2) When the Access width is greater than the FieldByteLength, we252* are done. (This does not optimize for the perfectly aligned253* case yet).254*/255if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <=256RegionLength)257{258FieldStartOffset =259ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) /260AccessByteWidth;261262FieldEndOffset =263ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset),264AccessByteWidth) / AccessByteWidth;265266Accesses = FieldEndOffset - FieldStartOffset;267268ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,269"AccessWidth %u end is within region\n", AccessByteWidth));270271ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,272"Field Start %u, Field End %u -- requires %u accesses\n",273FieldStartOffset, FieldEndOffset, Accesses));274275/* Single access is optimal */276277if (Accesses <= 1)278{279ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,280"Entire field can be accessed "281"with one operation of size %u\n",282AccessByteWidth));283return_VALUE (AccessByteWidth);284}285286/*287* Fits in the region, but requires more than one read/write.288* try the next wider access on next iteration289*/290if (Accesses < MinimumAccesses)291{292MinimumAccesses = Accesses;293MinimumAccessWidth = AccessByteWidth;294}295}296else297{298ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,299"AccessWidth %u end is NOT within region\n",300AccessByteWidth));301if (AccessByteWidth == 1)302{303ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,304"Field goes beyond end-of-region!\n"));305306/* Field does not fit in the region at all */307308return_VALUE (0);309}310311/*312* This width goes beyond the end-of-region, back off to313* previous access314*/315ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,316"Backing off to previous optimal access width of %u\n",317MinimumAccessWidth));318return_VALUE (MinimumAccessWidth);319}320}321322/*323* Could not read/write field with one operation,324* just use max access width325*/326ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,327"Cannot access field in one operation, using width 8\n"));328329return_VALUE (8);330}331#endif /* ACPI_UNDER_DEVELOPMENT */332333334/*******************************************************************************335*336* FUNCTION: AcpiExDecodeFieldAccess337*338* PARAMETERS: ObjDesc - Field object339* FieldFlags - Encoded fieldflags (contains access bits)340* ReturnByteAlignment - Where the byte alignment is returned341*342* RETURN: Field granularity (8, 16, 32 or 64) and343* ByteAlignment (1, 2, 3, or 4)344*345* DESCRIPTION: Decode the AccessType bits of a field definition.346*347******************************************************************************/348349static UINT32350AcpiExDecodeFieldAccess (351ACPI_OPERAND_OBJECT *ObjDesc,352UINT8 FieldFlags,353UINT32 *ReturnByteAlignment)354{355UINT32 Access;356UINT32 ByteAlignment;357UINT32 BitLength;358359360ACPI_FUNCTION_TRACE (ExDecodeFieldAccess);361362363Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK);364365switch (Access)366{367case AML_FIELD_ACCESS_ANY:368369#ifdef ACPI_UNDER_DEVELOPMENT370ByteAlignment =371AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset,372ObjDesc->CommonField.BitLength,3730xFFFFFFFF /* Temp until we pass RegionLength as parameter */);374BitLength = ByteAlignment * 8;375#endif376377ByteAlignment = 1;378BitLength = 8;379break;380381case AML_FIELD_ACCESS_BYTE:382case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */383384ByteAlignment = 1;385BitLength = 8;386break;387388case AML_FIELD_ACCESS_WORD:389390ByteAlignment = 2;391BitLength = 16;392break;393394case AML_FIELD_ACCESS_DWORD:395396ByteAlignment = 4;397BitLength = 32;398break;399400case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */401402ByteAlignment = 8;403BitLength = 64;404break;405406default:407408/* Invalid field access type */409410ACPI_ERROR ((AE_INFO,411"Unknown field access type 0x%X",412Access));413414return_UINT32 (0);415}416417if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)418{419/*420* BufferField access can be on any byte boundary, so the421* ByteAlignment is always 1 byte -- regardless of any ByteAlignment422* implied by the field access type.423*/424ByteAlignment = 1;425}426427*ReturnByteAlignment = ByteAlignment;428return_UINT32 (BitLength);429}430431432/*******************************************************************************433*434* FUNCTION: AcpiExPrepCommonFieldObject435*436* PARAMETERS: ObjDesc - The field object437* FieldFlags - Access, LockRule, and UpdateRule.438* The format of a FieldFlag is described439* in the ACPI specification440* FieldAttribute - Special attributes (not used)441* FieldBitPosition - Field start position442* FieldBitLength - Field length in number of bits443*444* RETURN: Status445*446* DESCRIPTION: Initialize the areas of the field object that are common447* to the various types of fields. Note: This is very "sensitive"448* code because we are solving the general case for field449* alignment.450*451******************************************************************************/452453ACPI_STATUS454AcpiExPrepCommonFieldObject (455ACPI_OPERAND_OBJECT *ObjDesc,456UINT8 FieldFlags,457UINT8 FieldAttribute,458UINT32 FieldBitPosition,459UINT32 FieldBitLength)460{461UINT32 AccessBitWidth;462UINT32 ByteAlignment;463UINT32 NearestByteAddress;464465466ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject);467468469/*470* Note: the structure being initialized is the471* ACPI_COMMON_FIELD_INFO; No structure fields outside of the common472* area are initialized by this procedure.473*/474ObjDesc->CommonField.FieldFlags = FieldFlags;475ObjDesc->CommonField.Attribute = FieldAttribute;476ObjDesc->CommonField.BitLength = FieldBitLength;477478/*479* Decode the access type so we can compute offsets. The access type gives480* two pieces of information - the width of each field access and the481* necessary ByteAlignment (address granularity) of the access.482*483* For AnyAcc, the AccessBitWidth is the largest width that is both484* necessary and possible in an attempt to access the whole field in one485* I/O operation. However, for AnyAcc, the ByteAlignment is always one486* byte.487*488* For all Buffer Fields, the ByteAlignment is always one byte.489*490* For all other access types (Byte, Word, Dword, Qword), the Bitwidth is491* the same (equivalent) as the ByteAlignment.492*/493AccessBitWidth = AcpiExDecodeFieldAccess (494ObjDesc, FieldFlags, &ByteAlignment);495if (!AccessBitWidth)496{497return_ACPI_STATUS (AE_AML_OPERAND_VALUE);498}499500/* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */501502ObjDesc->CommonField.AccessByteWidth = (UINT8)503ACPI_DIV_8 (AccessBitWidth);504505/*506* BaseByteOffset is the address of the start of the field within the507* region. It is the byte address of the first *datum* (field-width data508* unit) of the field. (i.e., the first datum that contains at least the509* first *bit* of the field.)510*511* Note: ByteAlignment is always either equal to the AccessBitWidth or 8512* (Byte access), and it defines the addressing granularity of the parent513* region or buffer.514*/515NearestByteAddress =516ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);517ObjDesc->CommonField.BaseByteOffset = (UINT32)518ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment);519520/*521* StartFieldBitOffset is the offset of the first bit of the field within522* a field datum.523*/524ObjDesc->CommonField.StartFieldBitOffset = (UINT8)525(FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset));526527return_ACPI_STATUS (AE_OK);528}529530531/*******************************************************************************532*533* FUNCTION: AcpiExPrepFieldValue534*535* PARAMETERS: Info - Contains all field creation info536*537* RETURN: Status538*539* DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a540* subtype of DefField and connect it to the parent Node.541*542******************************************************************************/543544ACPI_STATUS545AcpiExPrepFieldValue (546ACPI_CREATE_FIELD_INFO *Info)547{548ACPI_OPERAND_OBJECT *ObjDesc;549ACPI_OPERAND_OBJECT *SecondDesc = NULL;550ACPI_STATUS Status;551UINT32 AccessByteWidth;552UINT32 Type;553554555ACPI_FUNCTION_TRACE (ExPrepFieldValue);556557558/* Parameter validation */559560if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)561{562if (!Info->RegionNode)563{564ACPI_ERROR ((AE_INFO, "Null RegionNode"));565return_ACPI_STATUS (AE_AML_NO_OPERAND);566}567568Type = AcpiNsGetType (Info->RegionNode);569if (Type != ACPI_TYPE_REGION)570{571ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",572Type, AcpiUtGetTypeName (Type)));573574return_ACPI_STATUS (AE_AML_OPERAND_TYPE);575}576}577578/* Allocate a new field object */579580ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);581if (!ObjDesc)582{583return_ACPI_STATUS (AE_NO_MEMORY);584}585586/* Initialize areas of the object that are common to all fields */587588ObjDesc->CommonField.Node = Info->FieldNode;589Status = AcpiExPrepCommonFieldObject (ObjDesc,590Info->FieldFlags, Info->Attribute,591Info->FieldBitPosition, Info->FieldBitLength);592if (ACPI_FAILURE (Status))593{594AcpiUtDeleteObjectDesc (ObjDesc);595return_ACPI_STATUS (Status);596}597598/* Initialize areas of the object that are specific to the field type */599600switch (Info->FieldType)601{602case ACPI_TYPE_LOCAL_REGION_FIELD:603604ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);605606/* Fields specific to GenericSerialBus fields */607608ObjDesc->Field.AccessLength = Info->AccessLength;609610if (Info->ConnectionNode)611{612SecondDesc = Info->ConnectionNode->Object;613if (SecondDesc == NULL)614{615break;616}617if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID))618{619Status = AcpiDsGetBufferArguments (SecondDesc);620if (ACPI_FAILURE (Status))621{622AcpiUtDeleteObjectDesc (ObjDesc);623return_ACPI_STATUS (Status);624}625}626627ObjDesc->Field.ResourceBuffer =628SecondDesc->Buffer.Pointer;629ObjDesc->Field.ResourceLength =630(UINT16) SecondDesc->Buffer.Length;631}632else if (Info->ResourceBuffer)633{634ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer;635ObjDesc->Field.ResourceLength = Info->ResourceLength;636}637638ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex;639640/* Allow full data read from EC address space */641642if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&643(ObjDesc->CommonField.BitLength > 8))644{645AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (646ObjDesc->CommonField.BitLength);647648/* Maximum byte width supported is 255 */649650if (AccessByteWidth < 256)651{652ObjDesc->CommonField.AccessByteWidth =653(UINT8) AccessByteWidth;654}655}656657ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,658"RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",659ObjDesc->Field.StartFieldBitOffset,660ObjDesc->Field.BaseByteOffset,661ObjDesc->Field.AccessByteWidth,662ObjDesc->Field.RegionObj));663break;664665case ACPI_TYPE_LOCAL_BANK_FIELD:666667ObjDesc->BankField.Value = Info->BankValue;668ObjDesc->BankField.RegionObj =669AcpiNsGetAttachedObject (Info->RegionNode);670ObjDesc->BankField.BankObj =671AcpiNsGetAttachedObject (Info->RegisterNode);672673/* An additional reference for the attached objects */674675AcpiUtAddReference (ObjDesc->BankField.RegionObj);676AcpiUtAddReference (ObjDesc->BankField.BankObj);677678ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,679"Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",680ObjDesc->BankField.StartFieldBitOffset,681ObjDesc->BankField.BaseByteOffset,682ObjDesc->Field.AccessByteWidth,683ObjDesc->BankField.RegionObj,684ObjDesc->BankField.BankObj));685686/*687* Remember location in AML stream of the field unit688* opcode and operands -- since the BankValue689* operands must be evaluated.690*/691SecondDesc = ObjDesc->Common.NextObject;692SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,693Info->DataRegisterNode)->Named.Data;694SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,695Info->DataRegisterNode)->Named.Length;696697break;698699case ACPI_TYPE_LOCAL_INDEX_FIELD:700701/* Get the Index and Data registers */702703ObjDesc->IndexField.IndexObj =704AcpiNsGetAttachedObject (Info->RegisterNode);705ObjDesc->IndexField.DataObj =706AcpiNsGetAttachedObject (Info->DataRegisterNode);707708if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)709{710ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));711AcpiUtDeleteObjectDesc (ObjDesc);712return_ACPI_STATUS (AE_AML_INTERNAL);713}714715/* An additional reference for the attached objects */716717AcpiUtAddReference (ObjDesc->IndexField.DataObj);718AcpiUtAddReference (ObjDesc->IndexField.IndexObj);719720/*721* April 2006: Changed to match MS behavior722*723* The value written to the Index register is the byte offset of the724* target field in units of the granularity of the IndexField725*726* Previously, the value was calculated as an index in terms of the727* width of the Data register, as below:728*729* ObjDesc->IndexField.Value = (UINT32)730* (Info->FieldBitPosition / ACPI_MUL_8 (731* ObjDesc->Field.AccessByteWidth));732*733* February 2006: Tried value as a byte offset:734* ObjDesc->IndexField.Value = (UINT32)735* ACPI_DIV_8 (Info->FieldBitPosition);736*/737ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (738ACPI_DIV_8 (Info->FieldBitPosition),739ObjDesc->IndexField.AccessByteWidth);740741ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,742"IndexField: BitOff %X, Off %X, Value %X, "743"Gran %X, Index %p, Data %p\n",744ObjDesc->IndexField.StartFieldBitOffset,745ObjDesc->IndexField.BaseByteOffset,746ObjDesc->IndexField.Value,747ObjDesc->Field.AccessByteWidth,748ObjDesc->IndexField.IndexObj,749ObjDesc->IndexField.DataObj));750break;751752default:753754/* No other types should get here */755756break;757}758759/*760* Store the constructed descriptor (ObjDesc) into the parent Node,761* preserving the current type of that NamedObj.762*/763Status = AcpiNsAttachObject (764Info->FieldNode, ObjDesc, AcpiNsGetType (Info->FieldNode));765766ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,767"Set NamedObj %p [%4.4s], ObjDesc %p\n",768Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));769770/* Remove local reference to the object */771772AcpiUtRemoveReference (ObjDesc);773return_ACPI_STATUS (Status);774}775776777