OSDN Git Service

klibc基本機能実装. ACPICAの準備
[vaneos/DivergeMirror.git] / drivers / acpi / components / executer / exprep.c
1 /******************************************************************************
2  *
3  * Module Name: exprep - ACPI AML (p-code) execution - field prep utilities
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2015, 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 #include "acpi.h"
117 #include "accommon.h"
118 #include "acinterp.h"
119 #include "amlcode.h"
120 #include "acnamesp.h"
121 #include "acdispat.h"
122
123
124 #define _COMPONENT          ACPI_EXECUTER
125         ACPI_MODULE_NAME    ("exprep")
126
127 /* Local prototypes */
128
129 static UINT32
130 AcpiExDecodeFieldAccess (
131     ACPI_OPERAND_OBJECT     *ObjDesc,
132     UINT8                   FieldFlags,
133     UINT32                  *ReturnByteAlignment);
134
135
136 #ifdef ACPI_UNDER_DEVELOPMENT
137
138 static UINT32
139 AcpiExGenerateAccess (
140     UINT32                  FieldBitOffset,
141     UINT32                  FieldBitLength,
142     UINT32                  RegionLength);
143
144 /*******************************************************************************
145  *
146  * FUNCTION:    AcpiExGenerateAccess
147  *
148  * PARAMETERS:  FieldBitOffset      - Start of field within parent region/buffer
149  *              FieldBitLength      - Length of field in bits
150  *              RegionLength        - Length of parent in bytes
151  *
152  * RETURN:      Field granularity (8, 16, 32 or 64) and
153  *              ByteAlignment (1, 2, 3, or 4)
154  *
155  * DESCRIPTION: Generate an optimal access width for fields defined with the
156  *              AnyAcc keyword.
157  *
158  * NOTE: Need to have the RegionLength in order to check for boundary
159  *       conditions (end-of-region). However, the RegionLength is a deferred
160  *       operation. Therefore, to complete this implementation, the generation
161  *       of this access width must be deferred until the region length has
162  *       been evaluated.
163  *
164  ******************************************************************************/
165
166 static UINT32
167 AcpiExGenerateAccess (
168     UINT32                  FieldBitOffset,
169     UINT32                  FieldBitLength,
170     UINT32                  RegionLength)
171 {
172     UINT32                  FieldByteLength;
173     UINT32                  FieldByteOffset;
174     UINT32                  FieldByteEndOffset;
175     UINT32                  AccessByteWidth;
176     UINT32                  FieldStartOffset;
177     UINT32                  FieldEndOffset;
178     UINT32                  MinimumAccessWidth = 0xFFFFFFFF;
179     UINT32                  MinimumAccesses = 0xFFFFFFFF;
180     UINT32                  Accesses;
181
182
183     ACPI_FUNCTION_TRACE (ExGenerateAccess);
184
185
186     /* Round Field start offset and length to "minimal" byte boundaries */
187
188     FieldByteOffset    = ACPI_DIV_8 (ACPI_ROUND_DOWN (FieldBitOffset, 8));
189     FieldByteEndOffset = ACPI_DIV_8 (ACPI_ROUND_UP   (FieldBitLength +
190                                                       FieldBitOffset, 8));
191     FieldByteLength    = FieldByteEndOffset - FieldByteOffset;
192
193     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
194         "Bit length %u, Bit offset %u\n",
195         FieldBitLength, FieldBitOffset));
196
197     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
198         "Byte Length %u, Byte Offset %u, End Offset %u\n",
199         FieldByteLength, FieldByteOffset, FieldByteEndOffset));
200
201     /*
202      * Iterative search for the maximum access width that is both aligned
203      * and does not go beyond the end of the region
204      *
205      * Start at ByteAcc and work upwards to QwordAcc max. (1,2,4,8 bytes)
206      */
207     for (AccessByteWidth = 1; AccessByteWidth <= 8; AccessByteWidth <<= 1)
208     {
209         /*
210          * 1) Round end offset up to next access boundary and make sure that
211          *    this does not go beyond the end of the parent region.
212          * 2) When the Access width is greater than the FieldByteLength, we
213          *    are done. (This does not optimize for the perfectly aligned
214          *    case yet).
215          */
216         if (ACPI_ROUND_UP (FieldByteEndOffset, AccessByteWidth) <= RegionLength)
217         {
218             FieldStartOffset =
219                 ACPI_ROUND_DOWN (FieldByteOffset, AccessByteWidth) /
220                 AccessByteWidth;
221
222             FieldEndOffset =
223                 ACPI_ROUND_UP ((FieldByteLength + FieldByteOffset),
224                     AccessByteWidth) / AccessByteWidth;
225
226             Accesses = FieldEndOffset - FieldStartOffset;
227
228             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
229                 "AccessWidth %u end is within region\n", AccessByteWidth));
230
231             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
232                 "Field Start %u, Field End %u -- requires %u accesses\n",
233                 FieldStartOffset, FieldEndOffset, Accesses));
234
235             /* Single access is optimal */
236
237             if (Accesses <= 1)
238             {
239                 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
240                     "Entire field can be accessed with one operation of size %u\n",
241                     AccessByteWidth));
242                 return_VALUE (AccessByteWidth);
243             }
244
245             /*
246              * Fits in the region, but requires more than one read/write.
247              * try the next wider access on next iteration
248              */
249             if (Accesses < MinimumAccesses)
250             {
251                 MinimumAccesses    = Accesses;
252                 MinimumAccessWidth = AccessByteWidth;
253             }
254         }
255         else
256         {
257             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
258                 "AccessWidth %u end is NOT within region\n", AccessByteWidth));
259             if (AccessByteWidth == 1)
260             {
261                 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
262                     "Field goes beyond end-of-region!\n"));
263
264                 /* Field does not fit in the region at all */
265
266                 return_VALUE (0);
267             }
268
269             /*
270              * This width goes beyond the end-of-region, back off to
271              * previous access
272              */
273             ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
274                 "Backing off to previous optimal access width of %u\n",
275                 MinimumAccessWidth));
276             return_VALUE (MinimumAccessWidth);
277         }
278     }
279
280     /*
281      * Could not read/write field with one operation,
282      * just use max access width
283      */
284     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
285         "Cannot access field in one operation, using width 8\n"));
286     return_VALUE (8);
287 }
288 #endif /* ACPI_UNDER_DEVELOPMENT */
289
290
291 /*******************************************************************************
292  *
293  * FUNCTION:    AcpiExDecodeFieldAccess
294  *
295  * PARAMETERS:  ObjDesc             - Field object
296  *              FieldFlags          - Encoded fieldflags (contains access bits)
297  *              ReturnByteAlignment - Where the byte alignment is returned
298  *
299  * RETURN:      Field granularity (8, 16, 32 or 64) and
300  *              ByteAlignment (1, 2, 3, or 4)
301  *
302  * DESCRIPTION: Decode the AccessType bits of a field definition.
303  *
304  ******************************************************************************/
305
306 static UINT32
307 AcpiExDecodeFieldAccess (
308     ACPI_OPERAND_OBJECT     *ObjDesc,
309     UINT8                   FieldFlags,
310     UINT32                  *ReturnByteAlignment)
311 {
312     UINT32                  Access;
313     UINT32                  ByteAlignment;
314     UINT32                  BitLength;
315
316
317     ACPI_FUNCTION_TRACE (ExDecodeFieldAccess);
318
319
320     Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK);
321
322     switch (Access)
323     {
324     case AML_FIELD_ACCESS_ANY:
325
326 #ifdef ACPI_UNDER_DEVELOPMENT
327         ByteAlignment =
328             AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset,
329                 ObjDesc->CommonField.BitLength,
330                 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */);
331         BitLength = ByteAlignment * 8;
332 #endif
333
334         ByteAlignment = 1;
335         BitLength = 8;
336         break;
337
338     case AML_FIELD_ACCESS_BYTE:
339     case AML_FIELD_ACCESS_BUFFER:   /* ACPI 2.0 (SMBus Buffer) */
340
341         ByteAlignment = 1;
342         BitLength     = 8;
343         break;
344
345     case AML_FIELD_ACCESS_WORD:
346
347         ByteAlignment = 2;
348         BitLength     = 16;
349         break;
350
351     case AML_FIELD_ACCESS_DWORD:
352
353         ByteAlignment = 4;
354         BitLength     = 32;
355         break;
356
357     case AML_FIELD_ACCESS_QWORD:    /* ACPI 2.0 */
358
359         ByteAlignment = 8;
360         BitLength     = 64;
361         break;
362
363     default:
364
365         /* Invalid field access type */
366
367         ACPI_ERROR ((AE_INFO,
368             "Unknown field access type 0x%X",
369             Access));
370         return_UINT32 (0);
371     }
372
373     if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
374     {
375         /*
376          * BufferField access can be on any byte boundary, so the
377          * ByteAlignment is always 1 byte -- regardless of any ByteAlignment
378          * implied by the field access type.
379          */
380         ByteAlignment = 1;
381     }
382
383     *ReturnByteAlignment = ByteAlignment;
384     return_UINT32 (BitLength);
385 }
386
387
388 /*******************************************************************************
389  *
390  * FUNCTION:    AcpiExPrepCommonFieldObject
391  *
392  * PARAMETERS:  ObjDesc             - The field object
393  *              FieldFlags          - Access, LockRule, and UpdateRule.
394  *                                    The format of a FieldFlag is described
395  *                                    in the ACPI specification
396  *              FieldAttribute      - Special attributes (not used)
397  *              FieldBitPosition    - Field start position
398  *              FieldBitLength      - Field length in number of bits
399  *
400  * RETURN:      Status
401  *
402  * DESCRIPTION: Initialize the areas of the field object that are common
403  *              to the various types of fields. Note: This is very "sensitive"
404  *              code because we are solving the general case for field
405  *              alignment.
406  *
407  ******************************************************************************/
408
409 ACPI_STATUS
410 AcpiExPrepCommonFieldObject (
411     ACPI_OPERAND_OBJECT     *ObjDesc,
412     UINT8                   FieldFlags,
413     UINT8                   FieldAttribute,
414     UINT32                  FieldBitPosition,
415     UINT32                  FieldBitLength)
416 {
417     UINT32                  AccessBitWidth;
418     UINT32                  ByteAlignment;
419     UINT32                  NearestByteAddress;
420
421
422     ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject);
423
424
425     /*
426      * Note: the structure being initialized is the
427      * ACPI_COMMON_FIELD_INFO;  No structure fields outside of the common
428      * area are initialized by this procedure.
429      */
430     ObjDesc->CommonField.FieldFlags = FieldFlags;
431     ObjDesc->CommonField.Attribute  = FieldAttribute;
432     ObjDesc->CommonField.BitLength  = FieldBitLength;
433
434     /*
435      * Decode the access type so we can compute offsets. The access type gives
436      * two pieces of information - the width of each field access and the
437      * necessary ByteAlignment (address granularity) of the access.
438      *
439      * For AnyAcc, the AccessBitWidth is the largest width that is both
440      * necessary and possible in an attempt to access the whole field in one
441      * I/O operation. However, for AnyAcc, the ByteAlignment is always one
442      * byte.
443      *
444      * For all Buffer Fields, the ByteAlignment is always one byte.
445      *
446      * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
447      * the same (equivalent) as the ByteAlignment.
448      */
449     AccessBitWidth = AcpiExDecodeFieldAccess (ObjDesc, FieldFlags,
450                         &ByteAlignment);
451     if (!AccessBitWidth)
452     {
453         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
454     }
455
456     /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */
457
458     ObjDesc->CommonField.AccessByteWidth = (UINT8)
459         ACPI_DIV_8 (AccessBitWidth);
460
461     /*
462      * BaseByteOffset is the address of the start of the field within the
463      * region. It is the byte address of the first *datum* (field-width data
464      * unit) of the field. (i.e., the first datum that contains at least the
465      * first *bit* of the field.)
466      *
467      * Note: ByteAlignment is always either equal to the AccessBitWidth or 8
468      * (Byte access), and it defines the addressing granularity of the parent
469      * region or buffer.
470      */
471     NearestByteAddress =
472         ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);
473     ObjDesc->CommonField.BaseByteOffset = (UINT32)
474         ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment);
475
476     /*
477      * StartFieldBitOffset is the offset of the first bit of the field within
478      * a field datum.
479      */
480     ObjDesc->CommonField.StartFieldBitOffset = (UINT8)
481         (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset));
482
483     return_ACPI_STATUS (AE_OK);
484 }
485
486
487 /*******************************************************************************
488  *
489  * FUNCTION:    AcpiExPrepFieldValue
490  *
491  * PARAMETERS:  Info    - Contains all field creation info
492  *
493  * RETURN:      Status
494  *
495  * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a
496  *              subtype of DefField and connect it to the parent Node.
497  *
498  ******************************************************************************/
499
500 ACPI_STATUS
501 AcpiExPrepFieldValue (
502     ACPI_CREATE_FIELD_INFO  *Info)
503 {
504     ACPI_OPERAND_OBJECT     *ObjDesc;
505     ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
506     ACPI_STATUS             Status;
507     UINT32                  AccessByteWidth;
508     UINT32                  Type;
509
510
511     ACPI_FUNCTION_TRACE (ExPrepFieldValue);
512
513
514     /* Parameter validation */
515
516     if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)
517     {
518         if (!Info->RegionNode)
519         {
520             ACPI_ERROR ((AE_INFO, "Null RegionNode"));
521             return_ACPI_STATUS (AE_AML_NO_OPERAND);
522         }
523
524         Type = AcpiNsGetType (Info->RegionNode);
525         if (Type != ACPI_TYPE_REGION)
526         {
527             ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",
528                 Type, AcpiUtGetTypeName (Type)));
529
530             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
531         }
532     }
533
534     /* Allocate a new field object */
535
536     ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);
537     if (!ObjDesc)
538     {
539         return_ACPI_STATUS (AE_NO_MEMORY);
540     }
541
542     /* Initialize areas of the object that are common to all fields */
543
544     ObjDesc->CommonField.Node = Info->FieldNode;
545     Status = AcpiExPrepCommonFieldObject (ObjDesc,
546                 Info->FieldFlags, Info->Attribute,
547                 Info->FieldBitPosition, Info->FieldBitLength);
548     if (ACPI_FAILURE (Status))
549     {
550         AcpiUtDeleteObjectDesc (ObjDesc);
551         return_ACPI_STATUS (Status);
552     }
553
554     /* Initialize areas of the object that are specific to the field type */
555
556     switch (Info->FieldType)
557     {
558     case ACPI_TYPE_LOCAL_REGION_FIELD:
559
560         ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);
561
562         /* Fields specific to GenericSerialBus fields */
563
564         ObjDesc->Field.AccessLength = Info->AccessLength;
565
566         if (Info->ConnectionNode)
567         {
568             SecondDesc = Info->ConnectionNode->Object;
569             if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID))
570             {
571                 Status = AcpiDsGetBufferArguments (SecondDesc);
572                 if (ACPI_FAILURE (Status))
573                 {
574                     AcpiUtDeleteObjectDesc (ObjDesc);
575                     return_ACPI_STATUS (Status);
576                 }
577             }
578
579             ObjDesc->Field.ResourceBuffer = SecondDesc->Buffer.Pointer;
580             ObjDesc->Field.ResourceLength = (UINT16) SecondDesc->Buffer.Length;
581         }
582         else if (Info->ResourceBuffer)
583         {
584             ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer;
585             ObjDesc->Field.ResourceLength = Info->ResourceLength;
586         }
587
588         ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex;
589
590         /* Allow full data read from EC address space */
591
592         if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
593             (ObjDesc->CommonField.BitLength > 8))
594         {
595             AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (
596                 ObjDesc->CommonField.BitLength);
597
598             /* Maximum byte width supported is 255 */
599
600             if (AccessByteWidth < 256)
601             {
602                 ObjDesc->CommonField.AccessByteWidth = (UINT8) AccessByteWidth;
603             }
604         }
605
606         /* An additional reference for the container */
607
608         AcpiUtAddReference (ObjDesc->Field.RegionObj);
609
610         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
611             "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
612             ObjDesc->Field.StartFieldBitOffset, ObjDesc->Field.BaseByteOffset,
613             ObjDesc->Field.AccessByteWidth, ObjDesc->Field.RegionObj));
614         break;
615
616     case ACPI_TYPE_LOCAL_BANK_FIELD:
617
618         ObjDesc->BankField.Value = Info->BankValue;
619         ObjDesc->BankField.RegionObj =
620             AcpiNsGetAttachedObject (Info->RegionNode);
621         ObjDesc->BankField.BankObj =
622             AcpiNsGetAttachedObject (Info->RegisterNode);
623
624         /* An additional reference for the attached objects */
625
626         AcpiUtAddReference (ObjDesc->BankField.RegionObj);
627         AcpiUtAddReference (ObjDesc->BankField.BankObj);
628
629         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
630             "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
631             ObjDesc->BankField.StartFieldBitOffset,
632             ObjDesc->BankField.BaseByteOffset,
633             ObjDesc->Field.AccessByteWidth,
634             ObjDesc->BankField.RegionObj,
635             ObjDesc->BankField.BankObj));
636
637         /*
638          * Remember location in AML stream of the field unit
639          * opcode and operands -- since the BankValue
640          * operands must be evaluated.
641          */
642         SecondDesc = ObjDesc->Common.NextObject;
643         SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
644             Info->DataRegisterNode)->Named.Data;
645         SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
646             Info->DataRegisterNode)->Named.Length;
647
648         break;
649
650     case ACPI_TYPE_LOCAL_INDEX_FIELD:
651
652         /* Get the Index and Data registers */
653
654         ObjDesc->IndexField.IndexObj =
655             AcpiNsGetAttachedObject (Info->RegisterNode);
656         ObjDesc->IndexField.DataObj =
657             AcpiNsGetAttachedObject (Info->DataRegisterNode);
658
659         if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)
660         {
661             ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));
662             AcpiUtDeleteObjectDesc (ObjDesc);
663             return_ACPI_STATUS (AE_AML_INTERNAL);
664         }
665
666         /* An additional reference for the attached objects */
667
668         AcpiUtAddReference (ObjDesc->IndexField.DataObj);
669         AcpiUtAddReference (ObjDesc->IndexField.IndexObj);
670
671         /*
672          * April 2006: Changed to match MS behavior
673          *
674          * The value written to the Index register is the byte offset of the
675          * target field in units of the granularity of the IndexField
676          *
677          * Previously, the value was calculated as an index in terms of the
678          * width of the Data register, as below:
679          *
680          *      ObjDesc->IndexField.Value = (UINT32)
681          *          (Info->FieldBitPosition / ACPI_MUL_8 (
682          *              ObjDesc->Field.AccessByteWidth));
683          *
684          * February 2006: Tried value as a byte offset:
685          *      ObjDesc->IndexField.Value = (UINT32)
686          *          ACPI_DIV_8 (Info->FieldBitPosition);
687          */
688         ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (
689             ACPI_DIV_8 (Info->FieldBitPosition),
690             ObjDesc->IndexField.AccessByteWidth);
691
692         ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
693             "IndexField: BitOff %X, Off %X, Value %X, Gran %X, Index %p, Data %p\n",
694             ObjDesc->IndexField.StartFieldBitOffset,
695             ObjDesc->IndexField.BaseByteOffset,
696             ObjDesc->IndexField.Value,
697             ObjDesc->Field.AccessByteWidth,
698             ObjDesc->IndexField.IndexObj,
699             ObjDesc->IndexField.DataObj));
700         break;
701
702     default:
703
704         /* No other types should get here */
705
706         break;
707     }
708
709     /*
710      * Store the constructed descriptor (ObjDesc) into the parent Node,
711      * preserving the current type of that NamedObj.
712      */
713     Status = AcpiNsAttachObject (Info->FieldNode, ObjDesc,
714                 AcpiNsGetType (Info->FieldNode));
715
716     ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Set NamedObj %p [%4.4s], ObjDesc %p\n",
717         Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));
718
719     /* Remove local reference to the object */
720
721     AcpiUtRemoveReference (ObjDesc);
722     return_ACPI_STATUS (Status);
723 }